Commit graph

9903 commits

Author SHA1 Message Date
Konstantin Belousov
eb36277dc9 posix_spawnattr_setflags(3): validate argument
(cherry picked from commit 80ac36c3a2a87a19790eba487466bf70d55f566e)
2024-03-11 02:25:58 +02:00
Konstantin Belousov
8a7d5d73b8 libc/sys: add errno test
(cherry picked from commit 32fdcff8703da6f2795193acc77ec3c1fb8b723d)
2024-03-02 07:05:05 +02:00
Dag-Erling Smørgrav
e257a38de4 Update tzcode to 2024a.
MFC after:	3 weeks
Sponsored by:	Klara, Inc.

(cherry picked from commit 46c599340f187db577b9212ab18022f3c7380c68)
2024-02-21 21:33:23 +01:00
Andrew Turner
bce8a0ba15 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

(cherry picked from commit fd5aaf2ea0178b03aa93c35245053247e5d3840c)
2024-02-19 13:17:37 +00:00
Konstantin Belousov
8309579720 Document aio_read2/aio_write2
(cherry picked from commit a52cb4c480f270fc7158a0f58179f7b80d8a5b3c)
2024-02-18 12:01:46 +02:00
Konstantin Belousov
e331ce2d60 aio_read2/aio_write2: add AIO_OP2_VECTORED
(cherry picked from commit 8dfc788b8480a13f1f945f0a94d8b1e327af5c6f)
2024-02-18 12:01:46 +02:00
Konstantin Belousov
e9014ead57 libc: add aio_read2() and aio_write2() functions
(cherry picked from commit 06cb1c3f9528f088bdaf10d28dcfe7eeaad726d3)
2024-02-18 12:01:46 +02:00
Konstantin Belousov
1298ecb6ba lio_listio(2): add LIO_FOFFSET flag to ignore aiocb aio_offset
(cherry picked from commit e4b7bbd6ab77e908a60362aa29e518f224a117b0)
2024-02-18 12:01:46 +02:00
Brooks Davis
0667d0e0e3 libc: expose execvpe for Linux compat
PR:		275370

(cherry picked from commit 8ccd0b876e67fda6249f294ff484798cc1e1569f)
2024-02-18 12:01:46 +02:00
Konstantin Belousov
16b1438c73 read.2: Describe debug.iosize_max_clamp
PR:	276937

(cherry picked from commit 3e9515846f8cbff0ecccaab65d9f70890d04429e)
2024-02-14 05:41:54 +02:00
Minsoo Choo
fd15ba7d72 libc: Specify parameter types for function pointer
Reviewed by:	dab
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D43726

(cherry picked from commit 6bd60e15b1484c6a3f5a87469e42a8e6ad9ab733)
2024-02-11 10:15:07 -05:00
Mark Johnston
324e914106 libc: Annotate a couple of local functions as such
No functional change intended.

MFC after:	1 week

(cherry picked from commit 8d5353de74471038bd75a6cb39bf58f50a600642)
2024-02-09 09:55:45 -05:00
Konstantin Belousov
14b7cf92e7 open(2): describe *at behavior for dirfd opened without O_SEARCH
(cherry picked from commit a570fe4d0dd979ce099374259ffc45d56ae4e471)
2024-02-01 02:30:40 +02:00
Mark Johnston
ea3197e69b kcmp: Add a manual page
Reviewed by:	kib, emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D43562

(cherry picked from commit af0d437dd31f71726f7eb5e9aca9fbd374a8277a)
2024-01-31 09:16:29 -05:00
Yuri Pankov
c0565e7d34 Create namespace for the symbols added during 15-CURRENT cycle
Reviewed by:	kib

(cherry picked from commit 95a4709b2cca726c6b76c6743ba2d665c1730666)
2024-01-31 01:14:38 -06:00
Konstantin Belousov
f8d885c08d Add kcmp(2) userspace bits
(cherry picked from commit 211bdd601ee51f90da9b123807ef68ac122116b9)
2024-01-30 22:24:42 +02:00
Mike Karels
e9e63d77c6 inet(3): clarify syntax accepted by inet_pton
The section INTERNET ADDRESSES describes the acceptance of dotted
values with varying number of parts in multiple bases.  This applies
to inet_aton and inet_addr, but not to inet_pton.  Clarify this
section by listing the functions to which this applies.  Move the
description of what inet_pton accepts into this section from STANDARDS,
where it is easily missed.  Rename the section to clarify that it
applies only to IPv4.  (inet_pton also works with IPv6.)

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D43537

(cherry picked from commit 9231c42127bf8e47588169ecc395f57cae0e15fb)
2024-01-30 14:10:30 -06:00
Mark Johnston
06fc42c0cb libc/amd64: Disable ASAN for amd64_archlevel.c
The code in this file runs before the sanitizer can initialize its
shadow map.

