diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-12-11 01:42:13 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-12-11 01:42:13 +0000 |
commit | dd4ca727ce71cabfe7ee80ccb2281dedda6a75f0 (patch) | |
tree | 4fc4c04847936656adf9d1d3aef35edd1ac5ffe7 /modutils/insmod.c | |
parent | 173d97e04827d42a7d32d6992ef599fdffbbb56f (diff) | |
download | busybox-w32-dd4ca727ce71cabfe7ee80ccb2281dedda6a75f0.tar.gz busybox-w32-dd4ca727ce71cabfe7ee80ccb2281dedda6a75f0.tar.bz2 busybox-w32-dd4ca727ce71cabfe7ee80ccb2281dedda6a75f0.zip |
Update modutils with 2.6 module support
git-svn-id: svn://busybox.net/trunk/busybox@8068 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'modutils/insmod.c')
-rw-r--r-- | modutils/insmod.c | 127 |
1 files changed, 111 insertions, 16 deletions
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) | ||
96 | extern 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 |
267 | static const int MODUTILS_MODULE_H = 1; | 283 | static 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 |
488 | static const int MODUTILS_OBJ_H = 1; | 504 | static 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); | |||
630 | static int obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, | 646 | static 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 |
634 | static int obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, | 650 | static 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 | ||
666 | static int obj_gpl_license(struct obj_file *f, const char **license); | 682 | static 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 |
669 | static int arch_init_module (struct obj_file *f, struct new_module *); | 685 | static 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 |
1630 | static int arch_init_module(struct obj_file *f, struct new_module *mod) | 1646 | static 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 |
3079 | static int | 3095 | static int |
3080 | obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, | 3096 | obj_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... */ | ||
4376 | static 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 | |||
4392 | extern 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 | ||