blob: cd7dc13f8061396108f12b60869a986fe5c4aa5b [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.
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +000029 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000030
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010031#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <fcntl.h>
33#include <sys/stat.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034#include <sys/wait.h>
35#include <sys/resource.h>
36#include <sys/utsname.h>
37#include <sys/user.h>
Wichert Akkerman7b3346b2001-10-09 23:47:38 +000038
39/* Bits of module.flags. */
40
41#define MOD_UNINITIALIZED 0
42#define MOD_RUNNING 1
43#define MOD_DELETED 2
44#define MOD_AUTOCLEAN 4
Denys Vlasenkob63256e2011-06-07 12:13:24 +020045#define MOD_VISITED 8
Wichert Akkerman7b3346b2001-10-09 23:47:38 +000046#define MOD_USED_ONCE 16
47#define MOD_JUST_FREED 32
48#define MOD_INITIALIZING 64
49
50/* Values for query_module's which. */
51
52#define QM_MODULES 1
53#define QM_DEPS 2
54#define QM_REFS 3
55#define QM_SYMBOLS 4
56#define QM_INFO 5
57
58struct module_symbol
59{
60 unsigned long value;
61 const char *name;
62};
63
64struct module_info
65{
66 unsigned long addr;
67 unsigned long size;
68 unsigned long flags;
69 long usecount;
70};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071
Roland McGrathd9f816f2004-09-04 03:39:20 +000072static const struct xlat which[] = {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000073 { 0, "0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 { QM_MODULES, "QM_MODULES" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000075 { QM_DEPS, "QM_DEPS" },
76 { QM_REFS, "QM_REFS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077 { QM_SYMBOLS, "QM_SYMBOLS" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000078 { QM_INFO, "QM_INFO" },
79 { 0, NULL },
80};
81
Roland McGrathd9f816f2004-09-04 03:39:20 +000082static const struct xlat modflags[] = {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000083 { MOD_UNINITIALIZED, "MOD_UNINITIALIZED" },
84 { MOD_RUNNING, "MOD_RUNNING" },
85 { MOD_DELETED, "MOD_DELETED" },
86 { MOD_AUTOCLEAN, "MOD_AUTOCLEAN" },
87 { MOD_VISITED, "MOD_VISITED" },
88 { MOD_USED_ONCE, "MOD_USED_ONCE" },
89 { MOD_JUST_FREED, "MOD_JUST_FREED" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090 { 0, NULL },
91};
92
93int
Dmitry V. Levin62e05962009-11-03 14:38:44 +000094sys_query_module(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000095{
Dmitry V. Levin62e05962009-11-03 14:38:44 +000096 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097 printstr(tcp, tcp->u_arg[0], -1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020098 tprints(", ");
Wichert Akkerman9123ac81999-11-27 21:58:20 +000099 printxval(which, tcp->u_arg[1], "QM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200100 tprints(", ");
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000101 } else {
102 size_t ret;
103
104 if (!verbose(tcp) || syserror(tcp) ||
105 umove(tcp, tcp->u_arg[4], &ret) < 0) {
106 tprintf("%#lx, %lu, %#lx", tcp->u_arg[2],
107 tcp->u_arg[3], tcp->u_arg[4]);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000108 } else if (tcp->u_arg[1]==QM_INFO) {
109 struct module_info mi;
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000110 if (umove(tcp, tcp->u_arg[2], &mi) < 0) {
111 tprintf("%#lx, ", tcp->u_arg[2]);
112 } else {
113 tprintf("{address=%#lx, size=%lu, flags=",
114 mi.addr, mi.size);
115 printflags(modflags, mi.flags, "MOD_???");
116 tprintf(", usecount=%lu}, ", mi.usecount);
117 }
Denys Vlasenko048cc422012-05-16 12:20:17 +0200118 tprintf("%lu", (unsigned long)ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000119 } else if ((tcp->u_arg[1]==QM_MODULES) ||
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000120 (tcp->u_arg[1]==QM_DEPS) ||
121 (tcp->u_arg[1]==QM_REFS)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200122 tprints("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000123 if (!abbrev(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000124 char* data = malloc(tcp->u_arg[3]);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000125 char* mod = data;
126 size_t idx;
127
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000128 if (!data) {
Roland McGrath46100d02005-06-01 18:55:42 +0000129 fprintf(stderr, "out of memory\n");
Denys Vlasenko048cc422012-05-16 12:20:17 +0200130 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Wichert Akkermanc7926982000-04-10 22:22:31 +0000131 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000132 if (umoven(tcp, tcp->u_arg[2],
133 tcp->u_arg[3], data) < 0) {
Denys Vlasenko048cc422012-05-16 12:20:17 +0200134 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000135 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200136 for (idx = 0; idx < ret; idx++) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000137 tprintf("%s%s",
138 (idx ? ", " : ""),
139 mod);
140 mod += strlen(mod)+1;
141 }
Wichert Akkermanc7926982000-04-10 22:22:31 +0000142 }
143 free(data);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000144 }
Roland McGrathd9f816f2004-09-04 03:39:20 +0000145 } else
Denys Vlasenko048cc422012-05-16 12:20:17 +0200146 tprintf(" /* %lu entries */ ", (unsigned long)ret);
147 tprintf("}, %lu", (unsigned long)ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000148 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200149 tprints("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000150 if (!abbrev(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000151 char* data = malloc(tcp->u_arg[3]);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000152 struct module_symbol* sym = (struct module_symbol*)data;
153 size_t idx;
154
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000155 if (!data) {
Roland McGrath46100d02005-06-01 18:55:42 +0000156 fprintf(stderr, "out of memory\n");
Denys Vlasenko048cc422012-05-16 12:20:17 +0200157 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Wichert Akkermanc7926982000-04-10 22:22:31 +0000158 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000159 if (umoven(tcp, tcp->u_arg[2],
160 tcp->u_arg[3], data) < 0) {
Denys Vlasenko048cc422012-05-16 12:20:17 +0200161 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000162 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200163 for (idx = 0; idx < ret; idx++) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000164 tprintf("%s{name=%s, value=%lu}",
165 (idx ? " " : ""),
166 data+(long)sym->name,
167 sym->value);
168 sym++;
169 }
Wichert Akkermanc7926982000-04-10 22:22:31 +0000170 }
171 free(data);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000172 }
Wichert Akkermanaec62381999-11-28 01:56:12 +0000173 } else
Denys Vlasenko048cc422012-05-16 12:20:17 +0200174 tprintf(" /* %lu entries */ ", (unsigned long)ret);
175 tprintf("}, %ld", (unsigned long)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
Denys Vlasenko12014262011-05-30 14:00:14 +0200185sys_create_module(struct tcb *tcp)
Wichert Akkerman50524821999-10-10 22:40:07 +0000186{
187 if (entering(tcp)) {
188 printpath(tcp, tcp->u_arg[0]);
189 tprintf(", %lu", tcp->u_arg[1]);
190 }
191 return RVAL_HEX;
192}
193
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000194int
Denys Vlasenko12014262011-05-30 14:00:14 +0200195sys_init_module(struct tcb *tcp)
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000196{
197 if (entering(tcp)) {
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100198 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrath7dbfe572005-08-03 11:27:30 +0000199 printstr(tcp, tcp->u_arg[2], -1);
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000200 }
201 return 0;
202}