History log of /openbsd-current/usr.bin/kdump/kdump.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.163 18-May-2024 guenther

Add pathconfat(2): pathconf(2) but with at-fd and flags arguments,
the latter supporting the ability to get timestamp resolution of
symlinks.

ok deraadt@ millert@


# 1.162 29-Mar-2024 deraadt

SYS_msyscall will go away soon. kdump does not need a special handler
for it.
ok tb


Revision tags: OPENBSD_7_5_BASE
# 1.161 15-Dec-2023 deraadt

provide the pieces for ktrace/kdump to observe pinsyscall violations.
(not used yet, because the pinsyscall changes are still being worked on)
ok kettenis


# 1.160 12-Dec-2023 deraadt

remove support for syscall(2) -- the "indirection system call" because
it is a dangerous alternative entry point for all system calls, and thus
incompatible with the precision system call entry point scheme we are
heading towards. This has been a 3-year mission:
First perl needed a code-generated wrapper to fake syscall(2) as a giant
switch table, then all the ports were cleaned with relatively minor fixes,
except for "go". "go" required two fixes -- 1) a framework issue with
old library versions, and 2) like perl, a fake syscall(2) wrapper to
handle ioctl(2) and sysctl(2) because "syscall(SYS_ioctl" occurs all over
the place in the "go" ecosystem because the "go developers" are plan9-loving
unix-hating folk who tried to build an ecosystem without allowing "ioctl".
ok kettenis, jsing, afresh1, sthen


# 1.159 09-Nov-2023 kn

Add [-P progam] to filter dumps by basename

[-p pid] requires knowing the PIDs beforehand, sieving through big
dumps by argv[0] strings is more ergonomic.

OK deraadt


Revision tags: OPENBSD_7_4_BASE
# 1.158 21-Aug-2023 visa

Make kdump show kqueue1(2) flags.

OK guenther@


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.162 29-Mar-2024 deraadt

SYS_msyscall will go away soon. kdump does not need a special handler
for it.
ok tb


Revision tags: OPENBSD_7_5_BASE
# 1.161 15-Dec-2023 deraadt

provide the pieces for ktrace/kdump to observe pinsyscall violations.
(not used yet, because the pinsyscall changes are still being worked on)
ok kettenis


# 1.160 12-Dec-2023 deraadt

remove support for syscall(2) -- the "indirection system call" because
it is a dangerous alternative entry point for all system calls, and thus
incompatible with the precision system call entry point scheme we are
heading towards. This has been a 3-year mission:
First perl needed a code-generated wrapper to fake syscall(2) as a giant
switch table, then all the ports were cleaned with relatively minor fixes,
except for "go". "go" required two fixes -- 1) a framework issue with
old library versions, and 2) like perl, a fake syscall(2) wrapper to
handle ioctl(2) and sysctl(2) because "syscall(SYS_ioctl" occurs all over
the place in the "go" ecosystem because the "go developers" are plan9-loving
unix-hating folk who tried to build an ecosystem without allowing "ioctl".
ok kettenis, jsing, afresh1, sthen


# 1.159 09-Nov-2023 kn

Add [-P progam] to filter dumps by basename

[-p pid] requires knowing the PIDs beforehand, sieving through big
dumps by argv[0] strings is more ergonomic.

OK deraadt


Revision tags: OPENBSD_7_4_BASE
# 1.158 21-Aug-2023 visa

Make kdump show kqueue1(2) flags.

OK guenther@


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.161 15-Dec-2023 deraadt

provide the pieces for ktrace/kdump to observe pinsyscall violations.
(not used yet, because the pinsyscall changes are still being worked on)
ok kettenis


# 1.160 12-Dec-2023 deraadt

