From a5f14abfd231777ed4f1ab2e7d4aeeb4418156f2 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 26 Jan 2016 19:07:09 +0000 Subject: [PATCH] Add support to libsysdecode for decoding system call names. A new sysdecode_syscallname() function accepts a system call code and returns a string of the corresponding name (or NULL if the code is unknown). To support different process ABIs, the new function accepts a value from a new sysdecode_abi enum as its first argument to select the ABI in use. Current ABIs supported include FREEBSD (native binaries), FREEBSD32, LINUX, LINUX32, and CLOUDABI64. Note that not all ABIs are supported by all platforms. In general, a given ABI is only supported if a platform can execute binaries for that ABI. To simplify the implementation, libsysdecode's build reuses the existing pre-generated files from the kernel source tree rather than duplicating new copies of said files during the build. kdump(1) and truss(1) now use these functions to map system call identifiers to names. For kdump(1), a new 'syscallname()' function consolidates duplicated code from ktrsyscall() and ktrsyscallret(). The Linux ABI no longer requires custom handling for ktrsyscall() and linux_ktrsyscall() has been removed as a result. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D4823 --- lib/libsysdecode/Makefile | 9 +- lib/libsysdecode/syscallnames.c | 105 +++++++++++++++++ lib/libsysdecode/sysdecode.3 | 28 ++++- lib/libsysdecode/sysdecode.h | 10 ++ lib/libsysdecode/sysdecode_syscallnames.3 | 67 +++++++++++ usr.bin/kdump/Makefile | 19 --- usr.bin/kdump/kdump.c | 136 ++++++++-------------- usr.bin/truss/Makefile | 23 +--- usr.bin/truss/aarch64-cloudabi64.c | 5 +- usr.bin/truss/aarch64-freebsd.c | 6 +- usr.bin/truss/amd64-cloudabi64.c | 5 +- usr.bin/truss/amd64-freebsd.c | 6 +- usr.bin/truss/amd64-freebsd32.c | 9 +- usr.bin/truss/amd64-linux32.c | 6 +- usr.bin/truss/arm-freebsd.c | 6 +- usr.bin/truss/i386-freebsd.c | 9 +- usr.bin/truss/i386-linux.c | 6 +- usr.bin/truss/main.c | 1 + usr.bin/truss/mips-freebsd.c | 6 +- usr.bin/truss/powerpc-freebsd.c | 6 +- usr.bin/truss/powerpc64-freebsd.c | 6 +- usr.bin/truss/powerpc64-freebsd32.c | 6 +- usr.bin/truss/setup.c | 4 +- usr.bin/truss/sparc64-freebsd.c | 6 +- usr.bin/truss/truss.h | 3 +- 25 files changed, 300 insertions(+), 193 deletions(-) create mode 100644 lib/libsysdecode/syscallnames.c create mode 100644 lib/libsysdecode/sysdecode_syscallnames.3 diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile index a6d3ba13961c..e1e69fef64e8 100644 --- a/lib/libsysdecode/Makefile +++ b/lib/libsysdecode/Makefile @@ -4,11 +4,14 @@ LIB= sysdecode -SRCS= ioctl.c utrace.c +SRCS= ioctl.c syscallnames.c utrace.c INCS= sysdecode.h +CFLAGS+= -I${.CURDIR}/../../sys + MAN+= sysdecode.3 \ sysdecode_ioctlname.3 \ + sysdecode_syscallnames.3 \ sysdecode_utrace.3 CLEANFILES= ioctl.c @@ -23,6 +26,10 @@ CFLAGS+=-DPF # Workaround duplicate declarations in CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls + +# Workaround warning for unused ssi_cables[] in +CFLAGS.gcc.ioctl.c+= -Wno-unused + CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}} ioctl.c: mkioctls diff --git a/lib/libsysdecode/syscallnames.c b/lib/libsysdecode/syscallnames.c new file mode 100644 index 000000000000..cfe50a6a6ea9 --- /dev/null +++ b/lib/libsysdecode/syscallnames.c @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 2015 John H. Baldwin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Map system call codes to names for the supported ABIs on each + * platform. Rather than regnerating system call name tables locally + * during the build, use the generated tables in the kernel source + * tree. + */ + +#include +#include +#include + +static +#include + +#if defined(__amd64__) || defined(__powerpc64__) +static +#include +#endif + +#if defined(__amd64__) || defined(__i386__) +static +#ifdef __amd64__ +#include +#else +#include +#endif +#endif + +#ifdef __amd64__ +static +#include +#endif + +#if defined(__amd64__) || defined(__aarch64__) +static +#include +#endif + +const char * +sysdecode_syscallname(enum sysdecode_abi abi, unsigned int code) +{ + + switch (abi) { + case FREEBSD: + if (code < nitems(syscallnames)) + return (syscallnames[code]); + break; +#if defined(__amd64__) || defined(__powerpc64__) + case FREEBSD32: + if (code < nitems(freebsd32_syscallnames)) + return (freebsd32_syscallnames[code]); + break; +#endif +#if defined(__amd64__) || defined(__i386__) + case LINUX: + if (code < nitems(linux_syscallnames)) + return (linux_syscallnames[code]); + break; +#endif +#ifdef __amd64__ + case LINUX32: + if (code < nitems(linux32_syscallnames)) + return (linux32_syscallnames[code]); + break; +#endif +#if defined(__amd64__) || defined(__aarch64__) + case CLOUDABI64: + if (code < nitems(cloudabi64_syscallnames)) + return (cloudabi64_syscallnames[code]); + break; +#endif + default: + break; + } + return (NULL); +} diff --git a/lib/libsysdecode/sysdecode.3 b/lib/libsysdecode/sysdecode.3 index 52faf5373dc9..994d278fe001 100644 --- a/lib/libsysdecode/sysdecode.3 +++ b/lib/libsysdecode/sysdecode.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 10, 2015 +.Dd January 24, 2016 .Dt SYSDECODE 3 .Os .Sh NAME @@ -38,8 +38,34 @@ The .Nm library includes several functions that provide descriptive names of values associated with system calls. +.Ss Supported ABIs +Some functions in this library provide ABI-specific descriptions. +The supported ABIs are named by the +.Vt enum sysdecode_abi +enumeration. +.Pp +.Bl -tag -width "Li UNKNOWN_ABI" -compact +.It Li FREEBSD +Native FreeBSD binaries. +Supported on all platforms. +.It Li FREEBSD32 +32-bit FreeBSD binaries. +Supported on amd64 and powerpc64. +.It Li LINUX +Linux binaries of the same platform. +Supported on amd64 and i386. +.It Li LINUX32 +32-bit Linux binaries. +Supported on amd64. +.It Li CLOUDABI64 +64-bit CloudABI binaries. +Supported on aarch64 and amd64. +.It Li UNKNOWN_ABI +A placeholder for use when the ABI is not known. +.El .Sh SEE ALSO .Xr sysdecode_ioctlname 3 , +.Xr sysdecode_syscallnames 3 , .Xr sysdecode_utrace 3 .Sh HISTORY The diff --git a/lib/libsysdecode/sysdecode.h b/lib/libsysdecode/sysdecode.h index aa95838e78d7..c2c3a9e801e5 100644 --- a/lib/libsysdecode/sysdecode.h +++ b/lib/libsysdecode/sysdecode.h @@ -29,7 +29,17 @@ #ifndef __SYSDECODE_H__ #define __SYSDECODE_H__ +enum sysdecode_abi { + UNKNOWN_ABI = 0, + FREEBSD, + FREEBSD32, + LINUX, + LINUX32, + CLOUDABI64 +}; + const char *sysdecode_ioctlname(unsigned long _val); +const char *sysdecode_syscallname(enum sysdecode_abi _abi, unsigned int _code); int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len); #endif /* !__SYSDECODE_H__ */ diff --git a/lib/libsysdecode/sysdecode_syscallnames.3 b/lib/libsysdecode/sysdecode_syscallnames.3 new file mode 100644 index 000000000000..1c75ab6e9d17 --- /dev/null +++ b/lib/libsysdecode/sysdecode_syscallnames.3 @@ -0,0 +1,67 @@ +.\" +.\" Copyright (c) 2016 John Baldwin +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd January 24, 2016 +.Dt sysdecode_syscallnames 3 +.Os +.Sh NAME +.Nm sysdecode_syscallnames +.Nd lookup name of system calls +.Sh LIBRARY +.Lb libsysdecode +.Sh SYNOPSIS +.Ft const char * +.Fn sysdecode_syscallnames "enum sysdecode_abi abi" "unsigned int code" +.Sh DESCRIPTION +This function returns a pointer to the name of a system call identified by +.Fa code +for the process ABI +.Fa abi . +If +.Fa code +specifies an unknown system call or +.Fa abi +is an unsupported ABI, +.Nm +returns +.Dv NULL . +.Pp +For the list of supported ABIs, +see +.Xr sysdecode 3 . +.Sh RETURN VALUES +The +.Nm +function returns a pointer to a string on success or +.Dv NULL +if either +.Fa code +or +.Fa ABI +is invalid . +.Sh SEE ALSO +.Xr sysdecode 3 diff --git a/usr.bin/kdump/Makefile b/usr.bin/kdump/Makefile index f149e80fa109..40109f0ca3ab 100644 --- a/usr.bin/kdump/Makefile +++ b/usr.bin/kdump/Makefile @@ -19,25 +19,6 @@ NO_WERROR?= YES CLEANFILES= kdump_subr.c kdump_subr.h -.if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386") -beforedepend: linux_syscalls.c - -CLEANFILES+= linux_syscalls.c -kdump.o: linux_syscalls.c -linux_syscalls.c: linux_syscalls.conf - sh ${.CURDIR}/../../sys/kern/makesyscalls.sh \ - ${.CURDIR}/../../sys/${MACHINE_ARCH}/linux/syscalls.master ${.CURDIR}/linux_syscalls.conf -.endif -.if (${MACHINE_ARCH} == "amd64") -beforedepend: linux32_syscalls.c - -CLEANFILES+= linux32_syscalls.c -kdump.o: linux32_syscalls.c -linux32_syscalls.c: linux32_syscalls.conf - sh ${.CURDIR}/../../sys/kern/makesyscalls.sh \ - ${.CURDIR}/../../sys/${MACHINE_ARCH}/linux32/syscalls.master ${.CURDIR}/linux32_syscalls.conf -.endif - kdump_subr.h: mksubr sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} | \ sed -n 's/^\([a-z].*)\)$$/void \1;/p' >${.TARGET} diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 7af99fb58659..d4406545fc4d 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -122,8 +122,7 @@ void usage(void); #define TIMESTAMP_ELAPSED 0x2 #define TIMESTAMP_RELATIVE 0x4 -extern const char *signames[], *syscallnames[]; -extern int nsyscalls; +extern const char *signames[]; static int timestamp, decimal, fancy = 1, suppressdata, tail, threads, maxdata, resolv = 0, abiflag = 0, syscallno = 0; @@ -145,11 +144,7 @@ static struct ktr_header ktr_header; #if defined(__amd64__) || defined(__i386__) -void linux_ktrsyscall(struct ktr_syscall *, u_int); void linux_ktrsysret(struct ktr_sysret *, u_int); -extern const char *linux_syscallnames[]; - -#include /* * from linux.h @@ -169,12 +164,6 @@ static int bsd_to_linux_errno[ELAST + 1] = { }; #endif -#if defined(__amd64__) -extern const char *linux32_syscallnames[]; - -#include -#endif - struct proc_info { TAILQ_ENTRY(proc_info) info; @@ -401,13 +390,7 @@ main(int argc, char *argv[]) drop_logged = 0; switch (ktr_header.ktr_type) { case KTR_SYSCALL: -#if defined(__amd64__) || defined(__i386__) - if ((sv_flags & SV_ABI_MASK) == SV_ABI_LINUX) - linux_ktrsyscall((struct ktr_syscall *)m, - sv_flags); - else -#endif - ktrsyscall((struct ktr_syscall *)m, sv_flags); + ktrsyscall((struct ktr_syscall *)m, sv_flags); break; case KTR_SYSRET: #if defined(__amd64__) || defined(__i386__) @@ -687,10 +670,6 @@ dumpheader(struct ktr_header *kth) } #include -#define KTRACE -#include -#undef KTRACE -int nsyscalls = sizeof (syscallnames) / sizeof (syscallnames[0]); static void ioctlname(unsigned long val) @@ -706,26 +685,57 @@ ioctlname(unsigned long val) printf("%#lx", val); } +static enum sysdecode_abi +syscallabi(u_int sv_flags) +{ + + if (sv_flags == 0) + return (FREEBSD); + switch (sv_flags & SV_ABI_MASK) { + case SV_ABI_FREEBSD: + return (FREEBSD); +#if defined(__amd64__) || defined(__i386__) + case SV_ABI_LINUX: +#ifdef __amd64__ + if (sv_flags & SV_ILP32) + return (LINUX32); +#endif + return (LINUX); +#endif + default: + return (UNKNOWN_ABI); + } +} + +static void +syscallname(u_int code, u_int sv_flags) +{ + const char *name; + + name = sysdecode_syscallname(syscallabi(sv_flags), code); + if (name == NULL) + printf("[%d]", code); + else { + printf("%s", name); + if (syscallno) + printf("[%d]", code); + } +} + void -ktrsyscall(struct ktr_syscall *ktr, u_int flags) +ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags) { int narg = ktr->ktr_narg; register_t *ip; intmax_t arg; - if ((flags != 0 && ((flags & SV_ABI_MASK) != SV_ABI_FREEBSD)) || - (ktr->ktr_code >= nsyscalls || ktr->ktr_code < 0)) - printf("[%d]", ktr->ktr_code); - else { - printf("%s", syscallnames[ktr->ktr_code]); - if (syscallno) - printf("[%d]", ktr->ktr_code); - } + syscallname(ktr->ktr_code, sv_flags); ip = &ktr->ktr_args[0]; if (narg) { char c = '('; if (fancy && - (flags == 0 || (flags & SV_ABI_MASK) == SV_ABI_FREEBSD)) { + (sv_flags == 0 || + (sv_flags & SV_ABI_MASK) == SV_ABI_FREEBSD)) { switch (ktr->ktr_code) { case SYS_bindat: case SYS_connectat: @@ -1332,21 +1342,13 @@ ktrsyscall(struct ktr_syscall *ktr, u_int flags) } void -ktrsysret(struct ktr_sysret *ktr, u_int flags) +ktrsysret(struct ktr_sysret *ktr, u_int sv_flags) { register_t ret = ktr->ktr_retval; int error = ktr->ktr_error; - int code = ktr->ktr_code; - if ((flags != 0 && ((flags & SV_ABI_MASK) != SV_ABI_FREEBSD)) || - (code >= nsyscalls || code < 0)) - printf("[%d] ", code); - else { - printf("%s", syscallnames[code]); - if (syscallno) - printf("[%d]", code); - printf(" "); - } + syscallname(ktr->ktr_code, sv_flags); + printf(" "); if (error == 0) { if (fancy) { @@ -1851,56 +1853,14 @@ ktrfaultend(struct ktr_faultend *ktr) } #if defined(__amd64__) || defined(__i386__) - -#if defined(__amd64__) -#define NLINUX_SYSCALLS(v) ((v) & SV_ILP32 ? \ - nitems(linux32_syscallnames) : nitems(linux_syscallnames)) -#define LINUX_SYSCALLNAMES(v, i) ((v) & SV_ILP32 ? \ - linux32_syscallnames[i] : linux_syscallnames[i]) -#else -#define NLINUX_SYSCALLS(v) (nitems(linux_syscallnames)) -#define LINUX_SYSCALLNAMES(v, i) (linux_syscallnames[i]) -#endif - -void -linux_ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags) -{ - int narg = ktr->ktr_narg; - unsigned code = ktr->ktr_code; - register_t *ip; - - if (ktr->ktr_code < 0 || code >= NLINUX_SYSCALLS(sv_flags)) - printf("[%d]", ktr->ktr_code); - else { - printf("%s", LINUX_SYSCALLNAMES(sv_flags, ktr->ktr_code)); - if (syscallno) - printf("[%d]", ktr->ktr_code); - } - ip = &ktr->ktr_args[0]; - if (narg) { - char c = '('; - while (narg > 0) - print_number(ip, narg, c); - putchar(')'); - } - putchar('\n'); -} - void linux_ktrsysret(struct ktr_sysret *ktr, u_int sv_flags) { register_t ret = ktr->ktr_retval; - unsigned code = ktr->ktr_code; int error = ktr->ktr_error; - if (ktr->ktr_code < 0 || code >= NLINUX_SYSCALLS(sv_flags)) - printf("[%d] ", ktr->ktr_code); - else { - printf("%s ", LINUX_SYSCALLNAMES(sv_flags, code)); - if (syscallno) - printf("[%d]", code); - printf(" "); - } + syscallname(ktr->ktr_code, sv_flags); + printf(" "); if (error == 0) { if (fancy) { diff --git a/usr.bin/truss/Makefile b/usr.bin/truss/Makefile index a6e45243e180..b28098c802a8 100644 --- a/usr.bin/truss/Makefile +++ b/usr.bin/truss/Makefile @@ -8,13 +8,6 @@ LIBADD= sysdecode CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys -# Define where to generate syscalls for each ABI. -ABI_SYSPATH.freebsd= sys/kern -ABI_SYSPATH.freebsd32= sys/compat/freebsd32 -ABI_SYSPATH.cloudabi64= sys/compat/cloudabi64 -ABI_SYSPATH.i386-linux= sys/i386/linux -ABI_SYSPATH.amd64-linux32= sys/amd64/linux32 - ABIS+= freebsd # Each ABI is expected to have an ABI.c, MACHINE_ARCH-ABI.c or # MACHINE_CPUARCH-ABI.c file that will be used to map the syscall arguments. @@ -42,21 +35,7 @@ ABI_SRCS= ${abi}.c ${MACHINE_ARCH}-${abi}.c ${MACHINE_CPUARCH}-${abi}.c abi_src= ${f} .endif .endfor -SRCS:= ${SRCS} ${abi_src} ${abi}_syscalls.h -CLEANFILES+= ${abi}_syscalls.conf ${abi}_syscalls.master ${abi}_syscalls.h -${abi}_syscalls.conf: ${.CURDIR}/makesyscallsconf.sh - /bin/sh ${.CURDIR}/makesyscallsconf.sh ${abi} ${.TARGET} - -${abi}_syscalls.master: ${.CURDIR:H:H}/${ABI_SYSPATH.${abi}}/syscalls.master - cp -f ${.ALLSRC} ${.TARGET} - -${abi}_syscalls.h: ${abi}_syscalls.master ${abi}_syscalls.conf \ - ${.CURDIR:H:H}/sys/kern/makesyscalls.sh - /bin/sh ${.CURDIR:H:H}/sys/kern/makesyscalls.sh \ - ${abi}_syscalls.master ${abi}_syscalls.conf -# Eliminate compiler warning about non-static global. - sed -i '' '/^const char \*/s/^/static /' ${.TARGET}.tmp - mv ${.TARGET}.tmp ${.TARGET} +SRCS:= ${SRCS} ${abi_src} .endfor .include diff --git a/usr.bin/truss/aarch64-cloudabi64.c b/usr.bin/truss/aarch64-cloudabi64.c index ad6afc260b5e..099cb1e7d746 100644 --- a/usr.bin/truss/aarch64-cloudabi64.c +++ b/usr.bin/truss/aarch64-cloudabi64.c @@ -33,9 +33,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "cloudabi.h" -#include "cloudabi64_syscalls.h" #include "truss.h" static int @@ -81,8 +81,7 @@ aarch64_cloudabi64_fetch_retval(struct trussinfo *trussinfo, long *retval, static struct procabi aarch64_cloudabi64 = { "CloudABI ELF64", - syscallnames, - nitems(syscallnames), + CLOUDABI64, aarch64_cloudabi64_fetch_args, aarch64_cloudabi64_fetch_retval }; diff --git a/usr.bin/truss/aarch64-freebsd.c b/usr.bin/truss/aarch64-freebsd.c index 1ec2b66c9f60..454bba7d77ca 100644 --- a/usr.bin/truss/aarch64-freebsd.c +++ b/usr.bin/truss/aarch64-freebsd.c @@ -39,11 +39,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int aarch64_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -100,8 +99,7 @@ aarch64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi aarch64_freebsd = { "FreeBSD ELF64", - syscallnames, - nitems(syscallnames), + FREEBSD, aarch64_fetch_args, aarch64_fetch_retval }; diff --git a/usr.bin/truss/amd64-cloudabi64.c b/usr.bin/truss/amd64-cloudabi64.c index 5982b66b4aeb..38768ff0074d 100644 --- a/usr.bin/truss/amd64-cloudabi64.c +++ b/usr.bin/truss/amd64-cloudabi64.c @@ -33,9 +33,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "cloudabi.h" -#include "cloudabi64_syscalls.h" #include "truss.h" static int @@ -90,8 +90,7 @@ amd64_cloudabi64_fetch_retval(struct trussinfo *trussinfo, long *retval, static struct procabi amd64_cloudabi64 = { "CloudABI ELF64", - syscallnames, - nitems(syscallnames), + CLOUDABI64, amd64_cloudabi64_fetch_args, amd64_cloudabi64_fetch_retval }; diff --git a/usr.bin/truss/amd64-freebsd.c b/usr.bin/truss/amd64-freebsd.c index 0461616100f4..8a211a0ce474 100644 --- a/usr.bin/truss/amd64-freebsd.c +++ b/usr.bin/truss/amd64-freebsd.c @@ -41,11 +41,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int amd64_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -122,8 +121,7 @@ amd64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi amd64_freebsd = { "FreeBSD ELF64", - syscallnames, - nitems(syscallnames), + FREEBSD, amd64_fetch_args, amd64_fetch_retval }; diff --git a/usr.bin/truss/amd64-freebsd32.c b/usr.bin/truss/amd64-freebsd32.c index 82eb6cd59c45..adce798b7c5c 100644 --- a/usr.bin/truss/amd64-freebsd32.c +++ b/usr.bin/truss/amd64-freebsd32.c @@ -42,11 +42,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd32_syscalls.h" - static int amd64_freebsd32_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -118,8 +117,7 @@ amd64_freebsd32_fetch_retval(struct trussinfo *trussinfo, long *retval, static struct procabi amd64_freebsd32 = { "FreeBSD ELF32", - syscallnames, - nitems(syscallnames), + FREEBSD32, amd64_freebsd32_fetch_args, amd64_freebsd32_fetch_retval }; @@ -128,8 +126,7 @@ PROCABI(amd64_freebsd32); static struct procabi amd64_freebsd32_aout = { "FreeBSD a.out", - syscallnames, - nitems(syscallnames), + FREEBSD32, amd64_freebsd32_fetch_args, amd64_freebsd32_fetch_retval }; diff --git a/usr.bin/truss/amd64-linux32.c b/usr.bin/truss/amd64-linux32.c index 17e5fdc2b29a..dd1d83361095 100644 --- a/usr.bin/truss/amd64-linux32.c +++ b/usr.bin/truss/amd64-linux32.c @@ -40,11 +40,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "amd64-linux32_syscalls.h" - static int amd64_linux32_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -132,8 +131,7 @@ amd64_linux32_fetch_retval(struct trussinfo *trussinfo, long *retval, static struct procabi amd64_linux32 = { "Linux ELF32", - syscallnames, - nitems(syscallnames), + LINUX32, amd64_linux32_fetch_args, amd64_linux32_fetch_retval }; diff --git a/usr.bin/truss/arm-freebsd.c b/usr.bin/truss/arm-freebsd.c index aa7bcccd5c3f..5722c91442fb 100644 --- a/usr.bin/truss/arm-freebsd.c +++ b/usr.bin/truss/arm-freebsd.c @@ -42,11 +42,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int arm_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -129,8 +128,7 @@ arm_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi arm_freebsd = { "FreeBSD ELF32", - syscallnames, - nitems(syscallnames), + FREEBSD, arm_fetch_args, arm_fetch_retval }; diff --git a/usr.bin/truss/i386-freebsd.c b/usr.bin/truss/i386-freebsd.c index d9d72aa28589..c166596dcb11 100644 --- a/usr.bin/truss/i386-freebsd.c +++ b/usr.bin/truss/i386-freebsd.c @@ -41,11 +41,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int i386_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -111,8 +110,7 @@ i386_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi i386_freebsd = { "FreeBSD ELF32", - syscallnames, - nitems(syscallnames), + FREEBSD, i386_fetch_args, i386_fetch_retval }; @@ -121,8 +119,7 @@ PROCABI(i386_freebsd); static struct procabi i386_freebsd_aout = { "FreeBSD a.out", - syscallnames, - nitems(syscallnames), + FREEBSD, i386_fetch_args, i386_fetch_retval }; diff --git a/usr.bin/truss/i386-linux.c b/usr.bin/truss/i386-linux.c index 91662711676b..5fdae8ee958c 100644 --- a/usr.bin/truss/i386-linux.c +++ b/usr.bin/truss/i386-linux.c @@ -40,11 +40,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "i386-linux_syscalls.h" - static int i386_linux_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -131,8 +130,7 @@ i386_linux_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi i386_linux = { "Linux ELF32", - syscallnames, - nitems(syscallnames), + LINUX, i386_linux_fetch_args, i386_linux_fetch_retval }; diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index 5eec9538f50c..531d7dbb4c12 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include diff --git a/usr.bin/truss/mips-freebsd.c b/usr.bin/truss/mips-freebsd.c index 0c504b88fd63..f4b5a7eb2aa0 100644 --- a/usr.bin/truss/mips-freebsd.c +++ b/usr.bin/truss/mips-freebsd.c @@ -41,11 +41,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int mips_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -132,8 +131,7 @@ static struct procabi mips_freebsd = { #else "FreeBSD ELF32", #endif - syscallnames, - nitems(syscallnames), + FREEBSD, mips_fetch_args, mips_fetch_retval }; diff --git a/usr.bin/truss/powerpc-freebsd.c b/usr.bin/truss/powerpc-freebsd.c index 90c3663d3c9c..6a245df76c6a 100644 --- a/usr.bin/truss/powerpc-freebsd.c +++ b/usr.bin/truss/powerpc-freebsd.c @@ -37,11 +37,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int powerpc_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -113,8 +112,7 @@ powerpc_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi powerpc_freebsd = { "FreeBSD ELF32", - syscallnames, - nitems(syscallnames), + FREEBSD, powerpc_fetch_args, powerpc_fetch_retval }; diff --git a/usr.bin/truss/powerpc64-freebsd.c b/usr.bin/truss/powerpc64-freebsd.c index fafaa1bde5bf..68a0b5d36abe 100644 --- a/usr.bin/truss/powerpc64-freebsd.c +++ b/usr.bin/truss/powerpc64-freebsd.c @@ -37,11 +37,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int powerpc64_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -109,8 +108,7 @@ powerpc64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi powerpc64_freebsd = { "FreeBSD ELF64", - syscallnames, - nitems(syscallnames), + FREEBSD, powerpc64_fetch_args, powerpc64_fetch_retval }; diff --git a/usr.bin/truss/powerpc64-freebsd32.c b/usr.bin/truss/powerpc64-freebsd32.c index fc0ffb8dbddb..ee37ead3cc11 100644 --- a/usr.bin/truss/powerpc64-freebsd32.c +++ b/usr.bin/truss/powerpc64-freebsd32.c @@ -37,11 +37,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd32_syscalls.h" - static int powerpc64_freebsd32_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -118,8 +117,7 @@ powerpc64_freebsd32_fetch_retval(struct trussinfo *trussinfo, long *retval, int static struct procabi powerpc64_freebsd32 = { "FreeBSD ELF32", - syscallnames, - nitems(syscallnames), + FREEBSD32, powerpc64_freebsd32_fetch_args, powerpc64_freebsd32_fetch_retval }; diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c index 74678e6ac2df..c0c15f0c7458 100644 --- a/usr.bin/truss/setup.c +++ b/usr.bin/truss/setup.c @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -335,8 +336,7 @@ enter_syscall(struct trussinfo *info, struct ptrace_lwpinfo *pl) return; } - if (t->cs.number >= 0 && t->cs.number < t->proc->abi->nsyscalls) - t->cs.name = t->proc->abi->syscallnames[t->cs.number]; + t->cs.name = sysdecode_syscallname(t->proc->abi->abi, t->cs.number); if (t->cs.name == NULL) fprintf(info->outfile, "-- UNKNOWN %s SYSCALL %d --\n", t->proc->abi->type, t->cs.number); diff --git a/usr.bin/truss/sparc64-freebsd.c b/usr.bin/truss/sparc64-freebsd.c index a4dba92e63e7..23486d76baa4 100644 --- a/usr.bin/truss/sparc64-freebsd.c +++ b/usr.bin/truss/sparc64-freebsd.c @@ -43,11 +43,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "truss.h" -#include "freebsd_syscalls.h" - static int sparc64_fetch_args(struct trussinfo *trussinfo, u_int narg) { @@ -116,8 +115,7 @@ sparc64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) static struct procabi sparc64_freebsd = { "FreeBSD ELF64", - syscallnames, - nitems(syscallnames), + FREEBSD, sparc64_fetch_args, sparc64_fetch_retval }; diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h index 5a57de7003c1..5ef24447c25a 100644 --- a/usr.bin/truss/truss.h +++ b/usr.bin/truss/truss.h @@ -41,8 +41,7 @@ struct trussinfo; struct procabi { const char *type; - const char **syscallnames; - int nsyscalls; + enum sysdecode_abi abi; int (*fetch_args)(struct trussinfo *, u_int); int (*fetch_retval)(struct trussinfo *, long *, int *); };