svn commit: r328454 - in stable/11: lib/libsysdecode sys/compat/freebsd32 sys/kern sys/sys usr.bin/kdump usr.bin/ktrace usr.bin/truss

John Baldwin jhb at FreeBSD.org
Fri Jan 26 23:49:33 UTC 2018


Author: jhb
Date: Fri Jan 26 23:49:31 2018
New Revision: 328454
URL: https://svnweb.freebsd.org/changeset/base/328454

Log:
  MFC 326184: Decode kevent structures logged via ktrace(2) in kdump.
  
  - Add a new KTR_STRUCT_ARRAY ktrace record type which dumps an array of
    structures.
  
    The structure name in the record payload is preceded by a size_t
    containing the size of the individual structures.  Use this to
    replace the previous code that dumped the kevent arrays dumped for
    kevent().  kdump is now able to decode the kevent structures rather
    than dumping their contents via a hexdump.
  
    One change from before is that the 'changes' and 'events' arrays are
    not marked with separate 'read' and 'write' annotations in kdump
    output.  Instead, the first array is the 'changes' array, and the
    second array (only present if kevent doesn't fail with an error) is
    the 'events' array.  For kevent(), empty arrays are denoted by an
    entry with an array containing zero entries rather than no record.
  
  - Move kevent decoding tables from truss to libsysdecode.
  
    This adds three new functions to decode members of struct kevent:
    sysdecode_kevent_filter, sysdecode_kevent_flags, and
    sysdecode_kevent_fflags.
  
    kdump uses these helper functions to pretty-print kevent fields.
  
  - Move structure definitions for freebsd11 and freebsd32 kevent
    structures to <sys/event.h> so that they can be shared with userland.
    The 32-bit structures are only exposed if _WANT_KEVENT32 is defined.
    The freebsd11 structures are only exposed if _WANT_FREEBSD11_KEVENT is
    defined.  The 32-bit freebsd11 structure requires both.
  
  - Decode freebsd11 kevent structures in truss for the compat11.kevent()
    system call.
  
  - Log 32-bit kevent structures via ktrace for 32-bit compat kevent()
    system calls.
  
  - While here, constify the 'void *data' argument to ktrstruct().
  
  Note that this version of the change for 11.x does not include freebsd11
  kevent structures or _WANT_FREEBSD11_KEVENT.  It also does not include
  the change to decode the compat11.kevent system call in truss.

Added:
  stable/11/lib/libsysdecode/sysdecode_kevent.3
     - copied unchanged from r326184, head/lib/libsysdecode/sysdecode_kevent.3
Modified:
  stable/11/lib/libsysdecode/Makefile
  stable/11/lib/libsysdecode/flags.c
  stable/11/lib/libsysdecode/mktables
  stable/11/lib/libsysdecode/sysdecode.3
  stable/11/lib/libsysdecode/sysdecode.h
  stable/11/sys/compat/freebsd32/freebsd32.h
  stable/11/sys/compat/freebsd32/freebsd32_misc.c
  stable/11/sys/kern/kern_event.c
  stable/11/sys/kern/kern_ktrace.c
  stable/11/sys/sys/event.h
  stable/11/sys/sys/ktrace.h
  stable/11/usr.bin/kdump/kdump.c
  stable/11/usr.bin/ktrace/ktrace.h
  stable/11/usr.bin/truss/syscall.h
  stable/11/usr.bin/truss/syscalls.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libsysdecode/Makefile
==============================================================================
--- stable/11/lib/libsysdecode/Makefile	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/lib/libsysdecode/Makefile	Fri Jan 26 23:49:31 2018	(r328454)
@@ -17,6 +17,7 @@ MAN=	sysdecode.3 \
 	sysdecode_cap_rights.3 \
 	sysdecode_enum.3 \
 	sysdecode_fcntl_arg.3 \
+	sysdecode_kevent.3 \
 	sysdecode_ioctlname.3 \
 	sysdecode_mask.3 \
 	sysdecode_quotactl_cmd.3 \
@@ -69,6 +70,9 @@ MLINKS+=sysdecode_enum.3 sysdecode_acltype.3 \
 	sysdecode_enum.3 sysdecode_vmresult.3 \
 	sysdecode_enum.3 sysdecode_whence.3
 MLINKS+=sysdecode_fcntl_arg.3 sysdecode_fcntl_arg_p.3
+MLINKS+=sysdecode_kevent.3 sysdecode_kevent_fflags.3 \
+	sysdecode_kevent.3 sysdecode_kevent_filter.3 \
+	sysdecode_kevent.3 sysdecode_kevent_flags.3
 MLINKS+=sysdecode_mask.3 sysdecode_accessmode.3 \
 	sysdecode_mask.3 sysdecode_atflags.3 \
 	sysdecode_mask.3 sysdecode_capfcntlrights.3 \

Modified: stable/11/lib/libsysdecode/flags.c
==============================================================================
--- stable/11/lib/libsysdecode/flags.c	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/lib/libsysdecode/flags.c	Fri Jan 26 23:49:31 2018	(r328454)
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/acl.h>
 #include <sys/capsicum.h>
+#include <sys/event.h>
 #include <sys/extattr.h>
 #include <sys/linker.h>
 #include <sys/mman.h>
@@ -499,6 +500,116 @@ sysdecode_getrusage_who(int who)
 {
 
 	return (lookup_value(rusage, who));
+}
+
+static struct name_table kevent_user_ffctrl[] = {
+	X(NOTE_FFNOP) X(NOTE_FFAND) X(NOTE_FFOR) X(NOTE_FFCOPY)
+	XEND
+};
+
+static struct name_table kevent_rdwr_fflags[] = {
+	X(NOTE_LOWAT) X(NOTE_FILE_POLL) XEND
+};
+
+static struct name_table kevent_vnode_fflags[] = {
+	X(NOTE_DELETE) X(NOTE_WRITE) X(NOTE_EXTEND) X(NOTE_ATTRIB)
+	X(NOTE_LINK) X(NOTE_RENAME) X(NOTE_REVOKE) X(NOTE_OPEN) X(NOTE_CLOSE)
+	X(NOTE_CLOSE_WRITE) X(NOTE_READ) XEND
+};
+
+static struct name_table kevent_proc_fflags[] = {
+	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR)
+	X(NOTE_CHILD) XEND
+};
+
+static struct name_table kevent_timer_fflags[] = {
+	X(NOTE_SECONDS) X(NOTE_MSECONDS) X(NOTE_USECONDS) X(NOTE_NSECONDS)
+	XEND
+};
+
+void
+sysdecode_kevent_fflags(FILE *fp, short filter, int fflags, int base)
+{
+	int rem;
+
+	if (fflags == 0) {
+		fputs("0", fp);
+		return;
+	}
+
+	switch (filter) {
+	case EVFILT_READ:
+	case EVFILT_WRITE:
+		if (!print_mask_int(fp, kevent_rdwr_fflags, fflags, &rem))
+			fprintf(fp, "%#x", rem);
+		else if (rem != 0)
+			fprintf(fp, "|%#x", rem);
+		break;
+	case EVFILT_VNODE:
+		if (!print_mask_int(fp, kevent_vnode_fflags, fflags, &rem))
+			fprintf(fp, "%#x", rem);
+		else if (rem != 0)
+			fprintf(fp, "|%#x", rem);
+		break;
+	case EVFILT_PROC:
+	case EVFILT_PROCDESC:
+		if (!print_mask_int(fp, kevent_proc_fflags, fflags, &rem))
+			fprintf(fp, "%#x", rem);
+		else if (rem != 0)
+			fprintf(fp, "|%#x", rem);
+		break;
+	case EVFILT_TIMER:
+		if (!print_mask_int(fp, kevent_timer_fflags, fflags, &rem))
+			fprintf(fp, "%#x", rem);
+		else if (rem != 0)
+			fprintf(fp, "|%#x", rem);
+		break;
+	case EVFILT_USER: {
+		unsigned int ctrl, data;
+
+		ctrl = fflags & NOTE_FFCTRLMASK;
+		data = fflags & NOTE_FFLAGSMASK;
+
+		if (fflags & NOTE_TRIGGER) {
+			fputs("NOTE_TRIGGER", fp);
+			if (fflags == NOTE_TRIGGER)
+				return;
+			fputc('|', fp);
+		}
+
+		/*
+		 * An event with 'ctrl' == NOTE_FFNOP is either a reported
+		 * (output) event for which only 'data' should be output
+		 * or a pointless input event.  Assume that pointless
+		 * input events don't occur in practice.  An event with
+		 * NOTE_TRIGGER is always an input event.
+		 */
+		if (ctrl != NOTE_FFNOP || fflags & NOTE_TRIGGER) {
+			fprintf(fp, "%s|%#x",
+			    lookup_value(kevent_user_ffctrl, ctrl), data);
+		} else {
+			print_integer(fp, data, base);
+		}
+		break;
+	}
+	default:
+		print_integer(fp, fflags, base);
+		break;
+	}
+}
+
+bool
+sysdecode_kevent_flags(FILE *fp, int flags, int *rem)
+{
+
+	return (print_mask_int(fp, keventflags, flags, rem));
+}
+
+const char *
+sysdecode_kevent_filter(int filter)
+{
+
+	return (lookup_value(keventfilters, filter));
 }
 
 const char *

