aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-12-11 01:42:13 +0000
committerEric Andersen <andersen@codepoet.org>2003-12-11 01:42:13 +0000
commite7047887b040da7035f11d0fe48d76bd67381c9c (patch)
tree4fc4c04847936656adf9d1d3aef35edd1ac5ffe7
parent37f4116ecb03fcf5de2bc8aab8d480b9b063bab5 (diff)
downloadbusybox-w32-e7047887b040da7035f11d0fe48d76bd67381c9c.tar.gz
busybox-w32-e7047887b040da7035f11d0fe48d76bd67381c9c.tar.bz2
busybox-w32-e7047887b040da7035f11d0fe48d76bd67381c9c.zip
Update modutils with 2.6 module support
-rw-r--r--debian/config-udeb-linux-i3864
-rw-r--r--modutils/Config.in36
-rw-r--r--modutils/insmod.c127
-rw-r--r--modutils/rmmod.c11
4 files changed, 140 insertions, 38 deletions
diff --git a/debian/config-udeb-linux-i386 b/debian/config-udeb-linux-i386
index f44000482..678a6a193 100644
--- a/debian/config-udeb-linux-i386
+++ b/debian/config-udeb-linux-i386
@@ -252,8 +252,8 @@ CONFIG_USE_BB_PWD_GRP=y
252CONFIG_MODUTILS_OBJ=y 252CONFIG_MODUTILS_OBJ=y
253CONFIG_DEPMOD=y 253CONFIG_DEPMOD=y
254CONFIG_INSMOD=y 254CONFIG_INSMOD=y
255# CONFIG_FEATURE_OLD_MODULE_INTERFACE is not set 255# CONFIG_FEATURE_2_2_MODULES is not set
256CONFIG_FEATURE_NEW_MODULE_INTERFACE=y 256CONFIG_FEATURE_2_4_MODULES=y
257 257
258# 258#
259# Support new (post 2.1) Linux kernels (Forced enabled) 259# Support new (post 2.1) Linux kernels (Forced enabled)
diff --git a/modutils/Config.in b/modutils/Config.in
index 96040cd69..d9f76d1b4 100644
--- a/modutils/Config.in
+++ b/modutils/Config.in
@@ -11,32 +11,31 @@ config CONFIG_INSMOD
11 help 11 help
12 insmod is used to load specified modules in the running kernel. 12 insmod is used to load specified modules in the running kernel.
13 13
14config CONFIG_FEATURE_OLD_MODULE_INTERFACE 14config CONFIG_FEATURE_2_2_MODULES
15 bool " Support older (pre 2.1) Linux kernels" 15 bool " Support older (pre 2.1) Linux kernels"
16 default n 16 default n
17 depends on CONFIG_INSMOD 17 depends on CONFIG_INSMOD
18 help 18 help
19 Provide insmod support for older (pre 2.1) Linux kernels. 19 Provide insmod support for older (pre 2.1) Linux kernels.
20 20
21if CONFIG_INSMOD && !CONFIG_FEATURE_OLD_MODULE_INTERFACE 21config CONFIG_FEATURE_2_4_MODULES
22 config CONFIG_FEATURE_NEW_MODULE_INTERFACE 22 bool " Support version 2.1.x to 2.4.x Linux kernels"
23 default y
24 comment " Support new (post 2.1) Linux kernels (Forced enabled)"
25endif
26
27if CONFIG_FEATURE_OLD_MODULE_INTERFACE
28config CONFIG_FEATURE_NEW_MODULE_INTERFACE
29 bool " Support new (post 2.1) Linux kernels"
30 default y 23 default y
31 depends on CONFIG_INSMOD 24 depends on CONFIG_INSMOD
32 help 25 help
33 Support module loading for newer (post 2.1) Linux kernels. 26 Support module loading for newer (post 2.1) Linux kernels.
34endif 27
28config CONFIG_FEATURE_2_6_MODULES
29 bool " Support version 2.6.x Linux kernels"
30 default n
31 depends on CONFIG_INSMOD
32 help
33 Support module loading for newer (post 2.1) Linux kernels.
35 34
36config CONFIG_FEATURE_INSMOD_VERSION_CHECKING 35config CONFIG_FEATURE_INSMOD_VERSION_CHECKING
37 bool " Module version checking" 36 bool " Module version checking"
38 default n 37 default n
39 depends on CONFIG_INSMOD 38 depends on CONFIG_INSMOD && ( CONFIG_FEATURE_2_2_MODULES || CONFIG_FEATURE_2_4_MODULES )
40 help 39 help
41 Support checking of versions for modules. This is used to 40 Support checking of versions for modules. This is used to
42 ensure that the kernel and module are made for each other. 41 ensure that the kernel and module are made for each other.
@@ -44,7 +43,7 @@ config CONFIG_FEATURE_INSMOD_VERSION_CHECKING
44config CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS 43config CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
45 bool " Add module symbols to kernel symbol table" 44 bool " Add module symbols to kernel symbol table"
46 default n 45 default n
47 depends on CONFIG_INSMOD 46 depends on CONFIG_INSMOD && ( CONFIG_FEATURE_2_2_MODULES || CONFIG_FEATURE_2_4_MODULES )
48 help 47 help
49 By adding module symbols to the kernel symbol table, Oops messages 48 By adding module symbols to the kernel symbol table, Oops messages
50 occuring within kernel modules can be properly debugged. By enabling 49 occuring within kernel modules can be properly debugged. By enabling
@@ -55,7 +54,7 @@ config CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
55config CONFIG_FEATURE_INSMOD_LOADINKMEM 54config CONFIG_FEATURE_INSMOD_LOADINKMEM
56 bool " In kernel memory optimization (uClinux only)" 55 bool " In kernel memory optimization (uClinux only)"
57 default n 56 default n
58 depends on CONFIG_INSMOD 57 depends on CONFIG_INSMOD && ( CONFIG_FEATURE_2_2_MODULES || CONFIG_FEATURE_2_4_MODULES )
59 help 58 help
60 This is a special uClinux only memory optimization that lets insmod 59 This is a special uClinux only memory optimization that lets insmod
61 load the specified kernel module directly into kernel space, reducing 60 load the specified kernel module directly into kernel space, reducing
@@ -65,7 +64,7 @@ config CONFIG_FEATURE_INSMOD_LOADINKMEM
65config CONFIG_FEATURE_INSMOD_LOAD_MAP 64config CONFIG_FEATURE_INSMOD_LOAD_MAP
66 bool " Enable load map (-m) option" 65 bool " Enable load map (-m) option"
67 default n 66 default n
68 depends on CONFIG_INSMOD 67 depends on CONFIG_INSMOD && ( CONFIG_FEATURE_2_2_MODULES || CONFIG_FEATURE_2_4_MODULES )
69 help 68 help
70 Enabling this, one would be able to get a load map 69 Enabling this, one would be able to get a load map
71 output on stdout. This makes kernel module debugging 70 output on stdout. This makes kernel module debugging
@@ -79,9 +78,8 @@ config CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL
79 depends on CONFIG_FEATURE_INSMOD_LOAD_MAP 78 depends on CONFIG_FEATURE_INSMOD_LOAD_MAP
80 help 79 help
81 Without this option, -m will only output section 80 Without this option, -m will only output section
82 load map. 81 load map. With this option, -m will also output
83 With this option, -m will also output symbols 82 symbols load map.
84 load map.
85 83
86config CONFIG_LSMOD 84config CONFIG_LSMOD
87 bool "lsmod" 85 bool "lsmod"
@@ -92,7 +90,7 @@ config CONFIG_LSMOD
92config CONFIG_FEATURE_QUERY_MODULE_INTERFACE 90config CONFIG_FEATURE_QUERY_MODULE_INTERFACE
93 bool " Support lsmod query_module interface (add 638 bytes)" 91 bool " Support lsmod query_module interface (add 638 bytes)"
94 default y 92 default y
95 depends on CONFIG_LSMOD && CONFIG_FEATURE_NEW_MODULE_INTERFACE 93 depends on CONFIG_LSMOD && ( CONFIG_FEATURE_2_4_MODULES || CONFIG_FEATURE_2_6_MODULES )
96 help 94 help
97 This will provide some extra information about each module when 95 This will provide some extra information about each module when
98 running lsmod. The fields provided are address, size, flags and 96 running lsmod. The fields provided are address, size, flags and
diff --git a/modutils/insmod.c b/modutils/insmod.c
index e2ca64169..979c41f78 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -80,8 +80,24 @@
80#include <sys/utsname.h> 80#include <sys/utsname.h>
81#include "busybox.h" 81#include "busybox.h"
82 82
83#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 83#if !defined(CONFIG_FEATURE_2_4_MODULES) && \
84# undef CONFIG_FEATURE_OLD_MODULE_INTERFACE 84 !defined(CONFIG_FEATURE_2_2_MODULES) && \
85 !defined(CONFIG_FEATURE_2_6_MODULES)
86#define CONFIG_FEATURE_2_4_MODULES
87#endif
88
89#if !defined(CONFIG_FEATURE_2_4_MODULES) && !defined(CONFIG_FEATURE_2_2_MODULES)
90#define insmod_ng_main insmod_main
91#endif
92
93#if defined(CONFIG_FEATURE_2_4_MODULES) || defined(CONFIG_FEATURE_2_2_MODULES)
94
95#if defined(CONFIG_FEATURE_2_6_MODULES)
96extern int insmod_ng_main( int argc, char **argv);
97#endif
98
99#ifdef CONFIG_FEATURE_2_4_MODULES
100# undef CONFIG_FEATURE_2_2_MODULES
85# define new_sys_init_module init_module 101# define new_sys_init_module init_module
86#else 102#else
87# define old_sys_init_module init_module 103# define old_sys_init_module init_module
@@ -266,7 +282,7 @@
266#ifndef MODUTILS_MODULE_H 282#ifndef MODUTILS_MODULE_H
267static const int MODUTILS_MODULE_H = 1; 283static const int MODUTILS_MODULE_H = 1;
268 284
269#ident "$Id: insmod.c,v 1.106 2003/12/04 15:02:57 mjn3 Exp $" 285#ident "$Id: insmod.c,v 1.107 2003/12/11 01:42:13 andersen Exp $"
270 286
271/* This file contains the structures used by the 2.0 and 2.1 kernels. 287/* This file contains the structures used by the 2.0 and 2.1 kernels.
272 We do not use the kernel headers directly because we do not wish 288 We do not use the kernel headers directly because we do not wish
@@ -399,7 +415,7 @@ struct new_module
399 unsigned tgt_long persist_end; 415 unsigned tgt_long persist_end;
400 unsigned tgt_long can_unload; 416 unsigned tgt_long can_unload;
401 unsigned tgt_long runsize; 417 unsigned tgt_long runsize;
402#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 418#ifdef CONFIG_FEATURE_2_4_MODULES
403 const char *kallsyms_start; /* All symbols for kernel debugging */ 419 const char *kallsyms_start; /* All symbols for kernel debugging */
404 const char *kallsyms_end; 420 const char *kallsyms_end;
405 const char *archdata_start; /* arch specific data for module */ 421 const char *archdata_start; /* arch specific data for module */
@@ -487,7 +503,7 @@ int delete_module(const char *);
487#ifndef MODUTILS_OBJ_H 503#ifndef MODUTILS_OBJ_H
488static const int MODUTILS_OBJ_H = 1; 504static const int MODUTILS_OBJ_H = 1;
489 505
490#ident "$Id: insmod.c,v 1.106 2003/12/04 15:02:57 mjn3 Exp $" 506#ident "$Id: insmod.c,v 1.107 2003/12/11 01:42:13 andersen Exp $"
491 507
492/* The relocatable object is manipulated using elfin types. */ 508/* The relocatable object is manipulated using elfin types. */
493 509
@@ -630,7 +646,7 @@ static void *obj_extend_section (struct obj_section *sec, unsigned long more);
630static int obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, 646static int obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
631 const char *string); 647 const char *string);
632 648
633#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 649#ifdef CONFIG_FEATURE_2_4_MODULES
634static int obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, 650static int obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
635 struct obj_symbol *sym); 651 struct obj_symbol *sym);
636#endif 652#endif
@@ -665,7 +681,7 @@ static void arch_create_got (struct obj_file *f);
665 681
666static int obj_gpl_license(struct obj_file *f, const char **license); 682static int obj_gpl_license(struct obj_file *f, const char **license);
667 683
668#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 684#ifdef CONFIG_FEATURE_2_4_MODULES
669static int arch_init_module (struct obj_file *f, struct new_module *); 685static int arch_init_module (struct obj_file *f, struct new_module *);
670#endif 686#endif
671 687
@@ -1626,7 +1642,7 @@ static void arch_create_got(struct obj_file *f)
1626#endif /* defined(CONFIG_USE_GOT_ENTRIES) || defined(CONFIG_USE_PLT_ENTRIES) */ 1642#endif /* defined(CONFIG_USE_GOT_ENTRIES) || defined(CONFIG_USE_PLT_ENTRIES) */
1627} 1643}
1628 1644
1629#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 1645#ifdef CONFIG_FEATURE_2_4_MODULES
1630static int arch_init_module(struct obj_file *f, struct new_module *mod) 1646static int arch_init_module(struct obj_file *f, struct new_module *mod)
1631{ 1647{
1632 return 1; 1648 return 1;
@@ -2224,7 +2240,7 @@ old_get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
2224 2240
2225#endif /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */ 2241#endif /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
2226 2242
2227#ifdef CONFIG_FEATURE_OLD_MODULE_INTERFACE 2243#ifdef CONFIG_FEATURE_2_2_MODULES
2228 2244
2229/* Fetch all the symbols and divvy them up as appropriate for the modules. */ 2245/* Fetch all the symbols and divvy them up as appropriate for the modules. */
2230 2246
@@ -2434,7 +2450,7 @@ old_init_module(const char *m_name, struct obj_file *f,
2434#define old_create_mod_use_count(x) TRUE 2450#define old_create_mod_use_count(x) TRUE
2435#define old_init_module(x, y, z) TRUE 2451#define old_init_module(x, y, z) TRUE
2436 2452
2437#endif /* CONFIG_FEATURE_OLD_MODULE_INTERFACE */ 2453#endif /* CONFIG_FEATURE_2_2_MODULES */
2438 2454
2439 2455
2440 2456
@@ -2720,7 +2736,7 @@ new_get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
2720#endif /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */ 2736#endif /* CONFIG_FEATURE_INSMOD_VERSION_CHECKING */
2721 2737
2722 2738
2723#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 2739#ifdef CONFIG_FEATURE_2_4_MODULES
2724 2740
2725/* Fetch the loaded modules, and all currently exported symbols. */ 2741/* Fetch the loaded modules, and all currently exported symbols. */
2726 2742
@@ -3041,7 +3057,7 @@ new_init_module(const char *m_name, struct obj_file *f,
3041#define new_create_module_ksymtab(x) 3057#define new_create_module_ksymtab(x)
3042#define query_module(v, w, x, y, z) -1 3058#define query_module(v, w, x, y, z) -1
3043 3059
3044#endif /* CONFIG_FEATURE_NEW_MODULE_INTERFACE */ 3060#endif /* CONFIG_FEATURE_2_4_MODULES */
3045 3061
3046 3062
3047/*======================================================================*/ 3063/*======================================================================*/
@@ -3075,7 +3091,7 @@ obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
3075 return 1; 3091 return 1;
3076} 3092}
3077 3093
3078#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 3094#ifdef CONFIG_FEATURE_2_4_MODULES
3079static int 3095static int
3080obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, 3096obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
3081 struct obj_symbol *sym) 3097 struct obj_symbol *sym)
@@ -4161,7 +4177,7 @@ extern int insmod_main( int argc, char **argv)
4161 4177
4162 printf("Using %s\n", m_filename); 4178 printf("Using %s\n", m_filename);
4163 4179
4164#ifdef CONFIG_FEATURE_REALLY_NEW_MODULE_INTERFACE 4180#ifdef CONFIG_FEATURE_2_6_MODULES
4165 if (create_module(NULL, 0) < 0 && errno == ENOSYS) { 4181 if (create_module(NULL, 0) < 0 && errno == ENOSYS) {
4166 optind--; 4182 optind--;
4167 argv[optind] = m_filename; 4183 argv[optind] = m_filename;
@@ -4214,7 +4230,7 @@ extern int insmod_main( int argc, char **argv)
4214 k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL); 4230 k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL);
4215 4231
4216 if (k_new_syscalls) { 4232 if (k_new_syscalls) {
4217#ifdef CONFIG_FEATURE_NEW_MODULE_INTERFACE 4233#ifdef CONFIG_FEATURE_2_4_MODULES
4218 if (!new_get_kernel_symbols()) 4234 if (!new_get_kernel_symbols())
4219 goto out; 4235 goto out;
4220 k_crcs = new_is_kernel_checksummed(); 4236 k_crcs = new_is_kernel_checksummed();
@@ -4223,7 +4239,7 @@ extern int insmod_main( int argc, char **argv)
4223 goto out; 4239 goto out;
4224#endif 4240#endif
4225 } else { 4241 } else {
4226#ifdef CONFIG_FEATURE_OLD_MODULE_INTERFACE 4242#ifdef CONFIG_FEATURE_2_2_MODULES
4227 if (!old_get_kernel_symbols(m_name)) 4243 if (!old_get_kernel_symbols(m_name))
4228 goto out; 4244 goto out;
4229 k_crcs = old_is_kernel_checksummed(); 4245 k_crcs = old_is_kernel_checksummed();
@@ -4345,3 +4361,82 @@ out:
4345#endif 4361#endif
4346 return(exit_status); 4362 return(exit_status);
4347} 4363}
4364
4365
4366#endif
4367
4368
4369#ifdef CONFIG_FEATURE_2_6_MODULES
4370
4371#include <sys/mman.h>
4372#include <asm/unistd.h>
4373#include <sys/syscall.h>
4374
4375/* We use error numbers in a loose translation... */
4376static const char *moderror(int err)
4377{
4378 switch (err) {
4379 case ENOEXEC:
4380 return "Invalid module format";
4381 case ENOENT:
4382 return "Unknown symbol in module";
4383 case ESRCH:
4384 return "Module has wrong symbol version";
4385 case EINVAL:
4386 return "Invalid parameters";
4387 default:
4388 return strerror(err);
4389 }
4390}
4391
4392extern int insmod_ng_main( int argc, char **argv)
4393{
4394 int i;
4395 int fd;
4396 long int ret;
4397 struct stat st;
4398 unsigned long len;
4399 void *map;
4400 char *filename, *options = bb_xstrdup("");
4401
4402 filename = argv[1];
4403 if (!filename) {
4404 bb_show_usage();
4405 return -1;
4406 }
4407
4408 /* Rest is options */
4409 for (i = 2; i < argc; i++) {
4410 options = xrealloc(options, strlen(options) + 2 + strlen(argv[i]) + 2);
4411 /* Spaces handled by "" pairs, but no way of escaping quotes */
4412 if (strchr(argv[i], ' ')) {
4413 strcat(options, "\"");
4414 strcat(options, argv[i]);
4415 strcat(options, "\"");
4416 } else {
4417 strcat(options, argv[i]);
4418 }
4419 strcat(options, " ");
4420 }
4421
4422 if ((fd = open(filename, O_RDONLY, 0)) < 0) {
4423 bb_perror_msg_and_die("cannot open module `%s'", filename);
4424 }
4425
4426 fstat(fd, &st);
4427 len = st.st_size;
4428 map = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
4429 if (map == MAP_FAILED) {
4430 bb_perror_msg_and_die("cannot mmap `%s'", filename);
4431 }
4432
4433 ret = syscall(__NR_init_module, map, len, options);
4434 if (ret != 0) {
4435 bb_perror_msg_and_die("cannot insert `%s': %s (%li)",
4436 filename, moderror(errno), ret);
4437 }
4438
4439 return 0;
4440}
4441
4442#endif
diff --git a/modutils/rmmod.c b/modutils/rmmod.c
index a4ea70410..311b03dc4 100644
--- a/modutils/rmmod.c
+++ b/modutils/rmmod.c
@@ -25,6 +25,8 @@
25#include <unistd.h> 25#include <unistd.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <getopt.h> 27#include <getopt.h>
28#include <fcntl.h>
29#include <sys/syscall.h>
28#include "busybox.h" 30#include "busybox.h"
29 31
30extern int delete_module(const char * name); 32extern int delete_module(const char * name);
@@ -37,10 +39,17 @@ extern int rmmod_main(int argc, char **argv)
37 size_t pnmod = -1; /* previous number of modules */ 39 size_t pnmod = -1; /* previous number of modules */
38 void *buf; /* hold the module names which we ignore but must get */ 40 void *buf; /* hold the module names which we ignore but must get */
39 size_t bufsize = 0; 41 size_t bufsize = 0;
42 unsigned int flags = O_NONBLOCK|O_EXCL;
40 43
41 /* Parse command line. */ 44 /* Parse command line. */
42 while ((n = getopt(argc, argv, "a")) != EOF) { 45 while ((n = getopt(argc, argv, "a")) != EOF) {
43 switch (n) { 46 switch (n) {
47 case 'w': // --wait
48 flags &= ~O_NONBLOCK;
49 break;
50 case 'f': // --force
51 flags |= O_TRUNC;
52 break;
44 case 'a': 53 case 'a':
45 /* Unload _all_ unused modules via NULL delete_module() call */ 54 /* Unload _all_ unused modules via NULL delete_module() call */
46 /* until the number of modules does not change */ 55 /* until the number of modules does not change */
@@ -67,7 +76,7 @@ extern int rmmod_main(int argc, char **argv)
67 bb_show_usage(); 76 bb_show_usage();
68 77
69 for (n = optind; n < argc; n++) { 78 for (n = optind; n < argc; n++) {
70 if (delete_module(argv[n]) < 0) { 79 if (syscall(__NR_delete_module, argv[n], flags) < 0) {
71 bb_perror_msg("%s", argv[n]); 80 bb_perror_msg("%s", argv[n]);
72 ret = EXIT_FAILURE; 81 ret = EXIT_FAILURE;
73 } 82 }