1 /*
2  * Check decoding of fanotify_init syscall.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * Copyright (c) 2016-2017 The strace developers.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "tests.h"
32 
33 #include <asm/unistd.h>
34 
35 #if defined __NR_fanotify_init
36 
37 # include <limits.h>
38 # include <stdio.h>
39 # include <unistd.h>
40 
41 /* Performs fanotify_init call via the syscall interface. */
42 static void
do_call(kernel_ulong_t flags,const char * flags_str,kernel_ulong_t event_f_flags,const char * event_f_flags_str)43 do_call(kernel_ulong_t flags, const char *flags_str,
44 	kernel_ulong_t event_f_flags, const char *event_f_flags_str)
45 {
46 	long rc;
47 
48 	rc = syscall(__NR_fanotify_init, flags, event_f_flags);
49 
50 	printf("fanotify_init(%s, %s) = %s\n",
51 	       flags_str, event_f_flags_str, sprintrc(rc));
52 }
53 
54 struct strval {
55 	kernel_ulong_t val;
56 	const char *str;
57 };
58 
59 
60 int
main(void)61 main(void)
62 {
63 	static const struct strval flags[] = {
64 		{ F8ILL_KULONG_MASK, "FAN_CLASS_NOTIF" },
65 		{ (kernel_ulong_t) 0xffffffff0000000cULL,
66 			"0xc /* FAN_CLASS_??? */" },
67 		{ (kernel_ulong_t) 0xdec0deddefaced04ULL,
68 			"FAN_CLASS_CONTENT|0xefaced00 /* FAN_??? */" },
69 		{ (kernel_ulong_t) 0xffffffffffffffffULL,
70 			"0xc /* FAN_CLASS_??? */|FAN_CLOEXEC|FAN_NONBLOCK|"
71 			"FAN_UNLIMITED_QUEUE|FAN_UNLIMITED_MARKS|0xffffffc0" },
72 	};
73 	static const struct strval event_f_flags[] = {
74 		{ F8ILL_KULONG_MASK, "O_RDONLY" },
75 		{ (kernel_ulong_t) 0xdeadbeef80000001ULL,
76 			"O_WRONLY|0x80000000" }
77 	};
78 
79 	unsigned int i;
80 	unsigned int j;
81 
82 
83 	for (i = 0; i < ARRAY_SIZE(flags); i++)
84 		for (j = 0; j < ARRAY_SIZE(event_f_flags); j++)
85 			do_call(flags[i].val, flags[i].str,
86 				event_f_flags[j].val, event_f_flags[j].str);
87 
88 	puts("+++ exited with 0 +++");
89 	return 0;
90 }
91 
92 #else
93 
94 SKIP_MAIN_UNDEFINED("__NR_fanotify_init")
95 
96 #endif
97