remove support for syscall(2) -- the "indirection system call" because
it is a dangerous alternative entry point for all system calls, and thus
incompatible with the precision system call entry point scheme we are
heading towards. This has been a 3-year mission:
First perl needed a code-generated wrapper to fake syscall(2) as a giant
switch table, then all the ports were cleaned with relatively minor fixes,
except for "go". "go" required two fixes -- 1) a framework issue with
old library versions, and 2) like perl, a fake syscall(2) wrapper to
handle ioctl(2) and sysctl(2) because "syscall(SYS_ioctl" occurs all over
the place in the "go" ecosystem because the "go developers" are plan9-loving
unix-hating folk who tried to build an ecosystem without allowing "ioctl".
ok kettenis, jsing, afresh1, sthen


# 1.159 09-Nov-2023 kn

Add [-P progam] to filter dumps by basename

[-p pid] requires knowing the PIDs beforehand, sieving through big
dumps by argv[0] strings is more ergonomic.

OK deraadt


Revision tags: OPENBSD_7_4_BASE
# 1.158 21-Aug-2023 visa

Make kdump show kqueue1(2) flags.

OK guenther@


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.160 12-Dec-2023 deraadt

remove support for syscall(2) -- the "indirection system call" because
it is a dangerous alternative entry point for all system calls, and thus
incompatible with the precision system call entry point scheme we are
heading towards. This has been a 3-year mission:
First perl needed a code-generated wrapper to fake syscall(2) as a giant
switch table, then all the ports were cleaned with relatively minor fixes,
except for "go". "go" required two fixes -- 1) a framework issue with
old library versions, and 2) like perl, a fake syscall(2) wrapper to
handle ioctl(2) and sysctl(2) because "syscall(SYS_ioctl" occurs all over
the place in the "go" ecosystem because the "go developers" are plan9-loving
unix-hating folk who tried to build an ecosystem without allowing "ioctl".
ok kettenis, jsing, afresh1, sthen


# 1.159 09-Nov-2023 kn

Add [-P progam] to filter dumps by basename

[-p pid] requires knowing the PIDs beforehand, sieving through big
dumps by argv[0] strings is more ergonomic.

OK deraadt


Revision tags: OPENBSD_7_4_BASE
# 1.158 21-Aug-2023 visa

Make kdump show kqueue1(2) flags.

OK guenther@


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.159 09-Nov-2023 kn

Add [-P progam] to filter dumps by basename

[-p pid] requires knowing the PIDs beforehand, sieving through big
dumps by argv[0] strings is more ergonomic.

OK deraadt


Revision tags: OPENBSD_7_4_BASE
# 1.158 21-Aug-2023 visa

Make kdump show kqueue1(2) flags.

OK guenther@


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.158 21-Aug-2023 visa

Make kdump show kqueue1(2) flags.

OK guenther@


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.157 16-Apr-2023 otto

Add a -u label option to print selected utrace records, used by upcoming
malloc (leak) dump fucntion. ok semarie@


Revision tags: OPENBSD_7_3_BASE
# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.156 17-Feb-2023 deraadt

KTRC_CODE__SYSCALL is never set anymore, because __syscall() is gone.


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.155 16-Jan-2023 deraadt

we spent far too long debugging a weird go library problem (incorrect
arguments to mmap) because it was using syscall(2) and that callpath
is invisible in ktrace. make it visible, it will now show "(via syscall)"
and such.
ok guenther


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.154 07-Jan-2023 guenther

Add argument and return support for {get,set}thrname()


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.153 29-Dec-2022 guenther

Add ktrace struct tracepoints for siginfo_t to the kernel side of
waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them.
Also report more from the siginfo_t inside PSIG tracepoints.

ok mpi@


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.152 20-Dec-2022 guenther

Add argument support for msyscall, pledge, unveil, __realpath,
ypconnect, and __tmpfd. Reorder several other syscalls to match
the order in syscalls.master

ok deraadt@


# 1.151 19-Dec-2022 guenther

Improve reporting of waitid(2)'s idtype/id and options arguments
Add mimmutable(2) to report like munmap(2)


Revision tags: OPENBSD_7_2_BASE
# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.150 08-Sep-2022 mbuhl

Support the sendmmsg and recvmmsg system calls.
Input guenther@
OK bluhm@


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.149 20-Jul-2022 deraadt

