]> granicus.if.org Git - strace/blob - bjm.c
update config.guess
[strace] / bjm.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  *      $Id$
31  */
32 #include "defs.h"
33
34 #if defined(LINUX)
35
36 #include <fcntl.h>
37 #include <sys/stat.h>
38 #include <sys/time.h>
39 #include <sys/wait.h>
40 #include <sys/resource.h>
41 #include <sys/utsname.h>
42 #include <sys/user.h>
43 #include <sys/syscall.h>
44 #include <signal.h>
45 #include <linux/module.h>
46
47 static struct xlat which[] = {
48         { 0,            "0"             },
49         { QM_MODULES,   "QM_MODULES"    },
50         { QM_DEPS,      "QM_DEPS"       },
51         { QM_REFS,      "QM_REFS"       },
52         { QM_SYMBOLS,   "QM_SYMBOLS"    },
53         { QM_INFO,      "QM_INFO"       },
54         { 0,            NULL            },
55 };
56
57 static struct xlat modflags[] = {
58         { MOD_UNINITIALIZED,    "MOD_UNINITIALIZED"     },
59         { MOD_RUNNING,          "MOD_RUNNING"           },
60         { MOD_DELETED,          "MOD_DELETED"           },
61         { MOD_AUTOCLEAN,        "MOD_AUTOCLEAN"         },
62         { MOD_VISITED,          "MOD_VISITED"           },
63         { MOD_USED_ONCE,        "MOD_USED_ONCE"         },
64         { MOD_JUST_FREED,       "MOD_JUST_FREED"        },
65         { 0,                    NULL                    },
66 };
67
68 int
69 sys_query_module(tcp)
70 struct tcb *tcp;
71 {
72
73         if (exiting(tcp)) {
74                 printstr(tcp, tcp->u_arg[0], -1);
75                 tprintf(", ");
76                 printxval(which, tcp->u_arg[1], "QM_???");
77                 tprintf(", ");
78                 if (!verbose(tcp)) {
79                         tprintf("%#lx, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
80                 } else if (tcp->u_rval!=0) {
81                         size_t  ret;
82                         umove(tcp, tcp->u_arg[4], &ret);
83                         tprintf("%#lx, %lu, %Zu", tcp->u_arg[2], tcp->u_arg[3], ret);
84                 } else if (tcp->u_arg[1]==QM_INFO) {
85                         struct module_info      mi;
86                         size_t                  ret;
87                         umove(tcp, tcp->u_arg[2], &mi);
88                         tprintf("{address=%#lx, size=%lu, flags=", mi.addr, mi.size);
89                         printflags(modflags, mi.flags);
90                         tprintf(", usecount=%lu}", mi.usecount);
91                         umove(tcp, tcp->u_arg[4], &ret);
92                         tprintf(", %Zu", ret);
93                 } else if ((tcp->u_arg[1]==QM_MODULES) ||
94                                 (tcp->u_arg[1]==QM_DEPS) ||
95                                 (tcp->u_arg[1]==QM_REFS)) {
96                         size_t  ret;
97
98                         umove(tcp, tcp->u_arg[4], &ret);
99                         tprintf("{");
100                         if (!abbrev(tcp)) {
101                                 char*   data    = (char*)malloc(tcp->u_arg[3]);
102                                 char*   mod     = data;
103                                 size_t  idx;
104
105                                 if (data==NULL) {
106                                         fprintf(stderr, "sys_query_module: No memory\n");
107                                         tprintf(" /* %Zu entries */ ", ret);
108                                 } else {
109                                         umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
110                                         for (idx=0; idx<ret; idx++) {
111                                                 if (idx!=0)
112                                                         tprintf(",");
113                                                 tprintf(mod);
114                                                 mod+=strlen(mod)+1;
115                                         }
116                                         free(data);
117                                 }
118                         } else 
119                                 tprintf(" /* %Zu entries */ ", ret);
120                         tprintf("}, %Zu", ret);
121                 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
122                         size_t  ret;
123                         umove(tcp, tcp->u_arg[4], &ret);
124                         tprintf("{");
125                         if (!abbrev(tcp)) {
126                                 char*                   data    = (char *)malloc(tcp->u_arg[3]);
127                                 struct module_symbol*   sym     = (struct module_symbol*)data;
128                                 size_t                  idx;
129
130                                 if (data==NULL) {
131                                         fprintf(stderr, "sys_query_module: No memory\n");
132                                         tprintf(" /* %Zu entries */ ", ret);
133                                 } else {
134                                         umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
135                                         for (idx=0; idx<ret; idx++) {
136                                                 tprintf("{name=%s, value=%lu} ", data+(long)sym->name, sym->value);
137                                                 sym++;
138                                         }
139                                         free(data);
140                                 }
141                         } else
142                                 tprintf(" /* %Zu entries */ ", ret);
143                         tprintf("}, %Zd", ret);
144                 } else {
145                         printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
146                         tprintf(", %#lx", tcp->u_arg[4]);
147                 }
148         }
149         return 0;
150 }
151
152 int
153 sys_create_module(tcp)
154 struct tcb *tcp;
155 {
156         if (entering(tcp)) {
157                 printpath(tcp, tcp->u_arg[0]);
158                 tprintf(", %lu", tcp->u_arg[1]);
159         }
160         return RVAL_HEX;
161 }
162
163 int
164 sys_init_module(tcp)
165 struct tcb *tcp;
166 {
167         if (entering(tcp)) {
168                 printpath(tcp, tcp->u_arg[0]);
169                 tprintf(", %#lx", tcp->u_arg[1]);
170         }
171         return 0;
172 }
173 #endif /* LINUX */
174