Modified: stable/11/lib/libsysdecode/mktables
==============================================================================
--- stable/11/lib/libsysdecode/mktables	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/lib/libsysdecode/mktables	Fri Jan 26 23:49:31 2018	(r328454)
@@ -107,6 +107,8 @@ gen_table "mmapprot"        "PROT_[A-Z]+[[:space:]]+0x
 gen_table "ngbtsolevel"     "SOL_[A-Z0-9]+[[:space:]]+0x[0-9A-Fa-f]+"      "netgraph/bluetooth/include/ng_btsocket.h"
 gen_table "fileflags"       "[SU]F_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+"       "sys/stat.h"		"UF_COMPRESSED|UF_TRACKED|UF_SETTABLE|SF_SETTABLE"
 gen_table "filemode"        "S_[A-Z]+[[:space:]]+[0-6]{7}"                 "sys/stat.h"
+gen_table "keventflags"     "EV_[A-Z]+[[:space:]]+0x[0-9]+"                "sys/event.h"        "EV_SYSFLAGS|EV_DROP|EV_FLAG[12]"
+gen_table "keventfilters"   "EVFILT_[A-Z]+[[:space:]]+\(-[0-9]+\)"         "sys/event.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 "nfssvcflags"     "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+"         "nfs/nfssvc.h"

