Home | History | Annotate | only in /src/tests/lib/libc/sys
History log of /src/tests/lib/libc/sys
RevisionDateAuthorComments
 1.80 10-Oct-2025  christos Commit GSoC 2025 aio project by Ethan Miller:
https://blog.netbsd.org/tnf/entry/gsoc2025_asynchronous_i_o_framework
 1.79 09-May-2025  riastradh tests/lib/libc/sys/Makefile: Fix truncate_test.root_owned output.

Announce the creation of this file with ${_MKTARGET_CREATE}, not with
cryptic dd(1) output. And just use touch(1) instead of dd from
/dev/null, simpler and clearer what's going on.

No functional change intended, other than to the cosmetics of build
output.
 1.78 09-Feb-2025  riastradh t_poll: Expand tests of polling when other endpoint is closed.

This covers fifos, pipes, and sockets; reads and writes; and polling
when the endpoint is already closed as well as sleeping until the
endpoint is closed after a delay.

Unfortunately, there is disagreement right now between:

(a) POSIX,
(b) our poll(2) man page, and
(c) our implementation,

for many of these cases. And we recently changed the behaviour of
poll(2) on fifos between 9 and 10 (PR kern/56429: poll(2) should
yield POLLHUP when last writer to a fifo close()'s it) but didn't get
it quite right.

So I've annotated these test cases with xfails for all the cases I
think we're currently doing wrong -- under a justification from some
combination of POSIX, our own documentation, and/or a reasonable
interpretation of what the semantics _should_ be based on how read(2)
and write(2) will behave. These are mostly edge cases:

1. [pollclosed_pipe_*_write*] When the read side of a pipe is closed,
poll(2) on the write side currently returns POLLHUP|POLLOUT, which
POSIX forbids because it requires POLLHUP to be mutually exclusive
with POLLOUT. And our man page concurs with POSIX on this rule,
and has for a long time (going as far back as NetBSD 1.3 or
earlier, judging by https://man.NetBSD.org/NetBSD-1.3/poll.2).

=> Fixing this won't change whether anything wakes up earlier or
later -- it will only change which bits are set when the
wakeups happen.

2. [pollclosed_fifo*_immediate_readsome] When the write side of a
fifo was previously open with the read side, and has since been
closed before calling poll(2), poll(2) on the read side returns 0
instead of POLLHUP|POLLIN as it is expected to, even though
read(2) will return EOF without blocking.

=> Fixing this may lead to more wakeups than before, but only in
cases where read(2) would actually return immediately anyway.

3. [pollclosed_fifo*_delayed_*_read] When the write side of a fifo is
closed, poll(2) on the read side returns POLLHUP|POLLIN, as it is
expected to. But this state currently isn't persistent, even
though the behaviour of read(2) in returning EOF without blocking
is persistent.

=> Fixing this may lead to more wakeups than before, but only in
cases where read(2) would actually return immediately anyway.

That said, it turns out that we are correct, according to POSIX, in
not setting POLLHUP on a socket whose peer has been closed: POLLHUP
is only for devices, pipes, and FIFOs. So one of the issues I
reported in PR 59056 turns out to be bogus. (Also POLLHUP is only
for the reader side anyway, not for the writer side.)

https://pubs.opengroup.org/onlinepubs/9799919799/functions/poll.html

PR kern/59056: poll POLLHUP bugs
 1.77 17-Dec-2024  christos PR/58896: Martin Husemann: Demonstrate that a PT_STOPed process could not be
PT_KILLed.
 1.76 07-Dec-2023  riastradh branches: 1.76.2;
t_setrlimit: Narrow the scope of stack-protector warning suppression.
 1.75 24-Nov-2023  christos t_setrlimit uses alloca now
 1.74 08-Aug-2023  mrg introduce new GCC 12 warning disables and use them in a few places

this introduces 4 new warning disable flags:

CC_WNO_MISSING_TEMPLATE_KEYWORD
CC_WNO_REGISTER
CC_WNO_STRINGOP_OVERREAD
CC_WNO_ARRAY_BOUNDS

and documents them in README.warnings. of these, the string op
and array bounds are both problematic (real bugs) and also spurious
(not real bugs), and the other 2 are mostly temporary for older
3rd party code.

add some new uses of CC_WNO_STRINGOP_OVERFLOW.

fix m68k build for gallium and GCC 12.
 1.73 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.72 01-Aug-2022  kre branches: 1.72.2;

Provide _GNU_SOURCE for t_clone now that is required to make clone()
visible.
 1.71 06-Apr-2022  gson Add a regression test for PR kern/52239, "Changing protections of
already mmap'ed region can fail", based on the test program in the PR.
 1.70 01-Nov-2021  hannken Test lib/libc/sys/t_timerfd often fails when run on QEMU because
QEMU misses clock interrupts.

Always check values against [ lower, upper ] bounds and use "4 * upper"
when run under QEMU.

Now becomes part of PR kern/43997 "Kernel timer discrepancies".
 1.69 19-Sep-2021  thorpej Add native implementations of eventfd(2) and timerfd(2), compatible with
the Linux interfaces of the same name.
 1.68 06-Sep-2020  mrg branches: 1.68.2;
add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.67 14-Aug-2020  riastradh New system call getrandom() compatible with Linux and others.

Three ways to call:

getrandom(p, n, 0) Blocks at boot until full entropy.
Returns up to n bytes at p; guarantees
up to 256 bytes even if interrupted
after blocking. getrandom(0,0,0)
serves as an entropy barrier: return
only after system has full entropy.

getrandom(p, n, GRND_INSECURE) Never blocks. Guarantees up to 256
bytes even if interrupted. Equivalent
to /dev/urandom. Safe only after
successful getrandom(...,0),
getrandom(...,GRND_RANDOM), or read
from /dev/random.

getrandom(p, n, GRND_RANDOM) May block at any time. Returns up to n
bytes at p, but no guarantees about how
many -- may return as short as 1 byte.
Equivalent to /dev/random. Legacy.
Provided only for source compatibility
with Linux.

Can also use flags|GRND_NONBLOCK to fail with EWOULDBLOCK/EAGAIN
without producing any output instead of blocking.

- The combination GRND_INSECURE|GRND_NONBLOCK is the same as
GRND_INSECURE, since GRND_INSECURE never blocks anyway.

- The combinations GRND_INSECURE|GRND_RANDOM and
GRND_INSECURE|GRND_RANDOM|GRND_NONBLOCK are nonsensical and fail
with EINVAL.

As proposed on tech-userlevel, tech-crypto, tech-security, and
tech-kern, and subsequently adopted by core (minus the getentropy part
of the proposal, because other operating systems and participants in
the discussion couldn't come to an agreement about getentropy and
blocking semantics):

https://mail-index.netbsd.org/tech-userlevel/2020/05/02/msg012333.html
 1.66 17-Jul-2020  kamil Add ppoll() a compatibility wrapper around pollts(2)

Submitted by Apurva Nandan.
 1.65 17-Jun-2020  rin Fix build for vax; Compile t_ptrace_sigchld.c with -D__TEST_FENV.
 1.64 30-Apr-2020  ryo Add a test for sigaltstack(2) and SA_ONSTACK
 1.63 26-Apr-2020  thorpej Add a NetBSD native futex implementation, mostly written by riastradh@.
Map the COMPAT_LINUX futex calls to the native ones.
 1.62 18-Apr-2020  christos PR/55177: Carlo Arenas: mremap(MAP_REMAPDUP) fails after fork()
 1.61 06-Mar-2020  kamil Add new ptrace(2) test file

t_ptrace_sigchld - for SIGCHLD handler + ptrace(2).

Right now a single test is enabled (raise(SIGKILL)) and marked as failed
as it never finishes as the child is never collected before exiting the
parent uninterested about its child (SA_NOCLDWAIT).
 1.60 01-Mar-2020  christos fix variable name
 1.59 01-Mar-2020  christos Centralize the base rump libraries into a variable used by all the other
Makefiles so that we can make changes to it centrally as needed and have
less mess. Fixes the sun2 build that needs rumpvfs after librump after
the latest changes.
 1.58 22-Feb-2020  kamil Disable t_ptrace_wait* tests for MKSANITIZER/MKLIBCSANITIZER

A subset of tests is not compatible with the sanitizers.
 1.57 30-Jun-2019  mgorny branches: 1.57.2;
Add a test for verifying procinfo note inside coredumps.

Add a first test for triggering a core dump in the debugged process
(via PT_DUMPCORE) and verifying it. The test finds procinfo note
and checks its contents.

The core dump is processed through libelf. However, it only provides
for finding all note segments (or sections?). I had to implement
finding and processing individual notes myself. I've added
a core_find_note() function that will be reused in future tests.

Reviewed by kamil.
 1.56 26-Apr-2019  maya Use LDADD, which apparently puts the libraries at the end of the command,
and makes static builds (aka sun2) happier.
 1.55 25-Apr-2019  kamil Introduce check for the support of FPU exceptions

If FPU exceptions are unsupported, skip the SIGFPE crash tests.

Reuse code from tests/kernel/h_segv.c
 1.54 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.53 21-Aug-2018  christos more tests
 1.52 25-May-2018  martin branches: 1.52.2;
Add a test to verify syscall() and/or __syscall() are working.
This used to trigger a panic (see PR kern/53261) on arm.
 1.51 18-May-2018  kamil Add new ATF tests: t_fork and t_vfork

Test behavior of raise(signal) in either fork(2)ed or vfork(2)ed child.

Tests:
- raise1 SIGKILL
- raise2 SIGSTOP
- raise3 SIGTSTP
- raise4 SIGTTIN
- raise5 SIGTTOU
- raise6 SIGABRT
- raise7 SIGHUP
- raise8 SIGCONT

t_vfork:raise2 fails ignoring non-maskable SIGSTOP.

The remaining ones pass.

Sponsored by <The NetBSD Foundation>
 1.50 25-Feb-2018  kamil branches: 1.50.2;
Add new tests in lib/libc/sys/t_ucontext

New tests:
- ucontext_sp
- ucontext_fp
- ucontext_pc
- ucontext_intrv

They test respectively:
- _UC_MACHINE_SP
- _UC_MACHINE_FP
- _UC_MACHINE_PC
- _UC_MACHINE_INTRV

These tests attempt to access and print the values from ucontext, without
interpreting the values.

This is a follow up of the _UC_MACHINE_FP() introduction.

These tests use PRIxREGISTER, and require to be built with -D_KERNTYPES.

Sponsored by <The NetBSD Foundation>
 1.49 02-Apr-2017  kamil branches: 1.49.4;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.48 01-Feb-2017  martin Restrict special mode/owner settings to truncate_test.root_owned;
otherwise the Atffile will be generated unreadable for group/others
as well.
 1.47 14-Jan-2017  pgoyette branches: 1.47.2;
Set FILESBUILD=yes to actually run the creation script for the file.

Should fix the build by creating a file which install can then find.
 1.46 13-Jan-2017  christos PR/51844: Ngie Cooper: use root-owned file created during build instead of
/usr/bin/fpr
 1.45 11-Nov-2016  njoly New clock_nanosleep(2) testcase.
 1.44 06-Nov-2016  kamil Add new tests: tests/lib/libc/sys/t_wait_noproc and t_wait_noproc_wnohang

The t_wait_noproc test checks whether wait(2)-family of functions return
error and set ECHILD for lack of childs.

The t_wait_noproc_wnohang adds to options (except wait(2), wait3(2)) new
parameter WNOHANG and verifies that error is still signaled and errno set
to ECHILD.

Currently t_wait_noproc_wnohang reports failures, these have been marked as
expected and referenced to PR standards/51606.

The problem report is authored by Robert Elz, and the initial regression
has been notified by Nicolas Joly.

Remove redundant test in tests/lib/libc/sys/t_wait for wait6(2) with no
WNOHANG specified.

Sponsored by <The NetBSD Foundation>.
 1.43 30-Jul-2016  njoly New getsockname(2) testcase for UNIX domain sockets.
 1.42 06-Apr-2016  christos branches: 1.42.2;
Add wait6(2) tests.
 1.41 24-Jan-2016  christos t_lwp_create needs kernel types.
 1.40 23-Jan-2016  christos Define _KERNTYPES for things that need it.
 1.39 22-Jun-2015  matt Don't build tests that depend on RUMP if BSD_MK_COMPAT_FILE is defined.
 1.38 05-Apr-2015  martin New test program for bind(2), with a single (currently eroneously failing)
test case from Tyler Retzlaff.
 1.37 31-Jan-2015  christos PR/49617: Kirk Russell: posix_fallocate() should be returning an error on
failure, without setting errno.
 1.36 18-Jul-2014  christos Add new minherit test.
 1.35 10-Jun-2014  he Fix static linking for the tests: -lrump is also used by -lrumpuser,
so we also need -lrump after -lrumpuser. Fixes build for sun2.
 1.34 24-Jul-2013  skrll branches: 1.34.2;
There wasn't a codegen bug - the test program itself was buggy.

Nothing to see hear... move along.
 1.33 23-Jul-2013  skrll Compile tests/lib/libc/sys/t_msgrcv with -O0 on hppa to avoid compiler
bug.
 1.32 08-Mar-2013  martin branches: 1.32.4;
Rename testprogram and make it more general by adding other testcases.
One commented out, I didn't manage to get all signal handling correct
for now.
 1.31 08-Mar-2013  martin Add a test program for PR kern/47625, based on the sample code provided
by anthony mallet.
 1.30 04-Dec-2012  jruoho Move the bitmap(3) test to the "right" place. Note it in bitops(3). Xrefs.
 1.29 01-Dec-2012  christos Add a bitops test
 1.28 12-Sep-2012  manu branches: 1.28.2;
setcontext() used to be incompatible with -lpthread since it affected
the TLS pointer, therefore wrecking the pthread environement.

Some ports had _UC_TLSBASE flag or equivalent (_UC_UNIQUE on alpha)
that controlled whether setcontext() would change the TLS pointer.
This change let libpthread override setcontext() with its own version
that unsets _UC_TLSBASE, enabling safe usage of setcontext() with
-lpthread.

We also have the following required changes here:
- rename alpha's _UC_UNIQUE into _UC_TLSBASE
- add _UC_TLSBASE definition in header file for all ports
(powerpc, sh3, sparc and sparc64 lack the implementation for now)
- introduce a libc stub that can be overriden for setcontext()
- modify MD libcs swapcontext() implementations so that they use the
setcontext() libc stub instead of doing a plain system call.

While we are there:
- document various MD _UC_* flags in header file
- add libc and libpthread tests for swapcontext() behavior
(hopefully helpful to spot MD problems introduced with this change)

Future work:
- Deciding whether kernel support or _UC_TLSBASE should be added for
powerpc, sh3, sparc and sparc64 is left to portmasters
sparc64

Approved by core@
 1.27 08-Aug-2012  christos Exclude tests that use rump
 1.26 22-Jun-2012  christos tests for recvmmsg
 1.25 07-Jun-2012  martin Revert previous - instead of guessing the amount of needed memory locked
limits (often way too high) and skipping the test case if in doubt,
raise the limits as far as we can, and fix a few places in the test where
we could run into the limits and either skip or fail with a reasonable
message.
 1.24 05-Jun-2012  martin Try to estimate the number of locked pages the mincore() test will need and
check it against resource limits, skipping the tests if it probably is too
low.
 1.23 21-May-2012  martin Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.22 20-Apr-2012  jruoho Add few unit tests for mlock(2), including a case for PR kern/44788.
 1.21 17-Mar-2012  jruoho Move the _lwp_ctl(2) preemption counter check to the right place.
 1.20 17-Nov-2011  christos branches: 1.20.2;
Add a test for PR/45618: Motoyuki OHMORI: kqueue EVFILT_TIMER with smaller
timeout value makes kernel busy or panic
 1.19 05-Nov-2011  jruoho Move connect(2), listen(2) and socketpair(2) tests to the right place.
 1.18 05-Nov-2011  jruoho Add 21 unit tests for the XSI message queues.
 1.17 31-Oct-2011  christos branches: 1.17.2;
Move all pipe2 tests to a separate file.
 1.16 15-Oct-2011  jruoho Move the sigaction(2) test to the right place.
 1.15 15-Oct-2011  jruoho Move the ucontext(2) test to the right place.
 1.14 15-Oct-2011  jruoho Move the writev(2) test to the right place.
 1.13 15-Oct-2011  jruoho Move the clock_gettime(2) timer test to the right place.
 1.12 15-Oct-2011  jruoho Move the mkdir(2) test to the right place.
 1.11 15-Oct-2011  jruoho Move the pipe(2) test to the right place.
 1.10 15-Oct-2011  jruoho Move the posix_fadvise(2) test to the right place.
 1.9 17-Sep-2011  jruoho Remove ptrace(2) tests that are not yet ready but were accidentally
committed.
 1.8 17-Sep-2011  jruoho Simplify.
 1.7 18-Jul-2011  jym Add a simple test case to check executable mapping rights for mprotect(2).

- provide an exec_prot_support() routine so $ARCH can indicate whether
it supports execution protection or not, and skip test accordingly.

- have a trivial 'return_one' shellcode to copy anywhere in a page, and
call it. The decision to keep the assembly solution is mine, reasons are
twofold:

- all pure-C implementations cannot be controlled easily:
bounds detection (beginning/end) of return_one is unpredictable,
or requires the use of overkill solutions like libelf. Using
dlsym(3) was a good proposal, however I can't use it to know the
end address of the payload. It makes copying of the shellcode a bit
more difficult: using a constant may be too small (code has not been
entirely copied, and can lead to errors that can be erroneously
detected as "test passed"), or too big (depending on where it is mapped
in memory, copying past the end of the function may trigger SIGSEGV).

- I have to ensure that the resulting assembly is the most compact
possible, especially as it will be reused to test other parts of
memory (stack, data, rodata, etc.).

Only i386 and amd64 are implemented so far. Others will come in due time.
FWIW, writing the exec_prot_support() callback and the return_one payload
should be enough. Writing callback requires good knowledge of the platform,
depending on chip revision, CPU, board, MMU... the protection level may vary.

Current files are put under lib/libc/arch/* and lib/libc/common/. Feel free to
move them around the tests/ tree. Keep in mind that the common/ and arch/ code
will be used outside of libc, so please do not hide them too deep in the tree.

I checked a few architectures via build.sh cross-compile, and will keep an
eye on buildbot for potential build breakage. Feel free to contact me in
case you see any, of course.
 1.6 07-Jul-2011  jruoho Fix previous.
 1.5 07-Jul-2011  jruoho Remove 't_cerror' (this is tested by numerous individual tests).
Rename 't_context' to 't_getcontext' for consistency.
 1.4 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.3 13-Jan-2011  pgoyette Make sure we build all of thests, not just the last one (use += vs =)
 1.2 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.1 10-Jan-2011  christos test for sigqueue
 1.17.2.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.2.4 30-Oct-2012  yamt sync with head
 1.17.2.3 23-May-2012  yamt sync with head.
 1.17.2.2 17-Apr-2012  yamt sync with head
 1.17.2.1 10-Nov-2011  yamt sync with head
 1.20.2.1 21-May-2012  riz Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.28.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.2.1 23-Jun-2013  tls resync from head
 1.32.4.1 23-Jul-2013  riastradh sync with HEAD
 1.34.2.1 10-Aug-2014  tls Rebase.
 1.42.2.4 26-Apr-2017  pgoyette Sync with HEAD
 1.42.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.42.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.42.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.47.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.49.4.4 09-Dec-2023  martin Additionally pull up following revision(s) (requested by riastradh in ticket #1920):

tests/lib/libc/sys/Makefile: revision 1.75 (via patch)

t_setrlimit uses alloca now
 1.49.4.3 21-Mar-2018  martin Pull up the following, requested by kamil in ticket #552:

external/gpl3/gcc{.old}/dist/libsanitizer/asan/asan_linux.cc 1.4
sys/arch/aarch64/include/mcontext.h 1.2
sys/arch/alpha/include/mcontext.h 1.9
sys/arch/amd64/include/mcontext.h 1.19
sys/arch/arm/include/mcontext.h 1.19
sys/arch/hppa/include/mcontext.h 1.9
sys/arch/i386/include/mcontext.h 1.14
sys/arch/ia64/include/mcontext.h 1.6
sys/arch/m68k/include/mcontext.h 1.10
sys/arch/mips/include/mcontext.h 1.22
sys/arch/or1k/include/mcontext.h 1.2
sys/arch/powerpc/include/mcontext.h 1.18
sys/arch/riscv/include/mcontext.h 1.5
sys/arch/sh3/include/mcontext.h 1.11
sys/arch/sparc/include/mcontext.h 1.14-1.17
sys/arch/sparc64/include/mcontext.h 1.10
sys/arch/vax/include/mcontext.h 1.9
tests/lib/libc/sys/Makefile 1.50
tests/lib/libc/sys/t_ucontext.c 1.2-1.5
sys/arch/hppa/include/mcontext.h 1.10
sys/arch/ia64/include/mcontext.h 1.7

- Introduce _UC_MACHINE_FP(). _UC_MACHINE_FP() is a helper
macro to extract from mcontext a frame pointer.
- Add new tests in lib/libc/sys/t_ucontext:
* ucontext_sp (testing _UC_MACHINE_SP)
* ucontext_fp (testing _UC_MACHINE_FP)
* ucontext_pc (testing _UC_MACHINE_PC)
* ucontext_intrv (testing _UC_MACHINE_INTRV)

Add a dummy implementation of _UC_MACHINE_INTRV() for ia64.

Implement _UC_MACHINE_INTRV() for hppa.

Make the t_ucontext.c test more portable.

We now have _UC_MACHINE_FP.
 1.49.4.2 26-Feb-2018  snj revert ticket 552, which broke the build
 1.49.4.1 25-Feb-2018  snj Pull up following revision(s) (requested by kamil in ticket #552):
sys/arch/aarch64/include/mcontext.h: 1.2
sys/arch/alpha/include/mcontext.h: 1.9
sys/arch/amd64/include/mcontext.h: 1.19
sys/arch/arm/include/mcontext.h: 1.19
sys/arch/hppa/include/mcontext.h: 1.9
sys/arch/i386/include/mcontext.h: 1.14
sys/arch/ia64/include/mcontext.h: 1.6
sys/arch/m68k/include/mcontext.h: 1.10
sys/arch/mips/include/mcontext.h: 1.22
sys/arch/or1k/include/mcontext.h: 1.2
sys/arch/powerpc/include/mcontext.h: 1.18
sys/arch/riscv/include/mcontext.h: 1.5
sys/arch/sh3/include/mcontext.h: 1.11
sys/arch/sparc/include/mcontext.h: 1.14-1.17
sys/arch/sparc64/include/mcontext.h: 1.10
sys/arch/vax/include/mcontext.h: 1.9
tests/lib/libc/sys/Makefile: 1.50
tests/lib/libc/sys/t_ucontext.c: 1.2
Introduce _UC_MACHINE_FP() as a macro
_UC_MACHINE_FP() is a helper macro to extract from mcontext a frame pointer.
Don't rely on this interface as a compiler might strip frame pointer or
optimize it making this interface unreliable.
For hppa assume a small frame context, for larger frames FP might be located
in a different register (4 instead of 3).
For ia64 there is no strict frame pointer, and registers might rotate.
Reuse 79 following:
./gcc/config/ia64/ia64.h:#define HARD_FRAME_POINTER_REGNUM LOC_REG (79)
Once ia64 will mature, this should be revisited.
A macro can encapsulate a real function for extracting Frame Pointer on
more complex CPUs / ABIs.
For the remaining CPUs, reuse standard register as defined in appropriate ABI.
The direct users of this macro are LLVM and GCC with Sanitizers.
Proposed on tech-userlevel@.
Sponsored by <The NetBSD Foundation>
--
Improve _UC_MACHINE_FP() for SPARC/SPARC64
Introduce a static inline function _uc_machine_fp() that contains improved
caluclation of a frame pointer.
Algorithm:
uptr *stk_ptr;
# if defined (__arch64__)
stk_ptr = (uptr *) (*sp + 2047);
# else
stk_ptr = (uptr *) *sp;
# endif
*bp = stk_ptr[15];
Noted by <mrg>
--
Make _UC_MACHINE_FP() compile again and fix it so that it does not add
the offset twice.
--
fix _UC_MACHINE32_FP() -- use 32 bit pointer value so that [15] is
the right offset. do this by using __greg32_t, which is only in
the sparc64 version, and these are only useful there, so move them.
--
Add new tests in lib/libc/sys/t_ucontext
New tests:
- ucontext_sp
- ucontext_fp
- ucontext_pc
- ucontext_intrv
They test respectively:
- _UC_MACHINE_SP
- _UC_MACHINE_FP
- _UC_MACHINE_PC
- _UC_MACHINE_INTRV
These tests attempt to access and print the values from ucontext, without
interpreting the values.
This is a follow up of the _UC_MACHINE_FP() introduction.
These tests use PRIxREGISTER, and require to be built with -D_KERNTYPES.
Sponsored by <The NetBSD Foundation>
 1.50.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.50.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.50.2.1 21-May-2018  pgoyette Sync with HEAD
 1.52.2.3 21-Apr-2020  martin Sync with HEAD
 1.52.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.52.2.1 10-Jun-2019  christos Sync with HEAD
 1.57.2.1 09-Dec-2023  martin Additionally pull up following revision(s) (requested by riastradh in ticket #1769):

tests/lib/libc/sys/Makefile: revision 1.75 (via patch)

t_setrlimit uses alloca now
 1.68.2.2 14-Dec-2020  thorpej Unit tests for timerfd.
 1.68.2.1 14-Dec-2020  thorpej Unit tests for eventfd(2).
 1.72.2.1 09-Dec-2023  martin Additionally pull up following revision(s) (requested by riastradh in ticket #477):

tests/lib/libc/sys/Makefile: revision 1.75 (via patch)

t_setrlimit uses alloca now
 1.76.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 06-Mar-2020  kamil Move macros wrapping functions from msg.h into msg.h

This makes code reusing easier.
 1.2 13-Mar-2018  kamil branches: 1.2.2;
ATF t_ptrace_wait*: Disable debug messages in msg.h

msg.h is a dummy IPC interface.

Disable additional debugging logging here, especially wanted in race*
tests.

Sponsored by <The NetBSD Foundation>
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.8; 1.1.14;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.14.1 15-Mar-2018  pgoyette Synch with HEAD
 1.1.8.1 12-Apr-2018  martin Pull up following revision(s) (requested by kamil in ticket #711):
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.24-1.31
tests/lib/libc/sys/t_ptrace_wait.h: revision 1.2
tests/lib/libc/sys/t_ptrace_x86_wait.h: revision 1.4,1.5
tests/lib/libc/sys/msg.h: revision 1.2

Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)

This code after refactoring stopped calling functions that were designed
to trigger expected behavior and thus, tests were breaking.
Sponsored by <The NetBSD Foundation>

ATF: Correct a race bug in attach2 (t_ptrace_wait*)
At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.

Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.

This test is still racy for some other and unknown reason and this is bei=
ng
investigated.

Sponsored by <The NetBSD Foundation>

ATF: Reenable attach2 in t_ptrace_wait*

The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).

This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.
The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2=
)/
read(2) or close to these features.

Sponsored by <The NetBSD Foundation>

Add a new function in ATF t_ptrace_wait*: await_zombie_raw()

Add await_zombie_raw() that is the same as await_zombie(), whith an
addition of additional "useconds_t ms" parameter indicating delays betwee=
n
new polling for a zombie process.

This new function will be used for testing a race condition that has been=
observed occassionally crashing a test case -- returning duplicate entrie=
s
for KERN_PROC_PID.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait*: Disable debug messages in msg.h
msg.h is a dummy IPC interface.

Disable additional debugging logging here, especially wanted in race*
tests.

Sponsored by <The NetBSD Foundation>

ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported
race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7=
).
A buggy kernel was asserting an error within this timeframe almost always=
=2E
The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>

Add check in ATF tests for security.models.extensions.user_set_dbregs
Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.

It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.
In case of not being able to do so, print a message and mark a test
as skipped:
Either run this test as root or set sysctl(3)
security.models.extensions.user_set_dbregs to 1
No functional change intended to the code flow of the existing tested
scenarios.

Sponsored by <The NetBSD Foundation>

Improve documentation of the ATF test t_ptrace_wait*: traceme2
Set the description to:
Verify that a signal emitted by a tracer to a child is caught by
a signal handler.

Sponsored by <The NetBSD Foundation>

Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

Marge bodies of two tests into the same function.

Add few checks for regular fork or not (vfork).

Sponsored by <The NetBSD Foundation>

ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones
Reduce code duplication, use the same function body with conditional
switches.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().

There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.
PR kern/51630

Sponsored by <The NetBSD Foundation>

Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.=
Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file msg.h was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file msg.h was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.2.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 16-Jul-2019  martin PR misc/54382: whenever open(2) is called with O_CREAT, make sure to
pass an open mode argument.
 1.2 10-Jan-2017  christos branches: 1.2.14;
more tests needing <sys/stat.h>
 1.1 07-Jul-2011  jruoho branches: 1.1.24;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 10-Oct-2025  christos Commit GSoC 2025 aio project by Ethan Miller:
https://blog.netbsd.org/tnf/entry/gsoc2025_asynchronous_i_o_framework
 1.1 10-Oct-2025  christos Commit GSoC 2025 aio project by Ethan Miller:
https://blog.netbsd.org/tnf/entry/gsoc2025_asynchronous_i_o_framework
 1.1 10-Oct-2025  christos Commit GSoC 2025 aio project by Ethan Miller:
https://blog.netbsd.org/tnf/entry/gsoc2025_asynchronous_i_o_framework
 1.1 10-Oct-2025  christos Commit GSoC 2025 aio project by Ethan Miller:
https://blog.netbsd.org/tnf/entry/gsoc2025_asynchronous_i_o_framework
 1.3 05-Apr-2015  rtr fix typo bindinging -> binding
 1.2 05-Apr-2015  rtr - ATF_REQUIRE(EINVAL == errno);
+ ATF_REQUIRE(EAFNOSUPPORT == errno);

as per http://pubs.opengroup.org/onlinepubs/009695399/functions/bind.html

while here remove some unnecessary initialization of port and addr members
and replace with a comment explaining why.
 1.1 05-Apr-2015  martin New test program for bind(2), with a single (currently eroneously failing)
test case from Tyler Retzlaff.
 1.2 04-Dec-2012  jruoho Move the bitmap(3) test to the "right" place. Note it in bitops(3). Xrefs.
 1.1 01-Dec-2012  christos Add a bitops test
 1.2 07-Jul-2011  jruoho Remove 't_cerror' (this is tested by numerous individual tests).
Rename 't_context' to 't_getcontext' for consistency.
 1.1 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.2 10-Jan-2017  christos more tests needing <sys/stat.h>
 1.1 07-Jul-2011  jruoho branches: 1.1.24;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10 25-Mar-2025  riastradh t_clock_gettime: Break overlong lines.

No functional change intended.
 1.9 20-Mar-2025  pho t_clock_gettime.c: Fix my typo
 1.8 19-Mar-2025  kre tv_nsec prints with %ld not %jd (should fix build)
 1.7 19-Mar-2025  pho clock_getres(2): Support CLOCK_{PROCESS,THREAD}_CPUTIME_ID

The syscall previously returned EINVAL for these two clocks. It still has
no support for CLOCK_VIRTUAL and CLOCK_PROF but clock_gettime(2) doesn't
either.

Fixes PR kern/59127
 1.6 09-Jul-2023  riastradh branches: 1.6.2;
t_clock_gettime: Avoid signed/unsigned comparison.
 1.5 08-Jul-2023  riastradh clock_gettime(2): Fix CLOCK_PROCESS/THREAD_CPUTIME_ID.

Use same calculation as getrusage, not some ad-hoc arithmetic of
internal scheduler parameters that are periodically rewound.

PR kern/57512

XXX pullup-8
XXX pullup-9
XXX pullup-10
 1.4 08-Jul-2023  riastradh t_clock_gettime: Add test for PR kern/57512.
 1.3 13-Jan-2017  christos branches: 1.3.16; 1.3.28;
Don't play with "../.." in includes for h_macros.h; deal with it centrally.
Minor fixes.
 1.2 13-Jan-2017  christos PR/51849: Ngie Cooper: headers portability fixes
 1.1 15-Oct-2011  jruoho branches: 1.1.24;
Move the clock_gettime(2) timer test to the right place.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.28.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #943):
sys/sys/resourcevar.h: revision 1.58
sys/kern/subr_time.c: revision 1.36
sys/kern/subr_time.c: revision 1.37
sys/kern/subr_time.c: revision 1.38
sys/kern/kern_resource.c: revision 1.190
sys/kern/kern_resource.c: revision 1.191
tests/lib/libc/sys/t_clock_gettime.c: revision 1.4
tests/lib/libc/sys/t_clock_gettime.c: revision 1.5
tests/lib/libc/sys/t_clock_gettime.c: revision 1.6
kern: KASSERT(A && B) -> KASSERT(A); KASSERT(B)
White space fix.
kern_resource.c: Fix brace placement.
No functional change intended.
t_clock_gettime: Add test for PR kern/57512.
clock_gettime(2): Fix CLOCK_PROCESS/THREAD_CPUTIME_ID.
Use same calculation as getrusage, not some ad-hoc arithmetic of
internal scheduler parameters that are periodically rewound.
PR kern/57512
XXX pullup-8
XXX pullup-9
XXX pullup-10
t_clock_gettime: Avoid signed/unsigned comparison.
 1.3.16.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1896):

sys/sys/resourcevar.h: revision 1.58
sys/kern/subr_time.c: revision 1.36
sys/kern/subr_time.c: revision 1.37
sys/kern/subr_time.c: revision 1.38
sys/kern/kern_resource.c: revision 1.190
sys/kern/kern_resource.c: revision 1.191
tests/lib/libc/sys/t_clock_gettime.c: revision 1.4
tests/lib/libc/sys/t_clock_gettime.c: revision 1.5
tests/lib/libc/sys/t_clock_gettime.c: revision 1.6
(all via patch)

kern: KASSERT(A && B) -> KASSERT(A); KASSERT(B)
White space fix.

kern_resource.c: Fix brace placement.
No functional change intended.

t_clock_gettime: Add test for PR kern/57512.

clock_gettime(2): Fix CLOCK_PROCESS/THREAD_CPUTIME_ID.
Use same calculation as getrusage, not some ad-hoc arithmetic of
internal scheduler parameters that are periodically rewound.
PR kern/57512

t_clock_gettime: Avoid signed/unsigned comparison.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 11-Nov-2016  njoly branches: 1.1.2;
New clock_nanosleep(2) testcase.
 1.1.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.1.2.1 11-Nov-2016  pgoyette file t_clock_nanosleep.c was added on branch pgoyette-localcount on 2017-01-07 08:56:55 +0000
 1.6 27-Sep-2024  riastradh tests/lib/libc/sys/t_clone: Nix trailing whitespace.

No functional change intended.
 1.5 25-Sep-2024  christos centralize stack allocation/freeing. The test that broke with the new jemalloc
had broken stack allocation.
 1.4 23-May-2017  christos branches: 1.4.26;
not allowed to map RWX anymore.
 1.3 12-Dec-2011  joerg Don't try to figure out how the stack grows at run time. It's not
portable and fails badly if the test function is removed...
 1.2 07-Jul-2011  jruoho branches: 1.2.2;
Rename test case names.
 1.1 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.4.26.1 02-Aug-2025  perseant Sync with HEAD
 1.3 13-Jan-2017  christos PR/51850: Ngie Cooper: add sys/socket.h for socket(2) and don't leak fds
 1.2 05-Apr-2015  rtr branches: 1.2.2;
add another test program for connect(2) that checks that connect fails
with EAFNOSUPPORT (similar to the bind test) if the domain of the socket
does not match the address family of the supplied address.

test currently fails as it should
 1.1 05-Nov-2011  jruoho branches: 1.1.2;
Move connect(2), listen(2) and socketpair(2) tests to the right place.
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 05-Nov-2011  yamt file t_connect.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.2.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 07-Jul-2011  jruoho Remove 't_cerror' (this is tested by numerous individual tests).
Rename 't_context' to 't_getcontext' for consistency.
 1.1 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.10 20-May-2024  christos Adjust to the new dup3 behavior for equal fds
 1.9 13-Jan-2017  christos PR/51851: Ngie Cooper: add stdbool.h #include for false/true
 1.8 18-Mar-2012  jruoho branches: 1.8.14;
Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.7 17-Oct-2011  njoly branches: 1.7.2;
Remove unneeded uneeded err.h include.
 1.6 30-Sep-2011  njoly Do not try to open files up to the RLIMIT_NOFILE limit, which fails
when process limit is identical to the whole system limit. Just do it
for a small fixed value, and adjust the limit accordingly instead.
 1.5 18-Jul-2011  jruoho Verify that dup2(2) and dup3(2) fail with EBADF if the "new descriptor" is
specified to be larger than RLIMIT_NOFILE.
 1.4 16-Jul-2011  jruoho PR lib/45148 was fixed; remove xfail.
 1.3 15-Jul-2011  jruoho Add some cases for dup2(2) and dup3(2).
 1.2 07-Jul-2011  jruoho Rewrite the limit-test.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.7.2.1 17-Apr-2012  yamt sync with head
 1.8.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3 20-Feb-2022  thorpej Validate basic fcntl(2) behavior for eventfd and timerfd.
 1.2 19-Sep-2021  thorpej Add native implementations of eventfd(2) and timerfd(2), compatible with
the Linux interfaces of the same name.
 1.1 14-Dec-2020  thorpej branches: 1.1.2;
file t_eventfd.c was initially added on branch thorpej-futex.
 1.1.2.1 14-Dec-2020  thorpej Unit tests for eventfd(2).
 1.5 24-May-2022  andvar s/estabilishing/establishing/ in copy pasted comment.
 1.4 06-Apr-2019  kamil Add new tests in ATF t_fork/t_vfork

Verify whether nested fork(2)/vfork(2)/clone(2) calls are supported in a
fork(2)ed/vforked(2) child.

The interesting ones are non-forked parent and non-forked child scenarios,
in particular double vfork(2).
 1.3 19-May-2018  kamil branches: 1.3.2; 1.3.4;
Reflect reality in the comment

The watcher process is emitting SIGKILL, not SIGTERM.

Sponsored by <The NetBSD Foundation>
 1.2 19-May-2018  kamil Stop masking SIGSTOP in a vfork(2)ed child

Keep the traditional BSD behavior masking SIGTSTP, SIGTTIN and SIGTTOU in
a vfork(2)ed child before exec(3)/exit(3). This is useful in shells and
prevents deadlocking, when a parent cannot unstop the sleeping child.

Change the behavior for SIGSTOP. This signal is by design not maskable and
this property shall be obeyed without exceptions. The STOP behavior is
expected in the context of debuggers and useful in standalone programs.

It is still possible to stop a vfork(2)ed child, however it requires
proc.curproc.stopfork=1, but it is not a flexible solution.

FreeBSD and OpenBSD keep masking SIGSTOP in a vfork(2)ed child.
Linux does not mask stop signals in the same scenarios.

This fixes ATF test: t_vfork:raise2.
No known regressions reported in the existing ATF tests.

Discussed with <kre>

Sponsored by <The NetBSD Foundation>
 1.1 18-May-2018  kamil Add new ATF tests: t_fork and t_vfork

Test behavior of raise(signal) in either fork(2)ed or vfork(2)ed child.

Tests:
- raise1 SIGKILL
- raise2 SIGSTOP
- raise3 SIGTSTP
- raise4 SIGTTIN
- raise5 SIGTTOU
- raise6 SIGABRT
- raise7 SIGHUP
- raise8 SIGCONT

t_vfork:raise2 fails ignoring non-maskable SIGSTOP.

The remaining ones pass.

Sponsored by <The NetBSD Foundation>
 1.3.4.1 10-Jun-2019  christos Sync with HEAD
 1.3.2.2 21-May-2018  pgoyette Sync with HEAD
 1.3.2.1 19-May-2018  pgoyette file t_fork.c was added on branch pgoyette-compat on 2018-05-21 04:36:17 +0000
 1.2 18-Mar-2012  jruoho Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.1 07-Jul-2011  jruoho branches: 1.1.2;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.14 05-Mar-2025  riastradh futex(2): Sign-extend FUTEX_WAKE_OP oparg/cmparg as Linux does.

Also mask off bits in the FUTEX_OP macro as Linux does so that passing
negative arguments works like in Linux.

PR kern/59129: futex(3): missing sign extension in FUTEX_WAKE_OP
 1.13 05-Mar-2025  riastradh t_futex_ops: Test sign-extension of WAKE_OP oparg/cmparg.

PR kern/59129: futex(3): missing sign extension in FUTEX_WAKE_OP
 1.12 05-Mar-2025  riastradh t_futex_ops: Relax various ATF_REQUIRE_* to ATF_CHECK_*.

This makes the test output more usable for browsing diagnostics when
multi-part tests partially fail.

Preparation for:

PR kern/59129: futex(3): missing sign extension in FUTEX_WAKE_OP
 1.11 05-Mar-2025  riastradh t_futex_ops: Spruce up diagnostics.

- Use RL to report errno for any syscalls that set it.
- Sprinkle messages to show intermediate quantities.

Preparation for:

PR kern/59129: futex(3): missing sign extension in FUTEX_WAKE_OP
 1.10 18-Jan-2025  riastradh futex(2): Fix return value of FUTEX_CMP_REQUEUE.

The return value is the number of waiters woken _or requeued_, not
just the number of waiters woken:

FUTEX_CMP_REQUEUE
Returns the total number of waiters that were woken up or
requeued to the futex for the futex word at uaddr2. If
this value is greater than val, then the difference is the
number of waiters requeued to the futex for the futex word
at uaddr2.

https://man7.org/linux/man-pages/man2/futex.2.html

While here, clarify some of the arguments with comments so it's not
quite so cryptic with val/val2/val3 everywhere.

PR kern/56828: futex calls in Linux emulation sometimes hang
 1.9 18-Jan-2025  riastradh futex(2): Fix FUTEX_CMP_REQUEUE to always compare even if no waiters.

It must always compare the futex value and fail with EAGAIN on
mismatch, even if there are no waiters.

FUTEX_CMP_REQUEUE (since Linux 2.6.7)
This operation first checks whether the location uaddr
still contains the value val3. If not, the operation
fails with the error EAGAIN. Otherwise, the operation [...]

https://man7.org/linux/man-pages/man2/futex.2.html

PR kern/56828: futex calls in Linux emulation sometimes hang
 1.8 18-Jan-2025  riastradh tests/lib/libc/sys/t_futex_ops: Fix another FUTEX_CMP_REQUEUE case.

PR kern/56828: futex calls in Linux emulation sometimes hang
 1.7 18-Jan-2025  riastradh tests/lib/libc/sys/t_futex_ops: Fix FUTEX_CMP_REQUEUE return values.

The return value is the number of waiters woken _or requeued_, not
just the number of waiters woken:

FUTEX_CMP_REQUEUE
Returns the total number of waiters that were woken up or
requeued to the futex for the futex word at uaddr2. If
this value is greater than val, then the difference is the
number of waiters requeued to the futex for the futex word
at uaddr2.

https://man7.org/linux/man-pages/man2/futex.2.html

PR kern/56828: futex calls in Linux emulation sometimes hang
 1.6 18-Jan-2025  riastradh tests/lib/libc/sys/t_futex_ops: Test FUTEX_CMP_REQUEUE edge case.

It must always compare the futex value and fail with EAGAIN on
mismatch, even if there are no waiters.

PR kern/56828: futex calls in Linux emulation sometimes hang
 1.5 06-May-2020  thorpej branches: 1.5.2; 1.5.8; 1.5.12;
Fix a bug in the futex_wake_highest_pri test case. Still fails as
expected.
 1.4 04-May-2020  thorpej Add a test case for PR kern/55230. It is currently marked as expect-fail.
 1.3 30-Apr-2020  thorpej - In uvm_voaddr_acquire(), take an extra hold on the anon lock obj.
- In uvm_voaddr_release(), if the anon ref count drops to 0, call
uvm_anfree() rather than uvm_anon_release(). Unconditionally drop
the anon lock, and release the extra hold on the anon lock obj.

Fixes a panic that occurs if the backing store for a futex backed by
an anon memory location is unmapped while a thread is waiting in the
futex.

Add a test case that reproduced the panic to verify that it's fixed.
 1.2 28-Apr-2020  riastradh Make FUTEX_WAIT_BITSET(bitset=0) fail with EINVAL to match Linux.
 1.1 26-Apr-2020  thorpej Add a NetBSD native futex implementation, mostly written by riastradh@.
Map the COMPAT_LINUX futex calls to the native ones.
 1.5.12.1 02-Aug-2025  perseant Sync with HEAD
 1.5.8.2 07-Aug-2021  thorpej futex_wake_highest_pri is not expected to fail on the thorpej-futex2
branch.
 1.5.8.1 07-Aug-2021  thorpej Fix the unit test for FUTEX_REQUEUE and FUTEX_CMP_REQUEUE to account
for the different return value semantics.
 1.5.2.1 01-Nov-2020  thorpej - Re-factor the code that sets up real-time LWPs for various tests.
- Add tests for the RW_HANDOFF operations.
 1.2 01-May-2020  thorpej Oops, accidentally #if 0'd some tests, probably while debugging
something else. Correct this silly mistake.
 1.1 26-Apr-2020  thorpej Add a NetBSD native futex implementation, mostly written by riastradh@.
Map the COMPAT_LINUX futex calls to the native ones.
 1.3 14-Jul-2011  jruoho Adjust.
 1.2 07-Jul-2011  jruoho Add some errno-checks.
 1.1 07-Jul-2011  jruoho Remove 't_cerror' (this is tested by numerous individual tests).
Rename 't_context' to 't_getcontext' for consistency.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.5 19-Dec-2024  riastradh t_getitimer: Test invalid itimerval arguments.

Use sig_atomic_t while here.

Ex-POSIX (POSIX.1-2008; the interface was removed in POSIX.1-2024)
prescribes EINVAL for all of these cases:

SYNOPSIS

#include <sys/time.h>

int getitimer(int which, struct itimerval *value);
int setitimer(int which, const struct itimerval *restrict value,
struct itimerval *restrict ovalue);
[...]
ERRORS

The setitimer() function shall fail if:

[EINVAL]
The value argument is not in canonical form. (In canonical
form, the number of microseconds is a non-negative integer
less than 1000000 and the number of seconds is a non-negative
integer.)

https://pubs.opengroup.org/onlinepubs/9699919799/functions/setitimer.html
 1.4 04-Apr-2022  andvar branches: 1.4.4;
fix various typos, mainly in comments.
 1.3 13-Jul-2019  gson In the setitimer_old test case, allow for time passing between the two
setitimer() calls. Should fix PR kern/54370.
 1.2 22-Mar-2012  christos branches: 1.2.32;
dholland fixed PR/44927
 1.1 07-Jul-2011  jruoho branches: 1.1.2;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.32.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4.4.1 02-Aug-2025  perseant Sync with HEAD
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.5 03-Aug-2023  rin t_getrandom: Fix false positives for short read(2)

This only affects really slooooow machines, 68030 for me :)
 1.4 18-Mar-2022  riastradh branches: 1.4.2;
getrandom(2): Fix return value checks in automatic tests.

The syscall only guarantees up to 256 bytes in a single go -- if
interrupted, it might return short, but if the caller requested at
least 256 bytes it will definitely return 256 bytes.
 1.3 25-Aug-2020  riastradh Fix getrandom() tests.

Use sigaction() without SA_RESTART -- signal() implies SA_RESTART so
we never got the EINTR.

While here, reduce the timeout to something more reasonable so we
don't waste 20min of testbed time if anything goes wrong and the
one-second alarm doesn't fire.
 1.2 23-Aug-2020  riastradh Split getrandom tests into several cases to find out which ones hang.
 1.1 14-Aug-2020  riastradh New system call getrandom() compatible with Linux and others.

Three ways to call:

getrandom(p, n, 0) Blocks at boot until full entropy.
Returns up to n bytes at p; guarantees
up to 256 bytes even if interrupted
after blocking. getrandom(0,0,0)
serves as an entropy barrier: return
only after system has full entropy.

getrandom(p, n, GRND_INSECURE) Never blocks. Guarantees up to 256
bytes even if interrupted. Equivalent
to /dev/urandom. Safe only after
successful getrandom(...,0),
getrandom(...,GRND_RANDOM), or read
from /dev/random.

getrandom(p, n, GRND_RANDOM) May block at any time. Returns up to n
bytes at p, but no guarantees about how
many -- may return as short as 1 byte.
Equivalent to /dev/random. Legacy.
Provided only for source compatibility
with Linux.

Can also use flags|GRND_NONBLOCK to fail with EWOULDBLOCK/EAGAIN
without producing any output instead of blocking.

- The combination GRND_INSECURE|GRND_NONBLOCK is the same as
GRND_INSECURE, since GRND_INSECURE never blocks anyway.

- The combinations GRND_INSECURE|GRND_RANDOM and
GRND_INSECURE|GRND_RANDOM|GRND_NONBLOCK are nonsensical and fail
with EINVAL.

As proposed on tech-userlevel, tech-crypto, tech-security, and
tech-kern, and subsequently adopted by core (minus the getentropy part
of the proposal, because other operating systems and participants in
the discussion couldn't come to an agreement about getentropy and
blocking semantics):

https://mail-index.netbsd.org/tech-userlevel/2020/05/02/msg012333.html
 1.4.2.1 11-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #319):

sys/dev/pci/ubsec.c: revision 1.64
sys/dev/pci/hifn7751.c: revision 1.82
lib/libc/gen/getentropy.3: revision 1.5
lib/libc/gen/getentropy.3: revision 1.6
share/man/man4/rnd.4: revision 1.41
lib/libc/sys/getrandom.2: revision 1.2
lib/libc/sys/getrandom.2: revision 1.3
share/man/man5/rc.conf.5: revision 1.193
share/man/man7/entropy.7: revision 1.5
share/man/man7/entropy.7: revision 1.6
share/man/man7/entropy.7: revision 1.7
share/man/man7/entropy.7: revision 1.8
etc/security: revision 1.130
share/man/man7/entropy.7: revision 1.9
etc/security: revision 1.131
sys/crypto/cprng_fast/cprng_fast.c: revision 1.19
sys/sys/rndio.h: revision 1.3
tests/lib/libc/sys/t_getrandom.c: revision 1.5
etc/defaults/rc.conf: revision 1.164
etc/defaults/rc.conf: revision 1.165
sys/sys/rndsource.h: revision 1.10
sys/kern/kern_entropy.c: revision 1.62
sys/kern/kern_entropy.c: revision 1.63
sys/kern/kern_entropy.c: revision 1.64
sys/kern/subr_cprng.c: revision 1.44
sys/kern/kern_entropy.c: revision 1.65
sys/kern/kern_clock.c: revision 1.149
sys/dev/pci/viornd.c: revision 1.22
share/man/man9/rnd.9: revision 1.32
sys/kern/subr_prf.c: revision 1.202
sys/sys/rndsource.h: revision 1.8
sys/sys/rndsource.h: revision 1.9
share/man/man7/entropy.7: revision 1.10

1. Reinstate netbsd<=9 entropy estimator to unblock /dev/random, in
parallel with assessment of only confident entropy sources (seed,
HWRNG) for security warnings like sshd keys in motd and daily
insecurity report.

2. Make multiuser boot wait for first /dev/random output soon after
loading a seed and configuring rndctl, so that getentropy(3) meets
its contract starting early at boot without introducing blocking
paths that could cause hangs in init(8) or single-user mode.
Operators can choose to disable this wait in rc.conf.

3. Fix some bugs left over from reducing the global entropy lock from
a spin lock at IPL_VM to an adaptive lock at IPL_SOFTSERIAL.

4. Update man pages.
 1.9 12-Apr-2024  gson Require at least 64 MB RAM to run the getrusage_maxrss test case as it
allocates 40 MB and we should leave some for the system, too.
 1.8 09-May-2018  mrg don't print "long" with "%zu".
 1.7 09-May-2018  martin Make the getrusage_maxrss test more stable by preventing the compiler to
optimize out a dummy loop. While there print more details when failing.
 1.6 08-May-2018  christos add tests for maxrss, msgsnd
 1.5 13-Jan-2017  christos branches: 1.5.12;
PR/51852: Ngie Cooper: mark signo __unused
 1.4 05-Aug-2016  scole PR port-ia64/51261

Make this compile for ia64
 1.3 03-Sep-2014  matt branches: 1.3.2;
The nop instruction on or1k is l.nop
 1.2 22-Aug-2011  dholland Requires stdint.h.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.3.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.3.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.5.12.1 21-May-2018  pgoyette Sync with HEAD
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1 30-Jul-2016  njoly branches: 1.1.2;
New getsockname(2) testcase for UNIX domain sockets.
 1.1.2.2 06-Aug-2016  pgoyette Sync with HEAD
 1.1.2.1 30-Jul-2016  pgoyette file t_getsockname.c was added on branch pgoyette-localcount on 2016-08-06 00:19:12 +0000
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.9 31-Oct-2020  christos PR/55663: Ruslan Nikolaev: Add support for EVFILT_USER in kqueue(2)
 1.8 25-Jun-2020  jruoho Reference PRs consistently.
 1.7 05-Feb-2015  isaki Skip kqueue_unsupported_fd test if /dev/drvctl is not configured
in the kernel. PR bin/49644.

XXX Ideally, it's better to modify to use more generic device file.
 1.6 29-Nov-2012  martin Skip kqueue_unsupported_fd if the drvctl device is not present.
 1.5 24-Nov-2012  christos Add a test for adding an event to an unsupported fd.
 1.4 02-Jun-2012  martin branches: 1.4.2;
adapt to new reality
 1.3 31-May-2012  martin Add a (skipped for now) test case for PR 46463
 1.2 18-Mar-2012  jruoho branches: 1.2.2;
Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.1 17-Nov-2011  christos branches: 1.1.2; 1.1.6;
Add a test for PR/45618: Motoyuki OHMORI: kqueue EVFILT_TIMER with smaller
timeout value makes kernel busy or panic
 1.1.6.1 24-Nov-2012  jdc Pull up revisions:
src/sys/kern/kern_event.c revision 1.79
src/sys/kern/kern_descrip.c revision 1.219
src/lib/libc/sys/kqueue.2 revision 1.33
src/tests/lib/libc/sys/t_kevent.c revision 1.2-1.5
(requested by christos in ticket #716).

- initialize kn_id
- in close, invalidate f_data and f_type early to prevent accidental re-use
- add a DIAGNOSTIC for when we use unsupported fd's and a KASSERT for f_event
being NULL.

Return EOPNOTSUPP for fnullop_kqfilter to prevent registration of unsupported
fds. XXX: We should really fix the fd's to be supported in the future.
Unsupported fd's have a NULL f_event, so registering crashes the kernel with
a NULL function dereference of f_event.

mention that kevent returns now EOPNOTSUPP.

Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.

Add a (skipped for now) test case for PR 46463

adapt to new reality

Add a test for adding an event to an unsupported fd.
 1.1.2.1 24-Nov-2012  jdc Pull up revisions:
src/sys/kern/kern_event.c revision 1.79
src/sys/kern/kern_descrip.c revision 1.219
src/lib/libc/sys/kqueue.2 revision 1.33
src/tests/lib/libc/sys/t_kevent.c revision 1.2-1.5
(requested by christos in ticket #716).

- initialize kn_id
- in close, invalidate f_data and f_type early to prevent accidental re-use
- add a DIAGNOSTIC for when we use unsupported fd's and a KASSERT for f_event
being NULL.

Return EOPNOTSUPP for fnullop_kqfilter to prevent registration of unsupported
fds. XXX: We should really fix the fd's to be supported in the future.
Unsupported fd's have a NULL f_event, so registering crashes the kernel with
a NULL function dereference of f_event.

mention that kevent returns now EOPNOTSUPP.

Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.

Add a (skipped for now) test case for PR 46463

adapt to new reality

Add a test for adding an event to an unsupported fd.
 1.2.2.4 16-Jan-2013  yamt sync with (a bit old) head
 1.2.2.3 30-Oct-2012  yamt sync with head
 1.2.2.2 17-Apr-2012  yamt sync with head
 1.2.2.1 18-Mar-2012  yamt file t_kevent.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.4.2.1 25-Feb-2013  tls resync with head
 1.2 15-Jul-2024  riastradh tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.

PR kern/58425
 1.1 07-Jul-2011  jruoho branches: 1.1.44; 1.1.56; 1.1.58;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.58.1 02-Aug-2025  perseant Sync with HEAD
 1.1.56.1 07-Aug-2024  martin Pull up following revision(s) (requested by kre in ticket #773):

sys/kern/kern_proc.c: revision 1.276
sys/kern/kern_ktrace.c: revision 1.185
sys/kern/sys_sig.c: revision 1.58
sys/kern/kern_descrip.c: revision 1.263
lib/libc/compat-43/killpg.c: revision 1.10
sys/kern/tty.c: revision 1.313
tests/lib/libc/sys/t_kill.c: revision 1.2

PR kern/58425 -- Disallow INT_MIN as a (negative) pid arg.

Since -INT_MIN is undefined, and to point of negative pid args is
to negate them, and use the result as a pgrp id instead, we need
to avoid accidentally negating INT_MIN.

Since pid_t is just an integral type, of unspecified width, when
testing pid_t value test for <= INT_MIN (or > INT_MIN sometimes)
rather than == INT_MIN. When testing int values, just == INT_MIN
is all that is needed, < INT_MIN cannot occur.

tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.
PR kern/58425
 1.1.44.1 07-Aug-2024  martin Pull up following revision(s) (requested by kre in ticket #1859):

sys/kern/kern_proc.c: revision 1.276 (via patch)
sys/kern/kern_ktrace.c: revision 1.185 (via patch)
sys/kern/sys_sig.c: revision 1.58 (via patch)
sys/kern/kern_descrip.c: revision 1.263 (via patch)
lib/libc/compat-43/killpg.c: revision 1.10
sys/kern/tty.c: revision 1.313 (via patch)
tests/lib/libc/sys/t_kill.c: revision 1.2

PR kern/58425 -- Disallow INT_MIN as a (negative) pid arg.
Since -INT_MIN is undefined, and to point of negative pid args is
to negate them, and use the result as a pgrp id instead, we need
to avoid accidentally negating INT_MIN.

Since pid_t is just an integral type, of unspecified width, when
testing pid_t value test for <= INT_MIN (or > INT_MIN sometimes)
rather than == INT_MIN. When testing int values, just == INT_MIN
is all that is needed, < INT_MIN cannot occur.

tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.
PR kern/58425
 1.3 13-Jan-2017  christos PR/51853: Ngie Cooper: add limits.h for MAXPATHLEN in FreeBSD
 1.2 21-Apr-2014  martin branches: 1.2.6;
When a hard link to a directory fails, accept both EPERM and EACCESS as
valid error codes.
 1.1 07-Jul-2011  jruoho branches: 1.1.2; 1.1.8; 1.1.18;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.18.1 10-Aug-2014  tls Rebase.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.6.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6 09-Jul-2019  maya return return atf_no_error() instead of 0 for consistency.

suggested by moritzbuhl in https://github.com/NetBSD/src/pull/11/
 1.5 13-Jan-2017  christos branches: 1.5.14;
PR/51854: Ngie Cooper: sys/socket.h include and check result from socket(2)
 1.4 18-Mar-2012  jruoho branches: 1.4.14;
Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.3 16-Mar-2012  matt This is no longer expected to fail.
 1.2 07-Mar-2012  jruoho Check the error values from listen(2), incl. case for standards/46150.
 1.1 05-Nov-2011  jruoho branches: 1.1.2;
Move connect(2), listen(2) and socketpair(2) tests to the right place.
 1.1.2.3 17-Apr-2012  yamt sync with head
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 05-Nov-2011  yamt file t_listen.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.4.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 22-Aug-2021  andvar s/priviledge/privilege/ in comments/log messages and fix one typo in descriptor.
 1.3 06-Jun-2020  thorpej Add a test case to ensure that _lwp_create() fails with the
expected error code when a bad new-lwp-id pointer is passed.
 1.2 22-May-2012  martin branches: 1.2.2;
Typo in comment
 1.1 21-May-2012  martin branches: 1.1.2;
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.1.2.3 22-May-2012  riz Pull up following revision(s) (requested by martin in ticket #275):
tests/lib/libc/sys/t_lwp_create.c: revision 1.2
Typo in comment
 1.1.2.2 21-May-2012  riz Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.1.2.1 21-May-2012  riz file t_lwp_create.c was added on branch netbsd-6 on 2012-05-21 15:25:58 +0000
 1.2.2.2 23-May-2012  yamt sync with head.
 1.2.2.1 22-May-2012  yamt file t_lwp_create.c was added on branch yamt-pagecache on 2012-05-23 10:08:21 +0000
 1.2 18-Mar-2012  jruoho branches: 1.2.2;
Get rid of the weird macros.
 1.1 17-Mar-2012  jruoho Move the _lwp_ctl(2) preemption counter check to the right place.
 1.2.2.2 17-Apr-2012  yamt sync with head
 1.2.2.1 18-Mar-2012  yamt file t_lwp_ctl.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.2 22-Apr-2020  thorpej Remove unit tests for the never-exposed _lwp_gettid(2).
 1.1 04-Apr-2020  thorpej branches: 1.1.2;
Add support for lazily generating a "global thread ID" for a LWP. This
identifier uniquely identifies an LWP across the entire system, and will
be used in future improvements in user-space synchronization primitives.

(Test disabled and libc stub not included intentionally so as to avoid
multiple libc version bumps.)
 1.1.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.2.1 04-Apr-2020  martin file t_lwp_tid.c was added on branch phil-wifi on 2020-04-08 14:09:09 +0000
 1.15 24-Feb-2020  rin 0x%p --> %p for non-external codes.
 1.14 08-Oct-2017  kre branches: 1.14.4;

Skip the mincore_shmseg test case if the SYSVSHM option is not configured
in the kernel.
 1.13 01-Sep-2017  kre Allow the test to build on systems where sys/mman.h does not provide
PROT_MPROTECT(), or if the test is built without _NETBSD_SOURCE defined,
by providing a dummy #define if the real one does not exist. The test
might then fail, if the PROT_MPROTECT() is really needed, but that's
better than not building.
 1.12 01-Sep-2017  kre Use PROT_MPROTECT() (which would have been better had it been called
PROT_MAXPROTECT or PROT_ALLOWPROTECT or something) on the mmap() call
which specifies PROT_NONE, and which we later want to change to PROT_READ,
otherwise when PAX is enabled, the mprotect() will fail.
 1.11 23-May-2017  christos Add the error in syscall failure.
 1.10 14-Jan-2017  christos Pr/51866: Ngie Cooper: fix leak and release limit on memory to prevent
false positives with mlock/mmap
 1.9 10-Jan-2017  christos more tests needing <sys/stat.h>
 1.8 08-Jun-2012  martin branches: 1.8.14;
Degrade all intermediate failures due to memory/resource shortage to
"skip" instead of "fail" - only if we get through to the real meat, we
can tell wether mlockall/mincore work or not.
 1.7 07-Jun-2012  martin Revert previous - instead of guessing the amount of needed memory locked
limits (often way too high) and skipping the test case if in doubt,
raise the limits as far as we can, and fix a few places in the test where
we could run into the limits and either skip or fail with a reasonable
message.
 1.6 05-Jun-2012  martin Try to estimate the number of locked pages the mincore() test will need and
check it against resource limits, skipping the tests if it probably is too
low.
 1.5 23-May-2012  martin Simplify creation of a temporary file slightly, fix sizeof(buf) confusion
when buf is a pointer.
 1.4 14-Mar-2012  jruoho Skip the ENOMEM/RLIMIT_MEMLOCK case when doing mlockall(2).
 1.3 14-Jul-2011  jruoho branches: 1.3.2;
Remove the 't_mincore' test case, as it is essentially a less elegant
version of the recently added page residency checks.
 1.2 14-Jul-2011  jruoho Add the test cases from the old ../regress/sys/uvm/mmap/mmap.c.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.3.2.2 30-Oct-2012  yamt sync with head
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.8.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1 18-Jul-2014  christos branches: 1.1.2; 1.1.6;
Add new minherit test.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 18-Jul-2014  tls file t_minherit.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 18-Jul-2014  tls file t_minherit.c was added on branch tls-earlyentropy on 2014-08-10 06:57:21 +0000
 1.2 15-Oct-2011  jruoho Add few basic checks.
 1.1 15-Oct-2011  jruoho Move the mkdir(2) test to the right place.
 1.3 20-Jun-2019  kamil Add mkfifo{,at}(2) mode in mknod{,at}(2) as requested by POSIX

mknod with mode & S_IFIFO and dev=0 shall behave like mkfifo.

Update the documentation to reflect this state.

Add ATF tests.

This is an in-kernel implementation as typically user-space programs use
mkfifo(2) directly, however whenever there is need to bypass libc (like in
valgrind) then portable POSIX software calls the mknod syscall.

Noted on tech-kern@ by Greg Troxel.
 1.2 02-Nov-2011  jruoho branches: 1.2.42;
Fix a test case to test what the comment says.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.42.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 18-Mar-2012  jruoho Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.1 07-Jul-2011  jruoho branches: 1.1.2;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.8 24-Jan-2020  skrll Don't print the pagesize it messes up atf-report
 1.7 13-Mar-2019  kre Add a bunch of fprintf(stderr,...) diagnostics to try and help determine
what is going wrong which is causing this test to crash the kernel.
 1.6 09-Aug-2016  kre branches: 1.6.14;

This test should be testing how the kernel should behave, not how
it actually (used to) behave when it was incorrect... Aside from
a possible EPERM (which is not tested) the only error possible from
mlock() is ENOMEM. POSIX also allows EINVAL if the address is not
page aligned and the implementation does not round down to the previous
page boundary, but NetBSD does.

The kernel was recently fixed to return the correct errors for mlock()
so now we really need the test to be checking them, and not expecting
the incorrect errno values that the kernel used to return.

Same for munlock() - there ENOMEM is the only possible error, again,
EINVAL cannot happen as the kernel rounds to page boundaries.
For munlock() the kernel has not yet been corrected (that is coming
real soon...) and one of the munlock() tests will currently fail
(as of the time this commit is made, hopefully not for much longer)
as it should - it is indicating a kernel bug.

Note that NetBSD mlock(2) talks about EINVAL for cases where the length
parameter is negative ... but that is a size_t - good luck having that
ever occur (the man page will soon be corrected as well.)
 1.5 26-Feb-2014  martin Remove hardcoded VM_MIN_ADDRESS and instead query current value via
sysctl vm.minaddress.
 1.4 08-Sep-2012  martin branches: 1.4.2;
Make this compile on archs where VM_MIN_ADDRESS is not defined (or not
exported to userland)
 1.3 07-Sep-2012  martin Deal with architectures defining VM_MIN_ADDRESS > 0.
Add additional error code tests using a pointer one page past current brk.
 1.2 21-Apr-2012  jruoho branches: 1.2.2;
Avoid harmless compiler (integer) warnings.
 1.1 20-Apr-2012  jruoho Add few unit tests for mlock(2), including a case for PR kern/44788.
 1.2.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.2.3 30-Oct-2012  yamt sync with head
 1.2.2.2 23-May-2012  yamt sync with head.
 1.2.2.1 21-Apr-2012  yamt file t_mlock.c was added on branch yamt-pagecache on 2012-05-23 10:08:21 +0000
 1.4.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.14.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6.14.1 10-Jun-2019  christos Sync with HEAD
 1.18 04-Jun-2022  riastradh tests/lib/libc: Test mmap(2) with bad hints.
 1.17 06-Apr-2022  gson Add a regression test for PR kern/52239, "Changing protections of
already mmap'ed region can fail", based on the test program in the PR.
 1.16 05-Apr-2022  gson In the mmap_err test case, mmap the address, not the address of the address.
Should fix PR kern/56780.
 1.15 05-Apr-2022  gson When the t_mmap:mmap_err test fails due to errno not having the expected
value of EINVAL, print the actual value.
 1.14 26-Jun-2020  jruoho Reference PRs consistently.
 1.13 23-May-2017  christos Handle dk disks and print errors.
 1.12 16-Jan-2017  christos PR/51891: Ngie Cooper: use sys/disklabel.h instead of machine/disklabel.h
 1.11 13-Jan-2017  christos branches: 1.11.2;
PR/51855: Ngie Cooper: fix leaks
 1.10 10-Jan-2017  christos more tests needing <sys/stat.h>
 1.9 28-Feb-2015  martin branches: 1.9.2;
Make sure to use the values calculated in the loop that is supposed to crash
the client process - so the compiler does not optimize it all away.
Also improve diagnostic in case of common bug: SIGSEGV instead of SIGBUS.
 1.8 27-Feb-2015  christos add truncate causing signal test
 1.7 14-Jun-2012  bouyer Disable the mmap_block test again, it doesn't panic when mmaping /dev/wd0d
only by accident. PR kern/46592.
 1.6 01-Jun-2012  martin Do not skip the block device mmap test, as it does not crash
the kernel any more. Mark it as expected failure instead.
 1.5 16-May-2012  martin mmap_block:
do not use a hardcoded block device list, but query the kernel for attached
disks instead, then try to mmap the raw partition.
 1.4 13-Mar-2012  jruoho Use atf_tc_skip().
 1.3 06-Mar-2012  jruoho A test case for serious PR kern/38889: crash on open/mmap/close of block
device. The test case is skipped for the time being as it replicates the
panic described in the PR (tested on NetBSD/amd64 6.0 BETA).
 1.2 14-Jul-2011  jruoho branches: 1.2.2; 1.2.4;
Move the uvm "loan" test to tests(7).
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.4.2 15-Jun-2012  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #345):
tests/lib/libc/sys/t_mmap.c: revision 1.7

Disable the mmap_block test again. It is only by accident that it doesn't
panic when mmaping /dev/wd0d. PR kern/46592
 1.2.4.1 11-Jun-2012  riz Pull up following revision(s) (requested by martin in ticket #301):
sys/uvm/uvm_vnode.c: revision 1.98
tests/lib/libc/sys/t_mmap.c: revision 1.3
tests/lib/libc/sys/t_mmap.c: revision 1.4
tests/lib/libc/sys/t_mmap.c: revision 1.5
tests/lib/libc/sys/t_mmap.c: revision 1.6
Only use generic readahead on VREG vnodes, the space used to store the
context is not valid on other types.
Prevents the crash reported in PR kern/38889, but does not fix the
mmap of block devices, more work is needed (no size on VBLK vnodes).
Do not skip the block device mmap test, as it does not crash
the kernel any more. Mark it as expected failure instead.
mmap_block:
do not use a hardcoded block device list, but query the kernel for attached
disks instead, then try to mmap the raw partition.
Use atf_tc_skip().
A test case for serious PR kern/38889: crash on open/mmap/close of block
device. The test case is skipped for the time being as it replicates the
panic described in the PR (tested on NetBSD/amd64 6.0 BETA).
 1.2.2.3 30-Oct-2012  yamt sync with head
 1.2.2.2 23-May-2012  yamt sync with head.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.9.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.11.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.9 18-Apr-2020  christos PR/55177: Carlo Arenas: mremap(MAP_REMAPDUP) fails after fork()
 1.8 16-Jul-2019  martin PR misc/54382: whenever open(2) is called with O_CREAT, make sure to
pass an open mode argument.
 1.7 06-May-2017  joerg branches: 1.7.10;
Extend the mmap(2) interface to allow requesting protections for later
use with mprotect(2), but without enabling them immediately.

Extend the mremap(2) interface to allow duplicating mappings, i.e.
create a second range of virtual addresses references the same physical
pages. Duplicated mappings can have different effective protections.

Adjust PAX mprotect logic to disallow effective protections of W&X, but
allow one mapping W and another X protections. This obsoletes using
temporary files for purposes like JIT.

Adjust PAX logic for mmap(2) and mprotect(2) to fail if W&X is requested
and not silently drop the X protection.

Improve test cases to ensure correct operation of the changed
interfaces.
 1.6 25-Mar-2017  pgoyette branches: 1.6.2;
Rather than ghecking system global state to see if mprotect might be
enabled, use the newly-committed sysctl proc.curproc.paxflags variable
 1.5 24-Mar-2017  martin Do not toggle global security.pax.mprotect state in an attempt to
activate it for the current process. It does not work and tests should
not change global system state anyway.
Instead: skip the test is pax.mprotect is not globally enabled. We could
use a better check for this (querying the current processes pax flags),
but unfortunately we don't have one.
 1.4 28-May-2016  christos branches: 1.4.2; 1.4.4;
Skip the mprotect_exec test if PaX MPROTECT restrictions are enabled.
 1.3 20-Jul-2011  jym Modify exec test to be more resilient regarding partial exec protection:
skip test instead of returning a failure that could be misinterpreted.

Suggested by Jukka in private mail.
 1.2 18-Jul-2011  jym Add a simple test case to check executable mapping rights for mprotect(2).

- provide an exec_prot_support() routine so $ARCH can indicate whether
it supports execution protection or not, and skip test accordingly.

- have a trivial 'return_one' shellcode to copy anywhere in a page, and
call it. The decision to keep the assembly solution is mine, reasons are
twofold:

- all pure-C implementations cannot be controlled easily:
bounds detection (beginning/end) of return_one is unpredictable,
or requires the use of overkill solutions like libelf. Using
dlsym(3) was a good proposal, however I can't use it to know the
end address of the payload. It makes copying of the shellcode a bit
more difficult: using a constant may be too small (code has not been
entirely copied, and can lead to errors that can be erroneously
detected as "test passed"), or too big (depending on where it is mapped
in memory, copying past the end of the function may trigger SIGSEGV).

- I have to ensure that the resulting assembly is the most compact
possible, especially as it will be reused to test other parts of
memory (stack, data, rodata, etc.).

Only i386 and amd64 are implemented so far. Others will come in due time.
FWIW, writing the exec_prot_support() callback and the return_one payload
should be enough. Writing callback requires good knowledge of the platform,
depending on chip revision, CPU, board, MMU... the protection level may vary.

Current files are put under lib/libc/arch/* and lib/libc/common/. Feel free to
move them around the tests/ tree. Keep in mind that the common/ and arch/ code
will be used outside of libc, so please do not hide them too deep in the tree.

I checked a few architectures via build.sh cross-compile, and will keep an
eye on buildbot for potential build breakage. Feel free to contact me in
case you see any, of course.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.4.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.4.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.6.2.1 11-May-2017  pgoyette Sync with HEAD
 1.7.10.2 21-Apr-2020  martin Sync with HEAD
 1.7.10.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 31-May-2022  skrll Avoid plabels on hppa to make some tests not crash
 1.1 18-Apr-2020  christos branches: 1.1.2;
PR/55177: Carlo Arenas: mremap(MAP_REMAPDUP) fails after fork()
 1.1.2.2 21-Apr-2020  martin Sync with HEAD
 1.1.2.1 18-Apr-2020  martin file t_mprotect_helper.c was added on branch phil-wifi on 2020-04-21 18:42:47 +0000
 1.2 31-May-2022  skrll Avoid plabels on hppa to make some tests not crash
 1.1 18-Apr-2020  christos branches: 1.1.2;
Oops, need the header too.
 1.1.2.2 21-Apr-2020  martin Sync with HEAD
 1.1.2.1 18-Apr-2020  martin file t_mprotect_helper.h was added on branch phil-wifi on 2020-04-21 18:42:47 +0000
 1.7 07-Oct-2017  kre If we have SYSVMSG in kernel (test finds it) restore the signal handler
to its previous state, so any signals that occur during the rest of the
test gat handled just as they would (core dump) as if the handler was never
executed. No need to bother if the SYSVMSG test fails, as in that case,
nothing else will be done anyway.
 1.6 06-Oct-2017  kre Make this test skip if running on a kernel without the SYSVMSG option.
(Assuming this behaves as intended the other tests which should behave
the same way will get upgrades as well.)
 1.5 13-Jan-2017  christos PR/51856: Ngie Cooper: add limits.h for INT_MAX
 1.4 27-Feb-2014  joerg branches: 1.4.8;
Use an abs wide enough to cover the types involved.
 1.3 11-Nov-2011  jruoho branches: 1.3.6;
Fix typo.
 1.2 05-Nov-2011  jruoho branches: 1.2.2;
Fix some typos.
 1.1 05-Nov-2011  jruoho Add 21 unit tests for the XSI message queues.
 1.2.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.2.3 17-Apr-2012  yamt sync with head
 1.2.2.2 10-Nov-2011  yamt sync with head
 1.2.2.1 05-Nov-2011  yamt file t_msgctl.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.3.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3 08-Oct-2017  kre Don't bother attempting any of the (real) test cases if the SYSVMSG
option isn't configured in the kernel.
 1.2 27-Feb-2014  joerg Use an abs wide enough to cover the types involved.
 1.1 05-Nov-2011  jruoho branches: 1.1.2; 1.1.8;
Add 21 unit tests for the XSI message queues.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 05-Nov-2011  yamt file t_msgget.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.5 08-Oct-2017  kre Don't bother attempting any of the (real) test cases if the SYSVMSG
option isn't configured in the kernel.
 1.4 13-Jan-2017  christos PR/51856: Ngie Cooper: add limits.h for INT_MAX
 1.3 24-Jul-2013  skrll branches: 1.3.8;
Fix msgsz confusion.
 1.2 11-Nov-2011  jruoho branches: 1.2.2; 1.2.6;
Fix typo.
 1.1 05-Nov-2011  jruoho branches: 1.1.2;
Add 21 unit tests for the XSI message queues.
 1.1.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.3 17-Apr-2012  yamt sync with head
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 05-Nov-2011  yamt file t_msgrcv.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.2.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.1 30-Jul-2013  msaitoh Pull up following revision(s) (requested by skrll in ticket #922):
tests/lib/libc/sys/t_msgrcv.c 1.3
lib/libc/sys/msgrcv.2 1.21-1.22
lib/libc/sys/msgsnd.2 1.19-1.20
Fix msgsz confusion.
 1.3.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 08-Oct-2017  kre Don't bother attempting any of the (real) test cases if the SYSVMSG
option isn't configured in the kernel.
 1.3 13-Jan-2017  christos PR/51856: Ngie Cooper: add limits.h for INT_MAX
 1.2 05-Nov-2011  jruoho branches: 1.2.2; 1.2.24;
Fix some typos.
 1.1 05-Nov-2011  jruoho Add 21 unit tests for the XSI message queues.
 1.2.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.2.2 10-Nov-2011  yamt sync with head
 1.2.2.1 05-Nov-2011  yamt file t_msgsnd.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.3 14-Jan-2017  christos PR/51867: Ngie Cooper: misc cleanups
 1.2 16-Mar-2012  matt branches: 1.2.14;
Don't rely on INT_MAX being unmapped. Use mmap to get a page and then unmap
it. Then use that address for msync.
 1.1 07-Jul-2011  jruoho branches: 1.1.2;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 13-Jan-2017  christos PR/51857: Ngie Cooper: mark signo __unused for -Wunused
 1.3 31-Mar-2013  christos branches: 1.3.10;
add more test cases for nanosleep
 1.2 31-Mar-2012  jruoho branches: 1.2.2;
Note PR bin/14558.
 1.1 07-Jul-2011  jruoho branches: 1.1.2;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.2.1 23-Jun-2013  tls resync from head
 1.3.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.7 26-Jun-2020  jruoho Reference PRs consistently.
 1.6 27-Dec-2019  msaitoh s/inital/initial/
 1.5 13-Jan-2017  christos branches: 1.5.14;
Don't play with "../.." in includes for h_macros.h; deal with it centrally.
Minor fixes.
 1.4 13-Jan-2017  christos PR/51858: Ngie Cooper: don't leak buf
 1.3 31-Oct-2011  christos branches: 1.3.24;
Move all pipe2 tests to a separate file.
 1.2 20-Oct-2011  njoly New testcase that check for close-on-exec flag on pipe2 syscall.
 1.1 15-Oct-2011  jruoho Move the pipe(2) test to the right place.
 1.3.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10 17-Jul-2025  kre ATF test additions for O_CLOFORK.

These are Ricardo Branco's ATF test modifications for O_CLOFORK
& SOCK_CLOFORK (with some FD_CLOFORK included).

These have all been made able to be built & run in an environment
where O_CLOFORK (etc) are not yet visible to userland.
 1.9 13-Jan-2017  christos branches: 1.9.30;
PR/51859: Ngie Cooper: use closefrom/restore RLIMIT_NOFILE when done
 1.8 16-May-2012  jruoho branches: 1.8.14;
Remove also redundant comment (the reference to the PR is already in the
metadata).
 1.7 16-May-2012  martin Simplify the test for PR kern/4645 and make it independend of resource
settings.
 1.6 16-May-2012  wiz Fix typo in comment.
 1.5 16-May-2012  martin Enable the test for PR kern/46457 now that it does not crash the
kernel any more.
 1.4 16-May-2012  jruoho Add a case for PR kern/46457. This is skipped for the time being, as it
reproduces the panic described in the PR.
 1.3 28-Jan-2012  christos branches: 1.3.2;
add a signopipe test
 1.2 31-Oct-2011  christos branches: 1.2.2;
make this work
 1.1 31-Oct-2011  christos Move all pipe2 tests to a separate file.
 1.2.2.2 23-May-2012  yamt sync with head.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 19-May-2012  riz Pull up following revision(s) (requested by martin in ticket #270):
sys/kern/sys_pipe.c: revision 1.136
tests/lib/libc/sys/t_pipe2.c: revision 1.4
tests/lib/libc/sys/t_pipe2.c: revision 1.5
tests/lib/libc/sys/t_pipe2.c: revision 1.6
tests/lib/libc/sys/t_pipe2.c: revision 1.7
Make sure we can deliver two file descriptors for pipe2() before we set
up anything special (like close on exec).
Fixes PR kern/46457.
Add a case for PR kern/46457. This is skipped for the time being, as it
reproduces the panic described in the PR.
Enable the test for PR kern/46457 now that it does not crash the
kernel any more.
Fix typo in comment.
Simplify the test for PR kern/4645 and make it independend of resource
settings.
 1.8.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.30.1 02-Aug-2025  perseant Sync with HEAD
 1.12 10-Feb-2025  riastradh t_poll: Extend the hangup tests to ptys too.

Of course, ptys work slightly differently from pipes and fifos and
sockets, presumably for hysterical raisins...

While here: add a more detailed comment to each xfail for the reason
why I think it is broken.

PR kern/59056: poll POLLHUP bugs
 1.11 09-Feb-2025  riastradh t_poll: Expand tests of polling when other endpoint is closed.

This covers fifos, pipes, and sockets; reads and writes; and polling
when the endpoint is already closed as well as sleeping until the
endpoint is closed after a delay.

Unfortunately, there is disagreement right now between:

(a) POSIX,
(b) our poll(2) man page, and
(c) our implementation,

for many of these cases. And we recently changed the behaviour of
poll(2) on fifos between 9 and 10 (PR kern/56429: poll(2) should
yield POLLHUP when last writer to a fifo close()'s it) but didn't get
it quite right.

So I've annotated these test cases with xfails for all the cases I
think we're currently doing wrong -- under a justification from some
combination of POSIX, our own documentation, and/or a reasonable
interpretation of what the semantics _should_ be based on how read(2)
and write(2) will behave. These are mostly edge cases:

1. [pollclosed_pipe_*_write*] When the read side of a pipe is closed,
poll(2) on the write side currently returns POLLHUP|POLLOUT, which
POSIX forbids because it requires POLLHUP to be mutually exclusive
with POLLOUT. And our man page concurs with POSIX on this rule,
and has for a long time (going as far back as NetBSD 1.3 or
earlier, judging by https://man.NetBSD.org/NetBSD-1.3/poll.2).

=> Fixing this won't change whether anything wakes up earlier or
later -- it will only change which bits are set when the
wakeups happen.

2. [pollclosed_fifo*_immediate_readsome] When the write side of a
fifo was previously open with the read side, and has since been
closed before calling poll(2), poll(2) on the read side returns 0
instead of POLLHUP|POLLIN as it is expected to, even though
read(2) will return EOF without blocking.

=> Fixing this may lead to more wakeups than before, but only in
cases where read(2) would actually return immediately anyway.

3. [pollclosed_fifo*_delayed_*_read] When the write side of a fifo is
closed, poll(2) on the read side returns POLLHUP|POLLIN, as it is
expected to. But this state currently isn't persistent, even
though the behaviour of read(2) in returning EOF without blocking
is persistent.

=> Fixing this may lead to more wakeups than before, but only in
cases where read(2) would actually return immediately anyway.

That said, it turns out that we are correct, according to POSIX, in
not setting POLLHUP on a socket whose peer has been closed: POLLHUP
is only for devices, pipes, and FIFOs. So one of the issues I
reported in PR 59056 turns out to be bogus. (Also POLLHUP is only
for the reader side anyway, not for the writer side.)

https://pubs.opengroup.org/onlinepubs/9799919799/functions/poll.html

PR kern/59056: poll POLLHUP bugs
 1.10 09-Feb-2025  riastradh t_poll: Tweak to improve diagnostics.

PR kern/59056: poll POLLHUP bugs
 1.9 09-Feb-2025  riastradh t_poll: Make sure POLLOUT is clear when testing POLLHUP.

POLLOUT and POLLHUP are mutually exclusive in POSIX. Also, we're
only polling for POLLIN anyway.

PR kern/59056: poll POLLHUP bugs
 1.8 02-Oct-2021  thorpej branches: 1.8.4;
- Strenghen the poll(2) fifo_inout test to ensure that once the reader
has read enough that exactly PIPE_BUF space is available that the FIFO
becomes writable again.
- When creating a FIFO, ensure that the receive low water mark is 1
(a FIFO must be readable when at least 1 byte is available); this
was already the case implicitly, but this makes it explicit.
- Similarly, set the send low water mark to PIPE_BUF to ensure that
the pipe is writable when at least PIPE_BUF bytes of space are available
in the send buffer. Without this change, the strengthened test case
above does not pass (the default send low water mark is larger than
PIPE_BUF; see soreserve()).
- Make the same low water mark changes to the PIPE_SOCKETPAIR case.
 1.7 02-Oct-2021  thorpej Add a fifo_inout test case that validates the expected POLLIN / POLLOUT
behavior for FIFOs:
- A FIFO is readable so long as at least 1 byte is available.
- A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF)
space is avaiable.

This will be cloned for a forthcoming kevent test case.
 1.6 02-Oct-2021  thorpej In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a
new writer appears.
 1.5 02-Oct-2021  thorpej - fifo_poll(): If the last writer has disappeared, detect this and return
POLLHUP, per POSIX.
- fifo_close(): Use the new fifo_socantrcvmore(), which is like the
garden-variety socantrcvmore(), except it specifies POLL_HUP rather
than POLL_IN (so the correct code for SIGIO is sent).
- sowakeup(): Allow POLL_HUP as a code (notifies poll'ers with POLLHUP).
- Add test cases for correct POLLHUP behavior with FIFOs.

Fixes PR kern/56429.
 1.4 17-Jul-2020  kamil Add ppoll() a compatibility wrapper around pollts(2)

Submitted by Apurva Nandan.
 1.3 18-Mar-2012  jruoho branches: 1.3.34;
Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.2 15-Oct-2011  jruoho branches: 1.2.2;
Follow the design principles of tests(7) by merging 't_poll3w' to 't_poll'
as a test case instead of separate file.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.34.2 04-Oct-2021  martin Pull up following revision(s) (requested by thorpej in ticket #1351):

sys/miscfs/fifofs/fifo_vnops.c: revision 1.88
sys/kern/uipc_syscalls.c: revision 1.201
tests/lib/libc/sys/t_poll.c: revision 1.6
tests/lib/libc/sys/t_poll.c: revision 1.7
tests/lib/libc/sys/t_poll.c: revision 1.8

- Strenghen the poll(2) fifo_inout test to ensure that once the reader
has read enough that exactly PIPE_BUF space is available that the FIFO
becomes writable again.
- When creating a FIFO, ensure that the receive low water mark is 1
(a FIFO must be readable when at least 1 byte is available); this
was already the case implicitly, but this makes it explicit.
- Similarly, set the send low water mark to PIPE_BUF to ensure that
the pipe is writable when at least PIPE_BUF bytes of space are available
in the send buffer. Without this change, the strengthened test case
above does not pass (the default send low water mark is larger than
PIPE_BUF; see soreserve()).
- Make the same low water mark changes to the PIPE_SOCKETPAIR case.

In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a
new writer appears.

Add a fifo_inout test case that validates the expected POLLIN / POLLOUT
behavior for FIFOs:
- A FIFO is readable so long as at least 1 byte is available.
- A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF)
space is avaiable.
This will be cloned for a forthcoming kevent test case.
 1.3.34.1 02-Oct-2021  martin Pull up following revision(s) (requested by thorpej in ticket #1350):

sys/kern/uipc_socket2.c: revision 1.140
tests/lib/libc/sys/t_poll.c: revision 1.5
sys/miscfs/fifofs/fifo_vnops.c: revision 1.87

- fifo_poll(): If the last writer has disappeared, detect this and return
POLLHUP, per POSIX.
- fifo_close(): Use the new fifo_socantrcvmore(), which is like the
garden-variety socantrcvmore(), except it specifies POLL_HUP rather
than POLL_IN (so the correct code for SIGIO is sent).
- sowakeup(): Allow POLL_HUP as a code (notifies poll'ers with POLLHUP).
- Add test cases for correct POLLHUP behavior with FIFOs.

Fixes PR kern/56429.
 1.8.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 01-Aug-2023  gutteridge t_pollts.c: fix typo in a description string (NFC)
 1.1 17-Jul-2020  kamil Add ppoll() a compatibility wrapper around pollts(2)

Submitted by Apurva Nandan.
 1.4 06-Apr-2025  riastradh t_posix_fadvise: Don't check whether errno is preserved.

I can find no guarantee in POSIX about posix_fadvise preserving
errno; until such language is found I'm going to assume there is no
such guarantee.

What is happening is that, sometimes, rump_sys_posix_fadvise waits on
a mutex or condvar, which uses _lwp_park internally, which sometimes
wakes up early with EALREADY because a wakeup was already pending for
the thread by the time it entered _lwp_park. And that EALREADY is
delivered by _lwp_park via errno.

PR kern/53931: posix_fadvise_reg test case fails randomly on real
hardware
 1.3 19-Jun-2018  gson branches: 1.3.18;
No semicolon after macro do ... while (0) wrapper.
 1.2 13-Jan-2017  christos branches: 1.2.12;
Don't play with "../.." in includes for h_macros.h; deal with it centrally.
Minor fixes.
 1.1 15-Oct-2011  jruoho branches: 1.1.24;
Move the posix_fadvise(2) test to the right place.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.3.18.1 02-Aug-2025  perseant Sync with HEAD
 1.1 31-Jan-2015  christos PR/49617: Kirk Russell: posix_fallocate() should be returning an error on
failure, without setting errno.
 1.1 17-Jul-2020  kamil Add ppoll() a compatibility wrapper around pollts(2)

Submitted by Apurva Nandan.
 1.7 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Sprinkle improved diagnostics.

This should make it easier to look at the test failure output and
figure out what's going on.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.6 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.5 24-May-2022  andvar branches: 1.5.4;
s/estabilishing/establishing/ in copy pasted comment.
 1.4 14-May-2018  kamil Revert previous change in t_ptrace.c

By a mistake this file started to include <sys/mman.h>
This is not needed.

The include was intended to be add just in t_ptrace_wait.c.

Sponsored by <The NetBSD Foundation>
 1.3 13-May-2018  kamil Add a new ptrace(2) ATF exploit for: CVE-2018-8897 (POP SS debug exception)

The original expolit and mitigation have been developed by Maxime Villard.

I've reworked the shared code and adapted for the ATF context.
I've included PIE-aware version (RIP/EIP relative) and introduced
additional comments to the explanation how to trigger the flaw.

This test passes on NetBSD/8.99.17.

Sponsored by <The NetBSD Foundation>
 1.2 29-Apr-2018  kamil Add two new ptrace(2) ATF tests

Added:

- traceme_pid1_parent
Assert that a process cannot mark its parent a debugger twice

- traceme_twice
Verify that PT_TRACE_ME is not allowed when our parent is PID1

All tests pass.

Sponsored by <The NetBSD Foundation>
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.14;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.14.2 21-May-2018  pgoyette Sync with HEAD
 1.1.14.1 02-May-2018  pgoyette Synch with HEAD
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.5.4.1 02-Aug-2025  perseant Sync with HEAD
 1.13 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.12 08-Jan-2020  mgorny branches: 1.12.14;
Combine x86 register tests into unified test function

Reduce the code duplication and improve maintainability of x86 register
tests by combining all of them to a single base function.
 1.11 04-Jun-2019  mgorny Add more debug to register writing tests
 1.10 10-May-2019  mgorny Add tests for PT_SETREGS
 1.9 06-May-2019  christos fix unused variable warnings.
 1.8 05-May-2019  mgorny Introduce tests for reading r8..r15 registers.
 1.7 05-May-2019  mgorny Add tests for reading pre-set general purpose register values via PT_GETREGS.

Add new tests verifying that PT_GETREGS provides correct register values
from the underlying program. The test uses inline assembly in the child program
to set registers to well-known constants, then compares the results obtained
via PT_GETREGS against them.

Reviewed by kamil.
 1.6 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.5 26-May-2018  kamil branches: 1.5.2;
Port the CVE 2018-8897 mitigation to i386 ATF ptrace(2) tests

On i386 there is no need to switch execution mode.
Use 0x23 SS selector for i386, amd64 used 0x4f.

Based on pointers from <maxv>.

Sponsored by <The NetBSD Foundation>
 1.4 14-May-2018  kamil Simplify the x86_64_cve_2018_8897 ATF ptrace(2) test

Do not call _exit() from the child, ad this code shall not be reached.
Put there assert().

No functional change. The test still passes.

Sponsored by <The NetBSD Foundation>
 1.3 13-May-2018  kamil Add a new ptrace(2) ATF exploit for: CVE-2018-8897 (POP SS debug exception)

The original expolit and mitigation have been developed by Maxime Villard.

I've reworked the shared code and adapted for the ATF context.
I've included PIE-aware version (RIP/EIP relative) and introduced
additional comments to the explanation how to trigger the flaw.

This test passes on NetBSD/8.99.17.

Sponsored by <The NetBSD Foundation>
 1.2 14-Dec-2017  christos branches: 1.2.2;
sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.8;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.8.1 25-Feb-2018  snj Pull up following revision(s) (requested by martin in ticket #586):
tests/lib/libc/sys/t_ptrace_amd64_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_i386_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_wait.c: 1.10-1.20
tests/lib/libc/sys/t_ptrace_x86_wait.h: 1.2-1.3
PR kern/52167 strikes on sparc64 too.
--
Temporarily disable t_ptrace_wait*::resume1 in ATF tests
It hangs forever on releng machines.
Sponsored by <The NetBSD Foundation>
--
Remove expected failure (fixed in kern_sig.c 1.339)
--
sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
--
Add expected failures.
--
make it fail instead of hang under qemu; XXX: need to investigate.
--
t_ptrace_wait*: Disable suspend* tests
These tests can hang the system. These interfaces will be improved and
temporarily disable them.
--
ptrace atf: Clanup reports of failures
Mark resume* suspend* tests as expected failure and link with PR 51995.
Sponsored by <The NetBSD Foundation>
--
report which errno failed
--
atf: t_ptrace_wait: Mark attach2 as racy
--
atf: ptrace: Temporarily disable signal3 as it breaks now on some ports
This test is marked as failing with: PR kern/51918.
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_amd64_wait.h was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_amd64_wait.h was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.2.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.2.2.1 21-May-2018  pgoyette Sync with HEAD
 1.5.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5.2.1 10-Jun-2019  christos Sync with HEAD
 1.12.14.1 02-Aug-2025  perseant Sync with HEAD
 1.2 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 04-May-2020  kamil branches: 1.1.12;
Move byte transfer tests out of t_ptrace_wait.c to t_ptrace_bytetransfer_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.1.12.1 02-Aug-2025  perseant Sync with HEAD
 1.4 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.3 11-May-2020  kamil branches: 1.3.12;
Fix potential race in ptrace(2) clone(2) tests

Instead of comparing old and new signal mask, just after the cloning
operation, check whether the expected signal is still masked and in
another test whether it is still ignored.

Catch up after t_ptrace_fork_wait.h r. 1.2.
 1.2 04-May-2020  kamil Bump (c) year
 1.1 04-May-2020  kamil Move clone() tests out of t_ptrace_wait.c to t_ptrace_clone_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.3.12.1 02-Aug-2025  perseant Sync with HEAD
 1.10 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.9 29-Jun-2024  rin branches: 1.9.2;
core_dump_procinfo: Fix false positive for vax

Increment PC after trapped by `bpt`, as done for many other platforms.
 1.8 24-Aug-2023  rin t_ptrace_core_wait.h: Increment PC after trap, also for riscv

Fix *:core_dump_procinfo tests for riscv64.
 1.7 09-Jun-2022  skrll There are two hard problems in computer science cache invalidation, naming
and off-by-one errors.

Fix a naming and off-by-one bug... Thanks to Tom Lane for spotting my typo.
 1.6 07-Jun-2022  skrll PR/56865: hppa: t_ptrace_core_wait test doesn't know it must advance PC after breakpoint

Add __hppa__ to the list of architectures that need to advance to the instruction
after the breakpoint

Thanks to Tom Lane for the fix.
 1.5 26-Mar-2022  martin Add sparc* to the list of architectures that need an explicit address
with PT_CONTINUE in this test.
 1.4 24-Jul-2021  rin For sh3, increment PC when PT_CONTINUE from trigger_trap(), as already
done for aarch64, arm, and powerpc. Otherwise, child is trapped to the
PTRACE_BREAKPOINT_ASM (== trapa) instruction indefinitely.

Fix tests/lib/libc/sys/t_ptrace_wait*:core_dump_procinfo.
 1.3 15-Oct-2020  rin Apply fix in rev 1.2 for core_dump_procinfo to aarch64 and arm:

http://cvsweb.netbsd.org/bsdweb.cgi/src/tests/lib/libc/sys/t_ptrace_core_wait.h#rev1.2

> For powerpc, program counter is not automatically incremented by trap
> instruction. We cannot increment PC in the trap handler, which breaks
> applications depending on this behavior, e.g., GDB.

This statement is true for aarch64 and arm.

Also, use PTRACE_BREAKPOINT_SIZE instead of hard-coded 4 to address
instruction next to PC.

OK ryo
 1.2 24-Jun-2020  rin Fix core_dump_procinfo tests for powerpc, for which child process was
stalled indefinitely in trap instruction even after PT_CONTINUE.

For powerpc, program counter is not automatically incremented by trap
instruction. We cannot increment PC in the trap handler, which breaks
applications depending on this behavior, e.g., GDB.

Therefore, we need to pass (PC + 4) instead of (void *)1 (== PC) to
PT_CONTINUE when child process traps itself.
 1.1 05-May-2020  kamil Move core tests out of t_ptrace_wait.c to t_ptrace_core_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 05-May-2020  kamil branches: 1.1.12;
Move eventmask tests out of t_ptrace_wait.c to t_ptrace_eventmask_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.1.12.1 02-Aug-2025  perseant Sync with HEAD
 1.1 05-May-2020  kamil Move exec() tests out of t_ptrace_wait.c to t_ptrace_exec_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.8 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.7 09-Jun-2020  kamil branches: 1.7.12;
Add fork/vfork/posix_spawn tests for processes within pgrp

New tests:
- fork_setpgid
- vfork_setpgid
- posix_spawn_setpgid
- unrelated_tracer_fork_setpgid
- unrelated_tracer_vfork_setpgid
- unrelated_tracer_posix_spawn_setpgid

These tests trigger a kernel assert for pg_jobc going negative.

The tests are temporarily skipped.
 1.6 16-May-2020  kamil Ignore interception of SIGCHLD signals in the debugger

Set SIGPASS for SIGCHLD for the traced child in the following tests:
- unrelated_tracer_fork*
- unrelated_tracer_vfork*
- unrelated_tracer_posix_spawn*

There is a race that SIGCHLD might be blocked during forking and dropped.

PR/55241 by Andreas Gustafsson
 1.5 16-May-2020  kamil Fix typo in test names

Noted by <joerg>
 1.4 16-May-2020  kamil Ignore interception of SIGCHLD signals in the debugger

Set SIGPASS for SIGCHLD for the traced child in the following tests:

- posix_spawn_singalmasked
- posix_spawn_singalignored
- fork_singalmasked
- fork_singalignored
- vfork_singalmasked
- vfork_singalignored
- vforkdone_singalmasked
- vforkdone_singalignored

There is a race that SIGCHLD might be blocked during forking and dropped.

PR/55241 by Andreas Gustafsson
 1.3 14-May-2020  kamil Ignore interception of the SIGCHLD signals.

SIGCHLD once blocked is discarded by the kernel as it has the
SA_IGNORE property. During the fork(2) operation all signals can be
shortly blocked and missed (unless there is a registered signal
handler in the traced child). This leads to a race in this test if
there would be an intention to catch SIGCHLD.

Fixes PR lib/55241 by Andreas Gustafsson
 1.2 11-May-2020  kamil Fix race in fork_singalmasked

ELF RTLD after rtld.c r. 1.204 introduced locking that wraps the fork
syscall. This locking changes signal mask of the calling process during
the forking process.

Instead of comparing old and new signal mask, just after the forking
operation, check whether the expected signal is still masked and in
another test whether it is still ignored.
 1.1 04-May-2020  kamil Move fork/vfork/posix_spawn tests out of t_ptrace_wait.c to t_ptrace_fork_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.7.12.1 02-Aug-2025  perseant Sync with HEAD
 1.10 08-Jan-2020  mgorny Combine x86 register tests into unified test function

Reduce the code duplication and improve maintainability of x86 register
tests by combining all of them to a single base function.
 1.9 04-Jun-2019  mgorny Add more debug to register writing tests
 1.8 10-May-2019  mgorny Add tests for PT_SETREGS
 1.7 06-May-2019  christos fix unused variable warnings.
 1.6 05-May-2019  mgorny Reintroduce i386 tests for general-purpose registers, without MMX req

Reintroduce the test for reading i386 general-purpose register values
from the debugged program. This time it's split into one test for the six
registers not normally used by the compiler (eax..edx, esi, edi), and another
for ebp, esp. This leaves enough free registers for the latter to work
without MMX.
 1.5 05-May-2019  mgorny Revert i386_regs_gp_read as it fails on non-MMX systems.
 1.4 05-May-2019  mgorny Add tests for reading pre-set general purpose register values via PT_GETREGS.

Add new tests verifying that PT_GETREGS provides correct register values
from the underlying program. The test uses inline assembly in the child program
to set registers to well-known constants, then compares the results obtained
via PT_GETREGS against them.

Reviewed by kamil.
 1.3 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.2 14-Dec-2017  christos branches: 1.2.4;
sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.8;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.8.1 25-Feb-2018  snj Pull up following revision(s) (requested by martin in ticket #586):
tests/lib/libc/sys/t_ptrace_amd64_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_i386_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_wait.c: 1.10-1.20
tests/lib/libc/sys/t_ptrace_x86_wait.h: 1.2-1.3
PR kern/52167 strikes on sparc64 too.
--
Temporarily disable t_ptrace_wait*::resume1 in ATF tests
It hangs forever on releng machines.
Sponsored by <The NetBSD Foundation>
--
Remove expected failure (fixed in kern_sig.c 1.339)
--
sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
--
Add expected failures.
--
make it fail instead of hang under qemu; XXX: need to investigate.
--
t_ptrace_wait*: Disable suspend* tests
These tests can hang the system. These interfaces will be improved and
temporarily disable them.
--
ptrace atf: Clanup reports of failures
Mark resume* suspend* tests as expected failure and link with PR 51995.
Sponsored by <The NetBSD Foundation>
--
report which errno failed
--
atf: t_ptrace_wait: Mark attach2 as racy
--
atf: ptrace: Temporarily disable signal3 as it breaks now on some ports
This test is marked as failing with: PR kern/51918.
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_i386_wait.h was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_i386_wait.h was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.2.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.4.1 10-Jun-2019  christos Sync with HEAD
 1.2 02-May-2025  riastradh branches: 1.2.4;
tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 17-Dec-2024  christos PR/58896: Martin Husemann: Demonstrate that a PT_STOPed process could not be
PT_KILLed.
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 02-May-2025  perseant file t_ptrace_kill.c was added on branch perseant-exfatfs on 2025-08-02 05:58:07 +0000
 1.1 04-May-2020  kamil Move kill()-like tests out of t_ptrace_wait.c to t_ptrace_kill_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 05-May-2020  kamil branches: 1.1.12;
Move LWP tests out of t_ptrace_wait.c to t_ptrace_lwp_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.1.12.1 02-Aug-2025  perseant Sync with HEAD
 1.1 05-May-2020  kamil Move misc tests out of t_ptrace_wait.c to t_ptrace_misc_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.5 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.4 14-Oct-2021  gson branches: 1.4.4;
Remove trailing whitespace
 1.3 11-May-2020  kamil Simplify previous

Emit SIGKILL without a loop and without checking for exact process status
once it is collected.
 1.2 11-May-2020  kamil Do not fail when trying to kill a dying process

A dying process can disappear for a while. Rather than aborting, retry
sending SIGKILL to it.
 1.1 04-May-2020  kamil Move register tests out of t_ptrace_wait.c to t_ptrace_register_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.4.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7 02-May-2025  riastradh t_ptrace_*: Turn debug output back off.

Even with the output reduction I recently implemented, this seems to
be filling up the releng testbed disk with excess output. Not
completely obviated by the recent diagnostic improvements -- e.g.,
the traceme_signalmasked_crash_fpe test still uses DPRINTF for some
output that isn't available any other way. But let's get the tests
running to completion again before improving that.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.6 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.5 01-May-2025  riastradh t_ptrace_*.c: Make debug output a little less verbose.

Maybe it will stop overflowing the releng testbed file systems this
way.
 1.4 29-Apr-2025  riastradh t_ptrace_wait, t_ptrace_sigchld: Enable debug output.

Otherwise failures lead only to nearly useless output like:

FAILED: /work/src/tests/lib/libc/sys/t_ptrace_signal_wait.h:852: info.psi_siginfo.si_signo != sig

What _was_ si_signo, you ask? Sorry, you have to guess or run the
test yourself!
 1.3 05-May-2020  kamil branches: 1.3.12;
Skip traceme_raise* tests rather than failing upfront

This avoid reporting the tests as unexpected failure.
 1.2 06-Mar-2020  kamil branches: 1.2.2;
Remove duplicated lines
 1.1 06-Mar-2020  kamil Add new ptrace(2) test file

t_ptrace_sigchld - for SIGCHLD handler + ptrace(2).

Right now a single test is enabled (raise(SIGKILL)) and marked as failed
as it never finishes as the child is never collected before exiting the
parent uninterested about its child (SA_NOCLDWAIT).
 1.2.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.2.1 06-Mar-2020  martin file t_ptrace_sigchld.c was added on branch phil-wifi on 2020-04-08 14:09:09 +0000
 1.3.12.1 02-Aug-2025  perseant Sync with HEAD
 1.2 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 05-May-2020  kamil branches: 1.1.12;
Move siginfo tests out of t_ptrace_wait.c to t_ptrace_siginfo_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.1.12.1 02-Aug-2025  perseant Sync with HEAD
 1.10 14-May-2025  riastradh t_ptrace_*: Fix softfloat conditionalization.

Evidently __SOFTFP__ is an armism.

Should improve the situation on sh3 and others.

PR misc/56820: Many FPE related tests fail on softfloat machines
 1.9 10-May-2025  riastradh t_ptrace_signal_wait.h: Add some more debug output for softfloat.

PR misc/56820: Many FPE related tests fail on softfloat machines
 1.8 02-May-2025  riastradh t_ptrace_*: More diagnostic output for assertion failures.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.7 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.6 27-Apr-2025  riastradh t_ptrace_wait*: Deal with quirk of softfloat trap SIGFPE delivery.

PR misc/56820: Many FPE related tests fail on softfloat machines
 1.5 19-Mar-2021  simonb branches: 1.5.10;
Sprinkle a few more \n's and the end of some debug printfs.
 1.4 22-Jun-2020  rin branches: 1.4.2;
Work around QEMU bug #1668041 differently, by which floating-point
division by zero is not correctly trapped for i386 and amd64:

https://bugs.launchpad.net/qemu/+bug/1668041

Make trigger_fpe() cause integer division by zero for x86, and
floating-point one for other architectures. Also, assertions for
si_code in *_crash_fpe tests are commented out for now. They
should be cleaned up after the bug is fixed.

Now, *_crash_fpe tests are working also on powerpc.

Suggested by kamil.
 1.3 22-Jun-2020  rin Turn trigger_fpe() back to integer division by zero for a while
until QEMU bug #1668041 is fixed:

https://bugs.launchpad.net/qemu/+bug/1668041

by which floating-point division by zero is not trapped correctly
both on amd64 and i386.

Skip *_crash_fpe tests on powerpc, where integer division by zero
is never trapped.
 1.2 17-Jun-2020  rin Let trigger_fpe() cause floating-point divide by zero exception, instead of
integer one, which is not trapped for powerpc and aarch64.

Note that it is checked in lib/libc/gen/t_siginfo whether integer divide by
zero is interpreted as SIGFPE or not.

Now, all *_crash_fpe tests pass for powerpc, and nothing changes for amd64
at least.
 1.1 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.4.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.5.10.1 02-Aug-2025  perseant Sync with HEAD
 1.1 04-May-2020  kamil Move PT_STEP tests out of t_ptrace_wait.c to t_ptrace_step_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.4 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.3 20-Mar-2023  hannken branches: 1.3.2;
Adjust pc/npc before syscall allowing EJUSTRETURN to return
to the next instruction. Only ERESTART should return to
the same instruction. Differences to sparc64 reduced.

Test t_ptrace_wait:syscallemu1 now passes on sparc.

Fixes PR kern/52166 "syscallemu does not work on sparc (32-bit)"

Ok: Martin Husemann
 1.2 21-Oct-2021  gson branches: 1.2.2;
Skip the lib/libc/sys/t_ptrace_waitid:syscall_signal_on_sce test case
with a reference to PR lib/55087. Marking it as an expected failure
would be more appropriate, but that doesn't work for test cases that
fail by timing out.
 1.1 04-May-2020  kamil Move syscall tests out of t_ptrace_wait.c to t_ptrace_syscall_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2.2.1 22-Mar-2023  martin Pull up following revision(s) (requested by hannken in ticket #124):

tests/lib/libc/sys/t_ptrace_syscall_wait.h: revision 1.3
sys/arch/sparc/sparc/syscall.c: revision 1.32
sys/arch/sparc/sparc/vm_machdep.c: revision 1.108

Adjust pc/npc before syscall allowing EJUSTRETURN to return
to the next instruction. Only ERESTART should return to
the same instruction. Differences to sparc64 reduced.

Test t_ptrace_wait:syscallemu1 now passes on sparc.

Fixes PR kern/52166 "syscallemu does not work on sparc (32-bit)"

Ok: Martin Husemann
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Sprinkle improved diagnostics.

This should make it easier to look at the test failure output and
figure out what's going on.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.2 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 05-May-2020  kamil branches: 1.1.12;
Move threads tests out of t_ptrace_wait.c to t_ptrace_threads_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.1.12.1 02-Aug-2025  perseant Sync with HEAD
 1.2 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.1 05-May-2020  kamil branches: 1.1.12;
Move topology tests out of t_ptrace_wait.c to t_ptrace_topology_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.1.12.1 02-Aug-2025  perseant Sync with HEAD
 1.195 02-May-2025  riastradh t_ptrace_*: Turn debug output back off.

Even with the output reduction I recently implemented, this seems to
be filling up the releng testbed disk with excess output. Not
completely obviated by the recent diagnostic improvements -- e.g.,
the traceme_signalmasked_crash_fpe test still uses DPRINTF for some
output that isn't available any other way. But let's get the tests
running to completion again before improving that.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.194 01-May-2025  riastradh t_ptrace_*.c: Make debug output a little less verbose.

Maybe it will stop overflowing the releng testbed file systems this
way.
 1.193 29-Apr-2025  riastradh t_ptrace_wait, t_ptrace_sigchld: Enable debug output.

Otherwise failures lead only to nearly useless output like:

FAILED: /work/src/tests/lib/libc/sys/t_ptrace_signal_wait.h:852: info.psi_siginfo.si_signo != sig

What _was_ si_signo, you ask? Sorry, you have to guess or run the
test yourself!
 1.192 01-Apr-2024  riastradh branches: 1.192.2;
elftoolchain: Be consistent about which ELF header files we use.

1. For tools that use elftoolchain: always use elftoolchain's
elfdefinitions.h. Don't even think about looking at the host's
sys/exec_elf.h, which makes no sense and should never happen.

(ELF tools that don't use elftoolchain, like m68k-elf2coff,
continue to use nbincludes/sys/exec_elf.h. But no more nbincludes
hacks in elftoolchain.)

2. For kernel components (solaris, zfs, dtrace): always use
sys/exec_elf.h, even in Solaris components via sys/elf.h.
elfdefinitions.h is not wired up in the kernel build at all.

3. For most userland components that involve libelf: use
elfdefinitions.h via libelf header files (libelf.h, gelf.h).

libdtrace in particular requires _all_ R_* reloc type definitions,
but sys/exec_elf.h brings in only the _current machine's_ R_*
reloc type definitions. (While here: Use uintptr_t instead of
Elf_Addr for pointer-to-integer cast, since Elf_Addr is MD and
provided only by sys/exec_elf.h, not by elfdefinitions.h.)

And most userland components using libelf don't rely on any
properties of the current machine from sys/exec_elf.h, so they can
use libelf's elfdefinition.h.

Exceptions:

- dtrace drti.c relies on link.h -> link_elf.h -> sys/exec_elf.h,
but it also relies on sys/dtrace.h -> sys/elf.h ->
elfdefinitions.h like other userland components using sys/elf.h.

- kdump-ioctl.c uses sys/exec_elf.h directly and sys/dtrace.h ->
sys/elf.h -> elfdefinitions like other userland components using
sys/elf.h.

- t_ptrace_wait.c (via t_ptrace_core_wait.h) uses libelf to parse
core files, but relies on sys/exec_elf.h for struct
netbsd_elfcore_procinfo.

None of these exceptions needs all R_* reloc type definitions, so
as a workaround, we can just suppress libelf's elfdefinitions.h by
defining _SYS_ELFDEFINITIONS_H_ and use sys/exec_elf.h in these
exceptions.

And undo the whole BUILTIN_ELF_HEADERS mistake. This was:

- half bogus workarounds for missing build_install dependencies in
tools/Makefile, which are no longer missing now, and
- half futile attempt to use src/sys/sys/exec_elf.h via nbincludes in
tools involving libelf instead of libelf's elfdefinitions.h, which
collides.

Longer-term, we may wish to unify sys/exec_elf.h and libelf's
elfdefinitions.h, so we don't have to play these games.

But at least now the games are limited to three .c files (one of
which is generated by Makefile.ioctl-c), rather than haphazardly
applied tree-wide by monstrous kludges in widely used .h files with
broken hackarounds to get the tools build lurching to completion.
 1.191 05-May-2020  kamil Move misc tests out of t_ptrace_wait.c to t_ptrace_misc_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.190 05-May-2020  kamil Move core tests out of t_ptrace_wait.c to t_ptrace_core_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.189 05-May-2020  kamil Move siginfo tests out of t_ptrace_wait.c to t_ptrace_siginfo_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.188 05-May-2020  kamil Move threads tests out of t_ptrace_wait.c to t_ptrace_threads_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.187 05-May-2020  kamil Move topology tests out of t_ptrace_wait.c to t_ptrace_topology_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.186 05-May-2020  kamil Move exec() tests out of t_ptrace_wait.c to t_ptrace_exec_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.185 05-May-2020  kamil Move LWP tests out of t_ptrace_wait.c to t_ptrace_lwp_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.184 05-May-2020  kamil Remove the duplicate ATF_TP_ADD_TC() entries

Event mask tests are already defined in
ATF_TP_ADD_TCS_PTRACE_WAIT_EVENTMASK().
 1.183 05-May-2020  kamil Move eventmask tests out of t_ptrace_wait.c to t_ptrace_eventmask_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.182 04-May-2020  kamil Remove the duplicate ATF_TP_ADD_TC() entries

Byte transfer tests are already defined in
ATF_TP_ADD_TCS_PTRACE_WAIT_BYTETRANSFER().
 1.181 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.180 04-May-2020  kamil Move fork/vfork/posix_spawn tests out of t_ptrace_wait.c to t_ptrace_fork_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.179 04-May-2020  kamil Move clone() tests out of t_ptrace_wait.c to t_ptrace_clone_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.178 04-May-2020  kamil Move byte transfer tests out of t_ptrace_wait.c to t_ptrace_bytetransfer_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.177 04-May-2020  kamil Move kill()-like tests out of t_ptrace_wait.c to t_ptrace_kill_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.176 04-May-2020  kamil Move PT_STEP tests out of t_ptrace_wait.c to t_ptrace_step_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.175 04-May-2020  kamil Move syscall tests out of t_ptrace_wait.c to t_ptrace_syscall_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.174 04-May-2020  kamil Move register tests out of t_ptrace_wait.c to t_ptrace_register_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.173 24-Apr-2020  kamil Reduce assumptions about LWP numbers
 1.172 24-Apr-2020  thorpej Update for new LWP behavior -- as of 9.99.59, the LWP ID of a single-LWP
process is the PID, not 1.
 1.171 17-Apr-2020  kamil Switch from C11 specific static_assert() to __CTASSERT()
 1.170 14-Apr-2020  kamil Add timeout to syscall_signal_on_sce that hangs from time to time
 1.169 07-Mar-2020  christos Try to fix the build. This is why all those inlines should really be in a
separate file as regular function. The code is too large and hard to manage
this way, and only increases in complexity as time goes by.
 1.168 06-Mar-2020  kamil Move macros wrapping functions from msg.h into msg.h

This makes code reusing easier.
 1.167 01-Mar-2020  kamil Add new signal trap entry tests in t_ptrace_wait*

New tests:
- syscall_signal_on_sce
- syscall_detach_on_sce

The first one fails as a signal emitted to the child is caught by the
debugger.

The second one passes.
 1.166 24-Feb-2020  kamil Add new test in t_ptrace_wait*

New test: syscall_killed_on_sce

Test passes correctly.
 1.165 22-Feb-2020  kamil Disable t_ptrace_wait* tests for MKSANITIZER/MKLIBCSANITIZER

A subset of tests is not compatible with the sanitizers.
 1.164 20-Feb-2020  kamil Minor changes to t_ptrace_wait*

Add check for security.models.extensions.user_set_dbregs in the
concurrent event tests.

Use unconditionally atf_tc_skip(); as the test is racy.
 1.163 19-Feb-2020  kamil Fix clang(1) build

Namespace a symbol that can be unused.
 1.162 13-Feb-2020  mgorny Enable combined breakpoint, watchpoint and signal tests
 1.161 13-Feb-2020  mgorny Extend concurrent events test to watchpoints
 1.160 13-Feb-2020  mgorny Extend concurrent events test to breakpoints

Add testing for concurrent breakpoint hits. The code is currently
x86-specific but since it reuses most of the generic concurrent event
test code, it's put in t_ptrace_wait.c with arch-specific hooks.
 1.159 13-Feb-2020  mgorny Include LWP events in concurrent event test

LWP events will be necessary when breakpoint/watchpoint support is added
to the test. However, they also benefit us by testing whether TRAP_LWP
events do not break signal reporting.
 1.158 13-Feb-2020  mgorny Test whether signal handler is called in concurrent bombarding
 1.157 13-Feb-2020  mgorny Extend concurrent signal tests to pass signal back to the thread
 1.156 13-Feb-2020  mgorny Generalize thread_concurrent_signals to a generic factory

Build thread_concurrent_signals on a generic parametrized
thread_concurrent_test() function. At first, this permits adjusting
the number of running signal threads but in the followup commits
support for different concurrent events (breakpoints, watchpoints)
and different signal handling will be added.
 1.155 11-Feb-2020  kamil Rewrite the t_ptrace_wait resume1 test

Switch to pthread functions.
Rename to 'resume'.
Synchronize the threads with pthread barriers.
Avoid race in the test.

Test passes correctly.

Fixes PR bin/54893 by Andreas Gustafsson
 1.154 10-Feb-2020  kamil Rename suspend2 to suspend_no_deadlock
 1.153 05-Feb-2020  kamil Refactor signal9 and signal10 tests in t_ptrace_wait*

Remove signal9 and signal10. Reimplement the idea of these test in new
trace_thread_lwpexit_masked_sigtrap, trace_thread_lwpcreate_masked_sigtrap
and trace_thread_lwpcreate_and_exit_masked_sigtrap.

This removes 2 tests directly using low-level lwp APIs.
 1.152 04-Feb-2020  kamil Disable debug code
 1.151 04-Feb-2020  kamil Add new ATF ptrace(2) test in t_ptrace_wait*

threads_and_exec - verify that the expected LWP events are reported for a
multithreaded process that calls execve(2).

Test passes.
 1.150 04-Feb-2020  kamil Add new ATF tests for unrelated tracer in t_ptrace_wait*

New tests:
- unrelated_tracer_posix_spawn_detach_spawner
- unrelated_tracer_fork_detach_forker
- unrelated_tracer_vfork_detach_vforker
- unrelated_tracer_vfork_detach_vforkerdone
- unrelated_tracer_posix_spawn_kill_spawner
- unrelated_tracer_fork_kill_forker
- unrelated_tracer_vfork_kill_vforker
- unrelated_tracer_vfork_kill_vforkerdone

All tests pass.
 1.149 29-Jan-2020  kamil Add new fork/vfork/posix_spawn ATF tests in t_ptrace_wait*

Add unrelated tracer variation of tests: fork1-16, vfork1-16,
posix_spawn1-16.

All tests pass.
 1.148 23-Jan-2020  martin Fix the build: access_regs_set_unaligned_pc_* tests depend on availability
of gpregs
 1.147 21-Jan-2020  kamil Add new ATF tests in t_ptrace_wait*

New tests:
- access_regs_set_unaligned_pc_0x1
- access_regs_set_unaligned_pc_0x3
- access_regs_set_unaligned_pc_0x7

The purpose of these tests is check whether unaligned PC can panic the
kernel. If there is a panic it is fine to return EINVAL on PT_SETREGS.
New tests check respectively pc |= 0x1, pc |= 0x3 and pc |= 0x7.

Inspired by https://marc.info/?l=openbsd-bugs&m=107558043319084&w=2

While there fix access_regs6 to really test PT_SETREGS.
 1.146 08-Jan-2020  mgorny Fix alignment when reading core notes

Both desc and note header needs to be aligned. Therefore, we need
to realign after skipping past desc as well.

While at it, fix the other alignment fix to use roundup() macro.
 1.145 25-Dec-2019  kamil Read TLS base pointer with _lwp_getprivate()

This avoid usage of fast versions that are mostly internal to RTLD.
 1.144 24-Dec-2019  kamil Define _RTLD_SOURCE in t_ptrace_wait.c

The __lwp_gettcb_fast() and __lwp_getprivate_fast() functions are
namespaced on a selection of ports.
 1.143 24-Dec-2019  kamil Introduce PT_LWPSTATUS + PT_LWPNEXT, obsolete PT_LWPINFO

PT_LWPINFO is a legacy ptrace(2) operation that was originally intended
to retrieve the thread (LWP) information inside a traced process.

It has a number of flaws and is confused with PT_LWPINFO from FreeBSD.

PT_LWPSTATUS and PT_LWPNEXT address the problems (shortly by: rename,
removal of pl_event) and introduces new features: signal context
(pl_sigpend, pl_sigmask), LWP name (pl_name), LWP TLS base address
(pl_private). The private pointer was so far missing information for
a debugger.

PT_LWPSTATUS@nnn is now shipped with core(5) files and contain LWP specific
information, so far missed in the core(5) files.

PT_LWPSTATUS retrieves LWP information for the prompted thread.
PT_LWPNEXT retrieves LWP information for the next thread, borrowing the
semantics from NetBSD specific PT_LWPINFO.

PT_LWPINFO is namespaced with __LEGACY_PT_LWPINFO and still available for
the foreseeable future, without plans of removing it.

Add ATF tests for PT_LWPSTATUS + PT_LWPNEXT.

Keep ATF tests for PT_LWPINFO.

Switch GDB to new API.

Proposed on tech-kern@.
 1.142 06-Dec-2019  kamil Log PID.LWP in t_ptrace_wait* tests for enabled debug

This is useful for multithreaded test scenarios.
 1.141 12-Nov-2019  kamil Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by <mgorny>, tested and tweaked by myself.
 1.140 21-Oct-2019  kamil Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*

LWP tests are now enabled always and confirmed to be stable.
 1.139 21-Oct-2019  kamil Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*

vfork(2) tests are now enabled always and confirmed to be stable.
 1.138 21-Oct-2019  mgorny Fix a race condition when handling concurrent LWP signals and add a test

Fix a race condition that caused PT_GET_SIGINFO to return incorrect
information when multiple signals were delivered concurrently
to different LWPs. Add a regression test that verifies that when 50
threads concurrently use pthread_kill() on themselves, the debugger
receives all signals with correct information.

The kernel uses separate signal queues for each LWP. However,
the signal context used to implement PT_GET_SIGINFO is stored in 'struct
proc' and therefore common to all LWPs in the process. Previously,
this member was filled in kpsignal2(), i.e. when the signal was sent.
This meant that if another LWP managed to send another signal
concurrently, the data was overwritten before the process was stopped.

As a result, PT_GET_SIGINFO did not report the correct LWP and signal
(it could even report a different signal than wait()). This can be
quite reliably reproduced with the number of 20 LWPs, however it can
also occur with 10.

This patch moves setting of signal context to issignal(), just before
the process is actually stopped. The data is taken from per-LWP
or per-process signal queue. The added test confirms that the debugger
correctly receives all signals, and PT_GET_SIGINFO reports both correct
LWP and signal number.

Reviewed by kamil.
 1.137 13-Oct-2019  kamil Fix race in t_ptrace_wait* LWP tests

Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.
 1.136 13-Oct-2019  kamil Enable TEST_LWP_ENABLED in t_ptrace_wait*

The LWP events (created, exited) are now reliable in my local tests.

PR kern/51420
PR kern/51995
 1.135 13-Oct-2019  kamil Bump the number of threads in LWP t_ptrace_wait*() tests from to 100

This is a torture, but on purpose to catch LWP_CREATED and LWP_EXITED bugs.
The threads do nothing other than calling sched_yield() in a loop.

MAXLWP is now defined to 2048 on all ports.

This change effects the following tests:

- trace_thread_nolwpevents
- trace_thread_lwpexit
- trace_thread_lwpcreate
- trace_thread_lwpcreate_and_exit
 1.134 02-Oct-2019  kamil Remove ATF t_ptrace_wait test suspend1

The tests verifies that a thread can be suspended by a debugger and later
resumed by a tracee.

This is an unwanted behavior and will be fixed soon.
 1.133 01-Oct-2019  kamil Merge PT_GET_PROCESS_STATE checks into traceme_raise ATF ptrace tests

Assert that PT_GET_PROCESS_STATE for !child and !lwp events returns
non-error and zeroed struct ptrace_state.

These checks are not really special to traceme_raise, it's just an
opportunity to reuse them in an existing tests without writing a dedicated
one.

This behavior is needed to maintain in 3rd party software (GDB).
 1.132 01-Oct-2019  kamil Add a few static asserts in t_ptrace_wait.c for conditions that must be kept

Assert that ptrace_state and siginfo_t's _ptrace_state are synchronized.
 1.131 01-Jul-2019  kamil branches: 1.131.2;
Avoid GCC warning on NetBSD/i386

Cast note_hdr.n_namesz to ssize_t through size_t to avoid potential
signedness bit shifts.
 1.130 30-Jun-2019  mgorny Add a test for verifying procinfo note inside coredumps.

Add a first test for triggering a core dump in the debugged process
(via PT_DUMPCORE) and verifying it. The test finds procinfo note
and checks its contents.

The core dump is processed through libelf. However, it only provides
for finding all note segments (or sections?). I had to implement
finding and processing individual notes myself. I've added
a core_find_note() function that will be reused in future tests.

Reviewed by kamil.
 1.129 26-Jun-2019  mgorny Implement PT_GETXSTATE and PT_SETXSTATE

Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE,
that provide access to the extended (and extensible) set of FPU
registers on amd64 and i386. At the moment, this covers AVX (YMM)
and AVX-512 (ZMM, opmask) registers. It can be easily extended
to cover further register types without breaking backwards
compatibility.

PT_GETXSTATE issues the XSAVE instruction with all kernel-supported
extended components enabled. The data is copied into 'struct xstate'
(which -- unlike the XSAVE area itself -- has stable format
and offsets).

PT_SETXSTATE issues the XRSTOR instruction to restore the register
values from user-provided 'struct xstate'. The function replaces only
the specific XSAVE components that are listed in 'xs_rfbm' field,
making it possible to issue partial updates.

Both syscalls take a 'struct iovec' pointer rather than a direct
argument. This requires the caller to explicitly specify the buffer
size. As a result, existing code will continue to work correctly
when the structure is extended (performing partial reads/updates).
 1.128 18-Jun-2019  kamil Allow to conditionally enable LWP ATF tests in t_ptrace_wait*

By default the tests are disabled.
 1.127 13-Jun-2019  kamil Enable vfork(2) ATF tests in t_ptrace_wait*

The racing issues are gone in my local setup.
 1.126 12-Jun-2019  kamil Add new ATF ptrace(2) tests for posix_spawn, reusing tests for fork/vfork

New tests:
- posix_spawn_detach_spawner
- posix_spawn_kill_spawner
- posix_spawn_singalmasked
- posix_spawn_singalignored

All test pass.
 1.125 11-Jun-2019  kamil Add new PTRACE_POSIX_SPAWN tests in ptrace(3)

Add test:
- eventmask_preserved_posix_spawn
- fork9..fork16
- vfork9..vfork16
- posix_spawn1..16

New tests verify semantics of PTRACE_POSIX_SPAWN.

All tests pass.
 1.124 10-Jun-2019  kamil Add posix_spawn(3) ATF tests in t_ptrace_wait*

New tests verify whether forking process reports forking events to a
debugger.

Right now there is no support in the kernel for this system.
 1.123 10-Jun-2019  kamil Add more verbosity to debug messages in t_ptrace_wait

Log func() file:line for each debug message.

Most messages are similar one with the other and this change allows easier
navigation in the code.
 1.122 25-May-2019  kamil Add new user_va0_disable* tests in t_ptrace_wait*

Add tests:
- user_va0_disable_pt_continue
- user_va0_disable_pt_syscall
- user_va0_disable_pt_detach

Assert that setting PC to 0x0 in PT_CONTINUE/PT_SYSCALL/PT_DETACH for
vm.user_va0_disable==0 is disallowed.
 1.121 09-May-2019  mgorny Add ptrace() tests for reading mm* and xmm* registers
 1.120 02-May-2019  kamil Adapt t_ptrace_wait* tests for recent kernel changes

Adapt AUXV reading loop to handle io.piod_len == 0 as EOF.

Temporarily disable trace_thread_lwpcreate until it will be verified that
it is stable.
 1.119 02-May-2019  kamil Rename and partially enable trace_thread ATF ptrace(2) tests

Rename trace_thrad[1234] to more meaningful names:

- trace_thread_nolwpevents
- trace_thread_lwpexit
- trace_thread_lwpcreate
- trace_thread_lwpcreate_and_exit

In my local tests LWP CREATE events work as expected.
LWP EXIT ones are still racy and keep them disabled racy.

PR kern/51995
 1.118 01-May-2019  kamil ATF ptrace(2) tests suspend1 and resume1 now pass

Verified on bare metal and in qemu.

PR kern/51995
 1.117 01-May-2019  kamil ATF ptrace(2) tests signal9 and signal10 now pass

PR kern/51918
 1.116 01-May-2019  kamil Add new fork/vfork ATF trests in t_ptrace_wait*

Add new tests:

- fork_detach_forker
- vfork_detach_vforker
- vfork_detach_vforkerdone
- fork_kill_forker
- vfork_kill_vforker
- vfork_kill_vforkerdone

All tests pass with recent kernel changes.
 1.115 30-Apr-2019  kamil Add new ATF ptrace(2) tests: bytes_transfer_eof

Assert that error is returned after attempt to read or write post EOF.
 1.114 25-Apr-2019  kamil Introduce check for the support of FPU exceptions

If FPU exceptions are unsupported, skip the SIGFPE crash tests.

Reuse code from tests/kernel/h_segv.c
 1.113 25-Apr-2019  kamil Do not allow 0 as ILL si_code as it's reserved for SI_USER
 1.112 25-Apr-2019  kamil In ATF t_ptrace_wait* SIGILL tests allow any si_code

These codes are not portable between CPUs and kernels.

Change the checks to return any valid si_code in the defined range of ILL
values.

PR port-sparc/54140 by Andreas Gustafsson
 1.111 19-Apr-2019  kamil Fix typo in TEST_VFORK_ENABLED

This allows building and running vfork(2) test scenarios correctly.
 1.110 17-Apr-2019  kamil Fix Clang/LLVM build in t_ptrace_wait.c

Do not compile functions that might be unused.
 1.109 15-Apr-2019  kamil Temporarily ifdef out PTRACE_VFORK and PTRACE_VFORKDONE tests

It's not reliable on all ports. sparc and evbarm are known to hang.

PR kern/54111 by Martin Husemann
 1.108 11-Apr-2019  kamil Add new tests in ATF t_prace_wait*

New tests:

- traceme_vfork_fork
- traceme_vfork_vfork

New tests assert that fork/vfork in vforked traced does not emit any
events.
 1.107 11-Apr-2019  kamil Add new tests traceme_vfork_clone* in ATF t_ptrace_wait*

Added tests:

- traceme_vfork_clone
- traceme_vfork_clone_vm
- traceme_vfork_clone_fs
- traceme_vfork_clone_files
- traceme_vfork_clone_sighand
- traceme_vfork_clone_vfork

All tests pass. Validate that children do not trigger any signals and dead
locks when traced by a vfork(2)ed parent.
 1.106 11-Apr-2019  kamil Validate that clone(2) is handled properly with more ptrace(2) ATF tests

New tests:

- clone[1-8]
- clone_vm[1-8]
- clone_fs[1-8]
- clone_files[1-8]
- clone_sighand[1-8] // disabled temporarily
- clone_vfork[1-8]

Assert that appropriate events are triggered for the combination of:

- PTRACE_FORK
- PTRACE_VFORK
- PTRACE_VFORK_DONE
 1.105 06-Apr-2019  kamil Simplify FORK_TEST in ATF t_ptrace_wait*

Reduce the scope of combinations that were planned to be tested from the
same function body.

NFCI
 1.104 05-Apr-2019  kamil Reenable tests vfork7 and vfork8 in ATF t_ptrace_wait*

These tests used to hang on SMP machines.

For experiment after recent changes reenable the tests.
 1.103 05-Apr-2019  kamil Add __clone(2) tests in t_ptrace_wait*

The __clone(2) API is a variation of fork(2)/vfork(2) operations.

New tests:
- clone_signalignored
- clone_signalmasked
- clone_vm_signalignored
- clone_vm_signalmasked
- clone_fs_signalignored
- clone_fs_signalmasked
- clone_files_signalignored
- clone_files_signalmasked
- clone_vfork_signalignored
- clone_vfork_signalmasked

All new tests pass.

CLONE_SIGHAND tests are right now disabled as they cannot reuse the shared
signal operations (wait(2)) to wait for a clonee.

Another nit is that wait(2) must be used right now with WALLSIG as for some
reason the default variation doesn't work.
 1.102 03-Apr-2019  kamil The *fork*_signalmasked ATF tests no longer fail

Add a fixup for signalmasking in the vforkdone_singalmasked test.
 1.101 28-Mar-2019  kamil Add new ATF ptrace(2) tests bytes_transfer_alignment*

Verify bytes transfer for potentially misaligned operation.

New tests:

- bytes_transfer_alignment_pt_read_i
- bytes_transfer_alignment_pt_read_d
- bytes_transfer_alignment_pt_write_i
- bytes_transfer_alignment_pt_write_d
- bytes_transfer_alignment_piod_read_i
- bytes_transfer_alignment_piod_read_d
- bytes_transfer_alignment_piod_write_i
- bytes_transfer_alignment_piod_write_d
- bytes_transfer_alignment_piod_read_auxv

All tests pass (at least on x86_64).
 1.100 08-Mar-2019  kamil Remove expected fail in various ATF t_ptrace_wait* tests

Tests for trap signal scenarios no longer fail.
 1.99 02-Mar-2019  kamil Refactor signal6-8 tests in t_ptrace_wait*

Transform original tests into new ones:
- fork_singalmasked
- fork_singalignored
- vfork_singalmasked
- vfork_singalignored
- vforkdone_singalmasked
- vforkdone_singalignored

All the signalignored ones pass, the remaining ones of them fail.
 1.98 23-Feb-2019  kamil Drop signal5 test-case from ATF t_ptrace_wait*

This test is now duplicated with traceme_signalmasked_exec.
 1.97 23-Feb-2019  kamil Add signal masked and ignored variations of traceme_exec in ATF tests

All tests pass.
 1.96 23-Feb-2019  kamil Add signal masked and ignored variations of traceme_vfork_exec in ATF tests

All tests pass.
 1.95 20-Feb-2019  kamil Replace signal4 (PT_STEP) test with refactored ones with extra asserts

New tests: step_signalmasked and step_signalignored.

Assert that signal context is not reset upon PT_STEP trap.

Mark new tests as expecting to fail.
 1.94 20-Feb-2019  kamil Add more tests for variations of unrelated_tracer_sees_crash in ATF

New tests:
- unrelated_tracer_sees_signalmasked_crash_trap
- unrelated_tracer_sees_signalmasked_crash_segv
- unrelated_tracer_sees_signalmasked_crash_ill
- unrelated_tracer_sees_signalmasked_crash_fpe
- unrelated_tracer_sees_signalmasked_crash_bus
- unrelated_tracer_sees_signalignored_crash_trap
- unrelated_tracer_sees_signalignored_crash_segv
- unrelated_tracer_sees_signalignored_crash_ill
- unrelated_tracer_sees_signalignored_crash_fpe
- unrelated_tracer_sees_signalignored_crash_bus

All these tests are failing with the current kernel.
 1.93 20-Feb-2019  kamil Add minor improvements in unrelated_tracer_sees_crash in t_ptrace_wait*

Switch forkee commands with asserts to be aligned for the purpose of being
used by forkees.
 1.92 17-Feb-2019  kamil Add new ATF t_ptrace_wait* vfork(2) tests

Add traceme_vfork_signalmasked_crash and traceme_vfork_signalignored_crash
tests for crash signals (SIGTRAP, SIGSEGV, SIGILL, SIGFPE, SIGBUS).

These new scenario assert that signal masked/ignored are delivered to
vfork(2)ed child.

All tests pass.
 1.91 17-Feb-2019  kamil Remove redundant test from ATF t_ptrace_wait*

signal3 duplicates traceme_signalmasked_crash(SIGSEGV)
 1.90 17-Feb-2019  kamil Add additional assert in traceme_signalignored_crash t_ptrace_wait* tests

Check whether sigignore is not reset on a trapsignal under a debugger.
The expected behavior is to not reset it. A side effect of resetting
signal mask is noticable especially with a software/hardware breakpoint
that changes state of a process.

Mark these tests as failing.
 1.89 17-Feb-2019  kamil Add additional assert in traceme_signalmasked_crash t_ptrace_wait* tests

Check whether signal mask is not reset on a trapsignal under a debugger.
The expected behavior is to not reset it. A side effect of resetting
signal mask is noticable especially with a software/hardware breakpoint
that changes state of a process.

Mark these tests as failing.
 1.88 15-Feb-2019  kamil Add new ATF tests traceme_signal{ignored,masked}_crash* in t_ptrace_wait*

New tests verify that crashes (from trap signals) are delivered to tracer
regardless of the signal masking or signal ignoring option enabled in the
traced child.

All tests pass.

In close future these tests will obtain additional asserts.
 1.87 15-Feb-2019  kamil Add new ATF tests traceme_raisesignal_ignored in t_ptrace_wait*

Verify that ignoring (with SIG_IGN) in tracee
does not stop tracer from catching this raised signal.

Cover crash signals and already covered ones in other tests.

All tests pass.
 1.86 14-Feb-2019  kamil Replace signal2 in t_ptrace_wait* with new tests

Add new tests traceme_raisesignal_masked[1-8].

New tests to verify that masking (with SIG_BLOCK) signal in tracee
stops tracer from catching this raised signal. Masked crash signals are
invisible to tracer as well.

All tests pass.
 1.85 14-Feb-2019  kamil Add new regression scenarios for crash signals in t_ptrace_wait*

Verify correct behavior of crash signals (SIGTRAP, SIGBUS, SIGILL, SIGFPE,
SIGSEGV) in existing test scenarios:
- traceme_raise
- traceme_sendsignal_handle
- traceme_sendsignal_masked
- traceme_sendsignal_ignored
- traceme_sendsignal_simple
- traceme_vfork_raise

These tests verify signals out of the context of CPU trap. These new tests
will help to retain expected behavior in future changes in semantics of
the trapsignals in the kernel.
 1.84 12-Feb-2019  kamil Rename signal1 to signal_mask_unrelated in t_ptrace_wait*

No functional change intended.
 1.83 12-Feb-2019  kamil Refactor lwp_create1 and lwp_exit1 into trace_thread* in ptrace(2) tests

New tests:
- trace_thread1
- trace_thread2
- trace_thread3
- trace_thread4

These tests verify _lwp_create(2) and _lwp_exit(2) events. They are
currently skipped as not reliable.
 1.82 11-Feb-2019  kamil Rename the siginfo4 test in ATF t_ptrace_wait*

The siginfo group of ptrace(2) tests has been replaced with new individual
tests or merged into existing ones. This is the last siginfo* test that
has been renamed.

New name: traceme_exec.
 1.81 11-Feb-2019  kamil Merge siginfo6 into other PT_STEP tests in t_ptrace_wait*
 1.80 11-Feb-2019  kamil Drop siginfo5 from ATF tests in t_ptrace_wait*

siginfo5 duplicates older tests verifying PTRACE_FORK.
 1.79 11-Feb-2019  kamil Initial refactoring of siginfo* tests in t_ptrace_wait*

Drop test siginfo1 as duplicated with earlier tests.

Rework and rename siginfo2 and siginfo3 into a single test body.

New tests:
- siginfo_set_unmodified (replaces siginfo2)
- siginfo_set_faked (replaces siginfo3)

All new tests pass.
 1.78 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.77 10-Feb-2019  kamil Add initial pthread(3) tests in ATF t_prace_wait* tests

There were tested few scenarios with native _lwp_create(2) functions, using
this interface is not needed and it's easier to manage tests with
high-level pthread(3) API.

Rewrite original lwpinfo1 and lwpinfo2 tests into 8 new tests:
- traceme_lwpinfo0 (0 spawned additional threads)
- traceme_lwpinfo1 (1 spawned additional thread)
- traceme_lwpinfo2 (2 spawned additional threads)
- traceme_lwpinfo3 (3 spawned additional threads)
- attach_lwpinfo0 (0 spawned additional threads)
- attach_lwpinfo1 (1 spawned additional thread)
- attach_lwpinfo2 (2 spawned additional threads)
- attach_lwpinfo3 (3 spawned additional threads)

These tests verify primarily the PT_LWPINFO interface.

Build the t_ptrace_wait* tests with -pthread.

All tests pass.
 1.76 09-Feb-2019  scole use HAVE_FPREGS not HAVE_FPGPREGS and move some register_t inside proper #define. fixes ia64 build. ok <kamil>
 1.75 08-Feb-2019  kamil Refactor kill* test in t_ptrace_wait*

Drop original scenario of kill1 (PT_CONTINUE(SIGKILL)) as it duplicates
traceme_sendsignal_simple1.

New kill tests:
- kill1: ptrace(PT_KILL) (previously kill2)
- kill2: kill(SIGKILL)
- kill3: killpg(SIGKILL)

All kill* tests share the same function body.

All tests pass.
 1.74 08-Feb-2019  kamil Correct a style in description of PT_STEP tests in t_ptrace_wait*
 1.73 08-Feb-2019  kamil Refactor definition of PT_STEP tests into single macro

No functional change intended.
 1.72 07-Feb-2019  kamil Refactor GPR and FPR tests in t_ptrace_wait* tests

This change deduplicates the code and puts all the test into shared
function body.

No functional change except ranaming tests regs* to access_regs* and
fpregs* to access_fpregs*.
 1.71 07-Feb-2019  kamil Enable 3 new ptrace(2) tests for SIGILL

Add missing code for SIGILL verification and enable new SIGILL tests:
- traceme_crash_ill
- traceme_vfork_crash_ill
- unrelated_tracer_sees_crash_ill

SIGILL is caused by a crash signal and needs special treatement that has
to be asserted to behave correctly.

In the unrelated_tracer_sees_crash* tests add additional check to catch
scenarios when a test dies due to abnormal condition and it's not caught
as the tracer is collected by initproc.

All tests pass on NetBSD/amd64, other ports have temporarily unimplemented
PTRACE_ILLEGAL_ASM.
 1.70 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.69 22-Jan-2019  kamil Mark traceme_vfork_crash_bus as no longer failing

Fixed in src/sys/kern/core_elf32.c r. 1.58

Closes PR lib/53343
 1.68 13-Jan-2019  gson Don't mark the traceme_vfork_crash_bus test case as an expected failure
when it is executing as part of the lib/libc/sys/t_ptrace_waitid test,
because that particular combination is not failing, at least not on amd64.
It is failing as part of other tests, so PR lib/53343 still applies.
 1.67 13-Aug-2018  kamil Add a new ATF ptrace(2) test: tracer_attach_to_unrelated_stopped_process

Reuse the body of tracer_sees_terminaton_before_the_parent_raw for a test
attaching to an unrelated stopped process.

This test passes.
 1.66 13-Aug-2018  kamil Add a new ATF test parent_attach_to_its_stopped_child

Reuse the body of parent_attach_to_its_child for a test attaching to a
stopped child.

This test passes.
 1.65 13-Aug-2018  kamil Add a new ATF ptrace(2) test: child_attach_to_its_stopped_parent

Reuse the body of child_attach_to_its_parent for a test attaching to a
stopped parent.

As a workaround to ATF framework (atf-run), run this test in a subprocess.
The raise(SIGSTOP) call breaks the pipe from atf-run, that is polling
whether a process is in order.
According to code inspection the poll(2) call in safe_poll() receives
EINTR and this tears down the test.

This test passes.
 1.64 17-Jul-2018  martin Comment out two tests that regularily hang on SMP machines (with unkillable
helper/child processes, so ATF timeout does not help).
Kamil knows about the SMP race in traced exit path and said he'll handle
it.
I would have skipped them on SMP machines only, but got lost in the
macro labyrinth - kamil, please feel free to improve ;-)
 1.63 06-Jun-2018  kamil branches: 1.63.2;
Fix previous

The failing tests are for vfork(2), not fork(2).
 1.62 06-Jun-2018  kamil Mark sigbus ATF tests in t_ptrace_wait as expected failure

They are breaking right now on all ports.

lib/53343
 1.61 01-Jun-2018  kre 80 column police. Some KNF and whitespace corrections (until I got bored...)
NFCI.
 1.60 30-May-2018  kre The bytes_transfer_piod_read_auxv test uses 4096 for the size param
to bytes_transfer() which asserted that the size is < the size of 512 AuxInfo
structs. On a 32 bit system, an AuxInfo is 8 bytes, and 512 AuxInfo
structs is thus 4096 bytes, and 4096 is not < 4096, so the assertion
failed. It would probably work as a <= assert, but I am not confident
enough with this test case to make that call, so instead increase the
array size to be 513 instead, 4096 is < 513*8 so happiness should return
and all should be right with the world. At least for this one test.
(There was no problem on 64 bit systems as AuxInfo is bigger there.)
 1.59 29-May-2018  kamil Add new ATF ptrace(2) tests verifying crash signal handling

Add new tests:
- traceme_crash_trap
- traceme_crash_segv
- traceme_crash_ill (temporarily disabled)
- traceme_crash_fpe
- traceme_crash_bus
- unrelated_tracer_sees_crash_trap
- unrelated_tracer_sees_crash_segv
- unrelated_tracer_sees_crash_ill (temporarily disabled)
- unrelated_tracer_sees_crash_fpe
- unrelated_tracer_sees_crash_bus

These tests verify two subtle kernel paths that differ internally:
- for a tracer that is a parent of a traced program (and not vforked)
real parent == tracer
- for a tracer that is an unrelated process of a traced program
real parent != tracer

Regressions in the signal code can cause to break one of the scenarios, and
keep working the other one. It might be propagated to a scenario like:
- attaching to a process with a debugger (over pid)
- starting a process inside a debugger

We can assert on the ATF level that both will be functional.

While there, cover all the crash signals as testing is done practically
for free. While the Machine Independent signal routing code for crash
signals is mostly the same in the kernel, we can verify whether Machine
Dependent parts works as expected emitting the proper signal number and
signal code (si_code).

There have been already caught an unexpected behavior on Alpha, that
instead of SIGBUS we receive SIGSEGV.

Another benefit is that it's easier to catch races, as they pop up more
frequently. (This already helped to catch bugs more quickly)

These tests will help assert correctness of future kernel changes in the
signal routines.

All tests pass.

Sponsored by <The NetBSD Foundation>
 1.58 28-May-2018  kamil Correct the t_ptrace_wait*:signal5 ATF test case

This functionality now works.
Correct the code path in this test.
Add additional sanity check with PT_GET_SIGINFO and validating si_code.

Sponsored by <The NetBSD Foundation>
 1.57 28-May-2018  kamil Drop trailing white space
 1.56 27-May-2018  kamil Fix ATF ptrace(2) bytes_transfer_piod_read_auxv test

Make the initial buffer larger to stop triggering the runtime assert about
its size.

Its size is probably larger than all real use cases, but it's good enough
for the purpose of ATF tests and immune of potential AUXV size.

Sponsored by <The NetBSD Foundation>
 1.55 27-May-2018  christos alloca, bad; stack protector, good.
 1.54 26-May-2018  kamil Refactor the PT_WRITE*/PT_READ* and PIOD_* ATF ptrace(2) tests

Merge all the PT_WRITE*/PT_READ* and PIOD_* the test cases into the common
body.

Changes:
- treat D and I variations exactly the same
- stop testing 2-3-4 attempts to perform the same read/write operation
- stop testing interlocked (handshake) read/write operations
- rename the tests
- test write to .text section (with D and I type of operations)

New tests:
- bytes_transfer_piod_read_d_8
- bytes_transfer_piod_read_d_16
- bytes_transfer_piod_read_d_32
- bytes_transfer_piod_read_d_64
- bytes_transfer_piod_read_i_8
- bytes_transfer_piod_read_i_16
- bytes_transfer_piod_read_i_32
- bytes_transfer_piod_read_i_64
- bytes_transfer_piod_write_d_8
- bytes_transfer_piod_write_d_16
- bytes_transfer_piod_write_d_32
- bytes_transfer_piod_write_d_64
- bytes_transfer_piod_write_i_8
- bytes_transfer_piod_write_i_16
- bytes_transfer_piod_write_i_32
- bytes_transfer_piod_write_i_64
- bytes_transfer_read_d
- bytes_transfer_read_i
- bytes_transfer_write_d
- bytes_transfer_write_i
- bytes_transfer_piod_read_d_8_text
- bytes_transfer_piod_read_d_16_text
- bytes_transfer_piod_read_d_32_text
- bytes_transfer_piod_read_d_64_text
- bytes_transfer_piod_read_i_8_text
- bytes_transfer_piod_read_i_16_text
- bytes_transfer_piod_read_i_32_text
- bytes_transfer_piod_read_i_64_text
- bytes_transfer_piod_write_d_8_text
- bytes_transfer_piod_write_d_16_text
- bytes_transfer_piod_write_d_32_text
- bytes_transfer_piod_write_d_64_text
- bytes_transfer_piod_write_i_8_text
- bytes_transfer_piod_write_i_16_text
- bytes_transfer_piod_write_i_32_text
- bytes_transfer_piod_write_i_64_text
- bytes_transfer_read_d_text
- bytes_transfer_read_i_text
- bytes_transfer_write_d_text
- bytes_transfer_write_i_text
- bytes_transfer_piod_read_auxv

These tests are now covering all usual code paths.

All tests pass.
The PaX MPROTECT violating ones automatically detect whether to be skipped.

Eliminated 4x more code than removed.

Sponsored by <The NetBSD Foundation>
 1.53 23-May-2018  kamil Merge the eventmask[1-6] ATF ptrace(2) tests into a shared function body

While there, rename the tests to:
- eventmask_preserved_empty
- eventmask_preserved_fork
- eventmask_preserved_lwp_create
- eventmask_preserved_lwp_exit
- eventmask_preserved_vfork
- eventmask_preserved_vfork_done

Sponsored by <The NetBSD Foundation>
 1.52 23-May-2018  kamil Extend traceme_vfork_breakpoint in ATF ptrace(2) tests for more scenarios

traceme_vfork_breakpoint used to test SIGTRAP event. Reuse its code for:
SIGSEGV, SIGILL, SIGFPE and SIGBUS.

The SIGILL case is disabled as of now as it required addition of
PTRACE_ILLEGAL_ASM in MD ptrace(2) headers.

Added tests:
- traceme_vfork_crash_trap
- traceme_vfork_crash_segv (renamed from traceme_vfork_breakpoint)
- traceme_vfork_crash_ill (disabled)
- traceme_vfork_crash_fpe
- traceme_vfork_crash_bus

All enabled tests pass.

Sponsored by <The NetBSD Foundation>
 1.51 23-May-2018  kamil Refactor the attach[1-8] and race1 ATF t_ptrace_wait* tests

Share code in: attach1, attach2 and race1 in the same function body.
Rename thsee tests to more verbose names:
- tracer_sees_terminaton_before_the_parent
- tracer_sysctl_lookup_without_duplicates
- unrelated_tracer_sees_terminaton_before_the_parent

Rename attach3 to parent_attach_to_its_child.

Rename attach4 to child_attach_to_its_parent.

Share code in attach5, attach6 and attach7 in the same function body and
reanem the tests to:
- tracee_sees_its_original_parent_getppid
- tracee_sees_its_original_parent_sysctl_kinfo_proc2
- tracee_sees_its_original_parent_procfs_status

Reduce the code by around 50%.

No functional change intended. All tests pass.

Sponsored by <The NetBSD Foundation>
 1.50 22-May-2018  kamil Add new ATF ptrace(2) tests: traceme_sendsignal_{masked,ignored}[1-3]

These tests emit signal from a tracer/parent to the child and verify the
behavior in the case of SIG_BLOCK (masked) and SIG_IGN (ignored).

The signal is not reported by the child process.

These tests pass.

While there, rename for consistency with other tests:
- traceme_sighandler_catch[1-3] -> traceme_sendsignal_handle[1-3]
- traceme_signal_nohandler[1-5] -> traceme_sendsignal_simple[1-5]

Sponsored by <The NetBSD Foundation>
 1.49 20-May-2018  kamil Refactor and enable the signal3 ATF ptrace(2) test

Adapt the test to be independent from the software breakpoint trap
behavior, whether the Program Counter is moved or not. Just kill the
process after catching the expected signal, instead of pretending to resume
it.

This test passes.

Sponsored by <The NetBSD Foundation>
 1.48 20-May-2018  kamil Fix and enable traceme_signal_nohandler2 in ATF ptrace(2) tests

traceme_signal_nohandler2 checks emitting SIGSTOP to a traced process
with the PT_CONTINUE operation.

The expected behavior is to simulate a behavior of receiving SIGSTOP,
generating SIGCHLD to its parent (in this case the debugger) and ability
to call wait(2)-like function receiving the stopped child event.

The previous behavior was unstopping the process and it has been adjusted
in the kernel code.

FreeBSD keeps unstopping a process for emitting SIGSTOP.
Linux handles this scenario in the same way as NetBSD now.

While there, implement the missing bits in the userland ATF test for
traceme_signal_nohandler2: receiving and validating 2nd SIGSTOP event and
continuing the process, followed by its normal termination.

Sponsored by <The NetBSD Foundation>
 1.47 19-May-2018  kamil Cover SIGTSTP, SIGTTIN and SIGTTOU in traceme_vfork_raise ATF tests

SIGTSTP, SIGTTIN and SIGTTOU are special case signals ignored in a
vfork(2)ed child. Assert the behavior of raise(2) after calling
PT_TRACE_ME.

Renumber existing traceme_vfork_raise tests.

Sponsored by <The NetBSD Foundation>
 1.46 19-May-2018  kamil Enable traceme_vfork_raise2 in ATF ptrace(2) tests

raise(SIGSTOP) is now handled correctly by the kernel, in a child that
vfork(2)ed and called PT_TRACE_ME.

Implement a helper process emitting SIGKILL to a stopped child of a
vfork(2)ed process.

Sponsored by <The NetBSD Foundation>
 1.45 16-May-2018  kamil Add extra asserts in three ATF ptrace(2) tests

In traceme* tests after validate_status_stopped() include additional check
the verify the received signal with PT_GET_SIGINFO.

All tests passes.

Sponsored by <The NetBSD Foundation>
 1.44 16-May-2018  kamil Improve the description of traceme_vfork_breakpoint (ATF ptrace(2) test)

Sponsored by <The NetBSD Foundation>
 1.43 16-May-2018  kamil Add a new ATF ptrace(2) test: traceme_vfork_exec

Verify PT_TRACE_ME followed by exec(3) in a vfork(2)ed child.

This tests passes correctly.

Sponsored by <The NetBSD Foundation>
 1.42 16-May-2018  kamil Improve the description of traceme_vfork_raise in ATF ptrace(2) tests

Set new description to:
- "Verify PT_TRACE_ME followed by raise of " #sig " in a vfork(2)ed "
"child"

The previous one was copy pasted from a different ATF test and not changed.

Sponsored by <The NetBSD Foundation>
 1.41 16-May-2018  kamil Add a new ATF ptrace(2) test: traceme_vfork_breakpoint

Verify software breakpoint in a vfork(2)ed child.

The expected behavior is not to route this signal to the parent, even if
that parent is a tracer. The parent cannot handle it and it would lead to
the deadlock.

This test passes correctly.

Sponsored by <The NetBSD Foundation>
 1.40 16-May-2018  kamil Correct handling of: vfork(2) + PT_TRACE_ME + raise(2)

Follow the FreeBSD approach of not routing signals to the parent that is
a became tracer after calling PT_TRACE_ME by the vfork(2)ed child (before
exec(3)/exit(3)).

Now if a child calls raise(3), the signal is processed directly to this
child.

Add new ATF ptrace(2) tests:
- traceme_vfork_raise1 (SIGKILL)
- traceme_vfork_raise2 (SIGSTOP) // temporarily disabled
- traceme_vfork_raise3 (SIGABRT)
- traceme_vfork_raise4 (SIGHUP)
- traceme_vfork_raise5 (SIGCONT)

The FreeBSD implementation introduces P_PPTRACE for this special case.
Right know keep opencoding check of this case in the kernel. It might be
refactored in future.

The Linux kernel does not follow this approach and causes dead locking of
the processes (parent and child).

Defer handling SIGSTOP into future.

This is an intermediate step towards correct handling of fork(2) and
vfork(2) in the context of ptrace(2).

All new tests pass.
There are no regressions in existing ATF ptrace(2) tests.

Sponsored by <The NetBSD Foundation>
 1.39 13-May-2018  kamil Add a new ptrace(2) ATF exploit for: CVE-2018-8897 (POP SS debug exception)

The original expolit and mitigation have been developed by Maxime Villard.

I've reworked the shared code and adapted for the ATF context.
I've included PIE-aware version (RIP/EIP relative) and introduced
additional comments to the explanation how to trigger the flaw.

This test passes on NetBSD/8.99.17.

Sponsored by <The NetBSD Foundation>
 1.38 01-May-2018  kamil Implement PTRACE_VFORK

Add support for tracing vfork(2) events in the context of ptrace(2).

This API covers other frontends to fork1(9) like posix_spawn(2) or clone(2),
if they cause parent to wait for exec(2) or exit(2) of the child.

Changes:
- Add new argument to sigswitch() determining whether we need to acquire
the proc_lock or whether it's already held.
- Refactor fork1(9) for fork(2) and vfork(2)-like events.
Call sigswitch() from fork(1) for forking or vforking parent, instead of
emitting kpsignal(9). We need to emit the signal and suspend the parent,
returning to user and relock proc_lock.
- Add missing prototype for proc_stop_done() in kern_sig.c.
- Make sigswitch a public function accessible from other kernel code
including <sys/signalvar.h>.
- Remove an entry about unimplemented PTRACE_VFORK in the ptrace(2) man page.
- Permin PTRACE_VFORK in the ptrace(2) frontend for userland.
- Remove expected failure for unimplemented PTRACE_VFORK tests in the ATF
ptrace(2) test-suite.
- Relax signal routing constraints under a debugger for a vfork(2)ed child.
This intended to protect from signaling a parent of a vfork(2)ed child that
called PT_TRACE_ME, but wrongly misrouted other signals in vfork(2)
use-cases.

Add XXX comments about still existing problems and future enhancements:
- correct vfork(2) + PT_TRACE_ME handling.
- fork1(2) handling of scenarios when a process is collected in valid but
rare cases.

All ATF ptrace(2) fork[1-8] and vfork[1-8] tests pass.

Fix PR kern/51630 by Kamil Rytarowski (myself).

Sponsored by <The NetBSD Foundation>
 1.37 29-Apr-2018  kamil Add two new ptrace(2) ATF tests

Added:

- traceme_pid1_parent
Assert that a process cannot mark its parent a debugger twice

- traceme_twice
Verify that PT_TRACE_ME is not allowed when our parent is PID1

All tests pass.

Sponsored by <The NetBSD Foundation>
 1.36 28-Apr-2018  kamil Enable traceme_raise1 in the ATF ptrace(2) tests

This test checks raise(SIGKILL). If we enter the kernel with this signal
we report a signaled child in a debugger, not stopped with an option to
make an action.

FreeBSD behaves differently and allows intercepting this event in a tracer.
Follow the Linux behavior.

If we really want to prevent raise(SIGKILL) from signaling the tracee, we
still can breakpoint raise(3) and alter the syscall arguments (or use
the PT_SYSCALL mode). If we are already in the kernel, SIGKILL always means
killing the process, whether or not traced and the source of SIGKILL.

This tests passes on NetBSD without kernel changes.

Sponsored by <The NetBSD Foundation>
 1.35 28-Apr-2018  kamil Refactor the traceme3 ATF ptrace(2) test

Replace traceme3 with new ATF tests using diverse signals:

- traceme_signal_nohandler1 SIGKILL
- traceme_signal_nohandler2 SIGSTOP (temporarily disabled)
- traceme_signal_nohandler3 SIGABRT (emits core dump)
- traceme_signal_nohandler4 SIGHUP
- traceme_signal_nohandler5 SIGCONT

These SIGSTOP test does not work properly right now as it unstops the
traccee.

Sponsored by <The NetBSD Foundation>
 1.34 28-Apr-2018  kamil Refactor the traceme2 ATF ptrace(2) tests

Replace traceme2 with 3 tests:
- traceme_sighandler_catch1
- traceme_sighandler_catch2
- traceme_sighandler_catch3

These tests are verified with PT_TRACE_ME for: SIGHUP, SIGCONT and SIGABRT.

We don't want tests all signals (this is a domain for a fuzzer), but we want
to cover tests with signals from different groups.

All tests pass.

Sponsored by <The NetBSD Foundation>
 1.33 27-Apr-2018  kamil Refactor the traceme1 and traceme4 ATF ptrace(2) tests

Use common bode for these tests and a macro 1-liner to define a new test.

Test the same scenarios for 5 signals:
- SIGKILL (temporarily disabled)
- SIGSTOP
- SIGABRT
- SIGHUP
- SIGCONT

These tests call: raise(sig). It's actually important to assert their
behavior for tests that are from different kinds.

The SIGKILL test is work in progress. It can be caught by a debugger on the
FreeBSD kernel, but it's causing a signaled event in a debugger on Linux.

NetBSD is right now in one of the camps, but research whether this is a bug
or feature is in progress.

Sponsored by <The NetBSD Foundation>
 1.32 15-Apr-2018  kamil Refactor fork-like ATG tests in t_ptrace_wait*

Add CPP syntax sugare to define each fork-like test within a single line
of code with less than 80 columns.

This is a preparation for new fork-like scenarios where we detach either
child and/or parent with PT_DETACH.

The code could be still reduced to smaller number of columns, instead of:

FORK_TEST(fork1, DSCR(fork,0,0,0,0,0), fork, F, F, F, F, F)

we could perhaps need 50% of it, as the data is duplicated.

On the other hand the line is already short and taking only a single line.

No functional change intended.

Sponsored by <The NetBSD Foundation>
 1.31 11-Apr-2018  kamil Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.

Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>
 1.30 10-Apr-2018  kamil ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().

There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.

PR kern/51630

Sponsored by <The NetBSD Foundation>
 1.29 10-Apr-2018  kamil ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones

Reduce code duplication, use the same function body with conditional
switches.

Sponsored by <The NetBSD Foundation>
 1.28 10-Apr-2018  kamil Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

Marge bodies of two tests into the same function.
Add few checks for regular fork or not (vfork).

Sponsored by <The NetBSD Foundation>
 1.27 09-Apr-2018  kamil Improve documentation of the ATF test t_ptrace_wait*: traceme2

Set the description to:

Verify that a signal emitted by a tracer to a child is caught by
a signal handler.

Sponsored by <The NetBSD Foundation>
 1.26 13-Mar-2018  kamil ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported

race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7).
A buggy kernel was asserting an error within this timeframe almost always.

The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>
 1.25 07-Mar-2018  kamil ATF: Reenable attach2 in t_ptrace_wait*

The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).

