]> granicus.if.org Git - strace/blob - tests/fsmount.c
Remove XLAT_END
[strace] / tests / fsmount.c
1 /*
2  * Check decoding of fsmount syscall.
3  *
4  * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11 #include "scno.h"
12
13 #ifdef __NR_fsmount
14
15 # include <fcntl.h>
16 # include <stdio.h>
17 # include <stdint.h>
18 # include <unistd.h>
19
20 static const char *errstr;
21
22 static long
23 k_fsmount(const unsigned int fs_fd,
24           const unsigned int flags,
25           const unsigned int attr_flags)
26 {
27         const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
28         const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
29         const kernel_ulong_t arg1 = fill | fs_fd;
30         const kernel_ulong_t arg2 = fill | flags;
31         const kernel_ulong_t arg3 = fill | attr_flags;
32         const long rc = syscall(__NR_fsmount,
33                                 arg1, arg2, arg3, bad, bad, bad);
34         errstr = sprintrc(rc);
35         return rc;
36 }
37
38 int
39 main(void)
40 {
41         skip_if_unavailable("/proc/self/fd/");
42
43         static const char path[] = "/dev/full";
44         int fd = open(path, O_WRONLY);
45         if (fd < 0)
46                 perror_msg_and_fail("open: %s", path);
47
48         struct {
49                 unsigned int val;
50                 const char *str;
51         } flags[] = {
52                 { ARG_STR(0) },
53                 { 1, "FSMOUNT_CLOEXEC" },
54                 { 2, "0x2 /* FSMOUNT_??? */" },
55                 { 0xfffffffe, "0xfffffffe /* FSMOUNT_??? */" },
56                 { -1, "FSMOUNT_CLOEXEC|0xfffffffe" }
57         },
58         attrs[] = {
59                 { ARG_STR(0) },
60                 { 1, "MOUNT_ATTR_RDONLY" },
61                 { 0x10, "MOUNT_ATTR_NOATIME" },
62                 { 0xbf, "MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV"
63                         "|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME"
64                         "|MOUNT_ATTR_STRICTATIME|MOUNT_ATTR_NODIRATIME" },
65                 { 0x40, "0x40 /* MOUNT_ATTR_??? */" },
66                 { 0xffffff40, "0xffffff40 /* MOUNT_ATTR_??? */" },
67                 { -1, "MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV"
68                         "|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME"
69                         "|MOUNT_ATTR_STRICTATIME|MOUNT_ATTR_NODIRATIME"
70                         "|0xffffff40" }
71         };
72
73         for (unsigned int i = 0; i < ARRAY_SIZE(flags); ++i) {
74                 for (unsigned int j = 0; j < ARRAY_SIZE(attrs); ++j) {
75                         k_fsmount(-1, flags[i].val, attrs[j].val);
76                         printf("fsmount(-1, %s, %s) = %s\n",
77                                flags[i].str, attrs[j].str, errstr);
78
79                         k_fsmount(-100, flags[i].val, attrs[j].val);
80                         printf("fsmount(-100, %s, %s) = %s\n",
81                                flags[i].str, attrs[j].str, errstr);
82
83                         k_fsmount(fd, flags[i].val, attrs[j].val);
84                         printf("fsmount(%d<%s>, %s, %s) = %s\n",
85                                fd, path, flags[i].str, attrs[j].str, errstr);
86                 }
87         }
88
89         puts("+++ exited with 0 +++");
90         return 0;
91 }
92
93 #else
94
95 SKIP_MAIN_UNDEFINED("__NR_fsmount")
96
97 #endif