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
This commit is contained in:
jhb 2015-12-22 20:33:49 +00:00
parent 2a63539543
commit b665ac0758
9 changed files with 108 additions and 51 deletions

View File

@ -4,10 +4,31 @@
LIB= sysdecode LIB= sysdecode
SRCS= utrace.c SRCS= ioctl.c utrace.c
INCS= sysdecode.h INCS= sysdecode.h
MAN+= sysdecode.3 \ MAN+= sysdecode.3 \
sysdecode_ioctlname.3 \
sysdecode_utrace.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> .include <bsd.lib.mk>

View File

@ -1,19 +1,15 @@
#!/bin/sh #!/bin/sh
# #
# $FreeBSD$ # $FreeBSD$
#
# When editing this script, keep in mind that truss also uses it.
#
set -e set -e
if [ $# -ne 2 -o \( $1 != "print" -a $1 != "return" \) ]; then if [ $# -ne 1 ]; then
echo "usage: sh $0 print|return include-dir" echo "usage: sh $0 include-dir"
exit 1 exit 1
fi fi
style="$1" includedir="$1"
includedir="$2"
LC_ALL=C; export LC_ALL LC_ALL=C; export LC_ALL
@ -40,7 +36,7 @@ esac
awk -v x="$ioctl_includes" 'BEGIN {print x}' | awk -v x="$ioctl_includes" 'BEGIN {print x}' |
$CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - | $CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - |
awk -v ioctl_includes="$ioctl_includes" -v style="$style" ' awk -v ioctl_includes="$ioctl_includes" '
BEGIN { BEGIN {
print "/* XXX obnoxious prerequisites. */" print "/* XXX obnoxious prerequisites. */"
print "#define COMPAT_43" print "#define COMPAT_43"
@ -68,20 +64,12 @@ BEGIN {
print "#include <cam/cam.h>" print "#include <cam/cam.h>"
print "#include <stddef.h>" print "#include <stddef.h>"
print "#include <stdint.h>" print "#include <stdint.h>"
print "#include <sysdecode.h>"
print "" print ""
print ioctl_includes print ioctl_includes
print "" print ""
if (style == "print") { print "const char *"
print "void ioctlname(unsigned long val, int decimal);" print "sysdecode_ioctlname(unsigned long val)"
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 "{" print "{"
print "\tconst char *str = NULL;" print "\tconst char *str = NULL;"
print "" print ""
@ -103,16 +91,7 @@ BEGIN {
} }
END { END {
print "" print ""
if (style == "print") { print "\treturn (str);"
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 "}" print "}"
} }
' '

View File

@ -39,6 +39,7 @@ The
library includes several functions that provide descriptive names of library includes several functions that provide descriptive names of
values associated with system calls. values associated with system calls.
.Sh SEE ALSO .Sh SEE ALSO
.Xr sysdecode_ioctlname 3 ,
.Xr sysdecode_utrace 3 .Xr sysdecode_utrace 3
.Sh HISTORY .Sh HISTORY
The The

View File

@ -29,6 +29,7 @@
#ifndef __SYSDECODE_H__ #ifndef __SYSDECODE_H__
#define __SYSDECODE_H__ #define __SYSDECODE_H__
const char *sysdecode_ioctlname(unsigned long _val);
int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len); int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len);
#endif /* !__SYSDECODE_H__ */ #endif /* !__SYSDECODE_H__ */

View File

@ -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

View File

@ -6,7 +6,7 @@
.PATH: ${.CURDIR}/../ktrace .PATH: ${.CURDIR}/../ktrace
PROG= kdump 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. CFLAGS+= -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
LIBADD= sysdecode LIBADD= sysdecode
@ -15,15 +15,9 @@ LIBADD+= capsicum
CFLAGS+=-DHAVE_LIBCAPSICUM CFLAGS+=-DHAVE_LIBCAPSICUM
.endif .endif
.if ${MK_PF} != "no"
CFLAGS+=-DPF
.endif
NO_WERROR?= YES NO_WERROR?= YES
CLEANFILES= ioctl.c kdump_subr.c kdump_subr.h CLEANFILES= kdump_subr.c kdump_subr.h
beforedepend: ioctl.c
.if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386") .if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386")
beforedepend: linux_syscalls.c 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 ${.CURDIR}/../../sys/${MACHINE_ARCH}/linux32/syscalls.master ${.CURDIR}/linux32_syscalls.conf
.endif .endif
ioctl.c: mkioctls
env MACHINE=${MACHINE} CPP="${CPP}" \
sh ${.CURDIR}/mkioctls print ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
kdump_subr.h: mksubr kdump_subr.h: mksubr
sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} | \ sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} | \
sed -n 's/^\([a-z].*)\)$$/void \1;/p' >${.TARGET} sed -n 's/^\([a-z].*)\)$$/void \1;/p' >${.TARGET}

View File

@ -116,7 +116,6 @@ void ktrfault(struct ktr_fault *);
void ktrfaultend(struct ktr_faultend *); void ktrfaultend(struct ktr_faultend *);
void limitfd(int fd); void limitfd(int fd);
void usage(void); void usage(void);
void ioctlname(unsigned long, int);
#define TIMESTAMP_NONE 0x0 #define TIMESTAMP_NONE 0x0
#define TIMESTAMP_ABSOLUTE 0x1 #define TIMESTAMP_ABSOLUTE 0x1
@ -693,6 +692,20 @@ dumpheader(struct ktr_header *kth)
#undef KTRACE #undef KTRACE
int nsyscalls = sizeof (syscallnames) / sizeof (syscallnames[0]); 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 void
ktrsyscall(struct ktr_syscall *ktr, u_int flags) ktrsyscall(struct ktr_syscall *ktr, u_int flags)
{ {
@ -741,7 +754,7 @@ ktrsyscall(struct ktr_syscall *ktr, u_int flags)
case SYS_ioctl: { case SYS_ioctl: {
print_number(ip, narg, c); print_number(ip, narg, c);
putchar(c); putchar(c);
ioctlname(*ip, decimal); ioctlname(*ip);
c = ','; c = ',';
ip++; ip++;
narg--; narg--;

View File

@ -2,16 +2,11 @@
NO_WERROR= NO_WERROR=
PROG= truss PROG= truss
SRCS= cloudabi.c ioctl.c main.c setup.c syscalls.c SRCS= cloudabi.c main.c setup.c syscalls.c
LIBADD= sysdecode LIBADD= sysdecode
CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys 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. # Define where to generate syscalls for each ABI.
ABI_SYSPATH.freebsd= sys/kern ABI_SYSPATH.freebsd= sys/kern

View File

@ -1315,7 +1315,7 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval,
unsigned long cmd; unsigned long cmd;
cmd = args[sc->offset]; cmd = args[sc->offset];
temp = ioctlname(cmd); temp = sysdecode_ioctlname(cmd);
if (temp) if (temp)
fputs(temp, fp); fputs(temp, fp);
else { else {