porting_aix.hpp revision 10061:197538942788
1251881Speter/*
2251881Speter * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
3251881Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4251881Speter *
5251881Speter * This code is free software; you can redistribute it and/or modify it
6251881Speter * under the terms of the GNU General Public License version 2 only, as
7251881Speter * published by the Free Software Foundation.
8251881Speter *
9251881Speter * This code is distributed in the hope that it will be useful, but WITHOUT
10251881Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11251881Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12251881Speter * version 2 for more details (a copy is included in the LICENSE file that
13251881Speter * accompanied this code).
14251881Speter *
15251881Speter * You should have received a copy of the GNU General Public License version
16251881Speter * 2 along with this work; if not, write to the Free Software Foundation,
17251881Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18251881Speter *
19251881Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20251881Speter * or visit www.oracle.com if you need additional information or have any
21251881Speter * questions.
22251881Speter *
23251881Speter */
24251881Speter
25251881Speter#ifndef OS_AIX_VM_PORTING_AIX_HPP
26251881Speter#define OS_AIX_VM_PORTING_AIX_HPP
27251881Speter
28251881Speter#include <stddef.h>
29251881Speter
30251881Speter// Header file to contain porting-relevant code which does not have a
31251881Speter// home anywhere else and which can not go into os_<platform>.h because
32251881Speter// that header is included inside the os class definition, hence all
33251881Speter// its content is part of the os class.
34251881Speter
35251881Speter// Aix' own version of dladdr().
36251881Speter// This function tries to mimick dladdr(3) on Linux
37251881Speter// (see http://linux.die.net/man/3/dladdr)
38251881Speter// dladdr(3) is not POSIX but a GNU extension, and is not available on AIX.
39251881Speter//
40251881Speter// Differences between AIX dladdr and Linux dladdr:
41251881Speter//
42251881Speter// 1) Dl_info.dli_fbase: can never work, is disabled.
43251881Speter//   A loaded image on AIX is divided in multiple segments, at least two
44251881Speter//   (text and data) but potentially also far more. This is because the loader may
45251881Speter//   load each member into an own segment, as for instance happens with the libC.a
46251881Speter// 2) Dl_info.dli_sname: This only works for code symbols (functions); for data, a
47251881Speter//   zero-length string is returned ("").
48251881Speter// 3) Dl_info.dli_saddr: For code, this will return the entry point of the function,
49251881Speter//   not the function descriptor.
50251881Speter
51251881Spetertypedef struct {
52251881Speter  const char *dli_fname; // file path of loaded library
53251881Speter  // void *dli_fbase;
54251881Speter  const char *dli_sname; // symbol name; "" if not known
55251881Speter  void *dli_saddr;       // address of *entry* of function; not function descriptor;
56251881Speter} Dl_info;
57251881Speter
58251881Speter// Note: we export this to use it inside J2se too
59251881Speter#ifdef __cplusplus
60251881Speterextern "C"
61251881Speter#endif
62251881Speterint dladdr(void *addr, Dl_info *info);
63251881Speter
64251881Speterstruct tbtable;
65251881Speter
66251881Speterclass AixSymbols {
67251881Speter public:
68251881Speter
69251881Speter  // Given a program counter, tries to locate the traceback table and returns info from
70251881Speter  // it - e.g. function name, displacement of the pc inside the function, and the traceback
71251881Speter  // table itself.
72251881Speter  static bool get_function_name (
73251881Speter    address pc,                      // [in] program counter
74251881Speter    char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
75251881Speter    int* p_displacement,             // [out] optional: displacement
76251881Speter    const struct tbtable** p_tb,     // [out] optional: ptr to traceback table to get further information
77251881Speter    bool demangle                    // [in] whether to demangle the name
78251881Speter  );
79251881Speter
80251881Speter  // Given a program counter, returns the name of the module (library and module) the pc points to
81251881Speter  static bool get_module_name (
82251881Speter    address pc,                      // [in] program counter
83251881Speter    char* p_name, size_t namelen     // [out] module name
84251881Speter  );
85251881Speter
86251881Speter};
87251881Speter
88251881Speterclass AixNativeCallstack {
89251881Speter public:
90251881Speter  static void print_callstack_for_context(outputStream* st, const ucontext_t* uc,
91251881Speter                                          bool demangle,
92251881Speter                                          char* buf, size_t buf_size);
93251881Speter};
94251881Speter
95251881Speter
96251881Speter#endif // OS_AIX_VM_PORTING_AIX_HPP
97251881Speter
98251881Speter