blob: b34c6ed71ecfae7eee8cea10188b7b2418e576f1 [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
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000072#include "xlat/qm_which.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000073#include "xlat/modflags.h"
Dmitry V. Levind04bb2b2014-06-04 15:51:55 +000074#include "xlat/delete_module_flags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000075
76int
Dmitry V. Levin62e05962009-11-03 14:38:44 +000077sys_query_module(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078{
Dmitry V. Levin62e05962009-11-03 14:38:44 +000079 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080 printstr(tcp, tcp->u_arg[0], -1);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020081 tprints(", ");
Dmitry V. Levin297b5942014-04-25 23:39:20 +000082 printxval(qm_which, tcp->u_arg[1], "QM_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020083 tprints(", ");
Dmitry V. Levin62e05962009-11-03 14:38:44 +000084 } else {
85 size_t ret;
86
87 if (!verbose(tcp) || syserror(tcp) ||
88 umove(tcp, tcp->u_arg[4], &ret) < 0) {
89 tprintf("%#lx, %lu, %#lx", tcp->u_arg[2],
90 tcp->u_arg[3], tcp->u_arg[4]);
Wichert Akkerman9123ac81999-11-27 21:58:20 +000091 } else if (tcp->u_arg[1]==QM_INFO) {
92 struct module_info mi;
Dmitry V. Levin62e05962009-11-03 14:38:44 +000093 if (umove(tcp, tcp->u_arg[2], &mi) < 0) {
94 tprintf("%#lx, ", tcp->u_arg[2]);
95 } else {
96 tprintf("{address=%#lx, size=%lu, flags=",
97 mi.addr, mi.size);
98 printflags(modflags, mi.flags, "MOD_???");
99 tprintf(", usecount=%lu}, ", mi.usecount);
100 }
Denys Vlasenko048cc422012-05-16 12:20:17 +0200101 tprintf("%lu", (unsigned long)ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000102 } else if ((tcp->u_arg[1]==QM_MODULES) ||
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000103 (tcp->u_arg[1]==QM_DEPS) ||
104 (tcp->u_arg[1]==QM_REFS)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200105 tprints("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000106 if (!abbrev(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000107 char* data = malloc(tcp->u_arg[3]);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000108 char* mod = data;
109 size_t idx;
110
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000111 if (!data) {
Roland McGrath46100d02005-06-01 18:55:42 +0000112 fprintf(stderr, "out of memory\n");
Denys Vlasenko048cc422012-05-16 12:20:17 +0200113 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Wichert Akkermanc7926982000-04-10 22:22:31 +0000114 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000115 if (umoven(tcp, tcp->u_arg[2],
116 tcp->u_arg[3], data) < 0) {
Denys Vlasenko048cc422012-05-16 12:20:17 +0200117 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000118 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200119 for (idx = 0; idx < ret; idx++) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000120 tprintf("%s%s",
121 (idx ? ", " : ""),
122 mod);
123 mod += strlen(mod)+1;
124 }
Wichert Akkermanc7926982000-04-10 22:22:31 +0000125 }
126 free(data);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000127 }
Roland McGrathd9f816f2004-09-04 03:39:20 +0000128 } else
Denys Vlasenko048cc422012-05-16 12:20:17 +0200129 tprintf(" /* %lu entries */ ", (unsigned long)ret);
130 tprintf("}, %lu", (unsigned long)ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000131 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200132 tprints("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +0000133 if (!abbrev(tcp)) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000134 char* data = malloc(tcp->u_arg[3]);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000135 struct module_symbol* sym = (struct module_symbol*)data;
136 size_t idx;
137
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000138 if (!data) {
Roland McGrath46100d02005-06-01 18:55:42 +0000139 fprintf(stderr, "out of memory\n");
Denys Vlasenko048cc422012-05-16 12:20:17 +0200140 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Wichert Akkermanc7926982000-04-10 22:22:31 +0000141 } else {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000142 if (umoven(tcp, tcp->u_arg[2],
143 tcp->u_arg[3], data) < 0) {
Denys Vlasenko048cc422012-05-16 12:20:17 +0200144 tprintf(" /* %lu entries */ ", (unsigned long)ret);
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000145 } else {
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200146 for (idx = 0; idx < ret; idx++) {
Dmitry V. Levin62e05962009-11-03 14:38:44 +0000147 tprintf("%s{name=%s, value=%lu}",
148 (idx ? " " : ""),
149 data+(long)sym->name,
150 sym->value);
151 sym++;
152 }
Wichert Akkermanc7926982000-04-10 22:22:31 +0000153 }
154 free(data);
Wichert Akkermanaec62381999-11-28 01:56:12 +0000155 }
Wichert Akkermanaec62381999-11-28 01:56:12 +0000156 } else
Denys Vlasenko048cc422012-05-16 12:20:17 +0200157 tprintf(" /* %lu entries */ ", (unsigned long)ret);
158 tprintf("}, %ld", (unsigned long)ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000159 } else {
160 printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
161 tprintf(", %#lx", tcp->u_arg[4]);
162 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163 }
164 return 0;
165}
166
Wichert Akkerman50524821999-10-10 22:40:07 +0000167int
Denys Vlasenko12014262011-05-30 14:00:14 +0200168sys_create_module(struct tcb *tcp)
Wichert Akkerman50524821999-10-10 22:40:07 +0000169{
170 if (entering(tcp)) {
171 printpath(tcp, tcp->u_arg[0]);
172 tprintf(", %lu", tcp->u_arg[1]);
173 }
174 return RVAL_HEX;
175}
176
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000177int
Dmitry V. Levind04bb2b2014-06-04 15:51:55 +0000178sys_delete_module(struct tcb *tcp)
179{
180 if (entering(tcp)) {
181 printstr(tcp, tcp->u_arg[0], -1);
182 tprints(", ");
183 printflags(delete_module_flags, tcp->u_arg[1], "O_???");
184 }
185 return 0;
186}
187
188int
Denys Vlasenko12014262011-05-30 14:00:14 +0200189sys_init_module(struct tcb *tcp)
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000190{
191 if (entering(tcp)) {
Denys Vlasenko859ea8b2013-02-23 20:07:44 +0100192 tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
Roland McGrath7dbfe572005-08-03 11:27:30 +0000193 printstr(tcp, tcp->u_arg[2], -1);
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000194 }
195 return 0;
196}
Dmitry V. Levinf67502e2014-02-05 16:17:02 +0000197
198#define MODULE_INIT_IGNORE_MODVERSIONS 1
199#define MODULE_INIT_IGNORE_VERMAGIC 2
200
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000201#include "xlat/module_init_flags.h"
Dmitry V. Levinf67502e2014-02-05 16:17:02 +0000202
203int
204sys_finit_module(struct tcb *tcp)
205{
206 if (exiting(tcp))
207 return 0;
208
209 /* file descriptor */
210 printfd(tcp, tcp->u_arg[0]);
211 tprints(", ");
212 /* param_values */
213 printstr(tcp, tcp->u_arg[1], -1);
214 tprints(", ");
215 /* flags */
216 printflags(module_init_flags, tcp->u_arg[2], "MODULE_INIT_???");
217
218 return 0;
219}