2081 Commits
Author SHA1 Message Date
Konstantin Belousov 7caa71145c posix_spawn: actions chdir and fchdir are now required by POSIX
Drop the _np suffix.

Reviewed by:	dim
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D56222
2026-04-03 11:22:53 +03:00
Konstantin Belousov 28599a1e5f sys: add renameat2(2) syscall
Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D55539
2026-03-06 01:46:53 +02:00
Brooks Davis 2adc3f0db1 stddef.h: centralize definition of offsetof()
Move to sys/_offsetof.h and use __builtin_offsetof() instead of
__offsetof to avoid reintroducing sys/cdefs.h polution in stddef.h.

This has the side effect of allowing sys/stddef.h to be included after
stddef.h which can happen in compatability headers.

Effort:		CHERI upstreaming
Sponsored by:	DARPA, AFRL
Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D55307
2026-02-19 15:10:32 +00:00
Brooks Davis cb59eec9eb stddef.h: add ptraddr_t
I'd missed that stddef.h is standalone and isn't a copy of sys/stddef.h
in my initial merge.

Effort:		CHERI upstreaming
Reviewed by:	kib
Sponsored by:	Innovate UK
Fixes:		dca634d154 ("new type: ptraddr_t")
Differential Revision:	https://reviews.freebsd.org/D55305
2026-02-19 15:10:32 +00:00
Konstantin Belousov 1443a455a9 libc: improve include usage for exterror sources
Include sys/types.h by exterr.h, since size_t is used.
Drop include of sys/exterr_cat.h, it is useless for the only prototype
provided.

Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D55337
2026-02-18 09:54:01 +02:00
Brooks Davis 18d47c1856 rpc: correct resultproc_t's type
It takes exactly three arguments of known type.

Tweak the types of various resultproc_t functions to match the type (mostly
added const to struct pointers) allowing us to drop casts.

Effort:		CHERI upstreaming
Reviewed by:	vangyzen, glebius
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54941
2026-02-02 21:20:16 +00:00
Brooks Davis e236502a99 clnt_broadcast(3): fix eachresult argument type
The `eachresult` argument is documented to take a function pointer of
type:

	bool_t (*)(caddr_t, struct sockaddr_in *)

It was declared to take a resultproc_t which has historically been
declared to be:

	bool_t (*resultproc_t)(caddr_t, ...);

This overlapped well enough for currently supported ABIs where variadic
arguments are passed in registers, but this declaration is misaligned
with the documentation (resultproc_t takes three arguments) and will be
fixed in a followup commit.

Fix the type to be non-variadic, matching callbacks, and define a
convenience type of as most callbacks take something other than a char *
as their first argument and need to be cast.

Effort:		CHERI upstreaming
Reviewed by:	ngie, glebius, jhb
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D54940
2026-02-02 21:20:10 +00:00
Konstantin Belousov 080d8ed7dd libc: add posix_spawnattr_{get,set}procdescp_np
Reviewed by:	asomers
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D54879
2026-01-26 21:30:14 +02:00
Konstantin Belousov 3f0aea0968 libc: add posix_spawnattr_{get,set}execfd_np(3)
If execfd is set, the fexecve(2) is used by posix_spawn() instead of the
provided path.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D54862
2026-01-25 19:19:53 +02:00
Brooks Davis ac5a19ec69 rpc/xdr.h: make xdrproc_t always take two arguments
The type of xdrproc_t is clearly defined in the comments as a function
with two arguments, an XDR * and a void * (sometimes spelled caddr_t).
It was initialy defined as:

	typedef bool_t (*xdrproc_t)();

At some point people started giving it a non-empty argument list.
Unfortunatly, there has been widespread disagreement about how arguments
are passed.  There seems to have been a widespread view that it should
be allowed to pass three argument function pointer to xdrproc_t.  Most
notable is xdr_string which takes a maximum length parameter. This lead
to all sorts of prototypes (all of which have been present in the
FreeBSD source tree):

FreeBSD userspace (nominally from tirpc, but seemingly local):
	typedef bool_t (*xdrproc_t)(XDR *, ...);
FreeBSD kernel, glibc:
	typedef bool_t (*xdrproc_t)(XDR *, void *, ...);
rcp/xdr.h with _KERNEL defined (not used?):
	typedef bool_t (*xdrproc_t)(XDR *, void *, u_int);
