]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: handle finit_module
authorKees Cook <keescook@chromium.org>
Mon, 18 Feb 2013 20:02:33 +0000 (12:02 -0800)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 19 Feb 2013 22:19:51 +0000 (19:19 -0300)
This adds the finit_module logic to the testsuite.

testsuite/init_module.c

index c4d7efbafe9c2b106cf04503134097113fb94e69..ca9f84c7a32ef9113aae9638315787f30ff01f68 100644 (file)
@@ -28,6 +28,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <stdio.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -274,6 +275,29 @@ long init_module(void *mem, unsigned long len, const char *args)
        return err;
 }
 
+TS_EXPORT int finit_module(const int fd, const char *args, const int flags);
+
+int finit_module(const int fd, const char *args, const int flags)
+{
+       int err;
+       void *mem;
+       unsigned long len;
+       struct stat st;
+
+       if (fstat(fd, &st) < 0)
+               return -1;
+
+       len = st.st_size;
+       mem = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
+       if (mem == MAP_FAILED)
+               return -1;
+
+       err = init_module(mem, len, args);
+       munmap(mem, len);
+
+       return err;
+}
+
 /* the test is going away anyway, but lets keep valgrind happy */
 void free_resources(void) __attribute__((destructor));
 void free_resources(void)