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> |
| 45 | #include <linux/module.h> |
| 46 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 47 | static struct xlat which[] = { |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 48 | { 0, "0" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 49 | { QM_MODULES, "QM_MODULES" }, |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 50 | { QM_DEPS, "QM_DEPS" }, |
| 51 | { QM_REFS, "QM_REFS" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 52 | { QM_SYMBOLS, "QM_SYMBOLS" }, |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 53 | { QM_INFO, "QM_INFO" }, |
| 54 | { 0, NULL }, |
| 55 | }; |
| 56 | |
| 57 | static 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 65 | { 0, NULL }, |
| 66 | }; |
| 67 | |
| 68 | int |
| 69 | sys_query_module(tcp) |
| 70 | struct tcb *tcp; |
| 71 | { |
| 72 | |
Wichert Akkerman | 5052482 | 1999-10-10 22:40:07 +0000 | [diff] [blame] | 73 | if (exiting(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | printstr(tcp, tcp->u_arg[0], -1); |
| 75 | tprintf(", "); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 76 | printxval(which, tcp->u_arg[1], "QM_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 77 | tprintf(", "); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 78 | 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 Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 81 | size_t ret; |
| 82 | umove(tcp, tcp->u_arg[4], &ret); |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame^] | 83 | 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] | 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); |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame^] | 92 | tprintf(", %Zu", ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 93 | } else if ((tcp->u_arg[1]==QM_MODULES) || |
| 94 | (tcp->u_arg[1]==QM_DEPS) || |
| 95 | (tcp->u_arg[1]==QM_REFS)) { |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 96 | size_t ret; |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 97 | |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 98 | umove(tcp, tcp->u_arg[4], &ret); |
| 99 | tprintf("{"); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 100 | 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 |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame^] | 114 | tprintf(" /* %Zu entries */ ", ret); |
| 115 | tprintf("}, %Zu", ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 116 | } else if (tcp->u_arg[1]==QM_SYMBOLS) { |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 117 | size_t ret; |
| 118 | umove(tcp, tcp->u_arg[4], &ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 119 | tprintf("{"); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 120 | 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 |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame^] | 132 | tprintf(" /* %Zu entries */ ", ret); |
| 133 | tprintf("}, %Zd", ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 134 | } else { |
| 135 | printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
| 136 | tprintf(", %#lx", tcp->u_arg[4]); |
| 137 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
Wichert Akkerman | 5052482 | 1999-10-10 22:40:07 +0000 | [diff] [blame] | 142 | int |
| 143 | sys_create_module(tcp) |
| 144 | struct 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 Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 153 | int |
| 154 | sys_init_module(tcp) |
| 155 | struct 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 Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 163 | #endif /* LINUX */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 164 | |