History log of /openbsd-current/sys/sys/ktrace.h
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.48 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.47 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


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.46 23-Feb-2023 deraadt

include two required header files, because we want people to use utrace()
easier
ok guenther


# 1.45 17-Feb-2023 deraadt

Do not need KTRC_CODE__SYSCALL in the ktrace files anymore, because
__syscall() was removed.


# 1.44 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.43 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@


Revision tags: OPENBSD_7_2_BASE
# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.47 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


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.46 23-Feb-2023 deraadt

include two required header files, because we want people to use utrace()
easier
ok guenther


# 1.45 17-Feb-2023 deraadt

Do not need KTRC_CODE__SYSCALL in the ktrace files anymore, because
__syscall() was removed.


# 1.44 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.43 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@


Revision tags: OPENBSD_7_2_BASE
# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.46 23-Feb-2023 deraadt

include two required header files, because we want people to use utrace()
easier
ok guenther


# 1.45 17-Feb-2023 deraadt

Do not need KTRC_CODE__SYSCALL in the ktrace files anymore, because
__syscall() was removed.


# 1.44 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.43 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@


Revision tags: OPENBSD_7_2_BASE
# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.45 17-Feb-2023 deraadt

Do not need KTRC_CODE__SYSCALL in the ktrace files anymore, because
__syscall() was removed.


# 1.44 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.43 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@


Revision tags: OPENBSD_7_2_BASE
# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.44 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.43 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@


Revision tags: OPENBSD_7_2_BASE
# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


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


Revision tags: OPENBSD_7_2_BASE
# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.42 02-Sep-2022 mbuhl

add the recvmmsg syscall that allows receiving multiple msghdrs at
once. libc, man page, and regress parts to come.
With input from jca@, guenther@, bluhm@.
OK bluhm@


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

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.41 22-Feb-2022 deraadt

Start using new _MAXCOMLEN (a proper string expanded to 24 bytes
including the NUL), in all internal interafaces, and expose this
in ktrace, core, or proc.h visibility.
ok millert


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.40 10-Mar-2021 jsg

spelling

ok gnezdo@ semarie@ mpi@


Revision tags: OPENBSD_6_8_BASE
# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.39 14-Sep-2020 mpi

Fix comment, ktrace flags are per-process.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.38 26-Feb-2019 deraadt

crank to 6.5-beta


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.37 05-Nov-2018 anton

trace struct flock; ok visa@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.36 28-Nov-2017 guenther

fktrace(2) has been removed


Revision tags: OPENBSD_6_2_BASE
# 1.35 13-Aug-2017 tedu

declaration for fktrace


# 1.34 20-Apr-2017 deraadt

only 32 bits of the pledgecode were passed up via ktrace
from Anton Lindqvist
ok semarie


Revision tags: OPENBSD_6_1_BASE
# 1.33 08-Oct-2016 guenther

Add ktracing of the fds returned by pipe() and socketpair()

ok deraadt@


# 1.32 01-Sep-2016 tom

Remove last mention of nonexistent ktr_kuser()

From Michal Mazurek <akfaew at jasminek dot net>

ok guenther@


Revision tags: OPENBSD_6_0_BASE
# 1.31 18-Jun-2016 guenther

KTRPOINT() is only useful in the kernel, so move it behind #ifdef _KERNEL

ok mpi@ kettenis@


# 1.30 07-Jun-2016 deraadt

ktrace support for pollfd[] arrays
ok guenther


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


Revision tags: OPENBSD_5_9_BASE
# 1.28 17-Dec-2015 tedu

add ktrace to kevent. ok guenther


# 1.27 06-Dec-2015 deraadt

Change kernel internal pledge variables to 64bit (to prepare for more
extensions). This change is exposed in ktrace.out files
ok semarie


# 1.26 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.25 02-Oct-2015 guenther

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

ok tedu@ deraadt@


# 1.24 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.23 28-Jul-2015 guenther

Add ktracing of structs iovec, msghdr, and cmsghdr for {,p}{read,write}v(),
sendmsg(), and recvmsg(). For cmsghdr, the len, level, and type are always
shown, and for SOL_SOCKET,SCM_RIGHTS the fd numbers being passed are shown.

ok millert@ deraadt@


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


Revision tags: OPENBSD_5_7_BASE
# 1.21 13-Oct-2014 guenther

Add dumping of struct dqblk done by quotactl(2)

ok millert@


Revision tags: OPENBSD_5_6_BASE
# 1.20 08-Jul-2014 deraadt

sys/user.h can now be substantially gutted.
ok guenther


# 1.19 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


Revision tags: OPENBSD_5_5_BASE
# 1.18 24-Jan-2014 guenther

exit1() needs to do a final aggregation of the thread's [us]ticks
and runtime to the process totals. Also, add ktracing of struct
rusage in wait4() and getrusage().

problem pointed out by tedu@
ok deraadt@


# 1.17 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


Revision tags: OPENBSD_5_4_BASE
# 1.16 01-Jun-2013 miod

Add utrace(2), a system call allowing for userland to send its own ktrace
records. From FreeBSD via otto@, with tweaks suggested by guenther@.
Commite on behalf of otto@ who is not around, to ride the libc minor bump.
Causes a librthread minor bump as well (new syscall).


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.15 09-Jul-2012 claudio

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


# 1.14 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.13 19-Mar-2012 guenther

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

ok otto@ jsing@


Revision tags: OPENBSD_5_1_BASE
# 1.12 14-Dec-2011 guenther

Handle rthreads consistently in ktrace by moving the flags and vnode into
struct process; KTRFAC_ACTIVE becomes P_INKTR. Also, save the credentials
used to open the file in sys_ktrace() and use them for all writes to the
vnode.

much feedback and ok jsing@


Revision tags: OPENBSD_5_0_BASE
# 1.11 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.10 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


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.9 17-May-2006 tedu

change ktr_len to size_t. put ktr_type after comm for better alignment
ok deraadt


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B
# 1.8 02-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_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 14-Mar-2002 millert

First round of __P removal in sys


# 1.6 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)


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.5 04-Jul-2001 espie

branches: 1.5.4;
ktrace.h looks better with an EOL at EOF...


Revision tags: OPENBSD_2_9_BASE
# 1.4 10-Nov-2000 art

Change the ktrace interface functions from taking the trace vnode to taking the
traced proc. The vnode is in the proc and all functions need the proc.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.3 20-Apr-2000 art

Add a function "ktrsettracevnode", that changes the ktrace vnode for a process
in a correct way. Use it in all places where the vnode was changed.
(most of the earlier code was incorrect and had races).


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.2 03-Mar-1996 niklas

branches: 1.2.16;
From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision