1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/aix/vm/loadlib_aix.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,128 @@ 1.4 +/* 1.5 + * Copyright 2012, 2013 SAP AG. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 + 1.29 +// Loadlib_aix.cpp contains support code for analysing the memory 1.30 +// layout of loaded binaries in ones own process space. 1.31 +// 1.32 +// It is needed, among other things, to provide a dladdr() emulation, because 1.33 +// that one is not provided by AIX 1.34 + 1.35 +#ifndef OS_AIX_VM_LOADLIB_AIX_HPP 1.36 +#define OS_AIX_VM_LOADLIB_AIX_HPP 1.37 + 1.38 +class outputStream; 1.39 + 1.40 +// This class holds information about a single loaded library module. 1.41 +// Note that on AIX, a single library can be spread over multiple 1.42 +// uintptr_t range on a module base, eg. 1.43 +// libC.a(shr3_64.o) or libC.a(shrcore_64.o). 1.44 +class LoadedLibraryModule { 1.45 + 1.46 + friend class LoadedLibraries; 1.47 + 1.48 + char fullpath[512]; // eg /usr/lib/libC.a 1.49 + char shortname[30]; // eg libC.a 1.50 + char membername[30]; // eg shrcore_64.o 1.51 + const unsigned char* text_from; 1.52 + const unsigned char* text_to; 1.53 + const unsigned char* data_from; 1.54 + const unsigned char* data_to; 1.55 + 1.56 + public: 1.57 + 1.58 + const char* get_fullpath() const { 1.59 + return fullpath; 1.60 + } 1.61 + const char* get_shortname() const { 1.62 + return shortname; 1.63 + } 1.64 + const char* get_membername() const { 1.65 + return membername; 1.66 + } 1.67 + 1.68 + // text_from, text_to: returns the range of the text (code) 1.69 + // segment for that module 1.70 + const unsigned char* get_text_from() const { 1.71 + return text_from; 1.72 + } 1.73 + const unsigned char* get_text_to() const { 1.74 + return text_to; 1.75 + } 1.76 + 1.77 + // data_from/data_to: returns the range of the data 1.78 + // segment for that module 1.79 + const unsigned char* get_data_from() const { 1.80 + return data_from; 1.81 + } 1.82 + const unsigned char* get_data_to() const { 1.83 + return data_to; 1.84 + } 1.85 + 1.86 + // returns true if the 1.87 + bool is_in_text(const unsigned char* p) const { 1.88 + return p >= text_from && p < text_to ? true : false; 1.89 + } 1.90 + 1.91 + bool is_in_data(const unsigned char* p) const { 1.92 + return p >= data_from && p < data_to ? true : false; 1.93 + } 1.94 + 1.95 + // output debug info 1.96 + void print(outputStream* os) const; 1.97 + 1.98 +}; // end LoadedLibraryModule 1.99 + 1.100 +// This class is a singleton holding a map of all loaded binaries 1.101 +// in the AIX process space. 1.102 +class LoadedLibraries 1.103 +// : AllStatic (including allocation.hpp just for AllStatic is overkill.) 1.104 +{ 1.105 + 1.106 + private: 1.107 + 1.108 + enum {MAX_MODULES = 100}; 1.109 + static LoadedLibraryModule tab[MAX_MODULES]; 1.110 + static int num_loaded; 1.111 + 1.112 + public: 1.113 + 1.114 + // rebuild the internal table of LoadedLibraryModule objects 1.115 + static void reload(); 1.116 + 1.117 + // checks whether the address p points to any of the loaded code segments. 1.118 + // If it does, returns the LoadedLibraryModule entry. If not, returns NULL. 1.119 + static const LoadedLibraryModule* find_for_text_address(const unsigned char* p); 1.120 + 1.121 + // checks whether the address p points to any of the loaded data segments. 1.122 + // If it does, returns the LoadedLibraryModule entry. If not, returns NULL. 1.123 + static const LoadedLibraryModule* find_for_data_address(const unsigned char* p); 1.124 + 1.125 + // output debug info 1.126 + static void print(outputStream* os); 1.127 + 1.128 +}; // end LoadedLibraries 1.129 + 1.130 + 1.131 +#endif // OS_AIX_VM_LOADLIB_AIX_HPP