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. |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 29 | */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 30 | |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 31 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | #include <fcntl.h> |
| 33 | #include <sys/stat.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 34 | #include <sys/wait.h> |
| 35 | #include <sys/resource.h> |
| 36 | #include <sys/utsname.h> |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 37 | |
| 38 | /* Bits of module.flags. */ |
| 39 | |
| 40 | #define MOD_UNINITIALIZED 0 |
| 41 | #define MOD_RUNNING 1 |
| 42 | #define MOD_DELETED 2 |
| 43 | #define MOD_AUTOCLEAN 4 |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 44 | #define MOD_VISITED 8 |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 45 | #define MOD_USED_ONCE 16 |
| 46 | #define MOD_JUST_FREED 32 |
| 47 | #define MOD_INITIALIZING 64 |
| 48 | |
| 49 | /* Values for query_module's which. */ |
| 50 | |
| 51 | #define QM_MODULES 1 |
| 52 | #define QM_DEPS 2 |
| 53 | #define QM_REFS 3 |
| 54 | #define QM_SYMBOLS 4 |
| 55 | #define QM_INFO 5 |
| 56 | |
| 57 | struct module_symbol |
| 58 | { |
| 59 | unsigned long value; |
| 60 | const char *name; |
| 61 | }; |
| 62 | |
| 63 | struct module_info |
| 64 | { |
| 65 | unsigned long addr; |
| 66 | unsigned long size; |
| 67 | unsigned long flags; |
| 68 | long usecount; |
| 69 | }; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 70 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 71 | #include "xlat/qm_which.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 72 | #include "xlat/modflags.h" |
Dmitry V. Levin | d04bb2b | 2014-06-04 15:51:55 +0000 | [diff] [blame] | 73 | #include "xlat/delete_module_flags.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 75 | SYS_FUNC(query_module) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 76 | { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 77 | if (entering(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 78 | printstr(tcp, tcp->u_arg[0], -1); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 79 | tprints(", "); |
Dmitry V. Levin | 297b594 | 2014-04-25 23:39:20 +0000 | [diff] [blame] | 80 | printxval(qm_which, tcp->u_arg[1], "QM_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 81 | tprints(", "); |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 82 | } else { |
| 83 | size_t ret; |
| 84 | |
| 85 | if (!verbose(tcp) || syserror(tcp) || |
| 86 | umove(tcp, tcp->u_arg[4], &ret) < 0) { |
| 87 | tprintf("%#lx, %lu, %#lx", tcp->u_arg[2], |
| 88 | tcp->u_arg[3], tcp->u_arg[4]); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 89 | } else if (tcp->u_arg[1]==QM_INFO) { |
| 90 | struct module_info mi; |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 91 | if (umove(tcp, tcp->u_arg[2], &mi) < 0) { |
| 92 | tprintf("%#lx, ", tcp->u_arg[2]); |
| 93 | } else { |
| 94 | tprintf("{address=%#lx, size=%lu, flags=", |
| 95 | mi.addr, mi.size); |
| 96 | printflags(modflags, mi.flags, "MOD_???"); |
| 97 | tprintf(", usecount=%lu}, ", mi.usecount); |
| 98 | } |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 99 | tprintf("%lu", (unsigned long)ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 100 | } else if ((tcp->u_arg[1]==QM_MODULES) || |
Dmitry V. Levin | 414fe7d | 2009-07-08 11:21:17 +0000 | [diff] [blame] | 101 | (tcp->u_arg[1]==QM_DEPS) || |
| 102 | (tcp->u_arg[1]==QM_REFS)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 103 | tprints("{"); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 104 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 105 | char* data = malloc(tcp->u_arg[3]); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 106 | char* mod = data; |
| 107 | size_t idx; |
| 108 | |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 109 | if (!data) { |
Dmitry V. Levin | df38991 | 2015-05-25 23:33:31 +0300 | [diff] [blame] | 110 | error_msg("Out of memory"); |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 111 | tprintf(" /* %lu entries */ ", (unsigned long)ret); |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 112 | } else { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 113 | if (umoven(tcp, tcp->u_arg[2], |
| 114 | tcp->u_arg[3], data) < 0) { |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 115 | tprintf(" /* %lu entries */ ", (unsigned long)ret); |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 116 | } else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 117 | for (idx = 0; idx < ret; idx++) { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 118 | tprintf("%s%s", |
| 119 | (idx ? ", " : ""), |
| 120 | mod); |
| 121 | mod += strlen(mod)+1; |
| 122 | } |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 123 | } |
| 124 | free(data); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 125 | } |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 126 | } else |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 127 | tprintf(" /* %lu entries */ ", (unsigned long)ret); |
| 128 | tprintf("}, %lu", (unsigned long)ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 129 | } else if (tcp->u_arg[1]==QM_SYMBOLS) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 130 | tprints("{"); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 131 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 132 | char* data = malloc(tcp->u_arg[3]); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 133 | struct module_symbol* sym = (struct module_symbol*)data; |
| 134 | size_t idx; |
| 135 | |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 136 | if (!data) { |
Dmitry V. Levin | df38991 | 2015-05-25 23:33:31 +0300 | [diff] [blame] | 137 | error_msg("Out of memory"); |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 138 | tprintf(" /* %lu entries */ ", (unsigned long)ret); |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 139 | } else { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 140 | if (umoven(tcp, tcp->u_arg[2], |
| 141 | tcp->u_arg[3], data) < 0) { |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 142 | tprintf(" /* %lu entries */ ", (unsigned long)ret); |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 143 | } else { |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 144 | for (idx = 0; idx < ret; idx++) { |
Dmitry V. Levin | 62e0596 | 2009-11-03 14:38:44 +0000 | [diff] [blame] | 145 | tprintf("%s{name=%s, value=%lu}", |
| 146 | (idx ? " " : ""), |
| 147 | data+(long)sym->name, |
| 148 | sym->value); |
| 149 | sym++; |
| 150 | } |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 151 | } |
| 152 | free(data); |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 153 | } |
Wichert Akkerman | aec6238 | 1999-11-28 01:56:12 +0000 | [diff] [blame] | 154 | } else |
Denys Vlasenko | 048cc42 | 2012-05-16 12:20:17 +0200 | [diff] [blame] | 155 | tprintf(" /* %lu entries */ ", (unsigned long)ret); |
| 156 | tprintf("}, %ld", (unsigned long)ret); |
Wichert Akkerman | 9123ac8 | 1999-11-27 21:58:20 +0000 | [diff] [blame] | 157 | } else { |
| 158 | printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]); |
| 159 | tprintf(", %#lx", tcp->u_arg[4]); |
| 160 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 161 | } |
| 162 | return 0; |
| 163 | } |
| 164 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 165 | SYS_FUNC(create_module) |
Wichert Akkerman | 5052482 | 1999-10-10 22:40:07 +0000 | [diff] [blame] | 166 | { |
Dmitry V. Levin | d9e8792 | 2015-07-20 19:35:42 +0000 | [diff] [blame] | 167 | printpath(tcp, tcp->u_arg[0]); |
| 168 | tprintf(", %lu", tcp->u_arg[1]); |
| 169 | |
| 170 | return RVAL_DECODED | RVAL_HEX; |
Wichert Akkerman | 5052482 | 1999-10-10 22:40:07 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 173 | SYS_FUNC(delete_module) |
Dmitry V. Levin | d04bb2b | 2014-06-04 15:51:55 +0000 | [diff] [blame] | 174 | { |
Dmitry V. Levin | d9e8792 | 2015-07-20 19:35:42 +0000 | [diff] [blame] | 175 | printstr(tcp, tcp->u_arg[0], -1); |
| 176 | tprints(", "); |
| 177 | printflags(delete_module_flags, tcp->u_arg[1], "O_???"); |
| 178 | |
| 179 | return RVAL_DECODED; |
Dmitry V. Levin | d04bb2b | 2014-06-04 15:51:55 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 182 | SYS_FUNC(init_module) |
Wichert Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 183 | { |
Dmitry V. Levin | d9e8792 | 2015-07-20 19:35:42 +0000 | [diff] [blame] | 184 | tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 185 | printstr(tcp, tcp->u_arg[2], -1); |
| 186 | |
| 187 | return RVAL_DECODED; |
Wichert Akkerman | 2f473da | 1999-11-01 19:53:31 +0000 | [diff] [blame] | 188 | } |
Dmitry V. Levin | f67502e | 2014-02-05 16:17:02 +0000 | [diff] [blame] | 189 | |
| 190 | #define MODULE_INIT_IGNORE_MODVERSIONS 1 |
| 191 | #define MODULE_INIT_IGNORE_VERMAGIC 2 |
| 192 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 193 | #include "xlat/module_init_flags.h" |
Dmitry V. Levin | f67502e | 2014-02-05 16:17:02 +0000 | [diff] [blame] | 194 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 195 | SYS_FUNC(finit_module) |
Dmitry V. Levin | f67502e | 2014-02-05 16:17:02 +0000 | [diff] [blame] | 196 | { |
Dmitry V. Levin | f67502e | 2014-02-05 16:17:02 +0000 | [diff] [blame] | 197 | /* file descriptor */ |
| 198 | printfd(tcp, tcp->u_arg[0]); |
| 199 | tprints(", "); |
| 200 | /* param_values */ |
| 201 | printstr(tcp, tcp->u_arg[1], -1); |
| 202 | tprints(", "); |
| 203 | /* flags */ |
| 204 | printflags(module_init_flags, tcp->u_arg[2], "MODULE_INIT_???"); |
| 205 | |
Dmitry V. Levin | d9e8792 | 2015-07-20 19:35:42 +0000 | [diff] [blame] | 206 | return RVAL_DECODED; |
Dmitry V. Levin | f67502e | 2014-02-05 16:17:02 +0000 | [diff] [blame] | 207 | } |