1 /*
2 * Validate syscallent.h file.
3 *
4 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@strace.io>
5 * Copyright (c) 2015-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 "sysent.h"
13 #include <stdio.h>
14 #include <string.h>
15 #include "scno.h"
16
17 #include "sysent_shorthand_defs.h"
18
19 static const struct_sysent syscallent[] = {
20 #include "syscallent.h"
21 };
22
23 #include "sysent_shorthand_undefs.h"
24
25 DIAG_PUSH_IGNORE_OVERRIDE_INIT
26 typedef const char *pstr_t;
27 static const pstr_t ksyslist[] = {
28 #include "ksysent.h"
29 };
30 DIAG_POP_IGNORE_OVERRIDE_INIT
31
32 int
33 main(void)
34 {
35 int rc = 0;
36
37 for (unsigned int i = 0; i < ARRAY_SIZE(ksyslist); ++i) {
38 if (!ksyslist[i])
39 continue;
40 if (i >= ARRAY_SIZE(syscallent) || !syscallent[i].sys_name) {
41 fprintf(stderr, "warning: \"%s\" syscall #%u"
42 " is missing in syscallent.h\n",
43 ksyslist[i], i);
44 continue;
45 }
46 #ifdef SYS_socket_nsubcalls
47 if (i >= SYS_socket_subcall &&
48 i < SYS_socket_subcall + SYS_socket_nsubcalls) {
49 fprintf(stderr, "error: \"%s\" syscall #%u"
50 " is a socket subcall in syscallent.h\n",
51 ksyslist[i], i);
52 rc = 1;
53 continue;
54 }
55 #endif
56 #ifdef SYS_ipc_nsubcalls
57 if (i >= SYS_ipc_subcall &&
58 i < SYS_ipc_subcall + SYS_ipc_nsubcalls) {
59 fprintf(stderr, "error: \"%s\" syscall #%u"
60 " is an ipc subcall in syscallent.h\n",
61 ksyslist[i], i);
62 rc = 1;
63 continue;
64 }
65 #endif
66 if (strcmp(ksyslist[i], syscallent[i].sys_name)) {
67 fprintf(stderr, "error: \"%s\" syscall #%u"
68 " is \"%s\" in syscallent.h\n",
69 ksyslist[i], i, syscallent[i].sys_name);
70 rc = 1;
71 continue;
72 }
73 }
74
75 for (unsigned int i = 0; i < ARRAY_SIZE(syscallent); ++i) {
76 if (!syscallent[i].sys_name
77 #ifdef SYS_socket_nsubcalls
78 || (i >= SYS_socket_subcall &&
79 i < SYS_socket_subcall + SYS_socket_nsubcalls)
80 #endif
81 #ifdef SYS_ipc_nsubcalls
82 || (i >= SYS_ipc_subcall &&
83 i < SYS_ipc_subcall + SYS_ipc_nsubcalls)
84 #endif
85 #ifdef ARM_FIRST_SHUFFLED_SYSCALL
86 || (i >= ARM_FIRST_SHUFFLED_SYSCALL &&
87 i <= ARM_FIRST_SHUFFLED_SYSCALL +
88 ARM_LAST_SPECIAL_SYSCALL + 1)
89 #endif
90 )
91 continue;
92 if (i >= ARRAY_SIZE(ksyslist) || !ksyslist[i]) {
93 fprintf(stderr, "note: unknown syscall #%u"
94 " is \"%s\" in syscallent.h\n",
95 i, syscallent[i].sys_name);
96 }
97 }
98
99 return rc;
100 }