summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2015-12-22 20:33:49 +0000
committerjhb <jhb@FreeBSD.org>2015-12-22 20:33:49 +0000
commitb665ac07581ab1fbd0d71db29a027b4a39734789 (patch)
tree12efcb04d4bc19b74d2554032b084f8fee602ddf
parent2a6353954347e51fe7f57c094b3d03b9199fae99 (diff)
downloadFreeBSD-src-b665ac07581ab1fbd0d71db29a027b4a39734789.zip
FreeBSD-src-b665ac07581ab1fbd0d71db29a027b4a39734789.tar.gz
Move the mkioctls script to libsysdecode and use it to generate a
sysdecode_ioctlname() function. This function matches the behavior of the truss variant in that it returns a pointer to a string description for known ioctls. The caller is responsible for displaying unknown ioctl requests. For kdump this meant moving the logic to handle unknown ioctl requests out of the generated function and into an ioctlname() function in kdump.c instead. Differential Revision: https://reviews.freebsd.org/D4610
-rw-r--r--lib/libsysdecode/Makefile23
-rw-r--r--lib/libsysdecode/mkioctls (renamed from usr.bin/kdump/mkioctls)37
-rw-r--r--lib/libsysdecode/sysdecode.31
-rw-r--r--lib/libsysdecode/sysdecode.h1
-rw-r--r--lib/libsysdecode/sysdecode_ioctlname.357
-rw-r--r--usr.bin/kdump/Makefile14
-rw-r--r--usr.bin/kdump/kdump.c17
-rw-r--r--usr.bin/truss/Makefile7
-rw-r--r--usr.bin/truss/syscalls.c2
9 files changed, 108 insertions, 51 deletions
diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile
index 8eb7908..a6d3ba1 100644
--- a/lib/libsysdecode/Makefile
+++ b/lib/libsysdecode/Makefile
@@ -4,10 +4,31 @@
LIB= sysdecode
-SRCS= utrace.c
+SRCS= ioctl.c utrace.c
INCS= sysdecode.h
MAN+= sysdecode.3 \
+ sysdecode_ioctlname.3 \
sysdecode_utrace.3
+CLEANFILES= ioctl.c
+
+.if defined(COMPAT_32BIT)
+CPP+= -m32
+.endif
+
+.if ${MK_PF} != "no"
+CFLAGS+=-DPF
+.endif
+
+# Workaround duplicate declarations in <netinet/ip_compat.h>
+CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls
+CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}}
+
+ioctl.c: mkioctls
+ env MACHINE=${MACHINE} CPP="${CPP}" \
+ /bin/sh ${.CURDIR}/mkioctls ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
+
+beforedepend: ioctl.c
+
.include <bsd.lib.mk>
diff --git a/usr.bin/kdump/mkioctls b/lib/libsysdecode/mkioctls
index a563341..e174d30 100644
--- a/usr.bin/kdump/mkioctls
+++ b/lib/libsysdecode/mkioctls
@@ -1,19 +1,15 @@
#!/bin/sh
#
# $FreeBSD$
-#
-# When editing this script, keep in mind that truss also uses it.
-#
set -e
-if [ $# -ne 2 -o \( $1 != "print" -a $1 != "return" \) ]; then
- echo "usage: sh $0 print|return include-dir"
+if [ $# -ne 1 ]; then
+ echo "usage: sh $0 include-dir"
exit 1
fi
-style="$1"
-includedir="$2"
+includedir="$1"
LC_ALL=C; export LC_ALL
@@ -40,7 +36,7 @@ esac
awk -v x="$ioctl_includes" 'BEGIN {print x}' |
$CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - |
- awk -v ioctl_includes="$ioctl_includes" -v style="$style" '
+ awk -v ioctl_includes="$ioctl_includes" '
BEGIN {
print "/* XXX obnoxious prerequisites. */"
print "#define COMPAT_43"
@@ -68,20 +64,12 @@ BEGIN {
print "#include <cam/cam.h>"
print "#include <stddef.h>"
print "#include <stdint.h>"
+ print "#include <sysdecode.h>"
print ""
print ioctl_includes
print ""
- if (style == "print") {
- print "void ioctlname(unsigned long val, int decimal);"
- print ""
- print "void"
- print "ioctlname(unsigned long val, int decimal)"
- } else {
- print "const char *ioctlname(unsigned long val);"
- print ""
- print "const char *"
- print "ioctlname(unsigned long val)"
- }
+ print "const char *"
+ print "sysdecode_ioctlname(unsigned long val)"
print "{"
print "\tconst char *str = NULL;"
print ""
@@ -103,16 +91,7 @@ BEGIN {
}
END {
print ""
- if (style == "print") {
- print "\tif (str != NULL)"
- print "\t\tprintf(\"%s\", str);"
- print "\telse if (decimal)"
- print "\t\tprintf(\"%lu\", val);"
- print "\telse"
- print "\t\tprintf(\"%#lx\", val);"
- } else {
- print "\treturn (str);"
- }
+ print "\treturn (str);"
print "}"
}
'
diff --git a/lib/libsysdecode/sysdecode.3 b/lib/libsysdecode/sysdecode.3
index fd1677d..52faf53 100644
--- a/lib/libsysdecode/sysdecode.3
+++ b/lib/libsysdecode/sysdecode.3
@@ -39,6 +39,7 @@ The
library includes several functions that provide descriptive names of
values associated with system calls.
.Sh SEE ALSO
+.Xr sysdecode_ioctlname 3 ,
.Xr sysdecode_utrace 3
.Sh HISTORY
The
diff --git a/lib/libsysdecode/sysdecode.h b/lib/libsysdecode/sysdecode.h
index 10feee1..aa95838 100644
--- a/lib/libsysdecode/sysdecode.h
+++ b/lib/libsysdecode/sysdecode.h
@@ -29,6 +29,7 @@
#ifndef __SYSDECODE_H__
#define __SYSDECODE_H__
+const char *sysdecode_ioctlname(unsigned long _val);
int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len);
#endif /* !__SYSDECODE_H__ */
diff --git a/lib/libsysdecode/sysdecode_ioctlname.3 b/lib/libsysdecode/sysdecode_ioctlname.3
new file mode 100644
index 0000000..6479f03
--- /dev/null
+++ b/lib/libsysdecode/sysdecode_ioctlname.3
@@ -0,0 +1,57 @@
+.\"
+.\" Copyright (c) 2015 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 December 12, 2015
+.Dt sysdecode_ioctlname 3
+.Os
+.Sh NAME
+.Nm sysdecode_ioctlname
+.Nd lookup name of device control command
+.Sh LIBRARY
+.Lb libsysdecode
+.Sh SYNOPSIS
+.Ft conts char *
+.Fn sysdecode_ioctlname "unsigned long request"
+.Sh DESCRIPTION
+The
+.Fn sysdecode_ioctlname
+function returns the name of a device control request identified by
+.Fa request .
+A table of names is generated during the build of the
+.Nm sysdecode
+library from system headers that maps device control request values to
+the name of the corresponding C macro.
+.Sh RETURN VALUES
+The
+.Fn sysdecode_ioctlname
+function returns the name of a device control request if
+.Fa request
+is a known value;
+otherwise
+.Dv NULL .
+.Sh SEE ALSO
+.Xr sysdecode 3
diff --git a/usr.bin/kdump/Makefile b/usr.bin/kdump/Makefile
index 52c0a09..f149e80 100644
--- a/usr.bin/kdump/Makefile
+++ b/usr.bin/kdump/Makefile
@@ -6,7 +6,7 @@
.PATH: ${.CURDIR}/../ktrace
PROG= kdump
-SRCS= kdump_subr.c kdump_subr.h kdump.c ioctl.c subr.c
+SRCS= kdump_subr.c kdump_subr.h kdump.c subr.c
CFLAGS+= -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
LIBADD= sysdecode
@@ -15,15 +15,9 @@ LIBADD+= capsicum
CFLAGS+=-DHAVE_LIBCAPSICUM
.endif
-.if ${MK_PF} != "no"
-CFLAGS+=-DPF
-.endif
-
NO_WERROR?= YES
-CLEANFILES= ioctl.c kdump_subr.c kdump_subr.h
-
-beforedepend: ioctl.c
+CLEANFILES= kdump_subr.c kdump_subr.h
.if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386")
beforedepend: linux_syscalls.c
@@ -44,10 +38,6 @@ linux32_syscalls.c: linux32_syscalls.conf
${.CURDIR}/../../sys/${MACHINE_ARCH}/linux32/syscalls.master ${.CURDIR}/linux32_syscalls.conf
.endif
-ioctl.c: mkioctls
- env MACHINE=${MACHINE} CPP="${CPP}" \
- sh ${.CURDIR}/mkioctls print ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
-
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 8165bc7..7af99fb 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -116,7 +116,6 @@ void ktrfault(struct ktr_fault *);
void ktrfaultend(struct ktr_faultend *);
void limitfd(int fd);
void usage(void);
-void ioctlname(unsigned long, int);
#define TIMESTAMP_NONE 0x0
#define TIMESTAMP_ABSOLUTE 0x1
@@ -693,6 +692,20 @@ dumpheader(struct ktr_header *kth)
#undef KTRACE
int nsyscalls = sizeof (syscallnames) / sizeof (syscallnames[0]);
+static void
+ioctlname(unsigned long val)
+{
+ const char *str;
+
+ str = sysdecode_ioctlname(val);
+ if (str != NULL)
+ printf("%s", str);
+ else if (decimal)
+ printf("%lu", val);
+ else
+ printf("%#lx", val);
+}
+
void
ktrsyscall(struct ktr_syscall *ktr, u_int flags)
{
@@ -741,7 +754,7 @@ ktrsyscall(struct ktr_syscall *ktr, u_int flags)
case SYS_ioctl: {
print_number(ip, narg, c);
putchar(c);
- ioctlname(*ip, decimal);
+ ioctlname(*ip);
c = ',';
ip++;
narg--;
diff --git a/usr.bin/truss/Makefile b/usr.bin/truss/Makefile
index a300da1..a6e4524 100644
--- a/usr.bin/truss/Makefile
+++ b/usr.bin/truss/Makefile
@@ -2,16 +2,11 @@
NO_WERROR=
PROG= truss
-SRCS= cloudabi.c ioctl.c main.c setup.c syscalls.c
+SRCS= cloudabi.c main.c setup.c syscalls.c
LIBADD= sysdecode
CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
-CLEANFILES= ioctl.c
-
-ioctl.c: ${.CURDIR}/../kdump/mkioctls
- env MACHINE=${MACHINE} CPP="${CPP}" \
- /bin/sh ${.CURDIR}/../kdump/mkioctls return ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
# Define where to generate syscalls for each ABI.
ABI_SYSPATH.freebsd= sys/kern
diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c
index 990403e6..8ff57db 100644
--- a/usr.bin/truss/syscalls.c
+++ b/usr.bin/truss/syscalls.c
@@ -1315,7 +1315,7 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval,
unsigned long cmd;
cmd = args[sc->offset];
- temp = ioctlname(cmd);
+ temp = sysdecode_ioctlname(cmd);
if (temp)
fputs(temp, fp);
else {
OpenPOWER on IntegriCloud