This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.

The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2)/
read(2) or close to these features.

Sponsored by <The NetBSD Foundation>
 1.24 07-Mar-2018  kamil ATF: Correct a race bug in attach2 (t_ptrace_wait*)

At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.

Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.

This test is still racy for some other and unknown reason and this is being
investigated.

Sponsored by <The NetBSD Foundation>
 1.23 05-Mar-2018  kamil branches: 1.23.2;
Remove PT_GET_SIGMASK / PT_SET_SIGMASK

These operations cloned Linux's specific PTRACE_GETSIGMASK / PTRACE_SETSIGMASK.
This feature was useful in applications like rr/criu/reptyr-like, where
the ptrace(2) interface is abused for the purpose of constructing an arbitrary
process. It's not reliable and not portable. For the NetBSD case it will be
better to invent something dedicated for serializing and deserializing a
process with threads.

Noted on tech-toolchain@ and blog entry

"LLDB restoration and return to ptrace(2)"
https://blog.netbsd.org/tnf/entry/lldb_restoration_and_return_to
 1.22 28-Dec-2017  christos mips panic should be fixed on head.
 1.21 28-Dec-2017  kamil atf: ptrace: Temporarily skip fpregs* tests on pmax

NetBSD/pmax 8.99.9 panics when attempting to use fpregs through ptrace(2).

