Home | History | Annotate | only in /src/tests/lib/libc
History log of /src/tests/lib/libc
RevisionDateAuthorComments
 1.5 13-Jul-2010  jmmv Get rid of static Atffiles and let bsd.test.mk generate them on the fly.
 1.4 28-Feb-2010  martin remove "string" directory for now, it isn't installed
 1.3 24-Jan-2010  joerg Add a regression test for the SHA2 family that also checks for unaligned
accesses.
 1.2 21-Jul-2009  joerg Add popcount(3) and the long and long long version. Name is inspired by
gnulib, the implementation goes back to the AMD Software Optimizer
guide. A number of platforms will want to replace the C version with
assembler code using native instructions.
 1.1 20-Jul-2009  joerg Add a fast, platform independent hash function to libc.
The algorithm used is the Jenkins hash. The name (mi_vector_hash)
reflects the nature of the hash function.
Add glue for libc ATF tests and include a test case to make sure that
(mis)alignment and endianess are handled correctly.

Bump libc minor to 169.
 1.52 29-Apr-2022  pgoyette Add a new test for PR kern/56713 and set to expected_failure for now.
 1.51 08-Apr-2022  riastradh membar_ops(3): Add some automatic tests.

These tests run two threads for five seconds each to try to trigger
races in the event of broken memory barriers. They run only on
machines with at least two CPUs; on uniprocessor systems there's no
point -- the membars can correctly just be (instruction barrier)
no-ops.
 1.50 08-Mar-2020  mgorny Add tests for missing libc catalog entries
 1.49 17-Feb-2019  isaki Add ATF tests for atomic_ops(3).
 1.48 03-Aug-2018  kamil Register micro-UBSan ATF tests in the distribution

Populate distrib files, mtree lists and add the entry in Makefile to
include the new code.
 1.47 17-Feb-2014  martin branches: 1.47.24; 1.47.26;
Add a link-time test for __sync_* primitives (see PR 48368) - this
will allow us to notice missing functions during the build, instead
of when compiling arbitrary pkgsrc stuff later.
 1.46 27-Jan-2013  christos rename the only use of HAS_SSP in the tree to HAVE_SSP.
 1.45 26-Jan-2013  christos Don't include bsd.sys.mk; like sys.mk it is supposed to be used only
internally.
 1.44 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.43 27-Sep-2012  joerg Add regression test for cdbr(3) and cdbw(3).
 1.42 19-Sep-2011  jruoho branches: 1.42.2; 1.42.8;
Remove ieeefp subdirectory.
 1.41 11-Jun-2011  christos Turn warns on for all tests and fix all the bugs.
 1.40 01-May-2011  jruoho branches: 1.40.2;
Add the new 'termios' subdirectory.
 1.39 09-Apr-2011  pgoyette atf-ify the various locale tests
 1.38 09-Mar-2011  joerg Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.37 13-Jan-2011  pgoyette Moving t_hsearch - belongs in stdlib/
 1.36 13-Jan-2011  pgoyette Another test moving: lib/libc/t_inet --> lib/libc/inet/t_inet_network
 1.35 13-Jan-2011  pgoyette Last one for today: move t_ptm test from lib/libc/ to lib/libc/ttyio/
 1.34 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.33 13-Jan-2011  pgoyette The nsdispatch test belongs in libc/net and not in libc
 1.32 13-Jan-2011  pgoyette Move t_mktime and t_strptime to their own ..../time/ subdirectory.

(Concurrence from christos@)
 1.31 12-Jan-2011  pgoyette Put the atexit test where it belongs - in libc/stdlib/
 1.30 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.29 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.28 11-Jan-2011  pgoyette Atf-ify the getaddrinfo test, with updated "golden" output files.
 1.27 10-Jan-2011  christos test for sigqueue
 1.26 08-Jan-2011  pgoyette Atf-ify the regex test
 1.25 08-Jan-2011  pgoyette Atf-ify the rpc/t_xdr test
 1.24 07-Jan-2011  pgoyette Atf-ify the db tests.

XXX Note that the original regress version of this test did not run the
XXX btree_delete test; that test is broken, and is disabled for now.
 1.23 07-Jan-2011  pgoyette Atf-ify a couple more tests
 1.22 06-Jan-2011  pgoyette Atf-ify test for mktime(3)
 1.21 05-Jan-2011  pgoyette Atf-ify the nsdispath test.
 1.20 04-Jan-2011  pgoyette Update the ieeefp tests so that they can be built on all architectures.
This enables us to avoid the set-list mess.

Build tested on amd64, i386, sun2, and vax!
 1.19 03-Jan-2011  pgoyette Ooopppsss - locale/ tests are not yet ready - don't SUBIDR yet
 1.18 03-Jan-2011  pgoyette Atf-ify the atexit test
 1.17 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.16 02-Jan-2011  pgoyette Atf-ify several of the ieeefp tests.

Note that t_round is currently mostly disabled, due to PR/44293. Also,
testfloat has not been converted.
 1.15 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.14 31-Dec-2010  pgoyette Ooopppsss - ieefp tests have not been atf-ified, so remove the stuff
that got committed by mistake.
 1.13 31-Dec-2010  pgoyette Migrate a few miscellaneous tests from the old regress to atf
 1.12 27-Dec-2010  pgoyette Move the various setjmp tests from regress to atf
 1.11 27-Dec-2010  he Don't try to build the SSP tests if the target doesn't have SSP.
 1.10 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.9 25-Dec-2010  pgoyette Migrate J.T.Conklin's public-domain str* tests from regress to atf.

While here, do some clean-up and knf.
 1.8 03-Nov-2010  christos disable string again
 1.7 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.6 09-Sep-2010  christos glue glob tests
 1.5 13-Jul-2010  jmmv Get rid of static Atffiles and let bsd.test.mk generate them on the fly.
 1.4 26-Feb-2010  martin Disable population count test for now, please re-enable once
PR toolchain/42885 is fixed
 1.3 24-Jan-2010  joerg Add a regression test for the SHA2 family that also checks for unaligned
accesses.
 1.2 21-Jul-2009  joerg Add popcount(3) and the long and long long version. Name is inspired by
gnulib, the implementation goes back to the AMD Software Optimizer
guide. A number of platforms will want to replace the C version with
assembler code using native instructions.
 1.1 20-Jul-2009  joerg Add a fast, platform independent hash function to libc.
The algorithm used is the Jenkins hash. The name (mi_vector_hash)
reflects the nature of the hash function.
Add glue for libc ATF tests and include a test case to make sure that
(mis)alignment and endianess are handled correctly.

Bump libc minor to 169.
 1.40.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.42.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.42.8.2 25-Feb-2013  tls resync with head
 1.42.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.42.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.42.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.42.2.1 30-Oct-2012  yamt sync with head
 1.47.26.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.47.26.1 10-Jun-2019  christos Sync with HEAD
 1.47.24.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.2 12-Jan-2011  pgoyette Put the atexit test where it belongs - in libc/stdlib/
 1.1 03-Jan-2011  pgoyette Atf-ify the atexit test
 1.2 13-Jan-2011  pgoyette The nsdispatch test belongs in libc/net and not in libc
 1.1 05-Jan-2011  pgoyette Atf-ify the nsdispath test.
 1.2 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.2 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.2 12-Jan-2011  pgoyette Put the atexit test where it belongs - in libc/stdlib/
 1.1 03-Jan-2011  pgoyette Atf-ify the atexit test
 1.4 08-Aug-2023  riastradh t_cdb: No need for weird padding any more.

cdbw_output never needed it at runtime, and the declaration no longer
makes gcc angry about not having it.
 1.3 01-Aug-2023  mrg cdbw_output()'s 3rd argument must be a 16-byte char array, so pad the
string literals passed to it with enough nuls to make this true.

found by GCC 12.
 1.2 10-Jan-2017  christos need <sys/stat.h>
 1.1 27-Sep-2012  joerg branches: 1.1.2; 1.1.4; 1.1.16;
Add regression test for cdbr(3) and cdbw(3).
 1.1.16.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1.4.2 27-Sep-2012  joerg Add regression test for cdbr(3) and cdbw(3).
 1.1.4.1 27-Sep-2012  joerg file t_cdb.c was added on branch tls-maxphys on 2012-09-27 00:38:58 +0000
 1.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 27-Sep-2012  yamt file t_cdb.c was added on branch yamt-pagecache on 2012-10-30 18:59:59 +0000
 1.3 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.2 10-Jan-2011  njoly Do close fd 4 in cerror_64 testcase too.
 1.1 07-Jan-2011  pgoyette Atf-ify a couple more tests
 1.2 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.1 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.2 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.1 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.7 14-Jun-2011  njoly Move unsigned int/long conversion test to their own testcases, to
avoid having the whole marked as skipped. While here update testcases
names.
 1.6 11-Jun-2011  christos Turn warns on for all tests and fix all the bugs.
 1.5 10-Jun-2011  njoly Do not print sizeof values in skip message.
 1.4 10-Jun-2011  njoly Remove unneeded prototypes.
 1.3 10-Jun-2011  njoly Remove newlines from various messages.
 1.2 10-Jun-2011  njoly Do not call exit() after atf_tc_fail().
 1.1 31-Dec-2010  pgoyette branches: 1.1.4;
Migrate a few miscellaneous tests from the old regress to atf
 1.1.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4 27-Sep-2012  martin Add missing include <stdlib.h>
 1.3 27-Sep-2012  christos make the test more precise.
 1.2 14-Jun-2011  njoly branches: 1.2.2; 1.2.8;
Avoid printf(3) directive interpretation in long_format testcase
description.
 1.1 31-Dec-2010  pgoyette branches: 1.1.4;
Migrate a few miscellaneous tests from the old regress to atf
 1.1.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.2.1 30-Oct-2012  yamt sync with head
 1.2 13-Jan-2011  pgoyette Moving t_hsearch - belongs in stdlib/
 1.1 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.2 13-Jan-2011  pgoyette Another test moving: lib/libc/t_inet --> lib/libc/inet/t_inet_network
 1.1 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.2 13-Jan-2011  pgoyette Move t_mktime and t_strptime to their own ..../time/ subdirectory.

(Concurrence from christos@)
 1.1 06-Jan-2011  pgoyette Atf-ify test for mktime(3)
 1.2 13-Jan-2011  pgoyette The nsdispatch test belongs in libc/net and not in libc
 1.1 05-Jan-2011  pgoyette Atf-ify the nsdispath test.
 1.3 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.2 04-Jan-2011  pgoyette Now that PR/44311 is fixed we can remove the expected-failure from this
test.
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.2 13-Jan-2011  pgoyette Last one for today: move t_ptm test from lib/libc/ to lib/libc/ttyio/
 1.1 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.2 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.1 31-Dec-2010  pgoyette Migrate a few miscellaneous tests from the old regress to atf
 1.2 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.2 13-Jan-2011  pgoyette Move t_mktime and t_strptime to their own ..../time/ subdirectory.

(Concurrence from christos@)
 1.1 31-Dec-2010  pgoyette Moving more tests out of regress and into atf mainstream
 1.1 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.2 27-Jul-2018  ryo aarch64 support per page execute protection
 1.1 10-Aug-2014  matt branches: 1.1.4; 1.1.24; 1.1.26;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
 1.1.26.1 10-Jun-2019  christos Sync with HEAD
 1.1.24.1 28-Jul-2018  pgoyette Sync with HEAD
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file exec_prot_support.c was added on branch tls-maxphys on 2014-08-20 00:04:49 +0000
 1.1 10-Aug-2014  matt branches: 1.1.4;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file return_one.S was added on branch tls-maxphys on 2014-08-20 00:04:49 +0000
 1.1 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.2 30-Dec-2017  martin Implement helper function for alpha
 1.1 18-Jul-2011  jym branches: 1.1.34;
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.34.1 26-Feb-2018  snj Pull up following revision(s) (requested by maya in ticket #582):
tests/lib/libc/arch/alpha/return_one.S: 1.2
Implement helper function for alpha
 1.1 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.2 26-Jan-2014  matt Make this real even though it isn't yet used.
 1.1 18-Jul-2011  jym branches: 1.1.2; 1.1.8;
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.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.1 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.4 31-May-2022  skrll Avoid plabels on hppa to make some tests not crash
 1.3 31-May-2022  skrll whitespace including space before delay slot instruction.
 1.2 14-Feb-2019  mrg implement return_one for hppa, mips, ppc64, and vax.
 1.1 18-Jul-2011  jym branches: 1.1.42;
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.42.1 10-Jun-2019  christos Sync with HEAD
 1.1 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 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 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.2 05-Aug-2016  scole PR port-ia64/51261

Fix for ia64
 1.1 18-Jul-2011  jym branches: 1.1.24;
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.24.1 06-Aug-2016  pgoyette Sync with HEAD
 1.1 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.2 10-Feb-2019  mlelstv provide a test function, avoids crashing tests with SIGSEGV.
 1.1 18-Jul-2011  jym branches: 1.1.42;
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.42.1 10-Jun-2019  christos Sync with HEAD
 1.1 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.3 21-Jan-2021  simonb Use .set noreorder and use reg names.

atf- lib/libc/sys/t_mprotect mprotect_mremap_exec is a bit happier now.
 1.2 14-Feb-2019  mrg implement return_one for hppa, mips, ppc64, and vax.
 1.1 18-Jul-2011  jym branches: 1.1.42;
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.42.1 10-Jun-2019  christos Sync with HEAD
 1.1 03-Sep-2014  matt New files for OR1K support
 1.1 03-Sep-2014  matt New files for OR1K support
 1.2 16-Mar-2012  matt Allow testing of exec pages on PowerPC BookE.
Make return_one actually do the right thing.
 1.1 18-Jul-2011  jym branches: 1.1.2; 1.1.4;
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.4.1 17-May-2012  riz Pull up following revision(s) (requested by matt in ticket #252):
tests/lib/libc/arch/powerpc/exec_prot_support.c: revision 1.2
tests/lib/libc/arch/powerpc/return_one.S: revision 1.2
Allow testing of exec pages on PowerPC BookE.
Make return_one actually do the right thing.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.3 29-Mar-2015  matt add return_one_start
 1.2 16-Mar-2012  matt Allow testing of exec pages on PowerPC BookE.
Make return_one actually do the right thing.
 1.1 18-Jul-2011  jym branches: 1.1.2; 1.1.4;
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.4.1 17-May-2012  riz Pull up following revision(s) (requested by matt in ticket #252):
tests/lib/libc/arch/powerpc/exec_prot_support.c: revision 1.2
tests/lib/libc/arch/powerpc/return_one.S: revision 1.2
Allow testing of exec pages on PowerPC BookE.
Make return_one actually do the right thing.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.1 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.2 14-Feb-2019  mrg implement return_one for hppa, mips, ppc64, and vax.
 1.1 18-Jul-2011  jym branches: 1.1.42;
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.42.1 10-Jun-2019  christos Sync with HEAD
 1.1 19-Sep-2014  matt New files for Userland support of UCB RISC-V (both 32-bit and 64-bit)
 1.2 28-Mar-2015  matt Update for new RISCV ABI
 1.1 19-Sep-2014  matt New files for Userland support of UCB RISC-V (both 32-bit and 64-bit)
 1.1 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.2 20-Jul-2017  uwe Don't execute random garbage. Fixes mprotect_mremap_exec test.
 1.1 18-Jul-2011  jym branches: 1.1.34;
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.34.1 25-Jul-2017  snj Pull up following revision(s) (requested by uwe in ticket #148):
tests/lib/libc/arch/sh3/return_one.S: revision 1.2
Don't execute random garbage. Fixes mprotect_mremap_exec test.
 1.2 14-Jan-2018  martin Sync sparc with sparc64
 1.1 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.2 14-Jan-2018  martin Sync sparc with sparc64
 1.1 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.2 31-Dec-2016  martin All sparc64 CPUs support per page execute protection.
 1.1 18-Jul-2011  jym branches: 1.1.24;
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.24.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.3 08-Feb-2021  joerg Don't define a label twice.
 1.2 31-Dec-2016  martin All sparc64 CPUs support per page execute protection.
 1.1 18-Jul-2011  jym branches: 1.1.24;
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.24.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.1 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.2 14-Feb-2019  mrg implement return_one for hppa, mips, ppc64, and vax.
 1.1 18-Jul-2011  jym branches: 1.1.42;
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.42.1 10-Jun-2019  christos Sync with HEAD
 1.1 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 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.2 26-Feb-2019  isaki branches: 1.2.2;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1 17-Feb-2019  isaki Add ATF tests for atomic_ops(3).
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 26-Feb-2019  christos file Makefile was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 26-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_add.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.3 01-Mar-2019  isaki branches: 1.3.2;
Revert previous hack.
Now all libc have __sync_and_and_fetch functions.
 1.2 27-Feb-2019  christos Make the _and_and_ have-nots compile.
 1.1 26-Feb-2019  isaki Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.3.2.2 10-Jun-2019  christos Sync with HEAD
 1.3.2.1 01-Mar-2019  christos file t___sync_and.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.3 25-Apr-2025  riastradh t___sync_compare_and_swap: Mark tests xfail on armv5.

PR port-arm/56839: GCC emits wrong codes for compare_and_swap_1
bultins on armv5 (el & eb)
 1.2 13-Mar-2025  riastradh tests/lib/libc/atomic: Test subword compare-and-swap explicitly.

Make sure the sign doesn't bleed into an adjacent word.

We already had failing tests, but this should make the failures a
little more obvious and perhaps check for more adjacent problems.

PR port-arm/56839: GCC emits wrong codes for compare_and_swap_1
bultins on armv5 (el & eb)
 1.1 26-Feb-2019  isaki branches: 1.1.2; 1.1.14;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.14.1 02-Aug-2025  perseant Sync with HEAD
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_compare_and_swap.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.2 07-Apr-2025  riastradh t___sync_lock: Try to make this work on VAX.

Add note about why it _isn't_ also special on HPPA even though it may
seems like it ought to be.

PR port-vax/59260: t___sync_lock:__sync_lock_release_N tests are failing
 1.1 26-Feb-2019  isaki branches: 1.1.2; 1.1.14;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.14.1 02-Aug-2025  perseant Sync with HEAD
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_lock.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 26-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_nand.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 26-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_or.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 26-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_sub.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 26-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 26-Feb-2019  christos file t___sync_xor.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_add.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_and.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_cas.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_dec.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_inc.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_or.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.1 17-Feb-2019  isaki branches: 1.1.2;
Add ATF tests for atomic_ops(3).
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 17-Feb-2019  christos file t_atomic_swap.c was added on branch phil-wifi on 2019-06-10 22:10:03 +0000
 1.2 15-Sep-2019  christos Remove the incomplete define.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4; 1.1.32;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.32.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file Makefile was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file Makefile was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.5 07-Jul-2024  christos avoid gcc warning.
 1.4 07-Jul-2024  christos Add more tests for absolute paths with different fds. (from Svivraj)
 1.3 10-Jan-2017  christos branches: 1.3.24;
PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_faccessat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_faccessat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.24.1 02-Aug-2025  perseant Sync with HEAD
 1.7 10-Jul-2024  rillig tests/fchmodat: add missing space in test failure message
 1.6 10-Jul-2024  christos correct test conditions.
 1.5 10-Jul-2024  rillig tests/libc: replace some more '=' with the intended '=='
 1.4 10-Jul-2024  christos Fix = -> ==. Pointed out by Shivraj
 1.3 10-Jan-2017  christos branches: 1.3.14; 1.3.22; 1.3.24;
PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_fchmodat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_fchmodat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.24.1 02-Aug-2025  perseant Sync with HEAD
 1.3.22.1 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #956):

tests/lib/libc/c063/t_fchmodat.c: revision 1.4
tests/lib/libc/c063/t_fchmodat.c: revision 1.5
tests/lib/libc/c063/t_fchmodat.c: revision 1.6
tests/lib/libc/c063/t_fchmodat.c: revision 1.7
tests/lib/libc/c063/t_utimensat.c: revision 1.7

Fix = -> ==. Pointed out by Shivraj
tests/libc: replace some more '=' with the intended '=='
correct test conditions.

tests/fchmodat: add missing space in test failure message
 1.3.14.1 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1900):

tests/lib/libc/c063/t_fchmodat.c: revision 1.4
tests/lib/libc/c063/t_fchmodat.c: revision 1.5
tests/lib/libc/c063/t_fchmodat.c: revision 1.6
tests/lib/libc/c063/t_fchmodat.c: revision 1.7
tests/lib/libc/c063/t_utimensat.c: revision 1.7

Fix = -> ==. Pointed out by Shivraj
tests/libc: replace some more '=' with the intended '=='
correct test conditions.

tests/fchmodat: add missing space in test failure message
 1.4 10-Jan-2017  christos PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.3 17-Mar-2013  jmmv branches: 1.3.12;
Remove unnecessary cleanup routines.
 1.2 20-Nov-2012  martin branches: 1.2.2;
Mark a few tests that require root
 1.1 18-Nov-2012  manu branches: 1.1.2;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.4 23-Jun-2013  tls resync from head
 1.1.2.3 25-Feb-2013  tls resync with head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_fchownat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 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 16-Jan-2013  yamt sync with (a bit old) head
 1.2.2.1 20-Nov-2012  yamt file t_fchownat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.3.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3 10-Jan-2017  christos PR/51805: Ngie Cooper: Fix file descriptor leaks
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
fexecve is not implemented, so mark the test as an expected failure.

While doing this, clean this whole thing: do not define a useless cleanup
routine and wait for the subprocess to finish instead of using sleep.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_fexecve.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_fexecve.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3 10-Jan-2017  christos PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_fstatat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_fstatat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 17-Mar-2013  jmmv Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_linkat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_linkat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2 17-Mar-2013  jmmv Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_mkdirat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_mkdirat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.5 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.4 14-Jan-2017  christos branches: 1.4.12;
PR/51868: Ngie Cooper: mkfifo does not return an fd
 1.3 10-Jan-2017  christos PR/51805: Ngie Cooper: Fix file descriptor leaks
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_mkfifoat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_mkfifoat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 10-Jan-2017  christos PR/51805: Ngie Cooper: Fix file descriptor leaks
 1.3 17-Mar-2013  jmmv branches: 1.3.12;
Remove unnecessary cleanup routines.
 1.2 20-Nov-2012  martin branches: 1.2.2;
Mark a few tests that require root
 1.1 18-Nov-2012  manu branches: 1.1.2;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.4 23-Jun-2013  tls resync from head
 1.1.2.3 25-Feb-2013  tls resync with head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_mknodat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 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 16-Jan-2013  yamt sync with (a bit old) head
 1.2.2.1 20-Nov-2012  yamt file t_mknodat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.3.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10 08-Feb-2020  kamil O_SEARCH tests: expect revoke +x failure on NFS

Patch by Kyle Evans (FreeBSD)

PR misc/54946
 1.9 06-Feb-2020  martin Add a few O_SEARCH tests, currently only run on FreeBSD.
Patch from Kyle Evans.
 1.8 05-Feb-2020  martin PR misc/54940: do not combine O_SEARCH with O_RDWR, from Kyle Evans.
 1.7 05-Feb-2020  martin PR misc/54939: fix file descriptor leak, patch from Kyle Evans.
 1.6 28-Jan-2020  martin PR 54902: fix octal numbers accidently spelled as decimal.
 1.5 10-Jan-2017  christos branches: 1.5.12;
need <sys/stat.h>
 1.4 17-Mar-2013  jmmv branches: 1.4.12;
Remove unnecessary cleanup routines.
 1.3 13-Jan-2013  dholland branches: 1.3.2;
Revert defective O_SEARCH implementation committed by manu@ along with
the *at system calls on November 18th of last year. Reasons to revert
it include:
- it is incorrect in a whole variety of ways (but fortunately, one
of them is that the missing and improper permission checks have
no net effect);
- it was committed without review or discussion;
- core ruled that all the new O_* flags pertaining to the *at calls
needed to wait until their semantics could be clarified.

manu was asked to revert it on these grounds but has ignored the request.

I have left O_SEARCH defined and visible and made open() explicitly
ignore it. This way, most code that tries to use it will continue to
build and run. I've also arranged lib/libc/c063/t_o_search.c so that
the tests that make use of the O_SEARCH semantics will disappear until
O_SEARCH comes back, and fixed some mistakes and/or incorrect hacks
that were causing some of these to succeed despite the broken O_SEARCH
implementation.
 1.2 23-Nov-2012  martin Split the test cases where root/non-root makes a difference in two and mark
them apropriately. Exact permission semantics are still under discussion,
this will have to be cleaned up once that discussion is settled.
For now, one test cases fails.
 1.1 18-Nov-2012  manu branches: 1.1.2;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.4 23-Jun-2013  tls resync from head
 1.1.2.3 25-Feb-2013  tls resync with head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_o_search.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.3.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.3.2.3 23-Jan-2013  yamt sync with head
 1.3.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.3.2.1 13-Jan-2013  yamt file t_o_search.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.4.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.12.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 10-Jan-2017  christos PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_openat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_openat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 10-Jan-2017  christos PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.3 17-Mar-2013  jmmv branches: 1.3.12;
Remove unnecessary cleanup routines.
 1.2 22-Nov-2012  martin branches: 1.2.2;
0-terminate strings returned by readlinkat
 1.1 18-Nov-2012  manu branches: 1.1.2;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.4 23-Jun-2013  tls resync from head
 1.1.2.3 25-Feb-2013  tls resync with head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_readlinkat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 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 16-Jan-2013  yamt sync with (a bit old) head
 1.2.2.1 22-Nov-2012  yamt file t_readlinkat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.3.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 17-Mar-2013  jmmv Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_renameat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_renameat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2 17-Mar-2013  jmmv Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_symlinkat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_symlinkat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.3 10-Jan-2017  christos PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.2 17-Mar-2013  jmmv branches: 1.2.12;
Remove unnecessary cleanup routines.
 1.1 18-Nov-2012  manu branches: 1.1.2; 1.1.4;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.4.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.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 18-Nov-2012  yamt file t_unlinkat.c was added on branch yamt-pagecache on 2013-01-16 05:33:59 +0000
 1.1.2.3 23-Jun-2013  tls resync from head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_unlinkat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9 10-Aug-2024  riastradh t_utimensat: Don't check atime on file systems mounted noatime.

PR kern/58571: utimensat tests are failing on armv7, aarch64, and
riscv64
 1.8 10-Aug-2024  riastradh t_utimensat: Tidy this up to make failures more obvious.

PR kern/58571: utimensat tests are failing on armv7, aarch64, and
riscv64
 1.7 10-Jul-2024  rillig tests/libc: replace some more '=' with the intended '=='
 1.6 10-Jan-2017  christos branches: 1.6.14; 1.6.22; 1.6.24;
PR/51804: Ngie Cooper: Sort headers; include <sys/stat.h>. On NetBSD,
<sys/stat.h> gets side-loaded from <sys/fcntl.h>. Should be fixed.
 1.5 17-Mar-2013  jmmv branches: 1.5.12;
Remove unnecessary cleanup routines.
 1.4 22-Nov-2012  martin branches: 1.4.2;
Compare against modification time instead of creation time - which we did
not set.
 1.3 22-Nov-2012  martin Fix off by one in static array acces, use valid timestamps (ns part < 1e9),
just in case a filesystem would need to convert this to some other
representation.
 1.2 19-Nov-2012  martin Do not require tv_nsec to be != 0 but instead require equality with the
test value.
 1.1 18-Nov-2012  manu branches: 1.1.2;
Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.4 23-Jun-2013  tls resync from head
 1.1.2.3 25-Feb-2013  tls resync with head
 1.1.2.2 18-Nov-2012  manu Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
 1.1.2.1 18-Nov-2012  manu file t_utimensat.c was added on branch tls-maxphys on 2012-11-18 17:41:55 +0000
 1.4.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.4.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.4.2.1 22-Nov-2012  yamt file t_utimensat.c was added on branch yamt-pagecache on 2013-01-16 05:34:00 +0000
 1.5.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6.24.1 02-Aug-2025  perseant Sync with HEAD
 1.6.22.2 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #957):

tests/lib/libc/c063/t_utimensat.c: revision 1.8
tests/lib/libc/c063/t_utimensat.c: revision 1.9

t_utimensat: Tidy this up to make failures more obvious.
PR kern/58571: utimensat tests are failing on armv7, aarch64, and
riscv64

t_utimensat: Don't check atime on file systems mounted noatime.
PR kern/58571: utimensat tests are failing on armv7, aarch64, and
riscv64
 1.6.22.1 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #956):

tests/lib/libc/c063/t_fchmodat.c: revision 1.4
tests/lib/libc/c063/t_fchmodat.c: revision 1.5
tests/lib/libc/c063/t_fchmodat.c: revision 1.6
tests/lib/libc/c063/t_fchmodat.c: revision 1.7
tests/lib/libc/c063/t_utimensat.c: revision 1.7

Fix = -> ==. Pointed out by Shivraj
tests/libc: replace some more '=' with the intended '=='
correct test conditions.

tests/fchmodat: add missing space in test failure message
 1.6.14.2 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1901):

tests/lib/libc/c063/t_utimensat.c: revision 1.8
tests/lib/libc/c063/t_utimensat.c: revision 1.9

t_utimensat: Tidy this up to make failures more obvious.
PR kern/58571: utimensat tests are failing on armv7, aarch64, and
riscv64

t_utimensat: Don't check atime on file systems mounted noatime.
PR kern/58571: utimensat tests are failing on armv7, aarch64, and
riscv64
 1.6.14.1 13-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1900):

tests/lib/libc/c063/t_fchmodat.c: revision 1.4
tests/lib/libc/c063/t_fchmodat.c: revision 1.5
tests/lib/libc/c063/t_fchmodat.c: revision 1.6
tests/lib/libc/c063/t_fchmodat.c: revision 1.7
tests/lib/libc/c063/t_utimensat.c: revision 1.7

Fix = -> ==. Pointed out by Shivraj
tests/libc: replace some more '=' with the intended '=='
correct test conditions.

tests/fchmodat: add missing space in test failure message
 1.2 31-May-2022  skrll Avoid plabels on hppa to make some tests not crash
 1.1 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.4 24-Sep-2016  christos Add more of the torture tests from the mit kerberos tree.
 1.3 18-Nov-2015  christos branches: 1.3.2;
Add more exhaustive db tests that include higher bucket sizes
 1.2 22-Jun-2015  christos Add new failing test.
 1.1 07-Jan-2011  pgoyette Atf-ify the db tests.

XXX Note that the original regress version of this test did not run the
XXX btree_delete test; that test is broken, and is disabled for now.
 1.3.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.1 07-Jan-2011  pgoyette Atf-ify the db tests.

XXX Note that the original regress version of this test did not run the
XXX btree_delete test; that test is broken, and is disabled for now.
 1.3 24-Sep-2016  christos remove mpool_getf
 1.2 24-Sep-2016  christos Add more of the torture tests from the mit kerberos tree.
 1.1 07-Jan-2011  pgoyette branches: 1.1.28;
Atf-ify the db tests.

XXX Note that the original regress version of this test did not run the
XXX btree_delete test; that test is broken, and is disabled for now.
 1.1.28.1 04-Nov-2016  pgoyette Sync with HEAD
 1.2 24-Jun-2017  gson Reduce the number of iterations in the bsize_torture test from 65535
to 1000 to make the ATF test suite as a whole take less time. Before
the change, this single test case could take more than two hours to
run on a qemu emulated ARM.
 1.1 18-Nov-2015  christos branches: 1.1.8;
Add more exhaustive db tests that include higher bucket sizes
 1.1.8.1 10-Jul-2017  martin Pull up following revision(s) (requested by jmcneill in ticket #115):
tests/lib/libc/db/h_lfsr.c: revision 1.2
Reduce the number of iterations in the bsize_torture test from 65535
to 1000 to make the ATF test suite as a whole take less time. Before
the change, this single test case could take more than two hours to
run on a qemu emulated ARM.
 1.9 12-Mar-2020  martin bsize_torture: skip bigger page size tests if space in the database
directory is limited (numbers pulled out of thin air).
 1.8 12-Mar-2020  martin btree_weird_page_split: set timeout to 900s, now my landisk tests have
a chance to complete this one.
 1.7 24-Sep-2016  christos branches: 1.7.14;
Add more of the torture tests from the mit kerberos tree.
 1.6 18-Nov-2015  christos branches: 1.6.2;
Add more exhaustive db tests that include higher bucket sizes
 1.5 26-Feb-2015  martin bsize_ffactor takes *very* long to complete on some slower machines (maybe
we should investigate?).
Bump timeout up to 1800 seconds (my hppa machine takes ~1100).
 1.4 29-Jul-2013  skrll Increase timeout. My hardware must be getting slower.
 1.3 10-Dec-2011  skrll branches: 1.3.6;
Give my slow, old hardware more time to complete bsize_ffactor.
 1.2 08-Jan-2011  pgoyette branches: 1.2.6;
Fix and re-enable the delete_btree test case
 1.1 07-Jan-2011  pgoyette Atf-ify the db tests.

XXX Note that the original regress version of this test did not run the
XXX btree_delete test; that test is broken, and is disabled for now.
 1.2.6.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.6.1 17-Apr-2012  yamt sync with head
 1.3.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.7.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.4 07-Sep-2020  mrg don't pass NULL to printf(), but use "<memory>" to signify this
test is operating on an in-memory only database.
 1.3 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.2 22-Jun-2015  christos branches: 1.2.16;
- don't create a db file.
- add more tests.
 1.1 22-Jun-2015  christos Add new failing test.
 1.2.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.61 15-Sep-2025  riastradh ctype(3): New environment variable LIBC_ALLOWCTYPEABUSE.

If set, this does not force the ctype(3) functions to crash when
passed invalid inputs -- instead, they will return nonsense results,
and possibly print warnings to stderr, as is their right in
implementing undefined behaviour.

The nature of the nonsense results is unspecified. Currently, is*()
will always return true (even if that leads to mutually contradictory
conclusions, like isalpha and isdigit, or isgraph and isblank), and
tolower/toupper() will always return EOF. But perhaps in the future
the results may be randomized.

This way, if an application like firefox crashes on ctype abuse, you
can opt to accept the consequences of nonsense results instead by
running `env LIBC_ALLOWCTYPEABUSE= firefox' until the application is
fixed.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.60 22-Apr-2025  nia branches: 1.60.2;
Add basic tests for timespec_get(3), timespec_getres(3)

PR standards/58608
 1.59 30-Mar-2025  riastradh ctype(3): Disable guard page in static libc.

Adding the guard page may have overflown several small installation
media. Let's try to keep this case small.

Update the tests to detect the cases where we will be running against
a libc without a guard page on the LC_CTYPE=C tables, and skip
testing abuse detection when it would rely on the guard page.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.58 28-Mar-2025  riastradh t_ctype: New test for ctype(3) functions/macros.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.57 13-Mar-2025  riastradh execve(2), posix_spawn(2): Add test case for an embarrassing bug.

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.56 27-Aug-2024  riastradh arc4random(3): Add automatic tests.

This verifies that:
- arc4random zeroes its state and reseeds itself on fork
- arc4random reseeds itself on entropy consolidation (e.g., VM clone)
- arc4random falls back to global state if it can't allocate local
state because address space limits cause mmap to fail

NOTE: This adds a new libc symbol __arc4random_global, but it's in
the reserved namespace and only used by t_arc4random, so no libc
minor bump.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
 1.55 31-May-2022  riastradh branches: 1.55.2; 1.55.4;
libc: Reintroduce getentropy.

This was introduced two years ago when the getrandom/getentropy API
question was still open, and removed because the discussion was
ongoing. Now getentropy is more widely adopted and soon to be in
POSIX. So reintroduce the symbol into libc since we'll be keeping it
anyway. Discussion of details of the semantics, as interpreted by
NetBSD, is ongoing, but the symbol needs to get in before the
netbsd-10 branch. The draft POSIX text is
(https://www.opengroup.org/austin/docs/austin_1110.pdf):

SYNOPSIS
#include <unistd.h>

int getentropy(void *buffer, size_t length);

DESCRIPTION
The getentropy() function shall write length bytes of data
starting at the location pointed to by buffer. The output
shall be unpredictable high quality random data, generated by
a cryptographically secure pseudo-random number
generator. The maximum permitted value for the length
argument is given by the {GETENTROPY_MAX} symbolic constant
defined in <limits.h>.

RETURN VALUES
Upon successful completion, getentropy() shall return 0;
otherwise, -1 shall be retunred and errno set to indicate the
error.

ERRORS
The getentropy() function shall fail if:

[EINVAL] The value of length is greater than
{GETENTROPY_MAX}.

The getentropy() function may fail if:

[ENOSYS] The system does not provide the necessary
source of entropy.

RATIONALE
The getentropy() function is not a cancellation point.

Minor changes from the previous introduction of getentropy into libc:

- Return EINVAL, not EIO, on buflen > 256.
- Define GETENTROPY_MAX in limits.h.

The declaration of getentropy in unistd.h and definition of
GETENTROPY_MAX in limits.h are currently conditional on
_NETBSD_SOURCE. When the next revision of POSIX is finalized, we can
expose them also under _POSIX_C_SOURCE > 20yymmL as usual -- and this
can be done as a pullup without breaking existing compiled programs.
 1.54 22-Feb-2020  kamil Update t_siginfo.c build rules

Add logic for MKSANITIZER/MKLIBCSANITIZER checks.
 1.53 26-Apr-2019  maya -frounding-math is gcc specific, help clang builds
 1.52 24-Apr-2019  christos PR/54000: Andreag Gustafsson: Compile the rounding test with
-fround-math since with gcc-7, the default mode ignores fenv settings
(the same effect can be achieved with -O0 :-)

https://gcc.gnu.org/wiki/FloatingPointMath
 1.51 09-Feb-2017  christos branches: 1.51.12;
remove exect, it will not be fixed and it will be removed.
 1.50 09-Dec-2016  kamil branches: 1.50.2;
Attach t_exect to ATF tests and distribution

Add missing SIGTRAP handler. Assert there that the signal is SIGTRAP as
expected and si_code TRAP_TRACE.

This test will break on some ports that have dummy or incomplete
implementation of exect(2).

This test works on amd64 correctly.

Sponsored by <The NetBSD Foundation>
 1.49 22-Dec-2015  christos branches: 1.49.2;
Add __TEST_FENV
 1.48 22-Dec-2015  christos Put have fenv elsewhere.
 1.47 22-Dec-2015  martin Sync list of fenv enabled architectures again (PR 48633), this time for mips
addition.
 1.46 21-Dec-2015  martin While PR 48633 is not properly fixed, keep the additional lists of
fenv-enabled architectures in sync.
 1.45 08-Jul-2015  matt Build t_fpgetmask/t_fpgetround for aarch64 since they are now in libc
 1.44 27-Dec-2014  martin Enable fenv for arm
 1.43 10-Aug-2014  martin Do not set HAVE_FENV for arm as long as it misses feenableexcept().
 1.42 10-Aug-2014  martin Use the same condition for HAVE_FENV
 1.41 10-Aug-2014  matt Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.
 1.40 29-Apr-2014  uebayasi Minimal execve(2) ATF test.
 1.39 30-Jan-2014  joerg branches: 1.39.2;
Add test for uint64 to real long double conversion.
 1.38 08-Nov-2012  pgoyette Convert old src/regress/timer&waiter tests to ATF
 1.37 13-Apr-2012  njoly branches: 1.37.2;
Do not re-add -mieee option on alpha, it's already set by default.
 1.36 18-Mar-2012  jruoho Add a case for PR lib/41558. It is unclear whether this is a bug, but at
least it is documented now. Probably it would be better to follow Linux,
where the test case does not fail.
 1.35 17-Mar-2012  jruoho Add few basic tests for realpath(3).
 1.34 13-Feb-2012  martin Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.33 08-Nov-2011  jruoho Few naive checks for cpuset(3) and ftok(3).
 1.32 05-Nov-2011  jruoho Few naive checks for time(3).
 1.31 30-Sep-2011  christos branches: 1.31.2;
Make the rounding test work properly, and actually test the rounding modes.
 1.30 19-Sep-2011  jruoho Move duplicate ldexp(3) test out from the tests/libc.
 1.29 19-Sep-2011  jruoho Move the tests/libc/ieeefp to tests/libc/gen to match the structure of libc.
Also rename the test files to gain functional scope.
 1.28 07-Jul-2011  jruoho Move 't_glob_star' to 't_glob' for glob(3).
 1.27 07-Jul-2011  jruoho Move 't_syslog_pthread' to 't_syslog' for consistency with libc.
 1.26 14-Jun-2011  jruoho Test that assert(3) works.
 1.25 03-Jun-2011  jruoho Test also setdomainname(3).
 1.24 02-Jun-2011  jruoho Few naive tests for sethostname(3).
 1.23 10-May-2011  jruoho branches: 1.23.2;
Few naive tests for pause(3).
 1.22 09-May-2011  jruoho Few basic tests for closefrom(3).
 1.21 05-May-2011  jruoho Try to mirror the real source with the test directory structure (otherwise
the latter carries a risk of becoming a difficult mess to manage.)
 1.20 05-May-2011  jruoho Few fundamental consistency checks for alarm(2).
 1.19 17-Apr-2011  jruoho Test nice(3) also with threads.
 1.18 10-Apr-2011  jruoho A naive test case for getcwd(3).
 1.17 05-Apr-2011  jruoho Add simple test cases for ttyname(3), strtod(3), and getgrent(3).
 1.16 04-Apr-2011  jruoho Few simple tests for nice(3).
 1.15 24-Mar-2011  jruoho Sort.
 1.14 24-Mar-2011  jruoho Add a naive test case for raise(3).
 1.13 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.12 02-Jan-2011  pgoyette One more reference to HAVE_SIGINFO bites the dust
 1.11 01-Jan-2011  pgoyette Build t_ldexp test always. The test itself determines if it is running
on an unsupported platform (vax) and exits.
 1.10 28-Dec-2010  pgoyette Fix name of t_ldexp test from previous
 1.9 28-Dec-2010  pgoyette Don't build ldexp tests on vax
 1.8 28-Dec-2010  pgoyette Migrate the ldexp test to atf
 1.7 28-Dec-2010  pgoyette Migrate the remaining libc/gen tests to atf
 1.6 25-Dec-2010  pgoyette Correctly added the conditional part, but now need to remove the original
unconditional part.
 1.5 25-Dec-2010  pgoyette Don't include the siginfo tests unless we actually have siginfo ability!
 1.4 25-Dec-2010  pgoyette Move the siginfo tests from regress to atf. While here, add a new test
for PR/43655.

XXX The sigchild_dump test currently fails when execute under atf-run.
XXX It does not fail when executed directly from the shell, so there's
XXX something in atf that prevents the child process from dumping.
 1.3 22-Dec-2010  pgoyette Migrate a couple more tests from the old regress structure to atf
 1.2 17-Dec-2010  pooka Add an isolated test case for PR lib/44248.
 1.1 06-Sep-2010  christos Add tests for GLOB_STAR
 1.23.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.31.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.31.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.31.2.2 17-Apr-2012  yamt sync with head
 1.31.2.1 10-Nov-2011  yamt sync with head
 1.37.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.37.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.39.2.1 10-Aug-2014  tls Rebase.
 1.49.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.49.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.50.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.51.12.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51.12.1 10-Jun-2019  christos Sync with HEAD
 1.55.4.1 02-Aug-2025  perseant Sync with HEAD
 1.55.2.1 09-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #939):

distrib/sets/lists/debug/module.md.amd64: revision 1.18
sys/modules/Makefile: revision 1.292
lib/libc/gen/arc4random.c: revision 1.34
lib/libc/gen/arc4random.c: revision 1.35
lib/libc/gen/arc4random.c: revision 1.36
lib/libc/gen/arc4random.c: revision 1.37
sys/kern/kern_entropy.c: revision 1.70
lib/libc/gen/arc4random.c: revision 1.38
sys/kern/kern_entropy.c: revision 1.71
lib/libc/gen/getentropy.3: revision 1.8
distrib/sets/lists/modules/md.amd64: revision 1.103
share/man/man4/rnd.4: revision 1.42
share/man/man4/rnd.4: revision 1.44
lib/libc/include/arc4random.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1786
sys/arch/i386/conf/GENERIC: revision 1.1258
sys/modules/acpivmgenid/acpivmgenid.ioconf: revision 1.1
sys/arch/amd64/conf/ALL: revision 1.190
distrib/sets/lists/debug/mi: revision 1.446
sys/arch/i386/conf/ALL: revision 1.521
lib/libc/gen/Makefile.inc: revision 1.219
distrib/sets/lists/debug/module.md.i386: revision 1.12
sys/dev/acpi/acpi_vmgenid.c: revision 1.1
sys/dev/acpi/acpi_vmgenid.c: revision 1.2
lib/libc/include/reentrant.h: revision 1.22
sys/arch/evbarm/conf/GENERIC64: revision 1.219
share/man/man4/Makefile: revision 1.735
distrib/sets/lists/modules/md.i386: revision 1.100
distrib/sets/lists/tests/mi: revision 1.1334
lib/libc/gen/arc4random.3: revision 1.22
sys/dev/acpi/files.acpi: revision 1.133
lib/libc/gen/arc4random.3: revision 1.23
tests/lib/libc/gen/t_arc4random.c: revision 1.1
sys/sys/entropy.h: revision 1.6
sys/arch/amd64/conf/GENERIC: revision 1.614
sys/modules/acpivmgenid/Makefile: revision 1.1
share/man/man4/acpivmgenid.4: revision 1.1
lib/libc/gen/Makefile.inc: revision 1.220
tests/lib/libc/gen/Makefile: revision 1.56
share/man/man4/acpivmgenid.4: revision 1.2
share/man/man4/acpivmgenid.4: revision 1.3

(all via patch)

Catch up with all the lint warnings since exit on warning was disabled.

Disable 'missing header declaration' and 'nested extern' warnings for now.
acpivmgenid(4): New driver for virtual machine generation ID.

Added to amd64/ALL and i386/ALL kernel configurations, and made
available as a loadable module acpivmgenid.kmod on x86, for now.
TBD: Add to all ACPI-supporting GENERIC kernels.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Factor out subroutines to reset and gather entropy.
`Reset' means we keep the data in the pool, but assume it had zero
entropy. `Gather' means we request samples from all on-demand
sources and wait for the synchronous ones to complete.

No functional change intended, other than to expose new symbols --
just preparation to expose these to acpivmgenid(4), so it can use
these when the VM host notifies us that we, the guest, have been
cloned.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Reset and gather entropy on VM clone notification.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Reseed if system entropy epoch changes.
This can happen, for example, if the system is a VM instance, and the
VM is cloned.

This incurs the cost of a system call on every arc4random call, which
is unfortunate, but
1. we don't currently have a (machine-independent) mechanism for
exposing a read-only page to userland shared by the kernel to
enable a cheaper access path to the entropy epoch; and
2. the algorithm here -- a simple application of ChaCha -- is likely
also a bottleneck and could be much cheaper by
(a) using sys/crypto/chacha for machine-dependent vectorized
ChaCha code, and
(b) filling a buffer (somewhere between a cipher block and a page)
in a batch at a time, instead of running ChaCha to generate
only 32 bytes at a time.
So although this might be a performance hit, the security benefit is
worthwhile and we have a clear path to do better than reversing the
performance hit later.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Nix BUGS that have been squashed.
Reference kern.entropy.epoch for the remaining bug (which is a
performance issue, not a security issue).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Allow unprivileged reads of sysctl kern.entropy.epoch.

Applications need this in order to know when to reseed. (We should
also expose it through a page shared read-only with userland for
cheaper access, but until we do, let's let applications get at it
through sysctl.)
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random.c: Fix test program.

This isn't wired up anywhere, but let's reduce the bitrot. It was
helpful in reminding me that kern.entropy.epoch was, for reasons I
can't remember, restricted to privileged access.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

amd64, evbarm, i386: Add acpivmgenid(4) to GENERIC.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

rnd(4): Document kern.entropy.epoch is unprivileged and elaborate.
Cross-reference acpivmgenid(4).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Note that arc4random respects kern.entropy.epoch.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
Add debug info for new acpivmgenid module

arc4random(3): Add automatic tests.

This verifies that:
- arc4random zeroes its state and reseeds itself on fork
- arc4random reseeds itself on entropy consolidation (e.g., VM clone)
- arc4random falls back to global state if it can't allocate local
state because address space limits cause mmap to fail

NOTE: This adds a new libc symbol __arc4random_global, but it's in
the reserved namespace and only used by t_arc4random, so no libc
minor bump.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

getentropy(3): Note intent to reseed on VM clone, and caveats.

Tidy markup and pacify some mandoc -Tlint complaints while here.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

Bump dates on man pages recently updated to mention VM clones.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Pacify some of lint's complaints.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random: suppress another lint warning
 1.60.2.1 01-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #45):

tests/lib/libc/gen/t_ctype.c: revision 1.12
lib/libc/gen/ctype_.c: revision 1.24
lib/libc/locale/rune.c: revision 1.50
tests/lib/libc/gen/Makefile: revision 1.61
lib/libc/gen/tolower_.c: revision 1.18
lib/libc/gen/isctype.c: revision 1.29
distrib/sets/lists/tests/mi: revision 1.1394
lib/libc/gen/toupper_.c: revision 1.18
lib/libc/gen/ctype_guard.h: revision 1.8
lib/libc/locale/Makefile.inc: revision 1.69
lib/libc/gen/ctype.3: revision 1.32
lib/libc/gen/ctype.3: revision 1.33
distrib/sets/lists/debug/mi: revision 1.486
tests/lib/libc/gen/h_ctype_abuse.c: revision 1.1
tests/lib/libc/gen/h_ctype_abuse.c: revision 1.2

ctype(3): New environment variable LIBC_ALLOWCTYPEABUSE.

If set, this does not force the ctype(3) functions to crash when
passed invalid inputs -- instead, they will return nonsense results,
and possibly print warnings to stderr, as is their right in
implementing undefined behaviour.

The nature of the nonsense results is unspecified. Currently, is*()
will always return true (even if that leads to mutually contradictory
conclusions, like isalpha and isdigit, or isgraph and isblank), and
tolower/toupper() will always return EOF. But perhaps in the future
the results may be randomized.

This way, if an application like firefox crashes on ctype abuse, you
can opt to accept the consequences of nonsense results instead by
running `env LIBC_ALLOWCTYPEABUSE= firefox' until the application is
fixed.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
ctype(3): Document LIBC_ALLOWCTYPEABUSE.

If this is pulled up to netbsd-11, we should tweak the text to make
it apply to 11 too.
PR lib/58208: ctype(3) provides poor runtime feedback of abuse

ctype(3): Fix build of tests on machines with unsigned char.
Could maybe phrase this better but this'll do for now.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.1 13-Mar-2025  riastradh branches: 1.1.4;
execve(2), posix_spawn(2): Fix build of tests after previous.

Forgot to add a file.

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Mar-2025  perseant file Makefile.inc was added on branch perseant-exfatfs on 2025-08-02 05:58:04 +0000
 1.2 15-Sep-2025  riastradh branches: 1.2.2;
ctype(3): Fix build of tests on machines with unsigned char.

Could maybe phrase this better but this'll do for now.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.1 15-Sep-2025  riastradh ctype(3): New environment variable LIBC_ALLOWCTYPEABUSE.

If set, this does not force the ctype(3) functions to crash when
passed invalid inputs -- instead, they will return nonsense results,
and possibly print warnings to stderr, as is their right in
implementing undefined behaviour.

The nature of the nonsense results is unspecified. Currently, is*()
will always return true (even if that leads to mutually contradictory
conclusions, like isalpha and isdigit, or isgraph and isblank), and
tolower/toupper() will always return EOF. But perhaps in the future
the results may be randomized.

This way, if an application like firefox crashes on ctype abuse, you
can opt to accept the consequences of nonsense results instead by
running `env LIBC_ALLOWCTYPEABUSE= firefox' until the application is
fixed.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.2.2.2 01-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #45):

tests/lib/libc/gen/t_ctype.c: revision 1.12
lib/libc/gen/ctype_.c: revision 1.24
lib/libc/locale/rune.c: revision 1.50
tests/lib/libc/gen/Makefile: revision 1.61
lib/libc/gen/tolower_.c: revision 1.18
lib/libc/gen/isctype.c: revision 1.29
distrib/sets/lists/tests/mi: revision 1.1394
lib/libc/gen/toupper_.c: revision 1.18
lib/libc/gen/ctype_guard.h: revision 1.8
lib/libc/locale/Makefile.inc: revision 1.69
lib/libc/gen/ctype.3: revision 1.32
lib/libc/gen/ctype.3: revision 1.33
distrib/sets/lists/debug/mi: revision 1.486
tests/lib/libc/gen/h_ctype_abuse.c: revision 1.1
tests/lib/libc/gen/h_ctype_abuse.c: revision 1.2

ctype(3): New environment variable LIBC_ALLOWCTYPEABUSE.

If set, this does not force the ctype(3) functions to crash when
passed invalid inputs -- instead, they will return nonsense results,
and possibly print warnings to stderr, as is their right in
implementing undefined behaviour.

The nature of the nonsense results is unspecified. Currently, is*()
will always return true (even if that leads to mutually contradictory
conclusions, like isalpha and isdigit, or isgraph and isblank), and
tolower/toupper() will always return EOF. But perhaps in the future
the results may be randomized.

This way, if an application like firefox crashes on ctype abuse, you
can opt to accept the consequences of nonsense results instead by
running `env LIBC_ALLOWCTYPEABUSE= firefox' until the application is
fixed.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
ctype(3): Document LIBC_ALLOWCTYPEABUSE.

If this is pulled up to netbsd-11, we should tweak the text to make
it apply to 11 too.
PR lib/58208: ctype(3) provides poor runtime feedback of abuse

ctype(3): Fix build of tests on machines with unsigned char.
Could maybe phrase this better but this'll do for now.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.2.2.1 15-Sep-2025  martin file h_ctype_abuse.c was added on branch netbsd-11 on 2025-10-01 17:41:14 +0000
 1.1 13-Mar-2025  riastradh branches: 1.1.4;
execve(2), posix_spawn(2): Add test case for an embarrassing bug.

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Mar-2025  perseant file h_execsig.c was added on branch perseant-exfatfs on 2025-08-02 05:58:04 +0000
 1.6 15-Dec-2021  gson When running the tests under "qemu -accel kvm" on a Linux host,
isQEMU_TCG() should return false. Fixes multiple test cases that were
failing with "Test case was expecting a failure but none were raised"
on that platform.
 1.5 23-Aug-2020  gson Provide separate functions to check for running under qemu in general
and for running under qemu's built-in TCG CPU emulation (as opposed to
hardware virtualization via NVMM or KVM).
 1.4 03-Jan-2015  gson Need stdlib.h for EXIT_FAILURE
 1.3 14-Apr-2013  martin branches: 1.3.2; 1.3.8; 1.3.10;
Mark the test function as inline, so we don't get warnings if it is not
actually used.
 1.2 12-Apr-2013  christos don't pay for sysctl if we don't have to.
 1.1 12-Apr-2013  christos easier way to find if we are on qemu.
 1.3.10.1 12-Jan-2015  snj Pull up following revision(s) (requested by gson in ticket #413):
tests/lib/libc/gen/isqemu.h: revision 1.4
Need stdlib.h for EXIT_FAILURE
 1.3.8.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.3.8.1 14-Apr-2013  yamt file isqemu.h was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.3.2.2 23-Jun-2013  tls resync from head
 1.3.2.1 14-Apr-2013  tls file isqemu.h was added on branch tls-maxphys on 2013-06-23 06:28:56 +0000
 1.2 10-May-2011  jruoho Fix comment/string typos.
 1.1 05-May-2011  jruoho Few fundamental consistency checks for alarm(2).
 1.5 09-Mar-2025  riastradh branches: 1.5.4;
arc4random(3): Provide a fallback in case pthread_atfork fails.

This is considerably more work and burden on testing than simply
statically preallocating a bit of storage for pthread_atfork to
eliminate the failure mode altogether, but it is less work than
arguing further over the atfork interface:
https://mail-index.NetBSD.org/source-changes-d/2025/03/02/msg014387.html

PR lib/59117: arc4random has some failure modes it shouldn't
 1.4 06-Mar-2025  riastradh t_arc4random: Test arc4random_global.per_thread, not .initialized.

If arc4random_initialize has been called, and thr_keycreate failed,
then .initialized will be true but .per_thread will be false -- and
.thread_key will be garbage (some other thread key for another
purpose, most likely). This path was enabled by allowing
thr_keycreate to fail instead of aborting the process.

This hasn't caused trouble yet, mainly because we don't do anything
to inject faults into thr_keycreate in these tests. Tweak the
global_threadkeylimit test while here to provoke a crash with the
wrong conditional.

Fix a similar edge case in the little test program embedded in
arc4random.c (which should maybe just go away now that we have atf
tests).

PR lib/59117: arc4random has some failure modes it shouldn't
 1.3 05-Mar-2025  riastradh t_arc4random: Verify arc4random works without fds.

It must work in an empty chroot where /dev/urandom doesn't exist, and
it must work when the file descriptor resource limit is exceeded.

Prompted by discussion around:

PR lib/59117: arc4random has some failure modes it shouldn't

Fortunately these are not failure modes of the current arc4random
implementation! But it is important to test them nevertheless, to
forestall any temptation to invent new failure modes.
 1.2 02-Mar-2025  riastradh arc4random(3): Avoid failure due to thread key limits.

If thr_keycreate (a.k.a. pthread_key_create) fails, fall back to
using globally serialized state instead of per-thread state. This is
unlikely to happen but arc4random(3) should work even if it does.
New test case forces exercising this path (at least, simulating the
effect of key creation failure).

PR lib/59117: arc4random has some failure modes it shouldn't
 1.1 27-Aug-2024  riastradh branches: 1.1.2;
arc4random(3): Add automatic tests.

This verifies that:
- arc4random zeroes its state and reseeds itself on fork
- arc4random reseeds itself on entropy consolidation (e.g., VM clone)
- arc4random falls back to global state if it can't allocate local
state because address space limits cause mmap to fail

NOTE: This adds a new libc symbol __arc4random_global, but it's in
the reserved namespace and only used by t_arc4random, so no libc
minor bump.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
 1.1.2.2 09-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #939):

distrib/sets/lists/debug/module.md.amd64: revision 1.18
sys/modules/Makefile: revision 1.292
lib/libc/gen/arc4random.c: revision 1.34
lib/libc/gen/arc4random.c: revision 1.35
lib/libc/gen/arc4random.c: revision 1.36
lib/libc/gen/arc4random.c: revision 1.37
sys/kern/kern_entropy.c: revision 1.70
lib/libc/gen/arc4random.c: revision 1.38
sys/kern/kern_entropy.c: revision 1.71
lib/libc/gen/getentropy.3: revision 1.8
distrib/sets/lists/modules/md.amd64: revision 1.103
share/man/man4/rnd.4: revision 1.42
share/man/man4/rnd.4: revision 1.44
lib/libc/include/arc4random.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1786
sys/arch/i386/conf/GENERIC: revision 1.1258
sys/modules/acpivmgenid/acpivmgenid.ioconf: revision 1.1
sys/arch/amd64/conf/ALL: revision 1.190
distrib/sets/lists/debug/mi: revision 1.446
sys/arch/i386/conf/ALL: revision 1.521
lib/libc/gen/Makefile.inc: revision 1.219
distrib/sets/lists/debug/module.md.i386: revision 1.12
sys/dev/acpi/acpi_vmgenid.c: revision 1.1
sys/dev/acpi/acpi_vmgenid.c: revision 1.2
lib/libc/include/reentrant.h: revision 1.22
sys/arch/evbarm/conf/GENERIC64: revision 1.219
share/man/man4/Makefile: revision 1.735
distrib/sets/lists/modules/md.i386: revision 1.100
distrib/sets/lists/tests/mi: revision 1.1334
lib/libc/gen/arc4random.3: revision 1.22
sys/dev/acpi/files.acpi: revision 1.133
lib/libc/gen/arc4random.3: revision 1.23
tests/lib/libc/gen/t_arc4random.c: revision 1.1
sys/sys/entropy.h: revision 1.6
sys/arch/amd64/conf/GENERIC: revision 1.614
sys/modules/acpivmgenid/Makefile: revision 1.1
share/man/man4/acpivmgenid.4: revision 1.1
lib/libc/gen/Makefile.inc: revision 1.220
tests/lib/libc/gen/Makefile: revision 1.56
share/man/man4/acpivmgenid.4: revision 1.2
share/man/man4/acpivmgenid.4: revision 1.3

(all via patch)

Catch up with all the lint warnings since exit on warning was disabled.

Disable 'missing header declaration' and 'nested extern' warnings for now.
acpivmgenid(4): New driver for virtual machine generation ID.

Added to amd64/ALL and i386/ALL kernel configurations, and made
available as a loadable module acpivmgenid.kmod on x86, for now.
TBD: Add to all ACPI-supporting GENERIC kernels.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Factor out subroutines to reset and gather entropy.
`Reset' means we keep the data in the pool, but assume it had zero
entropy. `Gather' means we request samples from all on-demand
sources and wait for the synchronous ones to complete.

No functional change intended, other than to expose new symbols --
just preparation to expose these to acpivmgenid(4), so it can use
these when the VM host notifies us that we, the guest, have been
cloned.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Reset and gather entropy on VM clone notification.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Reseed if system entropy epoch changes.
This can happen, for example, if the system is a VM instance, and the
VM is cloned.

This incurs the cost of a system call on every arc4random call, which
is unfortunate, but
1. we don't currently have a (machine-independent) mechanism for
exposing a read-only page to userland shared by the kernel to
enable a cheaper access path to the entropy epoch; and
2. the algorithm here -- a simple application of ChaCha -- is likely
also a bottleneck and could be much cheaper by
(a) using sys/crypto/chacha for machine-dependent vectorized
ChaCha code, and
(b) filling a buffer (somewhere between a cipher block and a page)
in a batch at a time, instead of running ChaCha to generate
only 32 bytes at a time.
So although this might be a performance hit, the security benefit is
worthwhile and we have a clear path to do better than reversing the
performance hit later.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Nix BUGS that have been squashed.
Reference kern.entropy.epoch for the remaining bug (which is a
performance issue, not a security issue).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Allow unprivileged reads of sysctl kern.entropy.epoch.

Applications need this in order to know when to reseed. (We should
also expose it through a page shared read-only with userland for
cheaper access, but until we do, let's let applications get at it
through sysctl.)
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random.c: Fix test program.

This isn't wired up anywhere, but let's reduce the bitrot. It was
helpful in reminding me that kern.entropy.epoch was, for reasons I
can't remember, restricted to privileged access.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

amd64, evbarm, i386: Add acpivmgenid(4) to GENERIC.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

rnd(4): Document kern.entropy.epoch is unprivileged and elaborate.
Cross-reference acpivmgenid(4).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Note that arc4random respects kern.entropy.epoch.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
Add debug info for new acpivmgenid module

arc4random(3): Add automatic tests.

This verifies that:
- arc4random zeroes its state and reseeds itself on fork
- arc4random reseeds itself on entropy consolidation (e.g., VM clone)
- arc4random falls back to global state if it can't allocate local
state because address space limits cause mmap to fail

NOTE: This adds a new libc symbol __arc4random_global, but it's in
the reserved namespace and only used by t_arc4random, so no libc
minor bump.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

getentropy(3): Note intent to reseed on VM clone, and caveats.

Tidy markup and pacify some mandoc -Tlint complaints while here.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

Bump dates on man pages recently updated to mention VM clones.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Pacify some of lint's complaints.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random: suppress another lint warning
 1.1.2.1 27-Aug-2024  martin file t_arc4random.c was added on branch netbsd-10 on 2024-10-09 13:25:13 +0000
 1.5.4.2 02-Aug-2025  perseant Sync with HEAD
 1.5.4.1 09-Mar-2025  perseant file t_arc4random.c was added on branch perseant-exfatfs on 2025-08-02 05:58:04 +0000
 1.3 10-Jan-2017  christos PR/51807: Ngie Cooper: disable core file generation in :assert_false,
:assert_true
 1.2 14-Jun-2011  jruoho branches: 1.2.2; 1.2.26;
Avoid ATF_REQUIRE() inside a child process.
 1.1 14-Jun-2011  jruoho Test that assert(3) works.
 1.2.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.2.1 14-Jun-2011  cherry file t_assert.c was added on branch cherry-xenmp on 2011-06-23 14:20:39 +0000
 1.2 07-Jul-2011  jruoho Rename some test case names for consistency. No functional change.
 1.1 22-Dec-2010  pgoyette Migrate a couple more tests from the old regress structure to atf
 1.5 12-Apr-2022  andvar s/sould/should/ and s/shoud/should/
 1.4 11-May-2011  jruoho Adjust.
 1.3 09-May-2011  jruoho On a second thought, require that close(2) fails for a descriptor already
closed with closefrom(3). For some odd reason (yet to be determined), this
check fails on 5.99.51 (amd64).
 1.2 09-May-2011  jruoho Remove superfluous close(2) pointed out by martin@.
 1.1 09-May-2011  jruoho Few basic tests for closefrom(3).
 1.1 08-Nov-2011  jruoho branches: 1.1.2;
Few naive checks for cpuset(3) and ftok(3).
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 08-Nov-2011  yamt file t_cpuset.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.12 15-Sep-2025  riastradh ctype(3): New environment variable LIBC_ALLOWCTYPEABUSE.

If set, this does not force the ctype(3) functions to crash when
passed invalid inputs -- instead, they will return nonsense results,
and possibly print warnings to stderr, as is their right in
implementing undefined behaviour.

The nature of the nonsense results is unspecified. Currently, is*()
will always return true (even if that leads to mutually contradictory
conclusions, like isalpha and isdigit, or isgraph and isblank), and
tolower/toupper() will always return EOF. But perhaps in the future
the results may be randomized.

This way, if an application like firefox crashes on ctype abuse, you
can opt to accept the consequences of nonsense results instead by
running `env LIBC_ALLOWCTYPEABUSE= firefox' until the application is
fixed.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.11 30-Mar-2025  riastradh branches: 1.11.2; 1.11.4;
ctype(3): Disable guard page in static libc.

Adding the guard page may have overflown several small installation
media. Let's try to keep this case small.

Update the tests to detect the cases where we will be running against
a libc without a guard page on the LC_CTYPE=C tables, and skip
testing abuse detection when it would rely on the guard page.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.10 29-Mar-2025  riastradh ctype(3): Put guard pages before the C ctype/tolower/toupper tables.

This also only affects machines where char is signed for now. (But
maybe it would be worth doing unconditionally; users could still try
to pass in explicit `signed char' inputs.)

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.9 29-Mar-2025  riastradh ctype(3): Summon a demon from caller's nose if abused out-of-line.

This way, applications which opt for the out-of-line functions will
crash with a potentially meaningful message to stderr if they pass
inputs on which the ctype(3) functions are undefined. (If fd 2 is
something else, tough -- this is nasal demon country, and they fly
where they please, application intent be damned.)

This probably won't catch many applications -- but it might catch C++
applications at runtime that can't be caught at build-time because
they eschew the macros.

The cost is a single predicted-not-taken branch -- it's checking c
for membership in the interval [-1,0xff] when we're already computing
c + 1, so it can be a single unsigned-compare. By deferring the
message and abort to an out-of-line function we avoid a stack frame
in the good case. And this is for the unlikely, out-of-line versions
of the ctype(3) functions -- most applications get the inline macros.
So I'm not concerned by the prospect of a performance impact.

Update the tests so they recognize SIGABRT as noisy failure too, not
just SIGSEGV.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.8 28-Mar-2025  riastradh t_ctype: More const is more better!

No functional change intended -- we never intended to write to this
array anyway.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.7 28-Mar-2025  riastradh t_ctype: Factor loop out of macro-generated functions.

No functional change intended.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.6 28-Mar-2025  riastradh t_ctype: Test some more code points with potential for EOF confusion.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.5 28-Mar-2025  riastradh t_ctype: Include UCHAR_MAX in the range of inputs tested.

It should definitely be included because it is important to distinguish
it from EOF!

Noted by rillig@.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.4 28-Mar-2025  riastradh t_ctype: Test explicit setlocale(LC_CTYPE, "C").

And do so after other setlocales -- just in case this behaves
differently from the default environment before any setlocale.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.3 28-Mar-2025  riastradh libc: Put guard pages before locale ctype/tolower/toupper tables.

This way, triggering the undefined behaviour of negative inputs to
the ctype functions leads to instant SIGSEGV, rather than silently
giving bonkers (and likely nondeterministic) answers. (See ctype(3)
man page for details.)

This only affects non-default locales, i.e., locales other than C.
The C locale's tables are statically linked into libc, and the
symbols defining them are baked into the ABI, so putting a guard page
before them will require either some careful elven surgery (which is
a class I must have missed back in university), or copying them into
dynamically allocated memory (which is a cost I'm reluctant to incur
on all programs using libc).

This also only affects machines where char is signed for now. (But
maybe it would be worth doing unconditionally; users could still try
to pass in explicit `signed char' inputs.)

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.2 28-Mar-2025  riastradh t_ctype: Fix tests on platforms where char is unsigned.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.1 28-Mar-2025  riastradh t_ctype: New test for ctype(3) functions/macros.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.11.4.2 02-Aug-2025  perseant Sync with HEAD
 1.11.4.1 30-Mar-2025  perseant file t_ctype.c was added on branch perseant-exfatfs on 2025-08-02 05:58:04 +0000
 1.11.2.1 01-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #45):

tests/lib/libc/gen/t_ctype.c: revision 1.12
lib/libc/gen/ctype_.c: revision 1.24
lib/libc/locale/rune.c: revision 1.50
tests/lib/libc/gen/Makefile: revision 1.61
lib/libc/gen/tolower_.c: revision 1.18
lib/libc/gen/isctype.c: revision 1.29
distrib/sets/lists/tests/mi: revision 1.1394
lib/libc/gen/toupper_.c: revision 1.18
lib/libc/gen/ctype_guard.h: revision 1.8
lib/libc/locale/Makefile.inc: revision 1.69
lib/libc/gen/ctype.3: revision 1.32
lib/libc/gen/ctype.3: revision 1.33
distrib/sets/lists/debug/mi: revision 1.486
tests/lib/libc/gen/h_ctype_abuse.c: revision 1.1
tests/lib/libc/gen/h_ctype_abuse.c: revision 1.2

ctype(3): New environment variable LIBC_ALLOWCTYPEABUSE.

If set, this does not force the ctype(3) functions to crash when
passed invalid inputs -- instead, they will return nonsense results,
and possibly print warnings to stderr, as is their right in
implementing undefined behaviour.

The nature of the nonsense results is unspecified. Currently, is*()
will always return true (even if that leads to mutually contradictory
conclusions, like isalpha and isdigit, or isgraph and isblank), and
tolower/toupper() will always return EOF. But perhaps in the future
the results may be randomized.

This way, if an application like firefox crashes on ctype abuse, you
can opt to accept the consequences of nonsense results instead by
running `env LIBC_ALLOWCTYPEABUSE= firefox' until the application is
fixed.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
ctype(3): Document LIBC_ALLOWCTYPEABUSE.

If this is pulled up to netbsd-11, we should tweak the text to make
it apply to 11 too.
PR lib/58208: ctype(3) provides poor runtime feedback of abuse

ctype(3): Fix build of tests on machines with unsigned char.
Could maybe phrase this better but this'll do for now.

PR lib/58208: ctype(3) provides poor runtime feedback of abuse
 1.11 19-Jun-2018  gson No semicolon after macro do ... while (0) wrapper.
 1.10 11-Jan-2017  christos branches: 1.10.12;
more error checks
 1.9 11-Jan-2017  christos fix mismatched paren, also the previous commit should say and check error
for -1.
 1.8 11-Jan-2017  christos wrap the macro in do/while.
 1.7 10-Jan-2017  christos PR/51808: Ngie Cooper: fix leaks, sort includes, check returns
 1.6 19-Oct-2013  christos branches: 1.6.8;
fix unused variable warnings
 1.5 18-Mar-2012  jruoho branches: 1.5.2;
To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
 1.4 07-Jul-2011  jruoho branches: 1.4.2;
Rename some test case names for consistency. No functional change.
 1.3 11-Jun-2011  christos Turn warns on for all tests and fix all the bugs.
 1.2 07-Apr-2011  jruoho branches: 1.2.2;
Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.1 28-Dec-2010  pgoyette Migrate the remaining libc/gen tests to atf
 1.2.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4.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.4.2.1 17-Apr-2012  yamt sync with head
 1.5.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.7 06-May-2024  riastradh tests/lib/libc/gen/t_floatunditf: Nix __HAVE_LONG_DOUBLE conditional.

Conversion from uint64_t to long double should work on all ports,
including those where long double is the same as double, i.e., where
__HAVE_LONG_DOUBLE is undefined.

Instead, conditionalize the test cases on how many bits of precision
long double has in the significand, according to LDBL_MANT_DIG. The
conditionals here should handle binary128, powerpc double-dekker
(~106-bit precision), x86 extended precision (80-bit), m68k extended
precision (80-bit), and VAX D (56-bit).
 1.6 04-Nov-2014  justin 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.5 02-Feb-2014  martin branches: 1.5.4; 1.5.8;
Add a few more test values from the range that sparc64 previously would
have got wrong.
 1.4 01-Feb-2014  martin Skip testcase inside its body for architectures w/o long double support
 1.3 01-Feb-2014  martin Print a slightly more helpfull message in case of test failure
 1.2 30-Jan-2014  joerg No unused functions if there is no long double support.
 1.1 30-Jan-2014  joerg Add test for uint64 to real long double conversion.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 02-Feb-2014  tls file t_floatunditf.c was added on branch tls-maxphys on 2014-08-20 00:04:49 +0000
 1.5.4.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.5.4.1 02-Feb-2014  yamt file t_floatunditf.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.6 13-Apr-2024  rillig tests/fmtcheck: show that fmtcheck does not support "%2$s"
 1.5 13-Dec-2017  rin Revert rev 1.4: fmtcheck(3) neglect unused trailing arguments as before.
"%d" is a valid format string with default format string "%d %s", etc.
 1.4 07-Dec-2017  kre Correct a couple of broken test cases:
"%d" does not take the same args as "%d %s"
"%%" does not take the same args as "%llx"
How did these ever survive any kind of even basic sanity check?
 1.3 14-Jun-2014  apb Update fmtcheck(3) test now that pointers and longs are differentiated.
 1.2 07-Jul-2011  jruoho branches: 1.2.8; 1.2.18;
Rename some test case names for consistency. No functional change.
 1.1 28-Dec-2010  pgoyette Migrate the remaining libc/gen tests to atf
 1.2.18.1 10-Aug-2014  tls Rebase.
 1.2.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7 31-Oct-2016  dholland Add another case related to the ones from PR 49278: [A-\\].
 1.6 12-Oct-2014  christos branches: 1.6.2;
You need double the number of backslashes in a pattern, since \\ -> '\' in
the string which means escape. Now the tests don't fail.
 1.5 12-Oct-2014  justin Add expect fail for PR lib/49278
 1.4 12-Oct-2014  justin Add some fnmatch test cases from other C library test suites
 1.3 08-Apr-2012  jruoho branches: 1.3.2;
Append few basic test cases.
 1.2 25-Mar-2012  christos PR/41558 has been fixed.
 1.1 18-Mar-2012  jruoho Add a case for PR lib/41558. It is unclear whether this is a bug, but at
least it is documented now. Probably it would be better to follow Linux,
where the test case does not fail.
 1.3.2.2 17-Apr-2012  yamt sync with head
 1.3.2.1 08-Apr-2012  yamt file t_fnmatch.c was added on branch yamt-pagecache on 2012-04-17 00:09:10 +0000
 1.6.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.8 08-Apr-2025  riastradh t_fpclassify: Fix build on vax after #if'ing out subnormal tests.

Must've neglected to compile-test this _on vax_, oops.

PR port-vax/59261: t_fpclassify tests are failing
 1.7 07-Apr-2025  riastradh tests: Use `#if __*_HAS_DENORM__', not `#ifdef __*_HAS_DENORM__'.

The compiler defines this to zero on, e.g., VAX.

PR port-vax/59261: t_fpclassify tests are failing
 1.6 09-May-2024  riastradh branches: 1.6.2;
tests/lib/libc/gen/t_fpclassify: Test fpclassify on non-IEEE754 too.

Just exclude the subnormal parts on non-IEEE754 architectures
according to __FLT/DBL/LDBL_HAS_DENORM__.
 1.5 09-May-2024  riastradh tests/lib/libc/gen/t_fpclassify: Spruce this up a bit.

Provide more useful diagnostics when tests fail.
 1.4 07-May-2024  riastradh tests/lib/libc/gen/t_fpclassify: Enable long double tests.

The necessary long double symbols should all be available now. If
there are any architectures where they're not, we can fix those
architectures.
 1.3 01-Oct-2011  christos branches: 1.3.44; 1.3.52;
add a missing E
 1.2 01-Oct-2011  christos use _FLOAT_IEEE754 instead of vax.
 1.1 19-Sep-2011  jruoho Move the tests/libc/ieeefp to tests/libc/gen to match the structure of libc.
Also rename the test files to gain functional scope.
 1.3.52.1 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #790):

tests/lib/libc/gen/t_fpclassify.c: revision 1.4
tests/lib/libc/gen/t_fpclassify.c: revision 1.5

tests/lib/libc/gen/t_fpclassify: Enable long double tests.

The necessary long double symbols should all be available now. If
there are any architectures where they're not, we can fix those
architectures.

tests/lib/libc/gen/t_fpclassify: Spruce this up a bit.
Provide more useful diagnostics when tests fail.
 1.3.44.2 23-Aug-2024  martin Back out previous - accidently commited to the wrong branch
 1.3.44.1 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #790):

tests/lib/libc/gen/t_fpclassify.c: revision 1.4
tests/lib/libc/gen/t_fpclassify.c: revision 1.5

tests/lib/libc/gen/t_fpclassify: Enable long double tests.

The necessary long double symbols should all be available now. If
there are any architectures where they're not, we can fix those
architectures.

tests/lib/libc/gen/t_fpclassify: Spruce this up a bit.
Provide more useful diagnostics when tests fail.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.22 14-May-2024  riastradh t_fpsetmask, t_fenv: Skip fp exception trap tests on RISC-V.

No architectural support for fp exception traps.

While here, make the macros behave a little better as C statements.
 1.21 23-Aug-2020  gson Expect failure only when running under qemu's TCG CPU emulation, not
when running under hardware virtualization such as qemu -accel nvmm.
 1.20 25-Apr-2019  kamil Fix typo in 'exceptions'
 1.19 30-Jan-2019  martin Clean up terminology: modern arm CPUs do properly implement IEEE 754
floating point exceptions - but some (actually all currently know ones)
do not implement sending traps when these exceptions are raised.

Pointed out by Peter Maydell.
 1.18 23-Jan-2019  martin There are aarch64 Cortex cpus that do not trap on some floating point
exceptions - so apply the arm handling for aarch64 as well.
 1.17 16-Dec-2018  sevan port-macppc/46319 is marked as resolved now.
Test on 8.99.26 build of NetBSD/macppc
 1.16 12-Mar-2016  martin branches: 1.16.14; 1.16.16;
Fix masking for the fpsetmask_basic test, pointed out by Timo Buhrmester
 1.15 18-Nov-2014  martin Skip the tests on ARM if the NEON fpu does not support exceptions (Cortex).
 1.14 04-Nov-2014  justin 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.13 09-Feb-2014  jmmv Use compiler builtins instead of atf_arch and atf_machine.

The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
 1.12 14-Apr-2013  martin Backout previous - which did not include the change described in the log
message anyway but pure accidental white space changes. The whole change
was not needed any more after fixing isqemu.h.
Thanks to agc for pointing it out.
 1.11 14-Apr-2013  martin Do not include isqemu.h if we are not going to use the test
 1.10 12-Apr-2013  christos easier way to find if we are on qemu.
 1.9 13-Apr-2012  jruoho branches: 1.9.2;
Xfail on qemu unconditionally after all.
 1.8 11-Apr-2012  jruoho Flip previous (i386/qemu fails, not the amd64/qemu).
 1.7 11-Apr-2012  jruoho Revisit the previous: fails on qemu/amd64 but not qemu/i386.
 1.6 11-Apr-2012  jruoho As it turned out, the fpsetmask(3) tests were unnecessarily skipped on Qemu.
Thus, remove xfails that do not trigger.
 1.5 10-Apr-2012  jruoho Do not skip the tests on Qemu, but point to PR misc/44767 instead.
 1.4 10-Apr-2012  jruoho Point to port-macppc/46319 when failing on macppc.
 1.3 19-Oct-2011  njoly branches: 1.3.2;
Add basic fpsetmask test to exercize setting/clearing bits.
 1.2 01-Oct-2011  christos use _FLOAT_IEEE754 instead of vax.
 1.1 19-Sep-2011  jruoho Move the tests/libc/ieeefp to tests/libc/gen to match the structure of libc.
Also rename the test files to gain functional scope.
 1.3.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.3.2.1 17-Apr-2012  yamt sync with head
 1.9.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.2.1 23-Jun-2013  tls resync from head
 1.16.16.1 10-Jun-2019  christos Sync with HEAD
 1.16.14.2 26-Jan-2019  pgoyette Sync with HEAD
 1.16.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.8 29-Oct-2024  riastradh fpsetround(3): Don't toggle all the other bits in fpcr on aarch64.

PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64
 1.7 28-Oct-2024  riastradh fpsetround(3): Test that this doesn't flip on FTZ by accident.

PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64
 1.6 01-Oct-2011  christos branches: 1.6.44; 1.6.52; 1.6.54;
use _FLOAT_IEEE754 instead of vax.
 1.5 30-Sep-2011  christos add more tests.
 1.4 30-Sep-2011  christos add symbolic name printing.
 1.3 30-Sep-2011  christos print stderr, when things go wrong.
 1.2 30-Sep-2011  christos Make the rounding test work properly, and actually test the rounding modes.
 1.1 19-Sep-2011  jruoho Move the tests/libc/ieeefp to tests/libc/gen to match the structure of libc.
Also rename the test files to gain functional scope.
 1.6.54.1 02-Aug-2025  perseant Sync with HEAD
 1.6.52.1 01-Nov-2024  martin Pull up following revision(s) (requested by rin in ticket #996):

tests/lib/libc/gen/t_fpsetround.c: revision 1.7
tests/lib/libc/gen/t_fpsetround.c: revision 1.8
lib/libc/arch/aarch64/gen/fpsetround.c: revision 1.4

fpsetround(3): Test that this doesn't flip on FTZ by accident.
PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64

fpsetround(3): Don't toggle all the other bits in fpcr on aarch64.
PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64
 1.6.44.1 20-Nov-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1923):

tests/lib/libc/gen/t_fpsetround.c: revision 1.7
tests/lib/libc/gen/t_fpsetround.c: revision 1.8
lib/libc/arch/aarch64/gen/fpsetround.c: revision 1.4

fpsetround(3): Test that this doesn't flip on FTZ by accident.
PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64

fpsetround(3): Don't toggle all the other bits in fpcr on aarch64.
PR port-arm/58782: fpsetround flips all the other fpcsr bits on aarch64
 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;
PR/51809: Ngie Cooper: fix file descriptor leak
 1.1 08-Nov-2011  jruoho branches: 1.1.2; 1.1.24;
Few naive checks for cpuset(3) and ftok(3).
 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 08-Nov-2011  yamt file t_ftok.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.2.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 27-Jul-2011  jruoho As per PR bin/45180, do not traverse too deep.
 1.2 16-Jun-2011  joerg Use proper format strings.
 1.1 10-Apr-2011  jruoho branches: 1.1.2;
A naive test case for getcwd(3).
 1.1.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1 31-May-2022  riastradh libc: Reintroduce getentropy.

This was introduced two years ago when the getrandom/getentropy API
question was still open, and removed because the discussion was
ongoing. Now getentropy is more widely adopted and soon to be in
POSIX. So reintroduce the symbol into libc since we'll be keeping it
anyway. Discussion of details of the semantics, as interpreted by
NetBSD, is ongoing, but the symbol needs to get in before the
netbsd-10 branch. The draft POSIX text is
(https://www.opengroup.org/austin/docs/austin_1110.pdf):

SYNOPSIS
#include <unistd.h>

int getentropy(void *buffer, size_t length);

DESCRIPTION
The getentropy() function shall write length bytes of data
starting at the location pointed to by buffer. The output
shall be unpredictable high quality random data, generated by
a cryptographically secure pseudo-random number
generator. The maximum permitted value for the length
argument is given by the {GETENTROPY_MAX} symbolic constant
defined in <limits.h>.

RETURN VALUES
Upon successful completion, getentropy() shall return 0;
otherwise, -1 shall be retunred and errno set to indicate the
error.

ERRORS
The getentropy() function shall fail if:

[EINVAL] The value of length is greater than
{GETENTROPY_MAX}.

The getentropy() function may fail if:

[ENOSYS] The system does not provide the necessary
source of entropy.

RATIONALE
The getentropy() function is not a cancellation point.

Minor changes from the previous introduction of getentropy into libc:

- Return EINVAL, not EIO, on buflen > 256.
- Define GETENTROPY_MAX in limits.h.

The declaration of getentropy in unistd.h and definition of
GETENTROPY_MAX in limits.h are currently conditional on
_NETBSD_SOURCE. When the next revision of POSIX is finalized, we can
expose them also under _POSIX_C_SOURCE > 20yymmL as usual -- and this
can be done as a pullup without breaking existing compiled programs.
 1.2 11-May-2011  njoly Typo in error message.
 1.1 05-Apr-2011  jruoho Add simple test cases for ttyname(3), strtod(3), and getgrent(3).
 1.10 13-Mar-2020  rillig t_glob.c: clean up test code

In struct vfs_file, using an int as a boolean is an anachronism and has
been replaced with a single-character file type, like in ls(1).

Some other redundant test code has been removed as well since it was
either unreachable or existed only for performance reasons.
 1.9 13-Mar-2020  rillig t_glob.c: add test cases for hidden directory and file

The existing test code was geared towards every little bit of
performance. It even duplicated the file definitions in vfs_stat in order
to avoid a few strcmp calls. This made the test code fragile. Therefore,
vfs_stat has been rewritten completely to not duplicate any information
from the vfs.

In vfs_stat, the returned st_mode is now more realistic. It had been 0
before. The file mode is only logged when it makes sense. In the ENOENT
case it is not logged anymore.

The debug logging for opendir/closedir now logs the same pointer, so that
the corresponding calls can be matched easily. Failed vfs_opendir calls
are logged as well, to get a more complete picture of which callbacks are
called.
 1.8 13-Mar-2020  rillig t_glob.c: use distinct names for test structures

Before, the structures and functions defined by the test used the same
prefix as the code to be tested. This made it difficult to draw a line
between these parts.
 1.7 13-Mar-2020  rillig t_glob.c: move expected globbing result directly into the test cases

This makes the tests more self-contained. The example directory tree that
is common to all the tests is still defined elsewhere, but in the same
file. Setting up the example directory structure in each test would make
the tests even more independent and read.
 1.6 26-Apr-2017  christos branches: 1.6.10;
- add range tests
- be more descriptive about errors
 1.5 14-Jan-2017  christos branches: 1.5.4;
PR/51825: Ngie Cooper: use the non _ version of the macro
 1.4 13-Jan-2017  christos Don't play with "../.." in includes for h_macros.h; deal with it centrally.
Minor fixes.
 1.3 02-Jan-2013  martin branches: 1.3.12;
Remove check for GLOB_NOCHECK - the behaviour has been changed again, so it
will return a modified pattern.
 1.2 18-Dec-2012  christos - make our stat function return ENOENT if a file is not found.
- add a GLOB_NOMATCH check
 1.1 07-Jul-2011  jruoho branches: 1.1.2; 1.1.8;
Move 't_glob_star' to 't_glob' for glob(3).
 1.1.8.1 25-Feb-2013  tls resync with head
 1.1.2.1 23-Jan-2013  yamt sync with head
 1.3.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.4.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.6.10.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.8 07-Jul-2011  jruoho Move 't_glob_star' to 't_glob' for glob(3).
 1.7 07-Jul-2011  jruoho Rename some test case names for consistency. No functional change.
 1.6 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.5 13-Oct-2010  pooka Use actual buffer size instead of sizeof(char *). Makes the test
work on non-64bit platforms.
 1.4 13-Oct-2010  pooka fix -DDEBUG
 1.3 11-Oct-2010  christos use "RZ()" instead of ATF_CHECK(), since ATF_CHECK does not deal with errno.
This is repulsive, specially the part about hard-coding the h_macros.h file
in the c code.
 1.2 11-Oct-2010  christos don't use err(), from pooka.
CV: ----------------------------------------------------------------------
 1.1 06-Sep-2010  christos Add tests for GLOB_STAR
 1.10 11-Mar-2019  kre Explicitly test for PR lib/54053

A suitable test was actually there already - but the results
were not verified. So just add a test that the result string
is what is expected. (Previously for len==128 and bytes==10000
it would have returned "0E" now it returns 10000 as it should.)
 1.9 10-Jan-2017  christos branches: 1.9.14;
PR/51810: Ngie Cooper: don't leak buf
 1.8 18-Mar-2012  jruoho branches: 1.8.14;
To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
 1.7 17-Mar-2012  christos This does not fail anymore. Explain why the test was modified.
 1.6 15-Mar-2012  joerg Mark w_printf as __printflike and fix a format string error.
 1.5 07-Jul-2011  jruoho branches: 1.5.2; 1.5.4;
Rename some test case names for consistency. No functional change.
 1.4 11-Jun-2011  christos Turn warns on for all tests and fix all the bugs.
 1.3 06-Apr-2011  jruoho branches: 1.3.2;
Mark this also as expected failure.
 1.2 06-Apr-2011  jruoho Formally verify the numerous bugs in humanize_number(3).
From PR lib/44097, by yamt@.
 1.1 28-Dec-2010  pgoyette Migrate the remaining libc/gen tests to atf
 1.3.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.5.4.1 17-Mar-2012  bouyer Pull up following revision(s) (requested by joerg in ticket #119):
tests/lib/libc/stdio/t_printf.c: revision 1.5
tests/lib/libc/stdio/t_scanf.c: revision 1.2
tests/lib/libc/gen/t_humanize_number.c: revision 1.6
Mark w_printf as __printflike and fix a format string error.
Fix format strings to properly quote %.
 1.5.2.1 17-Apr-2012  yamt sync with head
 1.8.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.14.1 10-Jun-2019  christos Sync with HEAD
 1.6 07-Apr-2025  riastradh tests/lib/libc/gen/t_isnan: Fix architecture conditionals.

1. Skip isinf_basic on VAX. We have no other way to query `does this
architecture support infinities?' and other tests already use
isinf(HUGE_VAL) to determine that, so let's just make sure it
works correctly on VAX.

2. Don't skip these tests on m68k. This was originally conditional
on m68000 (which is to say, NetBSD's MACHINE_ARCH for Motorola
68010 CPUs, i.e., the sun2 port), and was later mistakenly changed
to m68k. But there's no reason any m68k, 68010 or later, should
skip this -- the floating-point format of the ABI does have NaN
and infinity, whether it's a softfloat ABI or hardfloat ABI.

PR misc/59266: t_isnan:isinf_basic test is bogus on some ports
 1.5 04-Nov-2014  justin branches: 1.5.28;
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.4 09-Feb-2014  jmmv Use compiler builtins instead of atf_arch and atf_machine.

The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
 1.3 16-Sep-2013  martin Retry previous
 1.2 16-Sep-2013  martin Make it compile on archs where NAN is not defined - previously it only
compiled by chance (and details of the __isnan macro) on vax.
 1.1 19-Sep-2011  jruoho branches: 1.1.2; 1.1.8;
Move the tests/libc/ieeefp to tests/libc/gen to match the structure of libc.
Also rename the test files to gain functional scope.
 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.5.28.1 02-Aug-2025  perseant Sync with HEAD
 1.6 19-Sep-2011  jruoho Move duplicate ldexp(3) test out from the tests/libc.
 1.5 07-Apr-2011  jruoho Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.4 20-Feb-2011  jmmv Adjust tests now that the values of atf_arch and atf_machine have been
reversed to carry their real intended meanings.

This is part of PR bin/44305.
 1.3 03-Jan-2011  pgoyette branches: 1.3.2;
Don't run FP Exception tests under qemu - they don't work.

While here, properly skip certain tests on vax architecture. (It is
not legal to have a test-program with zero test cases, so each test
case needs to check-and-skip.)
 1.2 01-Jan-2011  pgoyette Build t_ldexp test always. The test itself determines if it is running
on an unsupported platform (vax) and exits.
 1.1 28-Dec-2010  pgoyette Migrate the ldexp test to atf
 1.3.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.8 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.7 01-May-2011  jruoho branches: 1.7.4;
PR lib/42587 was fixed; remove xfail.
 1.6 25-Apr-2011  njoly In nice_err testcase, use ATF_REQUIRE_ERRNO.
 1.5 17-Apr-2011  jruoho Test nice(3) also with threads.
 1.4 10-Apr-2011  jruoho "wrong return value" -> "wrong errno".
 1.3 06-Apr-2011  jruoho As there is PR lib/42587, mark tiny POSIX error as expected failure.
 1.2 04-Apr-2011  jruoho Use _exit(2).
 1.1 04-Apr-2011  jruoho Few simple tests for nice(3).
 1.7.4.1 17-Apr-2012  yamt sync with head
 1.1 10-May-2011  jruoho Few naive tests for pause(3).
 1.6 03-Nov-2016  kamil Prefer modern simple past tense and past participle of catch

The "catched" form is obsolete and nonstandard, prefer "caught".
 1.5 10-May-2011  jruoho branches: 1.5.26;
Add also a simplistic stress unit test.
 1.4 09-May-2011  jruoho Add one more naive unit test.
 1.3 05-Apr-2011  jruoho Rename some tests. No functional change.
 1.2 30-Mar-2011  jruoho Add missing __RCSID(3).
 1.1 24-Mar-2011  jruoho Add a naive test case for raise(3).
 1.5.26.1 04-Nov-2016  pgoyette Sync with HEAD
 1.5 07-Mar-2015  isaki Reduce the number of loops.
It avoids timeout on slow machines, and I think that 100,000
times loop also satisfies the evaluation.
PR lib/49664 (no comments)
 1.4 14-Feb-2015  isaki uint64_t -> uint32_t. 32bit is sufficient in this case
and it improved the performance approx 7% on my 68030.
see also PR lib/49664.
 1.3 07-Jul-2011  jruoho Rename some test case names for consistency. No functional change.
 1.2 13-Jan-2011  pgoyette Repair some printf formats
 1.1 13-Jan-2011  pgoyette Continuing the (re)organization of the lib/libc atf regression tests
 1.3 05-May-2011  jruoho Try to mirror the real source with the test directory structure (otherwise
the latter carries a risk of becoming a difficult mess to manage.)
 1.2 07-Apr-2011  jruoho Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.1 28-Dec-2010  pgoyette Migrate the remaining libc/gen tests to atf
 1.2 27-Mar-2012  njoly branches: 1.2.2;
Adjust the memset size to not override the nul byte at the end of buffer
array.
 1.1 17-Mar-2012  jruoho Add few basic tests for realpath(3).
 1.2.2.2 17-Apr-2012  yamt sync with head
 1.2.2.1 27-Mar-2012  yamt file t_realpath.c was added on branch yamt-pagecache on 2012-04-17 00:09:10 +0000
 1.2 25-Mar-2012  joerg Be UTF8 clean.
 1.1 03-Jun-2011  jruoho branches: 1.1.2; 1.1.4;
Test also setdomainname(3).
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.1.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1.2.1 03-Jun-2011  cherry file t_setdomainname.c was added on branch cherry-xenmp on 2011-06-23 14:20:39 +0000
 1.3 25-Mar-2012  joerg Be UTF8 clean.
 1.2 02-Jun-2011  jruoho branches: 1.2.2; 1.2.4;
Cleanup.
 1.1 02-Jun-2011  jruoho Few naive tests for sethostname(3).
 1.2.4.1 17-Apr-2012  yamt sync with head
 1.2.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.2.1 02-Jun-2011  cherry file t_sethostname.c was added on branch cherry-xenmp on 2011-06-23 14:20:39 +0000
 1.55 04-Sep-2024  rin t_siginfo:adraln: Brush up skip message for x86

Note that:

1. No data address is reported back for alignment check exception, as per
Intel SDM (June 2024).

2. Kernel sets faulting PC to si_addr.

3. 2. is compliant to siginfo(2), at least:

> For SIGILL, SIGFPE, SIGBUS and SIGSEGV ... si_addr contains
> the address of the faulting instruction or data and ...

4. IEEE Std 1003.1-2024 does not require si_addr for SIGBUS. For SIGILL
and SIGSEGV, e.g., it is required (SHALL) to store faulting PC and
data address, respectively, on the other hand.
 1.54 04-Sep-2024  rin t_siginfo:sigbus_adraln: Skip rather than expect_fail on x86

This is an architecture-defined behavior, not a failure.
 1.53 29-Jun-2024  rin branches: 1.53.2;
t_siginfo: sigbus_adraln: Skip for vax

According to "VAX Architecture Handbook", misaligned access does
not trap, although it has performance penalty.
 1.52 20-May-2024  riastradh t_siginfo: More volatile to prevent optimization.
 1.51 14-May-2024  riastradh t_siginfo: Use volatile to prevent optimization.
 1.50 14-May-2024  riastradh t_siginfo: No SIGFPE on RISC-V.
 1.49 04-Aug-2023  rin t_siginfo:sigfpe_int: Adjust for GCC12

Do not use constant 1 as numerator to raise integer division by zero.
GCC >= 12 optimizes (1 / i) into (abs(i) == 1 ? i : 0), even for -O0.
 1.48 07-May-2023  skrll RISC-V support that works on QEMU with a single hart.

Thanks for Simon Burge for plic(4).
 1.47 07-May-2022  rin branches: 1.47.2;
Skip sigfpe_int also for sh3; integer division by zero is not trapped.
 1.46 10-Dec-2021  andvar s/occured/occurred/ in comments, log messages and man pages.
 1.45 13-Jan-2021  skrll skip sigbus_adraln on MIPS
 1.44 11-Jan-2021  skrll PR/55715: pmax testbed panics with "assertion "asid == curcpu()->ci_pmap_asid_cur" failed"

It's GXemul that has the bug! Unfortunately, there's no way (currently) to
detect if we're running under GXemul emulation, so disable for all mips
for now. Hopefully, GXemul will get fixed soon.
 1.43 10-Jan-2021  skrll PR/55715: pmax testbed panics with "assertion "asid == curcpu()->ci_pmap_asid_cur" failed"

disable the sigbus_adraln test on qemu for now
 1.42 13-Oct-2020  rin For aarch64eb, no SIGBUS signal for unaligned accesses.
Convert to preprocessor directives.
 1.41 24-Aug-2020  gson Expect a failure to trap unaligned acesses only when running under
qemu's TCG CPU emulation, not when running under hardware virtualization
such as qemu -accel nvmm.
 1.40 20-Jun-2020  rin Skip sigbus_adraln for powerpc.

SIGBUS for unaligned accesses is not mandatory for powerpc;
most processors (not all, e.g., 403) can deal with that.
 1.39 22-Feb-2020  kamil Disable the t_siginfo test under MKSANITIZER / MKLIBCSANITIZER

Signal crash events are incompatible with sanitizers.
 1.38 21-Feb-2020  kamil Mark division by 0 as expected in sigfpe_int

Disable ubsan instrumentation on the operation.
 1.37 11-Feb-2020  riastradh aarch64 doesn't trap integer division by zero either.
 1.36 25-Apr-2019  kamil Fix typo in 'exceptions'
 1.35 30-Jan-2019  martin Clean up terminology: modern arm CPUs do properly implement IEEE 754
floating point exceptions - but some (actually all currently know ones)
do not implement sending traps when these exceptions are raised.

Pointed out by Peter Maydell.
 1.34 26-Jan-2019  martin aarch64 does not trap on unaligned acces
 1.33 23-Jan-2019  martin There are aarch64 Cortex cpus that do not trap on some floating point
exceptions - so apply the arm handling for aarch64 as well.
 1.32 17-Jan-2018  maya branches: 1.32.2; 1.32.4;
Improve portability of headers and sort them.

From Ngie Cooper in PR bin/51833
 1.31 05-Mar-2017  chs reenable sigfpe_flt on powerpc now that FPU exceptions work.
 1.30 22-Dec-2015  christos branches: 1.30.2; 1.30.4;
Add __TEST_FENV
 1.29 17-Feb-2015  isaki m68k (except sun2) never issue SIGBUS on unaligned accesses.
PR lib/49653. Thanks martin@.
 1.28 13-Feb-2015  martin Fix strange editor mishap and start block comment on its own line.
 1.27 29-Dec-2014  martin Include <ieeefp.h> even for the <fenv.h> case since we use fpsetmask()
to detect ARM Cortex NEON fpus.
 1.26 19-Nov-2014  martin Skip the SIGFPE test on arm when the FPU does not provide exception handling.
 1.25 19-Nov-2014  martin Use machdep.unaligned_sigbus to skip the unaligned access test on arm
as well.
 1.24 04-Nov-2014  justin 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.23 09-Feb-2014  jmmv Use compiler builtins instead of atf_arch and atf_machine.

The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
 1.22 26-Jan-2014  matt Support using fenv instead of fpsetmask if HAVE_FENV is defined.
 1.21 25-Jan-2014  skrll Use English spelling of alignment.
 1.20 12-Apr-2013  christos use one qemu test
 1.19 12-Apr-2013  christos easier way to find if we are on qemu.
 1.18 13-Jun-2012  njoly branches: 1.18.2;
Skip sigbus_adraln testcase on alpha unless global
machdep.unaligned_sigbus sysctl is enabled.
 1.17 23-Apr-2012  martin Revert previous, si_addr is expected to be the faulting *data* address
(mmm, consistent standards).
Add a few tweaks to prevent the compiler's optimizer outsmarting the test.
 1.16 22-Apr-2012  martin Do not compare si_addr (address of faulting instruction) against the
unaligned data address causing the fault - this will always fail.
If anybody knows a portable way to get the data address involved in the
fault, please fix the test case as originally intended.
 1.15 20-Apr-2012  jym ATF test for SIGBUS => BUS_ADRALN (invalid address alignment).

That one is tedious to test under x86: alignment exceptions are
not reported by this architecture unless you ask for them explicitely (by
setting the PSL_AC bit). The brokenness does not end there: %cr2 should
contain the address where the unaligned access occured, alas, it does not.

I am not aware of other architectures where this could happen. Still, my
knowledge is limited; if there is one, feel free to send me a mail and I
will update the test accordingly.

Adding insult to injury, this test can fail in various funny ways with VMs:
- under x86 QEMU, no trap() happens. As ring 3 code stays almost untouched by
QEMU VMM, I suppose the exception can only be triggered when the host
itself is capable of catching unaligned accesses.
- under Virtual Box with HVM support, i386 works fine, but amd64 fails with a
SIGILL (Illegal instruction) that happens right before entering the
signal handler. No idea why, and trying to debug it with gdb freezes the VM
(including ddb breaks).

Anyway, tested with:
- i386: P4 host, anita, Virtual Box HVM (Mac OS X)
- amd64: anita, Virtual Box HVM (Mac OS X)

XXX I would appreciate if someone could test it under a real amd64 host with
an up-to-date kernel, so I can reasonably assume that the culprit is
Virtual Box and not our amd64 port (my test machine being off line
I cannot do it myself). Results from other arches would be a plus too.

Initial issue reported by Nicolas Joly on port-amd64. Thanks!
 1.14 18-Mar-2012  jruoho To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
 1.13 17-Mar-2012  christos annotate the PR that failed, and has been fixed.
 1.12 01-Oct-2011  christos branches: 1.12.2;
use _FLOAT_IEEE754 instead of vax.
 1.11 24-May-2011  joerg Use volatile for explicit 0 dereference
 1.10 02-Mar-2011  riz Skip the sigfpe_flt and sigfpe_int tests on powerpc; powerpc does
not fault on divide-by-zero. As discussed on tech-userlevel.
 1.9 01-Mar-2011  pooka Attempt further qemu heuristics to avoid failures due to non-working FPU
 1.8 03-Jan-2011  pgoyette branches: 1.8.2;
Don't run FP Exception tests under qemu - they don't work.

While here, properly skip certain tests on vax architecture. (It is
not legal to have a test-program with zero test cases, so each test
case needs to check-and-skip.)
 1.7 02-Jan-2011  pgoyette If we survive the check for wrong signal code, reset our expectation to
"pass" before checking the signal errno.
 1.6 02-Jan-2011  pgoyette Fix $NetBSD$ keyword
 1.5 31-Dec-2010  mlelstv return from an SIGFPE handler is not defined when the hardware
caused the exception. Use sigsetjmp/siglongjmp to resume the
test function instead.
 1.4 27-Dec-2010  njoly Do use integer arithmetics to generate FPE_INTDIV in sigfpe_int testcase.

Ok pgoyette.
 1.3 26-Dec-2010  pgoyette Re-enable printing of MD data, with appropriate casts.
 1.2 26-Dec-2010  pgoyette For now, don't try to print out machine-dependant stuff. When I figure
out what the right format strings are, I'll re-enable it.
 1.1 25-Dec-2010  pgoyette Move the siginfo tests from regress to atf. While here, add a new test
for PR/43655.

XXX The sigchild_dump test currently fails when execute under atf-run.
XXX It does not fail when executed directly from the shell, so there's
XXX something in atf that prevents the child process from dumping.
 1.8.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.12.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.12.2.3 30-Oct-2012  yamt sync with head
 1.12.2.2 23-May-2012  yamt sync with head.
 1.12.2.1 17-Apr-2012  yamt sync with head
 1.18.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.2.1 23-Jun-2013  tls resync from head
 1.30.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.30.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.32.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.32.4.1 10-Jun-2019  christos Sync with HEAD
 1.32.2.1 26-Jan-2019  pgoyette Sync with HEAD
 1.47.2.1 13-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #856):

tests/lib/libc/gen/t_siginfo.c: revision 1.54
tests/lib/libc/gen/t_siginfo.c: revision 1.55

t_siginfo:sigbus_adraln: Skip rather than expect_fail on x86

This is an architecture-defined behavior, not a failure.
t_siginfo:adraln: Brush up skip message for x86

Note that:
1. No data address is reported back for alignment check exception, as per
Intel SDM (June 2024).
2. Kernel sets faulting PC to si_addr.
3. 2. is compliant to siginfo(2), at least:
For SIGILL, SIGFPE, SIGBUS and SIGSEGV ... si_addr contains
the address of the faulting instruction or data and ...
4. IEEE Std 1003.1-2024 does not require si_addr for SIGBUS. For SIGILL
and SIGSEGV, e.g., it is required (SHALL) to store faulting PC and
data address, respectively, on the other hand.
 1.53.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 08-Apr-2025  riastradh tests/lib/libc/gen/t_sleep: Sprinkle a few more diagnostics.

PR misc/59254: tests/lib/libc/gen/t_sleep:kevent: intermittent failures
 1.13 06-Apr-2025  riastradh tests/lib/libc/gen/t_sleep: Sprinkle diagnostics.

PR misc/59254: tests/lib/libc/gen/t_sleep:kevent: intermittent failures
 1.12 06-Apr-2025  riastradh tests/lib/libc/gen/t_sleep: Nix trailing whitespace.

No functional change intended.

Preparation for:

misc/59254: tests/lib/libc/gen/t_sleep:kevent: intermittent failures
 1.11 10-Jan-2017  maya branches: 1.11.26;
remove duplicate include.

(also move so it is alphabetical, hence the weird diff)
 1.10 10-Jan-2017  christos PR/51811: Ngie Cooper: Fix include file portability.
 1.9 11-Aug-2016  kre Correct use of incorrect errno - should have no real practical effect.
 1.8 15-Jul-2014  gson branches: 1.8.6;
space after comma
 1.7 12-Apr-2013  christos branches: 1.7.4;
easier way to find if we are on qemu.
 1.6 17-Mar-2013  jmmv Do not special-case qemu when expecting the failure due to PR kern/43997.

I am sporadically observing this in my real machine as well. It's harder
to trigger, but it happens.
 1.5 09-Nov-2012  pgoyette branches: 1.5.2; 1.5.4;
More clean-up, and adjust timing of kevent test to avoid issues with
PR kern/43887
 1.4 09-Nov-2012  pgoyette Remove unnecessary header file and an unused variable.
Adjust timing parameters to reduce overall elapsed time, and document
the parameters.
Clean-up status handling for kevent test.
Deal with QEMU timer-related issues (PR-43997).
 1.3 08-Nov-2012  pgoyette Provide clear explanation of test-case failures.
 1.2 08-Nov-2012  pgoyette Remove a debug printf(), and fix the format in another.

Should resolve build break.
 1.1 08-Nov-2012  pgoyette Convert old src/regress/timer&waiter tests to ATF
 1.5.4.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.5.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.5.4.1 09-Nov-2012  yamt file t_sleep.c was added on branch yamt-pagecache on 2013-01-16 05:34:00 +0000
 1.5.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.2.3 23-Jun-2013  tls resync from head
 1.5.2.2 09-Nov-2012  pgoyette More clean-up, and adjust timing of kevent test to avoid issues with
PR kern/43887
 1.5.2.1 09-Nov-2012  pgoyette file t_sleep.c was added on branch tls-maxphys on 2012-11-09 20:13:25 +0000
 1.7.4.1 10-Aug-2014  tls Rebase.
 1.8.6.1 20-Mar-2017  pgoyette Sync with HEAD
 1.11.26.1 02-Aug-2025  perseant Sync with HEAD
 1.3 03-Jul-2020  jruoho Verify that PR lib/55041 is no longer an issue.
 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;
Move 't_syslog_pthread' to 't_syslog' for consistency with libc.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.4 07-Jul-2011  jruoho Move 't_syslog_pthread' to 't_syslog' for consistency with libc.
 1.3 07-Jul-2011  jruoho Rename some test case names for consistency. No functional change.
 1.2 30-Dec-2010  pooka Test is no longer expected to hang.

PR lib/44248 closed when test associate with PR fails ==> brick dholland
 1.1 17-Dec-2010  pooka Add an isolated test case for PR lib/44248.
 1.4 10-Jan-2017  christos PR/51812: Ngie Cooper: According to ToG gettimeofday() needs <sys/time.h>
 1.3 31-Oct-2014  justin branches: 1.3.2;
PR misc/49342 fix issue where time can tick during tests

Note there are still potential issues as the clock being tested is not
monotonic but it should now not fail unless time is being adjusted.
 1.2 11-Nov-2011  jruoho Fix wrong format string.
 1.1 05-Nov-2011  jruoho branches: 1.1.2;
Few naive checks for time(3).
 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_time.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.3.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 22-Apr-2025  nia branches: 1.1.4;
Add basic tests for timespec_get(3), timespec_getres(3)

PR standards/58608
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 22-Apr-2025  perseant file t_timespec_get.c was added on branch perseant-exfatfs on 2025-08-02 05:58:04 +0000
 1.4 10-Jan-2017  christos PR/51813: Ngie Cooper: don't leak fd :ttyname_err
 1.3 01-May-2011  jruoho branches: 1.3.26;
Test also ttyname_r(3).
 1.2 08-Apr-2011  jruoho Adjust the test with stdin(3).
 1.1 05-Apr-2011  jruoho Add simple test cases for ttyname(3), strtod(3), and getgrent(3).
 1.3.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14 12-Aug-2023  riastradh vis(3): Fix one more buffer overrun in an edge case.

PR lib/57573

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.13 12-Aug-2023  riastradh vis(3): Fix main part of PR lib/57573.

From Kyle Evans <kevans@FreeBSD.org>.

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.12 12-Aug-2023  riastradh vis(3) tests: Test another overflow edge case.

Related to PR lib/57573.

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.11 12-Aug-2023  riastradh vis(3) tests: Expand tests and diagnostic outputs on failure.

PR lib/57573

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.10 12-Aug-2023  riastradh vis(3) tests: Add xfail test for encoding overflow.

From Kyle Evans <kevans@FreeBSD.org>.

PR lib/57573

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.9 10-Jan-2017  christos branches: 1.9.6; 1.9.16; 1.9.24;
PR/51806: Ngie Cooper: Only run the vis locale test if VIS_NOLOCALE is defined
 1.8 23-May-2015  christos branches: 1.8.2;
Add a VIS_NOLOCALE test
 1.7 08-Sep-2014  christos add null and empty tests.
 1.6 13-Feb-2013  christos - check the results of the vis functions
- zero output to make sure things work
- don't use encodings that don't work
- fix the style on decoding
 1.5 11-Feb-2013  christos check the results of encoding and decoding
 1.4 06-Nov-2011  christos branches: 1.4.6;
add tests for \x and \xx
 1.3 07-Jul-2011  jruoho branches: 1.3.2;
Move 't_syslog_pthread' to 't_syslog' for consistency with libc.
 1.2 12-Mar-2011  christos Fix various vis/unvis issues:
- no need for all the weak symbols
- define a new _VIS_END flag for UNVIS_END so that there are no collisions
between and vis and unvis flags.
- add bound versions of the vis and unvis functions that take the length of
the destination buffer. Unlike the OpenBSD ones they return -1 or NULL if
the buffer is not large enough, instead of silently truncating.
 1.1 28-Dec-2010  pgoyette Migrate the remaining libc/gen tests to atf
 1.3.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.3.2.1 10-Nov-2011  yamt sync with head
 1.4.6.1 25-Feb-2013  tls resync with head
 1.8.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.24.1 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #485):

lib/libc/gen/vis.c: revision 1.76-1.86
tests/lib/libc/gen/t_vis.c: revision 1.10-1.14

vis(3): Avoid nonportable MIN in portable code.

vis(3) tests: Add xfail test for encoding overflow.

From Kyle Evans <kevans%FreeBSD.org@localhost>.
PR lib/57573

vis(3) tests: Expand tests and diagnostic outputs on failure.
PR lib/57573

vis(3) tests: Test another overflow edge case.
Related to PR lib/57573.

vis(3): Make maxolen unsigned size_t, not ssize_t.
It is initialized once either to *dlen, which is unsigned size_t, or
to wcslen(start) * MB_MAX_LEN + 1, and wcslen returns unsigned size_t
too. So there appears to have never been any reason for this to be
signed.
Part of PR lib/57573.

vis(3): Make mbslength unsigned.
Sprinkle assertions and comments justifying the proposition that it
would never go negative if signed.
Obviates need to worry about mblength > SSIZE_MAX.
Prompted by PR lib/57573.

vis(3): Avoid arithmetic overflow before calloc(3).
Prompted by PR lib/57573.

vis(3): Call wcslen(start) only once.
It had better not change between these two times!
Prompted by PR lib/57573.

vis(3): Avoid potential arithmetic overflow in maxolen.
Can't easily prove that this overflow is impossible, so let's add a
check.
Prompted by PR lib/57573.

vis(3): Fix main part of PR lib/57573.
From Kyle Evans <kevans%FreeBSD.org@localhost>.

vis(3): Fix one more buffer overrun in an edge case.
PR lib/57573

vis(3): Sort includes. No functional change intended.
Prompted by PR lib/57573.

vis(3): Need <stdint.h> for SIZE_MAX, per C standard.
From Kyle Evans <kevans%FreeBSD.org@localhost>.
Followup to PR lib/57573.

vis(3): Per KNF, sys/param.h comes before sys/types.h.
Which is nice because that's also lexicographic.
 1.9.16.1 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1774):

lib/libc/gen/vis.c: revision 1.75-1.86
tests/lib/libc/gen/t_vis.c: revision 1.10-1.14

PR 56260: fix out-of-bounds stack read.

vis(3): Avoid nonportable MIN in portable code.

vis(3) tests: Add xfail test for encoding overflow.

From Kyle Evans <kevans%FreeBSD.org@localhost>.
PR lib/57573

vis(3) tests: Expand tests and diagnostic outputs on failure.
PR lib/57573

vis(3) tests: Test another overflow edge case.
Related to PR lib/57573.

vis(3): Make maxolen unsigned size_t, not ssize_t.
It is initialized once either to *dlen, which is unsigned size_t, or
to wcslen(start) * MB_MAX_LEN + 1, and wcslen returns unsigned size_t
too. So there appears to have never been any reason for this to be
signed.
Part of PR lib/57573.

vis(3): Make mbslength unsigned.
Sprinkle assertions and comments justifying the proposition that it
would never go negative if signed.
Obviates need to worry about mblength > SSIZE_MAX.
Prompted by PR lib/57573.

vis(3): Avoid arithmetic overflow before calloc(3).
Prompted by PR lib/57573.

vis(3): Call wcslen(start) only once.
It had better not change between these two times!
Prompted by PR lib/57573.

vis(3): Avoid potential arithmetic overflow in maxolen.
Can't easily prove that this overflow is impossible, so let's add a
check.
Prompted by PR lib/57573.

vis(3): Fix main part of PR lib/57573.
From Kyle Evans <kevans%FreeBSD.org@localhost>.

vis(3): Fix one more buffer overrun in an edge case.
PR lib/57573

vis(3): Sort includes. No functional change intended.
Prompted by PR lib/57573.

vis(3): Need <stdint.h> for SIZE_MAX, per C standard.
From Kyle Evans <kevans%FreeBSD.org@localhost>.
Followup to PR lib/57573.

vis(3): Per KNF, sys/param.h comes before sys/types.h.
Which is nice because that's also lexicographic.
 1.9.6.1 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1923):

lib/libc/gen/vis.c: revision 1.75-1.86
tests/lib/libc/gen/t_vis.c: revision 1.10-1.14

PR 56260: fix out-of-bounds stack read.

vis(3): Avoid nonportable MIN in portable code.

vis(3) tests: Add xfail test for encoding overflow.

From Kyle Evans <kevans%FreeBSD.org@localhost>.
PR lib/57573

vis(3) tests: Expand tests and diagnostic outputs on failure.
PR lib/57573

vis(3) tests: Test another overflow edge case.
Related to PR lib/57573.

vis(3): Make maxolen unsigned size_t, not ssize_t.
It is initialized once either to *dlen, which is unsigned size_t, or
to wcslen(start) * MB_MAX_LEN + 1, and wcslen returns unsigned size_t
too. So there appears to have never been any reason for this to be
signed.
Part of PR lib/57573.

vis(3): Make mbslength unsigned.
Sprinkle assertions and comments justifying the proposition that it
would never go negative if signed.
Obviates need to worry about mblength > SSIZE_MAX.
Prompted by PR lib/57573.

vis(3): Avoid arithmetic overflow before calloc(3).
Prompted by PR lib/57573.

vis(3): Call wcslen(start) only once.
It had better not change between these two times!
Prompted by PR lib/57573.

vis(3): Avoid potential arithmetic overflow in maxolen.
Can't easily prove that this overflow is impossible, so let's add a
check.
Prompted by PR lib/57573.

vis(3): Fix main part of PR lib/57573.
From Kyle Evans <kevans%FreeBSD.org@localhost>.

vis(3): Fix one more buffer overrun in an edge case.
PR lib/57573

vis(3): Sort includes. No functional change intended.
Prompted by PR lib/57573.

vis(3): Need <stdint.h> for SIZE_MAX, per C standard.
From Kyle Evans <kevans%FreeBSD.org@localhost>.
Followup to PR lib/57573.

vis(3): Per KNF, sys/param.h comes before sys/types.h.
Which is nice because that's also lexicographic.
 1.1 29-Apr-2014  uebayasi branches: 1.1.2; 1.1.4; 1.1.8;
Minimal execve(2) ATF test.
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 29-Apr-2014  tls file Makefile was added on branch tls-maxphys on 2014-08-20 00:04:49 +0000
 1.1.4.2 10-Aug-2014  tls Rebase.
 1.1.4.1 29-Apr-2014  tls file Makefile was added on branch tls-earlyentropy on 2014-08-10 06:57:21 +0000
 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 29-Apr-2014  yamt file Makefile was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.4 13-Mar-2025  riastradh execve(2), posix_spawn(2): Don't flush _all_ pending signals.

We need only flush those pending signals whose dispositions have been
reset to the default action when that action is to ignore them --
e.g., if the parent had a signal handler function for SIGCHLD or
SIGWINCH, this is reset to the default disposition, which is to
ignore the signal, so any pending SIGCHLD or SIGWINCH need to be
flushed.

And we have logic to do this already in execsigs(9), via
sigclearset(9), which clears the specified set of signals:

402 sigemptyset(&tset);
403 for (signo = 1; signo < NSIG; signo++) {
404 if (sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
405 prop = sigprop[signo];
406 if (prop & SA_IGNORE) {
407 if ((prop & SA_CONT) == 0)
408 sigaddset(&p->p_sigctx.ps_sigignore,
409 signo);
410 sigaddset(&tset, signo);
411 }
412 SIGACTION_PS(ps, signo).sa_handler = SIG_DFL;
...
420 sigclearall(p, &tset, &kq);

https://nxr.netbsd.org/xref/src/sys/kern/kern_sig.c?r=1.409#394

But back in 2003, when ksiginfo_t was introduced, before that logic
was written, we sprouted an exithook to clear _all_ the signals (and,
more importantly for the time, free the ksiginfo_t records to avoid
leaking memory) -- and we wired it up as an _exechook_ too:

+/*
+ * free all pending ksiginfo on exit
+ */
+static void
+ksiginfo_exithook(struct proc *p, void *v)
+{
+ ksiginfo_t *ksi, *hp = p->p_sigctx.ps_siginfo;
+
+ if (hp == NULL)
+ return;
+ for (;;) {
+ pool_put(&ksiginfo_pool, ksi);
+ if ((ksi = ksi->ksi_next) == hp)
+ break;
+ }
+}
...
+ exithook_establish(ksiginfo_exithook, NULL);
+ exechook_establish(ksiginfo_exithook, NULL);

https://mail-index.netbsd.org/source-changes/2003/09/14/msg133910.html

(The first iteration of ksiginfo_exithook had another bug, of course!
But it was soon fixed; that's not the issue here.)

Later, during the newlock2 branch, sigclearall got added for execsigs
to free only the ksiginfo_t records for those signals whose
disposition is being reset to a default action of ignoring the
signal:

void
execsigs(struct proc *p)
{
...
+ sigset_t tset;
...
- for (signum = 1; signum < NSIG; signum++) {
- if (sigismember(&p->p_sigctx.ps_sigcatch, signum)) {
- prop = sigprop[signum];
+ sigemptyset(&tset);
+ for (signo = 1; signo < NSIG; signo++) {
+ if (sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
+ prop = sigprop[signo];
if (prop & SA_IGNORE) {
if ((prop & SA_CONT) == 0)
sigaddset(&p->p_sigctx.ps_sigignore,
- signum);
- sigdelset(&p->p_sigctx.ps_siglist, signum);
+ signo);
+ sigaddset(&tset, signo);
...
}
+ sigclearall(p, &tset);

https://mail-index.netbsd.org/source-changes/2006/10/21/msg176390.html

And the _exithook_ was removed somewhere along the way in the
newlock2 branch (in favour of simply calling sigclearall in exit1),
but the _exechook_ remained:

-static void ksiginfo_exithook(struct proc *, void *);
+static void ksiginfo_exechook(struct proc *, void *);
...
- exithook_establish(ksiginfo_exithook, NULL);
- exechook_establish(ksiginfo_exithook, NULL);
+ exechook_establish(ksiginfo_exechook, NULL);
...
/*
- * ksiginfo_exithook:
+ * ksiginfo_exechook:
*
- * Free all pending ksiginfo entries from a process on exit.
+ * Free all pending ksiginfo entries from a process on exec.
* Additionally, drain any unused ksiginfo structures in the
* system back to the pool.
+ *
+ * XXX This should not be a hook, every process has signals.
*/
static void
-ksiginfo_exithook(struct proc *p, void *v)
+ksiginfo_exechook(struct proc *p, void *v)
{

https://mail-index.netbsd.org/source-changes/2007/02/05/msg180796.html

The symptom of this mistake is that a signal delivered _during_
execve(2) may be simply discarded, even if it should be caught and
cause the process to terminate.

On the bright side, isn't it a nice feeling when you can solve
problems by commits that consist exclusively of deletions?

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.3 13-Mar-2025  riastradh execve(2), posix_spawn(2): Add test case for an embarrassing bug.

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.2 12-Sep-2015  christos branches: 1.2.28;
make error more informative.
 1.1 29-Apr-2014  uebayasi branches: 1.1.2; 1.1.4; 1.1.8;
Minimal execve(2) ATF test.
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 29-Apr-2014  tls file t_execve.c was added on branch tls-maxphys on 2014-08-20 00:04:49 +0000
 1.1.4.2 10-Aug-2014  tls Rebase.
 1.1.4.1 29-Apr-2014  tls file t_execve.c was added on branch tls-earlyentropy on 2014-08-10 06:57:21 +0000
 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 29-Apr-2014  yamt file t_execve.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.2.28.1 02-Aug-2025  perseant Sync with HEAD
 1.4 07-Nov-2021  martin Fix linking for multi-source file tests, the second part of the tuple
needs to be the C source file (not the base name)
 1.3 07-Nov-2021  christos new tests for posix_spawn_chdir from Piyush Sachdeva
 1.2 14-Feb-2012  martin branches: 1.2.4;
Add a few more posix_spawn testcases, which should detect everything that
was wrong in the initial version, causing the failure reported in
PR kern/45991.
 1.1 13-Feb-2012  martin Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.2.4.2 17-Apr-2012  yamt sync with head
 1.2.4.1 14-Feb-2012  yamt file Makefile was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.1 13-Feb-2012  martin branches: 1.1.4;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file Makefile.inc was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.2 16-Mar-2025  riastradh tests/lib/libc/gen/posix_spawn: Spruce up a bit.

- KNF
- Don't touch files outside the test working directory.
- No need to pre-clean files -- atf gives us an empty tempdir.
- Use h_macros.h to simplify a lot of checks.
- Use names for enumerated arguments, not magic numbers.
- Check some more syscalls.
- Add include guard.
 1.1 07-Nov-2021  christos branches: 1.1.4;
new tests for posix_spawn_chdir from Piyush Sachdeva
 1.1.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 16-Mar-2025  riastradh tests/lib/libc/gen/posix_spawn: Spruce up a bit.

- KNF
- Don't touch files outside the test working directory.
- No need to pre-clean files -- atf gives us an empty tempdir.
- Use h_macros.h to simplify a lot of checks.
- Use names for enumerated arguments, not magic numbers.
- Check some more syscalls.
- Add include guard.
 1.1 07-Nov-2021  christos branches: 1.1.4;
new tests for posix_spawn_chdir from Piyush Sachdeva
 1.1.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 07-Nov-2021  christos new tests for posix_spawn_chdir from Piyush Sachdeva
 1.1 13-Feb-2012  martin branches: 1.1.4;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file h_fileactions.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.1 13-Feb-2012  martin branches: 1.1.4;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file h_nonexec.sh was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.3 07-Nov-2021  christos new tests for posix_spawn_chdir from Piyush Sachdeva
 1.2 02-May-2021  martin Add test for POSIX_SPAWN_RESETIDS flag
 1.1 13-Feb-2012  martin branches: 1.1.4;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file h_spawn.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.3 07-Nov-2021  christos new tests for posix_spawn_chdir from Piyush Sachdeva
 1.2 21-Aug-2021  andvar fix mainly same typos as in my previous commit but outside sys/dev/dm.
 1.1 13-Feb-2012  martin branches: 1.1.4;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file h_spawnattr.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.11 12-Jul-2025  gutteridge t_fileactions.c: fix typos in comments
 1.10 10-Jul-2025  martin In the test code for PR 59523 move the redirect of stdout to the end of
the fileactions, to avoid any interference with the assumptions of the
test-relevant file actions.
We can not guarantee anny of this anyway (but it did trigger the original
problem and both paths in the kernel before the bug was fixed).
Pointed out by kre.
 1.9 09-Jul-2025  martin Add two test cases triggereing the two paths in posix_spawn
that cause PR 59523.
 1.8 16-Mar-2025  riastradh tests/lib/libc/gen/posix_spawn: Spruce up a bit.

- KNF
- Don't touch files outside the test working directory.
- No need to pre-clean files -- atf gives us an empty tempdir.
- Use h_macros.h to simplify a lot of checks.
- Use names for enumerated arguments, not magic numbers.
- Check some more syscalls.
- Add include guard.
 1.7 07-Nov-2021  christos branches: 1.7.4;
new tests for posix_spawn_chdir from Piyush Sachdeva
 1.6 10-Jan-2017  christos more tests needing <sys/stat.h>
 1.5 09-Apr-2012  martin branches: 1.5.2; 1.5.16;
Fix asynchronous posix_spawn child exit status (and test for it).
 1.4 08-Apr-2012  martin Rework posix_spawn locking and memory management:
- always provide a vmspace for the new proc, initially borrowing from proc0
(this part fixes PR 46286)
- increase parallelism between parent and child if arguments allow this,
avoiding a potential deadlock on exec_lock
- add a new flag for userland to request old (lockstepped) behaviour for
better error reporting
- adapt test cases to the previous two and add a new variant to test the
diagnostics flag
- fix a few memory (and lock) leaks
- provide netbsd32 compat
 1.3 20-Feb-2012  martin Add a test case to call posix_spawn with empty file actions, which reproduced
the (now fixed) PR kern/46038.
 1.2 14-Feb-2012  martin branches: 1.2.2;
Add a few more posix_spawn testcases, which should detect everything that
was wrong in the initial version, causing the failure reported in
PR kern/45991.
 1.1 13-Feb-2012  martin Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.2.2.2 12-Apr-2012  riz Pull up following revision(s) (requested by martin in ticket #175):
sys/kern/kern_exit.c: revision 1.238
tests/lib/libc/gen/posix_spawn/t_fileactions.c: revision 1.4
tests/lib/libc/gen/posix_spawn/t_fileactions.c: revision 1.5
sys/uvm/uvm_extern.h: revision 1.183
lib/libc/gen/posix_spawn_fileactions.c: revision 1.2
sys/kern/kern_exec.c: revision 1.348
sys/kern/kern_exec.c: revision 1.349
sys/compat/netbsd32/syscalls.master: revision 1.95
sys/uvm/uvm_glue.c: revision 1.159
sys/uvm/uvm_map.c: revision 1.317
sys/compat/netbsd32/netbsd32.h: revision 1.95
sys/kern/exec_elf.c: revision 1.38
sys/sys/spawn.h: revision 1.2
sys/sys/exec.h: revision 1.135
sys/compat/netbsd32/netbsd32_execve.c: revision 1.34
Rework posix_spawn locking and memory management:
- always provide a vmspace for the new proc, initially borrowing from proc0
(this part fixes PR 46286)
- increase parallelism between parent and child if arguments allow this,
avoiding a potential deadlock on exec_lock
- add a new flag for userland to request old (lockstepped) behaviour for
better error reporting
- adapt test cases to the previous two and add a new variant to test the
diagnostics flag
- fix a few memory (and lock) leaks
- provide netbsd32 compat
Fix asynchronous posix_spawn child exit status (and test for it).
 1.2.2.1 20-Feb-2012  sborrill Pull up the following revisions(s) (requested by martin in ticket #14):
include/spawn.h: revision 1.2
sys/kern/kern_exec.c: revision 1.341
sys/uvm/uvm_glue.c: revision 1.157
tests/lib/libc/gen/posix_spawn/t_fileactions.c: revision 1.3

posix_spawn: fix kernel bug when passing empty fileactions (PR kern/46038)
and add a test case for this. Fix potential race condition, doublefreeing
of memory and memory leaks in error cases.
 1.5.16.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.2.2 17-Apr-2012  yamt sync with head
 1.5.2.1 09-Apr-2012  yamt file t_fileactions.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.7.4.1 02-Aug-2025  perseant Sync with HEAD
 1.12 16-Mar-2025  riastradh tests/lib/libc/gen/posix_spawn: Spruce up a bit.

- KNF
- Don't touch files outside the test working directory.
- No need to pre-clean files -- atf gives us an empty tempdir.
- Use h_macros.h to simplify a lot of checks.
- Use names for enumerated arguments, not magic numbers.
- Check some more syscalls.
- Add include guard.
 1.11 15-Mar-2025  riastradh t_spawn: Add missing dup2 in t_spawn_sig.

Matches what h_execsig expects, and what t_execve_sig arranges: stdin
is a pipe that the parent will write a single byte to after it has
delivered SIGTERM.

Now this should have a higher chance of provoking the bug (though it
was already good enough in cursory testing!).

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.10 13-Mar-2025  riastradh execve(2), posix_spawn(2): Don't flush _all_ pending signals.

We need only flush those pending signals whose dispositions have been
reset to the default action when that action is to ignore them --
e.g., if the parent had a signal handler function for SIGCHLD or
SIGWINCH, this is reset to the default disposition, which is to
ignore the signal, so any pending SIGCHLD or SIGWINCH need to be
flushed.

And we have logic to do this already in execsigs(9), via
sigclearset(9), which clears the specified set of signals:

402 sigemptyset(&tset);
403 for (signo = 1; signo < NSIG; signo++) {
404 if (sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
405 prop = sigprop[signo];
406 if (prop & SA_IGNORE) {
407 if ((prop & SA_CONT) == 0)
408 sigaddset(&p->p_sigctx.ps_sigignore,
409 signo);
410 sigaddset(&tset, signo);
411 }
412 SIGACTION_PS(ps, signo).sa_handler = SIG_DFL;
...
420 sigclearall(p, &tset, &kq);

https://nxr.netbsd.org/xref/src/sys/kern/kern_sig.c?r=1.409#394

But back in 2003, when ksiginfo_t was introduced, before that logic
was written, we sprouted an exithook to clear _all_ the signals (and,
more importantly for the time, free the ksiginfo_t records to avoid
leaking memory) -- and we wired it up as an _exechook_ too:

+/*
+ * free all pending ksiginfo on exit
+ */
+static void
+ksiginfo_exithook(struct proc *p, void *v)
+{
+ ksiginfo_t *ksi, *hp = p->p_sigctx.ps_siginfo;
+
+ if (hp == NULL)
+ return;
+ for (;;) {
+ pool_put(&ksiginfo_pool, ksi);
+ if ((ksi = ksi->ksi_next) == hp)
+ break;
+ }
+}
...
+ exithook_establish(ksiginfo_exithook, NULL);
+ exechook_establish(ksiginfo_exithook, NULL);

https://mail-index.netbsd.org/source-changes/2003/09/14/msg133910.html

(The first iteration of ksiginfo_exithook had another bug, of course!
But it was soon fixed; that's not the issue here.)

Later, during the newlock2 branch, sigclearall got added for execsigs
to free only the ksiginfo_t records for those signals whose
disposition is being reset to a default action of ignoring the
signal:

void
execsigs(struct proc *p)
{
...
+ sigset_t tset;
...
- for (signum = 1; signum < NSIG; signum++) {
- if (sigismember(&p->p_sigctx.ps_sigcatch, signum)) {
- prop = sigprop[signum];
+ sigemptyset(&tset);
+ for (signo = 1; signo < NSIG; signo++) {
+ if (sigismember(&p->p_sigctx.ps_sigcatch, signo)) {
+ prop = sigprop[signo];
if (prop & SA_IGNORE) {
if ((prop & SA_CONT) == 0)
sigaddset(&p->p_sigctx.ps_sigignore,
- signum);
- sigdelset(&p->p_sigctx.ps_siglist, signum);
+ signo);
+ sigaddset(&tset, signo);
...
}
+ sigclearall(p, &tset);

https://mail-index.netbsd.org/source-changes/2006/10/21/msg176390.html

And the _exithook_ was removed somewhere along the way in the
newlock2 branch (in favour of simply calling sigclearall in exit1),
but the _exechook_ remained:

-static void ksiginfo_exithook(struct proc *, void *);
+static void ksiginfo_exechook(struct proc *, void *);
...
- exithook_establish(ksiginfo_exithook, NULL);
- exechook_establish(ksiginfo_exithook, NULL);
+ exechook_establish(ksiginfo_exechook, NULL);
...
/*
- * ksiginfo_exithook:
+ * ksiginfo_exechook:
*
- * Free all pending ksiginfo entries from a process on exit.
+ * Free all pending ksiginfo entries from a process on exec.
* Additionally, drain any unused ksiginfo structures in the
* system back to the pool.
+ *
+ * XXX This should not be a hook, every process has signals.
*/
static void
-ksiginfo_exithook(struct proc *p, void *v)
+ksiginfo_exechook(struct proc *p, void *v)
{

https://mail-index.netbsd.org/source-changes/2007/02/05/msg180796.html

The symptom of this mistake is that a signal delivered _during_
execve(2) may be simply discarded, even if it should be caught and
cause the process to terminate.

On the bright side, isn't it a nice feeling when you can solve
problems by commits that consist exclusively of deletions?

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.9 13-Mar-2025  riastradh execve(2), posix_spawn(2): Add test case for an embarrassing bug.

PR kern/58091: after fork/execve or posix_spawn, parent kill(child,
SIGTERM) has race condition making it unreliable
 1.8 31-May-2022  andvar branches: 1.8.4;
s/disbale/disable/ and s/enbale/enable/ in comments. also one more typo fix.
 1.7 22-Nov-2021  christos undef a couple more.
 1.6 20-Nov-2021  christos Merge common code for the chdir cases (Piyush Sachdeva)
I also deduplicated some more code
 1.5 15-Nov-2021  christos Add missing test
 1.4 07-Nov-2021  christos new tests for posix_spawn_chdir from Piyush Sachdeva
 1.3 03-Sep-2021  andvar s/existant/existent/ in comments and messages, plus few more similar fixes.
 1.2 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.1 13-Feb-2012  martin branches: 1.1.4;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file t_spawn.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.8.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7 16-Mar-2025  riastradh tests/lib/libc/gen/posix_spawn: Spruce up a bit.

- KNF
- Don't touch files outside the test working directory.
- No need to pre-clean files -- atf gives us an empty tempdir.
- Use h_macros.h to simplify a lot of checks.
- Use names for enumerated arguments, not magic numbers.
- Check some more syscalls.
- Add include guard.
 1.6 23-May-2022  andvar branches: 1.6.4;
s/controll/control/ in comments.
 1.5 07-Nov-2021  christos new tests for posix_spawn_chdir from Piyush Sachdeva
 1.4 02-May-2021  martin Add test for POSIX_SPAWN_RESETIDS flag
 1.3 21-Dec-2017  christos Fix broken test: we can't assume that the current schedule priority range
will overlap with the requested scheduler range, so get the new scheduler
range, and then try to find a different priority. If that fails (to find
a different scheduling range), give up here.
 1.2 18-Dec-2017  christos Don't use SCHED_OTHER.
 1.1 13-Feb-2012  martin branches: 1.1.4; 1.1.34;
Move posix_spawn tests to lib/libc/gen/posix_spawn - they test both libc
and kernel, but that is an implementation detail unrelated to the tests
themselfs.
Ok: releng
 1.1.34.1 25-Jun-2018  martin Additionally pull up following revision(s) (requested by maya in ticket #892):

tests/lib/libc/gen/posix_spawn/t_spawnattr.c: revision 1.2,1.3

Don't use SCHED_OTHER.

Fix broken test: we can't assume that the current schedule priority range
will overlap with the requested scheduler range, so get the new scheduler
range, and then try to find a different priority. If that fails (to find
a different scheduling range), give up here.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 13-Feb-2012  yamt file t_spawnattr.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.6.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 13-Jul-2010  jmmv Get rid of static Atffiles and let bsd.test.mk generate them on the fly.
 1.1 24-Jan-2010  joerg Add a regression test for the SHA2 family that also checks for unaligned
accesses.
 1.5 19-Jul-2025  christos crypto needs threads
 1.4 21-May-2017  riastradh branches: 1.4.22;
Remove MKCRYPTO option.

Originally, MKCRYPTO was introduced because the United States
classified cryptography as a munition and restricted its export. The
export controls were substantially relaxed fifteen years ago, and are
essentially irrelevant for software with published source code.

In the intervening time, nobody bothered to remove the option after
its motivation -- the US export restriction -- was eliminated. I'm
not aware of any other operating system that has a similar option; I
expect it is mainly out of apathy for churn that we still have it.
Today, cryptography is an essential part of modern computing -- you
can't use the internet responsibly without cryptography.

The position of the TNF board of directors is that TNF makes no
representation that MKCRYPTO=no satisfies any country's cryptography
regulations.

My personal position is that the availability of cryptography is a
basic human right; that any local laws restricting it to a privileged
few are fundamentally immoral; and that it is wrong for developers to
spend effort crippling cryptography to work around such laws.

As proposed on tech-crypto, tech-security, and tech-userlevel to no
objections:

https://mail-index.netbsd.org/tech-crypto/2017/05/06/msg000719.html
https://mail-index.netbsd.org/tech-security/2017/05/06/msg000928.html
https://mail-index.netbsd.org/tech-userlevel/2017/05/06/msg010547.html

P.S. Reviewing all the uses of MKCRYPTO in src revealed a lot of
*bad* crypto that was conditional on it, e.g. DES in telnet... That
should probably be removed too, but on the grounds that it is bad,
not on the grounds that it is (nominally) crypto.
 1.3 02-Jul-2016  christos Add an hmac test.
 1.2 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.1 24-Jan-2010  joerg Add a regression test for the SHA2 family that also checks for unaligned
accesses.
 1.4.22.1 02-Aug-2025  perseant Sync with HEAD
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.3 24-May-2023  christos no more md5 for you.
 1.2 07-Feb-2018  christos branches: 1.2.14;
md2 has been deprecated in OpenSSL-1.1
 1.1 02-Jul-2016  christos Add an hmac test.
 1.2.14.1 11-Sep-2023  martin Pull up following revision(s) (requested by riastradh in ticket #370):

tests/lib/libc/hash/t_hmac.c: revision 1.3

no more md4 for you.
 1.3 26-Sep-2012  joerg Fix year.
 1.2 03-Nov-2010  christos branches: 1.2.6; 1.2.12;
add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 24-Jan-2010  joerg Add a regression test for the SHA2 family that also checks for unaligned
accesses.
 1.2.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.6.1 30-Oct-2012  yamt sync with head
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.1 02-Jan-2011  pgoyette Atf-ify servent and protoent tests, and the remaining hash test.
 1.2 09-Apr-2015  ginsbach Split inet_addr(3) tests from t_inet_network into stand-alone t_inet_addr,
so that t_inet_network only contains tests for inet_network(3).
 1.1 13-Jan-2011  pgoyette Another test moving: lib/libc/t_inet --> lib/libc/inet/t_inet_network
 1.2 16-Jan-2022  rillig tests/libc/inet: remove stray semicolons

No binary change.
 1.1 09-Apr-2015  ginsbach Split inet_addr(3) tests from t_inet_network into stand-alone t_inet_addr,
so that t_inet_network only contains tests for inet_network(3).
 1.5 06-Oct-2022  ryo add tests for PR/57046.
 1.4 09-Apr-2015  ginsbach Split inet_addr(3) tests from t_inet_network into stand-alone t_inet_addr,
so that t_inet_network only contains tests for inet_network(3).
 1.3 15-Jul-2011  jruoho Add two more naive tests.
 1.2 15-Jul-2011  jruoho Split the test to two contextually different tests.
 1.1 13-Jan-2011  pgoyette Another test moving: lib/libc/t_inet --> lib/libc/inet/t_inet_network
 1.1 29-Apr-2022  pgoyette Add a new test for PR kern/56713 and set to expected_failure for now.
 1.2 01-May-2022  pgoyette Rename variables to be more descriptive of their local meaning rather
than referring to external usage.
 1.1 29-Apr-2022  pgoyette Add a new test for PR kern/56713 and set to expected_failure for now.
 1.9 02-Oct-2025  martin PR 59683: check for availability of null FS support via
vfs.generic.fstypes, fail if the mount fails for other reasons.
 1.8 02-Jun-2025  martin branches: 1.8.2;
Skip the tests when the nullmount fails (kernel w/o file-system NULLFS)
 1.7 05-Aug-2023  riastradh branches: 1.7.2;
t_nullmnt: Need privileges for mount.

(unless vfs.generic.usermount=1 but let's keep it simple)
 1.6 18-Jul-2022  thorpej branches: 1.6.2;
Make kqueue event status for vnodes shareable, and for stacked file systems
like nullfs, make the upper vnode share that status with the lower vnode.

And, lo, NetBSD 9.99.99.

Fixes PR kern/56713.
 1.5 04-Jun-2022  pgoyette Fix syntax error
 1.4 30-May-2022  pgoyette More factoring of common code. NFCI
 1.3 30-May-2022  pgoyette Update test so all four combinations of update_{upper, lower} x
monitor_{upper, lower}} can be verified. Currently update_upper
is expected to fail regardless of which file is being monitored.

PR kern/56713
 1.2 30-Apr-2022  pgoyette Don't put temporary files and directories into the atf_srcdir (that
might be read-only!). Instead, put them in the test's working
directory what the atf framework will automatically clean up after
the test completes.
 1.1 29-Apr-2022  pgoyette Add a new test for PR kern/56713 and set to expected_failure for now.
 1.6.2.1 06-Oct-2025  martin Pull up following revision(s) (requested by kre in ticket #1171):

tests/lib/libc/kevent_nullmnt/t_nullmnt.sh: revision 1.7-1.9

t_nullmnt: Need privileges for mount.
(unless vfs.generic.usermount=1 but let's keep it simple)

PR 59683: check for availability of null FS support via
vfs.generic.fstypes, fail if the mount fails for other reasons.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8.2.1 06-Oct-2025  martin Pull up following revision(s) (requested by kre in ticket #47):

tests/lib/libc/kevent_nullmnt/t_nullmnt.sh: revision 1.9

PR 59683: check for availability of null FS support via
vfs.generic.fstypes, fail if the mount fails for other reasons.
 1.18 15-Aug-2024  riastradh libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L

(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
 1.17 15-Aug-2024  riastradh libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
 1.16 15-Aug-2024  riastradh uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.

PR lib/52374: <uchar.h> missing
 1.15 14-Aug-2024  riastradh tests/lib/libc/locale/Makefile: Sort.

No functional change intended.

Preparation for PR lib/52374.
 1.14 27-Nov-2023  christos branches: 1.14.2;
Don't use fmtcheck for strfmon format strings. It does not work. Fix a broken
test.
 1.13 28-Jul-2019  christos branches: 1.13.10;
PR/54414: Valery Ushakov: add a test for wcsrtombs(3) doesn't update the
source argument on conversion error
 1.12 16-Aug-2017  joerg branches: 1.12.4;
Add missing strfmon_l. Noticed by Bruno Haible. Add test case.
 1.11 23-Jul-2017  perseant Add missing files from last commit:

Move Unicode <-> ku/ten mapping into the individual codec modules.
Mapping is based on existing iconv data for single-byte encodings,
and included for several, but not all, multibyte encodings.
 1.10 14-Jul-2017  perseant branches: 1.10.2;
Add a simple collation test. This test is expected to fail on HEAD since
we do not yet have a working implementation of wcscoll.
 1.9 01-Jun-2017  perseant branches: 1.9.2;
Add tests for btowc(3)/wctob(3) and enable compilation of the test for
digittoint(3).

The digittoint(3) test is skipped since we don't provide that function yet.

One of the test cases for btowc(3) is also skipped, since it tests conversion
to Unicode---whereas our wchar_t representation is locale-dependent.
 1.8 30-May-2017  perseant Add test cases for sprintf/sscanf/strto{d,l} and the is* and isw* ctype functions, for single-byte encodings
 1.7 30-May-2017  perseant Add simple test case for toupper/tolower
 1.6 28-May-2013  joerg Add mbsnrtowcs and wcsnrtombs. Approved by core.
 1.5 28-Feb-2013  christos regression tests for wide char i/o. Currently there are failures.
 1.4 21-Nov-2011  joerg branches: 1.4.6;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.3 15-Jul-2011  jruoho branches: 1.3.2;
Rename two test files to get functional scope (and avoid confusion
with ctype(3)). No functional change.
 1.2 11-Apr-2011  tron Fix build with stack smash protection enabled.
 1.1 09-Apr-2011  pgoyette atf-ify the various locale tests
 1.3.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.3.2.1 17-Apr-2012  yamt sync with head
 1.4.6.1 23-Jun-2013  tls resync from head
 1.9.2.1 29-Aug-2017  martin Pull up following revision(s) (requested by joerg in ticket #215):
tests/lib/libc/locale/t_strfmon.c: revision 1.1
tests/lib/libc/locale/Makefile: revision 1.12
lib/libc/stdlib/strfmon.c: revision 1.11
distrib/sets/lists/debug/mi: revision 1.224
include/monetary.h: revision 1.3
distrib/sets/lists/tests/mi: revision 1.761
lib/libc/stdlib/strfmon.3: revision 1.6
lib/libc/stdlib/strfmon.3: revision 1.7
Add missing strfmon_l. Noticed by Bruno Haible. Add test case.
Typo fix.
 1.10.2.2 23-Jul-2017  perseant Add Unicode copyright notice and more verbose DUCET test.
 1.10.2.1 14-Jul-2017  perseant Initial commit of a mostly-working implementation of __STDC_ISO_10646__,
with collation support using the Unicode Collation Algorithm.

The conversion from men/ku/ten form to Unicode is a gross hack at present.
Fixing this, and fleshing out the LC_COLLATE locale component, are next
on the agenda.
 1.12.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.10.1 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 23-Jul-2017  perseant Add missing files from last commit:

Move Unicode <-> ku/ten mapping into the individual codec modules.
Mapping is based on existing iconv data for single-byte encodings,
and included for several, but not all, multibyte encodings.
 1.1 14-Jul-2017  perseant branches: 1.1.2;
file ducet_test.h was initially added on branch perseant-stdc-iso10646.
 1.1.2.2 23-Jul-2017  perseant Add Unicode copyright notice and more verbose DUCET test.
 1.1.2.1 14-Jul-2017  perseant Initial commit of a mostly-working implementation of __STDC_ISO_10646__,
with collation support using the Unicode Collation Algorithm.

The conversion from men/ku/ten form to Unicode is a gross hack at present.
Fixing this, and fleshing out the LC_COLLATE locale component, are next
on the agenda.
 1.3 10-Aug-2017  perseant Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.2 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.1 01-Jun-2017  perseant branches: 1.1.2;
Add tests for btowc(3)/wctob(3) and enable compilation of the test for
digittoint(3).

The digittoint(3) test is skipped since we don't provide that function yet.

One of the test cases for btowc(3) is also skipped, since it tests conversion
to Unicode---whereas our wchar_t representation is locale-dependent.
 1.1.2.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.6 19-Aug-2024  riastradh branches: 1.6.2; 1.6.6;
c32rtomb(3): Use conversion state to handle shift sequences.

For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:

1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state

This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.

Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing

- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character

XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.5 19-Aug-2024  riastradh t_c8rtomb, t_c16rtomb: Simplify comment.

ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.4 18-Aug-2024  riastradh c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.3 18-Aug-2024  riastradh c8rtomb(3), c16rtomb(3): Fix NUL handling.

PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong
 1.2 17-Aug-2024  riastradh c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.

PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong
 1.1 15-Aug-2024  riastradh libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
 1.6.6.2 02-Aug-2025  perseant Sync with HEAD
 1.6.6.1 19-Aug-2024  perseant file t_c16rtomb.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.6.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.6.2.1 19-Aug-2024  martin file t_c16rtomb.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.1 15-Aug-2024  riastradh branches: 1.1.2; 1.1.6;
libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
 1.1.6.2 02-Aug-2025  perseant Sync with HEAD
 1.1.6.1 15-Aug-2024  perseant file t_c32rtomb.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.1.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.1.2.1 15-Aug-2024  martin file t_c32rtomb.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.7 19-Aug-2024  riastradh branches: 1.7.2; 1.7.6;
c32rtomb(3): Use conversion state to handle shift sequences.

For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:

1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state

This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.

Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing

- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character

XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.6 19-Aug-2024  riastradh t_c8rtomb, t_c16rtomb: Simplify comment.

ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.5 18-Aug-2024  riastradh c8rtomb(3): Fix digit error in shift sequence test.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.4 18-Aug-2024  riastradh c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.

PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences
 1.3 18-Aug-2024  riastradh c8rtomb(3), c16rtomb(3): Fix NUL handling.

PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong
 1.2 17-Aug-2024  riastradh c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.

PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong
 1.1 15-Aug-2024  riastradh libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L

(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
 1.7.6.2 02-Aug-2025  perseant Sync with HEAD
 1.7.6.1 19-Aug-2024  perseant file t_c8rtomb.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.7.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.7.2.1 19-Aug-2024  martin file t_c8rtomb.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.2 15-Jul-2011  jruoho Rename two test files to get functional scope (and avoid confusion
with ctype(3)). No functional change.
 1.1 09-Apr-2011  pgoyette atf-ify the various locale tests
 1.2 15-Jul-2011  jruoho Rename two test files to get functional scope (and avoid confusion
with ctype(3)). No functional change.
 1.1 09-Apr-2011  pgoyette atf-ify the various locale tests
 1.3 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.2 01-Jun-2017  perseant Add tests for btowc(3)/wctob(3) and enable compilation of the test for
digittoint(3).

The digittoint(3) test is skipped since we don't provide that function yet.

One of the test cases for btowc(3) is also skipped, since it tests conversion
to Unicode---whereas our wchar_t representation is locale-dependent.
 1.1 30-May-2017  perseant Add test cases for sprintf/sscanf/strto{d,l} and the is* and isw* ctype functions, for single-byte encodings
 1.2 23-Jul-2017  perseant Add missing files from last commit:

Move Unicode <-> ku/ten mapping into the individual codec modules.
Mapping is based on existing iconv data for single-byte encodings,
and included for several, but not all, multibyte encodings.
 1.1 14-Jul-2017  perseant branches: 1.1.2;
file t_ducet.c was initially added on branch perseant-stdc-iso10646.
 1.1.2.2 23-Jul-2017  perseant Add Unicode copyright notice and more verbose DUCET test.
 1.1.2.1 14-Jul-2017  perseant Initial commit of a mostly-working implementation of __STDC_ISO_10646__,
with collation support using the Unicode Collation Algorithm.

The conversion from men/ku/ten form to Unicode is a gross hack at present.
Fixing this, and fleshing out the LC_COLLATE locale component, are next
on the agenda.
 1.5 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.4 21-Jan-2014  yamt branches: 1.4.4; 1.4.20;
fix comment typos pointed out by uebayasi
 1.3 20-Jan-2014  yamt - fix funopen usage
- some more checks
- remove a bogus test case (bad_eucJP_getwc) PR/47660 (Julio Merino)
- add XXX comments
 1.2 17-Mar-2013  jmmv branches: 1.2.4;
Mark two routinely-broken tests as expected failures referencing PR lib/47660.
 1.1 28-Feb-2013  christos regression tests for wide char i/o. Currently there are failures.
 1.2.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.4.2 23-Jun-2013  tls resync from head
 1.2.4.1 17-Mar-2013  tls file t_io.c was added on branch tls-maxphys on 2013-06-23 06:28:56 +0000
 1.4.20.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.4.4.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.4.4.1 21-Jan-2014  yamt file t_io.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.3 20-Aug-2024  riastradh branches: 1.3.2; 1.3.6;
mbrtoc32(3): Use conversion state to handle shift sequences.

PR lib/58618: mbrtocN(3) fails to keep shift state
 1.2 19-Aug-2024  riastradh mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.

This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.

PR lib/58618: mbrtocN(3) fails to keep shift state
 1.1 15-Aug-2024  riastradh libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
 1.3.6.2 02-Aug-2025  perseant Sync with HEAD
 1.3.6.1 20-Aug-2024  perseant file t_mbrtoc16.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.3.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.3.2.1 20-Aug-2024  martin file t_mbrtoc16.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.1 15-Aug-2024  riastradh branches: 1.1.2; 1.1.6;
libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
 1.1.6.2 02-Aug-2025  perseant Sync with HEAD
 1.1.6.1 15-Aug-2024  perseant file t_mbrtoc32.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.1.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.1.2.1 15-Aug-2024  martin file t_mbrtoc32.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.3 20-Aug-2024  riastradh branches: 1.3.2; 1.3.6;
mbrtoc32(3): Use conversion state to handle shift sequences.

PR lib/58618: mbrtocN(3) fails to keep shift state
 1.2 19-Aug-2024  riastradh mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.

This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.

PR lib/58618: mbrtocN(3) fails to keep shift state
 1.1 15-Aug-2024  riastradh libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L

(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
 1.3.6.2 02-Aug-2025  perseant Sync with HEAD
 1.3.6.1 20-Aug-2024  perseant file t_mbrtoc8.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.3.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.3.2.1 20-Aug-2024  martin file t_mbrtoc8.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.2 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.1 15-Jul-2011  jruoho branches: 1.1.34;
Rename two test files to get functional scope (and avoid confusion
with ctype(3)). No functional change.
 1.1.34.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.2 06-May-2014  yamt branches: 1.2.2;
include string.h for memset
 1.1 28-May-2013  joerg branches: 1.1.2; 1.1.6;
Add mbsnrtowcs and wcsnrtombs. Approved by core.
 1.1.6.1 10-Aug-2014  tls Rebase.
 1.1.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.2 23-Jun-2013  tls resync from head
 1.1.2.1 28-May-2013  tls file t_mbsnrtowcs.c was added on branch tls-maxphys on 2013-06-23 06:28:56 +0000
 1.2.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.2.2.1 06-May-2014  yamt file t_mbsnrtowcs.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.3 21-Dec-2022  wiz adapt mbstowcs_basic test for unicode table update

reformat so it's easier to find which result data belongs to which input
 1.2 12-Jul-2017  perseant branches: 1.2.16;
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.1 15-Jul-2011  jruoho branches: 1.1.34;
Rename two test files to get functional scope (and avoid confusion
with ctype(3)). No functional change.
 1.1.34.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.2.16.1 11-Sep-2023  martin Pull up following revision(s) (requested by wiz in ticket #368):

share/locale/ctype/en_US.UTF-8.src: revision 1.10
share/locale/ctype/en_US.UTF-8.src: revision 1.8
share/locale/ctype/en_US.UTF-8.src: revision 1.9
share/locale/ctype/gen_ctype_utf8.pl: revision 1.1
share/locale/ctype/gen_ctype_utf8.pl: revision 1.2
tests/lib/libc/locale/t_mbstowcs.c: revision 1.3

Update unicode tables.

This version of the file, and the generator script, come from
OpenBSD. The script was written by Andrew Fresh.
The file covers the encodings from Unicode 13.0.0, based on the files
distributed with perl 5.32.1.

Add NetBSD RCS Id header instead of OpenBSD one.

Update Unicode tables.

These tables are for Unicode 14.0.0 using the data provided with
perl 5.36.0.

Update Unicode tables to 15.0.0.
This is based on the tables provided by perl 5.37.7.

adapt mbstowcs_basic test for unicode table update
reformat so it's easier to find which result data belongs to which input
 1.3 30-Jun-2020  jruoho After a comedy of errors, move t_mbtowc to its final resting place.
 1.2 25-May-2017  perseant Add a member to the test data structure that indicates whether the given
encoding is state-dependent, and test the results of wctomb(NULL, '\0') and
mbtowc(NULL, NULL, 0) against this instead of against each other.
 1.1 09-Apr-2011  pgoyette atf-ify the various locale tests
 1.8 02-Aug-2021  andvar s/diferent/different/
 1.7 01-Dec-2017  kre Since the C standard allows for intermediate floating results to contain
more precision bits than the data type expects, but (kind of obviously)
does not allow such values to be stored in memory, expecting the value
returned from strtod() (an intermediate result) to be identical (that is,
equal) to a stored value is incorrect.

So instead go back to checking that the two numbers are very very close.
See comments added to the test for more explanation.
 1.6 28-Nov-2017  kre Revert 1.4 (perhaps temporarily) and add even more diagnostics to those
added in 1.3 to see if it is possible to determine why the strict equality
test fails on i386, yet succeeds elsewhere.
 1.5 24-Nov-2017  kre When comparing doubles (any floating point values) which have been
computed using different methods, don't expect to achieve identical
results (here, one constant is perhaps converted to binary from a string by
a cross compiler, the other is converted at run time). Allow them to
have a small difference (for now, small is < 1e-7 - the constant is ~ 1e5,
so this is 12 orders of magnitude less) before failing (and include the
actual difference in the error message if it does fail.)
 1.4 23-Nov-2017  kre Add some diagnostics to the strto test, so I can see why this
fails on i386 (on qemu) - will probably keep them when done.
 1.3 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.2 07-Jun-2017  perseant Change t_sprintf to an expected failure, since we don't respect the empty
thousands separator of the C/POSIX locale (PR standards/52282).
 1.1 30-May-2017  perseant branches: 1.1.2;
Add test cases for sprintf/sscanf/strto{d,l} and the is* and isw* ctype functions, for single-byte encodings
 1.1.2.3 15-Mar-2018  bouyer Pull up following revision(s) (requested by martin in ticket #631):
tests/lib/libc/locale/t_sprintf.c: revision 1.4
tests/lib/libc/locale/t_sprintf.c: revision 1.5
tests/lib/libc/locale/t_sprintf.c: revision 1.6
tests/lib/libc/locale/t_sprintf.c: revision 1.7
Add some diagnostics to the strto test, so I can see why this
fails on i386 (on qemu) - will probably keep them when done.
When comparing doubles (any floating point values) which have been
computed using different methods, don't expect to achieve identical
results (here, one constant is perhaps converted to binary from a string by
a cross compiler, the other is converted at run time). Allow them to
have a small difference (for now, small is < 1e-7 - the constant is ~ 1e5,
so this is 12 orders of magnitude less) before failing (and include the
actual difference in the error message if it does fail.)
Revert 1.4 (perhaps temporarily) and add even more diagnostics to those
added in 1.3 to see if it is possible to determine why the strict equality
test fails on i386, yet succeeds elsewhere.
Since the C standard allows for intermediate floating results to contain
more precision bits than the data type expects, but (kind of obviously)
does not allow such values to be stored in memory, expecting the value
returned from strtod() (an intermediate result) to be identical (that is,
equal) to a stored value is incorrect.
So instead go back to checking that the two numbers are very very close.
See comments added to the test for more explanation.
 1.1.2.2 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.1.2.1 14-Mar-2018  bouyer Pull up following revision(s) (requested by martin in ticket #630):
lib/libc/stdio/vfwprintf.c: revision 1.35
lib/libc/stdio/vfwprintf.c: revision 1.36
tests/lib/libc/locale/t_sprintf.c: revision 1.2
Change t_sprintf to an expected failure, since we don't respect the empty
thousands separator of the C/POSIX locale (PR standards/52282).
Do not use thousands grouping when none is specified by the locale.
Fixes PR standards/52282.
A more correct fix for PR standards/52282.
 1.6 27-Nov-2023  christos Don't use fmtcheck for strfmon format strings. It does not work. Fix a broken
test.
 1.5 14-Oct-2023  christos PR/57633: Jose Luis Duran: Add strfmon tests from FreeBSD
 1.4 28-Sep-2023  christos Add testing for pad resetting (Jose Luis Duran)
 1.3 02-Aug-2021  andvar s/diferent/different/
 1.2 07-Dec-2017  kre Update this test to expect the output that is supposed to be produced
by strfmon() rather than the output the old buggy implementation used
to produce.
 1.1 16-Aug-2017  joerg branches: 1.1.2;
Add missing strfmon_l. Noticed by Bruno Haible. Add test case.
 1.1.2.2 29-Aug-2017  martin Pull up following revision(s) (requested by joerg in ticket #215):
tests/lib/libc/locale/t_strfmon.c: revision 1.1
tests/lib/libc/locale/Makefile: revision 1.12
lib/libc/stdlib/strfmon.c: revision 1.11
distrib/sets/lists/debug/mi: revision 1.224
include/monetary.h: revision 1.3
distrib/sets/lists/tests/mi: revision 1.761
lib/libc/stdlib/strfmon.3: revision 1.6
lib/libc/stdlib/strfmon.3: revision 1.7
Add missing strfmon_l. Noticed by Bruno Haible. Add test case.
Typo fix.
 1.1.2.1 16-Aug-2017  martin file t_strfmon.c was added on branch netbsd-8 on 2017-08-29 11:51:50 +0000
 1.2 02-Aug-2021  andvar s/diferent/different/
 1.1 30-May-2017  perseant branches: 1.1.4;
Add simple test case for toupper/tolower
 1.1.4.1 23-Jan-2018  perseant Make the tests pass once more when __STDC_ISO_10646__ is not defined.
 1.3 14-Oct-2024  rillig branches: 1.3.2; 1.3.6;
tests/t_uchar: fix copy-and-paste typo
 1.2 13-Oct-2024  riastradh tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.

PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h

PR lib/52374: <uchar.h> missing
 1.1 15-Aug-2024  riastradh uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.

PR lib/52374: <uchar.h> missing
 1.3.6.2 02-Aug-2025  perseant Sync with HEAD
 1.3.6.1 14-Oct-2024  perseant file t_uchar.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.3.2.2 14-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #976):

lib/libc/locale/c32rtomb.3: revision 1.10
lib/libc/locale/c32rtomb.3: revision 1.9
lib/libc/locale/c32rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc32.c: revision 1.1
distrib/sets/lists/base/shl.mi: revision 1.988
lib/libc/include/namespace.h: revision 1.204
lib/libc/include/namespace.h: revision 1.205
lib/libc/locale/mbrtoc16.3: revision 1.1
lib/libc/locale/mbrtoc16.c: revision 1.1
lib/libc/locale/mbrtoc16.3: revision 1.2
lib/libc/locale/mbrtoc16.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.3
lib/libc/locale/mbrtoc16.c: revision 1.3
lib/libc/locale/mbrtoc32.3: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.1
tests/lib/libc/locale/t_c16rtomb.c: revision 1.1
lib/libc/locale/mbrtoc32.c: revision 1.2
lib/libc/locale/mbrtoc16.3: revision 1.4
lib/libc/locale/mbrtoc16.c: revision 1.4
lib/libc/locale/mbrtoc32.3: revision 1.2
tests/lib/libc/locale/t_c16rtomb.c: revision 1.2
lib/libc/locale/mbrtoc32.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.5
lib/libc/locale/mbrtoc16.c: revision 1.5
lib/libc/locale/mbrtoc32.3: revision 1.3
tests/lib/libc/locale/t_c16rtomb.c: revision 1.3
lib/libc/locale/mbrtoc32.c: revision 1.4
lib/libc/locale/mbrtoc16.3: revision 1.6
lib/libc/locale/mbrtoc16.c: revision 1.6
lib/libc/locale/mbrtoc32.3: revision 1.4
tests/lib/libc/locale/t_c16rtomb.c: revision 1.4
lib/libc/locale/mbrtoc32.c: revision 1.5
lib/libc/locale/mbrtoc16.3: revision 1.7
lib/libc/locale/mbrtoc16.c: revision 1.7
lib/libc/locale/mbrtoc32.3: revision 1.5
tests/lib/libc/locale/t_c16rtomb.c: revision 1.5
lib/libc/locale/mbrtoc32.c: revision 1.6
lib/libc/locale/mbrtoc16.3: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.6
tests/lib/libc/locale/t_c16rtomb.c: revision 1.6
lib/libc/locale/mbrtoc32.c: revision 1.7
lib/libc/locale/mbrtoc16.3: revision 1.9
lib/libc/locale/mbrtoc32.3: revision 1.7
lib/libc/locale/mbrtoc32.c: revision 1.8
lib/libc/locale/mbrtoc32.3: revision 1.8
lib/libc/locale/mbrtoc32.c: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2468
lib/libc/locale/mbrtoc32.3: revision 1.9
distrib/sets/lists/comp/mi: revision 1.2469
lib/libc/locale/c32rtomb.h: revision 1.1
lib/libc/locale/c32rtomb.h: revision 1.2
include/Makefile: revision 1.147
share/man/man3/uchar.3: revision 1.1
share/man/man3/uchar.3: revision 1.2
tests/lib/libc/locale/t_c32rtomb.c: revision 1.1
distrib/sets/lists/comp/mi: revision 1.2470
lib/libc/locale/c16rtomb.3: revision 1.1
lib/libc/locale/c16rtomb.c: revision 1.1
lib/libc/locale/c16rtomb.3: revision 1.2
lib/libc/locale/c16rtomb.c: revision 1.2
lib/libc/locale/c16rtomb.3: revision 1.3
lib/libc/locale/c16rtomb.c: revision 1.3
lib/libc/locale/c16rtomb.3: revision 1.4
lib/libc/locale/c16rtomb.c: revision 1.4
lib/libc/locale/c16rtomb.3: revision 1.5
lib/libc/locale/c16rtomb.c: revision 1.5
lib/libc/locale/c16rtomb.3: revision 1.6
lib/libc/locale/c16rtomb.c: revision 1.6
lib/libc/locale/c16rtomb.3: revision 1.7
lib/libc/locale/c16rtomb.c: revision 1.7
lib/libc/locale/c16rtomb.3: revision 1.8
lib/libc/locale/c16rtomb.3: revision 1.9
distrib/sets/lists/tests/mi: revision 1.1330
distrib/sets/lists/tests/mi: revision 1.1331
distrib/sets/lists/tests/mi: revision 1.1332
tests/lib/libc/locale/t_uchar.c: revision 1.1
tests/lib/libc/locale/t_uchar.c: revision 1.2
tests/lib/libc/locale/t_uchar.c: revision 1.3
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc16.c: revision 1.3
include/uchar.h: revision 1.1
include/uchar.h: revision 1.2
include/uchar.h: revision 1.3
include/uchar.h: revision 1.4
include/uchar.h: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.1
include/uchar.h: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.2
tests/lib/libc/locale/t_c8rtomb.c: revision 1.3
tests/lib/libc/locale/t_c8rtomb.c: revision 1.4
share/man/man3/Makefile: revision 1.93
tests/lib/libc/locale/t_c8rtomb.c: revision 1.5
tests/lib/libc/locale/t_c8rtomb.c: revision 1.6
tests/lib/libc/locale/t_c8rtomb.c: revision 1.7
lib/libc/shlib_version: revision 1.297
lib/libc/locale/c16rtomb.3: revision 1.10
lib/libc/locale/c16rtomb.3: revision 1.11
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.1
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.2
tests/lib/libc/locale/t_mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc16.3: revision 1.10
tests/lib/libc/locale/Makefile: revision 1.15
tests/lib/libc/locale/Makefile: revision 1.16
tests/lib/libc/locale/Makefile: revision 1.17
tests/lib/libc/locale/Makefile: revision 1.18
distrib/sets/lists/debug/mi: revision 1.442
distrib/sets/lists/debug/mi: revision 1.443
distrib/sets/lists/debug/mi: revision 1.444
lib/libc/locale/c8rtomb.3: revision 1.1
lib/libc/locale/c8rtomb.c: revision 1.1
lib/libc/locale/c8rtomb.3: revision 1.2
lib/libc/locale/c8rtomb.c: revision 1.2
lib/libc/locale/c8rtomb.3: revision 1.3
lib/libc/locale/c8rtomb.c: revision 1.3
lib/libc/locale/c8rtomb.3: revision 1.4
lib/libc/locale/c8rtomb.c: revision 1.4
lib/libc/locale/c8rtomb.3: revision 1.5
lib/libc/locale/c8rtomb.c: revision 1.5
lib/libc/locale/c8rtomb.3: revision 1.6
lib/libc/locale/c8rtomb.c: revision 1.6
lib/libc/locale/c8rtomb.3: revision 1.7
lib/libc/locale/c8rtomb.3: revision 1.8
lib/libc/locale/c8rtomb.3: revision 1.9
lib/libc/locale/mbrtoc32.h: revision 1.1
lib/libc/locale/mbrtoc32.h: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.1
lib/libc/locale/mbrtoc8.3: revision 1.1
lib/libc/locale/mbrtoc8.c: revision 1.2
lib/libc/locale/mbrtoc8.3: revision 1.2
lib/libc/locale/mbrtoc8.c: revision 1.3
lib/libc/locale/mbrtoc8.3: revision 1.3
lib/libc/locale/mbrtoc8.c: revision 1.4
lib/libc/locale/mbrtoc8.3: revision 1.4
lib/libc/locale/Makefile.inc: revision 1.66
lib/libc/locale/mbrtoc8.c: revision 1.5
lib/libc/locale/mbrtoc8.3: revision 1.5
lib/libc/locale/Makefile.inc: revision 1.67
lib/libc/locale/mbrtoc8.c: revision 1.6
lib/libc/locale/mbrtoc8.3: revision 1.6
lib/libc/locale/mbrtoc8.c: revision 1.7
lib/libc/locale/mbrtoc8.3: revision 1.7
lib/libc/locale/mbrtoc8.c: revision 1.8
lib/libc/locale/c32rtomb.3: revision 1.1
lib/libc/locale/c32rtomb.c: revision 1.1
lib/libc/locale/c32rtomb.3: revision 1.2
lib/libc/locale/c32rtomb.c: revision 1.2
lib/libc/locale/c32rtomb.3: revision 1.3
lib/libc/locale/c32rtomb.c: revision 1.3
lib/libc/locale/c32rtomb.3: revision 1.4
lib/libc/locale/c32rtomb.c: revision 1.4
lib/libc/locale/c32rtomb.3: revision 1.5
lib/libc/locale/c32rtomb.c: revision 1.5
lib/libc/locale/c32rtomb.3: revision 1.6
lib/libc/locale/c32rtomb.c: revision 1.6
lib/libc/locale/c32rtomb.3: revision 1.7
lib/libc/locale/c32rtomb.3: revision 1.8

(all via patch)


tests/lib/libc/locale/Makefile: Sort.
No functional change intended.
Preparation for PR lib/52374.

uchar.h: New header file for C11 (and C++11) compliance.

Implementation of the new functions mbrtoc16, c16rtomb, mbrtoc32, and
c32rtomb to come later. Updates for C23 to come later.
PR lib/52374: <uchar.h> missing

libc: New C11 functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb.

The mbrtoc16/32 functions read mulitbyte strings according to the
current locale into UTF-16/32 code unit sequences; the c16/32rtomb
functions write UTF-16/32 code unit sequences into multibyte strings
according to the current locale. The `r' means restartable: they
work incrementally and pick up where they left off.

NOTE: This bumps the libc minor version, since it adds new symbols.

PR lib/52374: <uchar.h> missing
mbrtoc16(3), mbrtoc32(3): Fix \n in man page examples.
Need to write \en to pacify roff.
PR lib/52374: <uchar.h> missing

c16rtomb(3), c32rtomb(3): Fix more \n in man pages.
Also, tighten an assertion: we left room for a NUL byte at the end.
PR lib/52374: <uchar.h> missing

libc: Use the more idiomatic alignof from stdalign.h.
No functional change intended.
PR lib/52374: <uchar.h> missing

mbrtoc16(3): Simplify surrogate state test.

Turn the finer-grained test into an assertion.
No semantic change intended: we are supposed to control this state,
and we always arrange it this way. (But in principle this could
change the behaviour of buggy programs that violate the mbstate_t
abstraction.)
PR lib/52374: <uchar.h> missing

libc: New functions c8rtomb(3) and mbrtoc8(3).

New in C23, for converting from UTF-8 to locale-dependent multibyte
sequences (c8rtomb) or vice versa (mbrtoc8), along with the new type
char8_t.

Conditional on either:
- _NETBSD_SOURCE
- _ISOC23_SOURCE
- __STDC_VERSION__ >= 202311L
(Riding the libc minor bump from this morning for the UTF-16/UTF-32
versions from C11.)

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
libc: c32rtomb and mbrtoc32 are used internally, so weak-alias them.
PR lib/52374: <uchar.h> missing
c8rtomb(3), mbrtoc8(3): Use namespace.h to get private aliases.

This way applications defining the symbols c32rtomb or mbrtoc32 won't
clobber our private definitions, which are slightly more constrained
about their use of mbstate_t than is obvious from the interface
contract.

PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
mbrtoc16(3), mbrtoc32(3): brush up markup

Split long .Fn lines into Fo/Fa/Fc. Dont indent the list of return
values. Don't use artisanal -width.

Untabify code examples - indented literal displays don't have correct
tab stops consistent with tab stops in the fixed font code, so the
lines end up misaligned in the PostScript output.

c16rtomb(3), c32rtomb(3): brush up markup

mbrtoc16(3), mbrtoc32(3): Simplify return value language.
Also expand BMP only once.
PR lib/52374: <uchar.h> missing

mbrtoc16(3), mbrtoc32(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc32(3): Clarify control flow.
No need for another goto here; let's keep it clearly structured with
a single `out' label.
No functional change intended.
PR lib/52374: <uchar.h> missing

c8rtomb(3), mbrtoc8(3): brush up markup

mbrtoc8(3): Simplify return value language.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Specify what happens if ps is null.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Specify what happens when ps is null.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): No state overlap with mbrtoc8 or c8rtomb.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Work on deturgidifying prose.
Still maybe not great but at least there's less jargon in most of the
text, without really losing any content.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Work on deturgidifying prose.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3), mbrtoc32(3): Restore word accidentally removed.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Restore word accidentally removed.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c8rtomb(3): Fix possible error descriptions.
The argument c8 can't be a surrogate code point itself (they're in
the range [0xd800,0xdfff], beyond 8-bit values), but the bits of a
surrogate code point could be forced into the UTF-8 format, which is
also invalid.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

c16rtomb(3), c32rtomb(3): Attempt a deturgidification pass.
Limit the jargon around surrogates.
PR lib/52374: <uchar.h> missing

c8rtomb(3): Clarify prose and fix example in caveat.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb
c16rtomb(3), c32rtomb(3), mbrtoc16(3), mbrtoc32(3): xref c8 versions.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc16(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR lib/52374: <uchar.h> missing

mbrtoc8(3): Clarify how many bytes are consumed in special cases.
Fix overlap in RETURN VALUES section.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

pass lint, XXX see lint bug.

libc: Add _l variants of the cNrtomb and mbrtocN functions.
These accept an explicit locale parameter, rather than using the
current locale.
Visible under _NETBSD_SOURCE, not exposed otherwise.
NOTE: This adds libc symbols. Riding the libc minor bump for the
non-_l variants of these from two days ago -- hope that's not pushing
it too far.
PR lib/58613: c*rtomb, mbrtoc* should have locale-parametric _l
variants

c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3): Fix NUL handling.
PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
wrong

c8rtomb(3), c16rtomb(3), c32rtomb(3): Test stateful shift sequences.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Fix digit error in shift sequence test.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3): Nix __CTASSERT after case label.
I put this in to make it (machine-verifiably) clear that zeroing the
state is the same as returning to the initial conversion state, as
the standard requires, but this is causing build trouble (and will
likely cause more trouble if pulled up) because some definitions of
__CTASSERT make a declaration which is forbidden after a label, so
let's remove it.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8(3): Fix pasto in comment at top.
No functional change intended.
PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb

mbrtoc8: remove lint-specific workarounds
No binary change.

mbrtoc8: fix comments

mbrtoc16, mbrtoc32: fix comments, remove lint-specific workarounds
No binary change.
t_c8rtomb, t_c16rtomb: Simplify comment.
ESC $ B is technically rather the JIS X 0208-1983 shift sequence, but
since I don't see any way to provoke the JIS X 0208-1978 shift
sequence to come flying out of this conversion (ESC $ @), and I'm not
sure there's any difference in the interpretation, let's just say JIS
X 0208.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c32rtomb(3): Use conversion state to handle shift sequences.
For conversion of Unicode scalar values to coding systems requiring
shift sequences, such as ISO-2022-JP, _citrus_iconv_convert will
always produce:
1. a shift sequence from the initial state to some nondefault state,
like from US-ASCII to JIS X 0208
2. the encoding of the desired characater
3. a shift sequence restoring the initial state
This is unnecessary if the output is already in the state needed to
encoded the desired character. For example, this method produces
seven bytes to encode each YEN SIGN in ISO-2022-JP -- and fourteen,
to encode two consecutive ones -- even though the shift sequence is
only three bytes long and once shifted YEN SIGN takes only one byte.
Instead, convert the Unicode scalar value to a locale-dependent wide
character and encode that, by composing
- _citrus_iconv_convert
=> gives us a multibyte encoding of the character from the initial
state (and restoring the initial state afterward)
- mbrtowc with initial conversion state
=> gives us the single wide character representation
XXX If combining characters are possible here, this may fail.
- wcrtomb with caller's conversion tsate
=> gives us a state-dependent multibyte encoding of the character
XXX Is there a cheaper way to convert from Unicode scalar value to
locale-dependent wide character? It is not obvious to me from the
largely undocumented Citrus machinery, but it would obviously be
better than this somewhat circuitous Rube Goldberg contraption of
chained multibyte APIs.
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

mbrtoc8(3), mbrtoc16(3): Test consuming shift sequences with state.
This has the side effect of testing mbrtoc32(3) because they are both
defined in terms of it.
PR lib/58618: mbrtocN(3) fails to keep shift state

c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example.
This way it avoids variable-length arrays, by always allocating the
maximum space that could be occupied by MB_CUR_MAX.

mbrtoc32(3): Use conversion state to handle shift sequences.
PR lib/58618: mbrtocN(3) fails to keep shift state

mbrtoc32(3): Fix name and type of mbrtowc_l return value.
This was from `int mbtowc_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to mbrtowc_l. Caught by
lint.
`mb_len' avoids (harmless) clash with standard C function mblen(3).
PR lib/58618: mbrtocN(3) fails to keep shift state

c32rtomb(3): Fix type of wcrtomb_l return value.
This was from `int wctomb_l(...)' in an earlier draft and I didn't
update it to size_t when I changed the draft to wcrtomb_l. Caught by
lint.
`wc_len' mirrors `mb_len' in the complementary code in mbrtoc32(3) to
avoid clash with standard C function mblen(3).
PR lib/58612: c8rtomb/c16rtomb/c32rtomb yield suboptimal shift
sequences

c8rtomb(3), c16rtomb(3), c32rtomb(3): Attempt to simplify language.

c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case.
This ignores c8/c16/c32, produces no output anywhere, and just resets
ps to the initial conversion state.
Also just use 0 in the example, not '\0' or L'\0'. This works for
C11, which prefers '\0' and L'\0', for and C23, which introduced the
new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32).
c16rtomb, c32rtomb, mbrtoc8: fix page numbers in comments
mbrtoc8(3), mbrtoc16(3), mbrtoc32(3): Say 0 for zero code unit.
Rather than deal with differences between C11 and C23 in notation,
'\0' vs L'\0' vs u8'\0' vs u'\0' vs U'\0'.
uchar.h: Include <sys/featuretest.h> before testing _*_SOURCE.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

uchar.h: Need <sys/cdefs.h> for __restrict.
PR lib/52374: <uchar.h> missing

uchar.h: Simplify __cpp_char8_t and __cplusplus conditionals.
No functional change intended.
PR lib/52374: <uchar.h> missing

tests/lib/libc/locale/t_uchar: Test for char8_t, mbrtoc8, c8rtomb.
PR lib/58752: various header files test _*_SOURCE macros but don't
include sys/featuretest.h
PR lib/52374: <uchar.h> missing

tests/t_uchar: fix copy-and-paste typo
 1.3.2.1 14-Oct-2024  martin file t_uchar.c was added on branch netbsd-10 on 2024-10-14 17:20:19 +0000
 1.1 14-Jul-2017  perseant branches: 1.1.2;
Add a simple collation test. This test is expected to fail on HEAD since
we do not yet have a working implementation of wcscoll.
 1.1.2.1 14-Jul-2017  perseant Initial commit of a mostly-working implementation of __STDC_ISO_10646__,
with collation support using the Unicode Collation Algorithm.

The conversion from men/ku/ten form to Unicode is a gross hack at present.
Fixing this, and fleshing out the LC_COLLATE locale component, are next
on the agenda.
 1.1 21-Nov-2011  joerg branches: 1.1.4;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 21-Nov-2011  yamt file t_wcscspn.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.1 21-Nov-2011  joerg branches: 1.1.4;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 21-Nov-2011  yamt file t_wcspbrk.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.1 28-Jul-2019  christos branches: 1.1.6;
PR/54414: Valery Ushakov: add a test for wcsrtombs(3) doesn't update the
source argument on conversion error
 1.1.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.6.1 28-Jul-2019  martin file t_wcsrtombs.c was added on branch phil-wifi on 2020-04-13 08:05:26 +0000
 1.1 21-Nov-2011  joerg branches: 1.1.4;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 21-Nov-2011  yamt file t_wcsspn.c was added on branch yamt-pagecache on 2012-04-17 00:09:11 +0000
 1.5 14-Jul-2017  joerg VAX doesn't have the test cases, so stub the body as well.
 1.4 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.3 01-Oct-2011  christos branches: 1.3.34;
Undo previous, Checking for vax is more appropriate.
 1.2 01-Oct-2011  christos no more ifdef vax
 1.1 09-Apr-2011  pgoyette atf-ify the various locale tests
 1.3.34.2 18-Mar-2018  martin Additionally pull up r1.5 for ticket #608:

VAX doesn't have the test cases, so stub the body as well.
 1.3.34.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.5 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.4 25-May-2017  perseant branches: 1.4.2;
Add a member to the test data structure that indicates whether the given
encoding is state-dependent, and test the results of wctomb(NULL, '\0') and
mbtowc(NULL, NULL, 0) against this instead of against each other.
 1.3 25-Mar-2013  gson Don't size an array using MB_CUR_MAX while one locale is in effect and
then use it with another locale having a larger MB_CUR_MAX. This
should fix the t_wctomb:wcrtomb_state test failures seen on i386.
 1.2 11-Jun-2011  christos branches: 1.2.2; 1.2.8;
Turn warns on for all tests and fix all the bugs.
 1.1 09-Apr-2011  pgoyette branches: 1.1.2;
atf-ify the various locale tests
 1.1.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.8.1 23-Jun-2013  tls resync from head
 1.2.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.4.2.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.3 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.2 12-Jul-2017  perseant Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.
 1.1 30-May-2017  perseant branches: 1.1.2;
Add test cases for sprintf/sscanf/strto{d,l} and the is* and isw* ctype functions, for single-byte encodings
 1.1.2.1 15-Mar-2018  martin Pull up following revision(s) (requested by maya in ticket #608):
tests/lib/libc/locale/t_sprintf.c: revision 1.3
tests/lib/libc/locale/t_wctomb.c: revision 1.5
tests/lib/libc/locale/t_io.c: revision 1.5
tests/lib/libc/locale/t_wcstod.c: revision 1.4
tests/lib/libc/locale/t_mbstowcs.c: revision 1.2
tests/lib/libc/locale/t_wctype.c: revision 1.2
tests/lib/libc/locale/t_mbrtowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.2
tests/lib/libc/locale/t_btowc.c: revision 1.3
Add ISO10646 versions of these tests, conditional on __STDC_ISO_10646__ .
Also make the tests a bit more verbose, to aid debugging when they fail.

Separate the C/POSIX locale test from the rest; make it more thorough
and more correct. This fixes a problem reported by martin@ when the
test is compiled with -funsigned-char.
 1.1 08-Apr-2022  riastradh membar_ops(3): Add some automatic tests.

These tests run two threads for five seconds each to try to trigger
races in the event of broken memory barriers. They run only on
machines with at least two CPUs; on uniprocessor systems there's no
point -- the membars can correctly just be (instruction barrier)
no-ops.
 1.3 10-Apr-2022  riastradh membar_ops(3): Simplify alarm handling in membar tests.
 1.2 09-Apr-2022  riastradh Introduce membar_acquire/release. Deprecate membar_enter/exit.

The names membar_enter/exit were unclear, and the documentation of
membar_enter has disagreed with the implementations on sparc,
powerpc, and even x86(!) for the entire time it has been in NetBSD.

The terms `acquire' and `release' are ubiquitous in the literature
today, and have been adopted in the C and C++ standards to mean
load-before-load/store and load/store-before-store, respectively,
which are exactly the orderings required by acquiring and releasing a
mutex, as well as other useful applications like decrementing a
reference count and then freeing the underlying object if it went to
zero.

Originally I proposed changing one word in the documentation for
membar_enter to make it load-before-load/store instead of
store-before-load/store, i.e., to make it an acquire barrier. I
proposed this on the grounds that

(a) all implementations guarantee load-before-load/store,
(b) some implementations fail to guarantee store-before-load/store,
and
(c) all uses in-tree assume load-before-load/store.

I verified parts (a) and (b) (except, for (a), powerpc didn't even
guarantee load-before-load/store -- isync isn't necessarily enough;
need lwsync in general -- but it _almost_ did, and it certainly didn't
guarantee store-before-load/store).

Part (c) might not be correct, however: under the mistaken assumption
that atomic-r/m/w then membar-w/rw is equivalent to atomic-r/m/w then
membar-r/rw, I only audited the cases of membar_enter that _aren't_
immediately after an atomic-r/m/w. All of those cases assume
load-before-load/store. But my assumption was wrong -- there are
cases of atomic-r/m/w then membar-w/rw that would be broken by
changing to atomic-r/m/w then membar-r/rw:

https://mail-index.netbsd.org/tech-kern/2022/03/29/msg028044.html

Furthermore, the name membar_enter has been adopted in other places
like OpenBSD where it actually does follow the documentation and
guarantee store-before-load/store, even if that order is not useful.
So the name membar_enter currently lives in a bad place where it
means either of two things -- r/rw or w/rw.

With this change, we deprecate membar_enter/exit, introduce
membar_acquire/release as better names for the useful pair (r/rw and
rw/w), and make sure the implementation of membar_enter guarantees
both what was documented _and_ what was implemented, making it an
alias for membar_sync.

While here, rework all of the membar_* definitions and aliases. The
new logic follows a rule to make it easier to audit:

membar_X is defined as an alias for membar_Y iff membar_X is
guaranteed by membar_Y.

The `no stronger than' relation is (the transitive closure of):

- membar_consumer (r/r) is guaranteed by membar_acquire (r/rw)
- membar_producer (w/w) is guaranteed by membar_release (rw/w)
- membar_acquire (r/rw) is guaranteed by membar_sync (rw/rw)
- membar_release (rw/w) is guaranteed by membar_sync (rw/rw)

And, for the deprecated membars:

- membar_enter (whether r/rw, w/rw, or rw/rw) is guaranteed by
membar_sync (rw/rw)
- membar_exit (rw/w) is guaranteed by membar_release (rw/w)

(membar_exit is identical to membar_release, but the name is
deprecated.)

Finally, while here, annotate some of the instructions with their
semantics. For powerpc, leave an essay with citations on the
unfortunate but -- as far as I can tell -- necessary decision to use
lwsync, not isync, for membar_acquire and membar_consumer.

Also add membar(3) and atomic(3) man page links.
 1.1 08-Apr-2022  riastradh membar_ops(3): Add some automatic tests.

These tests run two threads for five seconds each to try to trigger
races in the event of broken memory barriers. They run only on
machines with at least two CPUs; on uniprocessor systems there's no
point -- the membars can correctly just be (instruction barrier)
no-ops.
 1.2 10-Apr-2022  riastradh membar_ops(3): Simplify alarm handling in membar tests.
 1.1 08-Apr-2022  riastradh membar_ops(3): Add some automatic tests.

These tests run two threads for five seconds each to try to trigger
races in the event of broken memory barriers. They run only on
machines with at least two CPUs; on uniprocessor systems there's no
point -- the membars can correctly just be (instruction barrier)
no-ops.
 1.5 02-May-2025  riastradh t_spinlock: Mark this xfail on powerpc.

Not sure under exactly what circumstances it fails -- possible it's
only a subset of powerpc CPUs, dunno yet.

PR port-powerpc/59386: t_spinlock test is failing
 1.4 12-Aug-2022  riastradh branches: 1.4.4;
membar(3): Fix t_spinlock for machines with hash-locked atomics.

Regular stores don't participate in the hash-locking scheme, so use
atomic_swap instead of a regular store here.
 1.3 10-Apr-2022  riastradh membar_ops(3): Simplify alarm handling in membar tests.
 1.2 09-Apr-2022  riastradh Introduce membar_acquire/release. Deprecate membar_enter/exit.

The names membar_enter/exit were unclear, and the documentation of
membar_enter has disagreed with the implementations on sparc,
powerpc, and even x86(!) for the entire time it has been in NetBSD.

The terms `acquire' and `release' are ubiquitous in the literature
today, and have been adopted in the C and C++ standards to mean
load-before-load/store and load/store-before-store, respectively,
which are exactly the orderings required by acquiring and releasing a
mutex, as well as other useful applications like decrementing a
reference count and then freeing the underlying object if it went to
zero.

Originally I proposed changing one word in the documentation for
membar_enter to make it load-before-load/store instead of
store-before-load/store, i.e., to make it an acquire barrier. I
proposed this on the grounds that

(a) all implementations guarantee load-before-load/store,
(b) some implementations fail to guarantee store-before-load/store,
and
(c) all uses in-tree assume load-before-load/store.

I verified parts (a) and (b) (except, for (a), powerpc didn't even
guarantee load-before-load/store -- isync isn't necessarily enough;
need lwsync in general -- but it _almost_ did, and it certainly didn't
guarantee store-before-load/store).

Part (c) might not be correct, however: under the mistaken assumption
that atomic-r/m/w then membar-w/rw is equivalent to atomic-r/m/w then
membar-r/rw, I only audited the cases of membar_enter that _aren't_
immediately after an atomic-r/m/w. All of those cases assume
load-before-load/store. But my assumption was wrong -- there are
cases of atomic-r/m/w then membar-w/rw that would be broken by
changing to atomic-r/m/w then membar-r/rw:

https://mail-index.netbsd.org/tech-kern/2022/03/29/msg028044.html

Furthermore, the name membar_enter has been adopted in other places
like OpenBSD where it actually does follow the documentation and
guarantee store-before-load/store, even if that order is not useful.
So the name membar_enter currently lives in a bad place where it
means either of two things -- r/rw or w/rw.

With this change, we deprecate membar_enter/exit, introduce
membar_acquire/release as better names for the useful pair (r/rw and
rw/w), and make sure the implementation of membar_enter guarantees
both what was documented _and_ what was implemented, making it an
alias for membar_sync.

While here, rework all of the membar_* definitions and aliases. The
new logic follows a rule to make it easier to audit:

membar_X is defined as an alias for membar_Y iff membar_X is
guaranteed by membar_Y.

The `no stronger than' relation is (the transitive closure of):

- membar_consumer (r/r) is guaranteed by membar_acquire (r/rw)
- membar_producer (w/w) is guaranteed by membar_release (rw/w)
- membar_acquire (r/rw) is guaranteed by membar_sync (rw/rw)
- membar_release (rw/w) is guaranteed by membar_sync (rw/rw)

And, for the deprecated membars:

- membar_enter (whether r/rw, w/rw, or rw/rw) is guaranteed by
membar_sync (rw/rw)
- membar_exit (rw/w) is guaranteed by membar_release (rw/w)

(membar_exit is identical to membar_release, but the name is
deprecated.)

Finally, while here, annotate some of the instructions with their
semantics. For powerpc, leave an essay with citations on the
unfortunate but -- as far as I can tell -- necessary decision to use
lwsync, not isync, for membar_acquire and membar_consumer.

Also add membar(3) and atomic(3) man page links.
 1.1 08-Apr-2022  riastradh membar_ops(3): Add some automatic tests.

These tests run two threads for five seconds each to try to trigger
races in the event of broken memory barriers. They run only on
machines with at least two CPUs; on uniprocessor systems there's no
point -- the membars can correctly just be (instruction barrier)
no-ops.
 1.4.4.1 02-Aug-2025  perseant Sync with HEAD
 1.9 10-Aug-2023  mrg make this build with GCC 12.

there are some odd constructs here to trigger sanitizers.
 1.8 29-May-2022  andvar fix various typos in comments and log messages.
 1.7 07-Sep-2020  mrg avoid new GCC 9 warnings.
 1.6 30-Jan-2020  christos hack for clang/powerpc
 1.5 29-Sep-2019  mrg convert HAVE_GCC == 7 to HAVE_GCC >= 7.
 1.4 15-Aug-2019  kamil Fix build of t_ubsan/t_ubsanxx under MKSANITIZER

Do not link micro-ubsan runtime for disabled tests.

This avoids double symbols linked into a single binary.
 1.3 04-Feb-2019  mrg branches: 1.3.2; 1.3.4;
- revert previous to t_ubsan.c, it is desired behaviour. from kamil.
- use -Wno-int-in-bool-context instead
 1.2 09-Aug-2018  christos branches: 1.2.2;
Fix stack protector build.
 1.1 03-Aug-2018  kamil Import micro-UBSan ATF tests

These tests are used only when a distribution is built without MKSANITIZER
and without MKLIBCSANITIZER. They build the ubsan.c micro-implementation
in userland as a standalone library (a .c file linked into tests).

The code generation part emits symbols that are handled by uUBSan.

Tested with Clang amd64 + i386 and GCC amd64 + i386.

There are two sets of tests: C code generation and C++ code generation.

There are various little differences that are handled with proper ifdefs.

Clang 7svn has significantly more checks for Undefined Behavior than GCC
5.x. Some of the tests are or might be amd64 and/or i386 specific and are
marked with proper ifdefs and comments according to the compiler
documentation.
 1.2.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.2.2.1 09-Aug-2018  pgoyette file Makefile was added on branch pgoyette-compat on 2018-09-06 06:56:48 +0000
 1.3.4.1 16-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #62):

tests/lib/libc/misc/Makefile: revision 1.4

Fix build of t_ubsan/t_ubsanxx under MKSANITIZER
Do not link micro-ubsan runtime for disabled tests.

This avoids double symbols linked into a single binary.
 1.3.2.4 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3.2.2 10-Jun-2019  christos Sync with HEAD
 1.3.2.1 04-Feb-2019  christos file Makefile was added on branch phil-wifi on 2019-06-10 22:10:04 +0000
 1.6 28-Oct-2019  joerg Avoid warnings about tautological left shifts as conditional.
 1.5 20-Feb-2019  kamil branches: 1.5.2;
Unify the style of t_ubsan tests

Apply similar change for load_invalid_value_bool in
test_load_invalid_value_enum.

Follow up of PR bin/53968 by Michael van Elst
 1.4 20-Feb-2019  kamil Try to make load_invalid_value_bool portable to Big-Endian

PR bin/53968 by Michael van Elst
 1.3 04-Feb-2019  mrg - revert previous to t_ubsan.c, it is desired behaviour. from kamil.
- use -Wno-int-in-bool-context instead
 1.2 03-Feb-2019  mrg - avoid multipling a boolean value, use &&.
 1.1 03-Aug-2018  kamil branches: 1.1.2;
Import micro-UBSan ATF tests

These tests are used only when a distribution is built without MKSANITIZER
and without MKLIBCSANITIZER. They build the ubsan.c micro-implementation
in userland as a standalone library (a .c file linked into tests).

The code generation part emits symbols that are handled by uUBSan.

Tested with Clang amd64 + i386 and GCC amd64 + i386.

There are two sets of tests: C code generation and C++ code generation.

There are various little differences that are handled with proper ifdefs.

Clang 7svn has significantly more checks for Undefined Behavior than GCC
5.x. Some of the tests are or might be amd64 and/or i386 specific and are
marked with proper ifdefs and comments according to the compiler
documentation.
 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 03-Aug-2018  pgoyette file t_ubsan.c was added on branch pgoyette-compat on 2018-09-06 06:56:48 +0000
 1.5.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.2.2 10-Jun-2019  christos Sync with HEAD
 1.5.2.1 20-Feb-2019  christos file t_ubsan.c was added on branch phil-wifi on 2019-06-10 22:10:04 +0000
 1.1 03-Aug-2018  kamil branches: 1.1.2; 1.1.4;
Import micro-UBSan ATF tests

These tests are used only when a distribution is built without MKSANITIZER
and without MKLIBCSANITIZER. They build the ubsan.c micro-implementation
in userland as a standalone library (a .c file linked into tests).

The code generation part emits symbols that are handled by uUBSan.

Tested with Clang amd64 + i386 and GCC amd64 + i386.

There are two sets of tests: C code generation and C++ code generation.

There are various little differences that are handled with proper ifdefs.

Clang 7svn has significantly more checks for Undefined Behavior than GCC
5.x. Some of the tests are or might be amd64 and/or i386 specific and are
marked with proper ifdefs and comments according to the compiler
documentation.
 1.1.4.2 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 03-Aug-2018  christos file t_ubsanxx.cpp was added on branch phil-wifi on 2019-06-10 22:10:04 +0000
 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 03-Aug-2018  pgoyette file t_ubsanxx.cpp was added on branch pgoyette-compat on 2018-09-06 06:56:48 +0000
 1.14 01-Jun-2020  kamil Avoid redefining _REENTRANT under sanitizers

Switch away from -Wno-macro-redefined which was Clang specific.
 1.13 08-Feb-2020  kamil Expand the -Wno-macro-redefined usage to MKLIBCSANITIZER

_REENTRANT can be redefined and this is considered as an error.
 1.12 27-Aug-2019  kamil Enhance the support of LLVM sanitizers

Define _REENTRANT for MKSANITIZER build. This is needed for at least stdio
code. This caused new build issued with duplicated symbols in few places
and rump kernel code picking different code paths borrowed from libc.
Handle all this in one go.

Add bsd.sanitizer.mk to share common code used by programs and libraries.

Switch from realall to beforeinstall target in .syms files. This is more
reliable in MKSANITIZER.
 1.11 06-Aug-2018  msaitoh branches: 1.11.2;
Add simple test case for if_nametoindex(3).
 1.10 09-Jan-2014  christos branches: 1.10.24; 1.10.26;
Use our own resolv.conf file simplifying the test to not need rump_vfs.
Add debugging on the dns server
One test fails (gethostbyaddr6) why? It runs without rump
 1.9 06-Jan-2014  gson Make t_hostent test cases that query the DNS work on systems with no
Internet connectivity, by hijacking DNS queries and /etc/resolv.conf
accesses using librumphijack and providing a minimal DNS server to
answer the queries.
 1.8 16-Aug-2013  christos test harness for gethostbyname()/gethostbyaddr() and their internal bits.
XXX[1]: How can we avoid using hard-coded hosts for DNS
XXX[2]: How do we test NIS?
 1.7 15-Sep-2012  plunky correct spelling of file to clean
 1.6 01-Nov-2011  pgoyette branches: 1.6.2; 1.6.8;
atf-ify ether_aton test
 1.5 15-Jul-2011  jruoho Few naive unit tests for the getprotoent(3) family.
 1.4 13-Jan-2011  pgoyette Re-add missing -lpthread and fix some structure inializers (not sure how
these ever compiled)
 1.3 13-Jan-2011  pgoyette The nsdispatch test belongs in libc/net and not in libc
 1.2 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.6.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6.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.6.2.1 30-Oct-2012  yamt sync with head
 1.10.26.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10.26.1 10-Jun-2019  christos Sync with HEAD
 1.10.24.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.11.2.1 01-Sep-2019  martin Pull up following revision(s) (requested by kamil in ticket #126):

external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_minimal-m64/Makefile: revision 1.3
external/bsd/compiler_rt/lib/clang/lib/netbsd/msan_cxx-m64/Makefile: revision 1.3
external/gpl2/lvm2/lvm2tools.mk: revision 1.5
common/lib/libc/gmon/mcount.c: revision 1.14
Makefile: revision 1.331
share/mk/Makefile: revision 1.51
external/bsd/fetch/lib/Makefile: revision 1.12
external/bsd/compiler_rt/lib/clang/lib/netbsd/asan_cxx-m64/Makefile: revision 1.3
tests/lib/libc/net/Makefile: revision 1.12
external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone_cxx-m64/Makefile: revision 1.3
external/bsd/compiler_rt/lib/clang/lib/netbsd/msan-m64/Makefile: revision 1.3
distrib/sets/lists/base/mi: revision 1.1213
share/mk/bsd.lib.mk: revision 1.380
external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone-m64/Makefile: revision 1.3
external/bsd/compiler_rt/lib/clang/lib/netbsd/asan-m64/Makefile: revision 1.3
share/mk/bsd.sanitizer.mk: revision 1.1
share/mk/bsd.prog.mk: revision 1.323
external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan-m64/Makefile: revision 1.3
external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan_cxx-m64/Makefile: revision 1.3
lib/libc/gen/sysctlgetmibinfo.c: revision 1.14

Enhance the support of LLVM sanitizers

Define _REENTRANT for MKSANITIZER build. This is needed for at least stdio
code. This caused new build issued with duplicated symbols in few places
and rump kernel code picking different code paths borrowed from libc.

Handle all this in one go.

Add bsd.sanitizer.mk to share common code used by programs and libraries.

Switch from realall to beforeinstall target in .syms files. This is more
reliable in MKSANITIZER.
 1.1 11-Jun-2011  christos branches: 1.1.2;
Turn warns on for all tests and fix all the bugs.
 1.1.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1.2.1 11-Jun-2011  cherry file Makefile.inc was added on branch cherry-xenmp on 2011-06-23 14:20:39 +0000
 1.1 01-Nov-2011  pgoyette atf-ify ether_aton test
 1.4 29-Mar-2014  gson branches: 1.4.4; 1.4.8;
Use daemon(3) instead of the experimental daemon2_fork() and
daemon2_detach(). Now that newer versions of daemon2_fork() and
daemon2_detach() are used in nfsd, where two-stage daemonization is
actually needed, there is no longer any reason for h_dns_server to
serve as a test case and example of their use.
 1.3 09-Jan-2014  christos Use our own resolv.conf file simplifying the test to not need rump_vfs.
Add debugging on the dns server
One test fails (gethostbyaddr6) why? It runs without rump
 1.2 06-Jan-2014  gson Fix spelling of "daemon". Pointed out by Thomas Klausner.
 1.1 06-Jan-2014  gson Make t_hostent test cases that query the DNS work on systems with no
Internet connectivity, by hijacking DNS queries and /etc/resolv.conf
accesses using librumphijack and providing a minimal DNS server to
answer the queries.
 1.4.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 29-Mar-2014  tls file h_dns_server.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.4.4.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.4.4.1 29-Mar-2014  yamt file h_dns_server.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.2 09-Jan-2014  christos branches: 1.2.4; 1.2.8;
Use our own resolv.conf file simplifying the test to not need rump_vfs.
Add debugging on the dns server
One test fails (gethostbyaddr6) why? It runs without rump
 1.1 16-Aug-2013  christos test harness for gethostbyname()/gethostbyaddr() and their internal bits.
XXX[1]: How can we avoid using hard-coded hosts for DNS
XXX[2]: How do we test NIS?
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 09-Jan-2014  tls file h_hostent.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.2.4.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.4.1 09-Jan-2014  yamt file h_hostent.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.3 01-Jun-2020  kamil Avoid redefining _REENTRANT under sanitizers

Switch away from -Wno-macro-redefined which was Clang specific.
 1.2 13-Jan-2011  pgoyette Re-add missing -lpthread and fix some structure inializers (not sure how
these ever compiled)
 1.1 13-Jan-2011  pgoyette The nsdispatch test belongs in libc/net and not in libc
 1.2 07-Apr-2011  jruoho Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.1 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.2 07-Apr-2011  jruoho Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.1 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.1 16-Aug-2013  christos branches: 1.1.4; 1.1.8;
test harness for gethostbyname()/gethostbyaddr() and their internal bits.
XXX[1]: How can we avoid using hard-coded hosts for DNS
XXX[2]: How do we test NIS?
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 16-Aug-2013  tls file hosts was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.4.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.4.1 16-Aug-2013  yamt file hosts was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.1 09-Jan-2014  christos branches: 1.1.4; 1.1.8;
Use our own resolv.conf file simplifying the test to not need rump_vfs.
Add debugging on the dns server
One test fails (gethostbyaddr6) why? It runs without rump
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 09-Jan-2014  tls file resolv.conf was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.4.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.4.1 09-Jan-2014  yamt file resolv.conf was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.1 01-Nov-2011  pgoyette atf-ify ether_aton test
 1.2 04-Apr-2012  joerg Be UTF8 clean.
 1.1 15-Jul-2011  jruoho branches: 1.1.2;
Few naive unit tests for the getprotoent(3) family.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.10 13-Jan-2014  gson branches: 1.10.4; 1.10.8;
When using braces around shell variable names, do so consistently
 1.9 13-Jan-2014  gson Add missing resolv.conf override to the gethostbyaddr6 test case.
 1.8 10-Jan-2014  gson Remove comment that no longer applies.
 1.7 10-Jan-2014  christos Add a cleanup routine because if a test fails, the script exits and the
rest of the code is not executed.
Note that the cleanup routine is executed in a separate shell so environment
variables are not propagated and need to be set again.
 1.6 09-Jan-2014  christos fix copyright botch and add library for netinet6; still does not fix the
problem.
 1.5 09-Jan-2014  christos Use our own resolv.conf file simplifying the test to not need rump_vfs.
Add debugging on the dns server
One test fails (gethostbyaddr6) why? It runs without rump
 1.4 06-Jan-2014  gson Make t_hostent test cases that query the DNS work on systems with no
Internet connectivity, by hijacking DNS queries and /etc/resolv.conf
accesses using librumphijack and providing a minimal DNS server to
answer the queries.
 1.3 20-Dec-2013  christos sixthavenue got upgraded
 1.2 20-Oct-2013  christos broadway changed addresses.
 1.1 16-Aug-2013  christos test harness for gethostbyname()/gethostbyaddr() and their internal bits.
XXX[1]: How can we avoid using hard-coded hosts for DNS
XXX[2]: How do we test NIS?
 1.10.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.8.1 13-Jan-2014  tls file t_hostent.sh was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.10.4.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.10.4.1 13-Jan-2014  yamt file t_hostent.sh was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.1 06-Aug-2018  msaitoh branches: 1.1.2; 1.1.4;
Add simple test case for if_nametoindex(3).
 1.1.4.2 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 06-Aug-2018  christos file t_if_nametoindex.c was added on branch phil-wifi on 2019-06-10 22:10:04 +0000
 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 06-Aug-2018  pgoyette file t_if_nametoindex.c was added on branch pgoyette-compat on 2018-09-06 06:56:48 +0000
 1.1 13-Jan-2011  pgoyette The nsdispatch test belongs in libc/net and not in libc
 1.5 04-Dec-2022  jschauma allow testing of files other than those in /etc

To test e.g., the file "/some/where/protocols" instead of "/etc/protocols",
set TEST_FILE=/some/where/protocols in your environment.

Note: this now compares the contents of the file you gave versus what
getprotoent(3)/getservent(3) uses (which still is /etc/protocols via
h_protoent.c / /etc/services or /var/db/services.cdb via h_servent.c).

When you have expected changes in the services or protocols file that
you're generating, this necessarily produces a difference. To really
allow testing the file versus what the library function returns, you'd
have to install the file on the system running the test, but at least
with this change you can now generate the file and verify that it didn't
caused unexpected differences.
 1.4 28-Nov-2022  jschauma whoops, we don't want an extra space here

(erroneously introduced in my previous commit)
 1.3 28-Nov-2022  jschauma whitespace
 1.2 03-Sep-2012  christos whitespace
 1.1 12-Jan-2011  pgoyette branches: 1.1.6;
Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.1.6.1 30-Oct-2012  yamt sync with head
 1.4 04-Dec-2022  jschauma allow testing of files other than those in /etc

To test e.g., the file "/some/where/protocols" instead of "/etc/protocols",
set TEST_FILE=/some/where/protocols in your environment.

Note: this now compares the contents of the file you gave versus what
getprotoent(3)/getservent(3) uses (which still is /etc/protocols via
h_protoent.c / /etc/services or /var/db/services.cdb via h_servent.c).

When you have expected changes in the services or protocols file that
you're generating, this necessarily produces a difference. To really
allow testing the file versus what the library function returns, you'd
have to install the file on the system running the test, but at least
with this change you can now generate the file and verify that it didn't
caused unexpected differences.
 1.3 04-Dec-2022  jschauma whitespace
 1.2 08-Mar-2016  joerg libc fallback is known to not produce nice alias entries. Avoid spurious
failures when testing in an empty chroot by requiring the services db.
 1.1 12-Jan-2011  pgoyette Move the servent and protoent tests to src/tests/lib/libc/net/ (where
they should have gone initially).
 1.2 26-Aug-2016  darcy Replace MKMAN with NOMAN as suggested by christos@. Allows
userland to build when building man pages.
 1.1 12-Jan-2011  pgoyette branches: 1.1.24; 1.1.30;
By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1.30.1 18-Jan-2017  skrll Sync with netbsd-5
 1.1.24.1 25-Sep-2016  bouyer Pull up following revision(s) (requested by darcy in ticket #1241):
tests/lib/libc/net/getaddrinfo/Makefile: revision 1.2
tests/lib/libc/regex/Makefile: revision 1.10
Replace MKMAN with NOMAN as suggested by christos@. Allows
userland to build when building man pages.
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.2 03-Feb-2019  mrg - enlarge buffer to avoid snprintf() truncation
 1.1 12-Jan-2011  pgoyette branches: 1.1.46;
By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1.46.1 10-Jun-2019  christos Sync with HEAD
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.2 16-Dec-2018  dholland Update error string
 1.1 12-Jan-2011  pgoyette branches: 1.1.44; 1.1.46;
By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1.46.1 10-Jun-2019  christos Sync with HEAD
 1.1.44.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.2 18-Dec-2018  dholland Update error string
 1.1 12-Jan-2011  pgoyette branches: 1.1.44; 1.1.46;
By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1.46.1 10-Jun-2019  christos Sync with HEAD
 1.1.44.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.3 10-Jan-2019  pgoyette Remove extraneous && from check_output()

With this extra && the test case exits abnormally when the actual and
expected outputs don't match.
 1.2 15-Jun-2011  jmmv branches: 1.2.40; 1.2.42;
Fix obvious typo in test case name. Uncovered by atf 0.14.
 1.1 12-Jan-2011  pgoyette branches: 1.1.4;
By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.42.1 10-Jun-2019  christos Sync with HEAD
 1.2.40.1 10-Jan-2019  pgoyette Import fix from HEAD.

Now that the test behaves normally under failure (mismatched actual vs
expected outputs), maybe I can figure out why it actually fails.
 1.1 12-Jan-2011  pgoyette By request, put the getaddrinfo test in tests/lib/libc/net/
 1.1 08-Mar-2020  mgorny branches: 1.1.2;
Add tests for missing libc catalog entries
 1.1.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.2.1 08-Mar-2020  martin file Makefile was added on branch phil-wifi on 2020-04-13 08:05:26 +0000
 1.1 08-Mar-2020  mgorny branches: 1.1.2;
Add tests for missing libc catalog entries
 1.1.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.2.1 08-Mar-2020  martin file t_catalog.c was added on branch phil-wifi on 2020-04-13 08:05:26 +0000
 1.13 02-Jan-2025  kre Fix build after recent regex tests addition (make it be an addition, and
don't forget tests/libtre)
 1.12 01-Jan-2025  christos Add a test for PR/58910
 1.11 25-Feb-2021  christos branches: 1.11.8;
Adjust for conditional NLS
 1.10 26-Aug-2016  darcy Replace MKMAN with NOMAN as suggested by christos@. Allows
userland to build when building man pages.
 1.9 24-Aug-2012  jmmv branches: 1.9.10; 1.9.16;
Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.8 06-Nov-2011  christos make the standard tests optional.
 1.7 06-Nov-2011  christos skip the association that does not match with our implementation.
 1.6 06-Nov-2011  christos Add the AT&T regex tests
 1.5 05-Nov-2011  christos Arrange so that the same tests can be used by libtre.
 1.4 11-Oct-2011  dholland branches: 1.4.2;
Don't use 'nul' in filenames as windows will belch.
(Caught by importing the tree into mercurial)
 1.3 10-Oct-2011  christos - Use PROGS instead of PROG so that we can co-exist with TESTS_C
- Make the helper program compile again.
 1.2 09-Oct-2011  christos Add a test to check for DoS attacks against regcomp/regexec. From
Maksymilian Arciemowicz.
 1.1 09-Jan-2011  pgoyette Ouch - forgot the include this earlier.
 1.4.2.2 30-Oct-2012  yamt sync with head
 1.4.2.1 10-Nov-2011  yamt sync with head
 1.9.16.1 18-Jan-2017  skrll Sync with netbsd-5
 1.9.10.1 25-Sep-2016  bouyer Pull up following revision(s) (requested by darcy in ticket #1241):
tests/lib/libc/net/getaddrinfo/Makefile: revision 1.2
tests/lib/libc/regex/Makefile: revision 1.10
Replace MKMAN with NOMAN as suggested by christos@. Allows
userland to build when building man pages.
 1.11.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.8 24-Aug-2012  jmmv Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.7 06-Nov-2011  christos branches: 1.7.2;
- Handle TRE
- Make BUG comments print.
 1.6 06-Nov-2011  christos be less chatty.
 1.5 06-Nov-2011  christos more failed tests, perhaps I should move the data to a file, but how do
you open a file in ATF?
 1.4 06-Nov-2011  christos Add the failed forced association tests.
 1.3 06-Nov-2011  christos Add the nullsubexpression tests. We mostly fail or don't support them.
Two of the tests actually cause the regex library to enter infinite
recursion.
 1.2 06-Nov-2011  christos Add a bug section so we can skip tests that don't work.
 1.1 06-Nov-2011  christos Add a test harness for the att data files:
http://www2.research.att.com/~gsf/testregex/
Not part of the build yet.
 1.7.2.3 30-Oct-2012  yamt sync with head
 1.7.2.2 10-Nov-2011  yamt sync with head
 1.7.2.1 06-Nov-2011  yamt file att.c was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.7 25-Feb-2021  christos Adjust for conditional NLS
 1.6 24-Feb-2021  christos remove casts
 1.5 24-Feb-2021  christos minimal fix to match the library code (really make the constants unsigned
instead)
 1.4 23-Feb-2021  christos Delete category stuff that has changed with the new regex; make compile
on linux and with TRE
 1.3 14-Jan-2017  christos PR/51832: Ngie Cooper:
- limit memory to 64M
- error msg fixes
- includes fixes
 1.2 10-Oct-2011  christos branches: 1.2.24;
- Use PROGS instead of PROG so that we can co-exist with TESTS_C
- Make the helper program compile again.
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.2.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 23-Feb-2021  christos Add REG_GNU
 1.3 23-Feb-2021  christos Add REG_POSIX, and make compile on linux where we don't have a lot of the
internal flags.
 1.2 16-Sep-2011  plunky NULL does not need a cast, here
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.14 09-Jun-2021  christos remove the kill in the trace code.
 1.13 09-Jun-2021  christos remove not required include files
 1.12 09-Jun-2021  christos 1. Preallocate the patterns so that out of memory conditions don't happen
during their allocation, which the test cannot handle properly.
2. Enable building the test without atf so that we can easily debug with
atf memory allocations interfering
3. Add memory tracing (disabled)
 1.11 07-Jun-2021  christos Add more information for the malloc failure.
 1.10 09-Jul-2019  gson Update require.memory to match the increased rlimit.
 1.9 16-Mar-2019  christos PR/54061: Bump memory for jemalloc (a lot).
 1.8 14-Jan-2017  christos branches: 1.8.14;
PR/51832: Ngie Cooper:
- limit memory to 64M
- error msg fixes
- includes fixes
 1.7 16-Nov-2011  christos branches: 1.7.22;
this works with much less memory too.
 1.6 16-Nov-2011  christos add require.memory=500M
 1.5 09-Nov-2011  christos add a large timeout for libtre
 1.4 06-Nov-2011  christos - Print the symbolic error using regerror, as well as the pattern that caused
it.
- Add the ability to set the number of repetitions in the pattern from
cpp since TRE handles things poorly:
- It runs the machine out of memory with rep=9 (we use rep=9999)
- It truncates the pattern with rep=9999
 1.3 04-Nov-2011  christos stylistic improvements.
 1.2 21-Oct-2011  christos branches: 1.2.2;
simplify.
 1.1 09-Oct-2011  christos Add a test to check for DoS attacks against regcomp/regexec. From
Maksymilian Arciemowicz.
 1.2.2.2 17-Apr-2012  yamt sync with head
 1.2.2.1 10-Nov-2011  yamt sync with head
 1.7.22.1 20-Mar-2017  pgoyette Sync with HEAD
 1.8.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8.14.1 10-Jun-2019  christos Sync with HEAD
 1.3 24-Aug-2012  jmmv Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.2 06-Nov-2011  christos ability to select associativity
 1.1 08-Jan-2011  pgoyette branches: 1.1.6;
Atf-ify the regex test
 1.1.6.2 30-Oct-2012  yamt sync with head
 1.1.6.1 10-Nov-2011  yamt sync with head
 1.4 24-Aug-2012  jmmv Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.3 11-Oct-2011  dholland branches: 1.3.2;
Don't use 'nul' in filenames as windows will belch.
(Caught by importing the tree into mercurial)
 1.2 09-Jan-2011  pgoyette Fix typo that got lost between my trial build and the final commit
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.3.2.1 30-Oct-2012  yamt sync with head
 1.1 24-Aug-2012  jmmv branches: 1.1.4;
Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 24-Aug-2012  yamt file t_regex.sh was added on branch yamt-pagecache on 2012-10-30 19:00:00 +0000
 1.4 23-Feb-2021  christos Add support for ENOSYS (was never set)
 1.3 14-Jan-2017  christos PR/51873: Ngie Cooper: add util.h #include
 1.2 14-Jan-2017  christos PR/51832: Ngie Cooper:
- limit memory to 64M
- error msg fixes
- includes fixes
 1.1 24-Aug-2012  jmmv branches: 1.1.4; 1.1.16;
Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.1.16.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 24-Aug-2012  yamt file t_regex_att.c was added on branch yamt-pagecache on 2012-10-30 19:00:01 +0000
 1.3 24-Aug-2012  jmmv Sanitize the regex test cases.

- Merge h_regex_att (att.c) and t_regex_att.sh into a single C test program.
The former was really a test program, and the latter just a very strange
driver for it.

- Stop using awk to generate the shell test programs. This is unnecessary
and confusing. Instead, change t_regex.sh to generate the test case
functions on the fly with eval (as done in many other places).
 1.2 06-Nov-2011  christos branches: 1.2.2;
leave all tests in and have the awk script select which ones are appropriate.
 1.1 06-Nov-2011  christos Add the AT&T regex tests
 1.2.2.3 30-Oct-2012  yamt sync with head
 1.2.2.2 10-Nov-2011  yamt sync with head
 1.2.2.1 06-Nov-2011  yamt file t_regex_att.in was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 01-Jan-2025  christos branches: 1.1.4;
Add a test for PR/58910
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 01-Jan-2025  perseant file t_regex_binary.c was added on branch perseant-exfatfs on 2025-08-02 05:58:05 +0000
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.2 23-Feb-2021  christos Comment out tests that the new stricter regex does not like
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.2 11-Oct-2011  dholland Don't use 'nul' in filenames as windows will belch.
(Caught by importing the tree into mercurial)
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.2 23-Feb-2021  christos Comment out tests that the new stricter regex does not like
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.2 23-Feb-2021  christos Comment out tests that the new stricter regex does not like
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 08-Jan-2011  pgoyette Atf-ify the regex test
 1.1 11-Oct-2011  dholland Don't use 'nul' in filenames as windows will belch.
(Caught by importing the tree into mercurial)
 1.2 15-Aug-2023  christos Update link. We should also update the data...
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file README was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file basic.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file categorization.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file forcedassoc.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file leftassoc.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file nullsubexpr.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file repetition.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.1 06-Nov-2011  christos branches: 1.1.2;
moved because we cannot have multiple FILESDIR
 1.1.2.2 10-Nov-2011  yamt sync with head
 1.1.2.1 06-Nov-2011  yamt file rightassoc.dat was added on branch yamt-pagecache on 2011-11-10 14:31:52 +0000
 1.4 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.3 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.2 26-Feb-2013  christos branches: 1.2.30;
Add a test for the rpc getaddr bug lib/13082.
Timeout added, but it needs rpcbind to be running to succeed.
 1.1 08-Jan-2011  pgoyette branches: 1.1.6; 1.1.12;
Atf-ify the rpc/t_xdr test
 1.1.12.1 23-Jun-2013  tls resync from head
 1.1.6.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.30.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 08-Jan-2011  pgoyette Atf-ify the rpc/t_xdr test
 1.11 04-Feb-2019  mrg - make ERRX() return a value since it doesn't actually exit in the !TEST case.
 1.10 27-Aug-2016  christos branches: 1.10.14;
skip if we are not running rpcbind.
 1.9 27-Nov-2015  christos fix double negation
 1.8 10-Nov-2015  christos CID 1338516: Handle svc_run() returning.
 1.7 08-Nov-2015  christos Disable debugging.
 1.6 08-Nov-2015  christos Add more rpc tests. XXX: Need rpcbind running.
 1.5 06-Nov-2015  christos make this compile for tests.
 1.4 06-Nov-2015  christos Add a test for the raw transports which are currently busted.
 1.3 28-Feb-2013  christos branches: 1.3.4; 1.3.10;
remove the timeout; it is handled internally.
 1.2 27-Feb-2013  christos skip the tests if rpcbind is not responding.
 1.1 26-Feb-2013  christos Add a test for the rpc getaddr bug lib/13082.
Timeout added, but it needs rpcbind to be running to succeed.
 1.3.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.3.10.1 28-Feb-2013  yamt file t_rpc.c was added on branch yamt-pagecache on 2014-05-22 11:42:20 +0000
 1.3.4.2 23-Jun-2013  tls resync from head
 1.3.4.1 28-Feb-2013  tls file t_rpc.c was added on branch tls-maxphys on 2013-06-23 06:28:56 +0000
 1.10.14.1 10-Jun-2019  christos Sync with HEAD
 1.1 08-Jan-2011  pgoyette Atf-ify the rpc/t_xdr test
 1.3 19-Feb-2024  riastradh longjmp(3): Add test for PR lib/57946.
 1.2 21-Apr-2011  martin branches: 1.2.46; 1.2.54;
Add a variation of the setjmp tests that link to libpthread and verify
pthread_self() stays consistent.
 1.1 27-Dec-2010  pgoyette Move the various setjmp tests from regress to atf
 1.2.54.1 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #795):

tests/lib/libc/setjmp/Makefile: revision 1.3
distrib/sets/lists/debug/mi: revision 1.425
lib/libc/arch/sh3/gen/setjmp.S: revision 1.12
lib/libc/arch/i386/gen/sigsetjmp.S: revision 1.19
lib/libc/arch/x86_64/gen/__setjmp14.S: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.10
tests/lib/libc/setjmp/t_sigstack.c: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.12
tests/lib/libc/setjmp/t_sigstack.c: revision 1.1
lib/libc/arch/sh3/gen/sigsetjmp.S: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.2
tests/lib/libc/setjmp/t_sigstack.c: revision 1.3
tests/lib/libc/setjmp/t_sigstack.c: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.5
tests/lib/libc/setjmp/t_sigstack.c: revision 1.6
lib/libc/arch/arm/gen/setjmp.S: revision 1.19
tests/lib/libc/setjmp/t_sigstack.c: revision 1.7
tests/lib/libc/setjmp/t_sigstack.c: revision 1.8
tests/lib/libc/setjmp/t_sigstack.c: revision 1.9
lib/libc/arch/i386/gen/setjmp.S: revision 1.18
lib/libc/arch/x86_64/gen/__sigsetjmp14.S: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1306

longjmp(3): Add test for PR lib/57946.

longjmp(3): Paranoia: more error checking in PR lib/57946 test.

longjmp(3): Test signal mask vs stack restore with siglongjmp too.
PR lib/57946

longjmp(3) t_sigstack: Print which entry failed.
PR lib/57946

longjmp(3) t_sigstack: Note aarch64 seems to DTRT.
But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.
PR lib/57946

longjmp(3) t_sigstack: Use a sigaltstack per handler entry.
longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack. So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.
With this change, the test now passes on aarch64.
PR lib/57946

longjmp(3) t_sigstack: Fix fencepost error.
Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.
PR lib/57946

amd64 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use `xorl %eXX,%eXX' instead of `xorq %rXX,%rXX'.
=> Same effect, one byte shorter, breaks dep chain on more uarches.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

i386 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

arm longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Move the botched sp and lr tests earlier.
PR lib/57946
arm has been fixed

tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.
PR lib/57946

sh3: siglongjmp - restore register context first (PR lib/57946)
 1.2.46.1 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #795):

tests/lib/libc/setjmp/Makefile: revision 1.3
distrib/sets/lists/debug/mi: revision 1.425
lib/libc/arch/sh3/gen/setjmp.S: revision 1.12
lib/libc/arch/i386/gen/sigsetjmp.S: revision 1.19
lib/libc/arch/x86_64/gen/__setjmp14.S: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.10
tests/lib/libc/setjmp/t_sigstack.c: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.12
tests/lib/libc/setjmp/t_sigstack.c: revision 1.1
lib/libc/arch/sh3/gen/sigsetjmp.S: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.2
tests/lib/libc/setjmp/t_sigstack.c: revision 1.3
tests/lib/libc/setjmp/t_sigstack.c: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.5
tests/lib/libc/setjmp/t_sigstack.c: revision 1.6
lib/libc/arch/arm/gen/setjmp.S: revision 1.19
tests/lib/libc/setjmp/t_sigstack.c: revision 1.7
tests/lib/libc/setjmp/t_sigstack.c: revision 1.8
tests/lib/libc/setjmp/t_sigstack.c: revision 1.9
lib/libc/arch/i386/gen/setjmp.S: revision 1.18
lib/libc/arch/x86_64/gen/__sigsetjmp14.S: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1306 (patch)

longjmp(3): Add test for PR lib/57946.

longjmp(3): Paranoia: more error checking in PR lib/57946 test.

longjmp(3): Test signal mask vs stack restore with siglongjmp too.
PR lib/57946

longjmp(3) t_sigstack: Print which entry failed.
PR lib/57946

longjmp(3) t_sigstack: Note aarch64 seems to DTRT.
But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.
PR lib/57946

longjmp(3) t_sigstack: Use a sigaltstack per handler entry.
longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack. So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.
With this change, the test now passes on aarch64.
PR lib/57946

longjmp(3) t_sigstack: Fix fencepost error.
Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.
PR lib/57946

amd64 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use `xorl %eXX,%eXX' instead of `xorq %rXX,%rXX'.
=> Same effect, one byte shorter, breaks dep chain on more uarches.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

i386 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

arm longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Move the botched sp and lr tests earlier.
PR lib/57946
arm has been fixed

tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.
PR lib/57946

sh3: siglongjmp - restore register context first (PR lib/57946)
 1.13 28-Apr-2025  martin PR 59370: compat 1.3 setjmp has been fixed
 1.12 28-Apr-2025  riastradh tests/lib/libc/setjmp: Mark compat 1.3 setjmp busted on sparc64.

PR port-sparc64/59370: compat 1.3 setjmp is busted
 1.11 25-Apr-2025  riastradh t_setjmp, t_sigstack: Mark compat13 setjmp tests xfail on arm.

(Does it even make sense to have compat_setjmp on arm? Didn't we
break ABI compatibility with the oabi->eabi transition, long after
1.3?)

PR port-arm/59351: compat_setjmp is busted
 1.10 24-Apr-2025  riastradh mips/compat_longjmp: Make sure compat13 setjmp returns nonzero.

PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
 1.9 24-Apr-2025  riastradh mips/compat_sigsetjmp: Add missing RESTORE_GP64.

Otherwise, compat13 sigsetjmp clobbers the caller's gp when it
returns (the first time around, anyway), which leads to a lovely
display of fireworks.

PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
 1.8 24-Apr-2025  riastradh mips/compat_setjmp: .set reorder doesn't have delay slots.

PR port-mips/59342: compat_setjmp.S is confused about delay slots
 1.7 24-Apr-2025  riastradh t_setjmp, t_sigstack: Test compat13 setjmp/sigsetjmp too.

PR port-mips/59342: compat_setjmp.S is confused about delay slots
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
 1.6 24-Apr-2025  riastradh t_setjmp: Tidy up.

- KNF.
- Nix trailing whitespace.
- Use RL from h_macros.h.
- Use enum and case.

No functional change intended.

Preparation for extending these tests to the compat13 functions,
prompted by:

PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
PR port-mips/59342: compat_setjmp.S is confused about delay slots
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
 1.5 22-Apr-2025  riastradh mips: Fix _longjmp(..., 0) so _setjmp returns 1 as intended.

_setjmp (like setjmp and sigsetjmp) is only permitted to return 0 the
first time around.

PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
 1.4 22-Apr-2025  riastradh t_setjmp: Mark _longjmp_zero xfail on mips.

PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
 1.3 21-Mar-2021  christos branches: 1.3.8;
PR/56066: Jessica Clarke: Add tests for calling {_,}longjmp with a zero value.
 1.2 14-Jan-2017  christos PR/51874: Ngie Cooper: Add __unused to signal handlers
 1.1 27-Dec-2010  pgoyette branches: 1.1.28;
Move the various setjmp tests from regress to atf
 1.1.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.8.1 02-Aug-2025  perseant Sync with HEAD
 1.25 12-May-2025  christos fix the clang build.
 1.24 28-Apr-2025  martin PR 59370: compat 1.3 setjmp has been fixed
 1.23 28-Apr-2025  riastradh tests/lib/libc/setjmp: Mark compat 1.3 setjmp busted on sparc64.

PR port-sparc64/59370: compat 1.3 setjmp is busted
 1.22 28-Apr-2025  riastradh t_sigstack: Don't do atf_tc_expect_fail then atf_tc_expect_signal.

atf interprets this sequence, with no intervening atf_tc_fail, to
mean the xfail failed to fail so it fails. (Got that?) That is, it
is interpreted somewhat like

atf_tc_expect_fail(...);
... there is supposed to be a failure here ...
atf_tc_expect_pass();
... remaining checks are expected to pass ...

where a lack of failures between the xfail and the xpass means the
expectation was not met.

But in this case, there are two compounding bugs:

1. the compat 1.3 setjmp has botched its registers, as uwe@
discovered, so it is expected to crash on SIGSEGV (PR 59351); and

2. the compat 1.3 longjmp restores the stack poiter and signal mask
in the wrong order, so it is expected to fail the test (PR 57946).

Since the crash in setjmp triggers before the failure after longjmp,
only do atf_tc_expect_signal; once that is fixed we can re-enable the
atf_tc_expect_fail for longjmp.

PR lib/57946: longjmp fails to restore stack first before restoring
signal mask on most architectures

PR port-arm/59351: compat_setjmp is busted
 1.21 25-Apr-2025  riastradh t_setjmp, t_sigstack: Mark compat13 setjmp tests xfail on arm.

(Does it even make sense to have compat_setjmp on arm? Didn't we
break ABI compatibility with the oabi->eabi transition, long after
1.3?)

PR port-arm/59351: compat_setjmp is busted
 1.20 24-Apr-2025  riastradh tests/lib/libc/setjmp/t_sigstack: Update xfails.

Designations based on actual test run for i386 and code inspection
for arm and sh3 (and code inspection for all the other architectures
not listed because I expect the tests to pass on them -- they mostly
use sigreturn which will DTRT).

Move the ia64 xfail to just setjmp/sigsetjmp -- no compat13 on ia64.

Nix the long comment now that just about everything has been fixed.

PR lib/57946: longjmp fails to restore stack first before restoring
signal mask on most architectures
 1.19 24-Apr-2025  riastradh sparc, sparc64 longjmp: Use _UC_SIGMASK to restore signal mask.

This way, restoring the signal mask and restoring the stack pointer
happen atomically with respect to signal handler calls, whereas using
sigprocmask would restore the signal mask _before_ the stack pointer,
breaking sigaltstack.

The motivation for using sigprocmask first and then setcontext later,
rather than _UC_SIGMASK in setcontext, was to get SA-based libpthead
sigprocmask interposition. But that's long gone and unlikely to come
back.

PR lib/57946: longjmp fails to restore stack first before restoring
signal mask on most architectures
 1.18 24-Apr-2025  riastradh mips longjmp: Use _UC_SIGMASK to restore signal mask.

This way, restoring the signal mask and restoring the stack pointer
happen atomically with respect to signal handler calls, whereas using
sigprocmask would restore the signal mask _before_ the stack pointer,
breaking sigaltstack.

The motivation for using sigprocmask first and then setcontext later,
rather than _UC_SIGMASK in setcontext, was to get SA-based libpthead
sigprocmask interposition. But that's long gone and unlikely to come
back.

PR lib/57946: longjmp fails to restore stack first before restoring
signal mask on most architectures
 1.17 24-Apr-2025  riastradh mips/compat_longjmp: Make sure compat13 setjmp returns nonzero.

PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
 1.16 24-Apr-2025  riastradh mips/compat_sigsetjmp: Add missing RESTORE_GP64.

Otherwise, compat13 sigsetjmp clobbers the caller's gp when it
returns (the first time around, anyway), which leads to a lovely
display of fireworks.

PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
 1.15 24-Apr-2025  riastradh mips/compat_setjmp: .set reorder doesn't have delay slots.

PR port-mips/59342: compat_setjmp.S is confused about delay slots
 1.14 24-Apr-2025  riastradh t_setjmp, t_sigstack: Test compat13 setjmp/sigsetjmp too.

PR port-mips/59342: compat_setjmp.S is confused about delay slots
PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64
 1.13 13-Apr-2025  riastradh hppa longjmp: Use _UC_SIGMASK to restore signal mask.

This way, restoring the signal mask and restoring the stack pointer
happen atomically with respect to signal handler calls, whereas using
sigprocmask would restore the signal mask _before_ the stack pointer,
breaking sigaltstack.

The motivation for using sigprocmask first and then setcontext later,
rather than _UC_SIGMASK in setcontext, was to get SA-based libpthead
sigprocmask interposition. But that's long gone and unlikely to come
back.

Tested under qemu with:

atf-run /usr/tests/lib/libc/setjmp | atf-report
atf-run /usr/tests/lib/libpthread/t_siglongjmp | atf-report

PR lib/57946: longjmp fails to restore stack first before restoring
signal mask on most architectures
 1.12 17-Jul-2024  uwe branches: 1.12.2; 1.12.4;
sh3: siglongjmp - restore register context first (PR lib/57946)
 1.11 06-May-2024  riastradh branches: 1.11.2;
tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.

PR lib/57946
 1.10 06-May-2024  skrll arm has been fixed
 1.9 04-Apr-2024  riastradh i386 longjmp: Restore stack first, then signal mask.

Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:

- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp

PR lib/57946
 1.8 04-Apr-2024  riastradh amd64 longjmp: Restore stack first, then signal mask.

Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:

- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use `xorl %eXX,%eXX' instead of `xorq %rXX,%rXX'.
=> Same effect, one byte shorter, breaks dep chain on more uarches.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp

PR lib/57946
 1.7 19-Feb-2024  riastradh longjmp(3) t_sigstack: Fix fencepost error.

Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.

PR lib/57946
 1.6 19-Feb-2024  riastradh longjmp(3) t_sigstack: Use a sigaltstack per handler entry.

longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack. So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.

With this change, the test now passes on aarch64.

PR lib/57946
 1.5 19-Feb-2024  riastradh longjmp(3) t_sigstack: Note aarch64 seems to DTRT.

But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.

PR lib/57946
 1.4 19-Feb-2024  riastradh longjmp(3) t_sigstack: Print which entry failed.

PR lib/57946
 1.3 19-Feb-2024  riastradh longjmp(3): Test signal mask vs stack restore with siglongjmp too.

PR lib/57946
 1.2 19-Feb-2024  riastradh longjmp(3): Paranoia: more error checking in PR lib/57946 test.
 1.1 19-Feb-2024  riastradh longjmp(3): Add test for PR lib/57946.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12.4.2 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #795):

tests/lib/libc/setjmp/Makefile: revision 1.3
distrib/sets/lists/debug/mi: revision 1.425
lib/libc/arch/sh3/gen/setjmp.S: revision 1.12
lib/libc/arch/i386/gen/sigsetjmp.S: revision 1.19
lib/libc/arch/x86_64/gen/__setjmp14.S: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.10
tests/lib/libc/setjmp/t_sigstack.c: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.12
tests/lib/libc/setjmp/t_sigstack.c: revision 1.1
lib/libc/arch/sh3/gen/sigsetjmp.S: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.2
tests/lib/libc/setjmp/t_sigstack.c: revision 1.3
tests/lib/libc/setjmp/t_sigstack.c: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.5
tests/lib/libc/setjmp/t_sigstack.c: revision 1.6
lib/libc/arch/arm/gen/setjmp.S: revision 1.19
tests/lib/libc/setjmp/t_sigstack.c: revision 1.7
tests/lib/libc/setjmp/t_sigstack.c: revision 1.8
tests/lib/libc/setjmp/t_sigstack.c: revision 1.9
lib/libc/arch/i386/gen/setjmp.S: revision 1.18
lib/libc/arch/x86_64/gen/__sigsetjmp14.S: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1306 (patch)

longjmp(3): Add test for PR lib/57946.

longjmp(3): Paranoia: more error checking in PR lib/57946 test.

longjmp(3): Test signal mask vs stack restore with siglongjmp too.
PR lib/57946

longjmp(3) t_sigstack: Print which entry failed.
PR lib/57946

longjmp(3) t_sigstack: Note aarch64 seems to DTRT.
But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.
PR lib/57946

longjmp(3) t_sigstack: Use a sigaltstack per handler entry.
longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack. So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.
With this change, the test now passes on aarch64.
PR lib/57946

longjmp(3) t_sigstack: Fix fencepost error.
Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.
PR lib/57946

amd64 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use `xorl %eXX,%eXX' instead of `xorq %rXX,%rXX'.
=> Same effect, one byte shorter, breaks dep chain on more uarches.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

i386 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

arm longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Move the botched sp and lr tests earlier.
PR lib/57946
arm has been fixed

tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.
PR lib/57946

sh3: siglongjmp - restore register context first (PR lib/57946)
 1.12.4.1 17-Jul-2024  martin file t_sigstack.c was added on branch netbsd-9 on 2024-08-23 16:59:51 +0000
 1.12.2.2 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #795):

tests/lib/libc/setjmp/Makefile: revision 1.3
distrib/sets/lists/debug/mi: revision 1.425
lib/libc/arch/sh3/gen/setjmp.S: revision 1.12
lib/libc/arch/i386/gen/sigsetjmp.S: revision 1.19
lib/libc/arch/x86_64/gen/__setjmp14.S: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.10
tests/lib/libc/setjmp/t_sigstack.c: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.12
tests/lib/libc/setjmp/t_sigstack.c: revision 1.1
lib/libc/arch/sh3/gen/sigsetjmp.S: revision 1.11
tests/lib/libc/setjmp/t_sigstack.c: revision 1.2
tests/lib/libc/setjmp/t_sigstack.c: revision 1.3
tests/lib/libc/setjmp/t_sigstack.c: revision 1.4
tests/lib/libc/setjmp/t_sigstack.c: revision 1.5
tests/lib/libc/setjmp/t_sigstack.c: revision 1.6
lib/libc/arch/arm/gen/setjmp.S: revision 1.19
tests/lib/libc/setjmp/t_sigstack.c: revision 1.7
tests/lib/libc/setjmp/t_sigstack.c: revision 1.8
tests/lib/libc/setjmp/t_sigstack.c: revision 1.9
lib/libc/arch/i386/gen/setjmp.S: revision 1.18
lib/libc/arch/x86_64/gen/__sigsetjmp14.S: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1306

longjmp(3): Add test for PR lib/57946.

longjmp(3): Paranoia: more error checking in PR lib/57946 test.

longjmp(3): Test signal mask vs stack restore with siglongjmp too.
PR lib/57946

longjmp(3) t_sigstack: Print which entry failed.
PR lib/57946

longjmp(3) t_sigstack: Note aarch64 seems to DTRT.
But only by code inspection; it appears to have another problem: on
re-entry, the signal handler is called on the normal stack, not on
the alternate signal stack.
PR lib/57946

longjmp(3) t_sigstack: Use a sigaltstack per handler entry.
longjmp evidently doesn't reset the state of whether the process is
executing on the alternate signal stack. So when we re-enter the
signal handler, the alternate stack appears to be still in use, and
the system chooses the original stack for the second call to the
signal handler -- which trips our assertion asking to verify that the
signal handler is always using an alternate stack.

Not strictly necessary for the signal handler to use an alternate
stack on re-entry, but this makes it clearer that the signal handler
itself is always using the alternate stack so we can verify that the
interrupted code is _not_ in the signal handler.
With this change, the test now passes on aarch64.
PR lib/57946

longjmp(3) t_sigstack: Fix fencepost error.
Extremely unlikely to cause trouble, but let's just turn that into
`never' to keep it easier for readers.
PR lib/57946

amd64 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use `xorl %eXX,%eXX' instead of `xorq %rXX,%rXX'.
=> Same effect, one byte shorter, breaks dep chain on more uarches.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

i386 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use forward branches for statically predicted not-taken.
=> val==0 is unlikely in longjmp
PR lib/57946

arm longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:
- Move the botched sp and lr tests earlier.
PR lib/57946
arm has been fixed

tests/lib/libc/setjmp/t_sigstack: Add missing comment for 1.10.
PR lib/57946

sh3: siglongjmp - restore register context first (PR lib/57946)
 1.12.2.1 17-Jul-2024  martin file t_sigstack.c was added on branch netbsd-10 on 2024-08-23 16:56:29 +0000
 1.2 14-Jan-2017  christos PR/51874: Ngie Cooper: Add __unused to signal handlers
 1.1 21-Apr-2011  martin branches: 1.1.26;
Add a variation of the setjmp tests that link to libpthread and verify
pthread_self() stays consistent.
 1.1.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.12 10-Nov-2023  christos PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE
 1.11 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.10 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.9 29-Sep-2019  mrg convert HAVE_GCC == 7 to HAVE_GCC >= 7.
 1.8 04-Feb-2019  mrg - tests explicitly check failure modes, ignore those warnings
 1.7 06-Apr-2014  christos branches: 1.7.24;
add stp*cpy() tests
 1.6 23-Sep-2012  joerg branches: 1.6.6;
Update LLVM/Clang snapshot to r164464. This adopts the GCC options for
the SSP parameters and a not-yet-default rewrite of SROA.
 1.5 04-Apr-2012  joerg branches: 1.5.2;
Disable new -Wstring-plus-int warning where needed for now.
Adjust various places that add GCC-only options to check for the active
compiler first.
 1.4 12-Jun-2011  plunky branches: 1.4.2;
reinstate ssp:raw test, slightly differently.. this one is built
with -fstack-protector-all and tests that the compiler built in
stack protection works, by poking directly outside the buffer
 1.3 12-Jun-2011  plunky don't pass -fstack-protector for these, the tests are actually for the
__*_chk functions included by -D_FORTIFY_SOURCE=2, and if the compiler
provides additional protection, it can mask broken functions..

(none of the _chk functions will return or process any data if
the length given is known to be larger than the buffer)
 1.2 26-Feb-2011  pgoyette branches: 1.2.2;
The ssp/raw test is useless. Remove it.
 1.1 27-Dec-2010  pgoyette branches: 1.1.2;
Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.2.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4.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.4.2.2 30-Oct-2012  yamt sync with head
 1.4.2.1 17-Apr-2012  yamt sync with head
 1.5.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6.6.1 10-Aug-2014  tls Rebase.
 1.7.24.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.24.1 10-Jun-2019  christos Sync with HEAD
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 10-Nov-2023  christos PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.2 16-Jan-2017  christos PR/51893: Ngie Cooper: prevent toolchain from optimizing out memset call
 1.1 27-Dec-2010  pgoyette branches: 1.1.28; 1.1.32;
Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1.32.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6 24-Jul-2011  christos make sum volatile to avoid printing
 1.5 23-Jul-2011  martin gcc optimizes away the side effect free call to the "poke" function which
is supposed to smash our stack in this test case.
So: make it print out some dummy value based on the smashing changes.
 1.4 15-Jun-2011  plunky branches: 1.4.2;
gcc seems to pad small character arrays, use an array of ints

while here, make the poke function non-static, so that it doesnt
get optimised away
 1.3 12-Jun-2011  plunky reinstate ssp:raw test, slightly differently.. this one is built
with -fstack-protector-all and tests that the compiler built in
stack protection works, by poking directly outside the buffer
 1.2 26-Feb-2011  pgoyette The ssp/raw test is useless. Remove it.
 1.1 27-Dec-2010  pgoyette branches: 1.1.2;
Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.4.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4.2.1 15-Jun-2011  cherry file h_raw.c was added on branch cherry-xenmp on 2011-06-23 14:20:39 +0000
 1.2 16-Jan-2017  christos PR/51894: Ngie Cooper: Use /dev/zero to read instead of stdin
 1.1 27-Dec-2010  pgoyette branches: 1.1.28; 1.1.32;
Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1.32.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 06-Apr-2014  christos branches: 1.1.2; 1.1.4; 1.1.8;
add stp*cpy() tests
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 06-Apr-2014  tls file h_stpcpy.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.4.2 10-Aug-2014  tls Rebase.
 1.1.4.1 06-Apr-2014  tls file h_stpcpy.c was added on branch tls-earlyentropy on 2014-08-10 06:57:21 +0000
 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 06-Apr-2014  yamt file h_stpcpy.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.2 07-Apr-2014  christos branches: 1.2.2; 1.2.4; 1.2.8;
fix lossage with gcc-4.5
 1.1 06-Apr-2014  christos add stp*cpy() tests
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 07-Apr-2014  tls file h_stpncpy.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.2.4.2 10-Aug-2014  tls Rebase.
 1.2.4.1 07-Apr-2014  tls file h_stpncpy.c was added on branch tls-earlyentropy on 2014-08-10 06:57:21 +0000
 1.2.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.2.2.1 07-Apr-2014  yamt file h_stpncpy.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.3 15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.2 28-Dec-2010  christos branches: 1.2.6;
allocate the buffer at the same function level as the compiler so that
the compiler knows to emit the right _chk call.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.2.6.1 17-Apr-2012  yamt sync with head
 1.3 15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.2 28-Dec-2010  christos branches: 1.2.6;
allocate the buffer at the same function level as the compiler so that
the compiler knows to emit the right _chk call.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.2.6.1 17-Apr-2012  yamt sync with head
 1.8 10-Nov-2023  christos PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE
 1.7 06-Apr-2014  christos add stp*cpy() tests
 1.6 10-Jan-2014  martin branches: 1.6.2;
In the strcat test, smash the stack more severely (this all may depend
on alignment and stack frame details).
The gcc folks disagree with this test in general:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59750
 1.5 12-Jun-2011  plunky branches: 1.5.2; 1.5.8;
reinstate ssp:raw test, slightly differently.. this one is built
with -fstack-protector-all and tests that the compiler built in
stack protection works, by poking directly outside the buffer
 1.4 26-Feb-2011  pgoyette branches: 1.4.2;
The ssp/raw test is useless. Remove it.
 1.3 25-Feb-2011  pgoyette Disable the "raw" test case. The test is bogus, and did not work before
conversion from src/regress/ to atf
 1.2 27-Dec-2010  pgoyette branches: 1.2.2;
Since atf_check doesn't deal with a pipeline, modify the tests to pipe
the output of the echo commands to atf_check itself. This fixes the
three new ssp failures.

Note that the raw, strcpy, vsprintf, and vsnprintf tests still fail, but
they failed in the old 'regress' style, too.
 1.1 27-Dec-2010  pgoyette Migrate the ssp tests from regress to atf.

Of the 17 tests, 4 fail in both the regress and atf style. 3 additional
tests fails in atf that did NOT fail in regress: gets, fgets, and read.
I will investigate why, and update when I can, but it is still useful to
get these tests into the new format where they can be exercised.
 1.2.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.4.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.5.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.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.6.2.1 10-Aug-2014  tls Rebase.
 1.16 08-Jul-2021  christos need to set BINDIR
 1.15 08-Jul-2021  christos Add interrupted I/O tests (from RVP)
 1.14 29-Jun-2020  jruoho Use -Wl,--no-fatal-warnings for the mktemp(3) test.
 1.13 27-Jun-2020  jruoho Move the test for mktemp(3) to the right place.
 1.12 15-Oct-2014  justin PR standards/49279 add tests for open_memstream, ported from OpenBSD
 1.11 25-Apr-2013  joerg Since the mktemp test case uses mktemp, make linker warnings non-fatal.
 1.10 22-Apr-2013  christos new mktemp test
 1.9 17-Feb-2012  christos branches: 1.9.2;
add positional argument tests
 1.8 11-Sep-2011  jruoho branches: 1.8.2;
Naive tests for the naive putc(3) family.
 1.7 11-Sep-2011  jruoho Few unit tests for the fopen(3) family.
 1.6 11-Sep-2011  jruoho Couple of unit tests for fflush(3).
 1.5 08-Jul-2011  jruoho Split out 't_printf' and 't_scanf' from 't_format' to gain the common
"functional scope" for the test files.
 1.4 01-May-2011  jruoho Naive tests for clearerr(3).

Converted from the "PCCA" test suite by Stathis Kamperis.
 1.3 23-Dec-2010  pgoyette Migrate a couple more tests to aft
 1.2 19-Nov-2010  njoly Add testcase for PR/44113: printf(3) should ignore zero padding for
nan/inf.
 1.1 24-Sep-2010  tnozaki add fmemopen(3) derrived from POSIX:2008.
libc minor bump.
 1.8.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.8.2.1 17-Apr-2012  yamt sync with head
 1.9.2.1 23-Jun-2013  tls resync from head
 1.6 11-Sep-2021  rillig tests/stdio: normalize whitespace
 1.5 10-Jul-2021  christos space before star
 1.4 09-Jul-2021  kre Make opts.cmd const char * rather than char * -- nothing ever modifies
the string it points to, it is never passed to a function not taking a
const char * arg, and this allows "" (or other literal strings if ever
needed) to be assigned to it - which should fix the build.
 1.3 09-Jul-2021  christos fixes from RVP
 1.2 08-Jul-2021  christos fix printf format strings
 1.1 08-Jul-2021  christos Add interrupted I/O tests (from RVP)
 1.1 08-Jul-2021  christos Add interrupted I/O tests (from RVP)
 1.2 05-Sep-2021  rillig tests/stdio: on test failure, print more details

On amd64, the test stdio_intr_iofbf fails:

stdout: numbers.in...iw.ir.ir. OK
stderr: h_testnumbers: bad line 3914889

This information is not enough to get a complete picture of the
situation, so provide more details.
 1.1 08-Jul-2021  christos Add interrupted I/O tests (from RVP)
 1.1 01-May-2011  jruoho Naive tests for clearerr(3).

Converted from the "PCCA" test suite by Stathis Kamperis.
 1.1 11-Sep-2011  jruoho Couple of unit tests for fflush(3).
 1.7 11-Sep-2021  rillig tests/stdio: normalize whitespace
 1.6 10-Jul-2021  martin Use intmax_t to printf an off_t
 1.5 10-Jul-2021  christos add more info to ease future debugging.
 1.4 19-Oct-2013  christos fix unused variable warnings
 1.3 22-Aug-2011  dholland branches: 1.3.2; 1.3.8;
Requires stdint.h.
 1.2 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 24-Sep-2010  tnozaki add fmemopen(3) derrived from POSIX:2008.
libc minor bump.
 1.3.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.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.8 21-Feb-2020  kamil Avoid undefined behavior in is_module_present()

t_fopen.c:339:18, member access within misaligned address 0x7f7ff7ebd004
for type 'modstat_t' (aka 'struct modstat') which requires 8 byte alignment
 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 05-Feb-2019  kamil Add 2 new tests in t_fopen

Added:
- fopen_nullptr (without COMPAT_10)
- fopen_nullptr_compat10 (with COMPAT_10)

PR kern/53948

Reviewed by <mgorny>
 1.5 06-Nov-2017  kre branches: 1.5.4;
In the fopen_regular and fopen_symlink tests, when (that is, if) a
failure occurs, distinguish in the failure message the cases where the
open succeeded (and should not have), and where it failed, but not for
the expected reason (the "wrong errno" case not tested, would require
manufacturing a broken kernel...).

Add O_NOFOLLOW ('l' mode modifier) tests to the fopen_mode test case
(tests that are intended to open the file) and also add a few missing
commas which were causing a few of the sub-tests to be skipped, and
others to be not quite testing exactly what was intended.
 1.4 06-Nov-2017  christos add a symlink test
 1.3 14-Sep-2011  martin A test case may not assume opening /dev/tty does something sensible.
 1.2 12-Sep-2011  jruoho Add one more case. Also remove a double fclose(3) and do not
steal stderr(3) as atf(7) may use it in case of failures.
 1.1 11-Sep-2011  jruoho Few unit tests for the fopen(3) family.
 1.5.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5.4.1 10-Jun-2019  christos Sync with HEAD
 1.6 08-Jul-2011  jruoho Split out 't_printf' and 't_scanf' from 't_format' to gain the common
"functional scope" for the test files.
 1.5 23-Dec-2010  pgoyette Fix the $NetBSD$ tag (missed the trailing $)
 1.4 21-Dec-2010  pgoyette Migrate a few more tests from old regress style to atf
 1.3 01-Dec-2010  pooka comment why vax is left out of all the fun
 1.2 22-Nov-2010  mrg vax doesn't have ieee fp, so, don't try to test ieee fp on vax.
 1.1 19-Nov-2010  njoly Add testcase for PR/44113: printf(3) should ignore zero padding for
nan/inf.
 1.1 11-Sep-2011  jruoho Naive tests for the naive putc(3) family.
 1.7 01-May-2024  gson Increase the estimate of disk space required for the test, as the old
estimate recently proved too optimistic on the amd64 testbed on b4.
 1.6 31-Oct-2021  gson Skip the test when there is insufficient disk space. Fixes PR misc/56324.
 1.5 09-Sep-2021  rillig tests/stdio: disable flappy test for EINTR with _IOFBF for now

This case is currently not handled correctly by fwrite/fflush, which
makes the test fail sometimes. The tests for _IONBF and _IOLBF are
pretty stable though.
 1.4 05-Sep-2021  rillig tests/stdio: use standard ATF tools for verifying the test output

In case of a test failure, this outputs a diff between the actual and
expected files.

Even with the smaller buffer size LMAX, the fully buffered test fails.
It does so after printing numbers up to 12773, which together take 65532
bytes. The next number, 12774, would cross the 65536 boundary, but
instead of that number, 12710730 was written.
 1.3 05-Sep-2021  rillig tests/stdio: wrap test command with atf_check

Previously, the test output was:

FAILED: Test case body returned a non-ok exit code, but this is
not allowed

In many cases, the test now succeeds, but in some cases it fails:

h_testnumbers: bad line "1287185
", expected 12774

h_testnumbers: bad line "6186889
", expected 6154889
 1.2 09-Jul-2021  christos fixes from RVP
 1.1 08-Jul-2021  christos Add interrupted I/O tests (from RVP)
 1.2 27-Jun-2020  jruoho Move the test for mktemp(3) to the right place.
 1.1 22-Apr-2013  christos branches: 1.1.2; 1.1.8;
new mktemp test
 1.1.8.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.8.1 22-Apr-2013  yamt file t_mktemp.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.1.2.2 23-Jun-2013  tls resync from head
 1.1.2.1 22-Apr-2013  tls file t_mktemp.c was added on branch tls-maxphys on 2013-06-23 06:28:56 +0000
 1.3 11-Sep-2021  rillig tests/stdio: normalize whitespace
 1.2 19-Oct-2014  justin Add negative offset checks to fseeko

These were not strictly needed before, as lseek would error on negative
arguments, but having added open_memstream we have a virtual file pointer
that assumes that it gets sane values, so we get an assertion triggered
on a negative value. Best to check in one place rather than at all the
relevant points.
 1.1 15-Oct-2014  justin PR standards/49279 add tests for open_memstream, ported from OpenBSD
 1.4 15-Feb-2013  christos look at my index finger
 1.3 13-Jul-2011  jruoho branches: 1.3.2; 1.3.8;
Rename few test case names. No functional change.
 1.2 11-Jun-2011  christos Turn warns on for all tests and fix all the bugs.
 1.1 23-Dec-2010  pgoyette branches: 1.1.4;
Migrate a couple more tests to aft
 1.1.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.3.8.1 25-Feb-2013  tls resync with head
 1.3.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.18 11-May-2024  riastradh tests/lib/libc/stdio/t_printf: Fix sign error in ld128 case.

Also link back to where the test case came from.
 1.17 11-May-2024  riastradh tests/lib/libc/stdio/t_printf: Fix typo in ld128 case.

printf %La does not write the `L' suffix.
 1.16 09-May-2024  riastradh tests/lib/libc/stdio/t_printf: Fix another rounding error.

Noted by kre.

This doesn't break a passing test or fix a failed test, at least on
x86 -- our printf produces `0x1.533p+3' for the double case and
`0xa.99ap+0' for the long double case. But of the hexadecimal number
literals that that start with 0x5 having three hexadigits to the
right of the fractional point, 0x5.4cdp+1 closest to the IEEE 754
binary64, VAX D, x86 extended precision, and IEEE 754 binary128
floating-point numbers closest to 10.6.

The reason is that the number 10.6 (or the nearest floating-point
number in any format with enough precision) is:

101.0100 1100 1100|1100... * 2^1 = 0x5.4cc|c...p+1

If we round at the vertical bar to the _nearest_ output with three
hexadigits of precision, the result is:

101.0100 1100 1101 * 2^1 = 0x5.4cdp+1
 1.15 09-May-2024  riastradh Revert various broken changes to printf %La (hldtoa).

This reverts:

hdtoa.c 1.12 (PR/56247: Greg A. Woods: printf("%La", LDBL_MIN) dumps core)
hdtoa.c 1.11 (fix tyop)
hdtoa.c 1.10 (Via enh at google dot com in tech-userlevel. Fix handling of
EXT_FRAC{H,L}BITS (although we don't need to since we don't have them).)

The underlying motivation for this change was that when ld128 is
decomposed into 4x32 words, this hldtoa logic is broken.

But we don't decompose ld128 into 4x32 words; we decompose it into
6x64 words.

And the change, which was supposed to be a noop in our case of 2x64
words (or similar for x87 80-bit floating-point), broke it to the
point of causing buffer overruns (PR 56247) which when worked around
led to just incorrect output output (PR 56937).

If we want to make the #ifdefs for 4x32 words work, that's fine, but
we absolutely must have automatic test cases to detect this kind of
regression because %La formatting is extremely important for
diagnosing details of floating-point data since it doesn't involve
rounding in binary formats. For now I've added some trivial tests;
there is a more extensive test suite inside gdtoa that we need to
wire up before anyone tries any other shenanigans in this code.

PR lib/56937: printf(3) long double %a formatting is broken
 1.14 08-May-2024  riastradh tests/lib/libc/stdio/t_printf: Add another %La test.

This one was adapted from the screw case shown in

https://mail-index.netbsd.org/tech-userlevel/2020/04/11/msg012329.html

which wasn't broken in our libc, but which nevertheless prompted us
to commit a wrong and apparently untested patch that has rendered
printf %La broken for the last four years, which is a little
embarrassing. (The part of that patch that led to a buffer overrun
has been worked around, so now the output is just incorrect.)

PR lib/56937: printf(3) long double %a formatting is broken
 1.13 08-May-2024  riastradh tests/lib/libc/stdio/t_printf: Fix %a test the same way.
 1.12 08-May-2024  riastradh tests/lib/libc/stdio/t_printf: Fix %La test.

0xa.99ap+0 is closer to (long double)10.6 in x86 ld80 and in
binary128 (and possibly more formats, haven't verified).
 1.11 08-May-2024  riastradh tests/lib/libc/stdio/t_printf: Add a couple simple %La tests.

PR lib/56937: printf(3) long double %a formatting is broken
 1.10 04-Apr-2023  he Fix the test for "inf" output, also include newline in printf format...
 1.9 04-Apr-2023  christos Add a test for PR/57250 from Havard Eidnes
 1.8 11-Apr-2012  jruoho branches: 1.8.34; 1.8.42;
Reduce the number of snprintf(3) invocations, as sparc/qemu timeouts.
 1.7 18-Mar-2012  jruoho Verify that PR lib/22019 is no longer an issue.
 1.6 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.5 15-Mar-2012  joerg Fix format strings to properly quote %.
 1.4 26-Feb-2012  christos add a test to verify that snprintf float does not leak.
 1.3 17-Feb-2012  christos add positional argument tests
 1.2 13-Jul-2011  jruoho branches: 1.2.2; 1.2.4;
Rename few test case names. No functional change.
 1.1 08-Jul-2011  jruoho Split out 't_printf' and 't_scanf' from 't_format' to gain the common
"functional scope" for the test files.
 1.2.4.1 17-Mar-2012  bouyer Pull up following revision(s) (requested by joerg in ticket #119):
tests/lib/libc/stdio/t_printf.c: revision 1.5
tests/lib/libc/stdio/t_scanf.c: revision 1.2
tests/lib/libc/gen/t_humanize_number.c: revision 1.6
Mark w_printf as __printflike and fix a format string error.
Fix format strings to properly quote %.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.8.42.2 22-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #787):

tests/lib/libc/stdio/t_printf.c: revision 1.17
tests/lib/libc/stdio/t_printf.c: revision 1.18
lib/libc/gdtoa/hdtoa.c: revision 1.13
tests/lib/libc/stdio/t_printf.c: revision 1.11
tests/lib/libc/stdio/t_printf.c: revision 1.12
tests/lib/libc/stdio/t_printf.c: revision 1.13
tests/lib/libc/stdio/t_printf.c: revision 1.14
tests/lib/libc/stdio/t_printf.c: revision 1.15
tests/lib/libc/stdio/t_printf.c: revision 1.16

tests/lib/libc/stdio/t_printf: Add a couple simple %La tests.

PR lib/56937: printf(3) long double %a formatting is broken
tests/lib/libc/stdio/t_printf: Fix %La test.
0xa.99ap+0 is closer to (long double)10.6 in x86 ld80 and in
binary128 (and possibly more formats, haven't verified).
tests/lib/libc/stdio/t_printf: Fix %a test the same way.
tests/lib/libc/stdio/t_printf: Add another %La test.

This one was adapted from the screw case shown in
https://mail-index.netbsd.org/tech-userlevel/2020/04/11/msg012329.html
which wasn't broken in our libc, but which nevertheless prompted us
to commit a wrong and apparently untested patch that has rendered
printf %La broken for the last four years, which is a little
embarrassing. (The part of that patch that led to a buffer overrun
has been worked around, so now the output is just incorrect.)

PR lib/56937: printf(3) long double %a formatting is broken

Revert various broken changes to printf %La (hldtoa).
This reverts:
hdtoa.c 1.12 (PR/56247: Greg A. Woods: printf("%La", LDBL_MIN) dumps core)
hdtoa.c 1.11 (fix tyop)
hdtoa.c 1.10 (Via enh at google dot com in tech-userlevel. Fix handling of
EXT_FRAC{H,L}BITS (although we don't need to since we don't have them).)

The underlying motivation for this change was that when ld128 is
decomposed into 4x32 words, this hldtoa logic is broken.

But we don't decompose ld128 into 4x32 words; we decompose it into
6x64 words.

And the change, which was supposed to be a noop in our case of 2x64
words (or similar for x87 80-bit floating-point), broke it to the
point of causing buffer overruns (PR 56247) which when worked around
led to just incorrect output output (PR 56937).
If we want to make the #ifdefs for 4x32 words work, that's fine, but
we absolutely must have automatic test cases to detect this kind of
regression because %La formatting is extremely important for
diagnosing details of floating-point data since it doesn't involve
rounding in binary formats. For now I've added some trivial tests;
there is a more extensive test suite inside gdtoa that we need to
wire up before anyone tries any other shenanigans in this code.

PR lib/56937: printf(3) long double %a formatting is broken
tests/lib/libc/stdio/t_printf: Fix another rounding error.
Noted by kre.

This doesn't break a passing test or fix a failed test, at least on
x86 -- our printf produces `0x1.533p+3' for the double case and
`0xa.99ap+0' for the long double case. But of the hexadecimal number
literals that that start with 0x5 having three hexadigits to the
right of the fractional point, 0x5.4cdp+1 closest to the IEEE 754
binary64, VAX D, x86 extended precision, and IEEE 754 binary128
floating-point numbers closest to 10.6.

The reason is that the number 10.6 (or the nearest floating-point
number in any format with enough precision) is:
101.0100 1100 1100|1100... * 2^1 = 0x5.4cc|c...p+1
If we round at the vertical bar to the _nearest_ output with three
hexadigits of precision, the result is:
101.0100 1100 1101 * 2^1 = 0x5.4cdp+1
tests/lib/libc/stdio/t_printf: Fix typo in ld128 case.
printf %La does not write the `L' suffix.
tests/lib/libc/stdio/t_printf: Fix sign error in ld128 case.

Also link back to where the test case came from.
 1.8.42.1 17-Apr-2023  martin Pull up following revision(s) (requested by he in ticket #138):

tests/lib/libc/stdio/t_printf.c: revision 1.9
tests/lib/libc/stdio/t_printf.c: revision 1.10

Add a test for PR/57250 from Havard Eidnes

Fix the test for "inf" output, also include newline in printf format...
 1.8.34.2 22-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1866):

tests/lib/libc/stdio/t_printf.c: revision 1.17
tests/lib/libc/stdio/t_printf.c: revision 1.18
tests/lib/libc/stdio/t_printf.c: revision 1.11
tests/lib/libc/stdio/t_printf.c: revision 1.12
tests/lib/libc/stdio/t_printf.c: revision 1.13
tests/lib/libc/stdio/t_printf.c: revision 1.14
tests/lib/libc/stdio/t_printf.c: revision 1.15
tests/lib/libc/stdio/t_printf.c: revision 1.16
(all via patch)

tests/lib/libc/stdio/t_printf: Add a couple simple %La tests.

PR lib/56937: printf(3) long double %a formatting is broken
tests/lib/libc/stdio/t_printf: Fix %La test.
0xa.99ap+0 is closer to (long double)10.6 in x86 ld80 and in
binary128 (and possibly more formats, haven't verified).
tests/lib/libc/stdio/t_printf: Fix %a test the same way.
tests/lib/libc/stdio/t_printf: Add another %La test.

This one was adapted from the screw case shown in
https://mail-index.netbsd.org/tech-userlevel/2020/04/11/msg012329.html
which wasn't broken in our libc, but which nevertheless prompted us
to commit a wrong and apparently untested patch that has rendered
printf %La broken for the last four years, which is a little
embarrassing. (The part of that patch that led to a buffer overrun
has been worked around, so now the output is just incorrect.)

PR lib/56937: printf(3) long double %a formatting is broken
tests/lib/libc/stdio/t_printf: Fix another rounding error.
Noted by kre.

This doesn't break a passing test or fix a failed test, at least on
x86 -- our printf produces `0x1.533p+3' for the double case and
`0xa.99ap+0' for the long double case. But of the hexadecimal number
literals that that start with 0x5 having three hexadigits to the
right of the fractional point, 0x5.4cdp+1 closest to the IEEE 754
binary64, VAX D, x86 extended precision, and IEEE 754 binary128
floating-point numbers closest to 10.6.

The reason is that the number 10.6 (or the nearest floating-point
number in any format with enough precision) is:
101.0100 1100 1100|1100... * 2^1 = 0x5.4cc|c...p+1

If we round at the vertical bar to the _nearest_ output with three
hexadigits of precision, the result is:
101.0100 1100 1101 * 2^1 = 0x5.4cdp+1

tests/lib/libc/stdio/t_printf: Fix typo in ld128 case.
printf %La does not write the `L' suffix.

tests/lib/libc/stdio/t_printf: Fix sign error in ld128 case.
Also link back to where the test case came from.
 1.8.34.1 22-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1865):

lib/libc/stdio/Makefile.inc: revision 1.48
tests/lib/libc/stdio/t_printf.c: revision 1.9
lib/libc/stdio/vfwprintf.c: revision 1.40
lib/libc/include/extern.h: revision 1.27
tests/lib/libc/stdio/t_printf.c: revision 1.10

PR/57250: Martin Husemann: dtoa mishandles infinite doubles on 32bit big
endian machines. When long double support was added, the old code was kept
for the regular double code. This code was never used because WIDE_DOUBLE
was always defined in the Makefile. Remove that old code, and conditionalize
the WIDE_DOUBLE code based on if long doubles are different than doubles on
the specific platform.

Add a test for PR/57250 from Havard Eidnes

Fix the test for "inf" output, also include newline in printf format...
 1.4 11-Sep-2021  rillig tests/stdio: normalize whitespace
 1.3 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.2 15-Mar-2012  joerg Fix format strings to properly quote %.
 1.1 08-Jul-2011  jruoho branches: 1.1.2; 1.1.4;
Split out 't_printf' and 't_scanf' from 't_format' to gain the common
"functional scope" for the test files.
 1.1.4.1 17-Mar-2012  bouyer Pull up following revision(s) (requested by joerg in ticket #119):
tests/lib/libc/stdio/t_printf.c: revision 1.5
tests/lib/libc/stdio/t_scanf.c: revision 1.2
tests/lib/libc/gen/t_humanize_number.c: revision 1.6
Mark w_printf as __printflike and fix a format string error.
Fix format strings to properly quote %.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2 13-Jul-2010  jmmv Get rid of static Atffiles and let bsd.test.mk generate them on the fly.
 1.1 20-Jul-2009  joerg Add a fast, platform independent hash function to libc.
The algorithm used is the Jenkins hash. The name (mi_vector_hash)
reflects the nature of the hash function.
Add glue for libc ATF tests and include a test case to make sure that
(mis)alignment and endianess are handled correctly.

Bump libc minor to 169.
 1.36 18-Sep-2025  mrg introduce a couple of new turn-off-gcc-warning variables and use them.

GCC 14 has a new annoying calloc() checker that we turn off in a bunch
of places, and there are a few more dangling-pointer issuse that come up,
but seem bogus.
 1.35 02-Mar-2025  riastradh libc: New _r variants of heapsort, mergesort, qsort.

Also kheapsort_r for kernel/standalone use.

These variants allow the caller to pass a cookie through to the
comparison function, e.g. if you want to sort an array of indices
into a buffer.

qsort_r is new in POSIX.1-2024; the others are obvious analogues of
our nonstandard extensions for heapsort and mergesort.

PR lib/58931: qsort_r() missing
 1.34 04-Jul-2023  riastradh branches: 1.34.2;
t_posix_memalign: Expand test cases and properties.

- Test cartesian product of a sampling of sizes and a sampling of
alignments.

- Verify all the edge cases I could find in posix_memalign and
aligned_alloc, including failure modes.

- Test an unreasonably large (but aligned) allocation size.

- Use ATF_CHECK_* instead of ATF_REQUIRE_* so all failures will be
reported, not just the first one.

- While here, build with -fno-builtin-aligned_alloc and with
-fno-builtin-posix_memalign to make sure the compiler doesn't try
any shenanigans.

XXX pullup-10
 1.33 01-Jul-2020  jruoho branches: 1.33.6;
Add basic checks for a64l(3), l64a(3), and l64a_r(3).
 1.32 30-Jun-2020  jruoho After a comedy of errors, move t_mbtowc to its final resting place.
 1.31 29-Jun-2020  jruoho Use -Wl,--no-fatal-warnings for the mktemp(3) test.
 1.30 27-Jun-2020  jruoho Start moving the remaining tests from src/regress to src/tests.
 1.29 27-Jun-2020  jruoho Move the test for mktemp(3) to the right place.
 1.28 22-Dec-2015  christos Add __TEST_FENV
 1.27 22-Dec-2015  martin Sync list of fenv enabled architectures again (PR 48633), this time for mips
addition.
 1.26 21-Dec-2015  martin While PR 48633 is not properly fixed, keep the additional lists of
fenv-enabled architectures in sync.
 1.25 01-May-2015  christos - new test for strtoi
- namespace protection for strto{i,u}
- separate manpages for strto{i,u} from the ones for strto{u,}l
From: Kamil Rytarowski
 1.24 27-Dec-2014  martin Move the list of <fenv.h> supporting architectures to the makefile and
sync it with other copies.
 1.23 04-Apr-2012  joerg branches: 1.23.10;
Try fixing t_strtod to not depend on -ffloat-store by adding the
necessary volatiles.
 1.22 29-Mar-2012  jruoho Few fundamental consistency checks for the abs(3) family.
 1.21 29-Mar-2012  jruoho Few naive consistency checks for the atoi(3) family.
 1.20 28-Mar-2012  jruoho Add a small test that checks that random(3) does not always return zero when
the RNG is initialized with zero. Prompoted by the recent nasty bug in the
OpenBSD libc.
 1.19 24-Feb-2012  joerg Restrict -ffloat-store to t_strtod.c.
 1.18 11-Sep-2011  jruoho branches: 1.18.2;
See that system(3) works.
 1.17 15-Jul-2011  jruoho Fix wrong linker flag that has always been lurking here.
 1.16 15-Jul-2011  jruoho Split out the -lpthread tests to a separate file.

XXX: The only thing gained from this is seeing whether -lpthread breaks
the getenv(3) family. Yet, a strict hypothesis about this would require
that the two test files are identical, which they are not.
 1.15 07-Jul-2011  jruoho Merge 't_environment' and 't_environment_pth'.
 1.14 04-Jun-2011  jruoho Add some tests for strtol(3).
 1.13 04-Jun-2011  jruoho Add -ffloat-store add test lib/45020 also with __isnanl().
 1.12 09-May-2011  jruoho branches: 1.12.2;
Few basic tests for exit(3).
 1.11 05-Apr-2011  jruoho Try to maintain the structure of libc and move 't_strtox' to 't_strtod'.
 1.10 05-Apr-2011  jruoho Add simple test cases for ttyname(3), strtod(3), and getgrent(3).
 1.9 13-Jan-2011  pgoyette Moving t_hsearch - belongs in stdlib/
 1.8 12-Jan-2011  pgoyette Put the atexit test where it belongs - in libc/stdlib/
 1.7 01-Jan-2011  pgoyette Convert a few more tests from regress to atf
 1.6 23-Dec-2010  pgoyette Migrate a couple more tests to aft
 1.5 03-Dec-2010  njoly Add testcase for PR/44189: strtod(3) wrong results with "-0x".
 1.4 16-Nov-2010  tron Split threaded environment test for the other environment tests as
suggested by Nicolas Joly in private e-mail. Linking a binary with
"libpthread" effects the beaviour of "libc" and we really want to
test both cases.
 1.3 14-Nov-2010  tron Add a new regression test "t_threaded" which tests using getenv_r(3),
putenv(3), setenv(3) and unsetenv(3) concurrently.
 1.2 23-Sep-2010  christos unit test for environment. Grr, someone should make fixing the sets easier
otherwise people are not going to want to write unit-tests.
 1.1 20-Jul-2009  joerg Add a fast, platform independent hash function to libc.
The algorithm used is the Jenkins hash. The name (mi_vector_hash)
reflects the nature of the hash function.
Add glue for libc ATF tests and include a test case to make sure that
(mis)alignment and endianess are handled correctly.

Bump libc minor to 169.
 1.12.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.18.2.1 17-Apr-2012  yamt sync with head
 1.23.10.1 16-May-2015  snj Pull up following revision(s) (requested by christos in ticket #781):
common/lib/libc/stdlib/strtoi.c: revision 1.2
common/lib/libc/stdlib/strtou.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.113
distrib/sets/lists/tests/mi: revision 1.617
lib/libc/include/namespace.h: revision 1.178
lib/libc/stdlib/Makefile.inc: revision 1.90 via patch
lib/libc/stdlib/strtoi.3: revisions 1.1, 1.2
lib/libc/stdlib/strtol.3: revision 1.32
lib/libc/stdlib/strtou.3: revisions 1.1, 1.2
lib/libc/stdlib/strtoul.3: revisions 1.30, 1.31
tests/lib/libc/stdlib/Makefile: revision 1.25
tests/lib/libc/stdlib/t_strtoi.c: revision 1.1
- new test for strtoi
- namespace protection for strto{i,u}
- separate manpages for strto{i,u} from the ones for strto{u,}l
From: Kamil Rytarowski
--
Sort ERRORS and SEE ALSO.
--
Sort ERRORS and SEE ALSO.
--
Sort SEE ALSO.
 1.33.6.1 24-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #808):

tests/lib/libc/stdlib/t_posix_memalign.c: revision 1.6
tests/lib/libc/stdlib/t_posix_memalign.c: revision 1.7
tests/lib/libc/stdlib/Makefile: revision 1.34

t_posix_memalign: Expand test cases and properties.
- Test cartesian product of a sampling of sizes and a sampling of
alignments.
- Verify all the edge cases I could find in posix_memalign and
aligned_alloc, including failure modes.
- Test an unreasonably large (but aligned) allocation size.
- Use ATF_CHECK_* instead of ATF_REQUIRE_* so all failures will be
reported, not just the first one.
- While here, build with -fno-builtin-aligned_alloc and with
-fno-builtin-posix_memalign to make sure the compiler doesn't try
any shenanigans.

t_posix_memalign: Fix this to reflect restriction lifted in C17.
 1.34.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 12-Jan-2011  pgoyette Put the atexit test where it belongs - in libc/stdlib/
 1.1 01-Jan-2011  pgoyette Convert a few more tests from regress to atf
 1.1 01-Jan-2011  pgoyette Convert a few more tests from regress to atf
 1.3 02-Mar-2025  riastradh branches: 1.3.4;
tests/lib/libc/stdlib/h_sort: Reserve room for a NUL byte.

PR lib/58931: qsort_r() missing
 1.2 02-Mar-2025  riastradh t_sort: Test mergesort for stability too.

These test cases are trivial, but they're enough to trigger unstable
heapsort and qsort.

Fix some error branches while here.

PR lib/58931: qsort_r() missing
 1.1 02-Mar-2025  riastradh libc: New _r variants of heapsort, mergesort, qsort.

Also kheapsort_r for kernel/standalone use.

These variants allow the caller to pass a cookie through to the
comparison function, e.g. if you want to sort an array of indices
into a buffer.

qsort_r is new in POSIX.1-2024; the others are obvious analogues of
our nonstandard extensions for heapsort and mergesort.

PR lib/58931: qsort_r() missing
 1.3.4.2 02-Aug-2025  perseant Sync with HEAD
 1.3.4.1 02-Mar-2025  perseant file h_sort.c was added on branch perseant-exfatfs on 2025-08-02 05:58:06 +0000
 1.1 01-Jul-2020  jruoho Add basic checks for a64l(3), l64a(3), and l64a_r(3).
 1.3 01-Mar-2014  joerg Fix sign.
 1.2 27-Feb-2014  joerg Don't use integer downcasts, use correctly sized constants for each test.
 1.1 29-Mar-2012  jruoho branches: 1.1.2; 1.1.4;
Few fundamental consistency checks for the abs(3) family.
 1.1.4.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 17-Apr-2012  yamt sync with head
 1.1.2.1 29-Mar-2012  yamt file t_abs.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.2 10-Jul-2017  joerg Reference correct binary in error messages.
 1.1 12-Jan-2011  pgoyette branches: 1.1.38;
Put the atexit test where it belongs - in libc/stdlib/
 1.1.38.1 01-Sep-2017  martin Pull up following revision(s) (requested by joerg in ticket #255):
tests/lib/libc/stdlib/t_atexit.sh: revision 1.2
Reference correct binary in error messages.
 1.3 03-Feb-2019  mrg - enlarge buffer to avoid snprintf() truncation
 1.2 29-Mar-2012  jruoho branches: 1.2.2; 1.2.34;
There was also atoll(3).
 1.1 29-Mar-2012  jruoho Few naive consistency checks for the atoi(3) family.
 1.2.34.1 10-Jun-2019  christos Sync with HEAD
 1.2.2.2 17-Apr-2012  yamt sync with head
 1.2.2.1 29-Mar-2012  yamt file t_atoi.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.2 07-Jul-2011  jruoho Rename some test case names. No functional change.
 1.1 23-Dec-2010  pgoyette Migrate a couple more tests to aft
 1.13 07-Jul-2011  jruoho Merge 't_environment' and 't_environment_pth'.
 1.12 16-Nov-2010  tron Split threaded environment test for the other environment tests as
suggested by Nicolas Joly in private e-mail. Linking a binary with
"libpthread" effects the beaviour of "libc" and we really want to
test both cases.
 1.11 14-Nov-2010  tron Add a new regression test "t_threaded" which tests using getenv_r(3),
putenv(3), setenv(3) and unsetenv(3) concurrently.
 1.10 14-Nov-2010  tron Update tests for *env(3):
- Introduce randomness into "t_setenv" to avoid freeing environment
variables exactly in the order they have been allocated.
Also call unsetenv(3) twice to make sure it behaves well if the
environment variable doesn't exist.
- "t_getenv" is no longer a known failure after getenv(3) and getenv_r(3)
have been fixed.
 1.9 13-Nov-2010  tron Add a test for getenv(3) which fails at the moment because it doesn't
handle "=" in variable names properly.

I'll send out a diff for review soon which fixes this.
 1.8 13-Nov-2010  tron Improve testing of environment handling:
1.) Always check the return value of setenv(3) and unsetenv(3).
2.) Test that calling setenv(..., ..., 0) doesn't overwrite environment
variables.
3.) Add a new test which mixes putenv(3) and setenv(3).
 1.7 09-Nov-2010  pooka This test is cursed.

Yesterday I thought I committed the increased timeout and when the
test was still failing for the autotests n hours later I noticed
I had actually failed to commit it. I did manage to commit something
in the evening, but the autotests were still failing this morning,
so I noticed I increased the timeout of the wrong test. I wonder
what will go wrong this time...

(and p.s.: 10240 is probably slow because it's O(n^2) with a constant
of quite a few)
 1.6 08-Nov-2010  pooka Increase timeout from 30 to 300 since this test runs for a long time.

XXX1: should 2x10240 loops really be *that* slow?
XXX2: is 10240 a sensible number to begin with?
 1.5 03-Nov-2010  christos add a clearenv test.
 1.4 25-Oct-2010  njoly Make putenv(3) fails with EINVAL for a null pointer, or for a string
that either miss or start with a `=' character.

Adjust man page and testcase accordingly.
 1.3 16-Oct-2010  njoly Make setenv(3) follow the standard, by rejecting invalid strings. It
now fails with EINVAL errno when variable is NULL, empty or contains
an `=' character; or value is NULL.

Adjust the man page accordingly, and exercize them in the existing
environment testcase.
 1.2 01-Oct-2010  christos Add tests for putenv(3)
 1.1 23-Sep-2010  christos unit test for environment. Grr, someone should make fixing the sets easier
otherwise people are not going to want to write unit-tests.
 1.3 07-Jul-2011  jruoho Merge 't_environment' and 't_environment_pth'.
 1.2 17-Nov-2010  tron Put my name in the author section.
 1.1 16-Nov-2010  tron Split threaded environment test for the other environment tests as
suggested by Nicolas Joly in private e-mail. Linking a binary with
"libpthread" effects the beaviour of "libc" and we really want to
test both cases.
 1.1 09-May-2011  jruoho Few basic tests for exit(3).
 1.3 27-Feb-2015  martin Double the timeout for sentev_basic to 600 seconds to make it work on
slower machines.
 1.2 15-Jul-2011  jruoho Split out the -lpthread tests to a separate file.

XXX: The only thing gained from this is seeing whether -lpthread breaks
the getenv(3) family. Yet, a strict hypothesis about this would require
that the two test files are identical, which they are not.
 1.1 07-Jul-2011  jruoho Merge 't_environment' and 't_environment_pth'.
 1.2 15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.1 15-Jul-2011  jruoho branches: 1.1.2;
Split out the -lpthread tests to a separate file.

XXX: The only thing gained from this is seeing whether -lpthread breaks
the getenv(3) family. Yet, a strict hypothesis about this would require
that the two test files are identical, which they are not.
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.3 10-May-2023  gutteridge t_getopt.sh: fix naming of head() of getopt_optval test case
 1.2 20-Feb-2023  christos New optval test from des @ FreeBSD
 1.1 01-Jan-2011  pgoyette Convert a few more tests from regress to atf
 1.4 20-Jul-2014  christos amend the new destroy function to take function pointers.
 1.3 15-Sep-2011  christos branches: 1.3.8; 1.3.18;
add the reentrant function tests (copies of the non-reentrant one).
 1.2 07-Jul-2011  jruoho Rename some test case names. No functional change.
 1.1 13-Jan-2011  pgoyette Moving t_hsearch - belongs in stdlib/
 1.3.18.1 10-Aug-2014  tls Rebase.
 1.3.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4 30-Jun-2020  jruoho After a comedy of errors, move t_mbtowc to its final resting place.
 1.3 29-Jun-2020  maya Avoid copyright issues and name the listed author as the copyright holder.

In a private email, Miloslav had agreed that if they had written the
test, then it can be licensed bsd-2-clause. I am going to assume this
is true as the file names Miloslav as the author.

This test was likely sent to tcsh (not netbsd) that had changed bug
report systems since.
 1.2 27-Jun-2020  jruoho Add the default TNF copyright (2005), cf. PR misc/55419.
 1.1 27-Jun-2020  jruoho Start moving the remaining tests from src/regress to src/tests.
 1.3 07-Jul-2011  jruoho Rename some test case names. No functional change.
 1.2 20-Jul-2009  joerg Use __RCSID.
 1.1 20-Jul-2009  joerg Add a fast, platform independent hash function to libc.
The algorithm used is the Jenkins hash. The name (mi_vector_hash)
reflects the nature of the hash function.
Add glue for libc ATF tests and include a test case to make sure that
(mis)alignment and endianess are handled correctly.

Bump libc minor to 169.
 1.4 11-Jan-2021  christos Only try to create up-to NAME_MAX filenames.
XXX: this should be moved to stdio/t_mktemp.c where the rest of the tests
are and the code lives.
 1.3 01-Nov-2020  gson Make the mkstemps_basic and mkostemps_basic test cases not randomly
fail when the replacement string happens to contain the letter "y".
 1.2 01-Jul-2020  jruoho Add basic tests for the rest of the mktemp(3) family of functions, including
a case for PR lib/55441.
 1.1 27-Jun-2020  jruoho Move the test for mktemp(3) to the right place.
 1.8 05-Jul-2023  riastradh t_posix_memalign: Simplify.

No functional change intended.
 1.7 05-Jul-2023  riastradh t_posix_memalign: Fix this to reflect restriction lifted in C17.
 1.6 04-Jul-2023  riastradh t_posix_memalign: Expand test cases and properties.

- Test cartesian product of a sampling of sizes and a sampling of
alignments.

- Verify all the edge cases I could find in posix_memalign and
aligned_alloc, including failure modes.

- Test an unreasonably large (but aligned) allocation size.

- Use ATF_CHECK_* instead of ATF_REQUIRE_* so all failures will be
reported, not just the first one.

- While here, build with -fno-builtin-aligned_alloc and with
-fno-builtin-posix_memalign to make sure the compiler doesn't try
any shenanigans.

XXX pullup-10
 1.5 29-Jul-2018  maya branches: 1.5.10;
Don't require size to be a multiple of alignment. This is no longer a
requirement as of C18.
 1.4 07-Nov-2015  nros branches: 1.4.14; 1.4.16;
Fix code style errors pointed out by christos during the review of the
aligned_alloc test that also applies to the posix_memalign test.
Fix code style errors that I forgot to fix in the aligned_alloc test.
 1.3 07-Nov-2015  nros Add the C11 function aligned_alloc to libc.
 1.2 07-Jul-2011  jruoho Rename some test case names. No functional change.
 1.1 01-Jan-2011  pgoyette Convert a few more tests from regress to atf
 1.4.16.1 10-Jun-2019  christos Sync with HEAD
 1.4.14.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.5.10.1 24-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #808):

tests/lib/libc/stdlib/t_posix_memalign.c: revision 1.6
tests/lib/libc/stdlib/t_posix_memalign.c: revision 1.7
tests/lib/libc/stdlib/Makefile: revision 1.34

t_posix_memalign: Expand test cases and properties.
- Test cartesian product of a sampling of sizes and a sampling of
alignments.
- Verify all the edge cases I could find in posix_memalign and
aligned_alloc, including failure modes.
- Test an unreasonably large (but aligned) allocation size.
- Use ATF_CHECK_* instead of ATF_REQUIRE_* so all failures will be
reported, not just the first one.
- While here, build with -fno-builtin-aligned_alloc and with
-fno-builtin-posix_memalign to make sure the compiler doesn't try
any shenanigans.

t_posix_memalign: Fix this to reflect restriction lifted in C17.
 1.3 29-Mar-2012  jruoho branches: 1.3.2;
Adjust as per apb@'s suggestion.
 1.2 28-Mar-2012  jruoho Apparently there is a CVE coming for the bug, so append that to a comment.
 1.1 28-Mar-2012  jruoho Add a small test that checks that random(3) does not always return zero when
the RNG is initialized with zero. Prompoted by the recent nasty bug in the
OpenBSD libc.
 1.3.2.2 17-Apr-2012  yamt sync with head
 1.3.2.1 29-Mar-2012  yamt file t_random.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.2 02-Mar-2025  riastradh branches: 1.2.4;
t_sort: Test mergesort for stability too.

These test cases are trivial, but they're enough to trigger unstable
heapsort and qsort.

Fix some error branches while here.

PR lib/58931: qsort_r() missing
 1.1 02-Mar-2025  riastradh libc: New _r variants of heapsort, mergesort, qsort.

Also kheapsort_r for kernel/standalone use.

These variants allow the caller to pass a cookie through to the
comparison function, e.g. if you want to sort an array of indices
into a buffer.

qsort_r is new in POSIX.1-2024; the others are obvious analogues of
our nonstandard extensions for heapsort and mergesort.

PR lib/58931: qsort_r() missing
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 02-Mar-2025  perseant file t_sort.sh was added on branch perseant-exfatfs on 2025-08-02 05:58:06 +0000
 1.39 07-Apr-2025  riastradh tests/lib/libc/stdlib/t_strtod: Fix strtod_gherman_bug build on VAX.

A typo (DBL_MANG_DIG) excluded this whole block, so my attempts to
compile-test it failed to find the build errors. Oops!

PR port-vax/59264: t_strtod:strtod_gherman_bug test is failing
 1.38 07-Apr-2025  riastradh tests/lib/libc/stdlib/t_strtod: Adapt strtod_gherman_bug to VAX.

PR port-vax/59264: t_strtod:strtod_gherman_bug test is failing
 1.37 15-Jun-2024  rillig branches: 1.37.2;
tests/strtold: test a few simple examples
 1.36 06-May-2024  riastradh tests/lib/libc/stdlib/t_strtod: Spruce up and nix needless #ifdefs.
 1.35 14-Jan-2024  andvar s/rouding/rounding/ in test description.
 1.34 22-Dec-2015  christos Put have fenv elsewhere.
 1.33 27-Dec-2014  martin Move the list of <fenv.h> supporting architectures to the makefile and
sync it with other copies.
 1.32 04-Nov-2014  justin 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.31 26-Sep-2012  jruoho Remove expected failures that no longer fail (probably due a Qemu update).
 1.30 15-May-2012  alnsn branches: 1.30.2;
Test a bug found by Geza Herman.
 1.29 04-Apr-2012  joerg Try fixing t_strtod to not depend on -ffloat-store by adding the
necessary volatiles.
 1.28 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.27 30-Sep-2011  jruoho branches: 1.27.2;
Add expected failures for Qemu.
 1.26 29-Aug-2011  jruoho Remove some cruft that is no longer needed.
 1.25 29-Aug-2011  jruoho Remove Xfails that are related to the infamous qemu/amd64 floating point
bugs. It appears to be quite difficult to identify the exact Qemu version
and setup. These do not fail on the TNF's qemu/amd64 setup, which can be
taken as a reference point for expected failures.
 1.24 08-Jul-2011  jruoho Remove the amd64-part from the Qemu checks. The following tests fail also on
i386/qemu: 'strtold_inf', 'strtold_nan', and 'infinity_long_double'. It seems
that more than anything else, these are dependent on the used Qemu version.
 1.23 07-Jul-2011  jruoho Improve the QEMU/amd64 detection.
 1.22 04-Jul-2011  mrg XXX: ugly hack to make these valid for vax fp.
XXX: could consolidate some of this into a common header, but i'll
leave that clean up for another time.
 1.21 14-Jun-2011  jruoho The NaN case for strtold(3) was fixed for x86. Adjust for the expected
failures (known failures include again the special case of qemu/amd64).
 1.20 07-Jun-2011  martin Sparc64 does not fail the strtold_nan test, so don't expect failure there
 1.19 05-Jun-2011  jruoho Granularity is fine, but also adjust atf_tc_expect_fail() properly.
 1.18 05-Jun-2011  jmmv Do not blindly skip test code.

Tests are not supposed to skip whole parts of code to later report a success.
Instead, they need to report a 'skipped' result so that it is clear to the
user that some part of the tests were not run.

To do this, add proper calls to atf_tc_skip where some pieces of code are
skipped. Also, make the strtod/strtof/strtold inf and nan tests more granular
so that the *ld versions can be skipped altogether when there is no support
for them. As a result of this, the atf_tc_expect_fail becomes accurate; it
could have hidden bugs in strtod and strtof before.
 1.17 05-Jun-2011  christos - use c99 to avoid extra ifdefs and tidy up the code
- require that undeflow returns 0 and ERANGE
 1.16 04-Jun-2011  matt Only do the long double tests if __HAVE_LONG_DOUBLE is defined
 1.15 04-Jun-2011  jruoho Add -ffloat-store add test lib/45020 also with __isnanl().
 1.14 04-Jun-2011  jruoho Add more strings to the "infinity test".
 1.13 04-Jun-2011  jruoho Verify PR lib/45020. Fails at least on amd64.
 1.12 31-May-2011  jruoho branches: 1.12.2;
Mark the following tests as expected failures on qemu/amd64: 'strtod_inf',
'strtod_round', and 'infinity_long_double'. None of these fail on any known
native host. Use the tracker PR misc/44767 as the reference point.
 1.11 20-May-2011  nakayama Add fenv support for sparc. Mostly copied from sparc64 and share with it.
 1.10 16-May-2011  he The support of <fenv.h> is actually for __sparc64__, not for __sparc__
(which is also defined on sparc64). This fixes a build problem for
plain sparc.
 1.9 10-May-2011  jruoho Use the same conditional check from <fenv.h> to fix an immediate build error
pointed out by cliff@. (This does not however sound like a sane thing to
mandate from a C99 header.)
 1.8 10-May-2011  jruoho Verify that strtod(3) honors the current rounding mode set by fesetround(3).
Passes on amd64. Prompted by a bug in the GNU C library.
 1.7 12-Apr-2011  jruoho Better to still leave the old PR number as a comment.
 1.6 12-Apr-2011  jruoho PR lib/33262 should be fixed; remove expected failure.
 1.5 10-Apr-2011  jruoho Currently known failures affect only amd64; adjust atf_tc_expect_fail().
 1.4 08-Apr-2011  jruoho Fix build failure on VAX.
 1.3 06-Apr-2011  jruoho Verify the existence of PR lib/33262.
 1.2 05-Apr-2011  jruoho Try to maintain the structure of libc and move 't_strtox' to 't_strtod'.
 1.1 05-Apr-2011  jruoho Add simple test cases for ttyname(3), strtod(3), and getgrent(3).
 1.12.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.27.2.3 30-Oct-2012  yamt sync with head
 1.27.2.2 23-May-2012  yamt sync with head.
 1.27.2.1 17-Apr-2012  yamt sync with head
 1.30.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.37.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 24-Jul-2024  kre Add some test cases to tests/lib/libc/stdlib/t_strtoi

PR lib/58461 PR lib/58453

Apologies for the previous commit message - I managed to
forget to include the message filename after commit -F
and so used the file being committed (the only changed file
in the directory) as the log message. (Fortunately that
meant that the log didn't get appended to the PR).

For the PR, the command to check what actually changed is

cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/stdlib/t_strtoi.c

rather than what will be reported below.

This commit message really belongs to the previous commit,
(1.5) there are no changes at all in this one.

No pullups required.
 1.4 24-Jul-2024  kre /* $NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $ */

/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jukka Ruohonen.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/*
* Created by Kamil Rytarowski, based on ID:
* NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD: t_strtoi.c,v 1.3 2024/01/20 16:52:41 christos Exp $");

#include <atf-c.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

struct test {
const char *str;
intmax_t res;
int base;
const char *end;
intmax_t lo;
intmax_t hi;
int rstatus;
};

static void check(struct test *, intmax_t, char *, int);

static void
check(struct test *t, intmax_t rv, char *end, int rstatus)
{

if (rv != t->res)
atf_tc_fail_nonfatal("strtoi(\"%s\", &end, %d, %jd, %jd, "
"&rstatus) failed (rv = %jd)", t->str, t->base,
t->lo, t->hi, rv);

if (rstatus != t->rstatus) {
char *emsg;

if (rstatus != 0) {
emsg = strerror(rstatus);
if (emsg != NULL) {
emsg = strdup(emsg);
if (emsg == NULL) {
atf_tc_fail("Out of Memory");
return;
}
}
} else
emsg = NULL;

atf_tc_fail_nonfatal("strtoi(\"%s\", &end, %d, %jd, %jd, &rstatus)"
" failed (rstatus: %d %s%s%sexpected %d%s%s%s)",
t->str, t->base, t->lo, t->hi, rstatus, rstatus ? "('" : "",
emsg != NULL ? emsg : "", rstatus ? "') " : "", t->rstatus,
t->rstatus ? " ('" : "", t->rstatus ? strerror(t->rstatus)
: "", t->rstatus ? "')" : "");

free(emsg);
}

if ((t->end != NULL && strcmp(t->end, end) != 0) ||
(t->end == NULL && *end != '\0'))
atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
"strtoi(\"%s\", &end, %d, %jd, %jd, &rstatus), "
"expected '%s'", end, t->str, t->base, t->lo, t->hi,
t->end != NULL ? t->end : "\\0");
}

static void
check_errno(int e)
{
if (e != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
}

ATF_TC(strtoi_base);
ATF_TC_HEAD(strtoi_base, tc)
{
atf_tc_set_md_var(tc, "descr", "Test strtoi(3) with different bases");
}

ATF_TC_BODY(strtoi_base, tc)
{
struct test t[] = {
{ "123456789", 123456789, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "111010110111100110100010101",123456789, 2, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "22121022020212200", 123456789, 3, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "13112330310111", 123456789, 4, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "223101104124", 123456789, 5, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "20130035113", 123456789, 6, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "3026236221", 123456789, 7, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "726746425", 123456789, 8, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "277266780", 123456789, 9, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "123456789", 123456789, 10, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "63762A05", 123456789, 11, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "35418A99", 123456789, 12, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "1C767471", 123456789, 13, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "12579781", 123456789, 14, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "AC89BC9", 123456789, 15, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "75BCD15", 123456789, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "1234567", 342391, 8, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "01234567", 342391, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0123456789", 123456789, 10, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0x75bcd15", 123456789, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
};
struct test f[] = {
{ "1", 0, 1, "1",
INTMAX_MIN, INTMAX_MAX, EINVAL },
{ "2", 0, -1, "2",
INTMAX_MIN, INTMAX_MAX, EINVAL },
{ "3", 0, 37, "3",
INTMAX_MIN, INTMAX_MAX, EINVAL },
{ "4", 0, -1, "4",
INTMAX_MIN, INTMAX_MAX, EINVAL },
{ "0x", 0, 0, "x",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
};

intmax_t rv;
char *end;
int e;
size_t i;

for (i = 0; i < __arraycount(t); i++) {

errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);

check_errno(errno);

check(&t[i], rv, end, e);
}

for (i = 0; i < __arraycount(f); i++) {

end = NULL;
errno = 0;
e = -99;

rv = strtoi(f[i].str, &end, f[i].base, f[i].lo, f[i].hi, &e);

check_errno(errno);

check(&f[i], rv, end, e);
}
}

ATF_TC(strtoi_case);
ATF_TC_HEAD(strtoi_case, tc)
{
atf_tc_set_md_var(tc, "descr", "Case insensitivity with strtoi(3)");
}

ATF_TC_BODY(strtoi_case, tc)
{
struct test t[] = {
{ "abcd", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " dcba", 0xdcba, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "abcd dcba", 0xabcd, 16, " dcba",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "abc0x123", 0xabc0, 16, "x123",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "abcd\0x123", 0xabcd, 16, "\0x123",
INTMAX_MIN, INTMAX_MAX, 0 },
{ "ABCD", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "aBcD", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0xABCD", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0xABCDX", 0xabcd, 16, "X",
INTMAX_MIN, INTMAX_MAX, ENOTSUP},
};

intmax_t rv;
char *end;
int e;
size_t i;

for (i = 0; i < __arraycount(t); i++) {

errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);

check_errno(errno);

check(&t[i], rv, end, e);
}
}

ATF_TC(strtoi_range);
ATF_TC_HEAD(strtoi_range, tc)
{
atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtoi(3)");
}

ATF_TC_BODY(strtoi_range, tc)
{
struct test t[] = {
#if INTMAX_MAX == 0x7fffffffffffffff
{ "1000000000000000000000", INTMAX_MAX, 8, NULL,
INTMAX_MIN, INTMAX_MAX, ERANGE },
{ "9223372036854775808", INTMAX_MAX, 10, NULL,
INTMAX_MIN, INTMAX_MAX, ERANGE },
{ "8000000000000000", INTMAX_MAX, 16, NULL,
INTMAX_MIN, INTMAX_MAX, ERANGE },
#else
#error extend this test to your platform!
#endif
{ "10", 1, 10, NULL,
-1, 1, ERANGE },
{ "10", 11, 10, NULL,
11, 20, ERANGE },
{ "7", 7, 0, NULL,
7, 7, 0 },
{ "6", 7, 0, NULL,
7, 7, ERANGE },
{ "8", 7, 0, NULL,
7, 7, ERANGE },
{ "7x", 7, 0, "x",
7, 7, ENOTSUP },
{ "8x", 7, 0, "x",
7, 7, ERANGE },
{ "Z", 11, 10, "Z",
11, 20, ECANCELED },
};

intmax_t rv;
char *end;
int e;
size_t i;

for (i = 0; i < __arraycount(t); i++) {

errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);

if (errno != 0)
atf_tc_fail("Range test %zd set errno=%d", i, errno);
check_errno(errno);

check(&t[i], rv, end, e);
}
}

ATF_TC(strtoi_range_trail);
ATF_TC_HEAD(strtoi_range_trail, tc)
{
atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtoi(3) "
"with trailing characters");
}

ATF_TC_BODY(strtoi_range_trail, tc)
{
struct test t[] = {
{ "11x", 9, 10, "x", 0, 9, ERANGE },
{ " -3y", -2, 10, "y", -2, 1, ERANGE },
{ "11111z", 9, 10, "z", 0, 9, ERANGE },
{ "+0xAq", 9, 16, "q", 0, 9, ERANGE },
{ "-0xBAr", 0, 16, "r", 0, 9, ERANGE },
};

intmax_t rv;
char *end;
int e;
size_t i;

for (i = 0; i < __arraycount(t); i++) {

errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);

check_errno(errno);

check(&t[i], rv, end, e);
}
}

ATF_TC(strtoi_signed);
ATF_TC_HEAD(strtoi_signed, tc)
{
atf_tc_set_md_var(tc, "descr", "A basic test of strtoi(3)");
}

ATF_TC_BODY(strtoi_signed, tc)
{
struct test t[] = {
{ "1", 1, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " 2", 2, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " 3", 3, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " -3", -3, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "--1", 0, 0, "--1",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "+-2", 0, 0, "+-2",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "++3", 0, 0, "++3",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "+9", 9, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "+123", 123, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "-1 3", -1, 0, " 3",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "-1.3", -1, 0, ".3",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "- 3", 0, 0, "- 3",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "+33.", 33, 0, ".",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "30x0", 30, 0, "x0",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
};

intmax_t rv;
char *end;
int e;
size_t i;

for (i = 0; i < __arraycount(t); i++) {

errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);

check_errno(errno);

check(&t[i], rv, end, e);
}
}

ATF_TP_ADD_TCS(tp)
{

ATF_TP_ADD_TC(tp, strtoi_base);
ATF_TP_ADD_TC(tp, strtoi_case);
ATF_TP_ADD_TC(tp, strtoi_range);
ATF_TP_ADD_TC(tp, strtoi_range_trail);
ATF_TP_ADD_TC(tp, strtoi_signed);

return atf_no_error();
}
 1.3 20-Jan-2024  christos branches: 1.3.2;
Add range tests with trailing characters.
 1.2 28-Apr-2017  kamil branches: 1.2.12; 1.2.20;
Fix typo in ATF test t_strtoi.c

No functional change.
 1.1 01-May-2015  christos branches: 1.1.2; 1.1.8;
- new test for strtoi
- namespace protection for strto{i,u}
- separate manpages for strto{i,u} from the ones for strto{u,}l
From: Kamil Rytarowski
 1.1.8.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.1.2.2 16-May-2015  snj Pull up following revision(s) (requested by christos in ticket #781):
common/lib/libc/stdlib/strtoi.c: revision 1.2
common/lib/libc/stdlib/strtou.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.113
distrib/sets/lists/tests/mi: revision 1.617
lib/libc/include/namespace.h: revision 1.178
lib/libc/stdlib/Makefile.inc: revision 1.90 via patch
lib/libc/stdlib/strtoi.3: revisions 1.1, 1.2
lib/libc/stdlib/strtol.3: revision 1.32
lib/libc/stdlib/strtou.3: revisions 1.1, 1.2
lib/libc/stdlib/strtoul.3: revisions 1.30, 1.31
tests/lib/libc/stdlib/Makefile: revision 1.25
tests/lib/libc/stdlib/t_strtoi.c: revision 1.1
- new test for strtoi
- namespace protection for strto{i,u}
- separate manpages for strto{i,u} from the ones for strto{u,}l
From: Kamil Rytarowski
--
Sort ERRORS and SEE ALSO.
--
Sort ERRORS and SEE ALSO.
--
Sort SEE ALSO.
 1.1.2.1 01-May-2015  snj file t_strtoi.c was added on branch netbsd-7 on 2015-05-16 17:58:47 +0000
 1.2.20.1 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #792):

common/lib/libc/stdlib/_strtoi.h: revision 1.3
lib/libc/stdlib/strtou.3: revision 1.8
lib/libc/stdlib/strtonum.c: revision 1.7
lib/libc/stdlib/Makefile.inc: revision 1.97
lib/libc/stdlib/strtoi.3: revision 1.8
lib/libc/stdlib/strtoi.3: revision 1.9
lib/libc/stdlib/strtou.3: file removal
tests/lib/libc/stdlib/t_strtoi.c: revision 1.3

PR/57828: Alejandro Colomar: Prioritize test for ERANGE before testing for
fully consuming the string. Adjust strtonum(3) to behave as before. Document
the order of the tests and sync the man pages (I should really autogenerate
one of the two man pages...)

generate strtou.3 from strtoi.3, grammar police

Add range tests with trailing characters.
 1.2.12.1 23-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1870):

common/lib/libc/stdlib/_strtoi.h: revision 1.3
lib/libc/stdlib/strtou.3: revision 1.8
lib/libc/stdlib/strtonum.c: revision 1.7
lib/libc/stdlib/Makefile.inc: revision 1.97
lib/libc/stdlib/strtoi.3: revision 1.8
lib/libc/stdlib/strtoi.3: revision 1.9
lib/libc/stdlib/strtou.3: file removal
tests/lib/libc/stdlib/t_strtoi.c: revision 1.3

PR/57828: Alejandro Colomar: Prioritize test for ERANGE before testing for
fully consuming the string. Adjust strtonum(3) to behave as before. Document
the order of the tests and sync the man pages (I should really autogenerate
one of the two man pages...)
generate strtou.3 from strtoi.3, grammar police

Add range tests with trailing characters.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 22-Jul-2024  christos Add strto{i,u}max tests and invalid base tests
 1.7 06-Jul-2017  joerg branches: 1.7.18;
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.
 1.6 01-Jun-2016  pgoyette branches: 1.6.8;
Fix testing of returned entptr, and fix three affected tests.

From kamil@ via PR lib/49632
 1.5 14-Jun-2011  jruoho branches: 1.5.2; 1.5.6; 1.5.22;
Remove the cases that cause integer overflow on e.g. i386.
 1.4 08-Jun-2011  jruoho Adjust types.
 1.3 05-Jun-2011  jruoho Do not blindly cast things (obviously makes the test fail).
 1.2 04-Jun-2011  haad Fix problem with overflowing constant definition

t_strtol.c:95: warning: overflow in implicit constant conversion
 1.1 04-Jun-2011  jruoho Add some tests for strtol(3).
 1.5.22.1 17-Nov-2017  snj Pull up following revision(s) (requested by joerg in ticket #1448):
common/lib/libc/stdlib/_strtol.h: revision 1.11
common/lib/libc/stdlib/_strtoul.h: revision 1.11
tests/lib/libc/stdlib/t_strtol.c: revision 1.7
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.
 1.5.6.1 26-Aug-2017  snj Pull up following revision(s) (requested by joerg in ticket #1460):
common/lib/libc/stdlib/_strtol.h: 1.11 via patch
common/lib/libc/stdlib/_strtoul.h: 1.11 via patch
tests/lib/libc/stdlib/t_strtol.c: 1.6-1.7
Fix testing of returned entptr, and fix three affected tests.
From kamil@ via PR lib/49632
--
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.
 1.5.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.5.2.1 14-Jun-2011  cherry file t_strtol.c was added on branch cherry-xenmp on 2011-06-23 14:20:40 +0000
 1.6.8.1 10-Jul-2017  martin Pull up following revision(s) (requested by joerg in ticket #112):
common/lib/libc/stdlib/_strtol.h: revision 1.11
common/lib/libc/stdlib/_strtoul.h: revision 1.11
tests/lib/libc/stdlib/t_strtol.c: revision 1.7
Fix ISO C compliance: strtol of "0xX" should give the largest valid
numeric prefix, which is 0.
 1.7.18.1 02-Aug-2025  perseant Sync with HEAD
 1.4 05-Apr-2011  jruoho Try to maintain the structure of libc and move 't_strtox' to 't_strtod'.
 1.3 22-Mar-2011  njoly Test case from PR/44189 should not fail anymore.
 1.2 06-Dec-2010  pooka Adjust PR format in xfail message so that html test results gain a
link to http://gnats.netbsd.org/44189
 1.1 03-Dec-2010  njoly Add testcase for PR/44189: strtod(3) wrong results with "-0x".
 1.1 11-Sep-2011  jruoho See that system(3) works.
 1.2 13-Jul-2010  jmmv Get rid of static Atffiles and let bsd.test.mk generate them on the fly.
 1.1 21-Jul-2009  joerg Add popcount(3) and the long and long long version. Name is inspired by
gnulib, the implementation goes back to the AMD Software Optimizer
guide. A number of platforms will want to replace the C version with
assembler code using native instructions.
 1.15 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.14 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.13 30-Jan-2023  christos PR/57205: Dag-Erling Sm�rgrav: Add tests strchrnul(3), fix strchr pasto
from strlen.
 1.12 19-Dec-2019  macallan disable string op warnings for t_strcat
now this builds on macppc with gcc 8.3
from riastradh@
 1.11 15-Oct-2018  christos simple memmem test to show buffer overrun.
 1.10 26-May-2017  perseant branches: 1.10.8; 1.10.10;
Add simple expect-fail test case for strcoll(3)
 1.9 23-Jun-2014  shm Add bm(3) tests
 1.8 21-Nov-2011  joerg branches: 1.8.6; 1.8.16;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.7 07-Jul-2011  jruoho branches: 1.7.2;
Split out the string tests from t_string.c for consistency.
 1.6 03-Jun-2011  jruoho Add some fundamental checks for memset(3). Prompted by a recent nasty
bug in the Google Android libc.
 1.5 09-May-2011  jruoho branches: 1.5.2;
Few basic tests for strerror(3).
 1.4 26-Dec-2010  pgoyette Migrate the last of the libc/string/ tests from regress to atf, and
re-enable building of t_popcount
 1.3 25-Dec-2010  pgoyette Migrate J.T.Conklin's public-domain str* tests from regress to atf.

While here, do some clean-up and knf.
 1.2 26-Feb-2010  martin Disable population count test for now, please re-enable once
PR toolchain/42885 is fixed
 1.1 21-Jul-2009  joerg Add popcount(3) and the long and long long version. Name is inspired by
gnulib, the implementation goes back to the AMD Software Optimizer
guide. A number of platforms will want to replace the C version with
assembler code using native instructions.
 1.5.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.7.2.1 17-Apr-2012  yamt sync with head
 1.8.16.1 10-Aug-2014  tls Rebase.
 1.8.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.10.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10.10.1 10-Jun-2019  christos Sync with HEAD
 1.10.8.1 20-Oct-2018  pgoyette Sync with head
 1.3 11-Jul-2024  kre Correct a thinko in previous...
 1.2 11-Jul-2024  kre More ATF_CHECK() (etc) change fallout.

Really, developers making infrastructure changes like this should do
a full build before committing the change, and handle any fallout from
the change.
 1.1 23-Jun-2014  shm branches: 1.1.2; 1.1.6; 1.1.40;
Add bm(3) tests
 1.1.40.1 02-Aug-2025  perseant Sync with HEAD
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 23-Jun-2014  tls file t_bm.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 23-Jun-2014  tls file t_bm.c was added on branch tls-earlyentropy on 2014-08-10 06:57:21 +0000
 1.3 06-Apr-2012  jruoho Adjust.
 1.2 14-Jul-2011  jruoho branches: 1.2.2;
Add few simple test cases.
 1.1 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.6 11-Jan-2017  christos PR/51823: Ngie Cooper: Add output diagnostic if memcmp of the md5 string fails
 1.5 17-Mar-2013  christos branches: 1.5.12;
check return values
 1.4 14-Jul-2011  jruoho branches: 1.4.2; 1.4.8;
Add few simple test cases.
 1.3 07-Jul-2011  jruoho Rename some test case names for consistency.
 1.2 07-Apr-2011  jruoho Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.1 26-Dec-2010  pgoyette Migrate the last of the libc/string/ tests from regress to atf, and
re-enable building of t_popcount
 1.4.8.1 23-Jun-2013  tls resync from head
 1.4.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.5.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6 27-Nov-2020  christos map enough space for both the page we write and the guard so that we make
sure we own the guard page before we set its protection to none. This fixes
random SEGVs where the page we set protection to none probably belonged to
the dynamic linker. Reported by gson@
 1.5 27-Nov-2020  gson delete trailing whitespace
 1.4 15-Oct-2018  christos simple memmem test to show buffer overrun.
 1.3 11-Jan-2017  christos branches: 1.3.12; 1.3.14;
PR/51822: Ngie Cooper: add additional t_memmem check
 1.2 07-Jul-2011  jruoho branches: 1.2.24;
Rename some test case names for consistency.
 1.1 26-Dec-2010  pgoyette Migrate the last of the libc/string/ tests from regress to atf, and
re-enable building of t_popcount
 1.2.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.14.1 10-Jun-2019  christos Sync with HEAD
 1.3.12.1 20-Oct-2018  pgoyette Sync with head
 1.5 02-Nov-2024  riastradh memset_explicit(3): Add C23 alias for explicit_memset.

PR standards/58607: C23: <string.h> memset_explicit
 1.4 11-Sep-2015  martin branches: 1.4.28;
Add two test cases that should cover PR 50228.
 1.3 17-Mar-2013  christos check return values
 1.2 14-Jul-2011  jruoho branches: 1.2.2; 1.2.8;
Use ATF_CHECK() when appropriate.
 1.1 03-Jun-2011  jruoho branches: 1.1.2;
Add some fundamental checks for memset(3). Prompted by a recent nasty
bug in the Google Android libc.
 1.1.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1.2.1 03-Jun-2011  cherry file t_memset.c was added on branch cherry-xenmp on 2011-06-23 14:20:40 +0000
 1.2.8.1 23-Jun-2013  tls resync from head
 1.2.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.4.28.1 02-Aug-2025  perseant Sync with HEAD
 1.4 07-Jul-2011  jruoho Rename some test case names for consistency.
 1.3 26-Dec-2010  pgoyette Make running this test conditional on the setting of atf configuration
variable "run_popcount". This is a really long-running test (it takes
several hours on a qemu-emulation on a 2.8GHz AMD Pheno II) but could
still be useful if you want to run it manually, with the command

atf-run -v run_popcount=YES
 1.2 21-Jul-2009  drochner flag a 64-bit integer constant as "ULL" -- this is not clean but the
code around it assumes it anyway
fixes build on 32-bit
 1.1 21-Jul-2009  joerg Add popcount(3) and the long and long long version. Name is inspired by
gnulib, the implementation goes back to the AMD Software Optimizer
guide. A number of platforms will want to replace the C version with
assembler code using native instructions.
 1.2 14-Jul-2011  jruoho Add few simple test cases.
 1.1 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.3 30-Jan-2023  christos PR/57205: Dag-Erling Sm�rgrav: Add tests strchrnul(3), fix strchr pasto
from strlen.
 1.2 10-Jan-2017  christos PR/51815: Ngie Cooper: don't leak dlopen'ed handle
 1.1 07-Jul-2011  jruoho branches: 1.1.24;
Split out the string tests from t_string.c for consistency.
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 30-Jan-2023  christos PR/57205: Dag-Erling Sm�rgrav: Add tests strchrnul(3), fix strchr pasto
from strlen.
 1.4 25-Mar-2012  joerg Be UTF8 clean.
 1.3 14-Jul-2011  jruoho branches: 1.3.2;
Use ATF_CHECK() when appropriate.
 1.2 07-Jul-2011  jruoho Few basic checks, including a case for strnlen(3).
 1.1 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.2 02-Aug-2021  andvar s/diferent/different/
 1.1 26-May-2017  perseant Add simple expect-fail test case for strcoll(3)
 1.1 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.1 21-Nov-2011  joerg branches: 1.1.4;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 21-Nov-2011  yamt file t_strcspn.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.4 10-Jan-2017  christos add <stdio.h>
 1.3 10-May-2011  jruoho branches: 1.3.26;
Fix typo.
 1.2 09-May-2011  jruoho List the ATF_TC_() thins in the order of appearance.
 1.1 09-May-2011  jruoho Few basic tests for strerror(3).
 1.3.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 23-Aug-2017  christos Add test from PR/52499
 1.3 15-Feb-2013  christos branches: 1.3.22;
don't brk the build.
 1.2 07-Jul-2011  jruoho branches: 1.2.2; 1.2.8;
Rename some test case names for consistency.
 1.1 26-Dec-2010  pgoyette Migrate the last of the libc/string/ tests from regress to atf, and
re-enable building of t_popcount
 1.2.8.1 25-Feb-2013  tls resync with head
 1.2.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.3.22.1 14-May-2018  martin Pull up following revision(s) (requested by maya in ticket #822):

lib/libc/string/stresep.c: revision 1.4
tests/lib/libc/string/t_stresep.c: revision 1.4

PR/52499: Justin: stresep uses memmove with of-by-one length
Add test from PR/52499
 1.2 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.1 25-Dec-2010  pgoyette Migrate J.T.Conklin's public-domain str* tests from regress to atf.

While here, do some clean-up and knf.
 1.6 14-Jan-2017  christos PR/51815: Ngie Cooper: don't leak dlopen'ed handle
 1.5 14-Jul-2011  jruoho branches: 1.5.24;
Use ATF_CHECK() when appropriate.
 1.4 12-Jul-2011  njoly Fix off-by-one in strlen_huge testcase.
 1.3 07-Jul-2011  jruoho Few basic checks, including a case for strnlen(3).
 1.2 07-Jul-2011  jruoho Add one simple test case.
 1.1 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.5.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 21-Nov-2011  joerg branches: 1.1.4;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 21-Nov-2011  yamt file t_strpbrk.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.1 07-Jul-2011  jruoho Split out the string tests from t_string.c for consistency.
 1.1 21-Nov-2011  joerg branches: 1.1.4;
Add test cases for strcspn, strpbrk, strspn, wcscspn, wcspbrk and
wcsspn.
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 21-Nov-2011  yamt file t_strspn.c was added on branch yamt-pagecache on 2012-04-17 00:09:12 +0000
 1.3 28-Dec-2022  riastradh swab(3): Rewrite this to be understandable.

And make the tests work, and exercise all lengths up to 100.

Evidently the previous definition, presumably tightly optimized for
1980s-era compilers and CPUs, was too hard to understand, because it
was incorrectly tested for two decades and broken for years.

PR lib/57141

XXX pullup-8
XXX pullup-9
XXX pullup-10
 1.2 07-Jul-2011  jruoho branches: 1.2.34; 1.2.44; 1.2.52;
Rename some test case names for consistency.
 1.1 26-Dec-2010  pgoyette Migrate the last of the libc/string/ tests from regress to atf, and
re-enable building of t_popcount
 1.2.52.1 22-Feb-2023  martin Pull up following revision(s) (requested by riastradh in ticket #98):

tests/lib/libc/string/t_swab.c: revision 1.3
lib/libc/string/swab.c: revision 1.20

swab(3): Rewrite this to be understandable.

And make the tests work, and exercise all lengths up to 100.
Evidently the previous definition, presumably tightly optimized for
1980s-era compilers and CPUs, was too hard to understand, because it
was incorrectly tested for two decades and broken for years.

PR lib/57141
 1.2.44.1 22-Feb-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1601):

tests/lib/libc/string/t_swab.c: revision 1.3
lib/libc/string/swab.c: revision 1.20

swab(3): Rewrite this to be understandable.

And make the tests work, and exercise all lengths up to 100.
Evidently the previous definition, presumably tightly optimized for
1980s-era compilers and CPUs, was too hard to understand, because it
was incorrectly tested for two decades and broken for years.

PR lib/57141
 1.2.34.1 22-Feb-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1798):

tests/lib/libc/string/t_swab.c: revision 1.3
lib/libc/string/swab.c: revision 1.20

swab(3): Rewrite this to be understandable.

And make the tests work, and exercise all lengths up to 100.
Evidently the previous definition, presumably tightly optimized for
1980s-era compilers and CPUs, was too hard to understand, because it
was incorrectly tested for two decades and broken for years.

PR lib/57141
 1.8 26-Feb-2019  isaki Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.7 22-Feb-2017  maya branches: 1.7.12;
GC more gcc 4.8 specific (dead) logic
 1.6 18-Oct-2014  joerg branches: 1.6.2; 1.6.4;
Explicitly link C++ test case with CXX.
 1.5 13-Oct-2014  martin Fix include order, so the makefile actually does something again.
 1.4 13-Oct-2014  martin Do not try the C++ 2011 test with gcc < 4.8
 1.3 12-Oct-2014  martin Disable the <atomic> C++11 test for now, we are not ready for it.
 1.2 11-Oct-2014  martin Add a link time test to catch missing symbols in libc, as pointed
out in PR toolchain/49074.
 1.1 17-Feb-2014  martin branches: 1.1.4; 1.1.8;
Add a link-time test for __sync_* primitives (see PR 48368) - this
will allow us to notice missing functions during the build, instead
of when compiling arbitrary pkgsrc stuff later.
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 17-Feb-2014  tls file Makefile was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.1.4.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.4.1 17-Feb-2014  yamt file Makefile was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.6.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.6.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.7.12.1 10-Jun-2019  christos Sync with HEAD
 1.5 26-Feb-2019  isaki Add ATF tests for __sync_* functions instead of all_sync_ops_linkable.c
 1.4 21-Feb-2014  martin branches: 1.4.4; 1.4.8; 1.4.30;
Remove excemption for i386 (PR lib/48601) - missing aliases will be
added to the C code.
 1.3 18-Feb-2014  martin For now excempt i386 from __sync_lock_test_and_set_8 and point to
PR lib/48601. Probably more architectures to follow.
 1.2 17-Feb-2014  joerg Since clang doesn't recognize the nand variants of the sync builtins and
gcc doesn't support __has_builtin, use a plain #ifndef __clang__ check
as workaround.
 1.1 17-Feb-2014  martin Add a link-time test for __sync_* primitives (see PR 48368) - this
will allow us to notice missing functions during the build, instead
of when compiling arbitrary pkgsrc stuff later.
 1.4.30.1 10-Jun-2019  christos Sync with HEAD
 1.4.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 21-Feb-2014  tls file all_sync_ops_linkable.c was added on branch tls-maxphys on 2014-08-20 00:04:50 +0000
 1.4.4.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.4.4.1 21-Feb-2014  yamt file all_sync_ops_linkable.c was added on branch yamt-pagecache on 2014-05-22 11:42:21 +0000
 1.5 11-Jan-2017  joerg Remove LLVM atomic hacks for Sparc.
 1.4 27-Feb-2016  joerg branches: 1.4.2;
When building the atomic op test on SPARC64 with Clang, skip the
sub-32bit tests for now. Clang currently doesn't synthesize a CAS
replacement nor does it create a libcall.
 1.3 12-Oct-2014  martin If we don't have 64 bit atomic ops, also do not test "long long" and intmax_t
(and friends).
 1.2 11-Oct-2014  martin If not __HAVE_ATOMIC64_OPS, do not force the test for 64bit types.
 1.1 11-Oct-2014  martin Add a link time test to catch missing symbols in libc, as pointed
out in PR toolchain/49074.
 1.4.2.1 20-Mar-2017  pgoyette Sync with HEAD
 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
 1.1 01-May-2011  jruoho Add a test for PR lib/41673 (another trivial errno "bug").
 1.3 18-Mar-2012  jruoho To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
 1.2 17-Mar-2012  christos this has been fixed.
 1.1 01-May-2011  jruoho branches: 1.1.4;
Add a test for PR lib/41673 (another trivial errno "bug").
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.1 13-Jan-2011  pgoyette Move t_mktime and t_strptime to their own ..../time/ subdirectory.

(Concurrence from christos@)
 1.6 27-Oct-2017  kre Remove bogus errno checks, mktime() (and timegm()) does not guarantee
to leave errno unaltered if there is no error. And does not.

While here, write -1 the same way everyone else does (not ~0, which
would not even be negative on a 1's complement host, if you can find one).

And while not needed for the test, but so that if checked, the result is
more likely to be what is anticipated, set tm_mday to an in-range value
in the mtime_negyear test (otherwise the correction results in the result
movng backwards to the last day of the previous month, which is the
end of Decemper, 1898, rather than the 1899 one would expect from year -1.)
 1.5 18-Mar-2012  jruoho Add a test case for the old NetBSD 2.0 era PR lib/28324.
 1.4 07-Jan-2012  martin ATF_REQUIRE_ERRNO() needs to be used with care:
- pass the expected errno to it, not "errno"
- make sure to have errno set already before invoking the macro, i.e.
do not use it to test errno changes as side effect of the asserted
expression

Spotted by mlelstv, makes the epoch tests correctly fail on amd64 as
well.
 1.3 17-Dec-2011  apb Add some tests for timegm(3) close to the epoch. In
particular, 1969-12-31 23:59:59 should convert to (time_t)-1
with errno = 0.
 1.2 07-Apr-2011  jruoho branches: 1.2.4;
Remove the following (literal) text in the TNF copyrights:

* This code is derived from software contributed to The NetBSD Foundation
* by
*

XXX: If these originated from you and you want your name to be mentioned,
please add it.
 1.1 13-Jan-2011  pgoyette Move t_mktime and t_strptime to their own ..../time/ subdirectory.

(Concurrence from christos@)
 1.2.4.1 17-Apr-2012  yamt sync with head
 1.17 26-Mar-2024  rillig t_strptime: fix typo in test description
 1.16 16-Mar-2024  riastradh strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.

PR lib/58041
 1.15 03-Jun-2018  maya branches: 1.15.4; 1.15.12;
use ATF_CHECK instead of ATF_REQUIRE
(continue on failure, to see the rest of the failures)

From Ngie Cooper in PR bin/51834
 1.14 27-Oct-2017  kre branches: 1.14.2;

The Zone test was obviously intended to test %Z rather than %z, otherwise
it would be (and has been) identical to the zone test, which would be a
pointless waste of time.
 1.13 24-Aug-2017  ginsbach The military/nautical time zones were added following RFC 822 and RFC
2822 specifications. Unfortunately they are specified incorrectly in
RFC-822 and not very clearly in RFC 2822. RFC 1123 clearly states they
are specified incorrectly - counting the wrong way from UTC - in RFC
822. RFC 2822 just states they were implemented in a non-standard way.
Mea culpa for not noticing when originally implemented. Fix them so
the correct calculations are made.
 1.12 31-Oct-2015  christos merge more the tests
 1.11 31-Oct-2015  christos Account for J, fix %Z
 1.10 30-Oct-2015  christos tests for %Z
 1.9 30-Oct-2015  ginsbach ISO 8601 and RFC 3339 specify that an offset can be up to 23:59 and
not 12:00 east/west. Just proves that one shouldn't use other
implementations as a canonical reference. Thanks to all who pointed
this out.
 1.8 30-Oct-2015  ginsbach Additional tests for timezone offsets.
 1.7 29-Oct-2015  christos Add tests for %z
 1.6 04-Jul-2015  christos strptime now sets tm_yday
 1.5 28-Apr-2015  ginsbach Add hour tests as a standalone test case.
 1.4 22-Apr-2015  ginsbach Make century and year conversion tests a standalone test case rather than
part of the "common" test case.
 1.3 21-Apr-2015  ginsbach Make seconds conversion tests a standalone test case rather than
part of the "common" test case.
 1.2 17-Apr-2015  ginsbach Add more detail to test descriptions.
 1.1 13-Jan-2011  pgoyette Move t_mktime and t_strptime to their own ..../time/ subdirectory.

(Concurrence from christos@)
 1.14.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.15.12.1 25-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #638):

lib/libc/time/strptime.c: revision 1.64
lib/libc/time/strptime.c: revision 1.65
tests/lib/libc/time/t_strptime.c: revision 1.16

strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.
PR lib/58041

strptime(3): Avoid arithmetic overflow.
PR lib/58041

strptime(3): Reduce unnecessary indentation.
Post-fix tidying.
No functional change intended.
PR lib/58041
 1.15.4.1 24-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1881):

lib/libc/time/strptime.c: revision 1.64 (patch)
lib/libc/time/strptime.c: revision 1.65 (patch)
lib/libc/time/strptime.c: revision 1.66 (patch)
tests/lib/libc/time/t_strptime.c: revision 1.16 (patch)

strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.
PR lib/58041

strptime(3): Avoid arithmetic overflow.
PR lib/58041

strptime(3): Reduce unnecessary indentation.
Post-fix tidying.
No functional change intended.
PR lib/58041

strptime(3): Declare digit d as time_t.

This doesn't make a semantic difference -- d can only take on the ten
values {0,1,2,3,4,5,6,7,8,9}, and the arithmetic with it later all
comes out the same whether the type is unsigned or time_t, even if
time_t were int32_t instead of int64_t.

But it pacifies overzealous compilers used by downstream users of
this code. And while it's silly to use a much wider type (64-bit
signed) than is needed here to store a single digit, it doesn't
really hurt either (32-bit unsigned is much larger than needed too).

PR lib/58041
 1.6 18-Jul-2016  christos Not designed for PIE
 1.5 18-Jun-2016  joerg branches: 1.5.2;
Link static test program with LDSTATIC to deal with PIE.
 1.4 18-Nov-2011  joerg Add some dependencies
 1.3 30-Mar-2011  he branches: 1.3.4;
Put tests depending on dlopen etc. under a test for MKPIC, and move
the corresponding entries in the set lists over to the shl.mi file.
This should bring the sun2 port back to a buildable state.
 1.2 10-Mar-2011  skrll Deal with all objdir methods.
 1.1 09-Mar-2011  joerg Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.3.4.1 17-Apr-2012  yamt sync with head
 1.5.2.1 26-Jul-2016  pgoyette Sync with HEAD
 1.1 11-Jun-2011  christos branches: 1.1.2;
Turn warns on for all tests and fix all the bugs.
 1.1.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.1.2.1 11-Jun-2011  cherry file Makefile.inc was added on branch cherry-xenmp on 2011-06-23 14:20:40 +0000
 1.3 17-Jan-2012  joerg Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
 1.2 17-Nov-2011  joerg FreeBSD bug report 161344: TLS area for the main thread is set up to
early, if e.g. pointers to functions are used as initializers.
 1.1 09-Mar-2011  joerg branches: 1.1.4;
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.3 17-Jan-2012  joerg Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
 1.2 17-Nov-2011  joerg FreeBSD bug report 161344: TLS area for the main thread is set up to
early, if e.g. pointers to functions are used as initializers.
 1.1 09-Mar-2011  joerg branches: 1.1.4;
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.4 28-Oct-2017  christos fix typo
 1.3 28-Oct-2017  christos make tests print the values.
 1.2 17-Jan-2012  joerg Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
 1.1 09-Mar-2011  joerg branches: 1.1.4;
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.2 17-Jan-2012  joerg Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
 1.1 09-Mar-2011  joerg branches: 1.1.4;
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.1 09-Mar-2011  joerg Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.5 21-Oct-2013  joerg Only initialise TLS space from the PT_TLS segment, if the size is
positive and the offset has been computed. Fixes PR lib/48324.
 1.4 17-Jan-2012  joerg branches: 1.4.2; 1.4.6; 1.4.8; 1.4.14;
Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
 1.3 17-Nov-2011  joerg Reorder to make GCC happy.
 1.2 17-Nov-2011  joerg FreeBSD bug report 161344: TLS area for the main thread is set up to
early, if e.g. pointers to functions are used as initializers.
 1.1 09-Mar-2011  joerg branches: 1.1.4;
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.1.4.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.4.1 17-Apr-2012  yamt sync with head
 1.4.14.1 07-Nov-2013  snj Pull up following revision(s) (requested by joerg in ticket #976):
libexec/ld.elf_so/tls.c: revision 1.9
tests/lib/libc/tls/dso/h_tls_dlopen.c: revision 1.5
Only initialise TLS space from the PT_TLS segment, if the size is
positive and the offset has been computed. Fixes PR lib/48324.
 1.4.8.1 07-Nov-2013  snj Pull up following revision(s) (requested by joerg in ticket #976):
libexec/ld.elf_so/tls.c: revision 1.9
tests/lib/libc/tls/dso/h_tls_dlopen.c: revision 1.5
Only initialise TLS space from the PT_TLS segment, if the size is
positive and the offset has been computed. Fixes PR lib/48324.
 1.4.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.2.1 07-Nov-2013  snj Pull up following revision(s) (requested by joerg in ticket #976):
libexec/ld.elf_so/tls.c: revision 1.9
tests/lib/libc/tls/dso/h_tls_dlopen.c: revision 1.5
Only initialise TLS space from the PT_TLS segment, if the size is
positive and the offset has been computed. Fixes PR lib/48324.
 1.1 09-Mar-2011  joerg Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.5 21-Oct-2013  joerg Revert, init-exec in combination with initalised TLS variables is not
supported.
 1.4 20-Oct-2013  joerg Force use of static TLS space.
 1.3 17-Jan-2012  joerg Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as
__lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread.
Define VAX as going to use TLS variant I, if it is ever implemented.
 1.2 17-Nov-2011  joerg FreeBSD bug report 161344: TLS area for the main thread is set up to
early, if e.g. pointers to functions are used as initializers.
 1.1 09-Mar-2011  joerg branches: 1.1.4;
Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to
setup the thread private area of all new threads. ld.elf_so is
responsible for setting up the private area for the initial thread.
Similar functions are called from _libc_init for static binaries, using
dl_iterate_phdr to access the ELF Program Header.

Add test cases to exercise the different TLS storage models. Test cases
are compiled and installed on all platforms, but are skipped on
platforms not marked for TLS support.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.

It is inspired by the TLS support in FreeBSD by Doug Rabson and the
clean ups of the DragonFly port of the original FreeBSD modifications.
 1.1.4.1 17-Apr-2012  yamt sync with head
 1.2 13-Jan-2011  pgoyette Last one for today: move t_ptm test from lib/libc/ to lib/libc/ttyio/
 1.1 07-Jan-2011  pgoyette Atf-ify a couple more tests
 1.3 05-Aug-2025  gutteridge t_ptm.c: now also validate O_CLOFORK can be set
 1.2 17-May-2023  gutteridge branches: 1.2.4;
t_ptm.c: add a test case that passes extra flags

Validate that O_NONBLOCK and O_CLOEXEC are actually set by
posix_openpt(3), as until circa 9.99.101 they were not.

If/when other flags are added like close-on-fork, this test could be
adjusted. The current concern is with supporting the expectations of
components like vte3, used by various graphical terminal clients.
 1.1 13-Jan-2011  pgoyette Last one for today: move t_ptm test from lib/libc/ to lib/libc/ttyio/
 1.2.4.1 08-Aug-2025  martin Pull up following revision(s) (requested by gutteridge in ticket #8):

tests/lib/libc/ttyio/t_ptm.c: revision 1.3
lib/libc/stdlib/posix_openpt.3: revision 1.11
sys/kern/tty_ptm.c: revision 1.47

tty_ptm.c: support setting O_CLOFORK here as well

t_ptm.c: now also validate O_CLOFORK can be set

posix_openpt.3: note O_CLOFORK is also now supported
 1.3 10-Jan-2017  christos PR/51803: Ngie Cooper: CID 978321: Don't leak openpty() fd.
 1.2 19-Apr-2011  martin branches: 1.2.26;
Make the test case independend of stdin being a terminal
 1.1 07-Jan-2011  pgoyette Atf-ify a couple more tests
 1.2.26.1 20-Mar-2017  pgoyette Sync with HEAD

RSS XML Feed