Commit graph

10052 commits

Author SHA1 Message Date
Brooks Davis e88e127279 power*/SYS.h: implement _SYSCALL_BODY() macro
Add _SYSCALL_BODY() macro which invokes the syscall via _SYCALL() and
calls cerror as required.  Use to implement PSEUDO() and RSYSCALL().

Reviewed by:	jhibbits
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43056
2023-12-21 17:57:14 +00:00
Robert Clausecker c91cd7d03a lib/libc/amd64/string/strcspn.S: always return earliest match in 17--32 char case
When matching against a set of 17--32 characters, strcspn() uses two
invocations of PCMPISTRI to match against the first 16 characters
of the set and then the remaining characters.  If a match was found in
the first half of the set, the code originally immediately returned
that match.  However, it is possible for a match in the second half of
the set to occur earlier in the vector, leading to that match being
overlooked.

Fix the code by checking if there is a match in the second half of the
set and taking the earlier of the two matches.

The correctness of the function has been verified with extended unit
tests and test runs against the glibc test suite.

Approved by:	mjg (implicit, via IRC)
MFC after:	1 week
MFC to:		stable/14
2023-12-21 03:17:17 +01:00
Robert Clausecker a0ecf2224e lib/libc/tests/string/strcspn_test.c: add test for correct match order
This new unit test verifies that if there are multiple
matches, the first match is returned, ignoring later
matches.

Approved by:	mjg (blanket, via IRC)
MFC after:	1 week
MFC to:		stable/14
2023-12-21 03:16:57 +01:00
Brooks Davis 8a1b84f861 arm/SYS.h: align with other arches
Rename SYSTRAP() macro to _SYSCALL() and add _SYSCALL_BODY() which invokes
the syscall via _SYCALL() and then calls cerror as required.  Use to
implement PSEUDO() and RSYSCALL() removing _SYSCALL_NOERROR().

Reviewed by:	imp
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43061
2023-12-18 22:28:42 +00:00
Brooks Davis d444ef5393 arm/SYS.h: remove unused CURBRK macro
The last use was removed in 2018 as part of a reimplementation of brk()
and sbrk() in commit 9d9fd255d6.

Reviewed by:	imp
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43060
2023-12-18 22:28:42 +00:00
Brooks Davis 8f465f509b {amd64,i386}/SYS.h: add _SYSCALL and _SYSCALL_BODY
Add a _SYSCALL(name) which calls the SYS_name syscall.  Use it to add a
_SYSCALL_BODY() macro which invokes the syscall and calls cerror as
required.  Use the latter to implement PSEUDO() and RSYSCALL().

Reviewed by:	imp, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43059
2023-12-18 22:28:42 +00:00
Brooks Davis 300bbb3a43 riscv/SYS.h: implement _SYSCALL_BODY() macro
Add _SYSCALL_BODY() macro which invokes the syscall via _SYCALL() and
calls cerror as required.  Use to implement PSEUDO() and RSYSCALL().

Reviewed by:	imp, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43057
2023-12-18 22:28:42 +00:00
Alan Somers 18e2c4175f Remove _POSIX_PRIORITIZED_IO references from man pages
We don't support it, so there's no need to tell readers what would
happen if we did.  Also, don't remind the user that a certain field is
ignored by aio_read.  Mentioning every ignored field would make the man
pages too verbose.

MFC after:	1 week
Sponsored by:	Axcient
Reviewed by:	Pau Amma <pauamma@gundo.com>
Differential Revision: https://reviews.freebsd.org/D42622
2023-12-18 08:06:55 -07:00
Peter Eriksson 7aa375dcc6 libc: correct some memory leaks in acl_to_text(3) and acl_to_text_np(3)
PR:	275232
MFC after:	1 week
2023-12-18 00:06:03 +02:00
Brooks Davis 5c7a909271 libc/i386/SYS.h: Remove unused LCALL macro
It appears that the only user of this macro was removed
with support for building a.out binaries in 2002 by commit
66422f5b7a.