Sponsored by <The NetBSD Foundation>
 1.20 27-Dec-2017  kamil atf: ptrace: Temporarily disable signal3 as it breaks now on some ports

This test is marked as failing with: PR kern/51918.
 1.19 25-Dec-2017  kamil atf: t_ptrace_wait: Mark attach2 as racy
 1.18 23-Dec-2017  christos report which errno failed
 1.17 22-Dec-2017  kamil ptrace atf: Clanup reports of failures

Mark resume* suspend* tests as expected failure and link with PR 51995.

Sponsored by <The NetBSD Foundation>
 1.16 21-Dec-2017  kamil t_ptrace_wait*: Disable suspend* tests

These tests can hang the system. These interfaces will be improved and
temporarily disable them.
 1.15 18-Dec-2017  christos make it fail instead of hang under qemu; XXX: need to investigate.
 1.14 16-Dec-2017  christos Add expected failures.
 1.13 14-Dec-2017  christos sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
 1.12 10-Dec-2017  christos Remove expected failure (fixed in kern_sig.c 1.339)
 1.11 04-Dec-2017  kamil Temporarily disable t_ptrace_wait*::resume1 in ATF tests

It hangs forever on releng machines.

Sponsored by <The NetBSD Foundation>
 1.10 18-Nov-2017  martin PR kern/52167 strikes on sparc64 too.
 1.9 03-May-2017  kamil branches: 1.9.2;
