]> granicus.if.org Git - strace/blob - bjm.c
Move regs-related macros and declarations from defs.h to regs.h
[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
31 #include "defs.h"
32 #include <fcntl.h>
33 #include <sys/stat.h>
34 #include <sys/wait.h>
35 #include <sys/resource.h>
36 #include <sys/utsname.h>
37
38 /* Bits of module.flags.  */
39
40 #define MOD_UNINITIALIZED       0
41 #define MOD_RUNNING             1
42 #define MOD_DELETED             2
43 #define MOD_AUTOCLEAN           4
44 #define MOD_VISITED             8
45 #define MOD_USED_ONCE           16
46 #define MOD_JUST_FREED          32
47 #define MOD_INITIALIZING        64
48
49 /* Values for query_module's which.  */
50
51 #define QM_MODULES      1
52 #define QM_DEPS         2
53 #define QM_REFS         3
54 #define QM_SYMBOLS      4
55 #define QM_INFO         5
56
57 struct module_symbol
58 {
59         unsigned long value;
60         const char *name;
61 };
62
63 struct module_info
64 {
65         unsigned long addr;
66         unsigned long size;
67         unsigned long flags;
68         long usecount;
69 };
70
71 #include "xlat/qm_which.h"
72 #include "xlat/modflags.h"
73 #include "xlat/delete_module_flags.h"
74
75 int
76 sys_query_module(struct tcb *tcp)
77 {
78         if (entering(tcp)) {
79                 printstr(tcp, tcp->u_arg[0], -1);
80                 tprints(", ");
81                 printxval(qm_which, tcp->u_arg[1], "QM_???");
82                 tprints(", ");
83         } else {
84                 size_t ret;
85
86                 if (!verbose(tcp) || syserror(tcp) ||
87                     umove(tcp, tcp->u_arg[4], &ret) < 0) {
88                         tprintf("%#lx, %lu, %#lx", tcp->u_arg[2],
89                                 tcp->u_arg[3], tcp->u_arg[4]);
90                 } else if (tcp->u_arg[1]==QM_INFO) {
91                         struct module_info      mi;
92                         if (umove(tcp, tcp->u_arg[2], &mi) < 0) {
93                                 tprintf("%#lx, ", tcp->u_arg[2]);
94                         } else {
95                                 tprintf("{address=%#lx, size=%lu, flags=",
96                                         mi.addr, mi.size);
97                                 printflags(modflags, mi.flags, "MOD_???");
98                                 tprintf(", usecount=%lu}, ", mi.usecount);
99                         }
100                         tprintf("%lu", (unsigned long)ret);
101                 } else if ((tcp->u_arg[1]==QM_MODULES) ||
102                            (tcp->u_arg[1]==QM_DEPS) ||
103                            (tcp->u_arg[1]==QM_REFS)) {
104                         tprints("{");
105                         if (!abbrev(tcp)) {
106                                 char*   data    = malloc(tcp->u_arg[3]);
107                                 char*   mod     = data;
108                                 size_t  idx;
109
110                                 if (!data) {
111                                         fprintf(stderr, "out of memory\n");
112                                         tprintf(" /* %lu entries */ ", (unsigned long)ret);
113                                 } else {
114                                         if (umoven(tcp, tcp->u_arg[2],
115                                                 tcp->u_arg[3], data) < 0) {
116                                                 tprintf(" /* %lu entries */ ", (unsigned long)ret);
117                                         } else {
118                                                 for (idx = 0; idx < ret; idx++) {
119                                                         tprintf("%s%s",
120                                                                 (idx ? ", " : ""),
121                                                                 mod);
122                                                         mod += strlen(mod)+1;
123                                                 }
124                                         }
125                                         free(data);
126                                 }
127                         } else
128                                 tprintf(" /* %lu entries */ ", (unsigned long)ret);
129                         tprintf("}, %lu", (unsigned long)ret);
130                 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
131                         tprints("{");
132                         if (!abbrev(tcp)) {
133                                 char*                   data    = malloc(tcp->u_arg[3]);
134                                 struct module_symbol*   sym     = (struct module_symbol*)data;
135                                 size_t                  idx;
136
137                                 if (!data) {
138                                         fprintf(stderr, "out of memory\n");
139                                         tprintf(" /* %lu entries */ ", (unsigned long)ret);
140                                 } else {
141                                         if (umoven(tcp, tcp->u_arg[2],
142                                                 tcp->u_arg[3], data) < 0) {
143                                                 tprintf(" /* %lu entries */ ", (unsigned long)ret);
144                                         } else {
145                                                 for (idx = 0; idx < ret; idx++) {
146                                                         tprintf("%s{name=%s, value=%lu}",
147                                                                 (idx ? " " : ""),
148                                                                 data+(long)sym->name,
149                                                                 sym->value);
150                                                         sym++;
151                                                 }
152                                         }
153                                         free(data);
154                                 }
155                         } else
156                                 tprintf(" /* %lu entries */ ", (unsigned long)ret);
157                         tprintf("}, %ld", (unsigned long)ret);
158                 } else {
159                         printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
160                         tprintf(", %#lx", tcp->u_arg[4]);
161                 }
162         }
163         return 0;
164 }
165
166 int
167 sys_create_module(struct tcb *tcp)
168 {
169         if (entering(tcp)) {
170                 printpath(tcp, tcp->u_arg[0]);
171                 tprintf(", %lu", tcp->u_arg[1]);
172         }
173         return RVAL_HEX;
174 }
175
176 int
177 sys_delete_module(struct tcb *tcp)
178 {
179         if (entering(tcp)) {
180                 printstr(tcp, tcp->u_arg[0], -1);
181                 tprints(", ");
182                 printflags(delete_module_flags, tcp->u_arg[1], "O_???");
183         }
184         return 0;
185 }
186
187 int
188 sys_init_module(struct tcb *tcp)
189 {
190         if (entering(tcp)) {
191                 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
192                 printstr(tcp, tcp->u_arg[2], -1);
193         }
194         return 0;
195 }
196
197 #define MODULE_INIT_IGNORE_MODVERSIONS  1
198 #define MODULE_INIT_IGNORE_VERMAGIC     2
199
200 #include "xlat/module_init_flags.h"
201
202 int
203 sys_finit_module(struct tcb *tcp)
204 {
205         if (exiting(tcp))
206                 return 0;
207
208         /* file descriptor */
209         printfd(tcp, tcp->u_arg[0]);
210         tprints(", ");
211         /* param_values */
212         printstr(tcp, tcp->u_arg[1], -1);
213         tprints(", ");
214         /* flags */
215         printflags(module_init_flags, tcp->u_arg[2], "MODULE_INIT_???");
216
217         return 0;
218 }