Reviewed by:	imp, kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42997
2023-12-12 22:53:09 +00:00
Brooks Davis 9aaf4e3be6 libc/*/SYS.h: remove SYCALL macro
This has not been a univerally available interface since it was removed
from amd64 by commit efbef97de9 in 2004.
I removed the last consumers in 2016 when I replaced pipe(2) with
pipe2(2) in commit b60998c633.

Reviewed by:	imp, jhibbits
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42996
2023-12-12 22:52:41 +00:00
Brooks Davis 8ccd0b876e libc: expose execvpe for Linux compat
We already implemented execvpe internally with an _ prefix in libc so
go ahead and expose it for compatibility with Linux.

This reverts c605eea952.

Bump __FreeBSD_version for the addition and add definitions to supress
compat shims in libzfs (zfs changes were merged from upstream).

PR:		275370 (request and exp-run (thanks antoine!))
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D42846
2023-12-11 19:24:53 +00:00
Mariusz Zaborski a7100ae23a capsicum: introduce cap_rights_is_empty Function
Before this commit, we only had the capability to check if a specific
capability was set (using cap_rights_is_set function). However, there
was no efficient method to determine if a cap_rights_t structure doesn't
contain any capability. The cap_rights_is_empty function addresses
this gap.

PR:		275330
Reported by:	vini.ipsmaker@gmail.com
Reviewed by:	emaste, markj
Differential Revision:	https://reviews.freebsd.org/D42780
2023-12-11 12:15:46 +01:00
Konstantin Belousov 86e2bcbf47 strfmon.c: Use the restrict keyword directly
libc sources assume C99 or even C11 compiler already, unlike headers.
There is no reason to obfuscate the basic C constructs.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-10 23:28:25 +02:00
Jose Luis Duran 56a0d5444d strfmon: style fixes
Check style(9) with checkstyle9.pl and clang-format.
No functional change intended.

MFC after:	1 week
2023-12-10 23:28:16 +02:00
Jose Luis Duran 6abee52e0d strfmon: Silence scan-build warning
The value stored to 'value' is never read.

Reported by:	Jenkins (scan-build)
MFC after:	1 week
2023-12-09 03:06:28 +02:00
Jose Luis Duran 2a163c3649 strfmon.3: Cleanup example code
- xlocale.h would have been required if using strfmon_l().  Here,
  setlocale() just requires locale.h.
- ANSIfy function declaration.
- Add a final return().

MFC after:	1 week
2023-12-09 03:06:13 +02:00
Brooks Davis fc0288993c libc: simplify MDASM/NOASM checks
Use boolean evaluation of :M matches and a single if statement.

Reviewed by:	imp, kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42915
2023-12-06 20:49:08 +00:00
Brooks Davis ec27c0bb3e libc: don't needlessly add vfork.o to NOASM
For architectures where vfork.S was named Ovfork.S this was needed, but
it was always pointless here as an entry in either MDASM or NOASM is
equivalent.

Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42914
2023-12-06 20:49:08 +00:00
Brooks Davis 0ea469bcd5 libc: rename arm and i386 Ovfork.S to vfork.S
While this has been Ovfork.S forever on i386 it differs from other
syscalls that require wrappers for no obvious reason so fix that.

Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42909
2023-12-06 20:49:08 +00:00
Brooks Davis 7893419d49 Remove never implemented sbrk and sstk syscalls
Both system calls were stubs returning EOPNOTSUPP and libc did not
provide _ or __sys_ prefixed symbols.  The actual implementation of
sbrk(2) is on top of the undocumented break(2) system call.

Technically this is a change in ABI, but no non-contrived program ever
called these syscalls.

Reviewed by:	kib, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42872
2023-12-04 20:36:08 +00:00
Alan Somers c2ed7a6360 sigaction.2: clarify that fork isn't async-signal-safe, but _Fork is
[skip ci]

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D42865
2023-12-01 08:59:36 -07:00
Jamie Gritton ed31b3f4a1 jail: Don't allow jail_set(2) to resurrect dying jails.
Currently, a prison in "dying" state (removed but still holding
resources) can be brought back to alive state via "jail -d", or
the JAIL_DYING flag to jail_set(2).  This seemed like a good idea
at the time.

Its main use was to improve support for specifying the jid when
creating a jail, which also seemed like a good idea at the time.
But resurrecting a jail that was partway through thr process of
shutting down is trouble waiting to happen.

This patch deprecates that flag, leaving it as a no-op for creating
jails (but still useful for looking at dying jails).  It sill allows
creating a new jail with the same jid as a dying one, but will renumber
the old one in that case.  That's imperfect, but allows for current
behavior.

Reviewed by:	bz
Differential Revision:	https://reviews.freebsd.org/D28150
2023-11-29 16:12:13 -08:00
Brooks Davis c96772227b memfd_create: don't allocate heap memory
Rather than calling calloc() to allocate space for a page size array to
pass to getpagesizes(), just follow the getpagesizes() implementation
and allocate MAXPAGESIZES elements on the stack.  This avoids the need
for the allocation.

While this does mean that a new libc is required to take advantage of a
new huge page size, that was already true due to getpagesizes() using a
static buffer of MAXPAGESIZES elements.

Reviewed by:	kevans, imp, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42710
2023-11-28 17:09:27 +00:00
Brooks Davis c3207e2d25 memfd_create: move implementation to libc/gen
Due to memfd_create(3)'s construction of a path to pass to shm_open2(2),
it has a much larger than typical dependency footprint for a system
call wrapper (the list currently includes calloc, memset, sprintf, and
strlen).  As such, split it off into its own file under libc/gen to
lighten libc/sys's dependency list.

Reviewed by:	kevans, imp, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42709
2023-11-28 17:09:27 +00:00
Brooks Davis ea180bb379 getpagesize(3): drop support for non-ELF kernels
AT_PAGESZ was introduced with ELF support in 1996 (commit
e1743d02cd) so we can safely count on
being able to use it to get our page size via elf_aux_info().  As such
we don't need a fallback sysctl query.

Save a few bytes of bss by dropping caching as elf_aux_info() runs
in constant time for a given query.

Reviewed by:	kevans, imp, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42708
2023-11-28 17:09:26 +00:00
Brooks Davis df65c89375 getpagesizes(3): drop support for kernels before 9.0
AT_PAGESIZES and elf_aux_info where added prior to FreeBSD 9.0 in commit
ee235befcb.  It's safe to say that a
FreeBSD 15 libc won't work on a 8.x kernel so drop sysctl fallback.

Reviewed by:	kevans, imp, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D42707
2023-11-28 17:09:26 +00:00
Warner Losh a2f733abcf lib: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:23:59 -07:00
Warner Losh 0b8224d1cc Remove copyright strings ifdef'd out
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh 5b31cc94b1 sccs: Manual changes
For the uncommon items: Go through the tree and remove sccs tags that
didn't fit any nice pattern. If in the neighborhood, other SCM tags were
removed when they were detritis of long-ago CVS somehow in the early
mists of the project. Some adjacent copyrights stringswere removed (they
duplicated the copyright notices in the file). This also removed
non-standard formations of omission of SCCS tags (usually by adding an
extra #if 0 somewhere.

After this commit, a number of strings tagged with the 'what' @(#)
prefix remain, but they are primarily copyright notices.

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh dc36d6f9bb lib: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:28 -07:00
Ka Ho Ng d030761168 dirdeps: Update/fix Makefile.depend* for toolchain
This fixes make pseudo/toolchain.
2023-11-26 20:50:13 -05:00
Brooks Davis 9fc0ff9d85 libc: remove some obsolete VCS data
These wide char support files were copied from the previous versions
with expanded $FreeBSD$ strings in #if 0 blocks.  Remove them and the
scssid definitions in the same #if 0 blocks.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42688
2023-11-21 22:46:43 +00:00
Alan Somers 04cfe6c12c aio_read.2: correct the description of aio_buf
Looks like a copypasta from aio_write.2.

[skip ci]

Reported by:	Paul Floyd <pjfloyd@wanadoo.fr>
MFC after:	1 week
Sponsored by:	Axcient
Reviewed by:	jilles (manpages)
Differential Revision: https://reviews.freebsd.org/D42621
2023-11-21 09:52:02 -07:00
Andrew Turner fd5aaf2ea0 libc: Teach libc about the BTI elf note
Add the Branch Target Identification (BTI) note to libc assembly
sources. As all obect files need the note for the library to have it
we need to insert it in all asm files.

Reviewed by:	emaste, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42228
2023-11-21 10:02:51 +00:00
Gordon Bergling 8c8ffe541e Add a HISTORY section for memcpy(3) and mempcpy(3)
The memcpy() function first appeared in AT&T System V UNIX and was
reimplemented for 4.3BSD-Tahoe. The mempcpy() function first appeared in
FreeBSD 13.1.

PR:	272227
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42630
2023-11-18 10:09:40 +01:00
Gordon Bergling fa9f742201 getpeerid.3: Clarify the 's' argument
The argument 's' of getpeerid(3) must be a connected UNIX-domain socket,
so document it.

PR:	248614
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42629
2023-11-18 10:02:12 +01:00
Brooks Davis 500bf0592c libc: remove unused stub vdso timecounter implementations
All supported architectures have shared page support so remove this
unused stub.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D42619
2023-11-15 23:43:56 +00:00
Brooks Davis c704518681 libc: centralize a few numeric symbols
fabs, __infinity, and __nan are universally implemented so declare them
in gen/Symbol.map.

We would also include __flt_rounds, but  it's under FBSD_1.3 on arm so
until that's gone we're stuck with it.  Likewise, everyone but i386
implements fp[gs]etmask.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42618
2023-11-15 23:42:37 +00:00
Brooks Davis 5d79b5445e libc: centralize makecontext symbols
Declare makecontext() and __makecontext() symbols centrally as they are
always implemented.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D42617
2023-11-15 23:42:18 +00:00
Brooks Davis 1c656143be libc: centralize {_,sig,}{set,long}jmp symbols
These symbols are universally exposed and documented so declare them
centrally.  Double- and triple-underscore versions exist on some
platforms, but leave those alone for now.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D42616
2023-11-15 23:41:35 +00:00
Brooks Davis ff3a9d8e29 libc: centralize ntoh symbols
These are implemented by net/ntoh.c via headers and compiler intrinsics
so declare them in net/Symbol.map.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42615
2023-11-15 23:40:54 +00:00
Brooks Davis e4a1800f06 libc: further centralize syscall symbols
All architectures necessarily implement _exit(2) and vfork(2) so
declare them in sys/Symbol.map.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42614
2023-11-15 23:40:33 +00:00
Brooks Davis e3e9c205ff lib{c,lzma,z}: remove -DSYMBOL_VERSIONING from CFLAGS
This was part of a libkse and libpthread transition aide when libc
gained symbol versions in e62165c8b0
(March 2006).  The code that cared about this macro was removed in
commit 00fb440c1a (May 2007) when symbol
versioning was enabled by default and libthr became the default
threading library.  For unknown reasons, it stayed in libc (which
seemingly never used it) and seems to have been copied to liblzma and
libz.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D42613
2023-11-15 23:39:46 +00:00
Alan Somers 24938f9311 lib/libc/rpc: switch the per-fd structs in clnt_{dg,vc}.c to RB Trees
This saves oodles of memory, especially when "ulimit -n" is large.  It
also prevents a buffer overflow if getrlimit should fail.

Also replace per-fd condvars with mutexes to simplify the code.

PR:		274968
MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D42597
2023-11-15 16:12:50 -07:00
Alan Somers a5c2f4e939 libc/libc/rpc: refactor some global variables
* Combine dg_fd_locks and dg_cv into one array.
* Similarly for vc_fd_locks and vc_cv
* Turn some macros into inline functions

This is a mostly cosmetic change to make refactoring these strutures in
a future commit easier.

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D42597
2023-11-15 16:12:50 -07:00
Brooks Davis 1ca63a8219 libc: Remove empty comments in Symbol.map
These were left over from $FreeBSD$ removal.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D42612
2023-11-15 17:51:03 +00:00
Brooks Davis b73eace889 libc/<arch>/sys/Makefile.inc: remove cruft
Remove stray blank lines left over from $FreeBSD$ removal as well as
some CVS-era (perhaps pre-repocopy) version comments.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D42611
2023-11-15 17:50:53 +00:00
Robert Clausecker b49596de26 lib/libc/tests/string: add extended unit tests for strcmp()
This changeset add a new set of tests that comprehensively test strcmp() on
various alignments of the input. This made it easy to smoke out many
exciting new bugs in the new SSE strcmp() implementation from D41971.

MFC after:	1 week
Reviewed by:	ngie
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41970
2023-11-14 12:37:06 -05:00
Brooks Davis da8238d6cf libc: fix typo in Makefile comment
MFC after:	1 week
2023-11-13 23:05:11 +00:00
R. Christian McDonald 6e5b1ff71e libc: enable initial-exec (IE) as default thread-local storage model on arm
As suggested by jrtc27@ in https://reviews.freebsd.org/D42415, this
patch enables IE as default thread-local storage model in libc on arm.

Reviewed by:	kib
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42445
2023-11-09 21:24:23 +01:00
Ed Maste 4e0e01bf65 fflush: correct buffer handling in __sflush
Two additional stdio changes followed 86a16ada1e and need to be
reverted as part of the fflush fix.

This reverts commit 6e13794fbe.
This reverts commit bafaa70b6f.

Fixes: d09a3bf72c ("fflush: correct buffer handling in __sflush")
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42491
2023-11-07 11:03:34 -05:00
Ed Maste 418f026bd5 libc: remove unused errno.h include
errno.h was added in 44cf1e5eb4, which has been reverted.

Fixes: d09a3bf72c ("fflush: correct buffer handling in __sflush")
Sponsored by: The FreeBSD Foundation
2023-11-07 10:23:20 -05:00
Dag-Erling Smørgrav b8dbfb0a6c fflush: Add test for buffer handling in __sflush
Sponsored by:	Klara, Inc.
2023-11-07 08:21:12 -05:00
Dag-Erling Smørgrav d09a3bf72c fflush: correct buffer handling in __sflush
This fixes CVE-2014-8611 correctly.

The commit that purported to fix CVE-2014-8611 (805288c2f0) only hid
it behind another bug.  Two later commits, 86a16ada1e and
44cf1e5eb4, attempted to address this new bug but mostly just confused
the issue.  This commit rolls back the three previous changes and fixes
CVE-2014-8611 correctly.

The key to understanding the bug (and the fix) is that `_w` has
different meanings for different stream modes.  If the stream is
unbuffered, it is always zero.  If the stream is fully buffered, it is
the amount of space remaining in the buffer (equal to the buffer size
when the buffer is empty and zero when the buffer is full).  If the
stream is line-buffered, it is a negative number reflecting the amount
of data in the buffer (zero when the buffer is empty and negative buffer
size when the buffer is full).

At the heart of `fflush()`, we call the stream's write function in a
loop, where `t` represents the return value from the last call and `n`
the amount of data that remains to be written.  When the write function
fails, we need to move the unwritten data to the top of the buffer
(unless nothing was written) and adjust `_p` (which points to the next
free location in the buffer) and `_w` accordingly.  These variables have
already been set to the values they should have after a successful
flush, so instead of adjusting them down to reflect what was written,
we're adjusting them up to reflect what remains.

The bug was that while `_p` was always adjusted, we only adjusted `_w`
if the stream was fully buffered.  The fix is to also adjust `_w` for
line-buffered streams.  Everything else is just noise.

Fixes: 805288c2f0
Fixes: 86a16ada1e
Fixes: 44cf1e5eb4
Sponsored by:	Klara, Inc.
2023-11-07 08:21:12 -05:00
Dag-Erling Smørgrav 1f90b4edff fflush: Split a temporary variable in two.
It is clearer to avoid reusing temporary variables for different
purposes.

Sponsored by:	Klara, Inc.
2023-11-03 13:38:12 -04:00
Warner Losh 559a218c9b libc: Purge unneeded cdefs.h
These sys/cdefs.h are not needed. Purge them. They are mostly left-over
from the $FreeBSD$ removal. A few in libc are still required for macros
that cdefs.h defines. Keep those.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D42385
2023-11-01 16:44:30 -06:00
Warner Losh 0527c9bdc7 ino64: Remove 'forward compat' code for this
Forward compatibility code was added for running newer ino64 binaries on
older kernels as a transition aide. Now that ino64 has been in the tree
6 years, this code is no longer useful and should have been removed long
ago.  Remove it now. Should be no user-visible changes at this point as
all the 'upgrade' scenarios it was intended for are long since past.

Also need to remove this stuff from rtld since the _foo versions
no longer exist.

Sponsored by:		Netflix
Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D42382
2023-10-31 15:26:44 -06:00
Jessica Clarke 1c1f229e91 libc: Strip plentiful trailing whitespace from aarch64+arm makecontext.c 2023-10-28 02:45:06 +01:00
Warner Losh 314542de6d clock_gettime: Minor clarification
Add a note saying that the CLOCK_BOOTTIME is unrelated to FreeBSD's
kern.boottime sysctl. Make a minor tweak to markup.

Feedback from:		pauammu
Sponsored by:		Netflix
Differential Revsion:	https://reviews.freebsd.org/D36037
2023-10-27 11:20:28 -06:00
Warner Losh 5e50a0f39f strlcpy/strlcat: Remove references to snprintf
While strlcpy and snprintf are somewhat similar, there's big differences
between strlcat and snprintf which leads to confusion. Remove the
comparison, since it's ultimately not that useful: the snprintf man page
has similar language to strlcpy, so it doesn't provide a better
reference. The two implementations are otherwise unrelated.

Reviewed by:		bcr
Sponsored by:		Netflix
Differential Revision:  https://reviews.freebsd.org/D27228
2023-10-27 10:13:50 -06:00
Brooks Davis 4894205482 procctl.2: improve phrasing for ASLR disable
Reported by:	jrtc27
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D42364
2023-10-26 18:40:08 +01:00
Dag-Erling Smørgrav ca57a343e8 libc: More missing MLINKS.
Differential Revision:	https://reviews.freebsd.org/D42292
2023-10-20 12:29:40 +02:00
Dag-Erling Smørgrav dc41de36ab libc: Fix missing or misspelled MLINKS.
Differential Revision:	https://reviews.freebsd.org/D42192
2023-10-18 16:07:46 +02:00
Dag-Erling Smørgrav a66d27e22f memory(3): Mention more functions.
Differential Revision:	https://reviews.freebsd.org/D42191
2023-10-18 16:07:46 +02:00
Dag-Erling Smørgrav 64fc8a936c hesiod: Modernize.
Reviewed by:	zlei
Differential Revision:	https://reviews.freebsd.org/D42190
2023-10-18 16:05:55 +02:00
Robert Clausecker 5048c1b855 lib/libc/amd64/string: add timingsafe_memcmp() assembly implementation
Conceptually very similar to timingsafe_bcmp(), but with comparison
logic inspired by Elijah Stone's fancy memcmp. A baseline (SSE)
implementation was omitted this time as I was not able to get it to
perform adequately.  Best I got was 8% over the scalar version for
long inputs, but slower for short inputs.

Sponsored by:	The FreeBSD Foundation
Approved by:	security (cperciva)
Inspired by:	https://github.com/moon-chilled/fancy-memcmp
Differential Revision:	https://reviews.freebsd.org/D41696
2023-10-15 15:25:53 -04:00
Robert Clausecker 76c2b331bc lib/libc/amd64/string: add timingsafe_bcmp(3) scalar, baseline implementations
Very straightforward and similar to memcmp(3). The code has
been written to use only instructions specified as having
data operand independent timing by Intel.

Sponsored by:	The FreeBSD Foundation
Approved by:	security (cperciva)
Differential Revision:	https://reviews.freebsd.org/D41673
2023-10-15 15:19:04 -04:00
Ed Maste a5ed6a815e ptsname.3: accommodate upcoming POSIX Issue 8 ptsname_r
POSIX has accepted a proposal[1] to add glibc-compatible ptsname_r.  It
indicates an error by returning the error number, rather than returning
-1 and setting errno.  Update RETURN VALUES in ptsname_r's man page now
to encourage folks to test that the return value != 0 rather than == -1.

[1] https://www.austingroupbugs.net/bug_view_page.php?bug_id=508

Reported by:	Collin Funk
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42204
2023-10-13 22:10:21 -04:00
Ed Maste a572dfa1bf ktrace.2: correct kern.ktrace.genio_size sysctl name
The man page had `kern.ktrace.geniosize` but the sysctl node contains an
underscore.

PR:		274274
Reported by:	Ivan Rozhuk
Sponsored by:	The FreeBSD Foundation
2023-10-10 21:23:02 -04:00
Robert Clausecker c6cc06d465 lib/libc/tests/string: expand memcmp test to bcmp, timingsafe_{b,mem}cmp
The four functions more or less perform the same operation.
Reuse the same unit test with slight changes so we can cover
them all.  Constant-time operation is not verified for the
timingsafe_* functions.

Sponsored by:	The FreeBSD Foundation
Approved by:	ngie
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D41528
2023-10-02 15:25:31 -04:00
Robert Clausecker b166580681 lib/libc/tests/string/memcmp_test.c: extend test to support custom memcmp function
Extend the tests to permit loading an external memcmp function
and testing it over using the libc version. This was added by the
example of other tests in the test suite doing the same thing and
helped tremendously in development.

This change was originally part of D41442 but was taken out to
permit separate review as extrapolated from @ngie's request in
D41349.

Sponsored by:	FreeBSD Foundation
Approved by:	ngie
Differential Revision:	https://reviews.freebsd.org/D41528
2023-10-02 15:25:21 -04:00
Olivier Certner d952820105 ptrace(2): Disabling: Describe influence of security.bsd.see_jail_proc
Reviewed by:            mhorne, emaste, pauamma_gundo.com
MFC after:              2 weeks
Sponsored by:           Kumacom SAS
Differential Revision:  https://reviews.freebsd.org/D41109
2023-09-28 12:05:47 -03:00
Dag-Erling Smørgrav c7dd4601ae libc: Add a rudimentary test for quick_exit(3).
Sponsored by:	Klara, Inc.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D41937
2023-09-26 22:07:10 +02:00
Dag-Erling Smørgrav 1dc3abb052 libc: Rewrite quick_exit() and at_quick_exit() using C11 atomics.
Compiler memory barriers do not prevent the CPU from executing the code
out of order.  Switch to C11 atomics.  This also lets us get rid of the
mutex; instead, loop until the compare_exchange succeeds.

While here, change the return value of at_quick_exit() on failure to
the more traditional -1, matching atexit().

Sponsored by:	Klara, Inc.
Reviewed by:	Olivier Certner, kevans, kib
Differential Revision:	https://reviews.freebsd.org/D41936
2023-09-26 22:07:10 +02:00
Jens Schweikhardt e8a7cee673 Add paragraph about kern.mqueue sysctls and their defaults. 2023-09-26 21:41:29 +02:00
Christos Zoulas 3fb80f1476 regcomp: use unsigned char when testing for escapes
- cast GETNEXT to unsigned where it is being promoted to int to prevent
  sign-extension (really it would have been better for PEEK*() and
  GETNEXT() to return unsigned char; this would have removed a ton of
  (uch) casts, but it is too intrusive for now).
- fix an isalpha that should have been iswalpha

PR:		264275, 274032
Reviewed by:	kevans, eugen (previous version)
Obtained from:	NetBSD
Differential Revision:	https://reviews.freebsd.org/D41947
2023-09-26 00:49:14 +02:00
John Baldwin eba230afba Purge more stray embedded $FreeBSD$ strings
These do not use __FBSDID but instead use bare char arrays.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41957
2023-09-25 07:54:56 -07:00
John Baldwin 16837d353c Remove a few more stray __FBSDID uses
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41954
2023-09-25 07:49:52 -07:00
Yuri Pankov 95a4709b2c Create namespace for the symbols added during 15-CURRENT cycle
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D41935
2023-09-22 10:16:29 +02:00
Dag-Erling Smørgrav c34fce8a03 Fix typos in acl_get_entry(3) manual page.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D41924
2023-09-22 09:43:19 +02:00
Dag-Erling Smørgrav b653faaa19 Remove mention of defunct mailing list from acl / mac man pages.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D41923
2023-09-22 09:43:19 +02:00
Ed Maste b15f640037 swapon.2: correct FreeBSD release that introduced swapoff
It was introduced in 92da00bb24, after 5.0 and beforen 5.1.  Reported
in https://github.com/ziglang/zig/issues/16590.
2023-09-18 10:01:38 +01:00
Robert Clausecker 601fd768cf lib/libc/tests/string/strcspn_test.c: extend tests to catch previous bug
This extends the strcspn() unit tests to catch mistakes in the
implementation that only appear when a mismatch occurs in a certain
position of the string against a certain position of the set.

See also:	52d4a4d4e0
Sponsored by:	The FreeBSD Foundation
Approved by:	imp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D41821
2023-09-16 20:40:13 -04:00
Robert Clausecker 953b93cf24 lib/libc/amd64/string/memcmp.S: harden against phony buffer lengths
When memcmp(a, b, len) (or equally, bcmp) is called with a phony length
such that a + len < a, the code would malfunction and not compare the
two buffers correctly.  While such arguments are illegal (buffers do not
wrap around the end of the address space), it is neverthless conceivable
that people try things like memcmp(a, b, SIZE_MAX) to compare a and b
until the first mismatch, in the knowledge that such a mismatch exists,
expecting memcmp() to stop comparing somewhere around the mismatch.
While memcmp() is usually written to confirm to this assumption, no
version of ISO/IEC 9899 guarantees this behaviour (in contrast to
memchr() for which it is).

Neverthless it appears sensible to at least not grossly misbehave on
phony lengths.  This change hardens memcmp() against this case by
comparing at least until the end of the address space if a + len
overflows a 64 bit integer.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg (blanket, via IRC)
See also:	b2618b651b
MFC after:	1 week
2023-09-16 00:20:32 -04:00
Robert Clausecker 52d4a4d4e0 lib/libc/amd64/string/strcspn.S: fix behaviour with sets of 17--32
When a string is matched against a set of 17--32 characters, each chunk
of the string is matched first against the first 16 characters of the
set and then against the remaining characters.  We also check at the
same time if the string has a nul byte in the current chunk, terminating
the search if it does.

Due to misconceived logic, the order of checks was "first half of set,
nul byte, second half of set", meaning that a match with the second half
of the set was ignored when the string ended in the same 16 bytes.
Reverse the order of checks to fix this problem.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg (blanket, via IRC)
MFC after:	1 week
MFC to:		stable/14
2023-09-11 22:58:43 -04:00
Dag-Erling Smørgrav 88a9b6e1ed libc: Don't assume signed char.
MFC after:	3 days
Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D41814
2023-09-11 13:18:25 +00:00
Robert Clausecker b2618b651b lib/libc/amd64/string/memchr.S: fix behaviour with overly long buffers
When memchr(buf, c, len) is called with a phony len (say, SIZE_MAX),
buf + len overflows and we have buf + len < buf.  This confuses the
implementation and makes it return incorrect results.  Neverthless we
must support this case as memchr() is guaranteed to work even with
phony buffer lengths, as long as a match is found before the buffer
actually ends.

Sponsored by:	The FreeBSD Foundation
Reported by:	yuri, des
Tested by:	des
Approved by:	mjg (blanket, via IRC)
MFC after:	1 week
MFC to:		stable/14
PR:		273652
2023-09-10 08:52:59 -04:00
Robert Clausecker 331737281c lib/libc/amd64/string: implement strnlen(3) trough memchr(3)
Now that we have an optimised memchr(3), we can use it to implement
strnlen(3) with better perofrmance.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
MFC after:	1 week
MFC to:		stable/14
Differential Revision:	https://reviews.freebsd.org/D41598
2023-09-08 17:22:31 -04:00
Robert Clausecker de12a689fa lib/libc/amd64/string: add memchr(3) scalar, baseline implementation
This is conceptually similar to strchr(3), but there are
slight changes to account for the buffer having an explicit
buffer length.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
MFC after:	1 week
MFC to:		stable/14
Differential Revision:	https://reviews.freebsd.org/D41598
2023-09-08 17:22:20 -04:00
Robert Clausecker 7084133cde lib/libc/amd64/string: add strspn(3) scalar, x86-64-v2 implementation
This is conceptually very similar to the strcspn(3) implementations
from D41557, but we can't do the fast paths the same way.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
MFC after:	1 week
MFC to:		stable/14
Differential Revision:	https://reviews.freebsd.org/D41567
2023-09-08 17:21:59 -04:00
Robert Clausecker 468adddd75 lib/libc/tests/string: derive strspn(3) tests from strcspn(3) tests
To cover the new optimised amd64 strspn(3) SIMD implementation, extend
the previously written strcspn(3) unit test to also cover strspn(3).

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
MFC after:	1 week
MFC to:		stable/14
Differential Revision:	https://reviews.freebsd.org/D41567
2023-09-08 17:21:59 -04:00
Robert Clausecker 35a5359406 lib/libc/tests/string: add unit tests for strcspn(3)
We currently use the NetBSD test suite to cover strcspn(3).  It only
contains a very rudimentary test of this function.  This all new set
of unit tests for the FreeBSD test suite should cover many more edge
cases relating to alignment issues.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
MFC after:	1 week
MFC to:		stable/14
Differential Revision: https://reviews.freebsd.org/D41557
2023-09-08 17:21:31 -04:00
Robert Clausecker 474408bb79 lib/libc/amd64/string: add strcspn(3) scalar, x86-64-v2 implementation
This changeset adds both a scalar and an x86-64-v2 implementation
of the strcspn(3) function to libc. A baseline implementation does not
appear to be feasible given the requirements of the function.

The scalar implementation is similar to the generic libc implementation,
but expands the bit set into a byte set to reduce latency, improving
performance. This approach could probably be backported to the generic
C version to benefit other platforms.

The x86-64-v2 implementation is built around the infamous pcmpistri
instruction. An alternative implementation based on the Muła/Langdale
algorithm [1] was prototyped, but performed worse than the pcmpistri
approach except for sets of more than 16 characters with long input
strings.

All implementations provide special cases for the empty set (reduces to
strlen as well as single-character sets (reduces to strchr). The
x86-64-v2 kernel falls back to the scalar implementation for sets of
more than 32 characters. This limit could be raised by additional
multiples of 16 through the use of additional pcmpistri code paths, but
I consider this case to be too rare to be of importance.

[1]: http://0x80.pl/articles/simd-byte-lookup.html

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
MFC after:	1 week
MFC to:		stable/14
Differential Revision:	https://reviews.freebsd.org/D41557
2023-09-08 17:20:19 -04:00
Li-Wen Hsu 604f6bf022
powerpcspe: Fix build
Copy _fpmath.h from powerpc, which is the same as the one in powerpc64.

Sponsored by:	The FreeBSD Foundation
2023-09-09 04:46:25 +08:00
Dag-Erling Smørgrav 12b1c1e3fb libc: Add test cases for N2680.
This adds test cases for %wN and %wfN to the printf(3) and scanf(3) tests.

While here, fix a few nits in the N2630 test cases.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D41743
2023-09-07 06:40:14 +00:00
Dag-Erling Smørgrav bce0bef3c6 libc: Implement N2680.
This adds specific width length modifiers in the form of wN and wfN (where N is 8, 16, 32, or 64) which allow printing intN_t and int_fastN_t without resorting to casts or PRI macros.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41725
2023-09-07 06:40:14 +00:00
Dag-Erling Smørgrav 294bd2827e libc: Suppress format checks on printf() / scanf() tests.
Reviewed by:	jrtc27, markj, emaste
Differential Revision:	https://reviews.freebsd.org/D41727
2023-09-07 06:40:14 +00:00
Dag-Erling Smørgrav 4ec9ee9912 libc: Add a wide version of snprintf_test.
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41726
2023-09-07 06:40:14 +00:00
Warner Losh b19d8afe4d msun: LIBCSRCDIR is too fragile, use ${SRCTOP}/lib/libc instead
LIBCSRCDIR is defined in bsd.libnames.mk, which is read in later in the
Makefile than the line:

.if exists(${LIBCSRCDIR}/${MACHINE_ARCH})

so we test to see if /${MARCHIN_ARCH} exists which it usually doesn't
(but did for me since I mounted 13.2R SD image there).  Move to defining
our own LIBC_SRCTOP in terms of SRCTOP to treat these uniformily.

Sponsored by:		Netflix
Reviewed by:		sjg
Differential Revision:	https://reviews.freebsd.org/D41661
2023-09-05 16:08:02 -06:00
Mateusz Piotrowski 5b7a776f48 getdirentries.2: Reference dir(5)
As a note, parts of manual pages getdirentries(2) and dir(5) should
probably be consolidated.

MFC after:	3 days
2023-09-05 15:50:45 +02:00
Mateusz Piotrowski 52d374a067 getdirentries.2: Improve readability of dirent members
MFC after:	3 days
2023-09-05 15:50:45 +02:00
Robert Clausecker d41afb8146 */string.3,arch.7,environ.7: add cross-references to simd(7)
With the new simd-dispatch framework documented in simd(7),
add cross-references to the new man pages to appropriate places.

