aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/Makefile.inc64
-rw-r--r--lib/libc/gen/Symbol.map50
-rw-r--r--lib/libc/gen/__getosreldate.c67
-rw-r--r--lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c1
-rw-r--r--lib/libc/gen/__xuname.c3
-rw-r--r--lib/libc/gen/_once_stub.c1
-rw-r--r--lib/libc/gen/_pthread_stubs.c13
-rw-r--r--lib/libc/gen/_rand48.c1
-rw-r--r--lib/libc/gen/_spinlock_stub.c1
-rw-r--r--lib/libc/gen/_thread_init.c1
-rw-r--r--lib/libc/gen/aio_read2.c (renamed from lib/libc/gen/sched_getcpu_gen.c)32
-rw-r--r--lib/libc/gen/aio_write2.c (renamed from lib/libc/gen/errno.c)36
-rw-r--r--lib/libc/gen/alarm.34
-rw-r--r--lib/libc/gen/alarm.c2
-rw-r--r--lib/libc/gen/arc4random-compat.c1
-rw-r--r--lib/libc/gen/arc4random.324
-rw-r--r--lib/libc/gen/arc4random.c4
-rw-r--r--lib/libc/gen/arc4random_uniform.c71
-rw-r--r--lib/libc/gen/assert.c2
-rw-r--r--lib/libc/gen/auxv.3105
-rw-r--r--lib/libc/gen/auxv.c404
-rw-r--r--lib/libc/gen/basename.c1
-rw-r--r--lib/libc/gen/basename_compat.c1
-rw-r--r--lib/libc/gen/cap_sandboxed.c1
-rw-r--r--lib/libc/gen/check_utility_compat.c1
-rw-r--r--lib/libc/gen/clock.32
-rw-r--r--lib/libc/gen/clock.c2
-rw-r--r--lib/libc/gen/clock_getcpuclockid.c1
-rw-r--r--lib/libc/gen/closedir.c2
-rw-r--r--lib/libc/gen/confstr.32
-rw-r--r--lib/libc/gen/confstr.c2
-rw-r--r--lib/libc/gen/crypt.c2
-rw-r--r--lib/libc/gen/ctermid.32
-rw-r--r--lib/libc/gen/ctermid.c6
-rw-r--r--lib/libc/gen/daemon.32
-rw-r--r--lib/libc/gen/daemon.c2
-rw-r--r--lib/libc/gen/devname-compat11.c1
-rw-r--r--lib/libc/gen/devname.32
-rw-r--r--lib/libc/gen/devname.c2
-rw-r--r--lib/libc/gen/directory.32
-rw-r--r--lib/libc/gen/dirfd.c1
-rw-r--r--lib/libc/gen/dirname.c1
-rw-r--r--lib/libc/gen/dirname_compat.c1
-rw-r--r--lib/libc/gen/disklabel.c2
-rw-r--r--lib/libc/gen/dlfcn.c46
-rw-r--r--lib/libc/gen/dlopen.38
-rw-r--r--lib/libc/gen/drand48.c1
-rw-r--r--lib/libc/gen/dup3.315
-rw-r--r--lib/libc/gen/dup3.c10
-rw-r--r--lib/libc/gen/elf_utils.c27
-rw-r--r--lib/libc/gen/erand48.c1
-rw-r--r--lib/libc/gen/err.32
-rw-r--r--lib/libc/gen/err.c53
-rw-r--r--lib/libc/gen/errlst.c2
-rw-r--r--lib/libc/gen/eventfd.c1
-rw-r--r--lib/libc/gen/exec.327
-rw-r--r--lib/libc/gen/exec.c235
-rw-r--r--lib/libc/gen/exect.c1
-rw-r--r--lib/libc/gen/fdevname.c1
-rw-r--r--lib/libc/gen/fdopendir.c (renamed from lib/libc/gen/wait.c)41
-rw-r--r--lib/libc/gen/feature_present.c1
-rw-r--r--lib/libc/gen/fmtcheck.c1
-rw-r--r--lib/libc/gen/fmtmsg.c1
-rw-r--r--lib/libc/gen/fnmatch.310
-rw-r--r--lib/libc/gen/fnmatch.c229
-rw-r--r--lib/libc/gen/frexp.32
-rw-r--r--lib/libc/gen/fstab.c2
-rw-r--r--lib/libc/gen/ftok.c1
-rw-r--r--lib/libc/gen/fts-compat.c3
-rw-r--r--lib/libc/gen/fts-compat.h2
-rw-r--r--lib/libc/gen/fts-compat11.c3
-rw-r--r--lib/libc/gen/fts-compat11.h2
-rw-r--r--lib/libc/gen/fts.388
-rw-r--r--lib/libc/gen/fts.c298
-rw-r--r--lib/libc/gen/ftw-compat11.c1
-rw-r--r--lib/libc/gen/ftw.c1
-rw-r--r--lib/libc/gen/gen-private.h4
-rw-r--r--lib/libc/gen/getbootfile.32
-rw-r--r--lib/libc/gen/getbootfile.c3
-rw-r--r--lib/libc/gen/getbsize.32
-rw-r--r--lib/libc/gen/getbsize.c2
-rw-r--r--lib/libc/gen/getcap.32
-rw-r--r--lib/libc/gen/getcap.c2
-rw-r--r--lib/libc/gen/getcwd.32
-rw-r--r--lib/libc/gen/getcwd.c5
-rw-r--r--lib/libc/gen/getdiskbyname.32
-rw-r--r--lib/libc/gen/getdomainname.32
-rw-r--r--lib/libc/gen/getdomainname.c5
-rw-r--r--lib/libc/gen/getentropy.312
-rw-r--r--lib/libc/gen/getentropy.c107
-rw-r--r--lib/libc/gen/getfsent.32
-rw-r--r--lib/libc/gen/getgrent.32
-rw-r--r--lib/libc/gen/getgrent.c1
-rw-r--r--lib/libc/gen/getgrouplist.32
-rw-r--r--lib/libc/gen/getgrouplist.c5
-rw-r--r--lib/libc/gen/gethostname.32
-rw-r--r--lib/libc/gen/gethostname.c5
-rw-r--r--lib/libc/gen/getloadavg.32
-rw-r--r--lib/libc/gen/getloadavg.c2
-rw-r--r--lib/libc/gen/getlogin.c5
-rw-r--r--lib/libc/gen/getmntinfo-compat11.c3
-rw-r--r--lib/libc/gen/getmntinfo.32
-rw-r--r--lib/libc/gen/getmntinfo.c2
-rw-r--r--lib/libc/gen/getnetgrent.32
-rw-r--r--lib/libc/gen/getnetgrent.c2
-rw-r--r--lib/libc/gen/getosreldate.c2
-rw-r--r--lib/libc/gen/getpagesize.369
-rw-r--r--lib/libc/gen/getpagesize.c73
-rw-r--r--lib/libc/gen/getpagesizes.397
-rw-r--r--lib/libc/gen/getpagesizes.c85
-rw-r--r--lib/libc/gen/getpass.32
-rw-r--r--lib/libc/gen/getpeereid.34
-rw-r--r--lib/libc/gen/getpeereid.c1
-rw-r--r--lib/libc/gen/getprogname.c1
-rw-r--r--lib/libc/gen/getpwent.32
-rw-r--r--lib/libc/gen/getpwent.c1
-rw-r--r--lib/libc/gen/getttyent.32
-rw-r--r--lib/libc/gen/getttyent.c2
-rw-r--r--lib/libc/gen/getusershell.32
-rw-r--r--lib/libc/gen/getusershell.c2
-rw-r--r--lib/libc/gen/getutxent.c1
-rw-r--r--lib/libc/gen/getvfsbyname.32
-rw-r--r--lib/libc/gen/getvfsbyname.c4
-rw-r--r--lib/libc/gen/glob-compat11.c3
-rw-r--r--lib/libc/gen/glob-compat11.h3
-rw-r--r--lib/libc/gen/glob.368
-rw-r--r--lib/libc/gen/glob.c77
-rw-r--r--lib/libc/gen/initgroups.32
-rw-r--r--lib/libc/gen/initgroups.c2
-rw-r--r--lib/libc/gen/inotify.c48
-rw-r--r--lib/libc/gen/isatty.c2
-rw-r--r--lib/libc/gen/jrand48.c1
-rw-r--r--lib/libc/gen/lcong48.c1
-rw-r--r--lib/libc/gen/ldexp.32
-rw-r--r--lib/libc/gen/ldexp.c1
-rw-r--r--lib/libc/gen/libc_dlopen.c1
-rw-r--r--lib/libc/gen/libc_interposing_table.c (renamed from lib/libc/gen/sendmmsg.c)53
-rw-r--r--lib/libc/gen/lockf.3264
-rw-r--r--lib/libc/gen/lockf.c84
-rw-r--r--lib/libc/gen/lrand48.c1
-rw-r--r--lib/libc/gen/makecontext.31
-rw-r--r--lib/libc/gen/memalign.c1
-rw-r--r--lib/libc/gen/memfd_create.c121
-rw-r--r--lib/libc/gen/modf.32
-rw-r--r--lib/libc/gen/modf.c2
-rw-r--r--lib/libc/gen/mrand48.c1
-rw-r--r--lib/libc/gen/nftw-compat11.c1
-rw-r--r--lib/libc/gen/nftw.c1
-rw-r--r--lib/libc/gen/nice.32
-rw-r--r--lib/libc/gen/nice.c2
-rw-r--r--lib/libc/gen/nlist.32
-rw-r--r--lib/libc/gen/nlist.c2
-rw-r--r--lib/libc/gen/nrand48.c1
-rw-r--r--lib/libc/gen/opendir.c321
-rw-r--r--lib/libc/gen/opendir2.c337
-rw-r--r--lib/libc/gen/pause.32
-rw-r--r--lib/libc/gen/pause.c2
-rw-r--r--lib/libc/gen/pmadvise.c1
-rw-r--r--lib/libc/gen/popen.32
-rw-r--r--lib/libc/gen/popen.c2
-rw-r--r--lib/libc/gen/posix_spawn.316
-rw-r--r--lib/libc/gen/posix_spawn.c27
-rw-r--r--lib/libc/gen/posix_spawn_file_actions_addopen.32
-rw-r--r--lib/libc/gen/posix_spawnattr_getflags.310
-rw-r--r--lib/libc/gen/psignal.378
-rw-r--r--lib/libc/gen/psignal.c8
-rw-r--r--lib/libc/gen/pututxline.c1
-rw-r--r--lib/libc/gen/pw_scan.c2
-rw-r--r--lib/libc/gen/pw_scan.h2
-rw-r--r--lib/libc/gen/raise.32
-rw-r--r--lib/libc/gen/raise.c2
-rw-r--r--lib/libc/gen/rand48.32
-rw-r--r--lib/libc/gen/readdir-compat11.c3
-rw-r--r--lib/libc/gen/readdir.c15
-rw-r--r--lib/libc/gen/readpassphrase.c1
-rw-r--r--lib/libc/gen/recvmmsg.c95
-rw-r--r--lib/libc/gen/rewinddir.c2
-rw-r--r--lib/libc/gen/rfork_thread.385
-rw-r--r--lib/libc/gen/rtld_get_var.3106
-rw-r--r--lib/libc/gen/scandir-compat11.c3
-rw-r--r--lib/libc/gen/scandir.3129
-rw-r--r--lib/libc/gen/scandir.c131
-rw-r--r--lib/libc/gen/seed48.c1
-rw-r--r--lib/libc/gen/seekdir.c2
-rw-r--r--lib/libc/gen/semctl.c1
-rw-r--r--lib/libc/gen/setdomainname.c2
-rw-r--r--lib/libc/gen/sethostname.c2
-rw-r--r--lib/libc/gen/setjmp.32
-rw-r--r--lib/libc/gen/setjmperr.c2
-rw-r--r--lib/libc/gen/setmode.32
-rw-r--r--lib/libc/gen/setmode.c2
-rw-r--r--lib/libc/gen/setproctitle.34
-rw-r--r--lib/libc/gen/setproctitle.c1
-rw-r--r--lib/libc/gen/setprogname.c1
-rw-r--r--lib/libc/gen/sig2str.c113
-rw-r--r--lib/libc/gen/siginterrupt.32
-rw-r--r--lib/libc/gen/siginterrupt.c2
-rw-r--r--lib/libc/gen/siglist.c2
-rw-r--r--lib/libc/gen/signal.32
-rw-r--r--lib/libc/gen/signal.c2
-rw-r--r--lib/libc/gen/sigsetops.32
-rw-r--r--lib/libc/gen/sigsetops.c2
-rw-r--r--lib/libc/gen/sleep.382
-rw-r--r--lib/libc/gen/sleep.c6
-rw-r--r--lib/libc/gen/statvfs.c1
-rw-r--r--lib/libc/gen/strtofflags.32
-rw-r--r--lib/libc/gen/strtofflags.c2
-rw-r--r--lib/libc/gen/sysconf.32
-rw-r--r--lib/libc/gen/sysconf.c11
-rw-r--r--lib/libc/gen/sysctl.3175
-rw-r--r--lib/libc/gen/sysctl.c2
-rw-r--r--lib/libc/gen/sysctlbyname.c1
-rw-r--r--lib/libc/gen/sysctlnametomib.c1
-rw-r--r--lib/libc/gen/syslog.32
-rw-r--r--lib/libc/gen/syslog.c2
-rw-r--r--lib/libc/gen/tcgetpgrp.32
-rw-r--r--lib/libc/gen/tcsendbreak.32
-rw-r--r--lib/libc/gen/tcsetattr.32
-rw-r--r--lib/libc/gen/tcsetpgrp.32
-rw-r--r--lib/libc/gen/telldir.c6
-rw-r--r--lib/libc/gen/telldir.h7
-rw-r--r--lib/libc/gen/termios.c2
-rw-r--r--lib/libc/gen/time.32
-rw-r--r--lib/libc/gen/time.c2
-rw-r--r--lib/libc/gen/times.32
-rw-r--r--lib/libc/gen/times.c2
-rw-r--r--lib/libc/gen/timezone.368
-rw-r--r--lib/libc/gen/timezone.c9
-rw-r--r--lib/libc/gen/tls.c101
-rw-r--r--lib/libc/gen/trivial-getcontextx.c1
-rw-r--r--lib/libc/gen/ttyname.32
-rw-r--r--lib/libc/gen/ttyname.c5
-rw-r--r--lib/libc/gen/ttyslot.c2
-rw-r--r--lib/libc/gen/tzset.3325
-rw-r--r--lib/libc/gen/ualarm.34
-rw-r--r--lib/libc/gen/ualarm.c2
-rw-r--r--lib/libc/gen/uexterr_format.c35
-rw-r--r--lib/libc/gen/uexterr_gettext.c43
-rw-r--r--lib/libc/gen/uname.32
-rw-r--r--lib/libc/gen/uname.c2
-rw-r--r--lib/libc/gen/usleep.379
-rw-r--r--lib/libc/gen/usleep.c5
-rw-r--r--lib/libc/gen/utime.32
-rw-r--r--lib/libc/gen/utime.c2
-rw-r--r--lib/libc/gen/utxdb.c1
-rw-r--r--lib/libc/gen/valloc.32
-rw-r--r--lib/libc/gen/valloc.c2
-rw-r--r--lib/libc/gen/wait3.c53
-rw-r--r--lib/libc/gen/waitid.c70
-rw-r--r--lib/libc/gen/waitpid.c54
-rw-r--r--lib/libc/gen/wordexp.c11
251 files changed, 2541 insertions, 3538 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 655843f03715..4d064d18d36e 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,5 +1,3 @@
-# @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
-
# machine-independent gen sources
.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen ${SRCTOP}/etc
@@ -7,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 \
@@ -15,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 \
@@ -47,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 \
@@ -80,8 +79,6 @@ SRCS+= __getosreldate.c \
getmntinfo-compat11.c \
getnetgrent.c \
getosreldate.c \
- getpagesize.c \
- getpagesizes.c \
getpeereid.c \
getprogname.c \
getpwent.c \
@@ -92,6 +89,7 @@ SRCS+= __getosreldate.c \
glob.c \
glob-compat11.c \
initgroups.c \
+ inotify.c \
isatty.c \
isinf.c \
isnan.c \
@@ -99,9 +97,10 @@ SRCS+= __getosreldate.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 \
@@ -162,6 +161,8 @@ SRCS+= __getosreldate.c \
ttyname.c \
ttyslot.c \
ualarm.c \
+ uexterr_format.c \
+ uexterr_gettext.c \
ulimit.c \
uname.c \
unvis-compat.c \
@@ -169,12 +170,13 @@ 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
@@ -206,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 \
@@ -252,8 +253,6 @@ MAN+= alarm.3 \
getmntinfo.3 \
getnetgrent.3 \
getosreldate.3 \
- getpagesize.3 \
- getpagesizes.3 \
getpass.3 \
getpeereid.3 \
getprogname.3 \
@@ -266,7 +265,6 @@ MAN+= alarm.3 \
initgroups.3 \
isgreater.3 \
ldexp.3 \
- lockf.3 \
makecontext.3 \
modf.3 \
nice.3 \
@@ -288,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 \
@@ -303,7 +301,6 @@ MAN+= alarm.3 \
siginterrupt.3 \
signal.3 \
sigsetops.3 \
- sleep.3 \
statvfs.3 \
stringlist.3 \
strtofflags.3 \
@@ -321,15 +318,12 @@ MAN+= alarm.3 \
times.3 \
timespec_get.3 \
timespec_getres.3 \
- timezone.3 \
ttyname.3 \
- tzset.3 \
ualarm.3 \
ucontext.3 \
ulimit.3 \
uname.3 \
unvis.3 \
- usleep.3 \
utime.3 \
valloc.3 \
vis.3 \
@@ -337,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
@@ -378,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 \
@@ -481,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 \
@@ -496,16 +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+=rtld_get_var.3 \
+ rtld_set_var.3
MLINKS+=scandir.3 alphasort.3 \
- scandir.3 scandirat.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 \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index bdd659197644..26f638568efc 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -1,6 +1,3 @@
-/*
- */
-
FBSD_1.0 {
__xuname;
pthread_atfork;
@@ -50,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;
@@ -62,6 +60,7 @@ FBSD_1.0 {
pthread_setcanceltype;
pthread_setspecific;
pthread_sigmask;
+ pthread_suspend_all_np;
pthread_testcancel;
alarm;
arc4random;
@@ -102,7 +101,6 @@ FBSD_1.0 {
vwarnx;
sys_errlist;
sys_nerr;
- errno;
exect;
execl;
execle;
@@ -110,6 +108,7 @@ FBSD_1.0 {
execv;
execvp;
execvP;
+ fabs;
fmtcheck;
fmtmsg;
fnmatch;
@@ -161,7 +160,6 @@ FBSD_1.0 {
endnetgrent;
innetgr;
getosreldate;
- getpagesize;
getpeereid;
_getprogname;
getprogname;
@@ -184,10 +182,12 @@ FBSD_1.0 {
endusershell;
setusershell;
getvfsbyname;
+ __nan;
__isnan;
isnan;
__isnanf;
isnanf;
+ __infinity;
__isinf;
isinf;
__isinff;
@@ -199,6 +199,7 @@ FBSD_1.0 {
ldexp;
lockf;
lrand48;
+ makecontext;
modf;
mrand48;
nice;
@@ -220,6 +221,12 @@ FBSD_1.0 {
group_from_gid;
setdomainname;
sethostname;
+ _setjmp;
+ _longjmp;
+ setjmp;
+ longjmp;
+ sigsetjmp;
+ siglongjmp;
longjmperror;
getmode;
setmode;
@@ -256,7 +263,6 @@ FBSD_1.0 {
setlogmask;
ttyname_r;
ttyname;
- timezone;
times;
time;
telldir;
@@ -332,7 +338,6 @@ FBSD_1.1 {
FBSD_1.2 {
cfmakesane;
endutxent;
- getpagesizes;
getutxent;
getutxid;
getutxline;
@@ -354,6 +359,7 @@ FBSD_1.2 {
};
FBSD_1.3 {
+ cap_sandboxed;
clock_getcpuclockid;
dirfd;
dup3;
@@ -397,7 +403,6 @@ FBSD_1.5 {
devname;
devname_r;
dirname;
- elf_aux_info;
fts_children;
fts_close;
fts_get_clientptr;
@@ -426,6 +431,7 @@ FBSD_1.6 {
eventfd_write;
getlogin_r;
memalign;
+ memfd_create;
pthread_getname_np;
scandir_b;
sigandset;
@@ -443,16 +449,36 @@ FBSD_1.7 {
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;
+ 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;
@@ -555,6 +581,8 @@ FBSDprivate_1.0 {
__waitpid;
_waitpid;
+ __libc_interposing_slot;
+
_libc_sem_init_compat;
_libc_sem_destroy_compat;
_libc_sem_open_compat;
@@ -568,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/__getosreldate.c b/lib/libc/gen/__getosreldate.c
deleted file mode 100644
index 81e7382caac6..000000000000
--- a/lib/libc/gen/__getosreldate.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2007 Peter Wemm
- *
- * 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>
-#include <sys/param.h>
-#include <sys/sysctl.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.
- */
-
-int
-__getosreldate(void)
-{
- static int osreldate;
- size_t len;
- int oid[2];
- int error, osrel;
-
- if (osreldate != 0)
- return (osreldate);
-
- error = _elf_aux_info(AT_OSRELDATE, &osreldate, sizeof(osreldate));
- if (error == 0 && osreldate != 0)
- return (osreldate);
-
- 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);
-}
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 1f0a8f7a944d..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,7 +29,6 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <pthread.h>
#include "libc_private.h"
diff --git a/lib/libc/gen/__xuname.c b/lib/libc/gen/__xuname.c
index f6e1372dc76a..4257c42f9519 100644
--- a/lib/libc/gen/__xuname.c
+++ b/lib/libc/gen/__xuname.c
@@ -27,11 +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>
#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 27de031108af..518072cbd28f 100644
--- a/lib/libc/gen/_once_stub.c
+++ b/lib/libc/gen/_once_stub.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 34e420ec11f5..d867ee4db51e 100644
--- a/lib/libc/gen/_pthread_stubs.c
+++ b/lib/libc/gen/_pthread_stubs.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <signal.h>
#include <pthread.h>
#include <stdlib.h>
@@ -51,6 +50,7 @@ struct pthread {
static struct pthread main_thread;
static int stub_main(void);
+static void stub_void(void);
static void *stub_null(void);
static struct pthread *stub_self(void);
static int stub_zero(void);
@@ -63,6 +63,7 @@ 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 +134,8 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = {
[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)},
};
/*
@@ -292,6 +295,8 @@ 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)
@@ -299,6 +304,12 @@ stub_zero(void)
return (0);
}
+static void
+stub_void(void)
+{
+
+}
+
static void *
stub_null(void)
{
diff --git a/lib/libc/gen/_rand48.c b/lib/libc/gen/_rand48.c
index e422781e44d3..990e2c86949b 100644
--- a/lib/libc/gen/_rand48.c
+++ b/lib/libc/gen/_rand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
unsigned short _rand48_seed[3] = {
diff --git a/lib/libc/gen/_spinlock_stub.c b/lib/libc/gen/_spinlock_stub.c
index b220d90ea193..30e5c61f5f74 100644
--- a/lib/libc/gen/_spinlock_stub.c
+++ b/lib/libc/gen/_spinlock_stub.c
@@ -29,7 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdio.h>
#include "spinlock.h"
diff --git a/lib/libc/gen/_thread_init.c b/lib/libc/gen/_thread_init.c
index b285654cc863..66fa8b8c2e96 100644
--- a/lib/libc/gen/_thread_init.c
+++ b/lib/libc/gen/_thread_init.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/types.h>
void _thread_init_stub(void);
diff --git a/lib/libc/gen/sched_getcpu_gen.c b/lib/libc/gen/aio_read2.c
index ef1bebc2915a..a5186d509b26 100644
--- a/lib/libc/gen/sched_getcpu_gen.c
+++ b/lib/libc/gen/aio_read2.c
@@ -1,5 +1,7 @@
/*-
- * Copyright (c) 2021 The FreeBSD Foundation
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 The FreeBSD Foundation
*
* This software were developed by Konstantin Belousov <kib@FreeBSD.org>
* under sponsorship from the FreeBSD Foundation.
@@ -26,11 +28,31 @@
* SUCH DAMAGE.
*/
-#include <sched.h>
-#include "libc_private.h"
+#include <sys/aio.h>
+#include <errno.h>
+#include <stddef.h>
int
-sched_getcpu(void)
+aio_read2(struct aiocb *iocb, int flags)
{
- return (__sys_sched_getcpu());
+ 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;
+
+ 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/errno.c b/lib/libc/gen/aio_write2.c
index aae8300a34b2..8f4f6a35fd4d 100644
--- a/lib/libc/gen/errno.c
+++ b/lib/libc/gen/aio_write2.c
@@ -1,8 +1,10 @@
/*-
* 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,5 +28,31 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-int errno;
+#include <sys/aio.h>
+#include <errno.h>
+#include <stddef.h>
+
+int
+aio_write2(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_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;
+
+ 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 6e9d13b51dd6..4a24cc6d7216 100644
--- a/lib/libc/gen/alarm.3
+++ b/lib/libc/gen/alarm.3
@@ -25,8 +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
-.\"
.Dd April 2, 2022
.Dt ALARM 3
.Os
@@ -65,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 58b9835608d8..043571ff89a1 100644
--- a/lib/libc/gen/alarm.c
+++ b/lib/libc/gen/alarm.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)alarm.c 8.1 (Berkeley) 6/4/93");
/*
* Backwards compatible alarm.
*/
diff --git a/lib/libc/gen/arc4random-compat.c b/lib/libc/gen/arc4random-compat.c
index 014273b1a76d..beeb4d75964a 100644
--- a/lib/libc/gen/arc4random-compat.c
+++ b/lib/libc/gen/arc4random-compat.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 62b62e883e9c..1b042f15f000 100644
--- a/lib/libc/gen/arc4random.3
+++ b/lib/libc/gen/arc4random.3
@@ -30,7 +30,7 @@
.\"
.\" Manual page, using -mandoc macros
.\"
-.Dd April 13, 2020
+.Dd November 18, 2024
.Dt ARC4RANDOM 3
.Os
.Sh NAME
@@ -129,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 621af03a57a7..cc65e0131970 100644
--- a/lib/libc/gen/arc4random.c
+++ b/lib/libc/gen/arc4random.c
@@ -23,7 +23,6 @@
* ChaCha based random number generator for OpenBSD.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#if defined(__FreeBSD__)
#include <assert.h>
@@ -36,6 +35,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ssp/ssp.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -244,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_uniform.c b/lib/libc/gen/arc4random_uniform.c
index 06cd29c6dbe4..23455e545899 100644
--- a/lib/libc/gen/arc4random_uniform.c
+++ b/lib/libc/gen/arc4random_uniform.c
@@ -1,56 +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>
+/*-
+ * SPDX-License-Identifier: 0BSD
*
- * 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.
+ * Copyright (c) Robert Clausecker <fuz@FreeBSD.org>
+ * Based on a publication by Daniel Lemire.
+ * Public domain where applicable.
*
- * 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.
+ * 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 06b4261437f3..21e5a44522ec 100644
--- a/lib/libc/gen/assert.c
+++ b/lib/libc/gen/assert.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)assert.c 8.1 (Berkeley) 6/4/93");
#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 10ec10e8755c..000000000000
--- a/lib/libc/gen/auxv.3
+++ /dev/null
@@ -1,105 +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.
-.\"
-.Dd September 16, 2022
-.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 *)).
-.It AT_USRSTACKBASE
-Top of the user stack for main thread.
-.It AT_USRSTACKLIM
-Limit for grow of the user stack for main thread.
-.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 1b0d886030b2..000000000000
--- a/lib/libc/gen/auxv.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * 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>
-#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 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;
-static u_long usrstackbase, usrstacklim;
-
-#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;
-
- case AT_USRSTACKBASE:
- usrstackbase = aux->a_un.a_val;
- break;
-
- case AT_USRSTACKLIM:
- usrstacklim = aux->a_un.a_val;
- 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;
- case AT_USRSTACKBASE:
- if (buflen == sizeof(u_long)) {
- if (usrstackbase != 0) {
- *(u_long *)buf = usrstackbase;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- case AT_USRSTACKLIM:
- if (buflen == sizeof(u_long)) {
- if (usrstacklim != 0) {
- *(u_long *)buf = usrstacklim;
- res = 0;
- } else
- res = ENOENT;
- } else
- res = EINVAL;
- break;
- default:
- res = ENOENT;
- break;
- }
- return (res);
-}
diff --git a/lib/libc/gen/basename.c b/lib/libc/gen/basename.c
index 46fea9a630cf..d0ba1bd9229c 100644
--- a/lib/libc/gen/basename.c
+++ b/lib/libc/gen/basename.c
@@ -23,7 +23,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <libgen.h>
#include <string.h>
diff --git a/lib/libc/gen/basename_compat.c b/lib/libc/gen/basename_compat.c
index 217c4582e857..19a4bd6c03eb 100644
--- a/lib/libc/gen/basename_compat.c
+++ b/lib/libc/gen/basename_compat.c
@@ -16,7 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#include <errno.h>
#include <libgen.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/cap_sandboxed.c b/lib/libc/gen/cap_sandboxed.c
index d01d94735bec..63c2439382a6 100644
--- a/lib/libc/gen/cap_sandboxed.c
+++ b/lib/libc/gen/cap_sandboxed.c
@@ -28,7 +28,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/capsicum.h>
#include <assert.h>
diff --git a/lib/libc/gen/check_utility_compat.c b/lib/libc/gen/check_utility_compat.c
index 6b1b487945f2..63a268896daa 100644
--- a/lib/libc/gen/check_utility_compat.c
+++ b/lib/libc/gen/check_utility_compat.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
/*
* 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 39a10ffbf15a..77d7ce085d2e 100644
--- a/lib/libc/gen/clock.3
+++ b/lib/libc/gen/clock.3
@@ -29,8 +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
-.\"
.Dd June 4, 1993
.Dt CLOCK 3
.Os
diff --git a/lib/libc/gen/clock.c b/lib/libc/gen/clock.c
index 59a85d393ceb..4d78fff73028 100644
--- a/lib/libc/gen/clock.c
+++ b/lib/libc/gen/clock.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)clock.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
diff --git a/lib/libc/gen/clock_getcpuclockid.c b/lib/libc/gen/clock_getcpuclockid.c
index fdfe3b614d69..77d6c3423301 100644
--- a/lib/libc/gen/clock_getcpuclockid.c
+++ b/lib/libc/gen/clock_getcpuclockid.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index 16f9bff452e4..6015114d6c47 100644
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)closedir.c 8.1 (Berkeley) 6/10/93");
#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 f10856878710..df19339c612a 100644
--- a/lib/libc/gen/confstr.3
+++ b/lib/libc/gen/confstr.3
@@ -25,8 +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
-.\"
.Dd December 3, 2006
.Dt CONFSTR 3
.Os
diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c
index c348d4ce1587..491df0cba67a 100644
--- a/lib/libc/gen/confstr.c
+++ b/lib/libc/gen/confstr.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)confstr.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include <errno.h>
diff --git a/lib/libc/gen/crypt.c b/lib/libc/gen/crypt.c
index a2deb670f148..ddcd6719775f 100644
--- a/lib/libc/gen/crypt.c
+++ b/lib/libc/gen/crypt.c
@@ -32,8 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)crypt.c 5.11 (Berkeley) 6/25/91");
#include <stdio.h>
#include <string.h>
#include <unistd.h>
diff --git a/lib/libc/gen/ctermid.3 b/lib/libc/gen/ctermid.3
index d2d0d8e5d815..2a53412f1b29 100644
--- a/lib/libc/gen/ctermid.3
+++ b/lib/libc/gen/ctermid.3
@@ -25,8 +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
-.\"
.Dd October 1, 2011
.Dt CTERMID 3
.Os
diff --git a/lib/libc/gen/ctermid.c b/lib/libc/gen/ctermid.c
index 35be197742a7..fb117b3c8ded 100644
--- a/lib/libc/gen/ctermid.c
+++ b/lib/libc/gen/ctermid.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -35,11 +34,12 @@
#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;
@@ -63,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 0c6479f65cc5..4619ba3489aa 100644
--- a/lib/libc/gen/daemon.3
+++ b/lib/libc/gen/daemon.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)daemon.3 8.1 (Berkeley) 6/9/93
-.\"
.Dd February 27, 2023
.Dt DAEMON 3
.Os
diff --git a/lib/libc/gen/daemon.c b/lib/libc/gen/daemon.c
index 0ea1e0809d08..525c99761aa3 100644
--- a/lib/libc/gen/daemon.c
+++ b/lib/libc/gen/daemon.c
@@ -30,8 +30,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)daemon.c 8.1 (Berkeley) 6/4/93");
#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 37886b6c8aaa..b01b0845e261 100644
--- a/lib/libc/gen/devname-compat11.c
+++ b/lib/libc/gen/devname-compat11.c
@@ -24,7 +24,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 1ab8b5ec98b9..44c1ff951cfa 100644
--- a/lib/libc/gen/devname.3
+++ b/lib/libc/gen/devname.3
@@ -25,8 +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
-.\"
.Dd February 22, 2005
.Dt DEVNAME 3
.Os
diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c
index bee5a78060e0..ebb56132c48d 100644
--- a/lib/libc/gen/devname.c
+++ b/lib/libc/gen/devname.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)devname.c 8.2 (Berkeley) 4/29/95");
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 0314ab90ca24..263dfdd6eb95 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -25,8 +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
-.\"
.Dd August 1, 2020
.Dt DIRECTORY 3
.Os
diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c
index 123d856eba47..85090bd4da6c 100644
--- a/lib/libc/gen/dirfd.c
+++ b/lib/libc/gen/dirfd.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
diff --git a/lib/libc/gen/dirname.c b/lib/libc/gen/dirname.c
index ab36ac66dea1..7157fec23630 100644
--- a/lib/libc/gen/dirname.c
+++ b/lib/libc/gen/dirname.c
@@ -23,7 +23,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <libgen.h>
#include <string.h>
diff --git a/lib/libc/gen/dirname_compat.c b/lib/libc/gen/dirname_compat.c
index 6423984b1877..7eca7eb03f83 100644
--- a/lib/libc/gen/dirname_compat.c
+++ b/lib/libc/gen/dirname_compat.c
@@ -16,7 +16,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/cdefs.h>
#include <errno.h>
#include <libgen.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c
index 8155202b7828..4b3730920529 100644
--- a/lib/libc/gen/disklabel.c
+++ b/lib/libc/gen/disklabel.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)disklabel.c 8.2 (Berkeley) 5/3/95");
#include <sys/param.h>
#define DKTYPENAMES
#define FSTYPENAMES
diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c
index b6dab041bac3..ae1c8d83df19 100644
--- a/lib/libc/gen/dlfcn.c
+++ b/lib/libc/gen/dlfcn.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#if !defined(IN_LIBDL) || defined(PIC)
/*
@@ -36,6 +35,7 @@
#include <sys/mman.h>
#include <machine/atomic.h>
#include <dlfcn.h>
+#include <errno.h>
#include <link.h>
#include <stddef.h>
#include <string.h>
@@ -203,9 +203,12 @@ 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)
{
#if defined IN_LIBDL
@@ -226,15 +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);
#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)
@@ -338,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/dlopen.3 b/lib/libc/gen/dlopen.3
index 09f37ff2fa93..340545114114 100644
--- a/lib/libc/gen/dlopen.3
+++ b/lib/libc/gen/dlopen.3
@@ -29,9 +29,7 @@
.\"
.\" Copyright (c) 1991 Sun Microsystems, Inc.
.\"
-.\" @(#) dlopen.3 1.6 90/01/31 SMI
-.\"
-.Dd May 14, 2020
+.Dd May 7, 2024
.Dt DLOPEN 3
.Os
.Sh NAME
@@ -201,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
diff --git a/lib/libc/gen/drand48.c b/lib/libc/gen/drand48.c
index e24b974ae84f..cec04a6a2425 100644
--- a/lib/libc/gen/drand48.c
+++ b/lib/libc/gen/drand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
extern unsigned short _rand48_seed[3];
diff --git a/lib/libc/gen/dup3.3 b/lib/libc/gen/dup3.3
index f2798930797b..338a9ae74c64 100644
--- a/lib/libc/gen/dup3.3
+++ b/lib/libc/gen/dup3.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 16, 2013
+.Dd May 17, 2025
.Dt DUP3 3
.Os
.Sh NAME
@@ -47,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
@@ -91,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 ,
@@ -112,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 e0298c821148..1401c1f5b607 100644
--- a/lib/libc/gen/dup3.c
+++ b/lib/libc/gen/dup3.c
@@ -28,7 +28,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <unistd.h>
#include <fcntl.h>
@@ -40,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 5b87e012d0eb..3714a0dc42b5 100644
--- a/lib/libc/gen/elf_utils.c
+++ b/lib/libc/gen/elf_utils.c
@@ -31,14 +31,16 @@
#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)
@@ -102,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 fb0b1aef8cf1..286904c27839 100644
--- a/lib/libc/gen/erand48.c
+++ b/lib/libc/gen/erand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
double
diff --git a/lib/libc/gen/err.3 b/lib/libc/gen/err.3
index eb429f888fae..088ead71239b 100644
--- a/lib/libc/gen/err.3
+++ b/lib/libc/gen/err.3
@@ -25,8 +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
-.\"
.Dd March 29, 2012
.Dt ERR 3
.Os
diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c
index 9636ef5b93b5..16cbe27693e7 100644
--- a/lib/libc/gen/err.c
+++ b/lib/libc/gen/err.c
@@ -29,12 +29,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)err.c 8.1 (Berkeley) 6/4/93");
#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>
@@ -45,6 +46,11 @@ __SCCSID("@(#)err.c 8.1 (Berkeley) 6/4/93");
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
@@ -72,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
@@ -87,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());
@@ -101,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);
@@ -159,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 837af5b0c6ae..a73fa06feb5e 100644
--- a/lib/libc/gen/errlst.c
+++ b/lib/libc/gen/errlst.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)errlst.c 8.2 (Berkeley) 11/16/93");
#include <errno.h>
#include <stdio.h>
#include "errlst.h"
diff --git a/lib/libc/gen/eventfd.c b/lib/libc/gen/eventfd.c
index e05218cf90e4..44a33915c2fb 100644
--- a/lib/libc/gen/eventfd.c
+++ b/lib/libc/gen/eventfd.c
@@ -24,7 +24,6 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <sys/cdefs.h>
#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 ead7ea0f416f..41ab18fa89ef 100644
--- a/lib/libc/gen/exec.3
+++ b/lib/libc/gen/exec.3
@@ -25,9 +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
-.\"
-.Dd March 22, 2020
+.Dd December 11, 2023
.Dt EXEC 3
.Os
.Sh NAME
@@ -37,6 +35,7 @@
.Nm exect ,
.Nm execv ,
.Nm execvp ,
+.Nm execvpe ,
.Nm execvP
.Nd execute a file
.Sh LIBRARY
@@ -50,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
@@ -58,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
@@ -99,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
@@ -112,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
@@ -136,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
@@ -146,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.
@@ -271,7 +275,8 @@ The
.Fn execl ,
.Fn execle ,
.Fn execlp ,
-.Fn execvp
+.Fn execvp ,
+.Fn execvpe ,
and
.Fn execvP
functions
@@ -309,6 +314,9 @@ and
functions
conform to
.St -p1003.1-88 .
+The
+.Fn execvpe
+function is a GNU extension.
.Sh HISTORY
The
.Fn exec
@@ -332,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
@@ -342,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 15dc7f0200ac..12020a79f6b4 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -29,13 +29,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)exec.c 8.1 (Berkeley) 6/4/93");
#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>
@@ -138,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') {
@@ -194,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,
@@ -204,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);
}
@@ -290,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;
@@ -300,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 b40c95c93fe3..e5be7a4d8755 100644
--- a/lib/libc/gen/exect.c
+++ b/lib/libc/gen/exect.c
@@ -24,7 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/ptrace.h>
#include <errno.h>
diff --git a/lib/libc/gen/fdevname.c b/lib/libc/gen/fdevname.c
index 585724e53fc9..62e71e98af63 100644
--- a/lib/libc/gen/fdevname.c
+++ b/lib/libc/gen/fdevname.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 ddb2e5725c11..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,26 +29,35 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)wait.c 8.1 (Berkeley) 6/4/93");
#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.c b/lib/libc/gen/feature_present.c
index bbf8fcc2eb47..4c0b41cfb23e 100644
--- a/lib/libc/gen/feature_present.c
+++ b/lib/libc/gen/feature_present.c
@@ -30,7 +30,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>
diff --git a/lib/libc/gen/fmtcheck.c b/lib/libc/gen/fmtcheck.c
index 8a3ea16b88cf..de889ad3421c 100644
--- a/lib/libc/gen/fmtcheck.c
+++ b/lib/libc/gen/fmtcheck.c
@@ -30,7 +30,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c
index 9a62c90f4d96..9edeee4405ce 100644
--- a/lib/libc/gen/fmtmsg.c
+++ b/lib/libc/gen/fmtmsg.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <fmtmsg.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/fnmatch.3 b/lib/libc/gen/fnmatch.3
index 1367f94b8f3e..7f020fec58e3 100644
--- a/lib/libc/gen/fnmatch.3
+++ b/lib/libc/gen/fnmatch.3
@@ -27,9 +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
-.\"
-.Dd April 2, 2022
+.Dd April 7, 2025
.Dt FNMATCH 3
.Os
.Sh NAME
@@ -131,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 e211f3d535ad..1c583a9d23e2 100644
--- a/lib/libc/gen/fnmatch.c
+++ b/lib/libc/gen/fnmatch.c
@@ -37,8 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)fnmatch.c 8.2 (Berkeley) 4/16/94");
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
@@ -69,7 +67,8 @@ __SCCSID("@(#)fnmatch.c 8.2 (Berkeley) 4/16/94");
#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);
@@ -87,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;
@@ -153,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)
@@ -166,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)) {
@@ -220,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;
}
@@ -230,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
@@ -261,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);
@@ -290,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);
@@ -297,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/frexp.3 b/lib/libc/gen/frexp.3
index a1d187ea44c8..1424ac888ad6 100644
--- a/lib/libc/gen/frexp.3
+++ b/lib/libc/gen/frexp.3
@@ -29,8 +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
-.\"
.Dd March 4, 2005
.Dt FREXP 3
.Os
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index 06aae12ff86a..ae21b4696883 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)fstab.c 8.1 (Berkeley) 6/4/93");
#include "namespace.h"
#include <sys/param.h>
#include <sys/mount.h>
diff --git a/lib/libc/gen/ftok.c b/lib/libc/gen/ftok.c
index 1465fe5c7e47..04fa5d464fb0 100644
--- a/lib/libc/gen/ftok.c
+++ b/lib/libc/gen/ftok.c
@@ -27,7 +27,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 e692e1f9e271..f87cabf085f7 100644
--- a/lib/libc/gen/fts-compat.c
+++ b/lib/libc/gen/fts-compat.c
@@ -27,12 +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>
#include "namespace.h"
#include <sys/param.h>
#define _WANT_FREEBSD11_STATFS
diff --git a/lib/libc/gen/fts-compat.h b/lib/libc/gen/fts-compat.h
index f1794fe3264d..d522e3befedb 100644
--- a/lib/libc/gen/fts-compat.h
+++ b/lib/libc/gen/fts-compat.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.
- *
- * @(#)fts.h 8.3 (Berkeley) 8/14/94
*/
#ifndef _FTS_H_
diff --git a/lib/libc/gen/fts-compat11.c b/lib/libc/gen/fts-compat11.c
index 2739e10a77de..0351ce5ac690 100644
--- a/lib/libc/gen/fts-compat11.c
+++ b/lib/libc/gen/fts-compat11.c
@@ -25,12 +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>
#include "namespace.h"
#include <sys/param.h>
#define _WANT_FREEBSD11_STATFS
diff --git a/lib/libc/gen/fts-compat11.h b/lib/libc/gen/fts-compat11.h
index ca77b9e491c0..f53e312374c5 100644
--- a/lib/libc/gen/fts-compat11.h
+++ b/lib/libc/gen/fts-compat11.h
@@ -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.
- *
- * @(#)fts.h 8.3 (Berkeley) 8/14/94
*/
#ifndef _FTS_COPMAT11_H_
diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3
index 04ff2ee0296a..ee558b892c8c 100644
--- a/lib/libc/gen/fts.3
+++ b/lib/libc/gen/fts.3
@@ -25,9 +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
-.\"
-.Dd January 12, 2014
+.Dd June 30, 2025
.Dt FTS 3
.Os
.Sh NAME
@@ -39,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 *
@@ -61,7 +61,9 @@ 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
@@ -178,6 +180,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.
@@ -188,6 +196,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
@@ -236,6 +246,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
@@ -382,12 +394,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
@@ -443,6 +459,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
@@ -520,6 +545,15 @@ 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_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.
.Sh FTS_READ
The
.Fn fts_read
@@ -595,9 +629,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
@@ -718,6 +756,8 @@ 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 .
The
@@ -725,29 +765,38 @@ The
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 ,
@@ -757,12 +806,12 @@ 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
@@ -790,6 +839,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 ff51d2b224c2..cce959ba836a 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -31,8 +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");
#include "namespace.h"
#include <sys/param.h>
#include <sys/mount.h>
@@ -42,6 +40,7 @@ __SCCSID("@(#)fts.c 8.6 (Berkeley) 8/14/94");
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
+#include <stdalign.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -49,6 +48,19 @@ __SCCSID("@(#)fts.c 8.6 (Berkeley) 8/14/94");
#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 *);
@@ -103,39 +115,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.
@@ -159,7 +153,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)
@@ -169,7 +165,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 {
@@ -182,7 +178,7 @@ fts_open(char * const *argv, int options,
}
}
}
- if (compar && nitems > 1)
+ if (sp->fts_compar && nitems > 1)
root = fts_sort(sp, root, nitems);
/*
@@ -215,6 +211,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)
{
@@ -266,6 +353,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;
@@ -651,14 +749,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;
@@ -785,10 +879,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) {
@@ -797,12 +889,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;
@@ -822,6 +910,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;
@@ -898,18 +1005,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) {
@@ -918,22 +1026,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)) {
@@ -978,21 +1091,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)
{
@@ -1015,7 +1113,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;
@@ -1028,44 +1137,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);
}
@@ -1145,6 +1242,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))
@@ -1157,9 +1255,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 aa9d9358aa15..28d6398f6fd8 100644
--- a/lib/libc/gen/ftw-compat11.c
+++ b/lib/libc/gen/ftw-compat11.c
@@ -22,7 +22,6 @@
* From: FreeBSD: head/lib/libc/gen/ftw.c 239151 2012-08-09 15:11:38Z jilles
*/
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/lib/libc/gen/ftw.c b/lib/libc/gen/ftw.c
index 80b45ff32f5c..35557d930bf4 100644
--- a/lib/libc/gen/ftw.c
+++ b/lib/libc/gen/ftw.c
@@ -20,7 +20,6 @@
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
diff --git a/lib/libc/gen/gen-private.h b/lib/libc/gen/gen-private.h
index 3792a61ff942..b6749b3435cd 100644
--- a/lib/libc/gen/gen-private.h
+++ b/lib/libc/gen/gen-private.h
@@ -43,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 1fffa9c9df7c..a857b3e8859e 100644
--- a/lib/libc/gen/getbootfile.3
+++ b/lib/libc/gen/getbootfile.3
@@ -25,8 +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
-.\"
.Dd September 23, 1994
.Dt GETBOOTFILE 3
.Os
diff --git a/lib/libc/gen/getbootfile.c b/lib/libc/gen/getbootfile.c
index e2c36a96378d..6250e3e2509b 100644
--- a/lib/libc/gen/getbootfile.c
+++ b/lib/libc/gen/getbootfile.c
@@ -27,11 +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>
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3
index 500968ad6db8..1d9d43fdfffb 100644
--- a/lib/libc/gen/getbsize.3
+++ b/lib/libc/gen/getbsize.3
@@ -25,8 +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
-.\"
.Dd June 11, 2017
.Dt GETBSIZE 3
.Os
diff --git a/lib/libc/gen/getbsize.c b/lib/libc/gen/getbsize.c
index 2fbcaf7b6dbd..efcabea663a0 100644
--- a/lib/libc/gen/getbsize.c
+++ b/lib/libc/gen/getbsize.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getbsize.c 8.1 (Berkeley) 6/4/93");
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3
index f736cfc3c4e9..00c7edd8026f 100644
--- a/lib/libc/gen/getcap.3
+++ b/lib/libc/gen/getcap.3
@@ -28,8 +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
-.\"
.Dd March 22, 2002
.Dt GETCAP 3
.Os
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index 9ba6cda5c280..cfb81ed0d065 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -32,8 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getcap.c 8.3 (Berkeley) 3/25/94");
#include "namespace.h"
#include <sys/types.h>
diff --git a/lib/libc/gen/getcwd.3 b/lib/libc/gen/getcwd.3
index 073838f2bf02..43d7718e92d6 100644
--- a/lib/libc/gen/getcwd.3
+++ b/lib/libc/gen/getcwd.3
@@ -25,8 +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
-.\"
.Dd April 17, 2010
.Dt GETCWD 3
.Os
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c
index c0cabacb96ba..18d8ce668274 100644
--- a/lib/libc/gen/getcwd.c
+++ b/lib/libc/gen/getcwd.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getcwd.c 8.5 (Berkeley) 2/7/95");
#include "namespace.h"
#include <sys/param.h>
#include <sys/stat.h>
@@ -42,6 +40,7 @@ __SCCSID("@(#)getcwd.c 8.5 (Berkeley) 2/7/95");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "gen-private.h"
@@ -53,7 +52,7 @@ __SCCSID("@(#)getcwd.c 8.5 (Berkeley) 2/7/95");
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 ddf7d39fd821..8de4f3976dd2 100644
--- a/lib/libc/gen/getdiskbyname.3
+++ b/lib/libc/gen/getdiskbyname.3
@@ -25,8 +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
-.\"
.Dd June 4, 1993
.Dt GETDISKBYNAME 3
.Os
diff --git a/lib/libc/gen/getdomainname.3 b/lib/libc/gen/getdomainname.3
index 94bafd6ece70..47fb139ac23c 100644
--- a/lib/libc/gen/getdomainname.3
+++ b/lib/libc/gen/getdomainname.3
@@ -25,8 +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
-.\"
.Dd May 6, 1994
.Dt GETDOMAINNAME 3
.Os
diff --git a/lib/libc/gen/getdomainname.c b/lib/libc/gen/getdomainname.c
index 70b1e460028f..c0be7465f967 100644
--- a/lib/libc/gen/getdomainname.c
+++ b/lib/libc/gen/getdomainname.c
@@ -29,15 +29,14 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)gethostname.c 8.1 (Berkeley) 6/4/93");
#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 0a3ba3e25610..5f7ee32ebbfc 100644
--- a/lib/libc/gen/getentropy.3
+++ b/lib/libc/gen/getentropy.3
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd February 24, 2018
+.Dd January 17, 2025
.Dt GETENTROPY 3
.Os
.Sh NAME
@@ -60,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 ,
@@ -69,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 44cb190f0237..6b8ad697b7e0 100644
--- a/lib/libc/gen/getentropy.c
+++ b/lib/libc/gen/getentropy.c
@@ -26,123 +26,44 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 dd2ea3417e78..4783c7469910 100644
--- a/lib/libc/gen/getfsent.3
+++ b/lib/libc/gen/getfsent.3
@@ -25,8 +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
-.\"
.Dd April 7, 2003
.Dt GETFSENT 3
.Os
diff --git a/lib/libc/gen/getgrent.3 b/lib/libc/gen/getgrent.3
index 0fba3bcd880d..e4a703f3bfad 100644
--- a/lib/libc/gen/getgrent.3
+++ b/lib/libc/gen/getgrent.3
@@ -25,8 +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
-.\"
.Dd July 31, 2016
.Dt GETGRENT 3
.Os
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index b7fe6021f9fd..508e3d63eb60 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -32,7 +32,6 @@
* SUCH DAMAGE.
*
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
#ifdef YP
diff --git a/lib/libc/gen/getgrouplist.3 b/lib/libc/gen/getgrouplist.3
index a7c478a9250c..e9a980f99751 100644
--- a/lib/libc/gen/getgrouplist.3
+++ b/lib/libc/gen/getgrouplist.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)getgrouplist.3 8.1 (Berkeley) 6/9/93
-.\"
.Dd October 26, 2014
.Dt GETGROUPLIST 3
.Os
diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c
index 6dddea5c3847..5bd06bc5121f 100644
--- a/lib/libc/gen/getgrouplist.c
+++ b/lib/libc/gen/getgrouplist.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94");
/*
* get credential
*/
@@ -39,11 +37,12 @@ __SCCSID("@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94");
#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 d9287f6c861b..99e723fa9595 100644
--- a/lib/libc/gen/gethostname.3
+++ b/lib/libc/gen/gethostname.3
@@ -25,8 +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
-.\"
.Dd July 13, 2020
.Dt GETHOSTNAME 3
.Os
diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c
index 9b0400d744e6..66d401fad846 100644
--- a/lib/libc/gen/gethostname.c
+++ b/lib/libc/gen/gethostname.c
@@ -29,16 +29,15 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)gethostname.c 8.1 (Berkeley) 6/4/93");
#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 8de0fca20b79..42a9f511c9ef 100644
--- a/lib/libc/gen/getloadavg.3
+++ b/lib/libc/gen/getloadavg.3
@@ -25,8 +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
-.\"
.Dd June 4, 1993
.Dt GETLOADAVG 3
.Os
diff --git a/lib/libc/gen/getloadavg.c b/lib/libc/gen/getloadavg.c
index 8b4844096015..4f6c23627f0e 100644
--- a/lib/libc/gen/getloadavg.c
+++ b/lib/libc/gen/getloadavg.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getloadavg.c 8.1 (Berkeley) 6/4/93");
#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 c2c8e24b070e..f8a3fb079067 100644
--- a/lib/libc/gen/getlogin.c
+++ b/lib/libc/gen/getlogin.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getlogin.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include <errno.h>
#include <pwd.h>
@@ -39,6 +37,7 @@ __SCCSID("@(#)getlogin.c 8.1 (Berkeley) 6/4/93");
#include <unistd.h>
#include "namespace.h"
#include <pthread.h>
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -56,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 317be508eda2..d5c308b387a0 100644
--- a/lib/libc/gen/getmntinfo-compat11.c
+++ b/lib/libc/gen/getmntinfo-compat11.c
@@ -25,11 +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>
#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 a136bd34175a..2bbe436078d6 100644
--- a/lib/libc/gen/getmntinfo.3
+++ b/lib/libc/gen/getmntinfo.3
@@ -25,8 +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
-.\"
.Dd December 27, 2016
.Dt GETMNTINFO 3
.Os
diff --git a/lib/libc/gen/getmntinfo.c b/lib/libc/gen/getmntinfo.c
index 8b374887f358..3c224ef27d76 100644
--- a/lib/libc/gen/getmntinfo.c
+++ b/lib/libc/gen/getmntinfo.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93");
#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 653187d2a401..be2e3cd1cdd5 100644
--- a/lib/libc/gen/getnetgrent.3
+++ b/lib/libc/gen/getnetgrent.3
@@ -25,8 +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
-.\"
.Dd June 5, 2016
.Dt GETNETGRENT 3
.Os
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index baa852076c12..7c92bc2ce9a9 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -32,8 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getnetgrent.c 8.2 (Berkeley) 4/27/95");
#include "namespace.h"
#include <ctype.h>
diff --git a/lib/libc/gen/getosreldate.c b/lib/libc/gen/getosreldate.c
index ce80c099f581..edd978973ade 100644
--- a/lib/libc/gen/getosreldate.c
+++ b/lib/libc/gen/getosreldate.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)gethostid.c 8.1 (Berkeley) 6/2/93");
#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 5a40c2b2c2a5..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
-.\"
-.Dd October 17, 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 getpagesizes 3 ,
-.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 94e579c987c9..000000000000
--- a/lib/libc/gen/getpagesize.c
+++ /dev/null
@@ -1,73 +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");
-#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 e00a1be7c550..000000000000
--- a/lib/libc/gen/getpagesizes.3
+++ /dev/null
@@ -1,97 +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.
-.\"
-.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 2cb4ebee0d0e..000000000000
--- a/lib/libc/gen/getpagesizes.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * 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>
-#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 bad4c7f75dea..c88e072e1900 100644
--- a/lib/libc/gen/getpass.3
+++ b/lib/libc/gen/getpass.3
@@ -25,8 +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
-.\"
.Dd June 4, 1993
.Dt GETPASS 3
.Os
diff --git a/lib/libc/gen/getpeereid.3 b/lib/libc/gen/getpeereid.3
index 204dec041d8f..8e3b763f716a 100644
--- a/lib/libc/gen/getpeereid.3
+++ b/lib/libc/gen/getpeereid.3
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd November 28, 2022
+.Dd November 16, 2023
.Dt GETPEEREID 3
.Os
.Sh NAME
@@ -44,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 b1934a6c471b..444dd2664cc4 100644
--- a/lib/libc/gen/getpeereid.c
+++ b/lib/libc/gen/getpeereid.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c
index 5b563534616b..54e59b6ac412 100644
--- a/lib/libc/gen/getprogname.c
+++ b/lib/libc/gen/getprogname.c
@@ -1,4 +1,3 @@
-#include <sys/cdefs.h>
#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 93578dd85ee9..486f0cab2399 100644
--- a/lib/libc/gen/getpwent.3
+++ b/lib/libc/gen/getpwent.3
@@ -25,8 +25,6 @@
.\" 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
-.\"
.Dd November 28, 2022
.Dt GETPWENT 3
.Os
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index e3c8098fad0d..1cbf97e7eb52 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -32,7 +32,6 @@
* SUCH DAMAGE.
*
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
#ifdef YP
diff --git a/lib/libc/gen/getttyent.3 b/lib/libc/gen/getttyent.3
index eb1c3d2ef8c5..bf38f417ac58 100644
--- a/lib/libc/gen/getttyent.3
+++ b/lib/libc/gen/getttyent.3
@@ -25,8 +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
-.\"
.Dd November 17, 1996
.Dt GETTTYENT 3
.Os
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c
index df19fb18ee81..3c92f603ff06 100644
--- a/lib/libc/gen/getttyent.c
+++ b/lib/libc/gen/getttyent.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)getttyent.c 8.1 (Berkeley) 6/4/93");
#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 f186d9448163..728e87c9d56a 100644
--- a/lib/libc/gen/getusershell.3
+++ b/lib/libc/gen/getusershell.3
@@ -27,8 +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
-.\"
.Dd January 16, 1999
.Dt GETUSERSHELL 3
.Os
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c
index c460cf4d4bd2..26c6e326e94d 100644
--- a/lib/libc/gen/getusershell.c
+++ b/lib/libc/gen/getusershell.c
@@ -30,8 +30,8 @@
*/
#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 $");
+
#include "namespace.h"
#include <sys/param.h>
#include <sys/file.h>
diff --git a/lib/libc/gen/getutxent.c b/lib/libc/gen/getutxent.c
index 94a20592c1bb..d0c307538930 100644
--- a/lib/libc/gen/getutxent.c
+++ b/lib/libc/gen/getutxent.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 9365d043a1fc..23036429b27e 100644
--- a/lib/libc/gen/getvfsbyname.3
+++ b/lib/libc/gen/getvfsbyname.3
@@ -25,8 +25,6 @@
.\" 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
-.\"
.Dd August 16, 2018
.Dt GETVFSBYNAME 3
.Os
diff --git a/lib/libc/gen/getvfsbyname.c b/lib/libc/gen/getvfsbyname.c
index 05efe8f8cd5e..18cbf64b9f4a 100644
--- a/lib/libc/gen/getvfsbyname.c
+++ b/lib/libc/gen/getvfsbyname.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)kvm_getvfsbyname.c 8.1 (Berkeley) 4/3/95");
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
@@ -40,7 +38,7 @@ __SCCSID("@(#)kvm_getvfsbyname.c 8.1 (Berkeley) 4/3/95");
#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 8fb45210b775..cdae52056f61 100644
--- a/lib/libc/gen/glob-compat11.c
+++ b/lib/libc/gen/glob-compat11.c
@@ -33,12 +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>
#include <sys/param.h>
#define _WANT_FREEBSD11_STAT
#include <sys/stat.h>
diff --git a/lib/libc/gen/glob-compat11.h b/lib/libc/gen/glob-compat11.h
index 720f3fab36f9..713e1a454b7f 100644
--- a/lib/libc/gen/glob-compat11.h
+++ b/lib/libc/gen/glob-compat11.h
@@ -28,14 +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
*/
#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 ea72558786f0..839d98ce02b5 100644
--- a/lib/libc/gen/glob.3
+++ b/lib/libc/gen/glob.3
@@ -27,13 +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
-.\"
-.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
@@ -41,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
@@ -274,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
@@ -309,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
@@ -326,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
@@ -354,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
@@ -399,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 ,
@@ -437,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
@@ -444,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 dbb6389d707e..f7da5f0cda09 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -37,8 +37,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)glob.c 8.3 (Berkeley) 10/13/93");
/*
* glob(3) -- a superset of the one defined in POSIX 1003.2.
*
@@ -90,8 +88,11 @@ __SCCSID("@(#)glob.c 8.3 (Berkeley) 10/13/93");
#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
@@ -106,8 +107,8 @@ __SCCSID("@(#)glob.c 8.3 (Berkeley) 10/13/93");
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;
};
@@ -181,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;
@@ -194,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);
@@ -252,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;
@@ -726,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);
@@ -1087,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 a44641a63828..03bd07494fc9 100644
--- a/lib/libc/gen/initgroups.3
+++ b/lib/libc/gen/initgroups.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)initgroups.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd October 26, 2014
.Dt INITGROUPS 3
.Os
diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c
index 6e417d6a62ed..b6697dd7ed8f 100644
--- a/lib/libc/gen/initgroups.c
+++ b/lib/libc/gen/initgroups.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)initgroups.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include "namespace.h"
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 60e94e0ba524..8844f3121538 100644
--- a/lib/libc/gen/isatty.c
+++ b/lib/libc/gen/isatty.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)isatty.c 8.1 (Berkeley) 6/4/93");
#include <termios.h>
#include <unistd.h>
diff --git a/lib/libc/gen/jrand48.c b/lib/libc/gen/jrand48.c
index 5fdd1778c340..0a9f780a9e5c 100644
--- a/lib/libc/gen/jrand48.c
+++ b/lib/libc/gen/jrand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include <stdint.h>
#include "rand48.h"
diff --git a/lib/libc/gen/lcong48.c b/lib/libc/gen/lcong48.c
index b77278db1750..f13826b3d3f3 100644
--- a/lib/libc/gen/lcong48.c
+++ b/lib/libc/gen/lcong48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
extern unsigned short _rand48_seed[3];
diff --git a/lib/libc/gen/ldexp.3 b/lib/libc/gen/ldexp.3
index 5158911fa99c..d89dea2d16c7 100644
--- a/lib/libc/gen/ldexp.3
+++ b/lib/libc/gen/ldexp.3
@@ -29,8 +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
-.\"
.Dd March 4, 2005
.Dt LDEXP 3
.Os
diff --git a/lib/libc/gen/ldexp.c b/lib/libc/gen/ldexp.c
index 5055add84ff3..1db62afc609e 100644
--- a/lib/libc/gen/ldexp.c
+++ b/lib/libc/gen/ldexp.c
@@ -1,4 +1,3 @@
-#include <sys/cdefs.h>
/*
* 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 bc7e13ca0043..4e5ec2961ac2 100644
--- a/lib/libc/gen/libc_dlopen.c
+++ b/lib/libc/gen/libc_dlopen.c
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 72b551792741..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,36 +29,27 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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);
- }
+#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
- /* Save sent bytes. */
- msgvec[i].msg_len = ret;
- }
-
- 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 bfd5719dee11..000000000000
--- a/lib/libc/gen/lockf.3
+++ /dev/null
@@ -1,264 +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.
-.\"
-.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 247066706a2b..000000000000
--- a/lib/libc/gen/lockf.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* $NetBSD: lockf.c,v 1.3 2008/04/28 20:22:59 martin Exp $ */
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * 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>
-#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 d7257febe717..a3d0111cf4d5 100644
--- a/lib/libc/gen/lrand48.c
+++ b/lib/libc/gen/lrand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
extern unsigned short _rand48_seed[3];
diff --git a/lib/libc/gen/makecontext.3 b/lib/libc/gen/makecontext.3
index bcf836979962..198c541d40a6 100644
--- a/lib/libc/gen/makecontext.3
+++ b/lib/libc/gen/makecontext.3
@@ -152,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 af64c998dbd4..269a5bc829b1 100644
--- a/lib/libc/gen/memalign.c
+++ b/lib/libc/gen/memalign.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <stdlib.h>
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 6d6ff16e236c..9d698ff62ce6 100644
--- a/lib/libc/gen/modf.3
+++ b/lib/libc/gen/modf.3
@@ -29,8 +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
-.\"
.Dd March 29, 2008
.Dt MODF 3
.Os
diff --git a/lib/libc/gen/modf.c b/lib/libc/gen/modf.c
index 6853a56d051d..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,7 +9,6 @@
* ====================================================
*/
-#include <sys/cdefs.h>
/*
* 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 6ee078e95c81..15b0bfb1bd6e 100644
--- a/lib/libc/gen/mrand48.c
+++ b/lib/libc/gen/mrand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include <stdint.h>
#include "rand48.h"
diff --git a/lib/libc/gen/nftw-compat11.c b/lib/libc/gen/nftw-compat11.c
index fdd5c9a707a4..36970424bf2a 100644
--- a/lib/libc/gen/nftw-compat11.c
+++ b/lib/libc/gen/nftw-compat11.c
@@ -21,7 +21,6 @@
* From: FreeBSD: head/lib/libc/gen/nftw.c 239160 2012-08-09 22:05:40Z jilles
*/
-#include <sys/cdefs.h>
#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 9b5c33e1057c..95cc9947b7c1 100644
--- a/lib/libc/gen/nftw.c
+++ b/lib/libc/gen/nftw.c
@@ -20,7 +20,6 @@
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
-#include <sys/cdefs.h>
#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 ff82610c34ec..011b4c33effc 100644
--- a/lib/libc/gen/nice.3
+++ b/lib/libc/gen/nice.3
@@ -25,8 +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
-.\"
.Dd February 28, 2015
.Dt NICE 3
.Os
diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c
index b71076efdcde..a96d4d06e081 100644
--- a/lib/libc/gen/nice.c
+++ b/lib/libc/gen/nice.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)nice.c 8.1 (Berkeley) 6/4/93");
#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 ef5b8d95282e..f4ef59083dab 100644
--- a/lib/libc/gen/nlist.3
+++ b/lib/libc/gen/nlist.3
@@ -25,8 +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
-.\"
.Dd April 19, 1994
.Dt NLIST 3
.Os
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index 0e00d8d23f99..ebf4ae92641a 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)nlist.c 8.1 (Berkeley) 6/4/93");
#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 12016ed76ec9..6c54065e7e0f 100644
--- a/lib/libc/gen/nrand48.c
+++ b/lib/libc/gen/nrand48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
long
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index a3864b0939fc..08d9eb10eaa2 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -29,24 +29,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)opendir.c 8.8 (Berkeley) 5/1/95");
#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.
*/
@@ -54,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 79d2b7455738..6b17ae10777d 100644
--- a/lib/libc/gen/pause.3
+++ b/lib/libc/gen/pause.3
@@ -25,8 +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
-.\"
.Dd April 3, 2022
.Dt PAUSE 3
.Os
diff --git a/lib/libc/gen/pause.c b/lib/libc/gen/pause.c
index ce255dbba6b2..38aed9da7439 100644
--- a/lib/libc/gen/pause.c
+++ b/lib/libc/gen/pause.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)pause.c 8.1 (Berkeley) 6/4/93");
#include <signal.h>
#include <unistd.h>
diff --git a/lib/libc/gen/pmadvise.c b/lib/libc/gen/pmadvise.c
index ac4f858d09c9..19525c939c26 100644
--- a/lib/libc/gen/pmadvise.c
+++ b/lib/libc/gen/pmadvise.c
@@ -4,7 +4,6 @@
*
*/
-#include <sys/cdefs.h>
#include <sys/mman.h>
#include <errno.h>
diff --git a/lib/libc/gen/popen.3 b/lib/libc/gen/popen.3
index 4fdff3172db4..bae37eed14cf 100644
--- a/lib/libc/gen/popen.3
+++ b/lib/libc/gen/popen.3
@@ -25,8 +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
-.\"
.Dd May 20, 2013
.Dt POPEN 3
.Os
diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c
index 1531ca462c24..db6b91d08af6 100644
--- a/lib/libc/gen/popen.c
+++ b/lib/libc/gen/popen.c
@@ -32,8 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)popen.c 8.3 (Berkeley) 5/3/95");
#include "namespace.h"
#include <sys/param.h>
#include <sys/queue.h>
diff --git a/lib/libc/gen/posix_spawn.3 b/lib/libc/gen/posix_spawn.3
index a9ff7b2b21da..278fee88463a 100644
--- a/lib/libc/gen/posix_spawn.3
+++ b/lib/libc/gen/posix_spawn.3
@@ -32,7 +32,7 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.Dd November 28, 2021
+.Dd March 4, 2024
.Dt POSIX_SPAWN 3
.Os
.Sh NAME
@@ -297,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.
@@ -432,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 77f7dd9955cd..a5b732696b8c 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -26,9 +26,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
+#include <sys/procctl.h>
#include <sys/queue.h>
#include <sys/wait.h>
@@ -92,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
@@ -140,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);
}
@@ -227,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
@@ -254,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;
@@ -318,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.
*/
@@ -630,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 ef6348daa4ba..80bc91454471 100644
--- a/lib/libc/gen/posix_spawn_file_actions_addopen.3
+++ b/lib/libc/gen/posix_spawn_file_actions_addopen.3
@@ -270,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_spawnattr_getflags.3 b/lib/libc/gen/posix_spawnattr_getflags.3
index 9a468cbb8b0f..308bbb386d76 100644
--- a/lib/libc/gen/posix_spawnattr_getflags.3
+++ b/lib/libc/gen/posix_spawnattr_getflags.3
@@ -32,7 +32,7 @@
.\" the referee document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
-.Dd March 24, 2008
+.Dd March 4, 2024
.Dt POSIX_SPAWNATTR_GETFLAGS 3
.Os
.Sh NAME
@@ -75,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
@@ -83,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/psignal.3 b/lib/libc/gen/psignal.3
index 0fc63418d3f3..098b7b02a9b9 100644
--- a/lib/libc/gen/psignal.3
+++ b/lib/libc/gen/psignal.3
@@ -25,16 +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
-.\"
-.Dd May 30, 2016
+.Dd May 10, 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
@@ -42,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
@@ -81,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 ,
@@ -97,12 +114,65 @@ 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 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 f8caf7621e83..291a6a9337a0 100644
--- a/lib/libc/gen/psignal.c
+++ b/lib/libc/gen/psignal.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)psignal.c 8.1 (Berkeley) 6/4/93");
/*
* Print the name of the signal indicated
* along with the supplied message.
@@ -57,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 36f987ee7ae7..15df7b5f6783 100644
--- a/lib/libc/gen/pututxline.c
+++ b/lib/libc/gen/pututxline.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 01ddc57a0d8c..35072d7c1b59 100644
--- a/lib/libc/gen/pw_scan.c
+++ b/lib/libc/gen/pw_scan.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)pw_scan.c 8.3 (Berkeley) 4/2/94");
/*
* 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 d3e33454195e..63457a382821 100644
--- a/lib/libc/gen/pw_scan.h
+++ b/lib/libc/gen/pw_scan.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.
- *
- * @(#)pw_scan.h 8.1 (Berkeley) 4/1/94
*/
#define _PWSCAN_MASTER 0x01
diff --git a/lib/libc/gen/raise.3 b/lib/libc/gen/raise.3
index 87319bb30329..c74777e7faa9 100644
--- a/lib/libc/gen/raise.3
+++ b/lib/libc/gen/raise.3
@@ -29,8 +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
-.\"
.Dd May 7, 2010
.Dt RAISE 3
.Os
diff --git a/lib/libc/gen/raise.c b/lib/libc/gen/raise.c
index 4cb596d49bc9..9829de18dcdc 100644
--- a/lib/libc/gen/raise.c
+++ b/lib/libc/gen/raise.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)raise.c 8.1 (Berkeley) 6/4/93");
#include <signal.h>
#include <unistd.h>
diff --git a/lib/libc/gen/rand48.3 b/lib/libc/gen/rand48.3
index d4a14b88ebee..1e47c843058e 100644
--- a/lib/libc/gen/rand48.3
+++ b/lib/libc/gen/rand48.3
@@ -9,8 +9,6 @@
.\" 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
-.\"
.Dd September 4, 2012
.Dt RAND48 3
.Os
diff --git a/lib/libc/gen/readdir-compat11.c b/lib/libc/gen/readdir-compat11.c
index 30cec5acd0e6..606e15bd7b36 100644
--- a/lib/libc/gen/readdir-compat11.c
+++ b/lib/libc/gen/readdir-compat11.c
@@ -25,12 +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>
#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 d2c8636651ff..94d2b2e8d877 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)readdir.c 8.3 (Berkeley) 9/29/94");
#include "namespace.h"
#include <sys/param.h>
#include <dirent.h>
@@ -50,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) {
@@ -63,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;
@@ -133,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.c b/lib/libc/gen/readpassphrase.c
index c6eb63f1469c..5319d3e634af 100644
--- a/lib/libc/gen/readpassphrase.c
+++ b/lib/libc/gen/readpassphrase.c
@@ -21,7 +21,6 @@
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
-#include <sys/cdefs.h>
#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 6fa400f00c22..000000000000
--- a/lib/libc/gen/recvmmsg.c
+++ /dev/null
@@ -1,95 +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>
-#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 bc072d2826ea..df829e98d138 100644
--- a/lib/libc/gen/rewinddir.c
+++ b/lib/libc/gen/rewinddir.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)rewinddir.c 8.1 (Berkeley) 6/8/93");
#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 0ade53b8afb6..000000000000
--- a/lib/libc/gen/rfork_thread.3
+++ /dev/null
@@ -1,85 +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.
-.\"
-.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 b5c9846c2798..96c9b1052b48 100644
--- a/lib/libc/gen/scandir-compat11.c
+++ b/lib/libc/gen/scandir-compat11.c
@@ -25,12 +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>
/*
* Scan the directory dirname calling select to make a list of selected
* directory entries then sort using qsort and compare routine dcomp.
diff --git a/lib/libc/gen/scandir.3 b/lib/libc/gen/scandir.3
index 033042acbb05..3da4500cefb9 100644
--- a/lib/libc/gen/scandir.3
+++ b/lib/libc/gen/scandir.3
@@ -25,15 +25,16 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)scandir.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd August 31, 2023
+.Dd June 25, 2025
.Dt SCANDIR 3
.Os
.Sh NAME
.Nm scandir ,
+.Nm fdscandir ,
.Nm scandirat ,
.Nm scandir_b ,
+.Nm fdscandir_b ,
+.Nm fdscandirat_b ,
.Nm alphasort ,
.Nm versionsort
.Nd scan a directory
@@ -49,6 +50,13 @@
.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"
@@ -64,6 +72,21 @@
.Fa "int \*(lp^compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp"
.Fc
.Ft int
+.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"
@@ -79,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
@@ -120,6 +144,13 @@ The memory allocated for the array can be deallocated with
by freeing each pointer in the array and then the array itself.
.Pp
The
+.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 ,
@@ -153,17 +184,67 @@ See
for additional details.
.Pp
The
-.Fn scandir_b
-function behaves in the same way as
+.Fn scandir_b ,
+.Fn fdscandir_b ,
+and
+.Fn scandirat_b
+functions behave in the same way as
.Fn scandir ,
-but takes blocks as arguments instead of function pointers and calls
+.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 ,
@@ -174,8 +255,25 @@ cannot allocate enough memory to hold all the data structures.
.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
-function is a GNU extension and conforms to no standard.
+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
@@ -184,8 +282,19 @@ and
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 28565150a035..fb589f4b36b6 100644
--- a/lib/libc/gen/scandir.c
+++ b/lib/libc/gen/scandir.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)scandir.c 8.3 (Berkeley) 1/2/94");
/*
* Scan the directory dirname calling select to make a list of selected
* directory entries then sort using qsort and compare routine dcomp.
@@ -40,6 +38,7 @@ __SCCSID("@(#)scandir.c 8.3 (Berkeley) 1/2/94");
#include "namespace.h"
#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
@@ -66,71 +65,76 @@ static int scandir_thunk_cmp(const void *p1, const void *p2, void *thunk);
static int
#ifdef I_AM_SCANDIR_B
-scandir_b_dirp(DIR *dirp, struct dirent ***namelist, select_block select,
+scandir_dirp_b(DIR *dirp, struct dirent ***namelist, select_block select,
dcomp_block dcomp)
#else
scandir_dirp(DIR *dirp, struct dirent ***namelist,
- int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
- const struct dirent **))
+ int (*select)(const struct dirent *),
+ int (*dcomp)(const struct dirent **, const struct dirent **))
#endif
{
- struct dirent *d, *p, **names = NULL;
- size_t arraysz, numitems;
+ struct dirent *d, *p = NULL, **names = NULL, **names2;
+ size_t arraysz = 32, numitems = 0;
+ int serrno;
- 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 *),
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);
}
@@ -140,44 +144,87 @@ 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 **))
+ 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);
- return (
+ ret =
#ifdef I_AM_SCANDIR_B
- scandir_b_dirp
+ scandir_dirp_b
#else
scandir_dirp
#endif
- (dirp, namelist, select, dcomp));
+ (dirp, namelist, select, dcomp);
+ serrno = errno;
+ closedir(dirp);
+ errno = serrno;
+ return (ret);
}
-#ifndef I_AM_SCANDIR_B
int
-scandirat(int dirfd, const char *dirname, struct dirent ***namelist,
- int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
- const struct dirent **))
+#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 fd;
+ 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);
- dirp = fdopendir(fd);
- if (dirp == NULL) {
- _close(fd);
- return (-1);
- }
- return (scandir_dirp(dirp, namelist, select, dcomp));
+ 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.
* POSIX 2008 requires that alphasort() uses strcoll().
diff --git a/lib/libc/gen/seed48.c b/lib/libc/gen/seed48.c
index 230348ff0fa8..258c4bac3c9f 100644
--- a/lib/libc/gen/seed48.c
+++ b/lib/libc/gen/seed48.c
@@ -11,7 +11,6 @@
* to anyone/anything when using this software.
*/
-#include <sys/cdefs.h>
#include "rand48.h"
extern unsigned short _rand48_seed[3];
diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c
index 8c88bdbf4ab5..c796aa7e3550 100644
--- a/lib/libc/gen/seekdir.c
+++ b/lib/libc/gen/seekdir.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)seekdir.c 8.1 (Berkeley) 6/4/93");
#include "namespace.h"
#include <sys/param.h>
#include <dirent.h>
diff --git a/lib/libc/gen/semctl.c b/lib/libc/gen/semctl.c
index 84df40e4c9af..374f01508236 100644
--- a/lib/libc/gen/semctl.c
+++ b/lib/libc/gen/semctl.c
@@ -28,7 +28,6 @@
*/
-#include <sys/cdefs.h>
#ifndef NO_COMPAT7
#define _WANT_SEMUN_OLD
#endif
diff --git a/lib/libc/gen/setdomainname.c b/lib/libc/gen/setdomainname.c
index b7d96ed8cdef..c40b7a393e3b 100644
--- a/lib/libc/gen/setdomainname.c
+++ b/lib/libc/gen/setdomainname.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sethostname.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/sethostname.c b/lib/libc/gen/sethostname.c
index b1ba640d3348..eeb3ec5cc6db 100644
--- a/lib/libc/gen/sethostname.c
+++ b/lib/libc/gen/sethostname.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sethostname.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/setjmp.3 b/lib/libc/gen/setjmp.3
index 70b46f47cb2b..e7c52473dbc9 100644
--- a/lib/libc/gen/setjmp.3
+++ b/lib/libc/gen/setjmp.3
@@ -29,8 +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
-.\"
.Dd April 2, 2022
.Dt SETJMP 3
.Os
diff --git a/lib/libc/gen/setjmperr.c b/lib/libc/gen/setjmperr.c
index 7532070c9f53..1ba722c30146 100644
--- a/lib/libc/gen/setjmperr.c
+++ b/lib/libc/gen/setjmperr.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)setjmperr.c 8.1 (Berkeley) 6/4/93");
/*
* 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 1a3ce2539ae8..a5dd05a5e7c6 100644
--- a/lib/libc/gen/setmode.3
+++ b/lib/libc/gen/setmode.3
@@ -25,8 +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
-.\"
.Dd July 18, 2019
.Dt SETMODE 3
.Os
diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c
index 823fcbd182bb..8d7ba905067f 100644
--- a/lib/libc/gen/setmode.c
+++ b/lib/libc/gen/setmode.c
@@ -32,8 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)setmode.c 8.2 (Berkeley) 3/25/94");
#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 15bafa23a982..087cbe4b84e9 100644
--- a/lib/libc/gen/setproctitle.3
+++ b/lib/libc/gen/setproctitle.3
@@ -74,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 9c73fd77ca42..715951a8c96d 100644
--- a/lib/libc/gen/setproctitle.c
+++ b/lib/libc/gen/setproctitle.c
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 849ff9188d47..853c5f277386 100644
--- a/lib/libc/gen/setprogname.c
+++ b/lib/libc/gen/setprogname.c
@@ -1,4 +1,3 @@
-#include <sys/cdefs.h>
#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 74e408c5fef9..4e286f28df7c 100644
--- a/lib/libc/gen/siginterrupt.3
+++ b/lib/libc/gen/siginterrupt.3
@@ -25,8 +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
-.\"
.Dd June 4, 1993
.Dt SIGINTERRUPT 3
.Os
diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c
index da010ca923fe..0a05e89982dc 100644
--- a/lib/libc/gen/siginterrupt.c
+++ b/lib/libc/gen/siginterrupt.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93");
#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 7af7e0ef5652..c1d0a8d425e1 100644
--- a/lib/libc/gen/siglist.c
+++ b/lib/libc/gen/siglist.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)siglist.c 8.1 (Berkeley) 6/4/93");
#include <signal.h>
const char *const sys_signame[NSIG] = {
diff --git a/lib/libc/gen/signal.3 b/lib/libc/gen/signal.3
index c71bf00d9e30..56e77325eed8 100644
--- a/lib/libc/gen/signal.3
+++ b/lib/libc/gen/signal.3
@@ -25,8 +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
-.\"
.Dd December 1, 2017
.Dt SIGNAL 3
.Os
diff --git a/lib/libc/gen/signal.c b/lib/libc/gen/signal.c
index 17fb057b2ced..dce06bba3678 100644
--- a/lib/libc/gen/signal.c
+++ b/lib/libc/gen/signal.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)signal.c 8.1 (Berkeley) 6/4/93");
/*
* Almost backwards compatible signal.
*/
diff --git a/lib/libc/gen/sigsetops.3 b/lib/libc/gen/sigsetops.3
index 7585cbedff18..109b1d9d4a8c 100644
--- a/lib/libc/gen/sigsetops.3
+++ b/lib/libc/gen/sigsetops.3
@@ -25,8 +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
-.\"
.Dd October 29, 2019
.Dt SIGSETOPS 3
.Os
diff --git a/lib/libc/gen/sigsetops.c b/lib/libc/gen/sigsetops.c
index 7050fa1607c1..3e22b0dba5e9 100644
--- a/lib/libc/gen/sigsetops.c
+++ b/lib/libc/gen/sigsetops.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sigsetops.c 8.1 (Berkeley) 6/4/93");
#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 549cd68257d3..000000000000
--- a/lib/libc/gen/sleep.3
+++ /dev/null
@@ -1,82 +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
-.\"
-.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 e73496854736..e32d434d4d33 100644
--- a/lib/libc/gen/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sleep.c 8.1 (Berkeley) 6/4/93");
#include "namespace.h"
#include <errno.h>
#include <limits.h>
@@ -57,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/statvfs.c b/lib/libc/gen/statvfs.c
index a7190f9a707d..94c61f0cd73d 100644
--- a/lib/libc/gen/statvfs.c
+++ b/lib/libc/gen/statvfs.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/param.h>
#include <sys/mount.h>
diff --git a/lib/libc/gen/strtofflags.3 b/lib/libc/gen/strtofflags.3
index dfeea2d7e018..0cf996275480 100644
--- a/lib/libc/gen/strtofflags.3
+++ b/lib/libc/gen/strtofflags.3
@@ -25,8 +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
-.\"
.Dd January 1, 2000
.Dt STRTOFFLAGS 3
.Os
diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c
index 09a811c37a80..73b4db54ccdd 100644
--- a/lib/libc/gen/strtofflags.c
+++ b/lib/libc/gen/strtofflags.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)stat_flags.c 8.1 (Berkeley) 5/31/93");
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3
index 56d4c0bc5aa6..e38357b898a7 100644
--- a/lib/libc/gen/sysconf.3
+++ b/lib/libc/gen/sysconf.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94
-.\"
.Dd April 26, 2013
.Dt SYSCONF 3
.Os
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 54f9526d3955..66562d0e29f0 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -32,10 +32,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sysconf.c 8.2 (Berkeley) 3/20/94");
#include "namespace.h"
#include <sys/param.h>
+#include <sys/exterrvar.h>
#include <sys/time.h>
#include <sys/sysctl.h>
#include <sys/resource.h>
@@ -52,7 +51,7 @@ __SCCSID("@(#)sysconf.c 8.2 (Berkeley) 3/20/94");
#include "un-namespace.h"
#include "../stdlib/atexit.h"
-#include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */
+#include "tzdir.h" /* from ../../../contrib/tzcode/stdtime */
#include "libc_private.h"
#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
@@ -288,6 +287,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:
@@ -569,7 +570,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);
@@ -604,6 +605,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 c2d43cc4e49c..ef897c653728 100644
--- a/lib/libc/gen/sysctl.3
+++ b/lib/libc/gen/sysctl.3
@@ -25,9 +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
-.\"
-.Dd March 16, 2023
+.Dd July 31, 2025
.Dt SYSCTL 3
.Os
.Sh NAME
@@ -327,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
@@ -334,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
@@ -348,16 +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_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
.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
@@ -382,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
@@ -392,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
@@ -448,41 +477,140 @@ 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
+.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
+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
-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"
+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.
.El
@@ -825,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 5586b78b26b9..d6fadd3c3e5c 100644
--- a/lib/libc/gen/sysctl.c
+++ b/lib/libc/gen/sysctl.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)sysctl.c 8.2 (Berkeley) 1/4/94");
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c
index 017dba86c11a..8cc9599f7a95 100644
--- a/lib/libc/gen/sysctlbyname.c
+++ b/lib/libc/gen/sysctlbyname.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 d2e33f5690ff..e45d23e10714 100644
--- a/lib/libc/gen/sysctlnametomib.c
+++ b/lib/libc/gen/sysctlnametomib.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 017a9092e625..62140554f4f5 100644
--- a/lib/libc/gen/syslog.3
+++ b/lib/libc/gen/syslog.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)syslog.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd July 3, 2023
.Dt SYSLOG 3
.Os
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c
index a9a87943da8b..a6290ee81a29 100644
--- a/lib/libc/gen/syslog.c
+++ b/lib/libc/gen/syslog.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)syslog.c 8.5 (Berkeley) 4/29/95");
#include "namespace.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/lib/libc/gen/tcgetpgrp.3 b/lib/libc/gen/tcgetpgrp.3
index 02a6ac51867c..2c9bd2983e06 100644
--- a/lib/libc/gen/tcgetpgrp.3
+++ b/lib/libc/gen/tcgetpgrp.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tcgetpgrp.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd November 28, 2022
.Dt TCGETPGRP 3
.Os
diff --git a/lib/libc/gen/tcsendbreak.3 b/lib/libc/gen/tcsendbreak.3
index a84148c59319..0eb132e22e8c 100644
--- a/lib/libc/gen/tcsendbreak.3
+++ b/lib/libc/gen/tcsendbreak.3
@@ -25,8 +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
-.\"
.Dd January 11, 2017
.Dt TCSENDBREAK 3
.Os
diff --git a/lib/libc/gen/tcsetattr.3 b/lib/libc/gen/tcsetattr.3
index 9564d9e9c223..6afa90af556b 100644
--- a/lib/libc/gen/tcsetattr.3
+++ b/lib/libc/gen/tcsetattr.3
@@ -25,8 +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
-.\"
.Dd July 15, 2020
.Dt TCSETATTR 3
.Os
diff --git a/lib/libc/gen/tcsetpgrp.3 b/lib/libc/gen/tcsetpgrp.3
index 10af071d2b77..4ae67d4520bf 100644
--- a/lib/libc/gen/tcsetpgrp.3
+++ b/lib/libc/gen/tcsetpgrp.3
@@ -25,8 +25,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)tcsetpgrp.3 8.1 (Berkeley) 6/4/93
-.\"
.Dd November 28, 2022
.Dt TCSETPGRP 3
.Os
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index 9b60093ac472..1731cc4d7a2c 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)telldir.c 8.1 (Berkeley) 6/4/93");
#include "namespace.h"
#include <sys/param.h>
#include <sys/queue.h>
@@ -120,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;
@@ -173,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 aafa6ac71b1e..02fd52af9060 100644
--- a/lib/libc/gen/telldir.h
+++ b/lib/libc/gen/telldir.h
@@ -46,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__
@@ -102,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 8f3a89188fb0..2178cc7c419d 100644
--- a/lib/libc/gen/termios.c
+++ b/lib/libc/gen/termios.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)termios.c 8.2 (Berkeley) 2/21/94");
#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 0499493a2fa0..6df74df2dcb4 100644
--- a/lib/libc/gen/time.3
+++ b/lib/libc/gen/time.3
@@ -29,8 +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
-.\"
.Dd April 14, 2022
.Dt TIME 3
.Os
diff --git a/lib/libc/gen/time.c b/lib/libc/gen/time.c
index b46d90a11999..3f26c937d15b 100644
--- a/lib/libc/gen/time.c
+++ b/lib/libc/gen/time.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)time.c 8.1 (Berkeley) 6/4/93");
#include <sys/types.h>
#include <sys/time.h>
diff --git a/lib/libc/gen/times.3 b/lib/libc/gen/times.3
index 75b8d1957ba9..71449767b551 100644
--- a/lib/libc/gen/times.3
+++ b/lib/libc/gen/times.3
@@ -25,8 +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
-.\"
.Dd December 1, 2008
.Dt TIMES 3
.Os
diff --git a/lib/libc/gen/times.c b/lib/libc/gen/times.c
index e357162dcb30..b609faedc7a1 100644
--- a/lib/libc/gen/times.c
+++ b/lib/libc/gen/times.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)times.c 8.1 (Berkeley) 6/4/93");
#include <sys/param.h>
#include <sys/time.h>
#include <sys/times.h>
diff --git a/lib/libc/gen/timezone.3 b/lib/libc/gen/timezone.3
deleted file mode 100644
index 34041b93791d..000000000000
--- a/lib/libc/gen/timezone.3
+++ /dev/null
@@ -1,68 +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
-.\"
-.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 e0f7d4a4ae0b..2809067eb8d8 100644
--- a/lib/libc/gen/timezone.c
+++ b/lib/libc/gen/timezone.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)timezone.c 8.1 (Berkeley) 6/4/93");
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
@@ -38,7 +36,7 @@ __SCCSID("@(#)timezone.c 8.1 (Berkeley) 6/4/93");
#include <string.h>
#define TZ_MAX_CHARS 255
-char *_tztab(int, int);
+static char *_tztab(int, int);
/*
* timezone --
@@ -51,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;
@@ -70,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;
@@ -101,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 c81ef7e9ad0e..b26b13d45589 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -32,7 +32,6 @@
* runtime from ld-elf.so.1.
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <stdlib.h>
#include <string.h>
@@ -81,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__
@@ -114,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);
@@ -150,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
@@ -166,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.
*/
/*
@@ -200,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));
}
@@ -232,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;
@@ -261,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) {
@@ -270,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);
@@ -302,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
@@ -312,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);
@@ -323,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 */
@@ -385,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);
diff --git a/lib/libc/gen/trivial-getcontextx.c b/lib/libc/gen/trivial-getcontextx.c
index 512e8d17e1c4..b9d4522d96ee 100644
--- a/lib/libc/gen/trivial-getcontextx.c
+++ b/lib/libc/gen/trivial-getcontextx.c
@@ -24,7 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#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 1c672f113c86..741b25946ace 100644
--- a/lib/libc/gen/ttyname.3
+++ b/lib/libc/gen/ttyname.3
@@ -25,8 +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
-.\"
.Dd July 18, 2014
.Dt TTYNAME 3
.Os
diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c
index 95a713c6a0a5..f1e2f401fe5d 100644
--- a/lib/libc/gen/ttyname.c
+++ b/lib/libc/gen/ttyname.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)ttyname.c 8.2 (Berkeley) 1/27/94");
#include "namespace.h"
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -44,6 +42,7 @@ __SCCSID("@(#)ttyname.c 8.2 (Berkeley) 1/27/94");
#include <paths.h>
#include <errno.h>
#include "reentrant.h"
+#include <ssp/ssp.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -55,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 6a1b5960ab86..a57b18dcf030 100644
--- a/lib/libc/gen/ttyslot.c
+++ b/lib/libc/gen/ttyslot.c
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__SCCSID("@(#)ttyslot.c 8.1 (Berkeley) 6/4/93");
+
int __ttyslot(void);
int
diff --git a/lib/libc/gen/tzset.3 b/lib/libc/gen/tzset.3
deleted file mode 100644
index 723ffc55979b..000000000000
--- a/lib/libc/gen/tzset.3
+++ /dev/null
@@ -1,325 +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
-.\"
-.Dd March 6, 2023
-.Dt TZSET 3
-.Os
-.Sh NAME
-.Nm tzset
-.Nd initialize time conversion information
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In time.h
-.Ft void
-.Fn tzset 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.
-.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
-function first appeared in
-.Bx 4.4 .
diff --git a/lib/libc/gen/ualarm.3 b/lib/libc/gen/ualarm.3
index d7591fdc68e9..dfd9ddd5f434 100644
--- a/lib/libc/gen/ualarm.3
+++ b/lib/libc/gen/ualarm.3
@@ -25,8 +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
-.\"
.Dd April 19, 1994
.Dt UALARM 3
.Os
@@ -72,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 389e88d73bd1..44e77252202f 100644
--- a/lib/libc/gen/ualarm.c
+++ b/lib/libc/gen/ualarm.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)ualarm.c 8.1 (Berkeley) 6/4/93");
#include <sys/time.h>
#include <unistd.h>
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/uname.3 b/lib/libc/gen/uname.3
index 7b548923104f..ed1596529c4c 100644
--- a/lib/libc/gen/uname.3
+++ b/lib/libc/gen/uname.3
@@ -25,8 +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
-.\"
.Dd December 2, 2005
.Dt UNAME 3
.Os
diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c
index b70b3942813e..3a14ae3fefc1 100644
--- a/lib/libc/gen/uname.c
+++ b/lib/libc/gen/uname.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)uname.c 8.1 (Berkeley) 1/4/94");
#define uname wrapped_uname
#include <sys/param.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/gen/usleep.3 b/lib/libc/gen/usleep.3
deleted file mode 100644
index ec3492f2c945..000000000000
--- a/lib/libc/gen/usleep.3
+++ /dev/null
@@ -1,79 +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
-.\"
-.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 7a59c584d417..31d5567d562d 100644
--- a/lib/libc/gen/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)usleep.c 8.1 (Berkeley) 6/4/93");
#include "namespace.h"
#include <time.h>
#include <unistd.h>
@@ -47,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 f892154f693b..e17fab908497 100644
--- a/lib/libc/gen/utime.3
+++ b/lib/libc/gen/utime.3
@@ -25,8 +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
-.\"
.Dd June 9, 2016
.Dt UTIME 3
.Os
diff --git a/lib/libc/gen/utime.c b/lib/libc/gen/utime.c
index 95897b7af8f4..208c6bdae449 100644
--- a/lib/libc/gen/utime.c
+++ b/lib/libc/gen/utime.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)utime.c 8.1 (Berkeley) 6/4/93");
#include <sys/time.h>
#include <utime.h>
diff --git a/lib/libc/gen/utxdb.c b/lib/libc/gen/utxdb.c
index e831f6970295..4c4c73bffea3 100644
--- a/lib/libc/gen/utxdb.c
+++ b/lib/libc/gen/utxdb.c
@@ -26,7 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include "namespace.h"
#include <sys/endian.h>
#include <sys/param.h>
diff --git a/lib/libc/gen/valloc.3 b/lib/libc/gen/valloc.3
index bd0291988e91..063e781e3174 100644
--- a/lib/libc/gen/valloc.3
+++ b/lib/libc/gen/valloc.3
@@ -25,8 +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
-.\"
.Dd October 30, 2007
.Dt VALLOC 3
.Os
diff --git a/lib/libc/gen/valloc.c b/lib/libc/gen/valloc.c
index a68c1fc0eaf9..6f3fd2d2d10c 100644
--- a/lib/libc/gen/valloc.c
+++ b/lib/libc/gen/valloc.c
@@ -29,8 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__SCCSID("@(#)valloc.c 8.1 (Berkeley) 6/4/93");
#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 2fdeb720296d..000000000000
--- a/lib/libc/gen/wait3.c
+++ /dev/null
@@ -1,53 +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");
-#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 018f2a2c8f94..000000000000
--- a/lib/libc/gen/waitid.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * 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>
-#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 196c842c3fa1..000000000000
--- a/lib/libc/gen/waitpid.c
+++ /dev/null
@@ -1,54 +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");
-#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.c b/lib/libc/gen/wordexp.c
index 0902814eb04f..f8080c20d121 100644
--- a/lib/libc/gen/wordexp.c
+++ b/lib/libc/gen/wordexp.c
@@ -27,7 +27,6 @@
*/
#include "namespace.h"
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
@@ -266,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 */
/*