aoqi@0: /* aoqi@0: * Copyright 2012, 2013 SAP AG. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include aoqi@0: aoqi@0: // Header file to contain porting-relevant code which does not have a aoqi@0: // home anywhere else and which can not go into os_.h because aoqi@0: // that header is included inside the os class definition, hence all aoqi@0: // its content is part of the os class. aoqi@0: aoqi@0: // Aix' own version of dladdr(). aoqi@0: // This function tries to mimick dladdr(3) on Linux aoqi@0: // (see http://linux.die.net/man/3/dladdr) aoqi@0: // dladdr(3) is not POSIX but a GNU extension, and is not available on AIX. aoqi@0: // aoqi@0: // Differences between AIX dladdr and Linux dladdr: aoqi@0: // aoqi@0: // 1) Dl_info.dli_fbase: can never work, is disabled. aoqi@0: // A loaded image on AIX is divided in multiple segments, at least two aoqi@0: // (text and data) but potentially also far more. This is because the loader may aoqi@0: // load each member into an own segment, as for instance happens with the libC.a aoqi@0: // 2) Dl_info.dli_sname: This only works for code symbols (functions); for data, a aoqi@0: // zero-length string is returned (""). aoqi@0: // 3) Dl_info.dli_saddr: For code, this will return the entry point of the function, aoqi@0: // not the function descriptor. aoqi@0: aoqi@0: typedef struct { aoqi@0: const char *dli_fname; // file path of loaded library aoqi@0: // void *dli_fbase; aoqi@0: const char *dli_sname; // symbol name; "" if not known aoqi@0: void *dli_saddr; // address of *entry* of function; not function descriptor; aoqi@0: } Dl_info; aoqi@0: aoqi@0: // Note: we export this to use it inside J2se too aoqi@0: #ifdef __cplusplus aoqi@0: extern "C" aoqi@0: #endif aoqi@0: int dladdr(void *addr, Dl_info *info); aoqi@0: aoqi@0: aoqi@0: // The semantics in this file are thus that codeptr_t is a *real code ptr*. aoqi@0: // This means that any function taking codeptr_t as arguments will assume aoqi@0: // a real codeptr and won't handle function descriptors (eg getFuncName), aoqi@0: // whereas functions taking address as args will deal with function aoqi@0: // descriptors (eg os::dll_address_to_library_name). aoqi@0: typedef unsigned int* codeptr_t; aoqi@0: aoqi@0: // helper function - given a program counter, tries to locate the traceback table and aoqi@0: // returns info from it (like, most importantly, function name, displacement of the aoqi@0: // pc inside the function, and the traceback table itself. aoqi@0: #ifdef __cplusplus aoqi@0: extern "C" aoqi@0: #endif aoqi@0: int getFuncName( aoqi@0: codeptr_t pc, // [in] program counter aoqi@0: char* p_name, size_t namelen, // [out] optional: user provided buffer for the function name aoqi@0: int* p_displacement, // [out] optional: displacement aoqi@0: const struct tbtable** p_tb, // [out] optional: ptr to traceback table to get further information aoqi@0: char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages aoqi@0: );