the _pad_ system calls from 2021/12/23 can go away
ok guenther


Revision tags: OPENBSD_7_1_BASE
# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.148 22-Feb-2022 deraadt

Since ktr_comm is now a string, we do not need MAXCOMLEN to limit printf.
And thus, sys/param.h is not needed either.
ok millert


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.147 22-Feb-2022 deraadt

repair sys/param.h namespace list


# 1.146 22-Feb-2022 deraadt

need a local nitems() definition


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.145 23-Dec-2021 guenther

Roll the syscalls that have an off_t argument to remove the explicit padding.
Switch libc and ld.so to the generic stubs for these calls.
WARNING: reboot to updated kernel before installing libc or ld.so!

Time for a story...

When gcc (back in 1.x days) first implemented long long, it didn't (always)
pass 64bit arguments in 'aligned' registers/stack slots, with the result that
argument offsets didn't match structure offsets. This affected the nine system
calls that pass off_t arguments:
ftruncate lseek mmap mquery pread preadv pwrite pwritev truncate

To avoid having to do custom ASM wrappers for those, BSD put an explicit pad
argument in so that the off_t argument would always start on a even slot and
thus be naturally aligned. Thus those odd wrappers in lib/libc/sys/ that use
__syscall() and pass an extra '0' argument.

The ABIs for different CPUs eventually settled how things should be passed on
each and gcc 2.x followed them. The only arch now where it helps is landisk,
which needs to skip the last argument register if it would be the first half of
a 64bit argument. So: add new syscalls without the pad argument and on landisk
do that skipping directly in the syscall handler in the kernel. Keep compat
support for the existing syscalls long enough for the transition.

ok deraadt@


Revision tags: OPENBSD_7_0_BASE
# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.144 12-Jul-2021 beck

Change the error reporting pattern throughout the tree when unveil
fails to report the path that the failure occured on. Suggested by
deraadt@ after some tech discussion.

Work done and verified by Ashton Fagg <ashton@fagg.id.au>

ok deraadt@ semarie@ claudio@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.143 05-Apr-2020 mpi

Do not assume futex(2) is always returning an errno value.

In the case of FUTEX_WAKE a number of woken threads is returned.

ok guenther@


# 1.142 05-Apr-2020 visa

Declare pledgenames[] as const.

OK deraadt@


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.141 18-Jan-2020 cheloha

kdump(1): give timestamp types real names; ok schwarze@


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.140 27-Nov-2019 deraadt

use _PATH_PROTOCOLS from netdb.h instead


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.139 26-Nov-2019 otto

kdump reads /etc/protocols to translate proto numbers into names; ok sthen@ gilles@


Revision tags: OPENBSD_6_6_BASE
# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.138 15-May-2019 schwarze

improve wrong markup and poor wording regarding the -t argument
that was spotted by deraadt@;
OK deraadt@ jmc@


Revision tags: OPENBSD_6_5_BASE
# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.137 11-Jan-2019 deraadt

mincore() is a relic from the past, exposing physical machine information
about shared resources which no program should see. only a few pieces of
software use it, generally poorly thought out. they are being fixed, so
mincore() can be deleted.
ok guenther tedu jca sthen, others


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.136 12-Dec-2018 tedu

allow reading from stdin with -f -.
ok kn


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.135 21-Oct-2018 guenther

futex(2) returns an errno value to decode

ok otto@


Revision tags: OPENBSD_6_4_BASE
# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.134 11-Aug-2018 mestre

the only fs access kdump(1) needs is to the tracefile which by default is
ktrace.out unless argument -f is used. We can just unveil(2) that file with read
permissions before the pledge(2) call.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.133 28-Nov-2017 guenther

Need to remove fktrace here too
Noted by Andreas Kusalananda K��h��ri (andreas.kahari(at)icm.uu.se)


# 1.132 07-Oct-2017 guenther

Format fktrace(2) arguments

ok millert@


# 1.131 07-Oct-2017 guenther

Delete pointless casts from void*

ok otto@ millert@


Revision tags: OPENBSD_6_2_BASE
# 1.130 28-Apr-2017 mpi