gssrpc (in krb5) and Linux kernel:
	typedef bool_t (*xdrproc_t)(XDR *, void *);

For two argument functions on current ABIs, these all equivalent as
these arguments are passed in registers regardless of decleration and
definition, but we end up with two problems:

   - xdr_free((xdrproc_t)xdr_string, ...) calls xdr_string with no third
     argument and (at least on FreeBSD) may fail to free memory if the
     string is shorter than the value lying around in the third argument
     register.  There are no instance of this in tree, but I found some
     with Debian code search, in particular in OpenAFS.

   - Under CheriABI, variadic arguments are passed in a separate,
     bounded array so theses prototypes aren't equilvalent to the
     non-variadic calling convention of the functions.

The reality is that that xdr_string should not be cast to xdrproc_t and
xdr_wrapstring should be used instead so we do not need to support this
case.  Instances of the former behavior are now extremely rare.

With this change we bring FreeBSD in line with gssrpc and the Linux
Kernel.  Warnings about casts should now be correct and should be fixed.

Bump __FreeBSD_version as some software required adaptation if it is
declaring functions to cast to xdrproc_t.  Update OpenZFS's workaround
of this historic mess accordingly.

Effort:		CHERI upstreaming
Sponsored by:	Innovate UK

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D54824
2026-01-23 10:35:32 +00:00
Konstantin Belousov afa70a8496 libthr: add pthread_tryjoin_np()
Similar to the same glibc function.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D54766
2026-01-19 18:49:57 +02:00
Hans Rosenfeld 6a6f230d31 libc/stdlib: Port strtonumx() from Illumos
Add strtonumx(), a companion to strtonum(3) that preserves its safety
and error-reporting semantics while allowing the caller to specify a
conversion base, similar to the strtol(3) family of functions.

Reviewed by:	emaste, kib, ziaee
Obtained from:	https://www.illumos.org/issues/15365
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D54270
2026-01-15 09:45:42 -04:00
Minsoo Choo 94d1731e73 Makefile*: remove powerpcspe
As reported on the freebsd-announce mailing list[1] FreeBSD is
continuing to retire 32-bit support.  Remove powerpcspe from build
infrastructure.

[1] https://lists.freebsd.org/archives/freebsd-announce/2024-February/000117.html

Signed-off-by: Minsoo Choo <[email protected]>
Reviewed by:	jhibbits, emaste
Pull request:	https://github.com/freebsd/freebsd-src/pull/1914
2026-01-09 11:28:43 -05:00
Minsoo Choo f441a225c4 stdbool.h: Update for C23
When a compiler with C23 or higher is detected, builtin bool, true,
and false are used to conform the C23 standard.

Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D44664
2026-01-06 20:26:59 -05:00
Konstantin Belousov b8c99e7d91 libc: add glibc-compatible tdestroy(3)
The function clears the whole tree.

Relnotes:	yes
Reviewed by:	alc, emaste
Discussed with:	dougm
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D54365
2025-12-29 19:18:55 +02:00
Brooks Davis 80203a27e9 Add sys/_align.h replacing machine/_align.h
Define _ALIGNBYTES using sizeof(void *) (no functional change on any
existing architecture) which will allow it to work with CHERI were we
must align things up to capability alignment.

In _ALIGN, replace integer manipulation which does not preserve pointer
provenance with a type and provenance preserving builtin.  This requires
modest changes in code which assumes _ALIGN returns an integer, but
those are relatively rare.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53947
2025-12-10 10:57:50 +00:00
Konstantin Belousov a98e5d7850 libc/string: add strdupa(3) and strndupa(3)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D54066
2025-12-09 00:34:57 +02:00
Robert Clausecker fc88be257e Revert "stddef.h: add unreachable() for C23 compliance"
Seems like a number of ports are *really* unhappy with this new
macro.  These ports will have to be fixed and the patch reworked
to perhaps not affect C++ (see D54041).  A general discussion on
how we expose new language features may also need to take place.

Reported by:	many people
Approved by:	markj (mentor)

This reverts commit b381d09802.
2025-12-05 00:25:10 +01:00
Robert Clausecker 6296500a85 libc: implement C23 <stdbit.h> functions
This new header complies with ISO/IEC 9899:2024 (C23).

Contrary to glibc, we do not provide inline definitions in
<stdbit.h> as we expect our system compiler to soon recognise
these as builtins anyway.