Improve style of PT_SETSTEP and PT_CLEARSTEP tests in t_ptrace_wait*

No functional change.

Sponsored by <The NetBSD Foundation>
 1.8 16-Apr-2017  kamil branches: 1.8.2; 1.8.4; 1.8.6;
ATF test attach2/t_ptrace_wait* is unstable

Mark it broken with:

PR kern/52168 attach2:t_ptrace_wait* is unsable

In order to get reliable failure, abort this test at the end (if we get
there).
 1.7 16-Apr-2017  kamil Mark signal3/t_ptrace_wait* with timeout on sparc 32-bit

PR kern/52167 signal3/t_ptrace_wait* timeouts on sparc 32-bit

This test is also marked as failure on other platforms:

PR kern/51918 ptrace tracee can prevent tracer to get its signals by masking

Both issues are valid on sparc 32-bit, but the timeout one wins.
 1.6 16-Apr-2017  kamil Mark syscallemu1/t_ptrace_wait* broken on 32-bit sparc

PR kern/52166
 1.5 16-Apr-2017  kamil Restore atf_tc_expect_fail in signal4 of t_ptrace_wait*

Accidentally there was removed a PR, it was never fixed.

PR 51918 "ptrace tracee can prevent tracer to get its signals by masking"
 1.4 12-Apr-2017  kamil Add new macro PTRACE_BREAKPOINT_ASM in <sys/ptrace.h> MD part

