]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: use right offset for module name
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 21 Jun 2012 14:30:56 +0000 (11:30 -0300)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 21 Jun 2012 14:30:56 +0000 (11:30 -0300)
We need to cope with the case in which a 32 bits machine is opening a 64
bits kernel module and vice-versa. The offset in `struct module' are
different and do not depend on the architecture we are running, but
rather on the architecture they were created for.

This fixes `make check' in 32 bits machines (since we are shipping 64
bits modules for testing)

testsuite/init_module.c
testsuite/stripped-module.h

index 814998aac0add8dc4e7a00ab7dfdaef7b986fa6d..8089636d3ac575cf176d2265ac9eeec3c2f5975c 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <assert.h>
+#include <elf.h>
 #include <errno.h>
 #include <dirent.h>
 #include <fcntl.h>
@@ -206,6 +207,12 @@ static inline bool module_is_inkernel(const char *modname)
        return ret;
 }
 
+static uint8_t elf_identify(void *mem)
+{
+       uint8_t *p = mem;
+       return p[EI_CLASS];
+}
+
 TS_EXPORT long init_module(void *mem, unsigned long len, const char *args);
 
 /*
@@ -225,6 +232,8 @@ long init_module(void *mem, unsigned long len, const char *args)
        const void *buf;
        uint64_t bufsize;
        int err;
+       uint8_t class;
+       off_t offset;
 
        init_retcodes();
 
@@ -236,14 +245,18 @@ long init_module(void *mem, unsigned long len, const char *args)
                                                                &bufsize);
        kmod_elf_unref(elf);
 
-       /*
-        * We couldn't find the module's name inside the ELF file. Just exit
-        * as if it was successful
-        */
+       /* We couldn't parse the ELF file. Just exit as if it was successful */
        if (err < 0)
                return 0;
 
-       modname = (char *)buf + offsetof(struct module, name);
+       /* We need to open both 32 and 64 bits module - hack! */
+       class = elf_identify(mem);
+       if (class == ELFCLASS64)
+               offset = MODULE_NAME_OFFSET_64;
+       else
+               offset = MODULE_NAME_OFFSET_32;
+
+       modname = (char *)buf + offset;
        mod = find_module(modules, modname);
        if (mod != NULL) {
                errno = mod->errcode;
index 9f97daebf81e2cab59f5b9a9d8b651cd2332123c..19862f3c3cd8e20a326db13222fb253345959d62 100644 (file)
@@ -13,6 +13,7 @@ struct list_head {
 };
 
 #define MODULE_NAME_LEN (64 - sizeof(unsigned long))
+
 struct module
 {
        enum module_state state;
@@ -24,4 +25,8 @@ struct module
        char name[MODULE_NAME_LEN];
 };
 
+/*                                padding */
+#define MODULE_NAME_OFFSET_64 4 + 4           + 2 * 8
+#define MODULE_NAME_OFFSET_32 4 + 2 * 4
+
 #endif