Modified: stable/11/lib/libsysdecode/sysdecode.3
==============================================================================
--- stable/11/lib/libsysdecode/sysdecode.3	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/lib/libsysdecode/sysdecode.3	Fri Jan 26 23:49:31 2018	(r328454)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 3, 2017
+.Dd November 24, 2017
 .Dt SYSDECODE 3
 .Os
 .Sh NAME
@@ -73,6 +73,7 @@ A placeholder for use when the ABI is not known.
 .Xr sysdecode_enum 3 ,
 .Xr sysdecode_fcntl_arg 3 ,
 .Xr sysdecode_ioctlname 3 ,
+.Xr sysdecode_kevent 3 ,
 .Xr sysdecode_mask 3 ,
 .Xr sysdecode_quotactl_cmd 3 ,
 .Xr sysdecode_sigcode 3 ,

Modified: stable/11/lib/libsysdecode/sysdecode.h
==============================================================================
--- stable/11/lib/libsysdecode/sysdecode.h	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/lib/libsysdecode/sysdecode.h	Fri Jan 26 23:49:31 2018	(r328454)
@@ -60,6 +60,10 @@ const char *sysdecode_getrusage_who(int _who);
 const char *sysdecode_idtype(int _idtype);
 const char *sysdecode_ioctlname(unsigned long _val);
 const char *sysdecode_ipproto(int _protocol);
+void	sysdecode_kevent_fflags(FILE *_fp, short _filter, int _fflags,
+	    int _base);
+const char *sysdecode_kevent_filter(int _filter);
+bool	sysdecode_kevent_flags(FILE *_fp, int _flags, int *_rem);
 const char *sysdecode_kldsym_cmd(int _cmd);
 const char *sysdecode_kldunload_flags(int _flags);
 const char *sysdecode_lio_listio_mode(int _mode);

Copied: stable/11/lib/libsysdecode/sysdecode_kevent.3 (from r326184, head/lib/libsysdecode/sysdecode_kevent.3)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/lib/libsysdecode/sysdecode_kevent.3	Fri Jan 26 23:49:31 2018	(r328454, copy of r326184, head/lib/libsysdecode/sysdecode_kevent.3)
@@ -0,0 +1,126 @@
+.\"
+.\" Copyright (c) 2017 John Baldwin <jhb at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd November 24, 2017
+.Dt sysdecode_kevent 3
+.Os
+.Sh NAME
+.Nm sysdecode_kevent ,
+.Nm sysdecode_kevent_fflags ,
+.Nm sysdecode_kevent_filter ,
+.Nm sysdecode_kevent_flags
+.Nd output description of kevent structure fields
+.Sh LIBRARY
+.Lb libsysdecode
+.Sh SYNOPSIS
+.In sys/types.h
+.In stdbool.h
+.In stdio.h
+.In sysdecode.h
+.Ft void
+.Fn sysdecode_kevent_fflags "FILE *fp" "short filter" "int fflags" "int base"
+.Ft bool
+.Fn sysdecode_kevent_flags "FILE *fp" "int flags" "int *rem"
+.Ft const char *
+.Fn sysdecode_kevent_filter "int filter"
+.Sh DESCRIPTION
+These functions provide text descriptions of
+.Vt struct kevent
+fields.
+.Pp
+The
+.Fn sysdecode_kevent_fflags
+function outputs a text description of the
+.Fa fflags
+member of a
+.Vt struct kevent
+to the stream
+.Fa fp .
+For the
+.Dv EVFILT_READ ,
+.Dv EVFILT_WRITE ,
+.Dv EVFILT_VNODE ,
+.Dv EVFILT_PROC ,
+.Dv EVFILT_PROCDESC ,
+.Dv EVFILT_TIMER ,
+and
+.Dv EVFILT_USER
+filters,
+.Fn sysdecode_kevent_fflags
+outputs a bitmask of filter-specific
+.Dv NOTE_*
+flags as documented in
+.Xr kevent 2 .
+For other values of
+.Fa filter ,
+the value of
+.Fa fflags
+is output in the indicated
+.Fa base
+.Pq one of 8, 10, or 16 .
+.Pp
+The
+.Fn sysdecode_kevent_filter
+function returns a text description of the
+.Fa filter
+member of a
+.Vt struct kevent .
+.Dv NULL
+is returned if the
+.Fa filter
+value is unknown.
+.Pp
+The
+.Fn sysdecode_kevent_flags
+function outputs a text description of the
+.Fa flags
+member of a
+.Vt struct kevent
+to the stream
+.Fa fp .
+This function uses the same calling convention and formatting as the other
+functions described in
+.Xr sysdecode_mask 3 .
+.Sh RETURN VALUES
+The
+.Nm sysdecode_kevent_filter
+function returns the name of a filter or
+.Dv NULL if the filter value is unknown.
+.Pp
+The
+.Nm sysdecode_kevent_flags
+function returns
+.Dv true
+if any flags in the
+.Fa flags
+field were decoded and
+.Dv false
+if no flags were decoded.
+.Sh SEE ALSO
+.Xr sysdecode 3 ,
+.Xr sysdecode_enum 3 ,
+.Xr sysdecode_mask 3

