blob: 5947a4192d7b66d990df83dfed8078c7663f5775 [file] [log] [blame]
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00001/*
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 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include "defs.h"
33
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000034#if defined(LINUX)
35
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036#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>
Wichert Akkerman7b3346b2001-10-09 23:47:38 +000045
46/* Bits of module.flags. */
47
48#define MOD_UNINITIALIZED 0
49#define MOD_RUNNING 1
50#define MOD_DELETED 2
51#define MOD_AUTOCLEAN 4
52#define MOD_VISITED 8
53#define MOD_USED_ONCE 16
54#define MOD_JUST_FREED 32
55#define MOD_INITIALIZING 64
56
57/* Values for query_module's which. */
58
59#define QM_MODULES 1
60#define QM_DEPS 2
61#define QM_REFS 3
62#define QM_SYMBOLS 4
63#define QM_INFO 5
64
65struct module_symbol
66{
67 unsigned long value;
68 const char *name;
69};
70
71struct module_info
72{
73 unsigned long addr;
74 unsigned long size;
75 unsigned long flags;
76 long usecount;
77};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078
Roland McGrathd9f816f2004-09-04 03:39:20 +000079static const struct xlat which[] = {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000080 { 0, "0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081 { QM_MODULES, "QM_MODULES" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000082 { QM_DEPS, "QM_DEPS" },
83 { QM_REFS, "QM_REFS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 { QM_SYMBOLS, "QM_SYMBOLS" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000085 { QM_INFO, "QM_INFO" },
86 { 0, NULL },
87};
88
Roland McGrathd9f816f2004-09-04 03:39:20 +000089static const struct xlat modflags[] = {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000090 { MOD_UNINITIALIZED, "MOD_UNINITIALIZED" },
91 { MOD_RUNNING, "MOD_RUNNING" },
92 { MOD_DELETED, "MOD_DELETED" },
93 { MOD_AUTOCLEAN, "MOD_AUTOCLEAN" },
94 { MOD_VISITED, "MOD_VISITED" },
95 { MOD_USED_ONCE, "MOD_USED_ONCE" },
96 { MOD_JUST_FREED, "MOD_JUST_FREED" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097 { 0, NULL },
98};
99
100int
101sys_query_module(tcp)
102struct tcb *tcp;
103{
104
Wichert Akkerman50524821999-10-10 22:40:07 +0000105 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106 printstr(tcp, tcp->u_arg[0], -1);
107 tprintf(", ");
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000108 printxval(which, tcp->u_arg[1], "QM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000109 tprintf(", ");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000110 if (!verbose(tcp)) {
111 tprintf("%#lx, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
112 } else if (tcp->u_rval!=0) {
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000113 size_t ret;
114 umove(tcp, tcp->u_arg[4], &ret);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000115 tprintf("%#lx, %lu, %Zu", tcp->u_arg[2], tcp->u_arg[3], ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000116 } else if (tcp->u_arg[1]==QM_INFO) {
117 struct module_info mi;
118 size_t ret;
119 umove(tcp, tcp->u_arg[2], &mi);
120 tprintf("{address=%#lx, size=%lu, flags=", mi.addr, mi.size);
Roland McGrathb2dee132005-06-01 19:02:36 +0000121 printflags(modflags, mi.flags, "MOD_???");
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000122 tprintf(", usecount=%lu}", mi.usecount);
123 umove(tcp, tcp->u_arg[4], &ret);
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000124 tprintf(", %Zu", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000125 } else if ((tcp->u_arg[1]==QM_MODULES) ||
126 (tcp->u_arg[1]==QM_DEPS) ||
127 (tcp->u_arg[1]==QM_REFS)) {
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000128 size_t ret;
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000129
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000130 umove(tcp, tcp->u_arg[4], &ret);
131 tprintf("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000132 if (!abbrev(tcp)) {
133 char* data = (char*)malloc(tcp->u_arg[3]);
134 char* mod = data;
135 size_t idx;
136
Wichert Akkermanc7926982000-04-10 22:22:31 +0000137 if (data==NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +0000138 fprintf(stderr, "out of memory\n");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000139 tprintf(" /* %Zu entries */ ", ret);
140 } else {
141 umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
142 for (idx=0; idx<ret; idx++) {
143 if (idx!=0)
144 tprintf(",");
145 tprintf(mod);
146 mod+=strlen(mod)+1;
147 }
148 free(data);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000149 }
Roland McGrathd9f816f2004-09-04 03:39:20 +0000150 } else
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000151 tprintf(" /* %Zu entries */ ", ret);
152 tprintf("}, %Zu", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000153 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
Wichert Akkermanaec62381999-11-28 01:56:12 +0000154 size_t ret;
155 umove(tcp, tcp->u_arg[4], &ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000156 tprintf("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000157 if (!abbrev(tcp)) {
158 char* data = (char *)malloc(tcp->u_arg[3]);
159 struct module_symbol* sym = (struct module_symbol*)data;
160 size_t idx;
161
Wichert Akkermanc7926982000-04-10 22:22:31 +0000162 if (data==NULL) {
Roland McGrath46100d02005-06-01 18:55:42 +0000163 fprintf(stderr, "out of memory\n");
Wichert Akkermanc7926982000-04-10 22:22:31 +0000164 tprintf(" /* %Zu entries */ ", ret);
165 } else {
166 umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
167 for (idx=0; idx<ret; idx++) {
168 tprintf("{name=%s, value=%lu} ", data+(long)sym->name, sym->value);
169 sym++;
170 }
171 free(data);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000172 }
Wichert Akkermanaec62381999-11-28 01:56:12 +0000173 } else
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000174 tprintf(" /* %Zu entries */ ", ret);
175 tprintf("}, %Zd", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000176 } else {
177 printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
178 tprintf(", %#lx", tcp->u_arg[4]);
179 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000180 }
181 return 0;
182}
183
Wichert Akkerman50524821999-10-10 22:40:07 +0000184int
185sys_create_module(tcp)
186struct tcb *tcp;
187{
188 if (entering(tcp)) {
189 printpath(tcp, tcp->u_arg[0]);
190 tprintf(", %lu", tcp->u_arg[1]);
191 }
192 return RVAL_HEX;
193}
194
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000195int
196sys_init_module(tcp)
197struct tcb *tcp;
198{
199 if (entering(tcp)) {
Roland McGrath7dbfe572005-08-03 11:27:30 +0000200 tprintf("%#lx, ", tcp->u_arg[0]);
201 tprintf("%lu, ", tcp->u_arg[1]);
202 printstr(tcp, tcp->u_arg[2], -1);
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000203 }
204 return 0;
205}
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000206#endif /* LINUX */