Relnotes:	yes
MFC after:	1 month
Reviewed by:	adrian
Approved by:	markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D53657
2025-11-30 20:21:52 +01:00
Robert Clausecker b381d09802 stddef.h: add unreachable() for C23 compliance
unreachable() is a hint to the compiler that it is unreachable.
Add a new man page unreachable(3) to document this macro.

Reviewed by:	imp
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D53967
2025-11-28 16:56:49 +01:00
Robert Clausecker f0e541118c uchar.h: add char8_t
A type similar to char16 and char32_t, for compliance with C23.
The related type atomic_char8_t is added to stdatomic.h.
As char8_t is always unsigned char, I've skipped adding __char8_t.
This can be added, too, if desired.

Reviewed by:	imp
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D53952
2025-11-28 16:19:53 +01:00
Robert Clausecker 5da388c633 time.h: add timegm() to the C23 namespace
This function is part of ISO/IEC 9899:2024 (C23) and was forgotten in D47856.

Reviewed by:	imp
Approved by:	markj (mentor)
See also:	D47856
Fixes:		59677aecb6
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D53951
2025-11-28 16:19:40 +01:00
John Baldwin e928afc531 Use ZFSTOP more broadly
Reviewed by:	brooks
Obtained from:	CheriBSD
Differential Revision:	https://reviews.freebsd.org/D53791
2025-11-24 10:47:10 -05:00
Robert Clausecker 6c57e368eb lib/libc: implement C23 memalignment()
This new function computes the alignment of a pointer.
It is part of ISO/IEC 9899:2024, the new C standard.
If the pointer is a null pointer, null is returned.
I have tried to write an implementation that can cope
with traditional address-based architectures, even if
size_t and uintptr_t are of different length.  Adjustments
may be needed for CHERI though.

A man page is provided, too.  No unit test for now.

Reviewed by:	kib, imp, ziaee (manpages), [email protected]
Approved by:	markj (mentor)
MFC after:	1 month
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D53673
2025-11-12 13:23:09 +01:00
Konstantin Belousov 3c052bec12 include/stdckdint.h: make the header compatible with C++
by removing the cast to _Bool.  The _Bool type is not defined for C++,
and the specification from the gcc info doc states that the return
type of the  __builtin_{add,sub,mul}_overflow() is bool already.

This is done instead of including stdbool.h to avoid namespace
pollution, since defining bool from stdckdint.h simingly is not
sanctioned by ISO/IEC 9899:2024.

PR:	290299
Reviewed by:	des
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D53149
2025-10-18 00:48:30 +03:00
Robert Clausecker d518f64cef libc/resolv: get rid of MD5
MD5 is used by libc/resolv to generate a random sequence id from a
current time stamp.  Replace this convoluted mechanism with a call
to arc4random().  This permits us to entirely drop MD5 from libc,
simplifying the MD5 rework proposed in D45670.

Approved by:	markj
Reviewed by:	kevans, markj
See also:	D45670
Event:		EuroBSDcon 2025
Differential Revision:	https://reviews.freebsd.org/D52784
2025-10-04 10:50:02 +02:00
Robert Clausecker 4266461079 lib/libc: add recallocarray()
This function from OpenBSD is a hybrid of reallocarray() and calloc().
It reallocates an array, clearing any newly allocated items.
reallocarray() ultimately originates from OpenBSD.

The source is taken from lib/libopenbsd, which now no longer has the
function unless when bootstrapping (needed for mandoc).

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D52863
2025-10-03 19:46:55 +02:00
Lexi Winter a053f948ad libbsm: Rename package to audit-lib
This is part of audit, so use the new LIB_PACKAGE feature to name the
package audit-lib, rather than libbsm.

MFC after:	1 day
Reviewed by:	bapt
Sponsored by:	https://www.patreon.com/bsdivy
Differential Revision:	https://reviews.freebsd.org/D52789
2025-09-30 09:14:58 +01:00
Dag-Erling Smørgrav 155290b23f tzcode: Expose and document offtime() and offtime_r()
Includes diff reduction to upstream version of this patch.

MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	philip
Differential Revision:	https://reviews.freebsd.org/D39715
2025-09-23 21:38:49 +02:00
Dag-Erling Smørgrav d20c825072 Revert "libc: Remove readdir_r(3)"
This reverts commit d549de7690.
2025-09-11 17:12:22 +02:00
Dag-Erling Smørgrav d549de7690 libc: Remove readdir_r(3)
This function was never safe to use.  We marked it deprecated in the
manual page in 2016, and it is marked obsolete in POSIX 2024.  We
previously added a linker warning and annotated the prototype; now that
stable/15 has been branched, we can remove it from main.

