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