• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Validate syscallent.h file.
3  *
4  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "tests.h"
31 #include "sysent.h"
32 #include <stdio.h>
33 #include <string.h>
34 #include <asm/unistd.h>
35 
36 #define TD 0
37 #define TF 0
38 #define TI 0
39 #define TN 0
40 #define TP 0
41 #define TS 0
42 #define TM 0
43 #define NF 0
44 #define MA 0
45 #define SI 0
46 #define SE 0
47 #define CST 0
48 #define SEN(arg) 0,0
49 
50 static const struct_sysent syscallent[] = {
51 #include "syscallent.h"
52 };
53 
54 typedef const char *pstr_t;
55 static const pstr_t ksyslist[] = {
56 #include "ksysent.h"
57 };
58 
59 int
main(void)60 main(void)
61 {
62 	int rc = 0;
63 	unsigned int i;
64 
65 	for (i = 0; i < ARRAY_SIZE(ksyslist); ++i) {
66 		if (!ksyslist[i])
67 			continue;
68 		if (i >= ARRAY_SIZE(syscallent) || !syscallent[i].sys_name) {
69 			fprintf(stderr, "warning: \"%s\" syscall #%u"
70 				" is missing in syscallent.h\n",
71 				ksyslist[i], i);
72 			continue;
73 		}
74 #ifdef SYS_socket_nsubcalls
75 		if (i >= SYS_socket_subcall &&
76 		    i < SYS_socket_subcall + SYS_socket_nsubcalls) {
77 			fprintf(stderr, "error: \"%s\" syscall #%u"
78 				" is a socket subcall in syscallent.h\n",
79 				ksyslist[i], i);
80 			rc = 1;
81 			continue;
82 		}
83 #endif
84 #ifdef SYS_ipc_nsubcalls
85 		if (i >= SYS_ipc_subcall &&
86 		    i < SYS_ipc_subcall + SYS_ipc_nsubcalls) {
87 			fprintf(stderr, "error: \"%s\" syscall #%u"
88 				" is an ipc subcall in syscallent.h\n",
89 				ksyslist[i], i);
90 			rc = 1;
91 			continue;
92 		}
93 #endif
94 		if (strcmp(ksyslist[i], syscallent[i].sys_name)) {
95 			fprintf(stderr, "error: \"%s\" syscall #%u"
96 				" is \"%s\" in syscallent.h\n",
97 				ksyslist[i], i, syscallent[i].sys_name);
98 			rc = 1;
99 			continue;
100 		}
101 	}
102 
103 	for (i = 0; i < ARRAY_SIZE(syscallent); ++i) {
104 		if (!syscallent[i].sys_name
105 #ifdef SYS_socket_nsubcalls
106 		    || (i >= SYS_socket_subcall &&
107 			i < SYS_socket_subcall + SYS_socket_nsubcalls)
108 #endif
109 #ifdef SYS_ipc_nsubcalls
110 		    || (i >= SYS_ipc_subcall &&
111 			i < SYS_ipc_subcall + SYS_ipc_nsubcalls)
112 #endif
113 #ifdef ARM_FIRST_SHUFFLED_SYSCALL
114 		    || (i >= ARM_FIRST_SHUFFLED_SYSCALL &&
115 			i <= ARM_FIRST_SHUFFLED_SYSCALL +
116 			    ARM_LAST_SPECIAL_SYSCALL + 1)
117 #endif
118 		   )
119 			continue;
120 		if (i >= ARRAY_SIZE(ksyslist) || !ksyslist[i]) {
121 			fprintf(stderr, "note: unknown syscall #%u"
122 				" is \"%s\" in syscallent.h\n",
123 				i, syscallent[i].sys_name);
124 		}
125 	}
126 
127 	return rc;
128 }
129