2008-08-20 14:00:34 +00:00
|
|
|
--- a/modutils/insmod.c
|
|
|
|
+++ b/modutils/insmod.c
|
2007-11-10 16:51:11 +00:00
|
|
|
@@ -61,21 +61,117 @@
|
2007-10-05 00:27:49 +00:00
|
|
|
#include "libbb.h"
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
+#if ENABLE_FEATURE_2_6_MODULES
|
|
|
|
+#include <sys/mman.h>
|
|
|
|
+#include <asm/unistd.h>
|
|
|
|
+#include <sys/syscall.h>
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
#if !ENABLE_FEATURE_2_4_MODULES && !ENABLE_FEATURE_2_6_MODULES
|
|
|
|
#undef ENABLE_FEATURE_2_4_MODULES
|
|
|
|
#define ENABLE_FEATURE_2_4_MODULES 1
|
|
|
|
#endif
|
|
|
|
|
2007-11-10 16:51:11 +00:00
|
|
|
-/*
|
|
|
|
- * Big piece of 2.4-specific code
|
|
|
|
- */
|
|
|
|
#if ENABLE_FEATURE_2_4_MODULES
|
2007-10-05 00:27:49 +00:00
|
|
|
-
|
2007-11-10 16:51:11 +00:00
|
|
|
+int insmod_main_24(int argc, char **argv);
|
|
|
|
+#endif
|
2007-10-05 00:27:49 +00:00
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
2007-11-10 16:51:11 +00:00
|
|
|
-static int insmod_ng_main(int argc, char **argv);
|
2007-10-05 00:27:49 +00:00
|
|
|
+int insmod_main_26(int argc, char **argv);
|
2008-08-20 14:00:34 +00:00
|
|
|
#endif
|
2007-11-10 16:51:11 +00:00
|
|
|
+int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-08-20 14:00:34 +00:00
|
|
|
|
2007-10-05 00:27:49 +00:00
|
|
|
+static char *g_filename = NULL;
|
|
|
|
+#define _PATH_MODULES "/lib/modules"
|
|
|
|
+
|
|
|
|
+static int check_module_name_match(const char *filename, struct stat *statbuf,
|
|
|
|
+ void *userdata, int depth)
|
|
|
|
+{
|
|
|
|
+ char *fullname = (char *) userdata;
|
2007-11-10 16:51:11 +00:00
|
|
|
+ char *tmp;
|
2007-10-05 00:27:49 +00:00
|
|
|
+
|
|
|
|
+ if (fullname[0] == '\0')
|
|
|
|
+ return FALSE;
|
2007-11-10 16:51:11 +00:00
|
|
|
+
|
|
|
|
+ tmp = bb_get_last_path_component_nostrip(filename);
|
|
|
|
+ if (strcmp(tmp, fullname) == 0) {
|
|
|
|
+ /* Stop searching if we find a match */
|
|
|
|
+ g_filename = xstrdup(filename);
|
|
|
|
+ return FALSE;
|
2007-10-05 00:27:49 +00:00
|
|
|
+ }
|
2007-11-10 16:51:11 +00:00
|
|
|
+
|
2007-10-05 00:27:49 +00:00
|
|
|
+ return TRUE;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int find_module(char *filename)
|
|
|
|
+{
|
|
|
|
+ char *module_dir, real_module_dir[FILENAME_MAX];
|
|
|
|
+ int len, slen, ret = ENOENT, k_version;
|
|
|
|
+ struct utsname myuname;
|
|
|
|
+ const char *suffix;
|
|
|
|
+ struct stat st;
|
|
|
|
+
|
|
|
|
+ /* check the kernel version */
|
|
|
|
+ if ((uname(&myuname) != 0) || (myuname.release[0] != '2'))
|
|
|
|
+ return EINVAL;
|
|
|
|
+
|
|
|
|
+ k_version = myuname.release[2] - '0';
|
|
|
|
+#if ENABLE_FEATURE_2_4_MODULES
|
|
|
|
+ if (k_version <= 4)
|
|
|
|
+ suffix = ".o";
|
|
|
|
+ else
|
2008-08-20 14:00:34 +00:00
|
|
|
+#endif
|
2007-10-05 00:27:49 +00:00
|
|
|
+ suffix = ".ko";
|
|
|
|
+
|
|
|
|
+ len = strlen(filename);
|
|
|
|
+ slen = strlen(suffix);
|
|
|
|
+
|
|
|
|
+ /* check for suffix and absolute path first */
|
|
|
|
+ if ((len < slen + 2) || (strcmp(filename + len - slen, suffix) != 0)) {
|
|
|
|
+ filename = xasprintf("%s%s", filename, suffix);
|
|
|
|
+ } else {
|
|
|
|
+ filename = strdup(filename);
|
2007-10-24 16:43:25 +00:00
|
|
|
+ if ((stat(filename, &st) == 0) && S_ISREG(st.st_mode)) {
|
|
|
|
+ g_filename = filename;
|
2007-10-05 00:27:49 +00:00
|
|
|
+ return 0;
|
2007-10-24 16:43:25 +00:00
|
|
|
+ }
|
|
|
|
+ free(filename);
|
|
|
|
+ return ENOENT;
|
2007-10-05 00:27:49 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* next: scan /lib/modules/<release> */
|
|
|
|
+ /* Jump through hoops in case /lib/modules/`uname -r`
|
|
|
|
+ * is a symlink. We do not want recursive_action to
|
|
|
|
+ * follow symlinks, but we do want to follow the
|
|
|
|
+ * /lib/modules/`uname -r` dir, So resolve it ourselves
|
|
|
|
+ * if it is a link... */
|
|
|
|
+ module_dir = concat_path_file(_PATH_MODULES, myuname.release);
|
|
|
|
+ if (realpath(module_dir, real_module_dir) != NULL) {
|
|
|
|
+ free(module_dir);
|
|
|
|
+ module_dir = real_module_dir;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ recursive_action(module_dir, ACTION_RECURSE,
|
|
|
|
+ check_module_name_match, 0, filename, 0);
|
|
|
|
+
|
|
|
|
+ /* Check if we have a complete path */
|
2007-10-08 20:31:17 +00:00
|
|
|
+ if (g_filename == NULL)
|
|
|
|
+ goto done;
|
|
|
|
+
|
|
|
|
+ if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode))
|
|
|
|
+ ret = 0;
|
|
|
|
+ else
|
|
|
|
+ free(g_filename);
|
2008-08-20 14:00:34 +00:00
|
|
|
+
|
2007-10-08 20:31:17 +00:00
|
|
|
+done:
|
2007-10-05 00:27:49 +00:00
|
|
|
+ free(filename);
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
2007-11-10 16:51:11 +00:00
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * Big piece of 2.4-specific code
|
|
|
|
+ */
|
|
|
|
+#if ENABLE_FEATURE_2_4_MODULES
|
|
|
|
#if ENABLE_FEATURE_INSMOD_LOADINKMEM
|
|
|
|
#define LOADBITS 0
|
|
|
|
#else
|
2008-08-20 14:00:34 +00:00
|
|
|
@@ -184,7 +280,6 @@
|
|
|
|
/* Microblaze */
|
|
|
|
#if defined(__microblaze__)
|
|
|
|
#define USE_SINGLE
|
|
|
|
-#include <linux/elf-em.h>
|
|
|
|
#define MATCH_MACHINE(x) (x == EM_XILINX_MICROBLAZE)
|
|
|
|
#define SHT_RELM SHT_RELA
|
|
|
|
#define Elf32_RelM Elf32_Rela
|
|
|
|
@@ -452,7 +547,7 @@
|
|
|
|
/* The system calls unchanged between 2.0 and 2.1. */
|
|
|
|
|
|
|
|
unsigned long create_module(const char *, size_t);
|
|
|
|
-int delete_module(const char *module, unsigned int flags);
|
|
|
|
+int delete_module(const char *);
|
2007-10-05 00:27:49 +00:00
|
|
|
|
|
|
|
|
2008-08-20 14:00:34 +00:00
|
|
|
#endif /* module.h */
|
|
|
|
@@ -652,7 +747,7 @@
|
|
|
|
|
|
|
|
static enum obj_reloc arch_apply_relocation(struct obj_file *f,
|
|
|
|
struct obj_section *targsec,
|
|
|
|
- /*struct obj_section *symsec,*/
|
|
|
|
+ struct obj_section *symsec,
|
|
|
|
struct obj_symbol *sym,
|
|
|
|
ElfW(RelM) *rel, ElfW(Addr) value);
|
|
|
|
|
|
|
|
@@ -673,6 +768,7 @@
|
|
|
|
#define SPFX ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+
|
2007-10-05 00:27:49 +00:00
|
|
|
enum { STRVERSIONLEN = 64 };
|
|
|
|
|
|
|
|
/*======================================================================*/
|
2008-08-20 14:00:34 +00:00
|
|
|
@@ -788,28 +884,6 @@
|
2007-11-10 16:51:11 +00:00
|
|
|
static char *m_fullName;
|
|
|
|
|
2007-10-05 00:27:49 +00:00
|
|
|
|
|
|
|
-/*======================================================================*/
|
|
|
|
-
|
|
|
|
-
|
2008-08-20 14:00:34 +00:00
|
|
|
-static int check_module_name_match(const char *filename,
|
|
|
|
- struct stat *statbuf ATTRIBUTE_UNUSED,
|
|
|
|
- void *userdata, int depth ATTRIBUTE_UNUSED)
|
2007-10-05 00:27:49 +00:00
|
|
|
-{
|
|
|
|
- char *fullname = (char *) userdata;
|
2007-11-10 16:51:11 +00:00
|
|
|
- char *tmp;
|
2007-10-05 00:27:49 +00:00
|
|
|
-
|
|
|
|
- if (fullname[0] == '\0')
|
|
|
|
- return FALSE;
|
2007-11-10 16:51:11 +00:00
|
|
|
-
|
|
|
|
- tmp = bb_get_last_path_component_nostrip(filename);
|
|
|
|
- if (strcmp(tmp, fullname) == 0) {
|
|
|
|
- /* Stop searching if we find a match */
|
|
|
|
- m_filename = xstrdup(filename);
|
|
|
|
- return FALSE;
|
2007-10-05 00:27:49 +00:00
|
|
|
- }
|
|
|
|
- return TRUE;
|
|
|
|
-}
|
|
|
|
-
|
2007-11-10 16:51:11 +00:00
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -835,32 +909,20 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
static enum obj_reloc
|
|
|
|
arch_apply_relocation(struct obj_file *f,
|
|
|
|
struct obj_section *targsec,
|
|
|
|
- /*struct obj_section *symsec,*/
|
|
|
|
+ struct obj_section *symsec,
|
|
|
|
struct obj_symbol *sym,
|
|
|
|
ElfW(RelM) *rel, ElfW(Addr) v)
|
|
|
|
{
|
|
|
|
-#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) \
|
2008-09-22 12:36:13 +00:00
|
|
|
- || defined(__sh__) || defined(__s390__) || defined(__x86_64__) \
|
|
|
|
- || defined(__powerpc__) || defined(__mips__)
|
2008-08-20 14:00:34 +00:00
|
|
|
struct arch_file *ifile = (struct arch_file *) f;
|
|
|
|
-#endif
|
|
|
|
enum obj_reloc ret = obj_reloc_ok;
|
|
|
|
ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset);
|
|
|
|
-#if defined(__arm__) || defined(__H8300H__) || defined(__H8300S__) \
|
|
|
|
- || defined(__i386__) || defined(__mc68000__) || defined(__microblaze__) \
|
|
|
|
- || defined(__mips__) || defined(__nios2__) || defined(__powerpc__) \
|
|
|
|
- || defined(__s390__) || defined(__sh__) || defined(__x86_64__)
|
|
|
|
ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset;
|
|
|
|
-#endif
|
|
|
|
#if defined(USE_GOT_ENTRIES) || defined(USE_PLT_ENTRIES)
|
|
|
|
struct arch_symbol *isym = (struct arch_symbol *) sym;
|
|
|
|
#endif
|
|
|
|
-#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) \
|
|
|
|
- || defined(__sh__) || defined(__s390__)
|
|
|
|
#if defined(USE_GOT_ENTRIES)
|
|
|
|
ElfW(Addr) got = ifile->got ? ifile->got->header.sh_addr : 0;
|
|
|
|
#endif
|
2008-09-22 12:36:13 +00:00
|
|
|
-#endif
|
|
|
|
#if defined(USE_PLT_ENTRIES)
|
|
|
|
ElfW(Addr) plt = ifile->plt ? ifile->plt->header.sh_addr : 0;
|
|
|
|
unsigned long *ip;
|
|
|
|
@@ -954,7 +1016,6 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
|
|
|
|
case R_386_PLT32:
|
|
|
|
case R_386_PC32:
|
|
|
|
- case R_386_GOTOFF:
|
|
|
|
*loc += v - dot;
|
|
|
|
break;
|
|
|
|
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -973,6 +1034,9 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
|
|
|
|
case R_386_GOT32:
|
|
|
|
goto bb_use_got;
|
|
|
|
+
|
|
|
|
+ case R_386_GOTOFF:
|
|
|
|
+ *loc += v - got;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#elif defined(__microblaze__)
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -1759,7 +1823,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
|
|
|
|
#if defined(USE_SINGLE)
|
|
|
|
|
|
|
|
-static int arch_single_init(/*ElfW(RelM) *rel,*/ struct arch_single_entry *single,
|
|
|
|
+static int arch_single_init(ElfW(RelM) *rel, struct arch_single_entry *single,
|
|
|
|
int offset, int size)
|
|
|
|
{
|
|
|
|
if (single->allocated == 0) {
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -1907,7 +1971,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
#if defined(USE_GOT_ENTRIES)
|
|
|
|
if (got_allocate) {
|
|
|
|
got_offset += arch_single_init(
|
|
|
|
- /*rel,*/ &intsym->gotent,
|
|
|
|
+ rel, &intsym->gotent,
|
|
|
|
got_offset, GOT_ENTRY_SIZE);
|
|
|
|
|
|
|
|
got_needed = 1;
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -1921,7 +1985,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
plt_offset, PLT_ENTRY_SIZE);
|
|
|
|
#else
|
|
|
|
plt_offset += arch_single_init(
|
|
|
|
- /*rel,*/ &intsym->pltent,
|
|
|
|
+ rel, &intsym->pltent,
|
|
|
|
plt_offset, PLT_ENTRY_SIZE);
|
|
|
|
#endif
|
|
|
|
plt_needed = 1;
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -1959,8 +2023,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
while (n > 0) {
|
|
|
|
ch = *name++;
|
|
|
|
h = (h << 4) + ch;
|
|
|
|
- g = (h & 0xf0000000);
|
|
|
|
- if (g != 0) {
|
|
|
|
+ if ((g = (h & 0xf0000000)) != 0) {
|
|
|
|
h ^= g >> 24;
|
|
|
|
h &= ~g;
|
|
|
|
}
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -2039,7 +2102,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
int n_type = ELF_ST_TYPE(info);
|
|
|
|
int n_binding = ELF_ST_BIND(info);
|
|
|
|
|
|
|
|
- for (sym = f->symtab[hash]; sym; sym = sym->next) {
|
|
|
|
+ for (sym = f->symtab[hash]; sym; sym = sym->next)
|
|
|
|
if (f->symbol_cmp(sym->name, name) == 0) {
|
|
|
|
int o_secidx = sym->secidx;
|
|
|
|
int o_info = sym->info;
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -2098,14 +2161,14 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- }
|
|
|
|
|
|
|
|
/* Completely new symbol. */
|
|
|
|
sym = arch_new_symbol();
|
|
|
|
sym->next = f->symtab[hash];
|
|
|
|
f->symtab[hash] = sym;
|
|
|
|
sym->ksymidx = -1;
|
|
|
|
- if (ELF_ST_BIND(info) == STB_LOCAL && symidx != (unsigned long)(-1)) {
|
|
|
|
+
|
|
|
|
+ if (ELF_ST_BIND(info) == STB_LOCAL && symidx != -1) {
|
|
|
|
if (symidx >= f->local_symtab_size)
|
|
|
|
bb_error_msg("local symbol %s with index %ld exceeds local_symtab_size %ld",
|
|
|
|
name, (long) symidx, (long) f->local_symtab_size);
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -3228,7 +3291,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
|
|
|
|
/* Do it! */
|
|
|
|
switch (arch_apply_relocation
|
|
|
|
- (f, targsec, /*symsec,*/ intsym, rel, value)
|
|
|
|
+ (f, targsec, symsec, intsym, rel, value)
|
|
|
|
) {
|
|
|
|
case obj_reloc_ok:
|
|
|
|
break;
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -3307,11 +3370,11 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
|
|
|
|
/*======================================================================*/
|
|
|
|
|
|
|
|
-static struct obj_file *obj_load(FILE * fp, int loadprogbits ATTRIBUTE_UNUSED)
|
|
|
|
+static struct obj_file *obj_load(FILE * fp, int loadprogbits)
|
|
|
|
{
|
|
|
|
struct obj_file *f;
|
|
|
|
ElfW(Shdr) * section_headers;
|
|
|
|
- size_t shnum, i;
|
|
|
|
+ int shnum, i;
|
|
|
|
char *shstrtab;
|
|
|
|
|
|
|
|
/* Read the file header. */
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -3583,7 +3646,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
while (ptr < endptr) {
|
|
|
|
value = strchr(ptr, '=');
|
|
|
|
if (value && strncmp(ptr, "license", value-ptr) == 0) {
|
|
|
|
- unsigned i;
|
|
|
|
+ int i;
|
|
|
|
if (license)
|
|
|
|
*license = value+1;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(gpl_licenses); ++i) {
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -3687,9 +3750,6 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
* start of some sections. this info is used by ksymoops to do better
|
|
|
|
* debugging.
|
|
|
|
*/
|
|
|
|
-#if !ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
|
|
|
-#define get_module_version(f, str) get_module_version(str)
|
|
|
|
-#endif
|
|
|
|
static int
|
|
|
|
get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
|
|
|
|
{
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -3722,8 +3782,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
struct obj_symbol *sym;
|
|
|
|
char *name, *absolute_filename;
|
|
|
|
char str[STRVERSIONLEN];
|
|
|
|
- unsigned i;
|
|
|
|
- int l, lm_name, lfilename, use_ksymtab, version;
|
|
|
|
+ int i, l, lm_name, lfilename, use_ksymtab, version;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
/* WARNING: was using realpath, but replaced by readlink to stop using
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -3910,145 +3969,57 @@
|
2007-10-05 00:27:49 +00:00
|
|
|
void print_load_map(struct obj_file *f);
|
|
|
|
#endif
|
|
|
|
|
2007-11-10 16:51:11 +00:00
|
|
|
-int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
-int insmod_main(int argc, char **argv)
|
2007-10-05 00:27:49 +00:00
|
|
|
+int insmod_main_24( int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *opt_o, *arg1;
|
2007-10-05 13:05:22 +00:00
|
|
|
- int len;
|
2007-10-05 00:27:49 +00:00
|
|
|
int k_crcs;
|
|
|
|
- char *tmp, *tmp1;
|
|
|
|
unsigned long m_size;
|
|
|
|
ElfW(Addr) m_addr;
|
|
|
|
struct obj_file *f;
|
2007-10-05 13:05:22 +00:00
|
|
|
- struct stat st;
|
2007-11-10 16:51:11 +00:00
|
|
|
- char *m_name = NULL;
|
2007-10-05 00:27:49 +00:00
|
|
|
- int exit_status = EXIT_FAILURE;
|
2007-10-05 20:09:55 +00:00
|
|
|
+ char *tmp = NULL, *m_name = NULL;
|
2007-10-05 00:27:49 +00:00
|
|
|
+ int ret = EINVAL;
|
|
|
|
int m_has_modinfo;
|
|
|
|
#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
|
|
|
|
struct utsname uts_info;
|
|
|
|
char m_strversion[STRVERSIONLEN];
|
|
|
|
int m_version, m_crcs;
|
|
|
|
#endif
|
|
|
|
-#if ENABLE_FEATURE_CLEAN_UP
|
2007-11-10 16:51:11 +00:00
|
|
|
FILE *fp = NULL;
|
2007-10-05 00:27:49 +00:00
|
|
|
-#else
|
|
|
|
- FILE *fp;
|
|
|
|
-#endif
|
|
|
|
- int k_version = 0;
|
|
|
|
+ int k_version;
|
|
|
|
struct utsname myuname;
|
|
|
|
|
|
|
|
+ /* check the kernel version */
|
|
|
|
+ if ((uname(&myuname) != 0) || (myuname.release[0] != '2'))
|
|
|
|
+ return EINVAL;
|
|
|
|
+
|
|
|
|
+ k_version = myuname.release[2] - '0';
|
|
|
|
+ if (k_version > 4)
|
|
|
|
+ return ENOTSUP;
|
|
|
|
+
|
|
|
|
/* Parse any options */
|
|
|
|
getopt32(argv, OPTION_STR, &opt_o);
|
|
|
|
arg1 = argv[optind];
|
2007-10-05 20:09:55 +00:00
|
|
|
if (option_mask32 & OPT_o) { // -o /* name the output module */
|
|
|
|
- free(m_name);
|
2007-10-05 00:27:49 +00:00
|
|
|
m_name = xstrdup(opt_o);
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (arg1 == NULL) {
|
|
|
|
+ if (arg1 == NULL)
|
|
|
|
bb_show_usage();
|
|
|
|
- }
|
2008-09-22 12:36:13 +00:00
|
|
|
|
2007-10-05 00:27:49 +00:00
|
|
|
- /* Grab the module name */
|
|
|
|
- tmp1 = xstrdup(arg1);
|
|
|
|
- tmp = basename(tmp1);
|
|
|
|
- len = strlen(tmp);
|
|
|
|
-
|
|
|
|
- if (uname(&myuname) == 0) {
|
|
|
|
- if (myuname.release[0] == '2') {
|
|
|
|
- k_version = myuname.release[2] - '0';
|
|
|
|
- }
|
|
|
|
- }
|
2007-10-08 20:31:17 +00:00
|
|
|
-
|
2007-10-05 00:27:49 +00:00
|
|
|
-#if ENABLE_FEATURE_2_6_MODULES
|
|
|
|
- if (k_version > 4 && len > 3 && tmp[len - 3] == '.'
|
|
|
|
- && tmp[len - 2] == 'k' && tmp[len - 1] == 'o'
|
|
|
|
- ) {
|
|
|
|
- len -= 3;
|
|
|
|
- tmp[len] = '\0';
|
|
|
|
- } else
|
|
|
|
-#endif
|
|
|
|
- if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') {
|
|
|
|
- len -= 2;
|
|
|
|
- tmp[len] = '\0';
|
|
|
|
- }
|
2008-09-22 12:36:13 +00:00
|
|
|
-
|
2007-11-10 16:51:11 +00:00
|
|
|
-
|
2007-10-05 00:27:49 +00:00
|
|
|
-#if ENABLE_FEATURE_2_6_MODULES
|
|
|
|
- if (k_version > 4)
|
|
|
|
- m_fullName = xasprintf("%s.ko", tmp);
|
|
|
|
- else
|
|
|
|
-#endif
|
|
|
|
- m_fullName = xasprintf("%s.o", tmp);
|
2007-10-05 20:09:55 +00:00
|
|
|
+ ret = find_module(arg1);
|
|
|
|
+ if (ret)
|
|
|
|
+ goto out;
|
2007-10-05 00:27:49 +00:00
|
|
|
|
2007-10-05 20:09:55 +00:00
|
|
|
if (!m_name) {
|
2007-10-05 00:27:49 +00:00
|
|
|
- m_name = tmp;
|
|
|
|
- } else {
|
|
|
|
- free(tmp1);
|
2007-11-10 16:51:11 +00:00
|
|
|
- tmp1 = NULL; /* flag for free(m_name) before exit() */
|
2008-08-20 14:00:34 +00:00
|
|
|
- }
|
|
|
|
-
|
2007-11-10 16:51:11 +00:00
|
|
|
- /* Get a filedesc for the module. Check that we have a complete path */
|
2007-10-05 00:27:49 +00:00
|
|
|
- if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode)
|
|
|
|
- || (fp = fopen(arg1, "r")) == NULL
|
|
|
|
- ) {
|
|
|
|
- /* Hmm. Could not open it. First search under /lib/modules/`uname -r`,
|
|
|
|
- * but do not error out yet if we fail to find it... */
|
|
|
|
- if (k_version) { /* uname succeedd */
|
|
|
|
- char *module_dir;
|
|
|
|
- char *tmdn;
|
|
|
|
-
|
2008-08-20 14:00:34 +00:00
|
|
|
- tmdn = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, myuname.release);
|
2007-10-05 00:27:49 +00:00
|
|
|
- /* Jump through hoops in case /lib/modules/`uname -r`
|
|
|
|
- * is a symlink. We do not want recursive_action to
|
|
|
|
- * follow symlinks, but we do want to follow the
|
|
|
|
- * /lib/modules/`uname -r` dir, So resolve it ourselves
|
|
|
|
- * if it is a link... */
|
2007-11-10 16:51:11 +00:00
|
|
|
- module_dir = xmalloc_readlink(tmdn);
|
|
|
|
- if (!module_dir)
|
|
|
|
- module_dir = xstrdup(tmdn);
|
2007-10-05 00:27:49 +00:00
|
|
|
- recursive_action(module_dir, ACTION_RECURSE,
|
2007-11-10 16:51:11 +00:00
|
|
|
- check_module_name_match, NULL, m_fullName, 0);
|
|
|
|
- free(module_dir);
|
2007-10-05 00:27:49 +00:00
|
|
|
- free(tmdn);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* Check if we have found anything yet */
|
2007-11-10 16:51:11 +00:00
|
|
|
- if (!m_filename || ((fp = fopen(m_filename, "r")) == NULL)) {
|
|
|
|
- int r;
|
|
|
|
- char *module_dir;
|
2007-10-05 00:27:49 +00:00
|
|
|
-
|
|
|
|
- free(m_filename);
|
2007-11-10 16:51:11 +00:00
|
|
|
- m_filename = NULL;
|
2008-08-20 14:00:34 +00:00
|
|
|
- module_dir = xmalloc_readlink(CONFIG_DEFAULT_MODULES_DIR);
|
2007-11-10 16:51:11 +00:00
|
|
|
- if (!module_dir)
|
2008-08-20 14:00:34 +00:00
|
|
|
- module_dir = xstrdup(CONFIG_DEFAULT_MODULES_DIR);
|
2007-10-05 00:27:49 +00:00
|
|
|
- /* No module found under /lib/modules/`uname -r`, this
|
|
|
|
- * time cast the net a bit wider. Search /lib/modules/ */
|
2007-11-10 16:51:11 +00:00
|
|
|
- r = recursive_action(module_dir, ACTION_RECURSE,
|
|
|
|
- check_module_name_match, NULL, m_fullName, 0);
|
|
|
|
- if (r)
|
|
|
|
- bb_error_msg_and_die("%s: module not found", m_fullName);
|
|
|
|
- free(module_dir);
|
|
|
|
- if (m_filename == NULL
|
|
|
|
- || ((fp = fopen(m_filename, "r")) == NULL)
|
2007-10-05 00:27:49 +00:00
|
|
|
- ) {
|
2007-11-10 16:51:11 +00:00
|
|
|
- bb_error_msg_and_die("%s: module not found", m_fullName);
|
|
|
|
- }
|
2008-08-20 14:00:34 +00:00
|
|
|
+ tmp = xstrdup(arg1);
|
|
|
|
+ m_name = basename(tmp);
|
|
|
|
}
|
2007-10-05 00:27:49 +00:00
|
|
|
- } else
|
|
|
|
- m_filename = xstrdup(arg1);
|
2008-08-20 14:00:34 +00:00
|
|
|
|
2007-10-05 00:27:49 +00:00
|
|
|
- if (flag_verbose)
|
|
|
|
- printf("Using %s\n", m_filename);
|
2007-10-05 20:09:55 +00:00
|
|
|
-
|
2007-10-05 00:27:49 +00:00
|
|
|
-#if ENABLE_FEATURE_2_6_MODULES
|
|
|
|
- if (k_version > 4) {
|
|
|
|
- argv[optind] = m_filename;
|
|
|
|
- optind--;
|
|
|
|
- return insmod_ng_main(argc - optind, argv + optind);
|
|
|
|
+ fp = fopen(g_filename, "r");
|
|
|
|
+ if (!fp) {
|
|
|
|
+ ret = errno;
|
|
|
|
+ goto out;
|
|
|
|
}
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
f = obj_load(fp, LOADBITS);
|
2007-11-10 16:51:11 +00:00
|
|
|
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4075,7 +4046,7 @@
|
2007-10-05 00:27:49 +00:00
|
|
|
"\t%s was compiled for kernel version %s\n"
|
|
|
|
"\twhile this kernel is version %s",
|
|
|
|
flag_force_load ? "warning: " : "",
|
|
|
|
- m_filename, m_strversion, uts_info.release);
|
|
|
|
+ g_filename, m_strversion, uts_info.release);
|
|
|
|
if (!flag_force_load)
|
|
|
|
goto out;
|
|
|
|
}
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4117,7 +4088,7 @@
|
2007-10-05 00:27:49 +00:00
|
|
|
hide_special_symbols(f);
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
|
|
|
|
- add_ksymoops_symbols(f, m_filename, m_name);
|
|
|
|
+ add_ksymoops_symbols(f, g_filename, m_name);
|
|
|
|
#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
|
|
|
|
|
|
|
|
new_create_module_ksymtab(f);
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4126,7 +4097,7 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
m_size = obj_load_size(f);
|
|
|
|
|
|
|
|
m_addr = create_module(m_name, m_size);
|
|
|
|
- if (m_addr == (ElfW(Addr))(-1)) switch (errno) {
|
|
|
|
+ if (m_addr == -1) switch (errno) {
|
|
|
|
case EEXIST:
|
|
|
|
bb_error_msg_and_die("a module named %s already exists", m_name);
|
|
|
|
case ENOMEM:
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4142,36 +4113,37 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
* now we can load them directly into the kernel memory
|
|
|
|
*/
|
|
|
|
if (!obj_load_progbits(fp, f, (char*)m_addr)) {
|
|
|
|
- delete_module(m_name, 0);
|
|
|
|
+ delete_module(m_name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!obj_relocate(f, m_addr)) {
|
|
|
|
- delete_module(m_name, 0);
|
|
|
|
+ delete_module(m_name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!new_init_module(m_name, f, m_size)) {
|
|
|
|
- delete_module(m_name, 0);
|
|
|
|
+ delete_module(m_name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-10-05 00:27:49 +00:00
|
|
|
if (flag_print_load_map)
|
|
|
|
print_load_map(f);
|
|
|
|
|
|
|
|
- exit_status = EXIT_SUCCESS;
|
2007-11-10 16:51:11 +00:00
|
|
|
+ ret = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
out:
|
2007-10-05 00:27:49 +00:00
|
|
|
#if ENABLE_FEATURE_CLEAN_UP
|
|
|
|
if (fp)
|
2007-10-05 20:09:55 +00:00
|
|
|
fclose(fp);
|
|
|
|
- free(tmp1);
|
|
|
|
- if (!tmp1)
|
|
|
|
+ if (tmp)
|
|
|
|
+ free(tmp);
|
|
|
|
+ else if (m_name)
|
2007-10-05 00:27:49 +00:00
|
|
|
free(m_name);
|
|
|
|
- free(m_filename);
|
|
|
|
+ free(g_filename);
|
|
|
|
#endif
|
2007-10-05 13:05:22 +00:00
|
|
|
- return exit_status;
|
|
|
|
+ return ret;
|
2007-10-05 00:27:49 +00:00
|
|
|
}
|
|
|
|
|
2007-11-10 16:51:11 +00:00
|
|
|
#endif /* ENABLE_FEATURE_2_4_MODULES */
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4183,15 +4155,8 @@
|
2008-08-20 14:00:34 +00:00
|
|
|
#if ENABLE_FEATURE_2_6_MODULES
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
-
|
|
|
|
-#if defined __UCLIBC__ && !ENABLE_FEATURE_2_4_MODULES
|
|
|
|
-/* big time suckage. The old prototype above renders our nice fwd-decl wrong */
|
|
|
|
-extern int init_module(void *module, unsigned long len, const char *options);
|
|
|
|
-#else
|
|
|
|
#include <asm/unistd.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
-#define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
/* We use error numbers in a loose translation... */
|
|
|
|
static const char *moderror(int err)
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4210,22 +4175,32 @@
|
2007-10-05 00:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-10 16:51:11 +00:00
|
|
|
-#if !ENABLE_FEATURE_2_4_MODULES
|
|
|
|
-int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-08-20 14:00:34 +00:00
|
|
|
-int insmod_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
2007-11-10 16:51:11 +00:00
|
|
|
-#else
|
2008-08-20 14:00:34 +00:00
|
|
|
-static int insmod_ng_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
2007-11-10 16:51:11 +00:00
|
|
|
-#endif
|
2007-10-05 00:27:49 +00:00
|
|
|
+int insmod_main_26(int argc, char **argv)
|
|
|
|
{
|
|
|
|
- size_t len;
|
|
|
|
+ char *filename, *options;
|
|
|
|
+ struct utsname myuname;
|
|
|
|
+ int k_version;
|
|
|
|
int optlen;
|
|
|
|
+ size_t len;
|
|
|
|
void *map;
|
|
|
|
- char *filename, *options;
|
|
|
|
+ long ret = 0;
|
|
|
|
+
|
|
|
|
+ /* check the kernel version */
|
|
|
|
+ if ((uname(&myuname) != 0) || (myuname.release[0] != '2'))
|
|
|
|
+ return EINVAL;
|
|
|
|
+
|
|
|
|
+ k_version = myuname.release[2] - '0';
|
|
|
|
+ if (k_version <= 4)
|
|
|
|
+ return ENOTSUP;
|
|
|
|
|
|
|
|
filename = *++argv;
|
|
|
|
if (!filename)
|
|
|
|
bb_show_usage();
|
|
|
|
|
|
|
|
+ ret = find_module(filename);
|
2007-10-08 20:31:17 +00:00
|
|
|
+ if (ret || (g_filename == NULL))
|
2007-10-05 00:27:49 +00:00
|
|
|
+ goto done;
|
|
|
|
+
|
|
|
|
/* Rest is options */
|
|
|
|
options = xzalloc(1);
|
|
|
|
optlen = 0;
|
2008-09-22 12:36:13 +00:00
|
|
|
@@ -4235,41 +4210,47 @@
|
2007-10-05 00:27:49 +00:00
|
|
|
optlen += sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
-#if 0
|
2008-08-20 14:00:34 +00:00
|
|
|
- /* Any special reason why mmap? It isn't performance critical. -vda */
|
|
|
|
- /* Yes, xmalloc'ing can use *alot* of RAM. Don't forget that there are
|
|
|
|
- * modules out there that are half a megabyte! mmap()ing is way nicer
|
|
|
|
- * for small mem boxes, i guess. */
|
|
|
|
- /* But after load, these modules will take up that 0.5mb in kernel
|
|
|
|
- * anyway. Using malloc here causes only a transient spike to 1mb,
|
|
|
|
- * after module is loaded, we go back to normal 0.5mb usage
|
|
|
|
- * (in kernel). Also, mmap isn't magic - when we touch mapped data,
|
|
|
|
- * we use memory. -vda */
|
2007-10-05 00:27:49 +00:00
|
|
|
- int fd;
|
|
|
|
- struct stat st;
|
|
|
|
- unsigned long len;
|
|
|
|
- fd = xopen(filename, O_RDONLY);
|
|
|
|
- fstat(fd, &st);
|
|
|
|
- len = st.st_size;
|
|
|
|
- map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
- if (map == MAP_FAILED) {
|
|
|
|
- bb_perror_msg_and_die("cannot mmap '%s'", filename);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* map == NULL on Blackfin, probably on other MMU-less systems too. Workaround. */
|
|
|
|
- if (map == NULL) {
|
|
|
|
- map = xmalloc(len);
|
|
|
|
- xread(fd, map, len);
|
|
|
|
- }
|
|
|
|
-#else
|
|
|
|
len = MAXINT(ssize_t);
|
|
|
|
- map = xmalloc_open_read_close(filename, &len);
|
|
|
|
-#endif
|
|
|
|
+ map = xmalloc_open_read_close(g_filename, &len);
|
2008-08-20 14:00:34 +00:00
|
|
|
+ ret = syscall(__NR_init_module, map, len, options);
|
|
|
|
+ if (ret != 0) {
|
|
|
|
+ bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
|
2007-10-05 00:27:49 +00:00
|
|
|
+ g_filename, moderror(errno), ret);
|
2008-08-20 14:00:34 +00:00
|
|
|
+ }
|
2007-10-05 00:27:49 +00:00
|
|
|
+done:
|
|
|
|
+ if (g_filename && (g_filename != filename))
|
|
|
|
+ free(g_filename);
|
|
|
|
|
2008-08-20 14:00:34 +00:00
|
|
|
- if (init_module(map, len, options) != 0)
|
|
|
|
- bb_error_msg_and_die("cannot insert '%s': %s",
|
|
|
|
- filename, moderror(errno));
|
2007-10-05 00:27:49 +00:00
|
|
|
- return 0;
|
|
|
|
+ return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
+
|
|
|
|
+int insmod_main(int argc, char **argv)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+
|
2007-10-08 20:31:17 +00:00
|
|
|
+ g_filename = NULL;
|
2007-10-05 00:27:49 +00:00
|
|
|
+#if ENABLE_FEATURE_2_6_MODULES
|
|
|
|
+ ret = insmod_main_26(argc, argv);
|
|
|
|
+ if (ret != ENOTSUP)
|
|
|
|
+ goto done;
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#if ENABLE_FEATURE_2_4_MODULES
|
|
|
|
+ ret = insmod_main_24(argc, argv);
|
|
|
|
+ if (ret != ENOTSUP)
|
|
|
|
+ goto done;
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ fprintf(stderr, "Error: Kernel version not supported\n");
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
+done:
|
|
|
|
+ if (ret) {
|
|
|
|
+ errno = ret;
|
|
|
|
+ bb_perror_msg("Loading module failed");
|
|
|
|
+ return ret;
|
|
|
|
+ } else
|
|
|
|
+ return 0;
|
|
|
|
+}
|