Sponsored by:	The FreeBSD Foundation
Approved by:	emaste
MFC to:		stable/14
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D41697
2023-09-05 09:33:12 -04:00
Mateusz Piotrowski 3a02df5e27 getdirentries.2: Reference directory(3)
MFC after:	3 days
2023-09-05 11:39:39 +02:00
Dag-Erling Smørgrav c9f5889d05 libc: Further nit in fopen(3) man page.
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D41687
2023-09-01 22:53:35 +00:00
Trond Endrestøl b7000cadfb scandir.3: Fix several typos
PR:		273480
Reviewed by:	markj
MFC after:	1 week
2023-09-01 16:57:03 -04:00
Dag-Erling Smørgrav 5a57401e71 libc: Fix fmemopen(3) prototype in fopen(3) man page.
While here, also update a mention of ANSI C.

Sponsored by:	Klara, Inc.
Reviewed by:	kevans, markj
Differential Revision:	https://reviews.freebsd.org/D41686
2023-09-01 20:56:26 +00:00
Brooks Davis 09e32b2fdd libc: add LIBC_MALLOC option
This will enable alternative mallocs to be included in the tree and
selected by setting LIBC_MALLOC.  As there is only one today (jemalloc)
this option does nothing, but we expect to add other implementations
in the future.  This will also reduce diffs to CheriBSD.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D41660
2023-09-01 17:54:23 +01:00
Mina Galić 09ec5e67a7 libc: fix history for strverscmp(3) and versionsort(3)
strverscmp(3) and versionsort(3) where first released in 13.2

