Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/aix/porting/porting_aix.c
38767 views
/*1* Copyright (c) 2012, 2018 SAP SE. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*24*/2526#include <stdio.h>27#include <sys/ldr.h>28#include <errno.h>2930#include "porting_aix.h"3132static unsigned char dladdr_buffer[0x4000];3334static void fill_dll_info(void) {35int rc = loadquery(L_GETINFO,dladdr_buffer, sizeof(dladdr_buffer));36if (rc == -1) {37fprintf(stderr, "loadquery failed (%d %s)", errno, strerror(errno));38fflush(stderr);39}40}4142static int dladdr_dont_reload(void* addr, Dl_info* info) {43const struct ld_info* p = (struct ld_info*) dladdr_buffer;44info->dli_fbase = 0; info->dli_fname = 0;45info->dli_sname = 0; info->dli_saddr = 0;46for (;;) {47if (addr >= p->ldinfo_textorg &&48addr < (((char*)p->ldinfo_textorg) + p->ldinfo_textsize)) {49info->dli_fname = p->ldinfo_filename;50info->dli_fbase = p->ldinfo_textorg;51return 1; /* [sic] */52}53if (!p->ldinfo_next) {54break;55}56p = (struct ld_info*)(((char*)p) + p->ldinfo_next);57}58return 0; /* [sic] */59}6061#ifdef __cplusplus62extern "C"63#endif64int dladdr(void *addr, Dl_info *info) {65static int loaded = 0;66if (!loaded) {67fill_dll_info();68loaded = 1;69}70if (!addr) {71return 0; /* [sic] */72}73/* Address could be AIX function descriptor? */74void* const addr0 = *( (void**) addr );75int rc = dladdr_dont_reload(addr, info);76if (rc == 0) {77rc = dladdr_dont_reload(addr0, info);78if (rc == 0) { /* [sic] */79fill_dll_info(); /* refill, maybe loadquery info is outdated */80rc = dladdr_dont_reload(addr, info);81if (rc == 0) {82rc = dladdr_dont_reload(addr0, info);83}84}85}86return rc;87}888990