Fixes:	ad2fac552c ("lib/libc/amd64: add archlevel-based simd dispatch framework")

(cherry picked from commit 4dedcb1bb54cbbe8043c79ad733f966b6ffc6972)
2024-01-30 13:01:58 -05:00
Robert Clausecker
ff7799e003 lib/libc/amd64/string: add memrchr() scalar, baseline implementation
The scalar implementation is fairly simplistic and only performs
slightly better than the generic C implementation. It could be
improved by using the same algorithm as for memchr, but it would
have been a lot more complicated.

The baseline implementation is similar to timingsafe_memcmp.  It's
slightly slower than memchr() due to the more complicated main
loop, but I don't think that can be significantly improved.

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42925

(cherry picked from commit fb197a4f7751bb4e116989e57ba7fb12a981895f)
2024-01-24 20:39:31 +01:00
Robert Clausecker
acb47064d6 lib/libc/tests/string: add memrchr unit tests
The "values" test case is specifically crafted to detect the off-by-one
error previous discovered in the scalar strchrnul implementation.

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42925

(cherry picked from commit 691ff1832e09a6ccbc8f5b04c88cafc7452b3ce6)
2024-01-24 20:39:30 +01:00
Robert Clausecker
667fa9c404 lib/libc/string: document restrict qualification of memccpy() arguments
POSIX.1-2004 and the upcoming C23 agree that memccpy()'s arguments
are restrict qualified and must not overlap.  In 2002, restrict
qualifiers were added to <string.h>'s declaration of the function.
Make things official and document that the arguments must not
overlap.

See also:	61b60edfd3
Approved by:	kib
MFC after:	1 month
MFC to:		stable/14

(cherry picked from commit e0d4f419ac41aa91b862f3ceadc32a86abf08572)
2024-01-24 20:39:30 +01:00
Robert Clausecker
ddab9e6461 lib/libc/amd64/string: implement strncat() by calling strlen(), memccpy()
This picks up the accelerated implementation of memccpy().

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42902

(cherry picked from commit ea7b13771cc9d45bf1bc6c6edad8d1b7bce12990)
2024-01-24 20:39:30 +01:00
Robert Clausecker
a3ce82e5b8 lib/libc/amd64/string: add memccpy scalar, baseline implementation
Based on the strlcpy code from D42863, this patch adds a SIMD-enhanced
implementation of memccpy for amd64. A scalar implementation calling
into memchr and memcpy to do the job is provided, too.

Please note that this code does not behave exactly the same as the C
implementation of memccpy for overlapping inputs. However, overlapping
inputs are not allowed for this function by ISO/IEC 9899:1999 and neither
has the C implementation any code to deal with the possibility. It just
proceeds byte-by-byte, which may or may not do the expected thing for
some overlaps. We do not document whether overlapping inputs are
supported in memccpy(3).

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42902

(cherry picked from commit fc0e38a7a67a6d43095efb00cf19ee5f95dcf710)
2024-01-24 20:39:30 +01:00
Robert Clausecker
de2d155d2c lib/libc/tests/string: add unit tests for memccpy()
Adapted from the strlcpy() unit tests.

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785

(cherry picked from commit e4b7b0bcbc741f0998640c2ba55ec00ba613bb75)
2024-01-24 20:39:29 +01:00
Robert Clausecker
3045c0f198 lib/libc/amd64/string: implement strlcat() through strlcpy()
This should pick up our optimised memchr(), strlen(), and strlcpy()
when strlcat() is called.

Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42863

(cherry picked from commit 2b7b03b7ae179db465c1ef19a5007f729874916a)
2024-01-24 20:39:29 +01:00
Robert Clausecker
903cb811ff lib/libc/amd64/string: add strlcpy scalar, baseline implementation
Somewhat similar to stpncpy, but different in that we need to compute
the full source length even if the buffer is shorter than the source.

strlcat is implemented as a simple wrapper around strlcpy.  The scalar
implementation of strlcpy just calls into strlen() and memcpy() to do
the job.

Perf-wise we're very close to stpncpy.  The code is slightly slower as
it needs to carry on with finding the source string length even if the
buffer ends before the string.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42863

(cherry picked from commit 74d6cfad54d676299ee5e4695139461876dfd757)
2024-01-24 20:39:28 +01:00
Robert Clausecker
f5d63ae20d lib/libc/tests/string: add unit test for strlcpy
A straightforward derivation from the stpncpy unit test.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42863