PR:		273401
Reviewed by:	kib
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D41617
2023-08-31 14:52:31 +03:00
Dag-Erling Smørgrav aca3bd1602 libc: Fix fixed-width case in the new integer parser.
Fixes:		d9dc1603d6
Differential Revision:	https://reviews.freebsd.org/D41622
2023-08-28 23:38:19 +00:00
Li-Wen Hsu e0752f431b
Revert "libc/locale tests: temporarily skip lib.libc.locale.c16rtomb_test.c16rtomb_utf_8_test"
This reverts commit b80572fe3b.

This has been fixed in e2030ca246.

PR:		265871
2023-08-29 01:18:42 +08:00
Dag-Erling Smørgrav 76edfabbec libc: Document support for binary integers.
Reviewed by:	debdrup, emaste
Differential Revision:	https://reviews.freebsd.org/D41522
2023-08-28 15:34:17 +00:00
Dag-Erling Smørgrav b9385720f3 libc: Add unit tests for N2630 and possible collateral damage.
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41512
2023-08-28 15:34:05 +00:00
Dag-Erling Smørgrav d9dc1603d6 libc: Implement N2630.
This adds formatted input/output of binary integer numbers to the printf(), scanf(), and strtol() families, including their wide-character counterparts.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41511
2023-08-28 15:33:51 +00:00
Robert Clausecker 3d8ef251aa lib/libc/amd64/string/strchrnul.S: fix edge case in scalar code
When the buffer is immediately preceeded by the character we
are looking for and begins with one higher than that character,
and the buffer is misaligned, a match was errorneously detected
in the first character.  Fix this by changing the way we prevent
matches before the buffer from being detected: instead of
removing the corresponding bit from the 0x80..80 mask, set the
LSB of bytes before the buffer after xoring with the character we
look for.