Relnotes:	yes
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D52474
2025-09-10 18:58:06 +02:00
Lexi Winter dc5ba6b8b4 Remove MK_GSSAPI
For MIT Kerberos, MK_GSSAPI has no meaning: GSSAPI is a required part of
Kerberos and is always built if MK_KERBEROS is enabled.  Backport this
behaviour to Heimdal so it works the same way.

While here, change Heimdal's libcom_err and compile_et to be selected by
MK_KERBEROS, not MK_KERBEROS_SUPPORT, since these are part of Kerberos
and third-party users might need it even if Kerberos support is disabled
in the base system.  This means MK_KERBEROS_SUPPORT installs the same
files with both MIT and Heimdal.

Reviewed by:	cy
Differential Revision:	https://reviews.freebsd.org/D51859
2025-08-20 19:42:20 +01:00
Lexi Winter 837b13af68 Revert "Remove Secure RPC DES authentication"
This reverts commit 7ac276298b.

Requested by:	kib
2025-08-15 17:59:18 +01:00
Lexi Winter 7ac276298b Remove Secure RPC DES authentication
Following the earlier removal of keyserv, none of this functionality
works since it requires keyserv.

Remove the relevant symbols from libc's Symbol.map.  Leave compatibility
symbols for existing applications, but since the functions don't work
without keyserv, stub them out to return an error.

Remove some private symbols that were only used by keyserv; these don't
get compatibility symbols.

Remove the documentation for the old functions.

Remove rpc.ypupdated since it requires DES authentication.

Reviewed by:		manu, des, emaste
Differential Revision:	https://reviews.freebsd.org/D50442
2025-08-10 16:36:40 +01:00
Cy Schubert e26259f48a gssapi,krb5: Replace libgssapi with the MIT version
lib/libgssapi is based on Heimdal. As on Linux systems, the MIT
libgssapi_krb5 replaces it. With both gssapi libraries and header files
installed results in broken buildworld (gssd) and ports that will not
build without modifications to support the MIT gssapi in an alternate
location.

73ed0c7992 removed the MIT GSSAPI headers from /usr/include. Apps using
MIT KRB5 gssapi functions and structures will fail to build without this
patch.

This patch includes a temporary patch to usr.sbin/gssd to allow it
to build with this patch. rmacklem@ has a patch for this and for
kgssapi that uses this patch to resolve kgssapi issues for NFS with
Kerberos.

This patch is an updated version of D51661 to allow it to build following
additional patchs to the tree.

This should have been implmented with 7e35117eb0.

Fixes:			7e35117eb0, 73ed0c7992
Differential Revision:	https://reviews.freebsd.org/D51661
2025-08-07 10:17:00 -07:00
Dag-Erling Smørgrav 2bd157bc73 libc: Deprecate readdir_r()
This function was never safe to use.  We marked it deprecated in the
manual page in 2016, and it is marked obsolete in POSIX 2024.  Add a
linker warning and annotate the prototype.

Sponsored by:	Klara, Inc.
Reviewed by:	imp, markj
Differential Revision:	https://reviews.freebsd.org/D51681
2025-08-02 01:11:56 +02:00
Ed Maste c143ffbaf7 rpc.h: Remove reference to unimplemented DES ioctls
We won't be adding support for hardware DES.  Remove the #ifdef notdef
block.

Sponsored by:	The FreeBSD Foundation
2025-07-23 16:53:30 -04:00
Dag-Erling Smørgrav 0a5b763d98 libc: Rename fscandir{,_b}() to fdscandir{,_b}().
This seems to fit the pattern better (e.g. fdopendir()).

I've added weak references to ease the transition, but since it's only
been a few days, we can remove them (and the ObsoleteFiles entries for
the manual pages) before we branch stable/15.

Fixes:		deeebfdeca
Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D50980
2025-06-23 15:03:10 +02:00
Dag-Erling Smørgrav deeebfdeca libc: Add fscandir(), fscandir_b(), scandirat_b().
While here, clean up scandir() a bit and improve the documentation.