This macro ships with a MD-specific assembly instruction triggering
a software breakpoint.

Missing instruction for powerpc targets.

This code is used in ATF tests (lib/libc/sys/t_ptrace_wait).

Original patch by Nick Hudson, thanks!
 1.3 10-Apr-2017  kamil fork1 and siginfo5 no longer fails on !x86 platforms in t_ptrace_wait*

The PTRACE_FORK operation has been fixed. Patch committed by <martin>

PR kern/52117
 1.2 08-Apr-2017  kamil Add new ptrace(2) API: PT_SETSTEP & PT_CLEARSTEP

These operations allow to mark thread as a single-stepping one.

This allows to i.a.:
- single step and emit a signal (PT_SETSTEP & PT_CONTINUE)
- single step and trace syscall entry and exit (PT_SETSTEP & PT_SYSCALL)

The former is useful for debuggers like GDB or LLDB. The latter can be used
to singlestep a usermode kernel. These examples don't limit use-cases of
this interface.

Define PT_*STEP only for platforms defining PT_STEP.

Add new ATF tests setstep[1234].

These ptrace(2) operations first appeared in FreeBSD.

Sponsored by <The NetBSD Foundation>
 1.1 02-Apr-2017  kamil Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.8.6.1 11-May-2017  pgoyette Sync with HEAD
 1.8.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.8.4.1 16-Apr-2017  pgoyette file t_ptrace_wait.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.8.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.8.2.1 16-Apr-2017  bouyer file t_ptrace_wait.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.9.2.3 12-Apr-2018  martin Pull up following revision(s) (requested by kamil in ticket #711):
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.24-1.31
tests/lib/libc/sys/t_ptrace_wait.h: revision 1.2
tests/lib/libc/sys/t_ptrace_x86_wait.h: revision 1.4,1.5
tests/lib/libc/sys/msg.h: revision 1.2

Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)

