loadlib_aix.hpp revision 5969:666e6ce3976c
1/*
2 * Copyright 2012, 2013 SAP AG. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25
26// Loadlib_aix.cpp contains support code for analysing the memory
27// layout of loaded binaries in ones own process space.
28//
29// It is needed, among other things, to provide a  dladdr() emulation, because
30// that one is not provided by AIX
31
32#ifndef OS_AIX_VM_LOADLIB_AIX_HPP
33#define OS_AIX_VM_LOADLIB_AIX_HPP
34
35class outputStream;
36
37// This class holds information about a single loaded library module.
38// Note that on AIX, a single library can be spread over multiple
39// uintptr_t range on a module base, eg.
40// libC.a(shr3_64.o) or libC.a(shrcore_64.o).
41class LoadedLibraryModule {
42
43    friend class LoadedLibraries;
44
45    char fullpath[512];  // eg /usr/lib/libC.a
46    char shortname[30];  // eg libC.a
47    char membername[30]; // eg shrcore_64.o
48    const unsigned char* text_from;
49    const unsigned char* text_to;
50    const unsigned char* data_from;
51    const unsigned char* data_to;
52
53  public:
54
55    const char* get_fullpath() const {
56      return fullpath;
57    }
58    const char* get_shortname() const {
59      return shortname;
60    }
61    const char* get_membername() const {
62      return membername;
63    }
64
65    // text_from, text_to: returns the range of the text (code)
66    // segment for that module
67    const unsigned char* get_text_from() const {
68      return text_from;
69    }
70    const unsigned char* get_text_to() const {
71      return text_to;
72    }
73
74    // data_from/data_to: returns the range of the data
75    // segment for that module
76    const unsigned char* get_data_from() const {
77      return data_from;
78    }
79    const unsigned char* get_data_to() const {
80      return data_to;
81    }
82
83    // returns true if the
84    bool is_in_text(const unsigned char* p) const {
85      return p >= text_from && p < text_to ? true : false;
86    }
87
88    bool is_in_data(const unsigned char* p) const {
89      return p >= data_from && p < data_to ? true : false;
90    }
91
92    // output debug info
93    void print(outputStream* os) const;
94
95}; // end LoadedLibraryModule
96
97// This class is a singleton holding a map of all loaded binaries
98// in the AIX process space.
99class LoadedLibraries
100// : AllStatic (including allocation.hpp just for AllStatic is overkill.)
101{
102
103  private:
104
105    enum {MAX_MODULES = 100};
106    static LoadedLibraryModule tab[MAX_MODULES];
107    static int num_loaded;
108
109  public:
110
111    // rebuild the internal table of LoadedLibraryModule objects
112    static void reload();
113
114    // checks whether the address p points to any of the loaded code segments.
115    // If it does, returns the LoadedLibraryModule entry. If not, returns NULL.
116    static const LoadedLibraryModule* find_for_text_address(const  unsigned char* p);
117
118    // checks whether the address p points to any of the loaded data segments.
119    // If it does, returns the LoadedLibraryModule entry. If not, returns NULL.
120    static const LoadedLibraryModule* find_for_data_address(const  unsigned char* p);
121
122    // output debug info
123    static void print(outputStream* os);
124
125}; // end LoadedLibraries
126
127
128#endif // OS_AIX_VM_LOADLIB_AIX_HPP
129