2 * Copyright (c) 1996-2004 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as "Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * This license is for research uses. For such uses, there is no
12 * charge. We define "research use" to mean you may freely use it
13 * inside your organization for whatever purposes you see fit. But you
14 * may not re-distribute Paradyn or parts of Paradyn, in any form
15 * source or binary (including derivatives), electronic or otherwise,
16 * to any other organization or entity without our permission.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
24 * By your use of Paradyn, you understand and agree that we (or any
25 * other person or entity with proprietary rights in Paradyn) are
26 * under no obligation to provide either maintenance services,
27 * update services, notices of latent defects, or correction of
28 * defects for Paradyn.
30 * Even if advised of the possibility of such damages, under no
31 * circumstances shall we (or any other person or entity with
32 * proprietary rights in the software licensed hereunder) be liable
33 * to you or any third party for direct, indirect, or consequential
34 * damages of any character regardless of type of action, including,
35 * without limitation, loss of profits, loss of use, loss of good
36 * will, or computer failure or malfunction. You agree to indemnify
37 * us (and any other person or entity with proprietary rights in the
38 * software licensed hereunder) for any and all liability it may
39 * incur to third parties resulting from your use of Paradyn.
42 /************************************************************************
43 * RTaix.c: mutatee-side library function specific to AIX
44 ************************************************************************/
46 #include "dyninstAPI_RT/h/dyninstAPI_RT.h"
48 #include <dlfcn.h> /* dlopen constants */
53 /************************************************************************
54 * void DYNINSTos_init(void)
56 * os initialization function
57 ************************************************************************/
59 void DYNINSTstaticHeap_1048576_textHeap_libSpace(void);
61 void DYNINSTos_init(int calledByFork, int calledByAttach)
63 /* Text heap initialization. Call this to force the library to
64 be included by the linker */
65 #ifdef USES_LIB_TEXT_HEAP
66 /* Dummy call to get the library space actually included
67 (not pruned by an optimizing linker) */
68 DYNINSTstaticHeap_1048576_textHeap_libSpace();
72 #define NOT_SETUP_ERR 0x2468ace0
74 int DYNINSTloadLibrary(char *libname)
78 gLoadLibraryErrorString[0]='\0';
82 if (NULL == (res = dlopen(libname, RTLD_NOW | RTLD_GLOBAL))) {
83 /* An error has occurred */
84 perror( "DYNINSTloadLibrary -- dlopen" );
86 if (NULL != (err_str = dlerror()))
87 strncpy(gLoadLibraryErrorString, err_str, ERROR_STRING_LENGTH);
89 sprintf(gLoadLibraryErrorString,"unknown error with dlopen");
91 /*fprintf(stderr, "%s[%d]: %s\n", __FILE__, __LINE__,
92 gLoadLibraryErrorString);*/
98 void DYNINST_ThreadPInfo(void* tls, void** stkbase, dyntid_t* tid,
99 long *pc, int* lwp, void** rs)
101 unsigned pthread_context;
103 struct __pthrdsinfo *ptr = (struct __pthrdsinfo *) tls;
104 *stkbase = (void*) (ptr->__pi_stackaddr);
105 /**tid = (int) ptr->__pi_ptid;*/
106 /**lwp = (int) ptr->__pi_tid;*/
107 *rs = &(ptr->__pi_context);
108 /* The PC is a little different. We grab the thread context
109 from a partial pthread structure. That +200 gives us the
110 function pointer to the start function. That gives us the
112 pthread_context = DYNINSTthreadContext();
114 func_ptr = (int *)*((int *)pthread_context);
118 int DYNINSTthreadInfo(BPatch_newThreadEventRecord *ev)
120 struct __pthrdsinfo pthread_desc;
121 int pthread_desc_size = sizeof(struct __pthrdsinfo);
123 int regsize = 1024*sizeof(int);
128 void *stkbase, *rs_p;
132 pthread_t pthread_id;
133 pthread_id = dyn_pthread_self();
135 result = dyn_pthread_getthrds_np(&pthread_id, PTHRDSINFO_QUERY_ALL,
136 &pthread_desc, pthread_desc_size,
137 registers, ®size);
140 if (result != NOT_SETUP_ERR)
141 perror("RTthread-aix:DYNINST_ThreadInfo");
143 fprintf(stderr, "[%s:%u] - TInfo not yet setup\n", __FILE__, __LINE__);
147 DYNINST_ThreadPInfo((void *)&pthread_desc, &stkbase, &tidp, &startpc,
150 ev->stack_addr = stkbase;
151 ev->start_pc = (void *) startpc;
154 fprintf(stderr, "DYNINST_ThreadInfo, stkbase=%x, tid=%d, "
155 "startpc=%x, lwp=%d, resumestate=%x\n",
156 (unsigned) *stkbase, *tidp, *startpc, *lwpid, (unsigned)*rs_p);
169 return thread_self();
177 typedef dyntid_t (*DYNINST_pself_t)(void);
178 typedef int (*DYNINST_pgetthrds_np_t)(pthread_t *, int, struct __pthrdsinfo *,
181 call_record_t DYNINST_pthread_self_record;
182 DYNINST_pself_t DYNINST_pthread_self =
183 (DYNINST_pself_t) &DYNINST_pthread_self_record;
184 dyntid_t dyn_pthread_self()
186 if (!DYNINST_pthread_self_record.func)
190 return (*DYNINST_pthread_self)();
193 call_record_t DYNINST_pthread_getthrds_np_record;
194 DYNINST_pgetthrds_np_t DYNINST_pthread_getthrds_np =
195 (DYNINST_pgetthrds_np_t) &DYNINST_pthread_getthrds_np_record;
196 int dyn_pthread_getthrds_np(pthread_t *thread, int mode,
197 struct __pthrdsinfo *buf, int bufsize,
198 void *regbuf, int *regbufsize)
200 if (!DYNINST_pthread_getthrds_np_record.func)
202 return NOT_SETUP_ERR;
204 return (*DYNINST_pthread_getthrds_np)(thread, mode, buf, bufsize,