Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | #include "defs.h" |
| 33 | |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 34 | #if defined(LINUX) |
| 35 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #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> |
Michal Ludvig | 39c0e94 | 2002-11-06 14:00:12 +0000 | [diff] [blame] | 45 | #include <linux/linkage.h> |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 46 | |
| 47 | /* Bits of module.flags. */ |
| 48 | |
| 49 | #define MOD_UNINITIALIZED 0 |
| 50 | #define MOD_RUNNING 1 |
| 51 | #define MOD_DELETED 2 |
| 52 | #define MOD_AUTOCLEAN 4 |
| 53 | #define MOD_VISITED 8 |
| 54 | #define MOD_USED_ONCE 16 |
| 55 | #define MOD_JUST_FREED 32 |
| 56 | #define MOD_INITIALIZING 64 |
| 57 | |
| 58 | /* Values for query_module's which. */ |
| 59 | |
| 60 | #define QM_MODULES 1 |
| 61 | #define QM_DEPS 2 |
| 62 | #define QM_REFS 3 |
| 63 | #define QM_SYMBOLS 4 |
| 64 | #define QM_INFO 5 |
| 65 | |
| 66 | struct module_symbol |
| 67 | { |
| 68 | unsigned long value; |
| 69 | const char *name; |
| 70 | }; |
| 71 | |
| 72 | struct module_info |
| 73 | { |
| 74 | unsigned long addr; |
| 75 | unsigned long size; |
| 76 | unsigned long flags; |
| 77 | long usecount; |
| 78 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 79 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 80 | static const struct xlat which[] = { |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 81 | { 0, "0" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | { QM_MODULES, "QM_MODULES" }, |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 83 | { QM_DEPS, "QM_DEPS" }, |
| 84 | { QM_REFS, "QM_REFS" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 85 | { QM_SYMBOLS, "QM_SYMBOLS" }, |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 86 | { QM_INFO, "QM_INFO" }, |
| 87 | { 0, NULL }, |
| 88 | }; |
| 89 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 90 | static const struct xlat modflags[] = { |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 91 | { MOD_UNINITIALIZED, "MOD_UNINITIALIZED" }, |
| 92 | { MOD_RUNNING, "MOD_RUNNING" }, |
| 93 | { MOD_DELETED, "MOD_DELETED" }, |
| 94 | { MOD_AUTOCLEAN, "MOD_AUTOCLEAN" }, |
| 95 | { MOD_VISITED, "MOD_VISITED" }, |
| 96 | { MOD_USED_ONCE, "MOD_USED_ONCE" }, |
| 97 | { MOD_JUST_FREED, "MOD_JUST_FREED" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 98 | { 0, NULL }, |
| 99 | }; |
| 100 | |
| 101 | int |
| 102 | sys_query_module(tcp) |
| 103 | struct tcb *tcp; |
| 104 | { |
| 105 | |
Wichert Akkerman | 5052482 | 1999-10-10 22:40:07 +0000 | [diff] [blame] | 106 | if (exiting(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 107 | printstr(tcp, tcp->u_arg[0], -1); |
| 108 | tprintf(", "); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 109 | printxval(which, tcp->u_arg[1], "QM_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 110 | tprintf(", "); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 111 | if (!verbose(tcp)) { |
| 112 | tprintf("%#lx, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]); |
| 113 | } else if (tcp->u_rval!=0) { |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 114 | size_t ret; |
| 115 | umove(tcp, tcp->u_arg[4], &ret); |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 116 | tprintf("%#lx, %lu, %Zu", tcp->u_arg[2], tcp->u_arg[3], ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 117 | } else if (tcp->u_arg[1]==QM_INFO) { |
| 118 | struct module_info mi; |
| 119 | size_t ret; |
| 120 | umove(tcp, tcp->u_arg[2], &mi); |
| 121 | tprintf("{address=%#lx, size=%lu, flags=", mi.addr, mi.size); |
| 122 | printflags(modflags, mi.flags); |
| 123 | tprintf(", usecount=%lu}", mi.usecount); |
| 124 | umove(tcp, tcp->u_arg[4], &ret); |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 125 | tprintf(", %Zu", ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 126 | } else if ((tcp->u_arg[1]==QM_MODULES) || |
| 127 | (tcp->u_arg[1]==QM_DEPS) || |
| 128 | (tcp->u_arg[1]==QM_REFS)) { |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 129 | size_t ret; |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 130 | |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 131 | umove(tcp, tcp->u_arg[4], &ret); |
| 132 | tprintf("{"); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 133 | if (!abbrev(tcp)) { |
| 134 | char* data = (char*)malloc(tcp->u_arg[3]); |
| 135 | char* mod = data; |
| 136 | size_t idx; |
| 137 | |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 138 | if (data==NULL) { |
| 139 | fprintf(stderr, "sys_query_module: No memory\n"); |
| 140 | tprintf(" /* %Zu entries */ ", ret); |
| 141 | } else { |
| 142 | umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data); |
| 143 | for (idx=0; idx<ret; idx++) { |
| 144 | if (idx!=0) |
| 145 | tprintf(","); |
| 146 | tprintf(mod); |
| 147 | mod+=strlen(mod)+1; |
| 148 | } |
| 149 | free(data); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 150 | } |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 151 | } else |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 152 | tprintf(" /* %Zu entries */ ", ret); |
| 153 | tprintf("}, %Zu", ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 154 | } else if (tcp->u_arg[1]==QM_SYMBOLS) { |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 155 | size_t ret; |
| 156 | umove(tcp, tcp->u_arg[4], &ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 157 | tprintf("{"); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 158 | if (!abbrev(tcp)) { |
| 159 | char* data = (char *)malloc(tcp->u_arg[3]); |
| 160 | struct module_symbol* sym = (struct module_symbol*)data; |
| 161 | size_t idx; |
| 162 | |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 163 | if (data==NULL) { |
| 164 | fprintf(stderr, "sys_query_module: No memory\n"); |
| 165 | tprintf(" /* %Zu entries */ ", ret); |
| 166 | } else { |
| 167 | umoven(tcp, tcp->u_arg[2], tcp->u_arg[3], data); |
| 168 | for (idx=0; idx<ret; idx++) { |
| 169 | tprintf("{name=%s, value=%lu} ", data+(long)sym->name, sym->value); |
| 170 | sym++; |
| 171 | } |
| 172 | free(data); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 173 | } |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 174 | } else |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 175 | tprintf(" /* %Zu entries */ ", ret); |
| 176 | tprintf("}, %Zd", ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 177 | } else { |
| 178 | printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
| 179 | tprintf(", %#lx", tcp->u_arg[4]); |
| 180 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 181 | } |
| 182 | return 0; |
| 183 | } |
| 184 | |
Wichert Akkerman | 5052482 | 1999-10-10 22:40:07 +0000 | [diff] [blame] | 185 | int |
| 186 | sys_create_module(tcp) |
| 187 | struct tcb *tcp; |
| 188 | { |
| 189 | if (entering(tcp)) { |
| 190 | printpath(tcp, tcp->u_arg[0]); |
| 191 | tprintf(", %lu", tcp->u_arg[1]); |
| 192 | } |
| 193 | return RVAL_HEX; |
| 194 | } |
| 195 | |
Wichert Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 196 | int |
| 197 | sys_init_module(tcp) |
| 198 | struct tcb *tcp; |
| 199 | { |
| 200 | if (entering(tcp)) { |
| 201 | printpath(tcp, tcp->u_arg[0]); |
| 202 | tprintf(", %#lx", tcp->u_arg[1]); |
| 203 | } |
| 204 | return 0; |
| 205 | } |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 206 | #endif /* LINUX */ |