blob: a26b61bf9701954aeac36928e1d3d8109c7c3c0c [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001#include "defs.h"
2
Wichert Akkerman2e2553a1999-05-09 00:29:58 +00003#if defined(LINUX)
4
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00005#include <fcntl.h>
6#include <sys/stat.h>
7#include <sys/time.h>
8#include <sys/wait.h>
9#include <sys/resource.h>
10#include <sys/utsname.h>
11#include <sys/user.h>
12#include <sys/syscall.h>
13#include <signal.h>
14#include <linux/module.h>
15
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000016static struct xlat which[] = {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000017 { 0, "0" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000018 { QM_MODULES, "QM_MODULES" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000019 { QM_DEPS, "QM_DEPS" },
20 { QM_REFS, "QM_REFS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000021 { QM_SYMBOLS, "QM_SYMBOLS" },
Wichert Akkerman9123ac81999-11-27 21:58:20 +000022 { QM_INFO, "QM_INFO" },
23 { 0, NULL },
24};
25
26static struct xlat modflags[] = {
27 { MOD_UNINITIALIZED, "MOD_UNINITIALIZED" },
28 { MOD_RUNNING, "MOD_RUNNING" },
29 { MOD_DELETED, "MOD_DELETED" },
30 { MOD_AUTOCLEAN, "MOD_AUTOCLEAN" },
31 { MOD_VISITED, "MOD_VISITED" },
32 { MOD_USED_ONCE, "MOD_USED_ONCE" },
33 { MOD_JUST_FREED, "MOD_JUST_FREED" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034 { 0, NULL },
35};
36
37int
38sys_query_module(tcp)
39struct tcb *tcp;
40{
41
Wichert Akkerman50524821999-10-10 22:40:07 +000042 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043 printstr(tcp, tcp->u_arg[0], -1);
44 tprintf(", ");
Wichert Akkerman9123ac81999-11-27 21:58:20 +000045 printxval(which, tcp->u_arg[1], "QM_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046 tprintf(", ");
Wichert Akkermanaec62381999-11-28 01:56:12 +000047 if (!verbose(tcp)) {
48 tprintf("%#lx, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
49 } else if (tcp->u_rval!=0) {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000050 size_t ret;
51 umove(tcp, tcp->u_arg[4], &ret);
52 tprintf("%#lx, %lu, %d", tcp->u_arg[2], tcp->u_arg[3], ret);
53 } else if (tcp->u_arg[1]==QM_INFO) {
54 struct module_info mi;
55 size_t ret;
56 umove(tcp, tcp->u_arg[2], &mi);
57 tprintf("{address=%#lx, size=%lu, flags=", mi.addr, mi.size);
58 printflags(modflags, mi.flags);
59 tprintf(", usecount=%lu}", mi.usecount);
60 umove(tcp, tcp->u_arg[4], &ret);
61 tprintf(", %d", ret);
62 } else if ((tcp->u_arg[1]==QM_MODULES) ||
63 (tcp->u_arg[1]==QM_DEPS) ||
64 (tcp->u_arg[1]==QM_REFS)) {
Wichert Akkerman9123ac81999-11-27 21:58:20 +000065 size_t ret;
Wichert Akkerman9123ac81999-11-27 21:58:20 +000066
Wichert Akkerman9123ac81999-11-27 21:58:20 +000067 umove(tcp, tcp->u_arg[4], &ret);
68 tprintf("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +000069 if (!abbrev(tcp)) {
70 char* data = (char*)malloc(tcp->u_arg[3]);
71 char* mod = data;
72 size_t idx;
73
74 umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
75 for (idx=0; idx<ret; idx++) {
76 if (idx!=0)
77 tprintf(",");
78 tprintf(mod);
79 mod+=strlen(mod)+1;
80 }
81 free(data);
82 } else
83 tprintf(" /* %d entries */ ", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +000084 tprintf("}, %d", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +000085 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
Wichert Akkermanaec62381999-11-28 01:56:12 +000086 size_t ret;
87 umove(tcp, tcp->u_arg[4], &ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +000088 tprintf("{");
Wichert Akkermanaec62381999-11-28 01:56:12 +000089 if (!abbrev(tcp)) {
90 char* data = (char *)malloc(tcp->u_arg[3]);
91 struct module_symbol* sym = (struct module_symbol*)data;
92 size_t idx;
93
94 umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data);
95 for (idx=0; idx<ret; idx++) {
96 tprintf("{name=%s, value=%lu} ", data+(long)sym->name, sym->value);
97 sym++;
98 }
99 free(data);
100 } else
101 tprintf(" /* %d entries */ ", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000102 tprintf("}, %d", ret);
Wichert Akkerman9123ac81999-11-27 21:58:20 +0000103 } else {
104 printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
105 tprintf(", %#lx", tcp->u_arg[4]);
106 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000107 }
108 return 0;
109}
110
Wichert Akkerman50524821999-10-10 22:40:07 +0000111int
112sys_create_module(tcp)
113struct tcb *tcp;
114{
115 if (entering(tcp)) {
116 printpath(tcp, tcp->u_arg[0]);
117 tprintf(", %lu", tcp->u_arg[1]);
118 }
119 return RVAL_HEX;
120}
121
Wichert Akkerman2f473da1999-11-01 19:53:31 +0000122int
123sys_init_module(tcp)
124struct tcb *tcp;
125{
126 if (entering(tcp)) {
127 printpath(tcp, tcp->u_arg[0]);
128 tprintf(", %#lx", tcp->u_arg[1]);
129 }
130 return 0;
131}
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000132#endif /* LINUX */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133