This code after refactoring stopped calling functions that were designed
to trigger expected behavior and thus, tests were breaking.
Sponsored by <The NetBSD Foundation>

ATF: Correct a race bug in attach2 (t_ptrace_wait*)
At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.

Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.

This test is still racy for some other and unknown reason and this is bei=
ng
investigated.

Sponsored by <The NetBSD Foundation>

ATF: Reenable attach2 in t_ptrace_wait*

The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).

This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.
The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2=
)/
read(2) or close to these features.

Sponsored by <The NetBSD Foundation>

Add a new function in ATF t_ptrace_wait*: await_zombie_raw()

Add await_zombie_raw() that is the same as await_zombie(), whith an
addition of additional "useconds_t ms" parameter indicating delays betwee=
n
new polling for a zombie process.

This new function will be used for testing a race condition that has been=
observed occassionally crashing a test case -- returning duplicate entrie=
s
for KERN_PROC_PID.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait*: Disable debug messages in msg.h
msg.h is a dummy IPC interface.

Disable additional debugging logging here, especially wanted in race*
tests.

Sponsored by <The NetBSD Foundation>

ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported
race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7=
).
A buggy kernel was asserting an error within this timeframe almost always=
=2E
The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>

Add check in ATF tests for security.models.extensions.user_set_dbregs
Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.

It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.
In case of not being able to do so, print a message and mark a test
as skipped:
Either run this test as root or set sysctl(3)
security.models.extensions.user_set_dbregs to 1
No functional change intended to the code flow of the existing tested
scenarios.

Sponsored by <The NetBSD Foundation>

Improve documentation of the ATF test t_ptrace_wait*: traceme2
Set the description to:
Verify that a signal emitted by a tracer to a child is caught by
a signal handler.

Sponsored by <The NetBSD Foundation>

Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

Marge bodies of two tests into the same function.

Add few checks for regular fork or not (vfork).

Sponsored by <The NetBSD Foundation>

ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones
Reduce code duplication, use the same function body with conditional
switches.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().

There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.
PR kern/51630

Sponsored by <The NetBSD Foundation>

Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.=
Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>
 1.9.2.2 06-Mar-2018  martin Pull up following revision(s) (requested by kamil in ticket #602):
doc/CHANGES{,.prev}: revision 1.138
sys/sys/ptrace.h: revision 1.63
lib/libc/sys/ptrace.2: revision 1.68
sys/kern/sys_ptrace_common.c: revision 1.35 (via patch)
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.23

Remove PT_GET_SIGMASK / PT_SET_SIGMASK

These operations cloned Linux's specific PTRACE_GETSIGMASK /
PTRACE_SETSIGMASK.

This feature was useful in applications like rr/criu/reptyr-like, where
the ptrace(2) interface is abused for the purpose of constructing an
arbitrary
process. It's not reliable and not portable. For the NetBSD case it will =
be
better to invent something dedicated for serializing and deserializing a
process with threads.

Noted on tech-toolchain@ and blog entry
"LLDB restoration and return to ptrace(2)"
https://blog.netbsd.org/tnf/entry/lldb_restoration_and_return_to
 1.9.2.1 25-Feb-2018  snj Pull up following revision(s) (requested by martin in ticket #586):
tests/lib/libc/sys/t_ptrace_amd64_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_i386_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_wait.c: 1.10-1.20
tests/lib/libc/sys/t_ptrace_x86_wait.h: 1.2-1.3
PR kern/52167 strikes on sparc64 too.
--
Temporarily disable t_ptrace_wait*::resume1 in ATF tests
It hangs forever on releng machines.
Sponsored by <The NetBSD Foundation>
--
Remove expected failure (fixed in kern_sig.c 1.339)
--
sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
--
Add expected failures.
--
make it fail instead of hang under qemu; XXX: need to investigate.
--
t_ptrace_wait*: Disable suspend* tests
These tests can hang the system. These interfaces will be improved and
temporarily disable them.
--
ptrace atf: Clanup reports of failures
Mark resume* suspend* tests as expected failure and link with PR 51995.
Sponsored by <The NetBSD Foundation>
--
report which errno failed
--
atf: t_ptrace_wait: Mark attach2 as racy
--
atf: ptrace: Temporarily disable signal3 as it breaks now on some ports
This test is marked as failing with: PR kern/51918.
 1.23.2.9 26-Jan-2019  pgoyette Sync with HEAD
 1.23.2.8 18-Jan-2019  pgoyette Synch with HEAD
 1.23.2.7 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.23.2.6 28-Jul-2018  pgoyette Sync with HEAD
 1.23.2.5 25-Jun-2018  pgoyette Sync with HEAD
 1.23.2.4 21-May-2018  pgoyette Sync with HEAD
 1.23.2.3 02-May-2018  pgoyette Synch with HEAD
 1.23.2.2 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.23.2.1 15-Mar-2018  pgoyette Synch with HEAD
 1.63.2.3 21-Apr-2020  martin Sync with HEAD
 1.63.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63.2.1 10-Jun-2019  christos Sync with HEAD
 1.131.2.8 25-May-2020  martin Apply patch, requested by kamil in ticket #925:
Adaption of:

tests/lib/libc/sys/t_ptrace_fork_wait.h 1.3,1.4,1.6

Ignore interception of SIGCHLD signals in the debugger

There is a race that SIGCHLD might be blocked during forking and dropped.

PR/55241 by Andreas Gustafsson
 1.131.2.7 25-May-2020  martin Apply patch, requested by kamil in ticket #925:

Cherry-pick from:

tests/lib/libc/sys/t_ptrace_fork_wait.h 1.2

Fix race in fork_singalmasked

ELF RTLD after rtld.c r. 1.204 introduced locking that wraps the fork
syscall. This locking changes signal mask of the calling process during
the forking process.

Instead of comparing old and new signal mask, just after the forking
operation, check whether the expected signal is still masked and in
another test whether it is still ignored.
 1.131.2.6 23-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #366):

tests/lib/libc/sys/t_ptrace_wait.c: revision 1.136
sys/kern/kern_sig.c: revision 1.373
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.138
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.139
sys/kern/kern_sig.c: revision 1.376
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.140
sys/kern/sys_ptrace_common.c: revision 1.64

Fix typo in a comment

Enable TEST_LWP_ENABLED in t_ptrace_wait*
The LWP events (created, exited) are now reliable in my local tests.
PR kern/51420
PR kern/51995

Remove the short-circuit lwp_exit() path from sigswitch()

sigswitch() can be called from exit1() through:

ttywait()->ttysleep()-> cv_timedwait_sig()->sleepq_block()->issignal()->sigswitch()

lwp_exit() called for the last LWP triggers exit1() and this causes a panic.
The debugger related signals have short-circuit demise paths in
eventswitch() and other functions, before calling sigswitch().

This change restores the original behavior, but there is an open question
whether the kernel crash is a red herring of misbehavior of ttywait().
This should fix PR kern/54618 by David H. Gutteridge

Fix a race condition when handling concurrent LWP signals and add a test

Fix a race condition that caused PT_GET_SIGINFO to return incorrect
information when multiple signals were delivered concurrently
to different LWPs. Add a regression test that verifies that when 50
threads concurrently use pthread_kill() on themselves, the debugger
receives all signals with correct information.

The kernel uses separate signal queues for each LWP. However,
the signal context used to implement PT_GET_SIGINFO is stored in 'struct
proc' and therefore common to all LWPs in the process. Previously,
this member was filled in kpsignal2(), i.e. when the signal was sent.

This meant that if another LWP managed to send another signal
concurrently, the data was overwritten before the process was stopped.

As a result, PT_GET_SIGINFO did not report the correct LWP and signal
(it could even report a different signal than wait()). This can be
quite reliably reproduced with the number of 20 LWPs, however it can
also occur with 10.

This patch moves setting of signal context to issignal(), just before
the process is actually stopped. The data is taken from per-LWP
or per-process signal queue. The added test confirms that the debugger
correctly receives all signals, and PT_GET_SIGINFO reports both correct
LWP and signal number.
Reviewed by kamil.

Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*
vfork(2) tests are now enabled always and confirmed to be stable.

Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*
LWP tests are now enabled always and confirmed to be stable.
 1.131.2.5 15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #317):

tests/lib/libc/sys/t_ptrace_wait.c: revision 1.133

Merge PT_GET_PROCESS_STATE checks into traceme_raise ATF ptrace tests

Assert that PT_GET_PROCESS_STATE for !child and !lwp events returns
non-error and zeroed struct ptrace_state.

These checks are not really special to traceme_raise, it's just an
opportunity to reuse them in an existing tests without writing a dedicated
one.

This behavior is needed to maintain in 3rd party software (GDB).
 1.131.2.4 15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #315):

tests/lib/libc/sys/t_ptrace_wait.c: revision 1.132

Add a few static asserts in t_ptrace_wait.c for conditions that must be kept
Assert that ptrace_state and siginfo_t's _ptrace_state are synchronized.
 1.131.2.3 15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #314):

tests/lib/libc/sys/t_ptrace_wait.c: revision 1.137

Fix race in t_ptrace_wait* LWP tests

Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.
 1.131.2.2 15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #312):

tests/lib/libc/sys/t_ptrace_wait.c: revision 1.135

Bump the number of threads in LWP t_ptrace_wait*() tests from to 100

This is a torture, but on purpose to catch LWP_CREATED and LWP_EXITED bugs.
The threads do nothing other than calling sched_yield() in a loop.

MAXLWP is now defined to 2048 on all ports.

This change effects the following tests:
- trace_thread_nolwpevents
- trace_thread_lwpexit
- trace_thread_lwpcreate
- trace_thread_lwpcreate_and_exit
 1.131.2.1 15-Oct-2019  martin Pull up following revision(s) (requested by kamil in ticket #310):

tests/lib/libc/sys/t_ptrace_wait.c: revision 1.134

Remove ATF t_ptrace_wait test suspend1

The tests verifies that a thread can be suspended by a debugger and later
resumed by a tracee.

This is an unwanted behavior and will be fixed soon.
 1.192.2.1 02-Aug-2025  perseant Sync with HEAD
 1.42 09-May-2025  riastradh t_ptrace_*: Put spaces in hexdump output for legibility.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.41 09-May-2025  riastradh t_ptrace*: Fix FORKEE_ASSERT_MEMEQ output and failureness.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.40 02-May-2025  riastradh t_ptrace_*: More diagnostic output for assertion failures.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.39 02-May-2025  riastradh t_ptrace*: Show values in hex for FORKEE_ASSERT_EQ/NEQ.

Should make the output easier to read for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.38 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Sprinkle improved diagnostics.

This should make it easier to look at the test failure output and
figure out what's going on.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.37 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.36 14-May-2024  riastradh branches: 1.36.2;
t_ptrace_wait: No FPU exception traps on RISC-V.

This macro is not named correctly -- RISC-V does implement
floating-point exceptions, but only via sticky status bits, not via
machine traps.
 1.35 14-May-2024  riastradh t_ptrace_wait: Force result by write to volatile, not call to usleep.

This is causing each FPE-related test to time out because it's
actually passinga large number to usleep, which now respects large
numbers.
 1.34 24-May-2022  andvar s/estabilishing/establishing/ in copy pasted comment.
 1.33 24-May-2021  gson On mips, avoid deliberately executing an illegal instruction for now
because it causes GXemul to exit rather than generating a trap. A bug
report has been sent to the GXemul author.
 1.32 22-Jun-2020  rin branches: 1.32.4;
Work around QEMU bug #1668041 differently, by which floating-point
division by zero is not correctly trapped for i386 and amd64:

https://bugs.launchpad.net/qemu/+bug/1668041

Make trigger_fpe() cause integer division by zero for x86, and
floating-point one for other architectures. Also, assertions for
si_code in *_crash_fpe tests are commented out for now. They
should be cleaned up after the bug is fixed.

Now, *_crash_fpe tests are working also on powerpc.

Suggested by kamil.
 1.31 22-Jun-2020  rin Turn trigger_fpe() back to integer division by zero for a while
until QEMU bug #1668041 is fixed:

https://bugs.launchpad.net/qemu/+bug/1668041

by which floating-point division by zero is not trapped correctly
both on amd64 and i386.

Skip *_crash_fpe tests on powerpc, where integer division by zero
is never trapped.
 1.30 17-Jun-2020  rin Let trigger_fpe() cause floating-point divide by zero exception, instead of
integer one, which is not trapped for powerpc and aarch64.

Note that it is checked in lib/libc/gen/t_siginfo whether integer divide by
zero is interpreted as SIGFPE or not.

Now, all *_crash_fpe tests pass for powerpc, and nothing changes for amd64
at least.
 1.29 17-Jun-2020  rin Regardless of __HAVE_FENV, include <fenv.h>, which itself defines __HAVE_FENV.
 1.28 05-May-2020  kamil Move threads tests out of t_ptrace_wait.c to t_ptrace_threads_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.27 08-Mar-2020  martin Only inlcude fenv.h if __HAVE_FENV
 1.26 07-Mar-2020  kamil Fix typo
 1.25 07-Mar-2020  christos Try to fix the build. This is why all those inlines should really be in a
separate file as regular function. The code is too large and hard to manage
this way, and only increases in complexity as time goes by.
 1.24 06-Mar-2020  kamil Add await_collected()

This functions waits for collecting a process.
 1.23 03-Mar-2020  kamil Mark find_event_count() with __used
 1.22 22-Feb-2020  kamil Disable t_ptrace_wait* tests for MKSANITIZER/MKLIBCSANITIZER

A subset of tests is not compatible with the sanitizers.
 1.21 13-Feb-2020  kamil Disable UBSan warnings for trigger_segv()

Dereferencing the NULL pointer is on purpose.
 1.20 13-Feb-2020  kamil Disable UBSan reports in trigger_fpe()

Division by 0 is on purpose.
 1.19 11-Feb-2020  kamil Rewrite the t_ptrace_wait resume1 test

Switch to pthread functions.
Rename to 'resume'.
Synchronize the threads with pthread barriers.
Avoid race in the test.

Test passes correctly.

Fixes PR bin/54893 by Andreas Gustafsson
 1.18 12-Nov-2019  kamil Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by <mgorny>, tested and tweaked by myself.
 1.17 25-May-2019  kamil Add get_user_va0_disable() in t_ptrace_wait.h

Add a utility function to check vm.user_va0_disable.
 1.16 25-Apr-2019  kamil Introduce check for the support of FPU exceptions

If FPU exceptions are unsupported, skip the SIGFPE crash tests.

Reuse code from tests/kernel/h_segv.c
 1.15 11-Apr-2019  kamil Add clone_func() in t_ptrace_wait.h
 1.14 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.13 09-Feb-2019  kamil Add infinite_thread() for ptrace(2) ATF tests

infinite_thread() is designed to be spawned as a pthread(3) function.

It will be used soon in new tests.
 1.12 13-Aug-2018  kamil Add await_stopped() in t_ptrace_wait.h

This is used in tests where a process awaits for a stopped process.
 1.11 30-May-2018  kamil branches: 1.11.2;
Add a comment for the workaround in trigger_bus()

Explain PROT_READ|PROT_WRITE.
 1.10 30-May-2018  kamil Make the trigger_bus() test compatible with more CPUs (at least ALPHA)

If we write a byte character into a pointer, a compiler can emit a
read-modify-write operation, especially when a CPU cannot access directly
a character wide address.

In this scenario calling mmap(2) with PROT_WRITE, without PROT_READ will
emit unexpected trap.

There are two possible workarounds for this issue:
- write register wide memory without rmw sequence,
- mark the region with additional protection PROT_READ

Both work for NetBSD/alpha.

Go for the latter as perhaps more safe for dump compilers emitting rmw
sequences.

Investigated by <martin>
 1.9 27-May-2018  kamil Try to fool $CC harder in ATF ptrace(2) tests in trigger_fpe()

A function that returns a value that is not used, can be optimized out by
a compiler. Try to fool the compiler with calling libc functions that shall
trigger a division by zero crash.

Sponsored by <The NetBSD Foundation>
 1.8 26-May-2018  kamil Introduce can_we_write_to_text() to ATF ptrace(2) tests

The purpose of this function is to detect whether a tracer can write to the
.text section of its tracee.

Sponsored by <The NetBSD Foundation>
 1.7 24-May-2018  kamil Try to fix 32-bit build

Cast pointer to uintptr_t rather than uintmax_t.
 1.6 23-May-2018  kamil Add new auxiliary functions in ATF ptrace(2) tests

Introduce:
- trigger_trap()
- trigger_segv()
- trigger_ill()
- trigger_fpe()
- trigger_bus()

These functions generate appropriate signals caused by crashes.

A debugger is required to collect the crashes regardless of signal masking,
catching or ignoring rules.

While there, append __used argument to can_we_set_dbregs().

Sponsored by <The NetBSD Foundation>
 1.5 19-May-2018  kamil Add new auxiliary functions in t_ptrace_wait.h

New functions:
- FORKEE_ASSERT_NEQ()
- await_stopped_child()

Both will be used soon in a new ATF ptrace(2) test.

Sponsored by <The NetBSD Foundation>
 1.4 13-May-2018  kamil Refactor code in ATF ptrace(2) tests

Move the can_we_set_dbregs() auxiliary function from t_ptrace_x86_wait.h
to a common file t_ptrace_wait.h. This allows using this function for
checking whether the DBREGS set operations in ptrace(2) are accessible for
a user.

Sponsored by <The NetBSD Foundation>
 1.3 28-Apr-2018  kamil Handle core dumps in ATF ptrace(2) tests easier

Cast WCOREDUMP() to either 1 or 0.

It could be changed to a boolean type, but it's already good enough.

Sponsored by <The NetBSD Foundation>
 1.2 13-Mar-2018  kamil Add a new function in ATF t_ptrace_wait*: await_zombie_raw()

Add await_zombie_raw() that is the same as await_zombie(), whith an
addition of additional "useconds_t ms" parameter indicating delays between
new polling for a zombie process.

This new function will be used for testing a race condition that has been
observed occassionally crashing a test case -- returning duplicate entries
for KERN_PROC_PID.

Sponsored by <The NetBSD Foundation>
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.8; 1.1.14;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.14.5 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.14.4 25-Jun-2018  pgoyette Sync with HEAD
 1.1.14.3 21-May-2018  pgoyette Sync with HEAD
 1.1.14.2 02-May-2018  pgoyette Synch with HEAD
 1.1.14.1 15-Mar-2018  pgoyette Synch with HEAD
 1.1.8.1 12-Apr-2018  martin Pull up following revision(s) (requested by kamil in ticket #711):
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.24-1.31
tests/lib/libc/sys/t_ptrace_wait.h: revision 1.2
tests/lib/libc/sys/t_ptrace_x86_wait.h: revision 1.4,1.5
tests/lib/libc/sys/msg.h: revision 1.2

Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)

This code after refactoring stopped calling functions that were designed
to trigger expected behavior and thus, tests were breaking.
Sponsored by <The NetBSD Foundation>

ATF: Correct a race bug in attach2 (t_ptrace_wait*)
At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.

Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.

This test is still racy for some other and unknown reason and this is bei=
ng
investigated.

Sponsored by <The NetBSD Foundation>

ATF: Reenable attach2 in t_ptrace_wait*

The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).

This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.
The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2=
)/
read(2) or close to these features.

Sponsored by <The NetBSD Foundation>

Add a new function in ATF t_ptrace_wait*: await_zombie_raw()

Add await_zombie_raw() that is the same as await_zombie(), whith an
addition of additional "useconds_t ms" parameter indicating delays betwee=
n
new polling for a zombie process.

This new function will be used for testing a race condition that has been=
observed occassionally crashing a test case -- returning duplicate entrie=
s
for KERN_PROC_PID.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait*: Disable debug messages in msg.h
msg.h is a dummy IPC interface.

Disable additional debugging logging here, especially wanted in race*
tests.

Sponsored by <The NetBSD Foundation>

ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported
race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7=
).
A buggy kernel was asserting an error within this timeframe almost always=
=2E
The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>