Display futex(2) operations and arguments.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.129 18-Jul-2016 guenther

Add 'p' trace point for KTRFAC_PLEDGE, as noted by
Michal Mazurek <akfaew@jasminek.net>

While here, fix handling of -t+ in ltrace.


# 1.128 02-Jun-2016 tedu

allow printing timestamps relative to beginnging of trace, -RT. ok benno


# 1.127 30-Mar-2016 guenther

Handle error return by SYS_getlogin_r and SYS___thrsleep correct, and
parse args of SYS_getlogin_r


# 1.126 24-Mar-2016 guenther

Display NAMI records and AF_UNIX socket paths with vis, using
VIS_CSTYLE | VIS_DQ | VIS_TAB | VIS_NL; add the latter three flags
to the existing vis encoding of exec argv/environ and pledge
requests/paths.
Delete local variables left unused when showbuf() and showbufc() were split

ok otto@ millert@


# 1.125 22-Mar-2016 guenther

Format the flags argument to sendsyslog()

ok deraadt@ bluhm@


# 1.124 21-Mar-2016 guenther

Handle kbind()'s third argument correctly


# 1.123 06-Mar-2016 guenther

Improve display of unknown and KTR_START records

request and ok naddy@


# 1.122 06-Mar-2016 guenther

No more compat emulations, so remove ktrace EMUL records and the baggage
for generating and parsing them.

ok mpi@ naddy@ millert@ deraadt@


# 1.121 28-Feb-2016 naddy

drop the support for Linux emulation; ok guenther@ visa@


Revision tags: OPENBSD_5_9_BASE
# 1.120 10-Nov-2015 guenther

Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.

Minor bump to both libc and libpthread: make sure you install a new kernel!

ok semarie@


# 1.119 28-Oct-2015 deraadt

remove knowledge of dnssocket/dnsconnect


# 1.118 26-Oct-2015 deraadt

If the system call is entirely unpermitted, code will be 0, and there is
no pledge to recommend.


# 1.117 25-Oct-2015 deraadt

Fold "malloc" into "stdio" and -- recognizing that no program so far has
used less than "stdio" -- include all the "self" operations. Instead of
different defines, use regular PLEDGE_* in the "p_pledgenote" variable
(which indicates the operation subtype a system call is performing). Many
checks before easier to understand. p_pledgenote can often be passed
directly to ktrace, so that kdump says:
15565 test CALL pledge(0xa9a3f804c51,0)
15565 test STRU pledge request="stdio"
15565 test RET pledge 0
15565 test CALL open(0xa9a3f804c57,0x2<O_RDWR>)
15565 test NAMI "/tmp/testfile"
15565 test PLDG open, "wpath", errno 1 Operation not permitted
with help from semarie, ok guenther


# 1.116 18-Oct-2015 deraadt

Describe dnssocket / dnsconnect arguments


# 1.115 10-Oct-2015 deraadt

normalize a few more tame request orderings, to help review


# 1.114 10-Oct-2015 deraadt

since kdump may getprotobynumber() late, do not drop "rpath". We could
potentially modify pledge() to permit /etc/protocols (/etc/rpc?
/etc/services? etc) without requiring a rpath attribute.. but where would
we draw the line for what /etc files libc functions need? At present, we
draw that line closer to the minimum.
issue found by theo@math.ethz.ch


# 1.113 09-Oct-2015 deraadt

Change all tame callers to namechange to pledge(2).


# 1.112 06-Oct-2015 deraadt

tame "stdio getpw"
discussed with guenther


# 1.111 03-Oct-2015 guenther

Add ktracing of tame()'s arguments' values

"every tool helps" deraadt@


# 1.110 03-Oct-2015 guenther

option LFS is dead, but we missed option ACCOUNTING here


# 1.109 03-Oct-2015 zhuk

Fix wrong cast.

This one should be an unsigned long in theory, but the formatter function
argument we're printing from is already an int (being casted from register_t
at the formatter call time). So lets fix one bug at a time.

