Index: lib/libsysdecode/Makefile =================================================================== --- lib/libsysdecode/Makefile +++ 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 +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 Index: lib/libsysdecode/mkioctls =================================================================== --- lib/libsysdecode/mkioctls +++ 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 @@ 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 @@ print "#include " print "#include " print "#include " + print "#include " 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 @@ } 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 "}" } ' Index: lib/libsysdecode/sysdecode.h =================================================================== --- lib/libsysdecode/sysdecode.h +++ 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__ */ Index: lib/libsysdecode/sysdecode.3 =================================================================== --- lib/libsysdecode/sysdecode.3 +++ lib/libsysdecode/sysdecode.3 @@ -39,6 +39,7 @@ 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 Index: lib/libsysdecode/sysdecode_ioctlname.3 =================================================================== --- lib/libsysdecode/sysdecode_ioctlname.3 +++ lib/libsysdecode/sysdecode_ioctlname.3 @@ -25,23 +25,33 @@ .\" .\" $FreeBSD$ .\" -.Dd December 10, 2015 -.Dt SYSDECODE 3 +.Dd December 12, 2015 +.Dt sysdecode_ioctlname 3 .Os .Sh NAME -.Nm sysdecode -.Nd system argument decoding library +.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 -.Nm -library includes several functions that provide descriptive names of -values associated with system calls. -.Sh SEE ALSO -.Xr sysdecode_utrace 3 -.Sh HISTORY +.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 -.Nm -library first appeared in -.Fx 11.0 . +.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 Index: usr.bin/kdump/Makefile =================================================================== --- usr.bin/kdump/Makefile +++ 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 @@ 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 @@ ${.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} Index: usr.bin/kdump/kdump.c =================================================================== --- usr.bin/kdump/kdump.c +++ usr.bin/kdump/kdump.c @@ -116,7 +116,6 @@ 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 @@ #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 @@ case SYS_ioctl: { print_number(ip, narg, c); putchar(c); - ioctlname(*ip, decimal); + ioctlname(*ip); c = ','; ip++; narg--; Index: usr.bin/truss/Makefile =================================================================== --- usr.bin/truss/Makefile +++ 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 Index: usr.bin/truss/syscalls.c =================================================================== --- usr.bin/truss/syscalls.c +++ usr.bin/truss/syscalls.c @@ -1315,7 +1315,7 @@ unsigned long cmd; cmd = args[sc->offset]; - temp = ioctlname(cmd); + temp = sysdecode_ioctlname(cmd); if (temp) fputs(temp, fp); else {