summaryrefslogtreecommitdiff
path: root/kmodloader.c
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2014-01-16 00:29:16 +0000
committerJohn Crispin <blogic@openwrt.org>2014-01-16 00:56:26 +0000
commit6a5ff020909d005ad014810b2b7b60aabe9d7ed0 (patch)
tree3428cdf030f77402f1096a068c60f21f865bde02 /kmodloader.c
parentfff945d10e8a09377759e726b5dd9be7d01e1bc9 (diff)
downloadubox-6a5ff020909d005ad014810b2b7b60aabe9d7ed0.tar.gz
kmodloader: fix elf header parsing on 64bit machines
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'kmodloader.c')
-rw-r--r--kmodloader.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/kmodloader.c b/kmodloader.c
index 7840215..f0985ee 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -111,8 +111,7 @@ static char* get_module_name(char *path)
return name;
}
-#if __WORDSIZE == 64
-static int elf_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size)
+static int elf64_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size)
{
const char *secnames;
Elf64_Ehdr *e;
@@ -133,8 +132,8 @@ static int elf_find_section(char *map, const char *section, unsigned int *offset
return -1;
}
-#else
-static int elf_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size)
+
+static int elf32_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size)
{
const char *secnames;
Elf32_Ehdr *e;
@@ -155,7 +154,20 @@ static int elf_find_section(char *map, const char *section, unsigned int *offset
return -1;
}
-#endif
+
+static int elf_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size)
+{
+ int clazz = map[EI_CLASS];
+
+ if (clazz == ELFCLASS32)
+ return elf32_find_section(map, section, offset, size);
+ else if (clazz == ELFCLASS64)
+ return elf64_find_section(map, section, offset, size);
+
+ LOG("unknown elf format %d\n", clazz);
+
+ return -1;
+}
static struct module *
alloc_module(const char *name, const char *depends, int size)