authoritative okay from guenther@


# 1.108 03-Oct-2015 deraadt

tame "stdio getpw rpath" can be done quite early after the getopt.
it might seem we can hoist the open above tame and then drop "rpath",
but guenther found getprotobynumber can be called much later.
ok guenther


# 1.107 02-Oct-2015 jmc

update the -t args list; ok guenther


# 1.106 02-Oct-2015 guenther

Add ktracing of argv and envp to execve(2), with envp not traced by default

ok tedu@ deraadt@


# 1.105 13-Sep-2015 guenther

Rename __sysctl syscall to just sysctl, as the userland wrapper is no longer
necessary

ok deraadt@ jsing@


# 1.104 07-Sep-2015 guenther

Delete ktracing of context switches: it's unused, and not particularly useful,
and doing VOP_WRITE() from inside tsleep/msleep makes the locking too
complicated, making it harder to move forward on MP changes.

ok deraadt@ kettenis@


Revision tags: OPENBSD_5_8_BASE
# 1.103 19-Jul-2015 guenther

Make KTR_SYSRET records variables variables sized, leaving out the
retval on error, including a long long retval on successful lseek(),
and including a register_t retval for other successes. This fixes
lseek reporting on ILP32 archs.

While here, reworking internal kern_ktrace.c bits to be able to pass
two buffers to ktrwriteraw(), so we can avoid mallocing a buffer
in some cases and so that KTR_GENIO logs are split at PAGE_SIZE,
not PAGE_SIZE-sizeof(struct ktrgenio)

ok miod@


# 1.102 19-Jul-2015 deraadt

Figure out the tty width using TIOCGWINSZ early on. Will make tame(2)
integration easier in the future.


# 1.101 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.100 17-Apr-2015 guenther

oops, started expecting sockoptlevelname() to handle two arguments
but never actually did so. Fix that so that we stop losing the
second argument to {get,set}sockopt(). Handling of levels other than
SOL_SOCKET could be improved.


# 1.99 17-Apr-2015 guenther

The first argument to socket/socketpair is an address family, not a protocol
family. (sysctl(3) is practically the only place where PF_* is correct)


Revision tags: OPENBSD_5_7_BASE
# 1.98 26-Jan-2015 guenther

Oops: symlinkat()'s 'atfd' argument is its second, not its first


# 1.97 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.96 28-Dec-2014 bluhm

With revision 1.93 a space character got lost when printing the
signal action. Print the space again.
OK jsg@


# 1.95 15-Dec-2014 jmc

remove -r from usage();


# 1.94 15-Dec-2014 guenther

Eliminate the -r option and always do sysctl OID, username, groupname,
and ctime presentation, but combined with the numeric form ala 0<"root">.
Do username and groupname presentation on syscall arguments and retvals.

ok millert@ otto@


# 1.93 09-Dec-2014 jsg

Add some additional sanity checks to kdump.
Fixes a variety of crashes found with the afl fuzzer.
ok miod@ on an earlier version.


# 1.92 08-Dec-2014 guenther

Convert syscall argument handling from a giant switch to a giant table.
While at it, use formatters for fds, counts, ids of all types, and "small
buffer sizes" that always show them in decimal, while paths, pointers, and
"big buffer sizes" get formatters that always show them in hex. The -d
option only affects args when the -n option is used or for unknown syscalls,
as well as syscall return values, and unrecognized ioctls.

ok otto@ millert@


# 1.91 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


# 1.90 08-Oct-2014 doug

userland reallocarray audit.

Replace malloc() and realloc() calls that may have integer overflow in the
multiplication of the arguments with reallocarray().

ok deraadt@


# 1.89 17-Sep-2014 guenther

Add display of the flags to pipe2, dup3, and accept4, display of
MSG_CMSG_CLOEXEC in recvmsg, and display of SOCK_{CLOEXEC,NONBLOCK}
in socket and socketpair.
Do _not_ display the O_ACCMODE bits in the arg to fcntl(F_SETFD)

ok miod@


# 1.88 18-Aug-2014 guenther

