summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.de.marchi@gmail.com>2013-04-09 05:21:42 -0300
committerLucas De Marchi <lucas.de.marchi@gmail.com>2013-04-09 05:45:44 -0300
commit0ae58609dc0b983aa17ea7aa38c071cf1830819a (patch)
treefda6077a3c5abbecede073477ceb79722e1cccbe
parent55112d19f7067dff89b1481d5bd8cc49139c4ecb (diff)
downloadkmod-0ae58609dc0b983aa17ea7aa38c071cf1830819a.tar.gz
testsuite: Wrap syscall() to get calls to finit_module()
When we don't have finit_module() in libc (most likely because as of today glibc didn't add it yet), we end up using syscall(__NR_finit_module, ...). In this case we would not wrap the function in the testsuite and thus having some tests failing: TESTSUITE: ERR: could not insert module: Operation not permitted This implementation relies on the fact that this is the only caller of syscall(2), because we can't call libc's syscall(). There's an abort() in place to be future safe: as soon as we need more calls to syscall(), we can detect (and decide what to do). Now we have all tests passing in the testsuite again.
-rw-r--r--testsuite/init_module.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/testsuite/init_module.c b/testsuite/init_module.c
index d60ca96..f1e7f82 100644
--- a/testsuite/init_module.c
+++ b/testsuite/init_module.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2012-2013 ProFUSION embedded systems
+ * Copyright (C) 2012-2013 Lucas De Marchi <lucas.de.marchi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -35,6 +36,7 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <unistd.h>
/* kmod_elf_get_section() is not exported, we need the private header */
@@ -302,6 +304,40 @@ int finit_module(const int fd, const char *args, const int flags)
return err;
}
+TS_EXPORT long int syscall(long int __sysno, ...)
+{
+ va_list ap;
+ long ret;
+
+ switch (__sysno) {
+ case -1:
+ errno = -ENOSYS;
+ return -1;
+ case __NR_finit_module: {
+ const char *args;
+ int flags;
+ int fd;
+
+ va_start(ap, __sysno);
+
+ fd = va_arg(ap, int);
+ args = va_arg(ap, const char *);
+ flags = va_arg(ap, int);
+
+ ret = finit_module(fd, args, flags);
+
+ va_end(ap);
+ return ret;
+ }
+ }
+
+ /*
+ * FIXME: no way to call the libc function - let's hope there are no
+ * other users.
+ */
+ abort();
+}
+
/* the test is going away anyway, but lets keep valgrind happy */
void free_resources(void) __attribute__((destructor));
void free_resources(void)