Modified: stable/11/sys/compat/freebsd32/freebsd32.h
==============================================================================
--- stable/11/sys/compat/freebsd32/freebsd32.h	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/sys/compat/freebsd32/freebsd32.h	Fri Jan 26 23:49:31 2018	(r328454)
@@ -135,15 +135,6 @@ struct statfs32 {
 	int32_t f_spare[2];
 };
 
-struct kevent32 {
-	u_int32_t	ident;		/* identifier for this event */
-	short		filter;		/* filter for event */
-	u_short		flags;
-	u_int		fflags;
-	int32_t		data;
-	u_int32_t	udata;		/* opaque user data identifier */
-};
-
 struct iovec32 {
 	u_int32_t iov_base;
 	int	iov_len;

Modified: stable/11/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- stable/11/sys/compat/freebsd32/freebsd32_misc.c	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/sys/compat/freebsd32/freebsd32_misc.c	Fri Jan 26 23:49:31 2018	(r328454)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_compat.h"
 #include "opt_inet.h"
 #include "opt_inet6.h"
+#include "opt_ktrace.h"
 
 #define __ELF_WORD_SIZE 32
 
@@ -83,6 +84,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/msg.h>
 #include <sys/sem.h>
 #include <sys/shm.h>
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
 
 #ifdef INET
 #include <netinet/in.h>
@@ -658,6 +662,9 @@ freebsd32_kevent(struct thread *td, struct freebsd32_k
 		.k_copyout = freebsd32_kevent_copyout,
 		.k_copyin = freebsd32_kevent_copyin,
 	};
+#ifdef KTRACE
+	struct kevent32 *eventlist = uap->eventlist;
+#endif
 	int error;
 
 
@@ -670,8 +677,18 @@ freebsd32_kevent(struct thread *td, struct freebsd32_k
 		tsp = &ts;
 	} else
 		tsp = NULL;
+#ifdef KTRACE
+	if (KTRPOINT(td, KTR_STRUCT_ARRAY))
+		ktrstructarray("kevent32", UIO_USERSPACE, uap->changelist,
+		    uap->nchanges, sizeof(struct kevent32));
+#endif
 	error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
 	    &k_ops, tsp);
+#ifdef KTRACE
+	if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
+		ktrstructarray("kevent32", UIO_USERSPACE, eventlist,
+		    td->td_retval[0], sizeof(struct kevent32));
+#endif
 	return (error);
 }
 

Modified: stable/11/sys/kern/kern_event.c
==============================================================================
--- stable/11/sys/kern/kern_event.c	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/sys/kern/kern_event.c	Fri Jan 26 23:49:31 2018	(r328454)
@@ -860,17 +860,6 @@ kern_kqueue(struct thread *td, int flags, struct filec
 	return (0);
 }
 
-#ifdef KTRACE
-static size_t
-kev_iovlen(int n, u_int kgio)
-{
-
-	if (n < 0 || n >= kgio / sizeof(struct kevent))
-		return (kgio);
-	return (n * sizeof(struct kevent));
-}
-#endif
-
 #ifndef _SYS_SYSPROTO_H_
 struct kevent_args {
 	int	fd;
@@ -890,14 +879,10 @@ sys_kevent(struct thread *td, struct kevent_args *uap)
 		.k_copyout = kevent_copyout,
 		.k_copyin = kevent_copyin,
 	};
-	int error;
 #ifdef KTRACE
-	struct uio ktruio;
-	struct iovec ktriov;
-	struct uio *ktruioin = NULL;
-	struct uio *ktruioout = NULL;
-	u_int kgio;
+	struct kevent *eventlist = uap->eventlist;
 #endif
