Bundle libseccomp 2.3.1
[linux-seccomp.git] / libseccomp / src / arch-syscall-dump.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 <errno.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <ctype.h>
27#include <string.h>
28#include <unistd.h>
29
30#include <seccomp.h>
31
32#include "arch.h"
33#include "arch-x86.h"
34#include "arch-x86_64.h"
35#include "arch-x32.h"
36#include "arch-arm.h"
37#include "arch-mips.h"
38#include "arch-mips64.h"
39#include "arch-mips64n32.h"
40#include "arch-aarch64.h"
41#include "arch-ppc.h"
42#include "arch-ppc64.h"
43#include "arch-s390.h"
44#include "arch-s390x.h"
45
46/**
47 * Print the usage information to stderr and exit
48 * @param program the name of the current program being invoked
49 *
50 * Print the usage information and exit with EINVAL.
51 *
52 */
53static void exit_usage(const char *program)
54{
55 fprintf(stderr, "usage: %s [-h] [-a <arch>] [-o <offset>]\n", program);
56 exit(EINVAL);
57}
58
59/**
60 * main
61 */
62int main(int argc, char *argv[])
63{
64 int opt;
65 const struct arch_def *arch = arch_def_native;
66 int offset = 0;
67 int iter;
68 int sys_num;
69 const char *sys_name;
70
71 /* parse the command line */
72 while ((opt = getopt(argc, argv, "a:o:h")) > 0) {
73 switch (opt) {
74 case 'a':
75 arch = arch_def_lookup_name(optarg);
76 if (arch == 0)
77 exit_usage(argv[0]);
78 break;
79 case 'o':
80 offset = atoi(optarg);
81 break;
82 case 'h':
83 default:
84 /* usage information */
85 exit_usage(argv[0]);
86 }
87 }
88
89 iter = 0;
90 do {
91 switch (arch->token) {
92 case SCMP_ARCH_X86:
93 sys_name = x86_syscall_iterate_name(iter);
94 break;
95 case SCMP_ARCH_X86_64:
96 sys_name = x86_64_syscall_iterate_name(iter);
97 break;
98 case SCMP_ARCH_X32:
99 sys_name = x32_syscall_iterate_name(iter);
100 break;
101 case SCMP_ARCH_ARM:
102 sys_name = arm_syscall_iterate_name(iter);
103 break;
104 case SCMP_ARCH_AARCH64:
105 sys_name = aarch64_syscall_iterate_name(iter);
106 break;
107 case SCMP_ARCH_MIPS:
108 case SCMP_ARCH_MIPSEL:
109 sys_name = mips_syscall_iterate_name(iter);
110 break;
111 case SCMP_ARCH_MIPS64:
112 case SCMP_ARCH_MIPSEL64:
113 sys_name = mips64_syscall_iterate_name(iter);
114 break;
115 case SCMP_ARCH_MIPS64N32:
116 case SCMP_ARCH_MIPSEL64N32:
117 sys_name = mips64n32_syscall_iterate_name(iter);
118 break;
119 case SCMP_ARCH_PPC:
120 sys_name = ppc_syscall_iterate_name(iter);
121 break;
122 case SCMP_ARCH_PPC64:
123 case SCMP_ARCH_PPC64LE:
124 sys_name = ppc64_syscall_iterate_name(iter);
125 break;
126 case SCMP_ARCH_S390:
127 sys_name = s390_syscall_iterate_name(iter);
128 break;
129 case SCMP_ARCH_S390X:
130 sys_name = s390x_syscall_iterate_name(iter);
131 break;
132 default:
133 /* invalid arch */
134 exit_usage(argv[0]);
135 }
136 if (sys_name != NULL) {
137 sys_num = arch_syscall_resolve_name(arch, sys_name);
138 if (offset > 0 && sys_num > 0)
139 sys_num -= offset;
140
141 /* output the results */
142 printf("%s\t%d\n", sys_name, sys_num);
143
144 /* next */
145 iter++;
146 }
147 } while (sys_name != NULL);
148
149 return 0;
150}
This page took 0.016893 seconds and 4 git commands to generate.