Add fancy printing of ktrace()'s ops argument
mquery() has the exact same argument layout as mmap(), so share the case
Fix a couple brace placement glitches


# 1.87 17-Aug-2014 guenther

Display symbolicly the mode argument of mkdir, mkfifo, mknod, and umask


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.86 21-Dec-2013 guenther

Recognize itimer and ktrace facility names to {get,set}itimer() and ktrace()

ok otto@


# 1.85 09-Sep-2013 guenther

Rename the 'pid' global to eliminate compiler warnings about shadowing

ok otto@


# 1.84 22-Aug-2013 guenther

Split out from kdump.c the ktrstruct.c bits into ktrstruct.c
Reduce the #includes to take advantage of that.

ok millert@ otto@


Revision tags: OPENBSD_5_4_BASE
# 1.83 03-Jul-2013 guenther

For consistency, move the functions that aren't generated at build-time
from mksubr to kdump.c

ok otto@ millert@


# 1.82 03-Jul-2013 guenther

Use WAIT_* for the first argument to wait4(), and otherwise treat it (and
the first argument to kill) as signed 32bit ints.

ok millert@ otto@


# 1.81 01-Jun-2013 miod

Userland bits for utrace record handling; from otto@


# 1.80 23-Apr-2013 deraadt

simple large ino_t handling


# 1.79 16-Apr-2013 deraadt

handle large time_t variables; ok guenther


# 1.78 15-Apr-2013 guenther

Remove CTL_USER hierarchy from sysctl()
(Use sysconf() or confstr() instead)

ok miod@ millert@


Revision tags: OPENBSD_5_3_BASE
# 1.77 25-Dec-2012 guenther

Report macro names for the second argument to shutdown(), getrusage(),
pathconf(), and fpathconf(), and for poll()'s INFTIM.
When open()'s flag arg doesn't include O_CREAT, don't show the third argument
unless th e-n option is given. Ditto for fcntl()'s F_GETFD and F_GETFL ops.
Show sysctl()'s KERN_PROC_KTHREAD as "kthread".

ok otto@


# 1.76 05-Dec-2012 millert

Explicitly include sys/resource.h for RLIM_INF, etc.


Revision tags: OPENBSD_5_2_BASE
# 1.75 11-Jul-2012 guenther

Report ptrace(PT_{GET,SET}XMMREGS) by name

ok otto@


# 1.74 09-Jul-2012 claudio

Print the fd_set used by select in kdump.
OK guenther@ and deraadt@


# 1.73 29-Jun-2012 guenther

sigpending() returns a sigset just like sigprocmask(), so decode it the same

ok matthew@ otto@


# 1.72 21-Jun-2012 guenther

Add dumping of struct __tfork done by the revised __tfork syscall


# 1.71 20-Jun-2012 guenther

Handle PT_GET_THREAD_*

ok otto@ kettenis@


# 1.70 12-Apr-2012 deraadt

remove rfork(); ok guenther miod


# 1.69 11-Apr-2012 mikeb

guenther and kettenis say THREAD_PID_OFFSET shouldn't be subtracted


# 1.68 11-Apr-2012 jmc

add -H to usage();


# 1.67 10-Apr-2012 mikeb

Add a start record to the ktrace and use a special magic string "KTR"
to identify ktrace files. kdump(1) will now refuse to operate on
trace data without the start record and as a bonus will print only
PID, unless an -H flag is specified to print PID/TID pairs. Initial
diff, input from and ok deraadt, guenther.


# 1.66 31-Mar-2012 deraadt

err(1, NULL) can drive people insane, so please avoid it.
ok guenther


# 1.65 19-Mar-2012 guenther

Add tracing and dumping of "pointer to struct" syscall arguments for
structs timespec, timeval, sigaction, and rlimit.

ok otto@ jsing@


# 1.64 20-Feb-2012 guenther

