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#define TD 0
38#define TF 0
39#define TI 0
40#define TN 0
41#define TP 0
42#define TS 0
43#define TM 0
44#define TST 0
45#define TLST 0
46#define TFST 0
47#define TSTA 0
48#define TSF 0
49#define TFSF 0
50#define TSFA 0
51#define NF 0
52#define MA 0
53#define SI 0
54#define SE 0
55#define CST 0
56#define SEN(arg) 0, 0
57
58static const struct_sysent syscallent[] = {
59#include "syscallent.h"
60};
61
62typedef const char *pstr_t;
63static const pstr_t ksyslist[] = {
64#include "ksysent.h"
65};
66
67int
68main(void)
69{
70	int rc = 0;
71	unsigned int i;
72
73	for (i = 0; i < ARRAY_SIZE(ksyslist); ++i) {
74		if (!ksyslist[i])
75			continue;
76		if (i >= ARRAY_SIZE(syscallent) || !syscallent[i].sys_name) {
77			fprintf(stderr, "warning: \"%s\" syscall #%u"
78				" is missing in syscallent.h\n",
79				ksyslist[i], i);
80			continue;
81		}
82#ifdef SYS_socket_nsubcalls
83		if (i >= SYS_socket_subcall &&
84		    i < SYS_socket_subcall + SYS_socket_nsubcalls) {
85			fprintf(stderr, "error: \"%s\" syscall #%u"
86				" is a socket subcall in syscallent.h\n",
87				ksyslist[i], i);
88			rc = 1;
89			continue;
90		}
91#endif
92#ifdef SYS_ipc_nsubcalls
93		if (i >= SYS_ipc_subcall &&
94		    i < SYS_ipc_subcall + SYS_ipc_nsubcalls) {
95			fprintf(stderr, "error: \"%s\" syscall #%u"
96				" is an ipc subcall in syscallent.h\n",
97				ksyslist[i], i);
98			rc = 1;
99			continue;
100		}
101#endif
102		if (strcmp(ksyslist[i], syscallent[i].sys_name)) {
103			fprintf(stderr, "error: \"%s\" syscall #%u"
104				" is \"%s\" in syscallent.h\n",
105				ksyslist[i], i, syscallent[i].sys_name);
106			rc = 1;
107			continue;
108		}
109	}
110
111	for (i = 0; i < ARRAY_SIZE(syscallent); ++i) {
112		if (!syscallent[i].sys_name
113#ifdef SYS_socket_nsubcalls
114		    || (i >= SYS_socket_subcall &&
115			i < SYS_socket_subcall + SYS_socket_nsubcalls)
116#endif
117#ifdef SYS_ipc_nsubcalls
118		    || (i >= SYS_ipc_subcall &&
119			i < SYS_ipc_subcall + SYS_ipc_nsubcalls)
120#endif
121#ifdef ARM_FIRST_SHUFFLED_SYSCALL
122		    || (i >= ARM_FIRST_SHUFFLED_SYSCALL &&
123			i <= ARM_FIRST_SHUFFLED_SYSCALL +
124			    ARM_LAST_SPECIAL_SYSCALL + 1)
125#endif
126		   )
127			continue;
128		if (i >= ARRAY_SIZE(ksyslist) || !ksyslist[i]) {
129			fprintf(stderr, "note: unknown syscall #%u"
130				" is \"%s\" in syscallent.h\n",
131				i, syscallent[i].sys_name);
132		}
133	}
134
135	return rc;
136}
137