+	int error;
 
 	if (uap->timeout != NULL) {
 		error = copyin(uap->timeout, &ts, sizeof(ts));
@@ -908,31 +893,18 @@ sys_kevent(struct thread *td, struct kevent_args *uap)
 		tsp = NULL;
 
 #ifdef KTRACE
-	if (KTRPOINT(td, KTR_GENIO)) {
-		kgio = ktr_geniosize;
-		ktriov.iov_base = uap->changelist;
-		ktriov.iov_len = kev_iovlen(uap->nchanges, kgio);
-		ktruio = (struct uio){ .uio_iov = &ktriov, .uio_iovcnt = 1,
-		    .uio_segflg = UIO_USERSPACE, .uio_rw = UIO_READ,
-		    .uio_td = td };
-		ktruioin = cloneuio(&ktruio);
-		ktriov.iov_base = uap->eventlist;
-		ktriov.iov_len = kev_iovlen(uap->nevents, kgio);
-		ktriov.iov_len = uap->nevents * sizeof(struct kevent);
-		ktruioout = cloneuio(&ktruio);
-	}
+	if (KTRPOINT(td, KTR_STRUCT_ARRAY))
+		ktrstructarray("kevent", UIO_USERSPACE, uap->changelist,
+		    uap->nchanges, sizeof(struct kevent));
 #endif
 
 	error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
 	    &k_ops, tsp);
 
 #ifdef KTRACE
-	if (ktruioin != NULL) {
-		ktruioin->uio_resid = kev_iovlen(uap->nchanges, kgio);
-		ktrgenio(uap->fd, UIO_WRITE, ktruioin, 0);
-		ktruioout->uio_resid = kev_iovlen(td->td_retval[0], kgio);
-		ktrgenio(uap->fd, UIO_READ, ktruioout, error);
-	}
+	if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
+		ktrstructarray("kevent", UIO_USERSPACE, eventlist,
+		    td->td_retval[0], sizeof(struct kevent));
 #endif
 
 	return (error);

Modified: stable/11/sys/kern/kern_ktrace.c
==============================================================================
--- stable/11/sys/kern/kern_ktrace.c	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/sys/kern/kern_ktrace.c	Fri Jan 26 23:49:31 2018	(r328454)
@@ -104,6 +104,7 @@ struct ktr_request {
 		struct	ktr_csw ktr_csw;
 		struct	ktr_fault ktr_fault;
 		struct	ktr_faultend ktr_faultend;
+		struct  ktr_struct_array ktr_struct_array;
 	} ktr_data;
 	STAILQ_ENTRY(ktr_request) ktr_list;
 };
@@ -123,6 +124,7 @@ static int data_lengths[] = {
 	[KTR_CAPFAIL] = sizeof(struct ktr_cap_fail),
 	[KTR_FAULT] = sizeof(struct ktr_fault),
 	[KTR_FAULTEND] = sizeof(struct ktr_faultend),
+	[KTR_STRUCT_ARRAY] = sizeof(struct ktr_struct_array),
 };
 
 static STAILQ_HEAD(, ktr_request) ktr_free;
@@ -740,7 +742,7 @@ ktrcsw(int out, int user, const char *wmesg)
 }
 
 void