(cherry picked from commit f7098b8659923873a7c60b64cb68182e470786f9)
2024-01-24 20:39:28 +01:00
Robert Clausecker
7a605ba8f7 lib/libc/amd64/string/strcat.S: enable use of SIMD
strcat has a bespoke scalar assembly implementation we
inherited from NetBSD.  While it performs well, it is
better to call into our SIMD implementations if any SIMD
features are available at all.  So do that and implement
strcat() by calling into strlen() and strcpy() if these
are available.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Reviison: https://reviews.freebsd.org/D42600

(cherry picked from commit aff9143a242c0012b0195b3666e03fa3b7cd33e8)
2024-01-24 20:39:28 +01:00
Robert Clausecker
76f9afcdcf lib/libc/amd64/string: implement strncpy() by calling stpncpy()
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42519

(cherry picked from commit e19d46c808267f53455e96a28ff7654211523d2c)
2024-01-24 20:39:27 +01:00
Robert Clausecker
7527fecbfe lib/libc/amd64/string: add stpncpy scalar, baseline implementation
This was surprisingly annoying to get right, despite being such a simple
function.  A scalar implementation is also provided, it just calls into
our optimised memchr(), memcpy(), and memset() routines to carry out its
job.

I'm quite happy with the performance.  glibc only beats us for very long
strings, likely due to the use of AVX-512.  The scalar implementation
just calls into our optimised memchr(), memcpy(), and memset() routines,
so it has a high overhead to begin with but then performs ok for the
amount of effort that went into it.  Still beats the old C code, except
for very short strings.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42519

(cherry picked from commit 90253d49db09a9b1490c448d05314f3e4bbfa468)
2024-01-24 20:39:27 +01:00
Robert Clausecker
438a1ff803 lib/libc/tests/string/stpncpy_test.c: extend for upcoming SSE implementation
This adds additional unit tests validating the function for
All possible alignment offsets of source and destination.

Also extend the test to allow testing of an external stpncpy
implementation, which greatly simplifies the development of
custom implementations.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42519

(cherry picked from commit 6fa9e7d8737548ef93c573387ce62402c368d486)
2024-01-24 20:39:27 +01:00
Robert Clausecker
265fb89aba lib/libc/amd64/string: implement strsep() through strcspn()
The strsep() function is basically strcspn() with extra steps.
On amd64, we now have an optimised implementation of strcspn(),
so instead of implementing the inner loop manually, just call
into the optimised routine.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42346

(cherry picked from commit fd2ecd91aeeeab579c769c9a39f90b4bd4a493a9)
2024-01-24 20:39:26 +01:00
Robert Clausecker
9b1a851e1e lib/libc/amd64/string: add strrchr scalar, baseline implementation
The baseline implementation is very straightforward, while the scalar
implementation suffers from register pressure and the need to use SWAR
techniques similar to those used for strchr().

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42217

(cherry picked from commit 2ed514a220edbac6ca5ec9f40a3e0b3f2804796d)
2024-01-24 20:39:26 +01:00
Robert Clausecker
3a19fcb9fd lib/libc/amd64/string: add strncmp scalar, baseline implementation
The scalar implementation is fairly straightforward and merely unrolled
four times.  The baseline implementation closely follows D41971 with
appropriate extensions and extra code paths to pay attention to string
length.

Performance is quite good.  We beat both glibc (except for very long
strings, but they likely use AVX which we don't) and Bionic (except for
medium-sized aligned strings, where we are still in the same ballpark).

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42122

(cherry picked from commit 14289e973f5c941e4502cc2b11265e4b3072839a)
2024-01-24 20:39:25 +01:00
Robert Clausecker
098997c5f0 lib/libc/tests/string: add unit tests for strncmp(3)
These are patterned after the previously added (D41970)
strcmp tests, but are extended to check for various length
conditions.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42122

(cherry picked from commit 459ddefcc9dcc010f6f7445285e61e2b6780379c)
2024-01-24 20:39:25 +01:00
Robert Clausecker
309b30ce84 lib/libc/amd64/string: implement strpbrk() through strcspn()
This lets us use our optimised strcspn() routine for strpbrk() calls.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D41980

(cherry picked from commit f4fc317c364f2c81ad3d36763d8e5a60393ddbd1)
2024-01-24 20:39:24 +01:00
Robert Clausecker
37728967ee lib/libc/amd64/string/strcmp.S: add baseline implementation
This is the most complicated one so far.  The basic idea is to process
the bulk of the string in aligned blocks of 16 bytes such that one
string runs ahead and the other runs behind.  The string that runs ahead
is checked for NUL bytes, the one that runs behind is compared with the
corresponding chunk of the string that runs ahead.  This trades an extra
load per iteration for the very complicated block-reassembly needed in
the other implementations (bionic, glibc).  On the flip side, we need
two code paths depending on the relative alignment of the two buffers.

The initial part of the string is compared directly if it is known not
to cross a page boundary.  Otherwise, a complex slow path to avoid
crossing into unmapped memory commences.

