8166189: Fix for Bug 8165524 breaks AIX build

Reviewed-by: simonis, goetz, mchung, cbensen, dsamersoff
This commit is contained in:
Christoph Langer 2016-09-20 08:46:33 +02:00
parent 73fbb10440
commit dd770672f8
3 changed files with 141 additions and 6 deletions

View File

@ -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;
}

View File

@ -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 */

View File

@ -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 GetJVMPath(const char *jrepath, const char *jvmtype,
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 */