aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/Makefile.inc5
-rw-r--r--lib/libc/gen/Symbol.map2
-rw-r--r--lib/libc/gen/dlopen.314
-rw-r--r--lib/libc/gen/memfd_create.c23
-rw-r--r--lib/libc/gen/pause.32
-rw-r--r--lib/libc/gen/posix_spawn.312
-rw-r--r--lib/libc/gen/posix_spawn.c5
-rw-r--r--lib/libc/gen/posix_spawn_file_actions_addopen.329
-rw-r--r--lib/libc/gen/sysctl.327
-rw-r--r--lib/libc/tests/string/Makefile2
-rw-r--r--lib/libc/tests/string/strrchr_test.c156
11 files changed, 240 insertions, 37 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 28e55f58ccf3..c31f789fd1d1 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -468,8 +468,8 @@ MLINKS+=posix_spawn.3 posix_spawnp.3 \
posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addclose.3 \
posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addclosefrom_np.3 \
posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_adddup2.3 \
- posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addchdir_np.3 \
- posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addfchdir_np.3 \
+ posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addchdir.3 \
+ posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addfchdir.3 \
posix_spawn_file_actions_init.3 posix_spawn_file_actions_destroy.3 \
posix_spawnattr_getflags.3 posix_spawnattr_setflags.3 \
posix_spawnattr_getexecfd_np.3 posix_spawnattr_setexecfd_np.3 \
@@ -562,6 +562,7 @@ MLINKS+=unvis.3 strunvis.3 \
unvis.3 strunvisx.3
MLINKS+=vis.3 nvis.3 \
vis.3 snvis.3 \
+ vis.3 stravis.3 \
vis.3 strenvisx.3 \
vis.3 strnunvis.3 \
vis.3 strnunvisx.3 \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index ddbd0522e13f..60f34b3a1923 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -475,6 +475,8 @@ FBSD_1.8 {
};
FBSD_1.9 {
+ posix_spawn_file_actions_addchdir;
+ posix_spawn_file_actions_addfchdir;
posix_spawnattr_getexecfd_np;
posix_spawnattr_getprocdescp_np;
posix_spawnattr_setexecfd_np;
diff --git a/lib/libc/gen/dlopen.3 b/lib/libc/gen/dlopen.3
index 340545114114..2f10c17a4f53 100644
--- a/lib/libc/gen/dlopen.3
+++ b/lib/libc/gen/dlopen.3
@@ -164,6 +164,20 @@ Symbols from the loaded library are put before global symbols when
resolving symbolic references originated from the library.
.El
.Pp
+A special syntax for the
+.Fa path
+is supported, in the form of
+.Dl #number/name .
+The
+.Ql number
+should be a decimal number, which references an open file descriptor,
+and which must be also listed in the environment variable
+.Ev LD_LIBRARY_PATH_FDS .
+In this case, the linker tries to load an object that can be opened by
+.Ql openat(number, path, O_RDONLY) .
+This feature is only available to trusted processes, i.e.,
+the activated image must be not set-uid or set-gid.
+.Pp
If
.Fn dlopen
fails, it returns a null pointer, and sets an error condition which may
diff --git a/lib/libc/gen/memfd_create.c b/lib/libc/gen/memfd_create.c
index 78131f46d7b1..8e6c93be4337 100644
--- a/lib/libc/gen/memfd_create.c
+++ b/lib/libc/gen/memfd_create.c
@@ -95,16 +95,25 @@ memfd_create(const char *name, unsigned int flags)
npgs = getpagesizes(pgs, nitems(pgs));
if (npgs == -1)
goto clean;
- pgsize = (size_t)1 << ((flags & MFD_HUGE_MASK) >> MFD_HUGE_SHIFT);
- for (pgidx = 0; pgidx < npgs; pgidx++) {
- if (pgsize == pgs[pgidx])
- break;
- }
- if (pgidx == npgs) {
- errno = EOPNOTSUPP;
+ else if (npgs == 1) {
+ errno = ENOSYS;
goto clean;
}
+ if ((flags & MFD_HUGE_MASK) == 0) {
+ pgidx = 1;
+ } else {
+ pgsize = 1UL << ((flags & MFD_HUGE_MASK) >> MFD_HUGE_SHIFT);
+ for (pgidx = 1; pgidx < npgs; pgidx++) {
+ if (pgsize == pgs[pgidx])
+ break;
+ }
+ if (pgidx == npgs) {
+ errno = EOPNOTSUPP;
+ goto clean;
+ }
+ }
+
memset(&slc, 0, sizeof(slc));
slc.psind = pgidx;
slc.alloc_policy = SHM_LARGEPAGE_ALLOC_DEFAULT;
diff --git a/lib/libc/gen/pause.3 b/lib/libc/gen/pause.3
index 6b17ae10777d..85257071ce2f 100644
--- a/lib/libc/gen/pause.3
+++ b/lib/libc/gen/pause.3
@@ -77,7 +77,7 @@ A
system call first appeared in the Programmer's Workbench (PWB/UNIX)
and was then ported to
.At v7 .
-It was reimplemeted as a wrapper around the
+It was reimplemented as a wrapper around the
.Fn sigpause
and
.Fn sigblock
diff --git a/lib/libc/gen/posix_spawn.3 b/lib/libc/gen/posix_spawn.3
index f7489890db31..ad66d1a426c4 100644
--- a/lib/libc/gen/posix_spawn.3
+++ b/lib/libc/gen/posix_spawn.3
@@ -446,11 +446,11 @@ action.
.Xr sched_setscheduler 2 ,
.Xr setpgid 2 ,
.Xr vfork 2 ,
-.Xr posix_spawn_file_actions_addchdir_np 3 ,
+.Xr posix_spawn_file_actions_addchdir 3 ,
.Xr posix_spawn_file_actions_addclose 3 ,
.Xr posix_spawn_file_actions_addclosefrom_np 3 ,
.Xr posix_spawn_file_actions_adddup2 3 ,
-.Xr posix_spawn_file_actions_addfchdir_np 3 ,
+.Xr posix_spawn_file_actions_addfchdir 3 ,
.Xr posix_spawn_file_actions_addopen 3 ,
.Xr posix_spawn_file_actions_destroy 3 ,
.Xr posix_spawn_file_actions_init 3 ,
@@ -467,7 +467,7 @@ action.
.Xr posix_spawnattr_setexecfd_np 3 ,
.Xr posix_spawnattr_setflags 3 ,
.Xr posix_spawnattr_setpgroup 3 ,
-.Xr posix_spawnattr_setprocdescp_np 3,
+.Xr posix_spawnattr_setprocdescp_np 3 ,
.Xr posix_spawnattr_setschedparam 3 ,
.Xr posix_spawnattr_setschedpolicy 3 ,
.Xr posix_spawnattr_setsigdefault 3 ,
@@ -481,8 +481,10 @@ functions conform to
.St -p1003.1-2001 ,
except that they ignore all errors from
.Fn close .
-A future update of the Standard is expected to require that these functions
-not fail because a file descriptor to be closed (via
+The
+.St -p1003.1-2024 ,
+version of the Standard no longer requires that these functions
+fail because a file descriptor to be closed (via
.Fn posix_spawn_file_actions_addclose )
is not open.
.Sh HISTORY
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
index 656c0f20f798..11cdb5a29d03 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -549,6 +549,8 @@ posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *
STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list);
return (0);
}
+__weak_reference(posix_spawn_file_actions_addchdir_np,
+ posix_spawn_file_actions_addchdir);
int
posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *__restrict fa,
@@ -571,6 +573,9 @@ posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *__restrict fa,
return (0);
}
+__weak_reference(posix_spawn_file_actions_addfchdir_np,
+ posix_spawn_file_actions_addfchdir);
+
int
posix_spawn_file_actions_addclosefrom_np (posix_spawn_file_actions_t *
__restrict fa, int from)
diff --git a/lib/libc/gen/posix_spawn_file_actions_addopen.3 b/lib/libc/gen/posix_spawn_file_actions_addopen.3
index 80bc91454471..1d0eac45f872 100644
--- a/lib/libc/gen/posix_spawn_file_actions_addopen.3
+++ b/lib/libc/gen/posix_spawn_file_actions_addopen.3
@@ -40,8 +40,8 @@
.Nm posix_spawn_file_actions_adddup2 ,
.Nm posix_spawn_file_actions_addclose ,
.Nm posix_spawn_file_actions_addclosefrom_np ,
-.Nm posix_spawn_file_actions_addchdir_np ,
-.Nm posix_spawn_file_actions_addfchdir_np
+.Nm posix_spawn_file_actions_addchdir ,
+.Nm posix_spawn_file_actions_addfchdir
.Nd "add open, dup2, close, closefrom, or chdir/fchdir actions to spawn file actions object"
.Sh LIBRARY
.Lb libc
@@ -72,12 +72,12 @@
.Fa "int from"
.Fc
.Ft int
-.Fo posix_spawn_file_actions_addchdir_np
+.Fo posix_spawn_file_actions_addchdir
.Fa "posix_spawn_file_actions_t *restrict file_actions"
.Fa "const char *restrict path"
.Fc
.Ft int
-.Fo posix_spawn_file_actions_addfchdir_np
+.Fo posix_spawn_file_actions_addfchdir
.Fa "posix_spawn_file_actions_t * file_actions"
.Fa "int fildes"
.Fc
@@ -189,9 +189,9 @@ For each open file descriptor, logically the close action is performed,
and any possible errors encountered are ignored.
.Pp
The
-.Fn posix_spawn_file_actions_addchdir_np
+.Fn posix_spawn_file_actions_addchdir
and
-.Fn posix_spawn_file_actions_addfchdir_np
+.Fn posix_spawn_file_actions_addfchdir
functions add a change current directory action to the object
referenced by
.Fa file_actions
@@ -201,11 +201,11 @@ in the order of insertion into the
object.
It also sets the working directory for the spawned program.
The
-.Fn posix_spawn_file_actions_addchdir_np
+.Fn posix_spawn_file_actions_addchdir
function takes the
.Fa path
to set as the working directory, while
-.Fn posix_spawn_file_actions_addfchdir_np
+.Fn posix_spawn_file_actions_addfchdir
takes the directory file descriptor.
.Sh RETURN VALUES
Upon successful completion, these functions return zero;
@@ -250,11 +250,8 @@ is equal to
A future update of the Standard is expected to require this behavior.
.Pp
The
-.Fn posix_spawn_file_actions_addchdir_np ,
-.Fn posix_spawn_file_actions_addfchdir_np ,
-and
.Fn posix_spawn_file_actions_addclosefrom_np
-functions are non-standard functions implemented after the similar
+function is non-standard and implemented after the similar
functionality provided by glibc.
.Sh HISTORY
The
@@ -271,5 +268,13 @@ and
.Fn posix_spawn_file_actions_addclosefrom_np
functions first appeared in
.Fx 13.1 .
+In
+.Fx 16.0 ,
+the
+.Fn posix_spawn_file_actions_addchdir ,
+.Fn posix_spawn_file_actions_addfchdir
+aliases where added to the corresponding functions with the
+.Ql _np
+suffix.
.Sh AUTHORS
.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3
index ef897c653728..75fd6307bd30 100644
--- a/lib/libc/gen/sysctl.3
+++ b/lib/libc/gen/sysctl.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 31, 2025
+.Dd April 15, 2026
.Dt SYSCTL 3
.Os
.Sh NAME
@@ -325,7 +325,7 @@ information.
.Bl -column "KERNXMAXFILESPERPROCXXX" "struct clockrateXXX" -offset indent
.It Sy Second Level Name Ta Sy Type Ta Sy Changeable
.It Dv KERN_ARGMAX Ta integer Ta no
-.It Dv KERN_ARND Ta integer Ta no
+.It Dv KERN_ARND Ta byte buffer Ta no
.It Dv KERN_BOOTFILE Ta string Ta yes
.It Dv KERN_BOOTTIME Ta struct timeval Ta no
.It Dv KERN_CLOCKRATE Ta struct clockinfo Ta no
@@ -333,7 +333,7 @@ information.
.It Dv KERN_HOSTID Ta integer Ta yes
.It Dv KERN_HOSTUUID Ta string Ta yes
.It Dv KERN_HOSTNAME Ta string Ta yes
-.It Dv KERN_IOV_MAX Ta integer Ta yes
+.It Dv KERN_IOV_MAX Ta integer Ta no
.It Dv KERN_JOB_CONTROL Ta integer Ta no
.It Dv KERN_LOCKF Ta struct kinfo_lockf Ta no
.It Dv KERN_LOGSIGEXIT Ta integer Ta yes
@@ -457,7 +457,7 @@ the currently installed userland.
.It Li KERN_OSRELEASE
The system release string.
.It Li KERN_OSREV
-The system revision string.
+The system revision number.
.It Li KERN_OSTYPE
The system type string.
.It Li KERN_POSIX1
@@ -501,14 +501,14 @@ specifies the current process.
.It Dv KERN_PROC_GROUPS Ta "gid_t []"
.It Dv KERN_PROC_ENV Ta "Set of strings"
.It Dv KERN_PROC_AUXV Ta "Elf_Auxinfo []"
-.It Dv KERN_PROC_RLIMIT Ta "Integer"
-.It Dv KERN_PROC_PS_STRINGS Ta "Integer"
+.It Dv KERN_PROC_RLIMIT Ta "struct rlimit"
+.It Dv KERN_PROC_PS_STRINGS Ta "Pointer to struct ps_strings"
.It Dv KERN_PROC_UMASK Ta "Integer/short"
.It Dv KERN_PROC_OSREL Ta "Integer"
-.It Dv KERN_PROC_SIGTRAMP Ta "Integer"
-.It Dv KERN_PROC_CWD Ta "String"
+.It Dv KERN_PROC_SIGTRAMP Ta "struct kinfo_sigtramp"
+.It Dv KERN_PROC_CWD Ta "struct kinfo_file"
.It Dv KERN_PROC_NFDS Ta "Integer"
-.It Dv KERN_PROC_SIGFASTBLK Ta "Integer"
+.It Dv KERN_PROC_SIGFASTBLK Ta "Address"
.It Dv KERN_PROC_VM_LAYOUT Ta "struct kinfo_vm_layout"
.It Dv KERN_PROC_RLIMIT_USAGE Ta "rlim_t []"
.It Dv KERN_PROC_KQUEUE Ta "struct kinfo_knote []"
@@ -570,7 +570,8 @@ Read from the note of the elf executable at
time.
Might be modified by the process.
.It Dv KERN_PROC_SIGTRAMP
-Address of the signal trampoline in the process address space,
+Structure describing the address range of the signal trampoline in the
+process address space,
where, simplifying, the kernel passes control for signal delivery.
.It Dv KERN_PROC_CWD
Returns the current working directory for the process.
@@ -586,6 +587,12 @@ Fills a structure describing process virtual address space layout.
Like
.Dv KERN_PROC_RLIMIT ,
but instead of the limit, returns the accounted resource usage.
+If the MIB is of the form
+.Li kern.proc.rlimit_usage\&. Ns Va pid ,
+usage values for all resources are returned.
+If the MIB is of the form
+.Li kern.proc.rlimit_usage\&. Ns Va pid Ns \&. Ns Va resource ,
+the usage value for the specified resource is returned.
For resources which do not have a meaningful current value,
.Li \-1
is returned.
diff --git a/lib/libc/tests/string/Makefile b/lib/libc/tests/string/Makefile
index a019939c30af..a4d23b2dcfe1 100644
--- a/lib/libc/tests/string/Makefile
+++ b/lib/libc/tests/string/Makefile
@@ -20,6 +20,7 @@ ATF_TESTS_C+= strcmp2_test
ATF_TESTS_C+= strcspn_test
ATF_TESTS_C+= strerror2_test
ATF_TESTS_C+= strlcpy_test
+ATF_TESTS_C+= strrchr2_test
ATF_TESTS_C+= strspn_test
ATF_TESTS_C+= strverscmp_test
ATF_TESTS_C+= strxfrm_test
@@ -49,6 +50,7 @@ NETBSD_ATF_TESTS_C+= swab_test
SRCS.memset2_test= memset_test.c
SRCS.strcmp2_test= strcmp_test.c
SRCS.strerror2_test= strerror_test.c
+SRCS.strrchr2_test= strrchr_test.c
.include "../Makefile.netbsd-tests"
diff --git a/lib/libc/tests/string/strrchr_test.c b/lib/libc/tests/string/strrchr_test.c
new file mode 100644
index 000000000000..1c3d912ec3f8
--- /dev/null
+++ b/lib/libc/tests/string/strrchr_test.c
@@ -0,0 +1,156 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023, 2026 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * Adapted from memrchr_test.c.
+ */
+
+#include <sys/cdefs.h>
+
+#include <dlfcn.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static char *(*strrchr_fn)(const char *, int);
+
+/*
+ * Check that when looking for the character NUL, we find the
+ * string terminator, and not some NUL character after it.
+ */
+ATF_TC_WITHOUT_HEAD(nul);
+ATF_TC_BODY(nul, tc)
+{
+ size_t i, j, k;
+ char buf[1+15+64]; /* offset [0+15] + 64 buffer bytes + sentinels */
+
+ buf[0] = '\0';
+ memset(buf + 1, '-', sizeof(buf) - 1);
+
+ for (i = 0; i < 16; i++)
+ for (j = 0; j < 64; j++)
+ for (k = j; k < 64; k++) {
+ buf[i + j + 1] = '\0';
+ buf[i + k + 1] = '\0';
+ ATF_CHECK_EQ(strrchr_fn(buf + i + 1, '\0'), buf + i + j + 1);
+ buf[i + j + 1] = '-';
+ buf[i + k + 1] = '-';
+ }
+}
+
+/*
+ * Check that if the character 'X' does not occur in the string
+ * (but occurs before and after it), we correctly return NULL.
+ */
+ATF_TC_WITHOUT_HEAD(not_found);
+ATF_TC_BODY(not_found, tc)
+{
+ size_t i, j;
+ char buf[1+15+64+2]; /* offset [0..15] + 64 buffer bytes + sentinels */
+
+ buf[0] = 'X';
+ memset(buf + 1, '-', sizeof(buf) - 1);
+
+ for (i = 0; i < 16; i++)
+ for (j = 0; j < 64; j++) {
+ buf[i + j + 1] = '\0';
+ buf[i + j + 2] = 'X';
+ ATF_CHECK_EQ(strrchr_fn(buf + i + 1, 'X'), NULL);
+ buf[i + j + 1] = '-';
+ buf[i + j + 2] = '-';
+ }
+}
+
+static void
+do_found_test(char buf[], size_t first, size_t second)
+{
+ /* invariant: first <= second */
+
+ buf[first] = 'X';
+ buf[second] = 'X';
+ ATF_CHECK_EQ(strrchr_fn(buf, 'X'), buf + second);
+ buf[first] = '-';
+ buf[second] = '-';
+}
+
+/*
+ * Check that if the character 'X' occurs in the string multiple
+ * times (i. e. twice), its last encounter is returned.
+ */
+ATF_TC_WITHOUT_HEAD(found);
+ATF_TC_BODY(found, tc)
+{
+ size_t i, j, k, l;
+ char buf[1+15+64+2];
+
+ buf[0] = 'X';
+ memset(buf + 1, '-', sizeof(buf) - 1);
+
+ for (i = 0; i < 16; i++)
+ for (j = 0; j < 64; j++)
+ for (k = 0; k < j; k++)
+ for (l = 0; l <= k; l++) {
+ buf[i + j + 1] = '\0';
+ buf[i + j + 2] = 'X';
+ do_found_test(buf + i + 1, l, k);
+ buf[i + j + 1] = '-';
+ buf[i + j + 2] = '-';
+ }
+}
+
+static void
+do_values_test(char buf[], size_t len, size_t i, int c)
+{
+ /* sentinels */
+ buf[-1] = c;
+ buf[len] = '\0';
+ buf[len + 1] = 'c';
+
+ /* fill the string with some other character, but not with NUL */
+ memset(buf, c == UCHAR_MAX ? c - 1 : c + 1, len);
+
+ if (i < len) {
+ buf[i] = c;
+ ATF_CHECK_EQ(strrchr_fn(buf, c), buf + i);
+ } else
+ ATF_CHECK_EQ(strrchr_fn(buf, c), c == 0 ? buf + len : NULL);
+}
+
+/*
+ * Check that the character is found regardless of its value.
+ * This catches arithmetic (overflow) errors in incorrect SWAR
+ * implementations of byte-parallel character matching.
+ */
+ATF_TC_WITHOUT_HEAD(values);
+ATF_TC_BODY(values, tc)
+{
+ size_t i, j, k;
+ int c;
+ char buf[1+15+64+2];
+
+ for (i = 0; i < 16; i++)
+ for (j = 0; j < 64; j++)
+ for (k = 0; k <= j; k++)
+ for (c = 0; c <= UCHAR_MAX; c++)
+ do_values_test(buf + i + 1, j, k, c);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ void *dl_handle;
+
+ dl_handle = dlopen(NULL, RTLD_LAZY);
+ strrchr_fn = dlsym(dl_handle, "test_strrchr");
+ if (strrchr_fn == NULL)
+ strrchr_fn = strrchr;
+
+ ATF_TP_ADD_TC(tp, nul);
+ ATF_TP_ADD_TC(tp, not_found);
+ ATF_TP_ADD_TC(tp, found);
+ ATF_TP_ADD_TC(tp, values);
+
+ return (atf_no_error());
+}