src/java.desktop/aix/native/libawt/porting_aix.c
author sgroeger
Thu, 20 Jun 2019 14:09:22 +0100
changeset 55489 c749ecf599c0
parent 52353 896e80158d35
child 55753 b9798272720b
permissions -rw-r--r--
8226468: [aix] loadquery failed error message displayed Reviewed-by: stuefe, mbaesken
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
/*
52353
896e80158d35 8213151: [AIX] Some class library files are missing the Classpath exception
simonis
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2018 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>
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    28
#include <sys/ldr.h>
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    29
#include <errno.h>
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    30
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    31
#include "porting_aix.h"
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    32
55489
c749ecf599c0 8226468: [aix] loadquery failed error message displayed
sgroeger
parents: 52353
diff changeset
    33
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
    34
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    35
static void fill_dll_info(void) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    36
  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
    37
  if (rc == -1) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    38
    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
    39
    fflush(stderr);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    40
  }
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
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
    44
  const struct ld_info* p = (struct ld_info*) dladdr_buffer;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    45
  info->dli_fbase = 0; info->dli_fname = 0;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    46
  info->dli_sname = 0; info->dli_saddr = 0;
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 &&
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
diff changeset
    49
        addr < (((char*)p->ldinfo_textorg) + p->ldinfo_textsize)) {
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
}