-ktrstruct(const char *name, void *data, size_t datalen)
+ktrstruct(const char *name, const void *data, size_t datalen)
 {
 	struct ktr_request *req;
 	char *buf;
@@ -757,6 +759,52 @@ ktrstruct(const char *name, void *data, size_t datalen
 		free(buf, M_KTRACE);
 		return;
 	}
+	req->ktr_buffer = buf;
+	req->ktr_header.ktr_len = buflen;
+	ktr_submitrequest(curthread, req);
+}
+
+void
+ktrstructarray(const char *name, enum uio_seg seg, const void *data,
+    int num_items, size_t struct_size)
+{
+	struct ktr_request *req;
+	struct ktr_struct_array *ksa;
+	char *buf;
+	size_t buflen, datalen, namelen;
+	int max_items;
+
+	/* Trim array length to genio size. */
+	max_items = ktr_geniosize / struct_size;
+	if (num_items > max_items) {
+		if (max_items == 0)
+			num_items = 1;
+		else
+			num_items = max_items;
+	}
+	datalen = num_items * struct_size;
+
+	if (data == NULL)
+		datalen = 0;
+
+	namelen = strlen(name) + 1;
+	buflen = namelen + datalen;
+	buf = malloc(buflen, M_KTRACE, M_WAITOK);
+	strcpy(buf, name);
+	if (seg == UIO_SYSSPACE)
+		bcopy(data, buf + namelen, datalen);
+	else {
+		if (copyin(data, buf + namelen, datalen) != 0) {
+			free(buf, M_KTRACE);
+			return;
+		}
+	}
+	if ((req = ktr_getrequest(KTR_STRUCT_ARRAY)) == NULL) {
+		free(buf, M_KTRACE);
+		return;
+	}
+	ksa = &req->ktr_data.ktr_struct_array;
+	ksa->struct_size = struct_size;
 	req->ktr_buffer = buf;
 	req->ktr_header.ktr_len = buflen;
 	ktr_submitrequest(curthread, req);

Modified: stable/11/sys/sys/event.h
==============================================================================
--- stable/11/sys/sys/event.h	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/sys/sys/event.h	Fri Jan 26 23:49:31 2018	(r328454)
@@ -64,6 +64,17 @@ struct kevent {
 	void		*udata;		/* opaque user data identifier */
 };
 
+#if defined(_WANT_KEVENT32) || (defined(_KERNEL) && defined(__LP64__))
+struct kevent32 {
+	u_int32_t	ident;		/* identifier for this event */
+	short		filter;		/* filter for event */
+	u_short		flags;
+	u_int		fflags;
+	int32_t		data;
+	u_int32_t	udata;		/* opaque user data identifier */
+};
+#endif
+
 /* actions */
 #define EV_ADD		0x0001		/* add event to kq (implies enable) */
 #define EV_DELETE	0x0002		/* delete event from kq */

Modified: stable/11/sys/sys/ktrace.h
==============================================================================
--- stable/11/sys/sys/ktrace.h	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/sys/sys/ktrace.h	Fri Jan 26 23:49:31 2018	(r328454)
@@ -219,6 +219,18 @@ struct ktr_faultend {
 };
 
 /*
+ * KTR_STRUCT_ARRAY - array of misc. structs
+ */
+#define	KTR_STRUCT_ARRAY 15
+struct ktr_struct_array {
+	size_t struct_size;
+	/*
+	 * Followed by null-terminated structure name and then payload
+	 * contents.
+	 */
+};
+
+/*
  * KTR_DROP - If this bit is set in ktr_type, then at least one event
  * between the previous record and this record was dropped.
  */
@@ -242,6 +254,7 @@ struct ktr_faultend {
 #define KTRFAC_CAPFAIL	(1<<KTR_CAPFAIL)
 #define KTRFAC_FAULT	(1<<KTR_FAULT)
 #define KTRFAC_FAULTEND	(1<<KTR_FAULTEND)
+#define	KTRFAC_STRUCT_ARRAY (1<<KTR_STRUCT_ARRAY)
 
 /*
  * trace flags (also in p_traceflags)
@@ -265,7 +278,8 @@ void	ktrprocexec(struct proc *, struct ucred **, struc
 void	ktrprocexit(struct thread *);
 void	ktrprocfork(struct proc *, struct proc *);
 void	ktruserret(struct thread *);
-void	ktrstruct(const char *, void *, size_t);
+void	ktrstruct(const char *, const void *, size_t);
+void	ktrstructarray(const char *, enum uio_seg, const void *, int, size_t);
 void	ktrcapfail(enum ktr_cap_fail_type, const cap_rights_t *,
 	    const cap_rights_t *);
 #define ktrcaprights(s) \

Modified: stable/11/usr.bin/kdump/kdump.c
==============================================================================
--- stable/11/usr.bin/kdump/kdump.c	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/usr.bin/kdump/kdump.c	Fri Jan 26 23:49:31 2018	(r328454)
@@ -42,11 +42,15 @@ static char sccsid[] = "@(#)kdump.c	8.1 (Berkeley) 6/6
 __FBSDID("$FreeBSD$");
 
 #define _WANT_KERNEL_ERRNO
+#ifdef __LP64__
+#define	_WANT_KEVENT32
+#endif
 #include <sys/param.h>
 #include <sys/capsicum.h>
 #include <sys/errno.h>
 #include <sys/time.h>
 #include <sys/uio.h>
+#include <sys/event.h>
 #include <sys/ktrace.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -109,6 +113,8 @@ void ktrstruct(char *, size_t);
 void ktrcapfail(struct ktr_cap_fail *);
 void ktrfault(struct ktr_fault *);
 void ktrfaultend(struct ktr_faultend *);
+void ktrkevent(struct kevent *);
+void ktrstructarray(struct ktr_struct_array *, size_t);
 void limitfd(int fd);
 void usage(void);
 
@@ -546,6 +552,9 @@ main(int argc, char *argv[])
 		case KTR_FAULTEND:
 			ktrfaultend((struct ktr_faultend *)m);
 			break;
+		case KTR_STRUCT_ARRAY:
+			ktrstructarray((struct ktr_struct_array *)m, ktrlen);
+			break;
 		default:
 			printf("\n");
 			break;
@@ -714,6 +723,7 @@ dumpheader(struct ktr_header *kth)
 		type = "USER";
 		break;
 	case KTR_STRUCT:
+	case KTR_STRUCT_ARRAY:
 		type = "STRU";
 		break;
 	case KTR_SYSCTL:
@@ -2106,6 +2116,104 @@ ktrfaultend(struct ktr_faultend *ktr)
 	else
 		printf("<invalid=%d>", ktr->result);
 	printf("\n");
+}
+
+void
+ktrkevent(struct kevent *kev)
+{
+
+	printf("{ ident=");
+	switch (kev->filter) {
+	case EVFILT_READ:
+	case EVFILT_WRITE:
+	case EVFILT_VNODE:
+	case EVFILT_PROC:
+	case EVFILT_TIMER:
+	case EVFILT_PROCDESC:
+		printf("%ju", (uintmax_t)kev->ident);
+		break;
+	case EVFILT_SIGNAL:
+		print_signal(kev->ident);
+		break;
+	default:
+		printf("%p", (void *)kev->ident);
+	}
+	printf(", filter=");
+	print_integer_arg(sysdecode_kevent_filter, kev->filter);
+	printf(", flags=");
+	print_mask_arg0(sysdecode_kevent_flags, kev->flags);
+	printf(", fflags=");
+	sysdecode_kevent_fflags(stdout, kev->filter, kev->fflags,
+	    decimal ? 10 : 16);
+	printf(", data=%#jx, udata=%p }", (uintmax_t)kev->data, kev->udata);
+}
+
+void
+ktrstructarray(struct ktr_struct_array *ksa, size_t buflen)
+{
+	struct kevent kev;
+	char *name, *data;
+	size_t namelen, datalen;
+	int i;
+	bool first;
+
+	buflen -= sizeof(*ksa);
+	for (name = (char *)(ksa + 1), namelen = 0;
+	     namelen < buflen && name[namelen] != '\0';
+	     ++namelen)
+		/* nothing */;
+	if (namelen == buflen)
+		goto invalid;
+	if (name[namelen] != '\0')
+		goto invalid;
+	/* sanity check */
+	for (i = 0; i < (int)namelen; ++i)
+		if (!isalnum(name[i]) && name[i] != '_')
+			goto invalid;
+	data = name + namelen + 1;
+	datalen = buflen - namelen - 1;
+	printf("struct %s[] = { ", name);
+	first = true;
+	for (; datalen >= ksa->struct_size;
+	    data += ksa->struct_size, datalen -= ksa->struct_size) {
+		if (!first)
+			printf("\n             ");
+		else
+			first = false;
+		if (strcmp(name, "kevent") == 0) {
+			if (ksa->struct_size != sizeof(kev))
+				goto bad_size;
+			memcpy(&kev, data, sizeof(kev));
+			ktrkevent(&kev);
+#ifdef _WANT_KEVENT32
+		} else if (strcmp(name, "kevent32") == 0) {
+			struct kevent32 kev32;
+
+			if (ksa->struct_size != sizeof(kev32))
+				goto bad_size;
+			memcpy(&kev32, data, sizeof(kev32));
+			memset(&kev, 0, sizeof(kev));
+			kev.ident = kev32.ident;
+			kev.filter = kev32.filter;
+			kev.flags = kev32.flags;
+			kev.fflags = kev32.fflags;
+			kev.data = kev32.data;
+			kev.udata = (void *)(uintptr_t)kev32.udata;
+			ktrkevent(&kev);
+#endif
+		} else {
+			printf("<unknown structure> }\n");
+			return;
+		}
+	}
+	printf(" }\n");
+	return;
+invalid:
+	printf("invalid record\n");
+	return;
+bad_size:
+	printf("<bad size> }\n");
+	return;
 }
 
 void

Modified: stable/11/usr.bin/ktrace/ktrace.h
==============================================================================
--- stable/11/usr.bin/ktrace/ktrace.h	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/usr.bin/ktrace/ktrace.h	Fri Jan 26 23:49:31 2018	(r328454)
@@ -32,7 +32,8 @@
 
 #define DEF_POINTS (KTRFAC_SYSCALL | KTRFAC_SYSRET | KTRFAC_NAMEI | \
 		    KTRFAC_GENIO | KTRFAC_PSIG | KTRFAC_USER | \
-		    KTRFAC_STRUCT | KTRFAC_SYSCTL | KTRFAC_CAPFAIL)
+		    KTRFAC_STRUCT | KTRFAC_SYSCTL | KTRFAC_CAPFAIL | \
+		    KTRFAC_STRUCT_ARRAY)
 
 #define PROC_ABI_POINTS (KTRFAC_PROCCTOR | KTRFAC_PROCDTOR)
 