- add more ptrace() ops
- be robust against a ktrace file the contains a record with
ktr_len==SIZE_MAX, instead of reallocating its buffer to zero size
- format the clockid_t argument to clock_*() and __thrsleep() as CLOCK_*
- format the sigset_t argument to sigprocmask() and __thrsigdivert(), the
return from sigprocmask(), and the mask reported for PSIG records
as a bitset of SIG* values, except that if most the bits are set
then invert it and prefix with '~'
- show the next level of the kern.proc sysctl
- __tfork() creates procs, so do the mappidtoemul() handling
- refactor ktrstat()'s time printing bits and fix a whitespace glitch
in its output
- reduce stack usage in ktrstruct()
- a value of zero is not an error for mode bits (S_*), atflag bits
(AT_*), wait options (W*), or shmat flags (SHM_*)

ok otto@


Revision tags: OPENBSD_5_1_BASE
# 1.63 19-Sep-2011 deraadt

teach kdump about "siginfo-style" signal sub-codes, and the (currently)
limited subset of information the kernel supplies.
ok miod pirofti


Revision tags: OPENBSD_5_0_BASE
# 1.62 28-Jul-2011 otto

Resolve sysctl numbers, original diff from nicm@, man page bits from
guenther@; ok guenther@ millert@


# 1.61 19-Jul-2011 matthew

Add fancy kdump support for the openat(2) system calls.

ok otto@


# 1.60 17-Jul-2011 otto

handle files produced by ktrace -a better by making a distinction
between default and current emulation; ok guenther@


# 1.59 17-Jul-2011 otto

since we're treating native emuls different (more fancy) than
non-native we should do a better job of tracking the emul
corresponding to a pid; ok guenther@; also tested by pirofti@


# 1.58 10-Jul-2011 otto

Make -m 0 work as expected.


# 1.57 09-Jul-2011 otto

print the name of an unknown struct, it has been verified to be sane;
prodded by tedu@


# 1.56 09-Jul-2011 deraadt

remove more atalk bits


# 1.55 08-Jul-2011 otto

Support sending struct info to kdump. So far for struct stat and
struct sockaddress; mostly from freebsd. ok deraadt@ tedu@ nicm@


# 1.54 07-Jul-2011 otto

Don't crash on non-native emuls; ok guenther@


# 1.53 04-Jul-2011 tedu

remove compat_svr4


# 1.52 04-Jul-2011 otto

Big restructuring of the main switch making it much more readable.
Also, handle offset_t (long long) args and padding in a consistent manner.
ok deraadt@


# 1.51 20-Jun-2011 otto

more fancy kdump output, mostly from FreeBSD; ok deraadt@ tedu@


# 1.50 02-Jun-2011 deraadt

Change ktr_retval to a register_t so that we can see the full 64-bits
when neccesary. It is incredible this 64-bit bug has existed for
this long.
ok miod


# 1.49 06-Apr-2011 miod

Avoid using NULL in non-pointer contexts: use 0 for integer values and '\0'
for chars.


# 1.48 05-Apr-2011 guenther

Remove FREEBSD_COMPAT bits and obsolete RTHREAD define


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.47 06-Jul-2010 oga

make kdump build after COMPAT_BSDOS removal.

Bad tedu, no cookie.


# 1.46 02-Jul-2010 tedu

remove userland bits of compat_sunos


# 1.45 01-Jul-2010 tedu

another day, another compat gets removed. today is ibcs2's turn


# 1.44 30-Jun-2010 tedu

remove compat_osf1. ok deraadt miod


# 1.43 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.42 29-Jun-2010 tedu

ultrix support going away, ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.41 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.40 21-Oct-2009 sobrado

sort options; synchronize argument names with synopsis;
split the usage's output in two lines to fit on standard displays.

ok millert@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.39 29-May-2007 deraadt

more parts of netbsd compat that go away


Revision tags: OPENBSD_4_1_BASE
# 1.38 03-Mar-2007 jmc

`l' before `n';


Revision tags: OPENBSD_4_0_BASE
# 1.37 17-May-2006 tedu

use lots more size_t instead of int running around
ok deraadt


# 1.36 11-May-2006 jmc

