Debian Codegraph @

testsuite/systemtap.syscall/module.c

raw
1 /* COVERAGE: init_module finit_module delete_module */
2
3 #define _GNU_SOURCE
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <sys/syscall.h>
10
11 #ifndef MODULE_INIT_IGNORE_MODVERSIONS
12 #define MODULE_INIT_IGNORE_MODVERSIONS 1
13 #endif
14 #ifndef MODULE_INIT_IGNORE_VERMAGIC
15 #define MODULE_INIT_IGNORE_VERMAGIC 2
16 #endif
17
18 // There aren't any glibc wrappers for these calls, so make our own.
19
20 static inline int
21 __init_module(void *module_image, unsigned long len, const char *param_values)
22 {
23 return syscall(SYS_init_module, module_image, len, param_values);
24 }
25
26 #ifdef SYS_finit_module
27 static inline int __finit_module(int fd, const char *param_values, int flags)
28 {
29 return syscall(SYS_finit_module, fd, param_values, flags);
30 }
31 #endif
32
33 static inline int __delete_module(const char *name, int flags)
34 {
35 return syscall(SYS_delete_module, name, flags);
36 }
37
38 int main()
39 {
40 int fd_null;
41
42 /* Normally we try to have a sucessful system call in the syscall
43 * tests. For these module calls, we're not going to bother. Why?
44 *
45 * 1) Laziness. We don't want to bother compiling a test module.
46 *
47 * 2) Permissions. If we aren't running as root, these calls will
48 * fail anyway.
49 *
50 * So, we expect all these calls to fail.
51 */
52
53 fd_null = open("/dev/null", O_RDONLY);
54
55 __init_module(NULL, 0, "foo=bar");
56 //staptest// init_module (0x0, 0, "foo=bar") = -NNNN
57
58 #ifdef SYS_finit_module
59 __finit_module(fd_null, "foo=bar", MODULE_INIT_IGNORE_MODVERSIONS);
60 //staptest// finit_module (NNNN, "foo=bar", MODULE_INIT_IGNORE_MODVERSIONS) = -NNNN
61 #endif
62
63 // Here we have to be careful to not remove a real module, but all
64 // we can really do is pick a bizarre module name that shouldn't exist.
65 __delete_module("__fAkE__sTaP__mOdUlE__", O_NONBLOCK);
66 //staptest// delete_module ("__fAkE__sTaP__mOdUlE__", O_NONBLOCK) = -NNNN
67
68 /* Limit testing. */
69
70 __init_module((void *)-1, 0, "foo=bar");
71 #ifdef __s390__
72 //staptest// init_module (0x[7]?[f]+, 0, "foo=bar") = -NNNN
73 #else
74 //staptest// init_module (0x[f]+, 0, "foo=bar") = -NNNN
75 #endif
76
77 // On RHEL 7 ppc64, this one can cause an OOM error.
78 #if 0
79 __init_module(NULL, -1, "foo=bar");
80 #if __WORDSIZE == 64
81 //staptest// init_module (0x0, 18446744073709551615, "foo=bar") = -NNNN
82 #else
83 //staptest// init_module (0x0, 4294967295, "foo=bar") = -NNNN
84 #endif
85 #endif
86
87 __init_module(NULL, 0, (char *)-1);
88 #ifdef __s390__
89 //staptest// init_module (0x0, 0, 0x[7]?[f]+) = -NNNN
90 #else
91 //staptest// init_module (0x0, 0, 0x[f]+) = -NNNN
92 #endif
93
94 #ifdef SYS_finit_module
95 __finit_module(-1, "foo=bar", MODULE_INIT_IGNORE_MODVERSIONS);
96 //staptest// finit_module (-1, "foo=bar", MODULE_INIT_IGNORE_MODVERSIONS) = -NNNN
97 __finit_module(fd_null, (char *)-1, MODULE_INIT_IGNORE_MODVERSIONS);
98 #ifdef __s390__
99 //staptest// finit_module (NNNN, 0x[7]?[f]+, MODULE_INIT_IGNORE_MODVERSIONS) = -NNNN
100 #else
101 //staptest// finit_module (NNNN, 0x[f]+, MODULE_INIT_IGNORE_MODVERSIONS) = -NNNN
102 #endif
103 __finit_module(fd_null, "foo=bar", -1);
104 //staptest// finit_module (NNNN, "foo=bar", MODULE_INIT_[^ ]+|XXXX) = -NNNN
105 #endif
106
107 __delete_module((char *)-1, O_TRUNC);
108 #ifdef __s390__
109 //staptest// delete_module (0x[7]?[f]+, O_TRUNC) = -NNNN
110 #else
111 //staptest// delete_module (0x[f]+, O_TRUNC) = -NNNN
112 #endif
113
114 __delete_module("__fAkE__sTaP__mOdUlE__", -1);
115 //staptest// delete_module ("__fAkE__sTaP__mOdUlE__", O_[^ ]+|XXXX) = -NNNN
116
117 close(fd_null);
118 return 0;
119 }