Path: blob/master/src/java.desktop/aix/native/libawt/porting_aix.c
41152 views
/*1* Copyright (c) 2012, 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*/2526#include <stdio.h>27#include <string.h>28#include <sys/ldr.h>29#include <errno.h>3031#include "porting_aix.h"3233static unsigned char dladdr_buffer[0x8000];3435static void fill_dll_info(void) {36int rc = loadquery(L_GETINFO,dladdr_buffer, sizeof(dladdr_buffer));37if (rc == -1) {38fprintf(stderr, "loadquery failed (%d %s)", errno, strerror(errno));39fflush(stderr);40}41}4243static int dladdr_dont_reload(void* addr, Dl_info* info) {44const struct ld_info* p = (struct ld_info*) dladdr_buffer;45memset((void *)info, 0, sizeof(Dl_info));46for (;;) {47if (addr >= p->ldinfo_textorg &&48addr < 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