1294849Sjhb/*-
2294849Sjhb * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
3294849Sjhb *
4294849Sjhb * Redistribution and use in source and binary forms, with or without
5294849Sjhb * modification, are permitted provided that the following conditions
6294849Sjhb * are met:
7294849Sjhb * 1. Redistributions of source code must retain the above copyright
8294849Sjhb *    notice, this list of conditions and the following disclaimer.
9294849Sjhb * 2. Redistributions in binary form must reproduce the above copyright
10294849Sjhb *    notice, this list of conditions and the following disclaimer in the
11294849Sjhb *    documentation and/or other materials provided with the distribution.
12294849Sjhb *
13294849Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14294849Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15294849Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16294849Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17294849Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18294849Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19294849Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20294849Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21294849Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22294849Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23294849Sjhb * SUCH DAMAGE.
24294849Sjhb */
25294849Sjhb
26294849Sjhb#include <sys/cdefs.h>
27294849Sjhb__FBSDID("$FreeBSD: stable/11/lib/libsysdecode/syscallnames.c 367457 2020-11-07 18:10:59Z dim $");
28294849Sjhb
29294849Sjhb/*
30294849Sjhb * Map system call codes to names for the supported ABIs on each
31294849Sjhb * platform.  Rather than regnerating system call name tables locally
32294849Sjhb * during the build, use the generated tables in the kernel source
33294849Sjhb * tree.
34294849Sjhb */
35294849Sjhb
36294849Sjhb#include <sys/param.h>
37311999Sjhb#include <sys/acl.h>
38311999Sjhb#include <sys/wait.h>
39311999Sjhb#include <stdbool.h>
40294849Sjhb#include <stdio.h>
41294849Sjhb#include <sysdecode.h>
42294849Sjhb
43294849Sjhbstatic
44294849Sjhb#include <kern/syscalls.c>
45294849Sjhb
46294849Sjhb#if defined(__amd64__) || defined(__powerpc64__)
47294849Sjhbstatic
48294849Sjhb#include <compat/freebsd32/freebsd32_syscalls.c>
49294849Sjhb#endif
50294849Sjhb
51294849Sjhb#if defined(__amd64__) || defined(__i386__)
52294849Sjhbstatic
53294849Sjhb#ifdef __amd64__
54294849Sjhb#include <amd64/linux/linux_syscalls.c>
55294849Sjhb#else
56294849Sjhb#include <i386/linux/linux_syscalls.c>
57294849Sjhb#endif
58294849Sjhb#endif
59294849Sjhb
60294849Sjhb#ifdef __amd64__
61294849Sjhbstatic
62294849Sjhb#include <amd64/linux32/linux32_syscalls.c>
63294849Sjhb#endif
64294849Sjhb
65294849Sjhb#if defined(__amd64__) || defined(__aarch64__)
66294849Sjhbstatic
67294849Sjhb#include <compat/cloudabi64/cloudabi64_syscalls.c>
68294849Sjhb#endif
69294849Sjhb
70294849Sjhbconst char *
71294849Sjhbsysdecode_syscallname(enum sysdecode_abi abi, unsigned int code)
72294849Sjhb{
73294849Sjhb
74294849Sjhb	switch (abi) {
75295056Sjhb	case SYSDECODE_ABI_FREEBSD:
76294849Sjhb		if (code < nitems(syscallnames))
77294849Sjhb			return (syscallnames[code]);
78294849Sjhb		break;
79294849Sjhb#if defined(__amd64__) || defined(__powerpc64__)
80295056Sjhb	case SYSDECODE_ABI_FREEBSD32:
81294849Sjhb		if (code < nitems(freebsd32_syscallnames))
82294849Sjhb			return (freebsd32_syscallnames[code]);
83294849Sjhb		break;
84294849Sjhb#endif
85294849Sjhb#if defined(__amd64__) || defined(__i386__)
86295056Sjhb	case SYSDECODE_ABI_LINUX:
87294849Sjhb		if (code < nitems(linux_syscallnames))
88294849Sjhb			return (linux_syscallnames[code]);
89294849Sjhb		break;
90294849Sjhb#endif
91294849Sjhb#ifdef __amd64__
92295056Sjhb	case SYSDECODE_ABI_LINUX32:
93294849Sjhb		if (code < nitems(linux32_syscallnames))
94294849Sjhb			return (linux32_syscallnames[code]);
95294849Sjhb		break;
96294849Sjhb#endif
97294849Sjhb#if defined(__amd64__) || defined(__aarch64__)
98295056Sjhb	case SYSDECODE_ABI_CLOUDABI64:
99294849Sjhb		if (code < nitems(cloudabi64_syscallnames))
100294849Sjhb			return (cloudabi64_syscallnames[code]);
101294849Sjhb		break;
102294849Sjhb#endif
103294849Sjhb	default:
104294849Sjhb		break;
105294849Sjhb	}
106294849Sjhb	return (NULL);
107294849Sjhb}
108