The bug only affects amd64 with ARCHLEVEL=scalar (cf. simd(7)).
The change comes at a 2% performance impact for short strings
if ARCHLEVEL is set to scalar.  The default configuration is not
affected.

os: FreeBSD
arch: amd64
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
        │ strchrnul.scalar.0.out │       strchrnul.scalar.2.out       │
        │         sec/op         │   sec/op     vs base               │
Short                57.89µ ± 2%   59.08µ ± 1%  +2.07% (p=0.030 n=20)
Mid                  19.24µ ± 0%   19.73µ ± 0%  +2.53% (p=0.000 n=20)
Long                 11.03µ ± 0%   11.03µ ± 0%       ~ (p=0.547 n=20)
geomean              23.07µ        23.43µ       +1.53%

        │ strchrnul.scalar.0.out │       strchrnul.scalar.2.out        │
        │          B/s           │     B/s       vs base               │
Short               2.011Gi ± 2%   1.970Gi ± 1%  -2.02% (p=0.030 n=20)
Mid                 6.049Gi ± 0%   5.900Gi ± 0%  -2.47% (p=0.000 n=20)
Long                10.56Gi ± 0%   10.56Gi ± 0%       ~ (p=0.547 n=20)
geomean             5.045Gi        4.969Gi       -1.50%

MFC to:		stable/14
MFC after:	3 days
Approved by:	mjg (blanket, via IRC)
Sponsored by:	The FreeBSD Foundation
2023-08-25 21:21:54 +02:00
Dag-Erling Smørgrav 9b5d724cad libc: Add timespec_getres(3) as per C23.
This also adds support for TIME_MONOTONIC to timespec_get(3).

Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D41524
2023-08-24 21:31:54 +00:00
Dag-Erling Smørgrav b8b6bef43f libc: Fix parsing of hexadecimal numbers in strtol() family.
This had previously been partly fixed in 2571c7f720.

MFC after:	1 week
Reviewed by:	imp, allanjude, emaste
Differential Revision:	https://reviews.freebsd.org/D41510
2023-08-24 21:31:54 +00:00
Jake Freeland 8544651dc5 timerfd: Add manual page.
This manual page accompanies the timerfd system calls.

Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D40218
2023-08-24 14:29:06 -06:00
Jake Freeland af93fea710 timerfd: Move implementation from linux compat to sys/kern
Move the timerfd impelemntation from linux compat code to sys/kern. Use
it to implement the new system calls for timerfd. Add a hook to kern_tc
to allow timerfd to know when the system time has stepped. Add kqueue
support to timerfd. Adjust a few names to be less Linux centric.

RelNotes: YES
Reviewed by: markj (on irc), imp, kib (with reservations), jhb (slack)
Differential Revision: https://reviews.freebsd.org/D38459
2023-08-24 14:28:56 -06:00
Kyle Evans 939199a2b5 libc: iconv: zero out cv_shared on allocation
Right now we have to zero-initialize most fields in the varius callers,
but this is a little error prone.  Simplify it by zeroing it out upon
allocation instead, drop the other redundant initialization.

Reviewed by:	markj
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D41546
2023-08-22 22:40:45 -05:00
Kyle Evans e2030ca246 libc: fix c*rtomb/mbrtoc*
In 693f88c9da ("iconv_std: complete the //IGNORE support"), we
more completely implemented //IGNORE, which changed the semantics of
ci_discard_ilseq. DISCARD_ILSEQ semantics are supposed to match
//IGNORE, so we really can't do much about that particular
incompatibility.  This broke c*rtomb and mbrtoc* handling of invalid
sequences, but it turns out they don't want DISCARD_ILSEQ semantics at
all; they really want the subset that we call
_CITRUS_ICONV_F_HIDE_INVALID.

