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 * $Id: RTsolaris.c,v 1.23 2006/01/13 00:00:48 jodom Exp $
44 * RTsolaris.c: mutatee-side library function specific to Solaris
45 ************************************************************************/
47 #include "dyninstAPI_RT/h/dyninstAPI_RT.h"
50 #include <sys/ucontext.h>
55 #include <sys/procfs.h> /* /proc PIOCUSAGE */
56 #include <fcntl.h> /* O_RDONLY */
57 #include <unistd.h> /* getpid() */
60 #ifdef i386_unknown_solaris2_5
61 void DYNINSTtrapHandler(int sig, siginfo_t *info, ucontext_t *uap);
63 extern struct sigaction DYNINSTactTrap;
64 extern struct sigaction DYNINSTactTrapApp;
67 /************************************************************************
68 * void DYNINSTos_init(void)
70 * OS initialization function
71 ************************************************************************/
73 extern void DYNINSTheap_setbounds(); /* RTheap-solaris.c */
76 DYNINSTos_init(int calledByFork, int calledByAttach)
78 RTprintf("DYNINSTos_init(%d,%d)\n", calledByFork, calledByAttach);
79 DYNINSTheap_setbounds();
80 /* uncomment this if you want instrumentation written out in core files */
84 int DYNINSTloadLibrary(char *libname)
88 gLoadLibraryErrorString[0]='\0';
91 if (NULL == (res = dlopen(libname, RTLD_NOW | RTLD_GLOBAL))) {
92 /* An error has occurred */
93 perror( "DYNINSTloadLibrary -- dlopen" );
95 if (NULL != (err_str = dlerror()))
96 strncpy(gLoadLibraryErrorString, err_str, ERROR_STRING_LENGTH);
98 sprintf(gLoadLibraryErrorString,"unknown error with dlopen");
100 fprintf(stderr, "%s[%d]: %s\n",__FILE__,__LINE__,gLoadLibraryErrorString);
108 We can get Solaris to put instrumented code in the core file of dumped
109 mutatees by setting setting WRITE protection on all pages in the
110 process (SHARED text pages cannot have WRITE protect set).
112 To use, compile and link this code with the runtime library, and call
113 setmemwrite from DYNINSTinit.
116 /* Set every page in this process to be writable to
117 cause pages with instrumented code to be saved in core dumps. */
118 #include <sys/types.h>
119 #include <sys/mman.h>
120 #include <sys/procfs.h>
126 prmap_t pmap[maxpmap];
129 sprintf(buf, "/proc/%05d", getpid());
130 pfd = open(buf, O_RDONLY);
132 perror("open (in setmemwrite)");
133 fprintf(stderr, "Can't open /proc on myself\n");
136 if (0 > ioctl(pfd, PIOCNMAP, &numpmap)) {
137 perror("PIOCNMAP (in setmemwrite)");
140 if (numpmap + 1 > maxpmap) {
141 fprintf(stderr, "Too many memory mappings\n");
144 if (0 > ioctl(pfd, PIOCMAP, pmap)) {
145 perror("PIOCMAP (in setmemwrite)");
148 for (i = 0; i < numpmap; i++) {
149 prmap_t *p = &pmap[i];
150 /* Enable WRITE if this region does not have it already and
151 we won't get in trouble for setting it (i.e., it is not
153 if (~p->pr_mflags & MA_WRITE
154 && ~p->pr_mflags & MA_SHARED)
155 if (0 > mprotect(p->pr_vaddr, p->pr_size,
158 | (p->pr_mflags & MA_EXEC ? PROT_EXEC : 0))) {
159 perror("mprotect (in setmemwrite)");
160 fprintf(stderr, "mprotect (it %d) args: %#010x, %x, %x\n",
162 p->pr_vaddr, p->pr_size,
165 | (p->pr_mflags & MA_EXEC ? PROT_EXEC : 0));
173 int dyn_pthread_self()
178 void DYNINST_initialize_index_list()