Performance-wise we beat bionic for misaligned strings (i.e. the strings
do not share an alignment offset) and reach comparable performance for
aligned strings.  glibc is a bit better as it has a special kernel for
AVX-512, where this stuff is a bit easier to do.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D41971

(cherry picked from commit bca25680b91b3bea7faef615765806a04634eb23)
2024-01-24 20:39:24 +01:00
Gordon Bergling
7c44565e23 pkru.3: Fix a typo in the manual page
- s/successfull/successful/

(cherry picked from commit 8593b5b2addf91987f81ebac0d8b2e51207e4793)
2024-01-23 07:43:42 +01:00
Gordon Bergling
c75648dc9b sigfastblock.2: Fix a typo in the manual page
- s/successfull/successful/

(cherry picked from commit a70008e95b907336bddbcc2aa9d567df6e3a41b6)
2024-01-23 07:43:27 +01:00
Gordon Bergling
9509e32f9e _umtx_op.2: Fix a typo in the manual page
- s/interpeted/interpreted/

(cherry picked from commit b2ec175fcaac90fc6a1caf066656eaa092f32611)
2024-01-23 07:40:33 +01:00
Alan Somers
5b4873c5b8 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.

Sponsored by:	Axcient
Reviewed by:	Pau Amma <pauamma@gundo.com>
Differential Revision: https://reviews.freebsd.org/D42622

(cherry picked from commit 18e2c4175f78f1aaa648dd7fb7530220aed23671)
2024-01-19 18:52:18 -07:00
Alan Somers
f9f7404cd5 sigaction.2: clarify that fork isn't async-signal-safe, but _Fork is
[skip ci]

Sponsored by:	Axcient
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D42865

(cherry picked from commit c2ed7a63604fc86244adee2966e19f8aba2a07cb)
2024-01-19 18:51:27 -07:00
Tom Hukins
554b8bc907 Fix "version introduced" in numerous manual pages
Pull request:	https://github.com/freebsd/freebsd-src/pull/853

(cherry picked from commit ba719a0fec8f831aef4b23de0ff36fd47bb26651)
2024-01-15 10:20:56 -05:00
Jan Beich
5a70219b20 resolv: Add a required include to resolv.h
Add a required include to resolv.h for sockaddr_in.  This should reduce
patching required when porting code written with Linux or NetBSD in mind.

PR:		182466
MFC after:	1 week

(cherry picked from commit 58cf91d3b72a01777bacf72d66a648a744ae3143)
2024-01-15 19:33:59 +09:00
Mark Johnston
8ac8b0b6aa setfib.2: Consistently capitalize "FIB"
MFC after:	1 week
Sponsored by:	Klara, Inc.

(cherry picked from commit ee7d5ba1b55441476643983d3f70df5ee9ea97c4)
2024-01-11 09:18:12 -05:00
Rick Macklem
5c4da68ad7 copy_file_range.2: Clarify that only regular files work
PR#273962 reported that copy_file_range(2) did not work
on shared memory objects and returned EINVAL.
Although the reporter felt this was incorrect, it is what
the Linux copy_file_range(2) syscall does.

Since there was no collective agreement that the FreeBSD
semantics should be changed to no longer be Linux compatible,
copy_file_range(2) still works on regular files only.

This man page update clarifies that. If, someday, copy_file_range(2)
is changed to support non-regular files, then the man page will
need to be updated to reflect that.

PR:	273962

(cherry picked from commit 84b4342c0d7ac8a3187309a978d41e6765154cc1)
2024-01-10 17:13:23 -08:00
Brooks Davis
1b0471936f 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

(cherry picked from commit fc0288993cdad8a559fcd2c2166cf95f1fa43745)
2024-01-02 16:59:04 +00:00
Brooks Davis
444024241e 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

(cherry picked from commit ec27c0bb3eea73be4db6cd2f275db6c516e12d00)
2024-01-02 16:58:54 +00:00
Brooks Davis
d3f8e4bf1c 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

(cherry picked from commit 0ea469bcd548d29bbbc970325e4fa851d0e4c022)
2024-01-02 16:58:42 +00:00
Brooks Davis
9467188141 libc: Centralize non-building of sbrk stubs
The actual implementation of sbrk(2) is on top of the undocumented
break(2) system call.  On powerpc* this means we don't build _sbrk and
__sys_sbrk which were neither used nor exposed for linkage.  Otherwise
it is a no-op.

The addition to lib/libc/sys/Makefile.inc is a direct commit to
stable/14 in lieu of merging the removal of the sbrk and sstk syscalls.

(cherry picked from commit 7893419d492c40ca82b68fca3dcc0f5f7047d39b)

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D43159
2024-01-02 16:22:13 +00:00