This restores the exact flow in iconv_std to precisely how it happened
prior to 693f88c9da.

PR:	265871
Fixes:	693f88c9da ("iconv_std: complete the //IGNORE support")
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D41513
2023-08-22 22:40:45 -05:00
Konstantin Belousov 4a69fc16a5 Add membarrier(2)
This is an attempt at clean-room implementation of the Linux'
membarrier(2) syscall.  For documentation, you would need to read
both membarrier(2) Linux man page, the comments in Linux
kernel/sched/membarrier.c implementation and possibly look at
actual uses.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32360
2023-08-23 03:02:21 +03:00
David E. O'Brien 4d004ccce2 Document strnstr()'s history. 2023-08-21 23:40:46 -07:00
Robert Clausecker 8803f01e93 lib/libc/amd64/string/memcmp.S: add baseline implementation
This changeset adds a baseline implementation of memcmp and bcmp
for amd64. The same code is used for both functions with conditional
code were the behaviour differs (we need more precise output for the
memcmp case).

FreeBSD documents that memcmp returns the difference between the
mismatching characters. Slightly faster code would be possible could
we relax this requirement to the ISO/IEC 9899:1999 requirement of
merely returning a negative/positive integer or zero.

Performance is better than bionic and glibc, except for long strings
were the two are 13% faster. This could be because they use SSE4
ptest which we cannot use in a baseline kernel.

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
Differential Revision:	https://reviews.freebsd.org/D41442
2023-08-21 21:19:46 +02:00
Robert Clausecker 9fbea87028 lib/libc/amd64/string/stpcpy.S: add baseline implementation
This commit adds a baseline implementation of stpcpy(3) for amd64.
It performs quite well in comparison to the previous scalar implementation
as well as agains bionic and glibc (though glibc is faster for very long
strings).  Fiddle with the Makefile to also have strcpy(3) call into the
optimised stpcpy(3) code, fixing an oversight from D9841.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	imp ngie emaste
Approved by:	mjg kib
Fixes:		D9841
Differential Revision:	https://reviews.freebsd.org/D41349
2023-08-21 20:59:38 +02:00
Konstantin Belousov 89e17c6ea0 libc/gen/_pthread_stubs.c: Remove stray whitespaces
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-08-21 01:44:18 +03:00
Minsoo Choo 0dc52b7210 libc: export pthread_getname_np stub
pthread_getname_np needs to be provided by libc in order to import
jemalloc 5.3.0.

A stub implementation for libc pthread_getname_np() is added for
_pthread_stubs.c, which always reports empty name for the main thread.

Internal _pthread_getname_np() is not exported, but provided for libc
own use.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D41461
2023-08-21 01:44:17 +03:00
John Baldwin ece58eaf50 Restore blank line after #include 2023-08-17 11:32:32 -07:00
Brooks Davis c5f49ece16 libc: regoranize malloc build
Create a stdlib/malloc to hold the definition of the malloc interface
(e.g., the Symbol.map file) and make jemalloc a subdirectory.  This will
make it easier to integrate alternative allocators such as snmalloc
while making it clear that the current jemalloc symbols are the FreeBSD
API/ABI (for better or worse).

Suggested by:	jrtc27
Reviewed by:	jrtc27, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D41457
2023-08-16 19:16:51 +01:00
Brooks Davis 075c716558 jemalloc: drop unused .PATH
All jemalloc sources are in contrib so don't look for them in the
jemalloc subdirectory.

Reviewed by:	jrtc27, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D41481
2023-08-16 19:16:43 +01:00
Brooks Davis 4c757938e4 libc: include malloc via stdlib/Makefile.inc
There's a hierarchy here and we should use it.

Improves: cbeacb7c46

Reviewed by:	jrtc27, jhb, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D41456
2023-08-16 19:16:26 +01:00
Warner Losh 401ab69cff Remove $FreeBSD$: one-line ps tag
Remove /^%\s*RCSID:\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:39 -06:00
Warner Losh ae992a336e Remove $FreeBSD$: one-line catalog
Remove /^\s*\$\s*\$FreeBSD\$$\n/
2023-08-16 11:55:26 -06:00
Warner Losh 05248206f7 Remove $FreeBSD$: one-line bare tag
Remove /^\s*\$FreeBSD\$$\n/
2023-08-16 11:55:20 -06:00
Warner Losh b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh b1cfcffa89 Remove $FreeBSD$: one-line .S pattern
Remove /^\s\.(asciz|ident)\s+\"\$FreeBSD\$\".*\n/
2023-08-16 11:54:57 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh 2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh 42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Warner Losh c251557621 glob.h: Remove $FreeBSD$
This likely documented where this file was copied, but the $FreeBSD$
tag was lost as soon as it was committed. Just remove it. Also remove
the one that looked like it was intended to track versions. That will
simplify the MFC.

Sponsored by:		Netflix
2023-08-16 01:46:21 -06:00
Warner Losh be6151e43c mpool: Remove $FreeBSD$ comment
Remove non-standard $FreeBSD$ comment. It's not useful

Sponsored by:		Netflix
2023-08-16 01:37:16 -06:00
Dmitry Chagin f3e11927dc vm: Allow MAP_32BIT for all architectures
Reviewed by:		alc, kib, markj
Differential revision:	https://reviews.freebsd.org/D41435
2023-08-14 20:20:20 +03:00
Michal Meloun e59b6e48f4 gdtoa: Regenerate configuration headers for 32-bit arm.
These configuration headers were only guessed, but unfortunately not exactly
correctly. Therefore, re-generate them on real HW.

Generated on CA15, verified on CA9, CA7(with VFP lite) and on 32-bit ARMv9.

PR:	272229
Reported by:	Robert Clausecker <fuz@FreeBSD.org>
MFC after:	2 weeks
2023-08-13 09:35:48 +02:00
Konstantin Belousov 41acfee690 libc vdso time functions: correctly convert errors into errnos
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-08-13 01:34:08 +03:00
Konstantin Belousov 21a52f9944 libc dlfcn.c: make dl_iterate_phdr() from libc more useful
Apparently there are applications that resolve dl_iterate_phdr from libc
and try to call the symbol. Our libc only provides stubs for dl* to
satisfy static linker or statically linked binaries, and is not prepared
to this situation.

Add a code to dso libc to find real dl_iterate_phdr and redirect the
call to it.

Reported by:	yuri
PR:	272992
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-08-09 08:07:05 +03:00
Robert Clausecker d7302cabc0 lib/libc/amd64/string/strchrnul.S: fix wrong indentation
Uses spaces instead of tabs for this line by accident.

Reported by:	jrtc27, kib
Approved by:	kib
2023-08-07 14:03:28 +02:00
Robert Clausecker 61f4c4d3dd lib/libc/amd64/string: add strchrnul implementations (scalar, baseline)
A lot better than the generic (pre) implementaion.  We do not beat glibc
for long strings, likely due to glibc switching to AVX once the input is
sufficiently long.  X86-64-v3 and v4 implementations may be added at a
future time.

os: FreeBSD
arch: amd64
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
        │ strchrnul_pre.out │         strchrnul_scalar.out         │       strchrnul_baseline.out        │
        │      sec/op       │    sec/op     vs base                │   sec/op     vs base                │
Short          129.68µ ± 3%    59.91µ ± 1%  -53.80% (p=0.000 n=20)   44.37µ ± 1%  -65.79% (p=0.000 n=20)
Mid             21.15µ ± 0%    19.30µ ± 0%   -8.76% (p=0.000 n=20)   12.30µ ± 0%  -41.85% (p=0.000 n=20)
Long           13.772µ ± 0%   11.028µ ± 0%  -19.92% (p=0.000 n=20)   3.285µ ± 0%  -76.15% (p=0.000 n=20)
geomean         33.55µ         23.36µ       -30.37%                  12.15µ       -63.80%

        │ strchrnul_pre.out │          strchrnul_scalar.out          │         strchrnul_baseline.out         │
        │        B/s        │      B/s       vs base                 │      B/s       vs base                 │
Short          919.3Mi ± 3%   1989.7Mi ± 1%  +116.45% (p=0.000 n=20)   2686.8Mi ± 1%  +192.28% (p=0.000 n=20)
Mid            5.505Gi ± 0%    6.033Gi ± 0%    +9.60% (p=0.000 n=20)    9.466Gi ± 0%   +71.97% (p=0.000 n=20)
Long           8.453Gi ± 0%   10.557Gi ± 0%   +24.88% (p=0.000 n=20)   35.441Gi ± 0%  +319.26% (p=0.000 n=20)
geomean        3.470Gi         4.983Gi        +43.62%                   9.584Gi       +176.22%