MFC after:	never
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D50935
2025-06-20 13:10:23 +02:00
Olivier Certner 63c9b01806 arm64: lib32: Don't try to install removed <machine/runq.h>
Reported by:    Herbert J. Skuhra (herbert gojira.at)
Fixes:          79d8a99ee583 ("runq: Deduce most parameters, remove machine headers")
MFC after:      1 month
Event:          Kitchener-Waterloo Hackathon 202506
Sponsored by:   The FreeBSD Foundation
2025-06-18 12:00:08 -04:00
Warner Losh d8b51259ca ssp: Protect sig2str with proper visibility markers
We only define SIG2STR_MAX with careful visibility, but define the
fortified version unconditionally. It needs to have the same visibility
both places.

Fixes:		3d12567133
Reviewed by:	jrtc27, kevans
Sponsored by:	Netflix
2025-06-11 21:19:05 -06:00
Ricardo Branco b0334450aa include: ssp: fortify <signal.h>
sig2str(3)

Reviewed by: imp, kib, des, jilles
Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
Closes: https://github.com/freebsd/freebsd-src/pull/1696
2025-06-11 17:16:22 -06:00
Ricardo Branco 3d12567133 Add the POSIX sig2str(3) & str2sig(3) calls
Signed-off-by: Ricardo Branco <[email protected]>
Reviewed by: imp, kib, des, jilles
Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
2025-06-11 17:16:22 -06:00
Ricardo Branco 86f06e612b Add POSIX NSIG_MAX & _SC_NSIG
Signed-off-by: Ricardo Branco <[email protected]>
Reviewed by: imp, kib
Pull Request: https://github.com/freebsd/freebsd-src/pull/1710
Closes: https://github.com/freebsd/freebsd-src/pull/1710
2025-06-11 17:16:20 -06:00
Brooks Davis 2d92a5abef Add sys/stdarg.h
While the type of va_list and implementation of va_*() psuedo functions
varies (sometimes greatly) by architecture, they will always be defined
by the compiler in a consistant way that does not require machine
dependent handling.

MFC after:	1 week

Reviewed by:	imp
Exp-run by:	antoine (PR 286274)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1595
2025-06-11 17:39:02 +01:00
Brooks Davis c190cd94b7 sys/_stdarg.h: drop cdefs.h and _types.h polution
Rely in sys/_visible for visibility macros and use __buitin_va_list
instead of __va_list everywere we declare va_list.

Reviewed by:	imp
Exp-run by:	antoine (PR 286274)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1595
2025-06-11 17:39:02 +01:00
Brooks Davis 2e783ea70a stddef.h: don't include sys/cdefs.h
Switch to sys/_visible.h for visibility macros.

Prefer __builtin_offsetof over __offset.  sys/cdefs.h always defines
__offsetof to __builtin_offsetof so just use the latter to remove a
dependency on sys/cdefs.h.  Realistically, we're never going to care
about a compiler that doesn't supply this builtin.

Add a somewhat questionable guard around the offsetof() definition
because the compiler no longer thinks it the same as a number of other
redundent definitions scattered around (e.g., in the openzfs codebase).
It is actually the same and those defintions likely shouldn't exist at
all, but it's easy to add a guard for now.

Reviewed by:	imp
Exp-run by:	antoine (PR 286274)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1595
2025-06-11 17:39:02 +01:00
Brooks Davis b01e971fd3 Don't rely on sys/_types.h including sys/cdefs.h
These headers relied in __BEGIN_DECS/__END_DECLS being defined when
sys/_types.h was included, but there's not a requirement that this be
the case.

Reviewed by:	imp
Exp-run by:	antoine (PR 286274)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1595
2025-06-11 17:39:01 +01:00
Bojan Novković 8bc0b97e19 glob.h: Limit glob_b prototype visibility
Hide glob_b behind __BSD_VISIBLE as it is not a POSIX function.

Reported by:	kib
Reviewed by:	kib
Fixes:	1e0743f54d ("glob: Add blocks support")
Differential Revision:	https://reviews.freebsd.org/D50670
2025-06-03 22:59:28 +02:00
Bojan Novković 1e0743f54d glob: Add blocks support
This change introduces the `glob_b` function which takes a block instead
of a function pointer.

Relnotes:	yes
Sponsored by:   Klara, Inc.
Inspired by:  https://github.com/apple-oss-distributions/Libc
Differential Revision:	https://reviews.freebsd.org/D50485
2025-06-02 11:32:50 +02:00