Add check in ATF tests for security.models.extensions.user_set_dbregs
Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.

It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.
In case of not being able to do so, print a message and mark a test
as skipped:
Either run this test as root or set sysctl(3)
security.models.extensions.user_set_dbregs to 1
No functional change intended to the code flow of the existing tested
scenarios.

Sponsored by <The NetBSD Foundation>

Improve documentation of the ATF test t_ptrace_wait*: traceme2
Set the description to:
Verify that a signal emitted by a tracer to a child is caught by
a signal handler.

Sponsored by <The NetBSD Foundation>

Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

Marge bodies of two tests into the same function.

Add few checks for regular fork or not (vfork).

Sponsored by <The NetBSD Foundation>

ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones
Reduce code duplication, use the same function body with conditional
switches.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().

There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.
PR kern/51630

Sponsored by <The NetBSD Foundation>

Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.=
Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_wait.h was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_wait.h was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.11.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.11.2.1 10-Jun-2019  christos Sync with HEAD
 1.32.4.1 31-May-2021  cjep sync with head
 1.36.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.16;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.16.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_wait3.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_wait3.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.3 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.16;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.16.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_wait4.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_wait4.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.3 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.16;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.16.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_wait6.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_wait6.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.3 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.16;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.16.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_waitid.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_waitid.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.3 04-May-2020  kamil Move signal tests out of t_ptrace_wait.c to t_ptrace_signal_wait.h

The same tests are now included with the preprocessor in t_ptrace_wait.c.

No functional change intended.
 1.2 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.16;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.16.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_waitpid.c was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_waitpid.c was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.33 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Sprinkle improved diagnostics.

This should make it easier to look at the test failure output and
figure out what's going on.

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.32 02-May-2025  riastradh tests/lib/libc/sys/t_ptrace*: Nix trailing whitespace.

No functional change intended.

Preparation for:

PR misc/59381: t_ptrace_wait* and t_ptrace_sigchld tests are flaky
 1.31 27-Oct-2020  mgorny branches: 1.31.12;
Add tests for AVX-512 registers (zmm0..zmm31, k0..7)

Thanks to David Seifert <soap@gentoo.org> for providing a VM
on an AVX-512 capable hardware

Reviewed by kamil
 1.30 24-Oct-2020  mgorny Issue 64-bit versions of *XSAVE* for 64-bit amd64 programs

When calling FXSAVE, XSAVE, FXRSTOR, ... for 64-bit programs on amd64
use the 64-suffixed variant in order to include the complete FIP/FDP
registers in the x87 area.

The difference between the two variants is that the FXSAVE64 (new)
variant represents FIP/FDP as 64-bit fields (union fp_addr.fa_64),
while the legacy FXSAVE variant uses split fields: 32-bit offset,
16-bit segment and 16-bit reserved field (union fp_addr.fa_32).
The latter implies that the actual addresses are truncated to 32 bits
which is insufficient in modern programs.

The change is applied only to 64-bit programs on amd64. Plain i386
and compat32 continue using plain FXSAVE. Similarly, NVMM is not
changed as I am not familiar with that code.

This is a potentially breaking change. However, I don't think it likely
to actually break anything because the data provided by the old variant
were not meaningful (because of the truncated pointer).
 1.29 16-Oct-2020  mgorny Remove leftover commented out #if 0
 1.28 15-Oct-2020  mgorny Fix s87_tw reconstruction to correctly indicate register states

Fix the code reconstructing s87_tw (full tag word) from fx_sw (abridged
tag word) to correctly represent all register states. The previous code
only distinguished between empty/non-empty registers, and assigned
'regular value' to all non-empty registers. The new code explicitly
distinguishes the two other tag word values: empty and special.
 1.27 09-Oct-2020  mgorny Add tests for x87 FPU registers

Reviewed by kamil
 1.26 09-Oct-2020  mgorny Rename MM_REG macro to ST_MAN, and cover fpr/xstate with it

Rename the MM_REG macro to ST_MAN, to make it clearer that it gets
mantissa of ST registers which overlaps with MM registers but can be
also used to read ST registers (to be used in the next commit). Extend
it to cover the difference between GETFPREGS and GETXSTATE,
and therefore avoid additional condition on i386.

Reviewed by kamil.
 1.25 24-Apr-2020  thorpej Update for new LWP behavior -- as of 9.99.59, the LWP ID of a single-LWP
process is the PID, not 1.
 1.24 20-Feb-2020  kamil Refactor dbregs_dont_inherit_lwp()

Switch from native LWP calls to pthread(3) calls.
 1.23 14-Feb-2020  christos Instead of turning optimization off, use unique labels with %= (thanks joerg@)
 1.22 13-Feb-2020  tnn adjust r1.19; add clang equivalent of gcc specific attribute
 1.21 13-Feb-2020  mgorny Extend concurrent events test to watchpoints
 1.20 13-Feb-2020  mgorny Extend concurrent events test to breakpoints

Add testing for concurrent breakpoint hits. The code is currently
x86-specific but since it reuses most of the generic concurrent event
test code, it's put in t_ptrace_wait.c with arch-specific hooks.
 1.19 13-Feb-2020  christos Turn off optimization on a function which contains constant labels.
The optimizer splits it and we end up with 2 copies and duplicate symbols.
 1.18 08-Jan-2020  mgorny Add tests for reading registers from x86 core dumps
 1.17 08-Jan-2020  mgorny Combine x86 register tests into unified test function

Reduce the code duplication and improve maintainability of x86 register
tests by combining all of them to a single base function.
 1.16 26-Jun-2019  mgorny Implement PT_GETXSTATE and PT_SETXSTATE

Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE,
that provide access to the extended (and extensible) set of FPU
registers on amd64 and i386. At the moment, this covers AVX (YMM)
and AVX-512 (ZMM, opmask) registers. It can be easily extended
to cover further register types without breaking backwards
compatibility.

PT_GETXSTATE issues the XSAVE instruction with all kernel-supported
extended components enabled. The data is copied into 'struct xstate'
(which -- unlike the XSAVE area itself -- has stable format
and offsets).

PT_SETXSTATE issues the XRSTOR instruction to restore the register
values from user-provided 'struct xstate'. The function replaces only
the specific XSAVE components that are listed in 'xs_rfbm' field,
making it possible to issue partial updates.

Both syscalls take a 'struct iovec' pointer rather than a direct
argument. This requires the caller to explicitly specify the buffer
size. As a result, existing code will continue to work correctly
when the structure is extended (performing partial reads/updates).
 1.15 04-Jun-2019  mgorny Fix alignment of SSE filling data
 1.14 04-Jun-2019  mgorny Add more debug to register writing tests
 1.13 10-May-2019  mgorny Add PT_SET*REGS tests for mm/xmm registers.
 1.12 10-May-2019  mgorny Remove obsolete size asserts.
 1.11 10-May-2019  mgorny Use newly-filled i386 reg structs in PT_GETFPREGS & PT_GETXMMREGS tests.
 1.10 09-May-2019  mgorny Add ptrace() tests for reading mm* and xmm* registers
 1.9 10-Feb-2019  kamil Link t_ptrace_wait* tests with -pthread

While there, bump (c) for ATF ptrace(2) tests.

Add __used in infinite_thread() for consistency with other functions in
the file.
 1.8 05-Feb-2019  kamil Add missing break keywords in t_ptrace_wait* x86 tests

Add missing break in switch() cases in dbregs_trap_variable().

Reported by <mrg>
Detected by GCC 7
 1.7 26-May-2018  kamil branches: 1.7.2;
Port the CVE 2018-8897 mitigation to i386 ATF ptrace(2) tests

On i386 there is no need to switch execution mode.
Use 0x23 SS selector for i386, amd64 used 0x4f.

Based on pointers from <maxv>.

Sponsored by <The NetBSD Foundation>
 1.6 13-May-2018  kamil Refactor code in ATF ptrace(2) tests

Move the can_we_set_dbregs() auxiliary function from t_ptrace_x86_wait.h
to a common file t_ptrace_wait.h. This allows using this function for
checking whether the DBREGS set operations in ptrace(2) are accessible for
a user.

Sponsored by <The NetBSD Foundation>
 1.5 08-Apr-2018  kamil Add check in ATF tests for security.models.extensions.user_set_dbregs

Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.
It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.

In case of not being able to do so, print a message and mark a test
as skipped:

Either run this test as root or set sysctl(3)
security.models.extensions.user_set_dbregs to 1

No functional change intended to the code flow of the existing tested
scenarios.

Sponsored by <The NetBSD Foundation>
 1.4 06-Mar-2018  kamil Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)

This code after refactoring stopped calling functions that were designed
to trigger expected behavior and thus, tests were breaking.

Sponsored by <The NetBSD Foundation>
 1.3 16-Dec-2017  christos branches: 1.3.2;
Add expected failures.
 1.2 14-Dec-2017  christos sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
 1.1 02-Apr-2017  kamil branches: 1.1.2; 1.1.4; 1.1.8;
Import ptrace(2) tests into appropriate directory tests/lib/libc/sys/

This is the correct directory documented in tests/README for such tests.

Discussed with <martin>

Sponsored by <The NetBSD Foundation>
 1.1.8.2 12-Apr-2018  martin Pull up following revision(s) (requested by kamil in ticket #711):
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.24-1.31
tests/lib/libc/sys/t_ptrace_wait.h: revision 1.2
tests/lib/libc/sys/t_ptrace_x86_wait.h: revision 1.4,1.5
tests/lib/libc/sys/msg.h: revision 1.2

Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)

This code after refactoring stopped calling functions that were designed
to trigger expected behavior and thus, tests were breaking.
Sponsored by <The NetBSD Foundation>

ATF: Correct a race bug in attach2 (t_ptrace_wait*)
At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.

Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.

This test is still racy for some other and unknown reason and this is bei=
ng
investigated.

Sponsored by <The NetBSD Foundation>

ATF: Reenable attach2 in t_ptrace_wait*

The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).

This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.
The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2=
)/
read(2) or close to these features.

Sponsored by <The NetBSD Foundation>

Add a new function in ATF t_ptrace_wait*: await_zombie_raw()

Add await_zombie_raw() that is the same as await_zombie(), whith an
addition of additional "useconds_t ms" parameter indicating delays betwee=
n
new polling for a zombie process.

This new function will be used for testing a race condition that has been=
observed occassionally crashing a test case -- returning duplicate entrie=
s
for KERN_PROC_PID.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait*: Disable debug messages in msg.h
msg.h is a dummy IPC interface.

Disable additional debugging logging here, especially wanted in race*
tests.

Sponsored by <The NetBSD Foundation>

ATF: Add new test race1 in t_ptrace_wait*

Reuse the attach1's test body for race1.

Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported
race1 requires HAVE_PID in wait(2)-like function.

This test is executed in a loop for 5 seconds (16k iterations on Intel i7=
).
A buggy kernel was asserting an error within this timeframe almost always=
=2E
The bug in the kernel is now gone and this test is expected to pass
correctly.

Sponsored by <The NetBSD Foundation>

Add check in ATF tests for security.models.extensions.user_set_dbregs
Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.

It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.
In case of not being able to do so, print a message and mark a test
as skipped:
Either run this test as root or set sysctl(3)
security.models.extensions.user_set_dbregs to 1
No functional change intended to the code flow of the existing tested
scenarios.

Sponsored by <The NetBSD Foundation>

Improve documentation of the ATF test t_ptrace_wait*: traceme2
Set the description to:
Verify that a signal emitted by a tracer to a child is caught by
a signal handler.

Sponsored by <The NetBSD Foundation>

Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)

Marge bodies of two tests into the same function.

Add few checks for regular fork or not (vfork).

Sponsored by <The NetBSD Foundation>

ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones
Reduce code duplication, use the same function body with conditional
switches.

Sponsored by <The NetBSD Foundation>

ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2

Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().

There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.
PR kern/51630

Sponsored by <The NetBSD Foundation>

Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests

Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.=
Merge vforkdone1 and vforkdone2 into vfork* tests.

All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE

All the PTRACE_VFORK tests are marked as expected failure.

Sponsored by <The NetBSD Foundation>
 1.1.8.1 25-Feb-2018  snj Pull up following revision(s) (requested by martin in ticket #586):
tests/lib/libc/sys/t_ptrace_amd64_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_i386_wait.h: 1.2
tests/lib/libc/sys/t_ptrace_wait.c: 1.10-1.20
tests/lib/libc/sys/t_ptrace_x86_wait.h: 1.2-1.3
PR kern/52167 strikes on sparc64 too.
--
Temporarily disable t_ptrace_wait*::resume1 in ATF tests
It hangs forever on releng machines.
Sponsored by <The NetBSD Foundation>
--
Remove expected failure (fixed in kern_sig.c 1.339)
--
sync a bit more with reality; some things still fail, some new failures.
reduce spewage, be more explanatory about syscall errors.
--
Add expected failures.
--
make it fail instead of hang under qemu; XXX: need to investigate.
--
t_ptrace_wait*: Disable suspend* tests
These tests can hang the system. These interfaces will be improved and
temporarily disable them.
--
ptrace atf: Clanup reports of failures
Mark resume* suspend* tests as expected failure and link with PR 51995.
Sponsored by <The NetBSD Foundation>
--
report which errno failed
--
atf: t_ptrace_wait: Mark attach2 as racy
--
atf: ptrace: Temporarily disable signal3 as it breaks now on some ports
This test is marked as failing with: PR kern/51918.
 1.1.4.2 26-Apr-2017  pgoyette Sync with HEAD
 1.1.4.1 02-Apr-2017  pgoyette file t_ptrace_x86_wait.h was added on branch pgoyette-localcount on 2017-04-26 02:53:33 +0000
 1.1.2.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 02-Apr-2017  bouyer file t_ptrace_x86_wait.h was added on branch bouyer-socketcan on 2017-04-21 16:54:11 +0000
 1.3.2.4 25-Jun-2018  pgoyette Sync with HEAD
 1.3.2.3 21-May-2018  pgoyette Sync with HEAD
 1.3.2.2 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.3.2.1 15-Mar-2018  pgoyette Synch with HEAD
 1.7.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.2.1 10-Jun-2019  christos Sync with HEAD
 1.31.12.1 02-Aug-2025  perseant Sync with HEAD
 1.4 21-Aug-2018  christos revert copyright change.
 1.3 21-Aug-2018  christos more tests
 1.2 21-Mar-2018  roy branches: 1.2.2;
Handle ENOBUFS when receiving messages.
Don't send messages if the receiver has died.
 1.1 22-Jun-2012  christos branches: 1.1.4; 1.1.26; 1.1.32;
tests for recvmmsg
 1.1.32.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.32.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.1.26.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by roy in ticket #724):
tests/net/icmp/t_ping.c: revision 1.19
sys/netinet6/raw_ip6.c: revision 1.166
sys/netinet6/ip6_input.c: revision 1.195
sys/net/raw_usrreq.c: revision 1.59
sys/sys/socketvar.h: revision 1.151
sys/kern/uipc_socket2.c: revision 1.128
tests/lib/libc/sys/t_recvmmsg.c: revision 1.2
lib/libc/sys/recv.2: revision 1.38
sys/net/rtsock.c: revision 1.239
sys/netinet/udp_usrreq.c: revision 1.246
sys/netinet6/icmp6.c: revision 1.224
tests/net/icmp/t_ping.c: revision 1.20
sys/netipsec/keysock.c: revision 1.63
sys/netinet/raw_ip.c: revision 1.172
sys/kern/uipc_socket.c: revision 1.260
tests/net/icmp/t_ping.c: revision 1.22
sys/kern/uipc_socket.c: revision 1.261
tests/net/icmp/t_ping.c: revision 1.23
sys/netinet/ip_mroute.c: revision 1.155
sbin/route/route.c: revision 1.159
sys/netinet6/ip6_mroute.c: revision 1.123
sys/netatalk/ddp_input.c: revision 1.31
sys/netcan/can.c: revision 1.3
sys/kern/uipc_usrreq.c: revision 1.184
sys/netinet6/udp6_usrreq.c: revision 1.138
tests/net/icmp/t_ping.c: revision 1.18
socket: report receive buffer overflows
Add soroverflow() which increments the overflow counter, sets so_error
to ENOBUFS and wakes the receive socket up.
Replace all code that manually increments this counter with soroverflow().
Add soroverflow() to raw_input().
This allows userland to detect route(4) overflows so it can re-sync
with the current state.
socket: clear error even when peeking
The error has already been reported and it's pointless requiring another
recv(2) call just to clear it.
socket: remove now incorrect comment that so_error is only udp
As it can be affected by route(4) sockets which are raw.
rtsock: log dropped messages that we cannot report to userland
Handle ENOBUFS when receiving messages.
Don't send messages if the receiver has died.
Sprinkle more soroverflow().
Handle ENOBUFS in recv
Handle ENOBUFS in sendto
Note value received. Harden another sendto for ENOBUFS.
Handle the routing socket overflowing gracefully.
Allow a valid sendto .... duh
Handle errors better.
Fix test for checking we sent all the data we asked to.
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 22-Jun-2012  yamt file t_recvmmsg.c was added on branch yamt-pagecache on 2012-10-30 19:00:02 +0000
 1.2.2.1 10-Jun-2019  christos Sync with HEAD
 1.2 13-Jan-2017  christos PR/51860: Ngie Cooper: don't leak fd
 1.1 07-Jul-2011  jruoho branches: 1.1.24;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5 18-Oct-2024  riastradh tests/lib/libc/sys/t_select: Test select on bad file descriptors.

This should immediately fail, not hang, even if the bad fd is
high-numbered.

PR kern/57504: select with large enough bogus fd number set hangs
instead of failing with EBADF
 1.4 13-Jan-2017  christos branches: 1.4.16; 1.4.28; 1.4.30;
PR/51861: Ngie Cooper: Sprinkle __unused, mark __dead, _exit().
 1.3 18-Mar-2012  jruoho branches: 1.3.14;
Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.2 12-Dec-2011  skrll Give the child more time to timeout, etc.
 1.1 07-Jul-2011  jruoho branches: 1.1.2;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.3.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4.30.1 02-Aug-2025  perseant Sync with HEAD
 1.4.28.1 18-Nov-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1011):

sys/kern/sys_select.c: revision 1.67
tests/lib/libc/sys/t_select.c: revision 1.5

PR kern/57504 : Check all fds passed in to select

If an application passes in a huge fd_set (select(BIG, ...))
then check every bit in the fd_sets provided, to make sure
they are valid.

If BIG is too big (cannot possibly represent an open fd for
this process, under any circumstances: ie: not just because
that many are not currently open) return EINVAL.
Otherwise, check every set bit to make sure it is valid. Any
fd bits set above the applications current highest open fd
automatically generate EBADF and quick(ish) exit.
fd's that are within the plausible range are then checked as
they always were (it is possible for there to be a few there
above the max open fd - as everything in select is done in
multiples of __FDBITS (fd_mask) but the max open fd is not so
constrained. Those always were checked, continue using the
same mechanism.

This should have zero impact on any sane application which
uses the highest fd for which it set a bit, +1, as the first
arg to select. However, if there are any broken applications
that were relying upon the previous behaviour of simply ignoring
any fd_masks that started beyond the max number of open files,
then they might (if they happen to have any bits set) now fail.

tests/lib/libc/sys/t_select: Test select on bad file descriptors.
This should immediately fail, not hang, even if the bad fd is
high-numbered.

PR kern/57504: select with large enough bogus fd number set hangs
instead of failing with EBADF
 1.4.16.1 20-Nov-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1926):

sys/kern/sys_select.c: revision 1.67 (patch)
tests/lib/libc/sys/t_select.c: revision 1.5 (patch)

PR kern/57504 : Check all fds passed in to select

If an application passes in a huge fd_set (select(BIG, ...))
then check every bit in the fd_sets provided, to make sure
they are valid.

If BIG is too big (cannot possibly represent an open fd for
this process, under any circumstances: ie: not just because
that many are not currently open) return EINVAL.

Otherwise, check every set bit to make sure it is valid. Any
fd bits set above the applications current highest open fd
automatically generate EBADF and quick(ish) exit.
fd's that are within the plausible range are then checked as
they always were (it is possible for there to be a few there
above the max open fd - as everything in select is done in
multiples of __FDBITS (fd_mask) but the max open fd is not so
constrained. Those always were checked, continue using the
same mechanism.

This should have zero impact on any sane application which
uses the highest fd for which it set a bit, +1, as the first
arg to select. However, if there are any broken applications
that were relying upon the previous behaviour of simply ignoring
any fd_masks that started beyond the max number of open files,
then they might (if they happen to have any bits set) now fail.


tests/lib/libc/sys/t_select: Test select on bad file descriptors.

This should immediately fail, not hang, even if the bad fd is
high-numbered.

PR kern/57504: select with large enough bogus fd number set hangs
instead of failing with EBADF
 1.3 16-Mar-2019  christos branches: 1.3.2;
PR/54062: Using random garbage in the mmsghdr (in this case 0xa5's from
jemalloc debug) makes the syscall unhappy. Zero out the memory instead...
 1.2 16-Oct-2018  roy Handle ENOBUFS better and clean some whitespace.
 1.1 21-Aug-2018  christos branches: 1.1.2;
more tests
 1.1.2.3 20-Oct-2018  pgoyette Sync with head
 1.1.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.2.1 21-Aug-2018  pgoyette file t_sendmmsg.c was added on branch pgoyette-compat on 2018-09-06 06:56:48 +0000
 1.3.2.2 10-Jun-2019  christos Sync with HEAD
 1.3.2.1 16-Mar-2019  christos file t_sendmmsg.c was added on branch phil-wifi on 2019-06-10 22:10:05 +0000
 1.8 28-Mar-2021  christos yield so we can lose packets
 1.7 21-Mar-2021  christos use a pipe instead of sched_yield()
 1.6 03-Feb-2019  mrg branches: 1.6.2; 1.6.8;
- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.5 06-Nov-2018  christos Add a test to enable rerror handling.
 1.4 22-Aug-2018  christos branches: 1.4.2;
Den't set SA_RESTART in the signal handler allowing the process to get
interrupted durning recv and exit (pointed out by kre@)
 1.3 21-Aug-2018  christos mark failed
 1.2 21-Aug-2018  christos should terminate and does with ktrace, but it does not normally.
 1.1 21-Aug-2018  christos Now add the file I really meant to add.
 1.4.2.3 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.4.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.4.2.1 22-Aug-2018  pgoyette file t_sendrecv.c was added on branch pgoyette-compat on 2018-09-06 06:56:48 +0000
 1.6.8.1 03-Apr-2021  thorpej Sync with HEAD.
 1.6.2.2 10-Jun-2019  christos Sync with HEAD
 1.6.2.1 03-Feb-2019  christos file t_sendrecv.c was added on branch phil-wifi on 2019-06-10 22:10:05 +0000
 1.11 07-Dec-2023  riastradh t_setrlimit: Narrow the scope of stack-protector warning suppression.
 1.10 22-Nov-2023  riastradh t_setrlimit: Fix typos in comments and messages.

No substantive change intended. Suggested by rillig@.

PR kern/57711

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.9 21-Nov-2023  riastradh exec: Map noaccess part of stack with prot=NONE, maxprot=READ|WRITE.

This way, setrlimit(RLIMT_STACK) can grant READ|WRITE access when
increasing the stack size.

PR kern/57711

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.8 20-Nov-2023  riastradh t_setrlimit: Verify changing RLIMIT_STACK affects access to stack.

PR kern/57711

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.7 13-Oct-2020  rin branches: 1.7.10;
Bump soft/hard limits for stack to 6MB for aarch64{,eb}, where old value
(~4MB) is too small to be accepted.
 1.6 13-Jan-2017  christos branches: 1.6.6; 1.6.16;
PR/51862: Ngie Cooper: don't leak buf
 1.5 13-Jul-2016  njoly branches: 1.5.2;
Add testcase that ensure that stack hard limit is never smaller than
soft limit.
 1.4 12-Jun-2012  christos check thread limit
 1.3 11-Mar-2012  njoly Use ATF_CHECK_ERRNO in setrlimit_perm().
 1.2 22-Aug-2011  dholland branches: 1.2.2;
Requires stdint.h.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.5.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6.16.1 28-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1769):