For comparison, glibc on the same machine:

        │ strchrnul_glibc.out │
        │       sec/op        │
Short             49.73µ ± 0%
Mid               14.60µ ± 0%
Long              1.237µ ± 0%
geomean           9.646µ

        │ strchrnul_glibc.out │
        │         B/s         │
Short            2.341Gi ± 0%
Mid              7.976Gi ± 0%
Long             94.14Gi ± 0%
geomean          12.07Gi

Sponsored by:	The FreeBSD Foundation
Approved by:	mjg
Differential Revision: https://reviews.freebsd.org/D41333
2023-08-06 15:58:27 +02:00
Ed Maste dedc71fd38 libc: unsplit log message to to make it greppable in src
Also use __func__ rather than hardcoding the function name.  This code
now fits in 80 columns without splitting the log message.

Reviewed by:	zlei
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39619
2023-08-04 20:59:30 -04:00
Robert Clausecker d8385768fb lib/libc/amd64/string/strlen.S: add amd64 baseline kernel
This performs very well.  x86-64-v3 and x86-64-v4 kernels were written,
too, but performed worse than the baseline kernel on short strings.
These may be added at a future point in time if the performance issues
can be fixed.

os: FreeBSD
arch: amd64
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
        │ strlen_scalar.out │          strlen_baseline.out          │
        │        B/s        │     B/s       vs base                 │
Short          1.667Gi ± 1%   2.676Gi ± 1%   +60.55% (p=0.000 n=20)
Mid            5.459Gi ± 1%   8.756Gi ± 1%   +60.39% (p=0.000 n=20)
Long           15.34Gi ± 0%   52.27Gi ± 0%  +240.64% (p=0.000 n=20)
geomean        5.188Gi        10.70Gi       +106.24%

Sponsored by:	The FreeBSD Foundation
Approved by:	kib
Reviewed by:	mjg jrtc27
Differential Revision:	https://reviews.freebsd.org/D40693
2023-08-04 01:54:23 +03:00
Robert Clausecker ad2fac552c lib/libc/amd64: add archlevel-based simd dispatch framework
Add a framework for selecting from one of multiple implementations
of a function based on amd64 architecture level (cf. amd64 SysV
ABI supplement).

Sponsored by:	The FreeBSD Foundation
Approved by:	kib
Reviewed by:	jrtc27
Differential Revision:	https://reviews.freebsd.org/D40693
2023-08-04 01:53:43 +03:00
Ed Maste 89c762c815 inet.3: remove mention of VAX endianness
Machine endianness is not very important in understanding the inet*
functions; the endianness of the VAX is especially so.

PR:		272728
Sponsored by:	The FreeBSD Foundation
2023-08-01 13:23:42 -04:00
Dmitry Chagin 03eab865aa man: Link _Fork(2) man page
Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D41221
MFC after:		1 week
2023-07-28 11:54:20 +03:00
Andrew Turner 835927fd8e arm: Remove swi.h
It has been unneeded since moving to the Arm EABI

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D41136
2023-07-24 17:58:14 +01:00
Dmitry Chagin 241a55b461 libc/csu: Do not compile the finalizer() for PIC build
Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D41148
2023-07-22 11:56:06 +03:00
Kyle Evans b744861818 libc: locale: flesh out an incomplete comment
Extrapolate from the context what the intention for the rest of the
comment probably was -- that the C/POSIX (and now C.UTF-8) locales may
avoid an allocation and reuse a global table.

Reviewed by:	bapt
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D41087
2023-07-20 23:27:24 -05:00
Robert Clausecker 4da7282a18 lib/libc/string/bcmp.c: fix integer overflow bug
bcmp() returned the number of remaining bytes when the main loop exits.
In case of a match, this is zero, else a positive integer.  On systems
where SIZE_MAX > INT_MAX, the implicit conversion from size_t to int in
the return value may cause the number of remaining bytes to overflow,
becoming zero and falsely indicating a successful comparison.

Fix the bug by always returning 0 on equality, 1 otherwise.

PR:		272474
Approved by:	emaste
Reviewed by:	imp
MFC After:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41011
2023-07-16 20:36:17 +03:00
Robert Clausecker 3f5788e0ed lib/libc/string/ffs*.c: work around gcc warning
Gcc warns of infinite recursion if we use __builtin_ffs*() to
implement ffs*().  This is because gcc uses ffs() to implement
these on some platforms.  Sidestep the warning by using
__builtin_ctz*() for these.

Sponsored by:	FreeBSD Foundation
Reported by:	jlduran@gmail.com, jhb
Fixes:		ee8b0c43 (D40730)
Reviewed by:	jhb, mhorne
Approved by:	jhb
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D40966
2023-07-14 22:26:43 +02:00
Jessica Clarke 0fbb77c3ef libc: Build all i386 sources for amd64 lib32
Having the symbols exported by libc differ between i386 and amd64 lib32
is questionable. Since these files build just fine today, stop guarding
them with !defined(COMPAT_32BIT). Whether or not they work at run time
is a different matter, but an i386 jail would be similarly affected if
not, so that's not a problem with lib32.

Reviewed by:	kib, jhb, imp
Differential Revision:	https://reviews.freebsd.org/D40937
2023-07-09 18:46:03 +01:00
Jens Schweikhardt 7a949a0f1c Correct grammo. 2023-07-08 14:25:44 +02:00
Dmitry Chagin acfd261524 libc: Improve setjmp comments
Reviewed by:		imp, kib
Differential Revision:	https://reviews.freebsd.org/D40879
2023-07-06 20:21:54 +03:00
Robert Clausecker ee8b0c436d lib/libc/string: replace ffs/fls implementations with clang builtins
Most architectures we support (except for riscv64) have instructions
to compute these functions very quickly.  Replace old code with the
ffs and clz builtin functions, allowing clang to generate good code
for all architectures.

As a consequence, toss out arm and i386 ffs() implementations.

Sponsored by:	FreeBSD Foundation
Approved by:	mhorne
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D40730
2023-07-03 22:18:27 +02:00
Robert Clausecker 49390697b9 lib/libc/tests/string: add unit tests for ffs, ffsl, ffsll, fls, flsl, and flsll
Also supply CFLAGS+=-fno-builtin to ensure our unit tests
actually test libc functions and not clang's builtins.

Sponsored by:	FreeBSD Foundation
Approved by:	kevans
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D40729
2023-07-03 22:18:27 +02:00
Eugene Grosbein 5aee3e14d4 syslog.3: document ident[N] format
When libc switched to generation of logs as per RFC 5424,
that change broke application ability to insert specific process id
using ident[N] format, the feature existed for decades.
Some processes rely on it (including logger and syslogd).

Later the regression was fixed but the feature remained undocumented.
This change documents it.

MFC after:	1 week
2023-07-03 19:46:40 +07:00
Yuri Pankov 24ec316c13 Correctly spell illumos (all lowercase) in man pages
From illumos FAQ:

    "illumos (pronounced i-llu-MOS and written in lowercase)"
2023-06-29 13:14:45 +02:00
Piotr Kubaj fd774e065c gdtoa: fix endianness issue on powerpc64le
The current code assumes running on big-endian, which causes issues with
e.g. strtod() as reported on https://github.com/ocaml/ocaml/pull/10837#issuecomment-1605346422
This is probably a leftover from when powerpc64le was introduced.

Approved by:	jhibbits (on IRC)
2023-06-29 01:45:50 +02:00
Konstantin Belousov 42ceab3ea1 libc.a: implement _rtld_addr_phdr()
to make __cxa_thread_call_dtors() operational for statically linked
binaries.

Noted by:	andrew
Reviewed by:	emaste, dim
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D40748
2023-06-25 21:27:25 +03:00
Gordon Bergling 8f79b07564 nameser: Fix a typo in a source code comment
-s /unknwon/unknown/

MFC after:	3 days
2023-06-19 13:49:23 +02:00
Kyle Evans 0e96337b11 acl_is_trivial_np(3): minor fixes
- Correct the document title
- This function has an _np suffix
- acl_strip_np has a manpage, xref it
- RETURN VALUES should describe acl_is_trivial_np, not acl_get_tag_type

Sponsored by:	Klara, Inc.
2023-06-19 00:47:04 -05:00
Gordon Bergling 85604f7008 xdr(3): Fix a typo in a source code comment
- s/curren/current/

MFC after: 3 days
2023-06-17 10:49:40 +02:00
David E. O'Brien 2a3493b93b Correct man page URI formatting.
Don't format URL's embedding a ',' where one doesn't exist; so that
one may copy-n-paste the displayed URL into a browser.
2023-06-09 20:49:51 -07:00
Konstantin Belousov 1fc174cba6 open(2): fix typo
__aLC_aclcheck_fd -> acl_aclcheck_fd

