aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Makefile15
-rw-r--r--include/Makefile.depend2
-rw-r--r--include/arpa/Makefile1
-rw-r--r--include/endian.h26
-rw-r--r--include/gssapi/Makefile1
-rw-r--r--include/ossfuzz.h79
-rw-r--r--include/paths.h4
-rw-r--r--include/protocols/Makefile1
-rw-r--r--include/rpc/Makefile1
-rw-r--r--include/rpc/xdr.h2
-rw-r--r--include/rpcsvc/Makefile1
-rw-r--r--include/ssp/Makefile5
-rw-r--r--include/ssp/Makefile.depend10
-rw-r--r--include/ssp/poll.h60
-rw-r--r--include/ssp/random.h42
-rw-r--r--include/ssp/socket.h120
-rw-r--r--include/ssp/ssp.h126
-rw-r--r--include/ssp/stdio.h107
-rw-r--r--include/ssp/stdlib.h53
-rw-r--r--include/ssp/string.h141
-rw-r--r--include/ssp/strings.h72
-rw-r--r--include/ssp/uio.h53
-rw-r--r--include/ssp/unistd.h90
-rw-r--r--include/ssp/wchar.h229
-rw-r--r--include/stddef.h7
-rw-r--r--include/stdio.h37
-rw-r--r--include/stdlib.h28
-rw-r--r--include/string.h31
-rw-r--r--include/strings.h8
-rw-r--r--include/sysexits.h7
-rw-r--r--include/unistd.h4
-rw-r--r--include/wchar.h9
-rw-r--r--include/xlocale.h1
-rw-r--r--include/xlocale/Makefile1
34 files changed, 1308 insertions, 66 deletions
diff --git a/include/Makefile b/include/Makefile
index d44c982d950c..16d641b42a90 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -4,7 +4,7 @@
PACKAGE=clibs
CLEANFILES= osreldate.h version
-SUBDIR= arpa protocols rpcsvc rpc xlocale
+SUBDIR= arpa protocols rpcsvc rpc ssp xlocale
.if ${MACHINE_CPUARCH} == "amd64"
SUBDIR+= i386
INCLUDE_SUBDIRS+= i386
@@ -182,6 +182,11 @@ OPENCRYPTODIR= ${INCLUDEDIR}/crypto
NVME= nvme.h
NVMEDIR= ${INCLUDEDIR}/dev/nvme
+.PATH: ${SRCTOP}/sys/dev/nvmf
+NVMF= nvmf.h \
+ nvmf_proto.h
+NVMFDIR= ${INCLUDEDIR}/dev/nvmf
+
.PATH: ${SRCTOP}/sys/dev/pci
PCI= pcireg.h
PCIDIR= ${INCLUDEDIR}/dev/pci
@@ -255,6 +260,7 @@ INCSGROUPS= INCS \
HYPERV \
OPENCRYPTO \
NVME \
+ NVMF \
PCI \
RPC \
SECAUDIT \
@@ -304,6 +310,13 @@ INCS+= iconv.h
LSUBDIRS+= dev/usb
.endif
+.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "aarch64" || \
+ ${MACHINE_CPUARCH} == "riscv"
+.if ${MK_BHYVE} != "no"
+LSUBDIRS+= dev/vmm
+.endif
+.endif
+
.if ${MACHINE_CPUARCH} == "powerpc" && ${MACHINE_ARCH} != "powerpcspe"
_dev_powermac_nvram= dev/powermac_nvram
.endif
diff --git a/include/Makefile.depend b/include/Makefile.depend
index 346d718d8511..d04576c4c409 100644
--- a/include/Makefile.depend
+++ b/include/Makefile.depend
@@ -2,8 +2,6 @@
DIRDEPS = \
bin/sh.host \
- usr.bin/awk.host \
- usr.bin/xinstall.host \
.include <dirdeps.mk>
diff --git a/include/arpa/Makefile b/include/arpa/Makefile
index 25bf83516844..ba589cc192fd 100644
--- a/include/arpa/Makefile
+++ b/include/arpa/Makefile
@@ -1,4 +1,3 @@
-
.include <src.opts.mk>
INCS= ftp.h inet.h nameser.h nameser_compat.h tftp.h
diff --git a/include/endian.h b/include/endian.h
index eb25cedf0bef..87ec7866c791 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -12,8 +12,32 @@
#define _ENDIAN_H_
/*
+ * POSIX Issue 8 requires that endian.h define uint{16,32,64}_t. Although POSIX
+ * allows stdint.h symbols here, be conservative and only define there required
+ * ones. FreeBSD's sys/_endian.h doesn't need to expose those types since it
+ * implements all the [bl]eXtoh hto[bl]eX interfaces as macros calling builtin
+ * functions. POSIX allows functions, macros or both. We opt for macros only.
+ */
+#include <sys/_types.h>
+
+#ifndef _UINT16_T_DECLARED
+typedef __uint16_t uint16_t;
+#define _UINT16_T_DECLARED
+#endif
+
+#ifndef _UINT32_T_DECLARED
+typedef __uint32_t uint32_t;
+#define _UINT32_T_DECLARED
+#endif
+
+#ifndef _UINT64_T_DECLARED
+typedef __uint64_t uint64_t;
+#define _UINT64_T_DECLARED
+#endif
+
+/*
* FreeBSD's sys/_endian.h is very close to the interface provided on Linux by
- * glibc's endian.h.
+ * glibc's endian.h as well as POSIX Issue 8's endian.h.
*/
#include <sys/_endian.h>
diff --git a/include/gssapi/Makefile b/include/gssapi/Makefile
index c0b18ae7a646..fb6cd7ee7dab 100644
--- a/include/gssapi/Makefile
+++ b/include/gssapi/Makefile
@@ -1,4 +1,3 @@
-
INCS= gssapi.h
INCSDIR= ${INCLUDEDIR}/gssapi
diff --git a/include/ossfuzz.h b/include/ossfuzz.h
new file mode 100644
index 000000000000..5c12a3c9c9fb
--- /dev/null
+++ b/include/ossfuzz.h
@@ -0,0 +1,79 @@
+/*
+ * *****************************************************************************
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2018-2024 Gavin D. Howard and contributors.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * *****************************************************************************
+ *
+ * Declarations for the OSS-Fuzz build of bc and dc.
+ *
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#ifndef BC_OSSFUZZ_H
+#define BC_OSSFUZZ_H
+
+/// The number of args in fuzzer arguments, including the NULL terminator.
+extern const size_t bc_fuzzer_args_len;
+
+/// The standard arguments for the bc fuzzer with the -c argument.
+extern const char* bc_fuzzer_args_c[];
+
+/// The standard arguments for the bc fuzzer with the -C argument.
+extern const char* bc_fuzzer_args_C[];
+
+/// The standard arguments for the dc fuzzer with the -c argument.
+extern const char* dc_fuzzer_args_c[];
+
+/// The standard arguments for the dc fuzzer with the -C argument.
+extern const char* dc_fuzzer_args_C[];
+
+/// The data pointer.
+extern uint8_t* bc_fuzzer_data;
+
+/**
+ * The function that the fuzzer runs.
+ * @param Data The data.
+ * @param Size The number of bytes in @a Data.
+ * @return 0 on success, -1 on error.
+ * @pre @a Data must not be equal to NULL if @a Size > 0.
+ */
+int
+LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size);
+
+/**
+ * The initialization function for the fuzzer.
+ * @param argc A pointer to the argument count.
+ * @param argv A pointer to the argument list.
+ * @return 0 on success, -1 on error.
+ */
+int
+LLVMFuzzerInitialize(int* argc, char*** argv);
+
+#endif // BC_OSSFUZZ_H
diff --git a/include/paths.h b/include/paths.h
index 9f9071af915c..f8861ea4e5a8 100644
--- a/include/paths.h
+++ b/include/paths.h
@@ -61,7 +61,6 @@
#define _PATH_FIRMWARE "/usr/share/firmware"
#define _PATH_FTPUSERS "/etc/ftpusers"
#define _PATH_FWMEM "/dev/fwmem"
-#define _PATH_GBDE "/sbin/gbde"
#define _PATH_GELI "/sbin/geli"
#define _PATH_HALT "/sbin/halt"
#ifdef COMPAT_libcompat
@@ -90,6 +89,7 @@
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHELLS "/etc/shells"
#define _PATH_TTY "/dev/tty"
+#define _PATH_TUNEFS "/sbin/tunefs"
#define _PATH_UNIX "don't use _PATH_UNIX"
#define _PATH_UFSSUSPEND "/dev/ufssuspend"
#define _PATH_VI "/usr/bin/vi"
@@ -139,6 +139,8 @@ __END_DECLS
#define _PATH_REBOOT "/rescue/reboot"
#undef _PATH_RM
#define _PATH_RM "/rescue/rm"
+#undef _PATH_TUNEFS
+#define _PATH_TUNEFS "/rescue/tunefs"
#undef _PATH_VI
#define _PATH_VI "/rescue/vi"
#undef _PATH_WALL
diff --git a/include/protocols/Makefile b/include/protocols/Makefile
index bdcbbae48a35..9817add2e9f1 100644
--- a/include/protocols/Makefile
+++ b/include/protocols/Makefile
@@ -1,4 +1,3 @@
-
INCS= dumprestore.h routed.h rwhod.h talkd.h timed.h
INCSDIR=${INCLUDEDIR}/protocols
diff --git a/include/rpc/Makefile b/include/rpc/Makefile
index 0c8434ee3473..b6e3ab53adb4 100644
--- a/include/rpc/Makefile
+++ b/include/rpc/Makefile
@@ -1,4 +1,3 @@
-
.SUFFIXES: .x
RPCCOM= RPCGEN_CPP=${CPP:Q} rpcgen -C
diff --git a/include/rpc/xdr.h b/include/rpc/xdr.h
index 11d6a8d13b49..ecf10e1659e4 100644
--- a/include/rpc/xdr.h
+++ b/include/rpc/xdr.h
@@ -278,7 +278,7 @@ struct xdr_discrim {
* These are the "generic" xdr routines.
*/
__BEGIN_DECLS
-extern bool_t xdr_void(void);
+extern bool_t xdr_void(XDR *, void *);
extern bool_t xdr_int(XDR *, int *);
extern bool_t xdr_u_int(XDR *, u_int *);
extern bool_t xdr_long(XDR *, long *);
diff --git a/include/rpcsvc/Makefile b/include/rpcsvc/Makefile
index 8ede7636f50e..bc2b74561422 100644
--- a/include/rpcsvc/Makefile
+++ b/include/rpcsvc/Makefile
@@ -1,4 +1,3 @@
-
.SUFFIXES: .x
RPCCOM= RPCGEN_CPP=${CPP:Q} rpcgen -C
diff --git a/include/ssp/Makefile b/include/ssp/Makefile
new file mode 100644
index 000000000000..ff622aeecfe9
--- /dev/null
+++ b/include/ssp/Makefile
@@ -0,0 +1,5 @@
+INCS= poll.h random.h socket.h ssp.h stdio.h stdlib.h string.h strings.h
+INCS+= uio.h unistd.h wchar.h
+INCSDIR= ${INCLUDEDIR}/ssp
+
+.include <bsd.prog.mk>
diff --git a/include/ssp/Makefile.depend b/include/ssp/Makefile.depend
new file mode 100644
index 000000000000..11aba52f82cf
--- /dev/null
+++ b/include/ssp/Makefile.depend
@@ -0,0 +1,10 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/include/ssp/poll.h b/include/ssp/poll.h
new file mode 100644
index 000000000000..815e73eb46b7
--- /dev/null
+++ b/include/ssp/poll.h
@@ -0,0 +1,60 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024, Klara, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_POLL_H_
+#define _SSP_POLL_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+__BEGIN_DECLS
+
+__ssp_redirect_raw_impl(int, poll, poll,
+ (struct pollfd fds[], nfds_t nfds, int timeout))
+{
+ if (__ssp_bos(fds) / sizeof(fds[0]) < nfds)
+ __chk_fail();
+
+ return (__ssp_real(poll)(fds, nfds, timeout));
+}
+
+#if __BSD_VISIBLE
+__ssp_redirect_raw_impl(int, ppoll, ppoll,
+ (struct pollfd fds[], nfds_t nfds,
+ const struct timespec *__restrict timeout,
+ const sigset_t *__restrict newsigmask))
+{
+ if (__ssp_bos(fds) / sizeof(fds[0]) < nfds)
+ __chk_fail();
+
+ return (__ssp_real(ppoll)(fds, nfds, timeout, newsigmask));
+}
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_POLL_H_ */
diff --git a/include/ssp/random.h b/include/ssp/random.h
new file mode 100644
index 000000000000..9f98ad2315a1
--- /dev/null
+++ b/include/ssp/random.h
@@ -0,0 +1,42 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024, Klara, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_RANDOM_H_
+#define _SSP_RANDOM_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+__BEGIN_DECLS
+
+__ssp_redirect(ssize_t, getrandom, (void *__buf, size_t __len,
+ unsigned int __flags), (__buf, __len, __flags));
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_RANDOM_H_ */
diff --git a/include/ssp/socket.h b/include/ssp/socket.h
new file mode 100644
index 000000000000..30a8f0adf1ea
--- /dev/null
+++ b/include/ssp/socket.h
@@ -0,0 +1,120 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024, Klara, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_SOCKET_H_
+#define _SSP_SOCKET_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#include <sys/_null.h>
+
+__BEGIN_DECLS
+
+__ssp_inline void
+__ssp_check_msghdr(struct msghdr *hdr)
+{
+ if (__ssp_bos(hdr->msg_name) < hdr->msg_namelen)
+ __chk_fail();
+
+ __ssp_check_iovec(hdr->msg_iov, hdr->msg_iovlen);
+
+ if (__ssp_bos(hdr->msg_control) < hdr->msg_controllen)
+ __chk_fail();
+}
+
+__ssp_redirect_raw_impl(int, getpeername, getpeername,
+ (int fdes, struct sockaddr *__restrict name, socklen_t *__restrict namelen))
+{
+ size_t namesz = __ssp_bos(name);
+
+ if (namesz != (size_t)-1 && namesz < *namelen)
+ __chk_fail();
+
+ return (__ssp_real(getpeername)(fdes, name, namelen));
+}
+
+__ssp_redirect_raw_impl(int, getsockname, getsockname,
+ (int fdes, struct sockaddr *__restrict name,
+ socklen_t *__restrict namelen))
+{
+ size_t namesz = __ssp_bos(name);
+
+ if (namesz != (size_t)-1 && namesz < *namelen)
+ __chk_fail();
+
+ return (__ssp_real(getsockname)(fdes, name, namelen));
+}
+
+__ssp_redirect(ssize_t, recv, (int __sock, void *__buf, size_t __len,
+ int __flags), (__sock, __buf, __len, __flags));
+
+__ssp_redirect_raw_impl(ssize_t, recvfrom, recvfrom,
+ (int s, void *buf, size_t len, int flags,
+ struct sockaddr *__restrict from,
+ socklen_t *__restrict fromlen))
+{
+ if (__ssp_bos(buf) < len)
+ __chk_fail();
+ if (from != NULL && __ssp_bos(from) < *fromlen)
+ __chk_fail();
+
+ return (__ssp_real(recvfrom)(s, buf, len, flags, from, fromlen));
+}
+
+__ssp_redirect_raw_impl(ssize_t, recvmsg, recvmsg,
+ (int s, struct msghdr *hdr, int flags))
+{
+ __ssp_check_msghdr(hdr);
+ return (__ssp_real(recvmsg)(s, hdr, flags));
+}
+
+#if __BSD_VISIBLE
+struct timespec;
+
+__ssp_redirect_raw_impl(ssize_t, recvmmsg, recvmmsg,
+ (int s, struct mmsghdr *__restrict hdrvec, size_t vlen, int flags,
+ const struct timespec *__restrict timeout))
+{
+ const size_t vecsz = __ssp_bos(hdrvec);
+ size_t i;
+
+ if (vecsz != (size_t)-1 && vecsz / sizeof(*hdrvec) < vlen)
+ __chk_fail();
+
+ for (i = 0; i < vlen; i++) {
+ __ssp_check_msghdr(&hdrvec[i].msg_hdr);
+ }
+
+ return (__ssp_real(recvmmsg)(s, hdrvec, vlen, flags, timeout));
+}
+#endif
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_SOCKET_H_ */
diff --git a/include/ssp/ssp.h b/include/ssp/ssp.h
new file mode 100644
index 000000000000..6856c5ce6961
--- /dev/null
+++ b/include/ssp/ssp.h
@@ -0,0 +1,126 @@
+/* $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp $ */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_SSP_H_
+#define _SSP_SSP_H_
+
+#include <sys/cdefs.h>
+
+#if !defined(__cplusplus)
+# if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && \
+ (__OPTIMIZE__ > 0 || defined(__clang__))
+# if _FORTIFY_SOURCE > 1
+# define __SSP_FORTIFY_LEVEL 2
+# else
+# define __SSP_FORTIFY_LEVEL 1
+# endif
+# else
+# define __SSP_FORTIFY_LEVEL 0
+# endif
+#else
+# define __SSP_FORTIFY_LEVEL 0
+#endif
+
+#define __ssp_var(type) __CONCAT(__ssp_ ## type, __COUNTER__)
+
+/* __ssp_real is used by the implementation in libc */
+#if __SSP_FORTIFY_LEVEL == 0
+#define __ssp_real_(fun) fun
+#else
+#define __ssp_real_(fun) __ssp_real_ ## fun
+#endif
+#define __ssp_real(fun) __ssp_real_(fun)
+
+#define __ssp_inline static __inline __attribute__((__always_inline__))
+
+#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
+#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
+
+#define __ssp_check(buf, len, bos) \
+ if (bos(buf) != (size_t)-1 && (size_t)len > bos(buf)) \
+ __chk_fail()
+
+#define __ssp_redirect_raw_impl(rtype, fun, symbol, args) \
+rtype __ssp_real_(fun) args __RENAME(symbol); \
+__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \
+__ssp_inline rtype fun args
+
+#define __ssp_redirect_raw(rtype, fun, symbol, args, call, cond, bos, len) \
+__ssp_redirect_raw_impl(rtype, fun, symbol, args) { \
+ if (cond) \
+ __ssp_check(__buf, len, bos); \
+ return __ssp_real_(fun) call; \
+}
+
+#define __ssp_redirect(rtype, fun, args, call) \
+ __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos, __len)
+#define __ssp_redirect0(rtype, fun, args, call) \
+ __ssp_redirect_raw(rtype, fun, fun, args, call, 1, __ssp_bos0, __len)
+
+#include <machine/_limits.h>
+
+__ssp_inline int
+__ssp_overlap(const void *leftp, const void *rightp, __size_t sz)
+{
+ __uintptr_t left = (__uintptr_t)leftp;
+ __uintptr_t right = (__uintptr_t)rightp;
+
+ if (left <= right)
+ return (__SIZE_T_MAX - sz < left || right < left + sz);
+
+ return (__SIZE_T_MAX - sz < right || left < right + sz);
+}
+
+#include <sys/_iovec.h>
+
+__BEGIN_DECLS
+void __stack_chk_fail(void) __dead2;
+void __chk_fail(void) __dead2;
+__END_DECLS
+
+__ssp_inline void
+__ssp_check_iovec(const struct iovec *iov, int iovcnt)
+{
+ const size_t iovsz = __ssp_bos(iov);
+ int i;
+
+ if (iovsz != (size_t)-1 && iovsz / sizeof(*iov) < (size_t)iovcnt)
+ __chk_fail();
+
+ for (i = 0; i < iovcnt; i++) {
+ if (__ssp_bos(iov[i].iov_base) < iov[i].iov_len)
+ __chk_fail();
+ }
+}
+
+#endif /* _SSP_SSP_H_ */
diff --git a/include/ssp/stdio.h b/include/ssp/stdio.h
new file mode 100644
index 000000000000..630683951e4b
--- /dev/null
+++ b/include/ssp/stdio.h
@@ -0,0 +1,107 @@
+/* $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:34 joerg Exp $ */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_STDIO_H_
+#define _SSP_STDIO_H_
+
+#include <ssp/ssp.h>
+
+__BEGIN_DECLS
+#if __SSP_FORTIFY_LEVEL > 0
+#if __POSIX_VISIBLE
+__ssp_redirect_raw(char *, ctermid, ctermid, (char *__buf), (__buf),
+ __buf != NULL, __ssp_bos, L_ctermid);
+#if __BSD_VISIBLE
+__ssp_redirect_raw(char *, ctermid_r, ctermid_r, (char *__buf), (__buf),
+ __buf != NULL, __ssp_bos, L_ctermid);
+#endif /* __BSD_VISIBLE */
+#endif /* __POSIX_VISIBLE */
+__ssp_redirect(size_t, fread, (void *__restrict __buf, size_t __len,
+ size_t __nmemb, FILE *__restrict __fp), (__buf, __len, __nmemb, __fp));
+__ssp_redirect(size_t, fread_unlocked, (void *__restrict __buf, size_t __len,
+ size_t __nmemb, FILE *__restrict __fp), (__buf, __len, __nmemb, __fp));
+#if __EXT1_VISIBLE
+__ssp_redirect(char *, gets_s, (char *__buf, rsize_t __len), (__buf, __len));
+#endif /* __EXT1_VISIBLE */
+__ssp_redirect_raw(char *, tmpnam, tmpnam, (char *__buf), (__buf), 1,
+ __ssp_bos, L_tmpnam);
+#endif
+
+int __sprintf_chk(char *__restrict, int, size_t, const char *__restrict, ...)
+ __printflike(4, 5);
+int __vsprintf_chk(char *__restrict, int, size_t, const char *__restrict,
+ __va_list)
+ __printflike(4, 0);
+int __snprintf_chk(char *__restrict, size_t, int, size_t,
+ const char *__restrict, ...)
+ __printflike(5, 6);
+int __vsnprintf_chk(char *__restrict, size_t, int, size_t,
+ const char *__restrict, __va_list)
+ __printflike(5, 0);
+char *__fgets_chk(char *, int, size_t, FILE *);
+__END_DECLS
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define sprintf(str, ...) __extension__ ({ \
+ char *_ssp_str = (str); \
+ __builtin___sprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), \
+ __VA_ARGS__); \
+})
+
+#define vsprintf(str, fmt, ap) __extension__ ({ \
+ char *_ssp_str = (str); \
+ __builtin___vsprintf_chk(_ssp_str, 0, __ssp_bos(_ssp_str), fmt, \
+ ap); \
+})
+
+#define snprintf(str, len, ...) __extension__ ({ \
+ char *_ssp_str = (str); \
+ __builtin___snprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_str), \
+ __VA_ARGS__); \
+})
+
+#define vsnprintf(str, len, fmt, ap) __extension__ ({ \
+ char *_ssp_str = (str); \
+ __builtin___vsnprintf_chk(_ssp_str, len, 0, __ssp_bos(_ssp_str), \
+ fmt, ap); \
+})
+
+#define fgets(str, len, fp) __extension__ ({ \
+ char *_ssp_str = (str); \
+ __fgets_chk(_ssp_str, len, __ssp_bos(_ssp_str), fp); \
+})
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+
+#endif /* _SSP_STDIO_H_ */
diff --git a/include/ssp/stdlib.h b/include/ssp/stdlib.h
new file mode 100644
index 000000000000..f595ecbcbc0a
--- /dev/null
+++ b/include/ssp/stdlib.h
@@ -0,0 +1,53 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024, Klara, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_STDLIB_H_
+#define _SSP_STDLIB_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#include <limits.h>
+
+__BEGIN_DECLS
+
+__ssp_redirect(void, arc4random_buf, (void *__buf, size_t __len),
+ (__buf, __len));
+
+__ssp_redirect_raw_impl(char *, realpath, realpath,
+ (const char *__restrict path, char *__restrict buf))
+{
+ if (__ssp_bos(buf) < PATH_MAX)
+ __chk_fail();
+
+ return (__ssp_real(realpath)(path, buf));
+}
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STDLIB_H_ */
diff --git a/include/ssp/string.h b/include/ssp/string.h
new file mode 100644
index 000000000000..2999aed13cb1
--- /dev/null
+++ b/include/ssp/string.h
@@ -0,0 +1,141 @@
+/* $NetBSD: string.h,v 1.14 2020/09/05 13:37:59 mrg Exp $ */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_STRING_H_
+#define _SSP_STRING_H_
+
+#include <ssp/ssp.h>
+
+__BEGIN_DECLS
+void *__memcpy_chk(void *, const void *, size_t, size_t);
+void *__memmove_chk(void *, const void *, size_t, size_t);
+void *__memset_chk(void *, int, size_t, size_t);
+char *__stpcpy_chk(char *, const char *, size_t);
+char *__stpncpy_chk(char *, const char *, size_t, size_t);
+char *__strcat_chk(char *, const char *, size_t);
+char *__strcpy_chk(char *, const char *, size_t);
+char *__strncat_chk(char *, const char *, size_t, size_t);
+size_t __strlcat_chk(char *, const char *, size_t, size_t);
+char *__strncpy_chk(char *, const char *, size_t, size_t);
+size_t __strlcpy_chk(char *, const char *, size_t, size_t);
+__END_DECLS
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define __ssp_bos_check3_typed_var(fun, dsttype, dsrvar, dst, srctype, srcvar, \
+ src, lenvar, len) __extension__ ({ \
+ srctype srcvar = (src); \
+ dsttype dstvar = (dst); \
+ size_t lenvar = (len); \
+ ((__ssp_bos0(dstvar) != (size_t)-1) ? \
+ __builtin___ ## fun ## _chk(dstvar, srcvar, lenvar, \
+ __ssp_bos0(dstvar)) : \
+ __ ## fun ## _ichk(dstvar, srcvar, lenvar)); \
+})
+
+#define __ssp_bos_check3_typed(fun, dsttype, dst, srctype, src, len) \
+ __ssp_bos_check3_typed_var(fun, dsttype, __ssp_var(dstv), dst, \
+ srctype, __ssp_var(srcv), src, __ssp_var(lenv), len)
+
+#define __ssp_bos_check3(fun, dst, src, len) \
+ __ssp_bos_check3_typed_var(fun, void *, __ssp_var(dstv), dst, \
+ const void *, __ssp_var(srcv), src, __ssp_var(lenv), len)
+
+#define __ssp_bos_check2_var(fun, dstvar, dst, srcvar, src) __extension__ ({ \
+ const void *srcvar = (src); \
+ void *dstvar = (dst); \
+ ((__ssp_bos0(dstvar) != (size_t)-1) ? \
+ __builtin___ ## fun ## _chk(dstvar, srcvar, \
+ __ssp_bos0(dstvar)) : \
+ __ ## fun ## _ichk(dstvar, srcvar)); \
+})
+
+#define __ssp_bos_check2(fun, dst, src) \
+ __ssp_bos_check2_var(fun, __ssp_var(dstv), dst, __ssp_var(srcv), src)
+
+#define __ssp_bos_icheck3_restrict(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1 __restrict, type2 __restrict, size_t); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src, size_t len) { \
+ return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \
+}
+
+#define __ssp_bos_icheck3(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1, type2, size_t); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 dst, type2 src, size_t len) { \
+ return __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)); \
+}
+
+#define __ssp_bos_icheck2_restrict(fun, type1, type2) \
+static __inline type1 __ ## fun ## _ichk(type1, type2); \
+static __inline __attribute__((__always_inline__)) type1 \
+__ ## fun ## _ichk(type1 __restrict dst, type2 __restrict src) { \
+ return __builtin___ ## fun ## _chk(dst, src, __ssp_bos0(dst)); \
+}
+
+__BEGIN_DECLS
+__ssp_bos_icheck3_restrict(memcpy, void *, const void *)
+__ssp_bos_icheck3_restrict(mempcpy, void *, const void *)
+__ssp_bos_icheck3(memmove, void *, const void *)
+__ssp_bos_icheck3(memset, void *, int)
+__ssp_redirect(void *, memset_explicit, (void *__buf, int __ch, size_t __len),
+ (__buf, __ch, __len));
+__ssp_bos_icheck2_restrict(stpcpy, char *, const char *)
+__ssp_bos_icheck3_restrict(stpncpy, char *, const char *)
+__ssp_bos_icheck2_restrict(strcpy, char *, const char *)
+__ssp_bos_icheck2_restrict(strcat, char *, const char *)
+__ssp_redirect0(int, strerror_r, (int __errnum, char *__buf, size_t __len),
+ (__errnum, __buf, __len));
+__ssp_bos_icheck3_restrict(strncpy, char *, const char *)
+__ssp_bos_icheck3_restrict(strncat, char *, const char *)
+__END_DECLS
+
+#define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len)
+#define mempcpy(dst, src, len) __ssp_bos_check3(mempcpy, dst, src, len)
+#define memmove(dst, src, len) __ssp_bos_check3(memmove, dst, src, len)
+#define memset(dst, val, len) \
+ __ssp_bos_check3_typed(memset, void *, dst, int, val, len)
+#define stpcpy(dst, src) __ssp_bos_check2(stpcpy, dst, src)
+#define stpncpy(dst, src, len) __ssp_bos_check3(stpncpy, dst, src, len)
+#define strcpy(dst, src) __ssp_bos_check2(strcpy, dst, src)
+#define strcat(dst, src) __ssp_bos_check2(strcat, dst, src)
+#define strlcpy(dst, src, dstlen) \
+ __strlcpy_chk(dst, src, dstlen, __ssp_bos(dst))
+#define strncpy(dst, src, len) __ssp_bos_check3(strncpy, dst, src, len)
+#define strlcat(dst, src, dstlen) \
+ __strlcat_chk(dst, src, dstlen, __ssp_bos(dst))
+#define strncat(dst, src, len) __ssp_bos_check3(strncat, dst, src, len)
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRING_H_ */
diff --git a/include/ssp/strings.h b/include/ssp/strings.h
new file mode 100644
index 000000000000..79b70eba1c5c
--- /dev/null
+++ b/include/ssp/strings.h
@@ -0,0 +1,72 @@
+/* $NetBSD: strings.h,v 1.3 2008/04/28 20:22:54 martin Exp $ */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_STRINGS_H_
+#define _SSP_STRINGS_H_
+
+#include <ssp/ssp.h>
+#include <string.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#define _ssp_bcopy(srcvar, src, dstvar, dst, lenvar, len) __extension__ ({ \
+ const void *srcvar = (src); \
+ void *dstvar = (dst); \
+ size_t lenvar = (len); \
+ ((__ssp_bos0(dstvar) != (size_t)-1) ? \
+ __builtin___memmove_chk(dstvar, srcvar, lenvar, \
+ __ssp_bos0(dstvar)) : \
+ __memmove_ichk(dstvar, srcvar, lenvar)); \
+})
+
+#define bcopy(src, dst, len) \
+ _ssp_bcopy(__ssp_var(srcv), src, __ssp_var(dstv), dst, __ssp_var(lenv), len)
+
+#define _ssp_bzero(dstvar, dst, lenvar, len) __extension__ ({ \
+ void *dstvar = (dst); \
+ size_t lenvar = (len); \
+ ((__ssp_bos0(dstvar) != (size_t)-1) ? \
+ __builtin___memset_chk(dstvar, 0, lenvar, \
+ __ssp_bos0(dstvar)) : \
+ __memset_ichk(dstvar, 0, lenvar)); \
+})
+
+#define bzero(dst, len) _ssp_bzero(__ssp_var(dstv), dst, __ssp_var(lenv), len)
+
+__BEGIN_DECLS
+__ssp_redirect(void, explicit_bzero, (void *__buf, size_t __len),
+ (__buf, __len));
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRINGS_H_ */
diff --git a/include/ssp/uio.h b/include/ssp/uio.h
new file mode 100644
index 000000000000..adf1dcbb3d67
--- /dev/null
+++ b/include/ssp/uio.h
@@ -0,0 +1,53 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024, Klara, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_UIO_H_
+#define _SSP_UIO_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+__BEGIN_DECLS
+
+__ssp_redirect_raw_impl(ssize_t, readv, readv,
+ (int fd, const struct iovec *iov, int iovcnt))
+{
+ __ssp_check_iovec(iov, iovcnt);
+ return (__ssp_real(readv)(fd, iov, iovcnt));
+}
+
+__ssp_redirect_raw_impl(ssize_t, preadv, preadv,
+ (int fd, const struct iovec *iov, int iovcnt, off_t offset))
+{
+ __ssp_check_iovec(iov, iovcnt);
+ return (__ssp_real(preadv)(fd, iov, iovcnt, offset));
+}
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_UIO_H_ */
diff --git a/include/ssp/unistd.h b/include/ssp/unistd.h
new file mode 100644
index 000000000000..7e9d72343dde
--- /dev/null
+++ b/include/ssp/unistd.h
@@ -0,0 +1,90 @@
+/* $NetBSD: unistd.h,v 1.7 2015/06/25 18:41:03 joerg Exp $ */
+
+/*-
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_UNISTD_H_
+#define _SSP_UNISTD_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+__BEGIN_DECLS
+
+#ifndef _FORTIFY_SOURCE_read
+#define _FORTIFY_SOURCE_read read
+#endif
+
+__ssp_inline size_t
+__ssp_gid_bos(const void *ptr)
+{
+ size_t ptrsize = __ssp_bos(ptr);
+
+ if (ptrsize == (size_t)-1)
+ return (ptrsize);
+
+ return (ptrsize / sizeof(gid_t));
+}
+
+__ssp_redirect_raw(int, getgrouplist, getgrouplist,
+ (const char *__name, gid_t __base, gid_t *__buf, int *__lenp),
+ (__name, __base, __buf, __lenp), 1, __ssp_gid_bos, *__lenp);
+
+__ssp_redirect_raw(int, getgroups, getgroups, (int __len, gid_t *__buf),
+ (__len, __buf), 1, __ssp_gid_bos, __len);
+
+__ssp_redirect(int, getloginclass, (char *__buf, size_t __len),
+ (__buf, __len));
+
+__ssp_redirect(ssize_t, _FORTIFY_SOURCE_read, (int __fd, void *__buf,
+ size_t __len), (__fd, __buf, __len));
+__ssp_redirect(ssize_t, pread, (int __fd, void *__buf, size_t __len,
+ off_t __offset), (__fd, __buf, __len, __offset));
+
+__ssp_redirect(ssize_t, readlink, (const char *__restrict __path, \
+ char *__restrict __buf, size_t __len), (__path, __buf, __len));
+__ssp_redirect(ssize_t, readlinkat, (int __fd, const char *__restrict __path,
+ char *__restrict __buf, size_t __len), (__fd, __path, __buf, __len));
+
+__ssp_redirect_raw(char *, getcwd, getcwd, (char *__buf, size_t __len),
+ (__buf, __len), __buf != 0, __ssp_bos, __len);
+
+__ssp_redirect(int, getdomainname, (char *__buf, int __len), (__buf, __len));
+__ssp_redirect(int, getentropy, (void *__buf, size_t __len), (__buf, __len));
+__ssp_redirect(int, gethostname, (char *__buf, size_t __len), (__buf, __len));
+__ssp_redirect(int, getlogin_r, (char *__buf, size_t __len), (__buf, __len));
+__ssp_redirect(int, ttyname_r, (int __fd, char *__buf, size_t __len),
+ (__fd, __buf, __len));
+
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_UNISTD_H_ */
diff --git a/include/ssp/wchar.h b/include/ssp/wchar.h
new file mode 100644
index 000000000000..7ed84e087f5d
--- /dev/null
+++ b/include/ssp/wchar.h
@@ -0,0 +1,229 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024, Klara, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _SSP_WCHAR_H_
+#define _SSP_WCHAR_H_
+
+#include <ssp/ssp.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+__ssp_inline int
+__ssp_wchar_overlap(const void *leftp, const void *rightp, size_t len)
+{
+
+ if (len > __SIZE_T_MAX / sizeof(wchar_t))
+ return (1);
+ return (__ssp_overlap(leftp, rightp, len * sizeof(wchar_t)));
+}
+
+/*
+ * __ssp_wbos for w*() calls where the size parameters are in sizeof(wchar_t)
+ * units, so the result needs to be scaled appropriately.
+ */
+__ssp_inline size_t
+__ssp_wbos(void *ptr)
+{
+ const size_t ptrsize = __ssp_bos(ptr);
+
+ if (ptrsize == (size_t)-1)
+ return (ptrsize);
+
+ return (ptrsize / sizeof(wchar_t));
+}
+
+__BEGIN_DECLS
+__ssp_redirect_raw_impl(wchar_t *, wmemcpy, wmemcpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(src, buf, len))
+ __chk_fail();
+
+ return (__ssp_real(wmemcpy)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wmempcpy, wmempcpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(src, buf, len))
+ __chk_fail();
+
+ return (__ssp_real(wmempcpy)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wmemmove, wmemmove,
+ (wchar_t *buf, const wchar_t *src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+
+ return (__ssp_real(wmemmove)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wmemset, wmemset,
+ (wchar_t *buf, wchar_t c, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ return (__ssp_real(wmemset)(buf, c, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wcpcpy, wcpcpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src))
+{
+ const size_t slen = __ssp_wbos(buf);
+ const size_t len = wcslen(src);
+
+ if (len >= slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ (void)__ssp_real(wmemcpy)(buf, src, len + 1);
+ return (buf + len);
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wcpncpy, wcpncpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ return (__ssp_real(wcpncpy)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wcscat, wcscat,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src))
+{
+ size_t slen = __ssp_wbos(buf);
+ wchar_t *cp;
+
+ cp = buf;
+ while (*cp != L'\0') {
+ cp++;
+ if (slen-- == 0)
+ __chk_fail();
+ }
+
+ while (*src != L'\0') {
+ if (slen-- == 0)
+ __chk_fail();
+ *cp++ = *src++;
+ }
+
+ if (slen-- == 0)
+ __chk_fail();
+ *cp = '\0';
+ return (buf);
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wcscpy, wcscpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src))
+{
+ const size_t slen = __ssp_wbos(buf);
+ size_t len = wcslen(src) + 1;
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ return (__ssp_real(wmemcpy)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wcsncat, wcsncat,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len == 0)
+ return (buf);
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ return (__ssp_real(wcsncat)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(size_t, wcslcat, wcslcat,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ return (__ssp_real(wcslcat)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(wchar_t *, wcsncpy, wcsncpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ return (__ssp_real(wcsncpy)(buf, src, len));
+}
+
+__ssp_redirect_raw_impl(size_t, wcslcpy, wcslcpy,
+ (wchar_t *__restrict buf, const wchar_t *__restrict src, size_t len))
+{
+ const size_t slen = __ssp_wbos(buf);
+
+ if (len > slen)
+ __chk_fail();
+ if (__ssp_wchar_overlap(buf, src, len))
+ __chk_fail();
+
+ return (__ssp_real(wcslcpy)(buf, src, len));
+}
+__END_DECLS
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_WCHAR_H_ */
diff --git a/include/stddef.h b/include/stddef.h
index b695ae7a07a7..2255ea47a49a 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -41,13 +41,6 @@ typedef __ptrdiff_t ptrdiff_t;
#define _PTRDIFF_T_DECLARED
#endif
-#if __BSD_VISIBLE
-#ifndef _RUNE_T_DECLARED
-typedef __rune_t rune_t;
-#define _RUNE_T_DECLARED
-#endif
-#endif
-
#ifndef _SIZE_T_DECLARED
typedef __size_t size_t;
#define _SIZE_T_DECLARED
diff --git a/include/stdio.h b/include/stdio.h
index fe7a6f7d6f82..ee3ab3bfb986 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -48,10 +48,13 @@ typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
+#if __EXT1_VISIBLE
+/* ISO/IEC 9899:2011 K.3.3.2 */
#ifndef _RSIZE_T_DEFINED
#define _RSIZE_T_DEFINED
typedef size_t rsize_t;
#endif
+#endif /* __EXT1_VISIBLE */
#if __POSIX_VISIBLE >= 200809
#ifndef _OFF_T_DECLARED
@@ -238,6 +241,21 @@ __END_DECLS
#define stdout __stdoutp
#define stderr __stderrp
+/*
+ * Functions defined in all versions of POSIX 1003.1.
+ */
+#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 199506)
+#define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */
+#endif
+
+#if __POSIX_VISIBLE
+#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */
+#endif /* __POSIX_VISIBLE */
+
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#include <ssp/stdio.h>
+#endif
+
__BEGIN_DECLS
#ifdef _XLOCALE_H_
#include <xlocale/_stdio.h>
@@ -252,7 +270,7 @@ int ferror(FILE *);
int fflush(FILE *);
int fgetc(FILE *);
int fgetpos(FILE * __restrict, fpos_t * __restrict);
-char *fgets(char * __restrict, int, FILE * __restrict);
+char *(fgets)(char * __restrict, int, FILE * __restrict);
FILE *fopen(const char * __restrict, const char * __restrict);
int fprintf(FILE * __restrict, const char * __restrict, ...);
int fputc(int, FILE *);
@@ -280,7 +298,7 @@ void rewind(FILE *);
int scanf(const char * __restrict, ...);
void setbuf(FILE * __restrict, char * __restrict);
int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
-int sprintf(char * __restrict, const char * __restrict, ...);
+int (sprintf)(char * __restrict, const char * __restrict, ...);
int sscanf(const char * __restrict, const char * __restrict, ...);
FILE *tmpfile(void);
char *tmpnam(char *);
@@ -288,13 +306,13 @@ int ungetc(int, FILE *);
int vfprintf(FILE * __restrict, const char * __restrict,
__va_list);
int vprintf(const char * __restrict, __va_list);
-int vsprintf(char * __restrict, const char * __restrict,
+int (vsprintf)(char * __restrict, const char * __restrict,
__va_list);
#if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 199506
-int snprintf(char * __restrict, size_t, const char * __restrict,
+int (snprintf)(char * __restrict, size_t, const char * __restrict,
...) __printflike(3, 4);
-int vsnprintf(char * __restrict, size_t, const char * __restrict,
+int (vsnprintf)(char * __restrict, size_t, const char * __restrict,
__va_list) __printflike(3, 0);
#endif
#if __ISO_C_VISIBLE >= 1999
@@ -305,16 +323,7 @@ int vsscanf(const char * __restrict, const char * __restrict, __va_list)
__scanflike(2, 0);
#endif
-/*
- * Functions defined in all versions of POSIX 1003.1.
- */
-#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 199506)
-#define L_cuserid 17 /* size for cuserid(3); MAXLOGNAME, legacy */
-#endif
-
#if __POSIX_VISIBLE
-#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */
-
char *ctermid(char *);
FILE *fdopen(int, const char *);
int fileno(FILE *);
diff --git a/include/stdlib.h b/include/stdlib.h
index 7a934dfa306d..162031ab393d 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -38,13 +38,6 @@
__NULLABILITY_PRAGMA_PUSH
-#if __BSD_VISIBLE
-#ifndef _RUNE_T_DECLARED
-typedef __rune_t rune_t;
-#define _RUNE_T_DECLARED
-#endif
-#endif
-
#ifndef _SIZE_T_DECLARED
typedef __size_t size_t;
#define _SIZE_T_DECLARED
@@ -76,6 +69,10 @@ typedef struct {
*/
#define RAND_MAX 0x7fffffff
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#include <ssp/stdlib.h>
+#endif
+
__BEGIN_DECLS
#ifdef _XLOCALE_H_
#include <xlocale/_stdlib.h>
@@ -337,23 +334,26 @@ __uint64_t
* parameter, and both are different from the ones expected by the historical
* FreeBSD qsort_r() interface.
*
- * Apply a workaround where we explicitly link against the historical
- * interface, qsort_r@FBSD_1.0, in case when qsort_r() is called with
- * the last parameter with a function pointer that exactly matches the
- * historical FreeBSD qsort_r() comparator signature, so applications
- * written for the historical interface can continue to work without
- * modification.
+ * Apply a workaround where we explicitly link against the historical interface,
+ * qsort_r@FBSD_1.0, in case when qsort_r() is called with the last parameter
+ * with a function pointer that exactly matches the historical FreeBSD qsort_r()
+ * comparator signature, so applications written for the historical interface
+ * can continue to work without modification. Toolchains that don't support
+ * symbol versioning don't define __sym_compat, so only provide this symbol in
+ * supported environments.
*/
+#ifdef __sym_compat
#if defined(__generic) || defined(__cplusplus)
void __qsort_r_compat(void *, size_t, size_t, void *,
int (*)(void *, const void *, const void *));
__sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0);
#endif
+#endif
#if defined(__generic) && !defined(__cplusplus)
#define qsort_r(base, nel, width, arg4, arg5) \
__generic(arg5, int (*)(void *, const void *, const void *), \
__qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5)
-#elif defined(__cplusplus)
+#elif defined(__cplusplus) && defined(__sym_compat)
__END_DECLS
extern "C++" {
static inline void qsort_r(void *base, size_t nmemb, size_t size,
diff --git a/include/string.h b/include/string.h
index 597308020cdb..73b675370c58 100644
--- a/include/string.h
+++ b/include/string.h
@@ -49,6 +49,10 @@ typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#include <ssp/string.h>
+#endif
+
__BEGIN_DECLS
#if __XSI_VISIBLE >= 600
void *memccpy(void * __restrict, const void * __restrict, int, size_t);
@@ -58,23 +62,26 @@ void *memchr(const void *, int, size_t) __pure;
void *memrchr(const void *, int, size_t) __pure;
#endif
int memcmp(const void *, const void *, size_t) __pure;
-void *memcpy(void * __restrict, const void * __restrict, size_t);
+void *(memcpy)(void * __restrict, const void * __restrict, size_t);
#if __BSD_VISIBLE
void *memmem(const void *, size_t, const void *, size_t) __pure;
#endif
-void *memmove(void *, const void *, size_t);
+void *(memmove)(void *, const void *, size_t);
#if __BSD_VISIBLE
-void *mempcpy(void * __restrict, const void * __restrict, size_t);
+void *(mempcpy)(void * __restrict, const void * __restrict, size_t);
+#endif
+void *(memset)(void *, int, size_t);
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 2023
+void *memset_explicit(void *, int, size_t);
#endif
-void *memset(void *, int, size_t);
#if __POSIX_VISIBLE >= 200809
-char *stpcpy(char * __restrict, const char * __restrict);
-char *stpncpy(char * __restrict, const char * __restrict, size_t);
+char *(stpcpy)(char * __restrict, const char * __restrict);
+char *(stpncpy)(char * __restrict, const char * __restrict, size_t);
#endif
#if __BSD_VISIBLE
char *strcasestr(const char *, const char *) __pure;
#endif
-char *strcat(char * __restrict, const char * __restrict);
+char *(strcat)(char * __restrict, const char * __restrict);
char *strchr(const char *, int) __pure;
#if __BSD_VISIBLE
char *strchrnul(const char*, int) __pure;
@@ -82,7 +89,7 @@ int strverscmp(const char *, const char *) __pure;
#endif
int strcmp(const char *, const char *) __pure;
int strcoll(const char *, const char *);
-char *strcpy(char * __restrict, const char * __restrict);
+char *(strcpy)(char * __restrict, const char * __restrict);
size_t strcspn(const char *, const char *) __pure;
#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
char *strdup(const char *) __malloc_like;
@@ -92,8 +99,8 @@ char *strerror(int);
int strerror_r(int, char *, size_t);
#endif
#if __BSD_VISIBLE
-size_t strlcat(char * __restrict, const char * __restrict, size_t);
-size_t strlcpy(char * __restrict, const char * __restrict, size_t);
+size_t (strlcat)(char * __restrict, const char * __restrict, size_t);
+size_t (strlcpy)(char * __restrict, const char * __restrict, size_t);
#endif
size_t strlen(const char *) __pure;
#if __BSD_VISIBLE
@@ -105,9 +112,9 @@ typedef __mode_t mode_t;
void strmode(mode_t, char *);
#endif
-char *strncat(char * __restrict, const char * __restrict, size_t);
+char *(strncat)(char * __restrict, const char * __restrict, size_t);
int strncmp(const char *, const char *, size_t) __pure;
-char *strncpy(char * __restrict, const char * __restrict, size_t);
+char *(strncpy)(char * __restrict, const char * __restrict, size_t);
#if __POSIX_VISIBLE >= 200809
char *strndup(const char *, size_t) __malloc_like;
size_t strnlen(const char *, size_t) __pure;
diff --git a/include/strings.h b/include/strings.h
index fde007186e04..889f43bd2311 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -37,11 +37,15 @@ typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#include <ssp/strings.h>
+#endif
+
__BEGIN_DECLS
#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112
int bcmp(const void *, const void *, size_t) __pure; /* LEGACY */
-void bcopy(const void *, void *, size_t); /* LEGACY */
-void bzero(void *, size_t); /* LEGACY */
+void (bcopy)(const void *, void *, size_t); /* LEGACY */
+void (bzero)(void *, size_t); /* LEGACY */
#endif
#if __BSD_VISIBLE
void explicit_bzero(void *, size_t);
diff --git a/include/sysexits.h b/include/sysexits.h
index f7247cc80080..3b24e131c647 100644
--- a/include/sysexits.h
+++ b/include/sysexits.h
@@ -35,9 +35,10 @@
/*
* SYSEXITS.H -- Exit status codes for system programs.
*
- * This include file attempts to categorize possible error
- * exit statuses for system programs, notably delivermail
- * and the Berkeley network.
+ * This include file attempts to categorize error exit statuses
+ * for system programs, notably sendmail. These values exist only
+ * for interface compatibility, and are deprecated for FreeBSD
+ * base software.
*
* Error numbers begin at EX__BASE to reduce the possibility of
* clashing with other exit statuses that random programs may
diff --git a/include/unistd.h b/include/unistd.h
index e4e5c62fbb67..48155bb2971b 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -37,6 +37,10 @@
#include <sys/_null.h>
#include <sys/_types.h>
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#include <ssp/unistd.h>
+#endif
+
#ifndef _GID_T_DECLARED
typedef __gid_t gid_t;
#define _GID_T_DECLARED
diff --git a/include/wchar.h b/include/wchar.h
index 2f23feec8792..e4b037c9b16f 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -109,6 +109,14 @@ typedef struct __sFILE FILE;
struct tm;
__BEGIN_DECLS
+size_t wcslen(const wchar_t *) __pure;
+__END_DECLS
+
+#if !defined(_STANDALONE) && defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
+#include <ssp/wchar.h>
+#endif
+
+__BEGIN_DECLS
wint_t btowc(int);
wint_t fgetwc(FILE *);
wchar_t *
@@ -146,7 +154,6 @@ wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict);
size_t wcscspn(const wchar_t *, const wchar_t *) __pure;
size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict,
const struct tm * __restrict);
-size_t wcslen(const wchar_t *) __pure;
wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict,
size_t);
int wcsncmp(const wchar_t *, const wchar_t *, size_t) __pure;
diff --git a/include/xlocale.h b/include/xlocale.h
index f39000d6b373..cc2fc0839593 100644
--- a/include/xlocale.h
+++ b/include/xlocale.h
@@ -2,7 +2,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011, 2012 The FreeBSD Foundation
- * All rights reserved.
*
* This software was developed by David Chisnall under sponsorship from
* the FreeBSD Foundation.
diff --git a/include/xlocale/Makefile b/include/xlocale/Makefile
index d862483ef4eb..fc2569c36502 100644
--- a/include/xlocale/Makefile
+++ b/include/xlocale/Makefile
@@ -1,4 +1,3 @@
-
INCS= _ctype.h _inttypes.h _langinfo.h _locale.h _monetary.h _stdio.h\
_stdlib.h _string.h _strings.h _time.h _uchar.h _wchar.h
INCSDIR=${INCLUDEDIR}/xlocale