tests/lib/libc/sys/t_setrlimit.c: revision 1.8
tests/lib/libc/sys/t_setrlimit.c: revision 1.9
sys/kern/exec_subr.c: revision 1.86

t_setrlimit: Verify changing RLIMIT_STACK affects access to stack.
PR kern/57711

exec: Map noaccess part of stack with prot=NONE, maxprot=READ|WRITE.
This way, setrlimit(RLIMT_STACK) can grant READ|WRITE access when
increasing the stack size.
PR kern/57711
 1.6.6.1 28-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1920):

tests/lib/libc/sys/t_setrlimit.c: revision 1.8
tests/lib/libc/sys/t_setrlimit.c: revision 1.9
sys/kern/exec_subr.c: revision 1.86

t_setrlimit: Verify changing RLIMIT_STACK affects access to stack.
PR kern/57711

exec: Map noaccess part of stack with prot=NONE, maxprot=READ|WRITE.
This way, setrlimit(RLIMT_STACK) can grant READ|WRITE access when
increasing the stack size.
PR kern/57711
 1.7.10.1 28-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #477):

tests/lib/libc/sys/t_setrlimit.c: revision 1.8
tests/lib/libc/sys/t_setrlimit.c: revision 1.9
sys/kern/exec_subr.c: revision 1.86

t_setrlimit: Verify changing RLIMIT_STACK affects access to stack.
PR kern/57711

exec: Map noaccess part of stack with prot=NONE, maxprot=READ|WRITE.
This way, setrlimit(RLIMT_STACK) can grant READ|WRITE access when
increasing the stack size.
PR kern/57711
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.5 13-Jan-2017  christos Don't play with "../.." in includes for h_macros.h; deal with it centrally.
Minor fixes.
 1.4 13-Jan-2017  christos PR/51848: Ngie Cooper: tests/lib/libc/sys/t_sigaction: mark variables __unused
XXX: h_macros.h needs to be fixed differently.
 1.3 04-Nov-2014  justin branches: 1.3.2;
PR misc/49356 remove unnecessary references to atf-c/config.h

The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
 1.2 07-Nov-2012  pgoyette Merge in the minimal test from the old src/regress/sys/kernel/sigtramp
test.
 1.1 15-Oct-2011  jruoho branches: 1.1.2; 1.1.8;
Move the sigaction(2) test to the right place.
 1.1.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.1.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.3.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 01-May-2020  christos no need for alloca() (breaks SSP)
 1.1 30-Apr-2020  ryo Add a test for sigaltstack(2) and SA_ONSTACK
 1.7 13-Jan-2017  christos PR/51847: Ngie Cooper: More error checks, add __unused
 1.6 04-Aug-2016  christos Realtime signal support from GSoC 2016, Charles Cui.
 1.5 06-Jun-2015  joerg branches: 1.5.2;
Don't pass uninitialized variables by value.
 1.4 07-Jul-2011  jruoho Rename test case names.
 1.3 10-Jan-2011  christos remove clauses 3/4
 1.2 10-Jan-2011  christos make constant fit in 32 bits.
 1.1 10-Jan-2011  christos test for sigqueue
 1.5.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.5.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.2 08-Mar-2013  martin branches: 1.2.4; 1.2.10;
Sharpen the "return imediately" test case and fix/uncomment the "wait untill
signal" one.
 1.1 08-Mar-2013  martin Rename testprogram and make it more general by adding other testcases.
One commented out, I didn't manage to get all signal handling correct
for now.
 1.2.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.10.1 08-Mar-2013  yamt file t_sigtimedwait.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 08-Mar-2013  tls file t_sigtimedwait.c was added on branch tls-maxphys on 2013-06-23 06:28:56 +0000
 1.2 08-Mar-2013  martin Rename testprogram and make it more general by adding other testcases.
One commented out, I didn't manage to get all signal handling correct
for now.
 1.1 08-Mar-2013  martin Add a test program for PR kern/47625, based on the sample code provided
by anthony mallet.
 1.3 17-Jul-2025  kre ATF test additions for O_CLOFORK.

These are Ricardo Branco's ATF test modifications for O_CLOFORK
& SOCK_CLOFORK (with some FD_CLOFORK included).

These have all been made able to be built & run in an environment
where O_CLOFORK (etc) are not yet visible to userland.
 1.2 13-Jan-2017  christos branches: 1.2.30;
PR/51846: Ngie Cooper: closefrom(3) instead of fcntl(3, F_CLOSEM)
for portability
 1.1 05-Nov-2011  jruoho branches: 1.1.2; 1.1.24;
Move connect(2), listen(2) and socketpair(2) tests to the right place.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 05-Nov-2011  yamt file t_socketpair.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.2.30.1 02-Aug-2025  perseant Sync with HEAD
 1.6 16-Jul-2019  martin PR misc/54382: whenever open(2) is called with O_CREAT, make sure to
pass an open mode argument.
 1.5 13-Jan-2017  christos branches: 1.5.14;
PP/51845: Ngie Cooper: need <netinet/in.h> for htonl etc and fix socket leak
 1.4 17-Mar-2012  jruoho branches: 1.4.14;
PR kern/46077 was fixed; remove xfail.
 1.3 06-Mar-2012  jruoho A test case for PR kern/46077: fstat() returns EINVAL on dup'd connected
socket. Expected failure on NetBSD x86, 5.0 - 6.0. Does not fail on Linux.
 1.2 16-Oct-2011  jruoho branches: 1.2.2;
Remove atf_tc_skip() to see whether this still panics i386/qemu.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.4.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 27-May-2024  thorpej Mark as expected-fail on VAX (PR port-vax/58290).
 1.4 01-Aug-2023  andvar fix RCSIDs.
 1.3 05-May-2013  skrll Whitespace
 1.2 27-Sep-2012  skrll branches: 1.2.2;
Simplify
 1.1 12-Sep-2012  manu branches: 1.1.2;
setcontext() used to be incompatible with -lpthread since it affected
the TLS pointer, therefore wrecking the pthread environement.

Some ports had _UC_TLSBASE flag or equivalent (_UC_UNIQUE on alpha)
that controlled whether setcontext() would change the TLS pointer.
This change let libpthread override setcontext() with its own version
that unsets _UC_TLSBASE, enabling safe usage of setcontext() with
-lpthread.

We also have the following required changes here:
- rename alpha's _UC_UNIQUE into _UC_TLSBASE
- add _UC_TLSBASE definition in header file for all ports
(powerpc, sh3, sparc and sparc64 lack the implementation for now)
- introduce a libc stub that can be overriden for setcontext()
- modify MD libcs swapcontext() implementations so that they use the
setcontext() libc stub instead of doing a plain system call.

While we are there:
- document various MD _UC_* flags in header file
- add libc and libpthread tests for swapcontext() behavior
(hopefully helpful to spot MD problems introduced with this change)

Future work:
- Deciding whether kernel support or _UC_TLSBASE should be added for
powerpc, sh3, sparc and sparc64 is left to portmasters
sparc64

Approved by core@
 1.1.2.2 23-Jun-2013  tls resync from head
 1.1.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 27-Sep-2012  yamt file t_swapcontext.c was added on branch yamt-pagecache on 2012-10-30 19:00:02 +0000
 1.4 18-Jan-2021  simonb Check for MAP_FAILED instead of NULL when looking for an error from mmap(2).
 1.3 28-May-2018  martin branches: 1.3.2; 1.3.10;
PR port-amd64/53316: two int don't make a long (when passed to
a C variadic function)
 1.2 25-May-2018  martin Fix typo in local macro name, pointed out by uwe
 1.1 25-May-2018  martin Add a test to verify syscall() and/or __syscall() are working.
This used to trigger a panic (see PR kern/53261) on arm.
 1.3.10.1 03-Apr-2021  thorpej Sync with HEAD.
 1.3.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.3.2.1 28-May-2018  pgoyette file t_syscall.c was added on branch pgoyette-compat on 2018-06-25 07:26:09 +0000
 1.10 16-Apr-2025  riastradh t_timer_create, t_timerfd: Make the invalidtime tests make sense.

Don't use uninitialized memory. Skip the absolute test when it's
just a time in the past (which should expire immediately), not an
invalid time.

PR misc/59300: timer/timerfd invalidtime tests are failing
 1.9 19-Dec-2024  riastradh timer_settime(2): Return relative duration remaining.

Not absolute time of next event.

PR kern/58917: timer_settime and timerfd_settime return absolute time
of next event
 1.8 19-Dec-2024  riastradh timer_settime(2): Fix error code for negative it_interval.

PR kern/58920: timer_settime fails ETIMEDOUT on negative interval,
not EINVAL
 1.7 19-Dec-2024  riastradh t_timer_create: Fix up tests for edge cases.

While here, save and restore errno in signal handler.

PR kern/58919: timer_settime fails to trigger for past times

PR kern/58920: timer_settime fails ETIMEDOUT on negative interval, not
EINVAL
 1.6 18-Dec-2024  riastradh t_timer_create: Add some more test cases.

PR kern/58917: timer_settime and timerfd_settime return absolute time
of next event

PR kern/58919: timer_settime fails to trigger for past times
 1.5 16-Jan-2017  christos branches: 1.5.28;
PR/51892: Ngie Cooper: add __unused to `osi` in the sigaction handler
 1.4 18-Mar-2012  jruoho branches: 1.4.14; 1.4.18;
Move the references to PRs from code comments to the test description. Once
ATF has the ability to output the metadata in the HTML reports, it should be
easy to traverse between releng and gnats -reports via links.
 1.3 18-Dec-2011  christos test timer expiration.
 1.2 17-Sep-2011  jruoho branches: 1.2.2;
Simplify.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.4.18.1 21-Apr-2017  bouyer Sync with HEAD
 1.4.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.28.1 02-Aug-2025  perseant Sync with HEAD
 1.12 16-Apr-2025  riastradh t_timer_create, t_timerfd: Make the invalidtime tests make sense.

Don't use uninitialized memory. Skip the absolute test when it's
just a time in the past (which should expire immediately), not an
invalid time.

PR misc/59300: timer/timerfd invalidtime tests are failing
 1.11 19-Dec-2024  riastradh timerfd_settime(2): Return relative duration remaining.

Not absolute time of next event.

PR kern/58917: timer_settime and timerfd_settime return absolute time
of next event
 1.10 19-Dec-2024  riastradh timerfd_settime(2): Sanitize inputs like timer_settime(2).

PR kern/58914: timerfd_settime(2) is missing itimespecfix
 1.9 19-Dec-2024  riastradh t_timerfd: Test for timerfd_settime old_value.

PR kern/58917: timer_settime and timerfd_settime return absolute time
of next event
 1.8 19-Dec-2024  riastradh t_timerfd: Sprinkle additional tests of various edge cases.

PR kern/58914: timerfd_settime(2) is missing itimespecfix
 1.7 19-Dec-2024  riastradh t_timerfd: Fix select/poll tests and add kevent EVFILT_WRITE test.

PR kern/58916: timerfd(2) claims ready for write
 1.6 18-Dec-2024  riastradh timerfd(2): Do not claim writable.

Writes will fail with EOPNOTSUPP.

PR kern/58916: timerfd(2) claims ready for write
 1.5 08-Jul-2023  riastradh branches: 1.5.2;
t_timerfd: Sprinkle slightly more diagnostics.

Might help us to see if we're off by just a little bit (maybe a tiny
jitter between the hardclock timer and the monotonic clock), or if
something is seriously amiss when the timerfd_block test fails
sporadically.
 1.4 20-Feb-2022  thorpej Validate basic fcntl(2) behavior for eventfd and timerfd.
 1.3 01-Nov-2021  hannken Test lib/libc/sys/t_timerfd often fails when run on QEMU because
QEMU misses clock interrupts.

Always check values against [ lower, upper ] bounds and use "4 * upper"
when run under QEMU.

Now becomes part of PR kern/43997 "Kernel timer discrepancies".
 1.2 19-Sep-2021  thorpej Add native implementations of eventfd(2) and timerfd(2), compatible with
the Linux interfaces of the same name.
 1.1 14-Dec-2020  thorpej branches: 1.1.2;
file t_timerfd.c was initially added on branch thorpej-futex.
 1.1.2.1 14-Dec-2020  thorpej Unit tests for timerfd.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 13-Jan-2017  christos PR/51844: Ngie Cooper: use root-owned file created during build instead of
/usr/bin/fpr
 1.2 18-Aug-2011  dholland branches: 1.2.24;
Fix the errno tests so if someone messes up permission checks and it
fails, it won't trash your /root/profile. Instead, the victim will be
/usr/bin/fpr. This way it at least won't break the world.

XXX: this test should probably be testing such things in a rump namespace.
 1.1 07-Jul-2011  jruoho Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.2.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5 27-Feb-2018  kamil Include <inttypes.h> in t_ucontext.c

The <inttypes.h> user-land header is required for PRI types.
We were including indirectly <sys/inttypes.h> through <sys/*.h> sources,
and this worked for most of the ports.

This fixes indirectly a build for MIPS (tested ports: arc and hpcmips),
where PRI types (PRIxREGISTER) were undefined.

Noted by <uwe>.
 1.4 27-Feb-2018  kamil Make the t_ucontext.c test more portable

Cast _UC_MACHINE_*(&u) to (register_t).
This allows to print the returned values with PRIxREGISTER.

This corrects build failures on MIPS and HPPA.
sizeof(int) == sizeof(long) on these 32-bit systems.
 1.3 25-Feb-2018  christos fix spello
 1.2 25-Feb-2018  kamil Add new tests in lib/libc/sys/t_ucontext

New tests:
- ucontext_sp
- ucontext_fp
- ucontext_pc
- ucontext_intrv

They test respectively:
- _UC_MACHINE_SP
- _UC_MACHINE_FP
- _UC_MACHINE_PC
- _UC_MACHINE_INTRV

These tests attempt to access and print the values from ucontext, without
interpreting the values.

This is a follow up of the _UC_MACHINE_FP() introduction.

These tests use PRIxREGISTER, and require to be built with -D_KERNTYPES.

Sponsored by <The NetBSD Foundation>
 1.1 15-Oct-2011  jruoho branches: 1.1.34;
Move the ucontext(2) test to the right place.
 1.1.34.3 21-Mar-2018  martin Pull up the following, requested by kamil in ticket #552:

external/gpl3/gcc{.old}/dist/libsanitizer/asan/asan_linux.cc 1.4
sys/arch/aarch64/include/mcontext.h 1.2
sys/arch/alpha/include/mcontext.h 1.9
sys/arch/amd64/include/mcontext.h 1.19
sys/arch/arm/include/mcontext.h 1.19
sys/arch/hppa/include/mcontext.h 1.9
sys/arch/i386/include/mcontext.h 1.14
sys/arch/ia64/include/mcontext.h 1.6
sys/arch/m68k/include/mcontext.h 1.10
sys/arch/mips/include/mcontext.h 1.22
sys/arch/or1k/include/mcontext.h 1.2
sys/arch/powerpc/include/mcontext.h 1.18
sys/arch/riscv/include/mcontext.h 1.5
sys/arch/sh3/include/mcontext.h 1.11
sys/arch/sparc/include/mcontext.h 1.14-1.17
sys/arch/sparc64/include/mcontext.h 1.10
sys/arch/vax/include/mcontext.h 1.9
tests/lib/libc/sys/Makefile 1.50
tests/lib/libc/sys/t_ucontext.c 1.2-1.5
sys/arch/hppa/include/mcontext.h 1.10
sys/arch/ia64/include/mcontext.h 1.7

- Introduce _UC_MACHINE_FP(). _UC_MACHINE_FP() is a helper
macro to extract from mcontext a frame pointer.
- Add new tests in lib/libc/sys/t_ucontext:
* ucontext_sp (testing _UC_MACHINE_SP)
* ucontext_fp (testing _UC_MACHINE_FP)
* ucontext_pc (testing _UC_MACHINE_PC)
* ucontext_intrv (testing _UC_MACHINE_INTRV)

Add a dummy implementation of _UC_MACHINE_INTRV() for ia64.

Implement _UC_MACHINE_INTRV() for hppa.

Make the t_ucontext.c test more portable.

We now have _UC_MACHINE_FP.
 1.1.34.2 26-Feb-2018  snj revert ticket 552, which broke the build
 1.1.34.1 25-Feb-2018  snj Pull up following revision(s) (requested by kamil in ticket #552):
sys/arch/aarch64/include/mcontext.h: 1.2
sys/arch/alpha/include/mcontext.h: 1.9
sys/arch/amd64/include/mcontext.h: 1.19
sys/arch/arm/include/mcontext.h: 1.19
sys/arch/hppa/include/mcontext.h: 1.9
sys/arch/i386/include/mcontext.h: 1.14
sys/arch/ia64/include/mcontext.h: 1.6
sys/arch/m68k/include/mcontext.h: 1.10
sys/arch/mips/include/mcontext.h: 1.22
sys/arch/or1k/include/mcontext.h: 1.2
sys/arch/powerpc/include/mcontext.h: 1.18
sys/arch/riscv/include/mcontext.h: 1.5
sys/arch/sh3/include/mcontext.h: 1.11
sys/arch/sparc/include/mcontext.h: 1.14-1.17
sys/arch/sparc64/include/mcontext.h: 1.10
sys/arch/vax/include/mcontext.h: 1.9
tests/lib/libc/sys/Makefile: 1.50
tests/lib/libc/sys/t_ucontext.c: 1.2
Introduce _UC_MACHINE_FP() as a macro
_UC_MACHINE_FP() is a helper macro to extract from mcontext a frame pointer.
Don't rely on this interface as a compiler might strip frame pointer or
optimize it making this interface unreliable.
For hppa assume a small frame context, for larger frames FP might be located
in a different register (4 instead of 3).
For ia64 there is no strict frame pointer, and registers might rotate.
Reuse 79 following:
./gcc/config/ia64/ia64.h:#define HARD_FRAME_POINTER_REGNUM LOC_REG (79)
Once ia64 will mature, this should be revisited.
A macro can encapsulate a real function for extracting Frame Pointer on
more complex CPUs / ABIs.
For the remaining CPUs, reuse standard register as defined in appropriate ABI.
The direct users of this macro are LLVM and GCC with Sanitizers.
Proposed on tech-userlevel@.
Sponsored by <The NetBSD Foundation>
--
Improve _UC_MACHINE_FP() for SPARC/SPARC64
Introduce a static inline function _uc_machine_fp() that contains improved
caluclation of a frame pointer.
Algorithm:
uptr *stk_ptr;
# if defined (__arch64__)
stk_ptr = (uptr *) (*sp + 2047);
# else
stk_ptr = (uptr *) *sp;
# endif
*bp = stk_ptr[15];
Noted by <mrg>
--
Make _UC_MACHINE_FP() compile again and fix it so that it does not add
the offset twice.
--
fix _UC_MACHINE32_FP() -- use 32 bit pointer value so that [15] is
the right offset. do this by using __greg32_t, which is only in
the sparc64 version, and these are only useful there, so move them.
--
Add new tests in lib/libc/sys/t_ucontext
New tests:
- ucontext_sp
- ucontext_fp
- ucontext_pc
- ucontext_intrv
They test respectively:
- _UC_MACHINE_SP
- _UC_MACHINE_FP
- _UC_MACHINE_PC
- _UC_MACHINE_INTRV
These tests attempt to access and print the values from ucontext, without
interpreting the values.
This is a follow up of the _UC_MACHINE_FP() introduction.
These tests use PRIxREGISTER, and require to be built with -D_KERNTYPES.
Sponsored by <The NetBSD Foundation>
 1.2 13-Jan-2017  christos PR/51843: Ngie Cooper: don't leak file descriptor
 1.1 07-Jul-2011  jruoho branches: 1.1.24;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 14-Jan-2017  christos PR/51868: Ngie Cooper: mkfifo does not return an fd
 1.3 13-Jan-2017  christos PR/51842: Ngie Cooper: don't leak fifo file descriptor
 1.2 21-Apr-2014  martin branches: 1.2.6;
When unlinking a directory as unprivileged user allow both EPERM and EACCESS
failures.
 1.1 07-Jul-2011  jruoho branches: 1.1.2; 1.1.8; 1.1.18;
Add the syscall tests back. Couple of files and tests were also renamed for
consistency. All of these now mimic the libc structure.
 1.1.18.1 10-Aug-2014  tls Rebase.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.6.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 18-May-2018  kamil branches: 1.1.2;
Add new ATF tests: t_fork and t_vfork

Test behavior of raise(signal) in either fork(2)ed or vfork(2)ed child.

Tests:
- raise1 SIGKILL
- raise2 SIGSTOP
- raise3 SIGTSTP
- raise4 SIGTTIN
- raise5 SIGTTOU
- raise6 SIGABRT
- raise7 SIGHUP
- raise8 SIGCONT

t_vfork:raise2 fails ignoring non-maskable SIGSTOP.

The remaining ones pass.

Sponsored by <The NetBSD Foundation>
 1.1.2.2 21-May-2018  pgoyette Sync with HEAD
 1.1.2.1 18-May-2018  pgoyette file t_vfork.c was added on branch pgoyette-compat on 2018-05-21 04:36:17 +0000
 1.10 17-Jul-2021  martin PR 56313: fix eroneous = that was meant to be ==
 1.9 04-Feb-2019  mrg - add __unreachable() after ATF_REQUIRE(pid > 0) where pid <= 0.
- rearrange one switch so that the -1/0/default cases are the
same order in all instances.
 1.8 13-Jan-2017  christos branches: 1.8.14;
PR/51841: Ngie Cooper: portability fixes for FreeBSD
 1.7 06-Nov-2016  kamil Add new tests: tests/lib/libc/sys/t_wait_noproc and t_wait_noproc_wnohang

The t_wait_noproc test checks whether wait(2)-family of functions return
error and set ECHILD for lack of childs.

The t_wait_noproc_wnohang adds to options (except wait(2), wait3(2)) new
parameter WNOHANG and verifies that error is still signaled and errno set
to ECHILD.

Currently t_wait_noproc_wnohang reports failures, these have been marked as
expected and referenced to PR standards/51606.

The problem report is authored by Robert Elz, and the initial regression
has been notified by Nicolas Joly.

Remove redundant test in tests/lib/libc/sys/t_wait for wait6(2) with no
WNOHANG specified.

Sponsored by <The NetBSD Foundation>.
 1.6 06-Nov-2016  kamil All tests in t_wait now pass

Christos Zoulas committed fixes to src/sys/sys/wait.h r.1.32.

Closes PR standards/51603

Sponsored by <The NetBSD Foundation>
 1.5 05-Nov-2016  kamil Add new test wait6_stopgo_loop in t_wait

This test verifies that it is possible to emit multiple times SIGSTOP and
SIGCONT for a child.

Add checks that status does not return more than one valid state from the
following list: STOPPED, CONTINUED, EXITED and SIGNALED. This check fails
for WIFCONTINUED()==true as it currently and wrongly returns true for
WIFSTOPPED().

This verification is added to wait6_stopgo_loop and wait6_stop_and_go and
marked as expected failure and linked with PR standards/51603.

Remove trailing whitespace.

Sponsored by <The NetBSD Foundation>
 1.4 27-Apr-2016  christos branches: 1.4.2;
- Adjust to the correct wait6 semantics (returns pid)
- Avoid race in setrlimit(2)
 1.3 06-Apr-2016  christos Use WIFCONTINUED.
 1.2 06-Apr-2016  christos Fix ATF_REQUIRE(false)
 1.1 06-Apr-2016  christos Add wait6(2) tests.
 1.4.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.4.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.8.14.1 10-Jun-2019  christos Sync with HEAD
 1.6 15-Jun-2020  christos language sensitivity
 1.5 09-Nov-2016  kamil branches: 1.5.2;
Add new tests in t_wait_noproc and t_wait_noproc to test more options types

Add new tests:
- waitpid_options
- waitid_options
- wait3_options
- wait4_options
- wait6_options

These tests are included in t_wait_noproc and t_wait_noproc_wnohang.

waitpid_options, wait3_options, wait4_options test combinations of options
of: bit for WALLSIG, WALTSIG, __WALL, __WCLONE and later a full combination
mask of WNOWAIT, WEXITED, WUNTRACED, WSTOPPED, WTRAPPED and WCONTINUED.

waitid and wait6 test full combination mask of WNOWAIT, WEXITED, WUNTRACED,
WSTOPPED, WTRAPPED and WCONTINUED -- excluded empty value and singular
WNOWAIT.

For compatibility reasons alter waitid and wait6 to test against options
WEXITED | WTRAPPED, as it's equivalent to waitpid, wait3, wait4.

The intention for these tests it to catch any possible issues with slighty
changed behavior of wait(2)-like functions in terms of valid options
values.

All tests pass successfully.

Sponsored by <The NetBSD Foundation>
 1.4 09-Nov-2016  kre PR standards/51600

These tests are no longer expected to fail when called with WNOHANG
(which is actually the t_wait_noproc_wnohang test but the sources are here.)
 1.3 08-Nov-2016  kamil Switch ATF_REQUIRE() to more appropriate ATF_REQUIRE_ERRNO()

Simplify the code of t_wait_noproc

Sponsored by <The NetBSD Foundation>
 1.2 07-Nov-2016  kamil Enable the wait3 test in t_wait_noproc_wnohang (through t_wait_noproc)

This test has set expected failure like other functions in the wait(2)
family and is linked with PR standards/51606.

The PR is labeled as:
wait4() (and friends) with WNOHANG and no children does not error

Originally, this test was accidently disabled in the WNOHANG checks. This
was noted by Robert Elz.

Sponsored by <The NetBSD Foundation>.
 1.1 06-Nov-2016  kamil Add new tests: tests/lib/libc/sys/t_wait_noproc and t_wait_noproc_wnohang

The t_wait_noproc test checks whether wait(2)-family of functions return
error and set ECHILD for lack of childs.

The t_wait_noproc_wnohang adds to options (except wait(2), wait3(2)) new
parameter WNOHANG and verifies that error is still signaled and errno set
to ECHILD.

Currently t_wait_noproc_wnohang reports failures, these have been marked as
expected and referenced to PR standards/51606.

The problem report is authored by Robert Elz, and the initial regression
has been notified by Nicolas Joly.

Remove redundant test in tests/lib/libc/sys/t_wait for wait6(2) with no
WNOHANG specified.

Sponsored by <The NetBSD Foundation>.
 1.5.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.5.2.1 09-Nov-2016  pgoyette file t_wait_noproc.c was added on branch pgoyette-localcount on 2017-01-07 08:56:55 +0000
 1.1 06-Nov-2016  kamil branches: 1.1.2;
Add new tests: tests/lib/libc/sys/t_wait_noproc and t_wait_noproc_wnohang

The t_wait_noproc test checks whether wait(2)-family of functions return
error and set ECHILD for lack of childs.

The t_wait_noproc_wnohang adds to options (except wait(2), wait3(2)) new
parameter WNOHANG and verifies that error is still signaled and errno set
to ECHILD.

Currently t_wait_noproc_wnohang reports failures, these have been marked as
expected and referenced to PR standards/51606.

The problem report is authored by Robert Elz, and the initial regression
has been notified by Nicolas Joly.

Remove redundant test in tests/lib/libc/sys/t_wait for wait6(2) with no
WNOHANG specified.

Sponsored by <The NetBSD Foundation>.
 1.1.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.1.2.1 06-Nov-2016  pgoyette file t_wait_noproc_wnohang.c was added on branch pgoyette-localcount on 2017-01-07 08:56:55 +0000
 1.7 16-Jul-2019  martin PR misc/54382: whenever open(2) is called with O_CREAT, make sure to
pass an open mode argument.
 1.6 09-Jul-2017  christos branches: 1.6.6;
add another missing munmap (Kamil)
 1.5 09-Jul-2017  christos add munmap
#define for const.
 1.4 09-Jul-2017  christos check for EFAULT on reads and writes to memory with not permission.
 1.3 13-Jan-2017  christos branches: 1.3.6;
PR/51840: Ngie Cooper: portability fixes for FreeBSD, etc
 1.2 19-Oct-2011  jruoho branches: 1.2.24;
Add few basic checks.
 1.1 15-Oct-2011  jruoho Move the writev(2) test to the right place.
 1.2.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.6.1 24-Jul-2017  snj Pull up following revision(s) (requested by kamil in ticket #120):
sys/uvm/uvm_fault.c: revision 1.200
tests/lib/libc/sys/t_write.c: revision 1.4-1.6
PR/52384: make uvm_fault_check() return EFAULT not EACCES, like our man
pages
(but not OpenGroup which does not document EFAULT for read/write, and onl=
y
documents EACCES for sockets) say for read/write.
--
check for EFAULT on reads and writes to memory with not permission.
--
add munmap
#define for const.
--
add another missing munmap (Kamil)
 1.6.6.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411

RSS XML Feed