Bundle libseccomp 2.3.1
[linux-seccomp.git] / libseccomp / src / arch-syscall-check.c
CommitLineData
8befd5cc
MG
1/**
2 * Enhanced Seccomp Architecture Sycall Checker
3 *
4 * Copyright (c) 2014 Red Hat <pmoore@redhat.com>
5 * Author: Paul Moore <paul@paul-moore.com>
6 *
7 */
8
9/*
10 * This library is free software; you can redistribute it and/or modify it
11 * under the terms of version 2.1 of the GNU Lesser General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, see <http://www.gnu.org/licenses>.
21 */
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26
27#include "arch.h"
28#include "arch-x86.h"
29#include "arch-x86_64.h"
30#include "arch-x32.h"
31#include "arch-arm.h"
32#include "arch-aarch64.h"
33#include "arch-mips.h"
34#include "arch-mips64.h"
35#include "arch-mips64n32.h"
36#include "arch-ppc.h"
37#include "arch-ppc64.h"
38#include "arch-s390.h"
39#include "arch-s390x.h"
40
41/**
42 * compare the syscall values
43 * @param str_miss the other bad architectures
44 * @param syscall the syscall string to compare against
45 * @param arch_name the name of the arch being tested
46 * @param arch_sys the syscall name to compare
47 *
48 * Compare the syscall names and update @str_miss if necessary.
49 *
50 */
51void syscall_check(char *str_miss, const char *syscall,
52 const char *arch_name, const char *arch_sys)
53{
54 if (strcmp(syscall, arch_sys)) {
55 if (str_miss[0] != '\0')
56 strcat(str_miss, ",");
57 strcat(str_miss, arch_name);
58 }
59}
60
61/**
62 * main
63 */
64int main(int argc, char *argv[])
65{
66 int i_x86 = 0;
67 int i_x86_64 = 0;
68 int i_x32 = 0;
69 int i_arm = 0;
70 int i_aarch64 = 0;
71 int i_mips = 0;
72 int i_mips64 = 0;
73 int i_mips64n32 = 0;
74 int i_ppc = 0;
75 int i_ppc64 = 0;
76 int i_s390 = 0;
77 int i_s390x = 0;
78 const char *sys_name;
79 char str_miss[256];
80
81 do {
82 str_miss[0] = '\0';
83 sys_name = x86_syscall_iterate_name(i_x86);
84 if (sys_name == NULL) {
85 printf("FAULT\n");
86 return 1;
87 }
88
89 /* check each arch using x86 as the reference */
90 syscall_check(str_miss, sys_name, "x86_64",
91 x86_64_syscall_iterate_name(i_x86_64));
92 syscall_check(str_miss, sys_name, "x32",
93 x32_syscall_iterate_name(i_x32));
94 syscall_check(str_miss, sys_name, "arm",
95 arm_syscall_iterate_name(i_arm));
96 syscall_check(str_miss, sys_name, "aarch64",
97 aarch64_syscall_iterate_name(i_aarch64));
98 syscall_check(str_miss, sys_name, "mips",
99 mips_syscall_iterate_name(i_mips));
100 syscall_check(str_miss, sys_name, "mips64",
101 mips64_syscall_iterate_name(i_mips64));
102 syscall_check(str_miss, sys_name, "mips64n32",
103 mips64n32_syscall_iterate_name(i_mips64n32));
104 syscall_check(str_miss, sys_name, "ppc",
105 ppc_syscall_iterate_name(i_ppc));
106 syscall_check(str_miss, sys_name, "ppc64",
107 ppc64_syscall_iterate_name(i_ppc64));
108 syscall_check(str_miss, sys_name, "s390",
109 s390_syscall_iterate_name(i_s390));
110 syscall_check(str_miss, sys_name, "s390x",
111 s390x_syscall_iterate_name(i_s390x));
112
113 /* output the results */
114 printf("%s: ", sys_name);
115 if (str_miss[0] != '\0') {
116 printf("MISS(%s)\n", str_miss);
117 return 1;
118 } else
119 printf("OK\n");
120
121 /* next */
122 if (x86_syscall_iterate_name(i_x86 + 1))
123 i_x86++;
124 if (!x86_64_syscall_iterate_name(++i_x86_64))
125 i_x86_64 = -1;
126 if (!x32_syscall_iterate_name(++i_x32))
127 i_x32 = -1;
128 if (!arm_syscall_iterate_name(++i_arm))
129 i_arm = -1;
130 if (!aarch64_syscall_iterate_name(++i_aarch64))
131 i_aarch64 = -1;
132 if (!mips_syscall_iterate_name(++i_mips))
133 i_mips = -1;
134 if (!mips64_syscall_iterate_name(++i_mips64))
135 i_mips64 = -1;
136 if (!mips64n32_syscall_iterate_name(++i_mips64n32))
137 i_mips64n32 = -1;
138 if (!ppc_syscall_iterate_name(++i_ppc))
139 i_ppc = -1;
140 if (!ppc64_syscall_iterate_name(++i_ppc64))
141 i_ppc64 = -1;
142 if (!s390_syscall_iterate_name(++i_s390))
143 i_s390 = -1;
144 if (!s390x_syscall_iterate_name(++i_s390x))
145 i_s390x = -1;
146 } while (i_x86_64 >= 0 && i_x32 >= 0 &&
147 i_arm >= 0 && i_aarch64 >= 0 &&
148 i_mips >= 0 && i_mips64 >= 0 && i_mips64n32 >= 0 &&
149 i_ppc >= 0 && i_ppc64 >= 0 &&
150 i_s390 >= 0 && i_s390x >= 0);
151
152 /* check for any leftovers */
153 sys_name = x86_syscall_iterate_name(i_x86 + 1);
154 if (sys_name) {
155 printf("%s: ERROR, x86 has additional syscalls\n", sys_name);
156 return 1;
157 }
158 if (i_x86_64 >= 0) {
159 printf("%s: ERROR, x86_64 has additional syscalls\n",
160 x86_64_syscall_iterate_name(i_x86_64));
161 return 1;
162 }
163 if (i_x32 >= 0) {
164 printf("%s: ERROR, x32 has additional syscalls\n",
165 x32_syscall_iterate_name(i_x32));
166 return 1;
167 }
168 if (i_arm >= 0) {
169 printf("%s: ERROR, arm has additional syscalls\n",
170 arm_syscall_iterate_name(i_arm));
171 return 1;
172 }
173 if (i_aarch64 >= 0) {
174 printf("%s: ERROR, aarch64 has additional syscalls\n",
175 aarch64_syscall_iterate_name(i_aarch64));
176 return 1;
177 }
178 if (i_mips >= 0) {
179 printf("%s: ERROR, mips has additional syscalls\n",
180 mips_syscall_iterate_name(i_mips));
181 return 1;
182 }
183 if (i_mips64 >= 0) {
184 printf("%s: ERROR, mips64 has additional syscalls\n",
185 mips64_syscall_iterate_name(i_mips64));
186 return 1;
187 }
188 if (i_mips64n32 >= 0) {
189 printf("%s: ERROR, mips64n32 has additional syscalls\n",
190 mips64n32_syscall_iterate_name(i_mips64n32));
191 return 1;
192 }
193 if (i_ppc >= 0) {
194 printf("%s: ERROR, ppc has additional syscalls\n",
195 ppc_syscall_iterate_name(i_ppc));
196 }
197 if (i_ppc64 >= 0) {
198 printf("%s: ERROR, ppc64 has additional syscalls\n",
199 ppc64_syscall_iterate_name(i_ppc64));
200 return 1;
201 }
202 if (i_s390 >= 0) {
203 printf("%s: ERROR, s390 has additional syscalls\n",
204 s390_syscall_iterate_name(i_s390));
205 return 1;
206 }
207 if (i_s390x >= 0) {
208 printf("%s: ERROR, s390x has additional syscalls\n",
209 s390x_syscall_iterate_name(i_s390x));
210 return 1;
211 }
212
213 /* if we made it here, all is good */
214 return 0;
215}
This page took 0.021591 seconds and 4 git commands to generate.