Modified: stable/11/usr.bin/truss/syscall.h
==============================================================================
--- stable/11/usr.bin/truss/syscall.h	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/usr.bin/truss/syscall.h	Fri Jan 26 23:49:31 2018	(r328454)
@@ -51,7 +51,7 @@ enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHe
 	Sockoptname, Msgflags, CapRights, PUInt, PQuadHex, Acltype,
 	Extattrnamespace, Minherit, Mlockall, Mountflags, Msync, Priowhich,
 	Ptraceop, Quotactlcmd, Reboothowto, Rtpriofunc, Schedpolicy, Schedparam,
-	PSig, Siginfo,
+	PSig, Siginfo, Kevent11,
 
 	CloudABIAdvice, CloudABIClockID, ClouduABIFDSFlags,
 	CloudABIFDStat, CloudABIFileStat, CloudABIFileType,

Modified: stable/11/usr.bin/truss/syscalls.c
==============================================================================
--- stable/11/usr.bin/truss/syscalls.c	Fri Jan 26 23:21:50 2018	(r328453)
+++ stable/11/usr.bin/truss/syscalls.c	Fri Jan 26 23:49:31 2018	(r328454)
@@ -638,43 +638,6 @@ struct xlat {
 #define	X(a)	{ a, #a },
 #define	XEND	{ 0, NULL }
 
-static struct xlat kevent_filters[] = {
-	X(EVFILT_READ) X(EVFILT_WRITE) X(EVFILT_AIO) X(EVFILT_VNODE)
-	X(EVFILT_PROC) X(EVFILT_SIGNAL) X(EVFILT_TIMER)
-	X(EVFILT_PROCDESC) X(EVFILT_FS) X(EVFILT_LIO) X(EVFILT_USER)
-	X(EVFILT_SENDFILE) XEND
-};
-
-static struct xlat kevent_flags[] = {
-	X(EV_ADD) X(EV_DELETE) X(EV_ENABLE) X(EV_DISABLE) X(EV_ONESHOT)
-	X(EV_CLEAR) X(EV_RECEIPT) X(EV_DISPATCH) X(EV_FORCEONESHOT)
-	X(EV_DROP) X(EV_FLAG1) X(EV_ERROR) X(EV_EOF) XEND
-};
-
-static struct xlat kevent_user_ffctrl[] = {
-	X(NOTE_FFNOP) X(NOTE_FFAND) X(NOTE_FFOR) X(NOTE_FFCOPY)
-	XEND
-};
-
-static struct xlat kevent_rdwr_fflags[] = {
-	X(NOTE_LOWAT) X(NOTE_FILE_POLL) XEND
-};
-
-static struct xlat kevent_vnode_fflags[] = {
-	X(NOTE_DELETE) X(NOTE_WRITE) X(NOTE_EXTEND) X(NOTE_ATTRIB)
-	X(NOTE_LINK) X(NOTE_RENAME) X(NOTE_REVOKE) XEND
-};
-
-static struct xlat kevent_proc_fflags[] = {
-	X(NOTE_EXIT) X(NOTE_FORK) X(NOTE_EXEC) X(NOTE_TRACK) X(NOTE_TRACKERR)
-	X(NOTE_CHILD) XEND
-};
-
-static struct xlat kevent_timer_fflags[] = {
-	X(NOTE_SECONDS) X(NOTE_MSECONDS) X(NOTE_USECONDS) X(NOTE_NSECONDS)
-	XEND
-};
-
 static struct xlat poll_flags[] = {
 	X(POLLSTANDARD) X(POLLIN) X(POLLPRI) X(POLLOUT) X(POLLERR)
 	X(POLLHUP) X(POLLNVAL) X(POLLRDNORM) X(POLLRDBAND)
@@ -1125,7 +1088,7 @@ strsig2(int sig)
 }
 
 static void
-print_kevent(FILE *fp, struct kevent *ke, int input)
+print_kevent(FILE *fp, struct kevent *ke)
 {
 
 	switch (ke->filter) {
@@ -1143,42 +1106,12 @@ print_kevent(FILE *fp, struct kevent *ke, int input)
 	default:
 		fprintf(fp, "%p", (void *)ke->ident);
 	}
-	fprintf(fp, ",%s,%s,", xlookup(kevent_filters, ke->filter),
-	    xlookup_bits(kevent_flags, ke->flags));
-	switch (ke->filter) {
-	case EVFILT_READ:
-	case EVFILT_WRITE:
-		fputs(xlookup_bits(kevent_rdwr_fflags, ke->fflags), fp);
-		break;
-	case EVFILT_VNODE:
-		fputs(xlookup_bits(kevent_vnode_fflags, ke->fflags), fp);
-		break;
-	case EVFILT_PROC:
-	case EVFILT_PROCDESC:
-		fputs(xlookup_bits(kevent_proc_fflags, ke->fflags), fp);
-		break;
-	case EVFILT_TIMER:
-		fputs(xlookup_bits(kevent_timer_fflags, ke->fflags), fp);
-		break;
-	case EVFILT_USER: {
-		int ctrl, data;
-
-		ctrl = ke->fflags & NOTE_FFCTRLMASK;
-		data = ke->fflags & NOTE_FFLAGSMASK;
-		if (input) {
-			fputs(xlookup(kevent_user_ffctrl, ctrl), fp);
-			if (ke->fflags & NOTE_TRIGGER)
-				fputs("|NOTE_TRIGGER", fp);
-			if (data != 0)
-				fprintf(fp, "|%#x", data);
-		} else {
-			fprintf(fp, "%#x", data);
-		}
-		break;
-	}
-	default:
-		fprintf(fp, "%#x", ke->fflags);
-	}
+	fprintf(fp, ",");
+	print_integer_arg(sysdecode_kevent_filter, fp, ke->filter);
+	fprintf(fp, ",");
+	print_mask_arg(sysdecode_kevent_flags, fp, ke->flags);
+	fprintf(fp, ",");
+	sysdecode_kevent_fflags(fp, ke->filter, ke->fflags, 16);
 	fprintf(fp, ",%p,%p", (void *)ke->data, (void *)ke->udata);
 }
 
@@ -1783,7 +1716,7 @@ print_arg(struct syscall_args *sc, unsigned long *args
 			fputc('{', fp);
 			for (i = 0; i < numevents; i++) {
 				fputc(' ', fp);
-				print_kevent(fp, &ke[i], sc->offset == 1);
+				print_kevent(fp, &ke[i]);
 			}
 			fputs(" }", fp);
 		} else {


More information about the svn-src-stable-11 mailing list