1 /*
2  * Validate syscallent.h file.
3  *
4  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2015-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 #include "sysent.h"
33 #include <stdio.h>
34 #include <string.h>
35 #include <asm/unistd.h>
36 
37 #include "sysent_shorthand_defs.h"
38 
39 static const struct_sysent syscallent[] = {
40 #include "syscallent.h"
41 };
42 
43 #include "sysent_shorthand_undefs.h"
44 
45 typedef const char *pstr_t;
46 static const pstr_t ksyslist[] = {
47 #include "ksysent.h"
48 };
49 
50 int
main(void)51 main(void)
52 {
53 	int rc = 0;
54 	unsigned int i;
55 
56 	for (i = 0; i < ARRAY_SIZE(ksyslist); ++i) {
57 		if (!ksyslist[i])
58 			continue;
59 		if (i >= ARRAY_SIZE(syscallent) || !syscallent[i].sys_name) {
60 			fprintf(stderr, "warning: \"%s\" syscall #%u"
61 				" is missing in syscallent.h\n",
62 				ksyslist[i], i);
63 			continue;
64 		}
65 #ifdef SYS_socket_nsubcalls
66 		if (i >= SYS_socket_subcall &&
67 		    i < SYS_socket_subcall + SYS_socket_nsubcalls) {
68 			fprintf(stderr, "error: \"%s\" syscall #%u"
69 				" is a socket subcall in syscallent.h\n",
70 				ksyslist[i], i);
71 			rc = 1;
72 			continue;
73 		}
74 #endif
75 #ifdef SYS_ipc_nsubcalls
76 		if (i >= SYS_ipc_subcall &&
77 		    i < SYS_ipc_subcall + SYS_ipc_nsubcalls) {
78 			fprintf(stderr, "error: \"%s\" syscall #%u"
79 				" is an ipc subcall in syscallent.h\n",
80 				ksyslist[i], i);
81 			rc = 1;
82 			continue;
83 		}
84 #endif
85 		if (strcmp(ksyslist[i], syscallent[i].sys_name)) {
86 			fprintf(stderr, "error: \"%s\" syscall #%u"
87 				" is \"%s\" in syscallent.h\n",
88 				ksyslist[i], i, syscallent[i].sys_name);
89 			rc = 1;
90 			continue;
91 		}
92 	}
93 
94 	for (i = 0; i < ARRAY_SIZE(syscallent); ++i) {
95 		if (!syscallent[i].sys_name
96 #ifdef SYS_socket_nsubcalls
97 		    || (i >= SYS_socket_subcall &&
98 			i < SYS_socket_subcall + SYS_socket_nsubcalls)
99 #endif
100 #ifdef SYS_ipc_nsubcalls
101 		    || (i >= SYS_ipc_subcall &&
102 			i < SYS_ipc_subcall + SYS_ipc_nsubcalls)
103 #endif
104 #ifdef ARM_FIRST_SHUFFLED_SYSCALL
105 		    || (i >= ARM_FIRST_SHUFFLED_SYSCALL &&
106 			i <= ARM_FIRST_SHUFFLED_SYSCALL +
107 			    ARM_LAST_SPECIAL_SYSCALL + 1)
108 #endif
109 		   )
110 			continue;
111 		if (i >= ARRAY_SIZE(ksyslist) || !ksyslist[i]) {
112 			fprintf(stderr, "note: unknown syscall #%u"
113 				" is \"%s\" in syscallent.h\n",
114 				i, syscallent[i].sys_name);
115 		}
116 	}
117 
118 	return rc;
119 }
120