Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/aix/vm/loadlib_aix.cpp
32284 views
/*1* Copyright 2012, 2013 SAP AG. 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/232425// Implementation of LoadedLibraries and friends2627// Ultimately this just uses loadquery()28// See:29// http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp30// ?topic=/com.ibm.aix.basetechref/doc/basetrf1/loadquery.htm3132#ifndef __STDC_FORMAT_MACROS33#define __STDC_FORMAT_MACROS34#endif35// 'allocation.inline.hpp' triggers the inclusion of 'inttypes.h' which defines macros36// required by the definitions in 'globalDefinitions.hpp'. But these macros in 'inttypes.h'37// are only defined if '__STDC_FORMAT_MACROS' is defined!38#include "memory/allocation.inline.hpp"39#include "oops/oop.inline.hpp"40#include "runtime/threadCritical.hpp"41#include "utilities/debug.hpp"42#include "utilities/ostream.hpp"43#include "loadlib_aix.hpp"44#include "porting_aix.hpp"4546// For loadquery()47#include <sys/ldr.h>4849///////////////////////////////////////////////////////////////////////////////50// Implementation for LoadedLibraryModule5152// output debug info53void LoadedLibraryModule::print(outputStream* os) const {54os->print("%15.15s: text: " INTPTR_FORMAT " - " INTPTR_FORMAT55", data: " INTPTR_FORMAT " - " INTPTR_FORMAT " ",56shortname, text_from, text_to, data_from, data_to);57os->print(" %s", fullpath);58if (strlen(membername) > 0) {59os->print("(%s)", membername);60}61os->cr();62}636465///////////////////////////////////////////////////////////////////////////////66// Implementation for LoadedLibraries6768// class variables69LoadedLibraryModule LoadedLibraries::tab[MAX_MODULES];70int LoadedLibraries::num_loaded = 0;7172// Checks whether the address p points to any of the loaded code segments.73// If it does, returns the LoadedLibraryModule entry. If not, returns NULL.74// static75const LoadedLibraryModule* LoadedLibraries::find_for_text_address(const unsigned char* p) {7677if (num_loaded == 0) {78reload();79}80for (int i = 0; i < num_loaded; i++) {81if (tab[i].is_in_text(p)) {82return &tab[i];83}84}85return NULL;86}8788// Checks whether the address p points to any of the loaded data segments.89// If it does, returns the LoadedLibraryModule entry. If not, returns NULL.90// static91const LoadedLibraryModule* LoadedLibraries::find_for_data_address(const unsigned char* p) {92if (num_loaded == 0) {93reload();94}95for (int i = 0; i < num_loaded; i++) {96if (tab[i].is_in_data(p)) {97return &tab[i];98}99}100return NULL;101}102103// Rebuild the internal table of LoadedLibraryModule objects104// static105void LoadedLibraries::reload() {106107ThreadCritical cs;108109// discard old content110num_loaded = 0;111112// Call loadquery(L_GETINFO..) to get a list of all loaded Dlls from AIX.113size_t buf_size = 4096;114char* loadquery_buf = AllocateHeap(buf_size, mtInternal);115116while(loadquery(L_GETINFO, loadquery_buf, buf_size) == -1) {117if (errno == ENOMEM) {118buf_size *= 2;119loadquery_buf = ReallocateHeap(loadquery_buf, buf_size, mtInternal);120} else {121FreeHeap(loadquery_buf);122// Ensure that the uintptr_t pointer is valid123assert(errno != EFAULT, "loadquery: Invalid uintptr_t in info buffer.");124fprintf(stderr, "loadquery failed (%d %s)", errno, strerror(errno));125return;126}127}128129// Iterate over the loadquery result. For details see sys/ldr.h on AIX.130const struct ld_info* p = (struct ld_info*) loadquery_buf;131132// Ensure we have all loaded libs.133bool all_loaded = false;134while(num_loaded < MAX_MODULES) {135LoadedLibraryModule& mod = tab[num_loaded];136mod.text_from = (const unsigned char*) p->ldinfo_textorg;137mod.text_to = (const unsigned char*) (((char*)p->ldinfo_textorg) + p->ldinfo_textsize);138mod.data_from = (const unsigned char*) p->ldinfo_dataorg;139mod.data_to = (const unsigned char*) (((char*)p->ldinfo_dataorg) + p->ldinfo_datasize);140sprintf(mod.fullpath, "%.*s", sizeof(mod.fullpath), p->ldinfo_filename);141// do we have a member name as well (see ldr.h)?142const char* p_mbr_name = p->ldinfo_filename + strlen(p->ldinfo_filename) + 1;143if (*p_mbr_name) {144sprintf(mod.membername, "%.*s", sizeof(mod.membername), p_mbr_name);145} else {146mod.membername[0] = '\0';147}148149// fill in the short name150const char* p_slash = strrchr(mod.fullpath, '/');151if (p_slash) {152sprintf(mod.shortname, "%.*s", sizeof(mod.shortname), p_slash + 1);153} else {154sprintf(mod.shortname, "%.*s", sizeof(mod.shortname), mod.fullpath);155}156num_loaded ++;157158// next entry...159if (p->ldinfo_next) {160p = (struct ld_info*)(((char*)p) + p->ldinfo_next);161} else {162all_loaded = true;163break;164}165}166167FreeHeap(loadquery_buf);168169// Ensure we have all loaded libs170assert(all_loaded, "loadquery returned more entries then expected. Please increase MAX_MODULES");171172} // end LoadedLibraries::reload()173174175// output loaded libraries table176//static177void LoadedLibraries::print(outputStream* os) {178179for (int i = 0; i < num_loaded; i++) {180tab[i].print(os);181}182183}184185186187