src/java.desktop/aix/native/libawt/porting_aix.c
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58202 a45cce906207
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     1
/*
55753
b9798272720b 8227737: avoid implicit-function-declaration on AIX
mbaesken
parents: 55489
diff changeset
     2
 * Copyright (c) 2012, 2019 SAP SE. All rights reserved.
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     4
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
52353
896e80158d35 8213151: [AIX] Some class library files are missing the Classpath exception
simonis
parents: 47216
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
896e80158d35 8213151: [AIX] Some class library files are missing the Classpath exception
simonis
parents: 47216
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
896e80158d35 8213151: [AIX] Some class library files are missing the Classpath exception
simonis
parents: 47216
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    10
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    15
 * accompanied this code).
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    16
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    20
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    23
 * questions.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    24
 *
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    25
 */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    26
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    27
#include <stdio.h>
55753
b9798272720b 8227737: avoid implicit-function-declaration on AIX
mbaesken
parents: 55489
diff changeset
    28
#include <string.h>
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    29
#include <sys/ldr.h>
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    30
#include <errno.h>
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    31
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    32
#include "porting_aix.h"
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    33
55489
c749ecf599c0 8226468: [aix] loadquery failed error message displayed
sgroeger
parents: 52353
diff changeset
    34
static unsigned char dladdr_buffer[0x8000];
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    35
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    36
static void fill_dll_info(void) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    37
  int rc = loadquery(L_GETINFO,dladdr_buffer, sizeof(dladdr_buffer));
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    38
  if (rc == -1) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    39
    fprintf(stderr, "loadquery failed (%d %s)", errno, strerror(errno));
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    40
    fflush(stderr);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    41
  }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    42
}
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    43
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    44
static int dladdr_dont_reload(void* addr, Dl_info* info) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    45
  const struct ld_info* p = (struct ld_info*) dladdr_buffer;
58202
a45cce906207 8228482: fix xlc16/xlclang comparison of distinct pointer types and string literal conversion warnings
mbaesken
parents: 55753
diff changeset
    46
  memset((void *)info, 0, sizeof(Dl_info));
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    47
  for (;;) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    48
    if (addr >= p->ldinfo_textorg &&
58202
a45cce906207 8228482: fix xlc16/xlclang comparison of distinct pointer types and string literal conversion warnings
mbaesken
parents: 55753
diff changeset
    49
        addr < p->ldinfo_textorg + p->ldinfo_textsize) {
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    50
      info->dli_fname = p->ldinfo_filename;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    51
      info->dli_fbase = p->ldinfo_textorg;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    52
      return 1; /* [sic] */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    53
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    54
    if (!p->ldinfo_next) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    55
      break;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    56
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    57
    p = (struct ld_info*)(((char*)p) + p->ldinfo_next);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    58
  }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    59
  return 0; /* [sic] */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    60
}
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    61
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    62
#ifdef __cplusplus
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    63
extern "C"
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    64
#endif
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    65
int dladdr(void *addr, Dl_info *info) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    66
  static int loaded = 0;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    67
  if (!loaded) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    68
    fill_dll_info();
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    69
    loaded = 1;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    70
  }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    71
  if (!addr) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    72
    return 0;  /* [sic] */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    73
  }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    74
  /* Address could be AIX function descriptor? */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    75
  void* const addr0 = *( (void**) addr );
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    76
  int rc = dladdr_dont_reload(addr, info);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    77
  if (rc == 0) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    78
    rc = dladdr_dont_reload(addr0, info);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    79
    if (rc == 0) { /* [sic] */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    80
      fill_dll_info(); /* refill, maybe loadquery info is outdated */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    81
      rc = dladdr_dont_reload(addr, info);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    82
      if (rc == 0) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    83
        rc = dladdr_dont_reload(addr0, info);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    84
      }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    85
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    86
  }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    87
  return rc;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    88
}