1 /*
2 * Check decoding of fanotify_init syscall.
3 *
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016-2022 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13
14 #include <limits.h>
15 #include <stdio.h>
16 #include <unistd.h>
17
18 /* Performs fanotify_init call via the syscall interface. */
19 static void
20 do_call(kernel_ulong_t flags, const char *flags_str,
21 kernel_ulong_t event_f_flags, const char *event_f_flags_str)
22 {
23 long rc;
24
25 rc = syscall(__NR_fanotify_init, flags, event_f_flags);
26
27 printf("fanotify_init(%s, %s) = %s\n",
28 flags_str, event_f_flags_str, sprintrc(rc));
29 }
30
31 struct strval {
32 kernel_ulong_t val;
33 const char *str;
34 };
35
36
37 int
38 main(void)
39 {
40 static const struct strval flags[] = {
41 { F8ILL_KULONG_MASK, "FAN_CLASS_NOTIF" },
42 { (kernel_ulong_t) 0xffffffff0000000cULL,
43 "0xc /* FAN_CLASS_??? */" },
44 { (kernel_ulong_t) 0xdec0deddeface004ULL,
45 "FAN_CLASS_CONTENT|0xeface000 /* FAN_??? */" },
46 { (kernel_ulong_t) 0xffffffffffffffffULL,
47 "0xc /* FAN_CLASS_??? */|FAN_CLOEXEC|FAN_NONBLOCK|"
48 "FAN_UNLIMITED_QUEUE|FAN_UNLIMITED_MARKS|"
49 "FAN_ENABLE_AUDIT|FAN_REPORT_PIDFD|FAN_REPORT_TID|"
50 "FAN_REPORT_FID|FAN_REPORT_DIR_FID|FAN_REPORT_NAME|"
51 "FAN_REPORT_TARGET_FID|0xffffe000" },
52 };
53 static const struct strval event_f_flags[] = {
54 { F8ILL_KULONG_MASK, "O_RDONLY" },
55 { (kernel_ulong_t) 0xdeadbeef80000001ULL,
56 "O_WRONLY|0x80000000" }
57 };
58
59 for (unsigned int i = 0; i < ARRAY_SIZE(flags); ++i)
60 for (unsigned int j = 0; j < ARRAY_SIZE(event_f_flags); ++j)
61 do_call(flags[i].val, flags[i].str,
62 event_f_flags[j].val, event_f_flags[j].str);
63
64 puts("+++ exited with 0 +++");
65 return 0;
66 }