Reported by:	Peter Eriksson  <pen@lysator.liu.se>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-05-30 12:18:25 +03:00
Konstantin Belousov 7a292504ba __acl_get_fd(2), __acl_aclcheck_fd(2): enable for O_PATH filedescriptors
PR:	271704
Reported by:	Peter Eriksson  <pen@lysator.liu.se>
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D40318
2023-05-30 08:53:56 +03:00
Kyle Evans e15da6b10a libc: locale: fix collation file size validation
At a minimum, we need enough for the colllation format version string +
locale definition version string and a full collate_info definition,
rather than just the first two and a pointer.

Sponsored by:	Klara, Inc.
2023-05-28 12:54:24 -05:00
Peter Wemm e829181c65
libc: Update copyright text to match current templates. 2023-05-18 11:30:10 -07:00
Warner Losh b61a573019 spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD
The SPDX folks have obsoleted the BSD-2-Clause-NetBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:04 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Kyle Evans 20c61a7c51 acl(3): improve discoverability of acl_get_perm_np(3)
- Mention it in acl(3) as an available function, xref
- Mention it in acl_get_permset(3), as acl_get_perm_np(3) is a natural
    follow-up to acl_get_permset(3)

Sponsored by:	Klara, Inc.
2023-05-08 22:45:12 -05:00
Mariusz Zaborski 95950880ad libc: document when the namespace was created
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D39989
2023-05-07 11:45:13 +02:00
Ed Maste 5f2e84015d bsd.lib.mk: decouple lib*_pic.a from TOOLCHAIN build knob
A user may use a tool chain from a package or just use an existing
tool chain from a previous installation.  There is no reason for this
to disable the installation of lib${LIB}_pic.a.

This also means we don't need to force MK_TOOLCHAIN=yes in lib/libc.

This reverts part of commit c0f5aeb032.

Reviewed by:	jrtc27
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39917
2023-05-01 16:46:39 -04:00
Tom Hukins 9c353fa4a9 libc: Fix a documentation spelling mistake
Pull Request:	https://github.com/freebsd/freebsd-src/pull/704
2023-05-01 10:30:15 -04:00
Eugene Grosbein 4824d78872 listen(2): improve administrator control over logging
As documented in listen.2 manual page, the kernel emits a LOG_DEBUG
syslog message if a socket listen queue overflows. For some appliances,
it may be desirable to change the priority to some higher value
like LOG_INFO while keeping other debugging suppressed.

OTOH there are cases when such overflows are normal and expected.
Then it may be desirable to suppress overflow logging altogether,
so that dmesg buffer is not flooded over long run.

In addition to existing sysctl kern.ipc.sooverinterval,
introduce new sysctl kern.ipc.sooverprio that defaults to 7 (LOG_DEBUG)
to preserve current behavior. It may be changed to any value
in a range of 0..7 for corresponding priority or to -1 to suppress logging.
Document it in the listen.2 manual page.

MFC after:	1 month
2023-05-01 03:26:44 +07:00
Dag-Erling Smørgrav 6f3c2f41b1 tzcode: Clean up the ctime(3) manual page.
MFC after:	3 weeks
Sponsored by:	Klara, Inc.
Reviewed by:	pauamma_gundo.com
Differential Revision:	https://reviews.freebsd.org/D39714
2023-04-26 11:46:41 +02:00
Dag-Erling Smørgrav 75411d1572 Update tzcode to 2023c.
MFC after:      3 weeks
Sponsored by:   Klara, Inc.
Reviewed by:    philip
Differential Revision:  https://reviews.freebsd.org/D39712
2023-04-26 11:46:21 +02:00
John Baldwin 47e888f836 Remove a few more references to riscv64sf.
Fixes:		1ca12bd927 Remove the riscv64sf architecture.
2023-04-20 11:00:46 -07:00
Hans Petter Selasky bb8e8e230d Revert "libc: Implement bsort(3) a bitonic type of sorting algorithm."
Some points for the future:
 - libc is not the right place for sorting algorithms.
   Probably libutil is better suited for this purpose or
   a dedicated libsort. Should move all sorting algorithms
   away from libc eventually.
 - CheriBSD uses capabilities for memory access, and could
   benefit from a standard memswap() function.
 - Do something about qsort() in FreeBSD's libc like:
   - Mark it deprecated on FreeBSD, as a first step,
     due to missing limits on CPU time.
   - Audit the use of qsort() in the FreeBSD base system
     and consider swapping to other existing sorting
     algorithms.

Discussed with:	brooks@

Differential Revision:	https://reviews.freebsd.org/D36493

This reverts commit a7469c9c0a.
This reverts commit 7d65a450cd.
This reverts commit 8dcf3a82c5.
2023-04-20 19:16:14 +02:00
Hans Petter Selasky ecb2ce3a51 libc: Sorting is not needed when there are less than two elements
If there are less than two elements avoid executing the first
sorting loop. No functional change intended.

Reviewed by:	kib@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
Differential Revision:	https://reviews.freebsd.org/D39691
2023-04-19 17:17:33 +02:00
Hans Petter Selasky 27bb0d337c libc: Add missing object size check to qsort_s(3)
When sorting, both the C11 standard (ISO/IEC 9899:2011, K.3.6.3.2) and
the ISO/IEC JTC1 SC22 WG14 N1172 standard, does not define objects of
zero size as undefined behaviour. However Microsoft's cpp-docs does.

Add proper checks for this. Found while working on bsort(3).

Reviewed by:	kib@ and emaste@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
Differential Revision:	https://reviews.freebsd.org/D39687
2023-04-19 15:35:14 +02:00
Hans Petter Selasky 7d65a450cd bsort.3: Fix warnings as reported by mandoc -W warning
Reported by:	Yuri <yuri@aetern.org>
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2023-04-19 15:34:00 +02:00
Hans Petter Selasky 8dcf3a82c5 libc: Implement bsort(3) a bitonic type of sorting algorithm.
The bsort(3) algorithm works by swapping objects, similarly to qsort(3),
and does not require any significant amount of additional memory.

The bsort(3) algorithm doesn't suffer from the processing time issues
known the plague the qsort(3) family of algorithms, and is bounded by
a complexity of O(log2(N) * log2(N) * N), where N is the number of
elements in the sorting array. The additional complexity compared to
mergesort(3) is a fair tradeoff in situations where no memory may
be allocated.

The bsort(3) APIs are identical to those of qsort(3), allowing for
easy drop-in and testing.

The design of the bsort(3) algorithm allows for future parallell CPU
execution when sorting arrays. The current version of the bsort(3)
algorithm is single threaded. This is possible because fixed areas
of the sorting data is compared at a time, and can easily be divided
among different CPU's to sort large arrays faster.

Reviewed by:	gbe@, delphij@, pauamma_gundo.com (manpages)
Sponsored by:	NVIDIA Networking
Differential Revision:	https://reviews.freebsd.org/D36493
2023-04-19 14:04:22 +02:00
Konstantin Belousov 93ca6ff295 umtx: allow to configure minimal timeout (in nanoseconds)
PR:	270785
Reviewed by:	markj, mav
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D39584
2023-04-19 02:22:28 +03:00
Val Packett 77f0e198d9 procctl: add state flags to PROC_REAP_GETPIDS reports
For a process supervisor using the reaper API to track process subtrees,
it is very useful to know the state of the processes on the list.

Sponsored by:   https://www.patreon.com/valpackett
Reviewed by:    kib
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D39585
2023-04-16 13:48:20 +03:00
Konstantin Belousov dcc19c6701 pkru.3: fix markup
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2023-04-15 02:53:59 +03:00
Konstantin Belousov 54579376c0 Change kqueue1() to be compatible with NetBSD
by making it accept some open(2) flags.  More precisely, only
O_CLOEXEC is supported, the flag is translated into the KQUEUE_CLOEXEC flag
for kqueuex(2), and O_NONBLOCK is silently ignored.

Reported and tested by:	vishwin
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D39377
2023-04-05 06:29:49 +03:00
Ed Maste 20c9c3be5a kqueue: add close() calls to man page example
There is no real need to close descriptors before a process exits, but
these close calls demonstrate by example that kqueue descriptors occupy
the same namespace as other file descriptors.

Reviewed by:	fernape, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39376
2023-04-04 09:29:53 -04:00
Konstantin Belousov dac3102488 Rename kqueue1(2) to kqueuex(2) to avoid compat issues with NetBSD
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D39377
2023-04-04 16:19:08 +03:00
Ed Maste d860991a72 kqueue: tidy up indentation in man page example
Fixes: e07b0c12ba ("[patch][doc] Fix EXAMPLE in kqueue(2)")
Sponsored by:	The FreeBSD Foundation
2023-03-31 14:48:39 -04:00
Ed Maste 30da840c62 memmem: add a note about other systems which have memmem
memmem started as a GNU extension but is now widely available.

Reviewed by:	mhorne (slightly earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39337
2023-03-30 12:14:26 -04:00