blob: 8583bc068fb3d052bf09d4e5c134b0c76028f49b [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>
45#include <linux/module.h>
46
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047static struct xlat which[] = {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000048 { 0, "0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049 { QM_MODULES, "QM_MODULES" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000050 { QM_DEPS, "QM_DEPS" },
51 { QM_REFS, "QM_REFS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052 { QM_SYMBOLS, "QM_SYMBOLS" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000053 { QM_INFO, "QM_INFO" },
54 { 0, NULL },
55};
56
57static 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" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065 { 0, NULL },
66};
67
68int
69sys_query_module(tcp)
70struct tcb *tcp;
71{
72
Wichert Akkerman50524821999-10-10 22:40:07 +000073 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 printstr(tcp, tcp->u_arg[0], -1);
75 tprintf(", ");
Wichert Akkerman9123ac81999-11-27 21:58:20 +000076 printxval(which, tcp->u_arg[1], "QM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077 tprintf(", ");
Wichert Akkermanaec62381999-11-28 01:56:12 +000078 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) {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000081 size_t ret;
82 umove(tcp, tcp->u_arg[4], &ret);
83 tprintf("%#lx, %lu, %d", 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(", %d", ret);
93 } else if ((tcp->u_arg[1]==QM_MODULES) ||
94 (tcp->u_arg[1]==QM_DEPS) ||
95 (tcp->u_arg[1]==QM_REFS)) {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000096 size_t ret;
Wichert Akkerman9123ac81999-11-27 21:58:20 +000097
Wichert Akkerman9123ac81999-11-27 21:58:20 +000098 umove(tcp, tcp->u_arg[4], &ret);
99 tprintf("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000100 if (!abbrev(tcp)) {
101 char* data = (char*)malloc(tcp->u_arg[3]);
102 char* mod = data;
103 size_t idx;
104
105 umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
106 for (idx=0; idx<ret; idx++) {
107 if (idx!=0)
108 tprintf(",");
109 tprintf(mod);
110 mod+=strlen(mod)+1;
111 }
112 free(data);
113 } else
114 tprintf(" /* %d entries */ ", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000115 tprintf("}, %d", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000116 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
Wichert Akkermanaec62381999-11-28 01:56:12 +0000117 size_t ret;
118 umove(tcp, tcp->u_arg[4], &ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000119 tprintf("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000120 if (!abbrev(tcp)) {
121 char* data = (char *)malloc(tcp->u_arg[3]);
122 struct module_symbol* sym = (struct module_symbol*)data;
123 size_t idx;
124
125 umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
126 for (idx=0; idx<ret; idx++) {
127 tprintf("{name=%s, value=%lu} ", data+(long)sym->name, sym->value);
128 sym++;
129 }
130 free(data);
131 } else
132 tprintf(" /* %d entries */ ", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000133 tprintf("}, %d", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000134 } else {
135 printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
136 tprintf(", %#lx", tcp->u_arg[4]);
137 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138 }
139 return 0;
140}
141
Wichert Akkerman50524821999-10-10 22:40:07 +0000142int
143sys_create_module(tcp)
144struct tcb *tcp;
145{
146 if (entering(tcp)) {
147 printpath(tcp, tcp->u_arg[0]);
148 tprintf(", %lu", tcp->u_arg[1]);
149 }
150 return RVAL_HEX;
151}
152
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000153int
154sys_init_module(tcp)
155struct tcb *tcp;
156{
157 if (entering(tcp)) {
158 printpath(tcp, tcp->u_arg[0]);
159 tprintf(", %#lx", tcp->u_arg[1]);
160 }
161 return 0;
162}
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000163#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164