- add -X and -x to SYNOPSIS
- sort options
- new sentence, new line
- sync usage()


# 1.35 11-May-2006 tedu

cedric points out 0xff mask isn't needed with unsigned chars


# 1.34 11-May-2006 tedu

oops, missed a %ld should be %lu


# 1.33 11-May-2006 tedu

need ctype.h for isprint.
%c expects an int argument, cast a u_long value so it gets it.


# 1.32 11-May-2006 tedu

C spells 'byte' as 'unsigned char'. signed chars are not healthy for isprint


# 1.31 11-May-2006 tedu

-x and -X options to print io output in hex. from cedric berger
ok mickey


Revision tags: OPENBSD_3_9_BASE
# 1.30 31-Dec-2005 miod

Grok rthreads system calls before Dale yiells after me.


# 1.29 20-Dec-2005 miod

No need to define UFS_EXTATTR anymore.


Revision tags: OPENBSD_3_8_BASE
# 1.28 10-Sep-2005 deraadt

for sysctl records, do not expect more than CTL_MAXNAME additional
"faked" arguments; ok uwe espie


# 1.27 02-Jun-2005 mickey

for sysctl syscall pass the mib[] back to kdump to parse;
always print () on syscalls w/ void args even (deraadt version)


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.26 09-Jul-2004 deraadt

#ifdef hpux only for m68k or hppa; this needs a revisit since this shows
something flawed in the way that the emulation system calls are being
handled


# 1.25 09-Jul-2004 mickey

better includes for syscalls from kernel


Revision tags: OPENBSD_3_5_BASE
# 1.24 04-Mar-2004 miod

Better ptrace description, also fix an off-by-one spotted by otto
ok otto@ tdeval@


# 1.23 13-Oct-2003 tedu

realloc stuff. ok deraadt@ jose@


Revision tags: OPENBSD_3_4_BASE
# 1.22 02-Jul-2003 deraadt

ioctlname() proto


# 1.21 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE
# 1.20 19-Feb-2003 deraadt

improve docs; raj@cerias.purdue.edu


# 1.19 17-Oct-2002 mickey

missing defines for syscalls and a better formatting in usage


Revision tags: OPENBSD_3_2_BASE
# 1.18 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.17 23-Jun-2002 deraadt

add -p pid feature, and ansi at the same time; millert ok


# 1.16 12-Jun-2002 mpech

a real pid_t cleanup.

espie@ ok for make/,
deraadt@ one extra eye,
millert@ ok


Revision tags: OPENBSD_3_1_BASE
# 1.15 12-Mar-2002 art

Add PT_IO to ptrace ops.


# 1.14 22-Feb-2002 deraadt

include a siginfo_t with ktrace PSIG information, so that kdump can print
fault addresses and other information. (a small bug exists: in some signal
delivery cases, two PSIG records may be inserted, because postsig() is
unaware a PSIG record has already been placed. but this small bug can
stay since the siginfo_t information helps us find and fix other bugs)


# 1.13 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.12 18-Aug-2001 espie

Add lots of missing prototypes, constify a few things. Add explicit ints.
Makes gcc much happier, less warnings.


# 1.11 12-Jul-2001 deraadt

first pass at a -Wall cleanup


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.10 25-Sep-1999 kstailey

add processing of netbsd syscall emulation


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.9 04-Nov-1997 deraadt

add more emulations; problem noted by khym@bga.com


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.8 28-Feb-1997 millert

Only include sys/errno.h once.


# 1.7 06-Feb-1997 deraadt

make are of a whole number of missing system call names; interesting fix
from ghelmer@freebsd.org


# 1.6 30-Jan-1997 deraadt

fix IOR/IOW/IOWR; cgd@netbsd.org


# 1.5 10-Dec-1996 deraadt

used to permit a single arg, which it ignored, now does usage(); fenner@freebsd


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 27-May-1996 deraadt

native emul is now called "native"


# 1.2 24-May-1996 deraadt

Decode unknown ioctl commands to _IO{R,W,}('c',x[,y]), instead of 0xabcdef00


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision