Page MenuHomeFreeBSD

D7847.id20241.diff
No OneTemporary

D7847.id20241.diff

Index: lib/libsysdecode/Makefile
===================================================================
--- lib/libsysdecode/Makefile
+++ lib/libsysdecode/Makefile
@@ -5,9 +5,10 @@
PACKAGE=lib${LIB}
LIB= sysdecode
-SRCS= errno.c ioctl.c syscallnames.c utrace.c
+SRCS= errno.c flags.c ioctl.c signal.c syscallnames.c utrace.c
INCS= sysdecode.h
+CFLAGS+= -I${.OBJDIR}
CFLAGS+= -I${.CURDIR}/../../sys
CFLAGS+= -I${.CURDIR}/../../libexec/rtld-elf
@@ -18,7 +19,7 @@
sysdecode_utrace.3
MLINKS+= sysdecode_abi_to_freebsd_errno.3 sysdecode_freebsd_to_abi_errno.3
-CLEANFILES= ioctl.c
+CLEANFILES= ioctl.c tables.h
.if defined(COMPAT_32BIT)
CPP+= -m32
@@ -36,10 +37,13 @@
CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}}
+tables.h: mktables
+ sh ${.CURDIR}/mktables ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
+
ioctl.c: mkioctls
env MACHINE=${MACHINE} CPP="${CPP}" \
/bin/sh ${.CURDIR}/mkioctls ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
-beforedepend: ioctl.c
+beforedepend: ioctl.c tables.h
.include <bsd.lib.mk>
Index: lib/libsysdecode/errno.c
===================================================================
--- lib/libsysdecode/errno.c
+++ lib/libsysdecode/errno.c
@@ -28,8 +28,11 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/acl.h>
+#include <sys/wait.h>
#include <errno.h>
#include <limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: lib/libsysdecode/flags.c
===================================================================
--- /dev/null
+++ lib/libsysdecode/flags.c
@@ -0,0 +1,958 @@
+/*
+ * Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. 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$");
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <sys/fcntl.h>
+#include <sys/stat.h>
+#include <sys/unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/procctl.h>
+#include <sys/ptrace.h>
+#include <sys/resource.h>
+#include <sys/reboot.h>
+#include <sched.h>
+#include <sys/linker.h>
+#include <sys/thr.h>
+#include <sys/extattr.h>
+#include <sys/acl.h>
+#include <aio.h>
+#include <sys/sem.h>
+#include <sys/ipc.h>
+#include <sys/rtprio.h>
+#include <sys/shm.h>
+#include <sys/umtx.h>
+#include <nfsserver/nfs.h>
+#include <ufs/ufs/quota.h>
+#include <sys/capsicum.h>
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <signal.h>
+#include <sysdecode.h>
+
+/*
+ * This is taken from the xlat tables originally in truss which were
+ * in turn taken from strace.
+ */
+struct name_table {
+ uintmax_t val;
+ const char *str;
+};
+
+#define X(a) { a, #a },
+#define XEND { 0, NULL }
+
+#define TABLE_START(n) static struct name_table n[] = {
+#define TABLE_ENTRY X
+#define TABLE_END XEND };
+
+#include "tables.h"
+
+#undef TABLE_START
+#undef TABLE_ENTRY
+#undef TABLE_END
+
+/*
+ * These are simple support macros. print_or utilizes a variable
+ * defined in the calling function to track whether or not it should
+ * print a logical-OR character ('|') before a string. if_print_or
+ * simply handles the necessary "if" statement used in many lines
+ * of this file.
+ */
+#define print_or(fp,str,orflag) do { \
+ if (orflag) fputc(fp, '|'); else orflag = true; \
+ fprintf(fp, str); } \
+ while (0)
+#define if_print_or(fp,i,flag,orflag) do { \
+ if ((i & flag) == flag) \
+ print_or(fp,#flag,orflag); } \
+ while (0)
+
+static const char *
+lookup_value(struct name_table *table, uintmax_t val)
+{
+
+ for (; table->str != NULL; table++)
+ if (table->val == val)
+ return (table->str);
+ return (NULL);
+}
+
+/*
+ * Used when the value maps to a bitmask of #definition values in the
+ * table. This is a helper routine which outputs a symbolic mask of
+ * matched masks. Multiple masks are separated by a pipe ('|').
+ * The value is modified on return to only hold unmatched bits.
+ */
+static void
+print_mask_part(FILE *fp, struct name_table *table, uintmax_t *valp,
+ bool *printed)
+{
+ uintmax_t rem;
+
+ rem = *valp;
+ for (; table->str != NULL; table++) {
+ if ((table->val & rem) == table->val) {
+ /*
+ * Only print a zero mask if the raw value is
+ * zero.
+ */
+ if (table->val == 0 && *valp != 0)
+ continue;
+ fprintf(fp, "%s%s", *printed ? "|" : "", table->str);
+ *printed = true;
+ rem &= ~table->val;
+ }
+ }
+
+ *valp = rem;
+}
+
+/*
+ * Used when the value maps to a bitmask of #definition values in the
+ * table. The return value is true if something was printed. If
+ * rem is not NULL, *rem holds any bits not decoded if something was
+ * printed. If nothing was printed and rem is not NULL, *rem holds
+ * the original value.
+ */
+static bool
+print_mask_int(FILE *fp, struct name_table *table, int ival, int *rem)
+{
+ uintmax_t val;
+ bool printed;
+
+ printed = false;
+ val = (unsigned)ival;
+ print_mask_part(fp, table, &val, &printed);
+ if (rem != NULL)
+ *rem = val;
+ return (printed);
+}
+
+/*
+ * Used for a mask of optional flags where a value of 0 is valid.
+ */
+static bool
+print_mask_0(FILE *fp, struct name_table *table, int val, int *rem)
+{
+
+ if (val == 0) {
+ fputs("0", fp);
+ if (rem != NULL)
+ *rem = 0;
+ return (true);
+ }
+ return (print_mask_int(fp, table, val, rem));
+}
+
+/*
+ * Like print_mask_0 but for a unsigned long instead of an int.
+ */
+static bool
+print_mask_0ul(FILE *fp, struct name_table *table, u_long lval, u_long *rem)
+{
+ uintmax_t val;
+ bool printed;
+
+ if (lval == 0) {
+ fputs("0", fp);
+ if (rem != NULL)
+ *rem = 0;
+ return (true);
+ }
+
+ printed = false;
+ val = lval;
+ print_mask_part(fp, table, &val, &printed);
+ if (rem != NULL)
+ *rem = val;
+ return (printed);
+}
+
+static void
+print_integer(FILE *fp, int val, int base)
+{
+
+ switch (base) {
+ case 8:
+ fprintf(fp, "0%o", val);
+ break;
+ case 10:
+ fprintf(fp, "%d", val);
+ break;
+ case 16:
+ fprintf(fp, "0x%x", val);
+ break;
+ default:
+ abort2("bad base", 0, NULL);
+ break;
+ }
+}
+
+static bool
+print_value(FILE *fp, struct name_table *table, uintmax_t val)
+{
+ const char *str;
+
+ str = lookup_value(table, val);
+ if (str != NULL) {
+ fputs(str, fp);
+ return (true);
+ }
+ return (false);
+}
+
+void
+sysdecode_atfd(FILE *fp, int fd, int base)
+{
+
+ if (fd == AT_FDCWD)
+ fprintf(fp, "AT_FDCWD");
+ else
+ print_integer(fp, fd, base);
+}
+
+static struct name_table semctlops[] = {
+ X(GETNCNT) X(GETPID) X(GETVAL) X(GETALL) X(GETZCNT) X(SETVAL) X(SETALL)
+ X(IPC_RMID) X(IPC_SET) X(IPC_STAT) XEND
+};
+
+const char *
+sysdecode_semctl_op(int cmd)
+{
+
+ return (lookup_value(semctlops, cmd));
+}
+
+static struct name_table shmctlops[] = {
+ X(IPC_RMID) X(IPC_SET) X(IPC_STAT) XEND
+};
+
+const char *
+sysdecode_shmctl_op(int cmd)
+{
+
+ return (lookup_value(shmctlops, cmd));
+}
+
+const char *
+sysdecode_msgctl_op(int cmd)
+{
+
+ return (sysdecode_shmctl_op(cmd));
+}
+
+static struct name_table semgetflags[] = {
+ X(IPC_CREAT) X(IPC_EXCL) X(SEM_R) X(SEM_A) X((SEM_R>>3)) X((SEM_A>>3))
+ X((SEM_R>>6)) X((SEM_A>>6)) XEND
+};
+
+bool
+sysdecode_semget_flags(FILE *fp, int flag, int *rem)
+{
+
+ return (print_mask_int(fp, semgetflags, flag, rem));
+}
+
+static struct name_table idtypes[] = {
+ X(P_PID) X(P_PPID) X(P_PGID) X(P_SID) X(P_CID) X(P_UID) X(P_GID)
+ X(P_ALL) X(P_LWPID) X(P_TASKID) X(P_PROJID) X(P_POOLID) X(P_JAILID)
+ X(P_CTID) X(P_CPUID) X(P_PSETID) XEND
+};
+
+/* XXX: idtype is really an idtype_t */
+const char *
+sysdecode_idtype(int idtype)
+{
+
+ return (lookup_value(idtypes, idtype));
+}
+
+/*
+ * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
+ * referring to a line in /etc/protocols . It might be appropriate
+ * to use getprotoent(3) here.
+ */
+void
+sysdecode_sockopt_level(FILE *fp, int level, int base)
+{
+ if (level == SOL_SOCKET) {
+ fprintf(fp, "SOL_SOCKET");
+ } else {
+ print_integer(fp, level, base);
+ }
+}
+
+bool
+sysdecode_vmprot(FILE *fp, int type, int *rem)
+{
+
+ return (print_mask_int(fp, vmprot, type, rem));
+}
+
+void
+sysdecode_sockettypewithflags(FILE *fp, int type)
+{
+ const char *str;
+
+ str = sysdecode_sockettype(type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK));
+ if (str != NULL)
+ fputs(str, fp);
+ else
+ fprintf(fp, "%d", type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK));
+ if (type & SOCK_CLOEXEC)
+ fprintf(fp, "|SOCK_CLOEXEC");
+ if (type & SOCK_NONBLOCK)
+ fprintf(fp, "|SOCK_NONBLOCK");
+}
+
+bool
+sysdecode_accessmode(FILE *fp, int mode, int *rem)
+{
+
+ return (print_mask_int(fp, accessmode, mode, rem));
+}
+
+/* XXX: 'type' is really an acl_type_t. */
+const char *
+sysdecode_acltype(int type)
+{
+
+ return (lookup_value(acltype, type));
+}
+
+bool
+sysdecode_capfcntlrights(FILE *fp, uint32_t rights, uint32_t *rem)
+{
+
+ return (print_mask_int(fp, capfcntl, rights, rem));
+}
+
+const char *
+sysdecode_extattrnamespace(int namespace)
+{
+
+ return (lookup_value(extattrns, namespace));
+}
+
+const char *
+sysdecode_fadvice(int advice)
+{
+
+ return (lookup_value(fadvisebehav, advice));
+}
+
+bool
+sysdecode_open_flags(FILE *fp, int flags, int *rem)
+{
+ bool printed;
+ int mode;
+ uintmax_t val;
+
+ mode = flags & O_ACCMODE;
+ flags &= ~O_ACCMODE;
+ switch (mode) {
+ case O_RDONLY:
+ if (flags & O_EXEC) {
+ flags &= ~O_EXEC;
+ fputs("O_EXEC", fp);
+ } else
+ fputs("O_RDONLY", fp);
+ printed = true;
+ mode = 0;
+ break;
+ case O_WRONLY:
+ fputs("O_WRONLY", fp);
+ printed = true;
+ mode = 0;
+ break;
+ case O_RDWR:
+ fputs("O_RDWR", fp);
+ printed = true;
+ mode = 0;
+ break;
+ default:
+ printed = false;
+ }
+ val = (unsigned)flags;
+ print_mask_part(fp, openflags, &val, &printed);
+ if (rem != NULL)
+ *rem = val | mode;
+ return (printed);
+}
+
+bool
+sysdecode_fcntl_fileflags(FILE *fp, int flags, int *rem)
+{
+ bool printed;
+ int oflags;
+
+ /*
+ * The file flags used with F_GETFL/F_SETFL mostly match the
+ * flags passed to open(2). However, a few open-only flag
+ * bits have been repurposed for fcntl-only flags.
+ */
+ oflags = flags & ~(O_NOFOLLOW | FRDAHEAD);
+ printed = sysdecode_open_flags(fp, oflags, rem);
+ if (flags & O_NOFOLLOW) {
+ fprintf(fp, "%sFPOIXSHM", printed ? "|" : "");
+ printed = true;
+ }
+ if (flags & FRDAHEAD) {
+ fprintf(fp, "%sFRDAHEAD", printed ? "|" : "");
+ printed = true;
+ }
+ return (printed);
+}
+
+bool
+sysdecode_flock_op(FILE *fp, int operation, int *rem)
+{
+
+ return (print_mask_int(fp, flockops, operation, rem));
+}
+
+bool
+sysdecode_getfsstat_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, getfsstatflags, flags, rem));
+}
+
+const char *
+sysdecode_kldsym_cmd(int command)
+{
+
+ return (lookup_value(kldsymcmd, command));
+}
+
+const char *
+sysdecode_kldunload_flags(int flags)
+{
+
+ return (lookup_value(kldunloadfflags, flags));
+}
+
+const char *
+sysdecode_lio_listio_mode(int mode)
+{
+
+ return (lookup_value(lio_listiomodes, mode));
+}
+
+const char *
+sysdecode_madvice(int advice)
+{
+
+ return (lookup_value(madvisebehav, advice));
+}
+
+const char *
+sysdecode_minherit_flags(int inherit)
+{
+
+ return (lookup_value(minheritflags, inherit));
+}
+
+bool
+sysdecode_mlockall_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, mlockallflags, flags, rem));
+}
+
+bool
+sysdecode_mmap_prot(FILE *fp, int prot, int *rem)
+{
+
+ return (print_mask_int(fp, mmapprot, prot, rem));
+}
+
+bool
+sysdecode_fileflags(FILE *fp, fflags_t flags, fflags_t *rem)
+{
+
+ return (print_mask_0(fp, fileflags, flags, rem));
+}
+
+bool
+sysdecode_filemode(FILE *fp, int mode, int *rem)
+{
+
+ return (print_mask_0(fp, filemode, mode, rem));
+}
+
+bool
+sysdecode_mount_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, mountflags, flags, rem));
+}
+
+bool
+sysdecode_msync_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, msyncflags, flags, rem));
+}
+
+const char *
+sysdecode_nfssvc_flags(int flags)
+{
+
+ return (lookup_value(nfssvc, flags));
+}
+
+static struct name_table pipe2flags[] = {
+ X(O_CLOEXEC) X(O_NONBLOCK) XEND
+};
+
+bool
+sysdecode_pipe2_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_0(fp, pipe2flags, flags, rem));
+}
+
+const char *
+sysdecode_prio_which(int which)
+{
+
+ return (lookup_value(prio, which));
+}
+
+const char *
+sysdecode_procctl_cmd(int cmd)
+{
+
+ return (lookup_value(procctlcmd, cmd));
+}
+
+const char *
+sysdecode_ptrace_request(int request)
+{
+
+ return (lookup_value(ptraceop, request));
+}
+
+static struct name_table quotatypes[] = {
+ X(GRPQUOTA) X(USRQUOTA) XEND
+};
+
+bool
+sysdecode_quotactl_cmd(FILE *fp, int cmd)
+{
+ const char *primary, *type;
+
+ primary = lookup_value(quotactlcmds, cmd >> SUBCMDSHIFT);
+ type = lookup_value(quotatypes, cmd & SUBCMDMASK);
+ if (primary == NULL && type == NULL)
+ return (false);
+ fprintf(fp, "QCMD(");
+ if (primary != NULL)
+ fprintf(fp, "%s", primary);
+ else
+ fprintf(fp, "%#x", cmd >> SUBCMDSHIFT);
+ fprintf(fp, ",");
+ if (type != NULL)
+ fprintf(fp, "%s", type);
+ else
+ fprintf(fp, "%#x", cmd & SUBCMDMASK);
+ fprintf(fp, ")");
+ return (true);
+}
+
+bool
+sysdecode_reboot_howto(FILE *fp, int howto, int *rem)
+{
+
+ return (print_mask_int(fp, rebootopt, howto, rem));
+}
+
+bool
+sysdecode_rfork_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, rforkflags, flags, rem));
+}
+
+const char *
+sysdecode_rlimit(int resource)
+{
+
+ return (lookup_value(rlimit, resource));
+}
+
+const char *
+sysdecode_scheduler_policy(int policy)
+{
+
+ return (lookup_value(schedpolicy, policy));
+}
+
+bool
+sysdecode_sendfile_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, sendfileflags, flags, rem));
+}
+
+bool
+sysdecode_shmat_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, shmatflags, flags, rem));
+}
+
+const char *
+sysdecode_shutdown_how(int how)
+{
+
+ return (lookup_value(shutdownhow, how));
+}
+
+const char *
+sysdecode_sigbus_code(int si_code)
+{
+
+ return (lookup_value(sigbuscode, si_code));
+}
+
+const char *
+sysdecode_sigchld_code(int si_code)
+{
+
+ return (lookup_value(sigchldcode, si_code));
+}
+
+const char *
+sysdecode_sigfpe_code(int si_code)
+{
+
+ return (lookup_value(sigfpecode, si_code));
+}
+
+const char *
+sysdecode_sigill_code(int si_code)
+{
+
+ return (lookup_value(sigillcode, si_code));
+}
+
+const char *
+sysdecode_sigsegv_code(int si_code)
+{
+
+ return (lookup_value(sigsegvcode, si_code));
+}
+
+const char *
+sysdecode_sigtrap_code(int si_code)
+{
+
+ return (lookup_value(sigtrapcode, si_code));
+}
+
+const char *
+sysdecode_sigprocmask_how(int how)
+{
+
+ return (lookup_value(sigprocmaskhow, how));
+}
+
+const char *
+sysdecode_socketdomain(int domain)
+{
+
+ return (lookup_value(sockdomain, domain));
+}
+
+const char *
+sysdecode_sockaddr_family(int sa_family)
+{
+
+ return (lookup_value(sockfamily, sa_family));
+}
+
+const char *
+sysdecode_ipproto(int protocol)
+{
+
+ return (lookup_value(sockipproto, protocol));
+}
+
+/* Accept level and optname? */
+const char *
+sysdecode_sockopt_name(int optname)
+{
+
+ return (lookup_value(sockopt, optname));
+}
+
+const char *
+sysdecode_sockettype(int type)
+{
+
+ return (lookup_value(socktype, type));
+}
+
+bool
+sysdecode_thr_create_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_int(fp, thrcreateflags, flags, rem));
+}
+
+const char *
+sysdecode_umtx_op(int op)
+{
+
+ return (lookup_value(umtxop, op));
+}
+
+const char *
+sysdecode_vmresult(int result)
+{
+
+ return (lookup_value(vmresult, result));
+}
+
+bool
+sysdecode_wait4_options(FILE *fp, int options, int *rem)
+{
+ bool printed;
+ int opt6;
+
+ /* A flags value of 0 is normal. */
+ if (options == 0) {
+ fputs("0", fp);
+ if (rem != NULL)
+ *rem = 0;
+ return (true);
+ }
+
+ /*
+ * These flags are implicit and aren't valid flags for wait4()
+ * directly (though they don't fail with EINVAL).
+ */
+ opt6 = options & (WEXITED | WTRAPPED);
+ options &= ~opt6;
+ printed = print_mask_int(fp, wait6opt, options, rem);
+ if (rem != NULL)
+ *rem |= opt6;
+ return (printed);
+}
+
+bool
+sysdecode_wait6_options(FILE *fp, int options, int *rem)
+{
+
+ return (print_mask_int(fp, wait6opt, options, rem));
+}
+
+const char *
+sysdecode_whence(int whence)
+{
+
+ return (lookup_value(seekwhence, whence));
+}
+
+const char *
+sysdecode_fcntl_cmd(int cmd)
+{
+
+ return (lookup_value(fcntlcmd, cmd));
+}
+
+static struct name_table fcntl_fd_arg[] = {
+ X(FD_CLOEXEC) X(0) XEND
+};
+
+bool
+sysdecode_fcntl_arg_p(int cmd)
+{
+
+ switch (cmd) {
+ case F_GETFD:
+ case F_GETFL:
+ case F_GETOWN:
+ return (false);
+ default:
+ return (true);
+ }
+}
+
+void
+sysdecode_fcntl_arg(FILE *fp, int cmd, uintptr_t arg, int base)
+{
+ int rem;
+
+ switch (cmd) {
+ case F_SETFD:
+ if (!print_value(fp, fcntl_fd_arg, arg))
+ print_integer(fp, arg, base);
+ break;
+ case F_SETFL:
+ if (!sysdecode_fcntl_fileflags(fp, arg, &rem))
+ fprintf(fp, "%#x", rem);
+ else if (rem != 0)
+ fprintf(fp, "|%#x", rem);
+ break;
+ case F_GETLK:
+ case F_SETLK:
+ case F_SETLKW:
+ fprintf(fp, "%p", (void *)arg);
+ break;
+ default:
+ print_integer(fp, arg, base);
+ break;
+ }
+}
+
+bool
+sysdecode_mmap_flags(FILE *fp, int flags, int *rem)
+{
+ uintmax_t val;
+ bool printed;
+ int align;
+
+ /*
+ * MAP_ALIGNED can't be handled directly by print_mask_int().
+ * MAP_32BIT is also problematic since it isn't defined for
+ * all platforms.
+ */
+ printed = false;
+ align = flags & MAP_ALIGNMENT_MASK;
+ val = (unsigned)flags & ~MAP_ALIGNMENT_MASK;
+ print_mask_part(fp, mmapflags, &val, &printed);
+#ifdef MAP_32BIT
+ if (val & MAP_32BIT) {
+ fprintf(fp, "%sMAP_32BIT", printed ? "|" : "");
+ printed = true;
+ val &= ~MAP_32BIT;
+ }
+#endif
+ if (align != 0) {
+ if (printed)
+ fputc('|', fp);
+ if (align == MAP_ALIGNED_SUPER)
+ fputs("MAP_ALIGNED_SUPER", fp);
+ else
+ fprintf(fp, "MAP_ALIGNED(%d)",
+ align >> MAP_ALIGNMENT_SHIFT);
+ printed = true;
+ }
+ if (rem != NULL)
+ *rem = val;
+ return (printed);
+}
+
+const char *
+sysdecode_rtprio_function(int function)
+{
+
+ return (lookup_value(rtpriofuncs, function));
+}
+
+bool
+sysdecode_msg_flags(FILE *fp, int flags, int *rem)
+{
+
+ return (print_mask_0(fp, msgflags, flags, rem));
+}
+
+const char *
+sysdecode_sigcode(int sig, int code)
+{
+ const char *str;
+
+ str = lookup_value(sigcode, code);
+ if (str != NULL)
+ return (str);
+
+ switch (sig) {
+ case SIGILL:
+ return (sysdecode_sigill_code(code));
+ case SIGBUS:
+ return (sysdecode_sigbus_code(code));
+ case SIGSEGV:
+ return (sysdecode_sigsegv_code(code));
+ case SIGFPE:
+ return (sysdecode_sigfpe_code(code));
+ case SIGTRAP:
+ return (sysdecode_sigtrap_code(code));
+ case SIGCHLD:
+ return (sysdecode_sigchld_code(code));
+ default:
+ return (NULL);
+ }
+}
+
+bool
+sysdecode_umtx_cvwait_flags(FILE *fp, u_long flags, u_long *rem)
+{
+
+ return (print_mask_0ul(fp, umtxcvwaitflags, flags, rem));
+}
+
+bool
+sysdecode_umtx_rwlock_flags(FILE *fp, u_long flags, u_long *rem)
+{
+
+ return (print_mask_0ul(fp, umtxrwlockflags, flags, rem));
+}
+
+/* XXX: This should be in <sys/capsicum.h> */
+#define CAPMASK(right) ((right) && (((uint64_t)1 << 57) - 1))
+
+void
+sysdecode_capname(FILE *fp, cap_rights_t *rightsp)
+{
+ struct name_table *t;
+ int idx;
+ bool comma;
+
+ comma = false;
+ for (t = caprights; t->str != NULL; t++) {
+ idx = ffs(CAPIDXBIT(t->val)) - 1;
+ if (CAPARSIZE(rightsp) < idx)
+ continue;
+ if ((rightsp->cr_rights[CAPIDXBIT(t->val)] & CAPMASK(t->val)) ==
+ CAPMASK(t->val)) {
+ fprintf(fp, "%s%s", comma ? "," : "", t->str);
+ comma = true;
+ }
+ }
+}
Index: lib/libsysdecode/mkioctls
===================================================================
--- lib/libsysdecode/mkioctls
+++ lib/libsysdecode/mkioctls
@@ -62,6 +62,7 @@
print "#include <netinet6/ip6_mroute.h>"
print "#include <stdio.h>"
print "#include <cam/cam.h>"
+ print "#include <stdbool.h>"
print "#include <stddef.h>"
print "#include <stdint.h>"
print "#include <sysdecode.h>"
Index: lib/libsysdecode/mktables
===================================================================
--- /dev/null
+++ lib/libsysdecode/mktables
@@ -0,0 +1,140 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. 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$
+#
+# Generates tables.h
+#
+# Originally this script was 'mksubr' for kdump which generated a complete
+# C file along with function definitions. Now this script generates tables
+# of constants and names extracted from header files.
+
+set -e
+
+LC_ALL=C; export LC_ALL
+
+if [ -z "$1" ]
+then
+ echo "usage: sh $0 include-dir"
+ exit 1
+fi
+include_dir=$1
+
+#
+# Generate a table C #definitions. The including file can define the
+# TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to define what
+# the tables map to.
+#
+gen_table()
+{
+ local name grep file excl filter
+ name=$1
+ grep=$2
+ file=$3
+ excl=$4
+
+ if [ -z "$excl" ]; then
+ filter="cat"
+ else
+ filter="egrep -v"
+ fi
+ cat <<_EOF_
+TABLE_START(${name})
+_EOF_
+ egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
+ $include_dir/$file | ${filter} ${excl} | \
+ awk '{ for (i = 1; i <= NF; i++) \
+ if ($i ~ /define/) \
+ break; \
+ ++i; \
+ printf "TABLE_ENTRY(%s)\n", $i }'
+cat <<_EOF_
+TABLE_END
+
+_EOF_
+}
+
+cat <<_EOF_
+/* This file is auto-generated. */
+
+_EOF_
+
+gen_table "accessmode" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
+gen_table "acltype" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
+gen_table "capfcntl" "CAP_FCNTL_[A-Z]+[[:space:]]+\(1" "sys/capsicum.h"
+gen_table "extattrns" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
+gen_table "fadvisebehav" "POSIX_FADV_[A-Z]+[[:space:]]+[0-9]+" "sys/fcntl.h"
+gen_table "openflags" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h" "O_RDONLY|O_RDWR|O_WRONLY"
+gen_table "flockops" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
+gen_table "getfsstatflags" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
+gen_table "kldsymcmd" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
+gen_table "kldunloadfflags" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
+gen_table "lio_listiomodes" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
+gen_table "madvisebehav" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
+gen_table "minheritflags" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
+gen_table "mlockallflags" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
+gen_table "mmapprot" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
+gen_table "fileflags" "[SU]F_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/stat.h" "UF_COMPRESSED|UF_TRACKED"
+gen_table "filemode" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
+gen_table "mountflags" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
+gen_table "msyncflags" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
+gen_table "nfssvc" "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+" "nfs/nfssvc.h"
+gen_table "prio" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
+gen_table "procctlcmd" "PROC_[A-Z_]+[[:space:]]+[0-9]" "sys/procctl.h" "PROC_TRACE_CTL_"
+gen_table "ptraceop" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
+gen_table "quotactlcmds" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
+gen_table "rebootopt" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
+gen_table "rforkflags" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h"
+gen_table "rlimit" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
+gen_table "schedpolicy" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
+gen_table "sendfileflags" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
+gen_table "shmatflags" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h"
+gen_table "shutdownhow" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
+gen_table "sigbuscode" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sigchldcode" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sigfpecode" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sigprocmaskhow" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sigillcode" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sigsegvcode" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sigtrapcode" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
+gen_table "sockdomain" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
+gen_table "sockfamily" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
+gen_table "sockipproto" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
+gen_table "sockopt" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
+gen_table "socktype" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
+gen_table "thrcreateflags" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
+gen_table "umtxop" "UMTX_OP_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/umtx.h"
+gen_table "vmprot" "VM_PROT_[A-Z]+[[:space:]]+\(\(vm_prot_t\)\)" "vm/vm.h"
+gen_table "vmresult" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h"
+gen_table "wait6opt" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
+gen_table "seekwhence" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
+gen_table "fcntlcmd" "F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]+" "sys/fcntl.h" "F_CANCEL|F_..LCK"
+gen_table "mmapflags" "MAP_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
+gen_table "rtpriofuncs" "RTP_[A-Z]+[[:space:]]+[0-9]+" "sys/rtprio.h"
+gen_table "msgflags" "MSG_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h" "MSG_SOCALLBCK"
+gen_table "sigcode" "SI_[A-Z]+[[:space:]]+0(x[0-9abcdef]+)?" "sys/signal.h"
+gen_table "umtxcvwaitflags" "CVWAIT_[A-Z_]+[[:space:]]+0x[0-9]+" "sys/umtx.h"
+gen_table "umtxrwlockflags" "URWLOCK_PREFER_READER[[:space:]]+0x[0-9]+" "sys/umtx.h"
+gen_table "caprights" "CAP_[A-Z_]+[[:space:]]+CAPRIGHT\([0-9],[[:space:]]+0x[0-9]{16}ULL\)" "sys/capsicum.h"
Index: lib/libsysdecode/signal.c
===================================================================
--- lib/libsysdecode/signal.c
+++ lib/libsysdecode/signal.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
+ * Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -22,26 +22,35 @@
* 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$
*/
-#ifndef __SYSDECODE_H__
-#define __SYSDECODE_H__
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
-enum sysdecode_abi {
- SYSDECODE_ABI_UNKNOWN = 0,
- SYSDECODE_ABI_FREEBSD,
- SYSDECODE_ABI_FREEBSD32,
- SYSDECODE_ABI_LINUX,
- SYSDECODE_ABI_LINUX32,
- SYSDECODE_ABI_CLOUDABI64
-};
+#include <sys/types.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sysdecode.h>
-int sysdecode_abi_to_freebsd_errno(enum sysdecode_abi _abi, int _error);
-int sysdecode_freebsd_to_abi_errno(enum sysdecode_abi _abi, int _error);
-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);
+const char *
+sysdecode_signal(int sig)
+{
+ static char sigbuf[64];
-#endif /* !__SYSDECODE_H__ */
+ if (sig > 0 && sig < NSIG) {
+ snprintf(sigbuf, sizeof(sigbuf), "SIG%s", sys_signame[sig]);
+ return (sigbuf);
+ }
+ switch (sig) {
+ case SIGTHR:
+ return ("SIGTHR");
+ case SIGLIBRT:
+ return ("SIGLIBRT");
+ }
+ if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
+ snprintf(sigbuf, sizeof(sigbuf), "SIGRT%d", sig - SIGRTMIN);
+ return (sigbuf);
+ }
+ return (NULL);
+}
Index: lib/libsysdecode/syscallnames.c
===================================================================
--- lib/libsysdecode/syscallnames.c
+++ lib/libsysdecode/syscallnames.c
@@ -35,6 +35,9 @@
*/
#include <sys/param.h>
+#include <sys/acl.h>
+#include <sys/wait.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: lib/libsysdecode/sysdecode.h
===================================================================
--- lib/libsysdecode/sysdecode.h
+++ lib/libsysdecode/sysdecode.h
@@ -39,9 +39,80 @@
};
int sysdecode_abi_to_freebsd_errno(enum sysdecode_abi _abi, int _error);
+bool sysdecode_accessmode(FILE *_fp, int _mode, int *_rem);
+const char *sysdecode_acltype(int _type);
+void sysdecode_atfd(FILE *_fp, int _fd, int _base);
+bool sysdecode_capfcntlrights(FILE *_fp, uint32_t _rights, uint32_t *_rem);
+void sysdecode_capname(FILE *_fp, cap_rights_t *_rightsp);
+const char *sysdecode_extattrnamespace(int _namespace);
+const char *sysdecode_fadvice(int _advice);
+void sysdecode_fcntl_arg(FILE *_fp, int _cmd, uintptr_t _arg, int _base);
+bool sysdecode_fcntl_arg_p(int _cmd);
+const char *sysdecode_fcntl_cmd(int _cmd);
+bool sysdecode_fcntl_fileflags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_fileflags(FILE *_fp, fflags_t _flags, fflags_t *_rem);
+bool sysdecode_filemode(FILE *_fp, int _mode, int *_rem);
+bool sysdecode_flock_op(FILE *_fp, int _operation, int *_rem);
int sysdecode_freebsd_to_abi_errno(enum sysdecode_abi _abi, int _error);
+bool sysdecode_getfsstat_flags(FILE *_fp, int _flags, int *_rem);
+const char *sysdecode_idtype(int _idtype);
const char *sysdecode_ioctlname(unsigned long _val);
+const char *sysdecode_ipproto(int _protocol);
+const char *sysdecode_kldsym_cmd(int _command);
+const char *sysdecode_kldunload_flags(int _flags);
+const char *sysdecode_lio_listio_mode(int _mode);
+const char *sysdecode_madvice(int _advice);
+const char *sysdecode_minherit_flags(int _inherit);
+const char *sysdecode_msgctl_op(int _cmd);
+bool sysdecode_mlockall_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_mmap_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_mmap_prot(FILE *_fp, int _prot, int *_rem);
+bool sysdecode_mount_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_msg_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_msync_flags(FILE *_fp, int _flags, int *_rem);
+const char *sysdecode_nfssvc_flags(int _flags);
+bool sysdecode_open_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_pipe2_flags(FILE *_fp, int _flags, int *_rem);
+const char *sysdecode_prio_which(int _which);
+const char *sysdecode_procctl_cmd(int _cmd);
+const char *sysdecode_ptrace_request(int _request);
+bool sysdecode_quotactl_cmd(FILE *_fp, int _cmd);
+bool sysdecode_reboot_howto(FILE *_fp, int _howto, int *_rem);
+bool sysdecode_rfork_flags(FILE *_fp, int _flags, int *_rem);
+const char *sysdecode_rlimit(int _resource);
+const char *sysdecode_rtprio_function(int _function);
+const char *sysdecode_scheduler_policy(int _policy);
+const char *sysdecode_semctl_op(int _cmd);
+bool sysdecode_semget_flags(FILE *_fp, int _flag, int *_rem);
+bool sysdecode_sendfile_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_shmat_flags(FILE *_fp, int _flags, int *_rem);
+const char *sysdecode_shmctl_op(int _cmd);
+const char *sysdecode_shutdown_how(int _how);
+const char *sysdecode_sigbus_code(int _si_code);
+const char *sysdecode_sigchld_code(int _si_code);
+const char *sysdecode_sigcode(int _sig, int _code);
+const char *sysdecode_sigfpe_code(int _si_code);
+const char *sysdecode_sigill_code(int _si_code);
+const char *sysdecode_signal(int _sig);
+const char *sysdecode_sigprocmask_how(int _how);
+const char *sysdecode_sigsegv_code(int _si_code);
+const char *sysdecode_sigtrap_code(int _si_code);
+const char *sysdecode_sockaddr_family(int _sa_family);
+const char *sysdecode_socketdomain(int _domain);
+const char *sysdecode_sockettype(int _type);
+void sysdecode_sockettypewithflags(FILE *_fp, int _type);
+void sysdecode_sockopt_level(FILE *_fp, int _level, int _base);
+const char *sysdecode_sockopt_name(int _optname);
const char *sysdecode_syscallname(enum sysdecode_abi _abi, unsigned int _code);
+bool sysdecode_thr_create_flags(FILE *_fp, int _flags, int *_rem);
+bool sysdecode_umtx_cvwait_flags(FILE *_fp, u_long _flags, u_long *_rem);
+const char *sysdecode_umtx_op(int _op);
+bool sysdecode_umtx_rwlock_flags(FILE *_fp, u_long _flags, u_long *_rem);
int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len);
+bool sysdecode_vmprot(FILE *_fp, int _type, int *_rem);
+const char *sysdecode_vmresult(int _result);
+bool sysdecode_wait4_options(FILE *_fp, int _options, int *_rem);
+bool sysdecode_wait6_options(FILE *_fp, int _options, int *_rem);
+const char *sysdecode_whence(int _whence);
#endif /* !__SYSDECODE_H__ */
Index: lib/libsysdecode/sysdecode_abi_to_freebsd_errno.3
===================================================================
--- lib/libsysdecode/sysdecode_abi_to_freebsd_errno.3
+++ lib/libsysdecode/sysdecode_abi_to_freebsd_errno.3
@@ -35,6 +35,9 @@
.Sh LIBRARY
.Lb libsysdecode
.Sh SYNOPSIS
+.In sys/types.h
+.In stdbool.h
+.In sysdecode.h
.Ft int
.Fn sysdecode_abi_to_freebsd_errno "enum sysdecode_abi abi" "int error"
.Ft int
Index: lib/libsysdecode/sysdecode_ioctlname.3
===================================================================
--- lib/libsysdecode/sysdecode_ioctlname.3
+++ lib/libsysdecode/sysdecode_ioctlname.3
@@ -34,6 +34,9 @@
.Sh LIBRARY
.Lb libsysdecode
.Sh SYNOPSIS
+.In sys/types.h
+.In stdbool.h
+.In sysdecode.h
.Ft conts char *
.Fn sysdecode_ioctlname "unsigned long request"
.Sh DESCRIPTION
Index: lib/libsysdecode/sysdecode_syscallnames.3
===================================================================
--- lib/libsysdecode/sysdecode_syscallnames.3
+++ lib/libsysdecode/sysdecode_syscallnames.3
@@ -34,6 +34,9 @@
.Sh LIBRARY
.Lb libsysdecode
.Sh SYNOPSIS
+.In sys/types.h
+.In stdbool.h
+.In sysdecode.h
.Ft const char *
.Fn sysdecode_syscallnames "enum sysdecode_abi abi" "unsigned int code"
.Sh DESCRIPTION
Index: lib/libsysdecode/sysdecode_utrace.3
===================================================================
--- lib/libsysdecode/sysdecode_utrace.3
+++ lib/libsysdecode/sysdecode_utrace.3
@@ -34,6 +34,9 @@
.Sh LIBRARY
.Lb libsysdecode
.Sh SYNOPSIS
+.In sys/types.h
+.In stdbool.h
+.In sysdecode.h
.Ft int
.Fn sysdecode_utrace "FILE *fp" "void *buf" "size_t len" "int decimal"
.Sh DESCRIPTION
Index: lib/libsysdecode/utrace.c
===================================================================
--- lib/libsysdecode/utrace.c
+++ lib/libsysdecode/utrace.c
@@ -32,6 +32,7 @@
#include <sys/param.h>
#include <dlfcn.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sysdecode.h>
Index: usr.bin/kdump/Makefile
===================================================================
--- usr.bin/kdump/Makefile
+++ usr.bin/kdump/Makefile
@@ -6,8 +6,8 @@
.PATH: ${.CURDIR}/../ktrace
PROG= kdump
-SRCS= kdump_subr.c kdump_subr.h kdump.c subr.c
-CFLAGS+= -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
+SRCS= kdump.c subr.c
+CFLAGS+= -I${.CURDIR}/../ktrace #-I${.CURDIR}/../...
LIBADD= sysdecode
.if ${MK_CASPER} != "no"
@@ -17,15 +17,6 @@
CFLAGS+=-DHAVE_LIBCASPER
.endif
-NO_WERROR?= YES
-
-CLEANFILES= kdump_subr.c kdump_subr.h
-
-kdump_subr.h: mksubr
- sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} | \
- sed -n 's/^\([a-z].*)\)$$/void \1;/p' >${.TARGET}
-
-kdump_subr.c: mksubr kdump_subr.h
- sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} >${.TARGET}
+#NO_WERROR?= YES
.include <bsd.prog.mk>
Index: usr.bin/kdump/kdump.c
===================================================================
--- usr.bin/kdump/kdump.c
+++ usr.bin/kdump/kdump.c
@@ -74,6 +74,7 @@
#include <netdb.h>
#include <nl_types.h>
#include <pwd.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -83,7 +84,6 @@
#include <unistd.h>
#include <vis.h>
#include "ktrace.h"
-#include "kdump_subr.h"
#ifdef HAVE_LIBCASPER
#include <libcasper.h>
@@ -122,8 +122,6 @@
#define TIMESTAMP_ELAPSED 0x2
#define TIMESTAMP_RELATIVE 0x4
-extern const char *signames[];
-
static int timestamp, decimal, fancy = 1, suppressdata, tail, threads, maxdata,
resolv = 0, abiflag = 0, syscallno = 0;
static const char *tracefile = DEF_TRACEFILE;
@@ -132,6 +130,27 @@
#define TIME_FORMAT "%b %e %T %Y"
#define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
+#define print_number64(first,i,n,c) do { \
+ uint64_t __v; \
+ \
+ if (quad_align && (((ptrdiff_t)((i) - (first))) & 1) == 1) { \
+ (i)++; \
+ (n)--; \
+ } \
+ if (quad_slots == 2) \
+ __v = (uint64_t)(uint32_t)(i)[0] | \
+ ((uint64_t)(uint32_t)(i)[1]) << 32; \
+ else \
+ __v = (uint64_t)*(i); \
+ if (decimal) \
+ printf("%c%jd", (c), (intmax_t)__v); \
+ else \
+ printf("%c%#jx", (c), (uintmax_t)__v); \
+ (i) += quad_slots; \
+ (n) -= quad_slots; \
+ (c) = ','; \
+} while (0)
+
#define print_number(i,n,c) do { \
if (decimal) \
printf("%c%jd", c, (intmax_t)*i); \
@@ -224,6 +243,116 @@
}
#endif /* HAVE_LIBCASPER */
+static void
+print_integer_arg(const char *(*decoder)(int), int value)
+{
+ const char *str;
+
+ str = decoder(value);
+ if (str != NULL)
+ printf("%s", str);
+ else {
+ if (decimal)
+ printf("<invalid=%d>", value);
+ else
+ printf("<invalid=%#x>", value);
+ }
+}
+
+static void
+print_mask_arg(bool (*decoder)(FILE *, int, int *), int value)
+{
+ bool invalid;
+ int rem;
+
+ printf("%#x<", value);
+ invalid = !decoder(stdout, value, &rem);
+ printf(">");
+ if (invalid)
+ printf("<invalid>%u", rem);
+}
+
+static void
+print_mask_arg0(bool (*decoder)(FILE *, int, int *), int value)
+{
+ bool invalid;
+ int rem;
+
+ if (value == 0) {
+ printf("0");
+ return;
+ }
+ printf("%#x<", value);
+ invalid = !decoder(stdout, value, &rem);
+ printf(">");
+ if (invalid)
+ printf("<invalid>%u", rem);
+}
+
+static void
+decode_fileflags(fflags_t value)
+{
+ bool invalid;
+ fflags_t rem;
+
+ if (value == 0) {
+ printf("0");
+ return;
+ }
+ printf("%#x<", value);
+ invalid = !sysdecode_fileflags(stdout, value, &rem);
+ printf(">");
+ if (invalid)
+ printf("<invalid>%u", rem);
+}
+
+static void
+decode_filemode(int value)
+{
+ bool invalid;
+ int rem;
+
+ if (value == 0) {
+ printf("0");
+ return;
+ }
+ printf("%#o<", value);
+ invalid = !sysdecode_filemode(stdout, value, &rem);
+ printf(">");
+ if (invalid)
+ printf("<invalid>%u", rem);
+}
+
+static void
+print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *), uint32_t value)
+{
+ bool invalid;
+ uint32_t rem;
+
+ printf("%#x<", value);
+ invalid = !decoder(stdout, value, &rem);
+ printf(">");
+ if (invalid)
+ printf("<invalid>%u", rem);
+}
+
+static void
+print_mask_argul(bool (*decoder)(FILE *, u_long, u_long *), u_long value)
+{
+ bool invalid;
+ u_long rem;
+
+ if (value == 0) {
+ printf("0");
+ return;
+ }
+ printf("%#lx<", value);
+ invalid = !decoder(stdout, value, &rem);
+ printf(">");
+ if (invalid)
+ printf("<invalid>%lu", rem);
+}
+
int
main(int argc, char *argv[])
{
@@ -701,20 +830,41 @@
}
}
+static void
+print_signal(int signo)
+{
+ const char *signame;
+
+ signame = sysdecode_signal(signo);
+ if (signame != NULL)
+ printf("%s", signame);
+ else
+ printf("SIG %d", signo);
+}
+
void
ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags)
{
int narg = ktr->ktr_narg;
- register_t *ip;
+ register_t *ip, *first;
intmax_t arg;
+ int quad_align, quad_slots;
syscallname(ktr->ktr_code, sv_flags);
- ip = &ktr->ktr_args[0];
+ ip = first = &ktr->ktr_args[0];
if (narg) {
char c = '(';
if (fancy &&
(sv_flags == 0 ||
(sv_flags & SV_ABI_MASK) == SV_ABI_FREEBSD)) {
+ quad_align = 0;
+ if (sv_flags & SV_ILP32) {
+#ifdef __powerpc__
+ quad_align = 1;
+#endif
+ quad_slots = 2;
+ } else
+ quad_slots = 1;
switch (ktr->ktr_code) {
case SYS_bindat:
case SYS_connectat:
@@ -733,7 +883,7 @@
case SYS_unlinkat:
case SYS_utimensat:
putchar('(');
- atfdname(*ip, decimal);
+ sysdecode_atfd(stdout, *ip, decimal ? 10 : 16);
c = ',';
ip++;
narg--;
@@ -751,7 +901,7 @@
}
case SYS_ptrace:
putchar('(');
- ptraceopname(*ip);
+ print_integer_arg(sysdecode_ptrace_request, *ip);
c = ',';
ip++;
narg--;
@@ -761,7 +911,7 @@
case SYS_faccessat:
print_number(ip, narg, c);
putchar(',');
- accessmodename(*ip);
+ print_mask_arg(sysdecode_accessmode, *ip);
ip++;
narg--;
break;
@@ -769,37 +919,32 @@
case SYS_openat:
print_number(ip, narg, c);
putchar(',');
- flagsandmodename(ip[0], ip[1], decimal);
+ print_mask_arg(sysdecode_open_flags, ip[0]);
+ if ((ip[0] & O_CREAT) == O_CREAT) {
+ putchar(',');
+ decode_filemode(ip[1]);
+ }
ip += 2;
narg -= 2;
break;
case SYS_wait4:
print_number(ip, narg, c);
print_number(ip, narg, c);
- /*
- * A flags value of zero is valid for
- * wait4() but not for wait6(), so
- * handle zero special here.
- */
- if (*ip == 0) {
- print_number(ip, narg, c);
- } else {
- putchar(',');
- wait6optname(*ip);
- ip++;
- narg--;
- }
+ putchar(',');
+ print_mask_arg0(sysdecode_wait4_options, *ip);
+ ip++;
+ narg--;
break;
case SYS_wait6:
putchar('(');
- idtypename(*ip, decimal);
+ print_integer_arg(sysdecode_idtype, *ip);
c = ',';
ip++;
narg--;
- print_number(ip, narg, c);
+ print_number64(first, ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- wait6optname(*ip);
+ print_mask_arg(sysdecode_wait6_options, *ip);
ip++;
narg--;
break;
@@ -809,7 +954,7 @@
case SYS_fchmodat:
print_number(ip, narg, c);
putchar(',');
- modename(*ip);
+ decode_filemode(*ip);
ip++;
narg--;
break;
@@ -817,7 +962,7 @@
case SYS_mknodat:
print_number(ip, narg, c);
putchar(',');
- modename(*ip);
+ decode_filemode(*ip);
ip++;
narg--;
break;
@@ -825,7 +970,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- getfsstatflagsname(*ip);
+ print_mask_arg(sysdecode_getfsstat_flags, *ip);
ip++;
narg--;
break;
@@ -833,14 +978,14 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- mountflagsname(*ip);
+ print_mask_arg(sysdecode_mount_flags, *ip);
ip++;
narg--;
break;
case SYS_unmount:
print_number(ip, narg, c);
putchar(',');
- mountflagsname(*ip);
+ print_mask_arg(sysdecode_mount_flags, *ip);
ip++;
narg--;
break;
@@ -849,7 +994,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- sendrecvflagsname(*ip);
+ print_mask_arg0(sysdecode_msg_flags, *ip);
ip++;
narg--;
break;
@@ -859,7 +1004,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- sendrecvflagsname(*ip);
+ print_mask_arg0(sysdecode_msg_flags, *ip);
ip++;
narg--;
break;
@@ -868,26 +1013,26 @@
case SYS_lchflags:
print_number(ip, narg, c);
putchar(',');
- modename(*ip);
+ decode_fileflags(*ip);
ip++;
narg--;
break;
case SYS_kill:
print_number(ip, narg, c);
putchar(',');
- signame(*ip);
+ print_signal(*ip);
ip++;
narg--;
break;
case SYS_reboot:
putchar('(');
- rebootoptname(*ip);
+ print_mask_arg(sysdecode_reboot_howto, *ip);
ip++;
narg--;
break;
case SYS_umask:
putchar('(');
- modename(*ip);
+ decode_filemode(*ip);
ip++;
narg--;
break;
@@ -895,7 +1040,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- msyncflagsname(*ip);
+ print_mask_arg(sysdecode_msync_flags, *ip);
ip++;
narg--;
break;
@@ -904,11 +1049,11 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- mmapprotname(*ip);
+ print_mask_arg(sysdecode_mmap_prot, *ip);
putchar(',');
ip++;
narg--;
- mmapflagsname(*ip);
+ print_mask_arg(sysdecode_mmap_flags, *ip);
ip++;
narg--;
break;
@@ -917,11 +1062,11 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- mmapprotname(*ip);
+ print_mask_arg(sysdecode_mmap_prot, *ip);
putchar(',');
ip++;
narg--;
- mmapflagsname(*ip);
+ print_mask_arg(sysdecode_mmap_flags, *ip);
ip++;
narg--;
break;
@@ -929,7 +1074,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- mmapprotname(*ip);
+ print_mask_arg(sysdecode_mmap_prot, *ip);
ip++;
narg--;
break;
@@ -937,7 +1082,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- madvisebehavname(*ip);
+ print_integer_arg(sysdecode_madvice, *ip);
ip++;
narg--;
break;
@@ -945,14 +1090,25 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- prioname(*ip);
+ print_integer_arg(sysdecode_prio_which, *ip);
ip++;
narg--;
break;
case SYS_fcntl:
print_number(ip, narg, c);
putchar(',');
- fcntlcmdname(ip[0], ip[1], decimal);
+ print_integer_arg(sysdecode_fcntl_cmd, ip[0]);
+ if (sysdecode_fcntl_arg_p(ip[0])) {
+ putchar(',');
+ if (ip[0] == F_SETFL)
+ print_mask_arg(
+ sysdecode_fcntl_fileflags,
+ ip[1]);
+ else
+ sysdecode_fcntl_arg(stdout,
+ ip[0], ip[1],
+ decimal ? 10 : 16);
+ }
ip += 2;
narg -= 2;
break;
@@ -960,17 +1116,19 @@
int sockdomain;
putchar('(');
sockdomain = *ip;
- sockdomainname(sockdomain);
+ print_integer_arg(sysdecode_socketdomain,
+ sockdomain);
ip++;
narg--;
putchar(',');
- socktypenamewithflags(*ip);
+ sysdecode_sockettypewithflags(stdout, *ip);
ip++;
narg--;
if (sockdomain == PF_INET ||
sockdomain == PF_INET6) {
putchar(',');
- sockipprotoname(*ip);
+ print_integer_arg(sysdecode_ipproto,
+ *ip);
ip++;
narg--;
}
@@ -981,12 +1139,14 @@
case SYS_getsockopt:
print_number(ip, narg, c);
putchar(',');
- sockoptlevelname(*ip, decimal);
+ sysdecode_sockopt_level(stdout, *ip,
+ decimal ? 10 : 16);
if (*ip == SOL_SOCKET) {
ip++;
narg--;
putchar(',');
- sockoptname(*ip);
+ print_integer_arg(sysdecode_sockopt_name,
+ *ip);
}
ip++;
narg--;
@@ -996,26 +1156,25 @@
print_number(ip, narg, c);
/* Hidden 'pad' argument, not in lseek(2) */
print_number(ip, narg, c);
- print_number(ip, narg, c);
+ print_number64(first, ip, narg, c);
putchar(',');
- whencename(*ip);
+ print_integer_arg(sysdecode_whence, *ip);
ip++;
narg--;
break;
#endif
case SYS_lseek:
print_number(ip, narg, c);
- /* Hidden 'pad' argument, not in lseek(2) */
- print_number(ip, narg, c);
+ print_number64(first, ip, narg, c);
putchar(',');
- whencename(*ip);
+ print_integer_arg(sysdecode_whence, *ip);
ip++;
narg--;
break;
case SYS_flock:
print_number(ip, narg, c);
putchar(',');
- flockname(*ip);
+ print_mask_arg(sysdecode_flock_op, *ip);
ip++;
narg--;
break;
@@ -1025,24 +1184,24 @@
case SYS_mkdirat:
print_number(ip, narg, c);
putchar(',');
- modename(*ip);
+ decode_filemode(*ip);
ip++;
narg--;
break;
case SYS_shutdown:
print_number(ip, narg, c);
putchar(',');
- shutdownhowname(*ip);
+ print_integer_arg(sysdecode_shutdown_how, *ip);
ip++;
narg--;
break;
case SYS_socketpair:
putchar('(');
- sockdomainname(*ip);
+ print_integer_arg(sysdecode_socketdomain, *ip);
ip++;
narg--;
putchar(',');
- socktypenamewithflags(*ip);
+ sysdecode_sockettypewithflags(stdout, *ip);
ip++;
narg--;
c = ',';
@@ -1050,7 +1209,7 @@
case SYS_getrlimit:
case SYS_setrlimit:
putchar('(');
- rlimitname(*ip);
+ print_integer_arg(sysdecode_rlimit, *ip);
ip++;
narg--;
c = ',';
@@ -1058,21 +1217,28 @@
case SYS_quotactl:
print_number(ip, narg, c);
putchar(',');
- quotactlname(*ip);
+ if (!sysdecode_quotactl_cmd(stdout, *ip)) {
+ if (decimal)
+ printf("<invalid=%d>", (int)*ip);
+ else
+ printf("<invalid=%#x>",
+ (int)*ip);
+ }
ip++;
narg--;
c = ',';
break;
case SYS_nfssvc:
putchar('(');
- nfssvcname(*ip);
+ print_integer_arg(sysdecode_nfssvc_flags, *ip);
ip++;
narg--;
c = ',';
break;
case SYS_rtprio:
putchar('(');
- rtprioname(*ip);
+ print_integer_arg(sysdecode_rtprio_function,
+ *ip);
ip++;
narg--;
c = ',';
@@ -1081,7 +1247,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- semctlname(*ip);
+ print_integer_arg(sysdecode_semctl_op, *ip);
ip++;
narg--;
break;
@@ -1089,14 +1255,14 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- semgetname(*ip);
+ print_mask_arg(sysdecode_semget_flags, *ip);
ip++;
narg--;
break;
case SYS_msgctl:
print_number(ip, narg, c);
putchar(',');
- shmctlname(*ip);
+ print_integer_arg(sysdecode_msgctl_op, *ip);
ip++;
narg--;
break;
@@ -1104,64 +1270,68 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- shmatname(*ip);
+ print_mask_arg(sysdecode_shmat_flags, *ip);
ip++;
narg--;
break;
case SYS_shmctl:
print_number(ip, narg, c);
putchar(',');
- shmctlname(*ip);
+ print_integer_arg(sysdecode_shmctl_op, *ip);
ip++;
narg--;
break;
case SYS_shm_open:
print_number(ip, narg, c);
putchar(',');
- flagsname(ip[0]);
- printf(",0%o", (unsigned int)ip[1]);
- ip += 3;
- narg -= 3;
+ print_mask_arg(sysdecode_open_flags, ip[0]);
+ putchar(',');
+ decode_filemode(ip[1]);
+ ip += 2;
+ narg -= 2;
break;
case SYS_minherit:
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- minheritname(*ip);
+ print_integer_arg(sysdecode_minherit_flags, *ip);
ip++;
narg--;
break;
case SYS_rfork:
putchar('(');
- rforkname(*ip);
+ print_mask_arg(sysdecode_rfork_flags, *ip);
ip++;
narg--;
c = ',';
break;
case SYS_lio_listio:
putchar('(');
- lio_listioname(*ip);
+ print_integer_arg(sysdecode_lio_listio_mode,
+ *ip);
ip++;
narg--;
c = ',';
break;
case SYS_mlockall:
putchar('(');
- mlockallname(*ip);
+ print_mask_arg(sysdecode_mlockall_flags, *ip);
ip++;
narg--;
break;
case SYS_sched_setscheduler:
print_number(ip, narg, c);
putchar(',');
- schedpolicyname(*ip);
+ print_integer_arg(sysdecode_scheduler_policy,
+ *ip);
ip++;
narg--;
break;
case SYS_sched_get_priority_max:
case SYS_sched_get_priority_min:
putchar('(');
- schedpolicyname(*ip);
+ print_integer_arg(sysdecode_scheduler_policy,
+ *ip);
ip++;
narg--;
break;
@@ -1173,20 +1343,21 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- sendfileflagsname(*(int *)ip);
+ print_mask_arg(sysdecode_sendfile_flags, *ip);
ip++;
narg--;
break;
case SYS_kldsym:
print_number(ip, narg, c);
putchar(',');
- kldsymcmdname(*ip);
+ print_integer_arg(sysdecode_kldsym_cmd, *ip);
ip++;
narg--;
break;
case SYS_sigprocmask:
putchar('(');
- sigprocmaskhowname(*ip);
+ print_integer_arg(sysdecode_sigprocmask_how,
+ *ip);
ip++;
narg--;
c = ',';
@@ -1205,13 +1376,13 @@
case SYS___acl_aclcheck_link:
print_number(ip, narg, c);
putchar(',');
- acltypename(*ip);
+ print_integer_arg(sysdecode_acltype, *ip);
ip++;
narg--;
break;
case SYS_sigaction:
putchar('(');
- signame(*ip);
+ print_signal(*ip);
ip++;
narg--;
c = ',';
@@ -1219,7 +1390,8 @@
case SYS_extattrctl:
print_number(ip, narg, c);
putchar(',');
- extattrctlname(*ip);
+ print_integer_arg(sysdecode_extattrnamespace,
+ *ip);
ip++;
narg--;
break;
@@ -1227,7 +1399,7 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- mountflagsname(*ip);
+ print_mask_arg(sysdecode_mount_flags, *ip);
ip++;
narg--;
break;
@@ -1235,21 +1407,22 @@
print_number(ip, narg, c);
print_number(ip, narg, c);
putchar(',');
- thrcreateflagsname(*ip);
+ print_mask_arg(sysdecode_thr_create_flags, *ip);
ip++;
narg--;
break;
case SYS_thr_kill:
print_number(ip, narg, c);
putchar(',');
- signame(*ip);
+ print_signal(*ip);
ip++;
narg--;
break;
case SYS_kldunloadf:
print_number(ip, narg, c);
putchar(',');
- kldunloadfflagsname(*ip);
+ print_integer_arg(sysdecode_kldunload_flags,
+ *ip);
ip++;
narg--;
break;
@@ -1258,7 +1431,7 @@
case SYS_symlinkat:
print_number(ip, narg, c);
putchar(',');
- atfdname(*ip, decimal);
+ sysdecode_atfd(stdout, *ip, decimal ? 10 : 16);
ip++;
narg--;
break;
@@ -1268,49 +1441,57 @@
arg = *ip;
ip++;
narg--;
- capfcntlname(arg);
+ print_mask_arg32(sysdecode_capfcntlrights, arg);
break;
case SYS_posix_fadvise:
print_number(ip, narg, c);
print_number(ip, narg, c);
print_number(ip, narg, c);
(void)putchar(',');
- fadvisebehavname((int)*ip);
+ print_integer_arg(sysdecode_fadvice, *ip);
ip++;
narg--;
break;
case SYS_procctl:
putchar('(');
- idtypename(*ip, decimal);
+ print_integer_arg(sysdecode_idtype, *ip);
c = ',';
ip++;
narg--;
- print_number(ip, narg, c);
+ print_number64(first, ip, narg, c);
putchar(',');
- procctlcmdname(*ip);
+ print_integer_arg(sysdecode_procctl_cmd, *ip);
ip++;
narg--;
break;
case SYS__umtx_op:
print_number(ip, narg, c);
putchar(',');
- umtxopname(*ip);
+ print_integer_arg(sysdecode_umtx_op, *ip);
switch (*ip) {
case UMTX_OP_CV_WAIT:
ip++;
narg--;
putchar(',');
- umtxcvwaitflags(*ip);
+ print_mask_argul(
+ sysdecode_umtx_cvwait_flags, *ip);
break;
case UMTX_OP_RW_RDLOCK:
ip++;
narg--;
putchar(',');
- umtxrwlockflags(*ip);
+ print_mask_argul(
+ sysdecode_umtx_rwlock_flags, *ip);
break;
}
ip++;
narg--;
+ break;
+ case SYS_ftruncate:
+ case SYS_truncate:
+ print_number(ip, narg, c);
+ print_number64(first, ip, narg, c);
+ break;
}
}
while (narg > 0) {
@@ -1490,32 +1671,25 @@
visdump(dp, datalen, screenwidth);
}
-const char *signames[] = {
- "NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", /* 1 - 6 */
- "EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", /* 7 - 12 */
- "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", /* 13 - 18 */
- "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", /* 19 - 24 */
- "XFSZ", "VTALRM", "PROF", "WINCH", "29", "USR1", /* 25 - 30 */
- "USR2", NULL, /* 31 - 32 */
-};
-
void
ktrpsig(struct ktr_psig *psig)
{
- if (psig->signo > 0 && psig->signo < NSIG)
- printf("SIG%s ", signames[psig->signo]);
- else
- printf("SIG %d ", psig->signo);
+ const char *str;
+
+ print_signal(psig->signo);
if (psig->action == SIG_DFL) {
- printf("SIG_DFL code=");
- sigcodename(psig->signo, psig->code);
- putchar('\n');
+ printf(" SIG_DFL");
} else {
- printf("caught handler=0x%lx mask=0x%x code=",
+ printf(" caught handler=0x%lx mask=0x%x",
(u_long)psig->action, psig->mask.__bits[0]);
- sigcodename(psig->signo, psig->code);
- putchar('\n');
}
+ printf(" code=");
+ str = sysdecode_sigcode(psig->signo, psig->code);
+ if (str != NULL)
+ printf("%s", str);
+ else
+ printf("<invalid=%#x>", psig->code);
+ putchar('\n');
}
void
@@ -1557,7 +1731,7 @@
{
printf("cap_rights_t ");
- capname(rightsp);
+ sysdecode_capname(stdout, rightsp);
printf("\n");
}
@@ -1589,6 +1763,7 @@
#include <netsmb/netbios.h>
struct sockaddr_nb *nb;
*/
+ const char *str;
char addr[64];
/*
@@ -1597,7 +1772,11 @@
* sa->sa_len bytes long.
*/
printf("struct sockaddr { ");
- sockfamilyname(sa->sa_family);
+ str = sysdecode_sockaddr_family(sa->sa_family);
+ if (str != NULL)
+ printf("%s", str);
+ else
+ printf("<invalid=%d>", sa->sa_family);
printf(", ");
#define check_sockaddr_len(n) \
@@ -1811,16 +1990,16 @@
case CAPFAIL_NOTCAPABLE:
/* operation on fd with insufficient capabilities */
printf("operation requires ");
- capname(&ktr->cap_needed);
+ sysdecode_capname(stdout, &ktr->cap_needed);
printf(", descriptor holds ");
- capname(&ktr->cap_held);
+ sysdecode_capname(stdout, &ktr->cap_held);
break;
case CAPFAIL_INCREASE:
/* requested more capabilities than fd already has */
printf("attempt to increase capabilities from ");
- capname(&ktr->cap_held);
+ sysdecode_capname(stdout, &ktr->cap_held);
printf(" to ");
- capname(&ktr->cap_needed);
+ sysdecode_capname(stdout, &ktr->cap_needed);
break;
case CAPFAIL_SYSCALL:
/* called restricted syscall */
@@ -1832,9 +2011,9 @@
break;
default:
printf("unknown capability failure: ");
- capname(&ktr->cap_needed);
+ sysdecode_capname(stdout, &ktr->cap_needed);
printf(" ");
- capname(&ktr->cap_held);
+ sysdecode_capname(stdout, &ktr->cap_held);
break;
}
printf("\n");
@@ -1845,15 +2024,20 @@
{
printf("0x%jx ", (uintmax_t)ktr->vaddr);
- vmprotname(ktr->type);
+ print_mask_arg(sysdecode_vmprot, ktr->type);
printf("\n");
}
void
ktrfaultend(struct ktr_faultend *ktr)
{
+ const char *str;
- vmresultname(ktr->result);
+ str = sysdecode_vmresult(ktr->result);
+ if (str != NULL)
+ printf("%s", str);
+ else
+ printf("<invalid=%d>", ktr->result);
printf("\n");
}
Index: usr.bin/kdump/mksubr
===================================================================
--- usr.bin/kdump/mksubr
+++ /dev/null
@@ -1,759 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. 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$
-#
-# Generates kdump_subr.c
-# mkioctls is a special-purpose script, and works fine as it is
-# now, so it remains independent. The idea behind how it generates
-# its list was heavily borrowed here.
-#
-# Some functions here are automatically generated. This can mean
-# the user will see unusual kdump output or errors while building
-# if the underlying .h files are changed significantly.
-#
-# Key:
-# AUTO: Completely auto-generated with either the "or" or the "switch"
-# method.
-# AUTO - Special: Generated automatically, but with some extra commands
-# that the auto_*_type() functions are inappropriate for.
-# MANUAL: Manually entered and must therefore be manually updated.
-
-set -e
-
-LC_ALL=C; export LC_ALL
-
-if [ -z "$1" ]
-then
- echo "usage: sh $0 include-dir"
- exit 1
-fi
-include_dir=$1
-
-#
-# Automatically generates a C function that will print out the
-# numeric input as a pipe-delimited string of the appropriate
-# #define keys. ex:
-# S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
-# The XOR is necessary to prevent including the "0"-value in every
-# line.
-#
-auto_or_type () {
- local name grep file
- name=$1
- grep=$2
- file=$3
-
- cat <<_EOF_
-/* AUTO */
-void
-$name(intmax_t arg)
-{
- int or = 0;
- printf("%#jx<", (uintmax_t)arg);
-_EOF_
- egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
- $include_dir/$file | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
-cat <<_EOF_
- printf(">");
- if (or == 0)
- printf("<invalid>%jd", arg);
-}
-
-_EOF_
-}
-
-#
-# Automatically generates a C function used when the argument
-# maps to a single, specific #definition
-#
-auto_switch_type () {
- local name grep file
- name=$1
- grep=$2
- file=$3
-
- cat <<_EOF_
-/* AUTO */
-void
-$name(intmax_t arg)
-{
- switch (arg) {
-_EOF_
- egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
- $include_dir/$file | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
-cat <<_EOF_
- default: /* Should not reach */
- printf("<invalid=%jd>", arg);
- }
-}
-
-_EOF_
-}
-
-#
-# Automatically generates a C function used when the argument
-# maps to a #definition
-#
-auto_if_type () {
- local name grep file
- name=$1
- grep=$2
- file=$3
-
- cat <<_EOF_
-/* AUTO */
-void
-$name(intmax_t arg)
-{
-_EOF_
- egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
- $include_dir/$file | \
- awk '{ printf "\t"; \
- if (NR > 1) \
- printf "else " ; \
- printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
-cat <<_EOF_
- else /* Should not reach */
- printf("<invalid=%jd>", arg);
-}
-
-_EOF_
-}
-
-# C start
-
-cat <<_EOF_
-#include <stdint.h>
-#include <stdio.h>
-#include <sys/fcntl.h>
-#include <sys/stat.h>
-#include <sys/unistd.h>
-#include <sys/mman.h>
-#include <sys/wait.h>
-#define _KERNEL
-#include <sys/socket.h>
-#undef _KERNEL
-#include <netinet/in.h>
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <sys/procctl.h>
-#include <sys/ptrace.h>
-#include <sys/resource.h>
-#include <sys/reboot.h>
-#include <sched.h>
-#include <sys/linker.h>
-#define _KERNEL
-#include <sys/thr.h>
-#undef _KERNEL
-#include <sys/extattr.h>
-#include <sys/acl.h>
-#include <aio.h>
-#include <sys/sem.h>
-#include <sys/ipc.h>
-#include <sys/rtprio.h>
-#include <sys/shm.h>
-#include <sys/umtx.h>
-#include <nfsserver/nfs.h>
-#include <ufs/ufs/quota.h>
-#include <sys/capsicum.h>
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-
-#include "kdump_subr.h"
-
-/*
- * These are simple support macros. print_or utilizes a variable
- * defined in the calling function to track whether or not it should
- * print a logical-OR character ('|') before a string. if_print_or
- * simply handles the necessary "if" statement used in many lines
- * of this file.
- */
-#define print_or(str,orflag) do { \\
- if (orflag) putchar('|'); else orflag = 1; \\
- printf (str); } \\
- while (0)
-#define if_print_or(i,flag,orflag) do { \\
- if ((i & flag) == flag) \\
- print_or(#flag,orflag); } \\
- while (0)
-
-/* MANUAL */
-void
-atfdname(int fd, int decimal)
-{
- if (fd == AT_FDCWD)
- printf("AT_FDCWD");
- else if (decimal)
- printf("%d", fd);
- else
- printf("%#x", fd);
-}
-
-/* MANUAL */
-extern char *signames[]; /* from kdump.c */
-void
-signame(int sig)
-{
- if (sig > 0 && sig < NSIG)
- printf("SIG%s",signames[sig]);
- else
- printf("SIG %d", sig);
-}
-
-/* MANUAL */
-void
-semctlname(int cmd)
-{
- switch (cmd) {
- case GETNCNT:
- printf("GETNCNT");
- break;
- case GETPID:
- printf("GETPID");
- break;
- case GETVAL:
- printf("GETVAL");
- break;
- case GETALL:
- printf("GETALL");
- break;
- case GETZCNT:
- printf("GETZCNT");
- break;
- case SETVAL:
- printf("SETVAL");
- break;
- case SETALL:
- printf("SETALL");
- break;
- case IPC_RMID:
- printf("IPC_RMID");
- break;
- case IPC_SET:
- printf("IPC_SET");
- break;
- case IPC_STAT:
- printf("IPC_STAT");
- break;
- default: /* Should not reach */
- printf("<invalid=%d>", cmd);
- }
-}
-
-/* MANUAL */
-void
-shmctlname(int cmd)
-{
- switch (cmd) {
- case IPC_RMID:
- printf("IPC_RMID");
- break;
- case IPC_SET:
- printf("IPC_SET");
- break;
- case IPC_STAT:
- printf("IPC_STAT");
- break;
- default: /* Should not reach */
- printf("<invalid=%d>", cmd);
- }
-}
-
-/* MANUAL */
-void
-semgetname(int flag)
-{
- int or = 0;
- if_print_or(flag, IPC_CREAT, or);
- if_print_or(flag, IPC_EXCL, or);
- if_print_or(flag, SEM_R, or);
- if_print_or(flag, SEM_A, or);
- if_print_or(flag, (SEM_R>>3), or);
- if_print_or(flag, (SEM_A>>3), or);
- if_print_or(flag, (SEM_R>>6), or);
- if_print_or(flag, (SEM_A>>6), or);
-}
-
-/*
- * MANUAL
- *
- * Only used by SYS_open. Unless O_CREAT is set in flags, the
- * mode argument is unused (and often bogus and misleading).
- */
-void
-flagsandmodename(int flags, int mode, int decimal)
-{
- flagsname(flags);
- putchar(',');
- if ((flags & O_CREAT) == O_CREAT) {
- modename (mode);
- } else {
- if (decimal) {
- printf("<unused>%d", mode);
- } else {
- printf("<unused>%#x", (unsigned int)mode);
- }
- }
-}
-
-/* MANUAL */
-void
-idtypename(idtype_t idtype, int decimal)
-{
- switch(idtype) {
- case P_PID:
- printf("P_PID");
- break;
- case P_PPID:
- printf("P_PPID");
- break;
- case P_PGID:
- printf("P_PGID");
- break;
- case P_SID:
- printf("P_SID");
- break;
- case P_CID:
- printf("P_CID");
- break;
- case P_UID:
- printf("P_UID");
- break;
- case P_GID:
- printf("P_GID");
- break;
- case P_ALL:
- printf("P_ALL");
- break;
- case P_LWPID:
- printf("P_LWPID");
- break;
- case P_TASKID:
- printf("P_TASKID");
- break;
- case P_PROJID:
- printf("P_PROJID");
- break;
- case P_POOLID:
- printf("P_POOLID");
- break;
- case P_JAILID:
- printf("P_JAILID");
- break;
- case P_CTID:
- printf("P_CTID");
- break;
- case P_CPUID:
- printf("P_CPUID");
- break;
- case P_PSETID:
- printf("P_PSETID");
- break;
- default:
- if (decimal) {
- printf("%d", idtype);
- } else {
- printf("%#x", idtype);
- }
- }
-}
-
-/*
- * MANUAL
- *
- * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
- * referring to a line in /etc/protocols . It might be appropriate
- * to use getprotoent(3) here.
- */
-void
-sockoptlevelname(int level, int decimal)
-{
- if (level == SOL_SOCKET) {
- printf("SOL_SOCKET");
- } else {
- if (decimal) {
- printf("%d", level);
- } else {
- printf("%#x", (unsigned int)level);
- }
- }
-}
-
-/*
- * MANUAL
- *
- * Used for page fault type. Cannot use auto_or_type since the macro
- * values contain a cast. Also, VM_PROT_NONE has to be handled specially.
- */
-void
-vmprotname (int type)
-{
- int or = 0;
-
- if (type == VM_PROT_NONE) {
- (void)printf("VM_PROT_NONE");
- return;
- }
- if_print_or(type, VM_PROT_READ, or);
- if_print_or(type, VM_PROT_WRITE, or);
- if_print_or(type, VM_PROT_EXECUTE, or);
- if_print_or(type, VM_PROT_COPY, or);
-}
-
-/*
- * MANUAL
- */
-void
-socktypenamewithflags(int type)
-{
- if (type & SOCK_CLOEXEC)
- printf("SOCK_CLOEXEC|"), type &= ~SOCK_CLOEXEC;
- if (type & SOCK_NONBLOCK)
- printf("SOCK_NONBLOCK|"), type &= ~SOCK_NONBLOCK;
- socktypename(type);
-}
-_EOF_
-
-auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
-auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
-auto_or_type "capfcntlname" "CAP_FCNTL_[A-Z]+[[:space:]]+\(1" "sys/capsicum.h"
-auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
-auto_switch_type "fadvisebehavname" "POSIX_FADV_[A-Z]+[[:space:]]+[0-9]+" "sys/fcntl.h"
-auto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
-auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
-auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
-auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
-auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
-auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
-auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
-auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
-auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
-auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
-auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
-auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
-auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
-auto_or_type "nfssvcname" "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+" "nfs/nfssvc.h"
-auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
-auto_switch_type "procctlcmdname" "PROC_[A-Z]+[[:space:]]+[0-9]" "sys/procctl.h"
-auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
-auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
-auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
-auto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h"
-auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
-auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
-auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
-auto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h"
-auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
-auto_switch_type "sigbuscodename" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_switch_type "sigchldcodename" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_switch_type "sigfpecodename" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_switch_type "sigillcodename" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_switch_type "sigsegvcodename" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_switch_type "sigtrapcodename" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
-auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
-auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
-auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
-auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
-auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
-auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
-auto_switch_type "umtxopname" "UMTX_OP_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/umtx.h"
-auto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h"
-auto_or_type "wait6optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
-auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
-
-cat <<_EOF_
-/*
- * AUTO - Special
- * F_ is used to specify fcntl commands as well as arguments. Both sets are
- * grouped in fcntl.h, and this awk script grabs the first group.
- */
-void
-fcntlcmdname(int cmd, int arg, int decimal)
-{
- switch (cmd) {
-_EOF_
-egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]*" \
- $include_dir/sys/fcntl.h | \
- awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- if (o <= $(i+1)) \
- printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i; \
- else \
- exit; \
- o = $(i+1) }'
-cat <<_EOF_
- default: /* Should not reach */
- printf("<invalid=%d>", cmd);
- }
- putchar(',');
- if (cmd == F_GETFD || cmd == F_SETFD) {
- if (arg == FD_CLOEXEC)
- printf("FD_CLOEXEC");
- else if (arg == 0)
- printf("0");
- else {
- if (decimal)
- printf("<invalid>%d", arg);
- else
- printf("<invalid>%#x", (unsigned int)arg);
- }
- } else if (cmd == F_SETFL) {
- flagsname(arg);
- } else {
- if (decimal)
- printf("%d", arg);
- else
- printf("%#x", (unsigned int)arg);
- }
-}
-
-/*
- * AUTO - Special
- *
- * The MAP_ALIGNED flag requires special handling.
- */
-void
-mmapflagsname(int flags)
-{
- int align;
- int or = 0;
- printf("%#x<", flags);
-_EOF_
-egrep "^#[[:space:]]*define[[:space:]]+MAP_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+[[:space:]]*" \
- $include_dir/sys/mman.h | grep -v MAP_ALIGNED | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tif (!((flags > 0) ^ ((%s) > 0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
-cat <<_EOF_
-#ifdef MAP_32BIT
- if (!((flags > 0) ^ ((MAP_32BIT) > 0)))
- if_print_or(flags, MAP_32BIT, or);
-#endif
- align = flags & MAP_ALIGNMENT_MASK;
- if (align != 0) {
- if (align == MAP_ALIGNED_SUPER)
- print_or("MAP_ALIGNED_SUPER", or);
- else {
- print_or("MAP_ALIGNED", or);
- printf("(%d)", align >> MAP_ALIGNMENT_SHIFT);
- }
- }
- printf(">");
- if (or == 0)
- printf("<invalid>%d", flags);
-}
-
-/*
- * AUTO - Special
- *
- * The only reason this is not fully automated is due to the
- * grep -v RTP_PRIO statement. A better egrep line should
- * make this capable of being a auto_switch_type() function.
- */
-void
-rtprioname(int func)
-{
- switch (func) {
-_EOF_
-egrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \
- $include_dir/sys/rtprio.h | grep -v RTP_PRIO | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
-cat <<_EOF_
- default: /* Should not reach */
- printf("<invalid=%d>", func);
- }
-}
-
-/*
- * AUTO - Special
- *
- * The send and recv functions have a flags argument which can be
- * set to 0. There is no corresponding #define. The auto_ functions
- * detect this as "invalid", which is incorrect here.
- */
-void
-sendrecvflagsname(int flags)
-{
- int or = 0;
-
- if (flags == 0) {
- printf("0");
- return;
- }
-
- printf("%#x<", flags);
-_EOF_
-egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
-cat <<_EOF_
- printf(">");
-}
-
-/*
- * AUTO - Special
- *
- * Check general codes first, then defer to signal-specific codes.
- */
-void
-sigcodename(int sig, int code)
-{
- switch (code) {
-_EOF_
-egrep "^#[[:space:]]*define[[:space:]]+SI_[A-Z]+[[:space:]]+0(x[0-9abcdef]+)?[[:space:]]*" \
- $include_dir/sys/signal.h | grep -v SI_UNDEFINED | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
-cat <<_EOF_
- default:
- switch (sig) {
- case SIGILL:
- sigillcodename(code);
- break;
- case SIGBUS:
- sigbuscodename(code);
- break;
- case SIGSEGV:
- sigsegvcodename(code);
- break;
- case SIGFPE:
- sigfpecodename(code);
- break;
- case SIGTRAP:
- sigtrapcodename(code);
- break;
- case SIGCHLD:
- sigchldcodename(code);
- break;
- default:
- printf("<invalid=%#x>", code);
- }
- }
-}
-
-/*
- * AUTO - Special
- *
- * Just print 0 as 0.
- */
-void
-umtxcvwaitflags(intmax_t arg)
-{
- int or = 0;
- if (arg == 0) {
- printf("0");
- return;
- }
- printf("%#jx<", (uintmax_t)arg);
-_EOF_
- egrep "^#[[:space:]]*define[[:space:]]+CVWAIT_[A-Z_]+[[:space:]]+0x[0-9]+[[:space:]]*" \
- $include_dir/sys/umtx.h | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
-cat <<_EOF_
- printf(">");
- if (or == 0)
- printf("<invalid>%jd", arg);
-}
-
-
-/*
- * AUTO - Special
- *
- * Just print 0 as 0.
- */
-void
-umtxrwlockflags(intmax_t arg)
-{
- int or = 0;
- if (arg == 0) {
- printf("0");
- return;
- }
- printf("%#jx<", (uintmax_t)arg);
-_EOF_
- egrep "^#[[:space:]]*define[[:space:]]+URWLOCK_PREFER_READER[[:space:]]+0x[0-9]+[[:space:]]*" \
- $include_dir/sys/umtx.h | \
- awk '{ for (i = 1; i <= NF; i++) \
- if ($i ~ /define/) \
- break; \
- ++i; \
- printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
-cat <<_EOF_
- printf(">");
- if (or == 0)
- printf("<invalid>%jd", arg);
-}
-_EOF_
-egrep '#define[[:space:]]+CAP_[A-Z_]+[[:space:]]+CAPRIGHT\([0-9],[[:space:]]+0x[0-9]{16}ULL\)' \
- $include_dir/sys/capsicum.h | \
- sed -E 's/[ ]+/ /g' | \
- awk -F '[ \(,\)]' '
- BEGIN {
- printf "void\n"
- printf "capname(const cap_rights_t *rightsp)\n"
- printf "{\n"
- printf "\tint comma = 0;\n\n"
- printf "\tprintf(\"<\");\n"
- }
- {
- printf "\tif ((rightsp->cr_rights[%s] & %s) == %s) {\n", $4, $2, $2
- printf "\t\tif (comma) printf(\",\"); else comma = 1;\n"
- printf "\t\tprintf(\"%s\");\n", $2
- printf "\t}\n"
- }
- END {
- printf "\tprintf(\">\");\n"
- printf "}\n"
- }'
Index: usr.bin/truss/Makefile
===================================================================
--- usr.bin/truss/Makefile
+++ usr.bin/truss/Makefile
@@ -1,12 +1,13 @@
# $FreeBSD$
-NO_WERROR=
+#NO_WERROR=
PROG= truss
SRCS= main.c setup.c syscalls.c
LIBADD= sysdecode
-CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
+#CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
+CFLAGS+= -I${.CURDIR}/../../sys
ABIS+= freebsd
# Each ABI is expected to have an ABI.c, MACHINE_ARCH-ABI.c or
Index: usr.bin/truss/aarch64-cloudabi64.c
===================================================================
--- usr.bin/truss/aarch64-cloudabi64.c
+++ usr.bin/truss/aarch64-cloudabi64.c
@@ -31,6 +31,7 @@
#include <machine/armreg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/aarch64-freebsd.c
===================================================================
--- usr.bin/truss/aarch64-freebsd.c
+++ usr.bin/truss/aarch64-freebsd.c
@@ -38,6 +38,7 @@
#include <machine/armreg.h>
#include <machine/ucontext.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/amd64-cloudabi64.c
===================================================================
--- usr.bin/truss/amd64-cloudabi64.c
+++ usr.bin/truss/amd64-cloudabi64.c
@@ -31,6 +31,7 @@
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/amd64-freebsd.c
===================================================================
--- usr.bin/truss/amd64-freebsd.c
+++ usr.bin/truss/amd64-freebsd.c
@@ -40,6 +40,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/amd64-freebsd32.c
===================================================================
--- usr.bin/truss/amd64-freebsd32.c
+++ usr.bin/truss/amd64-freebsd32.c
@@ -40,6 +40,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysdecode.h>
Index: usr.bin/truss/amd64-linux.c
===================================================================
--- usr.bin/truss/amd64-linux.c
+++ usr.bin/truss/amd64-linux.c
@@ -39,6 +39,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/amd64-linux32.c
===================================================================
--- usr.bin/truss/amd64-linux32.c
+++ usr.bin/truss/amd64-linux32.c
@@ -39,6 +39,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/arm-freebsd.c
===================================================================
--- usr.bin/truss/arm-freebsd.c
+++ usr.bin/truss/arm-freebsd.c
@@ -41,6 +41,7 @@
#include <machine/armreg.h>
#include <machine/ucontext.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/extern.h
===================================================================
--- usr.bin/truss/extern.h
+++ usr.bin/truss/extern.h
@@ -37,4 +37,3 @@
extern void restore_proc(int);
extern void eventloop(struct trussinfo *);
extern const char *ioctlname(unsigned long val);
-extern char *strsig(int sig);
Index: usr.bin/truss/i386-freebsd.c
===================================================================
--- usr.bin/truss/i386-freebsd.c
+++ usr.bin/truss/i386-freebsd.c
@@ -40,6 +40,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/i386-linux.c
===================================================================
--- usr.bin/truss/i386-linux.c
+++ usr.bin/truss/i386-linux.c
@@ -39,6 +39,7 @@
#include <machine/reg.h>
#include <machine/psl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/main.c
===================================================================
--- usr.bin/truss/main.c
+++ usr.bin/truss/main.c
@@ -42,6 +42,7 @@
#include <err.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysdecode.h>
@@ -61,18 +62,6 @@
exit(1);
}
-char *
-strsig(int sig)
-{
- static char tmp[64];
-
- if (sig > 0 && sig < NSIG) {
- snprintf(tmp, sizeof(tmp), "SIG%s", sys_signame[sig]);
- return (tmp);
- }
- return (NULL);
-}
-
int
main(int ac, char **av)
{
Index: usr.bin/truss/mips-freebsd.c
===================================================================
--- usr.bin/truss/mips-freebsd.c
+++ usr.bin/truss/mips-freebsd.c
@@ -40,6 +40,7 @@
#include <machine/frame.h>
#include <machine/reg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/powerpc-freebsd.c
===================================================================
--- usr.bin/truss/powerpc-freebsd.c
+++ usr.bin/truss/powerpc-freebsd.c
@@ -36,6 +36,7 @@
#include <machine/reg.h>
#include <machine/frame.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/powerpc64-freebsd.c
===================================================================
--- usr.bin/truss/powerpc64-freebsd.c
+++ usr.bin/truss/powerpc64-freebsd.c
@@ -36,6 +36,7 @@
#include <machine/reg.h>
#include <machine/frame.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/powerpc64-freebsd32.c
===================================================================
--- usr.bin/truss/powerpc64-freebsd32.c
+++ usr.bin/truss/powerpc64-freebsd32.c
@@ -36,6 +36,7 @@
#include <machine/reg.h>
#include <machine/frame.h>
+#include <stdbool.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/setup.c
===================================================================
--- usr.bin/truss/setup.c
+++ usr.bin/truss/setup.c
@@ -45,6 +45,7 @@
#include <err.h>
#include <errno.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -591,12 +592,12 @@
report_signal(struct trussinfo *info, siginfo_t *si)
{
struct threadinfo *t;
- char *signame;
+ const char *signame;
t = info->curthread;
clock_gettime(CLOCK_REALTIME, &t->after);
print_line_prefix(info);
- signame = strsig(si->si_status);
+ signame = sysdecode_signal(si->si_status);
fprintf(info->outfile, "SIGNAL %u (%s)\n", si->si_status,
signame == NULL ? "?" : signame);
}
Index: usr.bin/truss/sparc64-freebsd.c
===================================================================
--- usr.bin/truss/sparc64-freebsd.c
+++ usr.bin/truss/sparc64-freebsd.c
@@ -41,6 +41,7 @@
#include <machine/reg.h>
#include <machine/tstate.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <sysdecode.h>
Index: usr.bin/truss/syscall.h
===================================================================
--- usr.bin/truss/syscall.h
+++ usr.bin/truss/syscall.h
@@ -44,7 +44,7 @@
Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2,
Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl,
LinuxSockArgs, Umtxop, Atfd, Atflags, Timespec2, Accessmode, Long,
- Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex, Utrace, IntArray,
+ Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex, Utrace, IntArray, Pipe2,
CloudABIAdvice, CloudABIClockID, ClouduABIFDSFlags,
CloudABIFDStat, CloudABIFileStat, CloudABIFileType,
Index: usr.bin/truss/syscalls.c
===================================================================
--- usr.bin/truss/syscalls.c
+++ usr.bin/truss/syscalls.c
@@ -40,14 +40,11 @@
#include <sys/types.h>
#include <sys/event.h>
#include <sys/ioccom.h>
-#include <sys/mman.h>
#include <sys/mount.h>
-#include <sys/procctl.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
-#include <sys/umtx.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <machine/sysarch.h>
@@ -60,13 +57,10 @@
#include <poll.h>
#include <signal.h>
#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysdecode.h>
-#include <time.h>
#include <unistd.h>
#include <vis.h>
@@ -256,7 +250,7 @@
{ .name = "pipe", .ret_type = 1, .nargs = 1,
.args = { { PipeFds | OUT, 0 } } },
{ .name = "pipe2", .ret_type = 1, .nargs = 2,
- .args = { { Ptr, 0 }, { Open, 1 } } },
+ .args = { { Ptr, 0 }, { Pipe2, 1 } } },
{ .name = "poll", .ret_type = 1, .nargs = 3,
.args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "posix_openpt", .ret_type = 1, .nargs = 1,
@@ -553,83 +547,11 @@
X(POLLWRBAND) X(POLLINIGNEOF) XEND
};
-static struct xlat mmap_flags[] = {
- X(MAP_SHARED) X(MAP_PRIVATE) X(MAP_FIXED) X(MAP_RESERVED0020)
- X(MAP_RESERVED0040) X(MAP_RESERVED0080) X(MAP_RESERVED0100)
- X(MAP_HASSEMAPHORE) X(MAP_STACK) X(MAP_NOSYNC) X(MAP_ANON)
- X(MAP_EXCL) X(MAP_NOCORE) X(MAP_PREFAULT_READ)
-#ifdef MAP_32BIT
- X(MAP_32BIT)
-#endif
- XEND
-};
-
-static struct xlat mprot_flags[] = {
- X(PROT_NONE) X(PROT_READ) X(PROT_WRITE) X(PROT_EXEC) XEND
-};
-
-static struct xlat whence_arg[] = {
- X(SEEK_SET) X(SEEK_CUR) X(SEEK_END) X(SEEK_DATA) X(SEEK_HOLE) XEND
-};
-
static struct xlat sigaction_flags[] = {
X(SA_ONSTACK) X(SA_RESTART) X(SA_RESETHAND) X(SA_NOCLDSTOP)
X(SA_NODEFER) X(SA_NOCLDWAIT) X(SA_SIGINFO) XEND
};
-static struct xlat fcntl_arg[] = {
- X(F_DUPFD) X(F_GETFD) X(F_SETFD) X(F_GETFL) X(F_SETFL)
- X(F_GETOWN) X(F_SETOWN) X(F_OGETLK) X(F_OSETLK) X(F_OSETLKW)
- X(F_DUP2FD) X(F_GETLK) X(F_SETLK) X(F_SETLKW) X(F_SETLK_REMOTE)
- X(F_READAHEAD) X(F_RDAHEAD) X(F_DUPFD_CLOEXEC) X(F_DUP2FD_CLOEXEC)
- XEND
-};
-
-static struct xlat fcntlfd_arg[] = {
- X(FD_CLOEXEC) XEND
-};
-
-static struct xlat fcntlfl_arg[] = {
- X(O_APPEND) X(O_ASYNC) X(O_FSYNC) X(O_NONBLOCK) X(O_NOFOLLOW)
- X(FRDAHEAD) X(O_DIRECT) XEND
-};
-
-static struct xlat sockdomain_arg[] = {
- X(PF_UNSPEC) X(PF_LOCAL) X(PF_UNIX) X(PF_INET) X(PF_IMPLINK)
- X(PF_PUP) X(PF_CHAOS) X(PF_NETBIOS) X(PF_ISO) X(PF_OSI)
- X(PF_ECMA) X(PF_DATAKIT) X(PF_CCITT) X(PF_SNA) X(PF_DECnet)
- X(PF_DLI) X(PF_LAT) X(PF_HYLINK) X(PF_APPLETALK) X(PF_ROUTE)
- X(PF_LINK) X(PF_XTP) X(PF_COIP) X(PF_CNT) X(PF_SIP) X(PF_IPX)
- X(PF_RTIP) X(PF_PIP) X(PF_ISDN) X(PF_KEY) X(PF_INET6)
- X(PF_NATM) X(PF_ATM) X(PF_NETGRAPH) X(PF_SLOW) X(PF_SCLUSTER)
- X(PF_ARP) X(PF_BLUETOOTH) X(PF_IEEE80211) X(PF_INET_SDP)
- X(PF_INET6_SDP) XEND
-};
-
-static struct xlat socktype_arg[] = {
- X(SOCK_STREAM) X(SOCK_DGRAM) X(SOCK_RAW) X(SOCK_RDM)
- X(SOCK_SEQPACKET) XEND
-};
-
-static struct xlat open_flags[] = {
- X(O_RDONLY) X(O_WRONLY) X(O_RDWR) X(O_ACCMODE) X(O_NONBLOCK)
- X(O_APPEND) X(O_SHLOCK) X(O_EXLOCK) X(O_ASYNC) X(O_FSYNC)
- X(O_NOFOLLOW) X(O_CREAT) X(O_TRUNC) X(O_EXCL) X(O_NOCTTY)
- X(O_DIRECT) X(O_DIRECTORY) X(O_EXEC) X(O_TTY_INIT) X(O_CLOEXEC)
- X(O_VERIFY) XEND
-};
-
-static struct xlat shutdown_arg[] = {
- X(SHUT_RD) X(SHUT_WR) X(SHUT_RDWR) XEND
-};
-
-static struct xlat resource_arg[] = {
- X(RLIMIT_CPU) X(RLIMIT_FSIZE) X(RLIMIT_DATA) X(RLIMIT_STACK)
- X(RLIMIT_CORE) X(RLIMIT_RSS) X(RLIMIT_MEMLOCK) X(RLIMIT_NPROC)
- X(RLIMIT_NOFILE) X(RLIMIT_SBSIZE) X(RLIMIT_VMEM) X(RLIMIT_NPTS)
- X(RLIMIT_SWAP) X(RLIMIT_KQUEUES) XEND
-};
-
static struct xlat pathconf_arg[] = {
X(_PC_LINK_MAX) X(_PC_MAX_CANON) X(_PC_MAX_INPUT)
X(_PC_NAME_MAX) X(_PC_PATH_MAX) X(_PC_PIPE_BUF)
@@ -643,50 +565,11 @@
X(_PC_ACL_NFS4) X(_PC_MIN_HOLE_SIZE) XEND
};
-static struct xlat rfork_flags[] = {
- X(RFFDG) X(RFPROC) X(RFMEM) X(RFNOWAIT) X(RFCFDG) X(RFTHREAD)
- X(RFSIGSHARE) X(RFLINUXTHPN) X(RFTSIGZMB) X(RFPPWAIT) XEND
-};
-
-static struct xlat wait_options[] = {
- X(WNOHANG) X(WUNTRACED) X(WCONTINUED) X(WNOWAIT) X(WEXITED)
- X(WTRAPPED) XEND
-};
-
-static struct xlat idtype_arg[] = {
- X(P_PID) X(P_PPID) X(P_PGID) X(P_SID) X(P_CID) X(P_UID) X(P_GID)
- X(P_ALL) X(P_LWPID) X(P_TASKID) X(P_PROJID) X(P_POOLID) X(P_JAILID)
- X(P_CTID) X(P_CPUID) X(P_PSETID) XEND
-};
-
-static struct xlat procctl_arg[] = {
- X(PROC_SPROTECT) X(PROC_REAP_ACQUIRE) X(PROC_REAP_RELEASE)
- X(PROC_REAP_STATUS) X(PROC_REAP_GETPIDS) X(PROC_REAP_KILL)
- X(PROC_TRACE_CTL) X(PROC_TRACE_STATUS) XEND
-};
-
-static struct xlat umtx_ops[] = {
- X(UMTX_OP_RESERVED0) X(UMTX_OP_RESERVED1) X(UMTX_OP_WAIT)
- X(UMTX_OP_WAKE) X(UMTX_OP_MUTEX_TRYLOCK) X(UMTX_OP_MUTEX_LOCK)
- X(UMTX_OP_MUTEX_UNLOCK) X(UMTX_OP_SET_CEILING) X(UMTX_OP_CV_WAIT)
- X(UMTX_OP_CV_SIGNAL) X(UMTX_OP_CV_BROADCAST) X(UMTX_OP_WAIT_UINT)
- X(UMTX_OP_RW_RDLOCK) X(UMTX_OP_RW_WRLOCK) X(UMTX_OP_RW_UNLOCK)
- X(UMTX_OP_WAIT_UINT_PRIVATE) X(UMTX_OP_WAKE_PRIVATE)
- X(UMTX_OP_MUTEX_WAIT) X(UMTX_OP_MUTEX_WAKE) X(UMTX_OP_SEM_WAIT)
- X(UMTX_OP_SEM_WAKE) X(UMTX_OP_NWAKE_PRIVATE) X(UMTX_OP_MUTEX_WAKE2)
- X(UMTX_OP_SEM2_WAIT) X(UMTX_OP_SEM2_WAKE)
- XEND
-};
-
static struct xlat at_flags[] = {
X(AT_EACCESS) X(AT_SYMLINK_NOFOLLOW) X(AT_SYMLINK_FOLLOW)
X(AT_REMOVEDIR) XEND
};
-static struct xlat access_modes[] = {
- X(R_OK) X(W_OK) X(X_OK) XEND
-};
-
static struct xlat sysarch_ops[] = {
#if defined(__i386__) || defined(__amd64__)
X(I386_GET_LDT) X(I386_SET_LDT) X(I386_GET_IOPERM) X(I386_SET_IOPERM)
@@ -707,11 +590,6 @@
XEND
};
-static struct xlat sigprocmask_ops[] = {
- X(SIG_BLOCK) X(SIG_UNBLOCK) X(SIG_SETMASK)
- XEND
-};
-
#undef X
#define X(a) { CLOUDABI_##a, #a },
@@ -909,6 +787,29 @@
return (str);
}
+static void
+print_integer_arg(const char *(*decoder)(int), FILE *fp, int value)
+{
+ const char *str;
+
+ str = decoder(value);
+ if (str != NULL)
+ fputs(str, fp);
+ else
+ fprintf(fp, "%d", value);
+}
+
+static void
+print_mask_arg(bool (*decoder)(FILE *, int, int *), FILE *fp, int value)
+{
+ int rem;
+
+ if (!decoder(fp, value, &rem))
+ fprintf(fp, "0x%x", rem);
+ else if (rem != 0)
+ fprintf(fp, "|0x%x", rem);
+}
+
void
init_syscalls(void)
{
@@ -1028,13 +929,13 @@
}
}
-static char *
+static const char *
strsig2(int sig)
{
static char tmp[sizeof(int) * 3 + 1];
- char *ret;
+ const char *ret;
- ret = strsig(sig);
+ ret = sysdecode_signal(sig);
if (ret == NULL) {
snprintf(tmp, sizeof(tmp), "%d", sig);
ret = tmp;
@@ -1493,7 +1394,7 @@
for (i = 1; i < sys_nsig; i++) {
if (sigismember(&ss, i)) {
fprintf(fp, "%s%s", !first ? "|" : "",
- strsig(i));
+ sysdecode_signal(i));
first = 0;
}
}
@@ -1502,92 +1403,48 @@
fputc('}', fp);
break;
}
- case Sigprocmask: {
- fputs(xlookup(sigprocmask_ops, args[sc->offset]), fp);
+ case Sigprocmask:
+ print_integer_arg(sysdecode_sigprocmask_how, fp,
+ args[sc->offset]);
break;
- }
- case Fcntlflag: {
+ case Fcntlflag:
/* XXX: Output depends on the value of the previous argument. */
- switch (args[sc->offset - 1]) {
- case F_SETFD:
- fputs(xlookup_bits(fcntlfd_arg, args[sc->offset]), fp);
- break;
- case F_SETFL:
- fputs(xlookup_bits(fcntlfl_arg, args[sc->offset]), fp);
- break;
- case F_GETFD:
- case F_GETFL:
- case F_GETOWN:
- break;
- default:
- fprintf(fp, "0x%lx", args[sc->offset]);
- break;
- }
+ if (sysdecode_fcntl_arg_p(args[sc->offset - 1]))
+ sysdecode_fcntl_arg(fp, args[sc->offset - 1],
+ args[sc->offset], 16);
break;
- }
case Open:
- fputs(xlookup_bits(open_flags, args[sc->offset]), fp);
+ print_mask_arg(sysdecode_open_flags, fp, args[sc->offset]);
break;
case Fcntl:
- fputs(xlookup(fcntl_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_fcntl_cmd, fp, args[sc->offset]);
break;
case Mprot:
- fputs(xlookup_bits(mprot_flags, args[sc->offset]), fp);
+ print_mask_arg(sysdecode_mmap_prot, fp, args[sc->offset]);
break;
- case Mmapflags: {
- int align, flags;
-
- /*
- * MAP_ALIGNED can't be handled by xlookup_bits(), so
- * generate that string manually and prepend it to the
- * string from xlookup_bits(). Have to be careful to
- * avoid outputting MAP_ALIGNED|0 if MAP_ALIGNED is
- * the only flag.
- */
- flags = args[sc->offset] & ~MAP_ALIGNMENT_MASK;
- align = args[sc->offset] & MAP_ALIGNMENT_MASK;
- if (align != 0) {
- if (align == MAP_ALIGNED_SUPER)
- fputs("MAP_ALIGNED_SUPER", fp);
- else
- fprintf(fp, "MAP_ALIGNED(%d)",
- align >> MAP_ALIGNMENT_SHIFT);
- if (flags == 0)
- break;
- fputc('|', fp);
- }
- fputs(xlookup_bits(mmap_flags, flags), fp);
+ case Mmapflags:
+ print_mask_arg(sysdecode_mmap_flags, fp, args[sc->offset]);
break;
- }
case Whence:
- fputs(xlookup(whence_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_whence, fp, args[sc->offset]);
break;
case Sockdomain:
- fputs(xlookup(sockdomain_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_socketdomain, fp, args[sc->offset]);
break;
- case Socktype: {
- int type, flags;
-
- flags = args[sc->offset] & (SOCK_CLOEXEC | SOCK_NONBLOCK);
- type = args[sc->offset] & ~flags;
- fputs(xlookup(socktype_arg, type), fp);
- if (flags & SOCK_CLOEXEC)
- fprintf(fp, "|SOCK_CLOEXEC");
- if (flags & SOCK_NONBLOCK)
- fprintf(fp, "|SOCK_NONBLOCK");
+ case Socktype:
+ sysdecode_sockettypewithflags(fp, args[sc->offset]);
break;
- }
case Shutdown:
- fputs(xlookup(shutdown_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_shutdown_how, fp, args[sc->offset]);
break;
case Resource:
- fputs(xlookup(resource_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_rlimit, fp, args[sc->offset]);
break;
case Pathconf:
fputs(xlookup(pathconf_arg, args[sc->offset]), fp);
break;
case Rforkflags:
- fputs(xlookup_bits(rfork_flags, args[sc->offset]), fp);
+ print_mask_arg(sysdecode_rfork_flags, fp, args[sc->offset]);
break;
case Sockaddr: {
char addr[64];
@@ -1818,31 +1675,25 @@
break;
}
case Waitoptions:
- fputs(xlookup_bits(wait_options, args[sc->offset]), fp);
+ print_mask_arg(sysdecode_wait6_options, fp, args[sc->offset]);
break;
case Idtype:
- fputs(xlookup(idtype_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_idtype, fp, args[sc->offset]);
break;
case Procctl:
- fputs(xlookup(procctl_arg, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_procctl_cmd, fp, args[sc->offset]);
break;
case Umtxop:
- fputs(xlookup(umtx_ops, args[sc->offset]), fp);
+ print_integer_arg(sysdecode_umtx_op, fp, args[sc->offset]);
break;
case Atfd:
- if ((int)args[sc->offset] == AT_FDCWD)
- fputs("AT_FDCWD", fp);
- else
- fprintf(fp, "%d", (int)args[sc->offset]);
+ sysdecode_atfd(fp, args[sc->offset], 10);
break;
case Atflags:
fputs(xlookup_bits(at_flags, args[sc->offset]), fp);
break;
case Accessmode:
- if (args[sc->offset] == F_OK)
- fputs("F_OK", fp);
- else
- fputs(xlookup_bits(access_modes, args[sc->offset]), fp);
+ print_mask_arg(sysdecode_accessmode, fp, args[sc->offset]);
break;
case Sysarch:
fputs(xlookup(sysarch_ops, args[sc->offset]), fp);
@@ -1898,6 +1749,9 @@
fprintf(fp, "0x%lx", args[sc->offset]);
break;
}
+ case Pipe2:
+ print_mask_arg(sysdecode_pipe2_flags, fp, args[sc->offset]);
+ break;
case CloudABIAdvice:
fputs(xlookup(cloudabi_advice, args[sc->offset]), fp);
@@ -1924,9 +1778,9 @@
cloudabi_filestat_t fsb;
if (get_struct(pid, (void *)args[sc->offset], &fsb, sizeof(fsb))
!= -1)
- fprintf(fp, "{ %s, %lu }",
+ fprintf(fp, "{ %s, %ju }",
xlookup(cloudabi_filetype, fsb.st_filetype),
- fsb.st_size);
+ (uintmax_t)fsb.st_size);
else
fprintf(fp, "0x%lx", args[sc->offset]);
break;

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 31, 2:34 AM (4 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28107187
Default Alt Text
D7847.id20241.diff (99 KB)

Event Timeline