aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/Makefile.inc74
-rw-r--r--lib/libc/gen/Symbol.map57
-rw-r--r--lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c3
-rw-r--r--lib/libc/gen/__xuname.c5
-rw-r--r--lib/libc/gen/_once_stub.c5
-rw-r--r--lib/libc/gen/_pthread_stubs.c34
-rw-r--r--lib/libc/gen/_rand48.c37
-rw-r--r--lib/libc/gen/_spinlock_stub.c3
-rw-r--r--lib/libc/gen/_thread_init.c5
-rw-r--r--lib/libc/gen/aio_read2.c (renamed from lib/libc/gen/errno.c)38
-rw-r--r--lib/libc/gen/aio_write2.c (renamed from lib/libc/gen/__getosreldate.c)64
-rw-r--r--lib/libc/gen/alarm.35
-rw-r--r--lib/libc/gen/alarm.c4
-rw-r--r--lib/libc/gen/arc4random-compat.c7
-rw-r--r--lib/libc/gen/arc4random.325
-rw-r--r--lib/libc/gen/arc4random.c6
-rw-r--r--lib/libc/gen/arc4random.h2
-rw-r--r--lib/libc/gen/arc4random_uniform.c73
-rw-r--r--lib/libc/gen/assert.c4
-rw-r--r--lib/libc/gen/auxv.3103
-rw-r--r--lib/libc/gen/auxv.c378
-rw-r--r--lib/libc/gen/basename.32
-rw-r--r--lib/libc/gen/basename.c3
-rw-r--r--lib/libc/gen/basename_compat.c3
-rw-r--r--lib/libc/gen/cap_rights_get.32
-rw-r--r--lib/libc/gen/cap_sandboxed.32
-rw-r--r--lib/libc/gen/cap_sandboxed.c5
-rw-r--r--lib/libc/gen/check_utility_compat.32
-rw-r--r--lib/libc/gen/check_utility_compat.c3
-rw-r--r--lib/libc/gen/clock.33
-rw-r--r--lib/libc/gen/clock.c4
-rw-r--r--lib/libc/gen/clock_getcpuclockid.32
-rw-r--r--lib/libc/gen/clock_getcpuclockid.c5
-rw-r--r--lib/libc/gen/closedir.c4
-rw-r--r--lib/libc/gen/confstr.33
-rw-r--r--lib/libc/gen/confstr.c4
-rw-r--r--lib/libc/gen/crypt.c4
-rw-r--r--lib/libc/gen/ctermid.33
-rw-r--r--lib/libc/gen/ctermid.c10
-rw-r--r--lib/libc/gen/daemon.315
-rw-r--r--lib/libc/gen/daemon.c4
-rw-r--r--lib/libc/gen/devname-compat11.c3
-rw-r--r--lib/libc/gen/devname.33
-rw-r--r--lib/libc/gen/devname.c6
-rw-r--r--lib/libc/gen/directory.33
-rw-r--r--lib/libc/gen/dirfd.c7
-rw-r--r--lib/libc/gen/dirname.32
-rw-r--r--lib/libc/gen/dirname.c3
-rw-r--r--lib/libc/gen/dirname_compat.c3
-rw-r--r--lib/libc/gen/disklabel.c4
-rw-r--r--lib/libc/gen/dl_iterate_phdr.31
-rw-r--r--lib/libc/gen/dladdr.32
-rw-r--r--lib/libc/gen/dlfcn.c101
-rw-r--r--lib/libc/gen/dlinfo.32
-rw-r--r--lib/libc/gen/dllockinit.32
-rw-r--r--lib/libc/gen/dlopen.317
-rw-r--r--lib/libc/gen/drand48.c9
-rw-r--r--lib/libc/gen/dup3.317
-rw-r--r--lib/libc/gen/dup3.c14
-rw-r--r--lib/libc/gen/elf_utils.c60
-rw-r--r--lib/libc/gen/erand48.c12
-rw-r--r--lib/libc/gen/err.33
-rw-r--r--lib/libc/gen/err.c55
-rw-r--r--lib/libc/gen/errlst.c4
-rw-r--r--lib/libc/gen/eventfd.c5
-rw-r--r--lib/libc/gen/exec.328
-rw-r--r--lib/libc/gen/exec.c239
-rw-r--r--lib/libc/gen/exect.c3
-rw-r--r--lib/libc/gen/fdevname.c5
-rw-r--r--lib/libc/gen/fdopendir.c (renamed from lib/libc/gen/wait.c)43
-rw-r--r--lib/libc/gen/feature_present.32
-rw-r--r--lib/libc/gen/feature_present.c3
-rw-r--r--lib/libc/gen/fmtcheck.32
-rw-r--r--lib/libc/gen/fmtcheck.c5
-rw-r--r--lib/libc/gen/fmtmsg.32
-rw-r--r--lib/libc/gen/fmtmsg.c5
-rw-r--r--lib/libc/gen/fnmatch.311
-rw-r--r--lib/libc/gen/fnmatch.c231
-rw-r--r--lib/libc/gen/fpclassify.32
-rw-r--r--lib/libc/gen/fpclassify.c4
-rw-r--r--lib/libc/gen/frexp.33
-rw-r--r--lib/libc/gen/frexp.c4
-rw-r--r--lib/libc/gen/fstab.c12
-rw-r--r--lib/libc/gen/ftok.35
-rw-r--r--lib/libc/gen/ftok.c5
-rw-r--r--lib/libc/gen/fts-compat.c7
-rw-r--r--lib/libc/gen/fts-compat.h3
-rw-r--r--lib/libc/gen/fts-compat11.c7
-rw-r--r--lib/libc/gen/fts-compat11.h3
-rw-r--r--lib/libc/gen/fts.3280
-rw-r--r--lib/libc/gen/fts.c303
-rw-r--r--lib/libc/gen/ftw-compat11.c3
-rw-r--r--lib/libc/gen/ftw.32
-rw-r--r--lib/libc/gen/ftw.c3
-rw-r--r--lib/libc/gen/gen-compat.h50
-rw-r--r--lib/libc/gen/gen-private.h6
-rw-r--r--lib/libc/gen/getbootfile.33
-rw-r--r--lib/libc/gen/getbootfile.c5
-rw-r--r--lib/libc/gen/getbsize.33
-rw-r--r--lib/libc/gen/getbsize.c4
-rw-r--r--lib/libc/gen/getcap.33
-rw-r--r--lib/libc/gen/getcap.c4
-rw-r--r--lib/libc/gen/getcontext.32
-rw-r--r--lib/libc/gen/getcwd.33
-rw-r--r--lib/libc/gen/getcwd.c7
-rw-r--r--lib/libc/gen/getdiskbyname.33
-rw-r--r--lib/libc/gen/getdomainname.33
-rw-r--r--lib/libc/gen/getdomainname.c7
-rw-r--r--lib/libc/gen/getentropy.314
-rw-r--r--lib/libc/gen/getentropy.c111
-rw-r--r--lib/libc/gen/getfsent.33
-rw-r--r--lib/libc/gen/getgrent.33
-rw-r--r--lib/libc/gen/getgrent.c5
-rw-r--r--lib/libc/gen/getgrouplist.353
-rw-r--r--lib/libc/gen/getgrouplist.c13
-rw-r--r--lib/libc/gen/gethostname.33
-rw-r--r--lib/libc/gen/gethostname.c7
-rw-r--r--lib/libc/gen/getloadavg.33
-rw-r--r--lib/libc/gen/getloadavg.c4
-rw-r--r--lib/libc/gen/getlogin.c7
-rw-r--r--lib/libc/gen/getmntinfo-compat11.c5
-rw-r--r--lib/libc/gen/getmntinfo.33
-rw-r--r--lib/libc/gen/getmntinfo.c4
-rw-r--r--lib/libc/gen/getnetgrent.33
-rw-r--r--lib/libc/gen/getnetgrent.c4
-rw-r--r--lib/libc/gen/getosreldate.32
-rw-r--r--lib/libc/gen/getosreldate.c4
-rw-r--r--lib/libc/gen/getpagesize.369
-rw-r--r--lib/libc/gen/getpagesize.c75
-rw-r--r--lib/libc/gen/getpagesizes.399
-rw-r--r--lib/libc/gen/getpagesizes.c87
-rw-r--r--lib/libc/gen/getpass.33
-rw-r--r--lib/libc/gen/getpeereid.37
-rw-r--r--lib/libc/gen/getpeereid.c5
-rw-r--r--lib/libc/gen/getprogname.32
-rw-r--r--lib/libc/gen/getprogname.c3
-rw-r--r--lib/libc/gen/getpwent.36
-rw-r--r--lib/libc/gen/getpwent.c5
-rw-r--r--lib/libc/gen/getttyent.33
-rw-r--r--lib/libc/gen/getttyent.c4
-rw-r--r--lib/libc/gen/getusershell.33
-rw-r--r--lib/libc/gen/getusershell.c2
-rw-r--r--lib/libc/gen/getutxent.32
-rw-r--r--lib/libc/gen/getutxent.c5
-rw-r--r--lib/libc/gen/getvfsbyname.36
-rw-r--r--lib/libc/gen/getvfsbyname.c6
-rw-r--r--lib/libc/gen/glob-compat11.c8
-rw-r--r--lib/libc/gen/glob-compat11.h5
-rw-r--r--lib/libc/gen/glob.369
-rw-r--r--lib/libc/gen/glob.c82
-rw-r--r--lib/libc/gen/initgroups.3108
-rw-r--r--lib/libc/gen/initgroups.c57
-rw-r--r--lib/libc/gen/inotify.c48
-rw-r--r--lib/libc/gen/isatty.c4
-rw-r--r--lib/libc/gen/isgreater.32
-rw-r--r--lib/libc/gen/isinf.c4
-rw-r--r--lib/libc/gen/isnan.c4
-rw-r--r--lib/libc/gen/jrand48.c10
-rw-r--r--lib/libc/gen/kqueue1.c (renamed from lib/libc/gen/sched_getcpu_gen.c)26
-rw-r--r--lib/libc/gen/lcong48.c15
-rw-r--r--lib/libc/gen/ldexp.33
-rw-r--r--lib/libc/gen/ldexp.c3
-rw-r--r--lib/libc/gen/libc_dlopen.c7
-rw-r--r--lib/libc/gen/libc_interposing_table.c (renamed from lib/libc/gen/sendmmsg.c)55
-rw-r--r--lib/libc/gen/lockf.3266
-rw-r--r--lib/libc/gen/lockf.c86
-rw-r--r--lib/libc/gen/lrand48.c9
-rw-r--r--lib/libc/gen/makecontext.33
-rw-r--r--lib/libc/gen/memalign.c12
-rw-r--r--lib/libc/gen/memfd_create.c121
-rw-r--r--lib/libc/gen/modf.33
-rw-r--r--lib/libc/gen/modf.c4
-rw-r--r--lib/libc/gen/mrand48.c11
-rw-r--r--lib/libc/gen/nftw-compat11.c3
-rw-r--r--lib/libc/gen/nftw.c3
-rw-r--r--lib/libc/gen/nice.33
-rw-r--r--lib/libc/gen/nice.c4
-rw-r--r--lib/libc/gen/nlist.33
-rw-r--r--lib/libc/gen/nlist.c4
-rw-r--r--lib/libc/gen/nrand48.c9
-rw-r--r--lib/libc/gen/opendir.c323
-rw-r--r--lib/libc/gen/opendir2.c337
-rw-r--r--lib/libc/gen/pause.33
-rw-r--r--lib/libc/gen/pause.c4
-rw-r--r--lib/libc/gen/pmadvise.c3
-rw-r--r--lib/libc/gen/popen.33
-rw-r--r--lib/libc/gen/popen.c8
-rw-r--r--lib/libc/gen/posix_spawn.318
-rw-r--r--lib/libc/gen/posix_spawn.c33
-rw-r--r--lib/libc/gen/posix_spawn_file_actions_addopen.34
-rw-r--r--lib/libc/gen/posix_spawn_file_actions_init.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getflags.312
-rw-r--r--lib/libc/gen/posix_spawnattr_getpgroup.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getschedparam.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getschedpolicy.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getsigdefault.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getsigmask.32
-rw-r--r--lib/libc/gen/posix_spawnattr_init.32
-rw-r--r--lib/libc/gen/psignal.386
-rw-r--r--lib/libc/gen/psignal.c10
-rw-r--r--lib/libc/gen/pututxline.c5
-rw-r--r--lib/libc/gen/pw_scan.c4
-rw-r--r--lib/libc/gen/pw_scan.h3
-rw-r--r--lib/libc/gen/raise.33
-rw-r--r--lib/libc/gen/raise.c4
-rw-r--r--lib/libc/gen/rand48.38
-rw-r--r--lib/libc/gen/rand48.h63
-rw-r--r--lib/libc/gen/readdir-compat11.c5
-rw-r--r--lib/libc/gen/readdir.c17
-rw-r--r--lib/libc/gen/readpassphrase.32
-rw-r--r--lib/libc/gen/readpassphrase.c3
-rw-r--r--lib/libc/gen/recvmmsg.c97
-rw-r--r--lib/libc/gen/rewinddir.c4
-rw-r--r--lib/libc/gen/rfork_thread.387
-rw-r--r--lib/libc/gen/rtld_get_var.3106
-rw-r--r--lib/libc/gen/scandir-compat11.c13
-rw-r--r--lib/libc/gen/scandir.3209
-rw-r--r--lib/libc/gen/scandir.c167
-rw-r--r--lib/libc/gen/scandir_b.c2
-rw-r--r--lib/libc/gen/sched_getaffinity.c15
-rw-r--r--lib/libc/gen/sched_setaffinity.c14
-rw-r--r--lib/libc/gen/seed48.c21
-rw-r--r--lib/libc/gen/seekdir.c4
-rw-r--r--lib/libc/gen/sem.c4
-rw-r--r--lib/libc/gen/sem_destroy.32
-rw-r--r--lib/libc/gen/sem_getvalue.32
-rw-r--r--lib/libc/gen/sem_init.32
-rw-r--r--lib/libc/gen/sem_new.c4
-rw-r--r--lib/libc/gen/sem_open.32
-rw-r--r--lib/libc/gen/sem_post.32
-rw-r--r--lib/libc/gen/sem_timedwait.32
-rw-r--r--lib/libc/gen/sem_wait.32
-rw-r--r--lib/libc/gen/semctl.c5
-rw-r--r--lib/libc/gen/setdomainname.c4
-rw-r--r--lib/libc/gen/sethostname.c4
-rw-r--r--lib/libc/gen/setjmp.33
-rw-r--r--lib/libc/gen/setjmperr.c4
-rw-r--r--lib/libc/gen/setmode.33
-rw-r--r--lib/libc/gen/setmode.c4
-rw-r--r--lib/libc/gen/setproctitle.336
-rw-r--r--lib/libc/gen/setproctitle.c29
-rw-r--r--lib/libc/gen/setprogname.c3
-rw-r--r--lib/libc/gen/sig2str.c113
-rw-r--r--lib/libc/gen/siginterrupt.33
-rw-r--r--lib/libc/gen/siginterrupt.c4
-rw-r--r--lib/libc/gen/siglist.c4
-rw-r--r--lib/libc/gen/signal.33
-rw-r--r--lib/libc/gen/signal.c4
-rw-r--r--lib/libc/gen/sigsetops.33
-rw-r--r--lib/libc/gen/sigsetops.c4
-rw-r--r--lib/libc/gen/sleep.383
-rw-r--r--lib/libc/gen/sleep.c8
-rw-r--r--lib/libc/gen/srand48.c13
-rw-r--r--lib/libc/gen/statvfs.32
-rw-r--r--lib/libc/gen/statvfs.c3
-rw-r--r--lib/libc/gen/stringlist.32
-rw-r--r--lib/libc/gen/stringlist.c2
-rw-r--r--lib/libc/gen/strtofflags.33
-rw-r--r--lib/libc/gen/strtofflags.c4
-rw-r--r--lib/libc/gen/sysconf.39
-rw-r--r--lib/libc/gen/sysconf.c29
-rw-r--r--lib/libc/gen/sysctl.3221
-rw-r--r--lib/libc/gen/sysctl.c4
-rw-r--r--lib/libc/gen/sysctlbyname.c3
-rw-r--r--lib/libc/gen/sysctlnametomib.c5
-rw-r--r--lib/libc/gen/syslog.310
-rw-r--r--lib/libc/gen/syslog.c11
-rw-r--r--lib/libc/gen/tcgetpgrp.36
-rw-r--r--lib/libc/gen/tcgetsid.35
-rw-r--r--lib/libc/gen/tcgetwinsize.32
-rw-r--r--lib/libc/gen/tcsendbreak.33
-rw-r--r--lib/libc/gen/tcsetattr.33
-rw-r--r--lib/libc/gen/tcsetpgrp.36
-rw-r--r--lib/libc/gen/tcsetsid.35
-rw-r--r--lib/libc/gen/telldir.c8
-rw-r--r--lib/libc/gen/telldir.h9
-rw-r--r--lib/libc/gen/termios.c4
-rw-r--r--lib/libc/gen/time.33
-rw-r--r--lib/libc/gen/time.c4
-rw-r--r--lib/libc/gen/times.33
-rw-r--r--lib/libc/gen/times.c7
-rw-r--r--lib/libc/gen/timespec_get.319
-rw-r--r--lib/libc/gen/timespec_get.c6
-rw-r--r--lib/libc/gen/timespec_getres.351
-rw-r--r--lib/libc/gen/timespec_getres.c24
-rw-r--r--lib/libc/gen/timezone.369
-rw-r--r--lib/libc/gen/timezone.c11
-rw-r--r--lib/libc/gen/tls.c107
-rw-r--r--lib/libc/gen/trivial-getcontextx.c3
-rw-r--r--lib/libc/gen/ttyname.33
-rw-r--r--lib/libc/gen/ttyname.c7
-rw-r--r--lib/libc/gen/ttyslot.c2
-rw-r--r--lib/libc/gen/tzset.3338
-rw-r--r--lib/libc/gen/ualarm.35
-rw-r--r--lib/libc/gen/ualarm.c4
-rw-r--r--lib/libc/gen/ucontext.32
-rw-r--r--lib/libc/gen/uexterr_format.c35
-rw-r--r--lib/libc/gen/uexterr_gettext.c43
-rw-r--r--lib/libc/gen/ulimit.32
-rw-r--r--lib/libc/gen/ulimit.c4
-rw-r--r--lib/libc/gen/uname.33
-rw-r--r--lib/libc/gen/uname.c4
-rw-r--r--lib/libc/gen/unvis-compat.c4
-rw-r--r--lib/libc/gen/usleep.380
-rw-r--r--lib/libc/gen/usleep.c7
-rw-r--r--lib/libc/gen/utime.33
-rw-r--r--lib/libc/gen/utime.c4
-rw-r--r--lib/libc/gen/utxdb.c5
-rw-r--r--lib/libc/gen/utxdb.h4
-rw-r--r--lib/libc/gen/valloc.33
-rw-r--r--lib/libc/gen/valloc.c4
-rw-r--r--lib/libc/gen/wait3.c55
-rw-r--r--lib/libc/gen/waitid.c72
-rw-r--r--lib/libc/gen/waitpid.c56
-rw-r--r--lib/libc/gen/wordexp.32
-rw-r--r--lib/libc/gen/wordexp.c16
316 files changed, 3505 insertions, 4379 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 395edefc0503..4d064d18d36e 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,6 +1,3 @@
-# @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
-# $FreeBSD$
-
# machine-independent gen sources
.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen ${SRCTOP}/etc
@@ -8,7 +5,7 @@ CONFS+= group master.passwd shells
CONFSMODE_master.passwd= 600
CONFSPACKAGE= runtime
-SRCS+= __getosreldate.c \
+SRCS+= \
__pthread_mutex_init_calloc_cb_stub.c \
__xuname.c \
_once_stub.c \
@@ -16,12 +13,13 @@ SRCS+= __getosreldate.c \
_rand48.c \
_spinlock_stub.c \
_thread_init.c \
+ aio_read2.c \
+ aio_write2.c \
alarm.c \
arc4random.c \
arc4random-compat.c \
arc4random_uniform.c \
assert.c \
- auxv.c \
basename.c \
basename_compat.c \
cap_sandboxed.c \
@@ -48,11 +46,11 @@ SRCS+= __getosreldate.c \
erand48.c \
err.c \
errlst.c \
- errno.c \
eventfd.c \
exec.c \
exect.c \
fdevname.c \
+ fdopendir.c \
feature_present.c \
fmtcheck.c \
fmtmsg.c \
@@ -81,8 +79,6 @@ SRCS+= __getosreldate.c \
getmntinfo-compat11.c \
getnetgrent.c \
getosreldate.c \
- getpagesize.c \
- getpagesizes.c \
getpeereid.c \
getprogname.c \
getpwent.c \
@@ -93,15 +89,18 @@ SRCS+= __getosreldate.c \
glob.c \
glob-compat11.c \
initgroups.c \
+ inotify.c \
isatty.c \
isinf.c \
isnan.c \
jrand48.c \
+ kqueue1.c \
lcong48.c \
libc_dlopen.c \
- lockf.c \
+ libc_interposing_table.c \
lrand48.c \
memalign.c \
+ memfd_create.c \
mrand48.c \
nftw.c \
nftw-compat11.c \
@@ -109,6 +108,7 @@ SRCS+= __getosreldate.c \
nlist.c \
nrand48.c \
opendir.c \
+ opendir2.c \
pause.c \
pmadvise.c \
popen.c \
@@ -120,7 +120,6 @@ SRCS+= __getosreldate.c \
readdir.c \
readdir-compat11.c \
readpassphrase.c \
- recvmmsg.c \
rewinddir.c \
scandir.c \
scandir_b.c \
@@ -130,13 +129,13 @@ SRCS+= __getosreldate.c \
seed48.c \
seekdir.c \
semctl.c \
- sendmmsg.c \
setdomainname.c \
sethostname.c \
setjmperr.c \
setmode.c \
setproctitle.c \
setprogname.c \
+ sig2str.c \
siginterrupt.c \
siglist.c \
signal.c \
@@ -156,11 +155,14 @@ SRCS+= __getosreldate.c \
time.c \
times.c \
timespec_get.c \
+ timespec_getres.c \
timezone.c \
tls.c \
ttyname.c \
ttyslot.c \
ualarm.c \
+ uexterr_format.c \
+ uexterr_gettext.c \
ulimit.c \
uname.c \
unvis-compat.c \
@@ -168,14 +170,17 @@ SRCS+= __getosreldate.c \
utime.c \
utxdb.c \
valloc.c \
- wait.c \
- wait3.c \
- waitpid.c \
- waitid.c \
wordexp.c
+.if ${COMPILER_FEATURES:Mblocks}
+CFLAGS.fts.c= -fblocks
+CFLAGS.glob.c= -fblocks
+.endif
+
CFLAGS.arc4random.c= -I${SRCTOP}/sys -I${SRCTOP}/sys/crypto/chacha20
+CFLAGS.sysconf.c= -I${SRCTOP}/contrib/tzcode
+
CFLAGS.dlfcn.c= ${RTLD_HDRS}
CFLAGS.tls.c= ${RTLD_HDRS}
@@ -203,7 +208,6 @@ SYM_MAPS+=${LIBC_SRCTOP}/gen/Symbol.map
MAN+= alarm.3 \
arc4random.3 \
- auxv.3 \
basename.3 \
cap_rights_get.3 \
cap_sandboxed.3 \
@@ -249,8 +253,6 @@ MAN+= alarm.3 \
getmntinfo.3 \
getnetgrent.3 \
getosreldate.3 \
- getpagesize.3 \
- getpagesizes.3 \
getpass.3 \
getpeereid.3 \
getprogname.3 \
@@ -263,7 +265,6 @@ MAN+= alarm.3 \
initgroups.3 \
isgreater.3 \
ldexp.3 \
- lockf.3 \
makecontext.3 \
modf.3 \
nice.3 \
@@ -285,7 +286,7 @@ MAN+= alarm.3 \
raise.3 \
rand48.3 \
readpassphrase.3 \
- rfork_thread.3 \
+ rtld_get_var.3 \
scandir.3 \
sem_destroy.3 \
sem_getvalue.3 \
@@ -300,7 +301,6 @@ MAN+= alarm.3 \
siginterrupt.3 \
signal.3 \
sigsetops.3 \
- sleep.3 \
statvfs.3 \
stringlist.3 \
strtofflags.3 \
@@ -317,15 +317,13 @@ MAN+= alarm.3 \
time.3 \
times.3 \
timespec_get.3 \
- timezone.3 \
+ timespec_getres.3 \
ttyname.3 \
- tzset.3 \
ualarm.3 \
ucontext.3 \
ulimit.3 \
uname.3 \
unvis.3 \
- usleep.3 \
utime.3 \
valloc.3 \
vis.3 \
@@ -333,7 +331,6 @@ MAN+= alarm.3 \
MLINKS+=arc4random.3 arc4random_buf.3 \
arc4random.3 arc4random_uniform.3
-MLINKS+=auxv.3 elf_aux_info.3
MLINKS+=ctermid.3 ctermid_r.3
MLINKS+=daemon.3 daemonfd.3
MLINKS+=devname.3 devname_r.3
@@ -374,7 +371,8 @@ MLINKS+=exec.3 execl.3 \
exec.3 exect.3 \
exec.3 execv.3 \
exec.3 execvP.3 \
- exec.3 execvp.3
+ exec.3 execvp.3 \
+ exec.3 execvpe.3
MLINKS+=fpclassify.3 finite.3 \
fpclassify.3 finitef.3 \
fpclassify.3 isfinite.3 \
@@ -477,10 +475,17 @@ MLINKS+=posix_spawn.3 posix_spawnp.3 \
posix_spawnattr_getsigdefault.3 posix_spawnattr_setsigdefault.3 \
posix_spawnattr_getsigmask.3 posix_spawnattr_setsigmask.3 \
posix_spawnattr_init.3 posix_spawnattr_destroy.3
-MLINKS+=psignal.3 strsignal.3 \
+MLINKS+=psignal.3 psiginfo.3 \
+ psignal.3 sig2str.3 \
+ psignal.3 str2sig.3 \
+ psignal.3 strsignal.3 \
psignal.3 sys_siglist.3 \
psignal.3 sys_signame.3
-MLINKS+=pwcache.3 group_from_gid.3 \
+MLINKS+=pwcache.3 gid_from_group.3 \
+ pwcache.3 group_from_gid.3 \
+ pwcache.3 pwcache_groupdb.3 \
+ pwcache.3 pwcache_userdb.3 \
+ pwcache.3 uid_from_user.3 \
pwcache.3 user_from_uid.3
MLINKS+=rand48.3 _rand48.3 \
rand48.3 drand48.3 \
@@ -492,13 +497,19 @@ MLINKS+=rand48.3 _rand48.3 \
rand48.3 nrand48.3 \
rand48.3 seed48.3 \
rand48.3 srand48.3
-MLINKS+=recv.2 recvmmsg.2
-MLINKS+=scandir.3 alphasort.3
+MLINKS+=rtld_get_var.3 \
+ rtld_set_var.3
+MLINKS+=scandir.3 alphasort.3 \
+ scandir.3 fdscandir.3 \
+ scandir.3 fdscandir_b.3 \
+ scandir.3 scandir_b.3 \
+ scandir.3 scandirat.3 \
+ scandir.3 scandirat_b.3 \
+ scandir.3 versionsort.3
MLINKS+=sem_open.3 sem_close.3 \
sem_open.3 sem_unlink.3
MLINKS+=sem_wait.3 sem_trywait.3
MLINKS+=sem_timedwait.3 sem_clockwait_np.3
-MLINKS+=send.2 sendmmsg.2
MLINKS+=setjmp.3 _longjmp.3 \
setjmp.3 _setjmp.3 \
setjmp.3 longjmp.3 \
@@ -542,7 +553,6 @@ MLINKS+=tcsetattr.3 cfgetispeed.3 \
tcsetattr.3 tcgetattr.3
MLINKS+=ttyname.3 isatty.3 \
ttyname.3 ttyname_r.3
-MLINKS+=tzset.3 tzsetwall.3
MLINKS+=unvis.3 strunvis.3 \
unvis.3 strunvisx.3
MLINKS+=vis.3 nvis.3 \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index 012c9ff11f04..494b65bc5cc1 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -1,7 +1,3 @@
-/*
- * $FreeBSD$
- */
-
FBSD_1.0 {
__xuname;
pthread_atfork;
@@ -51,6 +47,7 @@ FBSD_1.0 {
pthread_mutexattr_init;
pthread_mutexattr_settype;
pthread_once;
+ pthread_resume_all_np;
pthread_rwlock_destroy;
pthread_rwlock_init;
pthread_rwlock_rdlock;
@@ -63,6 +60,7 @@ FBSD_1.0 {
pthread_setcanceltype;
pthread_setspecific;
pthread_sigmask;
+ pthread_suspend_all_np;
pthread_testcancel;
alarm;
arc4random;
@@ -103,7 +101,6 @@ FBSD_1.0 {
vwarnx;
sys_errlist;
sys_nerr;
- errno;
exect;
execl;
execle;
@@ -111,6 +108,7 @@ FBSD_1.0 {
execv;
execvp;
execvP;
+ fabs;
fmtcheck;
fmtmsg;
fnmatch;
@@ -162,7 +160,6 @@ FBSD_1.0 {
endnetgrent;
innetgr;
getosreldate;
- getpagesize;
getpeereid;
_getprogname;
getprogname;
@@ -185,21 +182,23 @@ FBSD_1.0 {
endusershell;
setusershell;
getvfsbyname;
+ __nan;
__isnan;
isnan;
__isnanf;
isnanf;
+ __infinity;
__isinf;
isinf;
__isinff;
__isinfl;
isatty;
- initgroups;
jrand48;
lcong48;
ldexp;
lockf;
lrand48;
+ makecontext;
modf;
mrand48;
nice;
@@ -221,6 +220,12 @@ FBSD_1.0 {
group_from_gid;
setdomainname;
sethostname;
+ _setjmp;
+ _longjmp;
+ setjmp;
+ longjmp;
+ sigsetjmp;
+ siglongjmp;
longjmperror;
getmode;
setmode;
@@ -257,7 +262,6 @@ FBSD_1.0 {
setlogmask;
ttyname_r;
ttyname;
- timezone;
times;
time;
telldir;
@@ -333,7 +337,6 @@ FBSD_1.1 {
FBSD_1.2 {
cfmakesane;
endutxent;
- getpagesizes;
getutxent;
getutxid;
getutxline;
@@ -355,6 +358,7 @@ FBSD_1.2 {
};
FBSD_1.3 {
+ cap_sandboxed;
clock_getcpuclockid;
dirfd;
dup3;
@@ -398,7 +402,6 @@ FBSD_1.5 {
devname;
devname_r;
dirname;
- elf_aux_info;
fts_children;
fts_close;
fts_get_clientptr;
@@ -427,6 +430,8 @@ FBSD_1.6 {
eventfd_write;
getlogin_r;
memalign;
+ memfd_create;
+ pthread_getname_np;
scandir_b;
sigandset;
sigisemptyset;
@@ -436,20 +441,44 @@ FBSD_1.6 {
};
FBSD_1.7 {
+ kqueue1;
posix_spawn_file_actions_addchdir_np;
posix_spawn_file_actions_addclosefrom_np;
posix_spawn_file_actions_addfchdir_np;
+ scandirat;
sched_getaffinity;
sched_setaffinity;
- sched_getcpu;
+ versionsort;
__cpuset_alloc;
__cpuset_free;
};
+FBSD_1.8 {
+ aio_read2;
+ aio_write2;
+ execvpe;
+ fdscandir;
+ fdscandir_b;
+ fts_open_b;
+ glob_b;
+ initgroups;
+ inotify_add_watch;
+ inotify_init;
+ inotify_init1;
+ psiginfo;
+ rtld_get_var;
+ rtld_set_var;
+ scandirat_b;
+ uexterr_gettext;
+ sig2str;
+ str2sig;
+};
+
FBSDprivate_1.0 {
/* needed by thread libraries */
__thr_jtable;
+ _dl_iterate_phdr_locked;
_pthread_atfork;
_pthread_attr_destroy;
_pthread_attr_getdetachstate;
@@ -552,6 +581,8 @@ FBSDprivate_1.0 {
__waitpid;
_waitpid;
+ __libc_interposing_slot;
+
_libc_sem_init_compat;
_libc_sem_destroy_compat;
_libc_sem_open_compat;
@@ -565,10 +596,10 @@ FBSDprivate_1.0 {
__libc_tcdrain;
- __elf_aux_vector;
- __pthread_distribute_static_tls;
__pthread_map_stacks_exec;
__fillcontextx;
__fillcontextx2;
__getcontextx_size;
+ __makecontext;
+ __uexterr_format;
};
diff --git a/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c b/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c
index 197d77c69541..3a81ace8a0f4 100644
--- a/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c
+++ b/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c
@@ -29,9 +29,6 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <pthread.h>
#include "libc_private.h"
diff --git a/lib/libc/gen/__xuname.c b/lib/libc/gen/__xuname.c
index fba5eaeebc88..4257c42f9519 100644
--- a/lib/libc/gen/__xuname.c
+++ b/lib/libc/gen/__xuname.c
@@ -27,13 +27,8 @@
* 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.
- *
- * From: @(#)uname.c 8.1 (Berkeley) 1/4/94
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/utsname.h>
diff --git a/lib/libc/gen/_once_stub.c b/lib/libc/gen/_once_stub.c
index 302f8536aec3..518072cbd28f 100644
--- a/lib/libc/gen/_once_stub.c
+++ b/lib/libc/gen/_once_stub.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2009 Hudson River Trading LLC
* Written by: John H. Baldwin <jhb@FreeBSD.org>
@@ -27,9 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <pthread.h>
#include "un-namespace.h"
diff --git a/lib/libc/gen/_pthread_stubs.c b/lib/libc/gen/_pthread_stubs.c
index fe5d704c3bb9..d867ee4db51e 100644
--- a/lib/libc/gen/_pthread_stubs.c
+++ b/lib/libc/gen/_pthread_stubs.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>.
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <signal.h>
#include <pthread.h>
#include <stdlib.h>
@@ -53,17 +50,20 @@ struct pthread {
static struct pthread main_thread;
static int stub_main(void);
-static void *stub_null(void);
+static void stub_void(void);
+static void *stub_null(void);
static struct pthread *stub_self(void);
static int stub_zero(void);
static int stub_fail(void);
static int stub_true(void);
static void stub_exit(void);
static int stub_esrch(void);
+static int stub_getname_np(pthread_t, char *, size_t);
#define PJT_DUAL_ENTRY(entry) \
(pthread_func_t)entry, (pthread_func_t)entry
+__attribute__((visibility("protected")))
pthread_func_entry_t __thr_jtable[PJT_MAX] = {
[PJT_ATFORK] = {PJT_DUAL_ENTRY(stub_zero)},
[PJT_ATTR_DESTROY] = {PJT_DUAL_ENTRY(stub_zero)},
@@ -133,6 +133,9 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = {
[PJT_MUTEXATTR_SETROBUST] = {PJT_DUAL_ENTRY(stub_zero)},
[PJT_GETTHREADID_NP] = {PJT_DUAL_ENTRY(stub_zero)},
[PJT_ATTR_GET_NP] = {PJT_DUAL_ENTRY(stub_esrch)},
+ [PJT_GETNAME_NP] = {PJT_DUAL_ENTRY(stub_getname_np)},
+ [PJT_SUSPEND_ALL_NP] = {PJT_DUAL_ENTRY(stub_void)},
+ [PJT_RESUME_ALL_NP] = {PJT_DUAL_ENTRY(stub_void)},
};
/*
@@ -242,7 +245,7 @@ STUB_FUNC2(pthread_mutexattr_getrobust, PJT_MUTEXATTR_GETROBUST, int, void *,
int *)
STUB_FUNC2(pthread_mutexattr_setrobust, PJT_MUTEXATTR_SETROBUST, int, void *,
int)
-STUB_FUNC2(pthread_once, PJT_ONCE, int, void *, void *)
+STUB_FUNC2(pthread_once, PJT_ONCE, int, void *, void *)
STUB_FUNC1(pthread_rwlock_destroy, PJT_RWLOCK_DESTROY, int, void *)
STUB_FUNC2(pthread_rwlock_init, PJT_RWLOCK_INIT, int, void *, void *)
STUB_FUNC1(pthread_rwlock_rdlock, PJT_RWLOCK_RDLOCK, int, void *)
@@ -291,6 +294,9 @@ STUB_FUNC3(__pthread_cleanup_push_imp, PJT_CLEANUP_PUSH_IMP, void, void *,
STUB_FUNC1(_pthread_cancel_enter, PJT_CANCEL_ENTER, void, int)
STUB_FUNC1(_pthread_cancel_leave, PJT_CANCEL_LEAVE, void, int)
STUB_FUNC2(pthread_attr_get_np, PJT_ATTR_GET_NP, int, pthread_t, pthread_attr_t *)
+STUB_FUNC3(pthread_getname_np, PJT_GETNAME_NP, int, pthread_t, char *, size_t)
+STUB_FUNC(pthread_suspend_all_np, PJT_SUSPEND_ALL_NP, void);
+STUB_FUNC(pthread_resume_all_np, PJT_RESUME_ALL_NP, void);
static int
stub_zero(void)
@@ -298,6 +304,12 @@ stub_zero(void)
return (0);
}
+static void
+stub_void(void)
+{
+
+}
+
static void *
stub_null(void)
{
@@ -339,3 +351,13 @@ stub_esrch(void)
{
return (ESRCH);
}
+
+static int
+stub_getname_np(pthread_t thread, char *buf, size_t len)
+{
+ if (thread != &main_thread)
+ return (ESRCH);
+ if (len >= 1)
+ buf[0] = '\0';
+ return (0);
+}
diff --git a/lib/libc/gen/_rand48.c b/lib/libc/gen/_rand48.c
index 279bbc362394..114c1595b33d 100644
--- a/lib/libc/gen/_rand48.c
+++ b/lib/libc/gen/_rand48.c
@@ -11,39 +11,8 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
-unsigned short _rand48_seed[3] = {
- RAND48_SEED_0,
- RAND48_SEED_1,
- RAND48_SEED_2
-};
-unsigned short _rand48_mult[3] = {
- RAND48_MULT_0,
- RAND48_MULT_1,
- RAND48_MULT_2
-};
-unsigned short _rand48_add = RAND48_ADD;
-
-void
-_dorand48(unsigned short xseed[3])
-{
- unsigned long accu;
- unsigned short temp[2];
-
- accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
- (unsigned long) _rand48_add;
- temp[0] = (unsigned short) accu; /* lower 16 bits */
- accu >>= sizeof(unsigned short) * 8;
- accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
- (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
- temp[1] = (unsigned short) accu; /* middle 16 bits */
- accu >>= sizeof(unsigned short) * 8;
- accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
- xseed[0] = temp[0];
- xseed[1] = temp[1];
- xseed[2] = (unsigned short) accu;
-}
+uint48 _rand48_seed = RAND48_SEED;
+uint48 _rand48_mult = RAND48_MULT;
+uint48 _rand48_add = RAND48_ADD;
diff --git a/lib/libc/gen/_spinlock_stub.c b/lib/libc/gen/_spinlock_stub.c
index 5d7ee3b2d2be..30e5c61f5f74 100644
--- a/lib/libc/gen/_spinlock_stub.c
+++ b/lib/libc/gen/_spinlock_stub.c
@@ -29,9 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
#include "spinlock.h"
diff --git a/lib/libc/gen/_thread_init.c b/lib/libc/gen/_thread_init.c
index 5778ad53f03f..66fa8b8c2e96 100644
--- a/lib/libc/gen/_thread_init.c
+++ b/lib/libc/gen/_thread_init.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
void _thread_init_stub(void);
diff --git a/lib/libc/gen/errno.c b/lib/libc/gen/aio_read2.c
index 4ee9b6475655..a5186d509b26 100644
--- a/lib/libc/gen/errno.c
+++ b/lib/libc/gen/aio_read2.c
@@ -1,8 +1,10 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2002 Peter Wemm <peter@freebsd.org>
- * All rights reserved.
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,7 +28,31 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+#include <sys/aio.h>
+#include <errno.h>
+#include <stddef.h>
+
+int
+aio_read2(struct aiocb *iocb, int flags)
+{
+ int error;
+
+ if ((flags & ~(AIO_OP2_FOFFSET | AIO_OP2_VECTORED)) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+ iocb->aio_lio_opcode = LIO_READ;
+ if ((flags & AIO_OP2_FOFFSET) != 0)
+ iocb->aio_lio_opcode |= LIO_FOFFSET;
+ if ((flags & AIO_OP2_VECTORED) != 0)
+ iocb->aio_lio_opcode |= LIO_VECTORED;
-int errno;
+ error = lio_listio(LIO_NOWAIT, &iocb, 1, NULL);
+ if (error == -1 && errno == EIO) {
+ error = aio_error(iocb);
+ if (error != -1 && error != 0)
+ errno = error;
+ error = -1;
+ }
+ return (error);
+}
diff --git a/lib/libc/gen/__getosreldate.c b/lib/libc/gen/aio_write2.c
index 938b1dc0e7f3..8f4f6a35fd4d 100644
--- a/lib/libc/gen/__getosreldate.c
+++ b/lib/libc/gen/aio_write2.c
@@ -1,8 +1,10 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2007 Peter Wemm
- * All rights reserved.
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,45 +28,31 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/sysctl.h>
+#include <sys/aio.h>
#include <errno.h>
-#include <link.h>
-#include "libc_private.h"
-
-/*
- * This is private to libc. It is intended for wrapping syscall stubs in order
- * to avoid having to put SIGSYS signal handlers in place to test for presence
- * of new syscalls. This caches the result in order to be as quick as possible.
- *
- * Use getosreldate(3) for public use as it respects the $OSVERSION environment
- * variable.
- */
+#include <stddef.h>
int
-__getosreldate(void)
+aio_write2(struct aiocb *iocb, int flags)
{
- static int osreldate;
- size_t len;
- int oid[2];
- int error, osrel;
-
- if (osreldate != 0)
- return (osreldate);
+ int error;
- error = _elf_aux_info(AT_OSRELDATE, &osreldate, sizeof(osreldate));
- if (error == 0 && osreldate != 0)
- return (osreldate);
+ if ((flags & ~(AIO_OP2_FOFFSET | AIO_OP2_VECTORED)) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+ iocb->aio_lio_opcode = LIO_WRITE;
+ if ((flags & AIO_OP2_FOFFSET) != 0)
+ iocb->aio_lio_opcode |= LIO_FOFFSET;
+ if ((flags & AIO_OP2_VECTORED) != 0)
+ iocb->aio_lio_opcode |= LIO_VECTORED;
- oid[0] = CTL_KERN;
- oid[1] = KERN_OSRELDATE;
- osrel = 0;
- len = sizeof(osrel);
- error = sysctl(oid, 2, &osrel, &len, NULL, 0);
- if (error == 0 && osrel > 0 && len == sizeof(osrel))
- osreldate = osrel;
- return (osreldate);
+ error = lio_listio(LIO_NOWAIT, &iocb, 1, NULL);
+ if (error == -1 && errno == EIO) {
+ error = aio_error(iocb);
+ if (error != -1 && error != 0)
+ errno = error;
+ error = -1;
+ }
+ return (error);
}
diff --git a/lib/libc/gen/alarm.3 b/lib/libc/gen/alarm.3
index d9e83fd410d9..4a24cc6d7216 100644
--- a/lib/libc/gen/alarm.3
+++ b/lib/libc/gen/alarm.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)alarm.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
.Dd April 2, 2022
.Dt ALARM 3
.Os
@@ -66,7 +63,7 @@ Due to
.Xr setitimer 2
restriction the maximum number of
.Fa seconds
-allowed is 100000000.
+allowed is 100,000,000.
.Sh RETURN VALUES
The return value of
.Fn alarm
diff --git a/lib/libc/gen/alarm.c b/lib/libc/gen/alarm.c
index 64bc7a86ebb5..043571ff89a1 100644
--- a/lib/libc/gen/alarm.c
+++ b/lib/libc/gen/alarm.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)alarm.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
/*
* Backwards compatible alarm.
*/
diff --git a/lib/libc/gen/arc4random-compat.c b/lib/libc/gen/arc4random-compat.c
index 065998e80553..beeb4d75964a 100644
--- a/lib/libc/gen/arc4random-compat.c
+++ b/lib/libc/gen/arc4random-compat.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2018 Google LLC
* All rights reserved.
@@ -24,13 +24,8 @@
* 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.
- *
- * $FreeBSD$
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <stdbool.h>
#include <syslog.h>
diff --git a/lib/libc/gen/arc4random.3 b/lib/libc/gen/arc4random.3
index 75f77a5cab59..1b042f15f000 100644
--- a/lib/libc/gen/arc4random.3
+++ b/lib/libc/gen/arc4random.3
@@ -29,9 +29,8 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" Manual page, using -mandoc macros
-.\" $FreeBSD$
.\"
-.Dd April 13, 2020
+.Dd November 18, 2024
.Dt ARC4RANDOM 3
.Os
.Sh NAME
@@ -130,9 +129,31 @@ functions using
.%O Document ID: 4027b5256e17b9796842e6d0f68b0b5e
.%U http://cr.yp.to/papers.html#chacha
.Re
+.Rs
+.%A Daniel Lemire
+.%T Fast Random Integer Generation in an Interval
+.%D January 2019
+.%J ACM Trans. Model. Comput. Simul.
+.%I Association for Computing Machinery
+.%C New York, NY, USA
+.%V vol. 29
+.%N no. 1
+.%P pp. 1\(en12
+.Re
.Sh HISTORY
These functions first appeared in
.Ox 2.1 .
+.Fn arc4random
+first appeared in
+.Fx 3.0 .
+.Fn arc4random_buf
+and
+.Fn arc4random_uniform
+first appeared in
+.Fx 8.0 .
+.Fn arc4random_stir
+was removed in
+.Fx 12.0 .
.Pp
The original version of this random number generator used the
RC4 (also known as ARC4) algorithm.
diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c
index 07e31e64e758..cc65e0131970 100644
--- a/lib/libc/gen/arc4random.c
+++ b/lib/libc/gen/arc4random.c
@@ -23,9 +23,6 @@
* ChaCha based random number generator for OpenBSD.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#if defined(__FreeBSD__)
#include <assert.h>
@@ -38,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ssp/ssp.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -246,7 +244,7 @@ arc4random(void)
}
void
-arc4random_buf(void *buf, size_t n)
+__ssp_real(arc4random_buf)(void *buf, size_t n)
{
_ARC4_LOCK();
_rs_random_buf(buf, n);
diff --git a/lib/libc/gen/arc4random.h b/lib/libc/gen/arc4random.h
index 459fcc7f6e1d..e6332f155db2 100644
--- a/lib/libc/gen/arc4random.h
+++ b/lib/libc/gen/arc4random.h
@@ -17,8 +17,6 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $FreeBSD$
*/
/*
diff --git a/lib/libc/gen/arc4random_uniform.c b/lib/libc/gen/arc4random_uniform.c
index 5f5e190790b0..23455e545899 100644
--- a/lib/libc/gen/arc4random_uniform.c
+++ b/lib/libc/gen/arc4random_uniform.c
@@ -1,58 +1,47 @@
-/* $OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $ */
-
-/*
- * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+/*-
+ * SPDX-License-Identifier: 0BSD
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * Copyright (c) Robert Clausecker <fuz@FreeBSD.org>
+ * Based on a publication by Daniel Lemire.
+ * Public domain where applicable.
*
- * $FreeBSD$
+ * Daniel Lemire, "Fast Random Integer Generation in an Interval",
+ * Association for Computing Machinery, ACM Trans. Model. Comput. Simul.,
+ * no. 1, vol. 29, pp. 1--12, New York, NY, USA, January 2019.
*/
#include <stdint.h>
#include <stdlib.h>
-/*
- * Calculate a uniformly distributed random number less than upper_bound
- * avoiding "modulo bias".
- *
- * Uniformity is achieved by generating new random numbers until the one
- * returned is outside the range [0, 2**32 % upper_bound). This
- * guarantees the selected random number will be inside
- * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
- * after reduction modulo upper_bound.
- */
uint32_t
arc4random_uniform(uint32_t upper_bound)
{
- uint32_t r, min;
-
- if (upper_bound < 2)
- return 0;
-
- /* 2**32 % x == (2**32 - x) % x */
- min = -upper_bound % upper_bound;
+ uint64_t product;
/*
- * This could theoretically loop forever but each retry has
- * p > 0.5 (worst case, usually far better) of selecting a
- * number inside the range we need, so it should rarely need
- * to re-roll.
+ * The paper uses these variable names:
+ *
+ * L -- log2(UINT32_MAX+1)
+ * s -- upper_bound
+ * x -- arc4random() return value
+ * m -- product
+ * l -- (uint32_t)product
+ * t -- threshold
*/
- for (;;) {
- r = arc4random();
- if (r >= min)
- break;
+
+ if (upper_bound <= 1)
+ return (0);
+
+ product = upper_bound * (uint64_t)arc4random();
+
+ if ((uint32_t)product < upper_bound) {
+ uint32_t threshold;
+
+ /* threshold = (2**32 - upper_bound) % upper_bound */
+ threshold = -upper_bound % upper_bound;
+ while ((uint32_t)product < threshold)
+ product = upper_bound * (uint64_t)arc4random();
}
- return r % upper_bound;
+ return (product >> 32);
}
diff --git a/lib/libc/gen/assert.c b/lib/libc/gen/assert.c
index 1a6ef1a8404b..21e5a44522ec 100644
--- a/lib/libc/gen/assert.c
+++ b/lib/libc/gen/assert.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)assert.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/auxv.3 b/lib/libc/gen/auxv.3
deleted file mode 100644
index 007e8066c791..000000000000
--- a/lib/libc/gen/auxv.3
+++ /dev/null
@@ -1,103 +0,0 @@
-.\"
-.\" Copyright (c) 2019 Ian Lepore <ian@freebsd.org>
-.\"
-.\" 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 AUTHOR ``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 AUTHOR 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.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd November 17, 2019
-.Dt ELF_AUX_INFO 3
-.Os
-.Sh NAME
-.Nm elf_aux_info
-.Nd extract data from the elf auxiliary vector of the current process
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/auxv.h
-.Ft int
-.Fn elf_aux_info "int aux" "void *buf" "int buflen"
-.Sh DESCRIPTION
-The
-.Fn elf_aux_info
-function retrieves the auxiliary info vector requested in
-.Va aux .
-The information is stored into the provided buffer if it will fit.
-The following values, defined in
-.In sys/elf_common.h
-can be requested (corresponding buffer sizes are specified in parenthesis):
-.Bl -tag -width AT_OSRELDATE
-.It AT_CANARY
-The canary value for SSP (arbitrary sized buffer, as many bytes are
-returned as it fits into it, rest is zeroed).
-.It AT_EXECPATH
-The path of executed program
-.Dv (MAXPATHLEN).
-This may not be present if the process was initialized by
-.Xr fexecve 2
-and the namecache no longer contains the file's name.
-.It AT_HWCAP
-CPU / hardware feature flags
-.Dv (sizeof(u_long)).
-.It AT_HWCAP2
-CPU / hardware feature flags
-.Dv (sizeof(u_long)).
-.It AT_NCPUS
-Number of CPUs
-.Dv (sizeof(int)).
-.It AT_OSRELDATE
-The
-.Dv OSRELDATE
-of the kernel or jail the program is running on
-.Dv (sizeof(int)).
-.It AT_PAGESIZES
-Vector of page sizes (arbitrary sized buffer, as many elements of the
-.Dv pagesizes
-array are returned as it fits).
-.It AT_PAGESZ
-Page size in bytes
-.Dv (sizeof(int)).
-.It AT_TIMEKEEP
-Pointer to VDSO timehands (for library internal use,
-.Dv sizeof(void *)).
-.El
-.Sh RETURN VALUES
-Returns zero on success, or an error number on failure.
-.Sh ERRORS
-.Bl -tag -width Er
-.It Bq Er EINVAL
-An unknown item was requested.
-.It Bq Er EINVAL
-The provided buffer was not the right size for the requested item.
-.It Bq Er ENOENT
-The requested item is not available.
-.El
-.Sh HISTORY
-The
-.Fn elf_aux_info
-function appeared in
-.Fx 12.0 .
-.Sh BUGS
-Only a small subset of available auxiliary info vector items are
-accessible with this function.
-Some items require a "right-sized" buffer while others just require a
-"big enough" buffer.
diff --git a/lib/libc/gen/auxv.c b/lib/libc/gen/auxv.c
deleted file mode 100644
index ae21d088a8d1..000000000000
--- a/lib/libc/gen/auxv.c
+++ /dev/null
@@ -1,378 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
- * Copyright 2010, 2012 Konstantin Belousov <kib@FreeBSD.ORG>.
- * All rights reserved.
- *
- * 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 AUTHOR ``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 AUTHOR 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.
- *
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <elf.h>
-#include <errno.h>
-#include <link.h>
-#include <pthread.h>
-#include <string.h>
-#include <sys/auxv.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-extern char **environ;
-extern int _DYNAMIC;
-#pragma weak _DYNAMIC
-
-void *__elf_aux_vector;
-static pthread_once_t aux_vector_once = PTHREAD_ONCE_INIT;
-
-static void
-init_aux_vector_once(void)
-{
- Elf_Addr *sp;
-
- sp = (Elf_Addr *)environ;
- while (*sp++ != 0)
- ;
- __elf_aux_vector = (Elf_Auxinfo *)sp;
-}
-
-void
-__init_elf_aux_vector(void)
-{
-
- if (&_DYNAMIC != NULL)
- return;
- _once(&aux_vector_once, init_aux_vector_once);
-}
-
-static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
-static int pagesize, osreldate, canary_len, ncpus, pagesizes_len, bsdflags;
-static int hwcap_present, hwcap2_present;
-static char *canary, *pagesizes, *execpath;
-static void *ps_strings, *timekeep;
-static u_long hwcap, hwcap2;
-static void *fxrng_seed_version;
-
-#ifdef __powerpc__
-static int powerpc_new_auxv_format = 0;
-static void _init_aux_powerpc_fixup(void);
-int _powerpc_elf_aux_info(int, void *, int);
-#endif
-
-static void
-init_aux(void)
-{
- Elf_Auxinfo *aux;
-
- for (aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
- switch (aux->a_type) {
- case AT_BSDFLAGS:
- bsdflags = aux->a_un.a_val;
- break;
-
- case AT_CANARY:
- canary = (char *)(aux->a_un.a_ptr);
- break;
-
- case AT_CANARYLEN:
- canary_len = aux->a_un.a_val;
- break;
-
- case AT_EXECPATH:
- execpath = (char *)(aux->a_un.a_ptr);
- break;
-
- case AT_HWCAP:
- hwcap_present = 1;
- hwcap = (u_long)(aux->a_un.a_val);
- break;
-
- case AT_HWCAP2:
- hwcap2_present = 1;
- hwcap2 = (u_long)(aux->a_un.a_val);
- break;
-
- case AT_PAGESIZES:
- pagesizes = (char *)(aux->a_un.a_ptr);
- break;
-
- case AT_PAGESIZESLEN:
- pagesizes_len = aux->a_un.a_val;
- break;
-
- case AT_PAGESZ:
- pagesize = aux->a_un.a_val;
- break;
-
- case AT_OSRELDATE:
- osreldate = aux->a_un.a_val;
- break;
-
- case AT_NCPUS:
- ncpus = aux->a_un.a_val;
- break;
-
- case AT_TIMEKEEP:
- timekeep = aux->a_un.a_ptr;
- break;
-
- case AT_PS_STRINGS:
- ps_strings = aux->a_un.a_ptr;
- break;
-
- case AT_FXRNG:
- fxrng_seed_version = aux->a_un.a_ptr;
- break;
-#ifdef __powerpc__
- /*
- * Since AT_STACKPROT is always set, and the common
- * value 23 is mutually exclusive with the legacy powerpc
- * value 21, the existence of AT_STACKPROT proves we are
- * on the common format.
- */
- case AT_STACKPROT: /* 23 */
- powerpc_new_auxv_format = 1;
- break;
-#endif
- }
- }
-#ifdef __powerpc__
- if (!powerpc_new_auxv_format)
- _init_aux_powerpc_fixup();
-#endif
-}
-
-#ifdef __powerpc__
-static void
-_init_aux_powerpc_fixup(void)
-{
- Elf_Auxinfo *aux;
-
- /*
- * Before 1300070, PowerPC platforms had nonstandard numbering for
- * the aux vector. When running old binaries, the kernel will pass
- * the vector using the old numbering. Reload affected variables.
- */
- for (aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
- switch (aux->a_type) {
- case AT_OLD_CANARY:
- canary = (char *)(aux->a_un.a_ptr);
- break;
- case AT_OLD_CANARYLEN:
- canary_len = aux->a_un.a_val;
- break;
- case AT_OLD_EXECPATH:
- execpath = (char *)(aux->a_un.a_ptr);
- break;
- case AT_OLD_PAGESIZES:
- pagesizes = (char *)(aux->a_un.a_ptr);
- break;
- case AT_OLD_PAGESIZESLEN:
- pagesizes_len = aux->a_un.a_val;
- break;
- case AT_OLD_OSRELDATE:
- osreldate = aux->a_un.a_val;
- break;
- case AT_OLD_NCPUS:
- ncpus = aux->a_un.a_val;
- break;
- }
- }
-}
-
-int
-_powerpc_elf_aux_info(int aux, void *buf, int buflen)
-{
-
- /*
- * If we are in the old auxv format, we need to translate the aux
- * parameter of elf_aux_info() calls into the common auxv format.
- * Internal libc calls always use the common format, and they
- * directly call _elf_aux_info instead of using the weak symbol.
- */
- if (!powerpc_new_auxv_format) {
- switch (aux) {
- case AT_OLD_EXECPATH:
- aux = AT_EXECPATH;
- break;
- case AT_OLD_CANARY:
- aux = AT_CANARY;
- break;
- case AT_OLD_CANARYLEN:
- aux = AT_CANARYLEN;
- break;
- case AT_OLD_OSRELDATE:
- aux = AT_OSRELDATE;
- break;
- case AT_OLD_NCPUS:
- aux = AT_NCPUS;
- break;
- case AT_OLD_PAGESIZES:
- aux = AT_PAGESIZES;
- break;
- case AT_OLD_PAGESIZESLEN:
- aux = AT_PAGESIZESLEN;
- break;
- case AT_OLD_STACKPROT:
- aux = AT_STACKPROT;
- break;
- }
- }
- return _elf_aux_info(aux, buf, buflen);
-}
-__weak_reference(_powerpc_elf_aux_info, elf_aux_info);
-#else
-__weak_reference(_elf_aux_info, elf_aux_info);
-#endif
-
-int
-_elf_aux_info(int aux, void *buf, int buflen)
-{
- int res;
-
- __init_elf_aux_vector();
- if (__elf_aux_vector == NULL)
- return (ENOSYS);
- _once(&aux_once, init_aux);
-
- if (buflen < 0)
- return (EINVAL);
-
- switch (aux) {
- case AT_CANARY:
- if (canary != NULL && canary_len >= buflen) {
- memcpy(buf, canary, buflen);
- memset(canary, 0, canary_len);
- canary = NULL;
- res = 0;
- } else
- res = ENOENT;
- break;
- case AT_EXECPATH:
- if (execpath == NULL)
- res = ENOENT;
- else if (buf == NULL)
- res = EINVAL;
- else {
- if (strlcpy(buf, execpath, buflen) >=
- (unsigned int)buflen)
- res = EINVAL;
- else
- res = 0;
- }
- break;
- case AT_HWCAP:
- if (hwcap_present && buflen == sizeof(u_long)) {
- *(u_long *)buf = hwcap;
- res = 0;
- } else
- res = ENOENT;
- break;
- case AT_HWCAP2:
- if (hwcap2_present && buflen == sizeof(u_long)) {
- *(u_long *)buf = hwcap2;
- res = 0;
- } else
- res = ENOENT;
- break;
- case AT_PAGESIZES:
- if (pagesizes != NULL && pagesizes_len >= buflen) {
- memcpy(buf, pagesizes, buflen);
- res = 0;
- } else
- res = ENOENT;
- break;
- case AT_PAGESZ:
- if (buflen == sizeof(int)) {
- if (pagesize != 0) {
- *(int *)buf = pagesize;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- case AT_OSRELDATE:
- if (buflen == sizeof(int)) {
- if (osreldate != 0) {
- *(int *)buf = osreldate;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- case AT_NCPUS:
- if (buflen == sizeof(int)) {
- if (ncpus != 0) {
- *(int *)buf = ncpus;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- case AT_TIMEKEEP:
- if (buflen == sizeof(void *)) {
- if (timekeep != NULL) {
- *(void **)buf = timekeep;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- case AT_BSDFLAGS:
- if (buflen == sizeof(int)) {
- *(int *)buf = bsdflags;
- res = 0;
- } else
- res = EINVAL;
- break;
- case AT_PS_STRINGS:
- if (buflen == sizeof(void *)) {
- if (ps_strings != NULL) {
- *(void **)buf = ps_strings;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- case AT_FXRNG:
- if (buflen == sizeof(void *)) {
- if (fxrng_seed_version != NULL) {
- *(void **)buf = fxrng_seed_version;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- default:
- res = ENOENT;
- break;
- }
- return (res);
-}
diff --git a/lib/libc/gen/basename.3 b/lib/libc/gen/basename.3
index 3bbddd9233e2..e3fb25606172 100644
--- a/lib/libc/gen/basename.3
+++ b/lib/libc/gen/basename.3
@@ -14,8 +14,6 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 22, 2017
.Dt BASENAME 3
.Os
diff --git a/lib/libc/gen/basename.c b/lib/libc/gen/basename.c
index 7569ab9c3029..d0ba1bd9229c 100644
--- a/lib/libc/gen/basename.c
+++ b/lib/libc/gen/basename.c
@@ -23,9 +23,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <libgen.h>
#include <string.h>
diff --git a/lib/libc/gen/basename_compat.c b/lib/libc/gen/basename_compat.c
index c7488f2dcb67..19a4bd6c03eb 100644
--- a/lib/libc/gen/basename_compat.c
+++ b/lib/libc/gen/basename_compat.c
@@ -16,9 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <libgen.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/cap_rights_get.3 b/lib/libc/gen/cap_rights_get.3
index 21815b73aa71..e99424c7afdc 100644
--- a/lib/libc/gen/cap_rights_get.3
+++ b/lib/libc/gen/cap_rights_get.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 5, 2020
.Dt CAP_RIGHTS_GET 3
.Os
diff --git a/lib/libc/gen/cap_sandboxed.3 b/lib/libc/gen/cap_sandboxed.3
index 0db42276ca28..6e2004fb7a29 100644
--- a/lib/libc/gen/cap_sandboxed.3
+++ b/lib/libc/gen/cap_sandboxed.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 5, 2020
.Dt CAP_SANDBOXED 3
.Os
diff --git a/lib/libc/gen/cap_sandboxed.c b/lib/libc/gen/cap_sandboxed.c
index f81d12217e33..63c2439382a6 100644
--- a/lib/libc/gen/cap_sandboxed.c
+++ b/lib/libc/gen/cap_sandboxed.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 The FreeBSD Foundation
*
@@ -28,9 +28,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/capsicum.h>
#include <assert.h>
diff --git a/lib/libc/gen/check_utility_compat.3 b/lib/libc/gen/check_utility_compat.3
index 89449a4064bb..05dea4f124b6 100644
--- a/lib/libc/gen/check_utility_compat.3
+++ b/lib/libc/gen/check_utility_compat.3
@@ -26,8 +26,6 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd October 27, 2002
.Dt CHECK_UTILITY_COMPAT 3
.Os
diff --git a/lib/libc/gen/check_utility_compat.c b/lib/libc/gen/check_utility_compat.c
index 04c594b52665..63a268896daa 100644
--- a/lib/libc/gen/check_utility_compat.c
+++ b/lib/libc/gen/check_utility_compat.c
@@ -27,9 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
/*
* I din't use "namespace.h" here because none of the relevant utilities
* are threaded, so I'm not concerned about cancellation points or other
diff --git a/lib/libc/gen/clock.3 b/lib/libc/gen/clock.3
index 390e35234cdc..77d7ce085d2e 100644
--- a/lib/libc/gen/clock.3
+++ b/lib/libc/gen/clock.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)clock.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 4, 1993
.Dt CLOCK 3
.Os
diff --git a/lib/libc/gen/clock.c b/lib/libc/gen/clock.c
index d20bbf878f50..4d78fff73028 100644
--- a/lib/libc/gen/clock.c
+++ b/lib/libc/gen/clock.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)clock.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
diff --git a/lib/libc/gen/clock_getcpuclockid.3 b/lib/libc/gen/clock_getcpuclockid.3
index 7a476846f51e..b14c956be71d 100644
--- a/lib/libc/gen/clock_getcpuclockid.3
+++ b/lib/libc/gen/clock_getcpuclockid.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd August 21, 2012
.Dt CLOCK_GETCPUCLOCKID 3
.Os
diff --git a/lib/libc/gen/clock_getcpuclockid.c b/lib/libc/gen/clock_getcpuclockid.c
index fe951392d3c6..77d6c3423301 100644
--- a/lib/libc/gen/clock_getcpuclockid.c
+++ b/lib/libc/gen/clock_getcpuclockid.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 David Xu <davidxu@FreeBSD.org>.
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <time.h>
#include <unistd.h>
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index b83ef273895b..6015114d6c47 100644
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)closedir.c 8.1 (Berkeley) 6/10/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
#include <dirent.h>
diff --git a/lib/libc/gen/confstr.3 b/lib/libc/gen/confstr.3
index 923f5db96aa1..df19339c612a 100644
--- a/lib/libc/gen/confstr.3
+++ b/lib/libc/gen/confstr.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)confstr.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd December 3, 2006
.Dt CONFSTR 3
.Os
diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c
index dc8ffff0d68f..491df0cba67a 100644
--- a/lib/libc/gen/confstr.c
+++ b/lib/libc/gen/confstr.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)confstr.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <errno.h>
diff --git a/lib/libc/gen/crypt.c b/lib/libc/gen/crypt.c
index 7995196ef234..ddcd6719775f 100644
--- a/lib/libc/gen/crypt.c
+++ b/lib/libc/gen/crypt.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)crypt.c 5.11 (Berkeley) 6/25/91");
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
#include <string.h>
#include <unistd.h>
diff --git a/lib/libc/gen/ctermid.3 b/lib/libc/gen/ctermid.3
index 946ce49fd94f..2a53412f1b29 100644
--- a/lib/libc/gen/ctermid.3
+++ b/lib/libc/gen/ctermid.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ctermid.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd October 1, 2011
.Dt CTERMID 3
.Os
diff --git a/lib/libc/gen/ctermid.c b/lib/libc/gen/ctermid.c
index eda960f80a51..fb117b3c8ded 100644
--- a/lib/libc/gen/ctermid.c
+++ b/lib/libc/gen/ctermid.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -37,11 +34,12 @@ __FBSDID("$FreeBSD$");
#include <paths.h>
#include <stdio.h>
#include <string.h>
+#include <ssp/ssp.h>
#define LEN_PATH_DEV (sizeof(_PATH_DEV) - 1)
char *
-ctermid(char *s)
+__ssp_real(ctermid)(char *s)
{
static char def[sizeof(_PATH_DEV) + SPECNAMELEN];
struct stat sb;
@@ -65,7 +63,7 @@ ctermid(char *s)
}
char *
-ctermid_r(char *s)
+__ssp_real(ctermid_r)(char *s)
{
return (s != NULL ? ctermid(s) : NULL);
diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3
index f4129fc47144..4619ba3489aa 100644
--- a/lib/libc/gen/daemon.3
+++ b/lib/libc/gen/daemon.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)daemon.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
-.\"
-.Dd December 23, 2017
+.Dd February 27, 2023
.Dt DAEMON 3
.Os
.Sh NAME
@@ -48,18 +45,18 @@ The
function is for programs wishing to detach themselves from the
controlling terminal and run in the background as system daemons.
.Pp
-Unless the argument
+If the argument
.Fa nochdir
-is non-zero,
+is zero,
.Fn daemon
changes the current working directory to the root
.Pq Pa / .
.Pp
-Unless the argument
+If the argument
.Fa noclose
-is non-zero,
+is zero,
.Fn daemon
-will redirect standard input, standard output, and standard error to
+redirects standard input, standard output, and standard error to
.Pa /dev/null .
.Pp
The
diff --git a/lib/libc/gen/daemon.c b/lib/libc/gen/daemon.c
index f6753a84c44a..525c99761aa3 100644
--- a/lib/libc/gen/daemon.c
+++ b/lib/libc/gen/daemon.c
@@ -30,10 +30,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)daemon.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <errno.h>
#include <fcntl.h>
diff --git a/lib/libc/gen/devname-compat11.c b/lib/libc/gen/devname-compat11.c
index 70cb6f0d641e..b01b0845e261 100644
--- a/lib/libc/gen/devname-compat11.c
+++ b/lib/libc/gen/devname-compat11.c
@@ -24,9 +24,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/devname.3 b/lib/libc/gen/devname.3
index c5d9ec036f4b..44c1ff951cfa 100644
--- a/lib/libc/gen/devname.3
+++ b/lib/libc/gen/devname.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)devname.3 8.2 (Berkeley) 4/29/95
-.\" $FreeBSD$
-.\"
.Dd February 22, 2005
.Dt DEVNAME 3
.Os
diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c
index e519b505f1f8..ebb56132c48d 100644
--- a/lib/libc/gen/devname.c
+++ b/lib/libc/gen/devname.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)devname.c 8.2 (Berkeley) 4/29/95");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
@@ -48,7 +44,7 @@ devname_r(dev_t dev, mode_t type, char *buf, int len)
int i;
size_t j;
- if (dev == NODEV || !(S_ISCHR(type) || S_ISBLK(dev))) {
+ if (dev == NODEV || !(S_ISCHR(type) || S_ISBLK(type))) {
strlcpy(buf, "#NODEV", len);
return (buf);
}
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index f517a00386c6..263dfdd6eb95 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)directory.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd August 1, 2020
.Dt DIRECTORY 3
.Os
diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c
index 14fd3c8fc823..85090bd4da6c 100644
--- a/lib/libc/gen/dirfd.c
+++ b/lib/libc/gen/dirfd.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Gleb Kurtsou <gleb@FreeBSD.org>
* All rights reserved.
@@ -24,13 +24,8 @@
* 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.
- *
- * $FreeBSD$
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
diff --git a/lib/libc/gen/dirname.3 b/lib/libc/gen/dirname.3
index 67eee664a1e1..bb3be09ab4c4 100644
--- a/lib/libc/gen/dirname.3
+++ b/lib/libc/gen/dirname.3
@@ -14,8 +14,6 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.\" $FreeBSD$
-.\"
.Dd September 5, 2016
.Dt DIRNAME 3
.Os
diff --git a/lib/libc/gen/dirname.c b/lib/libc/gen/dirname.c
index ae7b928d54eb..7157fec23630 100644
--- a/lib/libc/gen/dirname.c
+++ b/lib/libc/gen/dirname.c
@@ -23,9 +23,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <libgen.h>
#include <string.h>
diff --git a/lib/libc/gen/dirname_compat.c b/lib/libc/gen/dirname_compat.c
index f85d40993a91..7eca7eb03f83 100644
--- a/lib/libc/gen/dirname_compat.c
+++ b/lib/libc/gen/dirname_compat.c
@@ -16,9 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <libgen.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c
index d02644e1e1ce..4b3730920529 100644
--- a/lib/libc/gen/disklabel.c
+++ b/lib/libc/gen/disklabel.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)disklabel.c 8.2 (Berkeley) 5/3/95");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#define DKTYPENAMES
#define FSTYPENAMES
diff --git a/lib/libc/gen/dl_iterate_phdr.3 b/lib/libc/gen/dl_iterate_phdr.3
index fe4face9eeb7..448d6fbb2fc5 100644
--- a/lib/libc/gen/dl_iterate_phdr.3
+++ b/lib/libc/gen/dl_iterate_phdr.3
@@ -14,7 +14,6 @@
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" $OpenBSD: dl_iterate_phdr.3,v 1.3 2007/05/31 19:19:48 jmc Exp $
-.\" $FreeBSD$
.Dd April 5, 2021
.Dt DL_ITERATE_PHDR 3
.Os
diff --git a/lib/libc/gen/dladdr.3 b/lib/libc/gen/dladdr.3
index 65662793b59d..a9abf95393c3 100644
--- a/lib/libc/gen/dladdr.3
+++ b/lib/libc/gen/dladdr.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd February 5, 1998
.Dt DLADDR 3
.Os
diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c
index 337ad48fd691..ae1c8d83df19 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1998 John D. Polstra
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#if !defined(IN_LIBDL) || defined(PIC)
/*
@@ -38,8 +35,10 @@ __FBSDID("$FreeBSD$");
#include <sys/mman.h>
#include <machine/atomic.h>
#include <dlfcn.h>
+#include <errno.h>
#include <link.h>
#include <stddef.h>
+#include <string.h>
#include "namespace.h"
#include <pthread.h>
#include "un-namespace.h"
@@ -168,7 +167,9 @@ _rtld_thread_init(void *li __unused)
#ifndef IN_LIBDL
static pthread_once_t dl_phdr_info_once = PTHREAD_ONCE_INIT;
static struct dl_phdr_info phdr_info;
+#ifndef PIC
static mutex_t dl_phdr_info_lock = MUTEX_INITIALIZER;
+#endif
static void
dl_init_phdr_info(void)
@@ -202,12 +203,24 @@ dl_init_phdr_info(void)
}
#endif
-#pragma weak dl_iterate_phdr
+#pragma weak _dl_iterate_phdr_locked
+int _dl_iterate_phdr_locked(int (*callback)(struct dl_phdr_info *,
+ size_t, void *), void *data);
int
-dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
+_dl_iterate_phdr_locked(
+ int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
void *data __unused)
{
-#ifndef IN_LIBDL
+#if defined IN_LIBDL
+ return (0);
+#elif defined PIC
+ int (*r)(int (*)(struct dl_phdr_info *, size_t, void *), void *);
+
+ r = dlsym(RTLD_DEFAULT, "dl_iterate_phdr");
+ if (r == NULL)
+ return (0);
+ return (r(callback, data));
+#else
tls_index ti;
int ret;
@@ -216,17 +229,30 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
return (1);
_once(&dl_phdr_info_once, dl_init_phdr_info);
ti.ti_module = 1;
- ti.ti_offset = 0;
- mutex_lock(&dl_phdr_info_lock);
+ ti.ti_offset = -TLS_DTV_OFFSET;
phdr_info.dlpi_tls_data = __tls_get_addr(&ti);
ret = callback(&phdr_info, sizeof(phdr_info), data);
- mutex_unlock(&dl_phdr_info_lock);
return (ret);
-#else
- return (0);
#endif
}
+#pragma weak dl_iterate_phdr
+int
+dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
+ void *data __unused)
+{
+ int error;
+
+#if !defined(IN_LIBDL) && !defined(PIC)
+ mutex_lock(&dl_phdr_info_lock);
+#endif
+ error = _dl_iterate_phdr_locked(callback, data);
+#if !defined(IN_LIBDL) && !defined(PIC)
+ mutex_unlock(&dl_phdr_info_lock);
+#endif
+ return (error);
+}
+
#pragma weak fdlopen
void *
fdlopen(int fd __unused, int mode __unused)
@@ -248,13 +274,48 @@ _rtld_atfork_post(int *locks __unused)
{
}
+#ifndef IN_LIBDL
+struct _rtld_addr_phdr_cb_data {
+ const void *addr;
+ struct dl_phdr_info *dli;
+};
+
+static int
+_rtld_addr_phdr_cb(struct dl_phdr_info *dli, size_t sz, void *arg)
+{
+ struct _rtld_addr_phdr_cb_data *rd;
+ const Elf_Phdr *ph;
+ unsigned i;
+
+ rd = arg;
+ for (i = 0; i < dli->dlpi_phnum; i++) {
+ ph = &dli->dlpi_phdr[i];
+ if (ph->p_type == PT_LOAD &&
+ dli->dlpi_addr + ph->p_vaddr <= (uintptr_t)rd->addr &&
+ (uintptr_t)rd->addr < dli->dlpi_addr + ph->p_vaddr +
+ ph->p_memsz) {
+ memcpy(rd->dli, dli, sz);
+ return (1);
+ }
+ }
+ return (0);
+}
+#endif
+
#pragma weak _rtld_addr_phdr
int
_rtld_addr_phdr(const void *addr __unused,
struct dl_phdr_info *phdr_info_a __unused)
{
+#ifndef IN_LIBDL
+ struct _rtld_addr_phdr_cb_data rd;
+ rd.addr = addr;
+ rd.dli = phdr_info_a;
+ return (dl_iterate_phdr(_rtld_addr_phdr_cb, &rd));
+#else
return (0);
+#endif
}
#pragma weak _rtld_get_stack_prot
@@ -295,4 +356,20 @@ _rtld_is_dlopened(void *arg __unused)
return (0);
}
+#pragma weak rtld_get_var
+const char *
+rtld_get_var(const char *name __unused)
+{
+ _rtld_error(sorry);
+ return (NULL);
+}
+
+#pragma weak rtld_set_var
+int
+rtld_set_var(const char *name __unused, const char *val __unused)
+{
+ _rtld_error(sorry);
+ return (EINVAL);
+}
+
#endif /* !defined(IN_LIBDL) || defined(PIC) */
diff --git a/lib/libc/gen/dlinfo.3 b/lib/libc/gen/dlinfo.3
index e5da2bc9ffda..8f30e5f10af1 100644
--- a/lib/libc/gen/dlinfo.3
+++ b/lib/libc/gen/dlinfo.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 21, 2020
.Dt DLINFO 3
.Os
diff --git a/lib/libc/gen/dllockinit.3 b/lib/libc/gen/dllockinit.3
index be3e2cab87f7..8fe29f2516f9 100644
--- a/lib/libc/gen/dllockinit.3
+++ b/lib/libc/gen/dllockinit.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd July 5, 2000
.Dt DLLOCKINIT 3
.Os
diff --git a/lib/libc/gen/dlopen.3 b/lib/libc/gen/dlopen.3
index 8bafb0897fd9..340545114114 100644
--- a/lib/libc/gen/dlopen.3
+++ b/lib/libc/gen/dlopen.3
@@ -29,10 +29,7 @@
.\"
.\" Copyright (c) 1991 Sun Microsystems, Inc.
.\"
-.\" @(#) dlopen.3 1.6 90/01/31 SMI
-.\" $FreeBSD$
-.\"
-.Dd May 14, 2020
+.Dd May 7, 2024
.Dt DLOPEN 3
.Os
.Sh NAME
@@ -202,6 +199,10 @@ The
function can be used by the code that needs to perform
additional checks on the loaded objects, to prevent races with
symlinking or renames.
+Applications sandboxed using
+.Xr capsicum 4
+can also make beneficial use of
+.Fn fdlopen .
.Pp
The
.Fn dlsym
@@ -326,11 +327,9 @@ triggering compiler diagnostics.
(The
.Fn dlsym
function
-returns a data pointer; in the C standard, conversions between
-data and function pointer types are undefined.
-Some compilers and
-.Xr lint 1
-utilities warn about such casts.)
+returns an object pointer; in the C standard, conversions between
+object and function pointer types are undefined.
+Some compilers and lint utilities warn about such casts.)
The precise return type of
.Fn dlfunc
is unspecified; applications must cast it to an appropriate function pointer
diff --git a/lib/libc/gen/drand48.c b/lib/libc/gen/drand48.c
index 672b5eef6b19..f7f43ff20468 100644
--- a/lib/libc/gen/drand48.c
+++ b/lib/libc/gen/drand48.c
@@ -11,15 +11,12 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-
double
drand48(void)
{
- return erand48(_rand48_seed);
+ ERAND48_BEGIN;
+ _DORAND48(_rand48_seed);
+ ERAND48_END(_rand48_seed);
}
diff --git a/lib/libc/gen/dup3.3 b/lib/libc/gen/dup3.3
index d3bb116189b7..338a9ae74c64 100644
--- a/lib/libc/gen/dup3.3
+++ b/lib/libc/gen/dup3.3
@@ -22,9 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd August 16, 2013
+.Dd May 17, 2025
.Dt DUP3 3
.Os
.Sh NAME
@@ -49,6 +47,11 @@ The close-on-exec flag on the new file descriptor is determined by the
bit in
.Fa flags .
.Pp
+The close-on-fork flag on the new file descriptor is determined by the
+.Dv O_CLOFORK
+bit in
+.Fa flags .
+.Pp
If
.Fa oldd
\*(Ne
@@ -93,7 +96,9 @@ argument.
The
.Fa flags
argument has bits set other than
-.Dv O_CLOEXEC .
+.Dv O_CLOEXEC
+or
+.Dv O_CLOFORK .
.El
.Sh SEE ALSO
.Xr accept 2 ,
@@ -114,3 +119,7 @@ The
.Fn dup3
function appeared in
.Fx 10.0 .
+The
+.Dv O_CLOFORK
+flag appeared in
+.Fx 15.0 .
diff --git a/lib/libc/gen/dup3.c b/lib/libc/gen/dup3.c
index c091f3427738..1401c1f5b607 100644
--- a/lib/libc/gen/dup3.c
+++ b/lib/libc/gen/dup3.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 Jukka A. Ukkonen
* All rights reserved.
@@ -28,9 +28,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <unistd.h>
#include <fcntl.h>
@@ -42,21 +39,22 @@ int __dup3(int, int, int);
int
__dup3(int oldfd, int newfd, int flags)
{
- int how;
+ int fdflags;
if (oldfd == newfd) {
errno = EINVAL;
return (-1);
}
- if (flags & ~O_CLOEXEC) {
+ if ((flags & ~(O_CLOEXEC | O_CLOFORK)) != 0) {
errno = EINVAL;
return (-1);
}
- how = (flags & O_CLOEXEC) ? F_DUP2FD_CLOEXEC : F_DUP2FD;
+ fdflags = ((flags & O_CLOEXEC) != 0 ? FD_CLOEXEC : 0) |
+ ((flags & O_CLOFORK) != 0 ? FD_CLOFORK : 0);
- return (_fcntl(oldfd, how, newfd));
+ return (_fcntl(oldfd, F_DUP3FD | (fdflags << F_DUP3FD_SHIFT), newfd));
}
__weak_reference(__dup3, dup3);
diff --git a/lib/libc/gen/elf_utils.c b/lib/libc/gen/elf_utils.c
index fbf3bf17082c..3714a0dc42b5 100644
--- a/lib/libc/gen/elf_utils.c
+++ b/lib/libc/gen/elf_utils.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2010 Konstantin Belousov <kib@freebsd.org>
* All rights reserved.
@@ -24,22 +24,23 @@
* 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.
- *
- * $FreeBSD$
*/
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/auxv.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
+
+#include <machine/tls.h>
+
#include <link.h>
#include <stddef.h>
#include <string.h>
+
#include "libc_private.h"
-#include "static_tls.h"
void __pthread_map_stacks_exec(void);
-void __pthread_distribute_static_tls(size_t, void *, size_t, size_t);
int
__elf_phdr_match_addr(struct dl_phdr_info *phdr_info, void *addr)
@@ -77,19 +78,23 @@ __libc_map_stacks_exec(void)
{
int mib[2];
struct rlimit rlim;
- u_long usrstack;
+ u_long usrstack, stacksz;
size_t len;
- mib[0] = CTL_KERN;
- mib[1] = KERN_USRSTACK;
- len = sizeof(usrstack);
- if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0)
- == -1)
- return;
- if (getrlimit(RLIMIT_STACK, &rlim) == -1)
- return;
- mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur),
- rlim.rlim_cur, _rtld_get_stack_prot());
+ if (_elf_aux_info(AT_USRSTACKBASE, &usrstack, sizeof(usrstack)) != 0) {
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_USRSTACK;
+ len = sizeof(usrstack);
+ if (sysctl(mib, nitems(mib), &usrstack, &len, NULL, 0) == -1)
+ return;
+ }
+ if (_elf_aux_info(AT_USRSTACKLIM, &stacksz, sizeof(stacksz)) != 0) {
+ if (getrlimit(RLIMIT_STACK, &rlim) == -1)
+ return;
+ stacksz = rlim.rlim_cur;
+ }
+ mprotect((void *)(uintptr_t)(usrstack - stacksz), stacksz,
+ _rtld_get_stack_prot());
}
#pragma weak __pthread_map_stacks_exec
@@ -99,24 +104,3 @@ __pthread_map_stacks_exec(void)
((void (*)(void))__libc_interposing[INTERPOS_map_stacks_exec])();
}
-
-void
-__libc_distribute_static_tls(size_t offset, void *src, size_t len,
- size_t total_len)
-{
- uintptr_t tlsbase;
-
- tlsbase = _libc_get_static_tls_base(offset);
- memcpy((void *)tlsbase, src, len);
- memset((char *)tlsbase + len, 0, total_len - len);
-}
-
-#pragma weak __pthread_distribute_static_tls
-void
-__pthread_distribute_static_tls(size_t offset, void *src, size_t len,
- size_t total_len)
-{
-
- ((void (*)(size_t, void *, size_t, size_t))__libc_interposing[
- INTERPOS_distribute_static_tls])(offset, src, len, total_len);
-}
diff --git a/lib/libc/gen/erand48.c b/lib/libc/gen/erand48.c
index cdb3ec85052b..38d4774a9fe6 100644
--- a/lib/libc/gen/erand48.c
+++ b/lib/libc/gen/erand48.c
@@ -11,16 +11,14 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
double
erand48(unsigned short xseed[3])
{
- _dorand48(xseed);
- return ldexp((double) xseed[0], -48) +
- ldexp((double) xseed[1], -32) +
- ldexp((double) xseed[2], -16);
+ uint48 tmp;
+
+ ERAND48_BEGIN;
+ DORAND48(tmp, xseed);
+ ERAND48_END(tmp);
}
diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3
index 140772a4a6b8..088ead71239b 100644
--- a/lib/libc/gen/err.3
+++ b/lib/libc/gen/err.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
-.\"
.Dd March 29, 2012
.Dt ERR 3
.Os
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c
index e72fac99ee61..16cbe27693e7 100644
--- a/lib/libc/gen/err.c
+++ b/lib/libc/gen/err.c
@@ -29,14 +29,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)err.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
+#include <sys/exterrvar.h>
#include <err.h>
#include <errno.h>
+#include <exterr.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -47,6 +46,11 @@ __FBSDID("$FreeBSD$");
static FILE *err_file; /* file to use for error output */
static void (*err_exit)(int);
+static void verrci(bool doexterr, int eval, int code, const char *fmt,
+ va_list ap) __printf0like(4, 0) __dead2;
+static void vwarnci(bool doexterr, int code, const char *fmt, va_list ap)
+ __printf0like(3, 0);
+
/*
* This is declared to take a `void *' so that the caller is not required
* to include <stdio.h> first. However, it is really a `FILE *', and the
@@ -74,14 +78,14 @@ _err(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- verrc(eval, errno, fmt, ap);
+ verrci(true, eval, errno, fmt, ap);
va_end(ap);
}
void
verr(int eval, const char *fmt, va_list ap)
{
- verrc(eval, errno, fmt, ap);
+ verrci(true, eval, errno, fmt, ap);
}
void
@@ -89,13 +93,24 @@ errc(int eval, int code, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- verrc(eval, code, fmt, ap);
+ verrci(false, eval, code, fmt, ap);
va_end(ap);
}
void
verrc(int eval, int code, const char *fmt, va_list ap)
{
+ verrci(false, eval, code, fmt, ap);
+}
+
+static void
+vexterr(bool doexterr, int code, const char *fmt, va_list ap)
+{
+ char exterr[UEXTERROR_MAXLEN]; /* libc knows the buffer size */
+ int extstatus;
+
+ if (doexterr)
+ extstatus = uexterr_gettext(exterr, sizeof(exterr));
if (err_file == NULL)
err_set_file(NULL);
fprintf(err_file, "%s: ", _getprogname());
@@ -103,7 +118,16 @@ verrc(int eval, int code, const char *fmt, va_list ap)
vfprintf(err_file, fmt, ap);
fprintf(err_file, ": ");
}
- fprintf(err_file, "%s\n", strerror(code));
+ fprintf(err_file, "%s", strerror(code));
+ if (doexterr && extstatus == 0 && exterr[0] != '\0')
+ fprintf(err_file, " (extended error %s)", exterr);
+ fprintf(err_file, "\n");
+}
+
+static void
+verrci(bool doexterr, int eval, int code, const char *fmt, va_list ap)
+{
+ vexterr(doexterr, code, fmt, ap);
if (err_exit)
err_exit(eval);
exit(eval);
@@ -161,17 +185,16 @@ warnc(int code, const char *fmt, ...)
void
vwarnc(int code, const char *fmt, va_list ap)
{
+ vwarnci(false, code, fmt, ap);
+}
+
+static void
+vwarnci(bool doexterr, int code, const char *fmt, va_list ap)
+{
int saved_errno;
saved_errno = errno;
- if (err_file == NULL)
- err_set_file(NULL);
- fprintf(err_file, "%s: ", _getprogname());
- if (fmt != NULL) {
- vfprintf(err_file, fmt, ap);
- fprintf(err_file, ": ");
- }
- fprintf(err_file, "%s\n", strerror(code));
+ vexterr(doexterr, code, fmt, ap);
errno = saved_errno;
}
diff --git a/lib/libc/gen/errlst.c b/lib/libc/gen/errlst.c
index bc673e8c9c66..a73fa06feb5e 100644
--- a/lib/libc/gen/errlst.c
+++ b/lib/libc/gen/errlst.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)errlst.c 8.2 (Berkeley) 11/16/93");
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <stdio.h>
#include "errlst.h"
diff --git a/lib/libc/gen/eventfd.c b/lib/libc/gen/eventfd.c
index b757f82029a9..44a33915c2fb 100644
--- a/lib/libc/gen/eventfd.c
+++ b/lib/libc/gen/eventfd.c
@@ -2,7 +2,7 @@
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2005-2020 Rich Felker, et al.
- * Copyright (c) 2020 Greg V
+ * Copyright (c) 2020 Val Packett
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -24,9 +24,6 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/eventfd.h>
#include <sys/specialfd.h>
diff --git a/lib/libc/gen/exec.3 b/lib/libc/gen/exec.3
index 37954fe1bf75..41ab18fa89ef 100644
--- a/lib/libc/gen/exec.3
+++ b/lib/libc/gen/exec.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)exec.3 8.3 (Berkeley) 1/24/94
-.\" $FreeBSD$
-.\"
-.Dd March 22, 2020
+.Dd December 11, 2023
.Dt EXEC 3
.Os
.Sh NAME
@@ -38,6 +35,7 @@
.Nm exect ,
.Nm execv ,
.Nm execvp ,
+.Nm execvpe ,
.Nm execvP
.Nd execute a file
.Sh LIBRARY
@@ -51,7 +49,6 @@
.Fn execlp "const char *file" "const char *arg" ... NULL
.Ft int
.Fn execle "const char *path" "const char *arg" ... NULL "char *const envp[]"
-.Fc
.Ft int
.Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
.Ft int
@@ -59,6 +56,8 @@
.Ft int
.Fn execvp "const char *file" "char *const argv[]"
.Ft int
+.Fn execvpe "const char *file" "char *const argv[]" "char *const envp[]"
+.Ft int
.Fn execvP "const char *file" "const char *search_path" "char *const argv[]"
.Sh DESCRIPTION
The
@@ -100,6 +99,7 @@ The
.Fn exect ,
.Fn execv ,
.Fn execvp ,
+.Fn execvpe ,
and
.Fn execvP
functions provide an array of pointers to null-terminated strings that
@@ -113,9 +113,10 @@ be terminated by a
pointer.
.Pp
The
-.Fn execle
+.Fn execle ,
+.Fn exect ,
and
-.Fn exect
+.Fn execvpe
functions also specify the environment of the executed process by following
the
.Dv NULL
@@ -137,6 +138,7 @@ Some of these functions have special semantics.
The functions
.Fn execlp ,
.Fn execvp ,
+.Fn execvpe ,
and
.Fn execvP
will duplicate the actions of the shell in searching for an executable file
@@ -147,6 +149,7 @@ For
.Fn execlp
and
.Fn execvp ,
+.Fn execvpe ,
search path is the path specified in the environment by
.Dq Ev PATH
variable.
@@ -272,7 +275,8 @@ The
.Fn execl ,
.Fn execle ,
.Fn execlp ,
-.Fn execvp
+.Fn execvp ,
+.Fn execvpe ,
and
.Fn execvP
functions
@@ -310,6 +314,9 @@ and
functions
conform to
.St -p1003.1-88 .
+The
+.Fn execvpe
+function is a GNU extension.
.Sh HISTORY
The
.Fn exec
@@ -333,6 +340,10 @@ The
.Fn execvP
function first appeared in
.Fx 5.2 .
+The
+.Fn execvpe
+function first appeared in
+.Fx 14.1 .
.Sh BUGS
The type of the
.Fa argv
@@ -343,6 +354,7 @@ parameters to
.Fn exect ,
.Fn execv ,
.Fn execvp ,
+.Fn execvpe ,
and
.Fn execvP
is a historical accident and no sane implementation should modify the provided
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c
index 2c703bb4e73e..12020a79f6b4 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -29,15 +29,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)exec.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/stat.h>
+#include <assert.h>
#include <errno.h>
#include <unistd.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -47,8 +45,6 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
-extern char **environ;
-
static const char execvPe_err_preamble[] = "execvP: ";
static const char execvPe_err_trailer[] = ": path too long\n";
@@ -142,29 +138,132 @@ execv(const char *name, char * const *argv)
int
execvp(const char *name, char * const *argv)
{
- return (_execvpe(name, argv, environ));
+ return (__libc_execvpe(name, argv, environ));
+}
+
+/*
+ * Returns 0 if we don't consider this a terminal condition, -1 if we do.
+ */
+static int
+execvPe_prog(const char *path, char * const *argv, char * const *envp)
+{
+ struct stat sb;
+ const char **memp;
+ size_t cnt;
+ int save_errno;
+
+ (void)_execve(path, argv, envp);
+ /* Grouped roughly by never terminal vs. usually terminal conditions */
+ switch (errno) {
+ case ELOOP:
+ case ENAMETOOLONG:
+ case ENOENT:
+ case ENOTDIR:
+ /* Non-terminal: property of the path we're trying */
+ break;
+ case ENOEXEC:
+ /*
+ * Failures here are considered terminal because we must handle
+ * this via the ENOEXEC fallback path; doing any further
+ * searching would be categorically incorrect.
+ */
+
+ for (cnt = 0; argv[cnt] != NULL; ++cnt)
+ ;
+
+ /*
+ * cnt may be 0 above; always allocate at least
+ * 3 entries so that we can at least fit "sh", path, and
+ * the NULL terminator. We can rely on cnt to take into
+ * account the NULL terminator in all other scenarios,
+ * as we drop argv[0].
+ */
+ memp = alloca(MAX(3, cnt + 2) * sizeof(char *));
+ assert(memp != NULL);
+ if (cnt > 0) {
+ memp[0] = argv[0];
+ memp[1] = path;
+ memcpy(&memp[2], &argv[1], cnt * sizeof(char *));
+ } else {
+ memp[0] = "sh";
+ memp[1] = path;
+ memp[2] = NULL;
+ }
+
+ (void)_execve(_PATH_BSHELL, __DECONST(char **, memp), envp);
+ return (-1);
+ case ENOMEM:
+ case E2BIG:
+ /* Terminal: persistent condition */
+ return (-1);
+ case ETXTBSY:
+ /*
+ * Terminal: we used to retry here, but sh(1) doesn't.
+ */
+ return (-1);
+ default:
+ /*
+ * EACCES may be for an inaccessible directory or
+ * a non-executable file. Call stat() to decide
+ * which. This also handles ambiguities for EFAULT
+ * and EIO, and undocumented errors like ESTALE.
+ * We hope that the race for a stat() is unimportant.
+ */
+ save_errno = errno;
+ if (stat(path, &sb) == -1) {
+ /*
+ * We force errno to ENOENT here to disambiguate the
+ * EACCESS case; the results of execve(2) are somewhat
+ * inconclusive because either the file did not exist or
+ * we just don't have search permissions, but the caller
+ * only really wants to see EACCES if the file did exist
+ * but was not accessible.
+ */
+ if (save_errno == EACCES)
+ errno = ENOENT;
+ break;
+ }
+
+ errno = save_errno;
+
+ /*
+ * Non-terminal: the file did exist and we just didn't have
+ * access to it, so we surface the EACCES and let the search
+ * continue for a candidate that we do have access to.
+ */
+ if (errno == EACCES)
+ break;
+
+ /*
+ * All other errors here are terminal, as prescribed by exec(3).
+ */
+ return (-1);
+ }
+
+ return (0);
}
static int
execvPe(const char *name, const char *path, char * const *argv,
char * const *envp)
{
- const char **memp;
- size_t cnt, lp, ln;
- int eacces, save_errno;
char buf[MAXPATHLEN];
- const char *bp, *np, *op, *p;
- struct stat sb;
+ size_t ln, lp;
+ const char *np, *op, *p;
+ bool eacces;
- eacces = 0;
+ eacces = false;
/* If it's an absolute or relative path name, it's easy. */
- if (strchr(name, '/')) {
- bp = name;
- op = NULL;
- goto retry;
+ if (strchr(name, '/') != NULL) {
+ /*
+ * We ignore non-terminal conditions because we don't have any
+ * further paths to try -- we can just bubble up the errno from
+ * execve(2) here.
+ */
+ (void)execvPe_prog(name, argv, envp);
+ return (-1);
}
- bp = buf;
/* If it's an empty path name, fail in the usual POSIX way. */
if (*name == '\0') {
@@ -198,9 +297,13 @@ execvPe(const char *name, const char *path, char * const *argv,
op = np + 1;
/*
- * If the path is too long complain. This is a possible
- * security issue; given a way to make the path too long
- * the user may execute the wrong program.
+ * If the path is too long, then complain. This is a possible
+ * security issue: given a way to make the path too long, the
+ * user may execute the wrong program.
+ *
+ * Remember to exercise caution here with assembling our final
+ * buf and any output, as we may be running in a vfork() context
+ * via posix_spawnp().
*/
if (lp + ln + 2 > sizeof(buf)) {
(void)_write(STDERR_FILENO, execvPe_err_preamble,
@@ -208,82 +311,40 @@ execvPe(const char *name, const char *path, char * const *argv,
(void)_write(STDERR_FILENO, p, lp);
(void)_write(STDERR_FILENO, execvPe_err_trailer,
sizeof(execvPe_err_trailer) - 1);
+
continue;
}
- bcopy(p, buf, lp);
+
+ memcpy(&buf[0], p, lp);
buf[lp] = '/';
- bcopy(name, buf + lp + 1, ln);
+ memcpy(&buf[lp + 1], name, ln);
buf[lp + ln + 1] = '\0';
-retry: (void)_execve(bp, argv, envp);
- switch (errno) {
- case E2BIG:
- goto done;
- case ELOOP:
- case ENAMETOOLONG:
- case ENOENT:
- break;
- case ENOEXEC:
- for (cnt = 0; argv[cnt]; ++cnt)
- ;
-
- /*
- * cnt may be 0 above; always allocate at least
- * 3 entries so that we can at least fit "sh", bp, and
- * the NULL terminator. We can rely on cnt to take into
- * account the NULL terminator in all other scenarios,
- * as we drop argv[0].
- */
- memp = alloca(MAX(3, cnt + 2) * sizeof(char *));
- if (memp == NULL) {
- /* errno = ENOMEM; XXX override ENOEXEC? */
- goto done;
- }
- if (cnt > 0) {
- memp[0] = argv[0];
- memp[1] = bp;
- bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
- } else {
- memp[0] = "sh";
- memp[1] = bp;
- memp[2] = NULL;
- }
- (void)_execve(_PATH_BSHELL,
- __DECONST(char **, memp), envp);
- goto done;
- case ENOMEM:
- goto done;
- case ENOTDIR:
- break;
- case ETXTBSY:
- /*
- * We used to retry here, but sh(1) doesn't.
- */
- goto done;
- default:
- /*
- * EACCES may be for an inaccessible directory or
- * a non-executable file. Call stat() to decide
- * which. This also handles ambiguities for EFAULT
- * and EIO, and undocumented errors like ESTALE.
- * We hope that the race for a stat() is unimportant.
- */
- save_errno = errno;
- if (stat(bp, &sb) != 0)
- break;
- if (save_errno == EACCES) {
- eacces = 1;
- continue;
- }
- errno = save_errno;
- goto done;
- }
+ /*
+ * For terminal conditions we can just return immediately. If
+ * it was non-terminal, we just need to note if we had an
+ * EACCES -- execvPe_prog would do a stat(2) and leave us with
+ * an errno of EACCES only if the file did exist; otherwise it
+ * would coerce it to an ENOENT because we may not know if a
+ * file actually existed there or not.
+ */
+ if (execvPe_prog(buf, argv, envp) == -1)
+ return (-1);
+ if (errno == EACCES)
+ eacces = true;
}
+
+ /*
+ * We don't often preserve errors encountering during the PATH search,
+ * so we override it here. ENOENT would be misleading if we found a
+ * candidate but couldn't access it, but most of the other conditions
+ * are either terminal or indicate that nothing was there.
+ */
if (eacces)
errno = EACCES;
else
errno = ENOENT;
-done:
+
return (-1);
}
@@ -294,7 +355,7 @@ execvP(const char *name, const char *path, char * const argv[])
}
int
-_execvpe(const char *name, char * const argv[], char * const envp[])
+__libc_execvpe(const char *name, char * const argv[], char * const envp[])
{
const char *path;
@@ -304,3 +365,5 @@ _execvpe(const char *name, char * const argv[], char * const envp[])
return (execvPe(name, path, argv, envp));
}
+
+__weak_reference(__libc_execvpe, execvpe);
diff --git a/lib/libc/gen/exect.c b/lib/libc/gen/exect.c
index b878d8cac085..e5be7a4d8755 100644
--- a/lib/libc/gen/exect.c
+++ b/lib/libc/gen/exect.c
@@ -24,9 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/ptrace.h>
#include <errno.h>
diff --git a/lib/libc/gen/fdevname.c b/lib/libc/gen/fdevname.c
index 217448fe2f59..62e71e98af63 100644
--- a/lib/libc/gen/fdevname.c
+++ b/lib/libc/gen/fdevname.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/ioctl.h>
diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/fdopendir.c
index b4fc17ee8113..9393cbe28f85 100644
--- a/lib/libc/gen/wait.c
+++ b/lib/libc/gen/fdopendir.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
- * Copyright (c) 1988, 1993
+ * Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,28 +29,35 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)wait.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include "un-namespace.h"
+#include <sys/stat.h>
-#include "libc_private.h"
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include "un-namespace.h"
-pid_t __wait(int *);
+#include "gen-private.h"
+#include "telldir.h"
-pid_t
-__wait(int *istat)
+/*
+ * Open a directory with existing file descriptor.
+ */
+DIR *
+fdopendir(int fd)
{
+ int flags, rc;
- return (((pid_t (*)(pid_t, int *, int, struct rusage *))
- __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, 0, NULL));
-}
+ flags = _fcntl(fd, F_GETFD, 0);
+ if (flags == -1)
+ return (NULL);
-__weak_reference(__wait, wait);
-__weak_reference(__wait, _wait);
+ if ((flags & FD_CLOEXEC) == 0) {
+ rc = _fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+ if (rc == -1)
+ return (NULL);
+ }
+ return (__opendir_common(fd, DTF_HIDEW | DTF_NODUP, true));
+}
diff --git a/lib/libc/gen/feature_present.3 b/lib/libc/gen/feature_present.3
index 3a702d441df2..3741ea0d3975 100644
--- a/lib/libc/gen/feature_present.3
+++ b/lib/libc/gen/feature_present.3
@@ -26,8 +26,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd January 8, 2008
.Dt FEATURE_PRESENT 3
.Os
diff --git a/lib/libc/gen/feature_present.c b/lib/libc/gen/feature_present.c
index 3615d50f2349..4c0b41cfb23e 100644
--- a/lib/libc/gen/feature_present.c
+++ b/lib/libc/gen/feature_present.c
@@ -30,9 +30,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>
diff --git a/lib/libc/gen/fmtcheck.3 b/lib/libc/gen/fmtcheck.3
index 0bd429982ead..07982f28b296 100644
--- a/lib/libc/gen/fmtcheck.3
+++ b/lib/libc/gen/fmtcheck.3
@@ -23,8 +23,6 @@
.\" 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.
-.\"
-.\" $FreeBSD$
.Dd October 16, 2002
.Dt FMTCHECK 3
.Os
diff --git a/lib/libc/gen/fmtcheck.c b/lib/libc/gen/fmtcheck.c
index a772f50e51c8..de889ad3421c 100644
--- a/lib/libc/gen/fmtcheck.c
+++ b/lib/libc/gen/fmtcheck.c
@@ -1,7 +1,7 @@
/* $NetBSD: fmtcheck.c,v 1.8 2008/04/28 20:22:59 martin Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -30,9 +30,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdio.h>
#include <string.h>
#include <ctype.h>
diff --git a/lib/libc/gen/fmtmsg.3 b/lib/libc/gen/fmtmsg.3
index 7995d7bd31c5..e50ab317e1aa 100644
--- a/lib/libc/gen/fmtmsg.3
+++ b/lib/libc/gen/fmtmsg.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd August 5, 2002
.Dt FMTMSG 3
.Os
diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c
index c5246561e0aa..9edeee4405ce 100644
--- a/lib/libc/gen/fmtmsg.c
+++ b/lib/libc/gen/fmtmsg.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <fmtmsg.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/fnmatch.3 b/lib/libc/gen/fnmatch.3
index 8cc0ef9551f1..7f020fec58e3 100644
--- a/lib/libc/gen/fnmatch.3
+++ b/lib/libc/gen/fnmatch.3
@@ -27,10 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fnmatch.3 8.3 (Berkeley) 4/28/95
-.\" $FreeBSD$
-.\"
-.Dd April 2, 2022
+.Dd April 7, 2025
.Dt FNMATCH 3
.Os
.Sh NAME
@@ -132,12 +129,8 @@ otherwise, it returns the value
.Sh STANDARDS
The current implementation of the
.Fn fnmatch
-function
-.Em does not
-conform to
+function is expected to conform to
.St -p1003.2 .
-Collating symbol expressions, equivalence class expressions and
-character class expressions are not supported.
.Sh HISTORY
A predecessor to
.Fn fnmatch ,
diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c
index 406705459938..1c583a9d23e2 100644
--- a/lib/libc/gen/fnmatch.c
+++ b/lib/libc/gen/fnmatch.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)fnmatch.c 8.2 (Berkeley) 4/16/94");
-__FBSDID("$FreeBSD$");
-
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
@@ -71,7 +67,8 @@ __FBSDID("$FreeBSD$");
#define RANGE_NOMATCH 0
#define RANGE_ERROR (-1)
-static int rangematch(const char *, wchar_t, int, char **, mbstate_t *);
+static int rangematch(const char *, wchar_t, const char *, int, char **,
+ char **, mbstate_t *, mbstate_t *);
static int fnmatch1(const char *, const char *, const char *, int, mbstate_t,
mbstate_t);
@@ -89,7 +86,7 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart,
{
const char *bt_pattern, *bt_string;
mbstate_t bt_patmbs, bt_strmbs;
- char *newp;
+ char *newp, *news;
char c;
wchar_t pc, sc;
size_t pclen, sclen;
@@ -155,8 +152,10 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart,
* there is no way having it match more characters
* can help us, given that we are already here.
*/
- bt_pattern = pattern, bt_patmbs = patmbs;
- bt_string = string, bt_strmbs = strmbs;
+ bt_pattern = pattern;
+ bt_patmbs = patmbs;
+ bt_string = string;
+ bt_strmbs = strmbs;
break;
case '[':
if (sc == EOS)
@@ -168,17 +167,17 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart,
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
goto backtrack;
- switch (rangematch(pattern, sc, flags, &newp,
- &patmbs)) {
+ switch (rangematch(pattern, sc, string + sclen, flags,
+ &newp, &news, &patmbs, &strmbs)) {
case RANGE_ERROR:
goto norm;
case RANGE_MATCH:
pattern = newp;
+ string = news;
break;
case RANGE_NOMATCH:
goto backtrack;
}
- string += sclen;
break;
case '\\':
if (!(flags & FNM_NOESCAPE)) {
@@ -222,8 +221,10 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart,
if (sc == '/' && flags & FNM_PATHNAME)
return (FNM_NOMATCH);
bt_string += sclen;
- pattern = bt_pattern, patmbs = bt_patmbs;
- string = bt_string, strmbs = bt_strmbs;
+ pattern = bt_pattern;
+ patmbs = bt_patmbs;
+ string = bt_string;
+ strmbs = bt_strmbs;
}
break;
}
@@ -232,15 +233,20 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart,
}
static int
-rangematch(const char *pattern, wchar_t test, int flags, char **newp,
- mbstate_t *patmbs)
+rangematch(const char *pattern, wchar_t test, const char *string, int flags,
+ char **newp, char **news, mbstate_t *patmbs, mbstate_t *strmbs)
{
int negate, ok;
wchar_t c, c2;
size_t pclen;
const char *origpat;
struct xlocale_collate *table =
- (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
+ (struct xlocale_collate *)__get_locale()->components[XLC_COLLATE];
+ wchar_t buf[COLLATE_STR_LEN]; /* STR_LEN defined in collate.h */
+ const char *cp, *savestring;
+ int special;
+ mbstate_t save;
+ size_t sclen, len;
/*
* A bracket expression starting with an unquoted circumflex
@@ -263,20 +269,132 @@ rangematch(const char *pattern, wchar_t test, int flags, char **newp,
ok = 0;
origpat = pattern;
for (;;) {
+ c = 0;
if (*pattern == ']' && pattern > origpat) {
- pattern++;
break;
} else if (*pattern == '\0') {
return (RANGE_ERROR);
} else if (*pattern == '/' && (flags & FNM_PATHNAME)) {
return (RANGE_NOMATCH);
- } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE))
+ } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE)) {
pattern++;
- pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs);
- if (pclen == (size_t)-1 || pclen == (size_t)-2)
- return (RANGE_NOMATCH);
- pattern += pclen;
+ } else if (*pattern == '[' &&
+ ((special = *(pattern + 1)) == '.' ||
+ special == '=' || special == ':')) {
+ cp = (pattern += 2);
+ while ((cp = strchr(cp, special))) {
+ if (*(cp + 1) == ']')
+ break;
+ cp++;
+ }
+ if (!cp)
+ return (RANGE_ERROR);
+ if (special == '.') {
+treat_like_collating_symbol:
+ len = __collate_collating_symbol(buf,
+ COLLATE_STR_LEN, pattern,
+ cp - pattern, patmbs);
+ if (len == (size_t)-1 || len == 0)
+ return (RANGE_ERROR);
+ pattern = cp + 2;
+ if (len > 1) {
+ wchar_t *wp, sc;
+ /*
+ * No multi-character collation
+ * symbols as start of range.
+ */
+ if (*(cp + 2) == '-' &&
+ *(cp + 3) != EOS &&
+ *(cp + 3) != ']')
+ return (RANGE_ERROR);
+ wp = buf;
+ if (test != *wp++)
+ continue;
+ if (len == 1) {
+ ok = 1;
+ break;
+ }
+ memcpy(&save, strmbs, sizeof(save));
+ savestring = string;
+ while (--len > 0) {
+ sclen = mbrtowc(&sc, string,
+ MB_LEN_MAX, strmbs);
+ if (sclen == (size_t)-1 ||
+ sclen == (size_t)-2) {
+ sc = (unsigned char)*string;
+ sclen = 1;
+ memset(&strmbs, 0,
+ sizeof(strmbs));
+ }
+ if (sc != *wp++) {
+ memcpy(strmbs, &save,
+ sizeof(save));
+ string = savestring;
+ break;
+ }
+ string += sclen;
+ }
+ if (len == 0) {
+ ok = 1;
+ break;
+ }
+ continue; /* no match */
+ }
+ c = *buf;
+ } else if (special == '=') {
+ int ec;
+ memcpy(&save, patmbs, sizeof(save));
+ ec = __collate_equiv_class(pattern,
+ cp - pattern, patmbs);
+ if (ec < 0)
+ return (RANGE_ERROR);
+ if (ec == 0) {
+ memcpy(patmbs, &save, sizeof(save));
+ goto treat_like_collating_symbol;
+ }
+ pattern = cp + 2;
+ /* no equivalence classes as start of range */
+ if (*(cp + 2) == '-' && *(cp + 3) != EOS &&
+ *(cp + 3) != ']')
+ return (RANGE_ERROR);
+ len = __collate_equiv_match(ec, NULL, 0, test,
+ string, strlen(string), strmbs, &sclen);
+ if (len < 0)
+ return (RANGE_ERROR);
+ if (len > 0) {
+ ok = 1;
+ string += sclen;
+ break;
+ }
+ continue;
+ } else { /* special == ':' */
+ wctype_t charclass;
+ char name[CHARCLASS_NAME_MAX + 1];
+ /* no character classes as start of range */
+ if (*(cp + 2) == '-' && *(cp + 3) != EOS &&
+ *(cp + 3) != ']')
+ return (RANGE_ERROR);
+ /* assume character class names are ascii */
+ if (cp - pattern > CHARCLASS_NAME_MAX)
+ return (RANGE_ERROR);
+ strlcpy(name, pattern, cp - pattern + 1);
+ pattern = cp + 2;
+ if ((charclass = wctype(name)) == 0)
+ return (RANGE_ERROR);
+ if (iswctype(test, charclass)) {
+ ok = 1;
+ break;
+ }
+ continue;
+ }
+ }
+ if (!c) {
+ pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (RANGE_NOMATCH);
+ pattern += pclen;
+ }
if (flags & FNM_CASEFOLD)
c = towlower(c);
@@ -292,6 +410,37 @@ rangematch(const char *pattern, wchar_t test, int flags, char **newp,
if (c2 == EOS)
return (RANGE_ERROR);
+ if ((c2 == '[' && (special = *pattern) == '.') ||
+ special == '=' || special == ':') {
+
+ /*
+ * No equivalence classes or character
+ * classes as end of range.
+ */
+ if (special == '=' || special == ':')
+ return (RANGE_ERROR);
+ cp = ++pattern;
+ while ((cp = strchr(cp, special))) {
+ if (*(cp + 1) == ']')
+ break;
+ cp++;
+ }
+ if (!cp)
+ return (RANGE_ERROR);
+ len = __collate_collating_symbol(buf,
+ COLLATE_STR_LEN, pattern,
+ cp - pattern, patmbs);
+
+ /*
+ * No multi-character collation symbols
+ * as end of range.
+ */
+ if (len != 1)
+ return (RANGE_ERROR);
+ pattern = cp + 2;
+ c2 = *buf;
+ }
+
if (flags & FNM_CASEFOLD)
c2 = towlower(c2);
@@ -299,12 +448,44 @@ rangematch(const char *pattern, wchar_t test, int flags, char **newp,
c <= test && test <= c2 :
__wcollate_range_cmp(c, test) <= 0
&& __wcollate_range_cmp(test, c2) <= 0
- )
+ ) {
ok = 1;
- } else if (c == test)
+ break;
+ }
+ } else if (c == test) {
ok = 1;
+ break;
+ }
}
- *newp = (char *)pattern;
+ /* go to end of bracket expression */
+ special = 0;
+ while (*pattern != ']') {
+ if (*pattern == 0)
+ return (RANGE_ERROR);
+ if (*pattern == special) {
+ if (*++pattern == ']') {
+ special = 0;
+ pattern++;
+ }
+ continue;
+ }
+ if (!special && *pattern == '[') {
+ special = *++pattern;
+ if (special != '.' && special != '=' && special != ':')
+ special = 0;
+ else
+ pattern++;
+ continue;
+ }
+ pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (RANGE_NOMATCH);
+ pattern += pclen;
+ }
+
+ *newp = (char *)++pattern;
+ *news = (char *)string;
+
return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
}
diff --git a/lib/libc/gen/fpclassify.3 b/lib/libc/gen/fpclassify.3
index a547eeb45466..5a5228463b3c 100644
--- a/lib/libc/gen/fpclassify.3
+++ b/lib/libc/gen/fpclassify.3
@@ -22,8 +22,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd January 26, 2005
.Dt FPCLASSIFY 3
.Os
diff --git a/lib/libc/gen/fpclassify.c b/lib/libc/gen/fpclassify.c
index 998656938936..876cb253a742 100644
--- a/lib/libc/gen/fpclassify.c
+++ b/lib/libc/gen/fpclassify.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
* Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
@@ -25,8 +25,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <sys/endian.h>
diff --git a/lib/libc/gen/frexp.3 b/lib/libc/gen/frexp.3
index 36f526c5b683..1424ac888ad6 100644
--- a/lib/libc/gen/frexp.3
+++ b/lib/libc/gen/frexp.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)frexp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd March 4, 2005
.Dt FREXP 3
.Os
diff --git a/lib/libc/gen/frexp.c b/lib/libc/gen/frexp.c
index e65332a0bdde..4207d5d7e9b7 100644
--- a/lib/libc/gen/frexp.c
+++ b/lib/libc/gen/frexp.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <math.h>
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index 3813202afb15..ae21b4696883 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)fstab.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/mount.h>
@@ -259,12 +255,8 @@ setfsent(void)
LineNo = 0;
return (1);
}
- if (fsp_set == 0) {
- if (issetugid())
- setfstab(NULL);
- else
- setfstab(getenv("PATH_FSTAB"));
- }
+ if (fsp_set == 0)
+ setfstab(secure_getenv("PATH_FSTAB"));
if ((_fs_fp = fopen(path_fstab, "re")) != NULL) {
LineNo = 0;
return (1);
diff --git a/lib/libc/gen/ftok.3 b/lib/libc/gen/ftok.3
index b819dbd185d4..490d93cc1f67 100644
--- a/lib/libc/gen/ftok.3
+++ b/lib/libc/gen/ftok.3
@@ -22,9 +22,7 @@
.\" 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.
-.\"
-.\" $FreeBSD$
-.Dd July 9, 2009
+.Dd November 28, 2022
.Dt FTOK 3
.Os
.Sh NAME
@@ -33,7 +31,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In sys/ipc.h
.Ft key_t
.Fn ftok "const char *path" "int id"
diff --git a/lib/libc/gen/ftok.c b/lib/libc/gen/ftok.c
index 6ea7dadbdd0e..04fa5d464fb0 100644
--- a/lib/libc/gen/ftok.c
+++ b/lib/libc/gen/ftok.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
* All rights reserved.
@@ -27,9 +27,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
index 9f295110f1c7..62a1e0a81f62 100644
--- a/lib/libc/gen/fts-compat.c
+++ b/lib/libc/gen/fts-compat.c
@@ -27,14 +27,9 @@
* 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.
- *
- * From: @(#)fts.c 8.6 (Berkeley) 8/14/94
* From: $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#define _WANT_FREEBSD11_STATFS
@@ -49,9 +44,9 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "gen-compat.h"
#include "fts-compat.h"
#include "un-namespace.h"
+#include "gen-compat.h"
#include "gen-private.h"
diff --git a/lib/libc/gen/fts-compat.h b/lib/libc/gen/fts-compat.h
index 6367ec9ebc4b..d522e3befedb 100644
--- a/lib/libc/gen/fts-compat.h
+++ b/lib/libc/gen/fts-compat.h
@@ -27,9 +27,6 @@
* 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.
- *
- * @(#)fts.h 8.3 (Berkeley) 8/14/94
- * $FreeBSD$
*/
#ifndef _FTS_H_
diff --git a/lib/libc/gen/fts-compat11.c b/lib/libc/gen/fts-compat11.c
index a18ce3f00a6a..5abb378f5f08 100644
--- a/lib/libc/gen/fts-compat11.c
+++ b/lib/libc/gen/fts-compat11.c
@@ -25,14 +25,9 @@
* 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.
- *
- * From: @(#)fts.c 8.6 (Berkeley) 8/14/94
* From: $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#define _WANT_FREEBSD11_STATFS
@@ -48,9 +43,9 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "gen-compat.h"
#include "fts-compat11.h"
#include "un-namespace.h"
+#include "gen-compat.h"
#include "gen-private.h"
diff --git a/lib/libc/gen/fts-compat11.h b/lib/libc/gen/fts-compat11.h
index 52c0637395fb..f53e312374c5 100644
--- a/lib/libc/gen/fts-compat11.h
+++ b/lib/libc/gen/fts-compat11.h
@@ -25,9 +25,6 @@
* 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.
- *
- * @(#)fts.h 8.3 (Berkeley) 8/14/94
- * $FreeBSD$
*/
#ifndef _FTS_COPMAT11_H_
diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3
index bba6f61094d5..da304e59ee72 100644
--- a/lib/libc/gen/fts.3
+++ b/lib/libc/gen/fts.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)fts.3 8.5 (Berkeley) 4/16/94
-.\" $FreeBSD$
-.\"
-.Dd January 12, 2014
+.Dd October 6, 2025
.Dt FTS 3
.Os
.Sh NAME
@@ -40,6 +37,8 @@
.In fts.h
.Ft FTS *
.Fn fts_open "char * const *path_argv" "int options" "int (*compar)(const FTSENT * const *, const FTSENT * const *)"
+.Ft FTS *
+.Fn fts_open_b "char * const *path_argv" "int options" "int (^compar)(const FTSENT * const *, const FTSENT * const *)"
.Ft FTSENT *
.Fn fts_read "FTS *ftsp"
.Ft FTSENT *
@@ -62,20 +61,23 @@ functions are provided for traversing
file hierarchies.
A simple overview is that the
.Fn fts_open
-function returns a
+and
+.Fn fts_open_b
+functions return a
.Dq handle
on a file hierarchy, which is then supplied to
the other
.Nm
functions.
-The function
+The
.Fn fts_read
-returns a pointer to a structure describing one of the files in the file
-hierarchy.
-The function
+function returns a pointer to a structure describing one of the files
+in the file hierarchy.
+The
.Fn fts_children
-returns a pointer to a linked list of structures, each of which describes
-one of the files contained in a directory in the hierarchy.
+function returns a pointer to a linked list of structures, each of
+which describes one of the files contained in a directory in the
+hierarchy.
In general, directories are visited two distinguishable times; in pre-order
(before any of their descendants are visited) and in post-order (after all
of their descendants have been visited).
@@ -179,6 +181,12 @@ by one of the other
values.
.It Dv FTS_DNR
A directory which cannot be read.
+This immediately follows
+.Dv FTS_D ,
+in place of
+.Dv FTS_DP ,
+when the directory could not be entered, or could be entered but not
+read.
This is an error return, and the
.Fa fts_errno
field will be set to indicate what caused the error.
@@ -189,6 +197,8 @@ or
.Ql ..\&
which was not specified as a file name to
.Fn fts_open
+or
+.Fn fts_open_b
(see
.Dv FTS_SEEDOT ) .
.It Dv FTS_DP
@@ -237,6 +247,8 @@ A path for accessing the file from the current directory.
The path for the file relative to the root of the traversal.
This path contains the path specified to
.Fn fts_open
+or
+.Fn fts_open_b
as a prefix.
.It Fa fts_pathlen
The length of the string referenced by
@@ -365,7 +377,44 @@ The
.Fa fts_name
field is always
.Dv NUL Ns -terminated .
-.Sh FTS_OPEN
+.Ss Thread Safety
+The
+.Nm
+functions can safely be used in multi-threaded programs provided no
+two threads access the same
+.Vt FTS
+or
+.Vt FTSENT
+structure simultaneously.
+However, unless the
+.Dv FTS_NOCHDIR
+flag was passed to
+.Fn fts_open
+or
+.Fn fts_open_b ,
+calls to
+.Fn fts_read
+and
+.Fn fts_children
+may change the current working directory, which will affect all
+threads.
+Conversely, changing the current working directory either during or
+between calls to
+.Fn fts_read
+or
+.Fn fts_children
+(even in a single-thread program) may cause
+.Nm
+to malfunction unless the
+.Dv FTS_NOCHDIR
+flag was passed to
+.Fn fts_open
+or
+.Fn fts_open_b
+and all paths in
+.Va path_argv
+were absolute.
+.Ss Fn fts_open
The
.Fn fts_open
function takes a pointer to an array of character pointers naming one
@@ -383,12 +432,16 @@ must be specified.
The options are selected by
.Em or Ns 'ing
the following values:
-.Bl -tag -width "FTS_PHYSICAL"
+.Bl -tag -width "FTS_COMFOLLOWDIR"
.It Dv FTS_COMFOLLOW
This option causes any symbolic link specified as a root path to be
followed immediately whether or not
.Dv FTS_LOGICAL
is also specified.
+.It Dv FTS_COMFOLLOWDIR
+This option is similar to
+.Dv FTS_COMFOLLOW ,
+but only follows symbolic links to directories.
.It Dv FTS_LOGICAL
This option causes the
.Nm
@@ -444,6 +497,15 @@ field to
and leave the contents of the
.Fa statp
field undefined.
+.It Dv FTS_NOSTAT_TYPE
+This option is similar to
+.Dv FTS_NOSTAT ,
+but attempts to populate
+.Fa fts_info
+based on information from the
+.Fa d_type
+field of
+.Vt struct dirent .
.It Dv FTS_PHYSICAL
This option causes the
.Nm
@@ -483,10 +545,10 @@ from descending into directories that have a different device number
than the file from which the descent began.
.El
.Pp
-The argument
-.Fn compar
-specifies a user-defined function which may be used to order the traversal
-of the hierarchy.
+The
+.Fa compar
+argument points to a user-defined function which may be used to order
+the traversal of the hierarchy.
It
takes two pointers to pointers to
.Vt FTSENT
@@ -521,7 +583,16 @@ the directory traversal order is in the order listed in
.Fa path_argv
for the root paths, and in the order listed in the directory for
everything else.
-.Sh FTS_READ
+.Ss Fn fts_open_b
+The
+.Fn fts_open_b
+function is identical to
+.Fn fts_open
+except that it takes a block pointer instead of a function pointer.
+The block is copied before
+.Fn fts_open_b
+returns, so the original can safely go out of scope or be released.
+.Ss Fn fts_read
The
.Fn fts_read
function returns a pointer to an
@@ -555,6 +626,15 @@ structure is returned, and
.Va errno
may or may not have been set (see
.Fa fts_info ) .
+Note that
+.Fn fts_read
+will not set
+.Va errno
+to 0 if called again with the same
+.Fa ftsp
+argument after the
+.Dv FTS_STOP
+flag has been set or the end of the stream has been reached.
.Pp
The
.Vt FTSENT
@@ -569,10 +649,10 @@ directory, in which case they will not be overwritten until after a call to
.Fn fts_read
after the
.Vt FTSENT
-structure has been returned by the function
+structure has been returned by the
.Fn fts_read
-in post-order.
-.Sh FTS_CHILDREN
+function in post-order.
+.Ss Fn fts_children
The
.Fn fts_children
function returns a pointer to an
@@ -596,9 +676,13 @@ As a special case, if
has not yet been called for a hierarchy,
.Fn fts_children
will return a pointer to the files in the logical directory specified to
-.Fn fts_open ,
+.Fn fts_open
+or
+.Fn fts_open_b ,
i.e., the arguments specified to
-.Fn fts_open .
+.Fn fts_open
+or
+.Fn fts_open_b .
Otherwise, if the
.Vt FTSENT
structure most recently returned by
@@ -642,11 +726,11 @@ and
.Fa fts_namelen
fields.
.El
-.Sh FTS_SET
-The function
+.Ss Fn fts_set
+The
.Fn fts_set
-allows the user application to determine further processing for the
-file
+function allows the user application to determine further processing
+for the file
.Fa f
of the stream
.Fa ftsp .
@@ -712,43 +796,156 @@ The file may be one of those most recently returned by either
or
.Fn fts_read .
.El
-.Sh FTS_CLOSE
+.Ss Fn fts_set_clientptr , Fn fts_get_clientptr
+The
+.Fn fts_set_clientptr
+function sets the client data pointer for the stream
+.Fa ftsp
+to
+.Fa clientdata .
+The
+.Fn fts_get_clientptr
+function returns the client data pointer associated with
+.Fa ftsp .
+This can be used to pass per-stream data to the comparison function.
+.Pp
+For performance reasons,
+.Fn fts_get_clientptr
+may be shadowed by a preprocessor macro.
+.Ss Fn fts_get_stream
+The
+.Fn fts_get_stream
+function returns the
+.Nm
+stream associated with the file entry
+.Fa f .
+A typical use for this would be for a comparison function to first call
+.Fn fts_get_stream
+on one of its arguments, then call
+.Fn fts_get_clientptr
+to obtain the client data pointer, which in turn points to information
+necessary to correctly order the two entries.
+.Pp
+For performance reasons,
+.Fn fts_get_stream
+may be shadowed by a preprocessor macro.
+.Ss Fn fts_close
The
.Fn fts_close
function closes a file hierarchy stream
.Fa ftsp
and restores the current directory to the directory from which
.Fn fts_open
+or
+.Fn fts_open_b
was called to open
.Fa ftsp .
+.Sh RETURN VALUES
+The
+.Fn fts_open
+and
+.Fn fts_open_b
+functions return a pointer to the new
+.Nm
+stream on success and
+.Dv NULL
+on failure.
+.Pp
+The
+.Fn fts_read
+function returns a pointer to the next file entry on success, or if an
+error occurs that relates specifically to that file entry.
+On reaching the end of the file hierarchy, it returns
+.Dv NULL
+and sets the external variable
+.Va errno
+to 0.
+On failure, it returns
+.Dv NULL
+and sets
+.Va errno
+to an appropriate non-zero value.
+If called again after the
+.Dv FTS_STOP
+flag has been set or the end of the stream has been reached,
+.Fn fts_read
+returns
+.Dv NULL
+and leaves
+.Va errno
+untouched.
+.Pp
+The
+.Fn fts_children
+function returns a pointer to a linked list of file entries on
+success.
+On reaching the end of the file hierarchy, it returns
+.Dv NULL
+and sets the external variable
+.Va errno
+to 0.
+On failure, it returns
+.Dv NULL
+and sets
+.Va errno
+to an appropriate non-zero value.
+.Pp
+The
+.Fn fts_set
+function returns 0 on success and \-1 if its
+.Fa instr
+argument is invalid.
+.Pp
+The
+.Fn fts_get_clientptr
+function returns the client data pointer associated with its argument,
+or
+.Dv NULL
+if none has been set.
+.Pp
+The
+.Fn fts_get_stream
+function returns a pointer to the
+.Nm
+stream associated with its argument.
+.Pp
The
.Fn fts_close
function
returns 0 on success, and \-1 if an error occurs.
.Sh ERRORS
-The function
+The
.Fn fts_open
-may fail and set
+and
+.Fn fts_open_b
+functions may fail and set
.Va errno
for any of the errors specified for the library functions
.Xr open 2
and
.Xr malloc 3 .
+The
+.Fn fts_open_b
+function may also fail and set
+.Va errno
+to
+.Dv ENOSYS
+if the blocks runtime is missing.
.Pp
-The function
+The
.Fn fts_close
-may fail and set
+function may fail and set
.Va errno
for any of the errors specified for the library functions
.Xr chdir 2
and
.Xr close 2 .
.Pp
-The functions
+The
.Fn fts_read
and
.Fn fts_children
-may fail and set
+functions may fail and set
.Va errno
for any of the errors specified for the library functions
.Xr chdir 2 ,
@@ -758,17 +955,17 @@ for any of the errors specified for the library functions
and
.Xr stat 2 .
.Pp
-In addition,
+In addition, the
.Fn fts_children ,
-.Fn fts_open
+.Fn fts_open ,
and
.Fn fts_set
-may fail and set
+functions may fail and set
.Va errno
as follows:
.Bl -tag -width Er
.It Bq Er EINVAL
-The options were invalid, or the list were empty.
+The options were invalid, or the list was empty.
.El
.Sh SEE ALSO
.Xr find 1 ,
@@ -791,6 +988,13 @@ functions were introduced in
principally to provide for alternative interfaces to the
.Nm
functionality using different data structures.
+Blocks support and the
+.Dv FTS_COMFOLLOWDIR
+and
+.Dv FTS_NOSTAT
+options were added in
+.Fx 15.0
+based on similar functionality in macOS.
.Sh BUGS
The
.Fn fts_open
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index 5186ae047a3b..4aa386d777cd 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -31,10 +31,6 @@
* $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)fts.c 8.6 (Berkeley) 8/14/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/mount.h>
@@ -44,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
+#include <stdalign.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -51,6 +48,19 @@ __FBSDID("$FreeBSD$");
#include "gen-private.h"
+#ifdef __BLOCKS__
+#include <Block.h>
+#else
+#include "block_abi.h"
+typedef DECLARE_BLOCK(int, fts_block,
+ const FTSENT * const *, const FTSENT * const *);
+void qsort_b(void *, size_t, size_t, fts_block);
+#endif /* __BLOCKS__ */
+/* only present if linked with blocks runtime */
+void *_Block_copy(const void *) __weak_symbol;
+void _Block_release(const void *) __weak_symbol;
+extern void *_NSConcreteGlobalBlock[] __weak_symbol;
+
static FTSENT *fts_alloc(FTS *, char *, size_t);
static FTSENT *fts_build(FTS *, int);
static void fts_lfree(FTSENT *);
@@ -96,7 +106,6 @@ struct _fts_private {
* This assumption only holds for UFS-like filesystems that implement
* links and directories this way, so we must punt for others.
*/
-
static const char *ufslike_filesystems[] = {
"ufs",
"zfs",
@@ -105,39 +114,21 @@ static const char *ufslike_filesystems[] = {
0
};
-FTS *
-fts_open(char * const *argv, int options,
- int (*compar)(const FTSENT * const *, const FTSENT * const *))
+static FTS *
+__fts_open(FTS *sp, char * const *argv)
{
- struct _fts_private *priv;
- FTS *sp;
FTSENT *p, *root;
FTSENT *parent, *tmp;
size_t len, nitems;
- /* Options check. */
- if (options & ~FTS_OPTIONMASK) {
- errno = EINVAL;
- return (NULL);
- }
-
- /* fts_open() requires at least one path */
- if (*argv == NULL) {
- errno = EINVAL;
- return (NULL);
- }
-
- /* Allocate/initialize the stream. */
- if ((priv = calloc(1, sizeof(*priv))) == NULL)
- return (NULL);
- sp = &priv->ftsp_fts;
- sp->fts_compar = compar;
- sp->fts_options = options;
-
/* Logical walks turn on NOCHDIR; symbolic links are too hard. */
if (ISSET(FTS_LOGICAL))
SET(FTS_NOCHDIR);
+ /* NOSTAT_TYPE implies NOSTAT */
+ if (ISSET(FTS_NOSTAT_TYPE))
+ SET(FTS_NOSTAT);
+
/*
* Start out with 1K of path space, and enough, in any case,
* to hold the user's paths.
@@ -161,7 +152,9 @@ fts_open(char * const *argv, int options,
p->fts_level = FTS_ROOTLEVEL;
p->fts_parent = parent;
p->fts_accpath = p->fts_name;
- p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW), -1);
+ p->fts_info = fts_stat(sp, p,
+ ISSET(FTS_COMFOLLOWDIR) ? -1 : ISSET(FTS_COMFOLLOW),
+ -1);
/* Command-line "." and ".." are real directories. */
if (p->fts_info == FTS_DOT)
@@ -171,7 +164,7 @@ fts_open(char * const *argv, int options,
* If comparison routine supplied, traverse in sorted
* order; otherwise traverse in the order specified.
*/
- if (compar) {
+ if (sp->fts_compar) {
p->fts_link = root;
root = p;
} else {
@@ -184,7 +177,7 @@ fts_open(char * const *argv, int options,
}
}
}
- if (compar && nitems > 1)
+ if (sp->fts_compar && nitems > 1)
root = fts_sort(sp, root, nitems);
/*
@@ -217,6 +210,97 @@ mem1: free(sp);
return (NULL);
}
+FTS *
+fts_open(char * const *argv, int options,
+ int (*compar)(const FTSENT * const *, const FTSENT * const *))
+{
+ struct _fts_private *priv;
+ FTS *sp;
+
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* fts_open() requires at least one path */
+ if (*argv == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Allocate/initialize the stream. */
+ if ((priv = calloc(1, sizeof(*priv))) == NULL)
+ return (NULL);
+ sp = &priv->ftsp_fts;
+ sp->fts_compar = compar;
+ sp->fts_options = options;
+
+ return (__fts_open(sp, argv));
+}
+
+#ifdef __BLOCKS__
+FTS *
+fts_open_b(char * const *argv, int options,
+ int (^compar)(const FTSENT * const *, const FTSENT * const *))
+#else
+FTS *
+fts_open_b(char * const *argv, int options, fts_block compar)
+#endif /* __BLOCKS__ */
+{
+ struct _fts_private *priv;
+ FTS *sp;
+
+ /* No blocks, no problems. */
+ if (compar == NULL)
+ return (fts_open(argv, options, NULL));
+
+ /* Avoid segfault if blocks runtime is missing. */
+ if (_Block_copy == NULL) {
+ errno = ENOSYS;
+ return (NULL);
+ }
+
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* fts_open() requires at least one path */
+ if (*argv == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Allocate/initialize the stream. */
+ if ((priv = calloc(1, sizeof(*priv))) == NULL)
+ return (NULL);
+ sp = &priv->ftsp_fts;
+#ifdef __BLOCKS__
+ compar = Block_copy(compar);
+#else
+ if (compar->isa != &_NSConcreteGlobalBlock)
+ compar = _Block_copy(compar);
+#endif /* __BLOCKS__ */
+ if (compar == NULL) {
+ free(priv);
+ return (NULL);
+ }
+ sp->fts_compar_b = compar;
+ sp->fts_options = options | FTS_COMPAR_B;
+
+ if ((sp = __fts_open(sp, argv)) == NULL) {
+#ifdef __BLOCKS__
+ Block_release(compar);
+#else
+ if (compar->isa != &_NSConcreteGlobalBlock)
+ _Block_release(compar);
+#endif /* __BLOCKS__ */
+ }
+ return (sp);
+}
+
static void
fts_load(FTS *sp, FTSENT *p)
{
@@ -268,6 +352,17 @@ fts_close(FTS *sp)
free(sp->fts_array);
free(sp->fts_path);
+ /* Free up any block pointer. */
+ if (ISSET(FTS_COMPAR_B) && sp->fts_compar_b != NULL) {
+#ifdef __BLOCKS__
+ Block_release(sp->fts_compar_b);
+#else
+ if (((fts_block)(sp->fts_compar_b))->isa !=
+ &_NSConcreteGlobalBlock)
+ _Block_release(sp->fts_compar_b);
+#endif /* __BLOCKS__ */
+ }
+
/* Return to original directory, save errno if necessary. */
if (!ISSET(FTS_NOCHDIR)) {
saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
@@ -583,7 +678,6 @@ fts_children(FTS *sp, int instr)
void *
(fts_get_clientptr)(FTS *sp)
{
-
return (fts_get_clientptr(sp));
}
@@ -600,7 +694,6 @@ FTS *
void
fts_set_clientptr(FTS *sp, void *clientptr)
{
-
sp->fts_clientptr = clientptr;
}
@@ -653,14 +746,10 @@ fts_build(FTS *sp, int type)
* Open the directory for reading. If this fails, we're done.
* If being called from fts_read, set the fts_info field.
*/
-#ifdef FTS_WHITEOUT
if (ISSET(FTS_WHITEOUT))
oflag = DTF_NODUP;
else
oflag = DTF_HIDEW | DTF_NODUP;
-#else
-#define __opendir2(path, flag) opendir(path)
-#endif
if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
if (type == BREAD) {
cur->fts_info = FTS_DNR;
@@ -787,10 +876,8 @@ mem1: saved_errno = errno;
p->fts_parent = sp->fts_cur;
p->fts_pathlen = len + dnamlen;
-#ifdef FTS_WHITEOUT
if (dp->d_type == DT_WHT)
p->fts_flags |= FTS_ISW;
-#endif
if (cderrno) {
if (nlinks) {
@@ -799,12 +886,8 @@ mem1: saved_errno = errno;
} else
p->fts_info = FTS_NSOK;
p->fts_accpath = cur->fts_accpath;
- } else if (nlinks == 0
-#ifdef DT_DIR
- || (nostat &&
- dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
-#endif
- ) {
+ } else if (nlinks == 0 || (nostat &&
+ dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)) {
p->fts_accpath =
ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
p->fts_info = FTS_NSOK;
@@ -824,6 +907,25 @@ mem1: saved_errno = errno;
p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
--nlinks;
}
+ if (p->fts_info == FTS_NSOK && ISSET(FTS_NOSTAT_TYPE)) {
+ switch (dp->d_type) {
+ case DT_FIFO:
+ case DT_CHR:
+ case DT_BLK:
+ case DT_SOCK:
+ p->fts_info = FTS_DEFAULT;
+ break;
+ case DT_REG:
+ p->fts_info = FTS_F;
+ break;
+ case DT_LNK:
+ p->fts_info = FTS_SL;
+ break;
+ case DT_WHT:
+ p->fts_info = FTS_W;
+ break;
+ }
+ }
/* We walk in directory order so "ls -f" doesn't get upset. */
p->fts_link = NULL;
@@ -900,18 +1002,19 @@ fts_stat(FTS *sp, FTSENT *p, int follow, int dfd)
dev_t dev;
ino_t ino;
struct stat *sbp, sb;
- int saved_errno;
+ int ret, saved_errno;
const char *path;
- if (dfd == -1)
- path = p->fts_accpath, dfd = AT_FDCWD;
- else
+ if (dfd == -1) {
+ path = p->fts_accpath;
+ dfd = AT_FDCWD;
+ } else {
path = p->fts_name;
+ }
/* If user needs stat info, stat buffer already allocated. */
sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
-#ifdef FTS_WHITEOUT
/* Check for whiteout. */
if (p->fts_flags & FTS_ISW) {
if (sbp != &sb) {
@@ -920,22 +1023,27 @@ fts_stat(FTS *sp, FTSENT *p, int follow, int dfd)
}
return (FTS_W);
}
-#endif
/*
- * If doing a logical walk, or application requested FTS_FOLLOW, do
- * a stat(2). If that fails, check for a non-existent symlink. If
- * fail, set the errno from the stat call.
+ * If doing a logical walk, or caller requested FTS_COMFOLLOW, do
+ * a full stat(2). If that fails, do an lstat(2) to check for a
+ * non-existent symlink. If that fails, set the errno from the
+ * stat(2) call.
+ *
+ * As a special case, if stat(2) succeeded but the target is not a
+ * directory and follow is negative (indicating FTS_COMFOLLOWDIR
+ * rather than FTS_COMFOLLOW), we also revert to lstat(2).
*/
if (ISSET(FTS_LOGICAL) || follow) {
- if (fstatat(dfd, path, sbp, 0)) {
+ if ((ret = fstatat(dfd, path, sbp, 0)) != 0 ||
+ (follow < 0 && !S_ISDIR(sbp->st_mode))) {
saved_errno = errno;
if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
p->fts_errno = saved_errno;
goto err;
}
errno = 0;
- if (S_ISLNK(sbp->st_mode))
+ if (ret != 0 && S_ISLNK(sbp->st_mode))
return (FTS_SLNONE);
}
} else if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
@@ -980,21 +1088,6 @@ err: memset(sbp, 0, sizeof(struct stat));
return (FTS_DEFAULT);
}
-/*
- * The comparison function takes pointers to pointers to FTSENT structures.
- * Qsort wants a comparison function that takes pointers to void.
- * (Both with appropriate levels of const-poisoning, of course!)
- * Use a trampoline function to deal with the difference.
- */
-static int
-fts_compar(const void *a, const void *b)
-{
- FTS *parent;
-
- parent = (*(const FTSENT * const *)a)->fts_fts;
- return (*parent->fts_compar)(a, b);
-}
-
static FTSENT *
fts_sort(FTS *sp, FTSENT *head, size_t nitems)
{
@@ -1017,7 +1110,18 @@ fts_sort(FTS *sp, FTSENT *head, size_t nitems)
}
for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p;
- qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar);
+ if (ISSET(FTS_COMPAR_B)) {
+#ifdef __BLOCKS__
+ qsort_b(sp->fts_array, nitems, sizeof(FTSENT *),
+ (int (^)(const void *, const void *))sp->fts_compar_b);
+#else
+ qsort_b(sp->fts_array, nitems, sizeof(FTSENT *),
+ sp->fts_compar_b);
+#endif /* __BLOCKS__ */
+ } else {
+ qsort(sp->fts_array, nitems, sizeof(FTSENT *),
+ (int (*)(const void *, const void *))sp->fts_compar);
+ }
for (head = *(ap = sp->fts_array); --nitems; ++ap)
ap[0]->fts_link = ap[1];
ap[0]->fts_link = NULL;
@@ -1030,44 +1134,32 @@ fts_alloc(FTS *sp, char *name, size_t namelen)
FTSENT *p;
size_t len;
- struct ftsent_withstat {
- FTSENT ent;
- struct stat statbuf;
- };
-
/*
* The file name is a variable length array and no stat structure is
* necessary if the user has set the nostat bit. Allocate the FTSENT
* structure, the file name and the stat structure in one chunk, but
* be careful that the stat structure is reasonably aligned.
*/
- if (ISSET(FTS_NOSTAT))
- len = sizeof(FTSENT) + namelen + 1;
- else
- len = sizeof(struct ftsent_withstat) + namelen + 1;
-
- if ((p = malloc(len)) == NULL)
- return (NULL);
-
- if (ISSET(FTS_NOSTAT)) {
- p->fts_name = (char *)(p + 1);
- p->fts_statp = NULL;
+ len = sizeof(FTSENT) + namelen + 1;
+ if (!ISSET(FTS_NOSTAT)) {
+ len = roundup(len, alignof(struct stat));
+ p = calloc(1, len + sizeof(struct stat));
} else {
- p->fts_name = (char *)((struct ftsent_withstat *)p + 1);
- p->fts_statp = &((struct ftsent_withstat *)p)->statbuf;
+ p = calloc(1, len);
}
+ if (p == NULL)
+ return (NULL);
- /* Copy the name and guarantee NUL termination. */
- memcpy(p->fts_name, name, namelen);
- p->fts_name[namelen] = '\0';
- p->fts_namelen = namelen;
+ p->fts_symfd = -1;
p->fts_path = sp->fts_path;
- p->fts_errno = 0;
- p->fts_flags = 0;
+ p->fts_name = (char *)(p + 1);
+ p->fts_namelen = namelen;
p->fts_instr = FTS_NOINSTR;
- p->fts_number = 0;
- p->fts_pointer = NULL;
+ if (!ISSET(FTS_NOSTAT))
+ p->fts_statp = (struct stat *)((char *)p + len);
p->fts_fts = sp;
+ memcpy(p->fts_name, name, namelen);
+
return (p);
}
@@ -1147,6 +1239,7 @@ fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
{
int ret, oerrno, newfd;
struct stat sb;
+ struct statfs sf;
newfd = fd;
if (ISSET(FTS_NOCHDIR))
@@ -1159,9 +1252,15 @@ fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
goto bail;
}
if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
- errno = ENOENT; /* disinformation */
- ret = -1;
- goto bail;
+ if (_fstatfs(newfd, &sf) != 0 ||
+ (sf.f_flags & MNT_AUTOMOUNTED) == 0) {
+ errno = ENOENT; /* disinformation */
+ ret = -1;
+ goto bail;
+ }
+ /* autofs might did the mount under us, accept. */
+ p->fts_dev = sb.st_dev;
+ p->fts_ino = sb.st_ino;
}
ret = fchdir(newfd);
bail:
diff --git a/lib/libc/gen/ftw-compat11.c b/lib/libc/gen/ftw-compat11.c
index 92ce058726a7..28d6398f6fd8 100644
--- a/lib/libc/gen/ftw-compat11.c
+++ b/lib/libc/gen/ftw-compat11.c
@@ -22,9 +22,6 @@
* From: FreeBSD: head/lib/libc/gen/ftw.c 239151 2012-08-09 15:11:38Z jilles
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/lib/libc/gen/ftw.3 b/lib/libc/gen/ftw.3
index a936e431d882..c9a1d6f1eee9 100644
--- a/lib/libc/gen/ftw.3
+++ b/lib/libc/gen/ftw.3
@@ -18,8 +18,6 @@
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 12, 2020
.Dt FTW 3
.Os
diff --git a/lib/libc/gen/ftw.c b/lib/libc/gen/ftw.c
index 253a29583f36..35557d930bf4 100644
--- a/lib/libc/gen/ftw.c
+++ b/lib/libc/gen/ftw.c
@@ -20,9 +20,6 @@
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/lib/libc/gen/gen-compat.h b/lib/libc/gen/gen-compat.h
index 728a15a51b18..19b9addb4321 100644
--- a/lib/libc/gen/gen-compat.h
+++ b/lib/libc/gen/gen-compat.h
@@ -22,8 +22,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _GEN_COMPAT_H_
@@ -42,16 +40,50 @@ struct freebsd11_statfs;
struct freebsd11_dirent *freebsd11_readdir(DIR *);
int freebsd11_readdir_r(DIR *, struct freebsd11_dirent *,
struct freebsd11_dirent **);
-int freebsd11_stat(const char *, struct freebsd11_stat *);
-int freebsd11_lstat(const char *, struct freebsd11_stat *);
-int freebsd11_fstat(int, struct freebsd11_stat *);
-int freebsd11_fstatat(int, const char *, struct freebsd11_stat *, int);
-int freebsd11_statfs(const char *, struct freebsd11_statfs *);
-int freebsd11_getfsstat(struct freebsd11_statfs *, long, int);
int freebsd11_getmntinfo(struct freebsd11_statfs **, int);
char *freebsd11_devname(__uint32_t dev, __mode_t type);
-char *freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf, int len);
+char *freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf,
+ int len);
+
+/*
+ * We want freebsd11_fstat in C source to result in resolution to
+ * - fstat@FBSD_1.0 for libc.so (but we do not need the _definition_
+ * of this fstat, it is provided by libsys.so which we want to use).
+ * - freebsd11_fstat for libc.a (since if we make it fstat@FBSD_1.0
+ * for libc.a, then final linkage into static object ignores version
+ * and would reference fstat, which is the current syscall, not the
+ * compat syscall). libc.a provides the freebsd11_fstat implementation.
+ * Note that freebsd11_fstat from libc.a is not used for anything, but
+ * we make it correct nonetheless, just in case it would.
+ * This is arranged by COMPAT_SYSCALL, and libc can just use freebsd11_fstat.
+ */
+#ifdef PIC
+#define COMPAT_SYSCALL(rtype, fun, args, sym, ver) \
+ rtype fun args; __sym_compat(sym, fun, ver);
+#else
+#define COMPAT_SYSCALL(rtype, fun, args, sym, ver) \
+ rtype fun args;
+#endif
+
+COMPAT_SYSCALL(int, freebsd11_stat, (const char *, struct freebsd11_stat *),
+ stat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_lstat, (const char *, struct freebsd11_stat *),
+ lstat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_fstat, (int, struct freebsd11_stat *),
+ fstat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_fstatat, (int, const char *,
+ struct freebsd11_stat *, int), fstatat, FBSD_1.1);
+
+COMPAT_SYSCALL(int, freebsd11_statfs, (const char *,
+ struct freebsd11_statfs *), statfs, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_getfsstat, (struct freebsd11_statfs *, long,
+ int), getfsstat, FBSD_1.0);
+
+COMPAT_SYSCALL(int, freebsd14_setgroups, (int gidsize, const __gid_t *gidset),
+ setgroups, FBSD_1.0);
+
+#undef COMPAT_SYSCALL
#endif /* _GEN_COMPAT_H_ */
diff --git a/lib/libc/gen/gen-private.h b/lib/libc/gen/gen-private.h
index 034d186de56c..b6749b3435cd 100644
--- a/lib/libc/gen/gen-private.h
+++ b/lib/libc/gen/gen-private.h
@@ -27,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _GEN_PRIVATE_H_
@@ -45,8 +43,8 @@ struct pthread_mutex;
*/
struct _dirdesc {
int dd_fd; /* file descriptor associated with directory */
- long dd_loc; /* offset in current buffer */
- long dd_size; /* amount of data returned by getdirentries */
+ size_t dd_loc; /* offset in current buffer */
+ size_t dd_size; /* amount of data returned by getdirentries */
char *dd_buf; /* data buffer */
int dd_len; /* size of data buffer */
off_t dd_seek; /* magic cookie returned by getdirentries */
diff --git a/lib/libc/gen/getbootfile.3 b/lib/libc/gen/getbootfile.3
index b68b226a531b..a857b3e8859e 100644
--- a/lib/libc/gen/getbootfile.3
+++ b/lib/libc/gen/getbootfile.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" From: @(#)gethostname.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd September 23, 1994
.Dt GETBOOTFILE 3
.Os
diff --git a/lib/libc/gen/getbootfile.c b/lib/libc/gen/getbootfile.c
index 983199471792..6250e3e2509b 100644
--- a/lib/libc/gen/getbootfile.c
+++ b/lib/libc/gen/getbootfile.c
@@ -27,13 +27,8 @@
* 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.
- *
- * From: @(#)gethostname.c 8.1 (Berkeley) 6/4/93
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3
index acbe409a8456..1d9d43fdfffb 100644
--- a/lib/libc/gen/getbsize.3
+++ b/lib/libc/gen/getbsize.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 11, 2017
.Dt GETBSIZE 3
.Os
diff --git a/lib/libc/gen/getbsize.c b/lib/libc/gen/getbsize.c
index e91c12282ddf..efcabea663a0 100644
--- a/lib/libc/gen/getbsize.c
+++ b/lib/libc/gen/getbsize.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getbsize.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3
index 3f2428d7996f..00c7edd8026f 100644
--- a/lib/libc/gen/getcap.3
+++ b/lib/libc/gen/getcap.3
@@ -28,9 +28,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getcap.3 8.4 (Berkeley) 5/13/94
-.\" $FreeBSD$
-.\"
.Dd March 22, 2002
.Dt GETCAP 3
.Os
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index 364423fff0e0..cfb81ed0d065 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getcap.c 8.3 (Berkeley) 3/25/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
diff --git a/lib/libc/gen/getcontext.3 b/lib/libc/gen/getcontext.3
index f093f674edd1..db6d5ddcb00d 100644
--- a/lib/libc/gen/getcontext.3
+++ b/lib/libc/gen/getcontext.3
@@ -33,8 +33,6 @@
.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
.\" THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 23, 2020
.Dt GETCONTEXT 3
.Os
diff --git a/lib/libc/gen/getcwd.3 b/lib/libc/gen/getcwd.3
index 84190c319a2f..43d7718e92d6 100644
--- a/lib/libc/gen/getcwd.3
+++ b/lib/libc/gen/getcwd.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getcwd.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD$
-.\"
.Dd April 17, 2010
.Dt GETCWD 3
.Os
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index 42a6c204ba06..18d8ce668274 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getcwd.c 8.5 (Berkeley) 2/7/95");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/stat.h>
@@ -44,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "gen-private.h"
@@ -55,7 +52,7 @@ __FBSDID("$FreeBSD$");
extern int __getcwd(char *, size_t);
char *
-getcwd(char *pt, size_t size)
+__ssp_real(getcwd)(char *pt, size_t size)
{
struct dirent *dp;
DIR *dir = NULL;
diff --git a/lib/libc/gen/getdiskbyname.3 b/lib/libc/gen/getdiskbyname.3
index 3fc10d2180c8..8de4f3976dd2 100644
--- a/lib/libc/gen/getdiskbyname.3
+++ b/lib/libc/gen/getdiskbyname.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getdiskbyname.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 4, 1993
.Dt GETDISKBYNAME 3
.Os
diff --git a/lib/libc/gen/getdomainname.3 b/lib/libc/gen/getdomainname.3
index 16801104d561..47fb139ac23c 100644
--- a/lib/libc/gen/getdomainname.3
+++ b/lib/libc/gen/getdomainname.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd May 6, 1994
.Dt GETDOMAINNAME 3
.Os
diff --git a/lib/libc/gen/getdomainname.c b/lib/libc/gen/getdomainname.c
index 3df611b7e4c7..c0be7465f967 100644
--- a/lib/libc/gen/getdomainname.c
+++ b/lib/libc/gen/getdomainname.c
@@ -29,17 +29,14 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)gethostname.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
#include <unistd.h>
+#include <ssp/ssp.h>
int
-getdomainname(char *name, int namelen)
+__ssp_real(getdomainname)(char *name, int namelen)
{
int mib[2];
size_t size;
diff --git a/lib/libc/gen/getentropy.3 b/lib/libc/gen/getentropy.3
index 83812c6c7a92..5f7ee32ebbfc 100644
--- a/lib/libc/gen/getentropy.3
+++ b/lib/libc/gen/getentropy.3
@@ -15,9 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd February 24, 2018
+.Dd January 17, 2025
.Dt GETENTROPY 3
.Os
.Sh NAME
@@ -62,8 +60,8 @@ The
.Fa buf
parameter points to an
invalid address.
-.It Bq Er EIO
-Too many bytes requested, or some other fatal error occurred.
+.It Bq Er EINVAL
+Too many bytes requested.
.El
.Sh SEE ALSO
.Xr getrandom 2 ,
@@ -71,10 +69,8 @@ Too many bytes requested, or some other fatal error occurred.
.Xr random 4
.Sh STANDARDS
.Fn getentropy
-is non-standard.
-It is present on
-.Ox
-and Linux.
+conforms to
+.St -p1003.1-2024 .
.Sh HISTORY
The
.Fn getentropy
diff --git a/lib/libc/gen/getentropy.c b/lib/libc/gen/getentropy.c
index 2db3b8030243..6b8ad697b7e0 100644
--- a/lib/libc/gen/getentropy.c
+++ b/lib/libc/gen/getentropy.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2018 Conrad Meyer <cem@FreeBSD.org>
* All rights reserved.
@@ -26,125 +26,44 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/random.h>
-#include <sys/sysctl.h>
#include <errno.h>
+#include <limits.h>
#include <signal.h>
-#include <stdbool.h>
-#include <stdlib.h>
#include <unistd.h>
+#include <ssp/ssp.h>
#include "libc_private.h"
-/* First __FreeBSD_version bump after introduction of getrandom(2) (r331279) */
-#define GETRANDOM_FIRST 1200061
-
-extern int __sysctl(int *, u_int, void *, size_t *, void *, size_t);
-
static inline void
_getentropy_fail(void)
{
raise(SIGKILL);
}
-static size_t
-arnd_sysctl(u_char *buf, size_t size)
-{
- int mib[2];
- size_t len, done;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_ARND;
- done = 0;
-
- do {
- len = size;
- if (__sysctl(mib, 2, buf, &len, NULL, 0) == -1)
- return (done);
- done += len;
- buf += len;
- size -= len;
- } while (size > 0);
-
- return (done);
-}
-
-/*
- * If a newer libc is accidentally installed on an older kernel, provide high
- * quality random data anyway. The sysctl interface is not as fast and does
- * not block by itself, but is provided by even very old kernels.
- */
-static int
-getentropy_fallback(void *buf, size_t buflen)
-{
- /*
- * oldp (buf) == NULL has a special meaning for sysctl that results in
- * no EFAULT. For compatibility with the kernel getrandom(2), detect
- * this case and return the appropriate error.
- */
- if (buf == NULL && buflen > 0) {
- errno = EFAULT;
- return (-1);
- }
- if (arnd_sysctl(buf, buflen) != buflen) {
- if (errno == EFAULT)
- return (-1);
- /*
- * This cannot happen. arnd_sysctl() spins until the random
- * device is seeded and then repeatedly reads until the full
- * request is satisfied. The only way for this to return a zero
- * byte or short read is if sysctl(2) on the kern.arandom MIB
- * fails. In this case, excepting the user-provided-a-bogus-
- * buffer EFAULT, give up (like for arc4random(3)'s arc4_stir).
- */
- _getentropy_fail();
- }
- return (0);
-}
-
int
-getentropy(void *buf, size_t buflen)
+__ssp_real(getentropy)(void *buf, size_t buflen)
{
ssize_t rd;
- bool have_getrandom;
- if (buflen > 256) {
- errno = EIO;
+ if (buflen > GETENTROPY_MAX) {
+ errno = EINVAL;
return (-1);
}
- have_getrandom = (__getosreldate() >= GETRANDOM_FIRST);
-
while (buflen > 0) {
- if (have_getrandom) {
- rd = getrandom(buf, buflen, 0);
- if (rd == -1) {
- switch (errno) {
- case ECAPMODE:
- /*
- * Kernel >= r331280 and < r337999
- * will return ECAPMODE when the
- * caller is already in capability
- * mode, fallback to traditional
- * method in this case.
- */
- have_getrandom = false;
- continue;
- case EINTR:
- continue;
- case EFAULT:
- return (-1);
- default:
- _getentropy_fail();
- }
+ rd = getrandom(buf, buflen, 0);
+ if (rd == -1) {
+ switch (errno) {
+ case EINTR:
+ continue;
+ case EFAULT:
+ return (-1);
+ default:
+ _getentropy_fail();
}
- } else {
- return (getentropy_fallback(buf, buflen));
}
/* This cannot happen. */
diff --git a/lib/libc/gen/getfsent.3 b/lib/libc/gen/getfsent.3
index c5694ab08c2b..4783c7469910 100644
--- a/lib/libc/gen/getfsent.3
+++ b/lib/libc/gen/getfsent.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getfsent.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd April 7, 2003
.Dt GETFSENT 3
.Os
diff --git a/lib/libc/gen/getgrent.3 b/lib/libc/gen/getgrent.3
index d89ac631eff3..e4a703f3bfad 100644
--- a/lib/libc/gen/getgrent.3
+++ b/lib/libc/gen/getgrent.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" From: @(#)getgrent.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
.Dd July 31, 2016
.Dt GETGRENT 3
.Os
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index 3743518c8f58..508e3d63eb60 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003 Networks Associates Technology, Inc.
* All rights reserved.
@@ -32,9 +32,6 @@
* SUCH DAMAGE.
*
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#ifdef YP
diff --git a/lib/libc/gen/getgrouplist.3 b/lib/libc/gen/getgrouplist.3
index 4982ebba2696..9e05ff7e7a29 100644
--- a/lib/libc/gen/getgrouplist.3
+++ b/lib/libc/gen/getgrouplist.3
@@ -1,5 +1,13 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2025 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Olivier Certner
+.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+.\" Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -25,15 +33,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getgrouplist.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
-.\"
-.Dd October 26, 2014
+.Dd October 9, 2025
.Dt GETGROUPLIST 3
.Os
.Sh NAME
.Nm getgrouplist
-.Nd calculate group access list
+.Nd produce a user's effective group list
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -43,36 +48,44 @@
.Sh DESCRIPTION
The
.Fn getgrouplist
-function reads through the group file and calculates
-the group access list for the user specified in
-.Fa name .
-The
+function retrieves from the group database the supplementary groups for the user
+specified in
+.Fa name
+and returns the effective group list, whose first group is the value of
.Fa basegid
-is automatically included in the groups list.
-Typically this value is given as
-the group number from the password file.
+and the others are the supplementary groups.
+.Fa basegid
+typically is the user's initial numerical group ID from the password database.
.Pp
-The resulting group list is returned in the array pointed to by
+The effective group list is returned in the array pointed to by
.Fa groups .
-The caller specifies the size of the
+The caller specifies the length of the
.Fa groups
array in the integer pointed to by
-.Fa ngroups ;
-the actual number of groups found is returned in
+.Fa ngroups .
+The number of groups of the effective group list, which may be greater than the
+.Fa groups
+array's length, is returned through
.Fa ngroups .
.Sh RETURN VALUES
The
.Fn getgrouplist
-function
-returns 0 on success and \-1 if the size of the group list is too small to
-hold all the user's groups.
-Here, the group array will be filled with as many groups as will fit.
+function returns 0 on success and \-1 if the length of the group list is too
+small to hold all the user's groups.
+In the latter case, the
+.Fa groups
+array is filled with as many groups as possible from the start of the effective
+group list, and the length pointed to by
+.Fa ngroups
+is set to the full length of the latter, thus to a value strictly greater than
+before the call.
.Sh FILES
.Bl -tag -width /etc/group -compact
.It Pa /etc/group
group membership list
.El
.Sh SEE ALSO
+.Xr setcred 2 ,
.Xr setgroups 2 ,
.Xr initgroups 3
.Sh HISTORY
diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c
index c3c4af5f7cdb..9c57b7031336 100644
--- a/lib/libc/gen/getgrouplist.c
+++ b/lib/libc/gen/getgrouplist.c
@@ -29,24 +29,15 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94");
-__FBSDID("$FreeBSD$");
-
-/*
- * get credential
- */
#include <sys/types.h>
-#include <grp.h>
-#include <string.h>
#include <unistd.h>
+#include <ssp/ssp.h>
extern int __getgroupmembership(const char *, gid_t, gid_t *, int, int *);
int
-getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
+__ssp_real(getgrouplist)(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
{
return __getgroupmembership(uname, agroup, groups, *grpcnt, grpcnt);
}
-
diff --git a/lib/libc/gen/gethostname.3 b/lib/libc/gen/gethostname.3
index 00a67c77fb0f..99e723fa9595 100644
--- a/lib/libc/gen/gethostname.3
+++ b/lib/libc/gen/gethostname.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd July 13, 2020
.Dt GETHOSTNAME 3
.Os
diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c
index 8af10d6d0624..66d401fad846 100644
--- a/lib/libc/gen/gethostname.c
+++ b/lib/libc/gen/gethostname.c
@@ -29,18 +29,15 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)gethostname.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <unistd.h>
+#include <ssp/ssp.h>
int
-gethostname(char *name, size_t namelen)
+__ssp_real(gethostname)(char *name, size_t namelen)
{
int mib[2];
diff --git a/lib/libc/gen/getloadavg.3 b/lib/libc/gen/getloadavg.3
index 0e240be2d3f9..42a9f511c9ef 100644
--- a/lib/libc/gen/getloadavg.3
+++ b/lib/libc/gen/getloadavg.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getloadavg.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 4, 1993
.Dt GETLOADAVG 3
.Os
diff --git a/lib/libc/gen/getloadavg.c b/lib/libc/gen/getloadavg.c
index a0a707b6db9d..4f6c23627f0e 100644
--- a/lib/libc/gen/getloadavg.c
+++ b/lib/libc/gen/getloadavg.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getloadavg.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c
index a8bc2fd0688f..f8a3fb079067 100644
--- a/lib/libc/gen/getlogin.c
+++ b/lib/libc/gen/getlogin.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getlogin.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <errno.h>
#include <pwd.h>
@@ -41,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "namespace.h"
#include <pthread.h>
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -58,7 +55,7 @@ getlogin(void)
}
int
-getlogin_r(char *logname, size_t namelen)
+__ssp_real(getlogin_r)(char *logname, size_t namelen)
{
char tmpname[MAXLOGNAME];
int len;
diff --git a/lib/libc/gen/getmntinfo-compat11.c b/lib/libc/gen/getmntinfo-compat11.c
index b18da03133fd..d5c308b387a0 100644
--- a/lib/libc/gen/getmntinfo-compat11.c
+++ b/lib/libc/gen/getmntinfo-compat11.c
@@ -25,13 +25,8 @@
* 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.
- *
- * From: @(#)getmntinfo.c 8.1 (Berkeley) 6/4/93
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/ucred.h>
#define _WANT_FREEBSD11_STATFS
diff --git a/lib/libc/gen/getmntinfo.3 b/lib/libc/gen/getmntinfo.3
index d8821258b6e5..2bbe436078d6 100644
--- a/lib/libc/gen/getmntinfo.3
+++ b/lib/libc/gen/getmntinfo.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getmntinfo.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
-.\"
.Dd December 27, 2016
.Dt GETMNTINFO 3
.Os
diff --git a/lib/libc/gen/getmntinfo.c b/lib/libc/gen/getmntinfo.c
index 250be99c27c5..3c224ef27d76 100644
--- a/lib/libc/gen/getmntinfo.c
+++ b/lib/libc/gen/getmntinfo.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
diff --git a/lib/libc/gen/getnetgrent.3 b/lib/libc/gen/getnetgrent.3
index 29e0ce3265bc..be2e3cd1cdd5 100644
--- a/lib/libc/gen/getnetgrent.3
+++ b/lib/libc/gen/getnetgrent.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getnetgrent.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 5, 2016
.Dt GETNETGRENT 3
.Os
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index 733fe024ee28..7c92bc2ce9a9 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getnetgrent.c 8.2 (Berkeley) 4/27/95");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <ctype.h>
diff --git a/lib/libc/gen/getosreldate.3 b/lib/libc/gen/getosreldate.3
index 0bb96d138c8f..6ce5a11d131c 100644
--- a/lib/libc/gen/getosreldate.3
+++ b/lib/libc/gen/getosreldate.3
@@ -22,8 +22,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd June 13, 2018
.Dt GETOSRELDATE 3
.Os
diff --git a/lib/libc/gen/getosreldate.c b/lib/libc/gen/getosreldate.c
index 6a54df907546..edd978973ade 100644
--- a/lib/libc/gen/getosreldate.c
+++ b/lib/libc/gen/getosreldate.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)gethostid.c 8.1 (Berkeley) 6/2/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/getpagesize.3 b/lib/libc/gen/getpagesize.3
deleted file mode 100644
index 4c57f7474208..000000000000
--- a/lib/libc/gen/getpagesize.3
+++ /dev/null
@@ -1,69 +0,0 @@
-.\" Copyright (c) 1983, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" 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.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)getpagesize.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd June 1, 2022
-.Dt GETPAGESIZE 3
-.Os
-.Sh NAME
-.Nm getpagesize
-.Nd get system page size
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In unistd.h
-.Ft int
-.Fn getpagesize void
-.Sh DESCRIPTION
-The
-.Fn getpagesize
-function
-returns the number of bytes in a page.
-Page granularity is the granularity of many of the memory
-management calls.
-.Pp
-The page size is a system
-page size and may not be the same as the underlying
-hardware page size.
-.Pp
-.St -p1003.1-2001
-removed
-.Nm .
-Portable applications should use
-.Ql sysconf(_SC_PAGESIZE)
-instead.
-.Sh SEE ALSO
-.Xr pagesize 1 ,
-.Xr sbrk 2 ,
-.Xr sysconf 3
-.Sh HISTORY
-The
-.Fn getpagesize
-function appeared in
-.Bx 4.2 .
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c
deleted file mode 100644
index b722bd27c0a3..000000000000
--- a/lib/libc/gen/getpagesize.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#include <sys/cdefs.h>
-__SCCSID("@(#)getpagesize.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/sysctl.h>
-
-#include <errno.h>
-#include <link.h>
-#include <unistd.h>
-
-#include "libc_private.h"
-
-/*
- * This is unlikely to change over the running time of any
- * program, so we cache the result to save some syscalls.
- *
- * NB: This function may be called from malloc(3) at initialization
- * NB: so must not result in a malloc(3) related call!
- */
-
-int
-getpagesize(void)
-{
- int mib[2];
- static int value;
- size_t size;
- int error;
-
- if (value != 0)
- return (value);
-
- error = _elf_aux_info(AT_PAGESZ, &value, sizeof(value));
- if (error == 0 && value != 0)
- return (value);
-
- mib[0] = CTL_HW;
- mib[1] = HW_PAGESIZE;
- size = sizeof value;
- if (sysctl(mib, nitems(mib), &value, &size, NULL, 0) == -1)
- return (PAGE_SIZE);
-
- return (value);
-}
diff --git a/lib/libc/gen/getpagesizes.3 b/lib/libc/gen/getpagesizes.3
deleted file mode 100644
index 52fa866821f2..000000000000
--- a/lib/libc/gen/getpagesizes.3
+++ /dev/null
@@ -1,99 +0,0 @@
-.\" Copyright (c) 2009 Alan L. Cox <alc@cs.rice.edu>
-.\" All rights reserved.
-.\"
-.\" 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 AUTHOR 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 AUTHOR 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.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd September 21, 2009
-.Dt GETPAGESIZES 3
-.Os
-.Sh NAME
-.Nm getpagesizes
-.Nd "get system page sizes"
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/mman.h
-.Ft int
-.Fn getpagesizes "size_t pagesize[]" "int nelem"
-.Sh DESCRIPTION
-The
-.Fn getpagesizes
-function retrieves page size information from the system.
-When it is called with
-.Fa pagesize
-specified as
-.Dv NULL
-and
-.Fa nelem
-specified as 0, it returns the number of distinct page sizes that are
-supported by the system.
-Otherwise, it assigns up to
-.Fa nelem
-of the system-supported page sizes to consecutive elements of the
-array referenced by
-.Fa pagesize .
-These page sizes are expressed in bytes.
-In this case,
-.Fn getpagesizes
-returns the number of such page sizes that it assigned to the array.
-.Sh RETURN VALUES
-If successful, the
-.Fn getpagesizes
-function returns either the number of page sizes that are supported by
-the system or the number of supported page sizes that it assigned to
-the array referenced by
-.Fa pagesize .
-Otherwise, it returns the value\~\-1 and sets
-.Va errno
-to indicate the error.
-.Sh ERRORS
-The
-.Fn getpagesizes
-function will succeed unless:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Fa pagesize
-argument is
-.Dv NULL
-and the
-.Fa nelem
-argument is non-zero.
-.It Bq Er EINVAL
-The
-.Fa nelem
-argument is less than zero.
-.El
-.Sh SEE ALSO
-.Xr getpagesize 3
-.Sh HISTORY
-The
-.Fn getpagesizes
-function first appeared in Solaris 9.
-This manual page was written in conjunction with a new but compatible
-implementation that was first released in
-.Fx 7.3 .
-.Sh AUTHORS
-This manual page was written by
-.An Alan L. Cox Aq Mt alc@cs.rice.edu .
diff --git a/lib/libc/gen/getpagesizes.c b/lib/libc/gen/getpagesizes.c
deleted file mode 100644
index b138f6a49158..000000000000
--- a/lib/libc/gen/getpagesizes.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
- * Copyright (c) 2009 Alan L. Cox <alc@cs.rice.edu>
- * All rights reserved.
- *
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/mman.h>
-#include <sys/sysctl.h>
-
-#include <errno.h>
-#include <link.h>
-
-#include "libc_private.h"
-
-/*
- * Retrieves page size information from the system. Specifically, returns the
- * number of distinct page sizes that are supported by the system, if
- * "pagesize" is NULL and "nelem" is 0. Otherwise, assigns up to "nelem" of
- * the system-supported page sizes to consecutive elements of the array
- * referenced by "pagesize", and returns the number of such page sizes that it
- * assigned to the array. These page sizes are expressed in bytes.
- *
- * The implementation of this function does not directly or indirectly call
- * malloc(3) or any other dynamic memory allocator that may itself call this
- * function.
- */
-int
-getpagesizes(size_t pagesize[], int nelem)
-{
- static u_long ps[MAXPAGESIZES];
- static int nops;
- size_t size;
- int error, i;
-
- if (nelem < 0 || (nelem > 0 && pagesize == NULL)) {
- errno = EINVAL;
- return (-1);
- }
- /* Cache the result of the sysctl(2). */
- if (nops == 0) {
- error = _elf_aux_info(AT_PAGESIZES, ps, sizeof(ps));
- size = sizeof(ps);
- if (error != 0 || ps[0] == 0) {
- if (sysctlbyname("hw.pagesizes", ps, &size, NULL, 0)
- == -1)
- return (-1);
- }
- /* Count the number of page sizes that are supported. */
- nops = size / sizeof(ps[0]);
- while (nops > 0 && ps[nops - 1] == 0)
- nops--;
- }
- if (pagesize == NULL)
- return (nops);
- /* Return up to "nelem" page sizes from the cached result. */
- if (nelem > nops)
- nelem = nops;
- for (i = 0; i < nelem; i++)
- pagesize[i] = ps[i];
- return (nelem);
-}
diff --git a/lib/libc/gen/getpass.3 b/lib/libc/gen/getpass.3
index 87f2b12b36d3..c88e072e1900 100644
--- a/lib/libc/gen/getpass.3
+++ b/lib/libc/gen/getpass.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getpass.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 4, 1993
.Dt GETPASS 3
.Os
diff --git a/lib/libc/gen/getpeereid.3 b/lib/libc/gen/getpeereid.3
index 3c99eeda37f0..8e3b763f716a 100644
--- a/lib/libc/gen/getpeereid.3
+++ b/lib/libc/gen/getpeereid.3
@@ -23,9 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd February 3, 2017
+.Dd November 16, 2023
.Dt GETPEEREID 3
.Os
.Sh NAME
@@ -34,7 +32,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In unistd.h
.Ft int
.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid"
@@ -47,7 +44,7 @@ peer connected to a
socket.
The argument
.Fa s
-must be a
+must be a connected
.Ux Ns -domain
socket
.Pq Xr unix 4
diff --git a/lib/libc/gen/getpeereid.c b/lib/libc/gen/getpeereid.c
index 86396d359ba3..444dd2664cc4 100644
--- a/lib/libc/gen/getpeereid.c
+++ b/lib/libc/gen/getpeereid.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 Dima Dorfman.
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/lib/libc/gen/getprogname.3 b/lib/libc/gen/getprogname.3
index f43a7b8c6b69..7bc2c50d79c4 100644
--- a/lib/libc/gen/getprogname.3
+++ b/lib/libc/gen/getprogname.3
@@ -29,8 +29,6 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd April 18, 2021
.Dt GETPROGNAME 3
.Os
diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c
index fd51d1322517..54e59b6ac412 100644
--- a/lib/libc/gen/getprogname.c
+++ b/lib/libc/gen/getprogname.c
@@ -1,6 +1,3 @@
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <stdlib.h>
#include "un-namespace.h"
diff --git a/lib/libc/gen/getpwent.3 b/lib/libc/gen/getpwent.3
index d7043d814802..486f0cab2399 100644
--- a/lib/libc/gen/getpwent.3
+++ b/lib/libc/gen/getpwent.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" From: @(#)getpwent.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD$
-.\"
-.Dd April 16, 2003
+.Dd November 28, 2022
.Dt GETPWENT 3
.Os
.Sh NAME
@@ -45,7 +42,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In pwd.h
.Ft struct passwd *
.Fn getpwent void
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 634fc4fc8229..1cbf97e7eb52 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003 Networks Associates Technology, Inc.
* All rights reserved.
@@ -32,9 +32,6 @@
* SUCH DAMAGE.
*
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#ifdef YP
diff --git a/lib/libc/gen/getttyent.3 b/lib/libc/gen/getttyent.3
index 79b765163556..bf38f417ac58 100644
--- a/lib/libc/gen/getttyent.3
+++ b/lib/libc/gen/getttyent.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getttyent.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd November 17, 1996
.Dt GETTTYENT 3
.Os
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c
index 4b152095a946..3c92f603ff06 100644
--- a/lib/libc/gen/getttyent.c
+++ b/lib/libc/gen/getttyent.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getttyent.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/getusershell.3 b/lib/libc/gen/getusershell.3
index 4fe2027a2100..728e87c9d56a 100644
--- a/lib/libc/gen/getusershell.3
+++ b/lib/libc/gen/getusershell.3
@@ -27,9 +27,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getusershell.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd January 16, 1999
.Dt GETUSERSHELL 3
.Os
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c
index 7ea09df4d847..26c6e326e94d 100644
--- a/lib/libc/gen/getusershell.c
+++ b/lib/libc/gen/getusershell.c
@@ -30,9 +30,7 @@
*/
#include <sys/cdefs.h>
-__SCCSID("@(#)getusershell.c 8.1 (Berkeley) 6/4/93");
__RCSID("$NetBSD: getusershell.c,v 1.17 1999/01/25 01:09:34 lukem Exp $");
-__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <sys/param.h>
diff --git a/lib/libc/gen/getutxent.3 b/lib/libc/gen/getutxent.3
index 85c37b16e0fc..96d376dc29bc 100644
--- a/lib/libc/gen/getutxent.3
+++ b/lib/libc/gen/getutxent.3
@@ -22,8 +22,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd October 27, 2011
.Dt GETUTXENT 3
.Os
diff --git a/lib/libc/gen/getutxent.c b/lib/libc/gen/getutxent.c
index 664498126f13..d0c307538930 100644
--- a/lib/libc/gen/getutxent.c
+++ b/lib/libc/gen/getutxent.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/endian.h>
#include <sys/param.h>
diff --git a/lib/libc/gen/getvfsbyname.3 b/lib/libc/gen/getvfsbyname.3
index 656d671cd0e1..61fd48624fbd 100644
--- a/lib/libc/gen/getvfsbyname.3
+++ b/lib/libc/gen/getvfsbyname.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)kvm_getvfsbyname.3 8.3 (Berkeley) 5/4/95
-.\" $FreeBSD$
-.\"
-.Dd August 16, 2018
+.Dd October 28, 2025
.Dt GETVFSBYNAME 3
.Os
.Sh NAME
@@ -105,6 +102,7 @@ argument
specifies a file system that is unknown or not configured in the kernel.
.El
.Sh SEE ALSO
+.Xr lsvfs 1 ,
.Xr jail 2 ,
.Xr mount 2 ,
.Xr sysctl 3 ,
diff --git a/lib/libc/gen/getvfsbyname.c b/lib/libc/gen/getvfsbyname.c
index 91f4490bf504..18cbf64b9f4a 100644
--- a/lib/libc/gen/getvfsbyname.c
+++ b/lib/libc/gen/getvfsbyname.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)kvm_getvfsbyname.c 8.1 (Berkeley) 4/3/95");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
@@ -42,7 +38,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
/*
- * fusefs(5) file systems may have a "subtype" which gets appended to
+ * fusefs(4) file systems may have a "subtype" which gets appended to
* statfs(2)'s f_fstypename field on a per-mount basis. Allow getvfsbyname to
* match either the full "fusefs.foobar" or the more general "fusefs".
*/
diff --git a/lib/libc/gen/glob-compat11.c b/lib/libc/gen/glob-compat11.c
index 76a4553c922c..cdae52056f61 100644
--- a/lib/libc/gen/glob-compat11.c
+++ b/lib/libc/gen/glob-compat11.c
@@ -33,14 +33,9 @@
* 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.
- *
- * From: @(#)glob.c 8.3 (Berkeley) 10/13/93
* From: FreeBSD: head/lib/libc/gen/glob.c 317913 2017-05-07 19:52:56Z jilles
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#define _WANT_FREEBSD11_STAT
#include <sys/stat.h>
@@ -422,8 +417,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob11_t *pglob)
* we're not running setuid or setgid) and then trying
* the password file
*/
- if (issetugid() != 0 ||
- (h = getenv("HOME")) == NULL) {
+ if ((h = secure_getenv("HOME")) == NULL) {
if (((h = getlogin()) != NULL &&
(pwd = getpwnam(h)) != NULL) ||
(pwd = getpwuid(getuid())) != NULL)
diff --git a/lib/libc/gen/glob-compat11.h b/lib/libc/gen/glob-compat11.h
index d43086f819c5..713e1a454b7f 100644
--- a/lib/libc/gen/glob-compat11.h
+++ b/lib/libc/gen/glob-compat11.h
@@ -28,16 +28,11 @@
* 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.
- *
- * @(#)glob.h 8.1 (Berkeley) 6/2/93
- * from: $FreeBSD$
- * $FreeBSD$
*/
#ifndef _GLOB_COMPAT11_H_
#define _GLOB_COMPAT11_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <glob.h>
diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3
index d8b1b65d9c59..839d98ce02b5 100644
--- a/lib/libc/gen/glob.3
+++ b/lib/libc/gen/glob.3
@@ -27,14 +27,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)glob.3 8.3 (Berkeley) 4/16/94
-.\" $FreeBSD$
-.\"
-.Dd December 20, 2011
+.Dd June 23, 2025
.Dt GLOB 3
.Os
.Sh NAME
.Nm glob ,
+.Nm glob_b ,
.Nm globfree
.Nd generate pathnames matching a pattern
.Sh LIBRARY
@@ -42,7 +40,9 @@
.Sh SYNOPSIS
.In glob.h
.Ft int
-.Fn glob "const char * restrict pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t * restrict pglob"
+.Fn glob "const char * restrict pattern" "int flags" "int (*errfunc)(const char *epath, int errno)" "glob_t * restrict pglob"
+.Ft int
+.Fn glob_b "const char * restrict pattern" "int flags" "int (^errblk)(const char *epath, int errno)" "glob_t * restrict pglob"
.Ft void
.Fn globfree "glob_t *pglob"
.Sh DESCRIPTION
@@ -275,10 +275,24 @@ is
.Pf non- Dv NULL ,
.Fn glob
calls
-.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) ,
+.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) .
+This may be unintuitive: a pattern like
+.Ql */Makefile
+will try to
+.Xr stat 2
+.Ql foo/Makefile
+even if
+.Ql foo
+is not a directory, resulting in a
+call to
+.Fa errfunc .
+The error routine can suppress this action by testing for
+.Er ENOENT
+and
+.Er ENOTDIR ;
however, the
.Dv GLOB_ERR
-flag will cause an immediate
+flag will still cause an immediate
return when this happens.
.Pp
If
@@ -310,16 +324,27 @@ or
returns zero, the error is ignored.
.Pp
The
+.Fn glob_b
+function is like
+.Fn glob
+except that the error callback is a block pointer instead of a function
+pointer.
+.Pp
+The
.Fn globfree
function frees any space associated with
.Fa pglob
from a previous call(s) to
-.Fn glob .
+.Fn glob
+or
+.Fn glob_b .
.Sh RETURN VALUES
On successful completion,
.Fn glob
-returns zero.
-In addition the fields of
+and
+.Fn glob_b
+return zero.
+In addition, the fields of
.Fa pglob
contain the values described below:
.Bl -tag -width GLOB_NOCHECK
@@ -327,12 +352,16 @@ contain the values described below:
contains the total number of matched pathnames so far.
This includes other matches from previous invocations of
.Fn glob
+or
+.Fn glob_b
if
.Dv GLOB_APPEND
was specified.
.It Fa gl_matchc
contains the number of matched pathnames in the current invocation of
-.Fn glob .
+.Fn glob
+or
+.Fn glob_b .
.It Fa gl_flags
contains a copy of the
.Fa flags
@@ -355,6 +384,8 @@ are undefined.
.Pp
If
.Fn glob
+or
+.Fn glob_b
terminates due to an error, it sets errno and returns one of the
following non-zero constants, which are defined in the include
file
@@ -400,6 +431,14 @@ g.gl_pathv[0] = "ls";
g.gl_pathv[1] = "-l";
execvp("ls", g.gl_pathv);
.Ed
+.Sh CAVEATS
+The
+.Fn glob
+and
+.Fn glob_b
+functions
+will not match filenames that begin with a period
+unless this is specifically requested (e.g., by ".*").
.Sh SEE ALSO
.Xr sh 1 ,
.Xr fnmatch 3 ,
@@ -438,6 +477,10 @@ and
.Fn globfree
functions first appeared in
.Bx 4.4 .
+The
+.Fn glob_b
+function first appeared in
+.Fx 15.0 .
.Sh BUGS
Patterns longer than
.Dv MAXPATHLEN
@@ -445,7 +488,9 @@ may cause unchecked errors.
.Pp
The
.Fn glob
-argument
+and
+.Fn glob_b
+functions
may fail and set errno for any of the errors specified for the
library routines
.Xr stat 2 ,
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 2e8bf6310641..f7da5f0cda09 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -37,10 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)glob.c 8.3 (Berkeley) 10/13/93");
-__FBSDID("$FreeBSD$");
-
/*
* glob(3) -- a superset of the one defined in POSIX 1003.2.
*
@@ -92,8 +88,11 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include <wchar.h>
+#include "block_abi.h"
#include "collate.h"
+typedef DECLARE_BLOCK(int, glob_b_block, const char*, int);
+
/*
* glob(3) expansion limits. Stop the expansion if any of these limits
* is reached. This caps the runtime in the face of DoS attacks. See
@@ -108,8 +107,8 @@ __FBSDID("$FreeBSD$");
struct glob_limit {
size_t l_brace_cnt;
size_t l_path_lim;
- size_t l_readdir_cnt;
- size_t l_stat_cnt;
+ size_t l_readdir_cnt;
+ size_t l_stat_cnt;
size_t l_string_cnt;
};
@@ -183,9 +182,8 @@ static int err_aborted(glob_t *, int, char *);
static void qprintf(const char *, Char *);
#endif
-int
-glob(const char * __restrict pattern, int flags,
- int (*errfunc)(const char *, int), glob_t * __restrict pglob)
+static int
+__glob(const char *pattern, glob_t *pglob)
{
struct glob_limit limit = { 0, 0, 0, 0, 0 };
const char *patnext;
@@ -196,25 +194,23 @@ glob(const char * __restrict pattern, int flags,
int too_long;
patnext = pattern;
- if (!(flags & GLOB_APPEND)) {
+ if (!(pglob->gl_flags & GLOB_APPEND)) {
pglob->gl_pathc = 0;
pglob->gl_pathv = NULL;
- if (!(flags & GLOB_DOOFFS))
+ if (!(pglob->gl_flags & GLOB_DOOFFS))
pglob->gl_offs = 0;
}
- if (flags & GLOB_LIMIT) {
+ if (pglob->gl_flags & GLOB_LIMIT) {
limit.l_path_lim = pglob->gl_matchc;
if (limit.l_path_lim == 0)
limit.l_path_lim = GLOB_LIMIT_PATH;
}
- pglob->gl_flags = flags & ~GLOB_MAGCHAR;
- pglob->gl_errfunc = errfunc;
pglob->gl_matchc = 0;
bufnext = patbuf;
bufend = bufnext + MAXPATHLEN - 1;
too_long = 1;
- if (flags & GLOB_NOESCAPE) {
+ if (pglob->gl_flags & GLOB_NOESCAPE) {
memset(&mbs, 0, sizeof(mbs));
while (bufnext <= bufend) {
clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
@@ -254,15 +250,45 @@ glob(const char * __restrict pattern, int flags,
return (err_nomatch(pglob, &limit, pattern));
*bufnext = EOS;
- if (flags & GLOB_BRACE)
+ if (pglob->gl_flags & GLOB_BRACE)
return (globexp0(patbuf, pglob, &limit, pattern));
else
return (glob0(patbuf, pglob, &limit, pattern));
}
+int
+glob(const char * __restrict pattern, int flags,
+ int (*errfunc)(const char *, int), glob_t * __restrict pglob)
+{
+ int rv;
+
+ pglob->gl_flags = flags & ~(GLOB_MAGCHAR | _GLOB_ERR_BLOCK);
+ pglob->gl_errfunc = errfunc;
+ rv = __glob(pattern, pglob);
+ pglob->gl_errfunc = NULL;
+
+ return (rv);
+}
+
+int
+glob_b(const char * __restrict pattern, int flags,
+ glob_b_block block, glob_t * __restrict pglob)
+{
+ int rv;
+
+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
+ pglob->gl_flags |= _GLOB_ERR_BLOCK;
+ pglob->gl_errblk = block;
+ rv = __glob(pattern, pglob);
+ pglob->gl_errblk = NULL;
+
+ return (rv);
+}
+
static int
globexp0(const Char *pattern, glob_t *pglob, struct glob_limit *limit,
- const char *origpat) {
+ const char *origpat)
+{
int rv;
size_t oldpathc;
@@ -453,8 +479,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
* we're not running setuid or setgid) and then trying
* the password file
*/
- if (issetugid() != 0 ||
- (h = getenv("HOME")) == NULL) {
+ if ((h = secure_getenv("HOME")) == NULL) {
if (((h = getlogin()) != NULL &&
(pwd = getpwnam(h)) != NULL) ||
(pwd = getpwuid(getuid())) != NULL)
@@ -729,7 +754,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
return (GLOB_NOSPACE);
}
*pathend = EOS;
- if (pglob->gl_errfunc != NULL &&
+ if ((pglob->gl_errfunc != NULL || pglob->gl_errblk != NULL) &&
g_Ctoc(pathbuf, buf, sizeof(buf))) {
errno = E2BIG;
return (GLOB_NOSPACE);
@@ -1090,10 +1115,21 @@ err_nomatch(glob_t *pglob, struct glob_limit *limit, const char *origpat) {
}
static int
-err_aborted(glob_t *pglob, int err, char *buf) {
- if ((pglob->gl_errfunc != NULL && pglob->gl_errfunc(buf, err)) ||
- (pglob->gl_flags & GLOB_ERR))
+err_aborted(glob_t *pglob, int err, char *buf)
+{
+ int rv = 0;
+
+ if ((pglob->gl_flags & _GLOB_ERR_BLOCK) != 0) {
+ if (pglob->gl_errblk != NULL)
+ rv = CALL_BLOCK((glob_b_block)pglob->gl_errblk, buf,
+ errno);
+ } else if (pglob->gl_errfunc != NULL) {
+ rv = pglob->gl_errfunc(buf, errno);
+ }
+ /* GLOB_ERR is allowed to override the error callback function. */
+ if (rv != 0 || pglob->gl_flags & GLOB_ERR) {
return (GLOB_ABORTED);
+ }
return (0);
}
diff --git a/lib/libc/gen/initgroups.3 b/lib/libc/gen/initgroups.3
index 179e6da4f57d..74133e7d7048 100644
--- a/lib/libc/gen/initgroups.3
+++ b/lib/libc/gen/initgroups.3
@@ -1,5 +1,13 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2025 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Olivier Certner
+.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+.\" Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -25,15 +33,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)initgroups.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd October 26, 2014
+.Dd October 9, 2025
.Dt INITGROUPS 3
.Os
.Sh NAME
.Nm initgroups
-.Nd initialize group access list
+.Nd initialize supplementary groups as per the group database
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -43,19 +48,18 @@
.Sh DESCRIPTION
The
.Fn initgroups
-function
-uses the
-.Xr getgrouplist 3
-function to calculate the group access list for the user
-specified in
+function initializes the current process' supplementary groups as prescribed by
+its arguments and the system's group database.
+.Pp
+It first uses the
+.Fn getgrouplist
+function to compute a list of groups containing the passed
+.Fa basegid ,
+which typically is the user's initial numerical group ID from the password
+database, and the supplementary groups in the group database for the user named
.Fa name .
-This group list is then setup for the current process using
-.Xr setgroups 2 .
-The
-.Fa basegid
-is automatically included in the groups list.
-Typically this value is given as
-the group number from the password file.
+It then installs this list as the current process' supplementary groups using
+.Fn setgroups .
.Sh RETURN VALUES
.Rv -std initgroups
.Sh ERRORS
@@ -63,9 +67,9 @@ The
.Fn initgroups
function may fail and set
.Va errno
-for any of the errors specified for the library function
-.Xr setgroups 2 .
-It may also return:
+to any of the errors specified for the
+.Xr setgroups 2
+system call, or to:
.Bl -tag -width Er
.It Bq Er ENOMEM
The
@@ -80,3 +84,67 @@ The
.Fn initgroups
function appeared in
.Bx 4.2 .
+.Pp
+The
+.Fn initgroups
+function changed semantics in
+.Fx 15 ,
+following that of
+.Xr setgroups 2
+in the same release.
+Before that, it would also set the effective group ID to
+.Fa basegid ,
+and would not include the latter in the supplementary groups except before
+.Fx 8 .
+Its current behavior in these respects is known to be compatible with that of
+the following systems up to the specified versions that are current at time of
+this writing:
+.Bl -dash -width "-" -compact
+.It
+Linux (up to 6.6) with the GNU libc (up to 2.42)
+.It
+.Nx 1.1 and greater (up to 10)
+.It
+.Ox (up to 7.7)
+.It
+Systems based on illumos (up to August 2025 sources)
+.El
+.Sh SECURITY CONSIDERATIONS
+As
+.Fa basegid
+is typically the user's initial numerical group ID, to which the current
+process' effective group ID is generally initialized, processes using functions
+to change their effective group ID
+.Pq via Xr setgid 2 or similar
+or that are spawned from executables with the set-group-ID mode bit set will not
+be able to relinquish the access rights deriving from being a member of
+.Fa basegid ,
+as these functions do not change the supplementary groups.
+.Pp
+This behavior is generally desirable in order to paper over the difference of
+treatment between the effective group and supplementary ones in this situation,
+as they are all in the end indiscriminately used in traditional UNIX
+discretionary access checks.
+It blends well with the practice of allocating each user its own private group,
+as processes launched from a set-group-ID executable keep the same user and
+consistently stay also in the same user's group.
+Finally, it was also chosen for compatibility with other systems
+.Po
+see the
+.Sx HISTORY
+section
+.Pc .
+.Pp
+This convention of including
+.Fa basegid
+in the supplementary groups is however only enforced by the
+.Fn initgroups
+function, and not by the
+.Xr setgroups 2
+system call, so applications expressly wanting to include in the supplementary
+groups only those specified by the group database can themselves call
+.Fn getgrouplist
+and then
+.Fn setgroups
+on the result with the first element skipped
+.Pq see Xr getgrouplist 3 .
diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c
index 882dadbeb9ab..a1a7d92250e2 100644
--- a/lib/libc/gen/initgroups.c
+++ b/lib/libc/gen/initgroups.c
@@ -3,6 +3,11 @@
*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Olivier Certner
+ * <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+ * Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,38 +34,52 @@
* SUCH DAMAGE.
*/
+/* For __sym_compat(). */
#include <sys/cdefs.h>
-__SCCSID("@(#)initgroups.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include "namespace.h"
-#include <err.h>
-#include "un-namespace.h"
#include <errno.h>
-#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-int
-initgroups(const char *uname, gid_t agroup)
+/* For freebsd14_setgroups(). */
+#include "gen-compat.h"
+
+static int
+initgroups_impl(const char *uname, gid_t agroup,
+ int (*setgroups)(int, const gid_t *))
{
- int ngroups, ret;
- long ngroups_max;
gid_t *groups;
+ long ngroups_max;
+ int ngroups, ret;
/*
- * Provide space for one group more than possible to allow
- * setgroups to fail and set errno.
+ * Provide space for one group more than possible to allow setgroups()
+ * to fail and set 'errno' in case we get back more than {NGROUPS_MAX} +
+ * 1 groups.
*/
ngroups_max = sysconf(_SC_NGROUPS_MAX) + 2;
- if ((groups = malloc(sizeof(*groups) * ngroups_max)) == NULL)
- return (ENOMEM);
+ groups = malloc(sizeof(*groups) * ngroups_max);
+ if (groups == NULL)
+ return (-1); /* malloc() set 'errno'. */
ngroups = (int)ngroups_max;
- getgrouplist(uname, agroup, groups, &ngroups);
- ret = setgroups(ngroups, groups);
+ (void)getgrouplist(uname, agroup, groups, &ngroups);
+ ret = (*setgroups)(ngroups, groups);
+
free(groups);
- return (ret);
+ return (ret); /* setgroups() set 'errno'. */
}
+
+int
+initgroups(const char *uname, gid_t agroup)
+{
+ return (initgroups_impl(uname, agroup, setgroups));
+}
+
+int
+freebsd14_initgroups(const char *uname, gid_t agroup)
+{
+ return (initgroups_impl(uname, agroup, freebsd14_setgroups));
+}
+
+__sym_compat(initgroups, freebsd14_initgroups, FBSD_1.0);
diff --git a/lib/libc/gen/inotify.c b/lib/libc/gen/inotify.c
new file mode 100644
index 000000000000..7ce53aaccd58
--- /dev/null
+++ b/lib/libc/gen/inotify.c
@@ -0,0 +1,48 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Klara, Inc.
+ */
+
+#include "namespace.h"
+#include <sys/fcntl.h>
+#include <sys/inotify.h>
+#include <sys/specialfd.h>
+#include "un-namespace.h"
+#include "libc_private.h"
+
+/*
+ * Provide compatibility with libinotify, which uses different values for these
+ * flags.
+ */
+#define IN_NONBLOCK_OLD 0x80000
+#define IN_CLOEXEC_OLD 0x00800
+
+int
+inotify_add_watch(int fd, const char *pathname, uint32_t mask)
+{
+ return (inotify_add_watch_at(fd, AT_FDCWD, pathname, mask));
+}
+
+int
+inotify_init1(int flags)
+{
+ struct specialfd_inotify args;
+
+ if ((flags & IN_NONBLOCK_OLD) != 0) {
+ flags &= ~IN_NONBLOCK_OLD;
+ flags |= IN_NONBLOCK;
+ }
+ if ((flags & IN_CLOEXEC_OLD) != 0) {
+ flags &= ~IN_CLOEXEC_OLD;
+ flags |= IN_CLOEXEC;
+ }
+ args.flags = flags;
+ return (__sys___specialfd(SPECIALFD_INOTIFY, &args, sizeof(args)));
+}
+
+int
+inotify_init(void)
+{
+ return (inotify_init1(0));
+}
diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c
index de55b67ac0d0..8844f3121538 100644
--- a/lib/libc/gen/isatty.c
+++ b/lib/libc/gen/isatty.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)isatty.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <termios.h>
#include <unistd.h>
diff --git a/lib/libc/gen/isgreater.3 b/lib/libc/gen/isgreater.3
index 27e958f19b09..279867a2ba36 100644
--- a/lib/libc/gen/isgreater.3
+++ b/lib/libc/gen/isgreater.3
@@ -22,8 +22,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd February 12, 2003
.Dt ISGREATER 3
.Os
diff --git a/lib/libc/gen/isinf.c b/lib/libc/gen/isinf.c
index ec62762c641a..3f4fdacb791f 100644
--- a/lib/libc/gen/isinf.c
+++ b/lib/libc/gen/isinf.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <machine/float.h>
diff --git a/lib/libc/gen/isnan.c b/lib/libc/gen/isnan.c
index ea84c7ebe403..e6e2b16a92ce 100644
--- a/lib/libc/gen/isnan.c
+++ b/lib/libc/gen/isnan.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <math.h>
diff --git a/lib/libc/gen/jrand48.c b/lib/libc/gen/jrand48.c
index 5aab1e1bec9e..93442439d49e 100644
--- a/lib/libc/gen/jrand48.c
+++ b/lib/libc/gen/jrand48.c
@@ -11,17 +11,13 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdint.h>
-
#include "rand48.h"
long
jrand48(unsigned short xseed[3])
{
+ uint48 tmp;
- _dorand48(xseed);
- return ((int32_t)(((uint32_t)xseed[2] << 16) | (uint32_t)xseed[1]));
+ DORAND48(tmp, xseed);
+ return ((int)((tmp >> 16) & 0xffffffff));
}
diff --git a/lib/libc/gen/sched_getcpu_gen.c b/lib/libc/gen/kqueue1.c
index ef1bebc2915a..b27a8f63019e 100644
--- a/lib/libc/gen/sched_getcpu_gen.c
+++ b/lib/libc/gen/kqueue1.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2021 The FreeBSD Foundation
+ * Copyright (c) 2023 The FreeBSD Foundation
*
* This software were developed by Konstantin Belousov <kib@FreeBSD.org>
* under sponsorship from the FreeBSD Foundation.
@@ -26,11 +26,27 @@
* SUCH DAMAGE.
*/
-#include <sched.h>
-#include "libc_private.h"
+#include <sys/param.h>
+#include <sys/event.h>
+#include <errno.h>
+#include <fcntl.h>
+/*
+ * Provide some NetBSD compatibility. They support a set of O_*
+ * flags, we only carry O_CLOEXEC, and accept but ignore O_NONBLOCK.
+ */
int
-sched_getcpu(void)
+kqueue1(int openflags)
{
- return (__sys_sched_getcpu());
+ u_int flags;
+
+ if ((openflags & ~(O_CLOEXEC | O_NONBLOCK)) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ flags = 0;
+ if ((openflags & O_CLOEXEC) != 0)
+ flags |= KQUEUE_CLOEXEC;
+ return (kqueuex(flags));
}
diff --git a/lib/libc/gen/lcong48.c b/lib/libc/gen/lcong48.c
index ab0d1f762d80..871b2110ed94 100644
--- a/lib/libc/gen/lcong48.c
+++ b/lib/libc/gen/lcong48.c
@@ -11,23 +11,12 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-extern unsigned short _rand48_mult[3];
-extern unsigned short _rand48_add;
-
void
lcong48(unsigned short p[7])
{
- _rand48_seed[0] = p[0];
- _rand48_seed[1] = p[1];
- _rand48_seed[2] = p[2];
- _rand48_mult[0] = p[3];
- _rand48_mult[1] = p[4];
- _rand48_mult[2] = p[5];
+ LOADRAND48(_rand48_seed, &p[0]);
+ LOADRAND48(_rand48_mult, &p[3]);
_rand48_add = p[6];
}
diff --git a/lib/libc/gen/ldexp.3 b/lib/libc/gen/ldexp.3
index 91d9e2b15800..d89dea2d16c7 100644
--- a/lib/libc/gen/ldexp.3
+++ b/lib/libc/gen/ldexp.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ldexp.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
.Dd March 4, 2005
.Dt LDEXP 3
.Os
diff --git a/lib/libc/gen/ldexp.c b/lib/libc/gen/ldexp.c
index cbbcf0782387..1db62afc609e 100644
--- a/lib/libc/gen/ldexp.c
+++ b/lib/libc/gen/ldexp.c
@@ -1,6 +1,3 @@
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
/*
* ldexp() and scalbn() are defined to be identical, but ldexp() lives in libc
* for backwards compatibility.
diff --git a/lib/libc/gen/libc_dlopen.c b/lib/libc/gen/libc_dlopen.c
index 5c386b649456..4e5ec2961ac2 100644
--- a/lib/libc/gen/libc_dlopen.c
+++ b/lib/libc/gen/libc_dlopen.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Xin LI <delphij@FreeBSD.org>
*
@@ -23,13 +23,8 @@
* 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.
- *
- * $FreeBSD$
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <dlfcn.h>
#include <stddef.h>
#include <unistd.h>
diff --git a/lib/libc/gen/sendmmsg.c b/lib/libc/gen/libc_interposing_table.c
index 7b3e8f357613..025a67ac3eac 100644
--- a/lib/libc/gen/sendmmsg.c
+++ b/lib/libc/gen/libc_interposing_table.c
@@ -1,6 +1,8 @@
/*
- * Copyright (c) 2016 Boris Astardzhiev, Smartcom-Bulgaria AD
- * All rights reserved.
+ * Copyright (c) 2014 The FreeBSD Foundation.
+ *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,38 +29,27 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
-#include <sys/socket.h>
+#include <stddef.h>
#include "libc_private.h"
-ssize_t
-sendmmsg(int s, struct mmsghdr *__restrict msgvec, size_t vlen, int flags)
-{
- size_t i, sent;
- ssize_t ret;
-
- sent = 0;
- for (i = 0; i < vlen; i++, sent++) {
- ret = __sys_sendmsg(s, &msgvec[i].msg_hdr, flags);
- if (ret == -1) {
- if (sent != 0) {
- /*
- * We have sent messages. Let caller
- * know about the data sent, socket
- * error is returned on next
- * invocation.
- */
- return (sent);
- }
- return (ret);
- }
-
- /* Save sent bytes. */
- msgvec[i].msg_len = ret;
- }
+#define SLOT(a, b) \
+ [INTERPOS_##a] = (interpos_func_t)b
+interpos_func_t __libc_interposing[INTERPOS_MAX] = {
+ SLOT(system, __libc_system),
+ SLOT(tcdrain, __libc_tcdrain),
+ SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub),
+ SLOT(spinlock, __libc_spinlock_stub),
+ SLOT(spinunlock, __libc_spinunlock_stub),
+ SLOT(map_stacks_exec, __libc_map_stacks_exec),
+ SLOT(uexterr_gettext, __libc_uexterr_gettext),
+};
+#undef SLOT
- return (sent);
+interpos_func_t *
+__libc_interposing_slot(int interposno)
+{
+ if (__libc_interposing[interposno] == NULL)
+ return (__libsys_interposing_slot(interposno));
+ return (&__libc_interposing[interposno]);
}
diff --git a/lib/libc/gen/lockf.3 b/lib/libc/gen/lockf.3
deleted file mode 100644
index a4adcfa6e2ab..000000000000
--- a/lib/libc/gen/lockf.3
+++ /dev/null
@@ -1,266 +0,0 @@
-.\" $NetBSD: lockf.3,v 1.10 2008/04/30 13:10:50 martin Exp $
-.\"
-.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to The NetBSD Foundation
-.\" by Klaus Klein and S.P. Zeidler.
-.\"
-.\" 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.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd September 11, 2013
-.Dt LOCKF 3
-.Os
-.Sh NAME
-.Nm lockf
-.Nd record locking on files
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In unistd.h
-.Ft int
-.Fn lockf "int fd" "int function" "off_t size"
-.Sh DESCRIPTION
-The
-.Fn lockf
-function allows sections of a file to be locked with advisory-mode locks.
-Calls to
-.Fn lockf
-from other processes which attempt to lock the locked file section will
-either return an error value or block until the section becomes unlocked.
-All the locks for a process are removed when the process terminates.
-.Pp
-The argument
-.Fa fd
-is an open file descriptor.
-The file descriptor must have been opened either for write-only
-.Dv ( O_WRONLY )
-or read/write
-.Dv ( O_RDWR )
-operation.
-.Pp
-The
-.Fa function
-argument is a control value which specifies the action to be taken.
-The permissible values for
-.Fa function
-are as follows:
-.Bl -tag -width F_ULOCKXX -compact -offset indent
-.It Sy Function
-.Sy Description
-.It Dv F_ULOCK
-unlock locked sections
-.It Dv F_LOCK
-lock a section for exclusive use
-.It Dv F_TLOCK
-test and lock a section for exclusive use
-.It Dv F_TEST
-test a section for locks by other processes
-.El
-.Pp
-.Dv F_ULOCK
-removes locks from a section of the file;
-.Dv F_LOCK
-and
-.Dv F_TLOCK
-both lock a section of a file if the section is available;
-.Dv F_TEST
-detects if a lock by another process is present on the specified section.
-.Pp
-The
-.Fa size
-argument is the number of contiguous bytes to be locked or
-unlocked.
-The section to be locked or unlocked starts at the current
-offset in the file and extends forward for a positive size or backward
-for a negative size (the preceding bytes up to but not including the
-current offset).
-However, it is not permitted to lock a section that
-starts or extends before the beginning of the file.
-If
-.Fa size
-is 0, the section from the current offset through the largest possible
-file offset is locked (that is, from the current offset through the
-present or any future end-of-file).
-.Pp
-The sections locked with
-.Dv F_LOCK
-or
-.Dv F_TLOCK
-may, in whole or in part, contain or be contained by a previously
-locked section for the same process.
-When this occurs, or if adjacent
-locked sections would occur, the sections are combined into a single
-locked section.
-If the request would cause the number of locks to
-exceed a system-imposed limit, the request will fail.
-.Pp
-.Dv F_LOCK
-and
-.Dv F_TLOCK
-requests differ only by the action taken if the section is not
-available.
-.Dv F_LOCK
-blocks the calling process until the section is available.
-.Dv F_TLOCK
-makes the function fail if the section is already locked by another
-process.
-.Pp
-File locks are released on first close by the locking process of any
-file descriptor for the file.
-.Pp
-.Dv F_ULOCK
-requests release (wholly or in part) one or more locked sections
-controlled by the process.
-Locked sections will be unlocked starting
-at the current file offset through
-.Fa size
-bytes or to the end of file if size is 0.
-When all of a locked section
-is not released (that is, when the beginning or end of the area to be
-unlocked falls within a locked section), the remaining portions of
-that section are still locked by the process.
-Releasing the center
-portion of a locked section will cause the remaining locked beginning
-and end portions to become two separate locked sections.
-If the
-request would cause the number of locks in the system to exceed a
-system-imposed limit, the request will fail.
-.Pp
-An
-.Dv F_ULOCK
-request in which size is non-zero and the offset of the last byte of
-the requested section is the maximum value for an object of type
-off_t, when the process has an existing lock in which size is 0 and
-which includes the last byte of the requested section, will be treated
-as a request to unlock from the start of the requested section with a
-size equal to 0.
-Otherwise an
-.Dv F_ULOCK
-request will attempt to unlock only the requested section.
-.Pp
-A potential for deadlock occurs if a process controlling a locked
-region is put to sleep by attempting to lock the locked region of
-another process.
-This implementation detects that sleeping until a
-locked region is unlocked would cause a deadlock and fails with an
-.Er EDEADLK
-error.
-.Pp
-The
-.Fn lockf ,
-.Xr fcntl 2 ,
-and
-.Xr flock 2
-locks are compatible.
-Processes using different locking interfaces can cooperate
-over the same file safely.
-However, only one of such interfaces should be used within
-the same process.
-If a file is locked by a process through
-.Xr flock 2 ,
-any record within the file will be seen as locked
-from the viewpoint of another process using
-.Xr fcntl 2
-or
-.Fn lockf ,
-and vice versa.
-.Pp
-Blocking on a section is interrupted by any signal.
-.Sh RETURN VALUES
-.Rv -std lockf
-In the case of a failure, existing locks are not changed.
-.Sh ERRORS
-The
-.Fn lockf
-function
-will fail if:
-.Bl -tag -width Er
-.It Bq Er EAGAIN
-The argument
-.Fa function
-is
-.Dv F_TLOCK
-or
-.Dv F_TEST
-and the section is already locked by another process.
-.It Bq Er EBADF
-The argument
-.Fa fd
-is not a valid open file descriptor.
-.Pp
-The argument
-.Fa function
-is
-.Dv F_LOCK
-or
-.Dv F_TLOCK ,
-and
-.Fa fd
-is not a valid file descriptor open for writing.
-.It Bq Er EDEADLK
-The argument
-.Fa function
-is
-.Dv F_LOCK
-and a deadlock is detected.
-.It Bq Er EINTR
-The argument
-.Fa function
-is F_LOCK
-and
-.Fn lockf
-was interrupted by the delivery of a signal.
-.It Bq Er EINVAL
-The argument
-.Fa function
-is not one of
-.Dv F_ULOCK ,
-.Dv F_LOCK ,
-.Dv F_TLOCK
-or
-.Dv F_TEST .
-.Pp
-The argument
-.Fa fd
-refers to a file that does not support locking.
-.It Bq Er ENOLCK
-The argument
-.Fa function
-is
-.Dv F_ULOCK ,
-.Dv F_LOCK
-or
-.Dv F_TLOCK ,
-and satisfying the lock or unlock request would result in the number
-of locked regions in the system exceeding a system-imposed limit.
-.El
-.Sh SEE ALSO
-.Xr fcntl 2 ,
-.Xr flock 2
-.Sh STANDARDS
-The
-.Fn lockf
-function conforms to
-.St -xpg4.2 .
diff --git a/lib/libc/gen/lockf.c b/lib/libc/gen/lockf.c
deleted file mode 100644
index 20f016dd1694..000000000000
--- a/lib/libc/gen/lockf.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* $NetBSD: lockf.c,v 1.3 2008/04/28 20:22:59 martin Exp $ */
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
- *
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Klaus Klein.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-int
-lockf(int filedes, int function, off_t size)
-{
- struct flock fl;
- int cmd;
-
- fl.l_start = 0;
- fl.l_len = size;
- fl.l_whence = SEEK_CUR;
-
- switch (function) {
- case F_ULOCK:
- cmd = F_SETLK;
- fl.l_type = F_UNLCK;
- break;
- case F_LOCK:
- cmd = F_SETLKW;
- fl.l_type = F_WRLCK;
- break;
- case F_TLOCK:
- cmd = F_SETLK;
- fl.l_type = F_WRLCK;
- break;
- case F_TEST:
- fl.l_type = F_WRLCK;
- if (((int (*)(int, int, ...))
- __libc_interposing[INTERPOS_fcntl])(filedes, F_GETLK, &fl)
- == -1)
- return (-1);
- if (fl.l_type == F_UNLCK || (fl.l_sysid == 0 &&
- fl.l_pid == getpid()))
- return (0);
- errno = EAGAIN;
- return (-1);
- /* NOTREACHED */
- default:
- errno = EINVAL;
- return (-1);
- /* NOTREACHED */
- }
-
- return (((int (*)(int, int, ...))
- __libc_interposing[INTERPOS_fcntl])(filedes, cmd, &fl));
-}
diff --git a/lib/libc/gen/lrand48.c b/lib/libc/gen/lrand48.c
index 44a7f5d0e924..cc07044b8af9 100644
--- a/lib/libc/gen/lrand48.c
+++ b/lib/libc/gen/lrand48.c
@@ -11,16 +11,11 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-
long
lrand48(void)
{
- _dorand48(_rand48_seed);
- return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1);
+ _DORAND48(_rand48_seed);
+ return (_rand48_seed >> 17) & 0x7fffffff;
}
diff --git a/lib/libc/gen/makecontext.3 b/lib/libc/gen/makecontext.3
index e75681795bee..198c541d40a6 100644
--- a/lib/libc/gen/makecontext.3
+++ b/lib/libc/gen/makecontext.3
@@ -33,8 +33,6 @@
.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
.\" THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 23, 2020
.Dt MAKECONTEXT 3
.Os
@@ -154,6 +152,7 @@ via
.Fn makecontext ;
portable applications should not rely on the implementation detail that
it may be possible to pass pointer arguments to functions.
+.Ef
.Sh HISTORY
The
.Fn makecontext
diff --git a/lib/libc/gen/memalign.c b/lib/libc/gen/memalign.c
index 4f5ea2fd61fd..269a5bc829b1 100644
--- a/lib/libc/gen/memalign.c
+++ b/lib/libc/gen/memalign.c
@@ -26,14 +26,18 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <stdlib.h>
void *
memalign(size_t align, size_t size)
{
- return (aligned_alloc(align, roundup(size, align)));
+ /*
+ * glibc allows align == 0, but that is not valid for roundup.
+ * Just pass through to malloc in that case.
+ */
+ if (align != 0)
+ return (aligned_alloc(align, roundup(size, align)));
+ else
+ return (malloc(size));
}
diff --git a/lib/libc/gen/memfd_create.c b/lib/libc/gen/memfd_create.c
new file mode 100644
index 000000000000..78131f46d7b1
--- /dev/null
+++ b/lib/libc/gen/memfd_create.c
@@ -0,0 +1,121 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org>
+ *
+ * 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(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), 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 HOLDER(S) ``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(S) 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.
+ */
+
+#include <sys/param.h>
+#include <sys/filio.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libc_private.h"
+
+#define MEMFD_NAME_PREFIX "memfd:"
+
+/*
+ * The path argument is passed to the kernel, but the kernel doesn't currently
+ * do anything with it. Linux exposes it in linprocfs for debugging purposes
+ * only, but our kernel currently will not do the same.
+ */
+int
+memfd_create(const char *name, unsigned int flags)
+{
+ char memfd_name[NAME_MAX + 1];
+ size_t pgs[MAXPAGESIZES];
+ size_t namelen, pgsize;
+ struct shm_largepage_conf slc;
+ int error, fd, npgs, oflags, pgidx, saved_errno, shmflags;
+
+ if (name == NULL) {
+ errno = EBADF;
+ return (-1);
+ }
+ namelen = strlen(name);
+ if (namelen + sizeof(MEMFD_NAME_PREFIX) - 1 > NAME_MAX) {
+ errno = EINVAL;
+ return (-1);
+ }
+ if ((flags & ~(MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB |
+ MFD_HUGE_MASK)) != 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+ /* Size specified but no HUGETLB. */
+ if ((flags & MFD_HUGE_MASK) != 0 && (flags & MFD_HUGETLB) == 0) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ /* We've already validated that we're sufficiently sized. */
+ snprintf(memfd_name, NAME_MAX + 1, "%s%s", MEMFD_NAME_PREFIX, name);
+ oflags = O_RDWR;
+ shmflags = 0;
+ if ((flags & MFD_CLOEXEC) != 0)
+ oflags |= O_CLOEXEC;
+ if ((flags & MFD_ALLOW_SEALING) != 0)
+ shmflags |= SHM_ALLOW_SEALING;
+ if ((flags & MFD_HUGETLB) != 0)
+ shmflags |= SHM_LARGEPAGE;
+ else
+ shmflags |= SHM_GROW_ON_WRITE;
+ fd = __sys_shm_open2(SHM_ANON, oflags, 0, shmflags, memfd_name);
+ if (fd == -1 || (flags & MFD_HUGETLB) == 0)
+ return (fd);
+
+ 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;
+ goto clean;
+ }
+
+ memset(&slc, 0, sizeof(slc));
+ slc.psind = pgidx;
+ slc.alloc_policy = SHM_LARGEPAGE_ALLOC_DEFAULT;
+ error = ioctl(fd, FIOSSHMLPGCNF, &slc);
+ if (error == -1)
+ goto clean;
+ return (fd);
+
+clean:
+ saved_errno = errno;
+ close(fd);
+ errno = saved_errno;
+ return (-1);
+}
diff --git a/lib/libc/gen/modf.3 b/lib/libc/gen/modf.3
index 493f5866d6e1..9d698ff62ce6 100644
--- a/lib/libc/gen/modf.3
+++ b/lib/libc/gen/modf.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)modf.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd March 29, 2008
.Dt MODF 3
.Os
diff --git a/lib/libc/gen/modf.c b/lib/libc/gen/modf.c
index d67b44121aaa..b4093d6e930c 100644
--- a/lib/libc/gen/modf.c
+++ b/lib/libc/gen/modf.c
@@ -1,4 +1,3 @@
-/* @(#)s_modf.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
@@ -10,9 +9,6 @@
* ====================================================
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
/*
* modf(double x, double *iptr)
* return fraction part of x, and return x's integral part in *iptr.
diff --git a/lib/libc/gen/mrand48.c b/lib/libc/gen/mrand48.c
index 795a8585802d..f9128a6d4188 100644
--- a/lib/libc/gen/mrand48.c
+++ b/lib/libc/gen/mrand48.c
@@ -11,20 +11,13 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdint.h>
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-
long
mrand48(void)
{
-
- _dorand48(_rand48_seed);
- return ((int32_t)(((uint32_t)_rand48_seed[2] << 16) |
- (uint32_t)_rand48_seed[1]));
+ _DORAND48(_rand48_seed);
+ return ((int)((_rand48_seed >> 16) & 0xffffffff));
}
diff --git a/lib/libc/gen/nftw-compat11.c b/lib/libc/gen/nftw-compat11.c
index 1cf9ba8cb9b6..36970424bf2a 100644
--- a/lib/libc/gen/nftw-compat11.c
+++ b/lib/libc/gen/nftw-compat11.c
@@ -21,9 +21,6 @@
* From: FreeBSD: head/lib/libc/gen/nftw.c 239160 2012-08-09 22:05:40Z jilles
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/lib/libc/gen/nftw.c b/lib/libc/gen/nftw.c
index a338e5a34c84..95cc9947b7c1 100644
--- a/lib/libc/gen/nftw.c
+++ b/lib/libc/gen/nftw.c
@@ -20,9 +20,6 @@
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/lib/libc/gen/nice.3 b/lib/libc/gen/nice.3
index dee1a3da9100..011b4c33effc 100644
--- a/lib/libc/gen/nice.3
+++ b/lib/libc/gen/nice.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)nice.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd February 28, 2015
.Dt NICE 3
.Os
diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c
index 7f217059fb11..a96d4d06e081 100644
--- a/lib/libc/gen/nice.c
+++ b/lib/libc/gen/nice.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)nice.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
diff --git a/lib/libc/gen/nlist.3 b/lib/libc/gen/nlist.3
index ea9ad732d387..f4ef59083dab 100644
--- a/lib/libc/gen/nlist.3
+++ b/lib/libc/gen/nlist.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)nlist.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
.Dd April 19, 1994
.Dt NLIST 3
.Os
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index c30fa4dbaca2..ebf4ae92641a 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)nlist.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/mman.h>
diff --git a/lib/libc/gen/nrand48.c b/lib/libc/gen/nrand48.c
index 16c8ca111b5e..f6f4e231105c 100644
--- a/lib/libc/gen/nrand48.c
+++ b/lib/libc/gen/nrand48.c
@@ -11,14 +11,13 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
long
nrand48(unsigned short xseed[3])
{
- _dorand48(xseed);
- return ((long) xseed[2] << 15) + ((long) xseed[1] >> 1);
+ uint48 tmp;
+
+ DORAND48(tmp, xseed);
+ return ((tmp >> 17) & 0x7fffffff);
}
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index c294081847e2..08d9eb10eaa2 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -29,26 +29,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)opendir.c 8.8 (Berkeley) 5/1/95");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
-#include <sys/param.h>
-
#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
#include "un-namespace.h"
#include "gen-private.h"
#include "telldir.h"
-static DIR * __opendir_common(int, int, bool);
-
/*
* Open a directory.
*/
@@ -56,313 +43,5 @@ DIR *
opendir(const char *name)
{
- return (__opendir2(name, DTF_HIDEW|DTF_NODUP));
-}
-
-/*
- * Open a directory with existing file descriptor.
- */
-DIR *
-fdopendir(int fd)
-{
-
- if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
- return (NULL);
- return (__opendir_common(fd, DTF_HIDEW|DTF_NODUP, true));
-}
-
-DIR *
-__opendir2(const char *name, int flags)
-{
- int fd;
- DIR *dir;
- int saved_errno;
-
- if ((flags & (__DTF_READALL | __DTF_SKIPREAD)) != 0)
- return (NULL);
- if ((fd = _open(name,
- O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC)) == -1)
- return (NULL);
-
- dir = __opendir_common(fd, flags, false);
- if (dir == NULL) {
- saved_errno = errno;
- _close(fd);
- errno = saved_errno;
- }
- return (dir);
-}
-
-static int
-opendir_compar(const void *p1, const void *p2)
-{
-
- return (strcmp((*(const struct dirent * const *)p1)->d_name,
- (*(const struct dirent * const *)p2)->d_name));
-}
-
-/*
- * For a directory at the top of a unionfs stack, the entire directory's
- * contents are read and cached locally until the next call to rewinddir().
- * For the fdopendir() case, the initial seek position must be preserved.
- * For rewinddir(), the full directory should always be re-read from the
- * beginning.
- *
- * If an error occurs, the existing buffer and state of 'dirp' is left
- * unchanged.
- */
-bool
-_filldir(DIR *dirp, bool use_current_pos)
-{
- struct dirent **dpv;
- char *buf, *ddptr, *ddeptr;
- off_t pos;
- int fd2, incr, len, n, saved_errno, space;
-
- len = 0;
- space = 0;
- buf = NULL;
- ddptr = NULL;
-
- /*
- * Use the system page size if that is a multiple of DIRBLKSIZ.
- * Hopefully this can be a big win someday by allowing page
- * trades to user space to be done by _getdirentries().
- */
- incr = getpagesize();
- if ((incr % DIRBLKSIZ) != 0)
- incr = DIRBLKSIZ;
-
- /*
- * The strategy here is to read all the directory
- * entries into a buffer, sort the buffer, and
- * remove duplicate entries by setting the inode
- * number to zero.
- *
- * We reopen the directory because _getdirentries()
- * on a MNT_UNION mount modifies the open directory,
- * making it refer to the lower directory after the
- * upper directory's entries are exhausted.
- * This would otherwise break software that uses
- * the directory descriptor for fchdir or *at
- * functions, such as fts.c.
- */
- if ((fd2 = _openat(dirp->dd_fd, ".", O_RDONLY | O_CLOEXEC)) == -1)
- return (false);
-
- if (use_current_pos) {
- pos = lseek(dirp->dd_fd, 0, SEEK_CUR);
- if (pos == -1 || lseek(fd2, pos, SEEK_SET) == -1) {
- saved_errno = errno;
- _close(fd2);
- errno = saved_errno;
- return (false);
- }
- }
-
- do {
- /*
- * Always make at least DIRBLKSIZ bytes
- * available to _getdirentries
- */
- if (space < DIRBLKSIZ) {
- space += incr;
- len += incr;
- buf = reallocf(buf, len);
- if (buf == NULL) {
- saved_errno = errno;
- _close(fd2);
- errno = saved_errno;
- return (false);
- }
- ddptr = buf + (len - space);
- }
-
- n = _getdirentries(fd2, ddptr, space, &dirp->dd_seek);
- if (n > 0) {
- ddptr += n;
- space -= n;
- }
- if (n < 0) {
- saved_errno = errno;
- _close(fd2);
- errno = saved_errno;
- return (false);
- }
- } while (n > 0);
- _close(fd2);
-
- ddeptr = ddptr;
-
- /*
- * There is now a buffer full of (possibly) duplicate
- * names.
- */
- dirp->dd_buf = buf;
-
- /*
- * Go round this loop twice...
- *
- * Scan through the buffer, counting entries.
- * On the second pass, save pointers to each one.
- * Then sort the pointers and remove duplicate names.
- */
- for (dpv = NULL;;) {
- n = 0;
- ddptr = buf;
- while (ddptr < ddeptr) {
- struct dirent *dp;
-
- dp = (struct dirent *) ddptr;
- if ((long)dp & 03L)
- break;
- if ((dp->d_reclen <= 0) ||
- (dp->d_reclen > (ddeptr + 1 - ddptr)))
- break;
- ddptr += dp->d_reclen;
- if (dp->d_fileno) {
- if (dpv)
- dpv[n] = dp;
- n++;
- }
- }
-
- if (dpv) {
- struct dirent *xp;
-
- /*
- * This sort must be stable.
- */
- mergesort(dpv, n, sizeof(*dpv), opendir_compar);
-
- dpv[n] = NULL;
- xp = NULL;
-
- /*
- * Scan through the buffer in sort order,
- * zapping the inode number of any
- * duplicate names.
- */
- for (n = 0; dpv[n]; n++) {
- struct dirent *dp = dpv[n];
-
- if ((xp == NULL) ||
- strcmp(dp->d_name, xp->d_name)) {
- xp = dp;
- } else {
- dp->d_fileno = 0;
- }
- if (dp->d_type == DT_WHT &&
- (dirp->dd_flags & DTF_HIDEW))
- dp->d_fileno = 0;
- }
-
- free(dpv);
- break;
- } else {
- dpv = malloc((n+1) * sizeof(struct dirent *));
- if (dpv == NULL)
- break;
- }
- }
-
- dirp->dd_len = len;
- dirp->dd_size = ddptr - dirp->dd_buf;
- return (true);
-}
-
-static bool
-is_unionstack(int fd)
-{
- int unionstack;
-
- unionstack = _fcntl(fd, F_ISUNIONSTACK, 0);
- if (unionstack != -1)
- return (unionstack);
-
- /*
- * Should not happen unless running on a kernel without the op,
- * but no use rendering the system useless in such a case.
- */
- return (0);
-}
-
-/*
- * Common routine for opendir(3), __opendir2(3) and fdopendir(3).
- */
-static DIR *
-__opendir_common(int fd, int flags, bool use_current_pos)
-{
- DIR *dirp;
- int incr;
- int saved_errno;
- bool unionstack;
-
- if ((dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL)
- return (NULL);
-
- dirp->dd_buf = NULL;
- dirp->dd_fd = fd;
- dirp->dd_flags = flags;
- dirp->dd_loc = 0;
- dirp->dd_lock = NULL;
- dirp->dd_td = (struct _telldir *)((char *)dirp + sizeof(DIR));
- LIST_INIT(&dirp->dd_td->td_locq);
- dirp->dd_td->td_loccnt = 0;
- dirp->dd_compat_de = NULL;
-
- /*
- * Use the system page size if that is a multiple of DIRBLKSIZ.
- * Hopefully this can be a big win someday by allowing page
- * trades to user space to be done by _getdirentries().
- */
- incr = getpagesize();
- if ((incr % DIRBLKSIZ) != 0)
- incr = DIRBLKSIZ;
-
- /*
- * Determine whether this directory is the top of a union stack.
- */
- unionstack = false;
- if (flags & DTF_NODUP) {
- unionstack = is_unionstack(fd);
- }
-
- if (unionstack) {
- if (!_filldir(dirp, use_current_pos))
- goto fail;
- dirp->dd_flags |= __DTF_READALL;
- } else {
- dirp->dd_len = incr;
- dirp->dd_buf = malloc(dirp->dd_len);
- if (dirp->dd_buf == NULL)
- goto fail;
- if (use_current_pos) {
- /*
- * Read the first batch of directory entries
- * to prime dd_seek. This also checks if the
- * fd passed to fdopendir() is a directory.
- */
- dirp->dd_size = _getdirentries(dirp->dd_fd,
- dirp->dd_buf, dirp->dd_len, &dirp->dd_seek);
- if (dirp->dd_size < 0) {
- if (errno == EINVAL)
- errno = ENOTDIR;
- goto fail;
- }
- dirp->dd_flags |= __DTF_SKIPREAD;
- } else {
- dirp->dd_size = 0;
- dirp->dd_seek = 0;
- }
- }
-
- return (dirp);
-
-fail:
- saved_errno = errno;
- free(dirp->dd_buf);
- free(dirp);
- errno = saved_errno;
- return (NULL);
+ return (__opendir2(name, DTF_HIDEW | DTF_NODUP));
}
diff --git a/lib/libc/gen/opendir2.c b/lib/libc/gen/opendir2.c
new file mode 100644
index 000000000000..c5c2e662efd8
--- /dev/null
+++ b/lib/libc/gen/opendir2.c
@@ -0,0 +1,337 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#include "namespace.h"
+#include <sys/types.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "un-namespace.h"
+
+#include "gen-private.h"
+#include "telldir.h"
+
+DIR *
+__opendir2(const char *name, int flags)
+{
+ int fd;
+ DIR *dir;
+ int saved_errno;
+
+ if ((flags & (__DTF_READALL | __DTF_SKIPREAD)) != 0)
+ return (NULL);
+ if ((fd = _open(name, O_DIRECTORY | O_RDONLY | O_CLOEXEC)) == -1)
+ return (NULL);
+
+ dir = __opendir_common(fd, flags, false);
+ if (dir == NULL) {
+ saved_errno = errno;
+ _close(fd);
+ errno = saved_errno;
+ }
+ return (dir);
+}
+
+static int
+opendir_compar(const void *p1, const void *p2)
+{
+
+ return (strcmp((*(const struct dirent * const *)p1)->d_name,
+ (*(const struct dirent * const *)p2)->d_name));
+}
+
+/*
+ * For a directory at the top of a unionfs stack, the entire directory's
+ * contents are read and cached locally until the next call to rewinddir().
+ * For the fdopendir() case, the initial seek position must be preserved.
+ * For rewinddir(), the full directory should always be re-read from the
+ * beginning.
+ *
+ * If an error occurs, the existing buffer and state of 'dirp' is left
+ * unchanged.
+ */
+bool
+_filldir(DIR *dirp, bool use_current_pos)
+{
+ struct dirent **dpv;
+ char *buf, *ddptr, *ddeptr;
+ off_t pos;
+ int fd2, incr, len, n, saved_errno, space;
+
+ len = 0;
+ space = 0;
+ buf = NULL;
+ ddptr = NULL;
+
+ /*
+ * Use the system page size if that is a multiple of DIRBLKSIZ.
+ * Hopefully this can be a big win someday by allowing page
+ * trades to user space to be done by _getdirentries().
+ */
+ incr = getpagesize();
+ if ((incr % DIRBLKSIZ) != 0)
+ incr = DIRBLKSIZ;
+
+ /*
+ * The strategy here is to read all the directory
+ * entries into a buffer, sort the buffer, and
+ * remove duplicate entries by setting the inode
+ * number to zero.
+ *
+ * We reopen the directory because _getdirentries()
+ * on a MNT_UNION mount modifies the open directory,
+ * making it refer to the lower directory after the
+ * upper directory's entries are exhausted.
+ * This would otherwise break software that uses
+ * the directory descriptor for fchdir or *at
+ * functions, such as fts.c.
+ */
+ if ((fd2 = _openat(dirp->dd_fd, ".", O_RDONLY | O_CLOEXEC)) == -1)
+ return (false);
+
+ if (use_current_pos) {
+ pos = lseek(dirp->dd_fd, 0, SEEK_CUR);
+ if (pos == -1 || lseek(fd2, pos, SEEK_SET) == -1) {
+ saved_errno = errno;
+ _close(fd2);
+ errno = saved_errno;
+ return (false);
+ }
+ }
+
+ do {
+ /*
+ * Always make at least DIRBLKSIZ bytes
+ * available to _getdirentries
+ */
+ if (space < DIRBLKSIZ) {
+ space += incr;
+ len += incr;
+ buf = reallocf(buf, len);
+ if (buf == NULL) {
+ saved_errno = errno;
+ _close(fd2);
+ errno = saved_errno;
+ return (false);
+ }
+ ddptr = buf + (len - space);
+ }
+
+ n = _getdirentries(fd2, ddptr, space, &dirp->dd_seek);
+ if (n > 0) {
+ ddptr += n;
+ space -= n;
+ }
+ if (n < 0) {
+ saved_errno = errno;
+ _close(fd2);
+ errno = saved_errno;
+ return (false);
+ }
+ } while (n > 0);
+ _close(fd2);
+
+ ddeptr = ddptr;
+
+ /*
+ * There is now a buffer full of (possibly) duplicate
+ * names.
+ */
+ dirp->dd_buf = buf;
+
+ /*
+ * Go round this loop twice...
+ *
+ * Scan through the buffer, counting entries.
+ * On the second pass, save pointers to each one.
+ * Then sort the pointers and remove duplicate names.
+ */
+ for (dpv = NULL;;) {
+ n = 0;
+ ddptr = buf;
+ while (ddptr < ddeptr) {
+ struct dirent *dp;
+
+ dp = (struct dirent *) ddptr;
+ if ((long)dp & 03L)
+ break;
+ if ((dp->d_reclen <= 0) ||
+ (dp->d_reclen > (ddeptr + 1 - ddptr)))
+ break;
+ ddptr += dp->d_reclen;
+ if (dp->d_fileno) {
+ if (dpv)
+ dpv[n] = dp;
+ n++;
+ }
+ }
+
+ if (dpv) {
+ struct dirent *xp;
+
+ /*
+ * This sort must be stable.
+ */
+ mergesort(dpv, n, sizeof(*dpv), opendir_compar);
+
+ dpv[n] = NULL;
+ xp = NULL;
+
+ /*
+ * Scan through the buffer in sort order,
+ * zapping the inode number of any
+ * duplicate names.
+ */
+ for (n = 0; dpv[n]; n++) {
+ struct dirent *dp = dpv[n];
+
+ if ((xp == NULL) ||
+ strcmp(dp->d_name, xp->d_name)) {
+ xp = dp;
+ } else {
+ dp->d_fileno = 0;
+ }
+ if (dp->d_type == DT_WHT &&
+ (dirp->dd_flags & DTF_HIDEW))
+ dp->d_fileno = 0;
+ }
+
+ free(dpv);
+ break;
+ } else {
+ dpv = malloc((n+1) * sizeof(struct dirent *));
+ if (dpv == NULL)
+ break;
+ }
+ }
+
+ dirp->dd_len = len;
+ dirp->dd_size = ddptr - dirp->dd_buf;
+ return (true);
+}
+
+/*
+ * Return true if the file descriptor is associated with a file from a
+ * union file system or from a file system mounted with the union flag.
+ */
+static bool
+is_unionstack(int fd)
+{
+ /*
+ * This call shouldn't fail, but if it does, just assume that the
+ * answer is no.
+ */
+ return (_fcntl(fd, F_ISUNIONSTACK, 0) > 0);
+}
+
+/*
+ * Common routine for opendir(3), __opendir2(3) and fdopendir(3).
+ */
+DIR *
+__opendir_common(int fd, int flags, bool use_current_pos)
+{
+ DIR *dirp;
+ ssize_t ret;
+ int incr;
+ int saved_errno;
+ bool unionstack;
+
+ if ((dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL)
+ return (NULL);
+
+ dirp->dd_buf = NULL;
+ dirp->dd_fd = fd;
+ dirp->dd_flags = flags;
+ dirp->dd_loc = 0;
+ dirp->dd_lock = NULL;
+ dirp->dd_td = (struct _telldir *)((char *)dirp + sizeof(DIR));
+ LIST_INIT(&dirp->dd_td->td_locq);
+ dirp->dd_td->td_loccnt = 0;
+ dirp->dd_compat_de = NULL;
+
+ /*
+ * Use the system page size if that is a multiple of DIRBLKSIZ.
+ * Hopefully this can be a big win someday by allowing page
+ * trades to user space to be done by _getdirentries().
+ */
+ incr = getpagesize();
+ if ((incr % DIRBLKSIZ) != 0)
+ incr = DIRBLKSIZ;
+
+ /*
+ * Determine whether this directory is the top of a union stack.
+ */
+ unionstack = false;
+ if (flags & DTF_NODUP) {
+ unionstack = is_unionstack(fd);
+ }
+
+ if (unionstack) {
+ if (!_filldir(dirp, use_current_pos))
+ goto fail;
+ dirp->dd_flags |= __DTF_READALL;
+ } else {
+ dirp->dd_len = incr;
+ dirp->dd_buf = malloc(dirp->dd_len);
+ if (dirp->dd_buf == NULL)
+ goto fail;
+ if (use_current_pos) {
+ /*
+ * Read the first batch of directory entries
+ * to prime dd_seek. This also checks if the
+ * fd passed to fdopendir() is a directory.
+ */
+ ret = _getdirentries(dirp->dd_fd,
+ dirp->dd_buf, dirp->dd_len, &dirp->dd_seek);
+ if (ret < 0)
+ goto fail;
+ dirp->dd_size = (size_t)ret;
+ dirp->dd_flags |= __DTF_SKIPREAD;
+ } else {
+ dirp->dd_size = 0;
+ dirp->dd_seek = 0;
+ }
+ }
+
+ return (dirp);
+
+fail:
+ saved_errno = errno;
+ free(dirp->dd_buf);
+ free(dirp);
+ errno = saved_errno;
+ return (NULL);
+}
diff --git a/lib/libc/gen/pause.3 b/lib/libc/gen/pause.3
index 128e81279efc..6b17ae10777d 100644
--- a/lib/libc/gen/pause.3
+++ b/lib/libc/gen/pause.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)pause.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd April 3, 2022
.Dt PAUSE 3
.Os
diff --git a/lib/libc/gen/pause.c b/lib/libc/gen/pause.c
index f6650a73a710..38aed9da7439 100644
--- a/lib/libc/gen/pause.c
+++ b/lib/libc/gen/pause.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)pause.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <signal.h>
#include <unistd.h>
diff --git a/lib/libc/gen/pmadvise.c b/lib/libc/gen/pmadvise.c
index 0dc77e3e992b..19525c939c26 100644
--- a/lib/libc/gen/pmadvise.c
+++ b/lib/libc/gen/pmadvise.c
@@ -4,9 +4,6 @@
*
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/mman.h>
#include <errno.h>
diff --git a/lib/libc/gen/popen.3 b/lib/libc/gen/popen.3
index 36af39ac1a8a..bae37eed14cf 100644
--- a/lib/libc/gen/popen.3
+++ b/lib/libc/gen/popen.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)popen.3 8.2 (Berkeley) 5/3/95
-.\" $FreeBSD$
-.\"
.Dd May 20, 2013
.Dt POPEN 3
.Os
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 4f94405c2ff4..db6b91d08af6 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)popen.c 8.3 (Berkeley) 5/3/95");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/queue.h>
@@ -53,8 +49,6 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
-extern char **environ;
-
struct pid {
SLIST_ENTRY(pid) next;
FILE *fp;
@@ -181,7 +175,7 @@ popen(const char *command, const char *type)
* the list which will cause an explicit close.
*/
if (!cloexec)
- (void)_fcntl(*type == 'r' ? pdes[0] : pdes[1], F_SETFD, 0);
+ (void)_fcntl(fileno(iop), F_SETFD, 0);
return (iop);
}
diff --git a/lib/libc/gen/posix_spawn.3 b/lib/libc/gen/posix_spawn.3
index f7d54903dcb6..278fee88463a 100644
--- a/lib/libc/gen/posix_spawn.3
+++ b/lib/libc/gen/posix_spawn.3
@@ -32,9 +32,7 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
-.Dd November 28, 2021
+.Dd March 4, 2024
.Dt POSIX_SPAWN 3
.Os
.Sh NAME
@@ -299,6 +297,15 @@ and the signals being indicated in the spawn-sigdefault attribute
of the object referenced by
.Fa attrp .
.Pp
+The Address Space Layout Randomization for the newly spawned process
+can be disabled by specifying the
+.Dv POSIX_SPAWN_DISABLE_ASLR_NP
+flag in the spawn-flags attribute.
+This setting is inherited by future children of the child as well.
+See
+.Xr procctl 2
+for more details.
+.Pp
If the value of the
.Fa attrp
pointer is NULL, then the default values are used.
@@ -434,16 +441,17 @@ action.
.Xr execve 2 ,
.Xr fcntl 2 ,
.Xr open 2 ,
+.Xr procctl 2 ,
.Xr sched_setparam 2 ,
.Xr sched_setscheduler 2 ,
.Xr setpgid 2 ,
.Xr vfork 2 ,
+.Xr posix_spawn_file_actions_addchdir_np 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_addopen 3 ,
-.Xr posix_spawn_file_actions_addchdir_np 3 ,
.Xr posix_spawn_file_actions_addfchdir_np 3 ,
+.Xr posix_spawn_file_actions_addopen 3 ,
.Xr posix_spawn_file_actions_destroy 3 ,
.Xr posix_spawn_file_actions_init 3 ,
.Xr posix_spawnattr_destroy 3 ,
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
index 909db9a60a02..a5b732696b8c 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -26,11 +26,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
+#include <sys/procctl.h>
#include <sys/queue.h>
#include <sys/wait.h>
@@ -45,8 +43,6 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "libc_private.h"
-extern char **environ;
-
struct __posix_spawnattr {
short sa_flags;
pid_t sa_pgroup;
@@ -96,7 +92,7 @@ static int
process_spawnattr(const posix_spawnattr_t sa)
{
struct sigaction sigact = { .sa_flags = 0, .sa_handler = SIG_DFL };
- int i;
+ int aslr, i;
/*
* POSIX doesn't really describe in which order everything
@@ -144,6 +140,13 @@ process_spawnattr(const posix_spawnattr_t sa)
}
}
+ /* Disable ASLR. */
+ if ((sa->sa_flags & POSIX_SPAWN_DISABLE_ASLR_NP) != 0) {
+ aslr = PROC_ASLR_FORCE_DISABLE;
+ if (procctl(P_PID, 0, PROC_ASLR_CTL, &aslr) != 0)
+ return (errno);
+ }
+
return (0);
}
@@ -231,7 +234,7 @@ struct posix_spawn_args {
#if defined(__i386__) || defined(__amd64__)
/*
* Below we'll assume that _RFORK_THREAD_STACK_SIZE is appropriately aligned for
- * the posix_spawn() case where we do not end up calling _execvpe and won't ever
+ * the posix_spawn() case where we do not end up calling execvpe and won't ever
* try to allocate space on the stack for argv[].
*/
#define _RFORK_THREAD_STACK_SIZE 4096
@@ -258,7 +261,7 @@ _posix_spawn_thr(void *data)
}
envp = psa->envp != NULL ? psa->envp : environ;
if (psa->use_env_path)
- _execvpe(psa->path, psa->argv, envp);
+ __libc_execvpe(psa->path, psa->argv, envp);
else
_execve(psa->path, psa->argv, envp);
psa->error = errno;
@@ -322,11 +325,16 @@ do_posix_spawn(pid_t *pid, const char *path,
* ideal vfork(2) if we get an EINVAL from rfork -- this should only
* happen with newer libc on older kernel that doesn't accept
* RFSPAWN.
+ *
+ * Combination of vfork() (or its equivalent rfork() form) and
+ * a special property of the libthr rtld locks ensure that
+ * rtld is operational in the child. In particular, libthr
+ * rtld locks do not store owner' tid into the lock word.
*/
#ifdef _RFORK_THREAD_STACK_SIZE
/*
* x86 stores the return address on the stack, so rfork(2) cannot work
- * as-is because the child would clobber the return address om the
+ * as-is because the child would clobber the return address of the
* parent. Because of this, we must use rfork_thread instead while
* almost every other arch stores the return address in a register.
*/
@@ -634,6 +642,11 @@ posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa,
int
posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags)
{
+ if ((flags & ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP |
+ POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER |
+ POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK |
+ POSIX_SPAWN_DISABLE_ASLR_NP)) != 0)
+ return (EINVAL);
(*sa)->sa_flags = flags;
return (0);
}
diff --git a/lib/libc/gen/posix_spawn_file_actions_addopen.3 b/lib/libc/gen/posix_spawn_file_actions_addopen.3
index 0782e15b3126..80bc91454471 100644
--- a/lib/libc/gen/posix_spawn_file_actions_addopen.3
+++ b/lib/libc/gen/posix_spawn_file_actions_addopen.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 9, 2013
.Dt POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 3
.Os
@@ -272,6 +270,6 @@ The
and
.Fn posix_spawn_file_actions_addclosefrom_np
functions first appeared in
-.Fx 14.0 .
+.Fx 13.1 .
.Sh AUTHORS
.An \&Ed Schouten Aq Mt ed@FreeBSD.org
diff --git a/lib/libc/gen/posix_spawn_file_actions_init.3 b/lib/libc/gen/posix_spawn_file_actions_init.3
index 1215a04f6386..43b176441381 100644
--- a/lib/libc/gen/posix_spawn_file_actions_init.3
+++ b/lib/libc/gen/posix_spawn_file_actions_init.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd November 28, 2021
.Dt POSIX_SPAWN_FILE_ACTIONS_INIT 3
.Os
diff --git a/lib/libc/gen/posix_spawnattr_getflags.3 b/lib/libc/gen/posix_spawnattr_getflags.3
index 2571f4ab307c..308bbb386d76 100644
--- a/lib/libc/gen/posix_spawnattr_getflags.3
+++ b/lib/libc/gen/posix_spawnattr_getflags.3
@@ -32,9 +32,7 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
-.Dd March 24, 2008
+.Dd March 4, 2024
.Dt POSIX_SPAWNATTR_GETFLAGS 3
.Os
.Sh NAME
@@ -77,6 +75,7 @@ It is the bitwise-inclusive OR of zero or more of the following flags
.It Dv POSIX_SPAWN_SETSIGMASK
.It Dv POSIX_SPAWN_SETSCHEDPARAM
.It Dv POSIX_SPAWN_SETSCHEDULER
+.It Dv POSIX_SPAWN_DISABLE_ASLR_NP
.El
.Pp
These flags are defined in
@@ -85,9 +84,12 @@ The default value of this attribute is as if no flags were set.
.Sh RETURN VALUES
The
.Fn posix_spawnattr_getflags
-and
+function returns zero.
+The
.Fn posix_spawnattr_setflags
-functions return zero.
+function returns zero on success, and
+.Er EINVAL
+on failure due to invalid flag specified.
.Sh SEE ALSO
.Xr posix_spawn 3 ,
.Xr posix_spawnattr_destroy 3 ,
diff --git a/lib/libc/gen/posix_spawnattr_getpgroup.3 b/lib/libc/gen/posix_spawnattr_getpgroup.3
index cfc1b54ab633..cd8cb4899fa3 100644
--- a/lib/libc/gen/posix_spawnattr_getpgroup.3
+++ b/lib/libc/gen/posix_spawnattr_getpgroup.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 24, 2008
.Dt POSIX_SPAWNATTR_GETPGROUP 3
.Os
diff --git a/lib/libc/gen/posix_spawnattr_getschedparam.3 b/lib/libc/gen/posix_spawnattr_getschedparam.3
index 5eef96ea825d..bdb560d954e6 100644
--- a/lib/libc/gen/posix_spawnattr_getschedparam.3
+++ b/lib/libc/gen/posix_spawnattr_getschedparam.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 24, 2008
.Dt POSIX_SPAWNATTR_GETSCHEDPARAM 3
.Os
diff --git a/lib/libc/gen/posix_spawnattr_getschedpolicy.3 b/lib/libc/gen/posix_spawnattr_getschedpolicy.3
index 5276de5a2f35..f6d32babd29b 100644
--- a/lib/libc/gen/posix_spawnattr_getschedpolicy.3
+++ b/lib/libc/gen/posix_spawnattr_getschedpolicy.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 24, 2008
.Dt POSIX_SPAWNATTR_GETSCHEDPOLICY 3
.Os
diff --git a/lib/libc/gen/posix_spawnattr_getsigdefault.3 b/lib/libc/gen/posix_spawnattr_getsigdefault.3
index a81c71417449..897c337badfe 100644
--- a/lib/libc/gen/posix_spawnattr_getsigdefault.3
+++ b/lib/libc/gen/posix_spawnattr_getsigdefault.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 24, 2008
.Dt POSIX_SPAWNATTR_GETSIGDEFAULT 3
.Os
diff --git a/lib/libc/gen/posix_spawnattr_getsigmask.3 b/lib/libc/gen/posix_spawnattr_getsigmask.3
index be15d9d47d82..3800a9bc4325 100644
--- a/lib/libc/gen/posix_spawnattr_getsigmask.3
+++ b/lib/libc/gen/posix_spawnattr_getsigmask.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 24, 2008
.Dt POSIX_SPAWNATTR_GETSIGMASK 3
.Os
diff --git a/lib/libc/gen/posix_spawnattr_init.3 b/lib/libc/gen/posix_spawnattr_init.3
index b4ec52c30e25..e5b921967bf0 100644
--- a/lib/libc/gen/posix_spawnattr_init.3
+++ b/lib/libc/gen/posix_spawnattr_init.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 24, 2008
.Dt POSIX_SPAWNATTR_INIT 3
.Os
diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3
index 597d4fc9c35b..bf6a99b4b113 100644
--- a/lib/libc/gen/psignal.3
+++ b/lib/libc/gen/psignal.3
@@ -25,17 +25,17 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)psignal.3 8.2 (Berkeley) 2/27/95
-.\" $FreeBSD$
-.\"
-.Dd May 30, 2016
+.Dd September 23, 2025
.Dt PSIGNAL 3
.Os
.Sh NAME
.Nm psignal ,
+.Nm psiginfo ,
.Nm strsignal ,
.Nm sys_siglist ,
-.Nm sys_signame
+.Nm sys_signame ,
+.Nm sig2str ,
+.Nm str2sig
.Nd system signal messages
.Sh LIBRARY
.Lb libc
@@ -43,11 +43,17 @@
.In signal.h
.Ft void
.Fn psignal "int sig" "const char *s"
+.Ft void
+.Fn psiginfo "const siginfo_t *si" "const char *s"
.Vt extern const char * const sys_siglist[] ;
.Vt extern const char * const sys_signame[] ;
.In string.h
.Ft "char *"
.Fn strsignal "int sig"
+.Ft int
+.Fn sig2str "int signum" "char *str"
+.Ft int
+.Fn str2sig "char *str" "int *pnum"
.Sh DESCRIPTION
The
.Fn psignal
@@ -82,6 +88,16 @@ the string
.Dq "Unknown signal"
is produced.
.Pp
+The
+.Fn psiginfo
+function is similar to
+.Fn psignal ,
+except that the signal number information is taken from the
+.Fa si
+argument which is a
+.Vt siginfo_t
+structure.
+.Pp
The message strings can be accessed directly
through the external array
.Va sys_siglist ,
@@ -98,12 +114,72 @@ contains a count of the strings in
.Va sys_siglist
and
.Va sys_signame .
+.Pp
+The
+.Fn sig2str
+function translates the signal number
+.Fa signum
+to the signal name, without the
+.Dq SIG
+prefix, and stores it at the location specified by
+.Fa str ,
+which should be large enough to hold the name and the terminating
+.Dv NUL
+byte.
+The symbol
+.Dv SIG2STR_MAX
+gives the maximum size in bytes required.
+.Pp
+The
+.Fn str2sig
+function translates the signal name
+.Fa str
+to a signal number and stores it in the location referenced by
+.Fa pnum .
+The name in
+.Fa str
+can be either the name of the signal, with or without the
+.Dq SIG
+prefix, or a decimal number.
+.Sh RETURN VALUES
+The
+.Fn sig2str
+and
+.Fn str2sig
+return 0 on success and -1 on translation failure.
+In the latter case the memory to store the translation result is left intact.
.Sh SEE ALSO
.Xr sigaction 2 ,
.Xr perror 3 ,
.Xr strerror 3
+.Sh STANDARDS
+The
+.Fn psignal
+and
+.Fn psiginfo
+functions are defined by
+.St -p1003.1-2008
+, while the
+.Fn sig2str
+and
+.Fn str2sig
+functions are defined by
+.St -p1003.1-2024 .
.Sh HISTORY
The
.Fn psignal
function appeared in
.Bx 4.2 .
+The
+.Fn psiginfo
+function appeared in
+.Fx 14.3 ,
+.Nx 6.0 ,
+and
+.Dx 4.1 .
+The
+.Fn sig2str
+and
+.Fn str2sig
+functions appeared in
+.Fx 15.0 .
diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c
index f4cb1079a493..291a6a9337a0 100644
--- a/lib/libc/gen/psignal.c
+++ b/lib/libc/gen/psignal.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)psignal.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
/*
* Print the name of the signal indicated
* along with the supplied message.
@@ -59,3 +55,9 @@ psignal(int sig, const char *s)
(void)_write(STDERR_FILENO, c, strlen(c));
(void)_write(STDERR_FILENO, "\n", 1);
}
+
+void
+psiginfo(const siginfo_t *si, const char *s)
+{
+ psignal(si->si_signo, s);
+}
diff --git a/lib/libc/gen/pututxline.c b/lib/libc/gen/pututxline.c
index 45a9d3e95e59..15df7b5f6783 100644
--- a/lib/libc/gen/pututxline.c
+++ b/lib/libc/gen/pututxline.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/endian.h>
#include <sys/stat.h>
diff --git a/lib/libc/gen/pw_scan.c b/lib/libc/gen/pw_scan.c
index 619092d3d4bc..35072d7c1b59 100644
--- a/lib/libc/gen/pw_scan.c
+++ b/lib/libc/gen/pw_scan.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)pw_scan.c 8.3 (Berkeley) 4/2/94");
-__FBSDID("$FreeBSD$");
-
/*
* This module is used to "verify" password entries by chpass(1) and
* pwd_mkdb(8).
diff --git a/lib/libc/gen/pw_scan.h b/lib/libc/gen/pw_scan.h
index b56703677ac0..63457a382821 100644
--- a/lib/libc/gen/pw_scan.h
+++ b/lib/libc/gen/pw_scan.h
@@ -27,9 +27,6 @@
* 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.
- *
- * @(#)pw_scan.h 8.1 (Berkeley) 4/1/94
- * $FreeBSD$
*/
#define _PWSCAN_MASTER 0x01
diff --git a/lib/libc/gen/raise.3 b/lib/libc/gen/raise.3
index efc4a50cce3a..c74777e7faa9 100644
--- a/lib/libc/gen/raise.3
+++ b/lib/libc/gen/raise.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)raise.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd May 7, 2010
.Dt RAISE 3
.Os
diff --git a/lib/libc/gen/raise.c b/lib/libc/gen/raise.c
index 1b987c5fdadf..9829de18dcdc 100644
--- a/lib/libc/gen/raise.c
+++ b/lib/libc/gen/raise.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)raise.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <signal.h>
#include <unistd.h>
diff --git a/lib/libc/gen/rand48.3 b/lib/libc/gen/rand48.3
index c70a8320c15b..3ea649354270 100644
--- a/lib/libc/gen/rand48.3
+++ b/lib/libc/gen/rand48.3
@@ -9,10 +9,7 @@
.\" of any kind. I shall in no event be liable for anything that happens
.\" to anyone/anything when using this software.
.\"
-.\" @(#)rand48.3 V1.0 MB 8 Oct 1993
-.\" $FreeBSD$
-.\"
-.Dd September 4, 2012
+.Dd September 11, 2025
.Dt RAND48 3
.Os
.Sh NAME
@@ -186,5 +183,8 @@ generator calls.
.Xr arc4random 3 ,
.Xr rand 3 ,
.Xr random 3
+.Sh STANDARDS
+The functions described in this page are expected to conform to
+.St -p1003.1-2008 .
.Sh AUTHORS
.An Martin Birgmeier
diff --git a/lib/libc/gen/rand48.h b/lib/libc/gen/rand48.h
index b6602dc5a9f7..d3326e851491 100644
--- a/lib/libc/gen/rand48.h
+++ b/lib/libc/gen/rand48.h
@@ -9,17 +9,16 @@
* This software is provided ``as is'', and comes with no warranties
* of any kind. I shall in no event be liable for anything that happens
* to anyone/anything when using this software.
- *
- * $FreeBSD$
*/
#ifndef _RAND48_H_
#define _RAND48_H_
+#include <sys/types.h>
#include <math.h>
#include <stdlib.h>
-void _dorand48(unsigned short[3]);
+#include "fpmath.h"
#define RAND48_SEED_0 (0x330e)
#define RAND48_SEED_1 (0xabcd)
@@ -29,4 +28,62 @@ void _dorand48(unsigned short[3]);
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
+typedef uint64_t uint48;
+
+extern uint48 _rand48_seed;
+extern uint48 _rand48_mult;
+extern uint48 _rand48_add;
+
+#define TOUINT48(x, y, z) \
+ ((uint48)(x) + (((uint48)(y)) << 16) + (((uint48)(z)) << 32))
+
+#define RAND48_SEED TOUINT48(RAND48_SEED_0, RAND48_SEED_1, RAND48_SEED_2)
+#define RAND48_MULT TOUINT48(RAND48_MULT_0, RAND48_MULT_1, RAND48_MULT_2)
+
+#define LOADRAND48(l, x) do { \
+ (l) = TOUINT48((x)[0], (x)[1], (x)[2]); \
+} while (0)
+
+#define STORERAND48(l, x) do { \
+ (x)[0] = (unsigned short)(l); \
+ (x)[1] = (unsigned short)((l) >> 16); \
+ (x)[2] = (unsigned short)((l) >> 32); \
+} while (0)
+
+#define _DORAND48(l) do { \
+ (l) = (l) * _rand48_mult + _rand48_add; \
+} while (0)
+
+#define DORAND48(l, x) do { \
+ LOADRAND48(l, x); \
+ _DORAND48(l); \
+ STORERAND48(l, x); \
+} while (0)
+
+#define ERAND48_BEGIN \
+ union { \
+ union IEEEd2bits ieee; \
+ uint64_t u64; \
+ } u; \
+ int s
+
+/*
+ * Optimization for speed: assume doubles are IEEE 754 and use bit fiddling
+ * rather than converting to double. Specifically, clamp the result to 48 bits
+ * and convert to a double in [0.0, 1.0) via division by 2^48. Normalize by
+ * shifting the most significant bit into the implicit one position and
+ * adjusting the exponent accordingly. The store to the exponent field
+ * overwrites the implicit one.
+ */
+#define ERAND48_END(x) do { \
+ u.u64 = ((x) & 0xffffffffffffULL); \
+ if (u.u64 == 0) \
+ return (0.0); \
+ u.u64 <<= 5; \
+ for (s = 0; !(u.u64 & (1LL << 52)); s++, u.u64 <<= 1) \
+ ; \
+ u.ieee.bits.exp = 1022 - s; \
+ return (u.ieee.d); \
+} while (0)
+
#endif /* _RAND48_H_ */
diff --git a/lib/libc/gen/readdir-compat11.c b/lib/libc/gen/readdir-compat11.c
index ecdaf824cb78..606e15bd7b36 100644
--- a/lib/libc/gen/readdir-compat11.c
+++ b/lib/libc/gen/readdir-compat11.c
@@ -25,14 +25,9 @@
* 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.
- *
- * From: @(#)readdir.c 8.3 (Berkeley) 9/29/94
* From: FreeBSD: head/lib/libc/gen/readdir.c 314436 2017-02-28 23:42:47Z imp
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#define _WANT_FREEBSD11_DIRENT
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index 9a2fae2784af..94d2b2e8d877 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)readdir.c 8.3 (Berkeley) 9/29/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <dirent.h>
@@ -52,8 +48,9 @@ struct dirent *
_readdir_unlocked(DIR *dirp, int flags)
{
struct dirent *dp;
- long initial_seek;
- long initial_loc = 0;
+ off_t initial_seek;
+ size_t initial_loc = 0;
+ ssize_t ret;
for (;;) {
if (dirp->dd_loc >= dirp->dd_size) {
@@ -65,11 +62,13 @@ _readdir_unlocked(DIR *dirp, int flags)
}
if (dirp->dd_loc == 0 &&
!(dirp->dd_flags & (__DTF_READALL | __DTF_SKIPREAD))) {
+ dirp->dd_size = 0;
initial_seek = dirp->dd_seek;
- dirp->dd_size = _getdirentries(dirp->dd_fd,
+ ret = _getdirentries(dirp->dd_fd,
dirp->dd_buf, dirp->dd_len, &dirp->dd_seek);
- if (dirp->dd_size <= 0)
+ if (ret <= 0)
return (NULL);
+ dirp->dd_size = (size_t)ret;
_fixtelldir(dirp, initial_seek, initial_loc);
}
dirp->dd_flags &= ~__DTF_SKIPREAD;
@@ -135,3 +134,5 @@ __readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
}
__strong_reference(__readdir_r, readdir_r);
+__warn_references(readdir_r,
+ "warning: this program uses readdir_r(), which is unsafe.");
diff --git a/lib/libc/gen/readpassphrase.3 b/lib/libc/gen/readpassphrase.3
index 174639263997..5703ba5f1aaf 100644
--- a/lib/libc/gen/readpassphrase.3
+++ b/lib/libc/gen/readpassphrase.3
@@ -18,8 +18,6 @@
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 31, 2007
.Dt READPASSPHRASE 3
.Os
diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c
index 0961fbb35a8b..5319d3e634af 100644
--- a/lib/libc/gen/readpassphrase.c
+++ b/lib/libc/gen/readpassphrase.c
@@ -21,9 +21,6 @@
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <ctype.h>
#include <errno.h>
diff --git a/lib/libc/gen/recvmmsg.c b/lib/libc/gen/recvmmsg.c
deleted file mode 100644
index 7c5c289569ee..000000000000
--- a/lib/libc/gen/recvmmsg.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2016 Boris Astardzhiev, Smartcom-Bulgaria AD
- * All rights reserved.
- *
- * 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(s), this list of conditions and the following disclaimer as
- * the first lines of this file unmodified other than the possible
- * addition of one or more copyright notices.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice(s), 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 HOLDER(S) ``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(S) 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <poll.h>
-#include <stddef.h>
-#include "libc_private.h"
-
-ssize_t
-recvmmsg(int s, struct mmsghdr *__restrict msgvec, size_t vlen, int flags,
- const struct timespec *__restrict timeout)
-{
- struct pollfd pfd[1];
- size_t i, rcvd;
- ssize_t ret;
- int res;
- short ev;
-
- if (timeout != NULL) {
- pfd[0].fd = s;
- pfd[0].revents = 0;
- pfd[0].events = ev = POLLIN | POLLRDNORM | POLLRDBAND |
- POLLPRI;
- res = ppoll(&pfd[0], 1, timeout, NULL);
- if (res == -1 || res == 0)
- return (res);
- if (pfd[0].revents & POLLNVAL) {
- errno = EBADF;
- return (-1);
- }
- if ((pfd[0].revents & ev) == 0) {
- errno = ETIMEDOUT;
- return (-1);
- }
- }
-
- ret = __sys_recvmsg(s, &msgvec[0].msg_hdr, flags);
- if (ret == -1)
- return (ret);
-
- msgvec[0].msg_len = ret;
-
- /*
- * Do non-blocking receive for second and later messages if
- * WAITFORONE is set.
- */
- if (flags & MSG_WAITFORONE)
- flags |= MSG_DONTWAIT;
-
- rcvd = 1;
- for (i = rcvd; i < vlen; i++, rcvd++) {
- ret = __sys_recvmsg(s, &msgvec[i].msg_hdr, flags);
- if (ret == -1) {
- /* We have received messages. Let caller know
- * about the data received, socket error is
- * returned on next invocation.
- */
- return (rcvd);
- }
-
- /* Save received bytes. */
- msgvec[i].msg_len = ret;
- }
-
- return (rcvd);
-}
diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c
index 973e3e147cc7..df829e98d138 100644
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)rewinddir.c 8.1 (Berkeley) 6/8/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
#include <dirent.h>
diff --git a/lib/libc/gen/rfork_thread.3 b/lib/libc/gen/rfork_thread.3
deleted file mode 100644
index dfd6fbcc3c68..000000000000
--- a/lib/libc/gen/rfork_thread.3
+++ /dev/null
@@ -1,87 +0,0 @@
-.\"
-.\" Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" 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 AUTHOR 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 AUTHOR 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.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd February 6, 2011
-.Dt RFORK_THREAD 3
-.Os
-.Sh NAME
-.Nm rfork_thread
-.Nd create a rfork-based process thread
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In unistd.h
-.Ft pid_t
-.Fn rfork_thread "int flags" "void *stack" "int (*func)(void *arg)" "void *arg"
-.Sh DESCRIPTION
-.Bf -symbolic
-The
-.Fn rfork_thread
-function has been deprecated in favor of
-.Xr pthread_create 3 .
-.Ef
-.Pp
-The
-.Fn rfork_thread
-function
-is a helper function for
-.Xr rfork 2 .
-It arranges for a new process to be created and the child process will
-call the specified function with the specified argument, while running on
-the supplied stack.
-.Pp
-Using this function should avoid the need to implement complex stack
-swap code.
-.Sh RETURN VALUES
-Upon successful completion,
-.Fn rfork_thread
-returns the process ID of the child process to the parent process.
-Otherwise, a value of -1 is returned
-to the parent process, no child process is created, and the global
-variable
-.Va errno
-is set to indicate the error.
-.Pp
-The child process context is not aware of a return from the
-.Fn rfork_thread
-function as it begins executing directly with the supplied function.
-.Sh ERRORS
-See
-.Xr rfork 2
-for error return codes.
-.Sh SEE ALSO
-.Xr fork 2 ,
-.Xr intro 2 ,
-.Xr minherit 2 ,
-.Xr rfork 2 ,
-.Xr vfork 2 ,
-.Xr pthread_create 3
-.Sh HISTORY
-The
-.Fn rfork_thread
-function first appeared in
-.Fx 4.3 .
diff --git a/lib/libc/gen/rtld_get_var.3 b/lib/libc/gen/rtld_get_var.3
new file mode 100644
index 000000000000..092114e86d78
--- /dev/null
+++ b/lib/libc/gen/rtld_get_var.3
@@ -0,0 +1,106 @@
+.\" Copyright (c) 2024 The FreeBSD Foundation
+.\"
+.\" This documentation was written by
+.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
+.\" from the FreeBSD Foundation.
+.\"
+.\" 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 AUTHORS 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 AUTHORS 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.
+.\"
+.Dd October 31, 2024
+.Dt RTLD_GET_VAR 3
+.Os
+.Sh NAME
+.Nm rtld_get_var ,
+.Nm rtld_set_var
+.Nd query or change run-time linker parameters after image activation
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/errno.h
+.In link.h
+.Ft const char *
+.Fn rtld_get_var "const char *name"
+.Ft int
+.Fn rtld_set_var "const char *name" "const char *value"
+.Sh DESCRIPTION
+The dynamic linker
+.Xr rtld 1
+can be configured by setting some environment variables for the process,
+before image activation.
+Sometimes it is desirable to query the current effective settings or
+change them afterward.
+.Pp
+Since the process environment variables are maintained by higher-level
+libraries, the run-time linker cannot access them after the image
+activation.
+The described functions make it possible to operate on rtld settings.
+.Pp
+The
+.Fn rtld_get_var
+function returns the current value of the named parameter.
+.Pp
+The
+.Fn rtld_set_var
+functions changes the value of the parameter to the new
+.Fa value
+value, if possible.
+The
+.Fa name
+argument to both functions is the name of the parameter, which
+is same as the corresponding environment variable
+.Pq see Xr rtld 1
+but without the
+.Ev LD_
+(or
+.Ev LD_32_
+or any other ABI-specific) prefix.
+.Sh RETURN VALUES
+The
+.Fn rtld_get_var
+returns the current value of the named parameter, or
+.Dv NULL
+if the name is invalid.
+.Pp
+The
+.Fn rtld_set_var
+returns 0 on success, or an integer indicating the error condition
+which prevented the operation.
+.Sh ERRORS
+Possible errors returned from
+.Fn rtld_set_var :
+.Bl -tag -width Er
+.It Bq Er EPERM
+The requested change cannot be made at runtime, either because the
+runtime linker can only take this parameter at initialization time,
+or because the current process is executing with elevated privileges.
+.It Bq ENOENT
+The supplied parameter
+.Fa name
+is unknown.
+.El
+.Sh SEE ALSO
+.Xr rtld 1
+.Sh HISTORY
+The
+.Nm
+function first appeared in
+.Fx 14.3 .
diff --git a/lib/libc/gen/scandir-compat11.c b/lib/libc/gen/scandir-compat11.c
index 2c86b548f1d9..96c9b1052b48 100644
--- a/lib/libc/gen/scandir-compat11.c
+++ b/lib/libc/gen/scandir-compat11.c
@@ -25,14 +25,9 @@
* 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.
- *
- * From: @(#)scandir.c 8.3 (Berkeley) 1/2/94
* From: FreeBSD: head/lib/libc/gen/scandir.c 317372 2017-04-24 14:56:41Z pfg
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
/*
* Scan the directory dirname calling select to make a list of selected
* directory entries then sort using qsort and compare routine dcomp.
@@ -58,8 +53,8 @@ __FBSDID("$FreeBSD$");
#define SELECT(x) select(x)
-static int freebsd11_alphasort_thunk(void *thunk, const void *p1,
- const void *p2);
+static int freebsd11_scandir_thunk_cmp(const void *p1, const void *p2,
+ void *thunk);
int
freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist,
@@ -116,7 +111,7 @@ freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist,
closedir(dirp);
if (numitems && dcomp != NULL)
qsort_r(names, numitems, sizeof(struct freebsd11_dirent *),
- &dcomp, freebsd11_alphasort_thunk);
+ freebsd11_scandir_thunk_cmp, &dcomp);
*namelist = names;
return (numitems);
@@ -141,7 +136,7 @@ freebsd11_alphasort(const struct freebsd11_dirent **d1,
}
static int
-freebsd11_alphasort_thunk(void *thunk, const void *p1, const void *p2)
+freebsd11_scandir_thunk_cmp(const void *p1, const void *p2, void *thunk)
{
int (*dc)(const struct freebsd11_dirent **, const struct
freebsd11_dirent **);
diff --git a/lib/libc/gen/scandir.3 b/lib/libc/gen/scandir.3
index 7f9891343a1a..3da4500cefb9 100644
--- a/lib/libc/gen/scandir.3
+++ b/lib/libc/gen/scandir.3
@@ -25,26 +25,71 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)scandir.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd January 3, 2010
+.Dd June 25, 2025
.Dt SCANDIR 3
.Os
.Sh NAME
.Nm scandir ,
-.Nm alphasort
+.Nm fdscandir ,
+.Nm scandirat ,
+.Nm scandir_b ,
+.Nm fdscandir_b ,
+.Nm fdscandirat_b ,
+.Nm alphasort ,
+.Nm versionsort
.Nd scan a directory
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In dirent.h
.Ft int
-.Fn scandir "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp" "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fo scandir
+.Fa "const char *dirname"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fc
+.Ft int
+.Fo fdscandir
+.Fa "int dirfd"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fc
+.Ft int
+.Fo scandirat
+.Fa "int dirfd"
+.Fa "const char *dirname"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fc
+.Ft int
+.Fo scandir_b
+.Fa "const char *dirname"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp^select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fc
.Ft int
-.Fn scandir_b "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\^(rp\*(lpconst struct dirent *\*(rp" "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fo fdscandir_b
+.Fa "int dirfd"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp^select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fc
+.Ft int
+.Fo scandirat_b
+.Fa "int dirfd"
+.Fa "const char *dirname"
+.Fa "struct dirent ***namelist"
+.Fa "int \*(lp^select\*(rp\*(lpconst struct dirent *\*(rp"
+.Fa "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
+.Fc
.Ft int
.Fn alphasort "const struct dirent **d1" "const struct dirent **d2"
+.Ft int
+.Fn versionsort "const struct dirent **d1" "const struct dirent **d2"
.Sh DESCRIPTION
The
.Fn scandir
@@ -57,7 +102,8 @@ entries using
It returns the number of entries in the array.
A pointer to the array of directory entries is stored in the location
referenced by
-.Fa namelist .
+.Fa namelist
+(even if no entries were selected).
.Pp
The
.Fa select
@@ -86,28 +132,148 @@ is a routine which can be used for the
argument to sort the array alphabetically using
.Xr strcoll 3 .
.Pp
+The
+.Fn versionsort
+function is a routine which can be used for the
+.Fa compar
+argument to sort the array naturally using
+.Xr strverscmp 3 .
+.Pp
The memory allocated for the array can be deallocated with
.Xr free 3 ,
by freeing each pointer in the array and then the array itself.
.Pp
The
-.Fn scandir_b
-function behaves in the same way as
+.Fn fdscandir
+function is similar to
+.Fn scandir ,
+but takes a file descriptor referencing a directory instead of a path.
+The file descriptor is left open on return, regardless of outcome.
+.Pp
+The
+.Fn scandirat
+function is similar to
.Fn scandir ,
-but takes blocks as arguments instead of function pointers and calls
+but takes an additional
+.Fa dirfd
+argument.
+If the supplied
+.Fa dirname
+is absolute, the function's behavior is identical to that of
+.Fn scandir ,
+the
+.Fa dirfd
+argument is unused.
+If
+.Fa dirname
+is relative,
+.Fa dirfd
+must be a valid file descriptor referencing a directory, in
+which case the
+.Fa dirname
+lookup is performed relative to the directory referenced by
+.Fa dirfd .
+If
+.Fa dirfd
+has the special value
+.Va AT_FDCWD ,
+then the current process directory is used as the base for
+relative lookups.
+See
+.Xr openat 2
+for additional details.
+.Pp
+The
+.Fn scandir_b ,
+.Fn fdscandir_b ,
+and
+.Fn scandirat_b
+functions behave in the same way as
+.Fn scandir ,
+.Fn fdscandir ,
+and
+.Fn scandirat ,
+respectively,
+but take blocks as arguments instead of function pointers and call
.Fn qsort_b
rather than
.Fn qsort .
.Sh DIAGNOSTICS
-Returns \-1 if the directory cannot be opened for reading or if
+The
+.Fn scandir ,
+.Fn fdscandir ,
+.Fn scandirat ,
+.Fn scandir_b ,
+.Fn fdscandir_b ,
+and
+.Fn scandirat_b
+functions return the number of directory entries found on succes.
+If the directory cannot be opened for reading, an error occurs
+while reading the directory, or
.Xr malloc 3
-cannot allocate enough memory to hold all the data structures.
+cannot allocate enough memory to hold all the directory entries,
+they return \-1 and set
+.Va errno
+to an appropriate value.
+.Sh ERRORS
+The
+.Fn scandir ,
+.Fn scandirat ,
+.Fn scandir_b ,
+and
+.Fn scandirat_b
+functions may fail and set
+.Va errno
+for any of the errors specified for the
+.Xr opendir 3 ,
+.Xr malloc 3 ,
+.Xr readdir 3 ,
+and
+.Xr closedir 3
+functions.
+.Pp
+The
+.Fn fdscandir
+and
+.Fn fdscandir_b
+functions may fail and set
+.Va errno
+for any of the errors specified for the
+.Xr fdopendir 3 ,
+.Xr malloc 3 ,
+.Xr readdir 3 ,
+and
+.Xr closedir 3
+functions.
.Sh SEE ALSO
+.Xr openat 2 ,
.Xr directory 3 ,
.Xr malloc 3 ,
.Xr qsort 3 ,
.Xr strcoll 3 ,
+.Xr strverscmp 3 ,
.Xr dir 5
+.Sh STANDARDS
+The
+.Fn alphasort
+and
+.Fn scandir
+functions are expected to conform to
+.St -p1003.1-2008 .
+The
+.Fn scandirat
+and
+.Fn versionsort
+functions are GNU extensions and conform to no standard.
+The
+.Fn fdscandir ,
+.Fn scandir_b ,
+.Fn fdscandir_b ,
+and
+.Fn scandirat_b
+functions are
+.Fx
+extensions.
.Sh HISTORY
The
.Fn scandir
@@ -115,3 +281,20 @@ and
.Fn alphasort
functions appeared in
.Bx 4.2 .
+The
+.Fn scandir_b
+function was added in
+.Fx 11.0 .
+The
+.Fn scandirat
+and
+.Fn versionsort
+functions were added in
+.Fx 13.2 .
+The
+.Fn fdscandir ,
+.Fn fdscandir_b ,
+and
+.Fn scandirat_b
+functions were added in
+.Fx 15.0 .
diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c
index 10cd7633dac1..fb589f4b36b6 100644
--- a/lib/libc/gen/scandir.c
+++ b/lib/libc/gen/scandir.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)scandir.c 8.3 (Berkeley) 1/2/94");
-__FBSDID("$FreeBSD$");
-
/*
* Scan the directory dirname calling select to make a list of selected
* directory entries then sort using qsort and compare routine dcomp.
@@ -42,8 +38,11 @@ __FBSDID("$FreeBSD$");
#include "namespace.h"
#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "un-namespace.h"
#ifdef I_AM_SCANDIR_B
@@ -61,83 +60,170 @@ typedef DECLARE_BLOCK(int, select_block, const struct dirent *);
typedef DECLARE_BLOCK(int, dcomp_block, const struct dirent **,
const struct dirent **);
#else
-static int alphasort_thunk(void *thunk, const void *p1, const void *p2);
+static int scandir_thunk_cmp(const void *p1, const void *p2, void *thunk);
#endif
-int
+static int
#ifdef I_AM_SCANDIR_B
-scandir_b(const char *dirname, struct dirent ***namelist, select_block select,
+scandir_dirp_b(DIR *dirp, struct dirent ***namelist, select_block select,
dcomp_block dcomp)
#else
-scandir(const char *dirname, struct dirent ***namelist,
- int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
- const struct dirent **))
+scandir_dirp(DIR *dirp, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*dcomp)(const struct dirent **, const struct dirent **))
#endif
{
- struct dirent *d, *p, **names = NULL;
- size_t arraysz, numitems;
- DIR *dirp;
+ struct dirent *d, *p = NULL, **names = NULL, **names2;
+ size_t arraysz = 32, numitems = 0;
+ int serrno;
- if ((dirp = opendir(dirname)) == NULL)
- return(-1);
-
- numitems = 0;
- arraysz = 32; /* initial estimate of the array size */
- names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
+ names = malloc(arraysz * sizeof(*names));
if (names == NULL)
- goto fail;
+ return (-1);
- while ((d = readdir(dirp)) != NULL) {
+ while (errno = 0, (d = readdir(dirp)) != NULL) {
if (select != NULL && !SELECT(d))
continue; /* just selected names */
/*
* Make a minimum size copy of the data
*/
- p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d));
+ p = malloc(_GENERIC_DIRSIZ(d));
if (p == NULL)
goto fail;
p->d_fileno = d->d_fileno;
p->d_type = d->d_type;
p->d_reclen = d->d_reclen;
p->d_namlen = d->d_namlen;
- bcopy(d->d_name, p->d_name, p->d_namlen + 1);
+ memcpy(p->d_name, d->d_name, p->d_namlen + 1);
/*
* Check to make sure the array has space left and
* realloc the maximum size.
*/
if (numitems >= arraysz) {
- struct dirent **names2;
-
- names2 = reallocarray(names, arraysz,
- 2 * sizeof(struct dirent *));
- if (names2 == NULL) {
- free(p);
+ arraysz = arraysz * 2;
+ names2 = reallocarray(names, arraysz, sizeof(*names));
+ if (names2 == NULL)
goto fail;
- }
names = names2;
- arraysz *= 2;
}
names[numitems++] = p;
}
- closedir(dirp);
- if (numitems && dcomp != NULL)
+ /*
+ * Since we can't simultaneously return both -1 and a count, we
+ * must either suppress the error or discard the partial result.
+ * The latter seems the lesser of two evils.
+ */
+ if (errno != 0)
+ goto fail;
+ if (numitems > 0 && dcomp != NULL) {
#ifdef I_AM_SCANDIR_B
- qsort_b(names, numitems, sizeof(struct dirent *), (void*)dcomp);
+ qsort_b(names, numitems, sizeof(struct dirent *),
+ (void *)dcomp);
#else
qsort_r(names, numitems, sizeof(struct dirent *),
- &dcomp, alphasort_thunk);
+ scandir_thunk_cmp, &dcomp);
#endif
+ }
*namelist = names;
return (numitems);
fail:
+ serrno = errno;
+ if (numitems == 0 || names[numitems - 1] != p)
+ free(p);
while (numitems > 0)
free(names[--numitems]);
free(names);
- closedir(dirp);
+ errno = serrno;
return (-1);
}
+int
+#ifdef I_AM_SCANDIR_B
+scandir_b(const char *dirname, struct dirent ***namelist, select_block select,
+ dcomp_block dcomp)
+#else
+scandir(const char *dirname, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*dcomp)(const struct dirent **, const struct dirent **))
+#endif
+{
+ DIR *dirp;
+ int ret, serrno;
+
+ dirp = opendir(dirname);
+ if (dirp == NULL)
+ return (-1);
+ ret =
+#ifdef I_AM_SCANDIR_B
+ scandir_dirp_b
+#else
+ scandir_dirp
+#endif
+ (dirp, namelist, select, dcomp);
+ serrno = errno;
+ closedir(dirp);
+ errno = serrno;
+ return (ret);
+}
+
+int
+#ifdef I_AM_SCANDIR_B
+fdscandir_b(int dirfd, struct dirent ***namelist, select_block select,
+ dcomp_block dcomp)
+#else
+fdscandir(int dirfd, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*dcomp)(const struct dirent **, const struct dirent **))
+#endif
+{
+ DIR *dirp;
+ int ret, serrno;
+
+ dirp = fdopendir(dirfd);
+ if (dirp == NULL)
+ return (-1);
+ ret =
+#ifdef I_AM_SCANDIR_B
+ scandir_dirp_b
+#else
+ scandir_dirp
+#endif
+ (dirp, namelist, select, dcomp);
+ serrno = errno;
+ fdclosedir(dirp);
+ errno = serrno;
+ return (ret);
+}
+
+int
+#ifdef I_AM_SCANDIR_B
+scandirat_b(int dirfd, const char *dirname, struct dirent ***namelist,
+ select_block select, dcomp_block dcomp)
+#else
+scandirat(int dirfd, const char *dirname, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*dcomp)(const struct dirent **, const struct dirent **))
+#endif
+{
+ int fd, ret, serrno;
+
+ fd = _openat(dirfd, dirname, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (fd == -1)
+ return (-1);
+ ret =
+#ifdef I_AM_SCANDIR_B
+ fdscandir_b
+#else
+ fdscandir
+#endif
+ (fd, namelist, select, dcomp);
+ serrno = errno;
+ _close(fd);
+ errno = serrno;
+ return (ret);
+}
+
#ifndef I_AM_SCANDIR_B
/*
* Alphabetic order comparison routine for those who want it.
@@ -150,8 +236,15 @@ alphasort(const struct dirent **d1, const struct dirent **d2)
return (strcoll((*d1)->d_name, (*d2)->d_name));
}
+int
+versionsort(const struct dirent **d1, const struct dirent **d2)
+{
+
+ return (strverscmp((*d1)->d_name, (*d2)->d_name));
+}
+
static int
-alphasort_thunk(void *thunk, const void *p1, const void *p2)
+scandir_thunk_cmp(const void *p1, const void *p2, void *thunk)
{
int (*dc)(const struct dirent **, const struct dirent **);
diff --git a/lib/libc/gen/scandir_b.c b/lib/libc/gen/scandir_b.c
index 6310a9110598..3350ce8227b9 100644
--- a/lib/libc/gen/scandir_b.c
+++ b/lib/libc/gen/scandir_b.c
@@ -22,8 +22,6 @@
* 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.
- *
- * $FreeBSD$
*/
#define I_AM_SCANDIR_B
#include "scandir.c"
diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c
index ed304c111985..fce47fbfc0d2 100644
--- a/lib/libc/gen/sched_getaffinity.c
+++ b/lib/libc/gen/sched_getaffinity.c
@@ -26,16 +26,29 @@
* SUCH DAMAGE.
*/
+#define _WANT_P_OSREL
+#include <sys/param.h>
#include <errno.h>
#include <sched.h>
#include <string.h>
+#include "libc_private.h"
+
int
sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset)
{
+ cpuwhich_t which;
int error;
- error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
+ if (__getosreldate() < P_OSREL_TIDPID) {
+ if (pid == 0 || pid > _PID_MAX)
+ which = CPU_WHICH_TID;
+ else
+ which = CPU_WHICH_PID;
+ } else
+ which = CPU_WHICH_TIDPID;
+
+ error = cpuset_getaffinity(CPU_LEVEL_WHICH, which,
pid == 0 ? -1 : pid, cpusetsz, cpuset);
if (error == -1 && errno == ERANGE)
errno = EINVAL;
diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c
index 0052521cd081..b878e1affc41 100644
--- a/lib/libc/gen/sched_setaffinity.c
+++ b/lib/libc/gen/sched_setaffinity.c
@@ -26,20 +26,32 @@
* SUCH DAMAGE.
*/
+#define _WANT_P_OSREL
#include <sys/param.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <sched.h>
#include <string.h>
+#include "libc_private.h"
+
int
sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset)
{
static int mp_maxid;
+ cpuwhich_t which;
cpuset_t c;
int error, lbs, cpu;
size_t len, sz;
+ if (__getosreldate() < P_OSREL_TIDPID) {
+ if (pid == 0 || pid > _PID_MAX)
+ which = CPU_WHICH_TID;
+ else
+ which = CPU_WHICH_PID;
+ } else
+ which = CPU_WHICH_TIDPID;
+
sz = cpusetsz > sizeof(cpuset_t) ? sizeof(cpuset_t) : cpusetsz;
memset(&c, 0, sizeof(c));
memcpy(&c, cpuset, sz);
@@ -58,7 +70,7 @@ sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset)
if (cpu > mp_maxid)
CPU_CLR(cpu, &c);
}
- error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, which,
pid == 0 ? -1 : pid, sizeof(cpuset_t), &c);
if (error == -1 && errno == EDEADLK)
errno = EINVAL;
diff --git a/lib/libc/gen/seed48.c b/lib/libc/gen/seed48.c
index 5339b8c0c4e9..f57656ce1121 100644
--- a/lib/libc/gen/seed48.c
+++ b/lib/libc/gen/seed48.c
@@ -11,29 +11,16 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-extern unsigned short _rand48_mult[3];
-extern unsigned short _rand48_add;
-
unsigned short *
seed48(unsigned short xseed[3])
{
static unsigned short sseed[3];
- sseed[0] = _rand48_seed[0];
- sseed[1] = _rand48_seed[1];
- sseed[2] = _rand48_seed[2];
- _rand48_seed[0] = xseed[0];
- _rand48_seed[1] = xseed[1];
- _rand48_seed[2] = xseed[2];
- _rand48_mult[0] = RAND48_MULT_0;
- _rand48_mult[1] = RAND48_MULT_1;
- _rand48_mult[2] = RAND48_MULT_2;
+ STORERAND48(_rand48_seed, sseed);
+ LOADRAND48(_rand48_seed, xseed);
+ _rand48_mult = RAND48_MULT;
_rand48_add = RAND48_ADD;
- return sseed;
+ return (sseed);
}
diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c
index 3974af7d73ee..c796aa7e3550 100644
--- a/lib/libc/gen/seekdir.c
+++ b/lib/libc/gen/seekdir.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)seekdir.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <dirent.h>
diff --git a/lib/libc/gen/sem.c b/lib/libc/gen/sem.c
index a04926a950fe..9b0071bc64c0 100644
--- a/lib/libc/gen/sem.c
+++ b/lib/libc/gen/sem.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (C) 2010 David Xu <davidxu@freebsd.org>.
* Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
@@ -28,8 +28,6 @@
* 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.
- *
- * $FreeBSD$
*/
/*
diff --git a/lib/libc/gen/sem_destroy.3 b/lib/libc/gen/sem_destroy.3
index b43742065620..13cc81a03710 100644
--- a/lib/libc/gen/sem_destroy.3
+++ b/lib/libc/gen/sem_destroy.3
@@ -25,8 +25,6 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd February 15, 2000
.Dt SEM_DESTROY 3
.Os
diff --git a/lib/libc/gen/sem_getvalue.3 b/lib/libc/gen/sem_getvalue.3
index d81c2b17eaaa..8b2970373287 100644
--- a/lib/libc/gen/sem_getvalue.3
+++ b/lib/libc/gen/sem_getvalue.3
@@ -25,8 +25,6 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd February 15, 2000
.Dt SEM_GETVALUE 3
.Os
diff --git a/lib/libc/gen/sem_init.3 b/lib/libc/gen/sem_init.3
index a96749b0bad2..e0e4b3b3d6c2 100644
--- a/lib/libc/gen/sem_init.3
+++ b/lib/libc/gen/sem_init.3
@@ -25,8 +25,6 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd January 9, 2010
.Dt SEM_INIT 3
.Os
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c
index 409f4ce76608..ba81fb0ded78 100644
--- a/lib/libc/gen/sem_new.c
+++ b/lib/libc/gen/sem_new.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (C) 2010 David Xu <davidxu@freebsd.org>.
* All rights reserved.
@@ -27,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include "namespace.h"
diff --git a/lib/libc/gen/sem_open.3 b/lib/libc/gen/sem_open.3
index 2fdc01934172..76fa3463e1ab 100644
--- a/lib/libc/gen/sem_open.3
+++ b/lib/libc/gen/sem_open.3
@@ -25,8 +25,6 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd January 9, 2010
.Dt SEM_OPEN 3
.Os
diff --git a/lib/libc/gen/sem_post.3 b/lib/libc/gen/sem_post.3
index dea8eb697169..b389b6686a20 100644
--- a/lib/libc/gen/sem_post.3
+++ b/lib/libc/gen/sem_post.3
@@ -25,8 +25,6 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd January 28, 2015
.Dt SEM_POST 3
.Os
diff --git a/lib/libc/gen/sem_timedwait.3 b/lib/libc/gen/sem_timedwait.3
index e5e651541d37..8f253bb35f72 100644
--- a/lib/libc/gen/sem_timedwait.3
+++ b/lib/libc/gen/sem_timedwait.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd May 24, 2017
.Dt SEM_TIMEDWAIT 3
.Os
diff --git a/lib/libc/gen/sem_wait.3 b/lib/libc/gen/sem_wait.3
index cb5a2f68b782..2d4c77829a95 100644
--- a/lib/libc/gen/sem_wait.3
+++ b/lib/libc/gen/sem_wait.3
@@ -25,8 +25,6 @@
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd April 16, 2013
.Dt SEM_WAIT 3
.Os
diff --git a/lib/libc/gen/semctl.c b/lib/libc/gen/semctl.c
index 8760d76a82fa..374f01508236 100644
--- a/lib/libc/gen/semctl.c
+++ b/lib/libc/gen/semctl.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Doug Rabson
* All rights reserved.
@@ -28,9 +28,6 @@
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#ifndef NO_COMPAT7
#define _WANT_SEMUN_OLD
#endif
diff --git a/lib/libc/gen/setdomainname.c b/lib/libc/gen/setdomainname.c
index 2a001b9ffa98..c40b7a393e3b 100644
--- a/lib/libc/gen/setdomainname.c
+++ b/lib/libc/gen/setdomainname.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sethostname.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/sethostname.c b/lib/libc/gen/sethostname.c
index 0e120775afb9..eeb3ec5cc6db 100644
--- a/lib/libc/gen/sethostname.c
+++ b/lib/libc/gen/sethostname.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sethostname.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/setjmp.3 b/lib/libc/gen/setjmp.3
index 2b6ea9afeb64..e7c52473dbc9 100644
--- a/lib/libc/gen/setjmp.3
+++ b/lib/libc/gen/setjmp.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)setjmp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd April 2, 2022
.Dt SETJMP 3
.Os
diff --git a/lib/libc/gen/setjmperr.c b/lib/libc/gen/setjmperr.c
index abc13c0339f1..1ba722c30146 100644
--- a/lib/libc/gen/setjmperr.c
+++ b/lib/libc/gen/setjmperr.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)setjmperr.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
/*
* This routine is called from longjmp() when an error occurs.
* Programs that wish to exit gracefully from this error may
diff --git a/lib/libc/gen/setmode.3 b/lib/libc/gen/setmode.3
index 3e6796239db0..a5dd05a5e7c6 100644
--- a/lib/libc/gen/setmode.3
+++ b/lib/libc/gen/setmode.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
-.\" $FreeBSD$
-.\"
.Dd July 18, 2019
.Dt SETMODE 3
.Os
diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c
index 66976cdd7bcf..8d7ba905067f 100644
--- a/lib/libc/gen/setmode.c
+++ b/lib/libc/gen/setmode.c
@@ -32,10 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)setmode.c 8.2 (Berkeley) 3/25/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libc/gen/setproctitle.3 b/lib/libc/gen/setproctitle.3
index 1dd602ef58dc..087cbe4b84e9 100644
--- a/lib/libc/gen/setproctitle.3
+++ b/lib/libc/gen/setproctitle.3
@@ -1,26 +1,31 @@
-.\" Copyright (c) 1995 Peter Wemm <peter@FreeBSD.org>
-.\" All rights reserved.
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" Copyright (c) 1995 Peter Wemm
.\"
.\" Redistribution and use in source and binary forms, with or without
-.\" modification, is permitted provided that the following conditions
+.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
-.\" notice immediately at the beginning of the file, without modification,
-.\" this list of conditions, and the following disclaimer.
+.\" 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.
-.\" 3. This work was done expressly for inclusion into FreeBSD. Other use
-.\" is permitted provided this notation is included.
-.\" 4. Absolutely no warranty of function or purpose is made by the author
-.\" Peter Wemm.
-.\" 5. Modifications may be freely made to this file providing the above
-.\" conditions are met.
.\"
-.\" $FreeBSD$
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
.\"
.\" The following requests are required for all man pages.
-.Dd November 13, 2020
+.Dd November 28, 2022
.Dt SETPROCTITLE 3
.Os
.Sh NAME
@@ -28,7 +33,6 @@
.Nm setproctitle_fast
.Nd set process title
.Sh SYNOPSIS
-.In sys/types.h
.In unistd.h
.Ft void
.Fn setproctitle "const char *fmt" "..."
@@ -70,10 +74,10 @@ setproctitle("talking to %s", inet_ntoa(addr));
.Sh SEE ALSO
.Xr ps 1 ,
.Xr w 1 ,
-.Xr setprogname 3 ,
.Xr kvm 3 ,
.Xr kvm_getargv 3 ,
-.Xr printf 3
+.Xr printf 3 ,
+.Xr setprogname 3
.Sh STANDARDS
The
.Fn setproctitle
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c
index 08612e99d9bb..715951a8c96d 100644
--- a/lib/libc/gen/setproctitle.c
+++ b/lib/libc/gen/setproctitle.c
@@ -1,23 +1,30 @@
-/*
- * Copyright (c) 1995 Peter Wemm <peter@freebsd.org>
- * All rights reserved.
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 1995 Peter Wemm
*
* Redistribution and use in source and binary forms, with or without
- * modification, is permitted provided that the following conditions
+ * modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice immediately at the beginning of the file, without modification,
- * this list of conditions, and the following disclaimer.
+ * 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.
- * 3. Absolutely no warranty of function or purpose is made by the author
- * Peter Wemm.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/elf_common.h>
diff --git a/lib/libc/gen/setprogname.c b/lib/libc/gen/setprogname.c
index 29a6cd025ec8..853c5f277386 100644
--- a/lib/libc/gen/setprogname.c
+++ b/lib/libc/gen/setprogname.c
@@ -1,6 +1,3 @@
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdlib.h>
#include <string.h>
diff --git a/lib/libc/gen/sig2str.c b/lib/libc/gen/sig2str.c
new file mode 100644
index 000000000000..869a09ab9db4
--- /dev/null
+++ b/lib/libc/gen/sig2str.c
@@ -0,0 +1,113 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Ricardo Branco <rbranco@suse.de>.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+/*
+ * Translate between signal names and numbers
+ */
+#include "namespace.h"
+#include <ctype.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ssp/ssp.h>
+#include "un-namespace.h"
+
+static const char rtmin_str[] = "RTMIN";
+static const char rtmax_str[] = "RTMAX";
+
+int
+__ssp_real(sig2str)(int signum, char *str)
+{
+ if (signum <= 0 || signum > SIGRTMAX)
+ return (-1);
+
+ if (signum < sys_nsig)
+ (void)strlcpy(str, sys_signame[signum], SIG2STR_MAX);
+ else if (signum < SIGRTMIN)
+ (void)snprintf(str, SIG2STR_MAX, "%d", signum);
+ else if (signum == SIGRTMIN)
+ (void)strlcpy(str, rtmin_str, SIG2STR_MAX);
+ else if (signum == SIGRTMAX)
+ (void)strlcpy(str, rtmax_str, SIG2STR_MAX);
+ else if (signum <= (SIGRTMIN + SIGRTMAX) / 2)
+ (void)snprintf(str, SIG2STR_MAX, "%s+%d",
+ rtmin_str, signum - SIGRTMIN);
+ else
+ (void)snprintf(str, SIG2STR_MAX, "%s-%d",
+ rtmax_str, SIGRTMAX - signum);
+
+ return (0);
+}
+
+int
+str2sig(const char * restrict str, int * restrict pnum)
+{
+ const char *errstr;
+ long long n;
+ int sig;
+ int rtend = sizeof(rtmin_str) - 1;
+
+ if (strncasecmp(str, "SIG", 3) == 0)
+ str += 3;
+
+ if (strncasecmp(str, rtmin_str, sizeof(rtmin_str) - 1) == 0 ||
+ strncasecmp(str, rtmax_str, sizeof(rtmax_str) - 1) == 0) {
+ sig = (toupper(str[4]) == 'X') ? SIGRTMAX : SIGRTMIN;
+ n = 0;
+ if (str[rtend] == '+' || str[rtend] == '-') {
+ n = strtonum(str + rtend, INT_MIN, INT_MAX, &errstr);
+ if (n == 0 || errstr != NULL)
+ return (-1);
+ } else if (str[rtend] != '\0') {
+ return (-1);
+ }
+ sig += (int)n;
+ if (sig < SIGRTMIN || sig > SIGRTMAX)
+ return (-1);
+ *pnum = sig;
+ return (0);
+ }
+
+ if (isdigit((unsigned char)str[0])) {
+ n = strtonum(str, 1, SIGRTMAX, &errstr);
+ if (errstr == NULL) {
+ *pnum = (int)n;
+ return (0);
+ }
+ }
+
+ for (sig = 1; sig < sys_nsig; sig++) {
+ if (strcasecmp(sys_signame[sig], str) == 0) {
+ *pnum = sig;
+ return (0);
+ }
+ }
+
+ return (-1);
+}
diff --git a/lib/libc/gen/siginterrupt.3 b/lib/libc/gen/siginterrupt.3
index 0fcbcb984b6a..4e286f28df7c 100644
--- a/lib/libc/gen/siginterrupt.3
+++ b/lib/libc/gen/siginterrupt.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)siginterrupt.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 4, 1993
.Dt SIGINTERRUPT 3
.Os
diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c
index 2d7f9950776e..0a05e89982dc 100644
--- a/lib/libc/gen/siginterrupt.c
+++ b/lib/libc/gen/siginterrupt.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <signal.h>
#include "un-namespace.h"
diff --git a/lib/libc/gen/siglist.c b/lib/libc/gen/siglist.c
index 796a0b702136..c1d0a8d425e1 100644
--- a/lib/libc/gen/siglist.c
+++ b/lib/libc/gen/siglist.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)siglist.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <signal.h>
const char *const sys_signame[NSIG] = {
diff --git a/lib/libc/gen/signal.3 b/lib/libc/gen/signal.3
index 4e32d8cb75e7..56e77325eed8 100644
--- a/lib/libc/gen/signal.3
+++ b/lib/libc/gen/signal.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)signal.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
.Dd December 1, 2017
.Dt SIGNAL 3
.Os
diff --git a/lib/libc/gen/signal.c b/lib/libc/gen/signal.c
index 62af2e95bc79..dce06bba3678 100644
--- a/lib/libc/gen/signal.c
+++ b/lib/libc/gen/signal.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)signal.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
/*
* Almost backwards compatible signal.
*/
diff --git a/lib/libc/gen/sigsetops.3 b/lib/libc/gen/sigsetops.3
index a184289aeb8a..109b1d9d4a8c 100644
--- a/lib/libc/gen/sigsetops.3
+++ b/lib/libc/gen/sigsetops.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)sigsetops.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd October 29, 2019
.Dt SIGSETOPS 3
.Os
diff --git a/lib/libc/gen/sigsetops.c b/lib/libc/gen/sigsetops.c
index 53a450c0e5f6..3e22b0dba5e9 100644
--- a/lib/libc/gen/sigsetops.c
+++ b/lib/libc/gen/sigsetops.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sigsetops.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <errno.h>
#include <signal.h>
diff --git a/lib/libc/gen/sleep.3 b/lib/libc/gen/sleep.3
deleted file mode 100644
index c40dea9f8f83..000000000000
--- a/lib/libc/gen/sleep.3
+++ /dev/null
@@ -1,83 +0,0 @@
-.\" Copyright (c) 1986, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" 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.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd February 13, 1998
-.Dt SLEEP 3
-.Os
-.Sh NAME
-.Nm sleep
-.Nd suspend thread execution for an interval measured in seconds
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In unistd.h
-.Ft unsigned int
-.Fn sleep "unsigned int seconds"
-.Sh DESCRIPTION
-The
-.Fn sleep
-function suspends execution of the calling thread until either
-.Fa seconds
-seconds have elapsed or a signal is delivered to the thread and its
-action is to invoke a signal-catching function or to terminate the
-thread or process.
-System activity may lengthen the sleep by an indeterminate amount.
-.Pp
-This function is implemented using
-.Xr nanosleep 2
-by pausing for
-.Fa seconds
-seconds or until a signal occurs.
-Consequently, in this implementation,
-sleeping has no effect on the state of process timers,
-and there is no special handling for SIGALRM.
-.Sh RETURN VALUES
-If the
-.Fn sleep
-function returns because the requested time has elapsed, the value
-returned will be zero.
-If the
-.Fn sleep
-function returns due to the delivery of a signal, the value returned
-will be the unslept amount (the requested time minus the time actually
-slept) in seconds.
-.Sh SEE ALSO
-.Xr nanosleep 2 ,
-.Xr usleep 3
-.Sh STANDARDS
-The
-.Fn sleep
-function conforms to
-.St -p1003.1-90 .
-.Sh HISTORY
-A
-.Fn sleep
-function appeared in
-.At v7 .
diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c
index 620fda36ac10..e32d434d4d33 100644
--- a/lib/libc/gen/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sleep.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <errno.h>
#include <limits.h>
@@ -59,9 +55,7 @@ __sleep(unsigned int seconds)
time_to_sleep.tv_sec = seconds;
time_to_sleep.tv_nsec = 0;
- if (((int (*)(const struct timespec *, struct timespec *))
- __libc_interposing[INTERPOS_nanosleep])(
- &time_to_sleep, &time_remaining) != -1)
+ if (INTERPOS_SYS(nanosleep, &time_to_sleep, &time_remaining) != -1)
return (0);
if (errno != EINTR)
return (seconds); /* best guess */
diff --git a/lib/libc/gen/srand48.c b/lib/libc/gen/srand48.c
index fd369a094c51..4b82ece72db8 100644
--- a/lib/libc/gen/srand48.c
+++ b/lib/libc/gen/srand48.c
@@ -13,18 +13,11 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-extern unsigned short _rand48_mult[3];
-extern unsigned short _rand48_add;
-
void
srand48(long seed)
{
- _rand48_seed[0] = RAND48_SEED_0;
- _rand48_seed[1] = (unsigned short) seed;
- _rand48_seed[2] = (unsigned short) (seed >> 16);
- _rand48_mult[0] = RAND48_MULT_0;
- _rand48_mult[1] = RAND48_MULT_1;
- _rand48_mult[2] = RAND48_MULT_2;
+ _rand48_seed = TOUINT48(RAND48_SEED_0, (unsigned short)seed,
+ (unsigned short)(seed >> 16));
+ _rand48_mult = RAND48_MULT;
_rand48_add = RAND48_ADD;
}
diff --git a/lib/libc/gen/statvfs.3 b/lib/libc/gen/statvfs.3
index 73109bd98342..e88f01eeeb26 100644
--- a/lib/libc/gen/statvfs.3
+++ b/lib/libc/gen/statvfs.3
@@ -26,8 +26,6 @@
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd July 13, 2002
.Dt STATVFS 3
.Os
diff --git a/lib/libc/gen/statvfs.c b/lib/libc/gen/statvfs.c
index fe9462bd307b..94c61f0cd73d 100644
--- a/lib/libc/gen/statvfs.c
+++ b/lib/libc/gen/statvfs.c
@@ -27,9 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/mount.h>
diff --git a/lib/libc/gen/stringlist.3 b/lib/libc/gen/stringlist.3
index d4480beb0e2d..5e116f636281 100644
--- a/lib/libc/gen/stringlist.3
+++ b/lib/libc/gen/stringlist.3
@@ -26,8 +26,6 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd November 28, 1999
.Dt STRINGLIST 3
.Os
diff --git a/lib/libc/gen/stringlist.c b/lib/libc/gen/stringlist.c
index 158f3d20705d..5f333f3807aa 100644
--- a/lib/libc/gen/stringlist.c
+++ b/lib/libc/gen/stringlist.c
@@ -28,8 +28,6 @@
#include <sys/cdefs.h>
__RCSID("$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <stdio.h>
#include <string.h>
diff --git a/lib/libc/gen/strtofflags.3 b/lib/libc/gen/strtofflags.3
index 871936aa3fed..0cf996275480 100644
--- a/lib/libc/gen/strtofflags.3
+++ b/lib/libc/gen/strtofflags.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)setmode.3 8.2 (Berkeley) 4/28/95
-.\" $FreeBSD$
-.\"
.Dd January 1, 2000
.Dt STRTOFFLAGS 3
.Os
diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c
index 174c6742e232..73b4db54ccdd 100644
--- a/lib/libc/gen/strtofflags.c
+++ b/lib/libc/gen/strtofflags.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)stat_flags.c 8.1 (Berkeley) 5/31/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3
index c30c4453b3e7..290ef0dc158c 100644
--- a/lib/libc/gen/sysconf.3
+++ b/lib/libc/gen/sysconf.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
-.Dd April 26, 2013
+.Dd August 30, 2025
.Dt SYSCONF 3
.Os
.Sh NAME
@@ -80,7 +77,9 @@ The maximum number of supplemental groups.
.It Li _SC_NPROCESSORS_CONF
The number of processors configured.
.It Li _SC_NPROCESSORS_ONLN
-The number of processors currently online.
+The number of processors currently online, taking into account current jail
+restrictions to report only the number of processors that are usable to the
+process.
.It Li _SC_OPEN_MAX
One more than the maximum value the system may assign to a new file descriptor.
.It Li _SC_PAGESIZE
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 26bb9043ed3c..87aedc07c110 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -32,12 +32,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sysconf.c 8.2 (Berkeley) 3/20/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
+#include <sys/exterrvar.h>
#include <sys/time.h>
#include <sys/sysctl.h>
#include <sys/resource.h>
@@ -54,7 +51,7 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h"
#include "../stdlib/atexit.h"
-#include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */
+#include "tzdir.h" /* from ../../../contrib/tzcode */
#include "libc_private.h"
#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
@@ -75,6 +72,7 @@ long
sysconf(int name)
{
struct rlimit rl;
+ cpuset_t cpus;
size_t len;
int mib[2], sverrno, value;
long lvalue, defaultresult;
@@ -290,6 +288,8 @@ do_NAME_MAX:
mib[0] = CTL_P1003_1B;
mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
goto yesno;
+ case _SC_NSIG:
+ return (_SIG_MAXSIG);
case _SC_PAGESIZE:
return (getpagesize());
case _SC_RTSIG_MAX:
@@ -571,7 +571,7 @@ yesno:
case _SC_IPV6:
#if _POSIX_IPV6 == 0
sverrno = errno;
- value = _socket(PF_INET6, SOCK_DGRAM, 0);
+ value = _socket(PF_INET6, SOCK_CLOEXEC | SOCK_DGRAM, 0);
errno = sverrno;
if (value >= 0) {
_close(value);
@@ -582,8 +582,21 @@ yesno:
return (_POSIX_IPV6);
#endif
- case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
+ /*
+ * Consult our root set first, because our CPU availability
+ * may not match the total number of CPUs available on the
+ * system and we may have a non-uniform layout even within
+ * userland. In particular, each jail has a root set that can
+ * be constrained by its parent and processes within the jail
+ * cannot widen beyond those constraints, so to those processes
+ * it makes sense to claim the more limited count.
+ */
+ if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1,
+ sizeof(cpus), &cpus) == 0)
+ return (CPU_COUNT(&cpus));
+ /* FALLTHROUGH */
+ case _SC_NPROCESSORS_CONF:
if (_elf_aux_info(AT_NCPUS, &value, sizeof(value)) == 0)
return ((long)value);
mib[0] = CTL_HW;
@@ -606,6 +619,8 @@ yesno:
return (-1);
return ((long)value);
#endif
+ case _SC_UEXTERR_MAXLEN:
+ return (UEXTERROR_MAXLEN);
default:
errno = EINVAL;
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3
index 2d8da3974086..ef897c653728 100644
--- a/lib/libc/gen/sysctl.3
+++ b/lib/libc/gen/sysctl.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95
-.\" $FreeBSD$
-.\"
-.Dd October 18, 2021
+.Dd July 31, 2025
.Dt SYSCTL 3
.Os
.Sh NAME
@@ -328,6 +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_BOOTFILE Ta string Ta yes
.It Dv KERN_BOOTTIME Ta struct timeval Ta no
.It Dv KERN_CLOCKRATE Ta struct clockinfo Ta no
@@ -335,9 +333,13 @@ 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_JOB_CONTROL Ta integer Ta no
+.It Dv KERN_LOCKF Ta struct kinfo_lockf Ta no
+.It Dv KERN_LOGSIGEXIT Ta integer Ta yes
.It Dv KERN_MAXFILES Ta integer Ta yes
.It Dv KERN_MAXFILESPERPROC Ta integer Ta yes
+.It Dv KERN_MAXPHYS Ta integer Ta no
.It Dv KERN_MAXPROC Ta integer Ta no
.It Dv KERN_MAXPROCPERUID Ta integer Ta yes
.It Dv KERN_MAXVNODES Ta integer Ta yes
@@ -349,18 +351,28 @@ information.
.It Dv KERN_OSTYPE Ta string Ta no
.It Dv KERN_POSIX1 Ta integer Ta no
.It Dv KERN_PROC Ta node Ta not applicable
-.It Dv KERN_PROF Ta node Ta not applicable
-.It Dv KERN_QUANTUM Ta integer Ta yes
+.It Dv KERN_PS_STRINGS Ta integer Ta no
.It Dv KERN_SAVED_IDS Ta integer Ta no
.It Dv KERN_SECURELVL Ta integer Ta raise only
.It Dv KERN_UPDATEINTERVAL Ta integer Ta no
+.It Dv KERN_USRSTACK Ta integer Ta no
.It Dv KERN_VERSION Ta string Ta no
-.It Dv KERN_VNODE Ta struct xvnode Ta no
.El
.Bl -tag -width 6n
.It Li KERN_ARGMAX
The maximum bytes of argument to
.Xr execve 2 .
+.It Li KERN_ARND
+.Xr arc4rand 9
+Fills the buffer with random bytes from in-kernel random data generator.
+This is an alternative interface for
+.Xr read 2
+of
+.Xr random 4
+device, which does not depend on accessibility and correct mounting options
+of the
+.Xr devfs 4
+node.
.It Li KERN_BOOTFILE
The full pathname of the file from which the kernel was loaded.
.It Li KERN_BOOTTIME
@@ -385,8 +397,18 @@ Get or set the host ID.
Get or set the host's universally unique identifier (UUID).
.It Li KERN_HOSTNAME
Get or set the hostname.
+.It Li KERN_IOV_MAX
+The maximum accepted number of elements in an input-output vector (iovec),
+see
+.Xr readv 2
+and
+.Xr writev 2 .
.It Li KERN_JOB_CONTROL
Return 1 if job control is available on this system, otherwise 0.
+.It Li KERN_LOCKF
+Returns the list of the file advisory locks currently known to kernel.
+.It Li KERN_LOGSIGEXIT
+Controls logging of process exit due to untrapped signals.
.It Li KERN_MAXFILES
The maximum number of files that may be open in the system.
.It Li KERN_MAXFILESPERPROC
@@ -395,6 +417,10 @@ This limit only applies to processes with an effective uid of nonzero
at the time of the open request.
Files that have already been opened are not affected if the limit
or the effective uid is changed.
+.It Li KERN_MAXPHYS
+Specifies the maximum block I/O size.
+Can be changed by the tunable
+.Ev kern.maxphys .
.It Li KERN_MAXPROC
The maximum number of concurrent processes the system will allow.
.It Li KERN_MAXPROCPERUID
@@ -451,86 +477,142 @@ whose size depends on the current number of such objects in the system.
.It Dv KERN_PROC_ALL Ta None
.It Dv KERN_PROC_PID Ta A process ID
.It Dv KERN_PROC_PGRP Ta A process group
+.It Dv KERN_PROC_SESSION Ta A session
.It Dv KERN_PROC_TTY Ta A tty device
-.It Dv KERN_PROC_UID Ta A user ID
+.It Dv KERN_PROC_UID Ta An effective user ID
.It Dv KERN_PROC_RUID Ta A real user ID
+.It Dv KERN_PROC_GID Ta An effective group ID
+.It Dv KERN_PROC_RGID Ta A real group ID
+.El
+.Pp
+For the following names, the miscellaneous information about the target
+process, which is specified by the fourth level of the oid name,
+is returned.
+A process ID of
+.Li \-1
+specifies the current process.
+.Bl -column "Third Level NameXXXXXX" "TypeXXXXXX" -offset indent
+.It Sy Third Level Name Ta Sy Fourth Level
+.It Dv KERN_PROC_ARGS Ta "Set of strings"
+.It Dv KERN_PROC_PATHNAME Ta "String"
+.It Dv KERN_PROC_KSTACK Ta "struct kinfo_stack []"
+.It Dv KERN_PROC_VMMAP Ta "struct kinfo_vmentry []"
+.It Dv KERN_PROC_FILEDESC Ta "struct kinfo_file []"
+.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_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_NFDS Ta "Integer"
+.It Dv KERN_PROC_SIGFASTBLK Ta "Integer"
+.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 []"
.El
.Pp
-If the third level name is
-.Dv KERN_PROC_ARGS
-then the command line argument
+.Bl -tag -compact
+.It Dv KERN_PROC_ARGS
+The command line argument
array is returned in a flattened form, i.e., zero-terminated arguments
follow each other.
The total size of array is returned.
It is also possible for a process to set its own process title this way.
-If the third level name is
-.Dv KERN_PROC_PATHNAME ,
-the path of the
-process' text file is stored.
-For
-.Dv KERN_PROC_PATHNAME ,
-a process ID of
-.Li \-1
-implies the current process.
-.Bl -column "Third Level NameXXXXXX" "Fourth LevelXXXXXX" -offset indent
-.It Sy Third Level Name Ta Sy Fourth Level
-.It Dv KERN_PROC_ARGS Ta "A process ID"
-.It Dv KERN_PROC_PATHNAME Ta "A process ID"
-.El
-.It Li KERN_PROF
-Return profiling information about the kernel.
-If the kernel is not compiled for profiling,
-attempts to retrieve any of the KERN_PROF values will
-fail with
-.Er ENOENT .
-The third level names for the string and integer profiling information
-is detailed below.
-The changeable column shows whether a process with appropriate
-privilege may change the value.
-.Bl -column "GPROFXGMONPARAMXXX" "struct gmonparamXXX" -offset indent
-.It Sy Third Level Name Ta Sy Type Ta Sy Changeable
-.It Dv GPROF_STATE Ta integer Ta yes
-.It Dv GPROF_COUNT Ta u_short[\|] Ta yes
-.It Dv GPROF_FROMS Ta u_short[\|] Ta yes
-.It Dv GPROF_TOS Ta struct tostruct Ta yes
-.It Dv GPROF_GMONPARAM Ta struct gmonparam Ta no
-.El
+.It Dv KERN_PROC_PATHNAME
+The path of the process' text file is returned.
+.It Dv KERN_PROC_KSTACK
+The in-kernel call stacks for the threads of the specified process.
+.It Dv KERN_PROC_VMMAP
+The description of the map entries for the process.
+Also refer to
+.Xr kinfo_getvmmap 3 .
+.It Dv KERN_PROC_FILEDESC
+The file descriptors for files opened in the specified process.
+Also refer to
+.Xr kinfo_getfile 3 .
+.It Dv KERN_PROC_GROUPS
+Groups associated with the process.
+.It Dv KERN_PROC_ENV
+The set of strings representing the environment of the specified process.
.Pp
-The variables are as follows:
-.Bl -tag -width 6n
-.It Li GPROF_STATE
-Returns GMON_PROF_ON or GMON_PROF_OFF to show that profiling
-is running or stopped.
-.It Li GPROF_COUNT
-Array of statistical program counter counts.
-.It Li GPROF_FROMS
-Array indexed by program counter of call-from points.
-.It Li GPROF_TOS
-Array of
-.Va struct tostruct
-describing destination of calls and their counts.
-.It Li GPROF_GMONPARAM
-Structure giving the sizes of the above arrays.
+Note that from the kernel point of view, environment exists only at the
+time of
+.Xr execve 2
+system call.
+This node method tries to reconstruct the environment from the known
+breadcrumbs left in the process address space, but it is not guaranteed
+to succeed or to represent the current value as maintained by the program.
+.It Dv KERN_PROC_AUXV
+The set of ELF auxv entries.
+See the note above about environment, which is also applicable to auxv.
+.It Dv KERN_PROC_RLIMIT
+Additinal OID name element must be supplied, specifiing the resource name
+as in
+.Xr getrlimit 2 .
+The call returns the given resource limit for the process.
+.It Dv KERN_PROC_PS_STRINGS
+Returns the location of the
+.Vt ps_strings
+structure at the time of the last call to
+.Xr execve 2
+in the specified process.
+.It Dv KERN_PROC_UMASK
+The current umask value, see
+.Xr umask 2 .
+.It Dv KERN_PROC_OSREL
+The value of osrel for the process, that is the osrel the currently executed
+image was compiled for.
+Read from the note of the elf executable at
+.Xr execve 2
+time.
+Might be modified by the process.
+.It Dv KERN_PROC_SIGTRAMP
+Address 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.
+.It Dv KERN_PROC_NFDS
+Returns the total number of opened file descriptors for the process.
+.It Dv KERN_PROC_SIGFASTBLK
+Returns the address of the
+.Xr sigfastblock 2
+location, if active.
+.It Dv KERN_PROC_VM_LAYOUT
+Fills a structure describing process virtual address space layout.
+.It Dv KERN_PROC_RLIMIT_USAGE
+Like
+.Dv KERN_PROC_RLIMIT ,
+but instead of the limit, returns the accounted resource usage.
+For resources which do not have a meaningful current value,
+.Li \-1
+is returned.
+.It Dv KERN_PROC_KQUEUE
+Fills an array of structures describing events registered with
+the specified kqueue.
+The next two node's values are the
+.Va pid
+and
+.Va kqfd ,
+the process ID of the process, and the file descriptor of the kqueue
+in that process, to query.
.El
-.It Li KERN_QUANTUM
-The maximum period of time, in microseconds, for which a process is allowed
-to run without being preempted if other processes are in the run queue.
+.It Li KERN_PS_STRINGS
+Reports the location of the process
+.Vt ps_strings
+structure after exec, for the ABI of the querying process.
.It Li KERN_SAVED_IDS
Returns 1 if saved set-group and saved set-user ID is available.
.It Li KERN_SECURELVL
The system security level.
This level may be raised by processes with appropriate privilege.
It may not be lowered.
+.It Li KERN_USRSTACK
+Reports the top of the main thread user stack for the current process.
.It Li KERN_VERSION
The system version string.
-.It Li KERN_VNODE
-Return the entire vnode table.
-Note, the vnode table is not necessarily a consistent snapshot of
-the system.
-The returned data consists of an array whose size depends on the
-current number of such objects in the system.
-Each element of the array consists of a
-.Va struct xvnode .
.El
.Ss CTL_NET
The string and integer information available for the CTL_NET level
@@ -871,6 +953,7 @@ A process without appropriate privilege attempts to set a value.
.El
.Sh SEE ALSO
.Xr confstr 3 ,
+.Xr kinfo_getproc 3 ,
.Xr kvm 3 ,
.Xr sysconf 3 ,
.Xr sysctl 8
diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c
index 59242b50bbed..d6fadd3c3e5c 100644
--- a/lib/libc/gen/sysctl.c
+++ b/lib/libc/gen/sysctl.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sysctl.c 8.2 (Berkeley) 1/4/94");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c
index 5086cc4b7d81..8cc9599f7a95 100644
--- a/lib/libc/gen/sysctlbyname.c
+++ b/lib/libc/gen/sysctlbyname.c
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/sysctl.h>
#include <string.h>
diff --git a/lib/libc/gen/sysctlnametomib.c b/lib/libc/gen/sysctlnametomib.c
index 86e02e98f9e3..e45d23e10714 100644
--- a/lib/libc/gen/sysctlnametomib.c
+++ b/lib/libc/gen/sysctlnametomib.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright 2001 The FreeBSD Project. All Rights Reserved.
*
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/sysctl.h>
#include <string.h>
diff --git a/lib/libc/gen/syslog.3 b/lib/libc/gen/syslog.3
index ce7dfdccf55e..62140554f4f5 100644
--- a/lib/libc/gen/syslog.3
+++ b/lib/libc/gen/syslog.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)syslog.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd May 13, 2021
+.Dd July 3, 2023
.Dt SYSLOG 3
.Os
.Sh NAME
@@ -131,6 +128,11 @@ The
.Fa ident
argument
is a string that will be prepended to every message.
+It may be formatted as
+.Fa ident[N]
+in which case decimal number
+.Fa N
+replaces the process id within messages.
The
.Fa logopt
argument
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c
index 8d48f7f32836..a6290ee81a29 100644
--- a/lib/libc/gen/syslog.c
+++ b/lib/libc/gen/syslog.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)syslog.c 8.5 (Berkeley) 4/29/95");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -218,7 +214,7 @@ vsyslog1(int pri, const char *fmt, va_list ap)
* specified, as it provides valuable information. Many
* applications tend not to use this, even though they should.
*/
- if (LogPid == -1)
+ if (LogTagLength <= 0)
LogPid = getpid();
(void)fprintf(fp, "%d ", (int)LogPid);
/* Message ID. */
@@ -463,7 +459,10 @@ setlogmask(int pmask)
}
/*
- * Obtain LogPid from LogTag formatted as following: ident[NNN]
+ * Obtain LogPid from LogTag formatted as per RFC 3164,
+ * Section 5.3 Originating Process Information:
+ *
+ * ident[NNN]
*/
static void
parse_tag(void)
diff --git a/lib/libc/gen/tcgetpgrp.3 b/lib/libc/gen/tcgetpgrp.3
index 965416e9a50e..2c9bd2983e06 100644
--- a/lib/libc/gen/tcgetpgrp.3
+++ b/lib/libc/gen/tcgetpgrp.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tcgetpgrp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd June 4, 1993
+.Dd November 28, 2022
.Dt TCGETPGRP 3
.Os
.Sh NAME
@@ -37,7 +34,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In unistd.h
.Ft pid_t
.Fn tcgetpgrp "int fd"
diff --git a/lib/libc/gen/tcgetsid.3 b/lib/libc/gen/tcgetsid.3
index 60bff8d0b98a..d613f9d9d7cb 100644
--- a/lib/libc/gen/tcgetsid.3
+++ b/lib/libc/gen/tcgetsid.3
@@ -22,9 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd April 15, 2008
+.Dd November 28, 2022
.Dt TCGETSID 3
.Os
.Sh NAME
@@ -33,7 +31,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In termios.h
.Ft pid_t
.Fn tcgetsid "int fd"
diff --git a/lib/libc/gen/tcgetwinsize.3 b/lib/libc/gen/tcgetwinsize.3
index 1bc96689c792..cc3c288d8169 100644
--- a/lib/libc/gen/tcgetwinsize.3
+++ b/lib/libc/gen/tcgetwinsize.3
@@ -32,8 +32,6 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.\" $FreeBSD$
-.\"
.Dd December 28, 2020
.Dt TCGETWINSIZE 3
.Os
diff --git a/lib/libc/gen/tcsendbreak.3 b/lib/libc/gen/tcsendbreak.3
index 4fa3fab4906f..0eb132e22e8c 100644
--- a/lib/libc/gen/tcsendbreak.3
+++ b/lib/libc/gen/tcsendbreak.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tcsendbreak.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd January 11, 2017
.Dt TCSENDBREAK 3
.Os
diff --git a/lib/libc/gen/tcsetattr.3 b/lib/libc/gen/tcsetattr.3
index ce28e985cd60..6afa90af556b 100644
--- a/lib/libc/gen/tcsetattr.3
+++ b/lib/libc/gen/tcsetattr.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tcsetattr.3 8.3 (Berkeley) 1/2/94
-.\" $FreeBSD$
-.\"
.Dd July 15, 2020
.Dt TCSETATTR 3
.Os
diff --git a/lib/libc/gen/tcsetpgrp.3 b/lib/libc/gen/tcsetpgrp.3
index d59dcf03f446..4ae67d4520bf 100644
--- a/lib/libc/gen/tcsetpgrp.3
+++ b/lib/libc/gen/tcsetpgrp.3
@@ -25,10 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tcsetpgrp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd June 4, 1993
+.Dd November 28, 2022
.Dt TCSETPGRP 3
.Os
.Sh NAME
@@ -37,7 +34,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In unistd.h
.Ft int
.Fn tcsetpgrp "int fd" "pid_t pgrp_id"
diff --git a/lib/libc/gen/tcsetsid.3 b/lib/libc/gen/tcsetsid.3
index d0f1d985753e..a0a1907a6434 100644
--- a/lib/libc/gen/tcsetsid.3
+++ b/lib/libc/gen/tcsetsid.3
@@ -22,9 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd May 4, 2009
+.Dd November 28, 2022
.Dt TCSETSID 3
.Os
.Sh NAME
@@ -33,7 +31,6 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In termios.h
.Ft int
.Fn tcsetsid "int fd" "pid_t pid"
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index d801345fc24c..1731cc4d7a2c 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)telldir.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/queue.h>
@@ -122,7 +118,7 @@ _seekdir(DIR *dirp, long loc)
struct dirent *dp;
union ddloc_packed ddloc;
off_t loc_seek;
- long loc_loc;
+ size_t loc_loc;
ddloc.l = loc;
@@ -175,7 +171,7 @@ _seekdir(DIR *dirp, long loc)
* fetching a new block to fix any such telldir locations.
*/
void
-_fixtelldir(DIR *dirp, long oldseek, long oldloc)
+_fixtelldir(DIR *dirp, off_t oldseek, size_t oldloc)
{
struct ddloc_mem *lp;
diff --git a/lib/libc/gen/telldir.h b/lib/libc/gen/telldir.h
index 6880ec562a45..02fd52af9060 100644
--- a/lib/libc/gen/telldir.h
+++ b/lib/libc/gen/telldir.h
@@ -30,8 +30,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _TELLDIR_H_
@@ -48,9 +46,9 @@
*/
struct ddloc_mem {
LIST_ENTRY(ddloc_mem) loc_lqe; /* entry in list */
- long loc_index; /* key associated with structure */
+ size_t loc_index; /* key associated with structure */
off_t loc_seek; /* magic cookie returned by getdirentries */
- long loc_loc; /* offset of entry in buffer */
+ size_t loc_loc; /* offset of entry in buffer */
};
#ifdef __LP64__
@@ -104,7 +102,8 @@ bool _filldir(DIR *, bool);
struct dirent *_readdir_unlocked(DIR *, int);
void _reclaim_telldir(DIR *);
void _seekdir(DIR *, long);
-void _fixtelldir(DIR *dirp, long oldseek, long oldloc);
+void _fixtelldir(DIR *dirp, off_t oldseek, size_t oldloc);
+DIR *__opendir_common(int, int, bool);
#define RDU_SKIP 0x0001
#define RDU_SHORT 0x0002
diff --git a/lib/libc/gen/termios.c b/lib/libc/gen/termios.c
index f072b2f045d9..2178cc7c419d 100644
--- a/lib/libc/gen/termios.c
+++ b/lib/libc/gen/termios.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)termios.c 8.2 (Berkeley) 2/21/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
#include <sys/fcntl.h>
diff --git a/lib/libc/gen/time.3 b/lib/libc/gen/time.3
index 52785057a56b..6df74df2dcb4 100644
--- a/lib/libc/gen/time.3
+++ b/lib/libc/gen/time.3
@@ -29,9 +29,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)time.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd April 14, 2022
.Dt TIME 3
.Os
diff --git a/lib/libc/gen/time.c b/lib/libc/gen/time.c
index c08d58ed9a66..3f26c937d15b 100644
--- a/lib/libc/gen/time.c
+++ b/lib/libc/gen/time.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)time.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/time.h>
diff --git a/lib/libc/gen/times.3 b/lib/libc/gen/times.3
index 487339480e2a..71449767b551 100644
--- a/lib/libc/gen/times.3
+++ b/lib/libc/gen/times.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)times.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd December 1, 2008
.Dt TIMES 3
.Os
diff --git a/lib/libc/gen/times.c b/lib/libc/gen/times.c
index d811b553b990..b609faedc7a1 100644
--- a/lib/libc/gen/times.c
+++ b/lib/libc/gen/times.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)times.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/time.h>
#include <sys/times.h>
@@ -45,8 +41,7 @@ __FBSDID("$FreeBSD$");
#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
clock_t
-times(tp)
- struct tms *tp;
+times(struct tms *tp)
{
struct rusage ru;
struct timespec t;
diff --git a/lib/libc/gen/timespec_get.3 b/lib/libc/gen/timespec_get.3
index 43300074eea7..7edf4fe17c30 100644
--- a/lib/libc/gen/timespec_get.3
+++ b/lib/libc/gen/timespec_get.3
@@ -27,9 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
-.Dd August 10, 2018
+.Dd August 21, 2023
.Dt TIMESPEC_GET 3
.Os
.Sh NAME
@@ -57,6 +55,14 @@ In
.Fx ,
this corresponds to
.Dv CLOCK_REALTIME .
+.Pp
+The base
+.Dv TIME_MONOTONIC
+returns a monotonically-increasing time since an unspecified point in the past.
+In
+.Fx ,
+this corresponds to
+.Dv CLOCK_MONOTONIC .
.Sh RETURN VALUES
The
.Nm
@@ -68,7 +74,8 @@ on failure.
.Sh SEE ALSO
.Xr clock_gettime 2 ,
.Xr gettimeofday 2 ,
-.Xr time 3
+.Xr time 3 ,
+.Xr timespec_getres 3
.Sh STANDARDS
The
.Nm
@@ -78,6 +85,10 @@ of
.Dv TIME_UTC
conforms to
.St -isoC-2011 .
+.\" The
+.\" .Dv TIME_MONOTONIC
+.\" base conforms to
+.\" -isoC-2023 .
.Sh HISTORY
This interface first appeared in
.Fx 12 .
diff --git a/lib/libc/gen/timespec_get.c b/lib/libc/gen/timespec_get.c
index 1dd0147e933d..96845d545048 100644
--- a/lib/libc/gen/timespec_get.c
+++ b/lib/libc/gen/timespec_get.c
@@ -31,8 +31,6 @@
#include <sys/cdefs.h>
__RCSID("$NetBSD: timespec_get.c,v 1.2 2016/10/04 12:48:15 christos Exp $");
-__FBSDID("$FreeBSD$");
-
#include <time.h>
/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */
@@ -46,6 +44,10 @@ timespec_get(struct timespec *ts, int base)
if (clock_gettime(CLOCK_REALTIME, ts) == -1)
return 0;
break;
+ case TIME_MONOTONIC:
+ if (clock_gettime(CLOCK_MONOTONIC, ts) == -1)
+ return 0;
+ break;
default:
return 0;
}
diff --git a/lib/libc/gen/timespec_getres.3 b/lib/libc/gen/timespec_getres.3
new file mode 100644
index 000000000000..e00af6758f1a
--- /dev/null
+++ b/lib/libc/gen/timespec_getres.3
@@ -0,0 +1,51 @@
+.\"-
+.\" Copyright (c) 2023 Dag-Erling Smørgrav
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd August 21, 2023
+.Dt TIMESPEC_GETRES 3
+.Os
+.Sh NAME
+.Nm timespec_getres
+.Nd get clock resolution
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In time.h
+.Ft int
+.Fn timespec_getres "struct timespec *ts" "int base"
+.Sh DESCRIPTION
+If
+.Fa ts
+is non-null and
+.Fa base
+refers to a supported time base as described in
+.Xr timespec_get 3 ,
+the
+.Nm
+function fills in the structure pointed to by
+.Fa ts
+to reflect the resolution of that time base.
+.Sh RETURN VALUES
+The
+.Nm
+function returns the value of
+.Fa base
+if successful and zero otherwise.
+.Sh SEE ALSO
+.Xr clock_getres 2 ,
+.Xr timespec_get 3
+.\" .Sh STANDARDS
+.\" The
+.\" .Nm
+.\" function conforms to
+.\" .St -isoC-2023 .
+.Sh HISTORY
+This interface first appeared in
+.Fx 14 .
+.Sh AUTHORS
+The
+.Nm
+function and this manual page were written by
+.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
diff --git a/lib/libc/gen/timespec_getres.c b/lib/libc/gen/timespec_getres.c
new file mode 100644
index 000000000000..4977d22cf910
--- /dev/null
+++ b/lib/libc/gen/timespec_getres.c
@@ -0,0 +1,24 @@
+/*-
+ * Copyright (c) 2023 Dag-Erling Smørgrav
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <time.h>
+
+int
+timespec_getres(struct timespec *ts, int base)
+{
+
+ switch (base) {
+ case TIME_UTC:
+ if (clock_getres(CLOCK_REALTIME, ts) == 0)
+ return (base);
+ break;
+ case TIME_MONOTONIC:
+ if (clock_getres(CLOCK_MONOTONIC, ts) == 0)
+ return (base);
+ break;
+ }
+ return (0);
+}
diff --git a/lib/libc/gen/timezone.3 b/lib/libc/gen/timezone.3
deleted file mode 100644
index 58aff536f76c..000000000000
--- a/lib/libc/gen/timezone.3
+++ /dev/null
@@ -1,69 +0,0 @@
-.\" Copyright (c) 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" 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.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)timezone.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
-.Dd April 19, 1994
-.Dt TIMEZONE 3
-.Os
-.Sh NAME
-.Nm timezone
-.Nd return the timezone abbreviation
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.Ft char *
-.Fn timezone "int zone" "int dst"
-.Sh DESCRIPTION
-.Bf Sy
-This interface is for compatibility only; it is impossible to reliably
-map timezone's arguments to a time zone abbreviation.
-See
-.Xr ctime 3 .
-.Ef
-.Pp
-The
-.Fn timezone
-function returns a pointer to a time zone abbreviation for the specified
-.Fa zone
-and
-.Fa dst
-values.
-The
-.Fa zone
-argument
-is the number of minutes west of GMT and
-.Fa dst
-is non-zero if daylight savings time is in effect.
-.Sh SEE ALSO
-.Xr ctime 3
-.Sh HISTORY
-A
-.Fn timezone
-function appeared in
-.At v7 .
diff --git a/lib/libc/gen/timezone.c b/lib/libc/gen/timezone.c
index f99a6f919262..2809067eb8d8 100644
--- a/lib/libc/gen/timezone.c
+++ b/lib/libc/gen/timezone.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)timezone.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
@@ -40,7 +36,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#define TZ_MAX_CHARS 255
-char *_tztab(int, int);
+static char *_tztab(int, int);
/*
* timezone --
@@ -53,7 +49,7 @@ char *_tztab(int, int);
static char czone[TZ_MAX_CHARS]; /* space for zone name */
char *
-timezone(int zone, int dst)
+__timezone_compat(int zone, int dst)
{
char *beg,
*end;
@@ -72,6 +68,7 @@ timezone(int zone, int dst)
}
return(_tztab(zone,dst)); /* default: table or created zone */
}
+__sym_compat(timezone, __timezone_compat, FBSD_1.0);
static struct zone {
int offset;
@@ -103,7 +100,7 @@ static struct zone {
* aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE
* STANDARD LIBRARY.
*/
-char *
+static char *
_tztab(int zone, int dst)
{
struct zone *zp;
diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index 5ceaf439d839..b26b13d45589 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2004 Doug Rabson
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
/*
@@ -34,7 +32,6 @@
* runtime from ld-elf.so.1.
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <stdlib.h>
#include <string.h>
@@ -83,13 +80,13 @@ static void *libc_tls_init;
void *
__libc_tls_get_addr(void *vti)
{
- uintptr_t *dtv;
+ struct dtv *dtv;
tls_index *ti;
dtv = _tcb_get()->tcb_dtv;
ti = vti;
- return ((char *)(dtv[ti->ti_module + 1] + ti->ti_offset) +
- TLS_DTV_OFFSET);
+ return (dtv->dtv_slots[ti->ti_module - 1].dtvs_tls +
+ (ti->ti_offset + TLS_DTV_OFFSET));
}
#ifdef __i386__
@@ -116,6 +113,8 @@ libc_malloc_aligned(size_t size, size_t align)
align = sizeof(void *);
mem = __je_bootstrap_malloc(size + sizeof(void *) + align - 1);
+ if (mem == NULL)
+ return (NULL);
res = (void *)roundup2((uintptr_t)mem + sizeof(void *), align);
*(void **)((uintptr_t)res - sizeof(void *)) = mem;
return (res);
@@ -152,7 +151,8 @@ libc_free_aligned(void *ptr)
* where TP points (with bias) to TLS and TCB immediately precedes TLS without
* any alignment gap[4]. Only TLS should be aligned. The TCB[0] points to DTV
* vector and DTV values are biased by constant value (TLS_DTV_OFFSET) from
- * real addresses[5].
+ * real addresses. However, like RTLD, we don't actually bias the DTV values,
+ * instead we compensate in __tls_get_addr for ti_offset's bias.
*
* [1] Ulrich Drepper: ELF Handling for Thread-Local Storage
* www.akkadia.org/drepper/tls.pdf
@@ -168,8 +168,6 @@ libc_free_aligned(void *ptr)
* but we must follow this rule due to suboptimal _tcb_set()
* (aka <ARCH>_SET_TP) implementation. This function doesn't expect TP but
* TCB as argument.
- *
- * [5] I'm not able to validate "values are biased" assertions.
*/
/*
@@ -202,11 +200,9 @@ get_tls_block_ptr(void *tcb, size_t tcbsize)
void
__libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused)
{
- Elf_Addr *dtv;
- Elf_Addr **tls;
+ struct dtv *dtv;
- tls = (Elf_Addr **)tcb;
- dtv = tls[0];
+ dtv = ((struct tcb *)tcb)->tcb_dtv;
__je_bootstrap_free(dtv);
libc_free_aligned(get_tls_block_ptr(tcb, tcbsize));
}
@@ -234,7 +230,8 @@ __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused)
void *
__libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
{
- Elf_Addr *dtv, **tcb;
+ struct dtv *dtv;
+ struct tcb *tcb;
char *tls_block, *tls;
size_t extra_size, maxalign, post_size, pre_size, tls_block_size;
@@ -263,7 +260,7 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
abort();
}
memset(tls_block, 0, tls_block_size);
- tcb = (Elf_Addr **)(tls_block + pre_size + extra_size);
+ tcb = (struct tcb *)(tls_block + pre_size + extra_size);
tls = (char *)tcb + TLS_TCB_SIZE + post_size;
if (oldtcb != NULL) {
@@ -272,19 +269,20 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
libc_free_aligned(oldtcb);
/* Adjust the DTV. */
- dtv = tcb[0];
- dtv[2] = (Elf_Addr)(tls + TLS_DTV_OFFSET);
+ dtv = tcb->tcb_dtv;
+ dtv->dtv_slots[0].dtvs_tls = tls;
} else {
- dtv = __je_bootstrap_malloc(3 * sizeof(Elf_Addr));
+ dtv = __je_bootstrap_malloc(sizeof(struct dtv) +
+ sizeof(struct dtv_slot));
if (dtv == NULL) {
tls_msg("__libc_allocate_tls: Out of memory.\n");
abort();
}
/* Build the DTV. */
- tcb[0] = dtv;
- dtv[0] = 1; /* Generation. */
- dtv[1] = 1; /* Segments count. */
- dtv[2] = (Elf_Addr)(tls + TLS_DTV_OFFSET);
+ tcb->tcb_dtv = dtv;
+ dtv->dtv_gen = 1; /* Generation. */
+ dtv->dtv_size = 1; /* Segments count. */
+ dtv->dtv_slots[0].dtvs_tls = tls;
if (libc_tls_init_size > 0)
memcpy(tls, libc_tls_init, libc_tls_init_size);
@@ -304,8 +302,8 @@ void
__libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign)
{
size_t size;
- Elf_Addr* dtv;
- Elf_Addr tlsstart, tlsend;
+ struct dtv *dtv;
+ uintptr_t tlsstart, tlsend;
/*
* Figure out the size of the initial TLS block so that we can
@@ -314,8 +312,8 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign)
tcbalign = MAX(tcbalign, libc_tls_init_align);
size = roundup2(libc_tls_static_space, tcbalign);
- dtv = ((Elf_Addr**)tcb)[1];
- tlsend = (Elf_Addr) tcb;
+ dtv = ((struct tcb *)tcb)->tcb_dtv;
+ tlsend = (uintptr_t)tcb;
tlsstart = tlsend - size;
libc_free_aligned((void*)tlsstart);
__je_bootstrap_free(dtv);
@@ -325,61 +323,60 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign)
* Allocate Static TLS using the Variant II method.
*/
void *
-__libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign)
+__libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign)
{
size_t size;
- char *tls;
- Elf_Addr *dtv;
- Elf_Addr segbase, oldsegbase;
+ char *tls_block, *tls;
+ struct dtv *dtv;
+ struct tcb *tcb;
tcbalign = MAX(tcbalign, libc_tls_init_align);
size = roundup2(libc_tls_static_space, tcbalign);
- if (tcbsize < 2 * sizeof(Elf_Addr))
- tcbsize = 2 * sizeof(Elf_Addr);
- tls = libc_malloc_aligned(size + tcbsize, tcbalign);
- if (tls == NULL) {
+ if (tcbsize < 2 * sizeof(uintptr_t))
+ tcbsize = 2 * sizeof(uintptr_t);
+ tls_block = libc_malloc_aligned(size + tcbsize, tcbalign);
+ if (tls_block == NULL) {
tls_msg("__libc_allocate_tls: Out of memory.\n");
abort();
}
- memset(tls, 0, size + tcbsize);
- dtv = __je_bootstrap_malloc(3 * sizeof(Elf_Addr));
+ memset(tls_block, 0, size + tcbsize);
+ dtv = __je_bootstrap_malloc(sizeof(struct dtv) +
+ sizeof(struct dtv_slot));
if (dtv == NULL) {
tls_msg("__libc_allocate_tls: Out of memory.\n");
abort();
}
- segbase = (Elf_Addr)(tls + size);
- ((Elf_Addr*)segbase)[0] = segbase;
- ((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv;
+ tcb = (struct tcb *)(tls_block + size);
+ tls = (char *)tcb - libc_tls_static_space;
+ tcb->tcb_self = tcb;
+ tcb->tcb_dtv = dtv;
- dtv[0] = 1;
- dtv[1] = 1;
- dtv[2] = segbase - libc_tls_static_space;
+ dtv->dtv_gen = 1;
+ dtv->dtv_size = 1;
+ dtv->dtv_slots[0].dtvs_tls = tls;
- if (oldtls) {
+ if (oldtcb != NULL) {
/*
* Copy the static TLS block over whole.
*/
- oldsegbase = (Elf_Addr) oldtls;
- memcpy((void *)(segbase - libc_tls_static_space),
- (const void *)(oldsegbase - libc_tls_static_space),
+ memcpy(tls, (const char *)oldtcb - libc_tls_static_space,
libc_tls_static_space);
/*
* We assume that this block was the one we created with
* allocate_initial_tls().
*/
- _rtld_free_tls(oldtls, 2*sizeof(Elf_Addr), sizeof(Elf_Addr));
+ _rtld_free_tls(oldtcb, 2 * sizeof(uintptr_t),
+ sizeof(uintptr_t));
} else {
- memcpy((void *)(segbase - libc_tls_static_space),
- libc_tls_init, libc_tls_init_size);
- memset((void *)(segbase - libc_tls_static_space +
- libc_tls_init_size), 0,
+ memcpy(tls, libc_tls_init, libc_tls_init_size);
+ memset(tls + libc_tls_init_size, 0,
libc_tls_static_space - libc_tls_init_size);
}
- return (void*) segbase;
+ return (tcb);
}
#endif /* TLS_VARIANT_II */
@@ -387,7 +384,7 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign)
#else
void *
-__libc_allocate_tls(void *oldtls __unused, size_t tcbsize __unused,
+__libc_allocate_tls(void *oldtcb __unused, size_t tcbsize __unused,
size_t tcbalign __unused)
{
return (0);
@@ -401,8 +398,6 @@ __libc_free_tls(void *tcb __unused, size_t tcbsize __unused,
#endif /* PIC */
-extern char **environ;
-
void
_init_tls(void)
{
diff --git a/lib/libc/gen/trivial-getcontextx.c b/lib/libc/gen/trivial-getcontextx.c
index 54f851384811..b9d4522d96ee 100644
--- a/lib/libc/gen/trivial-getcontextx.c
+++ b/lib/libc/gen/trivial-getcontextx.c
@@ -24,9 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/ucontext.h>
#include <errno.h>
diff --git a/lib/libc/gen/ttyname.3 b/lib/libc/gen/ttyname.3
index 320764fb2202..741b25946ace 100644
--- a/lib/libc/gen/ttyname.3
+++ b/lib/libc/gen/ttyname.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ttyname.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd July 18, 2014
.Dt TTYNAME 3
.Os
diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c
index 0984538eaf76..f1e2f401fe5d 100644
--- a/lib/libc/gen/ttyname.c
+++ b/lib/libc/gen/ttyname.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)ttyname.c 8.2 (Berkeley) 1/27/94");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -46,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <paths.h>
#include <errno.h>
#include "reentrant.h"
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -57,7 +54,7 @@ static thread_key_t ttyname_key;
static int ttyname_keycreated = 0;
int
-ttyname_r(int fd, char *buf, size_t len)
+__ssp_real(ttyname_r)(int fd, char *buf, size_t len)
{
size_t used;
diff --git a/lib/libc/gen/ttyslot.c b/lib/libc/gen/ttyslot.c
index fc1b0565afee..a57b18dcf030 100644
--- a/lib/libc/gen/ttyslot.c
+++ b/lib/libc/gen/ttyslot.c
@@ -30,8 +30,6 @@
*/
#include <sys/cdefs.h>
-__SCCSID("@(#)ttyslot.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
int __ttyslot(void);
diff --git a/lib/libc/gen/tzset.3 b/lib/libc/gen/tzset.3
deleted file mode 100644
index ddeb40585f33..000000000000
--- a/lib/libc/gen/tzset.3
+++ /dev/null
@@ -1,338 +0,0 @@
-.\" Copyright (c) 1989, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Arthur Olson.
-.\"
-.\" 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.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)tzset.3 8.2 (Berkeley) 11/17/93
-.\" $FreeBSD$
-.\"
-.Dd November 17, 1993
-.Dt TZSET 3
-.Os
-.Sh NAME
-.Nm tzset ,
-.Nm tzsetwall
-.Nd initialize time conversion information
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In time.h
-.Ft void
-.Fn tzset void
-.Ft void
-.Fn tzsetwall void
-.Sh DESCRIPTION
-The
-.Fn tzset
-function
-initializes time conversion information used by the library routine
-.Xr localtime 3 .
-The environment variable
-.Ev TZ
-specifies how this is done.
-.Pp
-If
-.Ev TZ
-does not appear in the environment, the best available approximation to
-local wall clock time, as specified by the
-.Xr tzfile 5 Ns -format
-file
-.Pa /etc/localtime
-is used.
-.Pp
-If
-.Ev TZ
-appears in the environment but its value is a null string, Coordinated
-Universal Time
-.Pq Tn UTC
-is used (without leap second correction).
-.Pp
-If
-.Ev TZ
-appears in the environment and its value begins with a colon
-.Pq Ql \&: ,
-the rest of its value is used as a pathname of a
-.Xr tzfile 5 Ns -format
-file from which to read the time conversion information.
-If the first character of the pathname is a slash
-.Pq Ql /
-it is used as
-an absolute pathname; otherwise, it is used as a pathname relative to
-the system time conversion information directory.
-.Pp
-If its value does not begin with a colon, it is first used as the pathname
-of a file (as described above) from which to read the time conversion
-information.
-If that file cannot be read, the value is then interpreted as a direct
-specification (the format is described below) of the time conversion
-information.
-.Pp
-If the
-.Ev TZ
-environment variable does not specify a
-.Xr tzfile 5 Ns -format
-file and cannot be interpreted as a direct specification,
-.Tn UTC
-is used.
-.Pp
-The
-.Fn tzsetwall
-function
-sets things up so that
-.Xr localtime 3
-returns the best available approximation of local wall clock time.
-.Sh SPECIFICATION FORMAT
-When
-.Ev TZ
-is used directly as a specification of the time conversion information,
-it must have the following syntax (spaces inserted for clarity):
-.Bd -ragged -offset indent
-.Em std offset
-.Bo
-.Em dst
-.Bq Em offset
-.Bq , Em rule
-.Bc
-.Ed
-.Pp
-Where:
-.Bl -tag -width std_and_dst -offset indent
-.It Em std No and Em dst
-Three or more bytes that are the designation for the standard
-.Pq Em std
-or summer
-.Pq Em dst
-time zone.
-Only
-.Em std
-is required; if
-.Em dst
-is missing, then summer time does not apply in this locale.
-Upper and lowercase letters are explicitly allowed.
-Any characters
-except a leading colon
-.Pq Ql \&: ,
-digits, comma
-.Pq Ql \&, ,
-minus
-.Pq Ql \- ,
-plus
-.Pq Ql + ,
-and
-.Tn ASCII
-.Dv NUL
-are allowed.
-.It Em offset
-Indicates the value one must add to the local time to arrive at
-Coordinated Universal Time.
-The
-.Em offset
-has the form:
-.Bd -ragged -offset indent
-.Sm off
-.Em hh Bo
-.Em : mm
-.Bq Em : ss
-.Bc
-.Sm on
-.Ed
-.Pp
-The minutes
-.Pq Em mm
-and seconds
-.Pq Em ss
-are optional.
-The hour
-.Pq Em hh
-is required and may be a single digit.
-The
-.Em offset
-following
-.Em std
-is required.
-If no
-.Em offset
-follows
-.Em dst ,
-summer time is assumed to be one hour ahead of standard time.
-One or
-more digits may be used; the value is always interpreted as a decimal
-number.
-The hour must be between zero and 24, and the minutes (and
-seconds) \(em if present \(em between zero and 59.
-If preceded by a
-.Pq Ql \-
-the time zone shall be east of the Prime Meridian; otherwise it shall be
-west (which may be indicated by an optional preceding
-.Pq Ql + ) .
-.It Em rule
-Indicates when to change to and back from summer time.
-The
-.Em rule
-has the form:
-.Bd -ragged -offset indent
-.Em date/time,date/time
-.Ed
-.Pp
-where the first
-.Em date
-describes when the change from standard to summer time occurs and the
-second
-.Em date
-describes when the change back happens.
-Each
-.Em time
-field describes when, in current local time, the change to the other
-time is made.
-.Pp
-The format of
-.Em date
-is one of the following:
-.Bl -tag -width "M.m.n.d"
-.It Sy J Em n
-The Julian day
-.Em n
-(1 \*(Le
-.Em n
-\*(Le 365).
-Leap days are not counted; that is, in all years \(em including leap
-years \(em February 28 is day 59 and March 1 is day 60.
-It is
-impossible to explicitly refer to the occasional February 29.
-.It Em n
-The zero-based Julian day
-(0 \*(Le
-.Em n
-\*(Le 365 ) .
-Leap days are counted, and it is possible to refer to February 29.
-.It Sy M Em m.n.d
-The
-.Em d Ns 'th
-day (0 \*(Le
-.Em d
-\*(Le 6)
-of week
-.Em n
-of month
-.Em m
-of the year
-(1 \*(Le
-.Em n
-\*(Le 5),
-(1 \*(Le
-.Em m
-\*(Le 12),
-where week 5 means
-.Do
-the last
-.Em d
-day in month
-.Em m
-.Dc
-which may occur in either the fourth or the fifth week).
-Week 1 is the
-first week in which the
-.Em d Ns 'th
-day occurs.
-Day zero is Sunday.
-.Pp
-The
-.Em time
-has the same format as
-.Em offset
-except that no leading sign
-.Pq Ql \-
-or
-.Pq Ql +
-is allowed.
-The default, if
-.Em time
-is not given, is
-.Sy 02:00:00 .
-.El
-.Pp
-If no
-.Em rule
-is present in the
-.Ev TZ
-specification, the rules specified
-by the
-.Xr tzfile 5 Ns -format
-file
-.Em posixrules
-in the system time conversion information directory are used, with the
-standard and summer time offsets from
-.Tn UTC
-replaced by those specified by
-the
-.Em offset
-values in
-.Ev TZ .
-.El
-.Pp
-For compatibility with System V Release 3.1, a semicolon
-.Pq Ql \&;
-may be used to separate the
-.Em rule
-from the rest of the specification.
-.Sh FILES
-.Bl -tag -width /usr/share/zoneinfo/posixrules -compact
-.It Pa /etc/localtime
-local time zone file
-.It Pa /usr/share/zoneinfo
-time zone directory
-.It Pa /usr/share/zoneinfo/posixrules
-rules for
-.Tn POSIX Ns -style
-.Tn TZ Ns 's
-.It Pa /usr/share/zoneinfo/Etc/GMT
-for
-.Tn UTC
-leap seconds
-.El
-.Pp
-If the file
-.Pa /usr/share/zoneinfo/UTC
-does not exist,
-.Tn UTC
-leap seconds are loaded from
-.Pa /usr/share/zoneinfo/posixrules .
-.Sh SEE ALSO
-.Xr date 1 ,
-.Xr gettimeofday 2 ,
-.Xr ctime 3 ,
-.Xr getenv 3 ,
-.Xr time 3 ,
-.Xr tzfile 5
-.Sh HISTORY
-The
-.Fn tzset
-and
-.Fn tzsetwall
-functions first appeared in
-.Bx 4.4 .
diff --git a/lib/libc/gen/ualarm.3 b/lib/libc/gen/ualarm.3
index 7d40b2a53a81..dfd9ddd5f434 100644
--- a/lib/libc/gen/ualarm.3
+++ b/lib/libc/gen/ualarm.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" From: @(#)ualarm.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD$
-.\"
.Dd April 19, 1994
.Dt UALARM 3
.Os
@@ -73,7 +70,7 @@ restriction the maximum number of
.Fa microseconds
and
.Fa interval
-is limited to 100000000000000
+is limited to 100,000,000,000,000
(in case this value fits in the unsigned integer).
.Sh RETURN VALUES
When the signal has successfully been caught,
diff --git a/lib/libc/gen/ualarm.c b/lib/libc/gen/ualarm.c
index e1353176845f..44e77252202f 100644
--- a/lib/libc/gen/ualarm.c
+++ b/lib/libc/gen/ualarm.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)ualarm.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/time.h>
#include <unistd.h>
diff --git a/lib/libc/gen/ucontext.3 b/lib/libc/gen/ucontext.3
index d6e05dc2c1fa..4166049957db 100644
--- a/lib/libc/gen/ucontext.3
+++ b/lib/libc/gen/ucontext.3
@@ -33,8 +33,6 @@
.\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
.\" THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd March 23, 2020
.Dt UCONTEXT 3
.Os
diff --git a/lib/libc/gen/uexterr_format.c b/lib/libc/gen/uexterr_format.c
new file mode 100644
index 000000000000..e8ddfbd578e3
--- /dev/null
+++ b/lib/libc/gen/uexterr_format.c
@@ -0,0 +1,35 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#include <sys/types.h>
+#include <sys/exterrvar.h>
+#include <exterr.h>
+#include <stdio.h>
+#include <string.h>
+
+int
+__uexterr_format(const struct uexterror *ue, char *buf, size_t bufsz)
+{
+ if (bufsz > UEXTERROR_MAXLEN)
+ bufsz = UEXTERROR_MAXLEN;
+ if (ue->error == 0) {
+ strlcpy(buf, "", bufsz);
+ return (0);
+ }
+ if (ue->msg[0] == '\0') {
+ snprintf(buf, bufsz,
+ "errno %d category %u (src line %u) p1 %#jx p2 %#jx",
+ ue->error, ue->cat, ue->src_line,
+ (uintmax_t)ue->p1, (uintmax_t)ue->p2);
+ } else {
+ strlcpy(buf, ue->msg, bufsz);
+ }
+ return (0);
+}
diff --git a/lib/libc/gen/uexterr_gettext.c b/lib/libc/gen/uexterr_gettext.c
new file mode 100644
index 000000000000..5b8a5cd17a48
--- /dev/null
+++ b/lib/libc/gen/uexterr_gettext.c
@@ -0,0 +1,43 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#define _WANT_P_OSREL
+#include <sys/param.h>
+#include <sys/exterrvar.h>
+#include <exterr.h>
+#include <string.h>
+#include "libc_private.h"
+
+static struct uexterror uexterr = {
+ .ver = UEXTERROR_VER,
+};
+
+int __getosreldate(void);
+
+static void uexterr_ctr(void) __attribute__((constructor));
+static void
+uexterr_ctr(void)
+{
+ if (__getosreldate() >= P_OSREL_EXTERRCTL)
+ exterrctl(EXTERRCTL_ENABLE, 0, &uexterr);
+}
+
+int
+__libc_uexterr_gettext(char *buf, size_t bufsz)
+{
+ return (__uexterr_format(&uexterr, buf, bufsz));
+}
+
+int
+uexterr_gettext(char *buf, size_t bufsz)
+{
+ return (((int (*)(char *, size_t))
+ __libc_interposing[INTERPOS_uexterr_gettext])(buf, bufsz));
+}
diff --git a/lib/libc/gen/ulimit.3 b/lib/libc/gen/ulimit.3
index e4c2d769323c..771c40126944 100644
--- a/lib/libc/gen/ulimit.3
+++ b/lib/libc/gen/ulimit.3
@@ -21,8 +21,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd January 4, 2003
.Dt ULIMIT 3
.Os
diff --git a/lib/libc/gen/ulimit.c b/lib/libc/gen/ulimit.c
index c9602491cc20..93231bb86fa8 100644
--- a/lib/libc/gen/ulimit.c
+++ b/lib/libc/gen/ulimit.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Kyle Martin <mkm@ieee.org>
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <sys/types.h>
diff --git a/lib/libc/gen/uname.3 b/lib/libc/gen/uname.3
index a4c7d9030b06..ed1596529c4c 100644
--- a/lib/libc/gen/uname.3
+++ b/lib/libc/gen/uname.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)uname.3 8.1 (Berkeley) 1/4/94
-.\" $FreeBSD$
-.\"
.Dd December 2, 2005
.Dt UNAME 3
.Os
diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c
index bc72ff9d3c39..3a14ae3fefc1 100644
--- a/lib/libc/gen/uname.c
+++ b/lib/libc/gen/uname.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)uname.c 8.1 (Berkeley) 1/4/94");
-__FBSDID("$FreeBSD$");
-
#define uname wrapped_uname
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/unvis-compat.c b/lib/libc/gen/unvis-compat.c
index 2249f847621e..4562b8f7a383 100644
--- a/lib/libc/gen/unvis-compat.c
+++ b/lib/libc/gen/unvis-compat.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 SRI International
* All rights reserved.
@@ -28,8 +28,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <vis.h>
diff --git a/lib/libc/gen/usleep.3 b/lib/libc/gen/usleep.3
deleted file mode 100644
index f6ed9e6bb52e..000000000000
--- a/lib/libc/gen/usleep.3
+++ /dev/null
@@ -1,80 +0,0 @@
-.\" Copyright (c) 1986, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" 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.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)usleep.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
-.Dd February 11, 2021
-.Dt USLEEP 3
-.Os
-.Sh NAME
-.Nm usleep
-.Nd suspend thread execution for an interval measured in microseconds
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In unistd.h
-.Ft int
-.Fn usleep "useconds_t microseconds"
-.Sh DESCRIPTION
-The
-.Fn usleep
-function suspends execution of the calling thread until either
-.Fa microseconds
-microseconds have elapsed or a signal is delivered to the thread and its
-action is to invoke a signal-catching function or to terminate the
-process.
-System activity may lengthen the sleep by an indeterminate amount.
-.Pp
-This function is implemented using
-.Xr nanosleep 2
-by pausing for
-.Fa microseconds
-microseconds or until a signal occurs.
-Consequently, in this implementation,
-sleeping has no effect on the state of process timers,
-and there is no special handling for SIGALRM.
-.Sh RETURN VALUES
-.Rv -std usleep
-.Sh ERRORS
-The
-.Fn usleep
-function
-will fail if:
-.Bl -tag -width Er
-.It Bq Er EINTR
-A signal was delivered to the calling thread and its
-action was to invoke a signal-catching function.
-.El
-.Sh SEE ALSO
-.Xr nanosleep 2 ,
-.Xr sleep 3
-.Sh HISTORY
-The
-.Fn usleep
-function appeared in
-.Bx 4.3 .
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c
index e800f6275617..31d5567d562d 100644
--- a/lib/libc/gen/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)usleep.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <time.h>
#include <unistd.h>
@@ -49,8 +45,7 @@ __usleep(useconds_t useconds)
time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
time_to_sleep.tv_sec = useconds / 1000000;
- return (((int (*)(const struct timespec *, struct timespec *))
- __libc_interposing[INTERPOS_nanosleep])(&time_to_sleep, NULL));
+ return (INTERPOS_SYS(nanosleep, &time_to_sleep, NULL));
}
__weak_reference(__usleep, usleep);
diff --git a/lib/libc/gen/utime.3 b/lib/libc/gen/utime.3
index b995ea523cf5..e17fab908497 100644
--- a/lib/libc/gen/utime.3
+++ b/lib/libc/gen/utime.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)utime.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd June 9, 2016
.Dt UTIME 3
.Os
diff --git a/lib/libc/gen/utime.c b/lib/libc/gen/utime.c
index 3474849571b7..208c6bdae449 100644
--- a/lib/libc/gen/utime.c
+++ b/lib/libc/gen/utime.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)utime.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <sys/time.h>
#include <utime.h>
diff --git a/lib/libc/gen/utxdb.c b/lib/libc/gen/utxdb.c
index 3edccdbd2c2f..4c4c73bffea3 100644
--- a/lib/libc/gen/utxdb.c
+++ b/lib/libc/gen/utxdb.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/endian.h>
#include <sys/param.h>
diff --git a/lib/libc/gen/utxdb.h b/lib/libc/gen/utxdb.h
index 912dd0fa113e..5b1f35f99fd7 100644
--- a/lib/libc/gen/utxdb.h
+++ b/lib/libc/gen/utxdb.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org>
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _UTXDB_H_
diff --git a/lib/libc/gen/valloc.3 b/lib/libc/gen/valloc.3
index 2fc20bb82a4a..063e781e3174 100644
--- a/lib/libc/gen/valloc.3
+++ b/lib/libc/gen/valloc.3
@@ -25,9 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)valloc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
-.\"
.Dd October 30, 2007
.Dt VALLOC 3
.Os
diff --git a/lib/libc/gen/valloc.c b/lib/libc/gen/valloc.c
index b058543f54ac..6f3fd2d2d10c 100644
--- a/lib/libc/gen/valloc.c
+++ b/lib/libc/gen/valloc.c
@@ -29,10 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)valloc.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
#include <stdlib.h>
#include <unistd.h>
diff --git a/lib/libc/gen/wait3.c b/lib/libc/gen/wait3.c
deleted file mode 100644
index 104ab8e5652e..000000000000
--- a/lib/libc/gen/wait3.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#include <sys/cdefs.h>
-__SCCSID("@(#)wait3.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include "un-namespace.h"
-
-#include "libc_private.h"
-
-pid_t __wait3(int *, int, struct rusage *);
-
-pid_t
-__wait3(int *istat, int options, struct rusage *rup)
-{
-
- return (((pid_t (*)(pid_t, int *, int, struct rusage *))
- __libc_interposing[INTERPOS_wait4])(WAIT_ANY, istat, options, rup));
-}
-
-__weak_reference(__wait3, wait3);
diff --git a/lib/libc/gen/waitid.c b/lib/libc/gen/waitid.c
deleted file mode 100644
index b9a8c577150a..000000000000
--- a/lib/libc/gen/waitid.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
- * Copyright (c) 2012 Jukka A. Ukkonen
- * All rights reserved.
- *
- * This software was developed by Jukka Ukkonen for FreeBSD.
- *
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stddef.h>
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-int __waitid(idtype_t, id_t, siginfo_t *, int);
-
-int
-__waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
-{
- int status;
- pid_t ret;
-
- ret = ((pid_t (*)(idtype_t, id_t, int *, int, struct __wrusage *,
- siginfo_t *))__libc_interposing[INTERPOS_wait6])(idtype, id,
- &status, flags, NULL, info);
-
- /*
- * According to SUSv4, waitid() shall not return a PID when a
- * process is found, but only 0. If a process was actually
- * found, siginfo_t fields si_signo and si_pid will be
- * non-zero. In case WNOHANG was set in the flags and no
- * process was found those fields are set to zero using
- * memset() below.
- */
- if (ret == 0 && info != NULL)
- memset(info, 0, sizeof(*info));
- else if (ret > 0)
- ret = 0;
- return (ret);
-}
-
-__weak_reference(__waitid, waitid);
-__weak_reference(__waitid, _waitid);
diff --git a/lib/libc/gen/waitpid.c b/lib/libc/gen/waitpid.c
deleted file mode 100644
index c17cefa09ab3..000000000000
--- a/lib/libc/gen/waitpid.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#include <sys/cdefs.h>
-__SCCSID("@(#)waitpid.c 8.1 (Berkeley) 6/4/93");
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include "un-namespace.h"
-
-#include "libc_private.h"
-
-pid_t __waitpid(pid_t, int *, int);
-
-pid_t
-__waitpid(pid_t pid, int *istat, int options)
-{
-
- return (((pid_t (*)(pid_t, int *, int, struct rusage *))
- __libc_interposing[INTERPOS_wait4])(pid, istat, options, NULL));
-}
-
-__weak_reference(__waitpid, waitpid);
-__weak_reference(__waitpid, _waitpid);
diff --git a/lib/libc/gen/wordexp.3 b/lib/libc/gen/wordexp.3
index dd4605ffa6fd..f54d8af3f38c 100644
--- a/lib/libc/gen/wordexp.3
+++ b/lib/libc/gen/wordexp.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd September 30, 2015
.Dt WORDEXP 3
.Os
diff --git a/lib/libc/gen/wordexp.c b/lib/libc/gen/wordexp.c
index 0322c1176d69..f8080c20d121 100644
--- a/lib/libc/gen/wordexp.c
+++ b/lib/libc/gen/wordexp.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Tim J. Robbins.
* All rights reserved.
@@ -27,7 +27,6 @@
*/
#include "namespace.h"
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
@@ -42,9 +41,6 @@
#include <wordexp.h>
#include "un-namespace.h"
#include "libc_private.h"
-
-__FBSDID("$FreeBSD$");
-
static int we_askshell(const char *, wordexp_t *, int);
static int we_check(const char *);
@@ -269,7 +265,15 @@ cleanup:
errno = serrno;
return (error);
}
- if (wpid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ /*
+ * Check process exit status, but ignore ECHILD as the child may have
+ * been automatically reaped if the process had set SIG_IGN or
+ * SA_NOCLDWAIT for SIGCHLD, and our reason for waitpid was just to
+ * reap our own child on behalf of the calling process.
+ */
+ if (wpid < 0 && errno != ECHILD)
+ return (WRDE_NOSPACE); /* abort for unknown reason */
+ if (wpid >= 0 && (!WIFEXITED(status) || WEXITSTATUS(status) != 0))
return (WRDE_NOSPACE); /* abort for unknown reason */
/*