aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:47 -0400
commit8065be8d032f38da25b54bf077a05a30d9ce9f2a (patch)
tree32a7baf4b40e0240ab4b9dd6f2bbe6129929bb66 /tools
parent27d438c56009e5ae632de36fe70985d1aab5e344 (diff)
parentecc265fe9e09e32a3573b2ba26e79b2099eb8bbb (diff)
Merge branch 'akpm' (second patchbomb from Andrew Morton)
Merge more incoming from Andrew Morton: "Two new syscalls: memfd_create in "shm: add memfd_create() syscall" kexec_file_load in "kexec: implementation of new syscall kexec_file_load" And: - Most (all?) of the rest of MM - Lots of the usual misc bits - fs/autofs4 - drivers/rtc - fs/nilfs - procfs - fork.c, exec.c - more in lib/ - rapidio - Janitorial work in filesystems: fs/ufs, fs/reiserfs, fs/adfs, fs/cramfs, fs/romfs, fs/qnx6. - initrd/initramfs work - "file sealing" and the memfd_create() syscall, in tmpfs - add pci_zalloc_consistent, use it in lots of places - MAINTAINERS maintenance - kexec feature work" * emailed patches from Andrew Morton <akpm@linux-foundation.org: (193 commits) MAINTAINERS: update nomadik patterns MAINTAINERS: update usb/gadget patterns MAINTAINERS: update DMA BUFFER SHARING patterns kexec: verify the signature of signed PE bzImage kexec: support kexec/kdump on EFI systems kexec: support for kexec on panic using new system call kexec-bzImage64: support for loading bzImage using 64bit entry kexec: load and relocate purgatory at kernel load time purgatory: core purgatory functionality purgatory/sha256: provide implementation of sha256 in purgaotory context kexec: implementation of new syscall kexec_file_load kexec: new syscall kexec_file_load() declaration kexec: make kexec_segment user buffer pointer a union resource: provide new functions to walk through resources kexec: use common function for kimage_normal_alloc() and kimage_crash_alloc() kexec: move segment verification code in a separate function kexec: rename unusebale_pages to unusable_pages kernel: build bin2c based on config option CONFIG_BUILD_BIN2C bin2c: move bin2c in scripts/basic shm: wait for pins to be released when sealing ...
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/Makefile1
-rw-r--r--tools/testing/selftests/memfd/.gitignore4
-rw-r--r--tools/testing/selftests/memfd/Makefile41
-rw-r--r--tools/testing/selftests/memfd/fuse_mnt.c110
-rw-r--r--tools/testing/selftests/memfd/fuse_test.c311
-rw-r--r--tools/testing/selftests/memfd/memfd_test.c913
-rw-r--r--tools/testing/selftests/memfd/run_fuse_test.sh14
-rw-r--r--tools/testing/selftests/ptrace/peeksiginfo.c4
8 files changed, 1398 insertions, 0 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index d10f95ce2ea4..6fd2a4402069 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -2,6 +2,7 @@ TARGETS = breakpoints
2TARGETS += cpu-hotplug 2TARGETS += cpu-hotplug
3TARGETS += efivarfs 3TARGETS += efivarfs
4TARGETS += kcmp 4TARGETS += kcmp
5TARGETS += memfd
5TARGETS += memory-hotplug 6TARGETS += memory-hotplug
6TARGETS += mqueue 7TARGETS += mqueue
7TARGETS += net 8TARGETS += net
diff --git a/tools/testing/selftests/memfd/.gitignore b/tools/testing/selftests/memfd/.gitignore
new file mode 100644
index 000000000000..afe87c40ac80
--- /dev/null
+++ b/tools/testing/selftests/memfd/.gitignore
@@ -0,0 +1,4 @@
1fuse_mnt
2fuse_test
3memfd_test
4memfd-test-file
diff --git a/tools/testing/selftests/memfd/Makefile b/tools/testing/selftests/memfd/Makefile
new file mode 100644
index 000000000000..6816c491c5ff
--- /dev/null
+++ b/tools/testing/selftests/memfd/Makefile
@@ -0,0 +1,41 @@
1uname_M := $(shell uname -m 2>/dev/null || echo not)
2ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
3ifeq ($(ARCH),i386)
4 ARCH := X86
5endif
6ifeq ($(ARCH),x86_64)
7 ARCH := X86
8endif
9
10CFLAGS += -D_FILE_OFFSET_BITS=64
11CFLAGS += -I../../../../arch/x86/include/generated/uapi/
12CFLAGS += -I../../../../arch/x86/include/uapi/
13CFLAGS += -I../../../../include/uapi/
14CFLAGS += -I../../../../include/
15
16all:
17ifeq ($(ARCH),X86)
18 gcc $(CFLAGS) memfd_test.c -o memfd_test
19else
20 echo "Not an x86 target, can't build memfd selftest"
21endif
22
23run_tests: all
24ifeq ($(ARCH),X86)
25 gcc $(CFLAGS) memfd_test.c -o memfd_test
26endif
27 @./memfd_test || echo "memfd_test: [FAIL]"
28
29build_fuse:
30ifeq ($(ARCH),X86)
31 gcc $(CFLAGS) fuse_mnt.c `pkg-config fuse --cflags --libs` -o fuse_mnt
32 gcc $(CFLAGS) fuse_test.c -o fuse_test
33else
34 echo "Not an x86 target, can't build memfd selftest"
35endif
36
37run_fuse: build_fuse
38 @./run_fuse_test.sh || echo "fuse_test: [FAIL]"
39
40clean:
41 $(RM) memfd_test fuse_test
diff --git a/tools/testing/selftests/memfd/fuse_mnt.c b/tools/testing/selftests/memfd/fuse_mnt.c
new file mode 100644
index 000000000000..feacf1280fcd
--- /dev/null
+++ b/tools/testing/selftests/memfd/fuse_mnt.c
@@ -0,0 +1,110 @@
1/*
2 * memfd test file-system
3 * This file uses FUSE to create a dummy file-system with only one file /memfd.
4 * This file is read-only and takes 1s per read.
5 *
6 * This file-system is used by the memfd test-cases to force the kernel to pin
7 * pages during reads(). Due to the 1s delay of this file-system, this is a
8 * nice way to test race-conditions against get_user_pages() in the kernel.
9 *
10 * We use direct_io==1 to force the kernel to use direct-IO for this
11 * file-system.
12 */
13
14#define FUSE_USE_VERSION 26
15
16#include <fuse.h>
17#include <stdio.h>
18#include <string.h>
19#include <errno.h>
20#include <fcntl.h>
21#include <unistd.h>
22
23static const char memfd_content[] = "memfd-example-content";
24static const char memfd_path[] = "/memfd";
25
26static int memfd_getattr(const char *path, struct stat *st)
27{
28 memset(st, 0, sizeof(*st));
29
30 if (!strcmp(path, "/")) {
31 st->st_mode = S_IFDIR | 0755;
32 st->st_nlink = 2;
33 } else if (!strcmp(path, memfd_path)) {
34 st->st_mode = S_IFREG | 0444;
35 st->st_nlink = 1;
36 st->st_size = strlen(memfd_content);
37 } else {
38 return -ENOENT;
39 }
40
41 return 0;
42}
43
44static int memfd_readdir(const char *path,
45 void *buf,
46 fuse_fill_dir_t filler,
47 off_t offset,
48 struct fuse_file_info *fi)
49{
50 if (strcmp(path, "/"))
51 return -ENOENT;
52
53 filler(buf, ".", NULL, 0);
54 filler(buf, "..", NULL, 0);
55 filler(buf, memfd_path + 1, NULL, 0);
56
57 return 0;
58}
59
60static int memfd_open(const char *path, struct fuse_file_info *fi)
61{
62 if (strcmp(path, memfd_path))
63 return -ENOENT;
64
65 if ((fi->flags & 3) != O_RDONLY)
66 return -EACCES;
67
68 /* force direct-IO */
69 fi->direct_io = 1;
70
71 return 0;
72}
73
74static int memfd_read(const char *path,
75 char *buf,
76 size_t size,
77 off_t offset,
78 struct fuse_file_info *fi)
79{
80 size_t len;
81
82 if (strcmp(path, memfd_path) != 0)
83 return -ENOENT;
84
85 sleep(1);
86
87 len = strlen(memfd_content);
88 if (offset < len) {
89 if (offset + size > len)
90 size = len - offset;
91
92 memcpy(buf, memfd_content + offset, size);
93 } else {
94 size = 0;
95 }
96
97 return size;
98}
99
100static struct fuse_operations memfd_ops = {
101 .getattr = memfd_getattr,
102 .readdir = memfd_readdir,
103 .open = memfd_open,
104 .read = memfd_read,
105};
106
107int main(int argc, char *argv[])
108{
109 return fuse_main(argc, argv, &memfd_ops, NULL);
110}
diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/selftests/memfd/fuse_test.c
new file mode 100644
index 000000000000..67908b18f035
--- /dev/null
+++ b/tools/testing/selftests/memfd/fuse_test.c
@@ -0,0 +1,311 @@
1/*
2 * memfd GUP test-case
3 * This tests memfd interactions with get_user_pages(). We require the
4 * fuse_mnt.c program to provide a fake direct-IO FUSE mount-point for us. This
5 * file-system delays _all_ reads by 1s and forces direct-IO. This means, any
6 * read() on files in that file-system will pin the receive-buffer pages for at
7 * least 1s via get_user_pages().
8 *
9 * We use this trick to race ADD_SEALS against a write on a memfd object. The
10 * ADD_SEALS must fail if the memfd pages are still pinned. Note that we use
11 * the read() syscall with our memory-mapped memfd object as receive buffer to
12 * force the kernel to write into our memfd object.
13 */
14
15#define _GNU_SOURCE
16#define __EXPORTED_HEADERS__
17
18#include <errno.h>
19#include <inttypes.h>
20#include <limits.h>
21#include <linux/falloc.h>
22#include <linux/fcntl.h>
23#include <linux/memfd.h>
24#include <sched.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <signal.h>
28#include <string.h>
29#include <sys/mman.h>
30#include <sys/stat.h>
31#include <sys/syscall.h>
32#include <sys/wait.h>
33#include <unistd.h>
34
35#define MFD_DEF_SIZE 8192
36#define STACK_SIZE 65535
37
38static int sys_memfd_create(const char *name,
39 unsigned int flags)
40{
41 return syscall(__NR_memfd_create, name, flags);
42}
43
44static int mfd_assert_new(const char *name, loff_t sz, unsigned int flags)
45{
46 int r, fd;
47
48 fd = sys_memfd_create(name, flags);
49 if (fd < 0) {
50 printf("memfd_create(\"%s\", %u) failed: %m\n",
51 name, flags);
52 abort();
53 }
54
55 r = ftruncate(fd, sz);
56 if (r < 0) {
57 printf("ftruncate(%llu) failed: %m\n", (unsigned long long)sz);
58 abort();
59 }
60
61 return fd;
62}
63
64static __u64 mfd_assert_get_seals(int fd)
65{
66 long r;
67
68 r = fcntl(fd, F_GET_SEALS);
69 if (r < 0) {
70 printf("GET_SEALS(%d) failed: %m\n", fd);
71 abort();
72 }
73
74 return r;
75}
76
77static void mfd_assert_has_seals(int fd, __u64 seals)
78{
79 __u64 s;
80
81 s = mfd_assert_get_seals(fd);
82 if (s != seals) {
83 printf("%llu != %llu = GET_SEALS(%d)\n",
84 (unsigned long long)seals, (unsigned long long)s, fd);
85 abort();
86 }
87}
88
89static void mfd_assert_add_seals(int fd, __u64 seals)
90{
91 long r;
92 __u64 s;
93
94 s = mfd_assert_get_seals(fd);
95 r = fcntl(fd, F_ADD_SEALS, seals);
96 if (r < 0) {
97 printf("ADD_SEALS(%d, %llu -> %llu) failed: %m\n",
98 fd, (unsigned long long)s, (unsigned long long)seals);
99 abort();
100 }
101}
102
103static int mfd_busy_add_seals(int fd, __u64 seals)
104{
105 long r;
106 __u64 s;
107
108 r = fcntl(fd, F_GET_SEALS);
109 if (r < 0)
110 s = 0;
111 else
112 s = r;
113
114 r = fcntl(fd, F_ADD_SEALS, seals);
115 if (r < 0 && errno != EBUSY) {
116 printf("ADD_SEALS(%d, %llu -> %llu) didn't fail as expected with EBUSY: %m\n",
117 fd, (unsigned long long)s, (unsigned long long)seals);
118 abort();
119 }
120
121 return r;
122}
123
124static void *mfd_assert_mmap_shared(int fd)
125{
126 void *p;
127
128 p = mmap(NULL,
129 MFD_DEF_SIZE,
130 PROT_READ | PROT_WRITE,
131 MAP_SHARED,
132 fd,
133 0);
134 if (p == MAP_FAILED) {
135 printf("mmap() failed: %m\n");
136 abort();
137 }
138
139 return p;
140}
141
142static void *mfd_assert_mmap_private(int fd)
143{
144 void *p;
145
146 p = mmap(NULL,
147 MFD_DEF_SIZE,
148 PROT_READ | PROT_WRITE,
149 MAP_PRIVATE,
150 fd,
151 0);
152 if (p == MAP_FAILED) {
153 printf("mmap() failed: %m\n");
154 abort();
155 }
156
157 return p;
158}
159
160static int global_mfd = -1;
161static void *global_p = NULL;
162
163static int sealing_thread_fn(void *arg)
164{
165 int sig, r;
166
167 /*
168 * This thread first waits 200ms so any pending operation in the parent
169 * is correctly started. After that, it tries to seal @global_mfd as
170 * SEAL_WRITE. This _must_ fail as the parent thread has a read() into
171 * that memory mapped object still ongoing.
172 * We then wait one more second and try sealing again. This time it
173 * must succeed as there shouldn't be anyone else pinning the pages.
174 */
175
176 /* wait 200ms for FUSE-request to be active */
177 usleep(200000);
178
179 /* unmount mapping before sealing to avoid i_mmap_writable failures */
180 munmap(global_p, MFD_DEF_SIZE);
181
182 /* Try sealing the global file; expect EBUSY or success. Current
183 * kernels will never succeed, but in the future, kernels might
184 * implement page-replacements or other fancy ways to avoid racing
185 * writes. */
186 r = mfd_busy_add_seals(global_mfd, F_SEAL_WRITE);
187 if (r >= 0) {
188 printf("HURRAY! This kernel fixed GUP races!\n");
189 } else {
190 /* wait 1s more so the FUSE-request is done */
191 sleep(1);
192
193 /* try sealing the global file again */
194 mfd_assert_add_seals(global_mfd, F_SEAL_WRITE);
195 }
196
197 return 0;
198}
199
200static pid_t spawn_sealing_thread(void)
201{
202 uint8_t *stack;
203 pid_t pid;
204
205 stack = malloc(STACK_SIZE);
206 if (!stack) {
207 printf("malloc(STACK_SIZE) failed: %m\n");
208 abort();
209 }
210
211 pid = clone(sealing_thread_fn,
212 stack + STACK_SIZE,
213 SIGCHLD | CLONE_FILES | CLONE_FS | CLONE_VM,
214 NULL);
215 if (pid < 0) {
216 printf("clone() failed: %m\n");
217 abort();
218 }
219
220 return pid;
221}
222
223static void join_sealing_thread(pid_t pid)
224{
225 waitpid(pid, NULL, 0);
226}
227
228int main(int argc, char **argv)
229{
230 static const char zero[MFD_DEF_SIZE];
231 int fd, mfd, r;
232 void *p;
233 int was_sealed;
234 pid_t pid;
235
236 if (argc < 2) {
237 printf("error: please pass path to file in fuse_mnt mount-point\n");
238 abort();
239 }
240
241 /* open FUSE memfd file for GUP testing */
242 printf("opening: %s\n", argv[1]);
243 fd = open(argv[1], O_RDONLY | O_CLOEXEC);
244 if (fd < 0) {
245 printf("cannot open(\"%s\"): %m\n", argv[1]);
246 abort();
247 }
248
249 /* create new memfd-object */
250 mfd = mfd_assert_new("kern_memfd_fuse",
251 MFD_DEF_SIZE,
252 MFD_CLOEXEC | MFD_ALLOW_SEALING);
253
254 /* mmap memfd-object for writing */
255 p = mfd_assert_mmap_shared(mfd);
256
257 /* pass mfd+mapping to a separate sealing-thread which tries to seal
258 * the memfd objects with SEAL_WRITE while we write into it */
259 global_mfd = mfd;
260 global_p = p;
261 pid = spawn_sealing_thread();
262
263 /* Use read() on the FUSE file to read into our memory-mapped memfd
264 * object. This races the other thread which tries to seal the
265 * memfd-object.
266 * If @fd is on the memfd-fake-FUSE-FS, the read() is delayed by 1s.
267 * This guarantees that the receive-buffer is pinned for 1s until the
268 * data is written into it. The racing ADD_SEALS should thus fail as
269 * the pages are still pinned. */
270 r = read(fd, p, MFD_DEF_SIZE);
271 if (r < 0) {
272 printf("read() failed: %m\n");
273 abort();
274 } else if (!r) {
275 printf("unexpected EOF on read()\n");
276 abort();
277 }
278
279 was_sealed = mfd_assert_get_seals(mfd) & F_SEAL_WRITE;
280
281 /* Wait for sealing-thread to finish and verify that it
282 * successfully sealed the file after the second try. */
283 join_sealing_thread(pid);
284 mfd_assert_has_seals(mfd, F_SEAL_WRITE);
285
286 /* *IF* the memfd-object was sealed at the time our read() returned,
287 * then the kernel did a page-replacement or canceled the read() (or
288 * whatever magic it did..). In that case, the memfd object is still
289 * all zero.
290 * In case the memfd-object was *not* sealed, the read() was successfull
291 * and the memfd object must *not* be all zero.
292 * Note that in real scenarios, there might be a mixture of both, but
293 * in this test-cases, we have explicit 200ms delays which should be
294 * enough to avoid any in-flight writes. */
295
296 p = mfd_assert_mmap_private(mfd);
297 if (was_sealed && memcmp(p, zero, MFD_DEF_SIZE)) {
298 printf("memfd sealed during read() but data not discarded\n");
299 abort();
300 } else if (!was_sealed && !memcmp(p, zero, MFD_DEF_SIZE)) {
301 printf("memfd sealed after read() but data discarded\n");
302 abort();
303 }
304
305 close(mfd);
306 close(fd);
307
308 printf("fuse: DONE\n");
309
310 return 0;
311}
diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
new file mode 100644
index 000000000000..3634c909b1b0
--- /dev/null
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -0,0 +1,913 @@
1#define _GNU_SOURCE
2#define __EXPORTED_HEADERS__
3
4#include <errno.h>
5#include <inttypes.h>
6#include <limits.h>
7#include <linux/falloc.h>
8#include <linux/fcntl.h>
9#include <linux/memfd.h>
10#include <sched.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <signal.h>
14#include <string.h>
15#include <sys/mman.h>
16#include <sys/stat.h>
17#include <sys/syscall.h>
18#include <unistd.h>
19
20#define MFD_DEF_SIZE 8192
21#define STACK_SIZE 65535
22
23static int sys_memfd_create(const char *name,
24 unsigned int flags)
25{
26 return syscall(__NR_memfd_create, name, flags);
27}
28
29static int mfd_assert_new(const char *name, loff_t sz, unsigned int flags)
30{
31 int r, fd;
32
33 fd = sys_memfd_create(name, flags);
34 if (fd < 0) {
35 printf("memfd_create(\"%s\", %u) failed: %m\n",
36 name, flags);
37 abort();
38 }
39
40 r = ftruncate(fd, sz);
41 if (r < 0) {
42 printf("ftruncate(%llu) failed: %m\n", (unsigned long long)sz);
43 abort();
44 }
45
46 return fd;
47}
48
49static void mfd_fail_new(const char *name, unsigned int flags)
50{
51 int r;
52
53 r = sys_memfd_create(name, flags);
54 if (r >= 0) {
55 printf("memfd_create(\"%s\", %u) succeeded, but failure expected\n",
56 name, flags);
57 close(r);
58 abort();
59 }
60}
61
62static __u64 mfd_assert_get_seals(int fd)
63{
64 long r;
65
66 r = fcntl(fd, F_GET_SEALS);
67 if (r < 0) {
68 printf("GET_SEALS(%d) failed: %m\n", fd);
69 abort();
70 }
71
72 return r;
73}
74
75static void mfd_assert_has_seals(int fd, __u64 seals)
76{
77 __u64 s;
78
79 s = mfd_assert_get_seals(fd);
80 if (s != seals) {
81 printf("%llu != %llu = GET_SEALS(%d)\n",
82 (unsigned long long)seals, (unsigned long long)s, fd);
83 abort();
84 }
85}
86
87static void mfd_assert_add_seals(int fd, __u64 seals)
88{
89 long r;
90 __u64 s;
91
92 s = mfd_assert_get_seals(fd);
93 r = fcntl(fd, F_ADD_SEALS, seals);
94 if (r < 0) {
95 printf("ADD_SEALS(%d, %llu -> %llu) failed: %m\n",
96 fd, (unsigned long long)s, (unsigned long long)seals);
97 abort();
98 }
99}
100
101static void mfd_fail_add_seals(int fd, __u64 seals)
102{
103 long r;
104 __u64 s;
105
106 r = fcntl(fd, F_GET_SEALS);
107 if (r < 0)
108 s = 0;
109 else
110 s = r;
111
112 r = fcntl(fd, F_ADD_SEALS, seals);
113 if (r >= 0) {
114 printf("ADD_SEALS(%d, %llu -> %llu) didn't fail as expected\n",
115 fd, (unsigned long long)s, (unsigned long long)seals);
116 abort();
117 }
118}
119
120static void mfd_assert_size(int fd, size_t size)
121{
122 struct stat st;
123 int r;
124
125 r = fstat(fd, &st);
126 if (r < 0) {
127 printf("fstat(%d) failed: %m\n", fd);
128 abort();
129 } else if (st.st_size != size) {
130 printf("wrong file size %lld, but expected %lld\n",
131 (long long)st.st_size, (long long)size);
132 abort();
133 }
134}
135
136static int mfd_assert_dup(int fd)
137{
138 int r;
139
140 r = dup(fd);
141 if (r < 0) {
142 printf("dup(%d) failed: %m\n", fd);
143 abort();
144 }
145
146 return r;
147}
148
149static void *mfd_assert_mmap_shared(int fd)
150{
151 void *p;
152
153 p = mmap(NULL,
154 MFD_DEF_SIZE,
155 PROT_READ | PROT_WRITE,
156 MAP_SHARED,
157 fd,
158 0);
159 if (p == MAP_FAILED) {
160 printf("mmap() failed: %m\n");
161 abort();
162 }
163
164 return p;
165}
166
167static void *mfd_assert_mmap_private(int fd)
168{
169 void *p;
170
171 p = mmap(NULL,
172 MFD_DEF_SIZE,
173 PROT_READ,
174 MAP_PRIVATE,
175 fd,
176 0);
177 if (p == MAP_FAILED) {
178 printf("mmap() failed: %m\n");
179 abort();
180 }
181
182 return p;
183}
184
185static int mfd_assert_open(int fd, int flags, mode_t mode)
186{
187 char buf[512];
188 int r;
189
190 sprintf(buf, "/proc/self/fd/%d", fd);
191 r = open(buf, flags, mode);
192 if (r < 0) {
193 printf("open(%s) failed: %m\n", buf);
194 abort();
195 }
196
197 return r;
198}
199
200static void mfd_fail_open(int fd, int flags, mode_t mode)
201{
202 char buf[512];
203 int r;
204
205 sprintf(buf, "/proc/self/fd/%d", fd);
206 r = open(buf, flags, mode);
207 if (r >= 0) {
208 printf("open(%s) didn't fail as expected\n");
209 abort();
210 }
211}
212
213static void mfd_assert_read(int fd)
214{
215 char buf[16];
216 void *p;
217 ssize_t l;
218
219 l = read(fd, buf, sizeof(buf));
220 if (l != sizeof(buf)) {
221 printf("read() failed: %m\n");
222 abort();
223 }
224
225 /* verify PROT_READ *is* allowed */
226 p = mmap(NULL,
227 MFD_DEF_SIZE,
228 PROT_READ,
229 MAP_PRIVATE,
230 fd,
231 0);
232 if (p == MAP_FAILED) {
233 printf("mmap() failed: %m\n");
234 abort();
235 }
236 munmap(p, MFD_DEF_SIZE);
237
238 /* verify MAP_PRIVATE is *always* allowed (even writable) */
239 p = mmap(NULL,
240 MFD_DEF_SIZE,
241 PROT_READ | PROT_WRITE,
242 MAP_PRIVATE,
243 fd,
244 0);
245 if (p == MAP_FAILED) {
246 printf("mmap() failed: %m\n");
247 abort();
248 }
249 munmap(p, MFD_DEF_SIZE);
250}
251
252static void mfd_assert_write(int fd)
253{
254 ssize_t l;
255 void *p;
256 int r;
257
258 /* verify write() succeeds */
259 l = write(fd, "\0\0\0\0", 4);
260 if (l != 4) {
261 printf("write() failed: %m\n");
262 abort();
263 }
264
265 /* verify PROT_READ | PROT_WRITE is allowed */
266 p = mmap(NULL,
267 MFD_DEF_SIZE,
268 PROT_READ | PROT_WRITE,
269 MAP_SHARED,
270 fd,
271 0);
272 if (p == MAP_FAILED) {
273 printf("mmap() failed: %m\n");
274 abort();
275 }
276 *(char *)p = 0;
277 munmap(p, MFD_DEF_SIZE);
278
279 /* verify PROT_WRITE is allowed */
280 p = mmap(NULL,
281 MFD_DEF_SIZE,
282 PROT_WRITE,
283 MAP_SHARED,
284 fd,
285 0);
286 if (p == MAP_FAILED) {
287 printf("mmap() failed: %m\n");
288 abort();
289 }
290 *(char *)p = 0;
291 munmap(p, MFD_DEF_SIZE);
292
293 /* verify PROT_READ with MAP_SHARED is allowed and a following
294 * mprotect(PROT_WRITE) allows writing */
295 p = mmap(NULL,
296 MFD_DEF_SIZE,
297 PROT_READ,
298 MAP_SHARED,
299 fd,
300 0);
301 if (p == MAP_FAILED) {
302 printf("mmap() failed: %m\n");
303 abort();
304 }
305
306 r = mprotect(p, MFD_DEF_SIZE, PROT_READ | PROT_WRITE);
307 if (r < 0) {
308 printf("mprotect() failed: %m\n");
309 abort();
310 }
311
312 *(char *)p = 0;
313 munmap(p, MFD_DEF_SIZE);
314
315 /* verify PUNCH_HOLE works */
316 r = fallocate(fd,
317 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
318 0,
319 MFD_DEF_SIZE);
320 if (r < 0) {
321 printf("fallocate(PUNCH_HOLE) failed: %m\n");
322 abort();
323 }
324}
325
326static void mfd_fail_write(int fd)
327{
328 ssize_t l;
329 void *p;
330 int r;
331
332 /* verify write() fails */
333 l = write(fd, "data", 4);
334 if (l != -EPERM) {
335 printf("expected EPERM on write(), but got %d: %m\n", (int)l);
336 abort();
337 }
338
339 /* verify PROT_READ | PROT_WRITE is not allowed */
340 p = mmap(NULL,
341 MFD_DEF_SIZE,
342 PROT_READ | PROT_WRITE,
343 MAP_SHARED,
344 fd,
345 0);
346 if (p != MAP_FAILED) {
347 printf("mmap() didn't fail as expected\n");
348 abort();
349 }
350
351 /* verify PROT_WRITE is not allowed */
352 p = mmap(NULL,
353 MFD_DEF_SIZE,
354 PROT_WRITE,
355 MAP_SHARED,
356 fd,
357 0);
358 if (p != MAP_FAILED) {
359 printf("mmap() didn't fail as expected\n");
360 abort();
361 }
362
363 /* Verify PROT_READ with MAP_SHARED with a following mprotect is not
364 * allowed. Note that for r/w the kernel already prevents the mmap. */
365 p = mmap(NULL,
366 MFD_DEF_SIZE,
367 PROT_READ,
368 MAP_SHARED,
369 fd,
370 0);
371 if (p != MAP_FAILED) {
372 r = mprotect(p, MFD_DEF_SIZE, PROT_READ | PROT_WRITE);
373 if (r >= 0) {
374 printf("mmap()+mprotect() didn't fail as expected\n");
375 abort();
376 }
377 }
378
379 /* verify PUNCH_HOLE fails */
380 r = fallocate(fd,
381 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
382 0,
383 MFD_DEF_SIZE);
384 if (r >= 0) {
385 printf("fallocate(PUNCH_HOLE) didn't fail as expected\n");
386 abort();
387 }
388}
389
390static void mfd_assert_shrink(int fd)
391{
392 int r, fd2;
393
394 r = ftruncate(fd, MFD_DEF_SIZE / 2);
395 if (r < 0) {
396 printf("ftruncate(SHRINK) failed: %m\n");
397 abort();
398 }
399
400 mfd_assert_size(fd, MFD_DEF_SIZE / 2);
401
402 fd2 = mfd_assert_open(fd,
403 O_RDWR | O_CREAT | O_TRUNC,
404 S_IRUSR | S_IWUSR);
405 close(fd2);
406
407 mfd_assert_size(fd, 0);
408}
409
410static void mfd_fail_shrink(int fd)
411{
412 int r;
413
414 r = ftruncate(fd, MFD_DEF_SIZE / 2);
415 if (r >= 0) {
416 printf("ftruncate(SHRINK) didn't fail as expected\n");
417 abort();
418 }
419
420 mfd_fail_open(fd,
421 O_RDWR | O_CREAT | O_TRUNC,
422 S_IRUSR | S_IWUSR);
423}
424
425static void mfd_assert_grow(int fd)
426{
427 int r;
428
429 r = ftruncate(fd, MFD_DEF_SIZE * 2);
430 if (r < 0) {
431 printf("ftruncate(GROW) failed: %m\n");
432 abort();
433 }
434
435 mfd_assert_size(fd, MFD_DEF_SIZE * 2);
436
437 r = fallocate(fd,
438 0,
439 0,
440 MFD_DEF_SIZE * 4);
441 if (r < 0) {
442 printf("fallocate(ALLOC) failed: %m\n");
443 abort();
444 }
445
446 mfd_assert_size(fd, MFD_DEF_SIZE * 4);
447}
448
449static void mfd_fail_grow(int fd)
450{
451 int r;
452
453 r = ftruncate(fd, MFD_DEF_SIZE * 2);
454 if (r >= 0) {
455 printf("ftruncate(GROW) didn't fail as expected\n");
456 abort();
457 }
458
459 r = fallocate(fd,
460 0,
461 0,
462 MFD_DEF_SIZE * 4);
463 if (r >= 0) {
464 printf("fallocate(ALLOC) didn't fail as expected\n");
465 abort();
466 }
467}
468
469static void mfd_assert_grow_write(int fd)
470{
471 static char buf[MFD_DEF_SIZE * 8];
472 ssize_t l;
473
474 l = pwrite(fd, buf, sizeof(buf), 0);
475 if (l != sizeof(buf)) {
476 printf("pwrite() failed: %m\n");
477 abort();
478 }
479
480 mfd_assert_size(fd, MFD_DEF_SIZE * 8);
481}
482
483static void mfd_fail_grow_write(int fd)
484{
485 static char buf[MFD_DEF_SIZE * 8];
486 ssize_t l;
487
488 l = pwrite(fd, buf, sizeof(buf), 0);
489 if (l == sizeof(buf)) {
490 printf("pwrite() didn't fail as expected\n");
491 abort();
492 }
493}
494
495static int idle_thread_fn(void *arg)
496{
497 sigset_t set;
498 int sig;
499
500 /* dummy waiter; SIGTERM terminates us anyway */
501 sigemptyset(&set);
502 sigaddset(&set, SIGTERM);
503 sigwait(&set, &sig);
504
505 return 0;
506}
507
508static pid_t spawn_idle_thread(unsigned int flags)
509{
510 uint8_t *stack;
511 pid_t pid;
512
513 stack = malloc(STACK_SIZE);
514 if (!stack) {
515 printf("malloc(STACK_SIZE) failed: %m\n");
516 abort();
517 }
518
519 pid = clone(idle_thread_fn,
520 stack + STACK_SIZE,
521 SIGCHLD | flags,
522 NULL);
523 if (pid < 0) {
524 printf("clone() failed: %m\n");
525 abort();
526 }
527
528 return pid;
529}
530
531static void join_idle_thread(pid_t pid)
532{
533 kill(pid, SIGTERM);
534 waitpid(pid, NULL, 0);
535}
536
537/*
538 * Test memfd_create() syscall
539 * Verify syscall-argument validation, including name checks, flag validation
540 * and more.
541 */
542static void test_create(void)
543{
544 char buf[2048];
545 int fd;
546
547 /* test NULL name */
548 mfd_fail_new(NULL, 0);
549
550 /* test over-long name (not zero-terminated) */
551 memset(buf, 0xff, sizeof(buf));
552 mfd_fail_new(buf, 0);
553
554 /* test over-long zero-terminated name */
555 memset(buf, 0xff, sizeof(buf));
556 buf[sizeof(buf) - 1] = 0;
557 mfd_fail_new(buf, 0);
558
559 /* verify "" is a valid name */
560 fd = mfd_assert_new("", 0, 0);
561 close(fd);
562
563 /* verify invalid O_* open flags */
564 mfd_fail_new("", 0x0100);
565 mfd_fail_new("", ~MFD_CLOEXEC);
566 mfd_fail_new("", ~MFD_ALLOW_SEALING);
567 mfd_fail_new("", ~0);
568 mfd_fail_new("", 0x80000000U);
569
570 /* verify MFD_CLOEXEC is allowed */
571 fd = mfd_assert_new("", 0, MFD_CLOEXEC);
572 close(fd);
573
574 /* verify MFD_ALLOW_SEALING is allowed */
575 fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING);
576 close(fd);
577
578 /* verify MFD_ALLOW_SEALING | MFD_CLOEXEC is allowed */
579 fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING | MFD_CLOEXEC);
580 close(fd);
581}
582
583/*
584 * Test basic sealing
585 * A very basic sealing test to see whether setting/retrieving seals works.
586 */
587static void test_basic(void)
588{
589 int fd;
590
591 fd = mfd_assert_new("kern_memfd_basic",
592 MFD_DEF_SIZE,
593 MFD_CLOEXEC | MFD_ALLOW_SEALING);
594
595 /* add basic seals */
596 mfd_assert_has_seals(fd, 0);
597 mfd_assert_add_seals(fd, F_SEAL_SHRINK |
598 F_SEAL_WRITE);
599 mfd_assert_has_seals(fd, F_SEAL_SHRINK |
600 F_SEAL_WRITE);
601
602 /* add them again */
603 mfd_assert_add_seals(fd, F_SEAL_SHRINK |
604 F_SEAL_WRITE);
605 mfd_assert_has_seals(fd, F_SEAL_SHRINK |
606 F_SEAL_WRITE);
607
608 /* add more seals and seal against sealing */
609 mfd_assert_add_seals(fd, F_SEAL_GROW | F_SEAL_SEAL);
610 mfd_assert_has_seals(fd, F_SEAL_SHRINK |
611 F_SEAL_GROW |
612 F_SEAL_WRITE |
613 F_SEAL_SEAL);
614
615 /* verify that sealing no longer works */
616 mfd_fail_add_seals(fd, F_SEAL_GROW);
617 mfd_fail_add_seals(fd, 0);
618
619 close(fd);
620
621 /* verify sealing does not work without MFD_ALLOW_SEALING */
622 fd = mfd_assert_new("kern_memfd_basic",
623 MFD_DEF_SIZE,
624 MFD_CLOEXEC);
625 mfd_assert_has_seals(fd, F_SEAL_SEAL);
626 mfd_fail_add_seals(fd, F_SEAL_SHRINK |
627 F_SEAL_GROW |
628 F_SEAL_WRITE);
629 mfd_assert_has_seals(fd, F_SEAL_SEAL);
630 close(fd);
631}
632
633/*
634 * Test SEAL_WRITE
635 * Test whether SEAL_WRITE actually prevents modifications.
636 */
637static void test_seal_write(void)
638{
639 int fd;
640
641 fd = mfd_assert_new("kern_memfd_seal_write",
642 MFD_DEF_SIZE,
643 MFD_CLOEXEC | MFD_ALLOW_SEALING);
644 mfd_assert_has_seals(fd, 0);
645 mfd_assert_add_seals(fd, F_SEAL_WRITE);
646 mfd_assert_has_seals(fd, F_SEAL_WRITE);
647
648 mfd_assert_read(fd);
649 mfd_fail_write(fd);
650 mfd_assert_shrink(fd);
651 mfd_assert_grow(fd);
652 mfd_fail_grow_write(fd);
653
654 close(fd);
655}
656
657/*
658 * Test SEAL_SHRINK
659 * Test whether SEAL_SHRINK actually prevents shrinking
660 */
661static void test_seal_shrink(void)
662{
663 int fd;
664
665 fd = mfd_assert_new("kern_memfd_seal_shrink",
666 MFD_DEF_SIZE,
667 MFD_CLOEXEC | MFD_ALLOW_SEALING);
668 mfd_assert_has_seals(fd, 0);
669 mfd_assert_add_seals(fd, F_SEAL_SHRINK);
670 mfd_assert_has_seals(fd, F_SEAL_SHRINK);
671
672 mfd_assert_read(fd);
673 mfd_assert_write(fd);
674 mfd_fail_shrink(fd);
675 mfd_assert_grow(fd);
676 mfd_assert_grow_write(fd);
677
678 close(fd);
679}
680
681/*
682 * Test SEAL_GROW
683 * Test whether SEAL_GROW actually prevents growing
684 */
685static void test_seal_grow(void)
686{
687 int fd;
688
689 fd = mfd_assert_new("kern_memfd_seal_grow",
690 MFD_DEF_SIZE,
691 MFD_CLOEXEC | MFD_ALLOW_SEALING);
692 mfd_assert_has_seals(fd, 0);
693 mfd_assert_add_seals(fd, F_SEAL_GROW);
694 mfd_assert_has_seals(fd, F_SEAL_GROW);
695
696 mfd_assert_read(fd);
697 mfd_assert_write(fd);
698 mfd_assert_shrink(fd);
699 mfd_fail_grow(fd);
700 mfd_fail_grow_write(fd);
701
702 close(fd);
703}
704
705/*
706 * Test SEAL_SHRINK | SEAL_GROW
707 * Test whether SEAL_SHRINK | SEAL_GROW actually prevents resizing
708 */
709static void test_seal_resize(void)
710{
711 int fd;
712
713 fd = mfd_assert_new("kern_memfd_seal_resize",
714 MFD_DEF_SIZE,
715 MFD_CLOEXEC | MFD_ALLOW_SEALING);
716 mfd_assert_has_seals(fd, 0);
717 mfd_assert_add_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW);
718 mfd_assert_has_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW);
719
720 mfd_assert_read(fd);
721 mfd_assert_write(fd);
722 mfd_fail_shrink(fd);
723 mfd_fail_grow(fd);
724 mfd_fail_grow_write(fd);
725
726 close(fd);
727}
728
729/*
730 * Test sharing via dup()
731 * Test that seals are shared between dupped FDs and they're all equal.
732 */
733static void test_share_dup(void)
734{
735 int fd, fd2;
736
737 fd = mfd_assert_new("kern_memfd_share_dup",
738 MFD_DEF_SIZE,
739 MFD_CLOEXEC | MFD_ALLOW_SEALING);
740 mfd_assert_has_seals(fd, 0);
741
742 fd2 = mfd_assert_dup(fd);
743 mfd_assert_has_seals(fd2, 0);
744
745 mfd_assert_add_seals(fd, F_SEAL_WRITE);
746 mfd_assert_has_seals(fd, F_SEAL_WRITE);
747 mfd_assert_has_seals(fd2, F_SEAL_WRITE);
748
749 mfd_assert_add_seals(fd2, F_SEAL_SHRINK);
750 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
751 mfd_assert_has_seals(fd2, F_SEAL_WRITE | F_SEAL_SHRINK);
752
753 mfd_assert_add_seals(fd, F_SEAL_SEAL);
754 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL);
755 mfd_assert_has_seals(fd2, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL);
756
757 mfd_fail_add_seals(fd, F_SEAL_GROW);
758 mfd_fail_add_seals(fd2, F_SEAL_GROW);
759 mfd_fail_add_seals(fd, F_SEAL_SEAL);
760 mfd_fail_add_seals(fd2, F_SEAL_SEAL);
761
762 close(fd2);
763
764 mfd_fail_add_seals(fd, F_SEAL_GROW);
765 close(fd);
766}
767
768/*
769 * Test sealing with active mmap()s
770 * Modifying seals is only allowed if no other mmap() refs exist.
771 */
772static void test_share_mmap(void)
773{
774 int fd;
775 void *p;
776
777 fd = mfd_assert_new("kern_memfd_share_mmap",
778 MFD_DEF_SIZE,
779 MFD_CLOEXEC | MFD_ALLOW_SEALING);
780 mfd_assert_has_seals(fd, 0);
781
782 /* shared/writable ref prevents sealing WRITE, but allows others */
783 p = mfd_assert_mmap_shared(fd);
784 mfd_fail_add_seals(fd, F_SEAL_WRITE);
785 mfd_assert_has_seals(fd, 0);
786 mfd_assert_add_seals(fd, F_SEAL_SHRINK);
787 mfd_assert_has_seals(fd, F_SEAL_SHRINK);
788 munmap(p, MFD_DEF_SIZE);
789
790 /* readable ref allows sealing */
791 p = mfd_assert_mmap_private(fd);
792 mfd_assert_add_seals(fd, F_SEAL_WRITE);
793 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
794 munmap(p, MFD_DEF_SIZE);
795
796 close(fd);
797}
798
799/*
800 * Test sealing with open(/proc/self/fd/%d)
801 * Via /proc we can get access to a separate file-context for the same memfd.
802 * This is *not* like dup(), but like a real separate open(). Make sure the
803 * semantics are as expected and we correctly check for RDONLY / WRONLY / RDWR.
804 */
805static void test_share_open(void)
806{
807 int fd, fd2;
808
809 fd = mfd_assert_new("kern_memfd_share_open",
810 MFD_DEF_SIZE,
811 MFD_CLOEXEC | MFD_ALLOW_SEALING);
812 mfd_assert_has_seals(fd, 0);
813
814 fd2 = mfd_assert_open(fd, O_RDWR, 0);
815 mfd_assert_add_seals(fd, F_SEAL_WRITE);
816 mfd_assert_has_seals(fd, F_SEAL_WRITE);
817 mfd_assert_has_seals(fd2, F_SEAL_WRITE);
818
819 mfd_assert_add_seals(fd2, F_SEAL_SHRINK);
820 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
821 mfd_assert_has_seals(fd2, F_SEAL_WRITE | F_SEAL_SHRINK);
822
823 close(fd);
824 fd = mfd_assert_open(fd2, O_RDONLY, 0);
825
826 mfd_fail_add_seals(fd, F_SEAL_SEAL);
827 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK);
828 mfd_assert_has_seals(fd2, F_SEAL_WRITE | F_SEAL_SHRINK);
829
830 close(fd2);
831 fd2 = mfd_assert_open(fd, O_RDWR, 0);
832
833 mfd_assert_add_seals(fd2, F_SEAL_SEAL);
834 mfd_assert_has_seals(fd, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL);
835 mfd_assert_has_seals(fd2, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_SEAL);
836
837 close(fd2);
838 close(fd);
839}
840
841/*
842 * Test sharing via fork()
843 * Test whether seal-modifications work as expected with forked childs.
844 */
845static void test_share_fork(void)
846{
847 int fd;
848 pid_t pid;
849
850 fd = mfd_assert_new("kern_memfd_share_fork",
851 MFD_DEF_SIZE,
852 MFD_CLOEXEC | MFD_ALLOW_SEALING);
853 mfd_assert_has_seals(fd, 0);
854
855 pid = spawn_idle_thread(0);
856 mfd_assert_add_seals(fd, F_SEAL_SEAL);
857 mfd_assert_has_seals(fd, F_SEAL_SEAL);
858
859 mfd_fail_add_seals(fd, F_SEAL_WRITE);
860 mfd_assert_has_seals(fd, F_SEAL_SEAL);
861
862 join_idle_thread(pid);
863
864 mfd_fail_add_seals(fd, F_SEAL_WRITE);
865 mfd_assert_has_seals(fd, F_SEAL_SEAL);
866
867 close(fd);
868}
869
870int main(int argc, char **argv)
871{
872 pid_t pid;
873
874 printf("memfd: CREATE\n");
875 test_create();
876 printf("memfd: BASIC\n");
877 test_basic();
878
879 printf("memfd: SEAL-WRITE\n");
880 test_seal_write();
881 printf("memfd: SEAL-SHRINK\n");
882 test_seal_shrink();
883 printf("memfd: SEAL-GROW\n");
884 test_seal_grow();
885 printf("memfd: SEAL-RESIZE\n");
886 test_seal_resize();
887
888 printf("memfd: SHARE-DUP\n");
889 test_share_dup();
890 printf("memfd: SHARE-MMAP\n");
891 test_share_mmap();
892 printf("memfd: SHARE-OPEN\n");
893 test_share_open();
894 printf("memfd: SHARE-FORK\n");
895 test_share_fork();
896
897 /* Run test-suite in a multi-threaded environment with a shared
898 * file-table. */
899 pid = spawn_idle_thread(CLONE_FILES | CLONE_FS | CLONE_VM);
900 printf("memfd: SHARE-DUP (shared file-table)\n");
901 test_share_dup();
902 printf("memfd: SHARE-MMAP (shared file-table)\n");
903 test_share_mmap();
904 printf("memfd: SHARE-OPEN (shared file-table)\n");
905 test_share_open();
906 printf("memfd: SHARE-FORK (shared file-table)\n");
907 test_share_fork();
908 join_idle_thread(pid);
909
910 printf("memfd: DONE\n");
911
912 return 0;
913}
diff --git a/tools/testing/selftests/memfd/run_fuse_test.sh b/tools/testing/selftests/memfd/run_fuse_test.sh
new file mode 100644
index 000000000000..69b930e1e041
--- /dev/null
+++ b/tools/testing/selftests/memfd/run_fuse_test.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2
3if test -d "./mnt" ; then
4 fusermount -u ./mnt
5 rmdir ./mnt
6fi
7
8set -e
9
10mkdir mnt
11./fuse_mnt ./mnt
12./fuse_test ./mnt/memfd
13fusermount -u ./mnt
14rmdir ./mnt
diff --git a/tools/testing/selftests/ptrace/peeksiginfo.c b/tools/testing/selftests/ptrace/peeksiginfo.c
index d46558b1f58d..c34cd8ac8aaa 100644
--- a/tools/testing/selftests/ptrace/peeksiginfo.c
+++ b/tools/testing/selftests/ptrace/peeksiginfo.c
@@ -31,6 +31,10 @@ static int sys_ptrace(int request, pid_t pid, void *addr, void *data)
31#define TEST_SICODE_PRIV -1 31#define TEST_SICODE_PRIV -1
32#define TEST_SICODE_SHARE -2 32#define TEST_SICODE_SHARE -2
33 33
34#ifndef PAGE_SIZE
35#define PAGE_SIZE sysconf(_SC_PAGESIZE)
36#endif
37
34#define err(fmt, ...) \ 38#define err(fmt, ...) \
35 fprintf(stderr, \ 39 fprintf(stderr, \
36 "Error (%s:%d): " fmt, \ 40 "Error (%s:%d): " fmt, \