Path: blob/master/src/java.base/aix/native/libjli/java_md_aix.c
41119 views
/*1* Copyright (c) 2016, 2019 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#include <stdio.h>25#include <string.h>26#include <sys/ldr.h>2728#include "java_md_aix.h"2930static unsigned char dladdr_buffer[0x8000];3132static int fill_dll_info(void) {33return loadquery(L_GETINFO, dladdr_buffer, sizeof(dladdr_buffer));34}3536static int dladdr_dont_reload(void *addr, Dl_info *info) {37const struct ld_info *p = (struct ld_info *)dladdr_buffer;38memset((void *)info, 0, sizeof(Dl_info));39for (;;) {40if (addr >= p->ldinfo_textorg &&41addr < p->ldinfo_textorg + p->ldinfo_textsize) {42info->dli_fname = p->ldinfo_filename;43return 1;44}45if (!p->ldinfo_next) {46break;47}48p = (struct ld_info *)(((char *)p) + p->ldinfo_next);49}50return 0;51}5253int dladdr(void *addr, Dl_info *info) {54static int loaded = 0;55int rc = 0;56void *addr0;57if (!addr) {58return rc;59}60if (!loaded) {61if (fill_dll_info() == -1)62return rc;63loaded = 1;64}6566// first try with addr on cached data67rc = dladdr_dont_reload(addr, info);6869// addr could be an AIX function descriptor, so try dereferenced version70if (rc == 0) {71addr0 = *((void **)addr);72rc = dladdr_dont_reload(addr0, info);73}7475// if we had no success until now, maybe loadquery info is outdated.76// refresh and retry77if (rc == 0) {78if (fill_dll_info() == -1)79return rc;80rc = dladdr_dont_reload(addr, info);81if (rc == 0) {82rc = dladdr_dont_reload(addr0, info);83}84}85return rc;86}878889