summaryrefslogtreecommitdiffstats
path: root/lib/libsysdecode
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2016-01-26 19:07:09 +0000
committerjhb <jhb@FreeBSD.org>2016-01-26 19:07:09 +0000
commitcd4a0ee266068abaf08833b8d76b0ad8b0cea721 (patch)
tree817dc34ebf9af56aa355e84eee2cf55753669285 /lib/libsysdecode
parent1def741dc225d64b4a5b9f6ef7a3fb0b865294f5 (diff)
downloadFreeBSD-src-cd4a0ee266068abaf08833b8d76b0ad8b0cea721.zip
FreeBSD-src-cd4a0ee266068abaf08833b8d76b0ad8b0cea721.tar.gz
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
Diffstat (limited to 'lib/libsysdecode')
-rw-r--r--lib/libsysdecode/Makefile9
-rw-r--r--lib/libsysdecode/syscallnames.c105
-rw-r--r--lib/libsysdecode/sysdecode.328
-rw-r--r--lib/libsysdecode/sysdecode.h10
-rw-r--r--lib/libsysdecode/sysdecode_syscallnames.367
5 files changed, 217 insertions, 2 deletions
diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile
index a6d3ba1..e1e69fe 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 <netinet/ip_compat.h>
CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls
+
+# Workaround warning for unused ssi_cables[] in <dev/lmc/if_lmc.h>
+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 0000000..cfe50a6
--- /dev/null
+++ b/lib/libsysdecode/syscallnames.c
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
+ * 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 <sys/cdefs.h>
+__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 <sys/param.h>
+#include <stdio.h>
+#include <sysdecode.h>
+
+static
+#include <kern/syscalls.c>
+
+#if defined(__amd64__) || defined(__powerpc64__)
+static
+#include <compat/freebsd32/freebsd32_syscalls.c>
+#endif
+
+#if defined(__amd64__) || defined(__i386__)
+static
+#ifdef __amd64__
+#include <amd64/linux/linux_syscalls.c>
+#else
+#include <i386/linux/linux_syscalls.c>
+#endif
+#endif
+
+#ifdef __amd64__
+static
+#include <amd64/linux32/linux32_syscalls.c>
+#endif
+
+#if defined(__amd64__) || defined(__aarch64__)
+static
+#include <compat/cloudabi64/cloudabi64_syscalls.c>
+#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 52faf53..994d278 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 aa95838..c2c3a9e 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 0000000..1c75ab6
--- /dev/null
+++ b/lib/libsysdecode/sysdecode_syscallnames.3
@@ -0,0 +1,67 @@
+.\"
+.\" Copyright (c) 2016 John Baldwin <jhb@FreeBSD.org>
+.\" 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
OpenPOWER on IntegriCloud