8166189: Fix for Bug 8165524 breaks AIX build
authorclanger
Tue, 20 Sep 2016 08:46:33 +0200
changeset 41102 1b2130dd2d42
parent 41101 5e420a43b0c5
child 41103 c0b875b35b1e
8166189: Fix for Bug 8165524 breaks AIX build Reviewed-by: simonis, goetz, mchung, cbensen, dsamersoff
jdk/src/java.base/aix/native/libjli/java_md_aix.c
jdk/src/java.base/aix/native/libjli/java_md_aix.h
jdk/src/java.base/unix/native/libjli/java_md.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/aix/native/libjli/java_md_aix.c	Tue Sep 20 08:46:33 2016 +0200
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2016 SAP SE. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+#include <stdio.h>
+#include <sys/ldr.h>
+
+#include "java_md_aix.h"
+
+static unsigned char dladdr_buffer[0x4000];
+
+static int fill_dll_info(void) {
+    return loadquery(L_GETINFO, dladdr_buffer, sizeof(dladdr_buffer));
+}
+
+static int dladdr_dont_reload(void *addr, Dl_info *info) {
+    const struct ld_info *p = (struct ld_info *)dladdr_buffer;
+    memset((void *)info, 0, sizeof(Dl_info));
+    for (;;) {
+        if (addr >= p->ldinfo_textorg &&
+            addr < (((char*)p->ldinfo_textorg) + p->ldinfo_textsize))
+        {
+            info->dli_fname = p->ldinfo_filename;
+            return 1;
+        }
+        if (!p->ldinfo_next) {
+            break;
+        }
+        p = (struct ld_info *)(((char *)p) + p->ldinfo_next);
+    }
+    return 0;
+}
+
+int dladdr(void *addr, Dl_info *info) {
+    static int loaded = 0;
+    int rc = 0;
+    void *addr0;
+    if (!addr) {
+        return rc;
+    }
+    if (!loaded) {
+        if (fill_dll_info() == -1)
+            return rc;
+        loaded = 1;
+    }
+
+    // first try with addr on cached data
+    rc = dladdr_dont_reload(addr, info);
+
+    // addr could be an AIX function descriptor, so try dereferenced version
+    if (rc == 0) {
+        addr0 = *((void **)addr);
+        rc = dladdr_dont_reload(addr0, info);
+    }
+
+    // if we had no success until now, maybe loadquery info is outdated.
+    // refresh and retry
+    if (rc == 0) {
+        if (fill_dll_info() == -1)
+            return rc;
+        rc = dladdr_dont_reload(addr, info);
+        if (rc == 0) {
+            rc = dladdr_dont_reload(addr0, info);
+        }
+    }
+    return rc;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/aix/native/libjli/java_md_aix.h	Tue Sep 20 08:46:33 2016 +0200
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 SAP SE. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef JAVA_MD_AIX_H
+#define JAVA_MD_AIX_H
+
+/*
+ * Very limited AIX port of dladdr() for libjli.so.
+ *
+ * We try to mimick dladdr(3) on Linux (see http://linux.die.net/man/3/dladdr)
+ * dladdr(3) is not POSIX but a GNU extension, and is not available on AIX.
+ *
+ * We only support Dl_info.dli_fname here as this is the only thing that is
+ * used of it by libjli.so. A more comprehensive port of dladdr can be found
+ * in the hotspot implementation which is not available at this place, though.
+ */
+
+typedef struct {
+  const char *dli_fname; /* file path of loaded library */
+  void *dli_fbase;       /* unsupported */
+  const char *dli_sname; /* unsupported */
+  void *dli_saddr;       /* unsupported */
+} Dl_info;
+
+int dladdr(void *addr, Dl_info *info);
+
+#endif /* JAVA_MD_AIX_H */
--- a/jdk/src/java.base/unix/native/libjli/java_md.h	Tue Sep 20 10:32:52 2016 +0800
+++ b/jdk/src/java.base/unix/native/libjli/java_md.h	Tue Sep 20 08:46:33 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,12 +35,12 @@
 #include "manifest_info.h"
 #include "jli_util.h"
 
-#define PATH_SEPARATOR          ':'
-#define FILESEP                 "/"
-#define FILE_SEPARATOR          '/'
+#define PATH_SEPARATOR       ':'
+#define FILESEP              "/"
+#define FILE_SEPARATOR       '/'
 #define IS_FILE_SEPARATOR(c) ((c) == '/')
 #ifndef MAXNAMELEN
-#define MAXNAMELEN              PATH_MAX
+#define MAXNAMELEN           PATH_MAX
 #endif
 
 #ifdef _LP64
@@ -59,10 +59,13 @@
 static jboolean GetJREPath(char *path, jint pathsize, const char * arch,
                            jboolean speculative);
 
+#if defined(_AIX)
+#include "java_md_aix.h"
+#endif
+
 #ifdef MACOSX
 #include "java_md_macosx.h"
 #else  /* !MACOSX */
 #include "java_md_solinux.h"
 #endif /* MACOSX */
-
 #endif /* JAVA_MD_H */