aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile3
-rw-r--r--lib/atf/Makefile.inc2
-rw-r--r--lib/atf/libatf-c++/Makefile1
-rw-r--r--lib/atf/libatf-c++/tests/detail/Makefile2
-rw-r--r--lib/atf/libatf-c/Makefile1
-rw-r--r--lib/atf/libatf-c/tests/detail/Makefile2
-rw-r--r--lib/atf/tests/Makefile3
-rw-r--r--lib/clang/freebsd_cc_version.h2
-rw-r--r--lib/clang/libllvm/Makefile10
-rw-r--r--lib/clang/llvm.build.mk4
-rw-r--r--lib/geom/Makefile.inc11
-rw-r--r--lib/geom/part/gpart.822
-rw-r--r--lib/geom/shsec/gshsec.87
-rw-r--r--lib/googletest/Makefile.inc2
-rw-r--r--lib/googletest/tests/Makefile3
-rw-r--r--lib/googletest/tests/Makefile.inc2
-rw-r--r--lib/libarchive/Makefile9
-rw-r--r--lib/libarchive/tests/Makefile9
-rw-r--r--lib/libbe/Makefile15
-rw-r--r--lib/libbe/tests/Makefile9
-rw-r--r--lib/libblacklist/Makefile7
-rw-r--r--lib/libblocklist/Makefile30
-rw-r--r--lib/libblocklist/Makefile.depend16
-rw-r--r--lib/libbluetooth/Makefile2
-rw-r--r--lib/libbsddialog/Makefile1
-rw-r--r--lib/libbsdstat/bsdstat.h2
-rw-r--r--lib/libbsm/Makefile9
-rw-r--r--lib/libbz2/Makefile17
-rw-r--r--lib/libbz2/bzip2.pc.in11
-rw-r--r--lib/libc/Makefile2
-rw-r--r--lib/libc/Versions.def6
-rw-r--r--lib/libc/aarch64/string/timingsafe_memcmp.S2
-rw-r--r--lib/libc/arm/gen/arm_drain_writebuf.25
-rw-r--r--lib/libc/db/mpool/mpool.c2
-rw-r--r--lib/libc/gdtoa/_hdtoa.c3
-rw-r--r--lib/libc/gdtoa/_hldtoa.c3
-rw-r--r--lib/libc/gen/Symbol.map2
-rw-r--r--lib/libc/gen/_rand48.c34
-rw-r--r--lib/libc/gen/drand48.c6
-rw-r--r--lib/libc/gen/erand48.c9
-rw-r--r--lib/libc/gen/fts-compat.c2
-rw-r--r--lib/libc/gen/fts-compat11.c2
-rw-r--r--lib/libc/gen/fts.3195
-rw-r--r--lib/libc/gen/fts.c3
-rw-r--r--lib/libc/gen/gen-compat.h48
-rw-r--r--lib/libc/gen/getgrouplist.350
-rw-r--r--lib/libc/gen/getgrouplist.c6
-rw-r--r--lib/libc/gen/getvfsbyname.33
-rw-r--r--lib/libc/gen/initgroups.3105
-rw-r--r--lib/libc/gen/initgroups.c55
-rw-r--r--lib/libc/gen/jrand48.c7
-rw-r--r--lib/libc/gen/lcong48.c12
-rw-r--r--lib/libc/gen/lrand48.c6
-rw-r--r--lib/libc/gen/mrand48.c8
-rw-r--r--lib/libc/gen/nrand48.c6
-rw-r--r--lib/libc/gen/psignal.39
-rw-r--r--lib/libc/gen/rand48.35
-rw-r--r--lib/libc/gen/rand48.h61
-rw-r--r--lib/libc/gen/seed48.c18
-rw-r--r--lib/libc/gen/srand48.c13
-rw-r--r--lib/libc/gen/sysconf.36
-rw-r--r--lib/libc/gen/sysconf.c18
-rw-r--r--lib/libc/include/compat.h1
-rw-r--r--lib/libc/include/port_before.h1
-rw-r--r--lib/libc/inet/inet_net_ntop.c206
-rw-r--r--lib/libc/inet/inet_net_pton.c363
-rw-r--r--lib/libc/locale/Makefile.inc2
-rw-r--r--lib/libc/locale/xlocale_private.h6
-rw-r--r--lib/libc/md/Makefile.inc3
-rw-r--r--lib/libc/nls/Makefile.inc5
-rw-r--r--lib/libc/posix1e/Makefile.inc3
-rw-r--r--lib/libc/posix1e/mac_free.34
-rw-r--r--lib/libc/posix1e/mac_text.38
-rw-r--r--lib/libc/regex/Makefile.inc8
-rw-r--r--lib/libc/resolv/Symbol.map1
-rw-r--r--lib/libc/resolv/res_init.c61
-rw-r--r--lib/libc/riscv/string/Makefile.inc10
-rw-r--r--lib/libc/riscv/string/bcopy.c14
-rw-r--r--lib/libc/riscv/string/bzero.c14
-rw-r--r--lib/libc/riscv/string/memchr.S188
-rw-r--r--lib/libc/riscv/string/memcpy.S217
-rw-r--r--lib/libc/riscv/string/memset.S95
-rw-r--r--lib/libc/riscv/string/strchrnul.S116
-rw-r--r--lib/libc/riscv/string/strlen.S77
-rw-r--r--lib/libc/riscv/string/strnlen.S143
-rw-r--r--lib/libc/riscv/string/strrchr.S127
-rw-r--r--lib/libc/rpc/Makefile.inc4
-rw-r--r--lib/libc/rpc/rpc_generic.c4
-rw-r--r--lib/libc/stdbit/Makefile.inc34
-rw-r--r--lib/libc/stdbit/Symbol.map85
-rw-r--r--lib/libc/stdbit/stdc_bit_ceil.381
-rw-r--r--lib/libc/stdbit/stdc_bit_ceil.c71
-rw-r--r--lib/libc/stdbit/stdc_bit_floor.383
-rw-r--r--lib/libc/stdbit/stdc_bit_floor.c53
-rw-r--r--lib/libc/stdbit/stdc_bit_width.3104
-rw-r--r--lib/libc/stdbit/stdc_bit_width.c53
-rw-r--r--lib/libc/stdbit/stdc_count_ones.385
-rw-r--r--lib/libc/stdbit/stdc_count_ones.c38
-rw-r--r--lib/libc/stdbit/stdc_count_zeros.384
-rw-r--r--lib/libc/stdbit/stdc_count_zeros.c38
-rw-r--r--lib/libc/stdbit/stdc_first_leading_one.393
-rw-r--r--lib/libc/stdbit/stdc_first_leading_one.c57
-rw-r--r--lib/libc/stdbit/stdc_first_leading_zero.392
-rw-r--r--lib/libc/stdbit/stdc_first_leading_zero.c57
-rw-r--r--lib/libc/stdbit/stdc_first_trailing_one.3110
-rw-r--r--lib/libc/stdbit/stdc_first_trailing_one.c52
-rw-r--r--lib/libc/stdbit/stdc_first_trailing_zero.393
-rw-r--r--lib/libc/stdbit/stdc_first_trailing_zero.c53
-rw-r--r--lib/libc/stdbit/stdc_has_single_bit.398
-rw-r--r--lib/libc/stdbit/stdc_has_single_bit.c38
-rw-r--r--lib/libc/stdbit/stdc_leading_ones.386
-rw-r--r--lib/libc/stdbit/stdc_leading_ones.c60
-rw-r--r--lib/libc/stdbit/stdc_leading_zeros.386
-rw-r--r--lib/libc/stdbit/stdc_leading_zeros.c60
-rw-r--r--lib/libc/stdbit/stdc_trailing_ones.386
-rw-r--r--lib/libc/stdbit/stdc_trailing_ones.c56
-rw-r--r--lib/libc/stdbit/stdc_trailing_zeros.387
-rw-r--r--lib/libc/stdbit/stdc_trailing_zeros.c56
-rw-r--r--lib/libc/stdlib/Makefile.inc7
-rw-r--r--lib/libc/stdlib/Symbol.map5
-rw-r--r--lib/libc/stdlib/exit.32
-rw-r--r--lib/libc/stdlib/malloc/jemalloc/jemalloc.3200
-rw-r--r--lib/libc/stdlib/memalignment.353
-rw-r--r--lib/libc/stdlib/memalignment.c28
-rw-r--r--lib/libc/stdlib/reallocarray.337
-rw-r--r--lib/libc/stdlib/reallocarray.c14
-rw-r--r--lib/libc/stdlib/realpath.312
-rw-r--r--lib/libc/stdlib/realpath.c14
-rw-r--r--lib/libc/stdlib/recallocarray.c (renamed from lib/libopenbsd/recallocarray.c)15
-rw-r--r--lib/libc/stdlib/strfmon.312
-rw-r--r--lib/libc/stdlib/strfmon.c8
-rw-r--r--lib/libc/stdtime/Makefile.inc3
-rw-r--r--lib/libc/stdtime/ctime.339
-rw-r--r--lib/libc/stdtime/strptime.32
-rw-r--r--lib/libc/stdtime/strptime.c3
-rw-r--r--lib/libc/stdtime/tzset.357
-rw-r--r--lib/libc/string/ffs.315
-rw-r--r--lib/libc/tests/Makefile1
-rw-r--r--lib/libc/tests/gen/Makefile1
-rw-r--r--lib/libc/tests/gen/limits_test.c101
-rw-r--r--lib/libc/tests/gen/realpath2_test.c106
-rw-r--r--lib/libc/tests/net/Makefile2
-rw-r--r--lib/libc/tests/net/inet_net_test.cc333
-rw-r--r--lib/libc/tests/stdbit/Makefile21
-rw-r--r--lib/libc/tests/stdbit/stdbit-test-framework.c80
-rw-r--r--lib/libc/tests/stdbit/stdbit-test-kernel.c68
-rw-r--r--lib/libc/tests/stdbit/stdc_bit_ceil_test.c20
-rw-r--r--lib/libc/tests/stdbit/stdc_bit_floor_test.c25
-rw-r--r--lib/libc/tests/stdbit/stdc_bit_width_test.c22
-rw-r--r--lib/libc/tests/stdbit/stdc_count_ones_test.c22
-rw-r--r--lib/libc/tests/stdbit/stdc_count_zeros_test.c23
-rw-r--r--lib/libc/tests/stdbit/stdc_first_leading_one_test.c29
-rw-r--r--lib/libc/tests/stdbit/stdc_first_leading_zero_test.c30
-rw-r--r--lib/libc/tests/stdbit/stdc_first_trailing_one_test.c26
-rw-r--r--lib/libc/tests/stdbit/stdc_first_trailing_zero_test.c27
-rw-r--r--lib/libc/tests/stdbit/stdc_has_single_bit_test.c21
-rw-r--r--lib/libc/tests/stdbit/stdc_leading_ones_test.c26
-rw-r--r--lib/libc/tests/stdbit/stdc_leading_zeros_test.c26
-rw-r--r--lib/libc/tests/stdbit/stdc_trailing_ones_test.c23
-rw-r--r--lib/libc/tests/stdbit/stdc_trailing_zeros_test.c23
-rw-r--r--lib/libc/tests/stdio/printfloat_test.c13
-rw-r--r--lib/libc/tests/stdlib/strfmon_test.c80
-rw-r--r--lib/libc/tests/stdtime/Makefile1
-rw-r--r--lib/libc/tests/stdtime/detect_tz_changes_test.c113
-rw-r--r--lib/libc/tests/string/memcmp_test.c12
-rw-r--r--lib/libc/tests/sys/cpuset_test.c140
-rw-r--r--lib/libc/tests/tls/dso/Makefile1
-rw-r--r--lib/libc/tests/tls_dso/Makefile1
-rw-r--r--lib/libcasper/Makefile.inc2
-rw-r--r--lib/libcasper/libcasper/Makefile2
-rw-r--r--lib/libcasper/services/cap_dns/Makefile2
-rw-r--r--lib/libcasper/services/cap_fileargs/Makefile2
-rw-r--r--lib/libcasper/services/cap_fileargs/cap_fileargs.h2
-rw-r--r--lib/libcasper/services/cap_grp/Makefile2
-rw-r--r--lib/libcasper/services/cap_net/Makefile2
-rw-r--r--lib/libcasper/services/cap_netdb/Makefile2
-rw-r--r--lib/libcasper/services/cap_pwd/Makefile2
-rw-r--r--lib/libcasper/services/cap_sysctl/Makefile2
-rw-r--r--lib/libcasper/services/cap_syslog/Makefile2
-rw-r--r--lib/libcasper/services/tests/Makefile2
-rw-r--r--lib/libcasper/tests/Makefile2
-rw-r--r--lib/libdiff/Makefile2
-rw-r--r--lib/libedit/Makefile9
-rw-r--r--lib/libedit/Makefile.inc1
-rw-r--r--lib/libefivar/FreeBSD-update2
-rw-r--r--lib/libefivar/ProcessorBind.h3
-rw-r--r--lib/libefivar/efi-osdep.h110
-rw-r--r--lib/libefivar/efivar-dp-format.c3
-rw-r--r--lib/libefivar/efivar-dp-parse.c4
-rw-r--r--lib/libefivar/efivar-dp-xlate.c13
-rw-r--r--lib/libefivar/efivar.h2
-rw-r--r--lib/libefivar/uefi-dplib.h4
-rw-r--r--lib/libefivar/uefi-dputil.c540
-rw-r--r--lib/libexpat/expat_config.h18
-rw-r--r--lib/libexpat/libbsdxml.34
-rw-r--r--lib/libfido2/Makefile1
-rw-r--r--lib/libgcc_s/Makefile2
-rw-r--r--lib/libjail/jail.c26
-rw-r--r--lib/libkvm/kvm_proc.c9
-rw-r--r--lib/liblzma/Makefile4
-rw-r--r--lib/libmagic/Makefile8
-rw-r--r--lib/libmd/Makefile9
-rw-r--r--lib/libmd/aarch64/md5block.S206
-rw-r--r--lib/libmd/aarch64/sha1block.S2
-rw-r--r--lib/libmd/aarch64/sha1dispatch.c2
-rw-r--r--lib/libmd/amd64/md5block.S363
-rw-r--r--lib/libmd/amd64/md5dispatch.c41
-rw-r--r--lib/libmd/amd64/sha1block.S2
-rw-r--r--lib/libmd/amd64/sha1dispatch.c2
-rw-r--r--lib/libmd/sha1c.c2
-rw-r--r--lib/libmixer/Makefile2
-rw-r--r--lib/libopenbsd/Makefile8
-rw-r--r--lib/libpam/Makefile.inc2
-rw-r--r--lib/libpam/libpam/Makefile8
-rw-r--r--lib/libpam/modules/modules.inc2
-rw-r--r--lib/libpam/modules/pam_chroot/Makefile2
-rw-r--r--lib/libpam/modules/pam_deny/Makefile6
-rw-r--r--lib/libpam/modules/pam_echo/Makefile6
-rw-r--r--lib/libpam/modules/pam_exec/Makefile6
-rw-r--r--lib/libpam/modules/pam_ftpusers/Makefile6
-rw-r--r--lib/libpam/modules/pam_group/Makefile2
-rw-r--r--lib/libpam/modules/pam_guest/Makefile2
-rw-r--r--lib/libpam/modules/pam_krb5/Makefile18
-rw-r--r--lib/libpam/modules/pam_krb5/pam-krb5.82205
-rw-r--r--lib/libpam/modules/pam_ksu/Makefile7
-rw-r--r--lib/libpam/modules/pam_lastlog/Makefile8
-rw-r--r--lib/libpam/modules/pam_login_access/Makefile8
-rw-r--r--lib/libpam/modules/pam_nologin/Makefile8
-rw-r--r--lib/libpam/modules/pam_passwdqc/Makefile6
-rw-r--r--lib/libpam/modules/pam_permit/Makefile6
-rw-r--r--lib/libpam/modules/pam_radius/Makefile7
-rw-r--r--lib/libpam/modules/pam_rhosts/Makefile6
-rw-r--r--lib/libpam/modules/pam_rootok/Makefile6
-rw-r--r--lib/libpam/modules/pam_securetty/Makefile8
-rw-r--r--lib/libpam/modules/pam_self/Makefile8
-rw-r--r--lib/libpam/modules/pam_ssh/Makefile7
-rw-r--r--lib/libpam/modules/pam_tacplus/Makefile6
-rw-r--r--lib/libpam/modules/pam_unix/Makefile8
-rw-r--r--lib/libpam/modules/pam_xdg/Makefile6
-rw-r--r--lib/libpam/modules/pam_xdg/pam_xdg.81
-rw-r--r--lib/libpam/pam.d/Makefile20
-rw-r--r--lib/libpam/static_libpam/Makefile2
-rw-r--r--lib/libpcap/Makefile13
-rw-r--r--lib/libpfctl/libpfctl.c196
-rw-r--r--lib/libpfctl/libpfctl.h11
-rw-r--r--lib/libpmc/Makefile4
-rw-r--r--lib/libproc/Makefile9
-rw-r--r--lib/libproc/tests/Makefile2
-rw-r--r--lib/libprocstat/Makefile2
-rw-r--r--lib/libprocstat/libprocstat.c10
-rw-r--r--lib/libradius/Makefile4
-rw-r--r--lib/libsamplerate/Makefile4
-rw-r--r--lib/libsdp/Makefile3
-rw-r--r--lib/libsdp/sdp.34
-rw-r--r--lib/libsdp/sdp.h2
-rw-r--r--lib/libsdp/service.c2
-rw-r--r--lib/libsecureboot/Makefile.libsa.inc2
-rw-r--r--lib/libsecureboot/efi/efi_variables.c1
-rw-r--r--lib/libsecureboot/efi/include/Guid/GlobalVariable.h192
-rw-r--r--lib/libsecureboot/efi/include/Guid/ImageAuthentication.h350
-rw-r--r--lib/libsecureboot/efi/include/Protocol/Hash.h169
-rw-r--r--lib/libsecureboot/h/libsecureboot.h2
-rw-r--r--lib/libsecureboot/verify_file.c2
-rw-r--r--lib/libstdbuf/Makefile1
-rw-r--r--lib/libstdthreads/Makefile2
-rw-r--r--lib/libsys/Makefile.sys5
-rw-r--r--lib/libsys/Symbol.map6
-rw-r--r--lib/libsys/_libsys.h3
-rw-r--r--lib/libsys/arm/__vdso_gettc.c8
-rw-r--r--lib/libsys/clock_gettime.23
-rw-r--r--lib/libsys/closefrom.27
-rw-r--r--lib/libsys/getgroups.291
-rw-r--r--lib/libsys/getrlimitusage.24
-rw-r--r--lib/libsys/jail.296
-rw-r--r--lib/libsys/kexec_load.2119
-rw-r--r--lib/libsys/kqueue.283
-rw-r--r--lib/libsys/lseek.23
-rw-r--r--lib/libsys/pathconf.28
-rw-r--r--lib/libsys/posix_fallocate.226
-rw-r--r--lib/libsys/reboot.27
-rw-r--r--lib/libsys/revoke.24
-rw-r--r--lib/libsys/setcred.27
-rw-r--r--lib/libsys/setgroups.299
-rw-r--r--lib/libsys/socket.2302
-rw-r--r--lib/libsys/syscalls.map2
-rw-r--r--lib/libsys/write.220
-rw-r--r--lib/libsysdecode/Makefile.depend2
-rw-r--r--lib/libtacplus/Makefile4
-rw-r--r--lib/libufs/Makefile4
-rw-r--r--lib/libunbound/Makefile37
-rw-r--r--lib/libunbound/config.h521
-rw-r--r--lib/libutil/Makefile3
-rw-r--r--lib/libutil/login.conf.54
-rw-r--r--lib/libutil/login_class.c55
-rw-r--r--lib/libutil/mntopts.c53
-rw-r--r--lib/libwrap/Makefile17
-rw-r--r--lib/libxo/libxo/Makefile2
-rw-r--r--lib/libxo/tests/encoder/Makefile1
-rw-r--r--lib/liby/Makefile2
-rw-r--r--lib/libz/Makefile5
-rw-r--r--lib/msun/man/cospi.313
-rw-r--r--lib/msun/man/sinpi.312
-rw-r--r--lib/msun/man/tanpi.313
-rw-r--r--lib/msun/src/e_remainder.c4
-rw-r--r--lib/msun/src/math.h5
-rw-r--r--lib/msun/src/s_cpow.c5
-rw-r--r--lib/msun/src/s_cpowf.c5
-rw-r--r--lib/msun/src/s_cpowl.c5
-rw-r--r--lib/ncurses/Makefile.inc2
-rw-r--r--lib/ncurses/form/Makefile1
-rw-r--r--lib/ncurses/ncurses/Makefile1
-rw-r--r--lib/ncurses/panel/Makefile1
-rw-r--r--lib/ncurses/tinfo/Makefile7
-rw-r--r--lib/nss_tacplus/Makefile6
-rw-r--r--lib/ofed/Makefile.inc3
-rw-r--r--lib/virtual_oss/Makefile9
-rw-r--r--lib/virtual_oss/Makefile.inc5
-rw-r--r--lib/virtual_oss/bt/Makefile19
-rw-r--r--lib/virtual_oss/bt/avdtp.c720
-rw-r--r--lib/virtual_oss/bt/avdtp_signal.h139
-rw-r--r--lib/virtual_oss/bt/bt.c1061
-rw-r--r--lib/virtual_oss/bt/bt.h116
-rw-r--r--lib/virtual_oss/bt/cosdata-gen/Makefile12
-rw-r--r--lib/virtual_oss/bt/cosdata-gen/cosdata.c177
-rw-r--r--lib/virtual_oss/bt/sbc_coeffs.h69
-rw-r--r--lib/virtual_oss/bt/sbc_encode.c701
-rw-r--r--lib/virtual_oss/bt/sbc_encode.h82
-rw-r--r--lib/virtual_oss/null/Makefile10
-rw-r--r--lib/virtual_oss/null/null.c102
-rw-r--r--lib/virtual_oss/oss/Makefile10
-rw-r--r--lib/virtual_oss/oss/oss.c197
-rw-r--r--lib/virtual_oss/sndio/Makefile12
-rw-r--r--lib/virtual_oss/sndio/sndio.c203
333 files changed, 13223 insertions, 3606 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 2b7cf2fdcb7d..75a2355aa452 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -157,11 +157,13 @@ SUBDIR_DEPEND_liblzma= libthr
SUBDIR_DEPEND_libpcap= ofed
.endif
SUBDIR_DEPEND_nss_tacplus= libtacplus
+SUBDIR_DEPEND_virtual_oss= libsamplerate
# NB: keep these sorted by MK_* knobs
SUBDIR.${MK_BEARSSL}+= libbearssl libsecureboot
SUBDIR.${MK_BLACKLIST}+=libblacklist
+SUBDIR.${MK_BLOCKLIST}+=libblocklist
SUBDIR.${MK_BLUETOOTH}+=libbluetooth libsdp
SUBDIR.${MK_BSNMP}+= libbsnmp
@@ -173,6 +175,7 @@ SUBDIR+= clang
.endif
SUBDIR.${MK_CUSE}+= libcuse
+SUBDIR.${MK_CUSE}+= virtual_oss
SUBDIR.${MK_TOOLCHAIN}+=libpe
SUBDIR.${MK_DIALOG}+= libdpv libfigpar
SUBDIR.${MK_FDT}+= libfdt
diff --git a/lib/atf/Makefile.inc b/lib/atf/Makefile.inc
index f8f329842eb4..af176036f136 100644
--- a/lib/atf/Makefile.inc
+++ b/lib/atf/Makefile.inc
@@ -24,6 +24,8 @@
# SUCH DAMAGE.
#
+PACKAGE?= atf
+LIB_PACKAGE=
CFLAGS+= -DHAVE_CONFIG_H
WARNS?= 3
diff --git a/lib/atf/libatf-c++/Makefile b/lib/atf/libatf-c++/Makefile
index 985a79b7dc03..4f4f7f12ec05 100644
--- a/lib/atf/libatf-c++/Makefile
+++ b/lib/atf/libatf-c++/Makefile
@@ -27,7 +27,6 @@
.include <src.opts.mk>
.include <bsd.init.mk>
-PACKAGE= tests
LIB_CXX= atf-c++
PRIVATELIB= true
SHLIB_MAJOR= 2
diff --git a/lib/atf/libatf-c++/tests/detail/Makefile b/lib/atf/libatf-c++/tests/detail/Makefile
index 4b95f8dbd663..55cefe524068 100644
--- a/lib/atf/libatf-c++/tests/detail/Makefile
+++ b/lib/atf/libatf-c++/tests/detail/Makefile
@@ -1,5 +1,7 @@
.include <bsd.init.mk>
+PACKAGE= tests
+
TESTSDIR= ${TESTSBASE}/lib/atf/libatf-c++/detail
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/atf/libatf-c/Makefile b/lib/atf/libatf-c/Makefile
index 4cfee2ed824f..c0890abc7640 100644
--- a/lib/atf/libatf-c/Makefile
+++ b/lib/atf/libatf-c/Makefile
@@ -27,7 +27,6 @@
.include <src.opts.mk>
.include <bsd.init.mk>
-PACKAGE= tests
LIB= atf-c
PRIVATELIB= true
SHLIB_MAJOR= 1
diff --git a/lib/atf/libatf-c/tests/detail/Makefile b/lib/atf/libatf-c/tests/detail/Makefile
index 5123f6f4d796..3fa2919b98b9 100644
--- a/lib/atf/libatf-c/tests/detail/Makefile
+++ b/lib/atf/libatf-c/tests/detail/Makefile
@@ -1,5 +1,7 @@
.include <bsd.init.mk>
+PACKAGE= tests
+
TESTSDIR= ${TESTSBASE}/lib/atf/libatf-c/detail
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/atf/tests/Makefile b/lib/atf/tests/Makefile
index 500ff0f20c3b..2609bb593d57 100644
--- a/lib/atf/tests/Makefile
+++ b/lib/atf/tests/Makefile
@@ -1,4 +1,7 @@
.PATH: ${SRCTOP}/tests
+
+PACKAGE= tests
+
KYUAFILE= yes
SUBDIR= test-programs
diff --git a/lib/clang/freebsd_cc_version.h b/lib/clang/freebsd_cc_version.h
index b493dc96db5e..cf525916fe29 100644
--- a/lib/clang/freebsd_cc_version.h
+++ b/lib/clang/freebsd_cc_version.h
@@ -1 +1 @@
-#define FREEBSD_CC_VERSION 1600000
+#define FREEBSD_CC_VERSION 1600001
diff --git a/lib/clang/libllvm/Makefile b/lib/clang/libllvm/Makefile
index e634a72b4f90..810eac08d8d5 100644
--- a/lib/clang/libllvm/Makefile
+++ b/lib/clang/libllvm/Makefile
@@ -1245,16 +1245,6 @@ SRCS_MIN+= Support/regexec.c
SRCS_MIN+= Support/regfree.c
SRCS_MIN+= Support/regstrlcpy.c
SRCS_MIN+= Support/xxhash.cpp
-SRCS_MIN+= TableGen/DetailedRecordsBackend.cpp
-SRCS_MIN+= TableGen/Error.cpp
-SRCS_MIN+= TableGen/JSONBackend.cpp
-SRCS_MIN+= TableGen/Main.cpp
-SRCS_MIN+= TableGen/Record.cpp
-SRCS_MIN+= TableGen/SetTheory.cpp
-SRCS_MIN+= TableGen/StringMatcher.cpp
-SRCS_MIN+= TableGen/TGLexer.cpp
-SRCS_MIN+= TableGen/TGParser.cpp
-SRCS_MIN+= TableGen/TableGenBackend.cpp
.if ${MK_LLVM_TARGET_AARCH64} != "no"
SRCS_MIN+= Target/AArch64/AArch64A53Fix835769.cpp
SRCS_MIN+= Target/AArch64/AArch64A57FPLoadBalancing.cpp
diff --git a/lib/clang/llvm.build.mk b/lib/clang/llvm.build.mk
index e88b2ff1033e..a26e15679242 100644
--- a/lib/clang/llvm.build.mk
+++ b/lib/clang/llvm.build.mk
@@ -36,8 +36,8 @@ CFLAGS+= -DNDEBUG
TARGET_ARCH?= ${MACHINE_ARCH}
BUILD_ARCH?= ${MACHINE_ARCH}
-# Armv6 and armv7 uses hard float abi, unless the CPUTYPE has soft in it.
-# For all other targets, we stick with 'unknown'.
+# Arm uses hard float abi, unless the CPUTYPE has soft in it. For all other
+# targets, we stick with 'unknown'.
.if ${TARGET_ARCH:Marm*}
.if !defined(CPUTYPE) || ${CPUTYPE:M*soft*} == ""
TARGET_TRIPLE_ABI=-gnueabihf
diff --git a/lib/geom/Makefile.inc b/lib/geom/Makefile.inc
index 35163127538d..75d312a94fe4 100644
--- a/lib/geom/Makefile.inc
+++ b/lib/geom/Makefile.inc
@@ -1,10 +1,11 @@
.include <src.opts.mk>
-SHLIBDIR=${GEOM_CLASS_DIR}
-SHLIB_NAME?=geom_${GEOM_CLASS}.so
-MAN= g${GEOM_CLASS}.8
-SRCS+= geom_${GEOM_CLASS}.c subr.c
-CFLAGS+=-I${SRCTOP}/sbin/geom
+SHLIBDIR= ${GEOM_CLASS_DIR}
+SHLIB_NAME?= geom_${GEOM_CLASS}.so
+MANNODEV= g${GEOM_CLASS}.8
+
+SRCS+= geom_${GEOM_CLASS}.c subr.c
+CFLAGS+= -I${SRCTOP}/sbin/geom
.PATH: ${SRCTOP}/sbin/geom/misc
diff --git a/lib/geom/part/gpart.8 b/lib/geom/part/gpart.8
index f76c1d9d5d6c..2e11417f8494 100644
--- a/lib/geom/part/gpart.8
+++ b/lib/geom/part/gpart.8
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd February 11, 2025
+.Dd October 24, 2025
.Dt GPART 8
.Os
.Sh NAME
@@ -1497,6 +1497,26 @@ and
.Bd -literal -offset indent
/sbin/gpart backup ada0 | /sbin/gpart restore -F ada1 ada2
.Ed
+.Sh DIAGNOSTICS
+.Bl -diag
+.It gpart: arg0 '%s': Invalid argument
+The provided
+.Ar geom
+argument
+is not a GEOM provider.
+Not every device in
+.Xr devfs 4
+is a GEOM provider.
+For example, a
+.Xr zfs 4
+zvol will show up as a GEOM provider only if its
+.Sy volmode
+is set properly
+.Po refer to
+.Xr zfsprops 8
+for details
+.Pc .
+.El
.Sh SEE ALSO
.Xr geom 4 ,
.Xr boot0cfg 8 ,
diff --git a/lib/geom/shsec/gshsec.8 b/lib/geom/shsec/gshsec.8
index d4477de3a71e..f80ab9384fe3 100644
--- a/lib/geom/shsec/gshsec.8
+++ b/lib/geom/shsec/gshsec.8
@@ -1,3 +1,6 @@
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
.\" Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
.\" All rights reserved.
.\"
@@ -64,7 +67,7 @@ the rest of them.
The first argument to
.Nm
indicates an action to be performed:
-.Bl -tag -width ".Cm destroy"
+.Bl -tag -width indent
.It Cm label
Set up a shared secret device from the given components with the specified
.Ar name .
@@ -92,7 +95,7 @@ See
.El
.Pp
Additional options:
-.Bl -tag -width ".Fl f"
+.Bl -tag -width indent
.It Fl f
Force the removal of the specified shared secret device.
.It Fl h
diff --git a/lib/googletest/Makefile.inc b/lib/googletest/Makefile.inc
index 231d7545f364..43ebace19a15 100644
--- a/lib/googletest/Makefile.inc
+++ b/lib/googletest/Makefile.inc
@@ -1,5 +1,7 @@
.include <googletest.test.inc.mk>
+PACKAGE?= googletest
+
GTEST_DIR= ${SRCTOP}/contrib/googletest
GOOGLEMOCK_SRCROOT= ${GTEST_DIR}/googlemock
GOOGLETEST_SRCROOT= ${GTEST_DIR}/googletest
diff --git a/lib/googletest/tests/Makefile b/lib/googletest/tests/Makefile
index 886b1a2fe49d..350e0fe765fe 100644
--- a/lib/googletest/tests/Makefile
+++ b/lib/googletest/tests/Makefile
@@ -1,4 +1,7 @@
.PATH: ${SRCTOP}/tests
+
+PACKAGE= tests
+
KYUAFILE= yes
# Note: we start the gmock_main and gmock tests first since those take up to
diff --git a/lib/googletest/tests/Makefile.inc b/lib/googletest/tests/Makefile.inc
index 9691aaa93ded..8d19e1fafdea 100644
--- a/lib/googletest/tests/Makefile.inc
+++ b/lib/googletest/tests/Makefile.inc
@@ -3,6 +3,8 @@
# rather than installing all of them to /usr/tests/lib/googletest
TESTSDIR= ${TESTSBASE}/lib/googletest/${.CURDIR:T}
+PACKAGE= tests
+
# Clang's optimizer spends a really long time on these tests at -O2. Changing
# -O2 to -O1 reduces the -j32 time for lib/googletest/test from 131s to 71s.
# Using -O0 further reduces the time to 29s, and also reduces the disk usage
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile
index fed73c388318..4e32dcf72341 100644
--- a/lib/libarchive/Makefile
+++ b/lib/libarchive/Makefile
@@ -184,12 +184,13 @@ MAN= archive_entry.3 \
archive_write_new.3 \
archive_write_open.3 \
archive_write_set_options.3 \
- cpio.5 \
libarchive.3 \
libarchive_changes.3 \
- libarchive_internals.3 \
- libarchive-formats.5 \
- tar.5
+ libarchive_internals.3
+
+MANNODEV= cpio.5 \
+ libarchive-formats.5 \
+ tar.5
# Symlink the man pages under each function name.
MLINKS+= archive_entry.3 archive_entry_clear.3
diff --git a/lib/libarchive/tests/Makefile b/lib/libarchive/tests/Makefile
index 07c5fe24dd30..880c0d3ce0c6 100644
--- a/lib/libarchive/tests/Makefile
+++ b/lib/libarchive/tests/Makefile
@@ -125,6 +125,7 @@ TESTS_SRCS= \
test_read_format_7zip_encryption_data.c \
test_read_format_7zip_encryption_header.c \
test_read_format_7zip_encryption_partially.c \
+ test_read_format_7zip_issue2765.c \
test_read_format_7zip_malformed.c \
test_read_format_7zip_packinfo_digests.c \
test_read_format_ar.c \
@@ -185,6 +186,7 @@ TESTS_SRCS= \
test_read_format_rar_overflow.c \
test_read_format_raw.c \
test_read_format_tar.c \
+ test_read_format_tar_V_negative_size.c \
test_read_format_tar_concatenated.c \
test_read_format_tar_empty_filename.c \
test_read_format_tar_empty_pax.c \
@@ -391,6 +393,7 @@ ${PACKAGE}FILES+= test_compat_lz4_B6.tar.lz4.uu
${PACKAGE}FILES+= test_compat_lz4_B6BD.tar.lz4.uu
${PACKAGE}FILES+= test_compat_lz4_B7.tar.lz4.uu
${PACKAGE}FILES+= test_compat_lz4_B7BD.tar.lz4.uu
+${PACKAGE}FILES+= test_compat_lz4_skippable_frames_B4.tar.lz4.uu
${PACKAGE}FILES+= test_compat_lzip_1.tlz.uu
${PACKAGE}FILES+= test_compat_lzip_2.tlz.uu
${PACKAGE}FILES+= test_compat_lzip_3.lz.uu
@@ -484,6 +487,7 @@ ${PACKAGE}FILES+= test_read_format_7zip_encryption.7z.uu
${PACKAGE}FILES+= test_read_format_7zip_encryption_header.7z.uu
${PACKAGE}FILES+= test_read_format_7zip_encryption_partially.7z.uu
${PACKAGE}FILES+= test_read_format_7zip_extract_second.7z.uu
+${PACKAGE}FILES+= test_read_format_7zip_issue2765.7z.uu
${PACKAGE}FILES+= test_read_format_7zip_lzma1.7z.uu
${PACKAGE}FILES+= test_read_format_7zip_lzma1_2.7z.uu
${PACKAGE}FILES+= test_read_format_7zip_lzma1_lzma2.7z.uu
@@ -607,6 +611,7 @@ ${PACKAGE}FILES+= test_read_format_rar5_decode_number_out_of_bounds_read.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_different_solid_window_size.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_different_window_size.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_different_winsize_on_merge.rar.uu
+${PACKAGE}FILES+= test_read_format_rar5_dirdata.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_distance_overflow.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_encrypted.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_encrypted_filenames.rar.uu
@@ -616,6 +621,7 @@ ${PACKAGE}FILES+= test_read_format_rar5_extra_field_version.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_fileattr.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_hardlink.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_invalid_dict_reference.rar.uu
+${PACKAGE}FILES+= test_read_format_rar5_invalid_hash_valid_htime_exfld.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_leftshift1.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_leftshift2.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_multiarchive.part01.rar.uu
@@ -633,6 +639,7 @@ ${PACKAGE}FILES+= test_read_format_rar5_multiarchive_solid.part04.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_multiple_files.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_multiple_files_solid.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_nonempty_dir_stream.rar.uu
+${PACKAGE}FILES+= test_read_format_rar5_only_crypt_exfld.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_owner.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_readtables_overflow.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_sfx.exe.uu
@@ -642,12 +649,14 @@ ${PACKAGE}FILES+= test_read_format_rar5_stored_manyfiles.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_symlink.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_truncated_huff.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_unicode.rar.uu
+${PACKAGE}FILES+= test_read_format_rar5_unsupported_exfld.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_win32.rar.uu
${PACKAGE}FILES+= test_read_format_rar5_window_buf_and_size_desync.rar.uu
${PACKAGE}FILES+= test_read_format_raw.bufr.uu
${PACKAGE}FILES+= test_read_format_raw.data.Z.uu
${PACKAGE}FILES+= test_read_format_raw.data.gz.uu
${PACKAGE}FILES+= test_read_format_raw.data.uu
+${PACKAGE}FILES+= test_read_format_tar_V_negative_size.tar.uu
${PACKAGE}FILES+= test_read_format_tar_concatenated.tar.uu
${PACKAGE}FILES+= test_read_format_tar_empty_filename.tar.uu
${PACKAGE}FILES+= test_read_format_tar_empty_with_gnulabel.tar.uu
diff --git a/lib/libbe/Makefile b/lib/libbe/Makefile
index b04becc38d74..860a4aa1962a 100644
--- a/lib/libbe/Makefile
+++ b/lib/libbe/Makefile
@@ -3,6 +3,7 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
PACKAGE= zfs
+LIB_PACKAGE=
LIB= be
SHLIB_MAJOR= 1
SHLIB_MINOR= 0
@@ -52,15 +53,15 @@ LIBADD+= spl
LIBADD+= zfsbootenv
CFLAGS+= -DIN_BASE -DHAVE_RPC_TYPES
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include/os/freebsd
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzfs
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libzpool/include
+CFLAGS+= -I${ZFSTOP}/include
+CFLAGS+= -I${ZFSTOP}/include/os/freebsd
+CFLAGS+= -I${ZFSTOP}/lib/libspl/include
+CFLAGS+= -I${ZFSTOP}/lib/libspl/include/os/freebsd
+CFLAGS+= -I${ZFSTOP}/lib/libzfs
+CFLAGS+= -I${ZFSTOP}/lib/libzpool/include
CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h
CFLAGS+= -DHAVE_ISSETUGID -DHAVE_STRLCAT -DHAVE_STRLCPY
CFLAGS.be.c= -Wno-cast-qual
CFLAGS.be_access.c= -Wno-cast-qual
diff --git a/lib/libbe/tests/Makefile b/lib/libbe/tests/Makefile
index 20a4e1ddfeb7..dfe49bd7f3e5 100644
--- a/lib/libbe/tests/Makefile
+++ b/lib/libbe/tests/Makefile
@@ -10,15 +10,16 @@ LIBADD+= zfs \
spl \
nvpair \
be \
+ pthread
CFLAGS+= -I${SRCTOP}/lib/libbe
CFLAGS+= -DIN_BASE -DHAVE_RPC_TYPES
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
+CFLAGS+= -I${ZFSTOP}/include
+CFLAGS+= -I${ZFSTOP}/lib/libspl/include/
+CFLAGS+= -I${ZFSTOP}/lib/libspl/include/os/freebsd
CFLAGS+= -I${SRCTOP}/sys
CFLAGS+= -I${SRCTOP}/cddl/compat/opensolaris/include
-CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h
CFLAGS+= -DHAVE_ISSETUGID
.include <bsd.test.mk>
diff --git a/lib/libblacklist/Makefile b/lib/libblacklist/Makefile
index bfd9edb9614c..cac023d69bb7 100644
--- a/lib/libblacklist/Makefile
+++ b/lib/libblacklist/Makefile
@@ -1,6 +1,6 @@
BLOCKLIST_DIR=${SRCTOP}/contrib/blocklist
-.PATH: ${BLOCKLIST_DIR}/lib ${BLOCKLIST_DIR}/include
+.PATH: ${BLOCKLIST_DIR}/lib ${BLOCKLIST_DIR}/include ${BLOCKLIST_DIR}/port
PACKAGE= blocklist
LIB= blacklist
@@ -13,9 +13,10 @@ CFLAGS.clang+=-Wno-thread-safety-analysis
CFLAGS+=-I${BLOCKLIST_DIR}/include -I${BLOCKLIST_DIR}/port \
-D_REENTRANT -DHAVE_CONFIG_H -DHAVE_DB_H -DHAVE_LIBUTIL_H \
-DHAVE_CLOCK_GETTIME -DHAVE_FGETLN -DHAVE_GETPROGNAME \
- -DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRUCT_SOCKADDR_SA_LEN
+ -DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRUCT_SOCKADDR_SA_LEN \
+ -DHAVE_SYS_CDEFS_H
-SRCS= bl.c blacklist.c
+SRCS= old_bl.c blacklist.c vsyslog_r.c
INCS= blacklist.h
MAN= libblacklist.3
diff --git a/lib/libblocklist/Makefile b/lib/libblocklist/Makefile
new file mode 100644
index 000000000000..127abb23f43e
--- /dev/null
+++ b/lib/libblocklist/Makefile
@@ -0,0 +1,30 @@
+BLOCKLIST_DIR=${SRCTOP}/contrib/blocklist
+
+.PATH: ${BLOCKLIST_DIR}/lib ${BLOCKLIST_DIR}/include ${BLOCKLIST_DIR}/port
+
+PACKAGE= blocklist
+LIB= blocklist
+SHLIB_MAJOR= 0
+
+LIBADD+= pthread
+
+CFLAGS.clang+=-Wno-thread-safety-analysis
+
+CFLAGS+=-I${BLOCKLIST_DIR}/include -I${BLOCKLIST_DIR}/port \
+ -D_REENTRANT -DHAVE_CONFIG_H -DHAVE_DB_H -DHAVE_LIBUTIL_H \
+ -DHAVE_CLOCK_GETTIME -DHAVE_FGETLN -DHAVE_GETPROGNAME \
+ -DHAVE_STRLCAT -DHAVE_STRLCPY -DHAVE_STRUCT_SOCKADDR_SA_LEN \
+ -DHAVE_SYS_CDEFS_H
+
+SRCS= bl.c blocklist.c vsyslog_r.c
+INCS= blocklist.h
+MAN= libblocklist.3
+
+MLINKS= libblocklist.3 blocklist_open.3 \
+ libblocklist.3 blocklist_close.3 \
+ libblocklist.3 blocklist.3 \
+ libblocklist.3 blocklist_r.3 \
+ libblocklist.3 blocklist_sa.3 \
+ libblocklist.3 blocklist_sa_r.3
+
+.include <bsd.lib.mk>
diff --git a/lib/libblocklist/Makefile.depend b/lib/libblocklist/Makefile.depend
new file mode 100644
index 000000000000..577dc5747f1e
--- /dev/null
+++ b/lib/libblocklist/Makefile.depend
@@ -0,0 +1,16 @@
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libthr \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libbluetooth/Makefile b/lib/libbluetooth/Makefile
index a6ac291a0bf8..b935bdf3fc78 100644
--- a/lib/libbluetooth/Makefile
+++ b/lib/libbluetooth/Makefile
@@ -1,6 +1,8 @@
# $Id: Makefile,v 1.5 2003/07/22 18:38:04 max Exp $
PACKAGE= bluetooth
+LIB_PACKAGE=
+
CONFS= hosts protocols
CONFSDIR= /etc/bluetooth
CONFSMODE_protocols= 444
diff --git a/lib/libbsddialog/Makefile b/lib/libbsddialog/Makefile
index 2ec633b25147..54390cf87f71 100644
--- a/lib/libbsddialog/Makefile
+++ b/lib/libbsddialog/Makefile
@@ -13,6 +13,7 @@ SRCS= barbox.c \
libbsddialog.c \
menubox.c \
messagebox.c \
+ slider.c \
textbox.c \
theme.c \
timebox.c
diff --git a/lib/libbsdstat/bsdstat.h b/lib/libbsdstat/bsdstat.h
index 1b0d1f24e93f..b293cd652a72 100644
--- a/lib/libbsdstat/bsdstat.h
+++ b/lib/libbsdstat/bsdstat.h
@@ -76,7 +76,7 @@ struct fmt {
* classes derived from it are useful.
*/
struct bsdstat {
- const char *name; /* statistics name, e.g. wlanstats */
+ const char *name; /* statistics name, e.g. wlanstat */
const struct fmt *stats; /* statistics in class */
int nstats; /* number of stats */
#define FMTS_IS_STAT 0x80 /* the following two bytes are the stat id */
diff --git a/lib/libbsm/Makefile b/lib/libbsm/Makefile
index 67802eef62ac..4413a5dd79f7 100644
--- a/lib/libbsm/Makefile
+++ b/lib/libbsm/Makefile
@@ -1,9 +1,8 @@
-#
-#
+PACKAGE= audit
+LIB_PACKAGE=
-PACKAGE= lib${LIB}
-OPENBSMDIR= ${SRCTOP}/contrib/openbsm
-_LIBBSMDIR= ${OPENBSMDIR}/libbsm
+OPENBSMDIR= ${SRCTOP}/contrib/openbsm
+_LIBBSMDIR= ${OPENBSMDIR}/libbsm
LIB= bsm
SHLIB_MAJOR= 3
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index f7ea21b1a085..2aedbaed4328 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -1,4 +1,6 @@
-PACKAGE= lib${LIB}
+PACKAGE= bzip2
+LIB_PACKAGE=
+
BZ2DIR= ${SRCTOP}/contrib/bzip2
.PATH: ${BZ2DIR}
@@ -11,4 +13,17 @@ CFLAGS+= -I${BZ2DIR}
WARNS?= 3
+BZIP2_VERSION!= sed -n '/bzip2\/libbzip2 version /{s/.*version //;s/ of.*//p;q;}' ${BZ2DIR}/bzlib.h
+
+bzip2.pc: bzip2.pc.in
+ sed -e 's,@prefix@,/usr,g ; \
+ s,@exec_prefix@,$${prefix},g ; \
+ s,@libdir@,${LIBDIR},g ; \
+ s,@sharedlibdir@,${SHLIBDIR},g ; \
+ s,@includedir@,${INCLUDEDIR},g ; \
+ s,@VERSION@,${BZIP2_VERSION},g ;' \
+ ${.ALLSRC} > ${.TARGET}
+
+PCFILES= bzip2.pc
+
.include <bsd.lib.mk>
diff --git a/lib/libbz2/bzip2.pc.in b/lib/libbz2/bzip2.pc.in
new file mode 100644
index 000000000000..d91c9931a58a
--- /dev/null
+++ b/lib/libbz2/bzip2.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+sharedlibdir=@sharedlibdir@
+includedir=@includedir@
+
+Name: bzip2
+Description: bzip2 compression library
+Version: @VERSION@
+Libs: -L${libdir} -lbz2
+Cflags: -I${includedir}
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index d0c254e33396..34474cfa9fe4 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -109,7 +109,6 @@ NOASM=
.include "${LIBC_SRCTOP}/inet/Makefile.inc"
.include "${LIBC_SRCTOP}/isc/Makefile.inc"
.include "${LIBC_SRCTOP}/locale/Makefile.inc"
-.include "${LIBC_SRCTOP}/md/Makefile.inc"
.include "${LIBC_SRCTOP}/nameser/Makefile.inc"
.include "${LIBC_SRCTOP}/net/Makefile.inc"
.include "${LIBC_SRCTOP}/nls/Makefile.inc"
@@ -119,6 +118,7 @@ NOASM=
.endif
.include "${LIBC_SRCTOP}/regex/Makefile.inc"
.include "${LIBC_SRCTOP}/resolv/Makefile.inc"
+.include "${LIBC_SRCTOP}/stdbit/Makefile.inc"
.include "${LIBC_SRCTOP}/stdio/Makefile.inc"
.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
diff --git a/lib/libc/Versions.def b/lib/libc/Versions.def
index 184e107d225a..1c7b34bef35b 100644
--- a/lib/libc/Versions.def
+++ b/lib/libc/Versions.def
@@ -42,6 +42,10 @@ FBSD_1.7 {
FBSD_1.8 {
} FBSD_1.7;
+# This version was first added to 16.0-current.
+FBSD_1.9 {
+} FBSD_1.8;
+
# This is our private namespace. Any global interfaces that are
# strictly for use only by other FreeBSD applications and libraries
# are listed here. We use a separate namespace so we can write
@@ -49,4 +53,4 @@ FBSD_1.8 {
#
# Please do NOT increment the version of this namespace.
FBSDprivate_1.0 {
-} FBSD_1.8;
+} FBSD_1.9;
diff --git a/lib/libc/aarch64/string/timingsafe_memcmp.S b/lib/libc/aarch64/string/timingsafe_memcmp.S
index 28fdd911a387..4cc10a152aa8 100644
--- a/lib/libc/aarch64/string/timingsafe_memcmp.S
+++ b/lib/libc/aarch64/string/timingsafe_memcmp.S
@@ -114,4 +114,4 @@ ENTRY(timingsafe_memcmp)
csetm w0, lo
csinc w0, w0, wzr, ls
ret
-END(timingsafe_bcmp)
+END(timingsafe_memcmp)
diff --git a/lib/libc/arm/gen/arm_drain_writebuf.2 b/lib/libc/arm/gen/arm_drain_writebuf.2
index 613c35d39ef2..7fa9eb460114 100644
--- a/lib/libc/arm/gen/arm_drain_writebuf.2
+++ b/lib/libc/arm/gen/arm_drain_writebuf.2
@@ -42,10 +42,7 @@ Not all hardware supports buffered writes; on such systems the
.Nm
function is a no-op.
.Pp
-On ARMv5 systems, this executes a cp15 coprocessor
-.Dq drain write buffer
-operation.
-On ARMv6 and ARMv7 systems, this executes a
+This executes a
.Dq DSB SY
synchronization barrier, followed by an L2 cache drain on
systems where the DSB does not include L2 automatically.
diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c
index 9dab032134bc..1bab66d73baf 100644
--- a/lib/libc/db/mpool/mpool.c
+++ b/lib/libc/db/mpool/mpool.c
@@ -455,7 +455,7 @@ mpool_stat(MPOOL *mp)
(void)fprintf(stderr, "%lu pages in the file\n", mp->npages);
(void)fprintf(stderr,
- "page size %lu, cacheing %lu pages of %lu page max cache\n",
+ "page size %lu, caching %lu pages of %lu page max cache\n",
mp->pagesize, mp->curcache, mp->maxcache);
(void)fprintf(stderr, "%lu page puts, %lu page gets, %lu page new\n",
mp->pageput, mp->pageget, mp->pagenew);
diff --git a/lib/libc/gdtoa/_hdtoa.c b/lib/libc/gdtoa/_hdtoa.c
index 8ae739acf0db..9c42630cd918 100644
--- a/lib/libc/gdtoa/_hdtoa.c
+++ b/lib/libc/gdtoa/_hdtoa.c
@@ -40,6 +40,7 @@
#define DBL_ADJ (DBL_MAX_EXP - 2)
#define SIGFIGS ((DBL_MANT_DIG + 3) / 4 + 1)
+#define MAX_HEX_DIGITS ((DBL_MANT_DIG + 3 - 1) / 4 + 1)
static const float one[] = { 1.0f, -1.0f };
@@ -111,7 +112,7 @@ __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
s0 = rv_alloc(bufsize);
/* Round to the desired number of digits. */
- if (SIGFIGS > ndigits && ndigits > 0) {
+ if (MAX_HEX_DIGITS > ndigits && ndigits > 0) {
float redux = one[u.bits.sign];
int offset = 4 * ndigits + DBL_MAX_EXP - 4 - DBL_MANT_DIG;
u.bits.exp = offset;
diff --git a/lib/libc/gdtoa/_hldtoa.c b/lib/libc/gdtoa/_hldtoa.c
index 965d2349d103..5f10d12c5c09 100644
--- a/lib/libc/gdtoa/_hldtoa.c
+++ b/lib/libc/gdtoa/_hldtoa.c
@@ -65,6 +65,7 @@ typedef uint32_t manl_t;
#define LDBL_ADJ (LDBL_MAX_EXP - 2)
#define SIGFIGS ((LDBL_MANT_DIG + 3) / 4 + 1)
+#define MAX_HEX_DIGITS ((LDBL_MANT_DIG + 3 - 1) / 4 + 1)
static const float one[] = { 1.0f, -1.0f };
@@ -125,7 +126,7 @@ __hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
s0 = rv_alloc(bufsize);
/* Round to the desired number of digits. */
- if (SIGFIGS > ndigits && ndigits > 0) {
+ if (MAX_HEX_DIGITS > ndigits && ndigits > 0) {
float redux = one[u.bits.sign];
int offset = 4 * ndigits + LDBL_MAX_EXP - 4 - LDBL_MANT_DIG;
#ifdef __i386__
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index 26f638568efc..494b65bc5cc1 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -193,7 +193,6 @@ FBSD_1.0 {
__isinff;
__isinfl;
isatty;
- initgroups;
jrand48;
lcong48;
ldexp;
@@ -462,6 +461,7 @@ FBSD_1.8 {
fdscandir_b;
fts_open_b;
glob_b;
+ initgroups;
inotify_add_watch;
inotify_init;
inotify_init1;
diff --git a/lib/libc/gen/_rand48.c b/lib/libc/gen/_rand48.c
index 990e2c86949b..114c1595b33d 100644
--- a/lib/libc/gen/_rand48.c
+++ b/lib/libc/gen/_rand48.c
@@ -13,34 +13,6 @@
#include "rand48.h"
-unsigned short _rand48_seed[3] = {
- RAND48_SEED_0,
- RAND48_SEED_1,
- RAND48_SEED_2
-};
-unsigned short _rand48_mult[3] = {
- RAND48_MULT_0,
- RAND48_MULT_1,
- RAND48_MULT_2
-};
-unsigned short _rand48_add = RAND48_ADD;
-
-void
-_dorand48(unsigned short xseed[3])
-{
- unsigned long accu;
- unsigned short temp[2];
-
- accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
- (unsigned long) _rand48_add;
- temp[0] = (unsigned short) accu; /* lower 16 bits */
- accu >>= sizeof(unsigned short) * 8;
- accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
- (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
- temp[1] = (unsigned short) accu; /* middle 16 bits */
- accu >>= sizeof(unsigned short) * 8;
- accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
- xseed[0] = temp[0];
- xseed[1] = temp[1];
- xseed[2] = (unsigned short) accu;
-}
+uint48 _rand48_seed = RAND48_SEED;
+uint48 _rand48_mult = RAND48_MULT;
+uint48 _rand48_add = RAND48_ADD;
diff --git a/lib/libc/gen/drand48.c b/lib/libc/gen/drand48.c
index cec04a6a2425..f7f43ff20468 100644
--- a/lib/libc/gen/drand48.c
+++ b/lib/libc/gen/drand48.c
@@ -13,10 +13,10 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-
double
drand48(void)
{
- return erand48(_rand48_seed);
+ ERAND48_BEGIN;
+ _DORAND48(_rand48_seed);
+ ERAND48_END(_rand48_seed);
}
diff --git a/lib/libc/gen/erand48.c b/lib/libc/gen/erand48.c
index 286904c27839..38d4774a9fe6 100644
--- a/lib/libc/gen/erand48.c
+++ b/lib/libc/gen/erand48.c
@@ -16,8 +16,9 @@
double
erand48(unsigned short xseed[3])
{
- _dorand48(xseed);
- return ldexp((double) xseed[0], -48) +
- ldexp((double) xseed[1], -32) +
- ldexp((double) xseed[2], -16);
+ uint48 tmp;
+
+ ERAND48_BEGIN;
+ DORAND48(tmp, xseed);
+ ERAND48_END(tmp);
}
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c
index f87cabf085f7..62a1e0a81f62 100644
--- a/lib/libc/gen/fts-compat.c
+++ b/lib/libc/gen/fts-compat.c
@@ -44,9 +44,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "gen-compat.h"
#include "fts-compat.h"
#include "un-namespace.h"
+#include "gen-compat.h"
#include "gen-private.h"
diff --git a/lib/libc/gen/fts-compat11.c b/lib/libc/gen/fts-compat11.c
index 0351ce5ac690..5abb378f5f08 100644
--- a/lib/libc/gen/fts-compat11.c
+++ b/lib/libc/gen/fts-compat11.c
@@ -43,9 +43,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "gen-compat.h"
#include "fts-compat11.h"
#include "un-namespace.h"
+#include "gen-compat.h"
#include "gen-private.h"
diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3
index ee558b892c8c..da304e59ee72 100644
--- a/lib/libc/gen/fts.3
+++ b/lib/libc/gen/fts.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 30, 2025
+.Dd October 6, 2025
.Dt FTS 3
.Os
.Sh NAME
@@ -69,14 +69,15 @@ on a file hierarchy, which is then supplied to
the other
.Nm
functions.
-The function
+The
.Fn fts_read
-returns a pointer to a structure describing one of the files in the file
-hierarchy.
-The function
+function returns a pointer to a structure describing one of the files
+in the file hierarchy.
+The
.Fn fts_children
-returns a pointer to a linked list of structures, each of which describes
-one of the files contained in a directory in the hierarchy.
+function returns a pointer to a linked list of structures, each of
+which describes one of the files contained in a directory in the
+hierarchy.
In general, directories are visited two distinguishable times; in pre-order
(before any of their descendants are visited) and in post-order (after all
of their descendants have been visited).
@@ -376,7 +377,44 @@ The
.Fa fts_name
field is always
.Dv NUL Ns -terminated .
-.Sh FTS_OPEN
+.Ss Thread Safety
+The
+.Nm
+functions can safely be used in multi-threaded programs provided no
+two threads access the same
+.Vt FTS
+or
+.Vt FTSENT
+structure simultaneously.
+However, unless the
+.Dv FTS_NOCHDIR
+flag was passed to
+.Fn fts_open
+or
+.Fn fts_open_b ,
+calls to
+.Fn fts_read
+and
+.Fn fts_children
+may change the current working directory, which will affect all
+threads.
+Conversely, changing the current working directory either during or
+between calls to
+.Fn fts_read
+or
+.Fn fts_children
+(even in a single-thread program) may cause
+.Nm
+to malfunction unless the
+.Dv FTS_NOCHDIR
+flag was passed to
+.Fn fts_open
+or
+.Fn fts_open_b
+and all paths in
+.Va path_argv
+were absolute.
+.Ss Fn fts_open
The
.Fn fts_open
function takes a pointer to an array of character pointers naming one
@@ -507,10 +545,10 @@ from descending into directories that have a different device number
than the file from which the descent began.
.El
.Pp
-The argument
-.Fn compar
-specifies a user-defined function which may be used to order the traversal
-of the hierarchy.
+The
+.Fa compar
+argument points to a user-defined function which may be used to order
+the traversal of the hierarchy.
It
takes two pointers to pointers to
.Vt FTSENT
@@ -545,7 +583,7 @@ 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
+.Ss Fn fts_open_b
The
.Fn fts_open_b
function is identical to
@@ -554,7 +592,7 @@ 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
+.Ss Fn fts_read
The
.Fn fts_read
function returns a pointer to an
@@ -588,6 +626,15 @@ structure is returned, and
.Va errno
may or may not have been set (see
.Fa fts_info ) .
+Note that
+.Fn fts_read
+will not set
+.Va errno
+to 0 if called again with the same
+.Fa ftsp
+argument after the
+.Dv FTS_STOP
+flag has been set or the end of the stream has been reached.
.Pp
The
.Vt FTSENT
@@ -602,10 +649,10 @@ directory, in which case they will not be overwritten until after a call to
.Fn fts_read
after the
.Vt FTSENT
-structure has been returned by the function
+structure has been returned by the
.Fn fts_read
-in post-order.
-.Sh FTS_CHILDREN
+function in post-order.
+.Ss Fn fts_children
The
.Fn fts_children
function returns a pointer to an
@@ -679,11 +726,11 @@ and
.Fa fts_namelen
fields.
.El
-.Sh FTS_SET
-The function
+.Ss Fn fts_set
+The
.Fn fts_set
-allows the user application to determine further processing for the
-file
+function allows the user application to determine further processing
+for the file
.Fa f
of the stream
.Fa ftsp .
@@ -749,7 +796,40 @@ The file may be one of those most recently returned by either
or
.Fn fts_read .
.El
-.Sh FTS_CLOSE
+.Ss Fn fts_set_clientptr , Fn fts_get_clientptr
+The
+.Fn fts_set_clientptr
+function sets the client data pointer for the stream
+.Fa ftsp
+to
+.Fa clientdata .
+The
+.Fn fts_get_clientptr
+function returns the client data pointer associated with
+.Fa ftsp .
+This can be used to pass per-stream data to the comparison function.
+.Pp
+For performance reasons,
+.Fn fts_get_clientptr
+may be shadowed by a preprocessor macro.
+.Ss Fn fts_get_stream
+The
+.Fn fts_get_stream
+function returns the
+.Nm
+stream associated with the file entry
+.Fa f .
+A typical use for this would be for a comparison function to first call
+.Fn fts_get_stream
+on one of its arguments, then call
+.Fn fts_get_clientptr
+to obtain the client data pointer, which in turn points to information
+necessary to correctly order the two entries.
+.Pp
+For performance reasons,
+.Fn fts_get_stream
+may be shadowed by a preprocessor macro.
+.Ss Fn fts_close
The
.Fn fts_close
function closes a file hierarchy stream
@@ -760,6 +840,75 @@ or
.Fn fts_open_b
was called to open
.Fa ftsp .
+.Sh RETURN VALUES
+The
+.Fn fts_open
+and
+.Fn fts_open_b
+functions return a pointer to the new
+.Nm
+stream on success and
+.Dv NULL
+on failure.
+.Pp
+The
+.Fn fts_read
+function returns a pointer to the next file entry on success, or if an
+error occurs that relates specifically to that file entry.
+On reaching the end of the file hierarchy, it returns
+.Dv NULL
+and sets the external variable
+.Va errno
+to 0.
+On failure, it returns
+.Dv NULL
+and sets
+.Va errno
+to an appropriate non-zero value.
+If called again after the
+.Dv FTS_STOP
+flag has been set or the end of the stream has been reached,
+.Fn fts_read
+returns
+.Dv NULL
+and leaves
+.Va errno
+untouched.
+.Pp
+The
+.Fn fts_children
+function returns a pointer to a linked list of file entries on
+success.
+On reaching the end of the file hierarchy, it returns
+.Dv NULL
+and sets the external variable
+.Va errno
+to 0.
+On failure, it returns
+.Dv NULL
+and sets
+.Va errno
+to an appropriate non-zero value.
+.Pp
+The
+.Fn fts_set
+function returns 0 on success and \-1 if its
+.Fa instr
+argument is invalid.
+.Pp
+The
+.Fn fts_get_clientptr
+function returns the client data pointer associated with its argument,
+or
+.Dv NULL
+if none has been set.
+.Pp
+The
+.Fn fts_get_stream
+function returns a pointer to the
+.Nm
+stream associated with its argument.
+.Pp
The
.Fn fts_close
function
@@ -816,7 +965,7 @@ functions may fail and set
as follows:
.Bl -tag -width Er
.It Bq Er EINVAL
-The options were invalid, or the list were empty.
+The options were invalid, or the list was empty.
.El
.Sh SEE ALSO
.Xr find 1 ,
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
index cce959ba836a..4aa386d777cd 100644
--- a/lib/libc/gen/fts.c
+++ b/lib/libc/gen/fts.c
@@ -106,7 +106,6 @@ struct _fts_private {
* This assumption only holds for UFS-like filesystems that implement
* links and directories this way, so we must punt for others.
*/
-
static const char *ufslike_filesystems[] = {
"ufs",
"zfs",
@@ -679,7 +678,6 @@ fts_children(FTS *sp, int instr)
void *
(fts_get_clientptr)(FTS *sp)
{
-
return (fts_get_clientptr(sp));
}
@@ -696,7 +694,6 @@ FTS *
void
fts_set_clientptr(FTS *sp, void *clientptr)
{
-
sp->fts_clientptr = clientptr;
}
diff --git a/lib/libc/gen/gen-compat.h b/lib/libc/gen/gen-compat.h
index 08e80ede6b6e..19b9addb4321 100644
--- a/lib/libc/gen/gen-compat.h
+++ b/lib/libc/gen/gen-compat.h
@@ -40,16 +40,50 @@ struct freebsd11_statfs;
struct freebsd11_dirent *freebsd11_readdir(DIR *);
int freebsd11_readdir_r(DIR *, struct freebsd11_dirent *,
struct freebsd11_dirent **);
-int freebsd11_stat(const char *, struct freebsd11_stat *);
-int freebsd11_lstat(const char *, struct freebsd11_stat *);
-int freebsd11_fstat(int, struct freebsd11_stat *);
-int freebsd11_fstatat(int, const char *, struct freebsd11_stat *, int);
-int freebsd11_statfs(const char *, struct freebsd11_statfs *);
-int freebsd11_getfsstat(struct freebsd11_statfs *, long, int);
int freebsd11_getmntinfo(struct freebsd11_statfs **, int);
char *freebsd11_devname(__uint32_t dev, __mode_t type);
-char *freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf, int len);
+char *freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf,
+ int len);
+
+/*
+ * We want freebsd11_fstat in C source to result in resolution to
+ * - fstat@FBSD_1.0 for libc.so (but we do not need the _definition_
+ * of this fstat, it is provided by libsys.so which we want to use).
+ * - freebsd11_fstat for libc.a (since if we make it fstat@FBSD_1.0
+ * for libc.a, then final linkage into static object ignores version
+ * and would reference fstat, which is the current syscall, not the
+ * compat syscall). libc.a provides the freebsd11_fstat implementation.
+ * Note that freebsd11_fstat from libc.a is not used for anything, but
+ * we make it correct nonetheless, just in case it would.
+ * This is arranged by COMPAT_SYSCALL, and libc can just use freebsd11_fstat.
+ */
+#ifdef PIC
+#define COMPAT_SYSCALL(rtype, fun, args, sym, ver) \
+ rtype fun args; __sym_compat(sym, fun, ver);
+#else
+#define COMPAT_SYSCALL(rtype, fun, args, sym, ver) \
+ rtype fun args;
+#endif
+
+COMPAT_SYSCALL(int, freebsd11_stat, (const char *, struct freebsd11_stat *),
+ stat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_lstat, (const char *, struct freebsd11_stat *),
+ lstat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_fstat, (int, struct freebsd11_stat *),
+ fstat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_fstatat, (int, const char *,
+ struct freebsd11_stat *, int), fstatat, FBSD_1.1);
+
+COMPAT_SYSCALL(int, freebsd11_statfs, (const char *,
+ struct freebsd11_statfs *), statfs, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_getfsstat, (struct freebsd11_statfs *, long,
+ int), getfsstat, FBSD_1.0);
+
+COMPAT_SYSCALL(int, freebsd14_setgroups, (int gidsize, const __gid_t *gidset),
+ setgroups, FBSD_1.0);
+
+#undef COMPAT_SYSCALL
#endif /* _GEN_COMPAT_H_ */
diff --git a/lib/libc/gen/getgrouplist.3 b/lib/libc/gen/getgrouplist.3
index e9a980f99751..9e05ff7e7a29 100644
--- a/lib/libc/gen/getgrouplist.3
+++ b/lib/libc/gen/getgrouplist.3
@@ -1,5 +1,13 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2025 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Olivier Certner
+.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+.\" Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -25,12 +33,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd October 26, 2014
+.Dd October 9, 2025
.Dt GETGROUPLIST 3
.Os
.Sh NAME
.Nm getgrouplist
-.Nd calculate group access list
+.Nd produce a user's effective group list
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -40,36 +48,44 @@
.Sh DESCRIPTION
The
.Fn getgrouplist
-function reads through the group file and calculates
-the group access list for the user specified in
-.Fa name .
-The
+function retrieves from the group database the supplementary groups for the user
+specified in
+.Fa name
+and returns the effective group list, whose first group is the value of
+.Fa basegid
+and the others are the supplementary groups.
.Fa basegid
-is automatically included in the groups list.
-Typically this value is given as
-the group number from the password file.
+typically is the user's initial numerical group ID from the password database.
.Pp
-The resulting group list is returned in the array pointed to by
+The effective group list is returned in the array pointed to by
.Fa groups .
-The caller specifies the size of the
+The caller specifies the length of the
.Fa groups
array in the integer pointed to by
-.Fa ngroups ;
-the actual number of groups found is returned in
+.Fa ngroups .
+The number of groups of the effective group list, which may be greater than the
+.Fa groups
+array's length, is returned through
.Fa ngroups .
.Sh RETURN VALUES
The
.Fn getgrouplist
-function
-returns 0 on success and \-1 if the size of the group list is too small to
-hold all the user's groups.
-Here, the group array will be filled with as many groups as will fit.
+function returns 0 on success and \-1 if the length of the group list is too
+small to hold all the user's groups.
+In the latter case, the
+.Fa groups
+array is filled with as many groups as possible from the start of the effective
+group list, and the length pointed to by
+.Fa ngroups
+is set to the full length of the latter, thus to a value strictly greater than
+before the call.
.Sh FILES
.Bl -tag -width /etc/group -compact
.It Pa /etc/group
group membership list
.El
.Sh SEE ALSO
+.Xr setcred 2 ,
.Xr setgroups 2 ,
.Xr initgroups 3
.Sh HISTORY
diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c
index 5bd06bc5121f..9c57b7031336 100644
--- a/lib/libc/gen/getgrouplist.c
+++ b/lib/libc/gen/getgrouplist.c
@@ -29,13 +29,8 @@
* SUCH DAMAGE.
*/
-/*
- * get credential
- */
#include <sys/types.h>
-#include <grp.h>
-#include <string.h>
#include <unistd.h>
#include <ssp/ssp.h>
@@ -46,4 +41,3 @@ __ssp_real(getgrouplist)(const char *uname, gid_t agroup, gid_t *groups, int *gr
{
return __getgroupmembership(uname, agroup, groups, *grpcnt, grpcnt);
}
-
diff --git a/lib/libc/gen/getvfsbyname.3 b/lib/libc/gen/getvfsbyname.3
index 23036429b27e..61fd48624fbd 100644
--- a/lib/libc/gen/getvfsbyname.3
+++ b/lib/libc/gen/getvfsbyname.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 16, 2018
+.Dd October 28, 2025
.Dt GETVFSBYNAME 3
.Os
.Sh NAME
@@ -102,6 +102,7 @@ argument
specifies a file system that is unknown or not configured in the kernel.
.El
.Sh SEE ALSO
+.Xr lsvfs 1 ,
.Xr jail 2 ,
.Xr mount 2 ,
.Xr sysctl 3 ,
diff --git a/lib/libc/gen/initgroups.3 b/lib/libc/gen/initgroups.3
index 03bd07494fc9..74133e7d7048 100644
--- a/lib/libc/gen/initgroups.3
+++ b/lib/libc/gen/initgroups.3
@@ -1,5 +1,13 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2025 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Olivier Certner
+.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+.\" Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -25,12 +33,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd October 26, 2014
+.Dd October 9, 2025
.Dt INITGROUPS 3
.Os
.Sh NAME
.Nm initgroups
-.Nd initialize group access list
+.Nd initialize supplementary groups as per the group database
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -40,19 +48,18 @@
.Sh DESCRIPTION
The
.Fn initgroups
-function
-uses the
-.Xr getgrouplist 3
-function to calculate the group access list for the user
-specified in
+function initializes the current process' supplementary groups as prescribed by
+its arguments and the system's group database.
+.Pp
+It first uses the
+.Fn getgrouplist
+function to compute a list of groups containing the passed
+.Fa basegid ,
+which typically is the user's initial numerical group ID from the password
+database, and the supplementary groups in the group database for the user named
.Fa name .
-This group list is then setup for the current process using
-.Xr setgroups 2 .
-The
-.Fa basegid
-is automatically included in the groups list.
-Typically this value is given as
-the group number from the password file.
+It then installs this list as the current process' supplementary groups using
+.Fn setgroups .
.Sh RETURN VALUES
.Rv -std initgroups
.Sh ERRORS
@@ -60,9 +67,9 @@ The
.Fn initgroups
function may fail and set
.Va errno
-for any of the errors specified for the library function
-.Xr setgroups 2 .
-It may also return:
+to any of the errors specified for the
+.Xr setgroups 2
+system call, or to:
.Bl -tag -width Er
.It Bq Er ENOMEM
The
@@ -77,3 +84,67 @@ The
.Fn initgroups
function appeared in
.Bx 4.2 .
+.Pp
+The
+.Fn initgroups
+function changed semantics in
+.Fx 15 ,
+following that of
+.Xr setgroups 2
+in the same release.
+Before that, it would also set the effective group ID to
+.Fa basegid ,
+and would not include the latter in the supplementary groups except before
+.Fx 8 .
+Its current behavior in these respects is known to be compatible with that of
+the following systems up to the specified versions that are current at time of
+this writing:
+.Bl -dash -width "-" -compact
+.It
+Linux (up to 6.6) with the GNU libc (up to 2.42)
+.It
+.Nx 1.1 and greater (up to 10)
+.It
+.Ox (up to 7.7)
+.It
+Systems based on illumos (up to August 2025 sources)
+.El
+.Sh SECURITY CONSIDERATIONS
+As
+.Fa basegid
+is typically the user's initial numerical group ID, to which the current
+process' effective group ID is generally initialized, processes using functions
+to change their effective group ID
+.Pq via Xr setgid 2 or similar
+or that are spawned from executables with the set-group-ID mode bit set will not
+be able to relinquish the access rights deriving from being a member of
+.Fa basegid ,
+as these functions do not change the supplementary groups.
+.Pp
+This behavior is generally desirable in order to paper over the difference of
+treatment between the effective group and supplementary ones in this situation,
+as they are all in the end indiscriminately used in traditional UNIX
+discretionary access checks.
+It blends well with the practice of allocating each user its own private group,
+as processes launched from a set-group-ID executable keep the same user and
+consistently stay also in the same user's group.
+Finally, it was also chosen for compatibility with other systems
+.Po
+see the
+.Sx HISTORY
+section
+.Pc .
+.Pp
+This convention of including
+.Fa basegid
+in the supplementary groups is however only enforced by the
+.Fn initgroups
+function, and not by the
+.Xr setgroups 2
+system call, so applications expressly wanting to include in the supplementary
+groups only those specified by the group database can themselves call
+.Fn getgrouplist
+and then
+.Fn setgroups
+on the result with the first element skipped
+.Pq see Xr getgrouplist 3 .
diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c
index b6697dd7ed8f..a1a7d92250e2 100644
--- a/lib/libc/gen/initgroups.c
+++ b/lib/libc/gen/initgroups.c
@@ -3,6 +3,11 @@
*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Olivier Certner
+ * <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+ * Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,34 +34,52 @@
* SUCH DAMAGE.
*/
-#include <sys/param.h>
+/* For __sym_compat(). */
+#include <sys/cdefs.h>
-#include "namespace.h"
-#include <err.h>
-#include "un-namespace.h"
#include <errno.h>
-#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-int
-initgroups(const char *uname, gid_t agroup)
+/* For freebsd14_setgroups(). */
+#include "gen-compat.h"
+
+static int
+initgroups_impl(const char *uname, gid_t agroup,
+ int (*setgroups)(int, const gid_t *))
{
- int ngroups, ret;
- long ngroups_max;
gid_t *groups;
+ long ngroups_max;
+ int ngroups, ret;
/*
- * Provide space for one group more than possible to allow
- * setgroups to fail and set errno.
+ * Provide space for one group more than possible to allow setgroups()
+ * to fail and set 'errno' in case we get back more than {NGROUPS_MAX} +
+ * 1 groups.
*/
ngroups_max = sysconf(_SC_NGROUPS_MAX) + 2;
- if ((groups = malloc(sizeof(*groups) * ngroups_max)) == NULL)
- return (ENOMEM);
+ groups = malloc(sizeof(*groups) * ngroups_max);
+ if (groups == NULL)
+ return (-1); /* malloc() set 'errno'. */
ngroups = (int)ngroups_max;
- getgrouplist(uname, agroup, groups, &ngroups);
- ret = setgroups(ngroups, groups);
+ (void)getgrouplist(uname, agroup, groups, &ngroups);
+ ret = (*setgroups)(ngroups, groups);
+
free(groups);
- return (ret);
+ return (ret); /* setgroups() set 'errno'. */
}
+
+int
+initgroups(const char *uname, gid_t agroup)
+{
+ return (initgroups_impl(uname, agroup, setgroups));
+}
+
+int
+freebsd14_initgroups(const char *uname, gid_t agroup)
+{
+ return (initgroups_impl(uname, agroup, freebsd14_setgroups));
+}
+
+__sym_compat(initgroups, freebsd14_initgroups, FBSD_1.0);
diff --git a/lib/libc/gen/jrand48.c b/lib/libc/gen/jrand48.c
index 0a9f780a9e5c..93442439d49e 100644
--- a/lib/libc/gen/jrand48.c
+++ b/lib/libc/gen/jrand48.c
@@ -11,14 +11,13 @@
* to anyone/anything when using this software.
*/
-#include <stdint.h>
-
#include "rand48.h"
long
jrand48(unsigned short xseed[3])
{
+ uint48 tmp;
- _dorand48(xseed);
- return ((int32_t)(((uint32_t)xseed[2] << 16) | (uint32_t)xseed[1]));
+ DORAND48(tmp, xseed);
+ return ((int)((tmp >> 16) & 0xffffffff));
}
diff --git a/lib/libc/gen/lcong48.c b/lib/libc/gen/lcong48.c
index f13826b3d3f3..871b2110ed94 100644
--- a/lib/libc/gen/lcong48.c
+++ b/lib/libc/gen/lcong48.c
@@ -13,18 +13,10 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-extern unsigned short _rand48_mult[3];
-extern unsigned short _rand48_add;
-
void
lcong48(unsigned short p[7])
{
- _rand48_seed[0] = p[0];
- _rand48_seed[1] = p[1];
- _rand48_seed[2] = p[2];
- _rand48_mult[0] = p[3];
- _rand48_mult[1] = p[4];
- _rand48_mult[2] = p[5];
+ LOADRAND48(_rand48_seed, &p[0]);
+ LOADRAND48(_rand48_mult, &p[3]);
_rand48_add = p[6];
}
diff --git a/lib/libc/gen/lrand48.c b/lib/libc/gen/lrand48.c
index a3d0111cf4d5..cc07044b8af9 100644
--- a/lib/libc/gen/lrand48.c
+++ b/lib/libc/gen/lrand48.c
@@ -13,11 +13,9 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-
long
lrand48(void)
{
- _dorand48(_rand48_seed);
- return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1);
+ _DORAND48(_rand48_seed);
+ return (_rand48_seed >> 17) & 0x7fffffff;
}
diff --git a/lib/libc/gen/mrand48.c b/lib/libc/gen/mrand48.c
index 15b0bfb1bd6e..f9128a6d4188 100644
--- a/lib/libc/gen/mrand48.c
+++ b/lib/libc/gen/mrand48.c
@@ -15,13 +15,9 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-
long
mrand48(void)
{
-
- _dorand48(_rand48_seed);
- return ((int32_t)(((uint32_t)_rand48_seed[2] << 16) |
- (uint32_t)_rand48_seed[1]));
+ _DORAND48(_rand48_seed);
+ return ((int)((_rand48_seed >> 16) & 0xffffffff));
}
diff --git a/lib/libc/gen/nrand48.c b/lib/libc/gen/nrand48.c
index 6c54065e7e0f..f6f4e231105c 100644
--- a/lib/libc/gen/nrand48.c
+++ b/lib/libc/gen/nrand48.c
@@ -16,6 +16,8 @@
long
nrand48(unsigned short xseed[3])
{
- _dorand48(xseed);
- return ((long) xseed[2] << 15) + ((long) xseed[1] >> 1);
+ uint48 tmp;
+
+ DORAND48(tmp, xseed);
+ return ((tmp >> 17) & 0x7fffffff);
}
diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3
index 098b7b02a9b9..bf6a99b4b113 100644
--- a/lib/libc/gen/psignal.3
+++ b/lib/libc/gen/psignal.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 10, 2025
+.Dd September 23, 2025
.Dt PSIGNAL 3
.Os
.Sh NAME
@@ -141,6 +141,13 @@ The name in
can be either the name of the signal, with or without the
.Dq SIG
prefix, or a decimal number.
+.Sh RETURN VALUES
+The
+.Fn sig2str
+and
+.Fn str2sig
+return 0 on success and -1 on translation failure.
+In the latter case the memory to store the translation result is left intact.
.Sh SEE ALSO
.Xr sigaction 2 ,
.Xr perror 3 ,
diff --git a/lib/libc/gen/rand48.3 b/lib/libc/gen/rand48.3
index 1e47c843058e..3ea649354270 100644
--- a/lib/libc/gen/rand48.3
+++ b/lib/libc/gen/rand48.3
@@ -9,7 +9,7 @@
.\" of any kind. I shall in no event be liable for anything that happens
.\" to anyone/anything when using this software.
.\"
-.Dd September 4, 2012
+.Dd September 11, 2025
.Dt RAND48 3
.Os
.Sh NAME
@@ -183,5 +183,8 @@ generator calls.
.Xr arc4random 3 ,
.Xr rand 3 ,
.Xr random 3
+.Sh STANDARDS
+The functions described in this page are expected to conform to
+.St -p1003.1-2008 .
.Sh AUTHORS
.An Martin Birgmeier
diff --git a/lib/libc/gen/rand48.h b/lib/libc/gen/rand48.h
index 9861e99683cb..d3326e851491 100644
--- a/lib/libc/gen/rand48.h
+++ b/lib/libc/gen/rand48.h
@@ -14,10 +14,11 @@
#ifndef _RAND48_H_
#define _RAND48_H_
+#include <sys/types.h>
#include <math.h>
#include <stdlib.h>
-void _dorand48(unsigned short[3]);
+#include "fpmath.h"
#define RAND48_SEED_0 (0x330e)
#define RAND48_SEED_1 (0xabcd)
@@ -27,4 +28,62 @@ void _dorand48(unsigned short[3]);
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
+typedef uint64_t uint48;
+
+extern uint48 _rand48_seed;
+extern uint48 _rand48_mult;
+extern uint48 _rand48_add;
+
+#define TOUINT48(x, y, z) \
+ ((uint48)(x) + (((uint48)(y)) << 16) + (((uint48)(z)) << 32))
+
+#define RAND48_SEED TOUINT48(RAND48_SEED_0, RAND48_SEED_1, RAND48_SEED_2)
+#define RAND48_MULT TOUINT48(RAND48_MULT_0, RAND48_MULT_1, RAND48_MULT_2)
+
+#define LOADRAND48(l, x) do { \
+ (l) = TOUINT48((x)[0], (x)[1], (x)[2]); \
+} while (0)
+
+#define STORERAND48(l, x) do { \
+ (x)[0] = (unsigned short)(l); \
+ (x)[1] = (unsigned short)((l) >> 16); \
+ (x)[2] = (unsigned short)((l) >> 32); \
+} while (0)
+
+#define _DORAND48(l) do { \
+ (l) = (l) * _rand48_mult + _rand48_add; \
+} while (0)
+
+#define DORAND48(l, x) do { \
+ LOADRAND48(l, x); \
+ _DORAND48(l); \
+ STORERAND48(l, x); \
+} while (0)
+
+#define ERAND48_BEGIN \
+ union { \
+ union IEEEd2bits ieee; \
+ uint64_t u64; \
+ } u; \
+ int s
+
+/*
+ * Optimization for speed: assume doubles are IEEE 754 and use bit fiddling
+ * rather than converting to double. Specifically, clamp the result to 48 bits
+ * and convert to a double in [0.0, 1.0) via division by 2^48. Normalize by
+ * shifting the most significant bit into the implicit one position and
+ * adjusting the exponent accordingly. The store to the exponent field
+ * overwrites the implicit one.
+ */
+#define ERAND48_END(x) do { \
+ u.u64 = ((x) & 0xffffffffffffULL); \
+ if (u.u64 == 0) \
+ return (0.0); \
+ u.u64 <<= 5; \
+ for (s = 0; !(u.u64 & (1LL << 52)); s++, u.u64 <<= 1) \
+ ; \
+ u.ieee.bits.exp = 1022 - s; \
+ return (u.ieee.d); \
+} while (0)
+
#endif /* _RAND48_H_ */
diff --git a/lib/libc/gen/seed48.c b/lib/libc/gen/seed48.c
index 258c4bac3c9f..f57656ce1121 100644
--- a/lib/libc/gen/seed48.c
+++ b/lib/libc/gen/seed48.c
@@ -13,24 +13,14 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-extern unsigned short _rand48_mult[3];
-extern unsigned short _rand48_add;
-
unsigned short *
seed48(unsigned short xseed[3])
{
static unsigned short sseed[3];
- sseed[0] = _rand48_seed[0];
- sseed[1] = _rand48_seed[1];
- sseed[2] = _rand48_seed[2];
- _rand48_seed[0] = xseed[0];
- _rand48_seed[1] = xseed[1];
- _rand48_seed[2] = xseed[2];
- _rand48_mult[0] = RAND48_MULT_0;
- _rand48_mult[1] = RAND48_MULT_1;
- _rand48_mult[2] = RAND48_MULT_2;
+ STORERAND48(_rand48_seed, sseed);
+ LOADRAND48(_rand48_seed, xseed);
+ _rand48_mult = RAND48_MULT;
_rand48_add = RAND48_ADD;
- return sseed;
+ return (sseed);
}
diff --git a/lib/libc/gen/srand48.c b/lib/libc/gen/srand48.c
index fd369a094c51..4b82ece72db8 100644
--- a/lib/libc/gen/srand48.c
+++ b/lib/libc/gen/srand48.c
@@ -13,18 +13,11 @@
#include "rand48.h"
-extern unsigned short _rand48_seed[3];
-extern unsigned short _rand48_mult[3];
-extern unsigned short _rand48_add;
-
void
srand48(long seed)
{
- _rand48_seed[0] = RAND48_SEED_0;
- _rand48_seed[1] = (unsigned short) seed;
- _rand48_seed[2] = (unsigned short) (seed >> 16);
- _rand48_mult[0] = RAND48_MULT_0;
- _rand48_mult[1] = RAND48_MULT_1;
- _rand48_mult[2] = RAND48_MULT_2;
+ _rand48_seed = TOUINT48(RAND48_SEED_0, (unsigned short)seed,
+ (unsigned short)(seed >> 16));
+ _rand48_mult = RAND48_MULT;
_rand48_add = RAND48_ADD;
}
diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3
index e38357b898a7..290ef0dc158c 100644
--- a/lib/libc/gen/sysconf.3
+++ b/lib/libc/gen/sysconf.3
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 26, 2013
+.Dd August 30, 2025
.Dt SYSCONF 3
.Os
.Sh NAME
@@ -77,7 +77,9 @@ The maximum number of supplemental groups.
.It Li _SC_NPROCESSORS_CONF
The number of processors configured.
.It Li _SC_NPROCESSORS_ONLN
-The number of processors currently online.
+The number of processors currently online, taking into account current jail
+restrictions to report only the number of processors that are usable to the
+process.
.It Li _SC_OPEN_MAX
One more than the maximum value the system may assign to a new file descriptor.
.It Li _SC_PAGESIZE
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 66562d0e29f0..87aedc07c110 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -51,7 +51,7 @@
#include "un-namespace.h"
#include "../stdlib/atexit.h"
-#include "tzdir.h" /* from ../../../contrib/tzcode/stdtime */
+#include "tzdir.h" /* from ../../../contrib/tzcode */
#include "libc_private.h"
#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
@@ -72,6 +72,7 @@ long
sysconf(int name)
{
struct rlimit rl;
+ cpuset_t cpus;
size_t len;
int mib[2], sverrno, value;
long lvalue, defaultresult;
@@ -581,8 +582,21 @@ yesno:
return (_POSIX_IPV6);
#endif
- case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
+ /*
+ * Consult our root set first, because our CPU availability
+ * may not match the total number of CPUs available on the
+ * system and we may have a non-uniform layout even within
+ * userland. In particular, each jail has a root set that can
+ * be constrained by its parent and processes within the jail
+ * cannot widen beyond those constraints, so to those processes
+ * it makes sense to claim the more limited count.
+ */
+ if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1,
+ sizeof(cpus), &cpus) == 0)
+ return (CPU_COUNT(&cpus));
+ /* FALLTHROUGH */
+ case _SC_NPROCESSORS_CONF:
if (_elf_aux_info(AT_NCPUS, &value, sizeof(value)) == 0)
return ((long)value);
mib[0] = CTL_HW;
diff --git a/lib/libc/include/compat.h b/lib/libc/include/compat.h
index 97f22607ddd7..630ffe7daae3 100644
--- a/lib/libc/include/compat.h
+++ b/lib/libc/include/compat.h
@@ -80,4 +80,3 @@ __sym_compat(setgroups, freebsd14_setgroups, FBSD_1.0);
#undef __weak_reference
#endif /* __LIBC_COMPAT_H__ */
-
diff --git a/lib/libc/include/port_before.h b/lib/libc/include/port_before.h
index cfc43c53f157..aa2cd394104a 100644
--- a/lib/libc/include/port_before.h
+++ b/lib/libc/include/port_before.h
@@ -5,7 +5,6 @@
#define _LIBC 1
#define DO_PTHREADS 1
#define USE_POLL 1
-#define HAVE_MD5 1
#define ISC_SOCKLEN_T socklen_t
#define ISC_FORMAT_PRINTF(fmt, args) \
diff --git a/lib/libc/inet/inet_net_ntop.c b/lib/libc/inet/inet_net_ntop.c
index 9d98dbb5ca99..30dd5c0571f2 100644
--- a/lib/libc/inet/inet_net_ntop.c
+++ b/lib/libc/inet/inet_net_ntop.c
@@ -1,20 +1,23 @@
-/*-
- * SPDX-License-Identifier: ISC
+/* $OpenBSD: inet_net_ntop.c,v 1.9 2019/07/03 03:24:04 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org>
+ * Copyright (c) 1996 by Internet Software Consortium.
*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1996,1999 by Internet Software Consortium.
+ * SPDX-License-Identifier: ISC
*
* 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.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
*/
#include "port_before.h"
@@ -31,18 +34,10 @@
#include "port_after.h"
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-static char * inet_net_ntop_ipv4(const u_char *src, int bits, char *dst,
- size_t size);
-static char * inet_net_ntop_ipv6(const u_char *src, int bits, char *dst,
- size_t size);
+static char *inet_net_ntop_ipv4(const u_char *, int, char *, size_t);
+static char *inet_net_ntop_ipv6(const u_char *, int, char *, size_t);
-/*%
+/*
* char *
* inet_net_ntop(af, src, bits, dst, size)
* convert network number from network to presentation format.
@@ -66,7 +61,7 @@ inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
}
}
-/*%
+/*
* static char *
* inet_net_ntop_ipv4(src, bits, dst, size)
* convert IPv4 network number from network to presentation format.
@@ -83,53 +78,63 @@ static char *
inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
{
char *odst = dst;
- char *t;
u_int m;
int b;
+ char *ep;
+ int advance;
+
+ ep = dst + size;
+ if (ep <= dst)
+ goto emsgsize;
if (bits < 0 || bits > 32) {
errno = EINVAL;
return (NULL);
}
-
if (bits == 0) {
- if (size < sizeof "0")
+ if (ep - dst < sizeof "0")
goto emsgsize;
*dst++ = '0';
- size--;
*dst = '\0';
}
/* Format whole octets. */
for (b = bits / 8; b > 0; b--) {
- if (size <= sizeof "255.")
+ if (ep - dst < sizeof "255.")
+ goto emsgsize;
+ advance = snprintf(dst, ep - dst, "%u", *src++);
+ if (advance <= 0 || advance >= ep - dst)
goto emsgsize;
- t = dst;
- dst += SPRINTF((dst, "%u", *src++));
+ dst += advance;
if (b > 1) {
+ if (dst + 1 >= ep)
+ goto emsgsize;
*dst++ = '.';
*dst = '\0';
}
- size -= (size_t)(dst - t);
}
/* Format partial octet. */
b = bits % 8;
if (b > 0) {
- if (size <= sizeof ".255")
+ if (ep - dst < sizeof ".255")
goto emsgsize;
- t = dst;
if (dst != odst)
*dst++ = '.';
m = ((1 << b) - 1) << (8 - b);
- dst += SPRINTF((dst, "%u", *src & m));
- size -= (size_t)(dst - t);
+ advance = snprintf(dst, ep - dst, "%u", *src & m);
+ if (advance <= 0 || advance >= ep - dst)
+ goto emsgsize;
+ dst += advance;
}
/* Format CIDR /width. */
- if (size <= sizeof "/32")
+ if (ep - dst < sizeof "/32")
+ goto emsgsize;
+ advance = snprintf(dst, ep - dst, "/%u", bits);
+ if (advance <= 0 || advance >= ep - dst)
goto emsgsize;
- dst += SPRINTF((dst, "/%u", bits));
+ dst += advance;
return (odst);
emsgsize:
@@ -137,132 +142,27 @@ inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
return (NULL);
}
-/*%
- * static char *
- * inet_net_ntop_ipv6(src, bits, fakebits, dst, size)
- * convert IPv6 network number from network to presentation format.
- * generates CIDR style result always. Picks the shortest representation
- * unless the IP is really IPv4.
- * always prints specified number of bits (bits).
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * note:
- * network byte order assumed. this means 192.5.5.240/28 has
- * 0b11110000 in its fourth octet.
- * author:
- * Vadim Kogan (UCB), June 2001
- * Original version (IPv4) by Paul Vixie (ISC), July 1996
- */
-
static char *
-inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) {
- u_int m;
- int b;
- int p;
- int zero_s, zero_l, tmp_zero_s, tmp_zero_l;
- int i;
- int is_ipv4 = 0;
- unsigned char inbuf[16];
- char outbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
- char *cp;
- int words;
- u_char *s;
+inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
+{
+ int ret;
+ char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")];
if (bits < 0 || bits > 128) {
errno = EINVAL;
return (NULL);
}
- cp = outbuf;
-
- if (bits == 0) {
- *cp++ = ':';
- *cp++ = ':';
- *cp = '\0';
- } else {
- /* Copy src to private buffer. Zero host part. */
- p = (bits + 7) / 8;
- memcpy(inbuf, src, p);
- memset(inbuf + p, 0, 16 - p);
- b = bits % 8;
- if (b != 0) {
- m = ~0 << (8 - b);
- inbuf[p-1] &= m;
- }
-
- s = inbuf;
-
- /* how many words need to be displayed in output */
- words = (bits + 15) / 16;
- if (words == 1)
- words = 2;
-
- /* Find the longest substring of zero's */
- zero_s = zero_l = tmp_zero_s = tmp_zero_l = 0;
- for (i = 0; i < (words * 2); i += 2) {
- if ((s[i] | s[i+1]) == 0) {
- if (tmp_zero_l == 0)
- tmp_zero_s = i / 2;
- tmp_zero_l++;
- } else {
- if (tmp_zero_l && zero_l < tmp_zero_l) {
- zero_s = tmp_zero_s;
- zero_l = tmp_zero_l;
- tmp_zero_l = 0;
- }
- }
- }
-
- if (tmp_zero_l && zero_l < tmp_zero_l) {
- zero_s = tmp_zero_s;
- zero_l = tmp_zero_l;
- }
-
- if (zero_l != words && zero_s == 0 && ((zero_l == 6) ||
- ((zero_l == 5 && s[10] == 0xff && s[11] == 0xff) ||
- ((zero_l == 7 && s[14] != 0 && s[15] != 1)))))
- is_ipv4 = 1;
-
- /* Format whole words. */
- for (p = 0; p < words; p++) {
- if (zero_l != 0 && p >= zero_s && p < zero_s + zero_l) {
- /* Time to skip some zeros */
- if (p == zero_s)
- *cp++ = ':';
- if (p == words - 1)
- *cp++ = ':';
- s++;
- s++;
- continue;
- }
+ if (inet_ntop(AF_INET6, src, buf, size) == NULL)
+ return (NULL);
- if (is_ipv4 && p > 5 ) {
- *cp++ = (p == 6) ? ':' : '.';
- cp += SPRINTF((cp, "%u", *s++));
- /* we can potentially drop the last octet */
- if (p != 7 || bits > 120) {
- *cp++ = '.';
- cp += SPRINTF((cp, "%u", *s++));
- }
- } else {
- if (cp != outbuf)
- *cp++ = ':';
- cp += SPRINTF((cp, "%x", *s * 256 + s[1]));
- s += 2;
- }
- }
+ ret = snprintf(dst, size, "%s/%d", buf, bits);
+ if (ret < 0 || ret >= size) {
+ errno = EMSGSIZE;
+ return (NULL);
}
- /* Format CIDR /width. */
- sprintf(cp, "/%u", bits);
- if (strlen(outbuf) + 1 > size)
- goto emsgsize;
- strcpy(dst, outbuf);
return (dst);
-
-emsgsize:
- errno = EMSGSIZE;
- return (NULL);
}
/*
@@ -271,5 +171,3 @@ emsgsize:
*/
#undef inet_net_ntop
__weak_reference(__inet_net_ntop, inet_net_ntop);
-
-/*! \file */
diff --git a/lib/libc/inet/inet_net_pton.c b/lib/libc/inet/inet_net_pton.c
index d566a0e1d3c3..14c88eb72014 100644
--- a/lib/libc/inet/inet_net_pton.c
+++ b/lib/libc/inet/inet_net_pton.c
@@ -1,20 +1,23 @@
-/*-
- * SPDX-License-Identifier: ISC
+/* $OpenBSD: inet_net_pton.c,v 1.14 2022/12/27 17:10:06 jmc Exp $ */
+
+/*
+ * Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org>
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
*
- * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1996, 1998, 1999, 2001, 2003 Internet Software Consortium.
+ * SPDX-License-Identifier: ISC
*
- * Permission to use, copy, modify, and/or distribute this software for any
+ * 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.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
*/
#include "port_before.h"
@@ -22,7 +25,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include <arpa/nameser.h>
#include <arpa/inet.h>
#include <assert.h>
@@ -34,13 +36,37 @@
#include "port_after.h"
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
+static int inet_net_pton_ipv4(const char *, u_char *, size_t);
+static int inet_net_pton_ipv6(const char *, u_char *, size_t);
-/*%
+/*
+ * static int
+ * inet_net_pton(af, src, dst, size)
+ * convert network number from presentation to network format.
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
+ * "size" is in bytes and describes "dst".
+ * return:
+ * number of bits, either imputed classfully or specified with /CIDR,
+ * or -1 if some failure occurred (check errno). ENOENT means it was
+ * not a valid network specification.
+ * author:
+ * Paul Vixie (ISC), June 1996
+ */
+int
+inet_net_pton(int af, const char *src, void *dst, size_t size)
+{
+ switch (af) {
+ case AF_INET:
+ return (inet_net_pton_ipv4(src, dst, size));
+ case AF_INET6:
+ return (inet_net_pton_ipv6(src, dst, size));
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+}
+
+/*
* static int
* inet_net_pton_ipv4(src, dst, size)
* convert IPv4 network number from presentation to network format.
@@ -57,22 +83,24 @@
* Paul Vixie (ISC), June 1996
*/
static int
-inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
- static const char xdigits[] = "0123456789abcdef";
- static const char digits[] = "0123456789";
- int n, ch, tmp = 0, dirty, bits;
+inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
+{
+ static const char
+ xdigits[] = "0123456789abcdef",
+ digits[] = "0123456789";
+ int n, ch, tmp, dirty, bits;
const u_char *odst = dst;
- ch = *src++;
+ ch = (unsigned char)*src++;
if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
- && isascii((unsigned char)(src[1]))
- && isxdigit((unsigned char)(src[1]))) {
+ && isascii((unsigned char)src[1]) && isxdigit((unsigned char)src[1])) {
/* Hexadecimal: Eat nybble string. */
- if (size <= 0U)
+ if (size == 0)
goto emsgsize;
- dirty = 0;
- src++; /*%< skip x or X. */
- while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) {
+ tmp = 0, dirty = 0;
+ src++; /* skip x or X. */
+ while ((ch = (unsigned char)*src++) != '\0' &&
+ isascii(ch) && isxdigit(ch)) {
if (isupper(ch))
ch = tolower(ch);
n = strchr(xdigits, ch) - xdigits;
@@ -82,14 +110,14 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
else
tmp = (tmp << 4) | n;
if (++dirty == 2) {
- if (size-- <= 0U)
+ if (size-- == 0)
goto emsgsize;
*dst++ = (u_char) tmp;
dirty = 0;
}
}
- if (dirty) { /*%< Odd trailing nybble? */
- if (size-- <= 0U)
+ if (dirty) { /* Odd trailing nybble? */
+ if (size-- == 0)
goto emsgsize;
*dst++ = (u_char) (tmp << 4);
}
@@ -104,16 +132,16 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
tmp += n;
if (tmp > 255)
goto enoent;
- } while ((ch = *src++) != '\0' &&
+ } while ((ch = (unsigned char)*src++) != '\0' &&
isascii(ch) && isdigit(ch));
- if (size-- <= 0U)
+ if (size-- == 0)
goto emsgsize;
*dst++ = (u_char) tmp;
if (ch == '\0' || ch == '/')
break;
if (ch != '.')
goto enoent;
- ch = *src++;
+ ch = (unsigned char)*src++;
if (!isascii(ch) || !isdigit(ch))
goto enoent;
}
@@ -121,10 +149,10 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
goto enoent;
bits = -1;
- if (ch == '/' && isascii((unsigned char)(src[0])) &&
- isdigit((unsigned char)(src[0])) && dst > odst) {
+ if (ch == '/' && isascii((unsigned char)src[0]) &&
+ isdigit((unsigned char)src[0]) && dst > odst) {
/* CIDR width specifier. Nothing can follow it. */
- ch = *src++; /*%< Skip over the /. */
+ ch = (unsigned char)*src++; /* Skip over the /. */
bits = 0;
do {
n = strchr(digits, ch) - digits;
@@ -132,8 +160,9 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
bits *= 10;
bits += n;
if (bits > 32)
- goto enoent;
- } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
+ goto emsgsize;
+ } while ((ch = (unsigned char)*src++) != '\0' &&
+ isascii(ch) && isdigit(ch));
if (ch != '\0')
goto enoent;
}
@@ -147,29 +176,23 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
goto enoent;
/* If no CIDR spec was given, infer width from net class. */
if (bits == -1) {
- if (*odst >= 240) /*%< Class E */
+ if (*odst >= 240) /* Class E */
bits = 32;
- else if (*odst >= 224) /*%< Class D */
- bits = 8;
- else if (*odst >= 192) /*%< Class C */
+ else if (*odst >= 224) /* Class D */
+ bits = 4;
+ else if (*odst >= 192) /* Class C */
bits = 24;
- else if (*odst >= 128) /*%< Class B */
+ else if (*odst >= 128) /* Class B */
bits = 16;
- else /*%< Class A */
+ else /* Class A */
bits = 8;
/* If imputed mask is narrower than specified octets, widen. */
if (bits < ((dst - odst) * 8))
bits = (dst - odst) * 8;
- /*
- * If there are no additional bits specified for a class D
- * address adjust bits to 4.
- */
- if (bits == 8 && *odst == 224)
- bits = 4;
}
/* Extend network to cover the actual mask. */
while (bits > ((dst - odst) * 8)) {
- if (size-- <= 0U)
+ if (size-- == 0)
goto emsgsize;
*dst++ = '\0';
}
@@ -184,222 +207,48 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) {
return (-1);
}
-static int
-getbits(const char *src, int *bitsp) {
- static const char digits[] = "0123456789";
- int n;
- int val;
- char ch;
-
- val = 0;
- n = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- pch = strchr(digits, ch);
- if (pch != NULL) {
- if (n++ != 0 && val == 0) /*%< no leading zeros */
- return (0);
- val *= 10;
- val += (pch - digits);
- if (val > 128) /*%< range */
- return (0);
- continue;
- }
- return (0);
- }
- if (n == 0)
- return (0);
- *bitsp = val;
- return (1);
-}
static int
-getv4(const char *src, u_char *dst, int *bitsp) {
- static const char digits[] = "0123456789";
- u_char *odst = dst;
- int n;
- u_int val;
- char ch;
-
- val = 0;
- n = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
+inet_net_pton_ipv6(const char *src, u_char *dst, size_t size)
+{
+ struct in6_addr in6;
+ int ret;
+ int bits;
+ size_t bytes;
+ char buf[INET6_ADDRSTRLEN + sizeof("/128")];
+ char *sep;
+ const char *errstr;
- pch = strchr(digits, ch);
- if (pch != NULL) {
- if (n++ != 0 && val == 0) /*%< no leading zeros */
- return (0);
- val *= 10;
- val += (pch - digits);
- if (val > 255) /*%< range */
- return (0);
- continue;
- }
- if (ch == '.' || ch == '/') {
- if (dst - odst > 3) /*%< too many octets? */
- return (0);
- *dst++ = val;
- if (ch == '/')
- return (getbits(src, bitsp));
- val = 0;
- n = 0;
- continue;
- }
- return (0);
+ if (strlcpy(buf, src, sizeof buf) >= sizeof buf) {
+ errno = EMSGSIZE;
+ return (-1);
}
- if (n == 0)
- return (0);
- if (dst - odst > 3) /*%< too many octets? */
- return (0);
- *dst++ = val;
- return (1);
-}
-static int
-inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) {
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- u_int val;
- int digits;
- int bits;
- size_t bytes;
- int words;
- int ipv4;
+ sep = strchr(buf, '/');
+ if (sep != NULL)
+ *sep++ = '\0';
- memset((tp = tmp), '\0', NS_IN6ADDRSZ);
- endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- goto enoent;
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- digits = 0;
- bits = -1;
- ipv4 = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
+ ret = inet_pton(AF_INET6, buf, &in6);
+ if (ret != 1)
+ return (-1);
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (++digits > 4)
- goto enoent;
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- goto enoent;
- colonp = tp;
- continue;
- } else if (*src == '\0')
- goto enoent;
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- saw_xdigit = 0;
- digits = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
- getv4(curtok, tp, &bits) > 0) {
- tp += NS_INADDRSZ;
- saw_xdigit = 0;
- ipv4 = 1;
- break; /*%< '\\0' was seen by inet_pton4(). */
- }
- if (ch == '/' && getbits(src, &bits) > 0)
- break;
- goto enoent;
- }
- if (saw_xdigit) {
- if (tp + NS_INT16SZ > endp)
- goto enoent;
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- }
- if (bits == -1)
+ if (sep == NULL)
bits = 128;
-
- words = (bits + 15) / 16;
- if (words < 2)
- words = 2;
- if (ipv4)
- words = 8;
- endp = tmp + 2 * words;
-
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
-
- if (tp == endp)
- goto enoent;
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
+ else {
+ bits = strtonum(sep, 0, 128, &errstr);
+ if (errstr) {
+ errno = EINVAL;
+ return (-1);
}
- tp = endp;
}
- if (tp != endp)
- goto enoent;
bytes = (bits + 7) / 8;
- if (bytes > size)
- goto emsgsize;
- memcpy(dst, tmp, bytes);
- return (bits);
-
- enoent:
- errno = ENOENT;
- return (-1);
-
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
-}
-
-/*%
- * int
- * inet_net_pton(af, src, dst, size)
- * convert network number from presentation to network format.
- * accepts hex octets, hex strings, decimal octets, and /CIDR.
- * "size" is in bytes and describes "dst".
- * return:
- * number of bits, either imputed classfully or specified with /CIDR,
- * or -1 if some failure occurred (check errno). ENOENT means it was
- * not a valid network specification.
- * author:
- * Paul Vixie (ISC), June 1996
- */
-int
-inet_net_pton(int af, const char *src, void *dst, size_t size) {
- switch (af) {
- case AF_INET:
- return (inet_net_pton_ipv4(src, dst, size));
- case AF_INET6:
- return (inet_net_pton_ipv6(src, dst, size));
- default:
- errno = EAFNOSUPPORT;
+ if (bytes > size) {
+ errno = EMSGSIZE;
return (-1);
}
+ memcpy(dst, &in6.s6_addr, bytes);
+ return (bits);
}
/*
@@ -408,5 +257,3 @@ inet_net_pton(int af, const char *src, void *dst, size_t size) {
*/
#undef inet_net_pton
__weak_reference(__inet_net_pton, inet_net_pton);
-
-/*! \file */
diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc
index 33caafc5c10a..127f8fc67abc 100644
--- a/lib/libc/locale/Makefile.inc
+++ b/lib/libc/locale/Makefile.inc
@@ -46,7 +46,7 @@ MAN+= btowc.3 \
wctrans.3 wctype.3 wcwidth.3 \
duplocale.3 freelocale.3 newlocale.3 querylocale.3 uselocale.3 xlocale.3
-MAN+= big5.5 euc.5 gb18030.5 gb2312.5 gbk.5 mskanji.5 utf8.5
+MANNODEV+= big5.5 euc.5 gb18030.5 gb2312.5 gbk.5 mskanji.5 utf8.5
MLINKS+=btowc.3 wctob.3
MLINKS+=digittoint.3 digittoint_l.3
diff --git a/lib/libc/locale/xlocale_private.h b/lib/libc/locale/xlocale_private.h
index ef1a8687a376..4cb323d5fa4c 100644
--- a/lib/libc/locale/xlocale_private.h
+++ b/lib/libc/locale/xlocale_private.h
@@ -200,11 +200,9 @@ extern _Thread_local locale_t __thread_locale;
*/
static inline locale_t __get_locale(void)
{
-
- if (!__has_thread_locale) {
+ if (!__has_thread_locale || __thread_locale == NULL)
return (&__xlocale_global_locale);
- }
- return (__thread_locale ? __thread_locale : &__xlocale_global_locale);
+ return (__thread_locale);
}
/**
diff --git a/lib/libc/md/Makefile.inc b/lib/libc/md/Makefile.inc
deleted file mode 100644
index 82c5f0670485..000000000000
--- a/lib/libc/md/Makefile.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-.PATH: ${SRCTOP}/sys/kern
-
-SRCS+= md5c.c
diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc
index f26e04c187a5..c211026aba72 100644
--- a/lib/libc/nls/Makefile.inc
+++ b/lib/libc/nls/Makefile.inc
@@ -12,6 +12,11 @@ MAN+= catclose.3 catgets.3 catopen.3
# for translators.
NLSNAME= libc
+# We don't want libc's NLS catalogues to be installed in the clibs package.
+# Put them in locales instead, since anyone interested in NLS will have
+# that installed.
+NLSPACKAGE= locales
+
NLS+= be_BY.UTF-8
NLS+= ca_ES.ISO8859-1
NLS+= de_DE.ISO8859-1
diff --git a/lib/libc/posix1e/Makefile.inc b/lib/libc/posix1e/Makefile.inc
index 934998cdd092..48f6c1ddf884 100644
--- a/lib/libc/posix1e/Makefile.inc
+++ b/lib/libc/posix1e/Makefile.inc
@@ -84,7 +84,6 @@ MAN+= acl.3 \
acl_valid.3 \
extattr.3 \
mac.3 \
- mac.conf.5 \
mac_free.3 \
mac_is_present.3 \
mac_get.3 \
@@ -134,4 +133,6 @@ MLINKS+=acl_create_entry.3 acl_create_entry_np.3\
mac_text.3 mac_from_text.3 \
mac_text.3 mac_to_text.3
+MANNODEV+= mac.conf.5
+
CLEANFILES+= subr_acl_nfs4.c
diff --git a/lib/libc/posix1e/mac_free.3 b/lib/libc/posix1e/mac_free.3
index 4ed68b70f3a3..6674ca2e9094 100644
--- a/lib/libc/posix1e/mac_free.3
+++ b/lib/libc/posix1e/mac_free.3
@@ -31,7 +31,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd September 21, 2023
+.Dd October 26, 2025
.Dt MAC_FREE 3
.Os
.Sh NAME
@@ -85,7 +85,7 @@ is a complex structure in the
implementation,
.Fn mac_free
is specific to
-.Vt mac_3 ,
+.Vt mac_t ,
and must not be used to free the character strings returned from
.Fn mac_to_text .
Doing so may result in undefined behavior.
diff --git a/lib/libc/posix1e/mac_text.3 b/lib/libc/posix1e/mac_text.3
index 29c1aacca485..7633f4b0da64 100644
--- a/lib/libc/posix1e/mac_text.3
+++ b/lib/libc/posix1e/mac_text.3
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd September 21, 2023
+.Dd October 26, 2025
.Dt MAC_TEXT 3
.Os
.Sh NAME
@@ -52,14 +52,16 @@ into the internal policy label format
and places it in
.Fa *mac ,
which must later be freed with
-.Xr free 3 .
+.Xr mac_free 3 .
.Pp
The
.Fn mac_to_text
function allocates storage for
.Fa *text ,
which will be set to the text representation of
-.Fa label .
+.Fa label
+and must later be freed with
+.Xr free 3 .
.Pp
Refer to
.Xr maclabel 7
diff --git a/lib/libc/regex/Makefile.inc b/lib/libc/regex/Makefile.inc
index 89468f1317f6..e3417a3d9983 100644
--- a/lib/libc/regex/Makefile.inc
+++ b/lib/libc/regex/Makefile.inc
@@ -9,9 +9,9 @@ SYM_MAPS+=${LIBC_SRCTOP}/regex/Symbol.map
# manpages only included in libc version
.if ${LIB} == "c"
-MAN+= regex.3
-MAN+= re_format.7
+MAN+= regex.3
+MLINKS+= regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3
+MLINKS+= regexec.3 regfree.3
-MLINKS+=regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3
-MLINKS+=regexec.3 regfree.3
+MANNODEV+= re_format.7
.endif
diff --git a/lib/libc/resolv/Symbol.map b/lib/libc/resolv/Symbol.map
index 6b9c43298fb5..26daecbe2eff 100644
--- a/lib/libc/resolv/Symbol.map
+++ b/lib/libc/resolv/Symbol.map
@@ -103,6 +103,5 @@ FBSD_1.0 {
};
FBSD_1.4 {
- __res_rndinit;
__res_nrandomid;
};
diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c
index 71ab2dcb7038..5a2fce013c8c 100644
--- a/lib/libc/resolv/res_init.c
+++ b/lib/libc/resolv/res_init.c
@@ -86,19 +86,6 @@
#include <unistd.h>
#include <netdb.h>
-#ifndef HAVE_MD5
-# include "../dst/md5.h"
-#else
-# ifdef SOLARIS2
-# include <sys/md5.h>
-# elif _LIBC
-# include <md5.h>
-# endif
-#endif
-#ifndef _MD5_H_
-# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */
-#endif
-
#include "un-namespace.h"
#include "port_after.h"
@@ -184,8 +171,6 @@ __res_vinit(res_state statp, int preinit) {
statp->options = RES_DEFAULT;
}
- statp->_rnd = malloc(16);
- res_rndinit(statp);
statp->id = res_nrandomid(statp);
memset(u, 0, sizeof(u));
@@ -733,48 +718,18 @@ net_mask(struct in_addr in) /*!< XXX - should really use system's version of th
}
#endif
-static u_char srnd[16];
-
void
-res_rndinit(res_state statp)
+freebsd15_res_rndinit(res_state statp)
{
- struct timeval now;
- u_int32_t u32;
- u_int16_t u16;
- u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;
-
- gettimeofday(&now, NULL);
- u32 = now.tv_sec;
- memcpy(rnd, &u32, 4);
- u32 = now.tv_usec;
- memcpy(rnd + 4, &u32, 4);
- u32 += now.tv_sec;
- memcpy(rnd + 8, &u32, 4);
- u16 = getpid();
- memcpy(rnd + 12, &u16, 2);
+ (void)statp;
}
+__sym_compat(__res_rndinit, freebsd15_res_rndinit, FBSD_1.4);
u_int
res_nrandomid(res_state statp) {
- struct timeval now;
- u_int16_t u16;
- MD5_CTX ctx;
- u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;
-
- gettimeofday(&now, NULL);
- u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec);
- memcpy(rnd + 14, &u16, 2);
-#ifndef HAVE_MD5
- MD5_Init(&ctx);
- MD5_Update(&ctx, rnd, 16);
- MD5_Final(rnd, &ctx);
-#else
- MD5Init(&ctx);
- MD5Update(&ctx, rnd, 16);
- MD5Final(rnd, &ctx);
-#endif
- memcpy(&u16, rnd + 14, 2);
- return ((u_int) u16);
+ (void) statp;
+
+ return ((u_int)(arc4random() & 0xffff));
}
/*%
@@ -808,10 +763,6 @@ res_ndestroy(res_state statp) {
free(statp->_u._ext.ext);
statp->_u._ext.ext = NULL;
}
- if (statp->_rnd != NULL) {
- free(statp->_rnd);
- statp->_rnd = NULL;
- }
statp->options &= ~RES_INIT;
}
diff --git a/lib/libc/riscv/string/Makefile.inc b/lib/libc/riscv/string/Makefile.inc
new file mode 100644
index 000000000000..6dae6b2cb62d
--- /dev/null
+++ b/lib/libc/riscv/string/Makefile.inc
@@ -0,0 +1,10 @@
+MDSRCS+= \
+ bcopy.c \
+ bzero.c \
+ memchr.S \
+ memcpy.S \
+ memset.S \
+ strlen.S \
+ strnlen.S \
+ strchrnul.S \
+ strrchr.S
diff --git a/lib/libc/riscv/string/bcopy.c b/lib/libc/riscv/string/bcopy.c
new file mode 100644
index 000000000000..0dee529fb9df
--- /dev/null
+++ b/lib/libc/riscv/string/bcopy.c
@@ -0,0 +1,14 @@
+/*-
+ * Public domain.
+ */
+
+#include <string.h>
+
+#undef bcopy /* _FORTIFY_SOURCE */
+
+void
+bcopy(const void *src, void *dst, size_t len)
+{
+
+ memmove(dst, src, len);
+}
diff --git a/lib/libc/riscv/string/bzero.c b/lib/libc/riscv/string/bzero.c
new file mode 100644
index 000000000000..d82f3061865b
--- /dev/null
+++ b/lib/libc/riscv/string/bzero.c
@@ -0,0 +1,14 @@
+/*-
+ * Public domain.
+ */
+
+#include <string.h>
+
+#undef bzero /* _FORTIFY_SOURCE */
+
+void
+bzero(void *b, size_t len)
+{
+
+ memset(b, 0, len);
+}
diff --git a/lib/libc/riscv/string/memchr.S b/lib/libc/riscv/string/memchr.S
new file mode 100644
index 000000000000..e6e04bfae96a
--- /dev/null
+++ b/lib/libc/riscv/string/memchr.S
@@ -0,0 +1,188 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+/*
+ * a0 - const void *b
+ * a1 - int c
+ * a2 - size_t len
+ */
+ENTRY(memchr)
+ /*
+ * a0 - const char *ptr
+ * a1 - char cccccccc[8]
+ * a2 - char iter[8]
+ * a3 - uint8_t *end
+ * a4 - uint64_t *end_align
+ * a5 - uint64_t *end_unroll
+ */
+
+ beqz a2, .Lno_match
+
+ /* c = (uint8_t) c */
+ andi a1, a1, 0xFF
+
+ /*
+ * t0 = 0x0101010101010101
+ * t1 = 0x8080808080808080
+ * t2 = b << 3
+ * cccccccc = (uint8_t)c * t0
+ * end = b + len;
+ * ptr = b & ~0b111
+ */
+ add a3, a0, a2
+ li t0, 0x01010101
+ sltu t2, a0, a3
+ slli t1, t0, 32
+ neg t2, t2
+ or t0, t0, t1
+ and a3, a3, t2
+ slli t1, t0, 7
+ slli t2, a0, 3
+ and a0, a0, ~0b111
+ mul a1, t0, a1
+
+ ld a2, (a0)
+
+ /*
+ * mask_start = REP8_0x01 ^ (REP8_0x01 << t2)
+ * iter = iter ^ cccccccc
+ * iter = iter | mask_start
+ */
+ sll t2, t0, t2
+ xor a2, a2, a1
+ xor t2, t2, t0
+ or a2, a2, t2
+
+ /* has_zero(iter)
+ * end_align = (end + 7) & ~0b111;
+ */
+ addi a4, a3, 7
+ not t2, a2
+ sub a2, a2, t0
+ and t2, t2, t1
+ andi a4, a4, ~0b111
+ and a2, a2, t2
+
+ /* ptr = ptr + 8 */
+ addi a0, a0, 8
+
+ bnez a2, .Lfind_zero
+
+ /* if(ptr == end_align) */
+ beq a0, a4, .Lno_match
+
+ /* end_unroll = end_align & ~0b1111 */
+ andi a5, a4, ~0b1111
+
+ /*
+ * Instead of branching to check if `ptr` is 16-byte aligned:
+ * - Probe the next 8 bytes for `c`
+ * - Align `ptr` down to the nearest 16-byte boundary
+ *
+ * If `ptr` was already 16-byte aligned, those 8 bytes will be
+ * checked again inside the unrolled loop.
+ *
+ * This removes an unpredictable branch and improves performance.
+ */
+
+ ld a2, (a0)
+ xor a2, a2, a1
+
+ not t2, a2
+ sub a2, a2, t0
+ and t2, t2, t1
+ and a2, a2, t2
+
+ addi a0, a0, 8
+
+ bnez a2, .Lfind_zero
+
+ andi a0, a0, ~0b1111
+
+ /* while(ptr != end_unroll) */
+ beq a0, a5, .Lskip_loop
+.Lloop:
+ ld a2, (a0)
+ ld t3, 8(a0)
+
+ xor a2, a2, a1
+ xor t3, t3, a1
+
+ not t2, a2
+ not t4, t3
+ sub a2, a2, t0
+ sub t3, t3, t0
+ and t2, t2, t1
+ and t4, t4, t1
+ and a2, a2, t2
+ and t3, t3, t4
+
+ addi a0, a0, 8
+
+ bnez a2, .Lfind_zero
+
+ /* move into iter for find_zero */
+ mv a2, t3
+
+ addi a0, a0, 8
+
+ bnez a2, .Lfind_zero
+
+ bne a0, a5, .Lloop
+.Lskip_loop:
+
+ /* there might be one 8byte left */
+ beq a0, a4, .Lno_match
+
+ ld a2, (a0)
+ xor a2, a2, a1
+
+ not t2, a2
+ sub a2, a2, t0
+ and t2, t2, t1
+ and a2, a2, t2
+
+ addi a0, a0, 8
+
+ beqz a2, .Lno_match
+
+.Lfind_zero:
+ /*
+ * ptr = ptr - 8
+ * t1 = 0x0001020304050607
+ * iter = iter & (-iter)
+ * iter = iter >> 7
+ * iter = iter * t1
+ * iter = iter >> 56
+ */
+ li t1, 0x10203000
+ neg t0, a2
+ slli t1, t1, 4
+ and a2, a2, t0
+ addi t1, t1, 0x405
+ srli a2, a2, 7
+ slli t1, t1, 16
+ addi a0, a0, -8
+ addi t1, t1, 0x607
+ mul a2, a2, t1
+ srli a2, a2, 56
+
+ /* left = end - ptr */
+ sub t0, a3, a0
+
+ /* return iter < left ? ptr + iter : NULL */
+ sltu t1, a2, t0
+ neg t1, t1
+ add a0, a0, a2
+ and a0, a0, t1
+ ret
+
+.Lno_match:
+ li a0, 0
+ ret
+END(memchr)
diff --git a/lib/libc/riscv/string/memcpy.S b/lib/libc/riscv/string/memcpy.S
new file mode 100644
index 000000000000..7536514df777
--- /dev/null
+++ b/lib/libc/riscv/string/memcpy.S
@@ -0,0 +1,217 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+/*
+ * a0 - void* dst
+ * a1 - const void* src
+ * a2 - size_t len
+ */
+ENTRY(memcpy)
+ beqz a2, .Lreturn
+
+ /* diff = (dstv - srcv) & 0b111 */
+ sub t0, a0, a1
+ andi t0, t0, 0b111
+
+ sltiu t1, a2, 8
+
+ /* we never change a0, because memcpy returns the original dst */
+ mv a3, a0
+
+ /* len < 8 */
+ bnez t1, .Lend
+
+ /* t1 = (-dst) & 0b111 */
+ neg t1, a0
+ andi t1, t1, 0b111
+
+ sub a2, a2, t1
+
+ la t2, .Lduff_start
+ slli t3, t1, 3
+ sub t2, t2, t3
+ jr t2
+ lb t3, 6(a1)
+ sb t3, 6(a3)
+ lb t3, 5(a1)
+ sb t3, 5(a3)
+ lb t3, 4(a1)
+ sb t3, 4(a3)
+ lb t3, 3(a1)
+ sb t3, 3(a3)
+ lb t3, 2(a1)
+ sb t3, 2(a3)
+ lb t3, 1(a1)
+ sb t3, 1(a3)
+ lb t3, 0(a1)
+ sb t3, 0(a3)
+.Lduff_start:
+
+ add a1, a1, t1
+ add a3, a3, t1
+
+ beqz a2, .Lreturn
+
+ beqz t0, .Lmemcpy8
+
+ /*
+ * a4 - size_t right_shift
+ * a5 - size_t left_shift
+ * a6 - size_t whole (number of dword stores)
+ */
+
+ /* right_shift = (src % 0b111) * 8; */
+ andi a4, a1, 0b111
+ slli a4, a4, 3
+
+ /* left_shift = 64 - right_shift */
+ neg a5, a4
+
+ /* whole = len / 8 */
+ srli a6, a2, 3
+
+ /* len = len % 8 */
+ andi a2, a2, 0b111
+
+ /* t0 - uint64_t* ptr */
+
+ /* ptr = src & ~0b111 */
+ andi t0, a1, ~0b111
+
+ /* src += whole * 8 */
+ slli t1, a6, 3
+ add a1, a1, t1
+
+ /*
+ * t1 - uint64_t low
+ * t2 - uint64_t high
+ */
+
+ /* low = *ptr++ */
+ ld t1, (t0)
+ addi t0, t0, 8
+
+ /* low >>= right_shift */
+ srl t1, t1, a4
+
+ beqz a6, .Llmain_skip
+.Llmain:
+ /* high = *ptr++ */
+ ld t2, (t0)
+ addi t0, t0, 8
+
+ /* whole-- */
+ addi a6, a6, -1
+
+ /* temp = (high << left_shift) | low */
+ sll t3, t2, a5
+ or t3, t3, t1
+
+ /* low = high >> right_shift */
+ srl t1, t2, a4
+
+ /* *dst++ = temp */
+ sd t3, (a3)
+ addi a3, a3, 8
+
+ bnez a6, .Llmain
+
+.Llmain_skip:
+
+.Lend:
+ la t1, .Lduff_end
+ slli t2, a2, 3
+ sub t1, t1, t2
+ jr t1
+ lb t2, 6(a1)
+ sb t2, 6(a3)
+ lb t2, 5(a1)
+ sb t2, 5(a3)
+ lb t2, 4(a1)
+ sb t2, 4(a3)
+ lb t2, 3(a1)
+ sb t2, 3(a3)
+ lb t2, 2(a1)
+ sb t2, 2(a3)
+ lb t2, 1(a1)
+ sb t2, 1(a3)
+ lb t2, 0(a1)
+ sb t2, 0(a3)
+.Lduff_end:
+
+.Lreturn:
+ ret
+
+/* exectued when dst - src is multiple of 8
+ * a0 - void* dst
+ * a1 - const void* src
+ * a2 - size_t len
+ */
+.Lmemcpy8:
+
+ beqz a2, .Lreturn
+
+ slti t0, a2, 128
+ bnez t0, .Llmain8_64_skip
+
+ /* a4 - uint64_t* end_unroll */
+
+ /* end_unroll = dst + len / 64 * 64 */
+ andi t0, a2, ~0b111111
+ add a4, a3, t0
+
+ /* len = len % 64 */
+ andi a2, a2, 0b111111
+
+.Llmain8_64:
+ ld t0, 0(a1)
+ ld t1, 8(a1)
+ ld t2, 16(a1)
+ ld t3, 24(a1)
+ sd t0, 0(a3)
+ sd t1, 8(a3)
+ sd t2, 16(a3)
+ sd t3, 24(a3)
+ ld t0, 32(a1)
+ ld t1, 40(a1)
+ ld t2, 48(a1)
+ ld t3, 56(a1)
+ sd t0, 32(a3)
+ sd t1, 40(a3)
+ sd t2, 48(a3)
+ sd t3, 56(a3)
+ addi a3, a3, 64
+ addi a1, a1, 64
+ bne a3, a4, .Llmain8_64
+.Llmain8_64_skip:
+
+ beqz a2, .Lreturn
+
+ /* a4 - uint64_t* end_align */
+
+ /* end_align = (dst + len) & ~0b111 */
+ add a4, a3, a2
+ andi a4, a4, ~0b111
+
+ /* len = len % 8 */
+ andi a2, a2, 0b111
+
+ beq a3, a4, .Llmain8_skip
+.Llmain8:
+ ld t0, (a1)
+ sd t0, (a3)
+ addi a3, a3, 8
+ addi a1, a1, 8
+ bne a3, a4, .Llmain8
+.Llmain8_skip:
+
+ la t1, .Lduff_end
+ slli t2, a2, 3
+ sub t1, t1, t2
+ jr t1
+END(memcpy)
diff --git a/lib/libc/riscv/string/memset.S b/lib/libc/riscv/string/memset.S
new file mode 100644
index 000000000000..ca435dfdd5c1
--- /dev/null
+++ b/lib/libc/riscv/string/memset.S
@@ -0,0 +1,95 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+/*
+ * register a0 - void *dest
+ * register a1 - int c
+ * register a2 - size_t len
+ */
+ENTRY(memset)
+ andi a1, a1, 0xFF
+
+ sltiu t1, a2, 8
+ mv t0, a0
+ bnez t1, .Lend
+
+ li t1, 0x0101010101010101
+ mul a1, a1, t1
+
+ andi t1, a0, 0b111
+ andi t0, a0, ~0b111
+
+ beqz t1, .Lloop_store_64
+
+ la t2, .Lduff_start
+ slli t3, t1, 2
+ add t2, t2, t3
+ jr -4(t2)
+.Lduff_start:
+ sb a1, 1(t0)
+ sb a1, 2(t0)
+ sb a1, 3(t0)
+ sb a1, 4(t0)
+ sb a1, 5(t0)
+ sb a1, 6(t0)
+ sb a1, 7(t0)
+
+ /* a3 = a3 -(8-a) <=> a3 = a3 + (a-8) */
+ addi t1, t1, -8
+ add a2, a2, t1
+ addi t0, t0, 8
+
+.Lloop_store_64:
+ slti t1, a2, 64
+ bnez t1, .Lstore_rest
+ sd a1, 0(t0)
+ sd a1, 8(t0)
+ sd a1, 16(t0)
+ sd a1, 24(t0)
+ sd a1, 32(t0)
+ sd a1, 40(t0)
+ sd a1, 48(t0)
+ sd a1, 56(t0)
+ addi a2, a2, -64
+ addi t0, t0, 64
+ j .Lloop_store_64
+
+.Lstore_rest:
+ la t2, .Lduff_rest
+ andi t3, a2, ~0b111
+ srli t4, t3, 1
+ sub t2, t2, t4
+ jr t2
+ sd a1, 56(t0)
+ sd a1, 48(t0)
+ sd a1, 40(t0)
+ sd a1, 32(t0)
+ sd a1, 24(t0)
+ sd a1, 16(t0)
+ sd a1, 8(t0)
+ sd a1, 0(t0)
+.Lduff_rest:
+ add t0, t0, t3
+ sub a2, a2, t3
+
+.Lend:
+ slli a2, a2, 2
+ la t2, .Lduff_end
+ sub t2, t2, a2
+ jr t2
+ sb a1, 6(t0)
+ sb a1, 5(t0)
+ sb a1, 4(t0)
+ sb a1, 3(t0)
+ sb a1, 2(t0)
+ sb a1, 1(t0)
+ sb a1, (t0)
+.Lduff_end:
+ ret
+END(memset)
+
diff --git a/lib/libc/riscv/string/strchrnul.S b/lib/libc/riscv/string/strchrnul.S
new file mode 100644
index 000000000000..8abba71c4199
--- /dev/null
+++ b/lib/libc/riscv/string/strchrnul.S
@@ -0,0 +1,116 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+ .weak strchrnul
+ .set strchrnul, __strchrnul
+
+/*
+ * a0 - const char *str
+ * a1 - int c;
+ */
+ENTRY(__strchrnul)
+ /*
+ * a0 - const char *ptr;
+ * a1 - char cccccccc[8];
+ * a2 - char iter[8];
+ * a3 - char mask_end
+ */
+
+ /* int to char */
+ andi a1, a1, 0xFF
+
+ /* t0 = 0x0101010101010101 */
+ li t0, 0x01010101
+ slli t1, t0, 32
+ or t0, t0, t1
+
+ /* t1 = 0x8080808080808080 */
+ slli t1, t0, 7
+
+ /* spread char across bytes */
+ mul a1, a1, t0
+
+ /* align_offset */
+ andi t2, a0, 0b111
+
+ /* align pointer */
+ andi a0, a0, ~0b111
+
+ /* if pointer is aligned skip to loop */
+ beqz t2, .Lloop
+
+ ld a2, (a0)
+
+ /* mask_start calculation */
+ slli t2, t2, 3
+ neg t2, t2
+ srl t2, t0, t2
+
+ /* fill bytes before start with non-zero */
+ or a3, a2, t2
+
+ xor a2, a2, a1
+ or a2, a2, t2
+
+ /* has_zero for \0 */
+ not t3, a3
+ not t2, a2
+ sub a3, a3, t0
+ sub a2, a2, t0
+ and a3, a3, t3
+ and a2, a2, t2
+ and a3, a3, t1
+ and a2, a2, t1
+
+
+ /* if \0 or c was found, exit */
+ or a2, a2, a3
+ addi a0, a0, 8
+ bnez a2, .Lfind_char
+
+
+.Lloop:
+ ld a2, (a0)
+
+ /* has_zero for both \0 or c */
+ xor a3, a2, a1
+
+ not t2, a2
+ not t3, a3
+ sub a2, a2, t0
+ sub a3, a3, t0
+ and a2, a2, t2
+ and a3, a3, t3
+ and a2, a2, t1
+ and a3, a3, t1
+
+ /* if \0 or c was found, exit */
+ or a2, a2, a3
+ addi a0, a0, 8
+ beqz a2, .Lloop
+
+.Lfind_char:
+ addi a0, a0, -8
+
+ /* isolate lowest set bit */
+ neg t0, a2
+ and a2, a2, t0
+
+ li t0, 0x0001020304050607
+ srli a2, a2, 7
+
+ /* lowest set bit is 2^(8*k)
+ * multiplying by it shifts the idx array in t0 by k bytes to the left */
+ mul a2, a2, t0
+
+ /* highest byte contains idx of first zero */
+ srli a2, a2, 56
+
+ add a0, a0, a2
+ ret
+END(__strchrnul)
diff --git a/lib/libc/riscv/string/strlen.S b/lib/libc/riscv/string/strlen.S
new file mode 100644
index 000000000000..3beb160f2e6f
--- /dev/null
+++ b/lib/libc/riscv/string/strlen.S
@@ -0,0 +1,77 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+/*
+ * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
+ * uses haszero(v) (((v) - 0x01010101UL) & ~(v) & 0x80808080UL)
+ * which evalutates > 0 when there is zero in v
+ *
+ * register a0 - char *s
+ */
+ENTRY(strlen)
+ /*
+ * register a0 - char *str_start
+ * register a1 - char *str_ptr
+ * register a2 - char[8] iter
+ */
+
+ /* load constants for haszero */
+ li t0, 0x0101010101010101
+ slli t1, t0, 7 # 0x8080808080808080, avoid li
+
+ /* check alignment of str_start */
+ andi a1, a0, ~0b111
+ ld a2, (a1)
+ beq a1, a0, .Lhas_zero
+
+ /* fill bytes before str_start with non-zero */
+ slli t2, a0, 3
+ addi t3, t2, -64
+ neg t3, t3
+ srl t3, t0, t3
+ or a2, a2, t3
+
+ /* unrolled iteration of haszero */
+ not t2, a2
+ sub a2, a2, t0
+ and a2, a2, t2
+ and a2, a2, t1
+
+ bnez a2, .Lfind_zero
+
+.Lloop_has_zero:
+ ld a2, 8(a1)
+ addi a1, a1, 8 # move ptr to next 8byte
+.Lhas_zero:
+ not t2, a2
+ sub a2, a2, t0
+ and a2, a2, t2
+ and a2, a2, t1
+
+ beqz a2, .Lloop_has_zero
+
+.Lfind_zero:
+ /* use (iter & -iter) to isolate lowest set bit */
+ sub a3, zero, a2 #a3 = -iter
+ and t1, a2, a3 #t1 = (iter & -iter)
+
+ li t0, 0x0001020304050607
+ srli t1, t1, 7
+ /*
+ * lowest set bit is 2^(8*k)
+ * multiplying by it shifts the idx array in t0 by k bytes to the left
+ */
+ mul t1, t1, t0
+ /* highest byte contains idx of first zero */
+ srli t1, t1, 56
+
+ add a1, a1, t1
+ sub a0, a1, a0
+ ret
+END(strlen)
+
diff --git a/lib/libc/riscv/string/strnlen.S b/lib/libc/riscv/string/strnlen.S
new file mode 100644
index 000000000000..c0fd959548ff
--- /dev/null
+++ b/lib/libc/riscv/string/strnlen.S
@@ -0,0 +1,143 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+/*
+ * a0 - const char *s
+ * a1 - size_t maxlen;
+ */
+ENTRY(strnlen)
+ /*
+ * a0 - const char *s;
+ * a1 - size_t maxlen;
+ * a2 - uint64_t *ptr;
+ * a3 - char iter[8];
+ * a4 - uint64_t *end_align;
+ * a5 - uint64_t *end_unroll;
+ */
+
+ beqz a1, .Lnot_found
+
+ /* ptr = s & ~0b111 */
+ /* t0 = 0x0101010101010101 */
+ /* t1 = 0x8080808080808080 */
+ /* end_align = (s + maxlen + 7) & ~0b111 */
+ /* mask_start = t0 >> ((-s.value) << 3) */
+ add a4, a0, a1
+ li t0, 0x01010101
+ addi a4, a4, 7
+ slli t1, t0, 32
+ neg t2, a0
+ andi a4, a4, ~0b111
+ or t0, t0, t1
+ slli t2, t2, 3
+ andi a2, a0, ~0b111
+ slli t1, t0, 7
+ srl t2, t0, t2
+
+ /* if pointer is aligned skip to loop */
+ beq a0, a2, .Lskip_start
+
+ /* iter = *ptr */
+ ld a3, (a2)
+
+ /* iter = iter | mask_start */
+ or a3, a3, t2
+
+ /* has_zero */
+ not t2, a3
+ sub a3, a3, t0
+ and t2, t2, t1
+ and a3, a3, t2
+
+ addi a2, a2, 8
+ bnez a3, .Lfind_zero
+
+.Lskip_start:
+ /* end_unroll */
+ sub t2, a4, a2
+ andi t2, t2, ~0b1111
+ add a5, a2, t2
+
+ /* while (ptr != end_unroll) */
+ beq a2, a5, .Lskip_loop
+.Lloop:
+ ld a3, (a2)
+ ld a6, 8(a2)
+
+ /* has_zero */
+ not t2, a3
+ not t3, a6
+ sub a3, a3, t0
+ sub a6, a6, t0
+ and t2, t2, t1
+ and t3, t3, t1
+ and a3, a3, t2
+ and a6, a6, t3
+
+ addi a2, a2, 8
+ bnez a3, .Lfind_zero
+
+ mv a3, a6
+
+ addi a2, a2, 8
+ bnez a3, .Lfind_zero
+
+ bne a2, a5, .Lloop
+
+.Lskip_loop:
+
+ beq a2, a4, .Lnot_found
+
+ ld a3, (a2)
+
+ /* has_zero */
+ not t2, a3
+ sub a3, a3, t0
+ and t2, t2, t1
+ and a3, a3, t2
+
+
+ addi a2, a2, 8
+ beqz a3, .Lnot_found
+
+.Lfind_zero:
+
+ /* move ptr back */
+ addi a2, a2, -8
+
+ /* isolate lowest set bit */
+ neg t0, a3
+ and a3, a3, t0
+
+ li t0, 0x0001020304050607
+ srli a3, a3, 7
+
+ /* lowest set bit is 2^(8*k)
+ * multiplying by it shifts the idx array in t0 by k bytes to the left */
+ mul a3, a3, t0
+
+ /* highest byte contains idx of first zero */
+ srli a3, a3, 56
+
+ /* zero_idx */
+ sub a2, a2, a0
+ add a2, a2, a3
+
+ /* min(zero_idx, maxlen) */
+ sub a2, a2, a1
+ srai t1, a2, 63
+ and a2, a2, t1
+ add a0, a1, a2
+
+ ret
+
+.Lnot_found:
+ mv a0, a1
+ ret
+
+END(strnlen)
diff --git a/lib/libc/riscv/string/strrchr.S b/lib/libc/riscv/string/strrchr.S
new file mode 100644
index 000000000000..e922a692e77f
--- /dev/null
+++ b/lib/libc/riscv/string/strrchr.S
@@ -0,0 +1,127 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Strahinja Stanisic <strajabot@FreeBSD.org>
+ */
+
+#include <machine/asm.h>
+
+ .weak rindex
+ .set rindex, strrchr
+
+/*
+ * a0 - const char *s
+ * a1 - int c
+ */
+ENTRY(strrchr)
+ /*
+ * a0 - const char *ptr_align
+ * a1 - temporary
+ * a2 - temporary
+ * a3 - temporary
+ * a4 - temporary
+ * a5 - const char[8] cccccccc
+ * a6 - const uint64_t *save_align
+ * a7 - const uint64_t save_iter
+ * t0 - const uintr64_t REP8_0X01
+ * t1 - const uintr64_t REP8_0X80
+ */
+
+ /*
+ * save_align = 0
+ * save_iter = 0xFFFFFFFFFFFFFF00
+ * REP8_0X01 = 0x0101010101010101
+ * cccccccc = (char)c * REP8_0X01
+ * REP8_0X80 = (REP8_0X80 << 7) << ((str % 8) * 8)
+ * ptr_align = str - str % 8
+ */
+ li t0, 0x01010101
+ li a6, 0
+ slli a2, a0, 3
+ slli t1, t0, 32
+ li a7, 0xFFFFFFFFFFFFFF00
+ or t0, t0, t1
+ andi a1, a1, 0xFF
+ slli t1, t0, 7
+ andi a0, a0, ~0b111
+ mul a5, a1, t0
+ sll t1, t1, a2
+
+.Lloop: /* do { */
+ ld a1, 0(a0) /* a1 -> data = *ptr_align */
+ not a3, a1 /* a3 -> nhz = ~data */
+ xor a2, a1, a5 /* a2 -> iter = data ^ cccccccc */
+ sub a1, a1, t0 /* a1 -> hz = data - REP8_0X01 */
+ not a4, a2 /* a4 -> nhc = ~iter */
+ and a1, a1, a3 /* hz = hz & nhz */
+ sub a3, a2, t0 /* a3 -> hc = iter - REP8_0X01 */
+ and a1, a1, t1 /* hz = hz & REP8_0X80 */
+ and a3, a3, a4 /* hc = hc & nhc */
+ addi a4, a1, -1 /* a4 -> mask_end = hz - 1 */
+ and a3, a3, t1 /* hc = hc & REP8_0X80 */
+ xor a4, a4, a1 /* mask_end = mask_end ^ hz */
+ addi a0, a0, 8 /* ptr_align = ptr_align + 8 */
+ and a3, a3, a4 /* hc = hc & mask_end */
+ slli t1, t0, 7 /* REP8_0X80 = REP8_0X01 << 7 */
+ not a4, a4 /* mask_end = ~mask_end */
+
+ beqz a3, .Lskip_save /* if(!hc) goto skip_save */
+ or a2, a2, a4 /* iter = iter | mask_end */
+ addi a6, a0, -8 /* save_align = ptr_align - 8 */
+ mv a7, a2 /* save_iter = iter */
+
+.Lskip_save:
+ beqz a1, .Lloop /* } while(!hz) */
+
+.Lfind_char:
+ /*
+ * a1 -> iter = save_iter
+ * a2 -> mask_iter = 0xFF00000000000000
+ * a3 -> match_off = 7
+ */
+ li a2, 0xFF
+ mv a1, a7
+ slli a2, a2, 56
+ li a3, 7
+
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+ and a0, a1, a2
+ srli a2, a2, 8
+ beqz a0, .Lret
+
+ addi a3, a3, -1
+
+.Lret:
+ /* return save_align + match_offset */
+ add a0, a6, a3
+ ret
+END(strrchr)
diff --git a/lib/libc/rpc/Makefile.inc b/lib/libc/rpc/Makefile.inc
index 87963d10eec1..c22fac2c0e16 100644
--- a/lib/libc/rpc/Makefile.inc
+++ b/lib/libc/rpc/Makefile.inc
@@ -42,12 +42,12 @@ crypt_xdr.c: ${RPCDIR}/crypt.x crypt.h
crypt.h: ${RPCDIR}/crypt.x
${RPCGEN} -h -o ${.TARGET} ${RPCDIR}/crypt.x
+
MAN+= bindresvport.3 des_crypt.3 getnetconfig.3 getnetpath.3 getrpcent.3 \
getrpcport.3 rpc.3 rpc_soc.3 rpc_clnt_auth.3 rpc_clnt_calls.3 \
rpc_clnt_create.3 rpc_svc_calls.3 rpc_svc_create.3 rpc_svc_err.3 \
rpc_svc_reg.3 rpc_xdr.3 rpcbind.3 publickey.3 rpc_secure.3 \
rtime.3
-MAN+= rpc.5 netconfig.5
MLINKS+= bindresvport.3 bindresvport_sa.3 \
des_crypt.3 ecb_crypt.3 \
des_crypt.3 cbc_crypt.3 \
@@ -177,3 +177,5 @@ MLINKS+= bindresvport.3 bindresvport_sa.3 \
rpc_soc.3 xdr_authunix_parms.3 \
rpc_soc.3 xdr_pmap.3 \
rpc_soc.3 xdr_pmaplist.3
+
+MANNODEV+= rpc.5 netconfig.5
diff --git a/lib/libc/rpc/rpc_generic.c b/lib/libc/rpc/rpc_generic.c
index 0e563f6a5996..8019f2d8f236 100644
--- a/lib/libc/rpc/rpc_generic.c
+++ b/lib/libc/rpc/rpc_generic.c
@@ -610,6 +610,10 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf)
return NULL;
break;
#endif
+ case AF_NETLINK:
+ if (asprintf(&ret, "%s", (char *)nbuf->buf) < 0)
+ return NULL;
+ break;
case AF_LOCAL:
sun = nbuf->buf;
if (asprintf(&ret, "%.*s", (int)(sun->sun_len -
diff --git a/lib/libc/stdbit/Makefile.inc b/lib/libc/stdbit/Makefile.inc
new file mode 100644
index 000000000000..fceccb12b589
--- /dev/null
+++ b/lib/libc/stdbit/Makefile.inc
@@ -0,0 +1,34 @@
+# sources for <stdbit.h>
+.PATH: ${LIBC_SRCTOP}/stdbit
+
+SRCS+= stdc_bit_ceil.c \
+ stdc_bit_floor.c \
+ stdc_bit_width.c \
+ stdc_count_ones.c \
+ stdc_count_zeros.c \
+ stdc_first_leading_one.c \
+ stdc_first_leading_zero.c \
+ stdc_first_trailing_one.c \
+ stdc_first_trailing_zero.c \
+ stdc_has_single_bit.c \
+ stdc_leading_ones.c \
+ stdc_leading_zeros.c \
+ stdc_trailing_ones.c \
+ stdc_trailing_zeros.c
+
+SYM_MAPS+=${LIBC_SRCTOP}/stdbit/Symbol.map
+
+MAN+= stdc_bit_ceil.3 \
+ stdc_bit_floor.3 \
+ stdc_bit_width.3 \
+ stdc_count_ones.3 \
+ stdc_count_zeros.3 \
+ stdc_first_leading_one.3 \
+ stdc_first_leading_zero.3 \
+ stdc_first_trailing_one.3 \
+ stdc_first_trailing_zero.3 \
+ stdc_has_single_bit.3 \
+ stdc_leading_ones.3 \
+ stdc_leading_zeros.3 \
+ stdc_trailing_ones.3 \
+ stdc_trailing_zeros.3
diff --git a/lib/libc/stdbit/Symbol.map b/lib/libc/stdbit/Symbol.map
new file mode 100644
index 000000000000..7014d6984c07
--- /dev/null
+++ b/lib/libc/stdbit/Symbol.map
@@ -0,0 +1,85 @@
+FBSD_1.9 {
+ stdc_leading_zeros_uc;
+ stdc_leading_zeros_us;
+ stdc_leading_zeros_ui;
+ stdc_leading_zeros_ul;
+ stdc_leading_zeros_ull;
+
+ stdc_leading_ones_uc;
+ stdc_leading_ones_us;
+ stdc_leading_ones_ui;
+ stdc_leading_ones_ul;
+ stdc_leading_ones_ull;
+
+ stdc_trailing_zeros_uc;
+ stdc_trailing_zeros_us;
+ stdc_trailing_zeros_ui;
+ stdc_trailing_zeros_ul;
+ stdc_trailing_zeros_ull;
+
+ stdc_trailing_ones_uc;
+ stdc_trailing_ones_us;
+ stdc_trailing_ones_ui;
+ stdc_trailing_ones_ul;
+ stdc_trailing_ones_ull;
+
+ stdc_first_leading_zero_uc;
+ stdc_first_leading_zero_us;
+ stdc_first_leading_zero_ui;
+ stdc_first_leading_zero_ul;
+ stdc_first_leading_zero_ull;
+
+ stdc_first_leading_one_uc;
+ stdc_first_leading_one_us;
+ stdc_first_leading_one_ui;
+ stdc_first_leading_one_ul;
+ stdc_first_leading_one_ull;
+
+ stdc_first_trailing_zero_uc;
+ stdc_first_trailing_zero_us;
+ stdc_first_trailing_zero_ui;
+ stdc_first_trailing_zero_ul;
+ stdc_first_trailing_zero_ull;
+
+ stdc_first_trailing_one_uc;
+ stdc_first_trailing_one_us;
+ stdc_first_trailing_one_ui;
+ stdc_first_trailing_one_ul;
+ stdc_first_trailing_one_ull;
+
+ stdc_count_zeros_uc;
+ stdc_count_zeros_us;
+ stdc_count_zeros_ui;
+ stdc_count_zeros_ul;
+ stdc_count_zeros_ull;
+
+ stdc_count_ones_uc;
+ stdc_count_ones_us;
+ stdc_count_ones_ui;
+ stdc_count_ones_ul;
+ stdc_count_ones_ull;
+
+ stdc_has_single_bit_uc;
+ stdc_has_single_bit_us;
+ stdc_has_single_bit_ui;
+ stdc_has_single_bit_ul;
+ stdc_has_single_bit_ull;
+
+ stdc_bit_width_uc;
+ stdc_bit_width_us;
+ stdc_bit_width_ui;
+ stdc_bit_width_ul;
+ stdc_bit_width_ull;
+
+ stdc_bit_floor_uc;
+ stdc_bit_floor_us;
+ stdc_bit_floor_ui;
+ stdc_bit_floor_ul;
+ stdc_bit_floor_ull;
+
+ stdc_bit_ceil_uc;
+ stdc_bit_ceil_us;
+ stdc_bit_ceil_ui;
+ stdc_bit_ceil_ul;
+ stdc_bit_ceil_ull;
+};
diff --git a/lib/libc/stdbit/stdc_bit_ceil.3 b/lib/libc/stdbit/stdc_bit_ceil.3
new file mode 100644
index 000000000000..470b255f471e
--- /dev/null
+++ b/lib/libc/stdbit/stdc_bit_ceil.3
@@ -0,0 +1,81 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_BIT_CEIL 3
+.Os
+.Sh NAME
+.Nm stdc_bit_ceil
+.Nd round up to the next power of\~2
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned char
+.Fn stdc_bit_ceil_uc "unsigned char value"
+.Ft unsigned short
+.Fn stdc_bit_ceil_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_bit_ceil_ui "unsigned int value"
+.Ft unsigned long
+.Fn stdc_bit_ceil_ul "unsigned long value"
+.Ft unsigned long long
+.Fn stdc_bit_ceil_ull "unsigned long long value"
+.Ft typeof Ns Pq Em value
+.Fn stdc_bit_ceil "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_bit_ceil_ Ns Em type Ns ()
+family of functions rounds
+.Fa value
+up to the next power of\~2, where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_bit_ceil "value"
+type-generic macro picks the appropriate
+.Nm stdc_bit_ceil_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns
+.Fa value
+round up to the next power of\~2.
+If this value is not representable,
+0\~is returned.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_bit_floor 3
+.Sh STANDARDS
+The
+.Nm stdc_bit_ceil_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_bit_ceil
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_bit_ceil_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_bit_ceil
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_bit_ceil.c b/lib/libc/stdbit/stdc_bit_ceil.c
new file mode 100644
index 000000000000..2dfd7bbcbea2
--- /dev/null
+++ b/lib/libc/stdbit/stdc_bit_ceil.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <stdbit.h>
+
+/* Ensure we don't shift 1U out of range. */
+static_assert(UCHAR_WIDTH < UINT_WIDTH,
+ "stdc_bit_ceil_uc needs UCHAR_WIDTH < UINT_WIDTH");
+
+unsigned char
+stdc_bit_ceil_uc(unsigned char x)
+{
+ if (x <= 1)
+ return (1);
+
+ return (1U << (UINT_WIDTH - __builtin_clz(x - 1)));
+}
+
+/* Ensure we don't shift 1U out of range. */
+static_assert(USHRT_WIDTH < UINT_WIDTH,
+ "stdc_bit_ceil_us needs USHRT_WIDTH < UINT_WIDTH");
+
+unsigned short
+stdc_bit_ceil_us(unsigned short x)
+{
+ if (x <= 1)
+ return (1);
+
+ return (1U << (UINT_WIDTH - __builtin_clz(x - 1)));
+}
+
+unsigned int
+stdc_bit_ceil_ui(unsigned int x)
+{
+ if (x <= 1)
+ return (1);
+
+ if (x > UINT_MAX/2 + 1)
+ return (0);
+
+ return (1U << (UINT_WIDTH - __builtin_clz(x - 1)));
+}
+
+unsigned long
+stdc_bit_ceil_ul(unsigned long x)
+{
+ if (x <= 1)
+ return (1);
+
+ if (x > ULONG_MAX/2 + 1)
+ return (0);
+
+ return (1UL << (ULONG_WIDTH - __builtin_clzl(x - 1)));
+}
+
+unsigned long long
+stdc_bit_ceil_ull(unsigned long long x)
+{
+ if (x <= 1)
+ return (1);
+
+ if (x > ULLONG_MAX/2 + 1)
+ return (0);
+
+ return (1ULL << (ULLONG_WIDTH - __builtin_clzll(x - 1)));
+}
diff --git a/lib/libc/stdbit/stdc_bit_floor.3 b/lib/libc/stdbit/stdc_bit_floor.3
new file mode 100644
index 000000000000..3e90c34f070f
--- /dev/null
+++ b/lib/libc/stdbit/stdc_bit_floor.3
@@ -0,0 +1,83 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_BIT_FLOOR 3
+.Os
+.Sh NAME
+.Nm stdc_bit_floor
+.Nd round down to the previous power of\~2
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned char
+.Fn stdc_bit_floor_uc "unsigned char value"
+.Ft unsigned short
+.Fn stdc_bit_floor_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_bit_floor_ui "unsigned int value"
+.Ft unsigned long
+.Fn stdc_bit_floor_ul "unsigned long value"
+.Ft unsigned long long
+.Fn stdc_bit_floor_ull "unsigned long long value"
+.Ft typeof Ns Pq Em value
+.Fn stdc_bit_floor "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_bit_floor_ Ns Em type Ns ()
+family of functions rounds
+.Fa value
+down to the previous power of\~2, where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_bit_floor "value"
+type-generic macro picks the appropriate
+.Nm stdc_bit_floor_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns
+.Fa value
+round down to the previous power of\~2.
+If
+.Fa value
+is equal to zero,
+zero is returned.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_bit_ceil 3
+.Sh STANDARDS
+The
+.Nm stdc_bit_floor_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_bit_floor
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_bit_floor_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_bit_floor
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_bit_floor.c b/lib/libc/stdbit/stdc_bit_floor.c
new file mode 100644
index 000000000000..0a491d6ec7b3
--- /dev/null
+++ b/lib/libc/stdbit/stdc_bit_floor.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned char
+stdc_bit_floor_uc(unsigned char x)
+{
+ if (x == 0)
+ return (0);
+
+ return (1U << (UINT_WIDTH - __builtin_clz(x) - 1));
+}
+
+unsigned short
+stdc_bit_floor_us(unsigned short x)
+{
+ if (x == 0)
+ return (0);
+
+ return (1U << (UINT_WIDTH - __builtin_clz(x) - 1));
+}
+
+unsigned int
+stdc_bit_floor_ui(unsigned int x)
+{
+ if (x == 0)
+ return (0);
+
+ return (1U << (UINT_WIDTH - __builtin_clz(x) - 1));
+}
+
+unsigned long
+stdc_bit_floor_ul(unsigned long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (1UL << (ULONG_WIDTH - __builtin_clzl(x) - 1));
+}
+
+unsigned long long
+stdc_bit_floor_ull(unsigned long long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (1ULL << (ULLONG_WIDTH - __builtin_clzll(x) - 1));
+}
diff --git a/lib/libc/stdbit/stdc_bit_width.3 b/lib/libc/stdbit/stdc_bit_width.3
new file mode 100644
index 000000000000..8d59886818d3
--- /dev/null
+++ b/lib/libc/stdbit/stdc_bit_width.3
@@ -0,0 +1,104 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_BIT_WIDTH 3
+.Os
+.Sh NAME
+.Nm stdc_bit_width
+.Nd find the first trailing one in an intege
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_bit_width_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_bit_width_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_bit_width_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_bit_width_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_bit_width_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_bit_width "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_bit_width_ Ns Em type Ns ()
+family of functions returns the number of bits needed to represent
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_bit_width "value"
+type-generic macro picks the appropriate
+.Nm stdc_bit_width_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Pp
+Functions
+.Fn stdc_bit_width_ui ,
+.Fn stdc_bit_width_ul ,
+and
+.Fn stdc_bit_width_ull
+are identical to
+.Bx 4.3
+functions
+.Xr fls 3 ,
+.Xr flsl 3 ,
+and
+.Xr flsll 3
+respectively, except for operating on unsigned instead of signed values.
+.Sh RETURN VALUES
+Returns the least number of bits needed to represent
+.Fa value .
+If
+.Fa value
+is zero, the return value is zero.
+Otherwise it is
+.EQ
+1 + \(lf log sub 2 italic value \(rf .
+.EN
+.Sh SEE ALSO
+.Xr bit_fls 3 ,
+.Xr fls 3 ,
+.Xr flsl 3 ,
+.Xr flsll 3 ,
+.Xr stdbit 3 ,
+.Xr stdc_count_leading_zeros 3 ,
+.Xr stdc_first_leading_one 3
+.Sh STANDARDS
+The
+.Nm stdc_bit_width_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_bit_width
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_bit_width_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_bit_width
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_bit_width.c b/lib/libc/stdbit/stdc_bit_width.c
new file mode 100644
index 000000000000..e248fae48e9f
--- /dev/null
+++ b/lib/libc/stdbit/stdc_bit_width.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned int
+stdc_bit_width_uc(unsigned char x)
+{
+ if (x == 0)
+ return (0);
+
+ return (UINT_WIDTH - __builtin_clz(x));
+}
+
+unsigned int
+stdc_bit_width_us(unsigned short x)
+{
+ if (x == 0)
+ return (0);
+
+ return (UINT_WIDTH - __builtin_clz(x));
+}
+
+unsigned int
+stdc_bit_width_ui(unsigned int x)
+{
+ if (x == 0)
+ return (0);
+
+ return (UINT_WIDTH - __builtin_clz(x));
+}
+
+unsigned int
+stdc_bit_width_ul(unsigned long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (ULONG_WIDTH - __builtin_clzl(x));
+}
+
+unsigned int
+stdc_bit_width_ull(unsigned long long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (ULLONG_WIDTH - __builtin_clzll(x));
+}
diff --git a/lib/libc/stdbit/stdc_count_ones.3 b/lib/libc/stdbit/stdc_count_ones.3
new file mode 100644
index 000000000000..6de92216c24b
--- /dev/null
+++ b/lib/libc/stdbit/stdc_count_ones.3
@@ -0,0 +1,85 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_COUNT_ONES 3
+.Os
+.Sh NAME
+.Nm stdc_count_ones
+.Nd count the ones in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_count_ones_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_count_ones_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_count_ones_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_count_ones_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_count_ones_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_count_ones "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_count_ones_ Ns Em type Ns ()
+family of functions returns the number of bits set to\~1 in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+This is also known as the
+.Dq population count
+(popcount) or
+.Dq Hamming weight
+operation.
+The
+.Fn stdc_count_ones "value"
+type-generic macro picks the appropriate
+.Nm stdc_count_ones_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the number of bits set to\~1 in
+.Fa value .
+.Sh SEE ALSO
+.Xr bit_count 3 ,
+.Xr stdbit 3 ,
+.Xr stdc_count_zeros 3 ,
+.Xr stdc_has_single_bit 3
+.Sh STANDARDS
+The
+.Nm stdc_count_ones_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_count_ones
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_count_ones_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_count_ones
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_count_ones.c b/lib/libc/stdbit/stdc_count_ones.c
new file mode 100644
index 000000000000..c5198dca84df
--- /dev/null
+++ b/lib/libc/stdbit/stdc_count_ones.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned int
+stdc_count_ones_uc(unsigned char x)
+{
+ return (__builtin_popcount(x));
+}
+
+unsigned int
+stdc_count_ones_us(unsigned short x)
+{
+ return (__builtin_popcount(x));
+}
+
+unsigned int
+stdc_count_ones_ui(unsigned int x)
+{
+ return (__builtin_popcount(x));
+}
+
+unsigned int
+stdc_count_ones_ul(unsigned long x)
+{
+ return (__builtin_popcountl(x));
+}
+
+unsigned int
+stdc_count_ones_ull(unsigned long long x)
+{
+ return (__builtin_popcountll(x));
+}
diff --git a/lib/libc/stdbit/stdc_count_zeros.3 b/lib/libc/stdbit/stdc_count_zeros.3
new file mode 100644
index 000000000000..762ba62d3793
--- /dev/null
+++ b/lib/libc/stdbit/stdc_count_zeros.3
@@ -0,0 +1,84 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_COUNT_ZEROS 3
+.Os
+.Sh NAME
+.Nm stdc_count_zeros
+.Nd count the zeros in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_count_zeros_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_count_zeros_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_count_zeros_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_count_zeros_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_count_zeros_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_count_zeros "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_count_zeros_ Ns Em type Ns ()
+family of functions returns the number of bits set to\~0 in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+This is also known as the
+.Dq population count
+(popcount) or
+.Dq Hamming weight
+of the complement of
+.Fa value .
+The
+.Fn stdc_count_zeros "value"
+type-generic macro picks the appropriate
+.Nm stdc_count_zeros_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the number of bits set to\~0 in
+.Fa value .
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_count_ones 3
+.Sh STANDARDS
+The
+.Nm stdc_count_zeros_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_count_zeros
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_count_zeros_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_count_zeros
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_count_zeros.c b/lib/libc/stdbit/stdc_count_zeros.c
new file mode 100644
index 000000000000..35db965afcb5
--- /dev/null
+++ b/lib/libc/stdbit/stdc_count_zeros.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned int
+stdc_count_zeros_uc(unsigned char x)
+{
+ return (__builtin_popcount(x ^ UCHAR_MAX));
+}
+
+unsigned int
+stdc_count_zeros_us(unsigned short x)
+{
+ return (__builtin_popcount(x ^ USHRT_MAX));
+}
+
+unsigned int
+stdc_count_zeros_ui(unsigned int x)
+{
+ return (__builtin_popcount(~x));
+}
+
+unsigned int
+stdc_count_zeros_ul(unsigned long x)
+{
+ return (__builtin_popcountl(~x));
+}
+
+unsigned int
+stdc_count_zeros_ull(unsigned long long x)
+{
+ return (__builtin_popcountll(~x));
+}
diff --git a/lib/libc/stdbit/stdc_first_leading_one.3 b/lib/libc/stdbit/stdc_first_leading_one.3
new file mode 100644
index 000000000000..48f62d997043
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_leading_one.3
@@ -0,0 +1,93 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_FIRST_LEADING_ONE 3
+.Os
+.Sh NAME
+.Nm stdc_first_leading_one
+.Nd find the first leading one in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_first_leading_one_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_first_leading_one_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_first_leading_one_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_first_leading_one_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_first_leading_one_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_first_leading_one "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_first_leading_one_ Ns Em type Ns ()
+family of functions returns the index of the most significant set bit in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_first_leading_one "value"
+type-generic macro picks the appropriate
+.Nm stdc_first_leading_one_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the index of the most significant set bit in
+.Fa value .
+The bits are numbered such that the most significant bit has number\~1,
+and the least significant bit has number
+.Ms w
+where
+.Ms w
+is the number of bits in the type of
+.Fa value .
+If no bits are set in
+.Fa value
+(i.\^e.\&
+.Fa value
+is zero), zero is returned.
+.Sh SEE ALSO
+.Xr fls 3 ,
+.Xr stdbit 3 ,
+.Xr stdc_leading_zeros 3 ,
+.Xr stdc_first_leading_zero 3 ,
+.Xr stdc_first_trailing_one 3
+.Sh STANDARDS
+The
+.Nm stdc_first_leading_one_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_leading_one
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_first_leading_one_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_leading_one
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_first_leading_one.c b/lib/libc/stdbit/stdc_first_leading_one.c
new file mode 100644
index 000000000000..de436856569f
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_leading_one.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned int
+stdc_first_leading_one_uc(unsigned char x)
+{
+ const int offset = UINT_WIDTH - UCHAR_WIDTH;
+
+ if (x == 0)
+ return (0);
+
+ return (__builtin_clz(x << offset) + 1);
+}
+
+unsigned int
+stdc_first_leading_one_us(unsigned short x)
+{
+ const int offset = UINT_WIDTH - USHRT_WIDTH;
+
+ if (x == 0)
+ return (0);
+
+ return (__builtin_clz(x << offset) + 1);
+}
+
+unsigned int
+stdc_first_leading_one_ui(unsigned int x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_clz(x) + 1);
+}
+
+unsigned int
+stdc_first_leading_one_ul(unsigned long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_clzl(x) + 1);
+}
+
+unsigned int
+stdc_first_leading_one_ull(unsigned long long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_clzll(x) + 1);
+}
diff --git a/lib/libc/stdbit/stdc_first_leading_zero.3 b/lib/libc/stdbit/stdc_first_leading_zero.3
new file mode 100644
index 000000000000..317b6263acb0
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_leading_zero.3
@@ -0,0 +1,92 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_FIRST_LEADING_ZERO 3
+.Os
+.Sh NAME
+.Nm stdc_first_leading_zero
+.Nd find the first leading zero in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_first_leading_zero_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_first_leading_zero_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_first_leading_zero_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_first_leading_zero_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_first_leading_zero_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_first_leading_zero "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_first_leading_zero_ Ns Em type Ns ()
+family of functions returns the index of the most significant clear bit in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_first_leading_zero "value"
+type-generic macro picks the appropriate
+.Nm stdc_first_leading_zero_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the index of the most significant clear bit in
+.Fa value .
+The bits are numbered such that the most significant bit has number\~1,
+and the least significant bit has number
+.Ms w
+where
+.Ms w
+is the number of bits in the type of
+.Fa value .
+If no bits are clear in
+.Fa value
+(i.\^e.\&
+.Fa value
+is the bitwise complement of zero), zero is returned.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_leading_ones 3 ,
+.Xr stdc_first_leading_ones 3 ,
+.Xr stdc_first_trailing_zero 3
+.Sh STANDARDS
+The
+.Nm stdc_first_leading_zero_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_leading_zero
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_first_leading_zero_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_leading_zero
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_first_leading_zero.c b/lib/libc/stdbit/stdc_first_leading_zero.c
new file mode 100644
index 000000000000..e6609b51b648
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_leading_zero.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned int
+stdc_first_leading_zero_uc(unsigned char x)
+{
+ const int offset = UINT_WIDTH - UCHAR_WIDTH;
+
+ if (x == UCHAR_MAX)
+ return (0);
+
+ return (__builtin_clz(~(unsigned int)x << offset) + 1);
+}
+
+unsigned int
+stdc_first_leading_zero_us(unsigned short x)
+{
+ const int offset = UINT_WIDTH - USHRT_WIDTH;
+
+ if (x == USHRT_MAX)
+ return (0);
+
+ return (__builtin_clz(~(unsigned int)x << offset) + 1);
+}
+
+unsigned int
+stdc_first_leading_zero_ui(unsigned int x)
+{
+ if (x == ~0U)
+ return (0);
+
+ return (__builtin_clz(~x) + 1);
+}
+
+unsigned int
+stdc_first_leading_zero_ul(unsigned long x)
+{
+ if (x == ~0UL)
+ return (0);
+
+ return (__builtin_clzl(~x) + 1);
+}
+
+unsigned int
+stdc_first_leading_zero_ull(unsigned long long x)
+{
+ if (x == ~0ULL)
+ return (0);
+
+ return (__builtin_clzll(~x) + 1);
+}
diff --git a/lib/libc/stdbit/stdc_first_trailing_one.3 b/lib/libc/stdbit/stdc_first_trailing_one.3
new file mode 100644
index 000000000000..0b590ac39732
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_trailing_one.3
@@ -0,0 +1,110 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_FIRST_TRAILING_ONE 3
+.Os
+.Sh NAME
+.Nm stdc_first_trailing_one
+.Nd find the first trailing one in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_first_trailing_one_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_first_trailing_one_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_first_trailing_one_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_first_trailing_one_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_first_trailing_one_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_first_trailing_one "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_first_trailing_one_ Ns Em type Ns ()
+family of functions returns the index of the least significant set bit in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_first_trailing_one "value"
+type-generic macro picks the appropriate
+.Nm stdc_first_trailing_one_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Pp
+Functions
+.Fn stdc_first_trailing_one_ui ,
+.Fn stdc_first_trailing_one_ul ,
+and
+.Fn stdc_first_trailing_one_ull
+are identical to
+.Bx 4.3
+functions
+.Xr ffs 3 ,
+.Xr ffsl 3 ,
+and
+.Xr ffsll 3
+respectively, except for operating on unsigned instead of signed values.
+.Sh RETURN VALUES
+Returns the index of the least significant set bit in
+.Fa value .
+The bits are numbered such that the least significant bit has number\~1,
+and the most significant bit has number
+.Ms w
+where
+.Ms w
+is the number of bits in the type of
+.Fa value .
+If no bits are set in
+.Fa value
+(i.\^e.\&
+.Fa value
+is zero), one is returned.
+.Sh SEE ALSO
+.Xr bit_ffs 3 ,
+.Xr ffs 3 ,
+.Xr ffsl 3 ,
+.Xr ffsll 3 ,
+.Xr stdbit 3 ,
+.Xr stdc_trailing_zeros 3 ,
+.Xr stdc_first_trailing_zero 3 ,
+.Xr stdc_first_leading_one 3
+.Sh STANDARDS
+The
+.Nm stdc_first_trailing_one_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_trailing_one
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_first_trailing_one_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_trailing_one
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_first_trailing_one.c b/lib/libc/stdbit/stdc_first_trailing_one.c
new file mode 100644
index 000000000000..22972758d25d
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_trailing_one.c
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdbit.h>
+
+unsigned int
+stdc_first_trailing_one_uc(unsigned char x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_ctz(x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_one_us(unsigned short x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_ctz(x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_one_ui(unsigned int x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_ctz(x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_one_ul(unsigned long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_ctzl(x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_one_ull(unsigned long long x)
+{
+ if (x == 0)
+ return (0);
+
+ return (__builtin_ctzll(x) + 1);
+}
diff --git a/lib/libc/stdbit/stdc_first_trailing_zero.3 b/lib/libc/stdbit/stdc_first_trailing_zero.3
new file mode 100644
index 000000000000..bc4f7982d765
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_trailing_zero.3
@@ -0,0 +1,93 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_FIRST_TRAILING_ZERO 3
+.Os
+.Sh NAME
+.Nm stdc_first_trailing_zero
+.Nd find the first trailing zero in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_first_trailing_zero_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_first_trailing_zero_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_first_trailing_zero_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_first_trailing_zero_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_first_trailing_zero_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_first_trailing_zero "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_first_trailing_zero_ Ns Em type Ns ()
+family of functions returns the index of the least significant clear bit in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_first_trailing_zero "value"
+type-generic macro picks the appropriate
+.Nm stdc_first_trailing_zero_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the index of the least significant clear bit in
+.Fa value .
+The bits are numbered such that the least significant bit has number\~1,
+and the most significant bit has number
+.Ms w
+where
+.Ms w
+is the number of bits in the type of
+.Fa value .
+If no bits are clear in
+.Fa value
+(i.\^e.\&
+.Fa value
+is the bitwise complement of zero), zero is returned.
+.Sh SEE ALSO
+.Xr bit_ffc 3 ,
+.Xr stdbit 3 ,
+.Xr stdc_trailing_ones 3 ,
+.Xr stdc_first_trailing_ones 3 ,
+.Xr stdc_first_leading_zero 3
+.Sh STANDARDS
+The
+.Nm stdc_first_trailing_zero_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_trailing_zero
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_first_trailing_zero_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_first_trailing_zero
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_first_trailing_zero.c b/lib/libc/stdbit/stdc_first_trailing_zero.c
new file mode 100644
index 000000000000..27395c6977c3
--- /dev/null
+++ b/lib/libc/stdbit/stdc_first_trailing_zero.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <limits.h>
+#include <stdbit.h>
+
+unsigned int
+stdc_first_trailing_zero_uc(unsigned char x)
+{
+ if (x == UCHAR_MAX)
+ return (0);
+
+ return (__builtin_ctz(~x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_zero_us(unsigned short x)
+{
+ if (x == USHRT_MAX)
+ return (0);
+
+ return (__builtin_ctz(~x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_zero_ui(unsigned int x)
+{
+ if (x == ~0U)
+ return (0);
+
+ return (__builtin_ctz(~x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_zero_ul(unsigned long x)
+{
+ if (x == ~0UL)
+ return (0);
+
+ return (__builtin_ctzl(~x) + 1);
+}
+
+unsigned int
+stdc_first_trailing_zero_ull(unsigned long long x)
+{
+ if (x == ~0ULL)
+ return (0);
+
+ return (__builtin_ctzll(~x) + 1);
+}
diff --git a/lib/libc/stdbit/stdc_has_single_bit.3 b/lib/libc/stdbit/stdc_has_single_bit.3
new file mode 100644
index 000000000000..8f82c552216a
--- /dev/null
+++ b/lib/libc/stdbit/stdc_has_single_bit.3
@@ -0,0 +1,98 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_HAS_SINGLE_BIT 3
+.Os
+.Sh NAME
+.Nm stdc_has_single_bit
+.Nd check for single bit set
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft bool
+.Fn stdc_has_single_bit_uc "unsigned char value"
+.Ft bool
+.Fn stdc_has_single_bit_us "unsigned short value"
+.Ft bool
+.Fn stdc_has_single_bit_ui "unsigned int value"
+.Ft bool
+.Fn stdc_has_single_bit_ul "unsigned long value"
+.Ft bool
+.Fn stdc_has_single_bit_ull "unsigned long long value"
+.Ft bool
+.Fn stdc_has_single_bit "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_has_single_bit_ Ns Em type Ns ()
+family of functions checks if there is exactly one bit
+set in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_has_single_bit "value"
+type-generic macro picks the appropriate
+.Nm stdc_has_single_bit_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Pp
+The functions in this family behave similarly to the
+.Fn powerof2 "value"
+macro of
+.In sys/param.h ,
+but differ when
+.Fa value
+is zero: while
+.Fn powerof2
+considers zero to be a power of two,
+.Fn stdc_has_single_bit
+does not.
+.Sh RETURN VALUES
+Returns
+.Sy true
+if exactly one bit is set in
+.Fa value ,
+otherwise returns
+.Sy false .
+I.\^e. the function determines if
+.Fa value
+is a power of two.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_count_ones 3
+.Sh STANDARDS
+The
+.Nm stdc_has_single_bit_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_has_single_bit
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_has_single_bit_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_has_single_bit
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_has_single_bit.c b/lib/libc/stdbit/stdc_has_single_bit.c
new file mode 100644
index 000000000000..e5f676265551
--- /dev/null
+++ b/lib/libc/stdbit/stdc_has_single_bit.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdbit.h>
+#include <stdbool.h>
+
+bool
+stdc_has_single_bit_uc(unsigned char x)
+{
+ return (x != 0 && (x & x - 1) == 0);
+}
+
+bool
+stdc_has_single_bit_us(unsigned short x)
+{
+ return (x != 0 && (x & x - 1) == 0);
+}
+
+bool
+stdc_has_single_bit_ui(unsigned int x)
+{
+ return (x != 0 && (x & x - 1) == 0);
+}
+
+bool
+stdc_has_single_bit_ul(unsigned long x)
+{
+ return (x != 0 && (x & x - 1) == 0);
+}
+
+bool
+stdc_has_single_bit_ull(unsigned long long x)
+{
+ return (x != 0 && (x & x - 1) == 0);
+}
diff --git a/lib/libc/stdbit/stdc_leading_ones.3 b/lib/libc/stdbit/stdc_leading_ones.3
new file mode 100644
index 000000000000..6cf7989b73ea
--- /dev/null
+++ b/lib/libc/stdbit/stdc_leading_ones.3
@@ -0,0 +1,86 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_LEADING_ONES 3
+.Os
+.Sh NAME
+.Nm stdc_leading_ones
+.Nd find the number of leading ones in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_leading_ones_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_leading_ones_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_leading_ones_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_leading_ones_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_leading_ones_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_leading_ones "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_leading_ones_ Ns Em type Ns ()
+family of functions returns the number of leading ones in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_leading_ones "value"
+type-generic macro picks the appropriate
+.Nm stdc_leading_ones_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the number of leading ones in
+.Fa value .
+If
+.Fa value
+is all ones,
+the total number of bits in the type of
+.Fa value
+is returned.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_leading_zeros 3 ,
+.Xr stdc_trailing_ones 3 ,
+.Xr stdc_first_leading_zero 3
+.Sh STANDARDS
+The
+.Nm stdc_leading_ones_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_leading_ones
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_leading_ones_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_leading_ones
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_leading_ones.c b/lib/libc/stdbit/stdc_leading_ones.c
new file mode 100644
index 000000000000..79d3ec7f2065
--- /dev/null
+++ b/lib/libc/stdbit/stdc_leading_ones.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <stdbit.h>
+
+/* Avoid triggering undefined behavior if x == 0. */
+static_assert(UCHAR_WIDTH < UINT_WIDTH,
+ "stdc_leading_ones_uc needs UCHAR_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_leading_ones_uc(unsigned char x)
+{
+ const int offset = UINT_WIDTH - UCHAR_WIDTH;
+
+ return (__builtin_clz(~(x << offset)));
+}
+
+/* Avoid triggering undefined behavior if x == 0. */
+static_assert(USHRT_WIDTH < UINT_WIDTH,
+ "stdc_leading_ones_us needs USHRT_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_leading_ones_us(unsigned short x)
+{
+ const int offset = UINT_WIDTH - USHRT_WIDTH;
+
+ return (__builtin_clz(~(x << offset)));
+}
+
+unsigned int
+stdc_leading_ones_ui(unsigned int x)
+{
+ if (x == ~0U)
+ return (UINT_WIDTH);
+
+ return (__builtin_clz(~x));
+}
+
+unsigned int
+stdc_leading_ones_ul(unsigned long x)
+{
+ if (x == ~0UL)
+ return (ULONG_WIDTH);
+
+ return (__builtin_clzl(~x));
+}
+
+unsigned int
+stdc_leading_ones_ull(unsigned long long x)
+{
+ if (x == ~0ULL)
+ return (ULLONG_WIDTH);
+
+ return (__builtin_clzll(~x));
+}
diff --git a/lib/libc/stdbit/stdc_leading_zeros.3 b/lib/libc/stdbit/stdc_leading_zeros.3
new file mode 100644
index 000000000000..7a7a203ac78c
--- /dev/null
+++ b/lib/libc/stdbit/stdc_leading_zeros.3
@@ -0,0 +1,86 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_LEADING_ZEROS 3
+.Os
+.Sh NAME
+.Nm stdc_leading_zeros
+.Nd find the number of leading zeros in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_leading_zeros_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_leading_zeros_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_leading_zeros_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_leading_zeros_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_leading_zeros_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_leading_zeros "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_leading_zeros_ Ns Em type Ns ()
+family of functions returns the number of leading zeros in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_leading_zeros "value"
+type-generic macro picks the appropriate
+.Nm stdc_leading_zeros_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the number of leading zeros in
+.Fa value .
+If
+.Fa value
+is all zeros,
+the total number of bits in the type of
+.Fa value
+is returned.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_leading_ones 3 ,
+.Xr stdc_trailing_zeros 3 ,
+.Xr stdc_first_leading_one 3
+.Sh STANDARDS
+The
+.Nm stdc_leading_zeros_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_leading_zeros
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_leading_zeros_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_leading_zeros
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_leading_zeros.c b/lib/libc/stdbit/stdc_leading_zeros.c
new file mode 100644
index 000000000000..2fdf64ec93d4
--- /dev/null
+++ b/lib/libc/stdbit/stdc_leading_zeros.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <stdbit.h>
+
+/* Offset must be greater than zero. */
+static_assert(UCHAR_WIDTH < UINT_WIDTH,
+ "stdc_leading_zeros_uc needs UCHAR_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_leading_zeros_uc(unsigned char x)
+{
+ const int offset = UINT_WIDTH - UCHAR_WIDTH;
+
+ return (__builtin_clz((x << offset) + (1U << (offset - 1))));
+}
+
+/* Offset must be greater than zero. */
+static_assert(USHRT_WIDTH < UINT_WIDTH,
+ "stdc_leading_zeros_us needs USHRT_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_leading_zeros_us(unsigned short x)
+{
+ const int offset = UINT_WIDTH - USHRT_WIDTH;
+
+ return (__builtin_clz((x << offset) + (1U << (offset - 1))));
+}
+
+unsigned int
+stdc_leading_zeros_ui(unsigned int x)
+{
+ if (x == 0)
+ return (UINT_WIDTH);
+
+ return (__builtin_clz(x));
+}
+
+unsigned int
+stdc_leading_zeros_ul(unsigned long x)
+{
+ if (x == 0)
+ return (ULONG_WIDTH);
+
+ return (__builtin_clzl(x));
+}
+
+unsigned int
+stdc_leading_zeros_ull(unsigned long long x)
+{
+ if (x == 0)
+ return (ULLONG_WIDTH);
+
+ return (__builtin_clzll(x));
+}
diff --git a/lib/libc/stdbit/stdc_trailing_ones.3 b/lib/libc/stdbit/stdc_trailing_ones.3
new file mode 100644
index 000000000000..96277506fc17
--- /dev/null
+++ b/lib/libc/stdbit/stdc_trailing_ones.3
@@ -0,0 +1,86 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_TRAILING_ONES 3
+.Os
+.Sh NAME
+.Nm stdc_trailing_ones
+.Nd find the number of trailing ones in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_trailing_ones_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_trailing_ones_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_trailing_ones_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_trailing_ones_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_trailing_ones_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_trailing_ones "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_trailing_ones_ Ns Em type Ns ()
+family of functions returns the number of trailing ones in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_trailing_ones "value"
+type-generic macro picks the appropriate
+.Nm stdc_trailing_ones_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the number of trailing ones in
+.Fa value .
+If
+.Fa value
+is all ones,
+the total number of bits in the type of
+.Fa value
+is returned.
+.Sh SEE ALSO
+.Xr stdbit 3 ,
+.Xr stdc_leading_ones 3 ,
+.Xr stdc_trailing_zeros 3 ,
+.Xr stdc_first_trailing_zero 3
+.Sh STANDARDS
+The
+.Nm stdc_trailing_ones_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_trailing_ones
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_trailing_ones_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_trailing_ones
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_trailing_ones.c b/lib/libc/stdbit/stdc_trailing_ones.c
new file mode 100644
index 000000000000..c1a0e6b991da
--- /dev/null
+++ b/lib/libc/stdbit/stdc_trailing_ones.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <stdbit.h>
+
+/* Avoid triggering undefined behavior if x == ~0. */
+static_assert(UCHAR_WIDTH < UINT_WIDTH,
+ "stdc_trailing_ones_uc needs UCHAR_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_trailing_ones_uc(unsigned char x)
+{
+ return (__builtin_ctz(~x));
+}
+
+/* Avoid triggering undefined behavior if x == ~0. */
+static_assert(USHRT_WIDTH < UINT_WIDTH,
+ "stdc_trailing_ones_uc needs USHRT_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_trailing_ones_us(unsigned short x)
+{
+ return (__builtin_ctz(~x));
+}
+
+unsigned int
+stdc_trailing_ones_ui(unsigned int x)
+{
+ if (x == ~0U)
+ return (UINT_WIDTH);
+
+ return (__builtin_ctz(~x));
+}
+
+unsigned int
+stdc_trailing_ones_ul(unsigned long x)
+{
+ if (x == ~0UL)
+ return (ULONG_WIDTH);
+
+ return (__builtin_ctzl(~x));
+}
+
+unsigned int
+stdc_trailing_ones_ull(unsigned long long x)
+{
+ if (x == ~0ULL)
+ return (ULLONG_WIDTH);
+
+ return (__builtin_ctzll(~x));
+}
diff --git a/lib/libc/stdbit/stdc_trailing_zeros.3 b/lib/libc/stdbit/stdc_trailing_zeros.3
new file mode 100644
index 000000000000..4bc675590ee7
--- /dev/null
+++ b/lib/libc/stdbit/stdc_trailing_zeros.3
@@ -0,0 +1,87 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 9, 2025
+.Dt STDC_TRAILING_ZEROS 3
+.Os
+.Sh NAME
+.Nm stdc_trailing_zeros
+.Nd find the number of trailing zeros in an integer
+.Sh SYNOPSIS
+.Lb libc
+.In stdbit.h
+.Ft unsigned int
+.Fn stdc_trailing_zeros_uc "unsigned char value"
+.Ft unsigned int
+.Fn stdc_trailing_zeros_us "unsigned short value"
+.Ft unsigned int
+.Fn stdc_trailing_zeros_ui "unsigned int value"
+.Ft unsigned int
+.Fn stdc_trailing_zeros_ul "unsigned long value"
+.Ft unsigned int
+.Fn stdc_trailing_zeros_ull "unsigned long long value"
+.Ft unsigned int
+.Fn stdc_trailing_zeros "value"
+.Sh DESCRIPTION
+The
+.Nm stdc_trailing_zeros_ Ns Em type Ns ()
+family of functions returns the number of trailing zeros in
+.Fa value ,
+where
+.Fa value
+is of type
+.Va unsigned char ,
+.Va unsigned short ,
+.Va unsigned int ,
+.Va unsigned long ,
+or
+.Va unsigned long long
+for
+.Em type
+being
+.Sy uc ,
+.Sy us ,
+.Sy ui ,
+.Sy ul ,
+or
+.Sy ull
+respectively.
+The
+.Fn stdc_trailing_zeros "value"
+type-generic macro picks the appropriate
+.Nm stdc_trailing_zeros_ Ns Em type Ns ()
+function based on the type of
+.Fa value .
+.Sh RETURN VALUES
+Returns the number of trailing zeros in
+.Fa value .
+If
+.Fa value
+is all zeros,
+the total number of bits in the type of
+.Fa value
+is returned.
+.Sh SEE ALSO
+.Xr ffs 3 ,
+.Xr stdbit 3 ,
+.Xr stdc_leading_zeros 3 ,
+.Xr stdc_trailing_ones 3 ,
+.Xr stdc_first_trailing_one 3
+.Sh STANDARDS
+The
+.Nm stdc_trailing_zeros_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_trailing_zeros
+type-generic macro conform to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Nm stdc_trailing_zeros_ Ns Em type Ns ()
+family of functions and the
+.Fn stdc_trailing_zeros
+type-generic macro were added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdbit/stdc_trailing_zeros.c b/lib/libc/stdbit/stdc_trailing_zeros.c
new file mode 100644
index 000000000000..6213f62cffdb
--- /dev/null
+++ b/lib/libc/stdbit/stdc_trailing_zeros.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <stdbit.h>
+
+/* Ensure we do not shift 1U out of range. */
+static_assert(UCHAR_WIDTH < UINT_WIDTH,
+ "stdc_trailing_zeros_uc needs UCHAR_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_trailing_zeros_uc(unsigned char x)
+{
+ return (__builtin_ctz(x | 1U << UCHAR_WIDTH));
+}
+
+/* Ensure we do not shift 1U out of range. */
+static_assert(USHRT_WIDTH < UINT_WIDTH,
+ "stdc_trailing_zeros_uc needs USHRT_WIDTH < UINT_WIDTH");
+
+unsigned int
+stdc_trailing_zeros_us(unsigned short x)
+{
+ return (__builtin_ctz(x | 1U << USHRT_WIDTH));
+}
+
+unsigned int
+stdc_trailing_zeros_ui(unsigned int x)
+{
+ if (x == 0U)
+ return (UINT_WIDTH);
+
+ return (__builtin_ctz(x));
+}
+
+unsigned int
+stdc_trailing_zeros_ul(unsigned long x)
+{
+ if (x == 0UL)
+ return (ULONG_WIDTH);
+
+ return (__builtin_ctzl(x));
+}
+
+unsigned int
+stdc_trailing_zeros_ull(unsigned long long x)
+{
+ if (x == 0ULL)
+ return (ULLONG_WIDTH);
+
+ return (__builtin_ctzll(x));
+}
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index ca199a669be1..b878a7625e9f 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -7,10 +7,10 @@ MISRCS+=C99_Exit.c a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
div.c exit.c getenv.c getopt.c getopt_long.c \
getsubopt.c hcreate.c hcreate_r.c hdestroy_r.c heapsort.c heapsort_b.c \
hsearch_r.c imaxabs.c imaxdiv.c \
- insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \
+ insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c memalignment.c \
merge.c mergesort_b.c ptsname.c qsort.c qsort_r.c qsort_r_compat.c \
qsort_s.c quick_exit.c radixsort.c rand.c \
- random.c reallocarray.c reallocf.c realpath.c remque.c \
+ random.c reallocarray.c reallocf.c realpath.c recallocarray.c remque.c \
set_constraint_handler_s.c strfmon.c strtoimax.c \
strtol.c strtold.c strtoll.c strtoq.c strtoul.c strtonum.c strtoull.c \
strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c
@@ -35,7 +35,7 @@ MAN+= a64l.3 abort.3 abs.3 atexit.3 atof.3 \
atoi.3 atol.3 at_quick_exit.3 bsearch.3 \
div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 \
hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 llabs.3 lldiv.3 \
- lsearch.3 memory.3 ptsname.3 qsort.3 \
+ lsearch.3 memalignment.3 memory.3 ptsname.3 qsort.3 \
quick_exit.3 \
radixsort.3 rand.3 random.3 reallocarray.3 reallocf.3 realpath.3 \
set_constraint_handler_s.3 \
@@ -76,6 +76,7 @@ MLINKS+=random.3 initstate.3 \
random.3 srandom.3 \
random.3 srandomdev.3
MLINKS+=radixsort.3 sradixsort.3
+MLINKS+=reallocarray.3 recallocarray.3
MLINKS+=set_constraint_handler_s.3 abort_handler_s.3
MLINKS+=set_constraint_handler_s.3 ignore_handler_s.3
MLINKS+=strfmon.3 strfmon_l.3
diff --git a/lib/libc/stdlib/Symbol.map b/lib/libc/stdlib/Symbol.map
index 2b79ca2ece8b..8b7e97c3cbdc 100644
--- a/lib/libc/stdlib/Symbol.map
+++ b/lib/libc/stdlib/Symbol.map
@@ -131,6 +131,11 @@ FBSD_1.8 {
getenv_r;
};
+FBSD_1.9 {
+ memalignment;
+ recallocarray;
+};
+
FBSDprivate_1.0 {
__system;
_system;
diff --git a/lib/libc/stdlib/exit.3 b/lib/libc/stdlib/exit.3
index bfb14c5c9f83..40010e678e5f 100644
--- a/lib/libc/stdlib/exit.3
+++ b/lib/libc/stdlib/exit.3
@@ -104,7 +104,7 @@ may be used to provide more information to the parent process.
.Pp
The complete
.Fa status
-value is avaliable as
+value is available as
.Va si_status
member of the
.Vt siginfo_t
diff --git a/lib/libc/stdlib/malloc/jemalloc/jemalloc.3 b/lib/libc/stdlib/malloc/jemalloc/jemalloc.3
index a4ea3e1f54a9..1c99352a6ae2 100644
--- a/lib/libc/stdlib/malloc/jemalloc/jemalloc.3
+++ b/lib/libc/stdlib/malloc/jemalloc/jemalloc.3
@@ -1,13 +1,13 @@
'\" t
.\" Title: JEMALLOC
.\" Author: Jason Evans
-.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\" Date: 11/10/2019
+.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
+.\" Date: 05/06/2022
.\" Manual: User Manual
-.\" Source: jemalloc 5.2.1-0-gea6b3e973b477b8061e0076bb257dbd7f3faa756
+.\" Source: jemalloc 5.3.0-0-g54eaed1d8b56b1aa528be3bdd1877e59c56fa90c
.\" Language: English
.\"
-.TH "JEMALLOC" "3" "11/10/2019" "jemalloc 5.2.1-0-gea6b3e973b47" "User Manual"
+.TH "JEMALLOC" "3" "05/06/2022" "jemalloc 5.3.0-0-g54eaed1d8b56" "User Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -31,7 +31,7 @@
jemalloc \- general purpose memory allocation functions
.SH "LIBRARY"
.PP
-This manual describes jemalloc 5\&.2\&.1\-0\-gea6b3e973b477b8061e0076bb257dbd7f3faa756\&. More information can be found at the
+This manual describes jemalloc 5\&.3\&.0\-0\-g54eaed1d8b56b1aa528be3bdd1877e59c56fa90c\&. More information can be found at the
\m[blue]\fBjemalloc website\fR\m[]\&\s-2\u[1]\d\s+2\&.
.PP
The following configuration options are enabled in libc\*(Aqs built\-in jemalloc:
@@ -603,7 +603,7 @@ T}
:T{
8 KiB
T}:T{
-[40 KiB, 48 KiB, 54 KiB, 64 KiB]
+[40 KiB, 48 KiB, 56 KiB, 64 KiB]
T}
:T{
16 KiB
@@ -848,6 +848,11 @@ in these cases\&. This option is disabled by default unless
is specified during configuration, in which case it is enabled by default\&.
.RE
.PP
+opt\&.cache_oblivious (\fBbool\fR) r\-
+.RS 4
+Enable / Disable cache\-oblivious large allocation alignment, for large requests with no alignment constraints\&. If this feature is disabled, all large allocations are page\-aligned as an implementation artifact, which can severely harm CPU cache utilization\&. However, the cache\-oblivious layout comes at the cost of one extra page per large allocation, which in the most extreme case increases physical memory usage for the 16 KiB size class to 20 KiB\&. This option is enabled by default\&.
+.RE
+.PP
opt\&.metadata_thp (\fBconst char *\fR) r\-
.RS 4
Controls whether to allow jemalloc to use transparent huge page (THP) for internal metadata (see
@@ -859,6 +864,11 @@ uses no THP initially, but may begin to do so when metadata usage reaches certai
\(lqdisabled\(rq\&.
.RE
.PP
+opt\&.trust_madvise (\fBbool\fR) r\-
+.RS 4
+If true, do not perform runtime check for MADV_DONTNEED, to check that it actually zeros pages\&. The default is disabled on Linux and enabled elsewhere\&.
+.RE
+.PP
opt\&.retain (\fBbool\fR) r\-
.RS 4
If true, retain unused virtual memory for later reuse rather than discarding it by calling
@@ -990,6 +1000,28 @@ is enabled\&. The default is
\(lq\(rq\&.
.RE
.PP
+opt\&.stats_interval (\fBint64_t\fR) r\-
+.RS 4
+Average interval between statistics outputs, as measured in bytes of allocation activity\&. The actual interval may be sporadic because decentralized event counters are used to avoid synchronization bottlenecks\&. The output may be triggered on any thread, which then calls
+malloc_stats_print()\&.
+opt\&.stats_interval_opts
+can be combined to specify output options\&. By default, interval\-triggered stats output is disabled (encoded as \-1)\&.
+.RE
+.PP
+opt\&.stats_interval_opts (\fBconst char *\fR) r\-
+.RS 4
+Options (the
+\fIopts\fR
+string) to pass to the
+malloc_stats_print()
+for interval based statistics printing (enabled through
+opt\&.stats_interval)\&. See available options in
+malloc_stats_print()\&. Has no effect unless
+opt\&.stats_interval
+is enabled\&. The default is
+\(lq\(rq\&.
+.RE
+.PP
opt\&.junk (\fBconst char *\fR) r\- [\fB\-\-enable\-fill\fR]
.RS 4
Junk filling\&. If set to
@@ -1046,13 +1078,13 @@ This option is disabled by default\&.
opt\&.tcache (\fBbool\fR) r\-
.RS 4
Thread\-specific caching (tcache) enabled/disabled\&. When there are multiple threads, each thread uses a tcache for objects up to a certain size\&. Thread\-specific caching allows many allocations to be satisfied without performing any thread synchronization, at the cost of increased memory use\&. See the
-opt\&.lg_tcache_max
+opt\&.tcache_max
option for related tuning information\&. This option is enabled by default\&.
.RE
.PP
-opt\&.lg_tcache_max (\fBsize_t\fR) r\-
+opt\&.tcache_max (\fBsize_t\fR) r\-
.RS 4
-Maximum size class (log base 2) to cache in the thread\-specific cache (tcache)\&. At a minimum, all small size classes are cached, and at a maximum all large size classes are cached\&. The default maximum is 32 KiB (2^15)\&.
+Maximum size class to cache in the thread\-specific cache (tcache)\&. At a minimum, the first size class is cached; and at a maximum, size classes up to 8 MiB can be cached\&. The default maximum is 32 KiB (2^15)\&. As a convenience, this may also be set by specifying lg_tcache_max, which will be taken to be the base\-2 logarithm of the setting of tcache_max\&.
.RE
.PP
opt\&.thp (\fBconst char *\fR) r\-
@@ -1091,7 +1123,8 @@ for heap profile format documentation\&.
opt\&.prof_prefix (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
.RS 4
Filename prefix for profile dumps\&. If the prefix is set to the empty string, no automatic dumps will occur; this is primarily useful for disabling the automatic final heap dump (which also disables leak reporting, if enabled)\&. The default prefix is
-jeprof\&.
+jeprof\&. This prefix value can be overridden by
+prof\&.prefix\&.
.RE
.PP
opt\&.prof_active (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
@@ -1129,7 +1162,9 @@ Average interval (log base 2) between memory profile dumps, as measured in bytes
<prefix>
is controlled by the
opt\&.prof_prefix
-option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
+and
+prof\&.prefix
+options\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
.RE
.PP
opt\&.prof_gdump (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
@@ -1147,7 +1182,9 @@ function to dump final memory usage to a file named according to the pattern
<prefix>
is controlled by the
opt\&.prof_prefix
-option\&. Note that
+and
+prof\&.prefix
+options\&. Note that
atexit()
may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
atexit(), so this option is not universally usable (though the application can register its own
@@ -1161,7 +1198,46 @@ Leak reporting enabled/disabled\&. If enabled, use an
\fBatexit\fR(3)
function to report memory leaks detected by allocation sampling\&. See the
opt\&.prof
-option for information on analyzing heap profile output\&. This option is disabled by default\&.
+option for information on analyzing heap profile output\&. Works only when combined with
+opt\&.prof_final, otherwise does nothing\&. This option is disabled by default\&.
+.RE
+.PP
+opt\&.prof_leak_error (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
+.RS 4
+Similar to
+opt\&.prof_leak, but makes the process exit with error code 1 if a memory leak is detected\&. This option supersedes
+opt\&.prof_leak, meaning that if both are specified, this option takes precedence\&. When enabled, also enables
+opt\&.prof_leak\&. Works only when combined with
+opt\&.prof_final, otherwise does nothing\&. This option is disabled by default\&.
+.RE
+.PP
+opt\&.zero_realloc (\fBconst char *\fR) r\-
+.RS 4
+Determines the behavior of
+realloc()
+when passed a value of zero for the new size\&.
+\(lqalloc\(rq
+treats this as an allocation of size zero (and returns a non\-null result except in case of resource exhaustion)\&.
+\(lqfree\(rq
+treats this as a deallocation of the pointer, and returns
+\fBNULL\fR
+without setting
+\fIerrno\fR\&.
+\(lqabort\(rq
+aborts the process if zero is passed\&. The default is
+\(lqfree\(rq
+on Linux and Windows, and
+\(lqalloc\(rq
+elsewhere\&.
+.sp
+There is considerable divergence of behaviors across implementations in handling this case\&. Many have the behavior of
+\(lqfree\(rq\&. This can introduce security vulnerabilities, since a
+\fBNULL\fR
+return value indicates failure, and the continued validity of the passed\-in pointer (per POSIX and C11)\&.
+\(lqalloc\(rq
+is safe, but can cause leaks in programs that expect the common behavior\&. Programs intended to be portable and leak\-free cannot assume either behavior, and must therefore never call realloc with a size of 0\&. The
+\(lqabort\(rq
+option enables these testing this behavior\&.
.RE
.PP
thread\&.arena (\fBunsigned\fR) rw
@@ -1182,7 +1258,7 @@ Get a pointer to the the value that is returned by the
thread\&.allocated
mallctl\&. This is useful for avoiding the overhead of repeated
mallctl*()
-calls\&.
+calls\&. Note that the underlying counter should not be modified by the application\&.
.RE
.PP
thread\&.deallocated (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
@@ -1196,7 +1272,23 @@ Get a pointer to the the value that is returned by the
thread\&.deallocated
mallctl\&. This is useful for avoiding the overhead of repeated
mallctl*()
-calls\&.
+calls\&. Note that the underlying counter should not be modified by the application\&.
+.RE
+.PP
+thread\&.peak\&.read (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
+.RS 4
+Get an approximation of the maximum value of the difference between the number of bytes allocated and the number of bytes deallocated by the calling thread since the last call to
+thread\&.peak\&.reset, or since the thread\*(Aqs creation if it has not called
+thread\&.peak\&.reset\&. No guarantees are made about the quality of the approximation, but jemalloc currently endeavors to maintain accuracy to within one hundred kilobytes\&.
+.RE
+.PP
+thread\&.peak\&.reset (\fBvoid\fR) \-\- [\fB\-\-enable\-stats\fR]
+.RS 4
+Resets the counter for net bytes allocated in the calling thread to zero\&. This affects subsequent calls to
+thread\&.peak\&.read, but not the values returned by
+thread\&.allocated
+or
+thread\&.deallocated\&.
.RE
.PP
thread\&.tcache\&.enabled (\fBbool\fR) rw
@@ -1224,11 +1316,27 @@ Control whether sampling is currently active for the calling thread\&. This is a
prof\&.active; both must be active for the calling thread to sample\&. This flag is enabled by default\&.
.RE
.PP
+thread\&.idle (\fBvoid\fR) \-\-
+.RS 4
+Hints to jemalloc that the calling thread will be idle for some nontrivial period of time (say, on the order of seconds), and that doing some cleanup operations may be beneficial\&. There are no guarantees as to what specific operations will be performed; currently this flushes the caller\*(Aqs tcache and may (according to some heuristic) purge its associated arena\&.
+.sp
+This is not intended to be a general\-purpose background activity mechanism, and threads should not wake up multiple times solely to call it\&. Rather, a thread waiting for a task should do a timed wait first, call
+thread\&.idle
+if no task appears in the timeout interval, and then do an untimed wait\&. For such a background activity mechanism, see
+background_thread\&.
+.RE
+.PP
tcache\&.create (\fBunsigned\fR) r\-
.RS 4
Create an explicit thread\-specific cache (tcache) and return an identifier that can be passed to the
\fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
macro to explicitly use the specified cache rather than the automatically managed one that is used by default\&. Each explicit cache can be used by only one thread at a time; the application must assure that this constraint holds\&.
+.sp
+If the amount of space supplied for storing the thread\-specific cache identifier does not equal
+sizeof(\fBunsigned\fR), no thread\-specific cache will be created, no data will be written to the space pointed by
+\fIoldp\fR, and
+\fI*oldlenp\fR
+will be set to 0\&.
.RE
.PP
tcache\&.flush (\fBunsigned\fR) \-w
@@ -1634,6 +1742,12 @@ Maximum size supported by this large size class\&.
arenas\&.create (\fBunsigned\fR, \fBextent_hooks_t *\fR) rw
.RS 4
Explicitly create a new arena outside the range of automatically managed arenas, with optionally specified extent hooks, and return the new arena index\&.
+.sp
+If the amount of space supplied for storing the arena index does not equal
+sizeof(\fBunsigned\fR), no arena will be created, no data will be written to the space pointed by
+\fIoldp\fR, and
+\fI*oldlenp\fR
+will be set to 0\&.
.RE
.PP
arenas\&.lookup (\fBunsigned\fR, \fBvoid*\fR) rw
@@ -1666,7 +1780,16 @@ Dump a memory profile to the specified file, or if NULL is specified, to a file
<prefix>
is controlled by the
opt\&.prof_prefix
-option\&.
+and
+prof\&.prefix
+options\&.
+.RE
+.PP
+prof\&.prefix (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
+.RS 4
+Set the filename prefix for profile dumps\&. See
+opt\&.prof_prefix
+for the default setting\&. This can be useful to differentiate profile dumps such as from forked processes\&.
.RE
.PP
prof\&.gdump (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
@@ -1676,7 +1799,9 @@ When enabled, trigger a memory profile dump every time the total virtual memory
<prefix>
is controlled by the
opt\&.prof_prefix
-option\&.
+and
+prof\&.prefix
+options\&.
.RE
.PP
prof\&.reset (\fBsize_t\fR) \-w [\fB\-\-enable\-prof\fR]
@@ -1752,6 +1877,18 @@ for details)\&. Retained memory is excluded from mapped memory statistics, e\&.g
stats\&.mapped\&.
.RE
.PP
+stats\&.zero_reallocs (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
+.RS 4
+Number of times that the
+realloc()
+was called with a non\-\fBNULL\fR
+pointer argument and a
+\fB0\fR
+size argument\&. This is a fundamentally unsafe pattern in portable programs; see
+opt\&.zero_realloc
+for details\&.
+.RE
+.PP
stats\&.background_thread\&.num_threads (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
.RS 4
Number of
@@ -1825,6 +1962,26 @@ is one of the counters in
mutex profiling counters\&.
.RE
.PP
+stats\&.mutexes\&.prof_thds_data\&.{counter} (\fBcounter specific type\fR) r\- [\fB\-\-enable\-stats\fR]
+.RS 4
+Statistics on
+\fIprof\fR
+threads data mutex (global scope; profiling related)\&.
+{counter}
+is one of the counters in
+mutex profiling counters\&.
+.RE
+.PP
+stats\&.mutexes\&.prof_dump\&.{counter} (\fBcounter specific type\fR) r\- [\fB\-\-enable\-stats\fR]
+.RS 4
+Statistics on
+\fIprof\fR
+dumping mutex (global scope; profiling related)\&.
+{counter}
+is one of the counters in
+mutex profiling counters\&.
+.RE
+.PP
stats\&.mutexes\&.reset (\fBvoid\fR) \-\- [\fB\-\-enable\-stats\fR]
.RS 4
Reset all mutex profile statistics, including global mutexes, arena mutexes and bin mutexes\&.
@@ -2242,7 +2399,7 @@ heap_v2/524288
[\&.\&.\&.]
@ 0x5f86da8 0x5f5a1dc [\&.\&.\&.] 0x29e4d4e 0xa200316 0xabb2988 [\&.\&.\&.]
t*: 13: 6688 [0: 0]
- t3: 12: 6496 [0: ]
+ t3: 12: 6496 [0: 0]
t99: 1: 192 [0: 0]
[\&.\&.\&.]
@@ -2264,9 +2421,9 @@ to indicate descriptions of the corresponding fields\&.
<heap_profile_format_version>/<mean_sample_interval>
<aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
[\&.\&.\&.]
- <thread_3_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
+ <thread_3_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
[\&.\&.\&.]
- <thread_99_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
+ <thread_99_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
[\&.\&.\&.]
@ <top_frame> <frame> [\&.\&.\&.] <frame> <frame> <frame> [\&.\&.\&.]
<backtrace_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
@@ -2432,7 +2589,8 @@ is not
\fInewlen\fR
is too large or too small\&. Alternatively,
\fI*oldlenp\fR
-is too large or too small; in this case as much data as possible are read despite the error\&.
+is too large or too small; when it happens, except for a very few cases explicitly documented otherwise, as much data as possible are read despite the error, with the amount of data read being recorded in
+\fI*oldlenp\fR\&.
.RE
.PP
ENOENT
diff --git a/lib/libc/stdlib/memalignment.3 b/lib/libc/stdlib/memalignment.3
new file mode 100644
index 000000000000..4a2269a82c81
--- /dev/null
+++ b/lib/libc/stdlib/memalignment.3
@@ -0,0 +1,53 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 10, 2025
+.Dt MEMALIGNMENT 3
+.Os
+.Sh NAME
+.Nm memalignment
+.Nd find the memory alignment of an object
+.Sh SYNOPSIS
+.Lb libc
+.In stdlib.h
+.Ft size_t
+.Fn memalignment "const void *ptr"
+.Sh DESCRIPTION
+The
+.Fn memalignment
+function determines the alignment of the object pointed to by
+.Fa ptr .
+This alignment is a power of\~2, and may be larger than the range
+supported by the
+.Sy alignof
+operator.
+The value returned can be compared to the result of
+.Sy alignof ,
+and if it is greater or equal, the alignment requirement of the operand
+is satisfied.
+.Sh RETURN VALUES
+Returns the alignment of
+.Fa ptr
+as a power of\~2.
+If
+.Fa ptr
+is a null pointer, an alignment of zero is returned.
+An alignment of zero indicates that the tested pointer cannot be used to
+access an object of any type.
+.Sh SEE ALSO
+.Xr aligned_alloc 3 ,
+.Xr posix_memalign 3
+.Sh STANDARDS
+The
+.Fn memalignment
+function conforms to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Fn memalignment
+function was added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdlib/memalignment.c b/lib/libc/stdlib/memalignment.c
new file mode 100644
index 000000000000..771ddc2f5253
--- /dev/null
+++ b/lib/libc/stdlib/memalignment.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+size_t
+memalignment(const void *p)
+{
+ uintptr_t align;
+
+ if (p == NULL)
+ return (0);
+
+ align = (uintptr_t)p;
+ align &= -align;
+
+#if UINTPTR_MAX > SIZE_MAX
+ /* if alignment overflows size_t, return maximum possible */
+ if (align > SIZE_MAX)
+ align = SIZE_MAX - SIZE_MAX/2;
+#endif
+
+ return (align);
+}
diff --git a/lib/libc/stdlib/reallocarray.3 b/lib/libc/stdlib/reallocarray.3
index 80035c67a497..9a2ab5c7a840 100644
--- a/lib/libc/stdlib/reallocarray.3
+++ b/lib/libc/stdlib/reallocarray.3
@@ -26,7 +26,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 1, 2015
+.Dd October 2, 2025
.Dt REALLOCARRAY 3
.Os
.Sh NAME
@@ -38,6 +38,8 @@
.In stdlib.h
.Ft void *
.Fn reallocarray "void *ptr" "size_t nmemb" "size_t size"
+.Ft void *
+.Fn recallocarray "void *ptr" "size_t oldnmeb" "size_t nmemb" size_t size"
.Sh DESCRIPTION
The
.Fn reallocarray
@@ -52,6 +54,33 @@ and checks for integer overflow in the calculation
.Fa nmemb
*
.Fa size .
+.Pp
+The
+.Fn recallocarray
+function is similar to the
+.Fn reallocarray
+function
+except it ensures newly allocated memory is cleared similar to
+.Fn calloc .
+If
+.Fa ptr
+is
+.Dv NULL ,
+.Fa oldnmemb
+is ignored and the call is equivalent to
+.Fn calloc .
+If
+.Fa ptr
+is not
+.Dv NULL ,
+.Fa oldnmemb
+must be a value such that
+.Fa oldnmemb
+*
+.Fa size
+is the size of the earlier allocation that returned
+.Fa ptr ,
+otherwise the behaviour is undefined.
.Sh RETURN VALUES
The
.Fn reallocarray
@@ -142,3 +171,9 @@ function first appeared in
.Ox 5.6
and
.Fx 11.0 .
+The
+.Fn recallocarray
+function first appeared in
+.Ox 6.1
+and
+.Fx 16.0 .
diff --git a/lib/libc/stdlib/reallocarray.c b/lib/libc/stdlib/reallocarray.c
index 0868804486cc..3632734c84de 100644
--- a/lib/libc/stdlib/reallocarray.c
+++ b/lib/libc/stdlib/reallocarray.c
@@ -17,23 +17,19 @@
#include <sys/types.h>
#include <errno.h>
+#include <stdckdint.h>
#include <stdint.h>
#include <stdlib.h>
-/*
- * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
- * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
- */
-#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
-
void *
reallocarray(void *optr, size_t nmemb, size_t size)
{
+ size_t nbytes;
- if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- nmemb > 0 && SIZE_MAX / nmemb < size) {
+ if (ckd_mul(&nbytes, nmemb, size)) {
errno = ENOMEM;
return (NULL);
}
- return (realloc(optr, size * nmemb));
+
+ return (realloc(optr, nbytes));
}
diff --git a/lib/libc/stdlib/realpath.3 b/lib/libc/stdlib/realpath.3
index 065ba312c2ef..76f40249963b 100644
--- a/lib/libc/stdlib/realpath.3
+++ b/lib/libc/stdlib/realpath.3
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 11, 2012
+.Dd October 10, 2025
.Dt REALPATH 3
.Os
.Sh NAME
@@ -108,11 +108,11 @@ and
.Xr getcwd 3 .
.Sh SEE ALSO
.Xr getcwd 3
-.\" .Sh STANDARDS
-.\" The
-.\" .Fn realpath
-.\" function conforms to
-.\" .St -p1003.1-2001 .
+.Sh STANDARDS
+The
+.Fn realpath
+function conforms to
+.St -p1003.1-2001 .
.Sh HISTORY
The
.Fn realpath
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 4c52b73319ab..18f29e95ee6b 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -49,7 +49,7 @@ realpath1(const char *path, char *resolved)
{
struct stat sb;
char *p, *q;
- size_t left_len, resolved_len, next_token_len;
+ size_t left_len, prev_len, resolved_len, next_token_len;
unsigned symlinks;
ssize_t slen;
char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
@@ -98,6 +98,7 @@ realpath1(const char *path, char *resolved)
left_len = 0;
}
+ prev_len = resolved_len;
if (resolved[resolved_len - 1] != '/') {
if (resolved_len + 1 >= PATH_MAX) {
errno = ENAMETOOLONG;
@@ -133,8 +134,17 @@ realpath1(const char *path, char *resolved)
errno = ENAMETOOLONG;
return (NULL);
}
- if (lstat(resolved, &sb) != 0)
+ if (lstat(resolved, &sb) != 0) {
+ /*
+ * EACCES means the parent directory is not
+ * readable, while ENOTDIR means the parent
+ * directory is not a directory. Rewind the path
+ * to correctly indicate where the error lies.
+ */
+ if (errno == EACCES || errno == ENOTDIR)
+ resolved[prev_len] = '\0';
return (NULL);
+ }
if (S_ISLNK(sb.st_mode)) {
if (symlinks++ > MAXSYMLINKS) {
errno = ELOOP;
diff --git a/lib/libopenbsd/recallocarray.c b/lib/libc/stdlib/recallocarray.c
index 11e1fda744c7..cbf1fb2470cf 100644
--- a/lib/libopenbsd/recallocarray.c
+++ b/lib/libc/stdlib/recallocarray.c
@@ -16,17 +16,12 @@
*/
#include <errno.h>
+#include <stdckdint.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
-/*
- * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
- * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
- */
-#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
-
void *recallocarray(void *, size_t, size_t, size_t);
void *
@@ -38,19 +33,15 @@ recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size)
if (ptr == NULL)
return calloc(newnmemb, size);
- if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- newnmemb > 0 && SIZE_MAX / newnmemb < size) {
+ if (ckd_mul(&newsize, newnmemb, size)) {
errno = ENOMEM;
return NULL;
}
- newsize = newnmemb * size;
- if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- oldnmemb > 0 && SIZE_MAX / oldnmemb < size) {
+ if (ckd_mul(&oldsize, oldnmemb, size)) {
errno = EINVAL;
return NULL;
}
- oldsize = oldnmemb * size;
/*
* Don't bother too much if we're shrinking just a bit,
diff --git a/lib/libc/stdlib/strfmon.3 b/lib/libc/stdlib/strfmon.3
index 20cc560d401d..d537d9d05fa7 100644
--- a/lib/libc/stdlib/strfmon.3
+++ b/lib/libc/stdlib/strfmon.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 6, 2023
+.Dd November 24, 2025
.Dt STRFMON 3
.Os
.Sh NAME
@@ -182,6 +182,16 @@ function will fail if:
Conversion stopped due to lack of space in the buffer.
.It Bq Er EINVAL
The format string is invalid.
+.It Bq Er EINVAL
+The
+.Cm +
+flag was included in a conversion specification and the locale's
+.Va positive_sign
+and
+.Va negative_sign
+values would both be returned by
+.Xr localeconv 3
+as empty strings.
.It Bq Er ENOMEM
Not enough memory for temporary buffers.
.El
diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c
index 68a36a6d5567..611ac45b9c82 100644
--- a/lib/libc/stdlib/strfmon.c
+++ b/lib/libc/stdlib/strfmon.c
@@ -106,7 +106,7 @@ vstrfmon_l(char *__restrict s, size_t maxsize, locale_t loc,
const char *__restrict format, va_list ap)
{
char *dst; /* output destination pointer */
- const char *fmt; /* current format poistion pointer */
+ const char *fmt; /* current format position pointer */
struct lconv *lc; /* pointer to lconv structure */
char *asciivalue; /* formatted double pointer */
@@ -171,7 +171,9 @@ literal:
flags &= ~(NEED_GROUPING);
continue;
case '+': /* use locale defined signs */
- if (flags & SIGN_POSN_USED)
+ if ((flags & SIGN_POSN_USED) ||
+ ((lc->positive_sign[0] == '\0') &&
+ (lc->negative_sign[0] == '\0')))
goto format_error;
flags |= (SIGN_POSN_USED | LOCALE_POSN);
continue;
@@ -455,7 +457,7 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, char *sign_posn,
if (*sep_by_space == CHAR_MAX)
*sep_by_space = 0;
if (*sign_posn == CHAR_MAX)
- *sign_posn = 0;
+ *sign_posn = 1;
}
static int
diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc
index 647cbe6f40ba..1baa39a6c0a6 100644
--- a/lib/libc/stdtime/Makefile.inc
+++ b/lib/libc/stdtime/Makefile.inc
@@ -32,4 +32,5 @@ MLINKS+=strftime.3 strftime_l.3
MLINKS+=strptime.3 strptime_l.3
MLINKS+=time2posix.3 posix2time.3
MLINKS+=tzset.3 daylight.3 \
- tzset.3 timezone.3
+ tzset.3 timezone.3 \
+ tzset.3 tzname.3
diff --git a/lib/libc/stdtime/ctime.3 b/lib/libc/stdtime/ctime.3
index 96b7f775535a..6384e8bd959b 100644
--- a/lib/libc/stdtime/ctime.3
+++ b/lib/libc/stdtime/ctime.3
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 26, 2024
+.Dd September 23, 2025
.Dt CTIME 3
.Os
.Sh NAME
@@ -41,6 +41,8 @@
.Nm localtime ,
.Nm localtime_r ,
.Nm mktime ,
+.Nm offtime ,
+.Nm offtime_r ,
.Nm timegm
.Nd transform binary date and time values
.Sh LIBRARY
@@ -68,14 +70,19 @@
.Fn localtime_r "const time_t *clock" "struct tm *result"
.Ft time_t
.Fn mktime "struct tm *tm"
+.Ft struct tm *
+.Fn offtime "const time_t *clock" "long offset"
+.Ft struct tm *
+.Fn offtime_r "const time_t *clock" "long offset" "struct tm *result"
.Ft time_t
.Fn timegm "struct tm *tm"
.Sh DESCRIPTION
The
.Fn ctime ,
.Fn gmtime ,
+.Fn localtime ,
and
-.Fn localtime
+.Fn offtime
functions all take as argument a pointer to a time value representing
the time in seconds since the Epoch (00:00:00 UTC on January 1, 1970;
see
@@ -123,6 +130,18 @@ adjustment, and returns a pointer to a
.Vt struct tm .
.Pp
The
+.Fn offtime
+function similarly converts the time value with a time zone adjustment
+corresponding to the provided
+.Fa offset ,
+which is expressed in seconds, with positive values indicating a time
+zone ahead of UTC (east of the Prime Meridian).
+It does not call
+.Xr tzset 3
+or modify
+.Va tzname .
+.Pp
+The
.Fn ctime
function
adjusts the time value for the current time zone in the same manner as
@@ -155,13 +174,15 @@ except the caller must provide the output buffer
.Fa buf ,
which must be at least 26 characters long, to store the result in.
The
-.Fn localtime_r
+.Fn localtime_r ,
+.Fn gmtime_r ,
and
-.Fn gmtime_r
+.Fn offtime_r
functions provide the same functionality as
-.Fn localtime
+.Fn localtime ,
+.Fn gmtime ,
and
-.Fn gmtime
+.Fn offtime
respectively, except the caller must provide the output buffer
.Fa result .
.Pp
@@ -368,6 +389,12 @@ and
.Fn localtime_r
functions have been available since
.Fx 8.0 .
+The
+.Fn offtime
+and
+.Fn offtime_r
+functions were added in
+.Fx 15.0 .
.Sh BUGS
Except for
.Fn difftime ,
diff --git a/lib/libc/stdtime/strptime.3 b/lib/libc/stdtime/strptime.3
index 7df73d2d080a..9456fa757b85 100644
--- a/lib/libc/stdtime/strptime.3
+++ b/lib/libc/stdtime/strptime.3
@@ -171,7 +171,7 @@ is taken as noon.
The
.Fa %Z
format specifier only accepts time zone abbreviations of the local time zone,
-or the value "GMT".
+and the values "GMT", "UTC", or "Z".
This limitation is because of ambiguity due to of the over loading of time
zone abbreviations.
One such example is
diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c
index 5f1293c7a267..375e49146639 100644
--- a/lib/libc/stdtime/strptime.c
+++ b/lib/libc/stdtime/strptime.c
@@ -546,7 +546,8 @@ label:
zonestr[cp - buf] = '\0';
tzset();
if (0 == strcmp(zonestr, "GMT") ||
- 0 == strcmp(zonestr, "UTC")) {
+ 0 == strcmp(zonestr, "UTC") ||
+ 0 == strcmp(zonestr, "Z")) {
*GMTp = 1;
} else if (0 == strcmp(zonestr, tzname[0])) {
tm->tm_isdst = 0;
diff --git a/lib/libc/stdtime/tzset.3 b/lib/libc/stdtime/tzset.3
index 94ccbec9aba7..33e6a556306d 100644
--- a/lib/libc/stdtime/tzset.3
+++ b/lib/libc/stdtime/tzset.3
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 25, 2023
+.Dd September 30, 2025
.Dt TZSET 3
.Os
.Sh NAME
@@ -58,8 +58,8 @@ 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
+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
@@ -68,9 +68,7 @@ is used.
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).
+Universal Time (UTC) is used (without leap second correction).
.Pp
If
.Ev TZ
@@ -81,13 +79,12 @@ the rest of its value is used as a pathname of a
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.
+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 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.
@@ -96,24 +93,23 @@ 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.
+file and cannot be interpreted as a direct specification, UTC is used.
.Pp
After the first call to
.Nm tzset ,
the
.Vt timezone
-variable is set to the difference, in seconds, between Coordinated Universal
-Time (UTC) and the local time.
+variable is set to the difference, in seconds, between Coordinated
+Universal Time (UTC) and the local time.
The
.Vt daylight
variable is set to 0 if the local timezone is observing standard time.
-It is set to 1 if the local timezone ever observes an alternate time, such as summer time.
+It is set to 1 if the local timezone ever observes an alternate time,
+such as summer time.
The first element of the
.Vt tzname
-array is the timezone name of standard time, while the second element is the
-name of the altnerative time zone.
+array is the timezone name of standard time, while the second element
+is the name of the altnerative time zone.
.Sh SPECIFICATION FORMAT
When
.Ev TZ
@@ -151,8 +147,7 @@ minus
.Pq Ql \- ,
plus
.Pq Ql + ,
-and
-.Tn ASCII
+and ASCII
.Dv NUL
are allowed.
.It Em offset
@@ -294,10 +289,8 @@ by the
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
+standard and summer time offsets from UTC replaced by those specified
+by the
.Em offset
values in
.Ev TZ .
@@ -315,20 +308,14 @@ 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
+rules for POSIX-style TZs
.It Pa /usr/share/zoneinfo/Etc/GMT
-for
-.Tn UTC
-leap seconds
+for UTC leap seconds
.El
.Pp
If the file
.Pa /usr/share/zoneinfo/UTC
-does not exist,
-.Tn UTC
-leap seconds are loaded from
+does not exist, UTC leap seconds are loaded from
.Pa /usr/share/zoneinfo/posixrules .
.Sh SEE ALSO
.Xr date 1 ,
diff --git a/lib/libc/string/ffs.3 b/lib/libc/string/ffs.3
index 2a5adb01c737..14a64126e692 100644
--- a/lib/libc/string/ffs.3
+++ b/lib/libc/string/ffs.3
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd October 17, 2015
+.Dd October 25, 2025
.Dt FFS 3
.Os
.Sh NAME
@@ -79,7 +79,20 @@ A return value of zero from any of these functions means that the
argument was zero.
.Sh SEE ALSO
.Xr bitstring 3 ,
+.Xr stdc_first_trailing_one 3 ,
+.Xr stdc_trailing_zeros 3 ,
.Xr bitset 9
+.Sh STANDARDS
+The
+.Fn ffs
+function conforms to
+.St -p1003.1-2008 .
+The
+.Fn ffsl
+and
+.Fn ffsll
+functions conform to
+.St -p1003.1-2024 .
.Sh HISTORY
The
.Fn ffs
diff --git a/lib/libc/tests/Makefile b/lib/libc/tests/Makefile
index 975c895770ee..ae8e0e937676 100644
--- a/lib/libc/tests/Makefile
+++ b/lib/libc/tests/Makefile
@@ -14,6 +14,7 @@ TESTS_SUBDIRS+= resolv
TESTS_SUBDIRS+= rpc
TESTS_SUBDIRS+= secure
TESTS_SUBDIRS+= setjmp
+TESTS_SUBDIRS+= stdbit
TESTS_SUBDIRS+= stdio
TESTS_SUBDIRS+= stdlib
TESTS_SUBDIRS+= stdtime
diff --git a/lib/libc/tests/gen/Makefile b/lib/libc/tests/gen/Makefile
index 8c2151105209..054b1b426b3d 100644
--- a/lib/libc/tests/gen/Makefile
+++ b/lib/libc/tests/gen/Makefile
@@ -19,6 +19,7 @@ ATF_TESTS_C+= glob2_test
.if ${COMPILER_FEATURES:Mblocks}
ATF_TESTS_C+= glob_blocks_test
.endif
+ATF_TESTS_C+= limits_test
ATF_TESTS_C+= makecontext_test
ATF_TESTS_C+= opendir_test
ATF_TESTS_C+= popen_test
diff --git a/lib/libc/tests/gen/limits_test.c b/lib/libc/tests/gen/limits_test.c
new file mode 100644
index 000000000000..b4e8bf3178f1
--- /dev/null
+++ b/lib/libc/tests/gen/limits_test.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: FreeBSD-2-Clause
+ */
+
+#include <assert.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdint.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+/* if this file builds, the unit tests have passed */
+#define CHECK_STYPE(type, TYPE) \
+ static_assert(sizeof(type) * CHAR_BIT == TYPE ## _WIDTH, \
+ __XSTRING(TYPE) "_WIDTH wrongly defined"); \
+ static_assert((1ULL << (TYPE ## _WIDTH - 1)) - 1 == TYPE ## _MAX, \
+ __XSTRING(TYPE) "_MAX wrongly defined"); \
+ static_assert(TYPE ## _MIN == -TYPE ## _MAX - 1, \
+ __XSTRING(TYPE) "_MIN wrongly defined")
+#define CHECK_UTYPE(type, TYPE) \
+ static_assert(sizeof(type) * CHAR_BIT == TYPE ## _WIDTH, \
+ __XSTRING(TYPE) "_WIDTH wrongly defined"); \
+ static_assert((type)~0ULL == TYPE ## _MAX, \
+ __XSTRING(TYPE) "_MAX wrongly defined");
+
+/* primitive types */
+#ifdef __CHAR_UNSIGNED__
+CHECK_UTYPE(char, CHAR);
+#else
+CHECK_STYPE(char, CHAR);
+#endif
+
+CHECK_STYPE(signed char, SCHAR);
+CHECK_STYPE(short, SHRT);
+CHECK_STYPE(int, INT);
+CHECK_STYPE(long, LONG);
+CHECK_STYPE(long long, LLONG);
+
+CHECK_UTYPE(unsigned char, UCHAR);
+CHECK_UTYPE(unsigned short, USHRT);
+CHECK_UTYPE(unsigned int, UINT);
+CHECK_UTYPE(unsigned long, ULONG);
+CHECK_UTYPE(unsigned long long, ULLONG);
+
+/* fixed-width types */
+CHECK_STYPE(int8_t, INT8);
+CHECK_STYPE(int16_t, INT16);
+CHECK_STYPE(int32_t, INT32);
+CHECK_STYPE(int64_t, INT64);
+
+CHECK_UTYPE(uint8_t, UINT8);
+CHECK_UTYPE(uint16_t, UINT16);
+CHECK_UTYPE(uint32_t, UINT32);
+CHECK_UTYPE(uint64_t, UINT64);
+
+CHECK_STYPE(int_least8_t, INT_LEAST8);
+CHECK_STYPE(int_least16_t, INT_LEAST16);
+CHECK_STYPE(int_least32_t, INT_LEAST32);
+CHECK_STYPE(int_least64_t, INT_LEAST64);
+
+CHECK_UTYPE(uint_least8_t, UINT_LEAST8);
+CHECK_UTYPE(uint_least16_t, UINT_LEAST16);
+CHECK_UTYPE(uint_least32_t, UINT_LEAST32);
+CHECK_UTYPE(uint_least64_t, UINT_LEAST64);
+
+CHECK_STYPE(int_fast8_t, INT_FAST8);
+CHECK_STYPE(int_fast16_t, INT_FAST16);
+CHECK_STYPE(int_fast32_t, INT_FAST32);
+CHECK_STYPE(int_fast64_t, INT_FAST64);
+
+CHECK_UTYPE(uint_fast8_t, UINT_FAST8);
+CHECK_UTYPE(uint_fast16_t, UINT_FAST16);
+CHECK_UTYPE(uint_fast32_t, UINT_FAST32);
+CHECK_UTYPE(uint_fast64_t, UINT_FAST64);
+
+/* other types */
+#if WCHAR_MIN == 0
+CHECK_UTYPE(wchar_t, WCHAR);
+#else
+CHECK_STYPE(wchar_t, WCHAR);
+#endif
+CHECK_STYPE(intmax_t, INTMAX);
+CHECK_STYPE(intptr_t, INTPTR);
+CHECK_STYPE(ptrdiff_t, PTRDIFF);
+CHECK_STYPE(wint_t, WINT);
+CHECK_STYPE(sig_atomic_t, SIG_ATOMIC);
+
+CHECK_UTYPE(uintmax_t, UINTMAX);
+CHECK_UTYPE(uintptr_t, UINTPTR);
+CHECK_UTYPE(size_t, SIZE);
+
+/* dummy */
+ATF_TP_ADD_TCS(tp)
+{
+ (void)tp;
+
+ return (atf_no_error());
+}
diff --git a/lib/libc/tests/gen/realpath2_test.c b/lib/libc/tests/gen/realpath2_test.c
index f89dd99cbb72..431df8721ae0 100644
--- a/lib/libc/tests/gen/realpath2_test.c
+++ b/lib/libc/tests/gen/realpath2_test.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2017 Jan Kokemüller
* All rights reserved.
+ * Copyright (c) 2025 Klara, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,6 +26,8 @@
*/
#include <sys/param.h>
+#include <sys/stat.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -34,6 +37,31 @@
#include <atf-c.h>
+ATF_TC(realpath_null);
+ATF_TC_HEAD(realpath_null, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test null input");
+}
+ATF_TC_BODY(realpath_null, tc)
+{
+ ATF_REQUIRE_ERRNO(EINVAL, realpath(NULL, NULL) == NULL);
+}
+
+ATF_TC(realpath_empty);
+ATF_TC_HEAD(realpath_empty, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test empty input");
+}
+ATF_TC_BODY(realpath_empty, tc)
+{
+ char resb[PATH_MAX] = "";
+
+ ATF_REQUIRE_EQ(0, mkdir("foo", 0755));
+ ATF_REQUIRE_EQ(0, chdir("foo"));
+ ATF_REQUIRE_ERRNO(ENOENT, realpath("", resb) == NULL);
+ ATF_REQUIRE_STREQ("", resb);
+}
+
ATF_TC(realpath_buffer_overflow);
ATF_TC_HEAD(realpath_buffer_overflow, tc)
{
@@ -44,16 +72,11 @@ ATF_TC_HEAD(realpath_buffer_overflow, tc)
ATF_TC_BODY(realpath_buffer_overflow, tc)
{
- char path[MAXPATHLEN] = { 0 };
- char resb[MAXPATHLEN] = { 0 };
- size_t i;
+ char path[PATH_MAX] = "";
+ char resb[PATH_MAX] = "";
- path[0] = 'a';
+ memset(path, 'a', sizeof(path) - 1);
path[1] = '/';
- for (i = 2; i < sizeof(path) - 1; ++i) {
- path[i] = 'a';
- }
-
ATF_REQUIRE(realpath(path, resb) == NULL);
}
@@ -66,9 +89,9 @@ ATF_TC_HEAD(realpath_empty_symlink, tc)
ATF_TC_BODY(realpath_empty_symlink, tc)
{
- char path[MAXPATHLEN] = { 0 };
- char slnk[MAXPATHLEN] = { 0 };
- char resb[MAXPATHLEN] = { 0 };
+ char path[PATH_MAX] = "";
+ char slnk[PATH_MAX] = "";
+ char resb[PATH_MAX] = "";
int fd;
(void)strlcat(slnk, "empty_symlink", sizeof(slnk));
@@ -89,11 +112,70 @@ ATF_TC_BODY(realpath_empty_symlink, tc)
ATF_REQUIRE(unlink(slnk) == 0);
}
-ATF_TP_ADD_TCS(tp)
+ATF_TC(realpath_partial);
+ATF_TC_HEAD(realpath_partial, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that failure leaves a partial result");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+
+ATF_TC_BODY(realpath_partial, tc)
{
+ char resb[PATH_MAX] = "";
+ size_t len;
+
+ /* scenario 1: missing directory */
+ ATF_REQUIRE_EQ(0, mkdir("foo", 0755));
+ ATF_REQUIRE_ERRNO(ENOENT, realpath("foo/bar/baz", resb) == NULL);
+ len = strnlen(resb, sizeof(resb));
+ ATF_REQUIRE(len > 8 && len < sizeof(resb));
+ ATF_REQUIRE_STREQ("/foo/bar", resb + len - 8);
+
+ /* scenario 2: dead link 1 */
+ ATF_REQUIRE_EQ(0, symlink("nix", "foo/bar"));
+ ATF_REQUIRE_ERRNO(ENOENT, realpath("foo/bar/baz", resb) == NULL);
+ len = strnlen(resb, sizeof(resb));
+ ATF_REQUIRE(len > 8 && len < sizeof(resb));
+ ATF_REQUIRE_STREQ("/foo/nix", resb + len - 8);
+
+ /* scenario 3: missing file */
+ ATF_REQUIRE_EQ(0, unlink("foo/bar"));
+ ATF_REQUIRE_EQ(0, mkdir("foo/bar", 0755));
+ ATF_REQUIRE_ERRNO(ENOENT, realpath("foo/bar/baz", resb) == NULL);
+ len = strnlen(resb, sizeof(resb));
+ ATF_REQUIRE(len > 12 && len < sizeof(resb));
+ ATF_REQUIRE_STREQ("/foo/bar/baz", resb + len - 12);
+
+ /* scenario 4: dead link 2 */
+ ATF_REQUIRE_EQ(0, symlink("nix", "foo/bar/baz"));
+ ATF_REQUIRE_ERRNO(ENOENT, realpath("foo/bar/baz", resb) == NULL);
+ len = strnlen(resb, sizeof(resb));
+ ATF_REQUIRE(len > 12 && len < sizeof(resb));
+ ATF_REQUIRE_STREQ("/foo/bar/nix", resb + len - 12);
+
+ /* scenario 5: unreadable directory */
+ ATF_REQUIRE_EQ(0, chmod("foo", 000));
+ ATF_REQUIRE_ERRNO(EACCES, realpath("foo/bar/baz", resb) == NULL);
+ len = strnlen(resb, sizeof(resb));
+ ATF_REQUIRE(len > 4 && len < sizeof(resb));
+ ATF_REQUIRE_STREQ("/foo", resb + len - 4);
+
+ /* scenario 6: not a directory */
+ ATF_REQUIRE_EQ(0, close(creat("bar", 0644)));
+ ATF_REQUIRE_ERRNO(ENOTDIR, realpath("bar/baz", resb) == NULL);
+ len = strnlen(resb, sizeof(resb));
+ ATF_REQUIRE(len > 4 && len < sizeof(resb));
+ ATF_REQUIRE_STREQ("/bar", resb + len - 4);
+}
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, realpath_null);
+ ATF_TP_ADD_TC(tp, realpath_empty);
ATF_TP_ADD_TC(tp, realpath_buffer_overflow);
ATF_TP_ADD_TC(tp, realpath_empty_symlink);
+ ATF_TP_ADD_TC(tp, realpath_partial);
return atf_no_error();
}
diff --git a/lib/libc/tests/net/Makefile b/lib/libc/tests/net/Makefile
index 24cff61e8d24..ec0668633508 100644
--- a/lib/libc/tests/net/Makefile
+++ b/lib/libc/tests/net/Makefile
@@ -4,8 +4,10 @@ ATF_TESTS_C+= ether_test
ATF_TESTS_C+= eui64_aton_test
ATF_TESTS_C+= eui64_ntoa_test
ATF_TESTS_CXX+= link_addr_test
+ATF_TESTS_CXX+= inet_net_test
CXXSTD.link_addr_test= c++20
+CXXSTD.inet_net_test= c++20
CFLAGS+= -I${.CURDIR}
diff --git a/lib/libc/tests/net/inet_net_test.cc b/lib/libc/tests/net/inet_net_test.cc
new file mode 100644
index 000000000000..60b60b152eca
--- /dev/null
+++ b/lib/libc/tests/net/inet_net_test.cc
@@ -0,0 +1,333 @@
+/*
+ * SPDX-License-Identifier: ISC
+ *
+ * Copyright (c) 2025 Lexi Winter <ivy@FreeBSD.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * 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.
+ */
+
+/*
+ * Tests for inet_net_pton() and inet_net_ntop().
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <ranges>
+#include <string>
+#include <vector>
+
+#include <atf-c++.hpp>
+
+using namespace std::literals;
+
+/*
+ * inet_net_ntop() and inet_net_pton() for IPv4.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(inet_net_inet4)
+ATF_TEST_CASE_BODY(inet_net_inet4)
+{
+ /*
+ * Define a list of addresses we want to check. Each address is passed
+ * to inet_net_pton() to convert it to an in_addr, then we convert the
+ * in_addr back to a string and compare it with the expected value. We
+ * want to test over-long prefixes here (such as 10.0.0.1/8), so we also
+ * specify what the result is expected to be.
+ */
+
+ struct test_addr {
+ std::string input;
+ int bits;
+ std::string output;
+ };
+
+ auto test_addrs = std::vector<test_addr>{
+ // Simple prefixes that fall on octet boundaries.
+ { "10.0.0.0/8", 8, "10/8" },
+ { "10.1.0.0/16", 16, "10.1/16" },
+ { "10.1.2.0/24", 24, "10.1.2/24" },
+ { "10.1.2.3/32", 32, "10.1.2.3/32" },
+
+ // Simple prefixes with the short-form address.
+ { "10/8", 8, "10/8" },
+ { "10.1/16", 16, "10.1/16" },
+ { "10.1.2/24", 24, "10.1.2/24" },
+
+ // A prefix that doesn't fall on an octet boundary.
+ { "10.1.64/18", 18, "10.1.64/18" },
+
+ // An overlong prefix with bits that aren't part of the prefix.
+ { "10.0.0.1/8", 8, "10/8" },
+ };
+
+ for (auto const &addr: test_addrs) {
+ /*
+ * Convert the input string to an in_addr + bits, and make
+ * sure the result produces the number of bits we expected.
+ */
+
+ auto in = in_addr{};
+ auto bits = inet_net_pton(AF_INET, addr.input.c_str(),
+ &in, sizeof(in));
+ ATF_REQUIRE(bits != -1);
+ ATF_REQUIRE_EQ(bits, addr.bits);
+
+ /*
+ * Convert the in_addr back to a string
+ */
+
+ /*
+ * XXX: Should there be a constant for the size of the result
+ * buffer? For now, use ADDRSTRLEN + 3 ("/32") + 1 (NUL).
+ *
+ * Fill the buffer with 'Z', so we can check the result was
+ * properly terminated.
+ */
+ auto strbuf = std::vector<char>(INET_ADDRSTRLEN + 3 + 1, 'Z');
+ auto ret = inet_net_ntop(AF_INET, &in, bits,
+ strbuf.data(), strbuf.size());
+ ATF_REQUIRE(ret != NULL);
+ ATF_REQUIRE_EQ(ret, strbuf.data());
+
+ /* Make sure the result was NUL-terminated and find the NUL */
+ ATF_REQUIRE(strbuf.size() >= 1);
+ auto end = std::ranges::find(strbuf, '\0');
+ ATF_REQUIRE(end != strbuf.end());
+
+ /*
+ * Check the result matches what we expect. Use a temporary
+ * string here instead of std::ranges::equal because this
+ * means ATF can print the mismatch.
+ */
+ auto str = std::string(std::ranges::begin(strbuf), end);
+ ATF_REQUIRE_EQ(str, addr.output);
+ }
+}
+
+/*
+ * inet_net_ntop() and inet_net_pton() for IPv6.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(inet_net_inet6)
+ATF_TEST_CASE_BODY(inet_net_inet6)
+{
+ /*
+ * Define a list of addresses we want to check. Each address is
+ * passed to inet_net_pton() to convert it to an in6_addr, then we
+ * convert the in6_addr back to a string and compare it with the
+ * expected value. We want to test over-long prefixes here (such
+ * as 2001:db8::1/32), so we also specify what the result is
+ * expected to be.
+ */
+
+ struct test_addr {
+ std::string input;
+ int bits;
+ std::string output;
+ };
+
+ auto test_addrs = std::vector<test_addr>{
+ // A prefix with a trailing ::
+ { "2001:db8::/32", 32, "2001:db8::/32" },
+
+ // A prefix with a leading ::. Note that the output is
+ // different from the input because inet_ntop() renders
+ // this prefix with an IPv4 suffix for legacy reasons.
+ { "::ffff:0:0/96", 96, "::ffff:0.0.0.0/96" },
+
+ // The same prefix but with the IPv4 legacy form as input.
+ { "::ffff:0.0.0.0/96", 96, "::ffff:0.0.0.0/96" },
+
+ // A prefix with an infix ::.
+ { "2001:db8::1/128", 128, "2001:db8::1/128" },
+
+ // A prefix with bits set which are outside the prefix;
+ // these should be silently ignored.
+ { "2001:db8:1:1:1:1:1:1/32", 32, "2001:db8::/32" },
+
+ // As above but with infix ::.
+ { "2001:db8::1/32", 32, "2001:db8::/32" },
+
+ // A prefix with only ::, commonly used to represent the
+ // entire address space.
+ { "::/0", 0, "::/0" },
+
+ // A single address with no ::.
+ { "2001:db8:1:1:1:1:1:1/128", 128, "2001:db8:1:1:1:1:1:1/128" },
+
+ // A prefix with no ::.
+ { "2001:db8:1:1:0:0:0:0/64", 64, "2001:db8:1:1::/64" },
+
+ // A prefix which isn't on a 16-bit boundary.
+ { "2001:db8:c000::/56", 56, "2001:db8:c000::/56" },
+
+ // A prefix which isn't on a nibble boundary.
+ { "2001:db8:c100::/57", 57, "2001:db8:c100::/57" },
+
+ // An address without a prefix length, which should be treated
+ // as a /128.
+ { "2001:db8::", 128, "2001:db8::/128" },
+ { "2001:db8::1", 128, "2001:db8::1/128" },
+
+ // Test vectors provided in PR bin/289198.
+ { "fe80::1/64", 64, "fe80::/64" },
+ { "fe80::f000:74ff:fe54:bed2/64",
+ 64, "fe80::/64" },
+ { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64",
+ 64, "ffff:ffff:ffff:ffff::/64" },
+ { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 128,
+ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" },
+ };
+
+ for (auto const &addr: test_addrs) {
+ /*
+ * Convert the input string to an in6_addr + bits, and make
+ * sure the result produces the number of bits we expected.
+ */
+
+ auto in6 = in6_addr{};
+ errno = 0;
+ auto bits = inet_net_pton(AF_INET6, addr.input.c_str(),
+ &in6, sizeof(in6));
+ ATF_REQUIRE(bits != -1);
+ ATF_REQUIRE_EQ(bits, addr.bits);
+
+ /*
+ * Convert the in6_addr back to a string
+ */
+
+ /*
+ * XXX: Should there be a constant for the size of the result
+ * buffer? For now, use ADDRSTRLEN + 4 ("/128") + 1 (NUL).
+ *
+ * Fill the buffer with 'Z', so we can check the result was
+ * properly terminated.
+ */
+ auto strbuf = std::vector<char>(INET6_ADDRSTRLEN + 4 + 1, 'Z');
+ auto ret = inet_net_ntop(AF_INET6, &in6, bits,
+ strbuf.data(), strbuf.size());
+ ATF_REQUIRE(ret != NULL);
+ ATF_REQUIRE_EQ(ret, strbuf.data());
+
+ /* Make sure the result was NUL-terminated and find the NUL */
+ ATF_REQUIRE(strbuf.size() >= 1);
+ auto end = std::ranges::find(strbuf, '\0');
+ ATF_REQUIRE(end != strbuf.end());
+
+ /*
+ * Check the result matches what we expect. Use a temporary
+ * string here instead of std::ranges::equal because this
+ * means ATF can print the mismatch.
+ */
+ auto str = std::string(std::ranges::begin(strbuf), end);
+ ATF_REQUIRE_EQ(str, addr.output);
+ }
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(inet_net_pton_invalid)
+ATF_TEST_CASE_BODY(inet_net_pton_invalid)
+{
+ auto ret = int{};
+ auto addr4 = in_addr{};
+ auto str4 = "10.0.0.0"s;
+ auto addr6 = in6_addr{};
+ auto str6 = "2001:db8::"s;
+
+ /* Passing an address which is too short should be an error */
+ ret = inet_net_pton(AF_INET6, str6.c_str(), &addr6, sizeof(addr6) - 1);
+ ATF_REQUIRE_EQ(ret, -1);
+
+ ret = inet_net_pton(AF_INET, str4.c_str(), &addr4, sizeof(addr4) - 1);
+ ATF_REQUIRE_EQ(ret, -1);
+
+ /* Test some generally invalid addresses. */
+ auto invalid4 = std::vector<std::string>{
+ // Prefix length too big
+ "10.0.0.0/33",
+ // Prefix length is negative
+ "10.0.0.0/-1",
+ // Prefix length is not a number
+ "10.0.0.0/foo",
+ // Input is not a network prefix
+ "this is not an IP address",
+ };
+
+ for (auto const &addr: invalid4) {
+ auto ret = inet_net_pton(AF_INET, addr.c_str(), &addr4,
+ sizeof(addr4));
+ ATF_REQUIRE_EQ(ret, -1);
+ }
+
+ auto invalid6 = std::vector<std::string>{
+ // Prefix length too big
+ "2001:db8::/129",
+ // Prefix length is negative
+ "2001:db8::/-1",
+ // Prefix length is not a number
+ "2001:db8::/foo",
+ // Input is not a network prefix
+ "this is not an IP address",
+ };
+
+ for (auto const &addr: invalid6) {
+ auto ret = inet_net_pton(AF_INET6, addr.c_str(), &addr6,
+ sizeof(addr6));
+ ATF_REQUIRE_EQ(ret, -1);
+ }
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(inet_net_ntop_invalid)
+ATF_TEST_CASE_BODY(inet_net_ntop_invalid)
+{
+ auto addr4 = in_addr{};
+ auto addr6 = in6_addr{};
+ auto strbuf = std::vector<char>(INET6_ADDRSTRLEN + 4 + 1);
+
+ /*
+ * Passing a buffer which is too small should not overrun the buffer.
+ * Test this by initialising the buffer to 'Z', and only providing
+ * part of it to the function.
+ */
+
+ std::ranges::fill(strbuf, 'Z');
+ auto ret = inet_net_ntop(AF_INET6, &addr6, 128, strbuf.data(), 1);
+ ATF_REQUIRE_EQ(ret, nullptr);
+ ATF_REQUIRE_EQ(strbuf[1], 'Z');
+
+ std::ranges::fill(strbuf, 'Z');
+ ret = inet_net_ntop(AF_INET, &addr4, 32, strbuf.data(), 1);
+ ATF_REQUIRE_EQ(ret, nullptr);
+ ATF_REQUIRE_EQ(strbuf[1], 'Z');
+
+ /* Check that invalid prefix lengths return an error */
+
+ ret = inet_net_ntop(AF_INET6, &addr6, 129, strbuf.data(), strbuf.size());
+ ATF_REQUIRE_EQ(ret, nullptr);
+ ret = inet_net_ntop(AF_INET6, &addr6, -1, strbuf.data(), strbuf.size());
+ ATF_REQUIRE_EQ(ret, nullptr);
+
+ ret = inet_net_ntop(AF_INET, &addr4, 33, strbuf.data(), strbuf.size());
+ ATF_REQUIRE_EQ(ret, nullptr);
+ ret = inet_net_ntop(AF_INET, &addr4, -1, strbuf.data(), strbuf.size());
+ ATF_REQUIRE_EQ(ret, nullptr);
+}
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, inet_net_inet4);
+ ATF_ADD_TEST_CASE(tcs, inet_net_inet6);
+ ATF_ADD_TEST_CASE(tcs, inet_net_pton_invalid);
+ ATF_ADD_TEST_CASE(tcs, inet_net_ntop_invalid);
+}
diff --git a/lib/libc/tests/stdbit/Makefile b/lib/libc/tests/stdbit/Makefile
new file mode 100644
index 000000000000..8dbc86528de3
--- /dev/null
+++ b/lib/libc/tests/stdbit/Makefile
@@ -0,0 +1,21 @@
+TESTSDIR= ${TESTSBASE}/lib/libc/stdbit
+
+# ensure libc functions are tested, not clang's builtins
+CFLAGS+= -fno-builtin
+
+ATF_TESTS_C+= stdc_bit_ceil_test \
+ stdc_bit_floor_test \
+ stdc_bit_width_test \
+ stdc_count_ones_test \
+ stdc_count_zeros_test \
+ stdc_first_leading_one_test \
+ stdc_first_leading_zero_test \
+ stdc_first_trailing_one_test \
+ stdc_first_trailing_zero_test \
+ stdc_has_single_bit_test \
+ stdc_leading_ones_test \
+ stdc_leading_zeros_test \
+ stdc_trailing_ones_test \
+ stdc_trailing_zeros_test
+
+.include <bsd.test.mk>
diff --git a/lib/libc/tests/stdbit/stdbit-test-framework.c b/lib/libc/tests/stdbit/stdbit-test-framework.c
new file mode 100644
index 000000000000..368b38fb4745
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdbit-test-framework.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/*
+ * Test framework for stdbit functions.
+ * Requires the following macros to be defined:
+ *
+ * FUNCSTEM -- name of the function without type suffix
+ * MKREFFUNC(name, type) -- macro to generate a reference
+ * implementation of the function as a static function
+ * named name with give argument type.
+ */
+
+#include <sys/cdefs.h>
+#include <atf-c.h>
+#include <limits.h>
+#include <stdbit.h>
+#include <stdint.h>
+
+#define ATF_TC_WITHOUT_HEAD1(stem, suffix) ATF_TC_WITHOUT_HEAD2(__CONCAT(stem, suffix))
+#define ATF_TC_WITHOUT_HEAD2(case) ATF_TC_WITHOUT_HEAD(case)
+#define ATF_TC_BODY1(stem, suffix, tc) ATF_TC_BODY2(__CONCAT(stem, suffix), tc)
+#define ATF_TC_BODY2(case, tc) ATF_TC_BODY(case, tc)
+
+#define SUFFIX _uc
+#define TYPE unsigned char
+#define TYPE_WIDTH UCHAR_WIDTH
+#include "stdbit-test-kernel.c"
+#undef TYPE_WIDTH
+#undef TYPE
+#undef SUFFIX
+
+#define SUFFIX _us
+#define TYPE unsigned short
+#define TYPE_WIDTH USHRT_WIDTH
+#include "stdbit-test-kernel.c"
+#undef TYPE_WIDTH
+#undef TYPE
+#undef SUFFIX
+
+#define SUFFIX _ui
+#define TYPE unsigned int
+#define TYPE_WIDTH UINT_WIDTH
+#include "stdbit-test-kernel.c"
+#undef TYPE_WIDTH
+#undef TYPE
+#undef SUFFIX
+
+#define SUFFIX _ul
+#define TYPE unsigned long
+#define TYPE_WIDTH ULONG_WIDTH
+#include "stdbit-test-kernel.c"
+#undef TYPE_WIDTH
+#undef TYPE
+#undef SUFFIX
+
+#define SUFFIX _ull
+#define TYPE unsigned long long
+#define TYPE_WIDTH ULLONG_WIDTH
+#include "stdbit-test-kernel.c"
+#undef TYPE_WIDTH
+#undef TYPE
+#undef SUFFIX
+
+#define ADD_CASE(stem, suffix) ADD_CASE1(__CONCAT(stem, suffix))
+#define ADD_CASE1(case) ATF_TP_ADD_TC(tp, case)
+
+ATF_TP_ADD_TCS(tp)
+{
+ ADD_CASE(FUNCSTEM, _uc);
+ ADD_CASE(FUNCSTEM, _us);
+ ADD_CASE(FUNCSTEM, _ui);
+ ADD_CASE(FUNCSTEM, _ul);
+ ADD_CASE(FUNCSTEM, _ull);
+
+ return (atf_no_error());
+}
diff --git a/lib/libc/tests/stdbit/stdbit-test-kernel.c b/lib/libc/tests/stdbit/stdbit-test-kernel.c
new file mode 100644
index 000000000000..d584e391ff6f
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdbit-test-kernel.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/*
+ * test kernel for stdbit functions.
+ * Requires the following macros to be defined:
+ *
+ * FUNCSTEM -- stem of the function name
+ * SUFFIX -- type suffic
+ * TYPE -- argument type
+ * MKREFFUNC(ref, type) -- reference function builder
+ */
+
+#define FUNC __CONCAT(FUNCSTEM, SUFFIX)
+#define REF __CONCAT(FUNCSTEM, __CONCAT(SUFFIX, _ref))
+
+MKREFFUNC(REF, TYPE)
+
+ATF_TC_WITHOUT_HEAD1(FUNCSTEM, SUFFIX);
+ATF_TC_BODY1(FUNCSTEM, SUFFIX, tc)
+{
+ uintmax_t has, want;
+ size_t i, j;
+ TYPE value;
+
+ /* test all single-bit patterns */
+ for (i = 0; i < TYPE_WIDTH; i++) {
+ value = (TYPE)1 << i;
+ has = FUNC(value);
+ want = REF(value);
+ ATF_CHECK_EQ_MSG(has, want, "%s(%#jx) == %#jx != %#jx == %s(%#jx)",
+ __XSTRING(FUNC), (uintmax_t)value, has, want, __XSTRING(REF), (uintmax_t)value);
+ }
+
+ /* test all double-bit patterns */
+ for (i = 0; i < TYPE_WIDTH; i++) {
+ for (j = 0; j < i; j++) {
+ value = (TYPE)1 << i | (TYPE)1 << j;
+ has = FUNC(value);
+ want = REF(value);
+ ATF_CHECK_EQ_MSG(has, want, "%s(%#jx) == %#jx != %#jx == %s(%#jx)",
+ __XSTRING(FUNC), (uintmax_t)value, has, want, __XSTRING(REF), (uintmax_t)value);
+ }
+ }
+
+ /* test all barber-pole patterns */
+ value = ~(TYPE)0;
+ for (i = 0; i < TYPE_WIDTH; i++) {
+ has = FUNC(value);
+ want = REF(value);
+ ATF_CHECK_EQ_MSG(has, want, "%s(%#jx) == %#jx != %#jx == %s(%#jx)",
+ __XSTRING(FUNC), (uintmax_t)value, has, want, __XSTRING(REF), (uintmax_t)value);
+
+ value = ~value;
+ has = FUNC(value);
+ want = REF(value);
+ ATF_CHECK_EQ_MSG(has, want, "%s(%#jx) == %#jx != %#jx == %s(%#jx)",
+ __XSTRING(FUNC), (uintmax_t)value, has, want, __XSTRING(REF), (uintmax_t)value);
+
+ value = ~value << 1;
+ }
+}
+
+#undef REF
+#undef FUNC
diff --git a/lib/libc/tests/stdbit/stdc_bit_ceil_test.c b/lib/libc/tests/stdbit/stdc_bit_ceil_test.c
new file mode 100644
index 000000000000..0495da55c5d9
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_bit_ceil_test.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_bit_ceil
+#define MKREFFUNC(name, type) \
+ static type \
+ name(type value) \
+ { \
+ type ceil = 1; \
+ \
+ while (ceil < value && ceil != 0) \
+ ceil <<= 1; \
+ \
+ return (ceil); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_bit_floor_test.c b/lib/libc/tests/stdbit/stdc_bit_floor_test.c
new file mode 100644
index 000000000000..a2c5b5f7d8ce
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_bit_floor_test.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_bit_floor
+#define MKREFFUNC(name, type) \
+ static type \
+ name(type value) \
+ { \
+ type floor = 1; \
+ \
+ if (value == 0) \
+ return (0); \
+ \
+ while (value != 1) { \
+ floor <<= 1; \
+ value >>= 1; \
+ } \
+ \
+ return (floor); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_bit_width_test.c b/lib/libc/tests/stdbit/stdc_bit_width_test.c
new file mode 100644
index 000000000000..bfcb2b3bd779
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_bit_width_test.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_bit_width
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ unsigned width = 0; \
+ \
+ while (value != 0) { \
+ value >>= 1; \
+ width++; \
+ } \
+ \
+ return (width); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_count_ones_test.c b/lib/libc/tests/stdbit/stdc_count_ones_test.c
new file mode 100644
index 000000000000..9093edde495b
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_count_ones_test.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_count_ones
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ unsigned count = 0; \
+ \
+ while (value != 0) { \
+ count += value & 1; \
+ value >>= 1; \
+ } \
+ \
+ return (count); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_count_zeros_test.c b/lib/libc/tests/stdbit/stdc_count_zeros_test.c
new file mode 100644
index 000000000000..a82de6696a64
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_count_zeros_test.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_count_zeros
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ unsigned count = 0; \
+ \
+ value = ~value; \
+ while (value != 0) { \
+ count += value & 1; \
+ value >>= 1; \
+ } \
+ \
+ return (count); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_first_leading_one_test.c b/lib/libc/tests/stdbit/stdc_first_leading_one_test.c
new file mode 100644
index 000000000000..7312789262ea
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_first_leading_one_test.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_first_leading_one
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned pos = 1; \
+ \
+ if (value == 0) \
+ return (0); \
+ \
+ while ((type)(bit << 1) != 0) \
+ bit <<= 1; \
+ \
+ while ((bit & value) == 0) { \
+ bit >>= 1; \
+ pos++; \
+ } \
+ \
+ return (pos); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_first_leading_zero_test.c b/lib/libc/tests/stdbit/stdc_first_leading_zero_test.c
new file mode 100644
index 000000000000..df2a1f4b8673
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_first_leading_zero_test.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_first_leading_zero
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned pos = 1; \
+ \
+ value = ~value; \
+ if (value == 0) \
+ return (0); \
+ \
+ while ((type)(bit << 1) != 0) \
+ bit <<= 1; \
+ \
+ while ((bit & value) == 0) { \
+ bit >>= 1; \
+ pos++; \
+ } \
+ \
+ return (pos); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_first_trailing_one_test.c b/lib/libc/tests/stdbit/stdc_first_trailing_one_test.c
new file mode 100644
index 000000000000..43284786cd0e
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_first_trailing_one_test.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_first_trailing_one
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned pos = 1; \
+ \
+ if (value == 0) \
+ return (0); \
+ \
+ while ((bit & value) == 0) { \
+ bit <<= 1; \
+ pos++; \
+ } \
+ \
+ return (pos); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_first_trailing_zero_test.c b/lib/libc/tests/stdbit/stdc_first_trailing_zero_test.c
new file mode 100644
index 000000000000..ab2a995dcc86
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_first_trailing_zero_test.c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_first_trailing_zero
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned pos = 1; \
+ \
+ value = ~value; \
+ if (value == 0) \
+ return (0); \
+ \
+ while ((bit & value) == 0) { \
+ bit <<= 1; \
+ pos++; \
+ } \
+ \
+ return (pos); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_has_single_bit_test.c b/lib/libc/tests/stdbit/stdc_has_single_bit_test.c
new file mode 100644
index 000000000000..3426deccd8d0
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_has_single_bit_test.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_has_single_bit
+#define MKREFFUNC(name, type) \
+ static bool \
+ name(type value) \
+ { \
+ type bit; \
+ \
+ for (bit = 1; bit != 0; bit <<= 1) \
+ if (value == bit) \
+ return (true); \
+ \
+ return (false); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_leading_ones_test.c b/lib/libc/tests/stdbit/stdc_leading_ones_test.c
new file mode 100644
index 000000000000..616b3d5e6279
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_leading_ones_test.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_leading_ones
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned count = 0; \
+ \
+ while ((type)(bit << 1) != 0) \
+ bit <<= 1; \
+ \
+ while (bit != 0 && (bit & value) != 0) { \
+ bit >>= 1; \
+ count++; \
+ } \
+ \
+ return (count); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_leading_zeros_test.c b/lib/libc/tests/stdbit/stdc_leading_zeros_test.c
new file mode 100644
index 000000000000..7c9d26e86456
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_leading_zeros_test.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_leading_zeros
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned count = 0; \
+ \
+ while ((type)(bit << 1) != 0) \
+ bit <<= 1; \
+ \
+ while (bit != 0 && (bit & value) == 0) { \
+ bit >>= 1; \
+ count++; \
+ } \
+ \
+ return (count); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_trailing_ones_test.c b/lib/libc/tests/stdbit/stdc_trailing_ones_test.c
new file mode 100644
index 000000000000..9e261cc543de
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_trailing_ones_test.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_trailing_ones
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned count = 0; \
+ \
+ while (bit != 0 && (bit & value) != 0) { \
+ bit <<= 1; \
+ count++; \
+ } \
+ \
+ return (count); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdbit/stdc_trailing_zeros_test.c b/lib/libc/tests/stdbit/stdc_trailing_zeros_test.c
new file mode 100644
index 000000000000..81fe11c5c82a
--- /dev/null
+++ b/lib/libc/tests/stdbit/stdc_trailing_zeros_test.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#define FUNCSTEM stdc_trailing_zeros
+#define MKREFFUNC(name, type) \
+ static unsigned \
+ name(type value) \
+ { \
+ type bit = 1; \
+ unsigned count = 0; \
+ \
+ while (bit != 0 && (bit & value) == 0) { \
+ bit <<= 1; \
+ count++; \
+ } \
+ \
+ return (count); \
+ }
+
+#include "stdbit-test-framework.c"
diff --git a/lib/libc/tests/stdio/printfloat_test.c b/lib/libc/tests/stdio/printfloat_test.c
index 031859124163..4493fe1c15d3 100644
--- a/lib/libc/tests/stdio/printfloat_test.c
+++ b/lib/libc/tests/stdio/printfloat_test.c
@@ -398,6 +398,18 @@ ATF_TC_BODY(subnormal_float, tc)
testfmt("-0X1P-149", "%A", negative);
}
+ATF_TC_WITHOUT_HEAD(hexadecimal_rounding_fullprec);
+ATF_TC_BODY(hexadecimal_rounding_fullprec, tc)
+{
+ /* Double: %.13a with binary64 mantissa=53 */
+ testfmt("0x1.1234567890bbbp+0", "%.13a", 0x1.1234567890bbbp+0);
+
+#if defined(__aarch64__)
+ /* On arm64, long double is IEEE binary128 (mantissa=113) */
+ testfmt("0x1.3c0ca428c59fbbbbbbbbbbbbbbbbp+0", "%.28La", 0x1.3c0ca428c59fbbbbbbbbbbbbbbbbp+0L);
+#endif
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -414,6 +426,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, hexadecimal_rounding);
ATF_TP_ADD_TC(tp, subnormal_double);
ATF_TP_ADD_TC(tp, subnormal_float);
+ ATF_TP_ADD_TC(tp, hexadecimal_rounding_fullprec);
return (atf_no_error());
}
diff --git a/lib/libc/tests/stdlib/strfmon_test.c b/lib/libc/tests/stdlib/strfmon_test.c
index 86f6256dba0b..c6c20bd26985 100644
--- a/lib/libc/tests/stdlib/strfmon_test.c
+++ b/lib/libc/tests/stdlib/strfmon_test.c
@@ -1,31 +1,14 @@
-/*-
- * Copyright (C) 2018 Conrad Meyer <cem@FreeBSD.org>
+/*
+ * Copyright (c) 2018 Conrad Meyer <cem@FreeBSD.org>
* All rights reserved.
+ * Copyright (c) 2022-2025 Jose Luis Duran <jlduran@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 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.
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/param.h>
+#include <errno.h>
#include <locale.h>
#include <monetary.h>
#include <stdio.h>
@@ -208,6 +191,56 @@ ATF_TC_BODY(strfmon_international_currency_code, tc)
}
}
+ATF_TC_WITHOUT_HEAD(strfmon_plus_or_parenthesis);
+ATF_TC_BODY(strfmon_plus_or_parenthesis, tc)
+{
+ const struct {
+ const char *format;
+ const char *locale;
+ const char *expected;
+ } tests[] = {
+ { "%+n", "en_US.UTF-8", "[$123.45] [-$123.45]" },
+ { "%+i", "en_US.UTF-8", "[USD123.45] [-USD123.45]" },
+ { "%(n", "C", "[123.45] [(123.45)]" },
+ { "%(i", "C", "[123.45] [(123.45)]" },
+ { "%(n", "en_US.UTF-8", "[$123.45] [($123.45)]" },
+ { "%(i", "en_US.UTF-8", "[USD123.45] [(USD123.45)]" },
+ { "%n", "C", "[123.45] [-123.45]" },
+ { "%i", "C", "[123.45] [-123.45]" },
+ { "%n", "en_US.UTF-8", "[$123.45] [-$123.45]" },
+ { "%i", "en_US.UTF-8", "[USD123.45] [-USD123.45]" },
+ };
+ size_t i;
+ char actual[100], format[50];
+
+ for (i = 0; i < nitems(tests); ++i) {
+ if (setlocale(LC_MONETARY, tests[i].locale) == NULL)
+ atf_tc_skip("unable to setlocale(): %s",
+ tests[i].locale);
+
+ snprintf(format, sizeof(format), "[%s] [%s]",
+ tests[i].format, tests[i].format);
+ strfmon(actual, sizeof(actual) - 1, format,
+ 123.45, -123.45);
+ ATF_CHECK_STREQ_MSG(tests[i].expected, actual,
+ "[%s] %s", tests[i].format, tests[i].locale);
+ }
+
+ /*
+ * The '+' flag was included in a conversion specification and
+ * the locale's positive_sign and negative_sign values would
+ * both be returned by localeconv() as empty strings.
+ */
+ if (setlocale(LC_MONETARY, "C") == NULL)
+ atf_tc_skip("unable to setlocale(): %s", tests[i].locale);
+
+ ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1,
+ "[%+n] [%+n]", 123.45, -123.45));
+
+ ATF_CHECK_ERRNO(EINVAL, strfmon(actual, sizeof(actual) - 1,
+ "[%+i] [%+i]", 123.45, -123.45));
+}
+
ATF_TC(strfmon_l);
ATF_TC_HEAD(strfmon_l, tc)
{
@@ -220,7 +253,7 @@ ATF_TC_BODY(strfmon_l, tc)
const char *locale;
const char *expected;
} tests[] = {
- { "C", "[ **1234.57 ] [ **1234.57 ]" },
+ { "C", "[ **1234.57] [ **1234.57]" },
{ "de_DE.UTF-8", "[ **1234,57 €] [ **1.234,57 EUR]" },
{ "en_GB.UTF-8", "[ £**1234.57] [ GBP**1,234.57]" },
};
@@ -247,6 +280,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, strfmon_cs_precedes_0);
ATF_TP_ADD_TC(tp, strfmon_cs_precedes_1);
ATF_TP_ADD_TC(tp, strfmon_international_currency_code);
+ ATF_TP_ADD_TC(tp, strfmon_plus_or_parenthesis);
ATF_TP_ADD_TC(tp, strfmon_l);
return (atf_no_error());
}
diff --git a/lib/libc/tests/stdtime/Makefile b/lib/libc/tests/stdtime/Makefile
index 6b9068e1641b..590dea22da31 100644
--- a/lib/libc/tests/stdtime/Makefile
+++ b/lib/libc/tests/stdtime/Makefile
@@ -3,6 +3,7 @@
ATF_TESTS_C+= strptime_test
ATF_TESTS_C+= detect_tz_changes_test
+CFLAGS.detect_tz_changes_test+= -I${SRCTOP}/contrib/tzcode
.if ${MK_DETECT_TZ_CHANGES} != "no"
CFLAGS.detect_tz_changes_test+= -DDETECT_TZ_CHANGES
.endif
diff --git a/lib/libc/tests/stdtime/detect_tz_changes_test.c b/lib/libc/tests/stdtime/detect_tz_changes_test.c
index 6648d8498cc5..06c31c9fbc3d 100644
--- a/lib/libc/tests/stdtime/detect_tz_changes_test.c
+++ b/lib/libc/tests/stdtime/detect_tz_changes_test.c
@@ -20,12 +20,16 @@
#include <time.h>
#include <unistd.h>
+#include "tzdir.h"
+
#include <atf-c.h>
-static const struct tzcase {
+struct tzcase {
const char *tzfn;
const char *expect;
-} tzcases[] = {
+};
+
+static const struct tzcase tzcases[] = {
/*
* A handful of time zones and the expected result of
* strftime("%z (%Z)", tm) when that time zone is active
@@ -41,7 +45,8 @@ static const struct tzcase {
{ "UTC", "+0000 (UTC)" },
{ 0 },
};
-
+static const struct tzcase utc = { "UTC", "+0000 (UTC)" };
+static const struct tzcase invalid = { "invalid", "+0000 (-00)" };
static const time_t then = 1751328000; /* 2025-07-01 00:00:00 UTC */
static bool debugging;
@@ -62,9 +67,9 @@ debug(const char *fmt, ...)
static void
change_tz(const char *tzn)
{
- static const char *zfn = "/usr/share/zoneinfo";
- static const char *tfn = "root/etc/.localtime";
- static const char *dfn = "root/etc/localtime";
+ static const char *zfn = TZDIR;
+ static const char *tfn = "root" TZDEFAULT ".tmp";
+ static const char *dfn = "root" TZDEFAULT;
ssize_t clen;
int zfd, sfd, dfd;
@@ -96,6 +101,50 @@ test_tz(const char *expect)
ATF_CHECK_STREQ(expect, buf);
}
+ATF_TC(tz_default);
+ATF_TC_HEAD(tz_default, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test default zone");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(tz_default, tc)
+{
+ /* prepare chroot with no /etc/localtime */
+ ATF_REQUIRE_EQ(0, mkdir("root", 0755));
+ ATF_REQUIRE_EQ(0, mkdir("root/etc", 0755));
+ /* enter chroot */
+ ATF_REQUIRE_EQ(0, chroot("root"));
+ ATF_REQUIRE_EQ(0, chdir("/"));
+ /* check timezone */
+ unsetenv("TZ");
+ test_tz("+0000 (UTC)");
+}
+
+ATF_TC(tz_invalid_file);
+ATF_TC_HEAD(tz_invalid_file, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test invalid zone file");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(tz_invalid_file, tc)
+{
+ static const char *dfn = "root/etc/localtime";
+ int fd;
+
+ /* prepare chroot with bogus /etc/localtime */
+ ATF_REQUIRE_EQ(0, mkdir("root", 0755));
+ ATF_REQUIRE_EQ(0, mkdir("root/etc", 0755));
+ ATF_REQUIRE((fd = open(dfn, O_RDWR | O_CREAT, 0644)) >= 0);
+ ATF_REQUIRE_EQ(8, write(fd, "invalid\n", 8));
+ ATF_REQUIRE_EQ(0, close(fd));
+ /* enter chroot */
+ ATF_REQUIRE_EQ(0, chroot("root"));
+ ATF_REQUIRE_EQ(0, chdir("/"));
+ /* check timezone */
+ unsetenv("TZ");
+ test_tz(invalid.expect);
+}
+
ATF_TC(thin_jail);
ATF_TC_HEAD(thin_jail, tc)
{
@@ -320,6 +369,30 @@ test_tz_env(const char *tzval, const char *expect)
test_tz(expect);
}
+static void
+tz_env_common(void)
+{
+ char path[MAXPATHLEN];
+ const struct tzcase *tzcase = tzcases;
+ int len;
+
+ /* relative path */
+ for (tzcase = tzcases; tzcase->tzfn != NULL; tzcase++)
+ test_tz_env(tzcase->tzfn, tzcase->expect);
+ /* absolute path */
+ for (tzcase = tzcases; tzcase->tzfn != NULL; tzcase++) {
+ len = snprintf(path, sizeof(path), "%s/%s", TZDIR, tzcase->tzfn);
+ ATF_REQUIRE(len > 0 && (size_t)len < sizeof(path));
+ test_tz_env(path, tzcase->expect);
+ }
+ /* absolute path with additional slashes */
+ for (tzcase = tzcases; tzcase->tzfn != NULL; tzcase++) {
+ len = snprintf(path, sizeof(path), "%s/////%s", TZDIR, tzcase->tzfn);
+ ATF_REQUIRE(len > 0 && (size_t)len < sizeof(path));
+ test_tz_env(path, tzcase->expect);
+ }
+}
+
ATF_TC(tz_env);
ATF_TC_HEAD(tz_env, tc)
{
@@ -327,10 +400,22 @@ ATF_TC_HEAD(tz_env, tc)
}
ATF_TC_BODY(tz_env, tc)
{
- const struct tzcase *tzcase;
+ tz_env_common();
+ /* escape from TZDIR is permitted when not setugid */
+ test_tz_env("../zoneinfo/UTC", utc.expect);
+}
- for (tzcase = tzcases; tzcase->tzfn != NULL; tzcase++)
- test_tz_env(tzcase->tzfn, tzcase->expect);
+
+ATF_TC(tz_invalid_env);
+ATF_TC_HEAD(tz_invalid_env, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test invalid TZ value");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(tz_invalid_env, tc)
+{
+ test_tz_env("invalid", invalid.expect);
+ test_tz_env(":invalid", invalid.expect);
}
ATF_TC(setugid);
@@ -367,23 +452,25 @@ ATF_TC_HEAD(tz_env_setugid, tc)
}
ATF_TC_BODY(tz_env_setugid, tc)
{
- const struct tzcase *tzcase = tzcases;
-
ATF_REQUIRE_EQ(0, seteuid(UID_NOBODY));
ATF_REQUIRE(issetugid());
- for (tzcase = tzcases; tzcase->tzfn != NULL; tzcase++)
- test_tz_env(tzcase->tzfn, tzcase->expect);
+ tz_env_common();
+ /* escape from TZDIR is not permitted when setugid */
+ test_tz_env("../zoneinfo/UTC", invalid.expect);
}
ATF_TP_ADD_TCS(tp)
{
debugging = !getenv("__RUNNING_INSIDE_ATF_RUN") &&
isatty(STDERR_FILENO);
+ ATF_TP_ADD_TC(tp, tz_default);
+ ATF_TP_ADD_TC(tp, tz_invalid_file);
ATF_TP_ADD_TC(tp, thin_jail);
#ifdef DETECT_TZ_CHANGES
ATF_TP_ADD_TC(tp, detect_tz_changes);
#endif /* DETECT_TZ_CHANGES */
ATF_TP_ADD_TC(tp, tz_env);
+ ATF_TP_ADD_TC(tp, tz_invalid_env);
ATF_TP_ADD_TC(tp, setugid);
ATF_TP_ADD_TC(tp, tz_env_setugid);
return (atf_no_error());
diff --git a/lib/libc/tests/string/memcmp_test.c b/lib/libc/tests/string/memcmp_test.c
index 5286a0b994f3..fa2f498ccfaf 100644
--- a/lib/libc/tests/string/memcmp_test.c
+++ b/lib/libc/tests/string/memcmp_test.c
@@ -41,14 +41,14 @@
#endif
/*
- * On FreeBSD we demand that memcmp returns the difference between the
- * characters at the first site of mismatch. However, ISO/IEC 9899:1990
- * only specifies that a number greater than, equal to, or less than
- * zero shall be returned. If a unit test for this less strict
- * behaviour is desired, define RES(x) to be (((x) > 0) - ((x) < 0)).
+ * On FreeBSD we previously demanded that memcmp returns the difference
+ * between the characters at the first site of mismatch. However,
+ * ISO/IEC 9899:1990 only specifies that a number greater than, equal
+ * to, or less than zero shall be returned. If a unit test for the
+ * more strict behaviour is desired, define RES(x) to be (x).
*/
#ifndef RES
-#define RES(x) (x)
+#define RES(x) (((x) > 0) - ((x) < 0))
#endif
static int (*memcmp_fn)(const void *, const void *, size_t);
diff --git a/lib/libc/tests/sys/cpuset_test.c b/lib/libc/tests/sys/cpuset_test.c
index 53d6a8215bbc..c8ad225fadfc 100644
--- a/lib/libc/tests/sys/cpuset_test.c
+++ b/lib/libc/tests/sys/cpuset_test.c
@@ -34,8 +34,10 @@
#include <sys/uio.h>
#include <sys/wait.h>
+#include <assert.h>
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <atf-c.h>
@@ -107,6 +109,19 @@ skip_ltncpu(int ncpu, cpuset_t *mask)
atf_tc_skip("Test requires %d or more cores.", ncpu);
}
+static void
+skip_ltncpu_root(int ncpu, cpuset_t *mask)
+{
+
+ CPU_ZERO(mask);
+ ATF_REQUIRE_EQ(0, cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID,
+ -1, sizeof(*mask), mask));
+ if (CPU_COUNT(mask) < ncpu) {
+ atf_tc_skip("Test requires cpuset root with %d or more cores.",
+ ncpu);
+ }
+}
+
ATF_TC(newset);
ATF_TC_HEAD(newset, tc)
{
@@ -234,9 +249,8 @@ ATF_TC_BODY(deadlk, tc)
}
static int
-do_jail(int sock)
+create_jail(void)
{
- struct jail_test_info info;
struct iovec iov[2];
char *name;
int error;
@@ -250,8 +264,22 @@ do_jail(int sock)
iov[1].iov_base = name;
iov[1].iov_len = strlen(name) + 1;
- if (jail_set(iov, 2, JAIL_CREATE | JAIL_ATTACH) < 0)
+ error = jail_set(iov, 2, JAIL_CREATE | JAIL_ATTACH);
+ free(name);
+ if (error < 0)
return (FAILURE_JAIL);
+ return (0);
+}
+
+static int
+do_jail(int sock)
+{
+ struct jail_test_info info;
+ int error;
+
+ error = create_jail();
+ if (error != 0)
+ return (error);
/* Record parameters, kick them over, then make a swift exit. */
CPU_ZERO(&info.jail_tidmask);
@@ -641,6 +669,111 @@ ATF_TC_BODY(jail_attach_disjoint, tc)
try_attach(jid, &smask);
}
+struct nproc_info {
+ long nproc_init;
+ long nproc_final;
+ long nproc_global;
+};
+
+ATF_TC(jail_nproc);
+ATF_TC_HEAD(jail_nproc, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that _SC_PROCESSORS_ONLN reflects jail cpuset constraints");
+}
+ATF_TC_BODY(jail_nproc, tc)
+{
+ cpuset_t jmask;
+ struct nproc_info ninfo = { };
+ int sockpair[2];
+ cpusetid_t setid;
+ ssize_t readsz;
+ pid_t pid;
+ int fcpu, error, pfd, sock;
+ char okb = 0x7f, rcvb;
+
+ skip_ltncpu_root(2, &jmask);
+ fcpu = CPU_FFS(&jmask) - 1;
+
+ /*
+ * Just adjusting our affinity should not affect the number of
+ * processors considered online- we want to be sure that it's only
+ * adjusted if our jail's root set is.
+ */
+ CPU_CLR(fcpu, &jmask);
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
+ sizeof(jmask), &jmask);
+ ATF_REQUIRE_EQ(0, error);
+ ATF_REQUIRE(sysconf(_SC_NPROCESSORS_ONLN) > CPU_COUNT(&jmask));
+
+ ATF_REQUIRE_EQ(0, socketpair(PF_UNIX, SOCK_STREAM, 0, sockpair));
+
+ /* We'll wait on the procdesc, too, so we can fail faster if it dies. */
+ ATF_REQUIRE((pid = pdfork(&pfd, 0)) != -1);
+
+ if (pid == 0) {
+ /* First child sets up the jail. */
+ sock = sockpair[SP_CHILD];
+ close(sockpair[SP_PARENT]);
+
+ error = create_jail();
+ if (error != 0)
+ _exit(error);
+
+ ninfo.nproc_init = sysconf(_SC_NPROCESSORS_ONLN);
+
+ /* Signal the parent that we're jailed. */
+ readsz = write(sock, &okb, sizeof(okb));
+ assert(readsz == sizeof(okb));
+
+ /* Wait for parent to adjust our mask and signal OK. */
+ readsz = read(sock, &rcvb, sizeof(rcvb));
+ assert(readsz == sizeof(rcvb));
+ assert(rcvb == okb);
+
+ ninfo.nproc_final = sysconf(_SC_NPROCESSORS_ONLN);
+ ninfo.nproc_global = sysconf(_SC_NPROCESSORS_CONF);
+ readsz = write(sock, &ninfo, sizeof(ninfo));
+ assert(readsz == sizeof(ninfo));
+
+ _exit(0);
+ }
+
+ close(sockpair[SP_CHILD]);
+ sock = sockpair[SP_PARENT];
+
+ /* Wait for signal that they are jailed. */
+ readsz = read(sock, &rcvb, sizeof(rcvb));
+ assert(readsz == sizeof(rcvb));
+ assert(rcvb == okb);
+
+ /* Grab the cpuset id and adjust it. */
+ error = cpuset_getid(CPU_LEVEL_ROOT, CPU_WHICH_PID, pid, &setid);
+ ATF_REQUIRE_EQ(0, error);
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_CPUSET,
+ setid, sizeof(jmask), &jmask);
+ ATF_REQUIRE_EQ(0, error);
+
+ /* Signal OK to proceed. */
+ readsz = write(sock, &okb, sizeof(okb));
+ ATF_REQUIRE_EQ(sizeof(okb), readsz);
+
+ /* Grab our final nproc info. */
+ readsz = read(sock, &ninfo, sizeof(ninfo));
+ ATF_REQUIRE_EQ(sizeof(ninfo), readsz);
+
+ /*
+ * We set our own affinity to jmask, which is derived from *our* root
+ * set, at the beginning of the test. The jail would inherit from this
+ * set, so we just re-use that mask here to confirm that
+ * _SC_NPROCESSORS_ONLN did actually drop in response to us limiting the
+ * jail, and that its _SC_NPROCESSORS_CONF did not.
+ */
+ ATF_REQUIRE_EQ(CPU_COUNT(&jmask) + 1, ninfo.nproc_init);
+ ATF_REQUIRE_EQ(CPU_COUNT(&jmask) + 1, ninfo.nproc_global);
+ ATF_REQUIRE_EQ(CPU_COUNT(&jmask), ninfo.nproc_final);
+}
+
ATF_TC(badparent);
ATF_TC_HEAD(badparent, tc)
{
@@ -686,6 +819,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, jail_attach_prevbase);
ATF_TP_ADD_TC(tp, jail_attach_plain);
ATF_TP_ADD_TC(tp, jail_attach_disjoint);
+ ATF_TP_ADD_TC(tp, jail_nproc);
ATF_TP_ADD_TC(tp, badparent);
return (atf_no_error());
}
diff --git a/lib/libc/tests/tls/dso/Makefile b/lib/libc/tests/tls/dso/Makefile
index 5efd8b29a6bd..783534ff7aae 100644
--- a/lib/libc/tests/tls/dso/Makefile
+++ b/lib/libc/tests/tls/dso/Makefile
@@ -6,6 +6,7 @@ SRCS= h_tls_dlopen.c
MAN=
PACKAGE= tests
+NO_DEV_PACKAGE=
LIBDIR= ${TESTSBASE}/lib/libc/tls
SHLIB_MAJOR= 1
diff --git a/lib/libc/tests/tls_dso/Makefile b/lib/libc/tests/tls_dso/Makefile
index 89296c643695..7cb8f98b431e 100644
--- a/lib/libc/tests/tls_dso/Makefile
+++ b/lib/libc/tests/tls_dso/Makefile
@@ -7,6 +7,7 @@ LIBDIR= ${TESTSBASE}/lib/libc/tls
SHLIBDIR= ${TESTSBASE}/lib/libc/tls
SHLIB_MAJOR= 1
PACKAGE= tests
+NO_DEV_PACKAGE=
WITHOUT_STATIC=
WITHOUT_PROFILE=
diff --git a/lib/libcasper/Makefile.inc b/lib/libcasper/Makefile.inc
index 00bd221feb27..73a761ba4ce3 100644
--- a/lib/libcasper/Makefile.inc
+++ b/lib/libcasper/Makefile.inc
@@ -1,5 +1,7 @@
.include <src.opts.mk>
+PACKAGE?= libcasper
+
.if ${MK_CASPER} != "no"
CFLAGS+=-DWITH_CASPER
.endif
diff --git a/lib/libcasper/libcasper/Makefile b/lib/libcasper/libcasper/Makefile
index 4db26f665f19..1a794791570f 100644
--- a/lib/libcasper/libcasper/Makefile
+++ b/lib/libcasper/libcasper/Makefile
@@ -1,5 +1,3 @@
-PACKAGE= runtime
-
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libcasper/services/cap_dns/Makefile b/lib/libcasper/services/cap_dns/Makefile
index 4b11c97d29e5..b090c553bd28 100644
--- a/lib/libcasper/services/cap_dns/Makefile
+++ b/lib/libcasper/services/cap_dns/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 2
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_fileargs/Makefile b/lib/libcasper/services/cap_fileargs/Makefile
index 2c52d0887a48..9d70d0ab9237 100644
--- a/lib/libcasper/services/cap_fileargs/Makefile
+++ b/lib/libcasper/services/cap_fileargs/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 1
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_fileargs/cap_fileargs.h b/lib/libcasper/services/cap_fileargs/cap_fileargs.h
index 8207671d9753..d3a0150044d7 100644
--- a/lib/libcasper/services/cap_fileargs/cap_fileargs.h
+++ b/lib/libcasper/services/cap_fileargs/cap_fileargs.h
@@ -75,7 +75,7 @@ fileargs_init(int argc __unused, char *argv[] __unused, int flags, mode_t mode,
cap_rights_t *rightsp __unused, int operations __unused) {
fileargs_t *fa;
- fa = malloc(sizeof(*fa));
+ fa = (fileargs_t *)malloc(sizeof(*fa));
if (fa != NULL) {
fa->fa_flags = flags;
fa->fa_mode = mode;
diff --git a/lib/libcasper/services/cap_grp/Makefile b/lib/libcasper/services/cap_grp/Makefile
index a921dfa87e7c..13e695813bcf 100644
--- a/lib/libcasper/services/cap_grp/Makefile
+++ b/lib/libcasper/services/cap_grp/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 1
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_net/Makefile b/lib/libcasper/services/cap_net/Makefile
index 1ba35a674a05..4e9814118c41 100644
--- a/lib/libcasper/services/cap_net/Makefile
+++ b/lib/libcasper/services/cap_net/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE=libcasper
-
SHLIB_MAJOR= 1
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_netdb/Makefile b/lib/libcasper/services/cap_netdb/Makefile
index 853052e78d04..a330eeedeb11 100644
--- a/lib/libcasper/services/cap_netdb/Makefile
+++ b/lib/libcasper/services/cap_netdb/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 1
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_pwd/Makefile b/lib/libcasper/services/cap_pwd/Makefile
index a1e97845c736..ba8df80d5ad7 100644
--- a/lib/libcasper/services/cap_pwd/Makefile
+++ b/lib/libcasper/services/cap_pwd/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 1
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_sysctl/Makefile b/lib/libcasper/services/cap_sysctl/Makefile
index 522313df4ffc..4408bad4efb4 100644
--- a/lib/libcasper/services/cap_sysctl/Makefile
+++ b/lib/libcasper/services/cap_sysctl/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 2
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/cap_syslog/Makefile b/lib/libcasper/services/cap_syslog/Makefile
index 88979d8bed23..d18ad6d76ede 100644
--- a/lib/libcasper/services/cap_syslog/Makefile
+++ b/lib/libcasper/services/cap_syslog/Makefile
@@ -2,8 +2,6 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
-PACKAGE= runtime
-
SHLIB_MAJOR= 1
INCSDIR?= ${INCLUDEDIR}/casper
diff --git a/lib/libcasper/services/tests/Makefile b/lib/libcasper/services/tests/Makefile
index 29b1b564beca..4b6c72fd86e8 100644
--- a/lib/libcasper/services/tests/Makefile
+++ b/lib/libcasper/services/tests/Makefile
@@ -1,4 +1,6 @@
.PATH: ${SRCTOP}/tests
+
+PACKAGE= tests
KYUAFILE= yes
.include <bsd.test.mk>
diff --git a/lib/libcasper/tests/Makefile b/lib/libcasper/tests/Makefile
index 29b1b564beca..4b6c72fd86e8 100644
--- a/lib/libcasper/tests/Makefile
+++ b/lib/libcasper/tests/Makefile
@@ -1,4 +1,6 @@
.PATH: ${SRCTOP}/tests
+
+PACKAGE= tests
KYUAFILE= yes
.include <bsd.test.mk>
diff --git a/lib/libdiff/Makefile b/lib/libdiff/Makefile
index 8541ff424de2..25f849a69e05 100644
--- a/lib/libdiff/Makefile
+++ b/lib/libdiff/Makefile
@@ -8,7 +8,7 @@ INTERNALLIB= # API not published or supported.
SRCS= diff_atomize_text.c diff_main.c diff_myers.c \
diff_patience.c diff_output.c diff_output_plain.c \
- diff_output_unidiff.c diff_output_edscript.c recallocarray.c
+ diff_output_unidiff.c diff_output_edscript.c
WARNS=
CFLAGS+= -I${SRCTOP}/contrib/libdiff/compat/include
diff --git a/lib/libedit/Makefile b/lib/libedit/Makefile
index f0254c1f42bc..9161e05a7d36 100644
--- a/lib/libedit/Makefile
+++ b/lib/libedit/Makefile
@@ -1,7 +1,5 @@
# $NetBSD: Makefile,v 1.56 2016/03/02 19:24:20 christos Exp $
-PACKAGE=clibs
-
EDITDIR= ${SRCTOP}/contrib/libedit
.PATH: ${EDITDIR}
@@ -17,10 +15,10 @@ SRCS= chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \
parse.c prompt.c read.c readline.c refresh.c search.c sig.c \
terminal.c tokenizer.c tokenizern.c tty.c vi.c
+MAN= editline.3
+MANNODEV= editrc.5 editline.7
-MAN= editline.3 editrc.5 editline.7
-
-MLINKS= \
+MLINKS=\
editline.3 el_deletestr.3 \
editline.3 el_end.3 \
editline.3 el_get.3 \
@@ -93,6 +91,7 @@ tc1.o: ${EDITDIR}/TEST/tc1.c
test: tc1.o libedit.a ${DPADD} ${LIBTERMCAP}
${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}
+.include "Makefile.inc"
.include <bsd.lib.mk>
CWARNFLAGS.chartype.c= ${NO_WUSE_AFTER_FREE}
diff --git a/lib/libedit/Makefile.inc b/lib/libedit/Makefile.inc
new file mode 100644
index 000000000000..9ec65b0d266f
--- /dev/null
+++ b/lib/libedit/Makefile.inc
@@ -0,0 +1 @@
+PACKAGE?=runtime
diff --git a/lib/libefivar/FreeBSD-update b/lib/libefivar/FreeBSD-update
index 52d0db4021ef..53b8f0dfff1a 100644
--- a/lib/libefivar/FreeBSD-update
+++ b/lib/libefivar/FreeBSD-update
@@ -8,7 +8,7 @@ These files are first mechnaically processed with
sed -e "s/L'/'/g;"'s/L"/"/g;s/%g/%36s/g;s/%a/%s/g;s/^VOID/static VOID/g;s/ *$//g'
-for several reasons. We're moving from wide rotuines to narrow routines. The
+for several reasons. We're moving from wide routines to narrow routines. The
UTC-2 this code is written for is a bad match for wchar_t which is an int. It's
a much better match for plain narrow characters on FreeBSD. So we pretend that
CHAR16 for these files is really char * (ASCII).
diff --git a/lib/libefivar/ProcessorBind.h b/lib/libefivar/ProcessorBind.h
deleted file mode 100644
index 46abe715d38f..000000000000
--- a/lib/libefivar/ProcessorBind.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/* File in public domain */
-/* Brings in the glue for UEFI/EDK2 Tianocore code to run on this OS */
-#include "efi-osdep.h"
diff --git a/lib/libefivar/efi-osdep.h b/lib/libefivar/efi-osdep.h
deleted file mode 100644
index e91d7405da97..000000000000
--- a/lib/libefivar/efi-osdep.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-
- * Copyright (c) 2017 Netflix, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE 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.
- */
-
-#ifndef _EFI_OSDEP_H_
-#define _EFI_OSDEP_H_
-
-/*
- * Defines to adjust the types that EDK2 uses for FreeBSD so we can
- * use the code and headers mostly unchanged. The headers are imported
- * all into one directory to avoid case issues with filenames and
- * included. The actual code is heavily modified since it has too many
- * annoying dependencies that are difficult to satisfy.
- */
-
-#include <sys/cdefs.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <uuid.h>
-
-typedef int8_t INT8;
-typedef int16_t INT16;
-typedef int32_t INT32;
-typedef int64_t INT64;
-typedef intptr_t INTN;
-typedef uint8_t UINT8;
-typedef uint16_t UINT16;
-typedef uint32_t UINT32;
-typedef uint64_t UINT64;
-typedef uintptr_t UINTN;
-//typedef uintptr_t EFI_PHYSICAL_ADDRESS;
-//typedef uint32_t EFI_IPv4_ADDRESS;
-//typedef uint8_t EFI_MAC_ADDRESS[6];
-//typedef uint8_t EFI_IPv6_ADDRESS[16];
-typedef uint8_t CHAR8;
-typedef uint16_t CHAR16;
-typedef UINT8 BOOLEAN;
-typedef void VOID;
-//typedef uuid_t GUID;
-//typedef uuid_t EFI_GUID;
-
-/* We can't actually call this stuff, so snip out API syntactic sugar */
-#define INTERFACE_DECL(x)
-#define EFIAPI
-#define IN
-#define OUT
-#define CONST const
-#define OPTIONAL
-//#define TRUE 1
-//#define FALSE 0
-
-/*
- * EDK2 has fine definitions for these, so let it define them.
- */
-#undef NULL
-#undef EFI_PAGE_SIZE
-#undef EFI_PAGE_MASK
-
-/*
- * Note: the EDK2 code assumed #pragma packed works and PACKED is a
- * workaround for some old toolchain issues for EDK2 that aren't
- * relevent to FreeBSD.
- */
-#define PACKED
-
-/*
- * Since we're not compiling for the UEFI boot time (which use ms abi
- * conventions), tell EDK2 to define VA_START correctly. For the boot
- * loader, this likely needs to be different.
- */
-#define NO_MSABI_VA_FUNCS 1
-
-/*
- * Finally, we need to define the processor we are in EDK2 terms.
- */
-#if defined(__i386__)
-#define MDE_CPU_IA32
-#elif defined(__amd64__)
-#define MDE_CPU_X64
-#elif defined(__arm__)
-#define MDE_CPU_ARM
-#elif defined(__aarch64__)
-#define MDE_CPU_AARCH64
-#elif defined(__riscv)
-#define MDE_CPU_RISCV64
-#endif
-/* FreeBSD doesn't have/use MDE_CPU_EBC or MDE_CPU_IPF (ia64) */
-
-#endif /* _EFI_OSDEP_H_ */
diff --git a/lib/libefivar/efivar-dp-format.c b/lib/libefivar/efivar-dp-format.c
index f2dcf1b91c01..2050b09951cb 100644
--- a/lib/libefivar/efivar-dp-format.c
+++ b/lib/libefivar/efivar-dp-format.c
@@ -33,10 +33,7 @@
#include <string.h>
#include "efichar.h"
-
-#include "efi-osdep.h"
#include "efivar-dp.h"
-
#include "uefi-dplib.h"
/*
diff --git a/lib/libefivar/efivar-dp-parse.c b/lib/libefivar/efivar-dp-parse.c
index 51c134692f1e..f2eb46a54509 100644
--- a/lib/libefivar/efivar-dp-parse.c
+++ b/lib/libefivar/efivar-dp-parse.c
@@ -35,10 +35,7 @@
#include <wchar.h>
#include "efichar.h"
-
-#include "efi-osdep.h"
#include "efivar-dp.h"
-
#include "uefi-dplib.h"
/* XXX STUBS -- this stuff doesn't work yet */
@@ -316,7 +313,6 @@ GetNextDeviceNodeStr (
return ReturnStr;
}
-
#ifndef __FreeBSD__
/**
Return whether the integer string is a hex string.
diff --git a/lib/libefivar/efivar-dp-xlate.c b/lib/libefivar/efivar-dp-xlate.c
index 1e816cecbb81..2012842b6f80 100644
--- a/lib/libefivar/efivar-dp-xlate.c
+++ b/lib/libefivar/efivar-dp-xlate.c
@@ -39,10 +39,7 @@
#include <string.h>
#include "efichar.h"
-
-#include "efi-osdep.h"
#include "efivar-dp.h"
-
#include "uefi-dplib.h"
#define MAX_DP_SANITY 4096 /* Biggest device path in bytes */
@@ -224,7 +221,7 @@ efi_hd_to_unix(struct gmesh *mesh, const_efidp dp, char **dev, char **relpath, c
provider = pp;
for (i = 0; i < n; i++) {
/*
- * Skip all pseudo filesystems. This also skips the real filesytsem
+ * Skip all pseudo filesystems. This also skips the real filesystem
* of ZFS. There's no EFI designator for ZFS in the standard, so
* we'll need to invent one, but its decoding will be handled in
* a separate function.
@@ -331,7 +328,7 @@ errout:
*
* Extract the path from the File path node(s). translate any \ file separators
* to /. Append the result to the mount point. Copy the resulting path into
- * *path. Stat that path. If it is not found, return the errorr from stat.
+ * *path. Stat that path. If it is not found, return the error from stat.
*
* Finally, check to make sure the resulting path is still on the same
* device. If not, return ENODEV.
@@ -436,7 +433,7 @@ efivar_device_path_to_unix_path(const_efidp dp, char **dev, char **relpath, char
* For paths of the first form:
* find where the filesystem is mount (either the file directly, or
* its parent directory).
- * translate any logical device name (eg lable) to a physical one
+ * translate any logical device name (eg label) to a physical one
* If not possible, return ENXIO
* If the physical path is unsupported (Eg not on a GPT or MBR disk),
* return ENXIO
@@ -445,7 +442,7 @@ efivar_device_path_to_unix_path(const_efidp dp, char **dev, char **relpath, char
* as a file path.
*
* For paths matching the second form:
- * find the EFI partition corresponding to the root fileystem.
+ * find the EFI partition corresponding to the root filesystem.
* If none found, return ENXIO
* Create a media device path node for the found partition
* Append a File Path to the end for the rest of the file.
@@ -556,7 +553,7 @@ find_geom_efimedia(struct gmesh *mesh, const char *dev)
efimedia = geom_pp_attr(mesh, pp, "efimedia");
/*
- * If this device doesn't hav an efimedia attribute, see if it is a
+ * If this device doesn't have an efimedia attribute, see if it is a
* glabel node, and if so look for the underlying provider to get the
* efimedia attribute from.
*/
diff --git a/lib/libefivar/efivar.h b/lib/libefivar/efivar.h
index e159f4cccd3d..238b23a8b2b8 100644
--- a/lib/libefivar/efivar.h
+++ b/lib/libefivar/efivar.h
@@ -31,7 +31,7 @@
#include <sys/endian.h>
#include <stdint.h>
-/* Shoud these be elsewhere ? */
+/* Should these be elsewhere ? */
#define EFI_VARIABLE_NON_VOLATILE 0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
diff --git a/lib/libefivar/uefi-dplib.h b/lib/libefivar/uefi-dplib.h
index 6f76a9763a34..c048a280a08e 100644
--- a/lib/libefivar/uefi-dplib.h
+++ b/lib/libefivar/uefi-dplib.h
@@ -37,6 +37,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _UEFI_DEVICE_PATH_LIB_H_
#define _UEFI_DEVICE_PATH_LIB_H_
+
#include <Uefi.h>
#include <Protocol/DevicePathUtilities.h>
#include <Protocol/DebugPort.h>
@@ -174,8 +175,7 @@ typedef struct {
#pragma pack()
-#ifdef FreeBSD /* Remove these on FreeBSD */
-
+#ifndef __FreeBSD__ /* Remove these on FreeBSD */
/**
Returns the size of a device path in bytes.
diff --git a/lib/libefivar/uefi-dputil.c b/lib/libefivar/uefi-dputil.c
index 6e8f3aeca2ce..da87bffb7bd5 100644
--- a/lib/libefivar/uefi-dputil.c
+++ b/lib/libefivar/uefi-dputil.c
@@ -33,16 +33,11 @@
#include <stdio.h>
#include <string.h>
#include <sys/endian.h>
-
-#include "efi-osdep.h"
-
#include "uefi-dplib.h"
-/* XXX maybe I should include the entire DevicePathUtiltiies.c and ifdef out what we don't use */
-
/*
* Taken from MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
- * hash a11928f3310518ab1c6fd34e8d0fdbb72de9602c 2017-Mar-01
+ * hash 2f88bd3a1296c522317f1c21377876de63de5be7 2021-Dec-07
*/
/** @file
@@ -55,17 +50,13 @@
environment varibles. Multi-instance device paths should never be placed
on a Handle.
- Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php.
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+// #include "UefiDevicePathLib.h"
+
//
// Template for an end-of-device path node.
//
@@ -78,59 +69,16 @@ static CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {
}
};
-
-/**
- Returns the size of a device path in bytes.
-
- This function returns the size, in bytes, of the device path data structure
- specified by DevicePath including the end of device path node.
- If DevicePath is NULL or invalid, then 0 is returned.
-
- @param DevicePath A pointer to a device path data structure.
-
- @retval 0 If DevicePath is NULL or invalid.
- @retval Others The size of a device path in bytes.
-
-**/
-UINTN
-EFIAPI
-GetDevicePathSize (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- CONST EFI_DEVICE_PATH_PROTOCOL *Start;
-
- if (DevicePath == NULL) {
- return 0;
- }
-
- if (!IsDevicePathValid (DevicePath, 0)) {
- return 0;
- }
-
- //
- // Search for the end of the device path structure
- //
- Start = DevicePath;
- while (!IsDevicePathEnd (DevicePath)) {
- DevicePath = NextDevicePathNode (DevicePath);
- }
-
- //
- // Compute the size and add back in the size of the end device path structure
- //
- return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);
-}
-
/**
Determine whether a given device path is valid.
- If DevicePath is NULL, then ASSERT().
@param DevicePath A pointer to a device path data structure.
@param MaxSize The maximum size of the device path data structure.
@retval TRUE DevicePath is valid.
- @retval FALSE The length of any node in the DevicePath is less
+ @retval FALSE DevicePath is NULL.
+ @retval FALSE Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).
+ @retval FALSE The length of any node Node in the DevicePath is less
than sizeof (EFI_DEVICE_PATH_PROTOCOL).
@retval FALSE If MaxSize is not zero, the size of the DevicePath
exceeds MaxSize.
@@ -140,27 +88,25 @@ GetDevicePathSize (
BOOLEAN
EFIAPI
IsDevicePathValid (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
- IN UINTN MaxSize
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN UINTN MaxSize
)
{
- UINTN Count;
- UINTN Size;
- UINTN NodeLength;
-
- ASSERT (DevicePath != NULL);
-
- if (MaxSize == 0) {
- MaxSize = MAX_UINTN;
- }
+ UINTN Count;
+ UINTN Size;
+ UINTN NodeLength;
//
- // Validate the input size big enough to touch the first node.
+ // Validate the input whether exists and its size big enough to touch the first node
//
- if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
+ if ((DevicePath == NULL) || ((MaxSize > 0) && (MaxSize < END_DEVICE_PATH_LENGTH))) {
return FALSE;
}
+ if (MaxSize == 0) {
+ MaxSize = MAX_UINTN;
+ }
+
for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
NodeLength = DevicePathNodeLength (DevicePath);
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
@@ -170,6 +116,7 @@ IsDevicePathValid (
if (NodeLength > MAX_UINTN - Size) {
return FALSE;
}
+
Size += NodeLength;
//
@@ -185,12 +132,22 @@ IsDevicePathValid (
return FALSE;
}
}
+
+ //
+ // FilePath must be a NULL-terminated string.
+ //
+ if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP) &&
+ (*(const CHAR16 *)((const UINT8 *) DevicePath + NodeLength - 2) != 0))
+ {
+ return FALSE;
+ }
}
//
// Only return TRUE when the End Device Path node is valid.
//
- return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
+ return (BOOLEAN)(DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
}
/**
@@ -215,7 +172,6 @@ DevicePathType (
return ((const EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;
}
-
/**
Returns the SubType field of a device path node.
@@ -260,6 +216,7 @@ DevicePathNodeLength (
)
{
ASSERT (Node != NULL);
+// return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);
return ((const EFI_DEVICE_PATH_PROTOCOL *)Node)->Length[0] |
(((const EFI_DEVICE_PATH_PROTOCOL *)Node)->Length[1] << 8);
}
@@ -285,7 +242,7 @@ NextDevicePathNode (
)
{
ASSERT (Node != NULL);
- return ((EFI_DEVICE_PATH_PROTOCOL *)(__DECONST(UINT8 *, Node) + DevicePathNodeLength(Node)));
+ return (EFI_DEVICE_PATH_PROTOCOL *)(__DECONST(UINT8 *, Node) + DevicePathNodeLength (Node));
}
/**
@@ -315,7 +272,7 @@ IsDevicePathEndType (
)
{
ASSERT (Node != NULL);
- return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);
+ return (BOOLEAN)(DevicePathType (Node) == END_DEVICE_PATH_TYPE);
}
/**
@@ -342,34 +299,37 @@ IsDevicePathEnd (
)
{
ASSERT (Node != NULL);
- return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
+ return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
}
+#ifndef __FreeBSD__
/**
- Fills in all the fields of a device path node that is the end of an entire device path.
+ Determines if a device path node is an end node of a device path instance.
- Fills in all the fields of a device path node specified by Node so Node represents
- the end of an entire device path. The Type field of Node is set to
- END_DEVICE_PATH_TYPE, the SubType field of Node is set to
- END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
- END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
- so it is recommended that a function such as WriteUnaligned16() be used to set
- the contents of the Length field.
+ Determines if a device path node specified by Node is an end node of a device
+ path instance. If Node represents the end of a device path instance, then TRUE
+ is returned. Otherwise, FALSE is returned.
If Node is NULL, then ASSERT().
@param Node A pointer to a device path node data structure.
+ @retval TRUE The device path node specified by Node is the end of a device
+ path instance.
+ @retval FALSE The device path node specified by Node is not the end of a
+ device path instance.
+
**/
-VOID
+BOOLEAN
EFIAPI
-SetDevicePathEndNode (
- OUT VOID *Node
+IsDevicePathEndInstance (
+ IN CONST VOID *Node
)
{
ASSERT (Node != NULL);
- memcpy (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));
+ return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
}
+#endif
/**
Sets the length, in bytes, of a device path node.
@@ -404,49 +364,72 @@ SetDevicePathNodeLength (
}
/**
- Creates a device node.
+ Fills in all the fields of a device path node that is the end of an entire device path.
- This function creates a new device node in a newly allocated buffer of size
- NodeLength and initializes the device path node header with NodeType and NodeSubType.
- The new device path node is returned.
- If NodeLength is smaller than a device path header, then NULL is returned.
- If there is not enough memory to allocate space for the new device path, then
- NULL is returned.
- The memory is allocated from EFI boot services memory. It is the responsibility
- of the caller to free the memory allocated.
+ Fills in all the fields of a device path node specified by Node so Node represents
+ the end of an entire device path. The Type field of Node is set to
+ END_DEVICE_PATH_TYPE, the SubType field of Node is set to
+ END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
+ END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
+ so it is recommended that a function such as WriteUnaligned16() be used to set
+ the contents of the Length field.
- @param NodeType The device node type for the new device node.
- @param NodeSubType The device node sub-type for the new device node.
- @param NodeLength The length of the new device node.
+ If Node is NULL, then ASSERT().
- @return The new device path.
+ @param Node A pointer to a device path node data structure.
**/
-EFI_DEVICE_PATH_PROTOCOL *
+VOID
EFIAPI
-CreateDeviceNode (
- IN UINT8 NodeType,
- IN UINT8 NodeSubType,
- IN UINT16 NodeLength
+SetDevicePathEndNode (
+ OUT VOID *Node
)
{
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ ASSERT (Node != NULL);
+ memcpy (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));
+}
- if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
- //
- // NodeLength is less than the size of the header.
- //
- return NULL;
+/**
+ Returns the size of a device path in bytes.
+
+ This function returns the size, in bytes, of the device path data structure
+ specified by DevicePath including the end of device path node.
+ If DevicePath is NULL or invalid, then 0 is returned.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval 0 If DevicePath is NULL or invalid.
+ @retval Others The size of a device path in bytes.
+
+**/
+UINTN
+EFIAPI
+GetDevicePathSize (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ CONST EFI_DEVICE_PATH_PROTOCOL *Start;
+
+ if (DevicePath == NULL) {
+ return 0;
}
- DevicePath = AllocateZeroPool (NodeLength);
- if (DevicePath != NULL) {
- DevicePath->Type = NodeType;
- DevicePath->SubType = NodeSubType;
- SetDevicePathNodeLength (DevicePath, NodeLength);
+ if (!IsDevicePathValid (DevicePath, 0)) {
+ return 0;
}
- return DevicePath;
+ //
+ // Search for the end of the device path structure
+ //
+ Start = DevicePath;
+ while (!IsDevicePathEnd (DevicePath)) {
+ DevicePath = NextDevicePathNode (DevicePath);
+ }
+
+ //
+ // Compute the size and add back in the size of the end device path structure
+ //
+ return ((UINTN)DevicePath - (UINTN)Start) + DevicePathNodeLength (DevicePath);
}
/**
@@ -471,7 +454,7 @@ DuplicateDevicePath (
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- UINTN Size;
+ UINTN Size;
//
// Compute the size
@@ -515,7 +498,7 @@ DuplicateDevicePath (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
AppendDevicePath (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,
IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
)
{
@@ -544,9 +527,9 @@ AppendDevicePath (
// Allocate space for the combined device path. It only has one end node of
// length EFI_DEVICE_PATH_PROTOCOL.
//
- Size1 = GetDevicePathSize (FirstDevicePath);
- Size2 = GetDevicePathSize (SecondDevicePath);
- Size = Size1 + Size2 - END_DEVICE_PATH_LENGTH;
+ Size1 = GetDevicePathSize (FirstDevicePath);
+ Size2 = GetDevicePathSize (SecondDevicePath);
+ Size = Size1 + Size2 - END_DEVICE_PATH_LENGTH;
NewDevicePath = AllocatePool (Size);
@@ -555,8 +538,8 @@ AppendDevicePath (
//
// Over write FirstDevicePath EndNode and do the copy
//
- DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +
- (Size1 - END_DEVICE_PATH_LENGTH));
+ DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *)((CHAR8 *)NewDevicePath +
+ (Size1 - END_DEVICE_PATH_LENGTH));
CopyMem (DevicePath2, SecondDevicePath, Size2);
}
@@ -594,7 +577,7 @@ AppendDevicePath (
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
AppendDevicePathNode (
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
)
{
@@ -606,6 +589,7 @@ AppendDevicePathNode (
if (DevicePathNode == NULL) {
return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);
}
+
//
// Build a Node that has a terminator on it
//
@@ -615,6 +599,7 @@ AppendDevicePathNode (
if (TempDevicePath == NULL) {
return NULL;
}
+
TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);
//
// Add and end device path node to convert Node to device path
@@ -630,3 +615,302 @@ AppendDevicePathNode (
return NewDevicePath;
}
+
+#ifndef __FreeBSD__
+/**
+ Creates a new device path by appending the specified device path instance to the specified device
+ path.
+
+ This function creates a new device path by appending a copy of the device path
+ instance specified by DevicePathInstance to a copy of the device path specified
+ by DevicePath in a allocated buffer.
+ The end-of-device-path device node is moved after the end of the appended device
+ path instance and a new end-of-device-path-instance node is inserted between.
+ If DevicePath is NULL, then a copy if DevicePathInstance is returned.
+ If DevicePathInstance is NULL, then NULL is returned.
+ If DevicePath or DevicePathInstance is invalid, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param DevicePath A pointer to a device path data structure.
+ @param DevicePathInstance A pointer to a device path instance.
+
+ @return A pointer to the new device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibAppendDevicePathInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
+ UINTN SrcSize;
+ UINTN InstanceSize;
+
+ if (DevicePath == NULL) {
+ return DuplicateDevicePath (DevicePathInstance);
+ }
+
+ if (DevicePathInstance == NULL) {
+ return NULL;
+ }
+
+ if (!IsDevicePathValid (DevicePath, 0) || !IsDevicePathValid (DevicePathInstance, 0)) {
+ return NULL;
+ }
+
+ SrcSize = GetDevicePathSize (DevicePath);
+ InstanceSize = GetDevicePathSize (DevicePathInstance);
+
+ NewDevicePath = AllocatePool (SrcSize + InstanceSize);
+ if (NewDevicePath != NULL) {
+ TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);
+
+ while (!IsDevicePathEnd (TempDevicePath)) {
+ TempDevicePath = NextDevicePathNode (TempDevicePath);
+ }
+
+ TempDevicePath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
+ TempDevicePath = NextDevicePathNode (TempDevicePath);
+ CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);
+ }
+
+ return NewDevicePath;
+}
+
+/**
+ Creates a copy of the current device path instance and returns a pointer to the next device path
+ instance.
+
+ This function creates a copy of the current device path instance. It also updates
+ DevicePath to point to the next device path instance in the device path (or NULL
+ if no more) and updates Size to hold the size of the device path instance copy.
+ If DevicePath is NULL, then NULL is returned.
+ If DevicePath points to a invalid device path, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+ If Size is NULL, then ASSERT().
+
+ @param DevicePath On input, this holds the pointer to the current
+ device path instance. On output, this holds
+ the pointer to the next device path instance
+ or NULL if there are no more device path
+ instances in the device path pointer to a
+ device path data structure.
+ @param Size On output, this holds the size of the device
+ path instance, in bytes or zero, if DevicePath
+ is NULL.
+
+ @return A pointer to the current device path instance.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+UefiDevicePathLibGetNextDevicePathInstance (
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT UINTN *Size
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevPath;
+ EFI_DEVICE_PATH_PROTOCOL *ReturnValue;
+ UINT8 Temp;
+
+ ASSERT (Size != NULL);
+
+ if ((DevicePath == NULL) || (*DevicePath == NULL)) {
+ *Size = 0;
+ return NULL;
+ }
+
+ if (!IsDevicePathValid (*DevicePath, 0)) {
+ return NULL;
+ }
+
+ //
+ // Find the end of the device path instance
+ //
+ DevPath = *DevicePath;
+ while (!IsDevicePathEndType (DevPath)) {
+ DevPath = NextDevicePathNode (DevPath);
+ }
+
+ //
+ // Compute the size of the device path instance
+ //
+ *Size = ((UINTN)DevPath - (UINTN)(*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
+
+ //
+ // Make a copy and return the device path instance
+ //
+ Temp = DevPath->SubType;
+ DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ ReturnValue = DuplicateDevicePath (*DevicePath);
+ DevPath->SubType = Temp;
+
+ //
+ // If DevPath is the end of an entire device path, then another instance
+ // does not follow, so *DevicePath is set to NULL.
+ //
+ if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {
+ *DevicePath = NULL;
+ } else {
+ *DevicePath = NextDevicePathNode (DevPath);
+ }
+
+ return ReturnValue;
+}
+#endif
+
+/**
+ Creates a device node.
+
+ This function creates a new device node in a newly allocated buffer of size
+ NodeLength and initializes the device path node header with NodeType and NodeSubType.
+ The new device path node is returned.
+ If NodeLength is smaller than a device path header, then NULL is returned.
+ If there is not enough memory to allocate space for the new device path, then
+ NULL is returned.
+ The memory is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ @param NodeType The device node type for the new device node.
+ @param NodeSubType The device node sub-type for the new device node.
+ @param NodeLength The length of the new device node.
+
+ @return The new device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+CreateDeviceNode (
+ IN UINT8 NodeType,
+ IN UINT8 NodeSubType,
+ IN UINT16 NodeLength
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
+ //
+ // NodeLength is less than the size of the header.
+ //
+ return NULL;
+ }
+
+ DevicePath = AllocateZeroPool (NodeLength);
+ if (DevicePath != NULL) {
+ DevicePath->Type = NodeType;
+ DevicePath->SubType = NodeSubType;
+ SetDevicePathNodeLength (DevicePath, NodeLength);
+ }
+
+ return DevicePath;
+}
+
+#ifndef __FreeBSD__
+/**
+ Determines if a device path is single or multi-instance.
+
+ This function returns TRUE if the device path specified by DevicePath is
+ multi-instance.
+ Otherwise, FALSE is returned.
+ If DevicePath is NULL or invalid, then FALSE is returned.
+
+ @param DevicePath A pointer to a device path data structure.
+
+ @retval TRUE DevicePath is multi-instance.
+ @retval FALSE DevicePath is not multi-instance, or DevicePath
+ is NULL or invalid.
+
+**/
+BOOLEAN
+EFIAPI
+UefiDevicePathLibIsDevicePathMultiInstance (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ CONST EFI_DEVICE_PATH_PROTOCOL *Node;
+
+ if (DevicePath == NULL) {
+ return FALSE;
+ }
+
+ if (!IsDevicePathValid (DevicePath, 0)) {
+ return FALSE;
+ }
+
+ Node = DevicePath;
+ while (!IsDevicePathEnd (Node)) {
+ if (IsDevicePathEndInstance (Node)) {
+ return TRUE;
+ }
+
+ Node = NextDevicePathNode (Node);
+ }
+
+ return FALSE;
+}
+
+/**
+ Allocates a device path for a file and appends it to an existing device path.
+
+ If Device is a valid device handle that contains a device path protocol, then a device path for
+ the file specified by FileName is allocated and appended to the device path associated with the
+ handle Device. The allocated device path is returned. If Device is NULL or Device is a handle
+ that does not support the device path protocol, then a device path containing a single device
+ path node for the file specified by FileName is allocated and returned.
+ The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
+ of the caller to free the memory allocated.
+
+ If FileName is NULL, then ASSERT().
+ If FileName is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param Device A pointer to a device handle. This parameter
+ is optional and may be NULL.
+ @param FileName A pointer to a Null-terminated Unicode string.
+
+ @return The allocated device path.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+FileDevicePath (
+ IN EFI_HANDLE Device OPTIONAL,
+ IN CONST CHAR16 *FileName
+ )
+{
+ UINTN Size;
+ FILEPATH_DEVICE_PATH *FilePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
+
+ DevicePath = NULL;
+
+ Size = StrSize (FileName);
+ FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
+ if (FileDevicePath != NULL) {
+ FilePath = (FILEPATH_DEVICE_PATH *)FileDevicePath;
+ FilePath->Header.Type = MEDIA_DEVICE_PATH;
+ FilePath->Header.SubType = MEDIA_FILEPATH_DP;
+ CopyMem (&FilePath->PathName, FileName, Size);
+ SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
+ SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
+
+ if (Device != NULL) {
+ DevicePath = DevicePathFromHandle (Device);
+ }
+
+ DevicePath = AppendDevicePath (DevicePath, FileDevicePath);
+ FreePool (FileDevicePath);
+ }
+
+ return DevicePath;
+}
+#endif
diff --git a/lib/libexpat/expat_config.h b/lib/libexpat/expat_config.h
index 748f75ee157d..565404f1577b 100644
--- a/lib/libexpat/expat_config.h
+++ b/lib/libexpat/expat_config.h
@@ -31,7 +31,7 @@
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
-/* Define to 1 if you have the `getpagesize' function. */
+/* Define to 1 if you have the 'getpagesize' function. */
#define HAVE_GETPAGESIZE 1
/* Define to 1 if you have the `getrandom' function. */
@@ -40,10 +40,10 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
-/* Define to 1 if you have the `bsd' library (-lbsd). */
+/* Define to 1 if you have the 'bsd' library (-lbsd). */
/* #undef HAVE_LIBBSD */
-/* Define to 1 if you have a working `mmap' system call. */
+/* Define to 1 if you have a working 'mmap' system call. */
#define HAVE_MMAP 1
/* Define to 1 if you have the <stdint.h> header file. */
@@ -89,7 +89,7 @@
#define PACKAGE_NAME "expat"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "expat 2.7.1"
+#define PACKAGE_STRING "expat 2.7.3"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "expat"
@@ -98,15 +98,15 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "2.7.1"
+#define PACKAGE_VERSION "2.7.3"
-/* Define to 1 if all of the C90 standard headers exist (not just the ones
+/* Define to 1 if all of the C89 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#define STDC_HEADERS 1
/* Version number of package */
-#define VERSION "2.7.1"
+#define VERSION "2.7.3"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
@@ -140,10 +140,10 @@
/* Define to make XML Namespaces functionality available. */
#define XML_NS 1
-/* Define to empty if `const' does not conform to ANSI C. */
+/* Define to empty if 'const' does not conform to ANSI C. */
/* #undef const */
-/* Define to `long int' if <sys/types.h> does not define. */
+/* Define to 'long int' if <sys/types.h> does not define. */
/* #undef off_t */
#endif // ndef EXPAT_CONFIG_H
diff --git a/lib/libexpat/libbsdxml.3 b/lib/libexpat/libbsdxml.3
index c91184840b70..d25249bbc155 100644
--- a/lib/libexpat/libbsdxml.3
+++ b/lib/libexpat/libbsdxml.3
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"/
-.Dd April 7, 2025
+.Dd September 28, 2025
.Dt LIBBSDXML 3
.Os
.Sh NAME
@@ -34,7 +34,7 @@
.Sh DESCRIPTION
The
.Nm
-library is a verbatim copy of the eXpat XML library version 2.7.1.
+library is a verbatim copy of the eXpat XML library version 2.7.3.
.Pp
The
.Nm
diff --git a/lib/libfido2/Makefile b/lib/libfido2/Makefile
index 10c008967e3d..021a32dd514b 100644
--- a/lib/libfido2/Makefile
+++ b/lib/libfido2/Makefile
@@ -43,7 +43,6 @@ SRCS+= u2f.c
SRCS+= util.c
SRCS+= openbsd-compat/freezero.c
-SRCS+= openbsd-compat/recallocarray.c
CFLAGS+= -I ${DIST}/src -I${SRCTOP}/contrib/libcbor/src -I${.CURDIR}/../libcbor
CFLAGS+= -D_FIDO_INTERNAL
diff --git a/lib/libgcc_s/Makefile b/lib/libgcc_s/Makefile
index 992fc930ee9f..7e3911043843 100644
--- a/lib/libgcc_s/Makefile
+++ b/lib/libgcc_s/Makefile
@@ -11,7 +11,9 @@ MK_SSP= no
WARNS?= 2
LDFLAGS+= -nodefaultlibs
+LDFLAGS+= -Wl,-Bsymbolic
LIBADD+= c
+LIBADD+= compiler_rt
VERSION_DEF= ${.CURDIR}/Versions.def
SYMBOL_MAPS= ${.CURDIR}/Symbol.map
diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c
index 931391055919..ad3348af0d2d 100644
--- a/lib/libjail/jail.c
+++ b/lib/libjail/jail.c
@@ -95,8 +95,8 @@ jail_setv(int flags, ...)
goto error;
if (jailparam_import(jp + njp, value) < 0)
goto error;
- if (!strcmp(name, "desc")
- && (flags & (JAIL_GET_DESC | JAIL_OWN_DESC))) {
+ if (!strcmp(name, "desc") &&
+ (flags & (JAIL_GET_DESC | JAIL_OWN_DESC))) {
jp_desc = jp + njp;
desc_value = value;
}
@@ -145,8 +145,8 @@ jail_getv(int flags, ...)
va_end(tap);
goto error;
}
- if (!strcmp(jp[njp].jp_name, "desc")
- && (flags & (JAIL_USE_DESC | JAIL_AT_DESC))) {
+ if (!strcmp(jp[njp].jp_name, "desc") &&
+ (flags & (JAIL_USE_DESC | JAIL_AT_DESC))) {
jp_desc = jp + njp;
desc_value = value;
} else if (!strcmp(jp[njp].jp_name, "lastjid")) {
@@ -181,8 +181,8 @@ jail_getv(int flags, ...)
}
if (jailparam_import(jp_key, key_value) < 0)
goto error;
- if (jp_desc != NULL && jp_desc != jp_key
- && jailparam_import(jp_desc, desc_value) < 0)
+ if (jp_desc != NULL && jp_desc != jp_key &&
+ jailparam_import(jp_desc, desc_value) < 0)
goto error;
/* Get the jail and export the parameters. */
jid = jailparam_get(jp, njp, flags);
@@ -604,8 +604,8 @@ jailparam_get(struct jailparam *jp, unsigned njp, int flags)
jp_desc = jp_lastjid = jp_jid = jp_name = NULL;
arrays = 0;
for (ai = j = 0; j < njp; j++) {
- if (!strcmp(jp[j].jp_name, "desc")
- && (flags & (JAIL_USE_DESC | JAIL_AT_DESC)))
+ if (!strcmp(jp[j].jp_name, "desc") &&
+ (flags & (JAIL_USE_DESC | JAIL_AT_DESC)))
jp_desc = jp + j;
else if (!strcmp(jp[j].jp_name, "lastjid"))
jp_lastjid = jp + j;
@@ -920,13 +920,21 @@ jailparam_type(struct jailparam *jp)
} desc;
int mib[CTL_MAXNAME];
- /* The "lastjid" parameter isn't real. */
+ /*
+ * Some pseudo-parameters don't show up in the sysctl
+ * parameter list.
+ */
name = jp->jp_name;
if (!strcmp(name, "lastjid")) {
jp->jp_valuelen = sizeof(int);
jp->jp_ctltype = CTLTYPE_INT | CTLFLAG_WR;
return (0);
}
+ if (!strcmp(name, "desc")) {
+ jp->jp_valuelen = sizeof(int);
+ jp->jp_ctltype = CTLTYPE_INT | CTLFLAG_RW;
+ return (0);
+ }
/* Find the sysctl that describes the parameter. */
mib[0] = 0;
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
index b2b7c6ecce56..fed483978e62 100644
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -150,13 +150,14 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p,
kp->ki_cr_flags = 0;
if (ucred.cr_flags & CRED_FLAG_CAPMODE)
kp->ki_cr_flags |= KI_CRF_CAPABILITY_MODE;
- if (ucred.cr_ngroups > KI_NGROUPS) {
+ if (1 + ucred.cr_ngroups > KI_NGROUPS) {
kp->ki_ngroups = KI_NGROUPS;
kp->ki_cr_flags |= KI_CRF_GRP_OVERFLOW;
} else
- kp->ki_ngroups = ucred.cr_ngroups;
- kvm_read(kd, (u_long)ucred.cr_groups, kp->ki_groups,
- kp->ki_ngroups * sizeof(gid_t));
+ kp->ki_ngroups = 1 + ucred.cr_ngroups;
+ kp->ki_groups[0] = ucred.cr_gid;
+ kvm_read(kd, (u_long)ucred.cr_groups, kp->ki_groups + 1,
+ (kp->ki_ngroups - 1) * sizeof(gid_t));
if (ucred.cr_prison != NULL) {
if (KREAD(kd, (u_long)ucred.cr_prison, &pr)) {
_kvm_err(kd, kd->program,
diff --git a/lib/liblzma/Makefile b/lib/liblzma/Makefile
index 27e0521f5884..9c6ece74ffd0 100644
--- a/lib/liblzma/Makefile
+++ b/lib/liblzma/Makefile
@@ -1,4 +1,6 @@
-PACKAGE=lib${LIB}
+PACKAGE= xz
+LIB_PACKAGE=
+
LIB= lzma
LZMADIR= ${SRCTOP}/contrib/xz/src/liblzma
diff --git a/lib/libmagic/Makefile b/lib/libmagic/Makefile
index 150ddc686241..fe04f5ea68c8 100644
--- a/lib/libmagic/Makefile
+++ b/lib/libmagic/Makefile
@@ -11,7 +11,9 @@ SHLIB_MAJOR= 4
.if !make(build-tools)
LIBADD= z
.endif
-MAN= libmagic.3 magic.5
+
+MAN= libmagic.3
+MANNODEV= magic.5
SRCS= apprentice.c apptype.c ascmagic.c buffer.c cdf.c cdf_time.c \
compress.c der.c encoding.c fsmagic.c funcs.c is_json.c \
@@ -73,8 +75,8 @@ magic.mgc: mkmagic
FILEVER!= awk '$$1 == "\#define" && $$2 == "VERSION" { print $$3; exit }' \
${.CURDIR}/config.h
-CLEANFILES+= ${MAN}
-.for mp in ${MAN}
+CLEANFILES+= ${MAN} ${MANNODEV}
+.for mp in ${MAN} ${MANNODEV}
${mp}: ${mp:C/[0-9]/man/}
sed -e 's/__FSECTION__/5/g' -e 's/__CSECTION__/1/g' \
-e 's/__VERSION__/${FILEVER}/g' \
diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile
index 547a134fc440..c4ab767c8b2f 100644
--- a/lib/libmd/Makefile
+++ b/lib/libmd/Makefile
@@ -108,7 +108,7 @@ CFLAGS+= -DWEAK_REFS
CFLAGS.skein_block.c+= -DSKEIN_LOOP=995
.PATH: ${.CURDIR}/${MACHINE_ARCH} ${SRCTOP}/sys/crypto/sha2
.PATH: ${SRCTOP}/sys/crypto/skein ${SRCTOP}/sys/crypto/skein/${MACHINE_ARCH}
-.PATH: ${SRCTOP}/sys/kern
+.PATH: ${SRCTOP}/sys/crypto
USE_ASM_SOURCES?=1
.if defined(BOOTSTRAPPING) || ${MK_MACHDEP_OPTIMIZATIONS} == no
@@ -117,6 +117,13 @@ USE_ASM_SOURCES:=0
.endif
.if ${USE_ASM_SOURCES} != 0
+.if exists(${MACHINE_ARCH}/md5block.S)
+SRCS+= md5block.S
+CFLAGS+= -DMD5_ASM
+.if exists(${MACHINE_ARCH}/md5dispatch.c)
+SRCS+= md5dispatch.c
+.endif
+.endif
.if exists(${MACHINE_ARCH}/sha1block.S)
SRCS+= sha1block.S
CFLAGS+= -DSHA1_ASM
diff --git a/lib/libmd/aarch64/md5block.S b/lib/libmd/aarch64/md5block.S
new file mode 100644
index 000000000000..b928c8dd795a
--- /dev/null
+++ b/lib/libmd/aarch64/md5block.S
@@ -0,0 +1,206 @@
+/*-
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/elf_common.h>
+#include <machine/asm.h>
+
+# optimal instruction sequence for k = \key + \m
+.macro addkm key, m
+.if 0x100000000 - \key > 0x00ffffff
+ movz k, #\key & 0xffff
+ movk k, #\key >> 16, lsl #16
+ add k, k, \m
+.elseif 0x100000000 - \key > 0x0000ffff
+ sub k, \m, #(0x100000000 - \key) & 0xfff000
+ sub k, k, #(0x100000000 - \key) & 0xfff
+.else
+ movz k, #0x100000000 - \key
+ sub k, \m, k
+.endif
+.endm
+
+.macro round a, b, c, d, f, key, m, s
+ \f f, \b, \c, \d
+ addkm \key, \m // k[i] + m[g]
+ add \a, \a, k // k[i] + m[g] + a
+ add \a, \a, f // k[i] + m[g] + a + f
+ ror \a, \a, #32-\s
+ add \a, \a, \b
+.endm
+
+ /* f = b ? c : d */
+.macro f0 f, b, c, d
+ eor \f, \c, \d
+ and \f, \f, \b
+ eor \f, \f, \d
+.endm
+
+ /*
+ * special cased round 1 function
+ * f1 = d ? b : c = (d & b) + (~d & c)
+ */
+.macro round1 a, b, c, d, key, m, s
+ bic tmp, \c, \d // ~d & c
+ addkm \key, \m // k[i] + m[g]
+ add \a, \a, k // k[i] + m[g] + a
+ and f, \b, \d // d & b
+ add \a, \a, tmp // k[i] + m[g] + a + (~d & c)
+ add \a, \a, f // k[i] + m[g] + a + (~d & c) + (d & b)
+ ror \a, \a, #32-\s
+ add \a, \a, \b
+.endm
+
+ /* f = b ^ c ^ d */
+.macro f2 f, b, c, d
+ eor \f, \c, \d
+ eor \f, \f, \b
+.endm
+
+ /* f = c ^ (b | ~d) */
+.macro f3 f, b, c, d
+ orn \f, \b, \d
+ eor \f, \f, \c
+.endm
+
+ /* do 4 rounds */
+.macro rounds f, m0, m1, m2, m3, s0, s1, s2, s3, k0, k1, k2, k3
+ round a, b, c, d, \f, \k0, \m0, \s0
+ round d, a, b, c, \f, \k1, \m1, \s1
+ round c, d, a, b, \f, \k2, \m2, \s2
+ round b, c, d, a, \f, \k3, \m3, \s3
+.endm
+
+ /* do 4 rounds with f0, f1, f2, f3 */
+.macro rounds0 m0, m1, m2, m3, k0, k1, k2, k3
+ rounds f0, \m0, \m1, \m2, \m3, 7, 12, 17, 22, \k0, \k1, \k2, \k3
+.endm
+
+.macro rounds1 m0, m1, m2, m3, k0, k1, k2, k3
+ round1 a, b, c, d, \k0, \m0, 5
+ round1 d, a, b, c, \k1, \m1, 9
+ round1 c, d, a, b, \k2, \m2, 14
+ round1 b, c, d, a, \k3, \m3, 20
+.endm
+
+.macro rounds2 m0, m1, m2, m3, k0, k1, k2, k3
+ rounds f2, \m0, \m1, \m2, \m3, 4, 11, 16, 23, \k0, \k1, \k2, \k3
+.endm
+
+.macro rounds3 m0, m1, m2, m3, k0, k1, k2, k3
+ rounds f3, \m0, \m1, \m2, \m3, 6, 10, 15, 21, \k0, \k1, \k2, \k3
+.endm
+
+ /* md5block(MD5_CTX, buf, len) */
+ENTRY(_libmd_md5block)
+ctx .req x0
+buf .req x1
+len .req x2
+end .req x2 // aliases len
+a .req w3
+b .req w4
+c .req w5
+d .req w6
+f .req w7
+tmp .req w8
+k .req w9
+m0 .req w10
+m1 .req w11
+m2 .req w12
+m3 .req w13
+m4 .req w14
+m5 .req w15
+m6 .req w16
+m7 .req w17
+ // x18 is the platform register
+m8 .req w19
+m9 .req w20
+m10 .req w21
+m11 .req w22
+m12 .req w23
+m13 .req w24
+m14 .req w25
+m15 .req w26
+
+a_ .req m0
+b_ .req m7
+c_ .req m14
+d_ .req m5
+
+ stp x19, x20, [sp, #-0x40]!
+ stp x21, x22, [sp, #0x10]
+ stp x23, x24, [sp, #0x20]
+ stp x25, x26, [sp, #0x30]
+
+ bics len, len, #63 // length in blocks
+ add end, buf, len // end pointer
+
+ beq .Lend // was len == 0 after BICS?
+
+ ldp a, b, [ctx, #0]
+ ldp c, d, [ctx, #8]
+
+ /* first eight rounds interleaved with data loads */
+.Lloop: ldp m0, m1, [buf, #0]
+ round a, b, c, d, f0, 0xd76aa478, m0, 7
+ ldp m2, m3, [buf, #8]
+ round d, a, b, c, f0, 0xe8c7b756, m1, 12
+ ldp m4, m5, [buf, #16]
+ round c, d, a, b, f0, 0x242070db, m2, 17
+ ldp m6, m7, [buf, #24]
+ round b, c, d, a, f0, 0xc1bdceee, m3, 22
+
+ ldp m8, m9, [buf, #32]
+ round a, b, c, d, f0, 0xf57c0faf, m4, 7
+ ldp m10, m11, [buf, #40]
+ round d, a, b, c, f0, 0x4787c62a, m5, 12
+ ldp m12, m13, [buf, #48]
+ round c, d, a, b, f0, 0xa8304613, m6, 17
+ ldp m14, m15, [buf, #56]
+ round b, c, d, a, f0, 0xfd469501, m7, 22
+
+ /* remaining rounds use the roundsX macros */
+ rounds0 m8, m9, m10, m11, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be
+ rounds0 m12, m13, m14, m15, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821
+
+ rounds1 m1, m6, m11, m0, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa
+ rounds1 m5, m10, m15, m4, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8
+ rounds1 m9, m14, m3, m8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed
+ rounds1 m13, m2, m7, m12, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a
+
+ rounds2 m5, m8, m11, m14, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c
+ rounds2 m1, m4, m7, m10, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70
+ rounds2 m13, m0, m3, m6, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05
+ rounds2 m9, m12, m15, m2, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665
+
+ rounds3 m0, m7, m14, m5, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039
+ rounds3 m12, m3, m10, m1, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1
+ rounds3 m8, m15, m6, m13, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1
+ rounds3 m4, m11, m2, m9, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
+
+ ldp a_, b_, [ctx, #0]
+ ldp c_, d_, [ctx, #8]
+ add a, a, a_
+ add b, b, b_
+ add c, c, c_
+ add d, d, d_
+ stp a, b, [ctx, #0]
+ stp c, d, [ctx, #8]
+
+ add buf, buf, #64
+ cmp buf, end
+ bne .Lloop
+
+.Lend: ldp x25, x26, [sp, #0x30]
+ ldp x23, x24, [sp, #0x20]
+ ldp x21, x22, [sp, #0x10]
+ ldp x19, x20, [sp], #0x40
+
+ ret
+END(_libmd_md5block)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/libmd/aarch64/sha1block.S b/lib/libmd/aarch64/sha1block.S
index 56a0297efadd..e16fb36342fd 100644
--- a/lib/libmd/aarch64/sha1block.S
+++ b/lib/libmd/aarch64/sha1block.S
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2024 Robert Clausecker <fuz@freebsd.org>
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
diff --git a/lib/libmd/aarch64/sha1dispatch.c b/lib/libmd/aarch64/sha1dispatch.c
index e34bf0a1a344..045527044320 100644
--- a/lib/libmd/aarch64/sha1dispatch.c
+++ b/lib/libmd/aarch64/sha1dispatch.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2024 Robert Clausecker <fuz@freebsd.org>
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
diff --git a/lib/libmd/amd64/md5block.S b/lib/libmd/amd64/md5block.S
new file mode 100644
index 000000000000..0dd594dd5dc2
--- /dev/null
+++ b/lib/libmd/amd64/md5block.S
@@ -0,0 +1,363 @@
+/*-
+ * Copyright (c) 2024, 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <machine/asm.h>
+
+/* apply the round keys to the four round functions */
+.macro allrounds rfn0, rfn1, rfn2, rfn3
+ \rfn0 0, 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee
+ \rfn0 4, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501
+ \rfn0 8, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be
+ \rfn0 12, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821
+
+ \rfn1 16, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa
+ \rfn1 20, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8
+ \rfn1 24, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed
+ \rfn1 28, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a
+
+ \rfn2 32, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c
+ \rfn2 36, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70
+ \rfn2 40, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05
+ \rfn2 44, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665
+
+ \rfn3 48, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039
+ \rfn3 52, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1
+ \rfn3 56, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1
+ \rfn3 60, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
+.endm
+
+ // md5block(MD5_CTX, buf, len)
+ENTRY(_libmd_md5block_baseline)
+.macro round a, b, c, d, f, k, m, s
+ \f %ebp, \b, \c, \d
+ add $\k, \a // a + k[i]
+ add ((\m)%16*4)(%rsi), \a // a + k[i] + m[g]
+ add %ebp, \a // a + k[i] + m[g] + f
+ rol $\s, \a
+ add \b, \a
+.endm
+
+ // f = b ? c : d
+.macro f0 f, b, c, d
+ mov \c, \f
+ xor \d, \f
+ and \b, \f
+ xor \d, \f
+.endm
+
+ // f = d ? b : c
+.macro f1 f, b, c, d
+ mov \c, \f
+ xor \b, \f
+ and \d, \f
+ xor \c, \f
+.endm
+
+ // f = b ^ c ^ d
+.macro f2 f, b, c, d
+ mov \c, \f
+ xor \d, \f
+ xor \b, \f
+.endm
+
+ // f = c ^ (b | ~d)
+.macro f3 f, b, c, d
+ mov $-1, \f
+ xor \d, \f
+ or \b, \f
+ xor \c, \f
+.endm
+
+ // do 4 rounds
+.macro rounds f, p, q, s0, s1, s2, s3, k0, k1, k2, k3
+ round %eax, %ebx, %ecx, %edx, \f, \k0, \p*0+\q, \s0
+ round %edx, %eax, %ebx, %ecx, \f, \k1, \p*1+\q, \s1
+ round %ecx, %edx, %eax, %ebx, \f, \k2, \p*2+\q, \s2
+ round %ebx, %ecx, %edx, %eax, \f, \k3, \p*3+\q, \s3
+.endm
+
+ // do 4 rounds with f0, f1, f2, f3
+.macro rounds0 i, k0, k1, k2, k3
+ rounds f0, 1, \i, 7, 12, 17, 22, \k0, \k1, \k2, \k3
+.endm
+
+.macro rounds1 i, k0, k1, k2, k3
+ rounds f1, 5, 5*\i+1, 5, 9, 14, 20, \k0, \k1, \k2, \k3
+.endm
+
+.macro rounds2 i, k0, k1, k2, k3
+ rounds f2, 3, 3*\i+5, 4, 11, 16, 23, \k0, \k1, \k2, \k3
+.endm
+
+.macro rounds3 i, k0, k1, k2, k3
+ rounds f3, 7, 7*\i, 6, 10, 15, 21, \k0, \k1, \k2, \k3
+.endm
+
+ push %rbx
+ push %rbp
+ push %r12
+
+ and $~63, %rdx // length in blocks
+ lea (%rsi, %rdx, 1), %r12 // end pointer
+
+ mov (%rdi), %eax // a
+ mov 4(%rdi), %ebx // b
+ mov 8(%rdi), %ecx // c
+ mov 12(%rdi), %edx // d
+
+ cmp %rsi, %r12 // any data to process?
+ je .Lend
+
+ .balign 16
+.Lloop: mov %eax, %r8d
+ mov %ebx, %r9d
+ mov %ecx, %r10d
+ mov %edx, %r11d
+
+ allrounds rounds0, rounds1, rounds2, rounds3
+
+ add %r8d, %eax
+ add %r9d, %ebx
+ add %r10d, %ecx
+ add %r11d, %edx
+
+ add $64, %rsi
+ cmp %rsi, %r12
+ jne .Lloop
+
+ mov %eax, (%rdi)
+ mov %ebx, 4(%rdi)
+ mov %ecx, 8(%rdi)
+ mov %edx, 12(%rdi)
+
+.Lend: pop %r12
+ pop %rbp
+ pop %rbx
+ ret
+END(_libmd_md5block_baseline)
+
+ /*
+ * An implementation leveraging the ANDN instruction
+ * from BMI1 to shorten some dependency chains.
+ */
+ENTRY(_libmd_md5block_bmi1)
+ // special-cased round 1
+ // f1 = d ? b : c = (d & b) + (~d & c)
+.macro round1 a, b, c, d, k, m, s
+ andn \c, \d, %edi // ~d & c
+ add $\k, \a // a + k[i]
+ mov \d, %ebp
+ add ((\m)%16*4)(%rsi), \a // a + k[i] + m[g]
+ and \b, %ebp // d & b
+ add %edi, \a // a + k[i] + m[g] + (~d & c)
+ add %ebp, \a // a + k[i] + m[g] + (~d & c) + (d & b)
+ rol $\s, \a
+ add \b, \a
+.endm
+
+ // special-cased round 3
+ // f3 = c ^ (b | ~d) = ~(c ^ ~b & d) = -1 - (c ^ ~b & d)
+.macro round3 a, b, c, d, k, m, s
+ andn \d, \b, %ebp
+ add $\k - 1, \a // a + k[i] - 1
+ add ((\m)%16*4)(%rsi), \a // a + k[i] + m[g]
+ xor \c, %ebp
+ sub %ebp, \a // a + k[i] + m[g] + f
+ rol $\s, \a
+ add \b, \a
+.endm
+
+ .purgem rounds1
+.macro rounds1 i, k0, k1, k2, k3
+ round1 %eax, %ebx, %ecx, %edx, \k0, 5*\i+ 1, 5
+ round1 %edx, %eax, %ebx, %ecx, \k1, 5*\i+ 6, 9
+ round1 %ecx, %edx, %eax, %ebx, \k2, 5*\i+11, 14
+ round1 %ebx, %ecx, %edx, %eax, \k3, 5*\i+16, 20
+.endm
+
+ .purgem rounds3
+.macro rounds3 i, k0, k1, k2, k3
+ round3 %eax, %ebx, %ecx, %edx, \k0, 7*\i+ 0, 6
+ round3 %edx, %eax, %ebx, %ecx, \k1, 7*\i+ 7, 10
+ round3 %ecx, %edx, %eax, %ebx, \k2, 7*\i+14, 15
+ round3 %ebx, %ecx, %edx, %eax, \k3, 7*\i+21, 21
+.endm
+
+ push %rbx
+ push %rbp
+ push %r12
+
+ and $~63, %rdx // length in blocks
+ lea (%rsi, %rdx, 1), %r12 // end pointer
+
+ mov (%rdi), %eax // a
+ mov 4(%rdi), %ebx // b
+ mov 8(%rdi), %ecx // c
+ mov 12(%rdi), %edx // d
+
+ cmp %rsi, %r12 // any data to process?
+ je 0f
+
+ push %rdi
+
+ .balign 16
+1: mov %eax, %r8d
+ mov %ebx, %r9d
+ mov %ecx, %r10d
+ mov %edx, %r11d
+
+ allrounds rounds0, rounds1, rounds2, rounds3
+
+ add %r8d, %eax
+ add %r9d, %ebx
+ add %r10d, %ecx
+ add %r11d, %edx
+
+ add $64, %rsi
+ cmp %rsi, %r12
+ jne 1b
+
+ pop %rdi
+ mov %eax, (%rdi)
+ mov %ebx, 4(%rdi)
+ mov %ecx, 8(%rdi)
+ mov %edx, 12(%rdi)
+
+0: pop %r12
+ pop %rbp
+ pop %rbx
+ ret
+END(_libmd_md5block_bmi1)
+
+#ifndef _KERNEL
+ /*
+ * An implementation leveraging AVX-512 for its VPTERNLOGD
+ * instruction. We're using only XMM registers here,
+ * avoiding costly thermal licensing.
+ */
+ENTRY(_libmd_md5block_avx512)
+.macro vround a, b, c, d, f, i, m, mi, s
+ vmovdqa \b, %xmm4
+ vpternlogd $\f, \d, \c, %xmm4
+ vpaddd 4*(\i)(%rax){1to4}, \m, %xmm5 // m[g] + k[i]
+.if \mi != 0
+ vpshufd $0x55 * \mi, %xmm5, %xmm5 // broadcast to each dword
+.endif
+ vpaddd %xmm5, \a, \a // a + k[i] + m[g]
+ vpaddd %xmm4, \a, \a // a + k[i] + m[g] + f
+ vprold $\s, \a, \a
+ vpaddd \b, \a, \a
+.endm
+
+.macro vrounds f, i, m0, i0, m1, i1, m2, i2, m3, i3, s0, s1, s2, s3
+ vround %xmm0, %xmm1, %xmm2, %xmm3, \f, \i+0, \m0, \i0, \s0
+ vround %xmm3, %xmm0, %xmm1, %xmm2, \f, \i+1, \m1, \i1, \s1
+ vround %xmm2, %xmm3, %xmm0, %xmm1, \f, \i+2, \m2, \i2, \s2
+ vround %xmm1, %xmm2, %xmm3, %xmm0, \f, \i+3, \m3, \i3, \s3
+.endm
+
+/*
+ * d c b f0 f1 f2 f3
+ * 0 0 0 0 0 0 1
+ * 1 0 0 1 0 1 0
+ * 0 1 0 0 1 1 0
+ * 1 1 0 1 0 0 1
+ * 0 0 1 0 0 1 1
+ * 1 0 1 0 1 0 1
+ * 0 1 1 1 1 0 0
+ * 1 1 1 1 1 1 0
+ */
+
+.macro vrounds0 i, m
+ vrounds 0xca, \i, \m, 0, \m, 1, \m, 2, \m, 3, 7, 12, 17, 22
+.endm
+
+.macro vrounds1 i, m0, i0, m1, i1, m2, i2, m3, i3
+ vrounds 0xe4, \i, \m0, \i0, \m1, \i1, \m2, \i2, \m3, \i3, 5, 9, 14, 20
+.endm
+
+.macro vrounds2 i, m0, i0, m1, i1, m2, i2, m3, i3
+ vrounds 0x96, \i, \m0, \i0, \m1, \i1, \m2, \i2, \m3, \i3, 4, 11, 16, 23
+.endm
+
+.macro vrounds3 i, m0, i0, m1, i1, m2, i2, m3, i3
+ vrounds 0x39, \i, \m0, \i0, \m1, \i1, \m2, \i2, \m3, \i3, 6, 10, 15, 21
+.endm
+
+ and $~63, %rdx // length in blocks
+ add %rsi, %rdx // end pointer
+
+ vmovd (%rdi), %xmm0 // a
+ vmovd 4(%rdi), %xmm1 // b
+ vmovd 8(%rdi), %xmm2 // c
+ vmovd 12(%rdi), %xmm3 // d
+
+ lea keys(%rip), %rax
+
+ cmp %rsi, %rdx // any data to process?
+ je 0f
+
+ .balign 16
+1: vmovdqu 0*4(%rsi), %xmm8 // message words
+ vmovdqu 4*4(%rsi), %xmm9
+ vmovdqu 8*4(%rsi), %xmm10
+ vmovdqu 12*4(%rsi), %xmm11
+
+ vmovdqa %xmm0, %xmm12 // stash old state variables
+ vmovdqa %xmm1, %xmm13
+ vmovdqa %xmm2, %xmm14
+ vmovdqa %xmm3, %xmm15
+
+ vrounds0 0, %xmm8
+ vrounds0 4, %xmm9
+ vrounds0 8, %xmm10
+ vrounds0 12, %xmm11
+
+ vrounds1 16, %xmm8, 1, %xmm9, 2, %xmm10, 3, %xmm8, 0
+ vrounds1 20, %xmm9, 1, %xmm10, 2, %xmm11, 3, %xmm9, 0
+ vrounds1 24, %xmm10, 1, %xmm11, 2, %xmm8, 3, %xmm10, 0
+ vrounds1 28, %xmm11, 1, %xmm8, 2, %xmm9, 3, %xmm11, 0
+
+ vrounds2 32, %xmm9, 1, %xmm10, 0, %xmm10, 3, %xmm11, 2
+ vrounds2 36, %xmm8, 1, %xmm9, 0, %xmm9, 3, %xmm10, 2
+ vrounds2 40, %xmm11, 1, %xmm8, 0, %xmm8, 3, %xmm9, 2
+ vrounds2 44 %xmm10, 1, %xmm11, 0, %xmm11, 3, %xmm8, 2
+
+ vrounds3 48, %xmm8, 0, %xmm9, 3, %xmm11, 2, %xmm9, 1
+ vrounds3 52, %xmm11, 0, %xmm8, 3, %xmm10, 2, %xmm8, 1
+ vrounds3 56, %xmm10, 0, %xmm11, 3, %xmm9, 2, %xmm11, 1
+ vrounds3 60, %xmm9, 0, %xmm10, 3, %xmm8, 2, %xmm10, 1
+
+ vpaddd %xmm12, %xmm0, %xmm0
+ vpaddd %xmm13, %xmm1, %xmm1
+ vpaddd %xmm14, %xmm2, %xmm2
+ vpaddd %xmm15, %xmm3, %xmm3
+
+ add $64, %rsi
+ cmp %rsi, %rdx
+ jne 1b
+
+ vmovd %xmm0, (%rdi)
+ vmovd %xmm1, 4(%rdi)
+ vmovd %xmm2, 8(%rdi)
+ vmovd %xmm3, 12(%rdi)
+
+0: ret
+END(_libmd_md5block_avx512)
+
+ // round keys, for use in md5block_avx512
+ .section .rodata
+ .balign 16
+
+.macro putkeys i, a, b, c, d
+ .4byte \a, \b, \c, \d
+.endm
+
+keys: allrounds putkeys, putkeys, putkeys, putkeys
+ .size keys, .-keys
+#endif /* !defined(_KERNEL) */
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/libmd/amd64/md5dispatch.c b/lib/libmd/amd64/md5dispatch.c
new file mode 100644
index 000000000000..dd2131c5a57c
--- /dev/null
+++ b/lib/libmd/amd64/md5dispatch.c
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/types.h>
+#include <sys/md5.h>
+
+#include <machine/cpufunc.h>
+#include <machine/specialreg.h>
+#include <stdint.h>
+#include <string.h>
+#include <x86/ifunc.h>
+
+extern void _libmd_md5block_baseline(MD5_CTX *, const void *, size_t);
+extern void _libmd_md5block_bmi1(MD5_CTX *, const void *, size_t);
+extern void _libmd_md5block_avx512(MD5_CTX *, const void *, size_t);
+
+DEFINE_UIFUNC(, void, _libmd_md5block, (MD5_CTX *, const void *, size_t))
+{
+ if ((cpu_stdext_feature & (CPUID_STDEXT_AVX512F | CPUID_STDEXT_AVX512VL))
+ == (CPUID_STDEXT_AVX512F | CPUID_STDEXT_AVX512VL)) {
+ u_int regs[4];
+ char cpu_vendor[12];
+
+ do_cpuid(0, regs);
+ ((u_int *)&cpu_vendor)[0] = regs[1];
+ ((u_int *)&cpu_vendor)[1] = regs[3];
+ ((u_int *)&cpu_vendor)[2] = regs[2];
+
+ /* the AVX-512 kernel performs poorly on AMD */
+ if (memcmp(cpu_vendor, AMD_VENDOR_ID, sizeof(cpu_vendor)) != 0)
+ return (_libmd_md5block_avx512);
+ }
+
+ if (cpu_stdext_feature & CPUID_STDEXT_BMI1)
+ return (_libmd_md5block_bmi1);
+ else
+ return (_libmd_md5block_baseline);
+}
diff --git a/lib/libmd/amd64/sha1block.S b/lib/libmd/amd64/sha1block.S
index f1291ef2647a..6ef083178abc 100644
--- a/lib/libmd/amd64/sha1block.S
+++ b/lib/libmd/amd64/sha1block.S
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2013 The Go Authors. All rights reserved.
- * Copyright (c) 2024 Robert Clausecker <fuz@freebsd.org>
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
*
* Adapted from Go's crypto/sha1/sha1block_amd64.s.
*
diff --git a/lib/libmd/amd64/sha1dispatch.c b/lib/libmd/amd64/sha1dispatch.c
index 86509195d56e..c82a60334739 100644
--- a/lib/libmd/amd64/sha1dispatch.c
+++ b/lib/libmd/amd64/sha1dispatch.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2016 The Go Authors. All rights reserved.
- * Copyright (c) 2024 Robert Clausecker <fuz@freebsd.org>
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
*
* Adapted from Go's crypto/sha1/sha1block_amd64.go.
*
diff --git a/lib/libmd/sha1c.c b/lib/libmd/sha1c.c
index 128e0b991742..02132d720dac 100644
--- a/lib/libmd/sha1c.c
+++ b/lib/libmd/sha1c.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2009 The Go Authors. All rights reserved.
- * Copyright (c) 2024 Robert Clausecker <fuz@freebsd.org>
+ * Copyright (c) 2024 Robert Clausecker <fuz@FreeBSD.org>
*
* Adapted from Go's crypto/sha1/sha1.go.
*
diff --git a/lib/libmixer/Makefile b/lib/libmixer/Makefile
index a0bb37a85fb8..49621ad1f188 100644
--- a/lib/libmixer/Makefile
+++ b/lib/libmixer/Makefile
@@ -1,3 +1,5 @@
+PACKAGE= sound
+
LIB= mixer
SRCS= ${LIB}.c
INCS= ${LIB}.h
diff --git a/lib/libopenbsd/Makefile b/lib/libopenbsd/Makefile
index 53bd0200934f..80ae0f90621a 100644
--- a/lib/libopenbsd/Makefile
+++ b/lib/libopenbsd/Makefile
@@ -1,8 +1,12 @@
LIB= openbsd
SRCS= imsg-buffer.c \
imsg.c \
- ohash.c \
- recallocarray.c
+ ohash.c
+.if defined(BOOTSTRAPPING)
+.PATH: ${SRCTOP}/lib/libc/stdlib
+SRCS+= recallocarray.c
+.endif
+
.if !defined(BOOTSTRAPPING)
# Skip getdtablecount.c when bootstrapping since it doesn't compile for Linux
# and is not used by any of the bootstrap tools
diff --git a/lib/libpam/Makefile.inc b/lib/libpam/Makefile.inc
index bec0687d1b7f..28630e46b949 100644
--- a/lib/libpam/Makefile.inc
+++ b/lib/libpam/Makefile.inc
@@ -23,6 +23,8 @@
# SUCH DAMAGE.
#
+PACKAGE?= pam
+
CFLAGS+= -DOPENPAM_DEBUG
SHLIB_MAJOR= 6
diff --git a/lib/libpam/libpam/Makefile b/lib/libpam/libpam/Makefile
index dd19eba5c1ec..f220063971d7 100644
--- a/lib/libpam/libpam/Makefile
+++ b/lib/libpam/libpam/Makefile
@@ -42,7 +42,7 @@ OPENPAM= ${SRCTOP}/contrib/openpam
SHLIB= pam
.endif
-PACKAGE= runtime
+LIB_PACKAGE=
SRCS= openpam_asprintf.c \
openpam_borrow_cred.c \
@@ -148,10 +148,10 @@ MAN?= openpam.3 \
pam_strerror.3 \
pam_verror.3 \
pam_vinfo.3 \
- pam_vprompt.3 \
- pam.conf.5
+ pam_vprompt.3
-MLINKS?= pam.conf.5 pam.d.5
+MANNODEV?= pam.conf.5
+MANNODEVLINKS?= pam.conf.5 pam.d.5
CFLAGS+= -DLOCALBASE=\"${LOCALBASE:U/usr/local}\"
CFLAGS+= -I${OPENPAM}/include
diff --git a/lib/libpam/modules/modules.inc b/lib/libpam/modules/modules.inc
index f3ab65333f4f..1e9eb8970317 100644
--- a/lib/libpam/modules/modules.inc
+++ b/lib/libpam/modules/modules.inc
@@ -30,4 +30,4 @@ MODULES += pam_ssh
.endif
MODULES += pam_tacplus
MODULES += pam_unix
-MODULES += pam_xdg \ No newline at end of file
+MODULES += pam_xdg
diff --git a/lib/libpam/modules/pam_chroot/Makefile b/lib/libpam/modules/pam_chroot/Makefile
index 206f8fa40a09..fcec5bd04473 100644
--- a/lib/libpam/modules/pam_chroot/Makefile
+++ b/lib/libpam/modules/pam_chroot/Makefile
@@ -1,5 +1,5 @@
LIB= pam_chroot
SRCS= pam_chroot.c
-MAN= pam_chroot.8
+MANNODEV= pam_chroot.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_deny/Makefile b/lib/libpam/modules/pam_deny/Makefile
index 862d1859d0d6..8ff2bfcee869 100644
--- a/lib/libpam/modules/pam_deny/Makefile
+++ b/lib/libpam/modules/pam_deny/Makefile
@@ -23,8 +23,8 @@
# SUCH DAMAGE.
#
-LIB= pam_deny
-SRCS= pam_deny.c
-MAN= pam_deny.8
+LIB= pam_deny
+SRCS= pam_deny.c
+MANNODEV= pam_deny.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_echo/Makefile b/lib/libpam/modules/pam_echo/Makefile
index 532d0a51b58e..9ea51b392e31 100644
--- a/lib/libpam/modules/pam_echo/Makefile
+++ b/lib/libpam/modules/pam_echo/Makefile
@@ -1,5 +1,5 @@
-LIB= pam_echo
-SRCS= pam_echo.c
-MAN= pam_echo.8
+LIB= pam_echo
+SRCS= pam_echo.c
+MANNODEV= pam_echo.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_exec/Makefile b/lib/libpam/modules/pam_exec/Makefile
index c2327a2860cd..a3e9948ab69b 100644
--- a/lib/libpam/modules/pam_exec/Makefile
+++ b/lib/libpam/modules/pam_exec/Makefile
@@ -1,6 +1,6 @@
-LIB= pam_exec
-SRCS= pam_exec.c
-MAN= pam_exec.8
+LIB= pam_exec
+SRCS= pam_exec.c
+MANNODEV= pam_exec.8
WARNS?= 1
diff --git a/lib/libpam/modules/pam_ftpusers/Makefile b/lib/libpam/modules/pam_ftpusers/Makefile
index 07d37c8b17a8..e2326312426d 100644
--- a/lib/libpam/modules/pam_ftpusers/Makefile
+++ b/lib/libpam/modules/pam_ftpusers/Makefile
@@ -1,5 +1,5 @@
-LIB= pam_ftpusers
-SRCS= pam_ftpusers.c
-MAN= pam_ftpusers.8
+LIB= pam_ftpusers
+SRCS= pam_ftpusers.c
+MANNODEV= pam_ftpusers.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_group/Makefile b/lib/libpam/modules/pam_group/Makefile
index 0395b3a8f355..cbf902026d66 100644
--- a/lib/libpam/modules/pam_group/Makefile
+++ b/lib/libpam/modules/pam_group/Makefile
@@ -1,5 +1,5 @@
LIB= pam_group
SRCS= pam_group.c
-MAN= pam_group.8
+MANNODEV= pam_group.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_guest/Makefile b/lib/libpam/modules/pam_guest/Makefile
index 7128b513afbc..04eb249e4a79 100644
--- a/lib/libpam/modules/pam_guest/Makefile
+++ b/lib/libpam/modules/pam_guest/Makefile
@@ -1,5 +1,5 @@
LIB= pam_guest
SRCS= pam_guest.c
-MAN= pam_guest.8
+MANNODEV= pam_guest.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_krb5/Makefile b/lib/libpam/modules/pam_krb5/Makefile
index 7634930a7202..d55f2d0b5971 100644
--- a/lib/libpam/modules/pam_krb5/Makefile
+++ b/lib/libpam/modules/pam_krb5/Makefile
@@ -30,6 +30,7 @@ SRCDIR= ${SRCTOP}/contrib/pam-krb5
.PATH: ${SRCDIR}/module \
${SRCDIR}/portable \
${SRCDIR}/pam-util \
+ ${SRCDIR}/docs \
${SRCDIR}
PACKAGE= kerberos
@@ -57,8 +58,8 @@ SRCS= account.c \
support.c \
vector.c
-MAN= pam-krb5.8
-MLINKS= pam-krb5.8 pam_krb5.8
+MANNODEV= pam_krb5.8
+MANSRC.pam_krb5.8=pam-krb5.8
CFLAGS= -I${SRCDIR} \
-I${.CURDIR} \
@@ -74,12 +75,19 @@ pam-util_options.c: .PHONY
module_options.c: .PHONY
cp ${SRCDIR}/module/options.c module_options.c
+
+.ifdef VENDOR_IMPORT
+# Regenerate the manual page from the pod source after vendor import
+pam-krb5.8: pam_krb5.pod
+ sed -e 's/pam(7)/pam.conf(5)/' <${.ALLSRC} | \
+ pod2mdoc -n pam_krb5 -s 8 >${.CURDIR}/${.TARGET}
+.endif
.else
PACKAGE= kerberos
-LIB= pam_krb5
-SRCS= pam_krb5.c
-MAN= pam_krb5.8
+LIB= pam_krb5
+SRCS= pam_krb5.c
+MANNODEV= pam_krb5.8
.if defined(_FREEFALL_CONFIG)
CFLAGS+=-D_FREEFALL_CONFIG
WARNS?= 3
diff --git a/lib/libpam/modules/pam_krb5/pam-krb5.8 b/lib/libpam/modules/pam_krb5/pam-krb5.8
index 3413748c7850..ad4fa5c422c4 100644
--- a/lib/libpam/modules/pam_krb5/pam-krb5.8
+++ b/lib/libpam/modules/pam_krb5/pam-krb5.8
@@ -1,1025 +1,1356 @@
-.\" -*- mode: troff; coding: utf-8 -*-
-.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
-.ie n \{\
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds C`
-. ds C'
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is >0, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.\"
-.\" Avoid warning from groff about undefined register 'F'.
-.de IX
-..
-.nr rF 0
-.if \n(.g .if rF .nr rF 1
-.if (\n(rF:(\n(.g==0)) \{\
-. if \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. if !\nF==2 \{\
-. nr % 0
-. nr F 2
-. \}
-. \}
-.\}
-.rr rF
-.\" ========================================================================
-.\"
-.IX Title "PAM_KRB5 1"
-.TH PAM_KRB5 1 2025-06-05 "perl v5.40.2" "User Contributed Perl Documentation"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH NAME
-pam_krb5 \- Kerberos PAM module
-.SH SYNOPSIS
-.IX Header "SYNOPSIS"
-.Vb 4
-\& auth sufficient pam_krb5.so minimum_uid=1000
-\& session required pam_krb5.so minimum_uid=1000
-\& account required pam_krb5.so minimum_uid=1000
-\& password sufficient pam_krb5.so minimum_uid=1000
-.Ve
-.SH DESCRIPTION
-.IX Header "DESCRIPTION"
+.Dd November 21, 2025
+.Dt PAM_KRB5 8
+.Os
+.Sh NAME
+.Nm pam_krb5
+.Nd Kerberos PAM module
+.Sh SYNOPSIS
+.Bd -literal
+ auth sufficient pam_krb5.so minimum_uid=1000
+ session required pam_krb5.so minimum_uid=1000
+ account required pam_krb5.so minimum_uid=1000
+ password sufficient pam_krb5.so minimum_uid=1000
+.Ed
+.Sh DESCRIPTION
The Kerberos service module for PAM, typically installed at
-\&\fI/lib/security/pam_krb5.so\fR, provides functionality for the four PAM
-operations: authentication, account management, session management, and
-password management. \fIpam_krb5.so\fR is a shared object that is
-dynamically loaded by the PAM subsystem as necessary, based on the system
-PAM configuration. PAM is a system for plugging in external
-authentication and session management modules so that each application
-doesn't have to know the best way to check user authentication or create a
-user session on that system. For details on how to configure PAM on your
-system, see the PAM man page, often \fBpam\fR\|(7).
-.PP
+.Pa /lib/security/pam_krb5.so ,
+provides functionality for the four PAM operations: authentication,
+account management, session management, and password management.
+.Pa pam_krb5.so
+is a shared object that is dynamically loaded by the PAM subsystem as
+necessary, based on the system PAM configuration.
+PAM is a system for plugging in external authentication and session
+management modules so that each application doesn't have to know the
+best way to check user authentication or create a user session on that
+system.
+For details on how to configure PAM on your system, see the PAM man
+page, often pam.conf(5).
+.Pp
Here are the actions of this module when called from each group:
-.IP auth 4
-.IX Item "auth"
-Provides implementations of \fBpam_authenticate()\fR and \fBpam_setcred()\fR. The
-former takes the username from the PAM session, prompts for the user's
-password (unless configured to use an already-entered password), and then
-performs a Kerberos initial authentication, storing the obtained
-credentials (if successful) in a temporary ticket cache. The latter,
-depending on the flags it is called with, either takes the contents of the
-temporary ticket cache and writes it out to a persistent ticket cache
-owned by the user or uses the temporary ticket cache to refresh an
-existing user ticket cache.
-.Sp
+.Bl -tag -width Ds
+.It auth
+Provides implementations of
+.Xr pam_authenticate 3
+and
+.Xr pam_setcred 3 .
+The former takes the username from the PAM session, prompts for the
+user's password (unless configured to use an already-entered password),
+and then performs a Kerberos initial authentication, storing the
+obtained credentials (if successful) in a temporary ticket cache.
+The latter, depending on the flags it is called with, either takes the
+contents of the temporary ticket cache and writes it out to a persistent
+ticket cache owned by the user or uses the temporary ticket cache to
+refresh an existing user ticket cache.
+.Pp
Passwords as long or longer than PAM_MAX_RESP_SIZE octets (normally 512
-octets) will be rejected, since excessively long passwords can be used as
-a denial of service attack.
-.Sp
+octets) will be rejected, since excessively long passwords can be used
+as a denial of service attack.
+.Pp
After doing the initial authentication, the Kerberos PAM module will
attempt to obtain tickets for a key in the local system keytab and then
-verify those tickets. Unless this step is performed, the authentication
-is vulnerable to KDC spoofing, but it requires that the system have a
-local key and that the PAM module be running as a user that can read the
-keytab file (normally \fI/etc/krb5.keytab\fR. You can point the Kerberos PAM
-module at a different keytab with the \fIkeytab\fR option. If that keytab
-cannot be read or if no keys are found in it, the default (potentially
-insecure) behavior is to skip this check. If you want to instead fail
-authentication if the obtained tickets cannot be checked, set
-\&\f(CW\*(C`verify_ap_req_nofail\*(C'\fR to true in the [libdefaults] section of
-\&\fI/etc/krb5.conf\fR. Note that this will affect applications other than
-this PAM module.
-.Sp
+verify those tickets.
+Unless this step is performed, the authentication is vulnerable to KDC
+spoofing, but it requires that the system have a local key and that the
+PAM module be running as a user that can read the keytab file (normally
+.Pa /etc/krb5.keytab .
+You can point the Kerberos PAM module at a different keytab with the
+.Em keytab
+option.
+If that keytab cannot be read or if no keys are found in it, the default
+behavior is to fail authentication.
+If you want to skip this check, set the
+.Qo Li allow_kdc_spoof Qc
+option to true either in the [appdefaults] section of
+.Pa /etc/krb5.conf
+or in the PAM policy.
+.Pp
By default, whenever the user is authenticated, a basic authorization
-check will also be done using \fBkrb5_kuserok()\fR. The default behavior of
-this function is to check the user's account for a \fI.k5login\fR file and,
-if one is present, ensure that the user's principal is listed in that
-file. If \fI.k5login\fR is not present, the default check is to ensure that
-the user's principal is in the default local realm and the user portion of
-the principal matches the account name (this can be changed by configuring
-a custom aname to localname mapping in \fIkrb5.conf\fR; see the Kerberos
-documentation for details). This can be customized with several
-configuration options; see below.
-.Sp
-If the username provided to PAM contains an \f(CW\*(C`@\*(C'\fR and Kerberos can,
-treating the username as a principal, map it to a local account name,
-\&\fBpam_authenticate()\fR will change the PAM user to that local account name.
-This allows users to log in with their Kerberos principal and let Kerberos
-do the mapping to an account. This can be disabled with the
-\&\fIno_update_user\fR option. Be aware, however, that this facility cannot be
-used with OpenSSH. OpenSSH will reject usernames that don't match local
-accounts before this remapping can be done and will pass an invalid
-password to the PAM module. Also be aware that several other common PAM
-modules, such as pam_securetty, expect to be able to look up the user with
-\&\fBgetpwnam()\fR and cannot be called before pam_krb5 when using this feature.
-.Sp
-When \fBpam_setcred()\fR is called to initialize a new ticket cache, the
-environment variable KRB5CCNAME is set to the path to that ticket cache.
-By default, the cache will be named \fI/tmp/krb5cc_UID_RANDOM\fR where UID is
-the user's UID and RANDOM is six randomly-chosen letters. This can be
-configured with the \fIccache\fR and \fIccache_dir\fR options.
-.Sp
-pam\-krb5 does not use the default ticket cache location or
-\&\fIdefault_cc_name\fR in the \f(CW\*(C`[libdefaults]\*(C'\fR section of \fIkrb5.conf\fR. The
-default cache location would share a cache for all sessions of the same
-user, which causes confusing behavior when the user logs out of one of
-multiple sessions.
-.Sp
-If \fBpam_setcred()\fR initializes a new ticket cache, it will also set up that
-ticket cache so that it will be deleted when the PAM session is closed.
-Normally, the calling program (\fBlogin\fR, \fBsshd\fR, etc.) will run the
-user's shell as a sub-process, wait for it to exit, and then close the PAM
-session, thereby cleaning up the user's session.
-.IP session 4
-.IX Item "session"
-Provides implementations of \fBpam_open_session()\fR, which is equivalent to
-calling \fBpam_setcred()\fR with the PAM_ESTABLISH_CRED flag, and
-\&\fBpam_close_session()\fR, which destroys the ticket cache created by
-\&\fBpam_setcred()\fR.
-.IP account 4
-.IX Item "account"
-Provides an implementation of \fBpam_acct_mgmt()\fR. All it does is do the same
-authorization check as performed by the \fBpam_authenticate()\fR implementation
-described above.
-.IP password 4
-.IX Item "password"
-Provides an implementation of \fBpam_chauthtok()\fR, which implements password
-changes. The user is prompted for their existing password (unless
-configured to use an already entered one) and the PAM module then obtains
-credentials for the special Kerberos principal \f(CW\*(C`kadmin/changepw\*(C'\fR. It
-then prompts the user for a new password, twice to ensure that the user
-entered it properly (again, unless configured to use an already entered
-password), and then does a Kerberos password change.
-.Sp
+check will also be done using
+.Xr krb5_kuserok 3 .
+The default behavior of this function is to check the user's account for
+a
+.Pa .k5login
+file and, if one is present, ensure that the user's principal is listed
+in that file.
+If
+.Pa .k5login
+is not present, the default check is to ensure that the user's principal
+is in the default local realm and the user portion of the principal
+matches the account name (this can be changed by configuring a custom
+aname to localname mapping in
+.Pa krb5.conf ;
+see the Kerberos documentation for details).
+This can be customized with several configuration options; see below.
+.Pp
+If the username provided to PAM contains an
+.Qo Li @ Qc
+and Kerberos can, treating the username as a principal, map it to a
+local account name,
+.Xr pam_authenticate 3
+will change the PAM user to that local account name.
+This allows users to log in with their Kerberos principal and let
+Kerberos do the mapping to an account.
+This can be disabled with the
+.Em no_update_user
+option.
+Be aware, however, that this facility cannot be used with OpenSSH.
+OpenSSH will reject usernames that don't match local accounts before
+this remapping can be done and will pass an invalid password to the PAM
+module.
+Also be aware that several other common PAM modules, such as
+pam_securetty, expect to be able to look up the user with
+.Xr getpwnam 3
+and cannot be called before pam_krb5 when using this feature.
+.Pp
+When
+.Xr pam_setcred 3
+is called to initialize a new ticket cache, the environment variable
+KRB5CCNAME is set to the path to that ticket cache.
+By default, the cache will be named
+.Pa /tmp/krb5cc_UID_RANDOM
+where UID is the user's UID and RANDOM is six randomly-chosen letters.
+This can be configured with the
+.Em ccache
+and
+.Em ccache_dir
+options.
+.Pp
+pam-krb5 does not use the default ticket cache location or
+.Em default_cc_name
+in the
+.Qo Li [libdefaults] Qc
+section of
+.Pa krb5.conf .
+The default cache location would share a cache for all sessions of the
+same user, which causes confusing behavior when the user logs out of one
+of multiple sessions.
+.Pp
+If
+.Xr pam_setcred 3
+initializes a new ticket cache, it will also set up that ticket cache so
+that it will be deleted when the PAM session is closed.
+Normally, the calling program
+.Pf ( Sy login ,
+.Sy sshd ,
+etc.)
+will run the user's shell as a sub-process, wait for it to exit, and
+then close the PAM session, thereby cleaning up the user's session.
+.It session
+Provides implementations of
+.Xr pam_open_session 3 ,
+which is equivalent to calling
+.Xr pam_setcred 3
+with the PAM_ESTABLISH_CRED flag, and
+.Xr pam_close_session 3 ,
+which destroys the ticket cache created by
+.Xr pam_setcred 3 .
+.It account
+Provides an implementation of
+.Xr pam_acct_mgmt 3 .
+All it does is do the same authorization check as performed by the
+.Xr pam_authenticate 3
+implementation described above.
+.It password
+Provides an implementation of
+.Xr pam_chauthtok 3 ,
+which implements password changes.
+The user is prompted for their existing password (unless configured to
+use an already entered one) and the PAM module then obtains credentials
+for the special Kerberos principal
+.Qo Li kadmin/changepw Qc .
+It then prompts the user for a new password, twice to ensure that the
+user entered it properly (again, unless configured to use an already
+entered password), and then does a Kerberos password change.
+.Pp
Passwords as long or longer than PAM_MAX_RESP_SIZE octets (normally 512
-octets) will be rejected, since excessively long passwords can be used as
-a denial of service attack.
-.Sp
-Unlike the normal Unix password module, this module will allow any user to
-change any other user's password if they know the old password. Also,
-unlike the normal Unix password module, root will always be prompted for
-the old password, since root has no special status in Kerberos. (To
-change passwords in Kerberos without knowing the old password, use
-\&\fBkadmin\fR\|(8) instead.)
-.PP
+octets) will be rejected, since excessively long passwords can be used
+as a denial of service attack.
+.Pp
+Unlike the normal Unix password module, this module will allow any user
+to change any other user's password if they know the old password.
+Also, unlike the normal Unix password module, root will always be
+prompted for the old password, since root has no special status in
+Kerberos.
+(To change passwords in Kerberos without knowing the old password, use
+kadmin(8) instead.)
+.El
+.Pp
Both the account and session management calls of the Kerberos PAM module
will return PAM_IGNORE if called in the context of a PAM session for a
-user who did not authenticate with Kerberos (a return code of \f(CW\*(C`ignore\*(C'\fR in
-the Linux PAM configuration language).
-.PP
+user who did not authenticate with Kerberos (a return code of
+.Qo Li ignore Qc
+in the Linux PAM configuration language).
+.Pp
Note that this module assumes the network is available in order to do a
-Kerberos authentication. If the network is not available, some Kerberos
-libraries have timeouts longer than the timeout imposed by the login
-process. This means that using this module incautiously can make it
-impossible to log on to console as root. For this reason, you should
-always use the \fIignore_root\fR or \fIminimum_uid\fR options, list a local
-authentication module such as \fBpam_unix\fR first with a control field of
-\&\f(CW\*(C`sufficient\*(C'\fR so that the Kerberos PAM module will be skipped if local
-password authentication was successful.
-.PP
-This is not the same PAM module as the Kerberos PAM module available from
-Sourceforge, or the one included on Red Hat systems. It supports many of
-the same options, has some additional options, and doesn't support some of
-the options those modules do.
-.SH CONFIGURATION
-.IX Header "CONFIGURATION"
-The Kerberos PAM module takes many options, not all of which are relevant
-to every PAM group; options that are not relevant will be silently
-ignored. Any of these options can be set in the PAM configuration as
-arguments listed after \f(CW\*(C`pam_krb5.so\*(C'\fR. Some of the options can also be
-set in the system \fIkrb5.conf\fR file; if this is possible, it will be noted
-below in the option description.
-.PP
-To set a boolean option in the PAM configuration file, just give the name
-of the option in the arguments. To set an option that takes an argument,
-follow the option name with an equal sign (=) and the value, with no
-separating whitespace. Whitespace in option arguments is not supported in
-the PAM configuration.
-.PP
-To set an option for the PAM module in the system \fIkrb5.conf\fR file, put
-that option in the \f(CW\*(C`[appdefaults]\*(C'\fR section. All options must be followed
-by an equal sign (=) and a value, so for boolean options add \f(CW\*(C`= true\*(C'\fR.
+Kerberos authentication.
+If the network is not available, some Kerberos libraries have timeouts
+longer than the timeout imposed by the login process.
+This means that using this module incautiously can make it impossible to
+log on to console as root.
+For this reason, you should always use the
+.Em ignore_root
+or
+.Em minimum_uid
+options, list a local authentication module such as
+.Sy pam_unix
+first with a control field of
+.Qo Li sufficient Qc
+so that the Kerberos PAM module will be skipped if local password
+authentication was successful.
+.Pp
+This is not the same PAM module as the Kerberos PAM module available
+from Sourceforge, or the one included on Red Hat systems.
+It supports many of the same options, has some additional options, and
+doesn't support some of the options those modules do.
+.Sh CONFIGURATION
+The Kerberos PAM module takes many options, not all of which are
+relevant to every PAM group; options that are not relevant will be
+silently ignored.
+Any of these options can be set in the PAM configuration as arguments
+listed after
+.Qo Li pam_krb5.so Qc .
+Some of the options can also be set in the system
+.Pa krb5.conf
+file; if this is possible, it will be noted below in the option
+description.
+.Pp
+To set a boolean option in the PAM configuration file, just give the
+name of the option in the arguments.
+To set an option that takes an argument, follow the option name with an
+equal sign (=) and the value, with no separating whitespace.
+Whitespace in option arguments is not supported in the PAM
+configuration.
+.Pp
+To set an option for the PAM module in the system
+.Pa krb5.conf
+file, put that option in the
+.Qo Li [appdefaults] Qc
+section.
+All options must be followed by an equal sign (=) and a value, so for
+boolean options add
+.Qo Li = true Qc .
The Kerberos PAM module will look for options either at the top level of
-the \f(CW\*(C`[appdefaults]\*(C'\fR section or in a subsection named \f(CW\*(C`pam\*(C'\fR, inside or
-outside a section for the realm. For example, the following fragment of a
-\&\fIkrb5.conf\fR file would set \fIforwardable\fR to true, \fIminimum_uid\fR to
-1000, and set \fIignore_k5login\fR only if the realm is EXAMPLE.COM.
-.PP
-.Vb 8
-\& [appdefaults]
-\& forwardable = true
-\& pam = {
-\& minimum_uid = 1000
-\& EXAMPLE.COM = {
-\& ignore_k5login = true
-\& }
-\& }
-.Ve
-.PP
-For more information on the syntax of \fIkrb5.conf\fR, see \fBkrb5.conf\fR\|(5).
-Note that options that depend on the realm will be set only on the basis
-of the default realm, either as configured in \fBkrb5.conf\fR\|(5) or as set by
-the \fIrealm\fR option described below. If the user authenticates to an
-account qualified with a realm, that realm will not be used when
-determining which options will apply.
-.PP
-There is no difference to the PAM module whether options are specified at
-the top level or in a \f(CW\*(C`pam\*(C'\fR section; the \f(CW\*(C`pam\*(C'\fR section is supported in
-case there are options that should be set for the PAM module but not for
-other applications.
-.PP
-If the same option is set in \fIkrb5.conf\fR and in the PAM configuration,
-the latter takes precedent. Note, however, that due to the configuration
-syntax, there's no way to turn off a boolean option in the PAM
-configuration that was turned on in \fIkrb5.conf\fR.
-.PP
+the
+.Qo Li [appdefaults] Qc
+section or in a subsection named
+.Qo Li pam Qc ,
+inside or outside a section for the realm.
+For example, the following fragment of a
+.Pa krb5.conf
+file would set
+.Em forwardable
+to true,
+.Em minimum_uid
+to 1000, and set
+.Em ignore_k5login
+only if the realm is EXAMPLE.COM.
+.Bd -literal
+ [appdefaults]
+ forwardable = true
+ pam = {
+ minimum_uid = 1000
+ EXAMPLE.COM = {
+ ignore_k5login = true
+ }
+ }
+.Ed
+.Pp
+For more information on the syntax of
+.Pa krb5.conf ,
+see krb5.conf(5). Note that options that depend on the realm will be set
+only on the basis of the default realm, either as configured in
+krb5.conf(5) or as set by the
+.Em realm
+option described below.
+If the user authenticates to an account qualified with a realm, that
+realm will not be used when determining which options will apply.
+.Pp
+There is no difference to the PAM module whether options are specified
+at the top level or in a
+.Qo Li pam Qc
+section; the
+.Qo Li pam Qc
+section is supported in case there are options that should be set for
+the PAM module but not for other applications.
+.Pp
+If the same option is set in
+.Pa krb5.conf
+and in the PAM configuration, the latter takes precedent.
+Note, however, that due to the configuration syntax, there's no way to
+turn off a boolean option in the PAM configuration that was turned on in
+.Pa krb5.conf .
+.Pp
The start of each option description is annotated with the version of
-pam\-krb5 in which that option was added with the current meaning.
-.SS Authorization
-.IX Subsection "Authorization"
-.IP alt_auth_map=<format> 4
-.IX Item "alt_auth_map=<format>"
-[3.12] This functions similarly to the \fIsearch_k5login\fR option. The
-<format> argument is used as the authentication Kerberos principal, with
-any \f(CW%s\fR in <format> replaced with the username. If the username
-contains an \f(CW\*(C`@\*(C'\fR, only the part of the username before the realm is used
-to replace \f(CW%s\fR. If <format> contains a realm, it will be used;
-otherwise, the realm of the username (if any) will be appended to the
-result. There is no quote removal.
-.Sp
+pam-krb5 in which that option was added with the current meaning.
+.Ss Authorization
+.Bl -tag -width Ds
+.It allow_kdc_spoof
+Allow authentication to succeed even if there is no host or service key
+available in a keytab to authenticate the Kerberos KDC's ticket.
+.It alt_auth_map=<format>
+[3.12] This functions similarly to the
+.Em search_k5login
+option.
+The <format> argument is used as the authentication Kerberos principal,
+with any
+.Qo Li %s Qc
+in <format> replaced with the username.
+If the username contains an
+.Qo Li @ Qc ,
+only the part of the username before the realm is used to replace
+.Qo Li %s Qc .
+If <format> contains a realm, it will be used; otherwise, the realm of
+the username (if any) will be appended to the result.
+There is no quote removal.
+.Pp
If this option is present, the default behavior is to try this alternate
principal first and then fall back to the standard behavior if it fails.
The primary usage is to allow alternative principals to be used for
-authentication in programs like \fBsudo\fR. Most examples will look like:
-.Sp
-.Vb 1
-\& alt_auth_map=%s/root
-.Ve
-.Sp
+authentication in programs like
+.Sy sudo .
+Most examples will look like:
+.Bd -literal
+ alt_auth_map=%s/root
+.Ed
+.Pp
which attempts authentication as the root instance of the username first
-and then falls back to the regular username (but see \fIforce_alt_auth\fR and
-\&\fIonly_alt_auth\fR).
-.Sp
+and then falls back to the regular username (but see
+.Em force_alt_auth
+and
+.Em only_alt_auth Ns ).
+.Pp
This option also allows a cheap way to attempt authentication in an
-alternative realm first and then fall back to the primary realm. A
-setting like:
-.Sp
-.Vb 1
-\& alt_auth_map=%s@EXAMPLE.COM
-.Ve
-.Sp
+alternative realm first and then fall back to the primary realm.
+A setting like:
+.Bd -literal
+ alt_auth_map=%s@EXAMPLE.COM
+.Ed
+.Pp
will attempt authentication in the EXAMPLE.COM realm first and then fall
-back on the local default realm. This is more convenient than running the
-module multiple times with multiple default realms set with \fIrealm\fR, but
-it is very limited: only two realms can be tried, and the alternate realm
-is always tried first.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR, although
-normally it doesn't make sense to do that; normally it is used in the PAM
-options of configuration for specific programs. It is only applicable to
-the auth and account groups. If this option is set for the auth group, be
-sure to set it for the account group as well or account authorization may
-fail.
-.IP force_alt_auth 4
-.IX Item "force_alt_auth"
-[3.12] This option is used with \fIalt_auth_map\fR and forces authentication
-as the mapped principal if that principal exists in the KDC. Only if the
-KDC returns principal unknown does the Kerberos PAM module fall back to
-normal authentication. This can be used to force authentication with an
-alternate instance. If \fIalt_auth_map\fR is not set, it has no effect.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP ignore_k5login 4
-.IX Item "ignore_k5login"
-[2.0] Never look for a \fI.k5login\fR file in the user's home directory.
-Instead, only check that the Kerberos principal maps to the local account
-name. The default check is to ensure the realm matches the local realm
-and the user portion of the principal matches the local account name, but
-this can be customized by setting up an aname to localname mapping in
-\&\fIkrb5.conf\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and account groups.
-.IP ignore_root 4
-.IX Item "ignore_root"
-[1.1] Do not do anything if the username is \f(CW\*(C`root\*(C'\fR. The authentication
-and password calls will silently fail (allowing that status to be ignored
-via a control of \f(CW\*(C`optional\*(C'\fR or \f(CW\*(C`sufficient\*(C'\fR), and the account and
-session calls (including pam_setcred) will return PAM_IGNORE, telling the
-PAM library to proceed as if they weren't mentioned in the PAM
-configuration. This option is supported and will remain, but normally you
-want to use \fIminimum_uid\fR instead.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR.
-.IP minimum_uid=<uid> 4
-.IX Item "minimum_uid=<uid>"
-[2.0] Do not do anything if the authenticated account name corresponds to
-a local account and that local account has a UID lower than <uid>. If
+back on the local default realm.
+This is more convenient than running the module multiple times with
+multiple default realms set with
+.Em realm ,
+but it is very limited: only two realms can be tried, and the alternate
+realm is always tried first.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf ,
+although normally it doesn't make sense to do that; normally it is used
+in the PAM options of configuration for specific programs.
+It is only applicable to the auth and account groups.
+If this option is set for the auth group, be sure to set it for the
+account group as well or account authorization may fail.
+.It force_alt_auth
+[3.12] This option is used with
+.Em alt_auth_map
+and forces authentication as the mapped principal if that principal
+exists in the KDC. Only if the KDC returns principal unknown does the
+Kerberos PAM module fall back to normal authentication.
+This can be used to force authentication with an alternate instance.
+If
+.Em alt_auth_map
+is not set, it has no effect.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It ignore_k5login
+[2.0] Never look for a
+.Pa .k5login
+file in the user's home directory.
+Instead, only check that the Kerberos principal maps to the local
+account name.
+The default check is to ensure the realm matches the local realm and the
+user portion of the principal matches the local account name, but this
+can be customized by setting up an aname to localname mapping in
+.Pa krb5.conf .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and account groups.
+.It ignore_root
+[1.1] Do not do anything if the username is
+.Qo Li root Qc .
+The authentication and password calls will silently fail (allowing that
+status to be ignored via a control of
+.Qo Li optional Qc
+or
+.Qo Li sufficient Qc Ns ),
+and the account and session calls (including pam_setcred) will return
+PAM_IGNORE, telling the PAM library to proceed as if they weren't
+mentioned in the PAM configuration.
+This option is supported and will remain, but normally you want to use
+.Em minimum_uid
+instead.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf .
+.It minimum_uid=<uid>
+[2.0] Do not do anything if the authenticated account name corresponds
+to a local account and that local account has a UID lower than <uid>. If
both of those conditions are true, the authentication and password calls
will silently fail (allowing that status to be ignored via a control of
-\&\f(CW\*(C`optional\*(C'\fR or \f(CW\*(C`sufficient\*(C'\fR), and the account and session calls
-(including pam_setcred) will return PAM_IGNORE, telling the PAM library to
-proceed as if they weren't mentioned in the PAM configuration.
-.Sp
-Using this option is highly recommended if you don't need to use Kerberos
-to authenticate password logins to the root account (which isn't
-recommended since Kerberos requires a network connection). It provides
-some defense in depth against user principals that happen to match a
-system account incorrectly authenticating as that system account.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR.
-.IP only_alt_auth 4
-.IX Item "only_alt_auth"
-[3.12] This option is used with \fIalt_auth_map\fR and forces the use of the
-mapped principal for authentication. It disables fallback to normal
-authentication in all cases and overrides \fIsearch_k5login\fR and
-\&\fIforce_alt_auth\fR. If \fIalt_auth_map\fR is not set, it has no effect and
-the standard authentication behavior is used.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP search_k5login 4
-.IX Item "search_k5login"
+.Qo Li optional Qc
+or
+.Qo Li sufficient Qc Ns ),
+and the account and session calls (including pam_setcred) will return
+PAM_IGNORE, telling the PAM library to proceed as if they weren't
+mentioned in the PAM configuration.
+.Pp
+Using this option is highly recommended if you don't need to use
+Kerberos to authenticate password logins to the root account (which
+isn't recommended since Kerberos requires a network connection).
+It provides some defense in depth against user principals that happen to
+match a system account incorrectly authenticating as that system
+account.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf .
+.It only_alt_auth
+[3.12] This option is used with
+.Em alt_auth_map
+and forces the use of the mapped principal for authentication.
+It disables fallback to normal authentication in all cases and overrides
+.Em search_k5login
+and
+.Em force_alt_auth .
+If
+.Em alt_auth_map
+is not set, it has no effect and the standard authentication behavior is
+used.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It search_k5login
[2.0] Normally, the Kerberos implementation of pam_authenticate attempts
-to obtain tickets for the authenticating username in the local realm. If
-this option is set and the local user has a \fI.k5login\fR file in their home
-directory, the module will instead open and read that \fI.k5login\fR file,
-attempting to use the supplied password to authenticate as each principal
-listed there in turn. If any of those authentications succeed, the user
-will be successfully authenticated; otherwise, authentication will fail.
-This option is useful for allowing password authentication (via console or
-\&\fBsshd\fR without GSS-API support) to shared accounts. If there is no
-\&\fI.k5login\fR file, the behavior is the same as normal. Using this option
-requires that the user's \fI.k5login\fR file be readable at the time of
-authentication.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.SS "Kerberos Behavior"
-.IX Subsection "Kerberos Behavior"
-.IP anon_fast 4
-.IX Item "anon_fast"
+to obtain tickets for the authenticating username in the local realm.
+If this option is set and the local user has a
+.Pa .k5login
+file in their home directory, the module will instead open and read that
+.Pa .k5login
+file, attempting to use the supplied password to authenticate as each
+principal listed there in turn.
+If any of those authentications succeed, the user will be successfully
+authenticated; otherwise, authentication will fail.
+This option is useful for allowing password authentication (via console
+or
+.Sy sshd
+without GSS-API support) to shared accounts.
+If there is no
+.Pa .k5login
+file, the behavior is the same as normal.
+Using this option requires that the user's
+.Pa .k5login
+file be readable at the time of authentication.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.El
+.Ss Kerberos Behavior
+.Bl -tag -width Ds
+.It anon_fast
[4.6] Attempt to use Flexible Authentication Secure Tunneling (FAST) by
-first authenticating as the anonymous user (WELLKNOWN/ANONYMOUS) and using
-its credentials as the FAST armor. This requires anonymous PKINIT be
-enabled for the local realm, that PKINIT be configured on the local
-system, and that the Kerberos library support FAST and anonymous PKINIT.
-.Sp
-FAST is a mechanism to protect Kerberos against password guessing attacks
-and provide other security improvements. To work, FAST requires that a
-ticket be obtained with a strong key to protect exchanges with potentially
-weaker user passwords. This option uses anonymous authentication to
-obtain that key and then uses it to protect the subsequent authentication.
-.Sp
+first authenticating as the anonymous user (WELLKNOWN/ANONYMOUS) and
+using its credentials as the FAST armor.
+This requires anonymous PKINIT be enabled for the local realm, that
+PKINIT be configured on the local system, and that the Kerberos library
+support FAST and anonymous PKINIT.
+.Pp
+FAST is a mechanism to protect Kerberos against password guessing
+attacks and provide other security improvements.
+To work, FAST requires that a ticket be obtained with a strong key to
+protect exchanges with potentially weaker user passwords.
+This option uses anonymous authentication to obtain that key and then
+uses it to protect the subsequent authentication.
+.Pp
If anonymous PKINIT is not available or fails, FAST will not be used and
the authentication will proceed as normal.
-.Sp
+.Pp
To instead use an existing ticket cache for the FAST credentials, use
-\&\fIfast_ccache\fR instead of this option. If both \fIfast_ccache\fR and
-\&\fIanon_fast\fR are set, the ticket cache named by \fIfast_ccache\fR will be
-tried first, and the Kerberos PAM module will fall back on attempting
-anonymous PKINIT if that cache could not be used.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.Sp
-The operation is the same as if using the \fIfast_ccache\fR option, but the
-cache is created and destroyed automatically. If both \fIfast_ccache\fR and
-\&\fIanon_fast\fR options are used, the \fIfast_ccache\fR takes precedent and no
-anonymous authentication is done.
-.IP fast_ccache=<ccache_name> 4
-.IX Item "fast_ccache=<ccache_name>"
-[4.3] The same as \fIanon_fast\fR, but use an existing Kerberos ticket cache
-rather than anonymous PKINIT. This allows use of FAST with a realm that
-doesn't support PKINIT or doesn't support anonymous authentication.
-.Sp
+.Em fast_ccache
+instead of this option.
+If both
+.Em fast_ccache
+and
+.Em anon_fast
+are set, the ticket cache named by
+.Em fast_ccache
+will be tried first, and the Kerberos PAM module will fall back on
+attempting anonymous PKINIT if that cache could not be used.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.Pp
+The operation is the same as if using the
+.Em fast_ccache
+option, but the cache is created and destroyed automatically.
+If both
+.Em fast_ccache
+and
+.Em anon_fast
+options are used, the
+.Em fast_ccache
+takes precedent and no anonymous authentication is done.
+.It fast_ccache=<ccache_name>
+[4.3] The same as
+.Em anon_fast ,
+but use an existing Kerberos ticket cache rather than anonymous PKINIT.
+This allows use of FAST with a realm that doesn't support PKINIT or
+doesn't support anonymous authentication.
+.Pp
<ccache_name> should be a credential cache containing a ticket obtained
using a strong key, such as the randomized key for the host principal of
-the local system. If <ccache_name> names a ticket cache that is readable
-by the authenticating process and has tickets then FAST will be attempted.
-The easiest way to use this option is to use a program like \fBk5start\fR to
-maintain a ticket cache using the host's keytab. This ticket cache should
-normally only be readable by root, so this option will not be able to
-protect authentications done as non-root users (such as screensavers).
-.Sp
-If no credentials are present in the ticket cache, or if the ticket cache
-does not exist or is not readable, FAST will not used and authentication
-will proceed as normal. However, if the credentials in that ticket cache
-are expired, authentication will fail if the KDC supports FAST.
-.Sp
-To use anonymous PKINIT to protect the FAST exchange, use the \fIanon_fast\fR
-option instead. \fIanon_fast\fR is easier to configure, since no existing
-ticket cache is required, but requires PKINIT be available and configured
-and that the local realm support anonymous authentication. If both
-\&\fIfast_ccache\fR and \fIanon_fast\fR are set, the ticket cache named by
-\&\fIfast_ccache\fR will be tried first, and the Kerberos PAM module will fall
-back on attempting anonymous PKINIT if that cache could not be used.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.IP forwardable 4
-.IX Item "forwardable"
-[1.0] Obtain forwardable tickets. If set (to either true or false,
-although it can only be set to false in \fIkrb5.conf\fR), this overrides the
-Kerberos library default set in the [libdefaults] section of \fIkrb5.conf\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP keytab=<path> 4
-.IX Item "keytab=<path>"
-[3.0] Specifies the keytab to use when validating the user's credentials.
-The default is the default system keytab (normally \fI/etc/krb5.keytab\fR),
-which is usually only readable by root. Applications not running as root
-that use this PAM module for authentication may wish to point it to
-another keytab the application can read. The first principal found in the
-keytab will be used as the principal for credential verification.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP realm=<realm> 4
-.IX Item "realm=<realm>"
-[2.2] Set the default Kerberos realm and obtain credentials in that realm,
-rather than in the normal default realm for this system. If this option
-is used, it should be set for all groups being used for consistent
-results. This setting will affect authorization decisions since it
-changes the default realm. This setting will also change the service
-principal used to verify the obtained credentials to be in the specified
-realm.
-.Sp
+the local system.
+If <ccache_name> names a ticket cache that is readable by the
+authenticating process and has tickets then FAST will be attempted.
+The easiest way to use this option is to use a program like
+.Sy k5start
+to maintain a ticket cache using the host's keytab.
+This ticket cache should normally only be readable by root, so this
+option will not be able to protect authentications done as non-root
+users (such as screensavers).
+.Pp
+If no credentials are present in the ticket cache, or if the ticket
+cache does not exist or is not readable, FAST will not used and
+authentication will proceed as normal.
+However, if the credentials in that ticket cache are expired,
+authentication will fail if the KDC supports FAST.
+.Pp
+To use anonymous PKINIT to protect the FAST exchange, use the
+.Em anon_fast
+option instead.
+.Em anon_fast
+is easier to configure, since no existing ticket cache is required, but
+requires PKINIT be available and configured and that the local realm
+support anonymous authentication.
+If both
+.Em fast_ccache
+and
+.Em anon_fast
+are set, the ticket cache named by
+.Em fast_ccache
+will be tried first, and the Kerberos PAM module will fall back on
+attempting anonymous PKINIT if that cache could not be used.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.It forwardable
+[1.0] Obtain forwardable tickets.
+If set (to either true or false, although it can only be set to false in
+.Pa krb5.conf Ns ),
+this overrides the Kerberos library default set in the [libdefaults]
+section of
+.Pa krb5.conf .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It keytab=<path>
+[3.0] Specifies the keytab to use when validating the user's
+credentials.
+The default is the default system keytab (normally
+.Pa /etc/krb5.keytab Ns ),
+which is usually only readable by root.
+Applications not running as root that use this PAM module for
+authentication may wish to point it to another keytab the application
+can read.
+The first principal found in the keytab will be used as the principal
+for credential verification.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It realm=<realm>
+[2.2] Set the default Kerberos realm and obtain credentials in that
+realm, rather than in the normal default realm for this system.
+If this option is used, it should be set for all groups being used for
+consistent results.
+This setting will affect authorization decisions since it changes the
+default realm.
+This setting will also change the service principal used to verify the
+obtained credentials to be in the specified realm.
+.Pp
If you only want to set the realm assumed for user principals without
changing the realm for authorization decisions or the service principal
-used to verify credentials, see the \fIuser_realm\fR option.
-.IP renew_lifetime=<lifetime> 4
-.IX Item "renew_lifetime=<lifetime>"
+used to verify credentials, see the
+.Em user_realm
+option.
+.It renew_lifetime=<lifetime>
[2.0] Obtain renewable tickets with a maximum renewable lifetime of
-<lifetime>. <lifetime> should be a Kerberos lifetime string such as
-\&\f(CW\*(C`2d4h10m\*(C'\fR or a time in minutes. If set, this overrides the Kerberos
-library default set in the [libdefaults] section of \fIkrb5.conf\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP ticket_lifetime=<lifetime> 4
-.IX Item "ticket_lifetime=<lifetime>"
-[3.0] Obtain tickets with a maximum lifetime of <lifetime>. <lifetime>
-should be a Kerberos lifetime string such as \f(CW\*(C`2d4h10m\*(C'\fR or a time in
-minutes. If set, this overrides the Kerberos library default set in the
-[libdefaults] section of \fIkrb5.conf\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP user_realm 4
-.IX Item "user_realm"
-[4.6] Obtain credentials in the specified realm rather than in the default
-realm for this system. If this option is used, it should be set for all
-groups being used for consistent results (although the account group
-currently doesn't care about realm). This will not change authorization
-decisions. If the obtained credentials are supposed to allow access to a
-shell account, the user will need an appropriate \fI.k5login\fR file entry or
-the system will have to have a custom aname_to_localname mapping.
-.SS "PAM Behavior"
-.IX Subsection "PAM Behavior"
-.IP clear_on_fail 4
-.IX Item "clear_on_fail"
-[3.9] When changing passwords, PAM first does a preliminary check through
-the complete password stack, and then calls each module again to do the
-password change. After that preliminary check, the order of module
-invocation is fixed. This means that even if the Kerberos password change
-fails (or if one of the other password changes in the stack fails), other
-password PAM modules in the stack will still be called even if the failing
-module is marked required or requisite. When using multiple password PAM
-modules to synchronize passwords between multiple systems when they
-change, this behavior can cause unwanted differences between the
-environments.
-.Sp
-Setting this option provides a way to work around this behavior. If this
-option is set and a Kerberos password change is attempted and fails (due
-to network errors or password strength checking on the KDC, for example),
-this module will clear the stored password in the PAM stack. This will
-force any subsequent modules that have \fIuse_authtok\fR set to fail so that
-those environments won't get out of sync with the password in Kerberos.
+<lifetime>. <lifetime> should be a Kerberos lifetime string such as
+.Qo Li 2d4h10m Qc
+or a time in minutes.
+If set, this overrides the Kerberos library default set in the
+[libdefaults] section of
+.Pa krb5.conf .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It ticket_lifetime=<lifetime>
+[3.0] Obtain tickets with a maximum lifetime of <lifetime>. <lifetime>
+should be a Kerberos lifetime string such as
+.Qo Li 2d4h10m Qc
+or a time in minutes.
+If set, this overrides the Kerberos library default set in the
+[libdefaults] section of
+.Pa krb5.conf .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It user_realm
+[4.6] Obtain credentials in the specified realm rather than in the
+default realm for this system.
+If this option is used, it should be set for all groups being used for
+consistent results (although the account group currently doesn't care
+about realm).
+This will not change authorization decisions.
+If the obtained credentials are supposed to allow access to a shell
+account, the user will need an appropriate
+.Pa .k5login
+file entry or the system will have to have a custom aname_to_localname
+mapping.
+.El
+.Ss PAM Behavior
+.Bl -tag -width Ds
+.It clear_on_fail
+[3.9] When changing passwords, PAM first does a preliminary check
+through the complete password stack, and then calls each module again to
+do the password change.
+After that preliminary check, the order of module invocation is fixed.
+This means that even if the Kerberos password change fails (or if one of
+the other password changes in the stack fails), other password PAM
+modules in the stack will still be called even if the failing module is
+marked required or requisite.
+When using multiple password PAM modules to synchronize passwords
+between multiple systems when they change, this behavior can cause
+unwanted differences between the environments.
+.Pp
+Setting this option provides a way to work around this behavior.
+If this option is set and a Kerberos password change is attempted and
+fails (due to network errors or password strength checking on the KDC,
+for example), this module will clear the stored password in the PAM
+stack.
+This will force any subsequent modules that have
+.Em use_authtok
+set to fail so that those environments won't get out of sync with the
+password in Kerberos.
The Kerberos PAM module will not meddle with the stored password if it
skips the user due to configuration such as minimum_uid.
-.Sp
+.Pp
Unfortunately, setting this option interferes with other desirable PAM
configurations, such as attempting to change the password in Kerberos
-first and falling back on the local Unix password database if that fails.
-It therefore isn't the default. Turn it on (and list pam_krb5 first after
-pam_cracklib if used) when synchronizing passwords between multiple
-environments.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the password group.
-.IP debug 4
-.IX Item "debug"
+first and falling back on the local Unix password database if that
+fails.
+It therefore isn't the default.
+Turn it on (and list pam_krb5 first after pam_cracklib if used) when
+synchronizing passwords between multiple environments.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the password group.
+.It debug
[1.0] Log more verbose trace and debugging information to syslog at
-LOG_DEBUG priority, including entry and exit from each of the external PAM
-interfaces (except pam_close_session).
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR.
-.IP defer_pwchange 4
-.IX Item "defer_pwchange"
-[3.11] By default, pam\-krb5 lets the Kerberos library handle prompting for
-a password change if an account's password is expired during the auth
-group. If this fails, \fBpam_authenticate()\fR returns an error.
-.Sp
+LOG_DEBUG priority, including entry and exit from each of the external
+PAM interfaces (except pam_close_session).
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf .
+.It defer_pwchange
+[3.11] By default, pam-krb5 lets the Kerberos library handle prompting
+for a password change if an account's password is expired during the
+auth group.
+If this fails,
+.Xr pam_authenticate 3
+returns an error.
+.Pp
According to the PAM standard, this is not the correct way to handle
-expired passwords. Instead, \fBpam_authenticate()\fR should return success
-without attempting a password change, and then \fBpam_acct_mgmt()\fR should
-return PAM_NEW_AUTHTOK_REQD, at which point the calling application is
-responsible for either rejecting the authentication or calling
-\&\fBpam_chauthtok()\fR. However, following the standard requires that all
-applications call \fBpam_acct_mgmt()\fR and check its return status; otherwise,
-expired accounts may be able to successfully authenticate. Many
-applications do not do this.
-.Sp
-If this option is set, pam\-krb5 uses the fully correct PAM mechanism for
-handling expired accounts instead of failing in \fBpam_authenticate()\fR. Due
-to the security risk of widespread broken applications, be very careful
-about enabling this option. It should normally only be turned on to solve
-a specific problem (such as using Solaris Kerberos libraries that don't
-support prompting for password changes during authentication), and then
-only for specific applications known to call \fBpam_acct_mgmt()\fR and check its
-return status properly.
-.Sp
-This option is only supported when pam\-krb5 is built with MIT Kerberos.
+expired passwords.
+Instead,
+.Xr pam_authenticate 3
+should return success without attempting a password change, and then
+.Xr pam_acct_mgmt 3
+should return PAM_NEW_AUTHTOK_REQD, at which point the calling
+application is responsible for either rejecting the authentication or
+calling
+.Xr pam_chauthtok 3 .
+However, following the standard requires that all applications call
+.Xr pam_acct_mgmt 3
+and check its return status; otherwise, expired accounts may be able to
+successfully authenticate.
+Many applications do not do this.
+.Pp
+If this option is set, pam-krb5 uses the fully correct PAM mechanism for
+handling expired accounts instead of failing in
+.Xr pam_authenticate 3 .
+Due to the security risk of widespread broken applications, be very
+careful about enabling this option.
+It should normally only be turned on to solve a specific problem (such
+as using Solaris Kerberos libraries that don't support prompting for
+password changes during authentication), and then only for specific
+applications known to call
+.Xr pam_acct_mgmt 3
+and check its return status properly.
+.Pp
+This option is only supported when pam-krb5 is built with MIT Kerberos.
If built against Heimdal, this option does nothing and normal expired
-password change handling still happens. (Heimdal is missing the required
-API to implement this option, at least as of version 1.6.)
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP fail_pwchange 4
-.IX Item "fail_pwchange"
-[4.2] By default, pam\-krb5 lets the Kerberos library handle prompting for
-a password change if an account's password is expired during the auth
-group. If this option is set, expired passwords are instead treated as an
-authentication failure identical to an incorrect password. Also see
-\&\fIdefer_pwchange\fR and \fIforce_pwchange\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP force_pwchange 4
-.IX Item "force_pwchange"
+password change handling still happens.
+(Heimdal is missing the required API to implement this option, at least
+as of version 1.6.)
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It fail_pwchange
+[4.2] By default, pam-krb5 lets the Kerberos library handle prompting
+for a password change if an account's password is expired during the
+auth group.
+If this option is set, expired passwords are instead treated as an
+authentication failure identical to an incorrect password.
+Also see
+.Em defer_pwchange
+and
+.Em force_pwchange .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It force_pwchange
[3.11] If this option is set and authentication fails with a Kerberos
error indicating the user's password is expired, attempt to immediately
-change their password during the authenticate step. Under normal
-circumstances, this is unnecessary. Most Kerberos libraries will do this
-for you, and setting this option will prompt the user twice to change
-their password if the first attempt (done by the Kerberos library) fails.
-However, some system Kerberos libraries (such as Solaris's) have password
-change prompting disabled in the Kerberos library; on those systems, you
-can set this option to simulate the normal library behavior.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP no_update_user 4
-.IX Item "no_update_user"
-[4.7] Normally, if pam\-krb5 is able to canonicalize the principal to a
-local name using \fBkrb5_aname_to_localname()\fR or similar calls, it changes
-the PAM_USER variable for this PAM session to the canonicalized local
-name. Setting this option disables this behavior and leaves PAM_USER set
-to the initial authentication identity.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth group.
-.IP silent 4
-.IX Item "silent"
+change their password during the authenticate step.
+Under normal circumstances, this is unnecessary.
+Most Kerberos libraries will do this for you, and setting this option
+will prompt the user twice to change their password if the first attempt
+(done by the Kerberos library) fails.
+However, some system Kerberos libraries (such as Solaris's) have
+password change prompting disabled in the Kerberos library; on those
+systems, you can set this option to simulate the normal library
+behavior.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It no_update_user
+[4.7] Normally, if pam-krb5 is able to canonicalize the principal to a
+local name using
+.Xr krb5_aname_to_localname 3
+or similar calls, it changes the PAM_USER variable for this PAM session
+to the canonicalized local name.
+Setting this option disables this behavior and leaves PAM_USER set to
+the initial authentication identity.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth group.
+.It silent
[1.0] Don't show messages and errors from Kerberos, such as warnings of
-expiring passwords, to the user via the prompter. This is equivalent to
-the behavior when the application passes in PAM_SILENT, but can be set in
-the PAM configuration.
-.Sp
+expiring passwords, to the user via the prompter.
+This is equivalent to the behavior when the application passes in
+PAM_SILENT, but can be set in the PAM configuration.
+.Pp
This option is only applicable to the auth and password groups.
-.IP trace=<log\-file> 4
-.IX Item "trace=<log-file>"
-[4.6] Enables Kerberos library trace logging to the specified log file if
-it is supported by the Kerberos library. This is intended for temporary
-debugging. The specified file will be appended to without further
-security checks, so do not specify a file in a publicly writable directory
-like \fI/tmp\fR.
-.SS PKINIT
-.IX Subsection "PKINIT"
-.IP pkinit_anchors=<anchors> 4
-.IX Item "pkinit_anchors=<anchors>"
-[3.0] When doing PKINIT authentication, use <anchors> as the client trust
-anchors. This is normally a reference to a file containing the trusted
-certificate authorities. This option is only used if \fItry_pkinit\fR or
-\&\fIuse_pkinit\fR are set.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.IP pkinit_prompt 4
-.IX Item "pkinit_prompt"
-[3.0] Before attempting PKINIT authentication, prompt the user to insert a
-smart card. You may want to set this option for programs such as
-\&\fBgnome-screensaver\fR that call PAM as soon as the mouse is touched and
-don't give the user an opportunity to enter the smart card first. Any
-information entered at the first prompt is ignored. If \fItry_pkinit\fR is
-set, a user who wishes to use a password instead can just press Enter and
-then enter their password as normal. This option is only used if
-\&\fItry_pkinit\fR or \fIuse_pkinit\fR are set.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.IP pkinit_user=<userid> 4
-.IX Item "pkinit_user=<userid>"
-[3.0] When doing PKINIT authentication, use <userid> as the user ID. The
+.It trace=<log-file>
+[4.6] Enables Kerberos library trace logging to the specified log file
+if it is supported by the Kerberos library.
+This is intended for temporary debugging.
+The specified file will be appended to without further security checks,
+so do not specify a file in a publicly writable directory like
+.Pa /tmp .
+.El
+.Ss PKINIT
+.Bl -tag -width Ds
+.It pkinit_anchors=<anchors>
+[3.0] When doing PKINIT authentication, use <anchors> as the client
+trust anchors.
+This is normally a reference to a file containing the trusted
+certificate authorities.
+This option is only used if
+.Em try_pkinit
+or
+.Em use_pkinit
+are set.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.It pkinit_prompt
+[3.0] Before attempting PKINIT authentication, prompt the user to insert
+a smart card.
+You may want to set this option for programs such as
+.Sy gnome-screensaver
+that call PAM as soon as the mouse is touched and don't give the user an
+opportunity to enter the smart card first.
+Any information entered at the first prompt is ignored.
+If
+.Em try_pkinit
+is set, a user who wishes to use a password instead can just press Enter
+and then enter their password as normal.
+This option is only used if
+.Em try_pkinit
+or
+.Em use_pkinit
+are set.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.It pkinit_user=<userid>
+[3.0] When doing PKINIT authentication, use <userid> as the user ID. The
value of this string is highly dependent on the type of PKINIT
implementation you're using, but will generally be something like:
-.Sp
-.Vb 1
-\& PKCS11:/usr/lib/pkcs11/lib/soft\-pkcs11.so
-.Ve
-.Sp
-to specify the module to use with a smart card. It may also point to a
-user certificate or to other types of user IDs. See the Kerberos library
-documentation for more details. This option is only used if \fItry_pkinit\fR
-or \fIuse_pkinit\fR are set.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.IP preauth_opt=<option> 4
-.IX Item "preauth_opt=<option>"
-[3.3] Sets a preauth option (currently only applicable when built with MIT
-Kerberos). <option> is either a key/value pair with the key separated
-from the value by \f(CW\*(C`=\*(C'\fR or a boolean option (in which case it's turned on).
-In \fIkrb5.conf\fR, multiple options should be separated by whitespace. In
-the PAM configuration, this option can be given multiple times to set
-multiple options. In either case, <option> may not contain whitespace.
-.Sp
+.Bd -literal
+ PKCS11:/usr/lib/pkcs11/lib/soft-pkcs11.so
+.Ed
+.Pp
+to specify the module to use with a smart card.
+It may also point to a user certificate or to other types of user IDs.
+See the Kerberos library documentation for more details.
+This option is only used if
+.Em try_pkinit
+or
+.Em use_pkinit
+are set.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.It preauth_opt=<option>
+[3.3] Sets a preauth option (currently only applicable when built with
+MIT Kerberos).
+<option> is either a key/value pair with the key separated from the
+value by
+.Qo Li = Qc
+or a boolean option (in which case it's turned on).
+In
+.Pa krb5.conf ,
+multiple options should be separated by whitespace.
+In the PAM configuration, this option can be given multiple times to set
+multiple options.
+In either case, <option> may not contain whitespace.
+.Pp
The primary use of this option, at least in the near future, will be to
-set options for the MIT Kerberos PKINIT support. For the full list of
-possible options, see the PKINIT plugin documentation. At the time of
-this writing, \f(CW\*(C`X509_user_identity\*(C'\fR is equivalent to \fIpkinit_user\fR and
-\&\f(CW\*(C`X509_anchors\*(C'\fR is equivalent to \fIpkinit_anchors\fR. \f(CW\*(C`flag_DSA_PROTOCOL\*(C'\fR
+set options for the MIT Kerberos PKINIT support.
+For the full list of possible options, see the PKINIT plugin
+documentation.
+At the time of this writing,
+.Qo Li X509_user_identity Qc
+is equivalent to
+.Em pkinit_user
+and
+.Qo Li X509_anchors Qc
+is equivalent to
+.Em pkinit_anchors .
+.Qo Li flag_DSA_PROTOCOL Qc
can only be set via this option.
-.Sp
-Any settings made with this option are applied after the \fIpkinit_anchors\fR
-and \fIpkinit_user\fR options, so if an equivalent setting is made via
-\&\fIpreauth_opt\fR, it will probably override the other setting.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups. Note that there is no way to
-remove a setting made in \fIkrb5.conf\fR using the PAM configuration, but
-options set in the PAM configuration are applied after options set in
-\&\fIkrb5.conf\fR and therefore may override earlier settings.
-.IP try_pkinit 4
-.IX Item "try_pkinit"
-[3.0] Attempt PKINIT authentication before trying a regular password. You
-will probably also need to set the \fIpkinit_user\fR configuration option.
+.Pp
+Any settings made with this option are applied after the
+.Em pkinit_anchors
+and
+.Em pkinit_user
+options, so if an equivalent setting is made via
+.Em preauth_opt ,
+it will probably override the other setting.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+Note that there is no way to remove a setting made in
+.Pa krb5.conf
+using the PAM configuration, but options set in the PAM configuration
+are applied after options set in
+.Pa krb5.conf
+and therefore may override earlier settings.
+.It try_pkinit
+[3.0] Attempt PKINIT authentication before trying a regular password.
+You will probably also need to set the
+.Em pkinit_user
+configuration option.
If PKINIT fails, the PAM module will fall back on regular password
-authentication. This option is currently only supported if pam\-krb5 was
-built against Heimdal 0.8rc1 or later or MIT Kerberos 1.6.3 or later.
-.Sp
-If this option is set and pam\-krb5 is built against MIT Kerberos, and
+authentication.
+This option is currently only supported if pam-krb5 was built against
+Heimdal 0.8rc1 or later or MIT Kerberos 1.6.3 or later.
+.Pp
+If this option is set and pam-krb5 is built against MIT Kerberos, and
PKINIT fails and the module falls back to password authentication, the
user's password will not be stored in the PAM stack for subsequent
-modules. This is a bug in the interaction between the module and MIT
-Kerberos that requires some reworking of the PKINIT authentication method
-to fix.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.IP use_pkinit 4
-.IX Item "use_pkinit"
-[3.0, 4.9 for MIT Kerberos] Require PKINIT authentication. You will
-probably also need to set the \fIpkinit_user\fR configuration option. If
-PKINIT fails, authentication will fail. This option is only supported if
-pam\-krb5 was built against Heimdal 0.8rc1 or later or MIT Kerberos 1.12 or
-later.
-.Sp
+modules.
+This is a bug in the interaction between the module and MIT Kerberos
+that requires some reworking of the PKINIT authentication method to fix.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.It use_pkinit
+[3.0, 4.9 for MIT Kerberos] Require PKINIT authentication.
+You will probably also need to set the
+.Em pkinit_user
+configuration option.
+If PKINIT fails, authentication will fail.
+This option is only supported if pam-krb5 was built against Heimdal
+0.8rc1 or later or MIT Kerberos 1.12 or later.
+.Pp
Be aware that, with MIT Kerberos, this option is implemented by using a
-responder without a prompter, and thus any informational messages from the
-Kerberos libraries or KDC during authentication will not be displayed.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.SS Prompting
-.IX Subsection "Prompting"
-.IP banner=<banner> 4
-.IX Item "banner=<banner>"
+responder without a prompter, and thus any informational messages from
+the Kerberos libraries or KDC during authentication will not be
+displayed.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.El
+.Ss Prompting
+.Bl -tag -width Ds
+.It banner=<banner>
[3.0] By default, the prompts when a user changes their password are:
-.Sp
-.Vb 3
-\& Current Kerberos password:
-\& Enter new Kerberos password:
-\& Retype new Kerberos password:
-.Ve
-.Sp
+.Bd -literal
+ Current Kerberos password:
+ Enter new Kerberos password:
+ Retype new Kerberos password:
+.Ed
+.Pp
The string "Kerberos" is inserted so that users aren't confused about
-which password they're changing. Setting this option replaces the word
-"Kerberos" with whatever this option is set to. Setting this option to
-the empty string removes the word before "password:" entirely.
-.Sp
-If set in the PAM configuration, <banner> may not contain whitespace. If
-you want a value containing whitespace, set it in \fIkrb5.conf\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the password group.
-.IP expose_account 4
-.IX Item "expose_account"
+which password they're changing.
+Setting this option replaces the word "Kerberos" with whatever this
+option is set to.
+Setting this option to the empty string removes the word before
+"password:" entirely.
+.Pp
+If set in the PAM configuration, <banner> may not contain whitespace.
+If you want a value containing whitespace, set it in
+.Pa krb5.conf .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the password group.
+.It expose_account
[3.0] By default, the Kerberos PAM module password prompt is simply
-"Password:". This avoids leaking any information about the system realm
-or account to principal conversions. If this option is set, the string
-"for <principal>" is added before the colon, where <principal> is the
-user's principal. This string is also added before the colon on prompts
-when changing the user's password.
-.Sp
+"Password:". This avoids leaking any information about the system realm
+or account to principal conversions.
+If this option is set, the string "for <principal>" is added before the
+colon, where <principal> is the user's principal.
+This string is also added before the colon on prompts when changing the
+user's password.
+.Pp
Enabling this option with ChallengeResponseAuthentication enabled in
OpenSSH may cause problems for some ssh clients that only recognize
-"Password:" as a prompt. This option is automatically disabled if
-\&\fIsearch_k5login\fR is enabled since the principal displayed would be
-inaccurate.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and password groups.
-.IP force_first_pass 4
-.IX Item "force_first_pass"
+"Password:" as a prompt.
+This option is automatically disabled if
+.Em search_k5login
+is enabled since the principal displayed would be inaccurate.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and password groups.
+.It force_first_pass
[4.0] Use the password obtained by a previous authentication or password
-module to authenticate the user without prompting the user again. If no
-previous module obtained the user's password, fail without prompting the
-user. Also see \fItry_first_pass\fR and \fIuse_first_pass\fR for weaker
-versions of this option.
-.Sp
-This option is only applicable to the auth and password groups. For the
-password group, it applies only to the old password. See \fIuse_authtok\fR
+module to authenticate the user without prompting the user again.
+If no previous module obtained the user's password, fail without
+prompting the user.
+Also see
+.Em try_first_pass
+and
+.Em use_first_pass
+for weaker versions of this option.
+.Pp
+This option is only applicable to the auth and password groups.
+For the password group, it applies only to the old password.
+See
+.Em use_authtok
for a similar setting for the new password.
-.IP no_prompt 4
-.IX Item "no_prompt"
-[4.6] Never prompt for the current password. Instead, pass in a NULL
-password to the Kerberos library and let the Kerberos library do the
-prompting. This may be needed if, for example, the Kerberos library is
-configured to use other authentication mechanisms than passwords and needs
-full control over the prompting process.
-.Sp
-The major disadvantage of this option is that it means the PAM module will
-never see the user's password and therefore cannot save it in the PAM
-module data for any subsequent modules. In other words, this option
-cannot be used if another module is in the stack behind the Kerberos PAM
-module and wants to use \fIuse_first_pass\fR. The Kerberos library also
-usually includes the principal in the prompt, and therefore this option
-implies behavior similar to \fIexpose_account\fR. Similar to
-\&\fIexpose_account\fR, this can cause problems with OpenSSH if
-ChallengeResponseAuthentication is enabled, since clients may not
-recognize password prompts other than "Password:".
-.Sp
-Using this option with \fIsearch_k5login\fR would result in a password prompt
-for every principal listed in the user's \fI.k5login\fR file. This is
-probably not desired behavior, although it's not prohibited by the module.
-.Sp
-This option is only applicable to the auth and password groups. For the
-password group, it applies only to the authentication process; the user
-will still be prompted for a new password.
-.IP prompt_principal 4
-.IX Item "prompt_principal"
+.It no_prompt
+[4.6] Never prompt for the current password.
+Instead, pass in a NULL password to the Kerberos library and let the
+Kerberos library do the prompting.
+This may be needed if, for example, the Kerberos library is configured
+to use other authentication mechanisms than passwords and needs full
+control over the prompting process.
+.Pp
+The major disadvantage of this option is that it means the PAM module
+will never see the user's password and therefore cannot save it in the
+PAM module data for any subsequent modules.
+In other words, this option cannot be used if another module is in the
+stack behind the Kerberos PAM module and wants to use
+.Em use_first_pass .
+The Kerberos library also usually includes the principal in the prompt,
+and therefore this option implies behavior similar to
+.Em expose_account .
+Similar to
+.Em expose_account ,
+this can cause problems with OpenSSH if ChallengeResponseAuthentication
+is enabled, since clients may not recognize password prompts other than
+"Password:".
+.Pp
+Using this option with
+.Em search_k5login
+would result in a password prompt for every principal listed in the
+user's
+.Pa .k5login
+file.
+This is probably not desired behavior, although it's not prohibited by
+the module.
+.Pp
+This option is only applicable to the auth and password groups.
+For the password group, it applies only to the authentication process;
+the user will still be prompted for a new password.
+.It prompt_principal
[3.6] Before prompting for the user's password (or using the previously
-entered password, if \fItry_first_pass\fR, \fIuse_first_pass\fR, or
-\&\fIforce_first_pass\fR are set), prompt the user for the Kerberos principal
-to use for authentication. This allows the user to authenticate with a
-different principal than the one corresponding to the local username,
-provided that either a \fI.k5login\fR file or local Kerberos principal to
-account mapping authorize that principal to access the local account.
-.Sp
+entered password, if
+.Em try_first_pass ,
+.Em use_first_pass ,
+or
+.Em force_first_pass
+are set), prompt the user for the Kerberos principal to use for
+authentication.
+This allows the user to authenticate with a different principal than the
+one corresponding to the local username, provided that either a
+.Pa .k5login
+file or local Kerberos principal to account mapping authorize that
+principal to access the local account.
+.Pp
Be cautious when using this configuration option and don't use it with
OpenSSH PasswordAuthentication, only ChallengeResponseAuthentication.
Some PAM-enabled applications expect PAM modules to only prompt for
passwords and may even blindly give the password to the first prompt, no
-matter what it is. Such applications, in combination with this option,
-may expose the user's password in log messages and Kerberos requests.
-.IP try_first_pass 4
-.IX Item "try_first_pass"
+matter what it is.
+Such applications, in combination with this option, may expose the
+user's password in log messages and Kerberos requests.
+.It try_first_pass
[1.0] If the authentication module isn't the first on the stack, and a
previous module obtained the user's password, use that password to
-authenticate the user without prompting them again. If that
-authentication fails, fall back on prompting the user for their password.
+authenticate the user without prompting them again.
+If that authentication fails, fall back on prompting the user for their
+password.
This option has no effect if the authentication module is first in the
-stack or if no previous module obtained the user's password. Also see
-\&\fIuse_first_pass\fR and \fIforce_first_pass\fR for stronger versions of this
-option.
-.Sp
-This option is only applicable to the auth and password groups. For the
-password group, it applies only to the old password.
-.IP use_authtok 4
-.IX Item "use_authtok"
+stack or if no previous module obtained the user's password.
+Also see
+.Em use_first_pass
+and
+.Em force_first_pass
+for stronger versions of this option.
+.Pp
+This option is only applicable to the auth and password groups.
+For the password group, it applies only to the old password.
+.It use_authtok
[4.0] Use the new password obtained by a previous password module when
-changing passwords rather than prompting for the new password. If the new
-password isn't available, fail. This can be used to require passwords be
-checked by another, prior module, such as \fBpam_cracklib\fR.
-.Sp
+changing passwords rather than prompting for the new password.
+If the new password isn't available, fail.
+This can be used to require passwords be checked by another, prior
+module, such as
+.Sy pam_cracklib .
+.Pp
This option is only applicable to the password group.
-.IP use_first_pass 4
-.IX Item "use_first_pass"
+.It use_first_pass
[1.0] Use the password obtained by a previous authentication module to
-authenticate the user without prompting the user again. If no previous
-module obtained the user's password for either an authentication or
-password change, fall back on prompting the user. If a previous module
-did obtain the user's password but authentication with that password
-fails, fail without further prompting the user. Also see
-\&\fItry_first_pass\fR and \fIforce_first_pass\fR for other versions of this
-option.
-.Sp
-This option is only applicable to the auth and password groups. For the
-password group, it applies only to the old password. See \fIuse_authtok\fR
+authenticate the user without prompting the user again.
+If no previous module obtained the user's password for either an
+authentication or password change, fall back on prompting the user.
+If a previous module did obtain the user's password but authentication
+with that password fails, fail without further prompting the user.
+Also see
+.Em try_first_pass
+and
+.Em force_first_pass
+for other versions of this option.
+.Pp
+This option is only applicable to the auth and password groups.
+For the password group, it applies only to the old password.
+See
+.Em use_authtok
for a similar setting for the new password.
-.SS "Ticket Caches"
-.IX Subsection "Ticket Caches"
-.IP ccache=<pattern> 4
-.IX Item "ccache=<pattern>"
+.El
+.Ss Ticket Caches
+.Bl -tag -width Ds
+.It ccache=<pattern>
[2.0] Use <pattern> as the pattern for creating credential cache names.
<pattern> must be in the form <type>:<residual> where <type> and the
-following colon are optional if a file cache should be used. The special
-token \f(CW%u\fR, anywhere in <pattern>, is replaced with the user's numeric
-UID. The special token \f(CW%p\fR, anywhere in <pattern>, is replaced with the
-current process ID.
-.Sp
-If <pattern> ends in the literal string \f(CW\*(C`XXXXXX\*(C'\fR (six X's), that string
-will be replaced by randomly generated characters and the ticket cache
-will be created using \fBmkstemp\fR\|(3). This is strongly recommended if
-<pattern> points to a world-writable directory.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and session groups.
-.IP ccache_dir=<directory> 4
-.IX Item "ccache_dir=<directory>"
-[1.2] Store both the temporary ticket cache used during authentication and
-user ticket caches in <directory> instead of in \fI/tmp\fR. The algorithm
-for generating the ticket cache name is otherwise unchanged. <directory>
-may be prefixed with \f(CW\*(C`FILE:\*(C'\fR to make the cache type unambiguous (and this
-may be required on systems that use a cache type other than file as the
-default).
-.Sp
+following colon are optional if a file cache should be used.
+The special token
+.Qo Li %u Qc ,
+anywhere in <pattern>, is replaced with the user's numeric UID. The
+special token
+.Qo Li %p Qc ,
+anywhere in <pattern>, is replaced with the current process ID.
+.Pp
+If <pattern> ends in the literal string
+.Qo Li XXXXXX Qc
+(six X's), that string will be replaced by randomly generated characters
+and the ticket cache will be created using mkstemp(3). This is strongly
+recommended if <pattern> points to a world-writable directory.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and session groups.
+.It ccache_dir=<directory>
+[1.2] Store both the temporary ticket cache used during authentication
+and user ticket caches in <directory> instead of in
+.Pa /tmp .
+The algorithm for generating the ticket cache name is otherwise
+unchanged.
+<directory> may be prefixed with
+.Qo Li FILE: Qc
+to make the cache type unambiguous (and this may be required on systems
+that use a cache type other than file as the default).
+.Pp
Be aware that pam_krb5 creates and stores a temporary ticket cache file
-owned by root during the login process. If you set \fIccache\fR above to
-avoid using the system \fI/tmp\fR directory for user ticket caches, you may
-also want to set \fIccache_dir\fR to move those temporary caches to some
-other location. This will allow pam_krb5 to continue working even if the
-system \fI/tmp\fR directory is full.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and session groups.
-.IP no_ccache 4
-.IX Item "no_ccache"
-[1.0] Do not create a ticket cache after authentication. This option
-shouldn't be set in general, but is useful as part of the PAM
-configuration for a particular service that uses PAM for authentication
-but isn't creating user sessions and doesn't want the overhead of ever
-writing the user credentials to disk. When using this option, the
-application should only call \fBpam_authenticate()\fR; other functions like
-\&\fBpam_setcred()\fR, \fBpam_start_session()\fR, and \fBpam_acct_mgmt()\fR don't make sense
-with this option. Don't use this option if the application needs PAM
-account and session management calls.
-.Sp
+owned by root during the login process.
+If you set
+.Em ccache
+above to avoid using the system
+.Pa /tmp
+directory for user ticket caches, you may also want to set
+.Em ccache_dir
+to move those temporary caches to some other location.
+This will allow pam_krb5 to continue working even if the system
+.Pa /tmp
+directory is full.
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and session groups.
+.It no_ccache
+[1.0] Do not create a ticket cache after authentication.
+This option shouldn't be set in general, but is useful as part of the
+PAM configuration for a particular service that uses PAM for
+authentication but isn't creating user sessions and doesn't want the
+overhead of ever writing the user credentials to disk.
+When using this option, the application should only call
+.Xr pam_authenticate 3 ;
+other functions like
+.Xr pam_setcred 3 ,
+.Xr pam_start_session 3 ,
+and
+.Xr pam_acct_mgmt 3
+don't make sense with this option.
+Don't use this option if the application needs PAM account and session
+management calls.
+.Pp
This option is only applicable to the auth group.
-.IP retain_after_close 4
-.IX Item "retain_after_close"
-[2.3] Normally, the user's ticket cache is destroyed when either \fBpam_end()\fR
-or \fBpam_close_session()\fR is called by the authenticating application so that
-ticket caches aren't left behind after the user logs out. In some cases,
-however, this isn't desirable. (On Solaris 8, for instance, the default
-behavior means login will destroy the ticket cache before running the
-user's shell.) If this option is set, the PAM module will never destroy
-the user's ticket cache. If you set this, you may want to call
-\&\fBkdestroy\fR in the shell's logout configuration or run a temporary file
-removal program to avoid accumulating hundreds of ticket caches in
-\&\fI/tmp\fR.
-.Sp
-This option can be set in \f(CW\*(C`[appdefaults]\*(C'\fR in \fIkrb5.conf\fR and is only
-applicable to the auth and session groups.
-.SH ENVIRONMENT
-.IX Header "ENVIRONMENT"
-.IP KRB5CCNAME 4
-.IX Item "KRB5CCNAME"
-Set by \fBpam_setcred()\fR with the PAM_ESTABLISH_CRED option, and therefore
-also by \fBpam_open_session()\fR, to point to the new credential cache for the
-user. See the \fIccache\fR and \fIccache_dir\fR options. By default, the cache
-name will be prefixed with \f(CW\*(C`FILE:\*(C'\fR to make the cache type unambiguous.
-.IP PAM_KRB5CCNAME 4
-.IX Item "PAM_KRB5CCNAME"
-Set by \fBpam_authenticate()\fR to point to the temporary ticket cache used for
-authentication (unless the \fIno_ccache\fR option was given). \fBpam_setcred()\fR
-then uses that environment variable to locate the temporary cache even if
-it was not called in the same PAM session as \fBpam_authenticate()\fR (a problem
-with \fBsshd\fR running in some modes). This environment variable is only
-used internal to the PAM module.
-.SH FILES
-.IX Header "FILES"
-.IP \fI/tmp/krb5cc_UID_RANDOM\fR 4
-.IX Item "/tmp/krb5cc_UID_RANDOM"
-The default credential cache name. UID is the decimal UID of the local
-user and RANDOM is a random six-character string. The pattern may be
-changed with the \fIccache\fR option and the directory with the \fIccache_dir\fR
+.It retain_after_close
+[2.3] Normally, the user's ticket cache is destroyed when either
+.Xr pam_end 3
+or
+.Xr pam_close_session 3
+is called by the authenticating application so that ticket caches aren't
+left behind after the user logs out.
+In some cases, however, this isn't desirable.
+(On Solaris 8, for instance, the default behavior means login will
+destroy the ticket cache before running the user's shell.)
+If this option is set, the PAM module will never destroy the user's
+ticket cache.
+If you set this, you may want to call
+.Sy kdestroy
+in the shell's logout configuration or run a temporary file removal
+program to avoid accumulating hundreds of ticket caches in
+.Pa /tmp .
+.Pp
+This option can be set in
+.Qo Li [appdefaults] Qc
+in
+.Pa krb5.conf
+and is only applicable to the auth and session groups.
+.El
+.Sh ENVIRONMENT
+.Bl -tag -width Ds
+.It KRB5CCNAME
+Set by
+.Xr pam_setcred 3
+with the PAM_ESTABLISH_CRED option, and therefore also by
+.Xr pam_open_session 3 ,
+to point to the new credential cache for the user.
+See the
+.Em ccache
+and
+.Em ccache_dir
+options.
+By default, the cache name will be prefixed with
+.Qo Li FILE: Qc
+to make the cache type unambiguous.
+.It PAM_KRB5CCNAME
+Set by
+.Xr pam_authenticate 3
+to point to the temporary ticket cache used for authentication (unless
+the
+.Em no_ccache
+option was given).
+.Xr pam_setcred 3
+then uses that environment variable to locate the temporary cache even
+if it was not called in the same PAM session as
+.Xr pam_authenticate 3
+(a problem with
+.Sy sshd
+running in some modes).
+This environment variable is only used internal to the PAM module.
+.El
+.Sh FILES
+.Bl -tag -width Ds
+.It Pa /tmp/krb5cc_UID_RANDOM
+The default credential cache name.
+UID is the decimal UID of the local user and RANDOM is a random
+six-character string.
+The pattern may be changed with the
+.Em ccache
+option and the directory with the
+.Em ccache_dir
option.
-.IP \fI/tmp/krb5cc_pam_RANDOM\fR 4
-.IX Item "/tmp/krb5cc_pam_RANDOM"
-The credential cache name used for the temporary credential cache created
-by \fBpam_authenticate()\fR. This cache is removed again when the PAM session
-is ended or when \fBpam_setcred()\fR is called and will normally not be
-user-visible. RANDOM is a random six-character string.
-.IP \fI~/.k5login\fR 4
-.IX Item "~/.k5login"
+.It Pa /tmp/krb5cc_pam_RANDOM
+The credential cache name used for the temporary credential cache
+created by
+.Xr pam_authenticate 3 .
+This cache is removed again when the PAM session is ended or when
+.Xr pam_setcred 3
+is called and will normally not be user-visible.
+RANDOM is a random six-character string.
+.It Pa ~/.k5login
File containing Kerberos principals that are allowed access to that
account.
-.SH BUGS
-.IX Header "BUGS"
-If \fItry_pkinit\fR is set and pam\-krb5 is built with MIT Kerberos, the
-user's password is not saved in the PAM data if PKINIT fails and the
-module falls back to password authentication.
-.SH CAVEATS
-.IX Header "CAVEATS"
-Be sure to list this module in the session group as well as the auth group
-when using it for interactive logins. Otherwise, some applications (such
-as OpenSSH) will not set up the user's ticket cache correctly.
-.PP
-The Kerberos library, via pam\-krb5, will prompt the user to change their
+.El
+.Sh BUGS
+If
+.Em try_pkinit
+is set and pam-krb5 is built with MIT Kerberos, the user's password is
+not saved in the PAM data if PKINIT fails and the module falls back to
+password authentication.
+.Sh CAVEATS
+Be sure to list this module in the session group as well as the auth
+group when using it for interactive logins.
+Otherwise, some applications (such as OpenSSH) will not set up the
+user's ticket cache correctly.
+.Pp
+The Kerberos library, via pam-krb5, will prompt the user to change their
password if their password is expired, but when using OpenSSH, this will
-only work when ChallengeResponseAuthentication is enabled. Unless this
-option is enabled, OpenSSH doesn't pass PAM messages to the user and can
-only respond to a simple password prompt.
-.PP
+only work when ChallengeResponseAuthentication is enabled.
+Unless this option is enabled, OpenSSH doesn't pass PAM messages to the
+user and can only respond to a simple password prompt.
+.Pp
If you are using MIT Kerberos, be aware that users whose passwords are
expired will not be prompted to change their password unless the KDC
configuration for your realm in [realms] in krb5.conf contains a
-master_kdc setting or, if using DNS SRV records, you have a DNS entry for
-_kerberos\-master as well as _kerberos.
-.PP
-\&\fBpam_authenticate()\fR returns failure when called for an ignored account,
-requiring the system administrator to use \f(CW\*(C`optional\*(C'\fR or \f(CW\*(C`sufficient\*(C'\fR to
-ignore the module and move on to the next module. It's arguably more
-correct to return PAM_IGNORE, which causes the module to be ignored as if
-it weren't in the configuration, but this increases the risk of
-inadvertent security holes when listing pam\-krb5 as the only
+master_kdc setting or, if using DNS SRV records, you have a DNS entry
+for _kerberos-master as well as _kerberos.
+.Pp
+.Xr pam_authenticate 3
+returns failure when called for an ignored account, requiring the system
+administrator to use
+.Qo Li optional Qc
+or
+.Qo Li sufficient Qc
+to ignore the module and move on to the next module.
+It's arguably more correct to return PAM_IGNORE, which causes the module
+to be ignored as if it weren't in the configuration, but this increases
+the risk of inadvertent security holes when listing pam-krb5 as the only
authentication module.
-.PP
+.Pp
This module treats the empty password as an authentication failure
rather than attempting to use that password to avoid unwanted prompting
-behavior in the Kerberos libraries. If you have a Kerberos principal that
-intentionally has an empty password, it won't work with this module.
-.PP
+behavior in the Kerberos libraries.
+If you have a Kerberos principal that intentionally has an empty
+password, it won't work with this module.
+.Pp
This module will not refresh an existing ticket cache if called with an
-effective UID or GID different than the real UID or GID, since refreshing
-an existing ticket cache requires trusting the KRB5CCNAME environment
-variable and the environment should not be trusted in a setuid context.
-.PP
+effective UID or GID different than the real UID or GID, since
+refreshing an existing ticket cache requires trusting the KRB5CCNAME
+environment variable and the environment should not be trusted in a
+setuid context.
+.Pp
Old versions of OpenSSH are known to call pam_authenticate followed by
-pam_setcred(PAM_REINITIALIZE_CRED) without first calling pam_open_session,
-thereby requesting that an existing ticket cache be renewed (similar to
-what a screensaver would want) rather than requesting a new ticket cache
-be created. Since this behavior is indistinguishable at the PAM level
-from a screensaver, pam\-krb5 when used with these old versions of OpenSSH
-will refresh the ticket cache of the OpenSSH daemon rather than setting up
-a new ticket cache for the user. The resulting ticket cache will have the
-correct permissions, but will not be named correctly or referenced in the
-user's environment and will be overwritten by the next user login. The
-best solution to this problem is to upgrade OpenSSH. I'm not sure exactly
-when this problem was fixed, but at the very least OpenSSH 4.3 and later
-do not exhibit it.
-.SH AUTHOR
-.IX Header "AUTHOR"
-pam\-krb5 was originally written by Frank Cusack. Andres Salomon made
-extensive modifications, and then Russ Allbery <eagle@eyrie.org> adopted
-it and made even more extensive modifications. Russ Allbery currently
-maintains the module.
-.SH "COPYRIGHT AND LICENSE"
-.IX Header "COPYRIGHT AND LICENSE"
-Copyright 2005\-2010, 2014, 2020 Russ Allbery <eagle@eyrie.org>
-.PP
-Copyright 2008\-2014 The Board of Trustees of the Leland Stanford Junior
+pam_setcred(PAM_REINITIALIZE_CRED) without first calling
+pam_open_session, thereby requesting that an existing ticket cache be
+renewed (similar to what a screensaver would want) rather than
+requesting a new ticket cache be created.
+Since this behavior is indistinguishable at the PAM level from a
+screensaver, pam-krb5 when used with these old versions of OpenSSH will
+refresh the ticket cache of the OpenSSH daemon rather than setting up a
+new ticket cache for the user.
+The resulting ticket cache will have the correct permissions, but will
+not be named correctly or referenced in the user's environment and will
+be overwritten by the next user login.
+The best solution to this problem is to upgrade OpenSSH. I'm not sure
+exactly when this problem was fixed, but at the very least OpenSSH 4.3
+and later do not exhibit it.
+.Sh AUTHOR
+pam-krb5 was originally written by Frank Cusack.
+Andres Salomon made extensive modifications, and then Russ Allbery
+<eagle@eyrie.org> adopted it and made even more extensive modifications.
+Russ Allbery currently maintains the module.
+.Sh COPYRIGHT AND LICENSE
+Copyright 2005-2010, 2014, 2020 Russ Allbery <eagle@eyrie.org>
+.Pp
+Copyright 2008-2014 The Board of Trustees of the Leland Stanford Junior
University
-.PP
+.Pp
Copying and distribution of this file, with or without modification, are
-permitted in any medium without royalty provided the copyright notice and
-this notice are preserved. This file is offered as-is, without any
-warranty.
-.PP
+permitted in any medium without royalty provided the copyright notice
+and this notice are preserved.
+This file is offered as-is, without any warranty.
+.Pp
SPDX-License-Identifier: FSFAP
-.SH "SEE ALSO"
-.IX Header "SEE ALSO"
-\&\fBkadmin\fR\|(8), \fBkdestroy\fR\|(1), \fBkrb5.conf\fR\|(5), \fBpam\fR\|(7), \fBpasswd\fR\|(1), \fBsyslog\fR\|(3)
-.PP
+.Sh SEE ALSO
+kadmin(8), kdestroy(1), krb5.conf(5), pam.conf(5), passwd(1), syslog(3)
+.Pp
The current version of this module is available from its web page at
-<https://www.eyrie.org/~eagle/software/pam\-krb5/>.
+.Lk https://www.eyrie.org/~eagle/software/pam-krb5/ .
diff --git a/lib/libpam/modules/pam_ksu/Makefile b/lib/libpam/modules/pam_ksu/Makefile
index 953ca23d1416..8b695384c13c 100644
--- a/lib/libpam/modules/pam_ksu/Makefile
+++ b/lib/libpam/modules/pam_ksu/Makefile
@@ -27,9 +27,10 @@ PACKAGE= kerberos
.include <src.opts.mk>
-LIB= pam_ksu
-SRCS= pam_ksu.c
-MAN= pam_ksu.8
+LIB= pam_ksu
+SRCS= pam_ksu.c
+MANNODEV= pam_ksu.8
+
WARNS?= 3
LIBADD+= krb5
diff --git a/lib/libpam/modules/pam_lastlog/Makefile b/lib/libpam/modules/pam_lastlog/Makefile
index 1abf6f2b6304..9d27f4779184 100644
--- a/lib/libpam/modules/pam_lastlog/Makefile
+++ b/lib/libpam/modules/pam_lastlog/Makefile
@@ -23,10 +23,8 @@
# SUCH DAMAGE.
#
-PACKAGE= runtime
-
-LIB= pam_lastlog
-SRCS= pam_lastlog.c
-MAN= pam_lastlog.8
+LIB= pam_lastlog
+SRCS= pam_lastlog.c
+MANNODEV= pam_lastlog.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_login_access/Makefile b/lib/libpam/modules/pam_login_access/Makefile
index 43c025336354..e31866395a94 100644
--- a/lib/libpam/modules/pam_login_access/Makefile
+++ b/lib/libpam/modules/pam_login_access/Makefile
@@ -23,10 +23,8 @@
# SUCH DAMAGE.
#
-PACKAGE= runtime
-
-LIB= pam_login_access
-SRCS= pam_login_access.c login_access.c
-MAN= login.access.5 pam_login_access.8
+LIB= pam_login_access
+SRCS= pam_login_access.c login_access.c
+MANNODEV= login.access.5 pam_login_access.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_nologin/Makefile b/lib/libpam/modules/pam_nologin/Makefile
index e4c3c5a35c1e..38c9ea2b0a2a 100644
--- a/lib/libpam/modules/pam_nologin/Makefile
+++ b/lib/libpam/modules/pam_nologin/Makefile
@@ -23,11 +23,9 @@
# SUCH DAMAGE.
#
-PACKAGE= runtime
-
-LIB= pam_nologin
-SRCS= pam_nologin.c
-MAN= pam_nologin.8
+LIB= pam_nologin
+SRCS= pam_nologin.c
+MANNODEV= pam_nologin.8
LIBADD+= util
diff --git a/lib/libpam/modules/pam_passwdqc/Makefile b/lib/libpam/modules/pam_passwdqc/Makefile
index 91ce72928a66..9f2091d5403e 100644
--- a/lib/libpam/modules/pam_passwdqc/Makefile
+++ b/lib/libpam/modules/pam_passwdqc/Makefile
@@ -1,9 +1,9 @@
SRCDIR= ${SRCTOP}/contrib/pam_modules/pam_passwdqc
.PATH: ${SRCDIR}
-LIB= pam_passwdqc
-SRCS= pam_passwdqc.c passwdqc_check.c passwdqc_random.c wordset_4k.c
-MAN= pam_passwdqc.8
+LIB= pam_passwdqc
+SRCS= pam_passwdqc.c passwdqc_check.c passwdqc_random.c wordset_4k.c
+MANNODEV= pam_passwdqc.8
WARNS?= 2
CFLAGS+= -I${SRCDIR}
diff --git a/lib/libpam/modules/pam_permit/Makefile b/lib/libpam/modules/pam_permit/Makefile
index 5606fe1cf75a..cc3d9ca210f2 100644
--- a/lib/libpam/modules/pam_permit/Makefile
+++ b/lib/libpam/modules/pam_permit/Makefile
@@ -23,8 +23,8 @@
# SUCH DAMAGE.
#
-LIB= pam_permit
-SRCS= pam_permit.c
-MAN= pam_permit.8
+LIB= pam_permit
+SRCS= pam_permit.c
+MANNODEV= pam_permit.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_radius/Makefile b/lib/libpam/modules/pam_radius/Makefile
index ab39fedcee04..d1180af62324 100644
--- a/lib/libpam/modules/pam_radius/Makefile
+++ b/lib/libpam/modules/pam_radius/Makefile
@@ -23,9 +23,10 @@
# SUCH DAMAGE.
#
-LIB= pam_radius
-SRCS= pam_radius.c
-MAN= pam_radius.8
+LIB= pam_radius
+SRCS= pam_radius.c
+MANNODEV= pam_radius.8
+
WARNS?= 3
LIBADD+= radius
diff --git a/lib/libpam/modules/pam_rhosts/Makefile b/lib/libpam/modules/pam_rhosts/Makefile
index 4cd25fe5dfa5..3aaefc9ca89b 100644
--- a/lib/libpam/modules/pam_rhosts/Makefile
+++ b/lib/libpam/modules/pam_rhosts/Makefile
@@ -1,5 +1,5 @@
-LIB= pam_rhosts
-SRCS= pam_rhosts.c
-MAN= pam_rhosts.8
+LIB= pam_rhosts
+SRCS= pam_rhosts.c
+MANNODEV= pam_rhosts.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_rootok/Makefile b/lib/libpam/modules/pam_rootok/Makefile
index 668eeef7f7d9..bb5889139c16 100644
--- a/lib/libpam/modules/pam_rootok/Makefile
+++ b/lib/libpam/modules/pam_rootok/Makefile
@@ -23,8 +23,8 @@
# SUCH DAMAGE.
#
-LIB= pam_rootok
-SRCS= pam_rootok.c
-MAN= pam_rootok.8
+LIB= pam_rootok
+SRCS= pam_rootok.c
+MANNODEV= pam_rootok.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_securetty/Makefile b/lib/libpam/modules/pam_securetty/Makefile
index 3a36a37b543c..90740721a3f5 100644
--- a/lib/libpam/modules/pam_securetty/Makefile
+++ b/lib/libpam/modules/pam_securetty/Makefile
@@ -23,10 +23,8 @@
# SUCH DAMAGE.
#
-PACKAGE= runtime
-
-LIB= pam_securetty
-SRCS= pam_securetty.c
-MAN= pam_securetty.8
+LIB= pam_securetty
+SRCS= pam_securetty.c
+MANNODEV= pam_securetty.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_self/Makefile b/lib/libpam/modules/pam_self/Makefile
index 0a58728fea52..8a6b3702b5a1 100644
--- a/lib/libpam/modules/pam_self/Makefile
+++ b/lib/libpam/modules/pam_self/Makefile
@@ -23,10 +23,8 @@
# SUCH DAMAGE.
#
-PACKAGE= runtime
-
-LIB= pam_self
-SRCS= pam_self.c
-MAN= pam_self.8
+LIB= pam_self
+SRCS= pam_self.c
+MANNODEV= pam_self.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_ssh/Makefile b/lib/libpam/modules/pam_ssh/Makefile
index 6652244a84af..eb817b559331 100644
--- a/lib/libpam/modules/pam_ssh/Makefile
+++ b/lib/libpam/modules/pam_ssh/Makefile
@@ -2,11 +2,12 @@
SSHDIR= ${SRCTOP}/crypto/openssh
-LIB= pam_ssh
-MAN= pam_ssh.8
-SRCS= pam_ssh.c
PACKAGE= ssh
+LIB= pam_ssh
+MANNODEV= pam_ssh.8
+SRCS= pam_ssh.c
+
WARNS?= 5
CFLAGS+= -I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/lib/libpam/modules/pam_tacplus/Makefile b/lib/libpam/modules/pam_tacplus/Makefile
index 2b558d9f72b3..a29185f9bc23 100644
--- a/lib/libpam/modules/pam_tacplus/Makefile
+++ b/lib/libpam/modules/pam_tacplus/Makefile
@@ -23,9 +23,9 @@
# SUCH DAMAGE.
#
-LIB= pam_tacplus
-SRCS= pam_tacplus.c
-MAN= pam_tacplus.8
+LIB= pam_tacplus
+SRCS= pam_tacplus.c
+MANNODEV= pam_tacplus.8
LIBADD+= tacplus
diff --git a/lib/libpam/modules/pam_unix/Makefile b/lib/libpam/modules/pam_unix/Makefile
index 2e76f054c502..124a757eae9d 100644
--- a/lib/libpam/modules/pam_unix/Makefile
+++ b/lib/libpam/modules/pam_unix/Makefile
@@ -36,11 +36,9 @@
.include <src.opts.mk>
.include <bsd.init.mk>
-PACKAGE= runtime
-
-LIB= pam_unix
-SRCS= pam_unix.c
-MAN= pam_unix.8
+LIB= pam_unix
+SRCS= pam_unix.c
+MANNODEV= pam_unix.8
LIBADD+= util crypt
diff --git a/lib/libpam/modules/pam_xdg/Makefile b/lib/libpam/modules/pam_xdg/Makefile
index df3948987da6..e119354d1297 100644
--- a/lib/libpam/modules/pam_xdg/Makefile
+++ b/lib/libpam/modules/pam_xdg/Makefile
@@ -1,5 +1,5 @@
-LIB= pam_xdg
-SRCS= pam_xdg.c
-MAN= pam_xdg.8
+LIB= pam_xdg
+SRCS= pam_xdg.c
+MANNODEV= pam_xdg.8
.include <bsd.lib.mk>
diff --git a/lib/libpam/modules/pam_xdg/pam_xdg.8 b/lib/libpam/modules/pam_xdg/pam_xdg.8
index 9b335751a9fb..031010953e98 100644
--- a/lib/libpam/modules/pam_xdg/pam_xdg.8
+++ b/lib/libpam/modules/pam_xdg/pam_xdg.8
@@ -50,7 +50,6 @@ Use an alternate base directory
.Bl -tag -width indent
.It Ev XDG_RUNTIME_DIR
The location of the runtime files base directory created by this module.
-Note that the module does not set this environment variable.
.El
.Sh STANDARDS
The directory created by this module conforms to the
diff --git a/lib/libpam/pam.d/Makefile b/lib/libpam/pam.d/Makefile
index a58c37b6c223..2cc5122b2ecc 100644
--- a/lib/libpam/pam.d/Makefile
+++ b/lib/libpam/pam.d/Makefile
@@ -1,7 +1,5 @@
.include <src.opts.mk>
-PACKAGE= runtime
-
NO_OBJ=
CONFGROUPS= CONFS
@@ -17,20 +15,16 @@ CONFDIR= /etc/pam.d
CONFSMODE_README= 444
CONFGROUPS+= CRON
-CRON+= cron
+CRON= cron
CRONPACKAGE= cron
-.if ${MK_AT} != "no"
-CONFGROUPS+= AT
-AT+= atrun
-ATPACKAGE+= at
-.endif
+CONFGROUPS.${MK_AT}+= AT
+AT= atrun
+ATPACKAGE= at
-.if ${MK_FTP} != "no"
-CONFGROUPS+= FTP
-FTP+= ftp ftpd
+CONFGROUPS.${MK_FTP}+= FTP
+FTP= ftp ftpd
# Do not put these in the ftp package, since ports also use them.
-FTPPACKAGE= runtime
-.endif
+FTPPACKAGE= pam
.include <bsd.prog.mk>
diff --git a/lib/libpam/static_libpam/Makefile b/lib/libpam/static_libpam/Makefile
index a1f0f209dea1..703e6a4a2f00 100644
--- a/lib/libpam/static_libpam/Makefile
+++ b/lib/libpam/static_libpam/Makefile
@@ -42,8 +42,10 @@ NO_PIC=
# Avoid redundancy with the master Makefile.
MAN=
+MANNODEV=
INCS=
MLINKS=
+MANNODEVLINKS=
MK_TESTS= no
#
diff --git a/lib/libpcap/Makefile b/lib/libpcap/Makefile
index 9ba91504852b..c4bd175b502a 100644
--- a/lib/libpcap/Makefile
+++ b/lib/libpcap/Makefile
@@ -109,10 +109,11 @@ MAN= pcap.3 \
pcap_strerror.3 \
pcap_tstamp_type_name_to_val.3 \
pcap_tstamp_type_val_to_name.3 \
- pcap-savefile.5 \
- pcap-filter.7 \
- pcap-linktype.7 \
- pcap-tstamp.7
+ pcap-savefile.5
+
+MANNODEV= pcap-filter.7 \
+ pcap-linktype.7 \
+ pcap-tstamp.7
MLINKS= \
pcap_datalink_val_to_name.3 pcap_datalink_val_to_description.3 \
@@ -129,7 +130,7 @@ MLINKS= \
pcap_setnonblock.3 pcap_getnonblock.3
# Our man pages are a special copy from the distdir. See below.
-CLEANFILES+=${MAN}
+CLEANFILES+=${MAN} ${MANNODEV}
CLEANFILES+=grammar.y scanner.h tokdefs.h
YFLAGS+=-p pcap_
@@ -175,7 +176,7 @@ tokdefs.h: grammar.h .NOMETA
#
# Magic to convert the man pages to something non Solarish
#
-.for _page in ${MAN}
+.for _page in ${MAN} ${MANNODEV}
${_page}:
if [ -f ${PCAP_DISTDIR}/${_page:S/3$/3pcap/} ]; then \
F=${_page:S/3$/3pcap/}; \
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 190ee46baf21..3db596d6fd38 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -76,7 +76,6 @@ pfctl_open(const char *pf_device)
struct pfctl_handle *h;
h = calloc(1, sizeof(struct pfctl_handle));
- h->fd = -1;
h->fd = open(pf_device, O_RDWR);
if (h->fd < 0)
@@ -87,7 +86,8 @@ pfctl_open(const char *pf_device)
return (h);
error:
- close(h->fd);
+ if (h->fd != -1)
+ close(h->fd);
snl_free(&h->ss);
free(h);
@@ -391,6 +391,8 @@ static const struct snl_attr_parser ap_getstatus[] = {
{ .type = PF_GS_CHKSUM, .off = _OUT(pf_chksum), .arg_u32 = PF_MD5_DIGEST_LENGTH, .cb = snl_attr_get_bytes },
{ .type = PF_GS_BCOUNTERS, .off = _OUT(bcounters), .arg_u32 = 2 * 2, .cb = snl_attr_get_uint64_array },
{ .type = PF_GS_PCOUNTERS, .off = _OUT(pcounters), .arg_u32 = 2 * 2 * 2, .cb = snl_attr_get_uint64_array },
+ { .type = PF_GS_NCOUNTERS, .off = _OUT(ncounters), .cb = snl_attr_get_counters },
+ { .type = PF_GS_FRAGMENTS, .off = _OUT(fragments), .cb = snl_attr_get_uint64 },
};
SNL_DECLARE_PARSER(getstatus_parser, struct genlmsghdr, snl_f_p_empty, ap_getstatus);
#undef _OUT
@@ -429,6 +431,7 @@ pfctl_get_status_h(struct pfctl_handle *h)
TAILQ_INIT(&status->lcounters);
TAILQ_INIT(&status->fcounters);
TAILQ_INIT(&status->scounters);
+ TAILQ_INIT(&status->ncounters);
while ((hdr = snl_read_reply_multi(&h->ss, seq_id, &e)) != NULL) {
if (! snl_parse_nlmsg(&h->ss, hdr, &getstatus_parser, status))
@@ -558,6 +561,10 @@ pfctl_free_status(struct pfctl_status *status)
free(c->name);
free(c);
}
+ TAILQ_FOREACH_SAFE(c, &status->ncounters, entry, tmp) {
+ free(c->name);
+ free(c);
+ }
free(status);
}
@@ -1484,7 +1491,7 @@ snl_attr_get_pf_rule_labels(struct snl_state *ss, struct nlattr *nla,
bool ret;
if (l->i >= PF_RULE_MAX_LABEL_COUNT)
- return (E2BIG);
+ return (false);
ret = snl_attr_copy_string(ss, nla, (void *)PF_RULE_LABEL_SIZE,
l->labels[l->i]);
@@ -1554,7 +1561,7 @@ snl_attr_get_pf_timeout(struct snl_state *ss, struct nlattr *nla,
bool ret;
if (t->i >= PFTM_MAX)
- return (E2BIG);
+ return (false);
ret = snl_attr_get_uint32(ss, nla, NULL, &t->timeouts[t->i]);
if (ret)
@@ -1696,6 +1703,7 @@ static struct snl_attr_parser ap_getrule[] = {
{ .type = PF_RT_MAX_PKT_SIZE, .off =_OUT(r.max_pkt_size), .cb = snl_attr_get_uint16 },
{ .type = PF_RT_TYPE_2, .off = _OUT(r.type), .cb = snl_attr_get_uint16 },
{ .type = PF_RT_CODE_2, .off = _OUT(r.code), .cb = snl_attr_get_uint16 },
+ { .type = PF_RT_EXPTIME, .off = _OUT(r.exptime), .cb = snl_attr_get_time_t },
};
#undef _OUT
SNL_DECLARE_PARSER(getrule_parser, struct genlmsghdr, snl_f_p_empty, ap_getrule);
@@ -2589,6 +2597,101 @@ pfctl_table_del_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pf
return (ret);
}
+struct pfctl_change {
+ int add;
+ int del;
+ int change;
+};
+#define _OUT(_field) offsetof(struct pfctl_change, _field)
+static struct snl_attr_parser ap_table_set_addr[] = {
+ { .type = PF_TA_NBR_ADDED, .off = _OUT(add), .cb = snl_attr_get_uint32 },
+ { .type = PF_TA_NBR_DELETED, .off = _OUT(del), .cb = snl_attr_get_uint32 },
+ { .type = PF_TA_NBR_CHANGED, .off = _OUT(change), .cb = snl_attr_get_uint32 },
+};
+#undef _OUT
+SNL_DECLARE_PARSER(table_set_addr_parser, struct genlmsghdr, snl_f_p_empty, ap_table_set_addr);
+
+static int
+_pfctl_table_set_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr
+ *addrs, int size, int *nadd, int *ndel, int *nchange, int flags)
+{
+ struct snl_writer nw;
+ struct snl_errmsg_data e = {};
+ struct nlmsghdr *hdr;
+ struct pfctl_change change = { 0 };
+ uint32_t seq_id;
+ int family_id;
+
+ family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
+ if (family_id == 0)
+ return (ENOTSUP);
+
+ snl_init_writer(&h->ss, &nw);
+ hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_TABLE_SET_ADDR);
+
+ snl_add_msg_attr_table(&nw, PF_TA_TABLE, tbl);
+ snl_add_msg_attr_u32(&nw, PF_TA_FLAGS, flags);
+ for (int i = 0; i < size; i++)
+ snl_add_msg_attr_pfr_addr(&nw, PF_TA_ADDR, &addrs[i]);
+
+ if ((hdr = snl_finalize_msg(&nw)) == NULL)
+ return (ENXIO);
+ seq_id = hdr->nlmsg_seq;
+
+ if (! snl_send_message(&h->ss, hdr))
+ return (ENXIO);
+
+ while ((hdr = snl_read_reply_multi(&h->ss, seq_id, &e)) != NULL) {
+ if (! snl_parse_nlmsg(&h->ss, hdr, &table_set_addr_parser, &change))
+ continue;
+ }
+
+ if (nadd)
+ *nadd = change.add;
+ if (ndel)
+ *ndel = change.del;
+ if (nchange)
+ *nchange = change.change;
+
+ return (e.error);
+}
+
+int
+pfctl_table_set_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
+ struct pfr_addr *addr, int size, int *nadd, int *ndel,
+ int *nchange, int flags)
+{
+ int ret;
+ int off = 0;
+ int partial_add, partial_del, partial_change;
+ int chunk_size;
+
+ do {
+ flags &= ~(PFR_FLAG_START | PFR_FLAG_DONE);
+ if (off == 0)
+ flags |= PFR_FLAG_START;
+ chunk_size = MIN(size - off, 256);
+ if ((chunk_size + off) == size)
+ flags |= PFR_FLAG_DONE;
+ ret = _pfctl_table_set_addrs_h(h, tbl, &addr[off], chunk_size,
+ &partial_add, &partial_del, &partial_change, flags);
+ if (ret != 0)
+ break;
+ if (! (flags & PFR_FLAG_DONE)) {
+ assert(partial_del == 0);
+ }
+ if (nadd)
+ *nadd += partial_add;
+ if (ndel)
+ *ndel += partial_del;
+ if (nchange)
+ *nchange += partial_change;
+ off += chunk_size;
+ } while (off < size);
+
+ return (ret);
+}
+
int
pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
*addr, int size, int *size2, int *nadd, int *ndel, int *nchange, int flags)
@@ -2639,6 +2742,88 @@ int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr *addr,
return (0);
}
+struct nl_addrs {
+ size_t max;
+ struct pfr_addr *addrs;
+ size_t count;
+ size_t total_count;
+};
+
+#define _OUT(_field) offsetof(struct pfr_addr, _field)
+static const struct snl_attr_parser ap_pfr_addr[] = {
+ { .type = PFR_A_AF, .off = _OUT(pfra_af), .cb = snl_attr_get_uint32 },
+ { .type = PFR_A_NET, .off = _OUT(pfra_net), .cb = snl_attr_get_uint8 },
+ { .type = PFR_A_NOT, .off = _OUT(pfra_not), .cb = snl_attr_get_bool },
+ { .type = PFR_A_ADDR, .off = _OUT(pfra_ip6addr), .cb = snl_attr_get_in6_addr },
+};
+#undef _OUT
+SNL_DECLARE_ATTR_PARSER(pfr_addr_parser, ap_pfr_addr);
+
+static bool
+snl_attr_get_pfr_addrs(struct snl_state *ss, struct nlattr *nla,
+ const void *arg __unused, void *target)
+{
+ struct nl_addrs *a = (struct nl_addrs *)target;
+ bool ret;
+
+ if (a->count >= a->max)
+ return (false);
+
+ ret = snl_parse_header(ss, NLA_DATA(nla), NLA_DATA_LEN(nla),
+ &pfr_addr_parser, &a->addrs[a->count]);
+ if (ret)
+ a->count++;
+
+ return (ret);
+}
+
+#define _OUT(_field) offsetof(struct nl_addrs, _field)
+static struct snl_attr_parser ap_table_get_addr[] = {
+ { .type = PF_TA_ADDR, .off = 0, .cb = snl_attr_get_pfr_addrs },
+ { .type = PF_TA_ADDR_COUNT, .off = _OUT(total_count), .cb = snl_attr_get_uint32 },
+};
+#undef _OUT
+SNL_DECLARE_PARSER(table_get_addr_parser, struct genlmsghdr, snl_f_p_empty, ap_table_get_addr);
+int
+pfctl_table_get_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
+ struct pfr_addr *addr, int *size, int flags)
+{
+ struct nl_addrs addrs = { 0 };
+ struct snl_writer nw;
+ struct snl_errmsg_data e = {};
+ struct nlmsghdr *hdr;
+ uint32_t seq_id;
+ int family_id;
+
+ family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
+ if (family_id == 0)
+ return (ENOTSUP);
+
+ snl_init_writer(&h->ss, &nw);
+ hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_TABLE_GET_ADDR);
+
+ snl_add_msg_attr_table(&nw, PF_TA_TABLE, tbl);
+ snl_add_msg_attr_u32(&nw, PF_TA_FLAGS, flags);
+
+ if ((hdr = snl_finalize_msg(&nw)) == NULL)
+ return (ENXIO);
+
+ seq_id = hdr->nlmsg_seq;
+ if (! snl_send_message(&h->ss, hdr))
+ return (ENXIO);
+
+ addrs.addrs = addr;
+ addrs.max = *size;
+ while ((hdr = snl_read_reply_multi(&h->ss, seq_id, &e)) != NULL) {
+ if (! snl_parse_nlmsg(&h->ss, hdr, &table_get_addr_parser, &addrs))
+ continue;
+ }
+
+ *size = addrs.total_count;
+
+ return (e.error);
+}
+
int
pfctl_set_statusif(struct pfctl_handle *h, const char *ifname)
{
@@ -3194,6 +3379,9 @@ pfctl_get_ruleset(struct pfctl_handle *h, const char *path, uint32_t nr, struct
continue;
}
+ rs->nr = nr;
+ strlcpy(rs->path, path, sizeof(rs->path));
+
return (e.error);
}
diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h
index da16d5179ec0..a5b7e1c23bd0 100644
--- a/lib/libpfctl/libpfctl.h
+++ b/lib/libpfctl/libpfctl.h
@@ -62,6 +62,8 @@ struct pfctl_status {
struct pfctl_status_counters lcounters;
struct pfctl_status_counters fcounters;
struct pfctl_status_counters scounters;
+ struct pfctl_status_counters ncounters;
+ uint64_t fragments;
uint64_t pcounters[2][2][2];
uint64_t bcounters[2][2];
};
@@ -283,6 +285,8 @@ struct pfctl_rule {
struct pf_addr addr;
uint16_t port;
} divert;
+
+ time_t exptime;
};
TAILQ_HEAD(pfctl_rulequeue, pfctl_rule);
@@ -519,9 +523,14 @@ int pfctl_table_del_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
struct pfr_addr *addr, int size, int *ndel, int flags);
int pfctl_table_del_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
*addr, int size, int *ndel, int flags);
-int pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
+int pfctl_table_set_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
+ struct pfr_addr *addr, int size, int *nadd, int *ndel,
+ int *nchange, int flags);
+int pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
*addr, int size, int *size2, int *nadd, int *ndel, int *nchange,
int flags);
+int pfctl_table_get_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr *addr,
+ int *size, int flags);
int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
*addr, int *size, int flags);
int pfctl_set_statusif(struct pfctl_handle *h, const char *ifname);
diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile
index 8728b0c1c76d..590f719ebff4 100644
--- a/lib/libpmc/Makefile
+++ b/lib/libpmc/Makefile
@@ -1,5 +1,5 @@
-LIB_CXX= pmc
-
+PACKAGE=pmc
+LIB_CXX=pmc
SRCS= libpmc.c pmclog.c libpmc_pmu_util.c libpmc_json.cc
INCS= pmc.h pmclog.h pmcformat.h
diff --git a/lib/libproc/Makefile b/lib/libproc/Makefile
index 785007188255..670c4399f63e 100644
--- a/lib/libproc/Makefile
+++ b/lib/libproc/Makefile
@@ -19,10 +19,11 @@ LIBADD+= cxxrt elf procstat rtld_db util z
LIBADD+= ctf
IGNORE_PRAGMA= YES
CFLAGS+= -DIN_BASE
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/include
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/
-CFLAGS+= -I${SRCTOP}/sys/contrib/openzfs/lib/libspl/include/os/freebsd
-CFLAGS+= -include ${SRCTOP}/sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
+CFLAGS+= -DSKIP_SPL_SYS_CONDVAR_H
+CFLAGS+= -I${ZFSTOP}/include
+CFLAGS+= -I${ZFSTOP}/lib/libspl/include/
+CFLAGS+= -I${ZFSTOP}/lib/libspl/include/os/freebsd
+CFLAGS+= -include ${ZFSTOP}/include/os/freebsd/spl/sys/ccompile.h
CFLAGS+= -DHAVE_ISSETUGID -DHAVE_BOOLEAN -DHAVE_STRLCAT -DHAVE_STRLCPY
CFLAGS+= -I${SRCTOP}/cddl/contrib/opensolaris/lib/libctf/common \
-I${SRCTOP}/sys/cddl/contrib/opensolaris/uts/common \
diff --git a/lib/libproc/tests/Makefile b/lib/libproc/tests/Makefile
index 9467cc634884..ebefdfb713f2 100644
--- a/lib/libproc/tests/Makefile
+++ b/lib/libproc/tests/Makefile
@@ -4,7 +4,7 @@ PROGS= target_prog
SRCS_target_prog= target_prog.c
BINDIR_target_prog= ${TESTSDIR}
-LIBADD= elf proc rtld_db util
+LIBADD= elf proc rtld_db util pthread
# Ensure that symbols aren't stripped from the test program, as they're needed
# for testing symbol lookup.
diff --git a/lib/libprocstat/Makefile b/lib/libprocstat/Makefile
index e20518910ba3..648da69e2fcb 100644
--- a/lib/libprocstat/Makefile
+++ b/lib/libprocstat/Makefile
@@ -55,11 +55,11 @@ MLINKS+=libprocstat.3 procstat_close.3 \
.if ${MK_CDDL} != "no"
CFLAGS+= -DLIBPROCSTAT_ZFS
SRCS+= zfs.c
-ZFSTOP= ${SRCTOP}/sys/contrib/openzfs
CFLAGS.zfs.c+= -DIN_BASE
CFLAGS.zfs.c+= -DHAVE_ISSETUGID
CFLAGS.zfs.c+= -DZFS_DEBUG
CFLAGS.zfs.c+= -I${ZFSTOP}/include
+CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libzpool/include
CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libspl/include
CFLAGS.zfs.c+= -I${ZFSTOP}/lib/libspl/include/os/freebsd
CFLAGS.zfs.c+= -I${ZFSTOP}/include/os/freebsd/zfs
diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c
index 1651cbc6820f..df77cabcd36b 100644
--- a/lib/libprocstat/libprocstat.c
+++ b/lib/libprocstat/libprocstat.c
@@ -1973,6 +1973,7 @@ procstat_getgroups_kvm(kvm_t *kd, struct kinfo_proc *kp, unsigned int *cntp)
struct ucred ucred;
gid_t *groups;
size_t len;
+ unsigned int ngroups;
assert(kd != NULL);
assert(kp != NULL);
@@ -1990,19 +1991,22 @@ procstat_getgroups_kvm(kvm_t *kd, struct kinfo_proc *kp, unsigned int *cntp)
proc.p_ucred, kp->ki_pid);
return (NULL);
}
- len = ucred.cr_ngroups * sizeof(gid_t);
+ ngroups = 1 + ucred.cr_ngroups;
+ len = ngroups * sizeof(gid_t);
groups = malloc(len);
if (groups == NULL) {
warn("malloc(%zu)", len);
return (NULL);
}
- if (!kvm_read_all(kd, (unsigned long)ucred.cr_groups, groups, len)) {
+ groups[0] = ucred.cr_gid;
+ if (!kvm_read_all(kd, (unsigned long)ucred.cr_groups, groups + 1,
+ len - sizeof(gid_t))) {
warnx("can't read groups at %p for pid %d",
ucred.cr_groups, kp->ki_pid);
free(groups);
return (NULL);
}
- *cntp = ucred.cr_ngroups;
+ *cntp = ngroups;
return (groups);
}
diff --git a/lib/libradius/Makefile b/lib/libradius/Makefile
index 0ab83d5418b1..b6857a71260a 100644
--- a/lib/libradius/Makefile
+++ b/lib/libradius/Makefile
@@ -31,7 +31,9 @@ INCS= radlib.h radlib_vs.h
CFLAGS+= -Wall
CFLAGS+= -DOPENSSL_API_COMPAT=0x10100000L
SHLIB_MAJOR= 4
-MAN= libradius.3 radius.conf.5
+
+MAN= libradius.3
+MANNODEV= radius.conf.5
MLINKS+=libradius.3 rad_acct_open.3 \
libradius.3 rad_add_server.3 \
diff --git a/lib/libsamplerate/Makefile b/lib/libsamplerate/Makefile
index 256f2087284f..4c55d5c2cb82 100644
--- a/lib/libsamplerate/Makefile
+++ b/lib/libsamplerate/Makefile
@@ -1,7 +1,9 @@
.PATH: ${SRCTOP}/contrib/libsamplerate
+PACKAGE= sound
+
LIB= samplerate
-INTERNALLIB=
+PRIVATELIB=
SRCS= samplerate.c \
src_linear.c \
diff --git a/lib/libsdp/Makefile b/lib/libsdp/Makefile
index f0153e756dfd..8177c9bdbd1a 100644
--- a/lib/libsdp/Makefile
+++ b/lib/libsdp/Makefile
@@ -1,6 +1,7 @@
# $Id: Makefile,v 1.2 2003/09/07 20:34:19 max Exp $
-PACKAGE=lib${LIB}
+PACKAGE= bluetooth
+LIB_PACKAGE=
LIB= sdp
MAN= sdp.3
diff --git a/lib/libsdp/sdp.3 b/lib/libsdp/sdp.3
index dcd9077798ea..015f9cd8fb44 100644
--- a/lib/libsdp/sdp.3
+++ b/lib/libsdp/sdp.3
@@ -24,7 +24,7 @@
.\"
.\" $Id: sdp.3,v 1.1 2003/09/07 20:34:19 max Exp $
.\"
-.Dd April 30, 2018
+.Dd September 16, 2025
.Dt SDP 3
.Os
.Sh NAME
@@ -87,7 +87,7 @@
.Fn sdp_uuid2desc "uint16_t uuid"
.Ft int32_t
.Fo sdp_register_service
-.Fa "void *xss" "uint16_t uuid" "bdaddr_p const bdaddr" "uint8_t const *data"
+.Fa "void *xss" "uint16_t uuid" "const bdaddr_t *bdaddr" "uint8_t const *data"
.Fa "uint32_t datalen" "uint32_t *handle"
.Fc
.Ft int32_t
diff --git a/lib/libsdp/sdp.h b/lib/libsdp/sdp.h
index faad36aefca6..0c9474a70eff 100644
--- a/lib/libsdp/sdp.h
+++ b/lib/libsdp/sdp.h
@@ -702,7 +702,7 @@ typedef struct sdp_panu_profile sdp_panu_profile_t;
typedef struct sdp_panu_profile * sdp_panu_profile_p;
int32_t sdp_register_service (void *xss, uint16_t uuid,
- bdaddr_p const bdaddr, uint8_t const *data,
+ const bdaddr_t *bdaddr, uint8_t const *data,
uint32_t datalen, uint32_t *handle);
int32_t sdp_unregister_service (void *xss, uint32_t handle);
int32_t sdp_change_service (void *xss, uint32_t handle,
diff --git a/lib/libsdp/service.c b/lib/libsdp/service.c
index 9f07d1ba86ba..2cce6c133600 100644
--- a/lib/libsdp/service.c
+++ b/lib/libsdp/service.c
@@ -45,7 +45,7 @@
static int32_t sdp_receive_error_pdu(sdp_session_p ss);
int32_t
-sdp_register_service(void *xss, uint16_t uuid, bdaddr_p const bdaddr,
+sdp_register_service(void *xss, uint16_t uuid, const bdaddr_t *bdaddr,
uint8_t const *data, uint32_t datalen, uint32_t *handle)
{
sdp_session_p ss = (sdp_session_p) xss;
diff --git a/lib/libsecureboot/Makefile.libsa.inc b/lib/libsecureboot/Makefile.libsa.inc
index 7397d0fc1144..b1b5d7dd1e30 100644
--- a/lib/libsecureboot/Makefile.libsa.inc
+++ b/lib/libsecureboot/Makefile.libsa.inc
@@ -22,8 +22,8 @@ SRCS+= \
# Add includes required by efi part
CFLAGS+= \
+ -I${SRCTOP}/sys/contrib/edk2/Include \
-I${SRCTOP}/stand/efi/include \
- -I${SRCTOP}/lib/libsecureboot/efi/include \
-I${SRCTOP}/stand/efi/include/${MACHINE}
.endif
diff --git a/lib/libsecureboot/efi/efi_variables.c b/lib/libsecureboot/efi/efi_variables.c
index 3c36bc66f788..4b2b6b5c91ca 100644
--- a/lib/libsecureboot/efi/efi_variables.c
+++ b/lib/libsecureboot/efi/efi_variables.c
@@ -30,6 +30,7 @@
#include <efi.h>
#include <efilib.h>
+#include <Uefi.h>
#include <Guid/ImageAuthentication.h>
#define NEED_BRSSL_H
diff --git a/lib/libsecureboot/efi/include/Guid/GlobalVariable.h b/lib/libsecureboot/efi/include/Guid/GlobalVariable.h
deleted file mode 100644
index 3bd0a815fcf6..000000000000
--- a/lib/libsecureboot/efi/include/Guid/GlobalVariable.h
+++ /dev/null
@@ -1,192 +0,0 @@
-/** @file
- GUID for EFI (NVRAM) Variables.
- Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- @par Revision Reference:
- GUID defined in UEFI 2.1
-**/
-
-#ifndef __GLOBAL_VARIABLE_GUID_H__
-#define __GLOBAL_VARIABLE_GUID_H__
-
-#include <sys/cdefs.h>
-#ifndef EFI_GLOBAL_VARIABLE
-#define EFI_GLOBAL_VARIABLE \
- { \
- 0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C } \
- }
-#endif /* EFI_GLOBAL_VARIABLE */
-
-extern EFI_GUID gEfiGlobalVariableGuid;
-
-//
-// Follow UEFI 2.4 spec:
-// To prevent name collisions with possible future globally defined variables,
-// other internal firmware data variables that are not defined here must be
-// saved with a unique VendorGuid other than EFI_GLOBAL_VARIABLE or
-// any other GUID defined by the UEFI Specification. Implementations must
-// only permit the creation of variables with a UEFI Specification-defined
-// VendorGuid when these variables are documented in the UEFI Specification.
-//
-// Note: except the globally defined variables defined below, the spec also defines
-// L"Boot####" - A boot load option.
-// L"Driver####" - A driver load option.
-// L"SysPrep####" - A System Prep application load option.
-// L"Key####" - Describes hot key relationship with a Boot#### load option.
-// The attribute for them is NV+BS+RT, #### is a printed hex value, and no 0x or h
-// is included in the hex value. They can not be expressed as a #define like other globally
-// defined variables, it is because we can not list the Boot0000, Boot0001, etc one by one.
-//
-
-///
-/// The language codes that the firmware supports. This value is deprecated.
-/// Its attribute is BS+RT.
-///
-#define EFI_LANG_CODES_VARIABLE_NAME L"LangCodes"
-///
-/// The language code that the system is configured for. This value is deprecated.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_LANG_VARIABLE_NAME L"Lang"
-///
-/// The firmware's boot managers timeout, in seconds, before initiating the default boot selection.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_TIME_OUT_VARIABLE_NAME L"Timeout"
-///
-/// The language codes that the firmware supports.
-/// Its attribute is BS+RT.
-///
-#define EFI_PLATFORM_LANG_CODES_VARIABLE_NAME L"PlatformLangCodes"
-///
-/// The language code that the system is configured for.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_PLATFORM_LANG_VARIABLE_NAME L"PlatformLang"
-///
-/// The device path of the default input/output/error output console.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_CON_IN_VARIABLE_NAME L"ConIn"
-#define EFI_CON_OUT_VARIABLE_NAME L"ConOut"
-#define EFI_ERR_OUT_VARIABLE_NAME L"ErrOut"
-///
-/// The device path of all possible input/output/error output devices.
-/// Its attribute is BS+RT.
-///
-#define EFI_CON_IN_DEV_VARIABLE_NAME L"ConInDev"
-#define EFI_CON_OUT_DEV_VARIABLE_NAME L"ConOutDev"
-#define EFI_ERR_OUT_DEV_VARIABLE_NAME L"ErrOutDev"
-///
-/// The ordered boot option load list.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_BOOT_ORDER_VARIABLE_NAME L"BootOrder"
-///
-/// The boot option for the next boot only.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_BOOT_NEXT_VARIABLE_NAME L"BootNext"
-///
-/// The boot option that was selected for the current boot.
-/// Its attribute is BS+RT.
-///
-#define EFI_BOOT_CURRENT_VARIABLE_NAME L"BootCurrent"
-///
-/// The types of boot options supported by the boot manager. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME L"BootOptionSupport"
-///
-/// The ordered driver load option list.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_DRIVER_ORDER_VARIABLE_NAME L"DriverOrder"
-///
-/// The ordered System Prep Application load option list.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_SYS_PREP_ORDER_VARIABLE_NAME L"SysPrepOrder"
-///
-/// Identifies the level of hardware error record persistence
-/// support implemented by the platform. This variable is
-/// only modified by firmware and is read-only to the OS.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME L"HwErrRecSupport"
-///
-/// Whether the system is operating in setup mode (1) or not (0).
-/// All other values are reserved. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_SETUP_MODE_NAME L"SetupMode"
-///
-/// The Key Exchange Key Signature Database.
-/// Its attribute is NV+BS+RT+AT.
-///
-#define EFI_KEY_EXCHANGE_KEY_NAME L"KEK"
-///
-/// The public Platform Key.
-/// Its attribute is NV+BS+RT+AT.
-///
-#define EFI_PLATFORM_KEY_NAME L"PK"
-///
-/// Array of GUIDs representing the type of signatures supported
-/// by the platform firmware. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_SIGNATURE_SUPPORT_NAME L"SignatureSupport"
-///
-/// Whether the platform firmware is operating in Secure boot mode (1) or not (0).
-/// All other values are reserved. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_SECURE_BOOT_MODE_NAME L"SecureBoot"
-///
-/// The OEM's default Key Exchange Key Signature Database. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_KEK_DEFAULT_VARIABLE_NAME L"KEKDefault"
-///
-/// The OEM's default public Platform Key. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_PK_DEFAULT_VARIABLE_NAME L"PKDefault"
-///
-/// The OEM's default secure boot signature store. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_DB_DEFAULT_VARIABLE_NAME L"dbDefault"
-///
-/// The OEM's default secure boot blacklist signature store. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_DBX_DEFAULT_VARIABLE_NAME L"dbxDefault"
-///
-/// The OEM's default secure boot timestamp signature store. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_DBT_DEFAULT_VARIABLE_NAME L"dbtDefault"
-///
-/// Allows the firmware to indicate supported features and actions to the OS.
-/// Its attribute is BS+RT.
-///
-#define EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME L"OsIndicationsSupported"
-///
-/// Allows the OS to request the firmware to enable certain features and to take certain actions.
-/// Its attribute is NV+BS+RT.
-///
-#define EFI_OS_INDICATIONS_VARIABLE_NAME L"OsIndications"
-///
-/// Whether the system is configured to use only vendor provided
-/// keys or not. Should be treated as read-only.
-/// Its attribute is BS+RT.
-///
-#define EFI_VENDOR_KEYS_VARIABLE_NAME L"VendorKeys"
-
-#endif
diff --git a/lib/libsecureboot/efi/include/Guid/ImageAuthentication.h b/lib/libsecureboot/efi/include/Guid/ImageAuthentication.h
deleted file mode 100644
index b1fc1f54cce1..000000000000
--- a/lib/libsecureboot/efi/include/Guid/ImageAuthentication.h
+++ /dev/null
@@ -1,350 +0,0 @@
-/** @file
- Image signature database are defined for the signed image validation.
- Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- @par Revision Reference:
- GUIDs defined in UEFI 2.5 spec.
-**/
-
-#ifndef __IMAGE_AUTHTICATION_H__
-#define __IMAGE_AUTHTICATION_H__
-
-#include <sys/cdefs.h>
-#include <Guid/GlobalVariable.h>
-#include <Protocol/Hash.h>
-
-#define EFI_IMAGE_SECURITY_DATABASE_GUID \
- { \
- 0xd719b2cb, 0x3d3a, 0x4596, { 0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 0x65, 0x6f } \
- }
-
-///
-/// Varialbe name with guid EFI_IMAGE_SECURITY_DATABASE_GUID
-/// for the authorized signature database.
-///
-#define EFI_IMAGE_SECURITY_DATABASE L"db"
-///
-/// Varialbe name with guid EFI_IMAGE_SECURITY_DATABASE_GUID
-/// for the forbidden signature database.
-///
-#define EFI_IMAGE_SECURITY_DATABASE1 L"dbx"
-///
-/// Variable name with guid EFI_IMAGE_SECURITY_DATABASE_GUID
-/// for the timestamp signature database.
-///
-#define EFI_IMAGE_SECURITY_DATABASE2 L"dbt"
-
-#define SECURE_BOOT_MODE_ENABLE 1
-#define SECURE_BOOT_MODE_DISABLE 0
-
-#define SETUP_MODE 1
-#define USER_MODE 0
-
-//***********************************************************************
-// Signature Database
-//***********************************************************************
-///
-/// The format of a signature database.
-///
-#pragma pack(1)
-
-typedef struct {
- ///
- /// An identifier which identifies the agent which added the signature to the list.
- ///
- EFI_GUID SignatureOwner;
- ///
- /// The format of the signature is defined by the SignatureType.
- ///
- UINT8 SignatureData[1];
-} EFI_SIGNATURE_DATA;
-
-typedef struct {
- ///
- /// Type of the signature. GUID signature types are defined in below.
- ///
- EFI_GUID SignatureType;
- ///
- /// Total size of the signature list, including this header.
- ///
- UINT32 SignatureListSize;
- ///
- /// Size of the signature header which precedes the array of signatures.
- ///
- UINT32 SignatureHeaderSize;
- ///
- /// Size of each signature.
- ///
- UINT32 SignatureSize;
- ///
- /// Header before the array of signatures. The format of this header is specified
- /// by the SignatureType.
- /// UINT8 SignatureHeader[SignatureHeaderSize];
- ///
- /// An array of signatures. Each signature is SignatureSize bytes in length.
- /// EFI_SIGNATURE_DATA Signatures[][SignatureSize];
- ///
-} EFI_SIGNATURE_LIST;
-
-typedef struct {
- ///
- /// The SHA256 hash of an X.509 certificate's To-Be-Signed contents.
- ///
- EFI_SHA256_HASH ToBeSignedHash;
- ///
- /// The time that the certificate shall be considered to be revoked.
- ///
- EFI_TIME TimeOfRevocation;
-} EFI_CERT_X509_SHA256;
-
-typedef struct {
- ///
- /// The SHA384 hash of an X.509 certificate's To-Be-Signed contents.
- ///
- EFI_SHA384_HASH ToBeSignedHash;
- ///
- /// The time that the certificate shall be considered to be revoked.
- ///
- EFI_TIME TimeOfRevocation;
-} EFI_CERT_X509_SHA384;
-
-typedef struct {
- ///
- /// The SHA512 hash of an X.509 certificate's To-Be-Signed contents.
- ///
- EFI_SHA512_HASH ToBeSignedHash;
- ///
- /// The time that the certificate shall be considered to be revoked.
- ///
- EFI_TIME TimeOfRevocation;
-} EFI_CERT_X509_SHA512;
-
-#pragma pack()
-
-///
-/// This identifies a signature containing a SHA-256 hash. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) +
-/// 32 bytes.
-///
-#define EFI_CERT_SHA256_GUID \
- { \
- 0xc1c41626, 0x504c, 0x4092, {0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28} \
- }
-
-///
-/// This identifies a signature containing an RSA-2048 key. The key (only the modulus
-/// since the public key exponent is known to be 0x10001) shall be stored in big-endian
-/// order.
-/// The SignatureHeader size shall always be 0. The SignatureSize shall always be 16 (size
-/// of SignatureOwner component) + 256 bytes.
-///
-#define EFI_CERT_RSA2048_GUID \
- { \
- 0x3c5766e8, 0x269c, 0x4e34, {0xaa, 0x14, 0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6} \
- }
-
-///
-/// This identifies a signature containing a RSA-2048 signature of a SHA-256 hash. The
-/// SignatureHeader size shall always be 0. The SignatureSize shall always be 16 (size of
-/// SignatureOwner component) + 256 bytes.
-///
-#define EFI_CERT_RSA2048_SHA256_GUID \
- { \
- 0xe2b36190, 0x879b, 0x4a3d, {0xad, 0x8d, 0xf2, 0xe7, 0xbb, 0xa3, 0x27, 0x84} \
- }
-
-///
-/// This identifies a signature containing a SHA-1 hash. The SignatureSize shall always
-/// be 16 (size of SignatureOwner component) + 20 bytes.
-///
-#define EFI_CERT_SHA1_GUID \
- { \
- 0x826ca512, 0xcf10, 0x4ac9, {0xb1, 0x87, 0xbe, 0x1, 0x49, 0x66, 0x31, 0xbd} \
- }
-
-///
-/// TThis identifies a signature containing a RSA-2048 signature of a SHA-1 hash. The
-/// SignatureHeader size shall always be 0. The SignatureSize shall always be 16 (size of
-/// SignatureOwner component) + 256 bytes.
-///
-#define EFI_CERT_RSA2048_SHA1_GUID \
- { \
- 0x67f8444f, 0x8743, 0x48f1, {0xa3, 0x28, 0x1e, 0xaa, 0xb8, 0x73, 0x60, 0x80} \
- }
-
-///
-/// This identifies a signature based on an X.509 certificate. If the signature is an X.509
-/// certificate then verification of the signature of an image should validate the public
-/// key certificate in the image using certificate path verification, up to this X.509
-/// certificate as a trusted root. The SignatureHeader size shall always be 0. The
-/// SignatureSize may vary but shall always be 16 (size of the SignatureOwner component) +
-/// the size of the certificate itself.
-/// Note: This means that each certificate will normally be in a separate EFI_SIGNATURE_LIST.
-///
-#define EFI_CERT_X509_GUID \
- { \
- 0xa5c059a1, 0x94e4, 0x4aa7, {0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72} \
- }
-
-///
-/// This identifies a signature containing a SHA-224 hash. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) +
-/// 28 bytes.
-///
-#define EFI_CERT_SHA224_GUID \
- { \
- 0xb6e5233, 0xa65c, 0x44c9, {0x94, 0x7, 0xd9, 0xab, 0x83, 0xbf, 0xc8, 0xbd} \
- }
-
-///
-/// This identifies a signature containing a SHA-384 hash. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) +
-/// 48 bytes.
-///
-#define EFI_CERT_SHA384_GUID \
- { \
- 0xff3e5307, 0x9fd0, 0x48c9, {0x85, 0xf1, 0x8a, 0xd5, 0x6c, 0x70, 0x1e, 0x1} \
- }
-
-///
-/// This identifies a signature containing a SHA-512 hash. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) +
-/// 64 bytes.
-///
-#define EFI_CERT_SHA512_GUID \
- { \
- 0x93e0fae, 0xa6c4, 0x4f50, {0x9f, 0x1b, 0xd4, 0x1e, 0x2b, 0x89, 0xc1, 0x9a} \
- }
-
-///
-/// This identifies a signature containing the SHA256 hash of an X.509 certificate's
-/// To-Be-Signed contents, and a time of revocation. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of the SignatureOwner component)
-/// + 48 bytes for an EFI_CERT_X509_SHA256 structure. If the TimeOfRevocation is non-zero,
-/// the certificate should be considered to be revoked from that time and onwards, and
-/// otherwise the certificate shall be considered to always be revoked.
-///
-#define EFI_CERT_X509_SHA256_GUID \
- { \
- 0x3bd2a492, 0x96c0, 0x4079, {0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed } \
- }
-
-///
-/// This identifies a signature containing the SHA384 hash of an X.509 certificate's
-/// To-Be-Signed contents, and a time of revocation. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of the SignatureOwner component)
-/// + 64 bytes for an EFI_CERT_X509_SHA384 structure. If the TimeOfRevocation is non-zero,
-/// the certificate should be considered to be revoked from that time and onwards, and
-/// otherwise the certificate shall be considered to always be revoked.
-///
-#define EFI_CERT_X509_SHA384_GUID \
- { \
- 0x7076876e, 0x80c2, 0x4ee6, {0xaa, 0xd2, 0x28, 0xb3, 0x49, 0xa6, 0x86, 0x5b } \
- }
-
-///
-/// This identifies a signature containing the SHA512 hash of an X.509 certificate's
-/// To-Be-Signed contents, and a time of revocation. The SignatureHeader size shall
-/// always be 0. The SignatureSize shall always be 16 (size of the SignatureOwner component)
-/// + 80 bytes for an EFI_CERT_X509_SHA512 structure. If the TimeOfRevocation is non-zero,
-/// the certificate should be considered to be revoked from that time and onwards, and
-/// otherwise the certificate shall be considered to always be revoked.
-///
-#define EFI_CERT_X509_SHA512_GUID \
- { \
- 0x446dbf63, 0x2502, 0x4cda, {0xbc, 0xfa, 0x24, 0x65, 0xd2, 0xb0, 0xfe, 0x9d } \
- }
-
-///
-/// This identifies a signature containing a DER-encoded PKCS #7 version 1.5 [RFC2315]
-/// SignedData value.
-///
-#define EFI_CERT_TYPE_PKCS7_GUID \
- { \
- 0x4aafd29d, 0x68df, 0x49ee, {0x8a, 0xa9, 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7} \
- }
-
-//***********************************************************************
-// Image Execution Information Table Definition
-//***********************************************************************
-typedef UINT32 EFI_IMAGE_EXECUTION_ACTION;
-
-#define EFI_IMAGE_EXECUTION_AUTHENTICATION 0x00000007
-#define EFI_IMAGE_EXECUTION_AUTH_UNTESTED 0x00000000
-#define EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED 0x00000001
-#define EFI_IMAGE_EXECUTION_AUTH_SIG_PASSED 0x00000002
-#define EFI_IMAGE_EXECUTION_AUTH_SIG_NOT_FOUND 0x00000003
-#define EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND 0x00000004
-#define EFI_IMAGE_EXECUTION_POLICY_FAILED 0x00000005
-#define EFI_IMAGE_EXECUTION_INITIALIZED 0x00000008
-
-//
-// EFI_IMAGE_EXECUTION_INFO is added to EFI System Configuration Table
-// and assigned the GUID EFI_IMAGE_SECURITY_DATABASE_GUID.
-//
-typedef struct {
- ///
- /// Describes the action taken by the firmware regarding this image.
- ///
- EFI_IMAGE_EXECUTION_ACTION Action;
- ///
- /// Size of all of the entire structure.
- ///
- UINT32 InfoSize;
- ///
- /// If this image was a UEFI device driver (for option ROM, for example) this is the
- /// null-terminated, user-friendly name for the device. If the image was for an application,
- /// then this is the name of the application. If this cannot be determined, then a simple
- /// NULL character should be put in this position.
- /// CHAR16 Name[];
- ///
-
- ///
- /// For device drivers, this is the device path of the device for which this device driver
- /// was intended. In some cases, the driver itself may be stored as part of the system
- /// firmware, but this field should record the device's path, not the firmware path. For
- /// applications, this is the device path of the application. If this cannot be determined,
- /// a simple end-of-path device node should be put in this position.
- /// EFI_DEVICE_PATH_PROTOCOL DevicePath;
- ///
-
- ///
- /// Zero or more image signatures. If the image contained no signatures,
- /// then this field is empty.
- /// EFI_SIGNATURE_LIST Signature;
- ///
-} EFI_IMAGE_EXECUTION_INFO;
-
-
-typedef struct {
- ///
- /// Number of EFI_IMAGE_EXECUTION_INFO structures.
- ///
- UINTN NumberOfImages;
- ///
- /// Number of image instances of EFI_IMAGE_EXECUTION_INFO structures.
- ///
- // EFI_IMAGE_EXECUTION_INFO InformationInfo[]
-} EFI_IMAGE_EXECUTION_INFO_TABLE;
-
-extern EFI_GUID gEfiImageSecurityDatabaseGuid;
-extern EFI_GUID gEfiCertSha256Guid;
-extern EFI_GUID gEfiCertRsa2048Guid;
-extern EFI_GUID gEfiCertRsa2048Sha256Guid;
-extern EFI_GUID gEfiCertSha1Guid;
-extern EFI_GUID gEfiCertRsa2048Sha1Guid;
-extern EFI_GUID gEfiCertX509Guid;
-extern EFI_GUID gEfiCertSha224Guid;
-extern EFI_GUID gEfiCertSha384Guid;
-extern EFI_GUID gEfiCertSha512Guid;
-extern EFI_GUID gEfiCertX509Sha256Guid;
-extern EFI_GUID gEfiCertX509Sha384Guid;
-extern EFI_GUID gEfiCertX509Sha512Guid;
-extern EFI_GUID gEfiCertPkcs7Guid;
-
-#endif
diff --git a/lib/libsecureboot/efi/include/Protocol/Hash.h b/lib/libsecureboot/efi/include/Protocol/Hash.h
deleted file mode 100644
index 094bf20964cc..000000000000
--- a/lib/libsecureboot/efi/include/Protocol/Hash.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/** @file
- EFI_HASH_SERVICE_BINDING_PROTOCOL as defined in UEFI 2.0.
- EFI_HASH_PROTOCOL as defined in UEFI 2.0.
- The EFI Hash Service Binding Protocol is used to locate hashing services support
- provided by a driver and to create and destroy instances of the EFI Hash Protocol
- so that a multiple drivers can use the underlying hashing services.
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
-This program and the accompanying materials are licensed and made available under
-the terms and conditions of the BSD License that accompanies this distribution.
-The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php.
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-**/
-
-#ifndef __EFI_HASH_PROTOCOL_H__
-#define __EFI_HASH_PROTOCOL_H__
-
-#include <sys/cdefs.h>
-#define CONST const
-
-#define EFI_HASH_SERVICE_BINDING_PROTOCOL_GUID \
- { \
- 0x42881c98, 0xa4f3, 0x44b0, {0xa3, 0x9d, 0xdf, 0xa1, 0x86, 0x67, 0xd8, 0xcd } \
- }
-
-#define EFI_HASH_PROTOCOL_GUID \
- { \
- 0xc5184932, 0xdba5, 0x46db, {0xa5, 0xba, 0xcc, 0x0b, 0xda, 0x9c, 0x14, 0x35 } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA1_GUID \
- { \
- 0x2ae9d80f, 0x3fb2, 0x4095, {0xb7, 0xb1, 0xe9, 0x31, 0x57, 0xb9, 0x46, 0xb6 } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA224_GUID \
- { \
- 0x8df01a06, 0x9bd5, 0x4bf7, {0xb0, 0x21, 0xdb, 0x4f, 0xd9, 0xcc, 0xf4, 0x5b } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA256_GUID \
- { \
- 0x51aa59de, 0xfdf2, 0x4ea3, {0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9 } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA384_GUID \
- { \
- 0xefa96432, 0xde33, 0x4dd2, {0xae, 0xe6, 0x32, 0x8c, 0x33, 0xdf, 0x77, 0x7a } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA512_GUID \
- { \
- 0xcaa4381e, 0x750c, 0x4770, {0xb8, 0x70, 0x7a, 0x23, 0xb4, 0xe4, 0x21, 0x30 } \
- }
-
-#define EFI_HASH_ALGORTIHM_MD5_GUID \
- { \
- 0xaf7c79c, 0x65b5, 0x4319, {0xb0, 0xae, 0x44, 0xec, 0x48, 0x4e, 0x4a, 0xd7 } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA1_NOPAD_GUID \
- { \
- 0x24c5dc2f, 0x53e2, 0x40ca, {0x9e, 0xd6, 0xa5, 0xd9, 0xa4, 0x9f, 0x46, 0x3b } \
- }
-
-#define EFI_HASH_ALGORITHM_SHA256_NOPAD_GUID \
- { \
- 0x8628752a, 0x6cb7, 0x4814, {0x96, 0xfc, 0x24, 0xa8, 0x15, 0xac, 0x22, 0x26 } \
- }
-
-//
-// Note: Use of the following algorithms with EFI_HASH_PROTOCOL is deprecated.
-// EFI_HASH_ALGORITHM_SHA1_GUID
-// EFI_HASH_ALGORITHM_SHA224_GUID
-// EFI_HASH_ALGORITHM_SHA256_GUID
-// EFI_HASH_ALGORITHM_SHA384_GUID
-// EFI_HASH_ALGORITHM_SHA512_GUID
-// EFI_HASH_ALGORTIHM_MD5_GUID
-//
-
-typedef struct _EFI_HASH_PROTOCOL EFI_HASH_PROTOCOL;
-
-typedef UINT8 EFI_MD5_HASH[16];
-typedef UINT8 EFI_SHA1_HASH[20];
-typedef UINT8 EFI_SHA224_HASH[28];
-typedef UINT8 EFI_SHA256_HASH[32];
-typedef UINT8 EFI_SHA384_HASH[48];
-typedef UINT8 EFI_SHA512_HASH[64];
-
-typedef union {
- EFI_MD5_HASH *Md5Hash;
- EFI_SHA1_HASH *Sha1Hash;
- EFI_SHA224_HASH *Sha224Hash;
- EFI_SHA256_HASH *Sha256Hash;
- EFI_SHA384_HASH *Sha384Hash;
- EFI_SHA512_HASH *Sha512Hash;
-} EFI_HASH_OUTPUT;
-
-/**
- Returns the size of the hash which results from a specific algorithm.
- @param[in] This Points to this instance of EFI_HASH_PROTOCOL.
- @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
- @param[out] HashSize Holds the returned size of the algorithm's hash.
- @retval EFI_SUCCESS Hash size returned successfully.
- @retval EFI_INVALID_PARAMETER HashSize is NULL or HashAlgorithm is NULL.
- @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported
- by this driver.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *EFI_HASH_GET_HASH_SIZE)(
- IN CONST EFI_HASH_PROTOCOL *This,
- IN CONST EFI_GUID *HashAlgorithm,
- OUT UINTN *HashSize
- );
-
-/**
- Creates a hash for the specified message text.
- @param[in] This Points to this instance of EFI_HASH_PROTOCOL.
- @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.
- @param[in] Extend Specifies whether to create a new hash (FALSE) or extend the specified
- existing hash (TRUE).
- @param[in] Message Points to the start of the message.
- @param[in] MessageSize The size of Message, in bytes.
- @param[in,out] Hash On input, if Extend is TRUE, then this parameter holds a pointer
- to a pointer to an array containing the hash to extend. If Extend
- is FALSE, then this parameter holds a pointer to a pointer to a
- caller-allocated array that will receive the result of the hash
- computation. On output (regardless of the value of Extend), the
- array will contain the result of the hash computation.
- @retval EFI_SUCCESS Hash returned successfully.
- @retval EFI_INVALID_PARAMETER Message or Hash, HashAlgorithm is NULL or MessageSize is 0.
- MessageSize is not an integer multiple of block size.
- @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this
- driver. Or, Extend is TRUE, and the algorithm doesn't support extending the hash.
-**/
-typedef
-EFI_STATUS
-(EFIAPI *EFI_HASH_HASH)(
- IN CONST EFI_HASH_PROTOCOL *This,
- IN CONST EFI_GUID *HashAlgorithm,
- IN BOOLEAN Extend,
- IN CONST UINT8 *Message,
- IN UINT64 MessageSize,
- IN OUT EFI_HASH_OUTPUT *Hash
- );
-
-///
-/// This protocol allows creating a hash of an arbitrary message digest
-/// using one or more hash algorithms.
-///
-struct _EFI_HASH_PROTOCOL {
- EFI_HASH_GET_HASH_SIZE GetHashSize;
- EFI_HASH_HASH Hash;
-};
-
-extern EFI_GUID gEfiHashServiceBindingProtocolGuid;
-extern EFI_GUID gEfiHashProtocolGuid;
-extern EFI_GUID gEfiHashAlgorithmSha1Guid;
-extern EFI_GUID gEfiHashAlgorithmSha224Guid;
-extern EFI_GUID gEfiHashAlgorithmSha256Guid;
-extern EFI_GUID gEfiHashAlgorithmSha384Guid;
-extern EFI_GUID gEfiHashAlgorithmSha512Guid;
-extern EFI_GUID gEfiHashAlgorithmMD5Guid;
-extern EFI_GUID gEfiHashAlgorithmSha1NoPadGuid;
-extern EFI_GUID gEfiHashAlgorithmSha256NoPadGuid;
-
-#endif
diff --git a/lib/libsecureboot/h/libsecureboot.h b/lib/libsecureboot/h/libsecureboot.h
index d32df9594332..fa8360338cfc 100644
--- a/lib/libsecureboot/h/libsecureboot.h
+++ b/lib/libsecureboot/h/libsecureboot.h
@@ -27,6 +27,8 @@
#ifndef _LIBSECUREBOOT_H_
#define _LIBSECUREBOOT_H_
+#undef MIN /* Conflicts with EDK2 */
+#undef MAX
#include <sys/param.h>
#ifdef _STANDALONE
#define _DEBUG_LEVEL_VAR DebugVe
diff --git a/lib/libsecureboot/verify_file.c b/lib/libsecureboot/verify_file.c
index 753204a33b6a..ee263dafe774 100644
--- a/lib/libsecureboot/verify_file.c
+++ b/lib/libsecureboot/verify_file.c
@@ -539,7 +539,7 @@ verify_file(int fd, const char *filename, off_t off, int severity,
return (0);
if (rc != VE_FINGERPRINT_WRONG && loaded_manifests) {
- if (rc != VE_NOT_CHECKED)
+ if (rc != VE_NOT_CHECKED && rc != VE_FINGERPRINT_NONE)
return (rc);
if (severity <= VE_GUESS)
diff --git a/lib/libstdbuf/Makefile b/lib/libstdbuf/Makefile
index 102c6745c593..9e289e0018fc 100644
--- a/lib/libstdbuf/Makefile
+++ b/lib/libstdbuf/Makefile
@@ -1,6 +1,5 @@
.include <bsd.own.mk>
-PACKAGE=lib${LIB}
LIB= stdbuf
SRCS= stdbuf.c
SHLIB_MAJOR= 1
diff --git a/lib/libstdthreads/Makefile b/lib/libstdthreads/Makefile
index 49d024052420..dcdac58efc12 100644
--- a/lib/libstdthreads/Makefile
+++ b/lib/libstdthreads/Makefile
@@ -1,4 +1,4 @@
-PACKAGE=lib${LIB}
+PACKAGE=runtime
LIB= stdthreads
SHLIB_MAJOR= 0
diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys
index bd65b58083c2..5f149170b974 100644
--- a/lib/libsys/Makefile.sys
+++ b/lib/libsys/Makefile.sys
@@ -243,6 +243,7 @@ MAN+= abort2.2 \
jail.2 \
kcmp.2 \
kenv.2 \
+ kexec_load.2 \
kill.2 \
kldfind.2 \
kldfirstmod.2 \
@@ -470,7 +471,9 @@ MLINKS+=intro.2 errno.2
MLINKS+=jail.2 jail_attach.2 \
jail.2 jail_get.2 \
jail.2 jail_remove.2 \
- jail.2 jail_set.2
+ jail.2 jail_set.2 \
+ jail.2 jail_attach_jd.2 \
+ jail.2 jail_remove_jd.2
MLINKS+=kldunload.2 kldunloadf.2
MLINKS+=kqueue.2 kevent.2 \
kqueue.2 kqueue1.2 \
diff --git a/lib/libsys/Symbol.map b/lib/libsys/Symbol.map
index eb71c813ae86..ae12124ca210 100644
--- a/lib/libsys/Symbol.map
+++ b/lib/libsys/Symbol.map
@@ -4,10 +4,4 @@ FBSDprivate_1.0 {
__getosreldate;
__libsys_interposing_slot;
_elf_aux_info;
- freebsd11_fstat;
- freebsd11_fstatat;
- freebsd11_getfsstat;
- freebsd11_lstat;
- freebsd11_stat;
- freebsd11_statfs;
};
diff --git a/lib/libsys/_libsys.h b/lib/libsys/_libsys.h
index 6bd768708a78..12417b572a60 100644
--- a/lib/libsys/_libsys.h
+++ b/lib/libsys/_libsys.h
@@ -32,6 +32,7 @@ struct itimerspec;
struct itimerval;
struct jail;
struct kevent;
+struct kexec_segment;
struct kld_file_stat;
struct mac;
struct module_stat;
@@ -470,6 +471,7 @@ typedef int (__sys_getgroups_t)(int, gid_t *);
typedef int (__sys_setgroups_t)(int, const gid_t *);
typedef int (__sys_jail_attach_jd_t)(int);
typedef int (__sys_jail_remove_jd_t)(int);
+typedef int (__sys_kexec_load_t)(uint64_t, u_long, struct kexec_segment *, u_long);
_Noreturn void __sys__exit(int rval);
int __sys_fork(void);
@@ -876,6 +878,7 @@ int __sys_getgroups(int gidsetsize, gid_t * gidset);
int __sys_setgroups(int gidsetsize, const gid_t * gidset);
int __sys_jail_attach_jd(int fd);
int __sys_jail_remove_jd(int fd);
+int __sys_kexec_load(uint64_t entry, u_long nseg, struct kexec_segment * segments, u_long flags);
__END_DECLS
#endif /* __LIBSYS_H_ */
diff --git a/lib/libsys/arm/__vdso_gettc.c b/lib/libsys/arm/__vdso_gettc.c
index cb4bdec1e8ef..c86bb78becb9 100644
--- a/lib/libsys/arm/__vdso_gettc.c
+++ b/lib/libsys/arm/__vdso_gettc.c
@@ -62,12 +62,8 @@ __vdso_gettc(const struct vdso_timehands *th, u_int *tc)
if (th->th_algo != VDSO_TH_ALGO_ARM_GENTIM)
return (ENOSYS);
- /*
- * Userspace gettimeofday() is only enabled on ARMv7 CPUs, but
- * libc is compiled for ARMv6. Due to clang issues, .arch
- * armv7-a directive does not work.
- */
- __asm __volatile(".word\t0xf57ff06f" : : : "memory"); /* isb */
+
+ __asm __volatile("isb" : : : "memory");
*tc = th->th_physical == 0 ? cp15_cntvct_get() : cp15_cntpct_get();
return (0);
}
diff --git a/lib/libsys/clock_gettime.2 b/lib/libsys/clock_gettime.2
index 89551d0f720b..841673648dfc 100644
--- a/lib/libsys/clock_gettime.2
+++ b/lib/libsys/clock_gettime.2
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 10, 2024
+.Dd October 15, 2025
.Dt CLOCK_GETTIME 2
.Os
.Sh NAME
@@ -80,7 +80,6 @@ Behavior during a leap second is not defined by and POSIX standard.
Increments in SI seconds, even while the system is suspended.
Its epoch is unspecified.
The count is not adjusted by leap seconds.
-.Fx implements
.It Dv CLOCK_UPTIME
.It Dv CLOCK_UPTIME_PRECISE
.It Dv CLOCK_UPTIME_FAST
diff --git a/lib/libsys/closefrom.2 b/lib/libsys/closefrom.2
index 1885a6fdeaa8..e6b4a5a3e9d7 100644
--- a/lib/libsys/closefrom.2
+++ b/lib/libsys/closefrom.2
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 17, 2025
+.Dd October 27, 2025
.Dt CLOSEFROM 2
.Os
.Sh NAME
@@ -94,6 +94,11 @@ function first appeared in
.Fx 8.0 .
.Pp
The
+.Fn close_range
+function first appeared in
+.Fx 12.2 .
+.Pp
+The
.Dv CLOSE_RANGE_CLOFORK
flag appeared in
.Fx 15.0 .
diff --git a/lib/libsys/getgroups.2 b/lib/libsys/getgroups.2
index 37c8fbad7215..4e94b32d4e7b 100644
--- a/lib/libsys/getgroups.2
+++ b/lib/libsys/getgroups.2
@@ -1,5 +1,13 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2025 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Olivier Certner
+.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+.\" Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -25,12 +33,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 1, 2025
+.Dd October 10, 2025
.Dt GETGROUPS 2
.Os
.Sh NAME
.Nm getgroups
-.Nd get group access list
+.Nd get the calling process' supplementary groups
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -40,36 +48,39 @@
.Sh DESCRIPTION
The
.Fn getgroups
-system call
-gets the current supplementary groups of the user process and stores it in the
-array
-.Fa gidset .
-The
+system call gets the calling process' supplementary groups and stores them in
+the
+.Fa gidset
+array in strictly ascending order.
+The value of
.Fa gidsetlen
-argument
-indicates the number of entries that may be placed in
-.Fa gidset .
-The
-.Fn getgroups
-system call
-returns the actual number of groups returned in
+indicates the maximum number of entries that may be placed in
.Fa gidset .
-As many as {NGROUPS_MAX} values may be returned.
+.Pp
If
.Fa gidsetlen
is zero,
.Fn getgroups
-returns the number of supplementary group IDs associated with
-the calling process without modifying the array pointed to by
+returns the cardinal of the calling process' supplementary groups set and
+ignores argument
.Fa gidset .
.Pp
+No more than
+.Dv {NGROUPS_MAX}
+values may ever be returned.
The value of
.Dv {NGROUPS_MAX}
should be obtained using
.Xr sysconf 3
to avoid hard-coding it into the executable.
.Sh RETURN VALUES
-A successful call returns the number of groups in the group set.
+On success, the
+.Fn getgroups
+system call returns the cardinal of the supplementary groups set.
+It always succeeds if argument
+.Fa gidsetlen
+is zero.
+.Pp
A value of -1 indicates that an error occurred, and the error
code is stored in the global variable
.Va errno .
@@ -81,12 +92,12 @@ are:
.It Bq Er EINVAL
The argument
.Fa gidsetlen
-is smaller than the number of groups in the group set.
+is smaller than the number of supplementary groups
+.Pq but not zero .
.It Bq Er EFAULT
-The argument
+An invalid address was encountered while reading from the
.Fa gidset
-specifies
-an invalid address.
+array.
.El
.Sh SEE ALSO
.Xr setgroups 2 ,
@@ -96,16 +107,48 @@ an invalid address.
The
.Fn getgroups
system call conforms to
-.St -p1003.1-2008 .
+.St -p1003.1-2008 ,
+not reporting the effective group ID.
.Sh HISTORY
The
.Fn getgroups
system call appeared in
.Bx 4.2 .
.Pp
+Since
+.Fx 14.3 ,
+the
+.Fn getgroups
+system call has been reporting the supplementary groups in strictly ascending
+order.
+.Pp
Before
.Fx 15.0 ,
the
.Fn getgroups
-system call always returned the effective group ID for the process as the first
+system call would additionally return the effective group ID as the first
element of the array, before the supplementary groups.
+.Sh SECURITY CONSIDERATIONS
+The
+.Fn getgroups
+system call gets the supplementary groups set in the
+.Fa gidset
+array.
+In particular, as evoked in
+.Sx HISTORY ,
+it does not anymore retrieve the effective group ID in the first slot of
+.Fa gidset .
+Programs that process this slot in a specific way must be modified to obtain the
+effective group ID through other means, such as a call to
+.Xr getegid 2 .
+.Pp
+The effective group ID is present in the supplementary groups set if and only if
+it was explicitly set as a supplementary group.
+The function
+.Fn initgroups
+enforces that, while the
+.Fn setgroups
+system call does not.
+Please consult the
+.Xr initgroups 3
+manual page for the rationale.
diff --git a/lib/libsys/getrlimitusage.2 b/lib/libsys/getrlimitusage.2
index e2114def56c2..d0e92d7f88b4 100644
--- a/lib/libsys/getrlimitusage.2
+++ b/lib/libsys/getrlimitusage.2
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd September 27, 2024
+.Dd October 24, 2025
.Dt GETRLIMITUSAGE 2
.Os
.Sh NAME
@@ -97,4 +97,4 @@ and
The
.Fn getrlimitusage
system call appeared in
-.Bx 15.0 .
+.Fx 14.2 .
diff --git a/lib/libsys/jail.2 b/lib/libsys/jail.2
index a0f47cc61cb3..ee4e5b03d38e 100644
--- a/lib/libsys/jail.2
+++ b/lib/libsys/jail.2
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd September 4, 2025
+.Dd September 15, 2025
.Dt JAIL 2
.Os
.Sh NAME
@@ -340,31 +340,6 @@ work the same as
and
.Fn jail_remove ,
except that they operate on the jail referred to by the passed descriptor.
-.Pp
-Jail operations via descriptors can be done by processes that do not
-normally have permission to see or affect the jail,
-as long as they are allowed by the file permissions of the jail
-descriptor itself.
-These permissions can be changed by the descriptor owner via
-.Xr fchmod 2
-and
-.Xr fchown 2 .
-.Fn jail_get
-requires read permission,
-.Fn jail_set
-and
-.Fn jail_remove
-require write permission,
-and
-.Fn jail_attach
-requires execute permission.
-Also, use of a descriptor with the
-.Dv JAIL_AT_DESC
-flag requires execute permission.
-An owning descriptor is identified by the
-.Em sticky bit ,
-which may also be changed via
-.Xr fchmod 2 .
.Sh RETURN VALUES
If successful,
.Fn jail ,
@@ -402,31 +377,6 @@ The
system call
will fail if:
.Bl -tag -width Er
-.It Bq Er EBADF
-The
-.Va desc
-parameter does not refer to a valid jail descriptor,
-and either the
-.Dv JAIL_USE_DESC
-or
-.Dv JAIL_AT_DESC
-flag was set.
-.It Bq Er EACCES
-Write permission is denied on the jail descriptor in the
-.Va desc
-parameter,
-and the
-.Dv JAIL_USE_DESC
-flag was set.
-.It Bq Er EACCES
-Execute permission is denied on the jail descriptor in the
-.Va desc
-parameter,
-and either the
-.Dv JAIL_AT_DESC
-or
-.Dv JAIL_ATTACH
-flag was set.
.It Bq Er EPERM
This process is not allowed to create a jail, either because it is not
the super-user, or because it would exceed the jail's
@@ -514,33 +464,6 @@ The
system call
will fail if:
.Bl -tag -width Er
-.It Bq Er EBADF
-The
-.Va desc
-parameter does not refer to a valid jail descriptor,
-and either the
-.Dv JAIL_USE_DESC
-or
-.Dv JAIL_AT_DESC
-flag was set.
-.It Bq Er EACCES
-Read permission is denied on the jail descriptor in the
-.Va desc
-parameter,
-and the
-.Dv JAIL_USE_DESC
-flag was set.
-.It Bq Er EACCES
-Execute permission is denied on the jail descriptor in the
-.Va desc
-parameter,
-and the
-.Dv JAIL_AT_DESC
-flag was set.
-.It Bq Er EFAULT
-.Fa Iov ,
-or one of the addresses contained within it,
-points to an address outside the allocated address space of the process.
.It Bq Er ENOENT
The jail referred to by a
.Va jid
@@ -564,6 +487,10 @@ parameter has been removed
.It Bq Er EINVAL
A supplied parameter is the wrong size.
.It Bq Er EINVAL
+A supplied parameter is out of range.
+.It Bq Er EINVAL
+A supplied string parameter is not null-terminated.
+.It Bq Er EINVAL
A supplied parameter name does not match any known parameters.
.It Bq Er EMFILE
A jail descriptor could not be created for the
@@ -607,18 +534,10 @@ and
system calls
will fail if:
.Bl -tag -width Er
-.It Bq Er EBADF
+.It Bq Er EINVAL
The
.Fa fd
argument is not a valid jail descriptor.
-.It Bq Er EACCES
-Permission is denied on the jail descriptor
-.Po
-execute permission for
-.Fn jail_attach_fd ,
-or write permission for
-.Fn jail_remove_fd
-.Pc .
.It Bq Er EPERM
The jail descriptor was created by a user other than the super-user.
.It Bq Er EINVAL
@@ -636,6 +555,9 @@ and
call
.Xr chroot 2
internally, so they can fail for all the same reasons.
+In particular, they return the
+.Bq Er EPERM
+error when the process to join a jail has open directories.
Please consult the
.Xr chroot 2
manual page for details.
diff --git a/lib/libsys/kexec_load.2 b/lib/libsys/kexec_load.2
new file mode 100644
index 000000000000..c3d458f34100
--- /dev/null
+++ b/lib/libsys/kexec_load.2
@@ -0,0 +1,119 @@
+.\"
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
+.\" Copyright (c) 2025 Juniper Networks, Inc.
+.\"
+.Dd October 29, 2025
+.Dt KEXEC_LOAD 2
+.Os
+.Sh NAME
+.Nm kexec_load
+.Nd prepare new kernel to reboot into
+.Sh SYNOPSIS
+.Lb libc
+.In sys/kexec.h
+.Ft int
+.Fn kexec_load "uint64_t entry" "unsigned long count" \
+ "struct kexec_segment *segments" "unsigned long flags"
+.Sh DESCRIPTION
+The
+.Fn kexec_load
+system call loads a new kernel that can be executed later by
+.Xr reboot 2 .
+Subsequent calls will replace previously loaded images.
+.Pp
+The
+.Fa flags
+argument is a bitmask of flags that control the operation of the call.
+This argument is present for compatibility with Linux, although it is currently
+unused and must be 0.
+.Pp
+The
+.Fa entry
+argument is the physical address of the entry point of the new kernel image.
+.Pp
+The
+.Fa count
+argument is the number of segments in the image, currently limited to 16.
+A value of 0 will unload the currently staged image, if one exists, without
+staging a new image.
+.Pp
+The
+.Fa segments
+argument is an array of
+.Fa count
+members of the following structure:
+.Bd -literal -offset indent
+struct kexec_segment {
+ void *buf;
+ size_t bufsz;
+ vm_paddr_t mem;
+ vm_size_t memsz;
+};
+.Ed
+.Pp
+The
+.Va buf
+and
+.Va bufsz
+members specify a memory region in the caller's address space containing the
+source of the segment.
+The
+.Va mem
+and
+.Va memsz
+members specify the target physical region of the segment.
+.Va bufsz
+must be less than or equal to
+.Va memsz ,
+and
+.Va mem
+and
+.Va memsz
+must be page aligned.
+The region covered by
+.Va mem
+must be in the list covered by the
+.Va vm.phys_segs
+sysctl.
+.Pp
+The
+.Fn kexec_load
+system call stages the kernel image in safe memory along with all
+machine-dependent image data until
+.Xr reboot 2
+is called with the
+.Va RB_KEXEC
+flag to load the image and execute the new kernel.
+.Sh RETURN VALUES
+The
+.Fn kexec_load
+system call returns 0 on success.
+On failure, -1 is returned, and
+.Va errno
+is set to indicate the error.
+On success any previously loaded image is unloaded and replaced with the new
+image.
+On failure, the previously loaded image is unchanged.
+.Sh ERRORS
+The following errors may be returned:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Too many segments in image.
+.It Bq Er EINVAL
+The value of
+.Va bufsz
+is larger than
+.Va memsz
+in one or more segments.
+.It Bq Er EINVAL
+Machine-dependent load error.
+.It Bq Er EBUSY
+Another
+.Fn kexec_load
+call is in progress.
+.Sh HISTORY
+The
+.Nm
+system call appeared in
+.Fx 16.0 .
diff --git a/lib/libsys/kqueue.2 b/lib/libsys/kqueue.2
index e413f7d4fbca..a8ebabf02cf7 100644
--- a/lib/libsys/kqueue.2
+++ b/lib/libsys/kqueue.2
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd September 4, 2025
+.Dd September 12, 2025
.Dt KQUEUE 2
.Os
.Sh NAME
@@ -97,10 +97,37 @@ system call also creates a new kernel event queue, and additionally takes
a
.Fa flags
argument, which is a bitwise-inclusive OR of the following flags:
-.Bl -tag -width "KQUEUE_CLOEXEC"
+.Bl -tag -width "KQUEUE_CPONFORK"
.It Dv KQUEUE_CLOEXEC
The returned file descriptor is automatically closed on
.Xr execve 2
+.It Dv KQUEUE_CPONFORK
+When this flag is set, the created kqueue is copied into
+the child process on
+.Xr fork 2
+calls.
+The kqueue descriptor index of the new kqueue will be inherited by the child,
+that is, the numeric value of the descriptor will remain the same.
+.Pp
+Copying is deep, that is, each registered event in the original kqueue is
+copied (and not shared) into the new kqueue.
+This is contrary to how other descriptor types are handled upon
+.Xr fork 2 ,
+where the copied file descriptor references the same file object
+as the source descriptor (shallow copy).
+.Pp
+By default, in other words, when the flag is not set, kqueues from
+the parent are not copied on fork to the child process.
+The corresponding file descriptor indeces are unused in the child.
+.Pp
+Registered events that reference file descriptors which are not
+duplicated on fork, are not copied into the new kqueue.
+For instance, if the event references a file descriptor opened with the
+.Dv O_CLOEXEC
+flag set, it is not copied.
+Similarly, if event references a kqueue opened without the
+.Dv KQUEUE_CPONFORK
+flag, the event is not copied.
.El
.Pp
The
@@ -614,41 +641,43 @@ The process ID will be stored in
If more than one process has attached since the last call to
.Fn kevent ,
.Va data
-will contain the most recently attached process ID,
-with
-.Dv NOTE_JAIL_ATTACH_MULTI
-set in
-.Va fflags .
+will be zero.
.It Dv NOTE_JAIL_REMOVE
The jail has been removed.
.It Dv NOTE_JAIL_CHILD
A child of the watched jail has been created.
-.It Dv NOTE_TRACK
-Follow child jails created under this jail.
-Register a new kevent to monitor the child jail using the same
-.Va fflags
-as the original event.
-The child jail will signal an event with
-.Dv NOTE_CHILD
-set in
-.Va fflags
-and the parent JID in
+Its jail ID will be stored in
.Va data .
-.Pp
-If registering a new kevent fails
-.Pq usually due to resource limitations ,
-it will signal an event with
-.Dv NOTE_TRACKERR
-set in
-.Va fflags ,
-and the child jail will not signal a
-.Dv NOTE_CHILD
-event.
+If more than one jail has been created since the last call to
+.Fn kevent ,
+.Va data
+will be zero.
.El
.Pp
On return,
.Va fflags
contains the events which triggered the filter.
+It will also contain
+.Dv NOTE_JAIL_MULTI
+if more than one
+.Dv NOTE_JAIL_ATTACH
+or
+.Dv NOTE_JAIL_CHILD
+event has been received since the last call to
+.Fn kevent .
+.It Dv EVFILT_JAILDESC
+Takes a jail descriptor returned by
+.Xr jail_set 2
+or
+.Xr jail_get 2
+as the identifier and the events to watch for in
+.Va fflags ,
+and returns when the jail performs one or more of the requested events.
+The events to monitor and the resulting
+.Va fflags
+are the same as those listed in
+.Dv EVFILT_JAIL ,
+above.
.It Dv EVFILT_TIMER
Establishes an arbitrary timer identified by
.Va ident .
diff --git a/lib/libsys/lseek.2 b/lib/libsys/lseek.2
index 6df543d8ce72..7fabe8fc3b4d 100644
--- a/lib/libsys/lseek.2
+++ b/lib/libsys/lseek.2
@@ -209,7 +209,8 @@ and
.Dv SEEK_DATA
directives, along with the
.Er ENXIO
-error, are extensions to that specification.
+error, are expected to conform to
+.St -p1003.1-2024 .
.Sh HISTORY
The
.Fn lseek
diff --git a/lib/libsys/pathconf.2 b/lib/libsys/pathconf.2
index 5a983a3a13e2..5348128be706 100644
--- a/lib/libsys/pathconf.2
+++ b/lib/libsys/pathconf.2
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 6, 2025
+.Dd October 31, 2025
.Dt PATHCONF 2
.Os
.Sh NAME
@@ -180,7 +180,8 @@ Return 1 if named attributes are enabled for the file system, otherwise 0.
.It Li _PC_HAS_NAMEDATTR
Return 1 if one or more named attributes exist for the file, otherwise 0.
.It Li _PC_HAS_HIDDENSYSTEM
-Return 1 if both
+Return 1 if all of the
+.Dv UF_ARCHIVE ,
.Dv UF_HIDDEN
and
.Dv UF_SYSTEM
@@ -192,6 +193,9 @@ Returns the block size required for block cloning via
.Xr copy_file_range 2
for a file system if block cloning is supported,
otherwise 0.
+.It Li _PC_CASE_INSENSITIVE
+Return 1 if the file system performs case insensitive lookups,
+otherwise 0.
.El
.Sh RETURN VALUES
If the call to
diff --git a/lib/libsys/posix_fallocate.2 b/lib/libsys/posix_fallocate.2
index 8be075b41331..94858c4a0f90 100644
--- a/lib/libsys/posix_fallocate.2
+++ b/lib/libsys/posix_fallocate.2
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 30, 2020
+.Dd November 2, 2025
.Dt POSIX_FALLOCATE 2
.Os
.Sh NAME
@@ -105,8 +105,7 @@ The
.Fa len
argument was less than or equal to zero, the
.Fa offset
-argument was less than zero,
-or the operation is not supported by the file system.
+argument was less than zero.
.It Bq Er EIO
An I/O error occurred while reading from or writing to a file system.
.It Bq Er EINTEGRITY
@@ -123,6 +122,8 @@ media.
The file descriptor
.Fa fd
has insufficient rights.
+.It Bq Er EOPNOTSUPP
+The operation is not supported by the file system.
.It Bq Er ESPIPE
The
.Fa fd
@@ -137,12 +138,29 @@ argument is associated with a pipe or FIFO.
The
.Fn posix_fallocate
system call conforms to
-.St -p1003.1-2004 .
+.St -p1003.1-2024 .
.Sh HISTORY
The
.Fn posix_fallocate
function appeared in
.Fx 9.0 .
+.Pp
+Previous versions of
+.Nm
+used
+.Er EINVAL
+to indicate that the operation is not supported by the file system, as specified
+in
+.St -p1003.1
+Base Specifications, Issue 7.
+.St -p1003.1
+Base Specifications, Issue 8 switched to requiring
+.Er EOPNOTSUPP
+for this error case.
+ZFS adopted the latter convention in
+.Fx 15.0 ,
+and the remaining filesystems in base adopted it in
+.Fx 15.1 .
.Sh AUTHORS
.Fn posix_fallocate
and this manual page were initially written by
diff --git a/lib/libsys/reboot.2 b/lib/libsys/reboot.2
index f6c7bf6c83cc..54fa8b599cd5 100644
--- a/lib/libsys/reboot.2
+++ b/lib/libsys/reboot.2
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 10, 2018
+.Dd October 29, 2025
.Dt REBOOT 2
.Os
.Sh NAME
@@ -126,6 +126,10 @@ on the console.
is actually interpreted by the
.Xr init 8
program in the newly booted system.
+.It Dv RB_KEXEC
+Execute a new kernel loaded via
+.Fn kexec_load 2 .
+If no kernel was loaded, reboot as normal.
.El
.Pp
When no options are given (i.e.,
@@ -149,6 +153,7 @@ variable
The caller is not the super-user.
.El
.Sh SEE ALSO
+.Xr kexec_load 2 ,
.Xr crash 8 ,
.Xr halt 8 ,
.Xr init 8 ,
diff --git a/lib/libsys/revoke.2 b/lib/libsys/revoke.2
index f5ae1e92c357..938d2f083e27 100644
--- a/lib/libsys/revoke.2
+++ b/lib/libsys/revoke.2
@@ -28,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 25, 2016
+.Dd October 24, 2025
.Dt REVOKE 2
.Os
.Sh NAME
@@ -62,7 +62,7 @@ using a special close method which does not block.
Access to a file may be revoked only by its owner or the super user.
The
.Fn revoke
-system call is currently supported only for block and character special
+system call is currently supported only for character special
device files.
It is normally used to prepare a terminal device for a new login session,
preventing any access by a previous user of the terminal.
diff --git a/lib/libsys/setcred.2 b/lib/libsys/setcred.2
index 86f61ddfdb30..f5d1f15b631b 100644
--- a/lib/libsys/setcred.2
+++ b/lib/libsys/setcred.2
@@ -6,7 +6,7 @@
.\" This documentation was written by Olivier Certner <olce.freebsd@certner.fr>
.\" at Kumacom SARL under sponsorship from the FreeBSD Foundation.
.\"
-.Dd December 19, 2024
+.Dd August 29, 2025
.Dt SETCRED 2
.Os
.Sh NAME
@@ -119,11 +119,6 @@ It must be less than or equal to
An array of IDs to set the supplementary groups to, if flag
.Dv SETCREDF_SUPP_GROUPS
is specified.
-Note that all groups in this array will be set as supplementary groups only, in
-contrast to
-.Xr setgroups 2
-which treats the first element specially as the new effective group, not adding
-it to supplementary groups.
.It Fa sc_label
A pointer to a valid MAC label structure, e.g., built with the
.Xr mac_from_text 3
diff --git a/lib/libsys/setgroups.2 b/lib/libsys/setgroups.2
index 451f63ba1266..0ec99507cfb0 100644
--- a/lib/libsys/setgroups.2
+++ b/lib/libsys/setgroups.2
@@ -1,5 +1,13 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-3-Clause
+.\"
.\" Copyright (c) 1983, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
+.\" Copyright (c) 2025 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Olivier Certner
+.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
+.\" Foundation.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -25,12 +33,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 1, 2025
+.Dd September 17, 2025
.Dt SETGROUPS 2
.Os
.Sh NAME
.Nm setgroups
-.Nd set group access list
+.Nd set the calling process' supplementary groups
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -41,21 +49,21 @@
.Sh DESCRIPTION
The
.Fn setgroups
-system call
-sets the supplementary group list of the current user process
-according to the array
-.Fa gidset .
+system call sets the calling process' supplementary groups according to the
+.Fa gidset
+array.
The
.Fa ngroups
-argument
-indicates the number of entries in the array and must be no
-more than
+argument indicates the number of entries in the array and must be no more than
.Dv {NGROUPS_MAX} .
+.Pp
The
.Fa ngroups
-argument may be set to 0 to clear the supplementary group list.
+argument may be set to zero to clear all supplementary groups, in which case
+.Fa gidset
+is ignored.
.Pp
-Only the super-user may set a new supplementary group list.
+Only the super-user may install a new supplementary groups set.
.Sh RETURN VALUES
.Rv -std setgroups
.Sh ERRORS
@@ -69,16 +77,16 @@ The caller is not the super-user.
The number specified in the
.Fa ngroups
argument is larger than the
-.Dv {NGROUPS_MAX}+1
+.Dv {NGROUPS_MAX}
limit.
.It Bq Er EFAULT
-The address specified for
+Part of the groups array starting at
.Fa gidset
-is outside the process
-address space.
+is outside the process address space.
.El
.Sh SEE ALSO
.Xr getgroups 2 ,
+.Xr setcred 2 ,
.Xr initgroups 3
.Sh HISTORY
The
@@ -92,4 +100,63 @@ the
.Fn setgroups
system call would set the effective group ID for the process to the first
element of
-.Fa gidset .
+.Fa gidset ,
+and only the other elements as supplementary groups.
+Despite treating the first element as the effective group ID to set, it accepted
+an empty
+.Fa gidset
+.Po
+.Fa ngroups
+being zero
+.Pc
+as a stance requiring to drop all supplementary groups, leaving the effective
+group ID unchanged.
+.Sh SECURITY CONSIDERATIONS
+The
+.Fn setgroups
+system call sets the process' supplementary groups to those contained in the
+.Fa gidset
+array.
+In particular, as evoked in
+.Sx HISTORY ,
+it does not anymore treat the first element of
+.Fa gidset
+separately.
+Formerly, it would set it as the effective group ID while only the others were
+used as supplementary groups.
+.Pp
+Programs solely relying on
+.Fn setgroups
+to change the effective group ID must be modified, e.g., to also call
+.Xr setegid 2
+or to instead use
+.Xr setcred 2 ,
+else they will unwillingly keep their effective group ID.
+.Pp
+Programs using
+.Fn setgroups
+with the effective group ID as the first element of array
+.Fa gidset
+and not duplicating it in the rest of the array, which includes those using
+.Fn initgroups ,
+now insert this group ID in the supplementary groups set.
+This is in general desirable, as explained in the
+.Xr initgroups 3
+manual page, and has the consequence that subsequent process' effective group
+ID's changes do not remove membership of the original effective group ID, since
+these changes do not affect the supplementary groups.
+Applications that expressly do not want that must be modified to stop passing
+the effective group ID as the first element to
+.Fn setgroups .
+.Pp
+To clear all the calling process' supplementary groups, always use the statement
+.Bd -literal -offset indent
+setgroups(0, NULL);
+.Ed
+.Pp
+which works also on older FreeBSD version
+.Po
+see the
+.Sx HISTORY
+section
+.Pc .
diff --git a/lib/libsys/socket.2 b/lib/libsys/socket.2
index b211611c6354..48b8f4e87489 100644
--- a/lib/libsys/socket.2
+++ b/lib/libsys/socket.2
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 17, 2025
+.Dd September 28, 2025
.Dt SOCKET 2
.Os
.Sh NAME
@@ -64,7 +64,7 @@ PF_NETGRAPH Netgraph sockets,
PF_NETLINK Netlink protocols,
PF_BLUETOOTH Bluetooth protocols,
PF_INET_SDP OFED socket direct protocol (IPv4),
-AF_HYPERV HyperV sockets
+PF_HYPERV HyperV sockets
.Ed
.Pp
Each protocol family is connected to an address family, which has the
@@ -89,32 +89,6 @@ SOCK_RAW Raw-protocol interface,
SOCK_SEQPACKET Sequenced packet stream
.Ed
.Pp
-A
-.Dv SOCK_STREAM
-type provides sequenced, reliable,
-two-way connection based byte streams.
-An out-of-band data transmission mechanism may be supported.
-A
-.Dv SOCK_DGRAM
-socket supports
-datagrams (connectionless, unreliable messages of
-a fixed (typically small) maximum length).
-A
-.Dv SOCK_SEQPACKET
-socket may provide a sequenced, reliable,
-two-way connection-based data transmission path for datagrams
-of fixed maximum length; a consumer may be required to read
-an entire packet with each read system call.
-This facility may have protocol-specific properties.
-.Dv SOCK_RAW
-sockets provide access to internal network protocols and interfaces.
-The
-.Dv SOCK_RAW
-type is available only to the super-user and is described in
-.Xr ip 4
-and
-.Xr ip6 4 .
-.Pp
Additionally, the following flags are allowed in the
.Fa type
argument:
@@ -140,32 +114,23 @@ particular to the
in which communication
is to take place; see
.Xr protocols 5 .
-.Pp
The
.Fa protocol
argument may be set to zero (0) to request the default
implementation of a socket type for the protocol, if any.
-.Pp
-Sockets of type
+.Sh STREAM SOCKET TYPE
+The
+.Dv SOCK_STREAM
+socket type provides reliable, sequenced, full-duplex octet streams between
+the socket and a peer to which the socket is connected.
+A socket of type
.Dv SOCK_STREAM
-are full-duplex byte streams, similar
-to pipes.
-A stream socket must be in a
+needs to be in a
.Em connected
-state before any data may be sent or received
-on it.
+state before any data can be sent or received.
A connection to another socket is created with a
.Xr connect 2
system call.
-Once connected, data may be transferred using
-.Xr read 2
-and
-.Xr write 2
-calls or some variant of the
-.Xr send 2
-and
-.Xr recv 2
-functions.
(Some protocol families, such as the Internet family,
support the notion of an
.Dq implied connect ,
@@ -173,62 +138,210 @@ which permits data to be sent piggybacked onto a connect operation by
using the
.Xr sendto 2
system call.)
-When a session has been completed a
-.Xr close 2
-may be performed.
-Out-of-band data may also be transmitted as described in
+Once connected, data may be sent using
+.Xr send 2 ,
+.Xr sendto 2 ,
+.Xr sendmsg 2
+and
+.Xr write 2
+system calls.
+Data may be received using
+.Xr recv 2 ,
+.Xr recvfrom 2 ,
+.Xr recvmsg 2 ,
+and
+.Xr read 2
+system calls.
+Record boundaries are not maintained; data sent on a stream socket using output
+operations of one size can be received using input operations of smaller or
+larger sizes without loss of data.
+Data may be buffered; successful return from an output function does not imply
+that the data has been delivered to the peer or even transmitted from the local
+system.
+For certain protocols out-of-band data may also be transmitted as described in
.Xr send 2
and received as described in
.Xr recv 2 .
.Pp
-The communications protocols used to implement a
-.Dv SOCK_STREAM
-ensure that data
-is not lost or duplicated.
-If a piece of data for which the
-peer protocol has buffer space cannot be successfully transmitted
-within a reasonable length of time, then
-the connection is considered broken and calls
-will indicate an error with
--1 returns and with
-.Er ETIMEDOUT
-as the specific code
-in the global variable
-.Va errno .
-The protocols optionally keep sockets
-.Dq warm
-by forcing transmissions
-roughly every minute in the absence of other activity.
-An error is then indicated if no response can be
-elicited on an otherwise
-idle connection for an extended period (e.g.\& 5 minutes).
-By default, a
+If data cannot be successfully transmitted within a given time then the
+connection is considered broken, and subsequent operations shall fail with
+a protocol specific error code.
+A
.Dv SIGPIPE
-signal is raised if a process sends
-on a broken stream, but this behavior may be inhibited via
+signal is raised if a thread attempts to send data on a broken stream (one that
+is no longer connected).
+The signal can be suppressed by the
+.Dv MSG_NOSIGNAL
+flag with distinct
+.Xr send 2 ,
+.Xr sendto 2 ,
+and
+.Xr sendmsg 2
+system calls or by the
+.Dv SO_NOSIGPIPE
+socket option set on the socket with
.Xr setsockopt 2 .
.Pp
-.Dv SOCK_SEQPACKET
-sockets employ the same system calls
-as
+The
.Dv SOCK_STREAM
-sockets.
-The only difference
-is that
-.Xr read 2
-calls will return only the amount of data requested,
-and any remaining in the arriving packet will be discarded.
+socket is supported by the following protocol families:
+.Dv PF_INET ,
+.Dv PF_INET6 ,
+.Dv PF_UNIX ,
+.Dv PF_BLUETOOTH ,
+.Dv PF_HYPERV ,
+and
+.Dv PF_INET_SDP .
+Out-of-band data transmission mechanism is supported for stream sockets of
+.Dv PF_INET
+and
+.Dv PF_INET6
+protocol families.
+.Sh DATAGRAM SOCKET TYPE
+The
+.Dv SOCK_DGRAM
+socket type supports connectionless data transfer which is not necessarily
+acknowledged or reliable.
+Datagrams can be sent to the address specified (possibly multicast or
+broadcast) in each output operation, and incoming datagrams can be received
+from multiple sources.
+The source address of each datagram is available when receiving the datagram
+with
+.Xr recvfrom 2
+or
+.Xr recvmsg 2 .
+An application can also pre-specify a peer address with
+.Xr sendto 2
+or
+.Xr sendmsg 2 ,
+in which case calls to output functions that do not specify a peer address
+shall send to the pre-specified peer.
+If a peer has been specified, only datagrams from that peer shall be received.
+A datagram shall be sent in a single output operation, and needs to be received
+in a single input operation.
+The maximum size of a datagram is protocol-specific.
+Output datagrams may be buffered within the system; thus, a successful return
+from an output function does not guarantee that a datagram is actually sent or
+received.
.Pp
+The
.Dv SOCK_DGRAM
+socket is supported by the following protocol families:
+.Dv PF_INET ,
+.Dv PF_INET6 ,
+.Dv PF_UNIX ,
+.Dv PF_NETGRAPH ,
and
-.Dv SOCK_RAW
-sockets allow sending of datagrams to correspondents
-named in
+.Dv PF_NETLINK .
+.Sh SEQUENCED PACKET SOCKET TYPE
+The
+.Dv SOCK_SEQPACKET
+socket type is similar to the
+.Dv SOCK_STREAM
+type, and is also connection-oriented.
+The only difference between these types is that record boundaries are
+maintained using the
+.Dv SOCK_SEQPACKET
+type.
+A record can be sent using one or more output operations and received using one
+or more input operations, but a single operation never transfers parts of more
+than one record.
+Record boundaries are set by the sender with the
+.Dv MSG_EOR
+flag of
.Xr send 2
-calls.
-Datagrams are generally received with
+or
+.Xr sendmsg 2
+functions.
+There is no possibility to set a record boundary with
+.Xr write 2 .
+Record boundaries are visible to the receiver via the
+.Dv MSG_EOR
+flag in the received message flags returned by the
+.Xr recvmsg 2
+function.
+It is protocol-specific whether a maximum record size is imposed.
+.Pp
+The
+.Dv SOCK_SEQPACKET
+socket is supported by the following protocol families:
+.Dv PF_INET ,
+.Dv PF_INET6 ,
+and
+.Dv PF_UNIX .
+.Pp
+.Sh RAW SOCKET TYPE
+The
+.Dv SOCK_RAW
+socket type provides access to internal network protocols and interfaces.
+It is a datagram socket in its nature, thus has the same semantics of
+read and write operations.
+The
+.Dv SOCK_RAW
+type is available only to the super-user and is described in
+.Xr ip 4
+and
+.Xr ip6 4 .
+.Sh NON-BLOCKING MODE
+A socket can be created in
+.Em non-blocking mode
+with the help of
+.Dv SOCK_NONBLOCK
+flag.
+Alternatively, the non-blocking mode on a socket can be turned on and off with
+the help of the
+.Dv O_NONBLOCK
+flag of the
+.Xr fcntl 2
+system call.
+.Pp
+When a non-blocking socket has not enough data in its receive buffer to fulfill
+the application supplied buffer, then data receiving system calls like
+.Xr recv 2 ,
.Xr recvfrom 2 ,
-which returns the next datagram with its return address.
+.Xr recvmsg 2
+and
+.Xr read 2
+will not block waiting for the data but immediately return.
+Return value will indicate amount of bytes read into the supplied buffer.
+The
+.Va errno
+will be set to
+.Dv EAGAIN
+.Po
+has same value as
+.Dv EWOULDBLOCK
+.Pc .
+.Pp
+If application tries to send more data on a non-blocking socket than the socket
+send buffer can accomodate with
+.Xr send 2 ,
+.Xr sendto 2 ,
+.Xr sendmsg 2
+or
+.Xr write 2
+system calls partial data will be sent.
+Return value will indicate amount of bytes sent.
+The
+.Va errno
+will be set to
+.Dv EAGAIN .
+Note that sockets of
+.Dv SOCK_DGRAM
+type are unreliable, thus for these sockets sending operations will never fail
+with
+.Dv EAGAIN
+in non-blocking mode neither will block in blocking mode.
+.Sh OTHER OPERATIONS ON SOCKETS
+Since socket descriptors are file descriptors, many generic file operations
+performed by
+.Xr fcntl 2 ,
+apply.
+Socket descriptors can be used with all event engines, such as
+.Xr kevent 2 ,
+.Xr select 2
+and
+.Xr poll 2 .
.Pp
An
.Xr fcntl 2
@@ -250,6 +363,12 @@ The
and
.Xr getsockopt 2
system calls are used to set and get options, respectively.
+.Pp
+Connection associated with a socket can be terminated by
+.Xr close 2
+system call.
+One direction of communication can be disabled with
+.Xr shutdown 2 .
.Sh RETURN VALUES
A -1 is returned if an error occurs, otherwise the return
value is a descriptor referencing the socket.
@@ -282,16 +401,23 @@ The socket type is not supported by the protocol.
.Sh SEE ALSO
.Xr accept 2 ,
.Xr bind 2 ,
+.Xr close 2 ,
.Xr connect 2 ,
+.Xr fcntl 2 ,
.Xr getpeername 2 ,
.Xr getsockname 2 ,
.Xr getsockopt 2 ,
.Xr ioctl 2 ,
+.Xr kevent 2 ,
.Xr listen 2 ,
+.Xr poll 2 ,
.Xr read 2 ,
.Xr recv 2 ,
.Xr select 2 ,
.Xr send 2 ,
+.Xr sendmsg 2 ,
+.Xr sendto 2 ,
+.Xr signal 3 ,
.Xr shutdown 2 ,
.Xr socketpair 2 ,
.Xr write 2 ,
diff --git a/lib/libsys/syscalls.map b/lib/libsys/syscalls.map
index b5400b9849b3..d00c862eb462 100644
--- a/lib/libsys/syscalls.map
+++ b/lib/libsys/syscalls.map
@@ -817,4 +817,6 @@ FBSDprivate_1.0 {
__sys_jail_attach_jd;
_jail_remove_jd;
__sys_jail_remove_jd;
+ _kexec_load;
+ __sys_kexec_load;
};
diff --git a/lib/libsys/write.2 b/lib/libsys/write.2
index d2ff41ceead9..77067893ab4c 100644
--- a/lib/libsys/write.2
+++ b/lib/libsys/write.2
@@ -132,6 +132,26 @@ and
may write fewer bytes than requested;
the return value must be noted,
and the remainder of the operation should be retried when possible.
+.Sh ATOMICITY OF WRITES
+When operating on regular files on local file systems, the effects of
+.Fn write
+are atomic.
+As required by the POSIX standard,
+the
+.Fn read ,
+.Fn write ,
+and
+.Fn ftruncate
+functions and their variations are atomic with respect to
+each other on the file data and metadata for regular files.
+See for instance
+.St -p1003.1-2024
+Volume 2, Section 2.9.7 for more information.
+.Pp
+.Fx
+implements the requirement by taking
+a read/write range lock on the file byte range
+affected by the corresponding function.
.Sh RETURN VALUES
Upon successful completion the number of bytes which were written
is returned.
diff --git a/lib/libsysdecode/Makefile.depend b/lib/libsysdecode/Makefile.depend
index 1c40e21d361d..a9ccf3aa0870 100644
--- a/lib/libsysdecode/Makefile.depend
+++ b/lib/libsysdecode/Makefile.depend
@@ -38,7 +38,7 @@ DIRDEPS = \
lib/libarchive \
lib/libbe \
lib/libbegemot \
- lib/libblacklist \
+ lib/libblocklist \
lib/libblocksruntime \
lib/libbluetooth \
lib/libbsddialog \
diff --git a/lib/libtacplus/Makefile b/lib/libtacplus/Makefile
index 43567350aeac..2149b57b124a 100644
--- a/lib/libtacplus/Makefile
+++ b/lib/libtacplus/Makefile
@@ -29,7 +29,9 @@ INCS= taclib.h
CFLAGS+= -Wall
LIBADD= md pam
SHLIB_MAJOR= 5
-MAN= libtacplus.3 tacplus.conf.5
+
+MAN= libtacplus.3
+MANNODEV= tacplus.conf.5
WARNS?= 2
diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile
index ab913f834bb3..3b1911d7a5cd 100644
--- a/lib/libufs/Makefile
+++ b/lib/libufs/Makefile
@@ -1,4 +1,6 @@
-PACKAGE= libufs
+PACKAGE= ufs
+LIB_PACKAGE=
+
LIB= ufs
SHLIBDIR?= /lib
SHLIB_MAJOR= 8
diff --git a/lib/libunbound/Makefile b/lib/libunbound/Makefile
index cdc965c20763..1a31e50e6416 100644
--- a/lib/libunbound/Makefile
+++ b/lib/libunbound/Makefile
@@ -1,4 +1,3 @@
-PACKAGE=lib${LIB}
# Vendor sources and generated files
LDNSDIR= ${SRCTOP}/contrib/ldns
UNBOUNDDIR= ${SRCTOP}/contrib/unbound
@@ -6,30 +5,28 @@ UNBOUNDDIR= ${SRCTOP}/contrib/unbound
# Hold my beer and watch this
.PATH: ${UNBOUNDDIR} ${UNBOUNDDIR}/cachedb ${UNBOUNDDIR}/dns64 ${UNBOUNDDIR}/iterator ${UNBOUNDDIR}/sldns ${UNBOUNDDIR}/libunbound ${UNBOUNDDIR}/services ${UNBOUNDDIR}/services/cache ${UNBOUNDDIR}/util ${UNBOUNDDIR}/util/data ${UNBOUNDDIR}/respip ${UNBOUNDDIR}/util/storage ${UNBOUNDDIR}/validator
-LIB= unbound
+PACKAGE= local-unbound
+
+LIB= unbound
PRIVATELIB=
-PACKAGE= unbound
CFLAGS+= -I${UNBOUNDDIR} -I${LDNSDIR} -I${.OBJDIR} -I${.CURDIR}
CFLAGS+= -DOPENSSL_API_COMPAT=0x10100000L
-SRCS= alloc.c as112.c authzone.c autotrust.c cachedb.c config_file.c \
- configlexer.l configparser.y context.c dname.c dns.c dns64.c \
- dnstree.c edns.c fptr_wlist.c infra.c iter_delegpt.c iter_donotq.c \
- iter_fwd.c iter_hints.c iter_priv.c iter_resptype.c iter_scrub.c \
- iter_utils.c iterator.c keyraw.c libunbound.c libworker.c \
- listen_dnsport.c localzone.c locks.c log.c lookup3.c lruhash.c \
- mesh.c mini_event.c modstack.c module.c msgencode.c msgparse.c \
- msgreply.c net_help.c netevent.c outbound_list.c outside_network.c \
- packed_rrset.c parse.c parseutil.c proxy_protocol.c \
- random.c rbtree.c redis.c \
- regional.c respip.c rfc_1982.c rpz.c rrdef.c rrset.c rtt.c sbuffer.c \
- siphash.c slabhash.c \
- str2wire.c tcp_conn_limit.c timehist.c timeval_func.c \
- tube.c ub_event_pluggable.c \
- val_anchor.c val_kcache.c val_kentry.c val_neg.c val_nsec.c \
- val_nsec3.c val_secalgo.c val_sigcrypt.c val_utils.c validator.c \
- view.c winsock_event.c wire2str.c
+SRCS= alloc.c as112.c authzone.c autotrust.c config_file.c configlexer.l \
+ configparser.y context.c dname.c dns.c dns64.c dnstree.c edns.c \
+ fptr_wlist.c infra.c iter_delegpt.c iter_donotq.c iter_fwd.c \
+ iter_hints.c iter_priv.c iter_resptype.c iter_scrub.c iter_utils.c \
+ iterator.c keyraw.c libunbound.c libworker.c listen_dnsport.c \
+ localzone.c locks.c log.c lookup3.c lruhash.c mesh.c mini_event.c \
+ modstack.c module.c msgencode.c msgparse.c msgreply.c net_help.c \
+ netevent.c outbound_list.c outside_network.c packed_rrset.c parse.c \
+ parseutil.c proxy_protocol.c random.c rbtree.c regional.c respip.c \
+ rfc_1982.c rpz.c rrdef.c rrset.c rtt.c sbuffer.c siphash.c \
+ slabhash.c str2wire.c tcp_conn_limit.c timehist.c timeval_func.c \
+ tube.c ub_event_pluggable.c val_anchor.c val_kcache.c val_kentry.c \
+ val_neg.c val_nsec.c val_nsec3.c val_secalgo.c val_sigcrypt.c \
+ val_utils.c validator.c view.c winsock_event.c wire2str.c
WARNS?= 2
NO_WTHREAD_SAFETY= true
diff --git a/lib/libunbound/config.h b/lib/libunbound/config.h
index a986bfc869a3..1b939b7f1074 100644
--- a/lib/libunbound/config.h
+++ b/lib/libunbound/config.h
@@ -20,7 +20,7 @@
/* #undef COMPAT_SHA512 */
/* Command line arguments used with configure */
-#define CONFCMDLINE "--with-ssl=/usr --with-libexpat=/usr --disable-dnscrypt --disable-dnstap --enable-ecdsa --disable-event-api --enable-gost --with-libevent --disable-subnet --disable-tfo-client --disable-tfo-server --with-pthreads--prefix=/usr --localstatedir=/var/unbound --mandir=/usr/share/man --build=freebsd"
+#define CONFCMDLINE "--prefix= --exec-prefix=/usr --with-conf-file=/var/unbound/unbound.conf --with-run-dir=/var/unbound --with-username=unbound"
/* Pathname to the Unbound configuration file */
#define CONFIGFILE "/var/unbound/unbound.conf"
@@ -49,13 +49,13 @@
internal symbols */
/* #undef EXPORT_ALL_SYMBOLS */
-/* Define to 1 if you have the `accept4' function. */
+/* Define to 1 if you have the 'accept4' function. */
#define HAVE_ACCEPT4 1
-/* Define to 1 if you have the `arc4random' function. */
+/* Define to 1 if you have the 'arc4random' function. */
#define HAVE_ARC4RANDOM 1
-/* Define to 1 if you have the `arc4random_uniform' function. */
+/* Define to 1 if you have the 'arc4random_uniform' function. */
#define HAVE_ARC4RANDOM_UNIFORM 1
/* Define to 1 if you have the <arpa/inet.h> header file. */
@@ -77,13 +77,10 @@
#define HAVE_ATTR_WEAK 1
/* If we have be64toh */
-/* #undef HAVE_BE64TOH */
+#define HAVE_BE64TOH 1
-/* Define to 1 if you have the `BIO_set_callback_ex' function. */
-/* #undef HAVE_BIO_SET_CALLBACK_EX */
-
-/* Define to 1 if you have the `BIO_set_callback_ex' function. */
-/* #undef HAVE_BIO_SET_CALLBACK_EX */
+/* Define to 1 if you have the 'BIO_set_callback_ex' function. */
+#define HAVE_BIO_SET_CALLBACK_EX 1
/* Define to 1 if you have the <bsd/stdlib.h> header file. */
/* #undef HAVE_BSD_STDLIB_H */
@@ -91,241 +88,241 @@
/* Define to 1 if you have the <bsd/string.h> header file. */
/* #undef HAVE_BSD_STRING_H */
-/* Define to 1 if you have the `chown' function. */
+/* Define to 1 if you have the 'chown' function. */
#define HAVE_CHOWN 1
-/* Define to 1 if you have the `chroot' function. */
+/* Define to 1 if you have the 'chroot' function. */
#define HAVE_CHROOT 1
-/* Define to 1 if you have the `CRYPTO_cleanup_all_ex_data' function. */
+/* Define to 1 if you have the 'CRYPTO_cleanup_all_ex_data' function. */
/* #undef HAVE_CRYPTO_CLEANUP_ALL_EX_DATA */
-/* Define to 1 if you have the `CRYPTO_THREADID_set_callback' function. */
+/* Define to 1 if you have the 'CRYPTO_THREADID_set_callback' function. */
/* #undef HAVE_CRYPTO_THREADID_SET_CALLBACK */
-/* Define to 1 if you have the `ctime_r' function. */
+/* Define to 1 if you have the 'ctime_r' function. */
#define HAVE_CTIME_R 1
-/* Define to 1 if you have the `daemon' function. */
+/* Define to 1 if you have the 'daemon' function. */
#define HAVE_DAEMON 1
-/* Define to 1 if you have the declaration of `arc4random', and to 0 if you
+/* Define to 1 if you have the declaration of 'arc4random', and to 0 if you
don't. */
/* #undef HAVE_DECL_ARC4RANDOM */
-/* Define to 1 if you have the declaration of `arc4random_uniform', and to 0
+/* Define to 1 if you have the declaration of 'arc4random_uniform', and to 0
if you don't. */
/* #undef HAVE_DECL_ARC4RANDOM_UNIFORM */
-/* Define to 1 if you have the declaration of `evsignal_assign', and to 0 if
+/* Define to 1 if you have the declaration of 'evsignal_assign', and to 0 if
you don't. */
/* #undef HAVE_DECL_EVSIGNAL_ASSIGN */
-/* Define to 1 if you have the declaration of `inet_ntop', and to 0 if you
+/* Define to 1 if you have the declaration of 'inet_ntop', and to 0 if you
don't. */
#define HAVE_DECL_INET_NTOP 1
-/* Define to 1 if you have the declaration of `inet_pton', and to 0 if you
+/* Define to 1 if you have the declaration of 'inet_pton', and to 0 if you
don't. */
#define HAVE_DECL_INET_PTON 1
-/* Define to 1 if you have the declaration of `nghttp2_session_server_new',
+/* Define to 1 if you have the declaration of 'nghttp2_session_server_new',
and to 0 if you don't. */
/* #undef HAVE_DECL_NGHTTP2_SESSION_SERVER_NEW */
-/* Define to 1 if you have the declaration of `NID_ED25519', and to 0 if you
+/* Define to 1 if you have the declaration of 'ngtcp2_conn_server_new', and to
+ 0 if you don't. */
+/* #undef HAVE_DECL_NGTCP2_CONN_SERVER_NEW */
+
+/* Define to 1 if you have the declaration of 'ngtcp2_crypto_encrypt_cb', and
+ to 0 if you don't. */
+/* #undef HAVE_DECL_NGTCP2_CRYPTO_ENCRYPT_CB */
+
+/* Define to 1 if you have the declaration of 'NID_ED25519', and to 0 if you
don't. */
#define HAVE_DECL_NID_ED25519 1
-/* Define to 1 if you have the declaration of `NID_ED448', and to 0 if you
+/* Define to 1 if you have the declaration of 'NID_ED448', and to 0 if you
don't. */
#define HAVE_DECL_NID_ED448 1
-/* Define to 1 if you have the declaration of `NID_secp384r1', and to 0 if you
+/* Define to 1 if you have the declaration of 'NID_secp384r1', and to 0 if you
don't. */
#define HAVE_DECL_NID_SECP384R1 1
-/* Define to 1 if you have the declaration of `NID_X9_62_prime256v1', and to 0
+/* Define to 1 if you have the declaration of 'NID_X9_62_prime256v1', and to 0
if you don't. */
#define HAVE_DECL_NID_X9_62_PRIME256V1 1
-/* Define to 1 if you have the declaration of `reallocarray', and to 0 if you
+/* Define to 1 if you have the declaration of 'reallocarray', and to 0 if you
don't. */
#define HAVE_DECL_REALLOCARRAY 1
-/* Define to 1 if you have the declaration of `redisConnect', and to 0 if you
+/* Define to 1 if you have the declaration of 'redisConnect', and to 0 if you
don't. */
/* #undef HAVE_DECL_REDISCONNECT */
-/* Define to 1 if you have the declaration of `sk_SSL_COMP_pop_free', and to 0
+/* Define to 1 if you have the declaration of 'sk_SSL_COMP_pop_free', and to 0
if you don't. */
#define HAVE_DECL_SK_SSL_COMP_POP_FREE 1
/* Define to 1 if you have the declaration of
- `SSL_COMP_get_compression_methods', and to 0 if you don't. */
+ 'SSL_COMP_get_compression_methods', and to 0 if you don't. */
#define HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS 1
-/* Define to 1 if you have the declaration of `SSL_CTX_set_ecdh_auto', and to
+/* Define to 1 if you have the declaration of 'SSL_CTX_set_ecdh_auto', and to
0 if you don't. */
-/* #undef HAVE_DECL_SSL_CTX_SET_ECDH_AUTO */
+#define HAVE_DECL_SSL_CTX_SET_ECDH_AUTO 1
-/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
+/* Define to 1 if you have the declaration of 'strlcat', and to 0 if you
don't. */
/* #undef HAVE_DECL_STRLCAT */
-/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you
+/* Define to 1 if you have the declaration of 'strlcpy', and to 0 if you
don't. */
/* #undef HAVE_DECL_STRLCPY */
-/* Define to 1 if you have the declaration of `XML_StopParser', and to 0 if
+/* Define to 1 if you have the declaration of 'XML_StopParser', and to 0 if
you don't. */
#define HAVE_DECL_XML_STOPPARSER 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
-/* Define to 1 if you have the `DSA_SIG_set0' function. */
+/* Define to 1 if you have the 'DSA_SIG_set0' function. */
#define HAVE_DSA_SIG_SET0 1
/* Define to 1 if you have the <endian.h> header file. */
-/* #undef HAVE_ENDIAN_H */
+#define HAVE_ENDIAN_H 1
-/* Define to 1 if you have the `endprotoent' function. */
+/* Define to 1 if you have the 'endprotoent' function. */
#define HAVE_ENDPROTOENT 1
-/* Define to 1 if you have the `endpwent' function. */
+/* Define to 1 if you have the 'endpwent' function. */
#define HAVE_ENDPWENT 1
-/* Define to 1 if you have the `endservent' function. */
+/* Define to 1 if you have the 'endservent' function. */
#define HAVE_ENDSERVENT 1
-/* Define to 1 if you have the `ENGINE_cleanup' function. */
+/* Define to 1 if you have the 'ENGINE_cleanup' function. */
/* #undef HAVE_ENGINE_CLEANUP */
-/* Define to 1 if you have the `ERR_free_strings' function. */
+/* Define to 1 if you have the 'ERR_free_strings' function. */
/* #undef HAVE_ERR_FREE_STRINGS */
-/* Define to 1 if you have the `ERR_load_crypto_strings' function. */
+/* Define to 1 if you have the 'ERR_load_crypto_strings' function. */
/* #undef HAVE_ERR_LOAD_CRYPTO_STRINGS */
-/* Define to 1 if you have the `event_assign' function. */
+/* Define to 1 if you have the 'event_assign' function. */
/* #undef HAVE_EVENT_ASSIGN */
-/* Define to 1 if you have the `event_base_free' function. */
+/* Define to 1 if you have the 'event_base_free' function. */
/* #undef HAVE_EVENT_BASE_FREE */
-/* Define to 1 if you have the `event_base_get_method' function. */
+/* Define to 1 if you have the 'event_base_get_method' function. */
/* #undef HAVE_EVENT_BASE_GET_METHOD */
-/* Define to 1 if you have the `event_base_new' function. */
+/* Define to 1 if you have the 'event_base_new' function. */
/* #undef HAVE_EVENT_BASE_NEW */
-/* Define to 1 if you have the `event_base_once' function. */
+/* Define to 1 if you have the 'event_base_once' function. */
/* #undef HAVE_EVENT_BASE_ONCE */
/* Define to 1 if you have the <event.h> header file. */
/* #undef HAVE_EVENT_H */
-/* Define to 1 if you have the `EVP_aes_256_cbc' function. */
+/* Define to 1 if you have the 'EVP_aes_256_cbc' function. */
#define HAVE_EVP_AES_256_CBC 1
-/* Define to 1 if you have the `EVP_cleanup' function. */
+/* Define to 1 if you have the 'EVP_cleanup' function. */
/* #undef HAVE_EVP_CLEANUP */
-/* Define to 1 if you have the `EVP_default_properties_is_fips_enabled'
+/* Define to 1 if you have the 'EVP_default_properties_is_fips_enabled'
function. */
-/* #undef HAVE_EVP_DEFAULT_PROPERTIES_IS_FIPS_ENABLED */
-
+#define HAVE_EVP_DEFAULT_PROPERTIES_IS_FIPS_ENABLED 1
-/* Define to 1 if you have the `EVP_default_properties_is_fips_enabled'
- function. */
-/* #undef HAVE_EVP_DEFAULT_PROPERTIES_IS_FIPS_ENABLED */
-
-/* Define to 1 if you have the `EVP_DigestVerify' function. */
+/* Define to 1 if you have the 'EVP_DigestVerify' function. */
#define HAVE_EVP_DIGESTVERIFY 1
-/* Define to 1 if you have the `EVP_dss1' function. */
+/* Define to 1 if you have the 'EVP_dss1' function. */
/* #undef HAVE_EVP_DSS1 */
-/* Define to 1 if you have the `EVP_EncryptInit_ex' function. */
+/* Define to 1 if you have the 'EVP_EncryptInit_ex' function. */
#define HAVE_EVP_ENCRYPTINIT_EX 1
-/* Define to 1 if you have the `EVP_MAC_CTX_set_params' function. */
-/* #undef HAVE_EVP_MAC_CTX_SET_PARAMS */
+/* Define to 1 if you have the 'EVP_MAC_CTX_set_params' function. */
+#define HAVE_EVP_MAC_CTX_SET_PARAMS 1
-/* Define to 1 if you have the `EVP_MD_CTX_new' function. */
+/* Define to 1 if you have the 'EVP_MD_CTX_new' function. */
#define HAVE_EVP_MD_CTX_NEW 1
-/* Define to 1 if you have the `EVP_sha1' function. */
+/* Define to 1 if you have the 'EVP_sha1' function. */
#define HAVE_EVP_SHA1 1
-/* Define to 1 if you have the `EVP_sha256' function. */
+/* Define to 1 if you have the 'EVP_sha256' function. */
#define HAVE_EVP_SHA256 1
-/* Define to 1 if you have the `EVP_sha512' function. */
+/* Define to 1 if you have the 'EVP_sha512' function. */
#define HAVE_EVP_SHA512 1
-/* Define to 1 if you have the `ev_default_loop' function. */
+/* Define to 1 if you have the 'ev_default_loop' function. */
/* #undef HAVE_EV_DEFAULT_LOOP */
-/* Define to 1 if you have the `ev_loop' function. */
+/* Define to 1 if you have the 'ev_loop' function. */
/* #undef HAVE_EV_LOOP */
/* Define to 1 if you have the <expat.h> header file. */
#define HAVE_EXPAT_H 1
-/* Define to 1 if you have the `explicit_bzero' function. */
+/* Define to 1 if you have the 'explicit_bzero' function. */
#define HAVE_EXPLICIT_BZERO 1
-/* Define to 1 if you have the `fcntl' function. */
+/* Define to 1 if you have the 'fcntl' function. */
#define HAVE_FCNTL 1
-/* Define to 1 if you have the `FIPS_mode' function. */
-#define HAVE_FIPS_MODE 1
+/* Define to 1 if you have the 'FIPS_mode' function. */
+/* #undef HAVE_FIPS_MODE */
-/* Define to 1 if you have the `fork' function. */
+/* Define to 1 if you have the 'fork' function. */
#define HAVE_FORK 1
-/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+/* Define to 1 if fseeko (and ftello) are declared in stdio.h. */
#define HAVE_FSEEKO 1
-/* Define to 1 if you have the `fsync' function. */
+/* Define to 1 if you have the 'fsync' function. */
#define HAVE_FSYNC 1
/* Whether getaddrinfo is available */
#define HAVE_GETADDRINFO 1
-/* Define to 1 if you have the `getauxval' function. */
+/* Define to 1 if you have the 'getauxval' function. */
/* #undef HAVE_GETAUXVAL */
-/* Define to 1 if you have the `getentropy' function. */
+/* Define to 1 if you have the 'getentropy' function. */
/* #undef HAVE_GETENTROPY */
-/* Define to 1 if you have the `getifaddrs' function. */
+/* Define to 1 if you have the 'getifaddrs' function. */
#define HAVE_GETIFADDRS 1
/* Define to 1 if you have the <getopt.h> header file. */
#define HAVE_GETOPT_H 1
-/* Define to 1 if you have the `getpwnam' function. */
+/* Define to 1 if you have the 'getpwnam' function. */
#define HAVE_GETPWNAM 1
-/* Define to 1 if you have the `getrlimit' function. */
+/* Define to 1 if you have the 'getrlimit' function. */
#define HAVE_GETRLIMIT 1
-/* Define to 1 if you have the `gettid' function. */
-/* #undef HAVE_GETTID */
-
-/* Define to 1 if you have the `gettid' function. */
+/* Define to 1 if you have the 'gettid' function. */
/* #undef HAVE_GETTID */
-/* Define to 1 if you have the `glob' function. */
+/* Define to 1 if you have the 'glob' function. */
#define HAVE_GLOB 1
/* Define to 1 if you have the <glob.h> header file. */
#define HAVE_GLOB_H 1
-/* Define to 1 if you have the `gmtime_r' function. */
+/* Define to 1 if you have the 'gmtime_r' function. */
#define HAVE_GMTIME_R 1
/* Define to 1 if you have the <grp.h> header file. */
@@ -334,31 +331,28 @@
/* Define to 1 if you have the <hiredis/hiredis.h> header file. */
/* #undef HAVE_HIREDIS_HIREDIS_H */
-/* Define to 1 if you have the `HMAC_Init_ex' function. */
+/* Define to 1 if you have the 'HMAC_Init_ex' function. */
#define HAVE_HMAC_INIT_EX 1
/* If we have htobe64 */
-/* #undef HAVE_HTOBE64 */
+#define HAVE_HTOBE64 1
/* Define to 1 if you have the <ifaddrs.h> header file. */
#define HAVE_IFADDRS_H 1
-/* Define to 1 if you have the `if_nametoindex' function. */
+/* Define to 1 if you have the 'if_nametoindex' function. */
#define HAVE_IF_NAMETOINDEX 1
-/* Define to 1 if you have the `if_nametoindex' function. */
-#define HAVE_IF_NAMETOINDEX 1
-
-/* Define to 1 if you have the `inet_aton' function. */
+/* Define to 1 if you have the 'inet_aton' function. */
#define HAVE_INET_ATON 1
-/* Define to 1 if you have the `inet_ntop' function. */
+/* Define to 1 if you have the 'inet_ntop' function. */
#define HAVE_INET_NTOP 1
-/* Define to 1 if you have the `inet_pton' function. */
+/* Define to 1 if you have the 'inet_pton' function. */
#define HAVE_INET_PTON 1
-/* Define to 1 if you have the `initgroups' function. */
+/* Define to 1 if you have the 'initgroups' function. */
#define HAVE_INITGROUPS 1
/* Define to 1 if you have the <inttypes.h> header file. */
@@ -370,10 +364,10 @@
/* Define to 1 if you have the <iphlpapi.h> header file. */
/* #undef HAVE_IPHLPAPI_H */
-/* Define to 1 if you have the `isblank' function. */
+/* Define to 1 if you have the 'isblank' function. */
#define HAVE_ISBLANK 1
-/* Define to 1 if you have the `kill' function. */
+/* Define to 1 if you have the 'kill' function. */
#define HAVE_KILL 1
/* Use portable libbsd functions */
@@ -385,7 +379,13 @@
/* Define if we have LibreSSL */
/* #undef HAVE_LIBRESSL */
-/* Define to 1 if you have the `localtime_r' function. */
+/* If we have atomic_store */
+#define HAVE_LINK_ATOMIC_STORE 1
+
+/* Define to 1 if you have the <linux/net_tstamp.h> header file. */
+/* #undef HAVE_LINUX_NET_TSTAMP_H */
+
+/* Define to 1 if you have the 'localtime_r' function. */
#define HAVE_LOCALTIME_R 1
/* Define to 1 if you have the <login_cap.h> header file. */
@@ -394,7 +394,7 @@
/* If have GNU libc compatible malloc */
#define HAVE_MALLOC 1
-/* Define to 1 if you have the `memmove' function. */
+/* Define to 1 if you have the 'memmove' function. */
#define HAVE_MEMMOVE 1
/* Define to 1 if you have the <minix/config.h> header file. */
@@ -424,29 +424,91 @@
/* Define to 1 if you have the <net/if.h> header file. */
#define HAVE_NET_IF_H 1
+/* Define to 1 if you have the <net/pfvar.h> header file. */
+/* #undef HAVE_NET_PFVAR_H */
+
/* Define this to use nghttp2 client. */
/* #undef HAVE_NGHTTP2 */
/* Define to 1 if you have the <nghttp2/nghttp2.h> header file. */
/* #undef HAVE_NGHTTP2_NGHTTP2_H */
+/* Define this to use ngtcp2. */
+/* #undef HAVE_NGTCP2 */
+
+/* Define to 1 if you have the 'ngtcp2_ccerr_default' function. */
+/* #undef HAVE_NGTCP2_CCERR_DEFAULT */
+
+/* Define to 1 if you have the 'ngtcp2_conn_encode_0rtt_transport_params'
+ function. */
+/* #undef HAVE_NGTCP2_CONN_ENCODE_0RTT_TRANSPORT_PARAMS */
+
+/* Define to 1 if you have the 'ngtcp2_conn_get_max_local_streams_uni'
+ function. */
+/* #undef HAVE_NGTCP2_CONN_GET_MAX_LOCAL_STREAMS_UNI */
+
+/* Define to 1 if you have the 'ngtcp2_conn_get_num_scid' function. */
+/* #undef HAVE_NGTCP2_CONN_GET_NUM_SCID */
+
+/* Define to 1 if you have the 'ngtcp2_conn_in_closing_period' function. */
+/* #undef HAVE_NGTCP2_CONN_IN_CLOSING_PERIOD */
+
+/* Define to 1 if you have the 'ngtcp2_conn_in_draining_period' function. */
+/* #undef HAVE_NGTCP2_CONN_IN_DRAINING_PERIOD */
+
+/* Define if ngtcp2_conn_shutdown_stream has 4 arguments. */
+/* #undef HAVE_NGTCP2_CONN_SHUTDOWN_STREAM4 */
+
+/* Define to 1 if you have the 'ngtcp2_conn_tls_early_data_rejected' function.
+ */
+/* #undef HAVE_NGTCP2_CONN_TLS_EARLY_DATA_REJECTED */
+
+/* Define to 1 if you have the 'ngtcp2_crypto_encrypt_cb' function. */
+/* #undef HAVE_NGTCP2_CRYPTO_ENCRYPT_CB */
+
+/* Define to 1 if you have the
+ 'ngtcp2_crypto_quictls_configure_client_context' function. */
+/* #undef HAVE_NGTCP2_CRYPTO_QUICTLS_CONFIGURE_CLIENT_CONTEXT */
+
+/* Define to 1 if you have the
+ 'ngtcp2_crypto_quictls_configure_server_context' function. */
+/* #undef HAVE_NGTCP2_CRYPTO_QUICTLS_CONFIGURE_SERVER_CONTEXT */
+
+/* Define to 1 if you have the
+ 'ngtcp2_crypto_quictls_from_ossl_encryption_level' function. */
+/* #undef HAVE_NGTCP2_CRYPTO_QUICTLS_FROM_OSSL_ENCRYPTION_LEVEL */
+
+/* Define to 1 if the system has the type 'ngtcp2_encryption_level'. */
+/* #undef HAVE_NGTCP2_ENCRYPTION_LEVEL */
+
+/* Define to 1 if you have the <ngtcp2/ngtcp2_crypto_openssl.h> header file.
+ */
+/* #undef HAVE_NGTCP2_NGTCP2_CRYPTO_OPENSSL_H */
+
+/* Define to 1 if you have the <ngtcp2/ngtcp2_crypto_quictls.h> header file.
+ */
+/* #undef HAVE_NGTCP2_NGTCP2_CRYPTO_QUICTLS_H */
+
+/* Define to 1 if you have the <ngtcp2/ngtcp2.h> header file. */
+/* #undef HAVE_NGTCP2_NGTCP2_H */
+
/* Use libnss for crypto */
/* #undef HAVE_NSS */
-/* Define to 1 if you have the `OpenSSL_add_all_digests' function. */
+/* Define to 1 if you have the 'OpenSSL_add_all_digests' function. */
/* #undef HAVE_OPENSSL_ADD_ALL_DIGESTS */
/* Define to 1 if you have the <openssl/bn.h> header file. */
#define HAVE_OPENSSL_BN_H 1
-/* Define to 1 if you have the `OPENSSL_config' function. */
+/* Define to 1 if you have the 'OPENSSL_config' function. */
#define HAVE_OPENSSL_CONFIG 1
/* Define to 1 if you have the <openssl/conf.h> header file. */
#define HAVE_OPENSSL_CONF_H 1
/* Define to 1 if you have the <openssl/core_names.h> header file. */
-/* #undef HAVE_OPENSSL_CORE_NAMES_H */
+#define HAVE_OPENSSL_CORE_NAMES_H 1
/* Define to 1 if you have the <openssl/dh.h> header file. */
#define HAVE_OPENSSL_DH_H 1
@@ -460,14 +522,14 @@
/* Define to 1 if you have the <openssl/err.h> header file. */
#define HAVE_OPENSSL_ERR_H 1
-/* Define to 1 if you have the `OPENSSL_init_crypto' function. */
+/* Define to 1 if you have the 'OPENSSL_init_crypto' function. */
#define HAVE_OPENSSL_INIT_CRYPTO 1
-/* Define to 1 if you have the `OPENSSL_init_ssl' function. */
+/* Define to 1 if you have the 'OPENSSL_init_ssl' function. */
#define HAVE_OPENSSL_INIT_SSL 1
/* Define to 1 if you have the <openssl/param_build.h> header file. */
-/* #undef HAVE_OPENSSL_PARAM_BUILD_H */
+#define HAVE_OPENSSL_PARAM_BUILD_H 1
/* Define to 1 if you have the <openssl/rand.h> header file. */
#define HAVE_OPENSSL_RAND_H 1
@@ -478,10 +540,10 @@
/* Define to 1 if you have the <openssl/ssl.h> header file. */
#define HAVE_OPENSSL_SSL_H 1
-/* Define to 1 if you have the `OSSL_PARAM_BLD_new' function. */
-/* #undef HAVE_OSSL_PARAM_BLD_NEW */
+/* Define to 1 if you have the 'OSSL_PARAM_BLD_new' function. */
+#define HAVE_OSSL_PARAM_BLD_NEW 1
-/* Define to 1 if you have the `poll' function. */
+/* Define to 1 if you have the 'poll' function. */
#define HAVE_POLL 1
/* Define to 1 if you have the <poll.h> header file. */
@@ -493,10 +555,10 @@
/* Have PTHREAD_PRIO_INHERIT. */
#define HAVE_PTHREAD_PRIO_INHERIT 1
-/* Define to 1 if the system has the type `pthread_rwlock_t'. */
+/* Define to 1 if the system has the type 'pthread_rwlock_t'. */
#define HAVE_PTHREAD_RWLOCK_T 1
-/* Define to 1 if the system has the type `pthread_spinlock_t'. */
+/* Define to 1 if the system has the type 'pthread_spinlock_t'. */
#define HAVE_PTHREAD_SPINLOCK_T 1
/* Define to 1 if you have the <pwd.h> header file. */
@@ -505,100 +567,109 @@
/* Define if you have Python libraries and header files. */
/* #undef HAVE_PYTHON */
-/* Define to 1 if you have the `random' function. */
+/* Define to 1 if you have the 'random' function. */
#define HAVE_RANDOM 1
-/* Define to 1 if you have the `RAND_cleanup' function. */
+/* Define to 1 if you have the 'RAND_cleanup' function. */
/* #undef HAVE_RAND_CLEANUP */
/* If we have reallocarray(3) */
#define HAVE_REALLOCARRAY 1
-/* Define to 1 if you have the `recvmsg' function. */
+/* Define to 1 if you have the 'recvmsg' function. */
#define HAVE_RECVMSG 1
-/* Define to 1 if you have the `sendmsg' function. */
+/* Define to 1 if you have the 'sendmsg' function. */
#define HAVE_SENDMSG 1
-/* Define to 1 if you have the `setregid' function. */
+/* Define to 1 if you have the 'setregid' function. */
/* #undef HAVE_SETREGID */
-/* Define to 1 if you have the `setresgid' function. */
+/* Define to 1 if you have the 'setresgid' function. */
#define HAVE_SETRESGID 1
-/* Define to 1 if you have the `setresuid' function. */
+/* Define to 1 if you have the 'setresuid' function. */
#define HAVE_SETRESUID 1
-/* Define to 1 if you have the `setreuid' function. */
+/* Define to 1 if you have the 'setreuid' function. */
/* #undef HAVE_SETREUID */
-/* Define to 1 if you have the `setrlimit' function. */
+/* Define to 1 if you have the 'setrlimit' function. */
#define HAVE_SETRLIMIT 1
-/* Define to 1 if you have the `setsid' function. */
+/* Define to 1 if you have the 'setsid' function. */
#define HAVE_SETSID 1
-/* Define to 1 if you have the `setusercontext' function. */
+/* Define to 1 if you have the 'setusercontext' function. */
#define HAVE_SETUSERCONTEXT 1
-/* Define to 1 if you have the `SHA512_Update' function. */
+/* Define to 1 if you have the 'SHA512_Update' function. */
/* #undef HAVE_SHA512_UPDATE */
-/* Define to 1 if you have the `shmget' function. */
+/* Define to 1 if you have the 'shmget' function. */
#define HAVE_SHMGET 1
-/* Define to 1 if you have the `sigprocmask' function. */
+/* Define to 1 if you have the 'sigprocmask' function. */
#define HAVE_SIGPROCMASK 1
-/* Define to 1 if you have the `sleep' function. */
+/* Define to 1 if you have the 'sleep' function. */
#define HAVE_SLEEP 1
-/* Define to 1 if you have the `snprintf' function. */
+/* Define to 1 if you have the 'snprintf' function. */
#define HAVE_SNPRINTF 1
-/* Define to 1 if you have the `socketpair' function. */
+/* Define to 1 if you have the 'socketpair' function. */
#define HAVE_SOCKETPAIR 1
/* Using Solaris threads */
/* #undef HAVE_SOLARIS_THREADS */
-/* Define to 1 if you have the `srandom' function. */
+/* Define to 1 if you have the 'srandom' function. */
#define HAVE_SRANDOM 1
/* Define if you have the SSL libraries installed. */
#define HAVE_SSL /**/
-/* Define to 1 if you have the `SSL_CTX_set_alpn_protos' function. */
+/* Define to 1 if you have the 'SSL_CTX_set_alpn_protos' function. */
#define HAVE_SSL_CTX_SET_ALPN_PROTOS 1
-/* Define to 1 if you have the `SSL_CTX_set_alpn_select_cb' function. */
+/* Define to 1 if you have the 'SSL_CTX_set_alpn_select_cb' function. */
#define HAVE_SSL_CTX_SET_ALPN_SELECT_CB 1
-/* Define to 1 if you have the `SSL_CTX_set_ciphersuites' function. */
+/* Define to 1 if you have the 'SSL_CTX_set_ciphersuites' function. */
#define HAVE_SSL_CTX_SET_CIPHERSUITES 1
-/* Define to 1 if you have the `SSL_CTX_set_security_level' function. */
+/* Define to 1 if you have the 'SSL_CTX_set_security_level' function. */
#define HAVE_SSL_CTX_SET_SECURITY_LEVEL 1
-/* Define to 1 if you have the `SSL_CTX_set_tlsext_ticket_key_evp_cb'
+/* Define to 1 if you have the 'SSL_CTX_set_tlsext_ticket_key_evp_cb'
function. */
-/* #undef HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB */
+#define HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_EVP_CB 1
+
+/* Define to 1 if you have the 'SSL_CTX_set_tmp_ecdh' function. */
+/* #undef HAVE_SSL_CTX_SET_TMP_ECDH */
-/* Define to 1 if you have the `SSL_get0_alpn_selected' function. */
+/* Define to 1 if you have the 'SSL_get0_alpn_selected' function. */
#define HAVE_SSL_GET0_ALPN_SELECTED 1
-/* Define to 1 if you have the `SSL_get0_peername' function. */
+/* Define to 1 if you have the 'SSL_get0_peername' function. */
#define HAVE_SSL_GET0_PEERNAME 1
-/* Define to 1 if you have the `SSL_get1_peer_certificate' function. */
-/* #undef HAVE_SSL_GET1_PEER_CERTIFICATE */
+/* Define to 1 if you have the 'SSL_get1_peer_certificate' function. */
+#define HAVE_SSL_GET1_PEER_CERTIFICATE 1
-/* Define to 1 if you have the `SSL_set1_host' function. */
+/* Define to 1 if you have the 'SSL_is_quic' function. */
+/* #undef HAVE_SSL_IS_QUIC */
+
+/* Define to 1 if you have the 'SSL_set1_host' function. */
#define HAVE_SSL_SET1_HOST 1
/* Define to 1 if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
+/* Define to 1 if you have the <stdatomic.h> header file. */
+#define HAVE_STDATOMIC_H 1
+
/* Define to 1 if you have the <stdbool.h> header file. */
#define HAVE_STDBOOL_H 1
@@ -611,7 +682,7 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
-/* Define to 1 if you have the `strftime' function. */
+/* Define to 1 if you have the 'strftime' function. */
#define HAVE_STRFTIME 1
/* Define to 1 if you have the <strings.h> header file. */
@@ -620,22 +691,39 @@
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
-/* Define to 1 if you have the `strlcat' function. */
+/* Define to 1 if you have the 'strlcat' function. */
#define HAVE_STRLCAT 1
-/* Define to 1 if you have the `strlcpy' function. */
+/* Define to 1 if you have the 'strlcpy' function. */
#define HAVE_STRLCPY 1
-/* Define to 1 if you have the `strptime' function. */
+/* Define to 1 if you have the 'strptime' function. */
#define HAVE_STRPTIME 1
-/* Define to 1 if you have the `strsep' function. */
+/* Define to 1 if you have the 'strsep' function. */
#define HAVE_STRSEP 1
-/* Define to 1 if `ipi_spec_dst' is a member of `struct in_pktinfo'. */
+/* Define to 1 if 'ipi_spec_dst' is a member of 'struct in_pktinfo'. */
/* #undef HAVE_STRUCT_IN_PKTINFO_IPI_SPEC_DST */
-/* Define to 1 if `sun_len' is a member of `struct sockaddr_un'. */
+/* Define to 1 if 'tokenlen' is a member of 'struct ngtcp2_pkt_hd'. */
+/* #undef HAVE_STRUCT_NGTCP2_PKT_HD_TOKENLEN */
+
+/* Define to 1 if 'max_tx_udp_payload_size' is a member of 'struct
+ ngtcp2_settings'. */
+/* #undef HAVE_STRUCT_NGTCP2_SETTINGS_MAX_TX_UDP_PAYLOAD_SIZE */
+
+/* Define to 1 if 'tokenlen' is a member of 'struct ngtcp2_settings'. */
+/* #undef HAVE_STRUCT_NGTCP2_SETTINGS_TOKENLEN */
+
+/* Define to 1 if 'original_dcid_present' is a member of 'struct
+ ngtcp2_transport_params'. */
+/* #undef HAVE_STRUCT_NGTCP2_TRANSPORT_PARAMS_ORIGINAL_DCID_PRESENT */
+
+/* Define to 1 if the system has the type 'struct ngtcp2_version_cid'. */
+/* #undef HAVE_STRUCT_NGTCP2_VERSION_CID */
+
+/* Define to 1 if 'sun_len' is a member of 'struct sockaddr_un'. */
#define HAVE_STRUCT_SOCKADDR_UN_SUN_LEN 1
/* Define if you have Swig libraries and header files. */
@@ -695,16 +783,16 @@
/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1
-/* Define to 1 if you have the `tzset' function. */
+/* Define to 1 if you have the 'tzset' function. */
#define HAVE_TZSET 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
-/* Define to 1 if you have the `usleep' function. */
+/* Define to 1 if you have the 'usleep' function. */
#define HAVE_USLEEP 1
-/* Define to 1 if you have the `vfork' function. */
+/* Define to 1 if you have the 'vfork' function. */
#define HAVE_VFORK 1
/* Define to 1 if you have the <vfork.h> header file. */
@@ -722,22 +810,22 @@
/* Define to 1 if you have the <winsock2.h> header file. */
/* #undef HAVE_WINSOCK2_H */
-/* Define to 1 if `fork' works. */
+/* Define to 1 if 'fork' works. */
#define HAVE_WORKING_FORK 1
-/* Define to 1 if `vfork' works. */
+/* Define to 1 if 'vfork' works. */
#define HAVE_WORKING_VFORK 1
-/* Define to 1 if you have the `writev' function. */
+/* Define to 1 if you have the 'writev' function. */
#define HAVE_WRITEV 1
/* Define to 1 if you have the <ws2tcpip.h> header file. */
/* #undef HAVE_WS2TCPIP_H */
-/* Define to 1 if you have the `X509_VERIFY_PARAM_set1_host' function. */
+/* Define to 1 if you have the 'X509_VERIFY_PARAM_set1_host' function. */
#define HAVE_X509_VERIFY_PARAM_SET1_HOST 1
-/* Define to 1 if you have the `_beginthreadex' function. */
+/* Define to 1 if you have the '_beginthreadex' function. */
/* #undef HAVE__BEGINTHREADEX */
/* If HMAC_Init_ex() returns void */
@@ -796,7 +884,7 @@
#define PACKAGE_NAME "unbound"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "unbound 1.23.0"
+#define PACKAGE_STRING "unbound 1.24.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "unbound"
@@ -805,7 +893,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.23.0"
+#define PACKAGE_VERSION "1.24.1"
/* default pidfile location */
#define PIDFILE "/var/unbound/unbound.pid"
@@ -828,7 +916,7 @@
#define ROOT_CERT_FILE "/var/unbound/icannbundle.pem"
/* version number for resource files */
-#define RSRC_PACKAGE_VERSION 1,23,0,0
+#define RSRC_PACKAGE_VERSION 1,23,1,0
/* Directory to chdir to */
#define RUN_DIR "/var/unbound"
@@ -836,32 +924,17 @@
/* Shared data */
#define SHARE_DIR "/var/unbound"
-#ifdef __LP64__
-/* The size of `size_t', as computed by sizeof. */
-#define SIZEOF_SIZE_T 8
-/* The size of `size_t'. */
-/* The size of `pthread_t', as computed by sizeof. */
+/* The size of 'pthread_t', as computed by sizeof. */
#define SIZEOF_PTHREAD_T 8
-#else
-#define SIZEOF_SIZE_T 4
-/* The size of `size_t'. */
-/* The size of `pthread_t', as computed by sizeof. */
-#define SIZEOF_PTHREAD_T 4
-#endif
-/* The size of `time_t', as computed by sizeof. */
-#ifdef __i386__
-#define SIZEOF_TIME_T 4
-#else
+/* The size of 'size_t', as computed by sizeof. */
+#define SIZEOF_SIZE_T 8
+
+/* The size of 'time_t', as computed by sizeof. */
#define SIZEOF_TIME_T 8
-#endif
-/* The size of `unsigned long', as computed by sizeof. */
-#ifdef __LP64__
+/* The size of 'unsigned long', as computed by sizeof. */
#define SIZEOF_UNSIGNED_LONG 8
-#else
-#define SIZEOF_UNSIGNED_LONG 4
-#endif
/* define if (v)snprintf does not return length needed, (but length used) */
/* #undef SNPRINTF_RET_BROKEN */
@@ -869,7 +942,7 @@
/* Define to 1 if libsodium supports sodium_set_misuse_handler */
/* #undef SODIUM_MISUSE_HANDLER */
-/* Define to 1 if all of the C90 standard headers exist (not just the ones
+/* Define to 1 if all of the C89 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#define STDC_HEADERS 1
@@ -911,7 +984,7 @@
/* #undef USE_DNSTAP */
/* Define this to enable DSA support. */
-#define USE_DSA 1
+/* #undef USE_DSA */
/* Define this to enable ECDSA support. */
#define USE_ECDSA 1
@@ -935,7 +1008,7 @@
/* #undef USE_IPSET */
/* Define if you enable libevent */
-#define USE_LIBEVENT 1
+/* #undef USE_LIBEVENT */
/* Define this to enable use of /proc/sys/net/ipv4/ip_local_port_range as a
default outgoing port range. This is only for the libunbound on Linux and
@@ -963,7 +1036,7 @@
/* Define this to enable SHA256 and SHA512 support. */
#define USE_SHA2 1
-/* Enable extensions on AIX 3, Interix. */
+/* Enable extensions on AIX, Interix, z/OS. */
#ifndef _ALL_SOURCE
# define _ALL_SOURCE 1
#endif
@@ -1024,11 +1097,15 @@
#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
# define __STDC_WANT_IEC_60559_DFP_EXT__ 1
#endif
+/* Enable extensions specified by C23 Annex F. */
+#ifndef __STDC_WANT_IEC_60559_EXT__
+# define __STDC_WANT_IEC_60559_EXT__ 1
+#endif
/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */
#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
# define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1
#endif
-/* Enable extensions specified by ISO/IEC TS 18661-3:2015. */
+/* Enable extensions specified by C23 Annex H and ISO/IEC TS 18661-3:2015. */
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
# define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
#endif
@@ -1069,30 +1146,36 @@
/* Define if you want PyUnbound. */
/* #undef WITH_PYUNBOUND */
-/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
- `char[]'. */
+/* Define to 1 if 'lex' declares 'yytext' as a 'char *' by default, not a
+ 'char[]'. */
#define YYTEXT_POINTER 1
/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */
-/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/* Define to 1 if necessary to make fseeko visible. */
/* #undef _LARGEFILE_SOURCE */
-/* Define for large files, on AIX-style hosts. */
+/* Define to 1 on platforms where this makes off_t a 64-bit type. */
/* #undef _LARGE_FILES */
/* Enable for compile on Minix */
#define _NETBSD_SOURCE 1
+/* Number of bits in time_t, on hosts where this is settable. */
+/* #undef _TIME_BITS */
+
+/* Define to 1 on platforms where this makes time_t a 64-bit type. */
+/* #undef __MINGW_USE_VC2005_COMPAT */
+
/* defined to use gcc ansi snprintf and sscanf that understands %lld when
compiled for windows. */
/* #undef __USE_MINGW_ANSI_STDIO */
-/* Define to empty if `const' does not conform to ANSI C. */
+/* Define to empty if 'const' does not conform to ANSI C. */
/* #undef const */
-/* Define to `int' if <sys/types.h> doesn't define. */
+/* Define as 'int' if <sys/types.h> doesn't define. */
/* #undef gid_t */
/* in_addr_t */
@@ -1101,28 +1184,28 @@
/* in_port_t */
/* #undef in_port_t */
-/* Define to `__inline__' or `__inline' if that's what the C compiler
+/* Define to '__inline__' or '__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
-/* Define to `short' if <sys/types.h> does not define. */
+/* Define to 'short' if <sys/types.h> does not define. */
/* #undef int16_t */
-/* Define to `int' if <sys/types.h> does not define. */
+/* Define to 'int' if <sys/types.h> does not define. */
/* #undef int32_t */
-/* Define to `long long' if <sys/types.h> does not define. */
+/* Define to 'long long' if <sys/types.h> does not define. */
/* #undef int64_t */
-/* Define to `signed char' if <sys/types.h> does not define. */
+/* Define to 'signed char' if <sys/types.h> does not define. */
/* #undef int8_t */
/* Define if replacement function should be used. */
/* #undef malloc */
-/* Define to `long int' if <sys/types.h> does not define. */
+/* Define to 'long int' if <sys/types.h> does not define. */
/* #undef off_t */
/* Define as a signed integer type capable of holding a process identifier. */
@@ -1131,71 +1214,71 @@
/* Define to 'int' if not defined */
/* #undef rlim_t */
-/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* Define as 'unsigned int' if <stddef.h> doesn't define. */
/* #undef size_t */
/* Define to 'int' if not defined */
/* #undef socklen_t */
-/* Define to `int' if <sys/types.h> does not define. */
+/* Define to 'int' if <sys/types.h> does not define. */
/* #undef ssize_t */
/* Define to 'unsigned char if not defined */
/* #undef u_char */
-/* Define to `int' if <sys/types.h> doesn't define. */
+/* Define as 'int' if <sys/types.h> doesn't define. */
/* #undef uid_t */
-/* Define to `unsigned short' if <sys/types.h> does not define. */
+/* Define to 'unsigned short' if <sys/types.h> does not define. */
/* #undef uint16_t */
-/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* Define to 'unsigned int' if <sys/types.h> does not define. */
/* #undef uint32_t */
-/* Define to `unsigned long long' if <sys/types.h> does not define. */
+/* Define to 'unsigned long long' if <sys/types.h> does not define. */
/* #undef uint64_t */
-/* Define to `unsigned char' if <sys/types.h> does not define. */
+/* Define to 'unsigned char' if <sys/types.h> does not define. */
/* #undef uint8_t */
-/* Define as `fork' if `vfork' does not work. */
+/* Define as 'fork' if 'vfork' does not work. */
/* #undef vfork */
#if defined(OMITTED__D_GNU_SOURCE) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE 1
-#endif
+#endif
#if defined(OMITTED__D_BSD_SOURCE) && !defined(_BSD_SOURCE)
#define _BSD_SOURCE 1
-#endif
+#endif
#if defined(OMITTED__D_DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE)
#define _DEFAULT_SOURCE 1
-#endif
+#endif
#if defined(OMITTED__D__EXTENSIONS__) && !defined(__EXTENSIONS__)
#define __EXTENSIONS__ 1
-#endif
+#endif
#if defined(OMITTED__D_POSIX_C_SOURCE_200112) && !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200112
-#endif
+#endif
#if defined(OMITTED__D_XOPEN_SOURCE_600) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
-#endif
+#endif
#if defined(OMITTED__D_XOPEN_SOURCE_EXTENDED_1) && !defined(_XOPEN_SOURCE_EXTENDED)
#define _XOPEN_SOURCE_EXTENDED 1
-#endif
+#endif
#if defined(OMITTED__D_ALL_SOURCE) && !defined(_ALL_SOURCE)
#define _ALL_SOURCE 1
-#endif
+#endif
#if defined(OMITTED__D_LARGEFILE_SOURCE_1) && !defined(_LARGEFILE_SOURCE)
#define _LARGEFILE_SOURCE 1
-#endif
+#endif
@@ -1279,7 +1362,7 @@
#endif
-
+
#ifdef HAVE_ATTR_FORMAT
# define ATTR_FORMAT(archetype, string_index, first_to_check) \
__attribute__ ((format (archetype, string_index, first_to_check)))
@@ -1389,7 +1472,7 @@ void* reallocarray(void *ptr, size_t nmemb, size_t size);
#ifdef HAVE_WINSOCK2_H
#define FD_SET_T (u_int)
#else
-#define FD_SET_T
+#define FD_SET_T
#endif
@@ -1517,6 +1600,10 @@ struct sockaddr_storage;
# define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
# define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
# define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
+# define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__)
+#ifdef HAVE_REALLOCARRAY
+# define reallocarray(p,n,s) unbound_stat_reallocarray_log(p, n, s, __FILE__, __LINE__, __func__)
+#endif
void *unbound_stat_malloc(size_t size);
void *unbound_stat_calloc(size_t nmemb, size_t size);
void unbound_stat_free(void *ptr);
@@ -1529,6 +1616,10 @@ void unbound_stat_free_log(void *ptr, const char* file, int line,
const char* func);
void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
int line, const char* func);
+void *unbound_stat_reallocarray_log(void *ptr, size_t nmemb, size_t size,
+ const char* file, int line, const char* func);
+char *unbound_stat_strdup_log(const char *s, const char* file, int line,
+ const char* func);
#elif defined(UNBOUND_ALLOC_LITE)
# include "util/alloc.h"
#endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index f6251c093345..d54d9af38a34 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -147,7 +147,8 @@ MLINKS+=uucplock.3 uu_lock.3
MLINKS+=uucplock.3 uu_lock_txfr.3
MLINKS+=uucplock.3 uu_lockerr.3
MLINKS+=uucplock.3 uu_unlock.3
-MAN+= login.conf.5
+
+MANNODEV= login.conf.5
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
diff --git a/lib/libutil/login.conf.5 b/lib/libutil/login.conf.5
index 27f37fb5fc30..942f3ecd2661 100644
--- a/lib/libutil/login.conf.5
+++ b/lib/libutil/login.conf.5
@@ -17,7 +17,7 @@
.\" 5. Modifications may be freely made to this file providing the above
.\" conditions are met.
.\"
-.Dd June 28, 2023
+.Dd September 25, 2025
.Dt LOGIN.CONF 5
.Os
.Sh NAME
@@ -496,7 +496,7 @@ lists.
.Xr pam 3 ,
.Xr passwd 5 ,
.Xr ttys 5 ,
-.Xr ftpd 8 ,
+.Xr ftpd 8 Pq Pa ports/ftp/freebsd-ftpd ,
.Xr pam_passwdqc 8
.Sh HISTORY
The file
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index c3c1b0ddda27..9478b4dc98ca 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -543,7 +543,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
/* we need a passwd entry to set these */
if (pwd == NULL)
- flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN | LOGIN_SETMAC);
+ flags &= ~(LOGIN_SETGROUP | LOGIN_SETLOGIN);
/* Set the process priority */
if (flags & LOGIN_SETPRIORITY)
@@ -564,6 +564,27 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
}
}
+ /* Set the sessions login */
+ if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) {
+ syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name);
+ login_close(llc);
+ return (-1);
+ }
+
+ /* Inform the kernel about current login class */
+ if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) {
+ error = setloginclass(lc->lc_class);
+ if (error != 0) {
+ syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class);
+#ifdef notyet
+ login_close(llc);
+ return (-1);
+#endif
+ }
+ }
+
+ setlogincontext(lc, pwd, flags);
+
/* Set up the user's MAC label. */
if ((flags & LOGIN_SETMAC) && mac_is_present(NULL) == 1) {
const char *label_string;
@@ -572,8 +593,10 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
label_string = login_getcapstr(lc, "label", NULL, NULL);
if (label_string != NULL) {
if (mac_from_text(&label, label_string) == -1) {
- syslog(LOG_ERR, "mac_from_text('%s') for %s: %m",
- pwd->pw_name, label_string);
+ syslog(LOG_ERR, "mac_from_text('%s') for %s %s: %m",
+ label_string, pwd != NULL ? "user" : "class",
+ pwd != NULL ? pwd->pw_name : lc->lc_class);
+ login_close(llc);
return (-1);
}
if (mac_set_proc(label) == -1)
@@ -582,33 +605,15 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
error = 0;
mac_free(label);
if (error != 0) {
- syslog(LOG_ERR, "mac_set_proc('%s') for %s: %s",
- label_string, pwd->pw_name, strerror(error));
+ syslog(LOG_ERR, "mac_set_proc('%s') for %s %s: %s",
+ label_string, pwd != NULL ? "user" : "class",
+ pwd != NULL ? pwd->pw_name : lc->lc_class, strerror(error));
+ login_close(llc);
return (-1);
}
}
}
- /* Set the sessions login */
- if ((flags & LOGIN_SETLOGIN) && setlogin(pwd->pw_name) != 0) {
- syslog(LOG_ERR, "setlogin(%s): %m", pwd->pw_name);
- login_close(llc);
- return (-1);
- }
-
- /* Inform the kernel about current login class */
- if (lc != NULL && lc->lc_class != NULL && (flags & LOGIN_SETLOGINCLASS)) {
- error = setloginclass(lc->lc_class);
- if (error != 0) {
- syslog(LOG_ERR, "setloginclass(%s): %m", lc->lc_class);
-#ifdef notyet
- login_close(llc);
- return (-1);
-#endif
- }
- }
-
- setlogincontext(lc, pwd, flags);
login_close(llc);
/* This needs to be done after anything that needs root privs */
diff --git a/lib/libutil/mntopts.c b/lib/libutil/mntopts.c
index 07d3dd6d98a3..4a064a086fd5 100644
--- a/lib/libutil/mntopts.c
+++ b/lib/libutil/mntopts.c
@@ -145,6 +145,18 @@ checkpath_allow_file(const char *path, char *resolved)
return (0);
}
+static char *
+prependdevtopath(const char *path, char *buf, u_long buflen)
+{
+ u_long len;
+
+ if ((len = strlen(_PATH_DEV) + strlen(path) + 1) > buflen)
+ return NULL;
+ strncpy(buf, _PATH_DEV, len);
+ strncat(buf, path, len - sizeof(_PATH_DEV));
+ return (buf);
+}
+
/*
* Get the mount point information for name. Name may be mount point name
* or device name (with or without /dev/ preprended).
@@ -153,19 +165,27 @@ struct statfs *
getmntpoint(const char *name)
{
struct stat devstat, mntdevstat;
- char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
- char *ddevname;
+ char *devname;
struct statfs *mntbuf, *statfsp;
- int i, mntsize, isdev;
- u_long len;
+ int i, len, isdev, mntsize, mntfromnamesize;
+ char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
+ u_long devlen;
- if (stat(name, &devstat) != 0)
+ devlen = sizeof(device);
+ /*
+ * Note that stat(NULL, &statbuf) returns -1 (EBADF) which will
+ * cause us to return NULL if prependdevtopath() returns NULL.
+ */
+ if (stat(name, &devstat) != 0 &&
+ (name[0] != '/' &&
+ stat(prependdevtopath(name, device, devlen), &devstat) != 0))
return (NULL);
if (S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode))
isdev = 1;
else
isdev = 0;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
+ mntfromnamesize = sizeof(statfsp->f_mntfromname);
for (i = 0; i < mntsize; i++) {
statfsp = &mntbuf[i];
if (isdev == 0) {
@@ -173,19 +193,20 @@ getmntpoint(const char *name)
continue;
return (statfsp);
}
- ddevname = statfsp->f_mntfromname;
- if (*ddevname != '/') {
- if ((len = strlen(_PATH_DEV) + strlen(ddevname) + 1) >
- sizeof(statfsp->f_mntfromname) ||
- len > sizeof(device))
+ devname = statfsp->f_mntfromname;
+ if (*devname == '/') {
+ if (stat(devname, &mntdevstat) != 0)
+ continue;
+ } else {
+ devname = prependdevtopath(devname, device, devlen);
+ if (devname == NULL ||
+ (len = strlen(devname)) > mntfromnamesize)
+ continue;
+ if (stat(devname, &mntdevstat) != 0)
continue;
- strncpy(device, _PATH_DEV, len);
- strncat(device, ddevname, len);
- if (stat(device, &mntdevstat) == 0)
- strncpy(statfsp->f_mntfromname, device, len);
+ strncpy(statfsp->f_mntfromname, devname, len);
}
- if (stat(ddevname, &mntdevstat) == 0 &&
- S_ISCHR(mntdevstat.st_mode) &&
+ if (S_ISCHR(mntdevstat.st_mode) &&
mntdevstat.st_rdev == devstat.st_rdev)
return (statfsp);
}
diff --git a/lib/libwrap/Makefile b/lib/libwrap/Makefile
index bc39d5804637..7c302e0f0dc5 100644
--- a/lib/libwrap/Makefile
+++ b/lib/libwrap/Makefile
@@ -1,6 +1,3 @@
-#
-#
-
.include <src.opts.mk>
PACKAGE= tcpd
@@ -9,12 +6,14 @@ CONFS= hosts.allow
LIB= wrap
SHLIB_MAJOR= 6
INCS= tcpd.h
-MAN= hosts_access.3
-MAN+= hosts_access.5 hosts_options.5
-MLINKS= hosts_access.3 hosts_ctl.3 \
- hosts_access.3 request_init.3 \
- hosts_access.3 request_set.3 \
- hosts_options.5 hosts.allow.5
+
+MAN= hosts_access.3
+MLINKS= hosts_access.3 hosts_ctl.3 \
+ hosts_access.3 request_init.3 \
+ hosts_access.3 request_set.3
+
+MANNODEV= hosts_access.5 hosts_options.5
+MANNODEVLINKS= hosts_options.5 hosts.allow.5
.PATH: ${SRCTOP}/contrib/tcp_wrappers
diff --git a/lib/libxo/libxo/Makefile b/lib/libxo/libxo/Makefile
index 38e6ff031c7f..9caf8a498b05 100644
--- a/lib/libxo/libxo/Makefile
+++ b/lib/libxo/libxo/Makefile
@@ -51,7 +51,7 @@ MAN+= xo_attr.3 \
MAN+= xo_format.5
-MAN+= xo_options.7
+MANNODEV= xo_options.7
MLINKS= xo_attr.3 xo_attr_h.3 \
xo_attr.3 xo_attr_hv.3 \
diff --git a/lib/libxo/tests/encoder/Makefile b/lib/libxo/tests/encoder/Makefile
index 7522328b0818..02634b971ace 100644
--- a/lib/libxo/tests/encoder/Makefile
+++ b/lib/libxo/tests/encoder/Makefile
@@ -1,4 +1,5 @@
PACKAGE= tests
+NO_DEV_PACKAGE=
LIBXOSRC= ${SRCTOP}/contrib/libxo
diff --git a/lib/liby/Makefile b/lib/liby/Makefile
index 93f72ee440f8..ace8f8457d22 100644
--- a/lib/liby/Makefile
+++ b/lib/liby/Makefile
@@ -1,4 +1,4 @@
-PACKAGE=lib${LIB}
+PACKAGE=toolchain
LIB= y
SRCS= main.c yyerror.c
NO_PIC=
diff --git a/lib/libz/Makefile b/lib/libz/Makefile
index 6a135158e134..03204e388674 100644
--- a/lib/libz/Makefile
+++ b/lib/libz/Makefile
@@ -1,7 +1,4 @@
-#
-#
-
-PACKAGE= runtime
+PACKAGE= zlib
LIB= z
SHLIBDIR?= /lib
SHLIB_MAJOR= 6
diff --git a/lib/msun/man/cospi.3 b/lib/msun/man/cospi.3
index 86e63fb77498..92b449832112 100644
--- a/lib/msun/man/cospi.3
+++ b/lib/msun/man/cospi.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 1, 2017
+.Dd November 16, 2025
.Dt COSPI 3
.Os
.Sh NAME
@@ -92,12 +92,9 @@ The half\(encycle trignometric functions were written by
.An Steven G. Kargl Aq Mt kargl@FreeBSD.org .
.Sh STANDARDS
These functions conform to
-IEEE Std 754\(tm\(en2008 ,
-\(dqIEEE Standard for Floating-Point Arithmetic\(dq
-and to
-ISO/IEC TS 18661-4 ,
+.St -ieee754-2008 ,
+to ISO/IEC TS 18661-4,
\(dqInformation technology \(em Programming languages, their environments,
and system software interfaces \(em Floating\(enpoint extensions for
-C\(dq \(em Part 4: Supplementary functions.
-
-
+C\(dq \(em Part 4: Supplementary functions, and to
+.St -isoC-2023 .
diff --git a/lib/msun/man/sinpi.3 b/lib/msun/man/sinpi.3
index 63a1e3010de5..9d64e9d343a7 100644
--- a/lib/msun/man/sinpi.3
+++ b/lib/msun/man/sinpi.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 1, 2017
+.Dd November 16, 2025
.Dt SINPI 3
.Os
.Sh NAME
@@ -86,11 +86,9 @@ The half\(encycle trignometric functions were written by
.An Steven G. Kargl Aq Mt kargl@FreeBSD.org .
.Sh STANDARDS
These functions conform to
-IEEE Std 754\(tm\(en2008 ,
-\(dqIEEE Standard for Floating-Point Arithmetic\(dq
-and to
-ISO/IEC TS 18661-4 ,
+.St -ieee754-2008 ,
+to ISO/IEC TS 18661-4,
\(dqInformation technology \(em Programming languages, their environments,
and system software interfaces \(em Floating\(enpoint extensions for
-C\(dq \(em Part 4: Supplementary functions.
-
+C\(dq \(em Part 4: Supplementary functions, and to
+.St -isoC-2023 .
diff --git a/lib/msun/man/tanpi.3 b/lib/msun/man/tanpi.3
index b11d54031b71..183240418e76 100644
--- a/lib/msun/man/tanpi.3
+++ b/lib/msun/man/tanpi.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 1, 2017
+.Dd November 16, 2025
.Dt TANPI 3
.Os
.Sh NAME
@@ -88,12 +88,9 @@ The half\(encycle trignometric functions were written by
.An Steven G. Kargl Aq Mt kargl@FreeBSD.org .
.Sh STANDARDS
These functions conform to
-IEEE Std 754\(tm\(en2008 ,
-\(dqIEEE Standard for Floating-Point Arithmetic\(dq
-and to
-ISO/IEC TS 18661-4 ,
+.St -ieee754-2008 ,
+to ISO/IEC TS 18661-4,
\(dqInformation technology \(em Programming languages, their environments,
and system software interfaces \(em Floating\(enpoint extensions for
-C\(dq \(em Part 4: Supplementary functions.
-
-
+C\(dq \(em Part 4: Supplementary functions, and to
+.St -isoC-2023 .
diff --git a/lib/msun/src/e_remainder.c b/lib/msun/src/e_remainder.c
index a5fb7141d01a..cc6cd320073e 100644
--- a/lib/msun/src/e_remainder.c
+++ b/lib/msun/src/e_remainder.c
@@ -64,8 +64,8 @@ remainder(double x, double p)
if(x>=p_half) x -= p;
}
}
- GET_HIGH_WORD(hx,x);
- if ((hx&0x7fffffff)==0) hx = 0;
+ EXTRACT_WORDS(hx, lx, x);
+ if (((hx&0x7fffffff)|lx) == 0) hx = 0;
SET_HIGH_WORD(x,hx^sx);
return x;
}
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index aecc652ea08a..25bd64e36a63 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -508,6 +508,9 @@ long double lgammal_r(long double, int *);
void sincos(double, double *, double *);
void sincosf(float, float *, float *);
void sincosl(long double, long double *, long double *);
+#endif /* __BSD_VISIBLE */
+
+#if __ISO_C_VISIBLE >= 2023
double cospi(double);
float cospif(float);
long double cospil(long double);
@@ -517,7 +520,7 @@ long double sinpil(long double);
double tanpi(double);
float tanpif(float);
long double tanpil(long double);
-#endif
+#endif /* __ISO_C_VISIBLE >= 2023 */
__END_DECLS
diff --git a/lib/msun/src/s_cpow.c b/lib/msun/src/s_cpow.c
index b887db51aa2a..2c20a8f3b48b 100644
--- a/lib/msun/src/s_cpow.c
+++ b/lib/msun/src/s_cpow.c
@@ -58,7 +58,10 @@ cpow(double complex a, double complex z)
y = cimag (z);
absa = cabs (a);
if (absa == 0.0) {
- return (CMPLX(0.0, 0.0));
+ if (x == 0 && y == 0)
+ return (CMPLX(1., 0.));
+ else
+ return (CMPLX(0., 0.));
}
arga = carg (a);
r = pow (absa, x);
diff --git a/lib/msun/src/s_cpowf.c b/lib/msun/src/s_cpowf.c
index 144291079f97..b8bdbd9cb07b 100644
--- a/lib/msun/src/s_cpowf.c
+++ b/lib/msun/src/s_cpowf.c
@@ -57,7 +57,10 @@ cpowf(float complex a, float complex z)
y = cimagf(z);
absa = cabsf (a);
if (absa == 0.0f) {
- return (CMPLXF(0.0f, 0.0f));
+ if (x == 0 && y == 0)
+ return (CMPLXF(1.f, 0.f));
+ else
+ return (CMPLXF(0.f, 0.f));
}
arga = cargf (a);
r = powf (absa, x);
diff --git a/lib/msun/src/s_cpowl.c b/lib/msun/src/s_cpowl.c
index 39797cadcfcb..efbe4936895f 100644
--- a/lib/msun/src/s_cpowl.c
+++ b/lib/msun/src/s_cpowl.c
@@ -57,7 +57,10 @@ cpowl(long double complex a, long double complex z)
y = cimagl(z);
absa = cabsl(a);
if (absa == 0.0L) {
- return (CMPLXL(0.0L, 0.0L));
+ if (x == 0 && y == 0)
+ return (CMPLXL(1.L, 0.L));
+ else
+ return (CMPLXL(0.L, 0.L));
}
arga = cargl(a);
r = powl(absa, x);
diff --git a/lib/ncurses/Makefile.inc b/lib/ncurses/Makefile.inc
index f2ed84e2e38f..e14867696834 100644
--- a/lib/ncurses/Makefile.inc
+++ b/lib/ncurses/Makefile.inc
@@ -1,5 +1,7 @@
# This is to include src/lib/Makefile.inc
+PACKAGE?= ncurses
+LIB_PACKAGE=
WARNS?= 3
.include "../Makefile.inc"
diff --git a/lib/ncurses/form/Makefile b/lib/ncurses/form/Makefile
index d4774a5f51a8..7d8963b05ae8 100644
--- a/lib/ncurses/form/Makefile
+++ b/lib/ncurses/form/Makefile
@@ -3,7 +3,6 @@
SRCDIR= ${NCURSES_DIR}/form
-PACKAGE= clibs
LIB= formw
SHLIB_MAJOR= 6
diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile
index 512a452ad6d0..b60760281b39 100644
--- a/lib/ncurses/ncurses/Makefile
+++ b/lib/ncurses/ncurses/Makefile
@@ -1,4 +1,3 @@
-PACKAGE= clibs
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/ncurses/panel/Makefile b/lib/ncurses/panel/Makefile
index a51129df42e3..dfb478aa5f5b 100644
--- a/lib/ncurses/panel/Makefile
+++ b/lib/ncurses/panel/Makefile
@@ -3,7 +3,6 @@
SRCDIR= ${NCURSES_DIR}/panel
-PACKAGE= clibs
LIB= panelw
SHLIB_MAJOR= 6
diff --git a/lib/ncurses/tinfo/Makefile b/lib/ncurses/tinfo/Makefile
index 476df54bb72a..08c2311cd7a9 100644
--- a/lib/ncurses/tinfo/Makefile
+++ b/lib/ncurses/tinfo/Makefile
@@ -1,4 +1,3 @@
-PACKAGE= clibs
SHLIBDIR?= /lib
.include <src.opts.mk>
@@ -400,6 +399,7 @@ terminfo.5: MKterminfo.sh terminfo.head Caps
CLEANFILES+= terminfo.5
.PATH: ${NCURSES_DIR}/man
+
MAN= \
curs_addch.3 \
curs_addchstr.3 \
@@ -476,8 +476,9 @@ MAN+= \
curs_printw.3 \
curs_scanw.3
-MAN+= term.5 terminfo.5 scr_dump.5 user_caps.5
-MAN+= term.7
+MAN+= scr_dump.5
+
+MANNODEV= term.5 term.7 terminfo.5 user_caps.5
CLEANFILES+= ${MAN:M*.3}
diff --git a/lib/nss_tacplus/Makefile b/lib/nss_tacplus/Makefile
index f39788cfbdea..e6fb934c234b 100644
--- a/lib/nss_tacplus/Makefile
+++ b/lib/nss_tacplus/Makefile
@@ -1,9 +1,9 @@
LIB= nss_tacplus
-SRCS= ${LIB}.8
+SRCS= ${LIB}.c
SHLIB_MAJOR= 1
SHLIB_NAME= ${LIB}.so.${SHLIB_MAJOR}
LIBADD= tacplus
-MK_INSTALLIB= no
-MAN= ${LIB}.8
+MK_INSTALLLIB= no
+MANNODEV= ${LIB}.8
.include <bsd.lib.mk>
diff --git a/lib/ofed/Makefile.inc b/lib/ofed/Makefile.inc
index 1b911c451c01..5a16e0015c07 100644
--- a/lib/ofed/Makefile.inc
+++ b/lib/ofed/Makefile.inc
@@ -1 +1,4 @@
+PACKAGE?= rdma
+LIB_PACKAGE=
+
WARNS?= 0
diff --git a/lib/virtual_oss/Makefile b/lib/virtual_oss/Makefile
new file mode 100644
index 000000000000..dc83edd4b980
--- /dev/null
+++ b/lib/virtual_oss/Makefile
@@ -0,0 +1,9 @@
+.include <src.opts.mk>
+
+SHLIBDIR?= ${LIBDIR}/virtual_oss
+
+SUBDIR+= null \
+ oss
+
+.include "Makefile.inc"
+.include <bsd.subdir.mk>
diff --git a/lib/virtual_oss/Makefile.inc b/lib/virtual_oss/Makefile.inc
new file mode 100644
index 000000000000..877465a5c548
--- /dev/null
+++ b/lib/virtual_oss/Makefile.inc
@@ -0,0 +1,5 @@
+PACKAGE= sound
+
+.include "../Makefile.inc"
+
+LDFLAGS+= -L${.OBJDIR:H:H}/libsamplerate
diff --git a/lib/virtual_oss/bt/Makefile b/lib/virtual_oss/bt/Makefile
new file mode 100644
index 000000000000..15413b7a1f1e
--- /dev/null
+++ b/lib/virtual_oss/bt/Makefile
@@ -0,0 +1,19 @@
+SHLIB_NAME= voss_bt.so
+SHLIBDIR= ${LIBDIR}/virtual_oss
+
+SRCS= bt.c \
+ avdtp.c \
+ sbc_encode.c
+
+CFLAGS+= -I${SRCTOP}/usr.sbin/virtual_oss/virtual_oss \
+ -I${SRCTOP}/contrib/libsamplerate
+LDFLAGS+= -lbluetooth -lsdp
+LIBADD= samplerate
+
+.if defined(HAVE_LIBAV)
+CFLAGS+= -I${LOCALBASE:U/usr/local}/include -DHAVE_LIBAV
+LDFLAGS+= -L${LOCALBASE:U/usr/local}/lib \
+ -lavdevice -lavutil -lavcodec -lavformat
+.endif
+
+.include <bsd.lib.mk>
diff --git a/lib/virtual_oss/bt/avdtp.c b/lib/virtual_oss/bt/avdtp.c
new file mode 100644
index 000000000000..82ed0fb942b6
--- /dev/null
+++ b/lib/virtual_oss/bt/avdtp.c
@@ -0,0 +1,720 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2015-2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
+ * Copyright (c) 2016-2019 Hans Petter Selasky <hps@selasky.org>
+ * Copyright (c) 2019 Google LLC, written by Richard Kralovic <riso@google.com>
+ *
+ * This software is dedicated to the memory of -
+ * Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
+ *
+ * Barry was a man who loved his music.
+ *
+ * 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/uio.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "avdtp_signal.h"
+#include "bt.h"
+
+#define DPRINTF(...) printf("backend_bt: " __VA_ARGS__)
+
+struct avdtpGetPacketInfo {
+ uint8_t buffer_data[512];
+ uint16_t buffer_len;
+ uint8_t trans;
+ uint8_t signalID;
+};
+
+static int avdtpAutoConfig(struct bt_config *);
+
+/* Return received message type if success, < 0 if failure. */
+static int
+avdtpGetPacket(int fd, struct avdtpGetPacketInfo *info)
+{
+ uint8_t *pos = info->buffer_data;
+ uint8_t *end = info->buffer_data + sizeof(info->buffer_data);
+ uint8_t message_type;
+ int len;
+
+ memset(info, 0, sizeof(*info));
+
+ /* Handle fragmented packets */
+ for (int remaining = 1; remaining > 0; --remaining) {
+ len = read(fd, pos, end - pos);
+
+ if (len < AVDTP_LEN_SUCCESS)
+ return (-1);
+ if (len == (int)(end - pos))
+ return (-1); /* buffer too small */
+
+ uint8_t trans = (pos[0] & TRANSACTIONLABEL) >> TRANSACTIONLABEL_S;
+ uint8_t packet_type = (pos[0] & PACKETTYPE) >> PACKETTYPE_S;
+ uint8_t current_message_type = (info->buffer_data[0] & MESSAGETYPE);
+ uint8_t shift;
+ if (pos == info->buffer_data) {
+ info->trans = trans;
+ message_type = current_message_type;
+ if (packet_type == singlePacket) {
+ info->signalID = (pos[1] & SIGNALID_MASK);
+ shift = 2;
+ } else {
+ if (packet_type != startPacket)
+ return (-1);
+ remaining = pos[1];
+ info->signalID = (pos[2] & SIGNALID_MASK);
+ shift = 3;
+ }
+ } else {
+ if (info->trans != trans ||
+ message_type != current_message_type ||
+ (remaining == 1 && packet_type != endPacket) ||
+ (remaining > 1 && packet_type != continuePacket)) {
+ return (-1);
+ }
+ shift = 1;
+ }
+ memmove(pos, pos + shift, len);
+ pos += len;
+ }
+ info->buffer_len = pos - info->buffer_data;
+ return (message_type);
+}
+
+/* Returns 0 on success, < 0 on failure. */
+static int
+avdtpSendPacket(int fd, uint8_t command, uint8_t trans, uint8_t type,
+ uint8_t * data0, int datasize0, uint8_t * data1,
+ int datasize1)
+{
+ struct iovec iov[3];
+ uint8_t header[2];
+ int retval;
+
+ /* fill out command header */
+ header[0] = (trans << 4) | (type & 3);
+ if (command != 0)
+ header[1] = command & 0x3f;
+ else
+ header[1] = 3;
+
+ iov[0].iov_base = header;
+ iov[0].iov_len = 2;
+ iov[1].iov_base = data0;
+ iov[1].iov_len = datasize0;
+ iov[2].iov_base = data1;
+ iov[2].iov_len = datasize1;
+
+ retval = writev(fd, iov, 3);
+ if (retval != (2 + datasize0 + datasize1))
+ return (-EINVAL);
+ else
+ return (0);
+}
+
+/* Returns 0 on success, < 0 on failure. */
+static int
+avdtpSendSyncCommand(int fd, struct avdtpGetPacketInfo *info,
+ uint8_t command, uint8_t type, uint8_t * data0,
+ int datasize0, uint8_t * data1, int datasize1)
+{
+ static uint8_t transLabel;
+ uint8_t trans;
+ int retval;
+
+ alarm(8); /* set timeout */
+
+ trans = (transLabel++) & 0xF;
+
+ retval = avdtpSendPacket(fd, command, trans, type,
+ data0, datasize0, data1, datasize1);
+ if (retval)
+ goto done;
+retry:
+ switch (avdtpGetPacket(fd, info)) {
+ case RESPONSEACCEPT:
+ if (info->trans != trans)
+ goto retry;
+ retval = 0;
+ break;
+ case RESPONSEREJECT:
+ if (info->trans != trans)
+ goto retry;
+ retval = -EINVAL;
+ break;
+ case COMMAND:
+ retval = avdtpSendReject(fd, info->trans, info->signalID);
+ if (retval == 0)
+ goto retry;
+ break;
+ default:
+ retval = -ENXIO;
+ break;
+ }
+done:
+ alarm(0); /* clear timeout */
+
+ return (retval);
+}
+
+/*
+ * Variant for acceptor role: We support any frequency, blocks, bands, and
+ * allocation. Returns 0 on success, < 0 on failure.
+ */
+static int
+avdtpSendCapabilitiesResponseSBCForACP(int fd, int trans)
+{
+ uint8_t data[10];
+
+ data[0] = mediaTransport;
+ data[1] = 0;
+ data[2] = mediaCodec;
+ data[3] = 0x6;
+ data[4] = mediaTypeAudio;
+ data[5] = SBC_CODEC_ID;
+ data[6] =
+ (1 << (3 - MODE_STEREO)) |
+ (1 << (3 - MODE_JOINT)) |
+ (1 << (3 - MODE_DUAL)) |
+ (1 << (3 - MODE_MONO)) |
+ (1 << (7 - FREQ_44_1K)) |
+ (1 << (7 - FREQ_48K)) |
+ (1 << (7 - FREQ_32K)) |
+ (1 << (7 - FREQ_16K));
+ data[7] =
+ (1 << (7 - BLOCKS_4)) |
+ (1 << (7 - BLOCKS_8)) |
+ (1 << (7 - BLOCKS_12)) |
+ (1 << (7 - BLOCKS_16)) |
+ (1 << (3 - BANDS_4)) |
+ (1 << (3 - BANDS_8)) | (1 << ALLOC_LOUDNESS) | (1 << ALLOC_SNR);
+ data[8] = MIN_BITPOOL;
+ data[9] = DEFAULT_MAXBPOOL;
+
+ return (avdtpSendPacket(fd, AVDTP_GET_CAPABILITIES, trans,
+ RESPONSEACCEPT, data, sizeof(data), NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpSendAccept(int fd, uint8_t trans, uint8_t myCommand)
+{
+ return (avdtpSendPacket(fd, myCommand, trans, RESPONSEACCEPT,
+ NULL, 0, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpSendReject(int fd, uint8_t trans, uint8_t myCommand)
+{
+ uint8_t value = 0;
+
+ return (avdtpSendPacket(fd, myCommand, trans, RESPONSEREJECT,
+ &value, 1, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpSendDiscResponseAudio(int fd, uint8_t trans,
+ uint8_t mySep, uint8_t is_sink)
+{
+ uint8_t data[2];
+
+ data[0] = mySep << 2;
+ data[1] = mediaTypeAudio << 4 | (is_sink ? (1 << 3) : 0);
+
+ return (avdtpSendPacket(fd, AVDTP_DISCOVER, trans, RESPONSEACCEPT,
+ data, 2, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpDiscoverAndConfig(struct bt_config *cfg, bool isSink)
+{
+ struct avdtpGetPacketInfo info;
+ uint16_t offset;
+ uint8_t chmode = cfg->chmode;
+ uint8_t aacMode1 = cfg->aacMode1;
+ uint8_t aacMode2 = cfg->aacMode2;
+ int retval;
+
+ retval = avdtpSendSyncCommand(cfg->hc, &info, AVDTP_DISCOVER, 0,
+ NULL, 0, NULL, 0);
+ if (retval)
+ return (retval);
+
+ retval = -EBUSY;
+ for (offset = 0; offset + 2 <= info.buffer_len; offset += 2) {
+ cfg->sep = info.buffer_data[offset] >> 2;
+ cfg->media_Type = info.buffer_data[offset + 1] >> 4;
+ cfg->chmode = chmode;
+ cfg->aacMode1 = aacMode1;
+ cfg->aacMode2 = aacMode2;
+ if (info.buffer_data[offset] & DISCOVER_SEP_IN_USE)
+ continue;
+ if (info.buffer_data[offset + 1] & DISCOVER_IS_SINK) {
+ if (!isSink)
+ continue;
+ } else {
+ if (isSink)
+ continue;
+ }
+ /* try to configure SBC */
+ retval = avdtpAutoConfig(cfg);
+ if (retval == 0)
+ return (0);
+ }
+ return (retval);
+}
+
+/* Returns 0 on success, < 0 on failure. */
+static int
+avdtpGetCapabilities(int fd, uint8_t sep, struct avdtpGetPacketInfo *info)
+{
+ uint8_t address = (sep << 2);
+
+ return (avdtpSendSyncCommand(fd, info,
+ AVDTP_GET_CAPABILITIES, 0, &address, 1,
+ NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpSetConfiguration(int fd, uint8_t sep, uint8_t * data, int datasize)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t configAddresses[2];
+
+ configAddresses[0] = sep << 2;
+ configAddresses[1] = INTSEP << 2;
+
+ return (avdtpSendSyncCommand(fd, &info, AVDTP_SET_CONFIGURATION, 0,
+ configAddresses, 2, data, datasize));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpOpen(int fd, uint8_t sep)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t address = sep << 2;
+
+ return (avdtpSendSyncCommand(fd, &info, AVDTP_OPEN, 0,
+ &address, 1, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpStart(int fd, uint8_t sep)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t address = sep << 2;
+
+ return (avdtpSendSyncCommand(fd, &info, AVDTP_START, 0,
+ &address, 1, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpClose(int fd, uint8_t sep)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t address = sep << 2;
+
+ return (avdtpSendSyncCommand(fd, &info, AVDTP_CLOSE, 0,
+ &address, 1, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpSuspend(int fd, uint8_t sep)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t address = sep << 2;
+
+ return (avdtpSendSyncCommand(fd, &info, AVDTP_SUSPEND, 0,
+ &address, 1, NULL, 0));
+}
+
+/* Returns 0 on success, < 0 on failure. */
+int
+avdtpAbort(int fd, uint8_t sep)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t address = sep << 2;
+
+ return (avdtpSendSyncCommand(fd, &info, AVDTP_ABORT, 0,
+ &address, 1, NULL, 0));
+}
+
+static int
+avdtpAutoConfig(struct bt_config *cfg)
+{
+ struct avdtpGetPacketInfo info;
+ uint8_t freqmode;
+ uint8_t blk_len_sb_alloc;
+ uint8_t availFreqMode = 0;
+ uint8_t availConfig = 0;
+ uint8_t supBitpoolMin = 0;
+ uint8_t supBitpoolMax = 0;
+ uint8_t aacMode1 = 0;
+ uint8_t aacMode2 = 0;
+#ifdef HAVE_LIBAV
+ uint8_t aacBitrate3 = 0;
+ uint8_t aacBitrate4 = 0;
+ uint8_t aacBitrate5 = 0;
+#endif
+ int retval;
+ int i;
+
+ retval = avdtpGetCapabilities(cfg->hc, cfg->sep, &info);
+ if (retval) {
+ DPRINTF("Cannot get capabilities\n");
+ return (retval);
+ }
+retry:
+ for (i = 0; (i + 1) < info.buffer_len;) {
+#if 0
+ DPRINTF("0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
+ info.buffer_data[i + 0],
+ info.buffer_data[i + 1],
+ info.buffer_data[i + 2],
+ info.buffer_data[i + 3],
+ info.buffer_data[i + 4], info.buffer_data[i + 5]);
+#endif
+ if (i + 2 + info.buffer_data[i + 1] > info.buffer_len)
+ break;
+ switch (info.buffer_data[i]) {
+ case mediaTransport:
+ break;
+ case mediaCodec:
+ if (info.buffer_data[i + 1] < 2)
+ break;
+ /* check codec */
+ switch (info.buffer_data[i + 3]) {
+ case 0: /* SBC */
+ if (info.buffer_data[i + 1] < 6)
+ break;
+ availFreqMode = info.buffer_data[i + 4];
+ availConfig = info.buffer_data[i + 5];
+ supBitpoolMin = info.buffer_data[i + 6];
+ supBitpoolMax = info.buffer_data[i + 7];
+ break;
+ case 2: /* MPEG2/4 AAC */
+ if (info.buffer_data[i + 1] < 8)
+ break;
+ aacMode1 = info.buffer_data[i + 5];
+ aacMode2 = info.buffer_data[i + 6];
+#ifdef HAVE_LIBAV
+ aacBitrate3 = info.buffer_data[i + 7];
+ aacBitrate4 = info.buffer_data[i + 8];
+ aacBitrate5 = info.buffer_data[i + 9];
+#endif
+ break;
+ default:
+ break;
+ }
+ }
+ /* jump to next information element */
+ i += 2 + info.buffer_data[i + 1];
+ }
+ aacMode1 &= cfg->aacMode1;
+ aacMode2 &= cfg->aacMode2;
+
+ /* Try AAC first */
+ if (aacMode1 == cfg->aacMode1 && aacMode2 == cfg->aacMode2) {
+#ifdef HAVE_LIBAV
+ uint8_t config[12] = { mediaTransport, 0x0, mediaCodec,
+ 0x8, 0x0, 0x02, 0x80, aacMode1, aacMode2, aacBitrate3,
+ aacBitrate4, aacBitrate5
+ };
+
+ if (avdtpSetConfiguration
+ (cfg->hc, cfg->sep, config, sizeof(config)) == 0) {
+ cfg->codec = CODEC_AAC;
+ return (0);
+ }
+#endif
+ }
+ /* Try SBC second */
+ if (cfg->freq == FREQ_UNDEFINED)
+ goto auto_config_failed;
+
+ freqmode = (1 << (3 - cfg->freq + 4)) | (1 << (3 - cfg->chmode));
+
+ if ((availFreqMode & freqmode) != freqmode) {
+ DPRINTF("No frequency and mode match\n");
+ goto auto_config_failed;
+ }
+ for (i = 0; i != 4; i++) {
+ blk_len_sb_alloc = (1 << (i + 4)) |
+ (1 << (1 - cfg->bands + 2)) | (1 << cfg->allocm);
+
+ if ((availConfig & blk_len_sb_alloc) == blk_len_sb_alloc)
+ break;
+ }
+ if (i == 4) {
+ DPRINTF("No bands available\n");
+ goto auto_config_failed;
+ }
+ cfg->blocks = (3 - i);
+
+ if (cfg->allocm == ALLOC_SNR)
+ supBitpoolMax &= ~1;
+
+ if (cfg->chmode == MODE_DUAL || cfg->chmode == MODE_MONO)
+ supBitpoolMax /= 2;
+
+ if (cfg->bands == BANDS_4)
+ supBitpoolMax /= 2;
+
+ if (supBitpoolMax > cfg->bitpool)
+ supBitpoolMax = cfg->bitpool;
+ else
+ cfg->bitpool = supBitpoolMax;
+
+ do {
+ uint8_t config[10] = { mediaTransport, 0x0, mediaCodec, 0x6,
+ 0x0, 0x0, freqmode, blk_len_sb_alloc, supBitpoolMin,
+ supBitpoolMax
+ };
+
+ if (avdtpSetConfiguration
+ (cfg->hc, cfg->sep, config, sizeof(config)) == 0) {
+ cfg->codec = CODEC_SBC;
+ return (0);
+ }
+ } while (0);
+
+auto_config_failed:
+ if (cfg->chmode == MODE_STEREO) {
+ cfg->chmode = MODE_MONO;
+ cfg->aacMode2 ^= 0x0C;
+ goto retry;
+ }
+ return (-EINVAL);
+}
+
+void
+avdtpACPFree(struct bt_config *cfg)
+{
+ if (cfg->handle.sbc_enc) {
+ free(cfg->handle.sbc_enc);
+ cfg->handle.sbc_enc = NULL;
+ }
+}
+
+/* Returns 0 on success, < 0 on failure. */
+static int
+avdtpParseSBCConfig(uint8_t * data, struct bt_config *cfg)
+{
+ if (data[0] & (1 << (7 - FREQ_48K))) {
+ cfg->freq = FREQ_48K;
+ } else if (data[0] & (1 << (7 - FREQ_44_1K))) {
+ cfg->freq = FREQ_44_1K;
+ } else if (data[0] & (1 << (7 - FREQ_32K))) {
+ cfg->freq = FREQ_32K;
+ } else if (data[0] & (1 << (7 - FREQ_16K))) {
+ cfg->freq = FREQ_16K;
+ } else {
+ return -EINVAL;
+ }
+
+ if (data[0] & (1 << (3 - MODE_STEREO))) {
+ cfg->chmode = MODE_STEREO;
+ } else if (data[0] & (1 << (3 - MODE_JOINT))) {
+ cfg->chmode = MODE_JOINT;
+ } else if (data[0] & (1 << (3 - MODE_DUAL))) {
+ cfg->chmode = MODE_DUAL;
+ } else if (data[0] & (1 << (3 - MODE_MONO))) {
+ cfg->chmode = MODE_MONO;
+ } else {
+ return -EINVAL;
+ }
+
+ if (data[1] & (1 << (7 - BLOCKS_16))) {
+ cfg->blocks = BLOCKS_16;
+ } else if (data[1] & (1 << (7 - BLOCKS_12))) {
+ cfg->blocks = BLOCKS_12;
+ } else if (data[1] & (1 << (7 - BLOCKS_8))) {
+ cfg->blocks = BLOCKS_8;
+ } else if (data[1] & (1 << (7 - BLOCKS_4))) {
+ cfg->blocks = BLOCKS_4;
+ } else {
+ return -EINVAL;
+ }
+
+ if (data[1] & (1 << (3 - BANDS_8))) {
+ cfg->bands = BANDS_8;
+ } else if (data[1] & (1 << (3 - BANDS_4))) {
+ cfg->bands = BANDS_4;
+ } else {
+ return -EINVAL;
+ }
+
+ if (data[1] & (1 << ALLOC_LOUDNESS)) {
+ cfg->allocm = ALLOC_LOUDNESS;
+ } else if (data[1] & (1 << ALLOC_SNR)) {
+ cfg->allocm = ALLOC_SNR;
+ } else {
+ return -EINVAL;
+ }
+ cfg->bitpool = data[3];
+ return 0;
+}
+
+int
+avdtpACPHandlePacket(struct bt_config *cfg)
+{
+ struct avdtpGetPacketInfo info;
+ int retval;
+
+ if (avdtpGetPacket(cfg->hc, &info) != COMMAND)
+ return (-ENXIO);
+
+ switch (info.signalID) {
+ case AVDTP_DISCOVER:
+ retval =
+ avdtpSendDiscResponseAudio(cfg->hc, info.trans, ACPSEP, 1);
+ if (!retval)
+ retval = AVDTP_DISCOVER;
+ break;
+ case AVDTP_GET_CAPABILITIES:
+ retval =
+ avdtpSendCapabilitiesResponseSBCForACP(cfg->hc, info.trans);
+ if (!retval)
+ retval = AVDTP_GET_CAPABILITIES;
+ break;
+ case AVDTP_SET_CONFIGURATION:
+ if (cfg->acceptor_state != acpInitial)
+ goto err;
+ cfg->sep = info.buffer_data[1] >> 2;
+ int is_configured = 0;
+ for (int i = 2; (i + 1) < info.buffer_len;) {
+ if (i + 2 + info.buffer_data[i + 1] > info.buffer_len)
+ break;
+ switch (info.buffer_data[i]) {
+ case mediaTransport:
+ break;
+ case mediaCodec:
+ if (info.buffer_data[i + 1] < 2)
+ break;
+ /* check codec */
+ switch (info.buffer_data[i + 3]) {
+ case 0: /* SBC */
+ if (info.buffer_data[i + 1] < 6)
+ break;
+ retval =
+ avdtpParseSBCConfig(info.buffer_data + i + 4, cfg);
+ if (retval)
+ return retval;
+ is_configured = 1;
+ break;
+ case 2: /* MPEG2/4 AAC */
+ /* TODO: Add support */
+ default:
+ break;
+ }
+ }
+ /* jump to next information element */
+ i += 2 + info.buffer_data[i + 1];
+ }
+ if (!is_configured)
+ goto err;
+
+ retval =
+ avdtpSendAccept(cfg->hc, info.trans, AVDTP_SET_CONFIGURATION);
+ if (retval)
+ return (retval);
+
+ /* TODO: Handle other codecs */
+ if (cfg->handle.sbc_enc == NULL) {
+ cfg->handle.sbc_enc = malloc(sizeof(*cfg->handle.sbc_enc));
+ if (cfg->handle.sbc_enc == NULL)
+ return (-ENOMEM);
+ }
+ memset(cfg->handle.sbc_enc, 0, sizeof(*cfg->handle.sbc_enc));
+
+ retval = AVDTP_SET_CONFIGURATION;
+ cfg->acceptor_state = acpConfigurationSet;
+ break;
+ case AVDTP_OPEN:
+ if (cfg->acceptor_state != acpConfigurationSet)
+ goto err;
+ retval = avdtpSendAccept(cfg->hc, info.trans, info.signalID);
+ if (retval)
+ return (retval);
+ retval = info.signalID;
+ cfg->acceptor_state = acpStreamOpened;
+ break;
+ case AVDTP_START:
+ if (cfg->acceptor_state != acpStreamOpened &&
+ cfg->acceptor_state != acpStreamSuspended) {
+ goto err;
+ }
+ retval = avdtpSendAccept(cfg->hc, info.trans, info.signalID);
+ if (retval)
+ return retval;
+ retval = info.signalID;
+ cfg->acceptor_state = acpStreamStarted;
+ break;
+ case AVDTP_CLOSE:
+ if (cfg->acceptor_state != acpStreamOpened &&
+ cfg->acceptor_state != acpStreamStarted &&
+ cfg->acceptor_state != acpStreamSuspended) {
+ goto err;
+ }
+ retval = avdtpSendAccept(cfg->hc, info.trans, info.signalID);
+ if (retval)
+ return (retval);
+ retval = info.signalID;
+ cfg->acceptor_state = acpStreamClosed;
+ break;
+ case AVDTP_SUSPEND:
+ if (cfg->acceptor_state != acpStreamOpened &&
+ cfg->acceptor_state != acpStreamStarted) {
+ goto err;
+ }
+ retval = avdtpSendAccept(cfg->hc, info.trans, info.signalID);
+ if (retval)
+ return (retval);
+ retval = info.signalID;
+ cfg->acceptor_state = acpStreamSuspended;
+ break;
+ case AVDTP_GET_CONFIGURATION:
+ case AVDTP_RECONFIGURE:
+ case AVDTP_ABORT:
+ /* TODO: Implement this. */
+ default:
+err:
+ avdtpSendReject(cfg->hc, info.trans, info.signalID);
+ return (-ENXIO);
+ }
+ return (retval);
+}
diff --git a/lib/virtual_oss/bt/avdtp_signal.h b/lib/virtual_oss/bt/avdtp_signal.h
new file mode 100644
index 000000000000..a46cc6dd9dcf
--- /dev/null
+++ b/lib/virtual_oss/bt/avdtp_signal.h
@@ -0,0 +1,139 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2015 Nathanial Sloss <nathanialsloss@yahoo.com.au>
+ *
+ * This software is dedicated to the memory of -
+ * Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
+ *
+ * Barry was a man who loved his music.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _AVDTP_SIGNAL_H_
+#define _AVDTP_SIGNAL_H_
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/* Our endpoint. */
+#define INTSEP 8
+#define ACPSEP 8
+
+/* AVDTP signals. */
+
+#define AVDTP_DISCOVER 0x01
+#define AVDTP_GET_CAPABILITIES 0x02
+#define AVDTP_SET_CONFIGURATION 0x03
+#define AVDTP_GET_CONFIGURATION 0x04
+#define AVDTP_RECONFIGURE 0x05
+#define AVDTP_OPEN 0x06
+#define AVDTP_START 0x07
+#define AVDTP_CLOSE 0x08
+#define AVDTP_SUSPEND 0x09
+#define AVDTP_ABORT 0x0a
+#define AVDTP_SECUURITY_CONTROL 0x0b
+
+/* Signal Command & Response Header Masks. */
+
+#define TRANSACTIONLABEL 0xf0
+#define TRANSACTIONLABEL_S 4
+#define SIGNALID_MASK 0x3f
+#define PACKETTYPE 0x0c
+#define PACKETTYPE_S 0x02
+#define MESSAGETYPE 0x03
+#define SIGNALIDENTIFIER 0x3f
+#define DISCOVER_SEP_IN_USE 0x02
+#define DISCOVER_IS_SINK 0x08
+
+/* Packet Types */
+#define singlePacket 0x0
+#define startPacket 0x1
+#define continuePacket 0x2
+#define endPacket 0x3
+
+/* Message Types */
+#define COMMAND 0x0
+#define RESPONSEACCEPT 0x2
+#define RESPONSEREJECT 0x3
+
+/* Response general error/success lengths */
+#define AVDTP_LEN_SUCCESS 2
+#define AVDTP_LEN_ERROR 3
+
+/* Error codes */
+#define BAD_HEADER_FORMAT 0x01
+#define BAD_LENGTH 0x11
+#define BAD_ACP_SEID 0x12
+#define SEP_IN_USE 0x13
+#define SEP_NOT_IN_USE 0x14
+#define BAD_SERV_CATAGORY 0x17
+#define BAD_PAYLOAD_FORMAT 0x18
+#define NOT_SUPPORTED_COMMAND 0x19
+#define INVALID_CAPABILITIES 0x1a
+
+#define BAD_RECOVERY_TYPE 0x22
+#define BAD_MEDIA_TRANSPORT_FORMAT 0x23
+#define BAD_RECOVERY_FORMAT 0x25
+#define BAD_ROHC_FORMAT 0x26
+#define BAD_CP_FORMAT 0x27
+#define BAD_MULTIPLEXING_FORMAT 0x28
+#define UNSUPPORTED_CONFIGURATION 0x29
+#define BAD_STATE 0x31
+
+/* Service Capabilities Field. */
+#define mediaTransport 0x1
+#define reporting 0x2
+#define recovery 0x3
+#define contentProtection 0x4
+#define headerCompression 0x5
+#define multiplexing 0x6
+#define mediaCodec 0x7
+
+/* Media Codec Capabilities */
+#define mediaCodecSbc 0x00
+#define mediaCodecMpeg1 0x01
+#define mediaCodecMpeg2 0x02
+
+#define SBC_CODEC_ID 0x0
+#define mediaTypeAudio 0x0
+
+struct bt_config;
+
+int avdtpSendAccept(int, uint8_t, uint8_t);
+int avdtpSendReject(int, uint8_t, uint8_t);
+int avdtpSendDiscResponseAudio(int, uint8_t, uint8_t, uint8_t);
+int avdtpDiscoverAndConfig(struct bt_config *, bool);
+int avdtpSetConfiguration(int, uint8_t, uint8_t *, int);
+int avdtpOpen(int, uint8_t);
+int avdtpStart(int, uint8_t);
+int avdtpClose(int, uint8_t);
+int avdtpSuspend(int, uint8_t);
+int avdtpAbort(int, uint8_t);
+
+/* Return < 0 if error, processed signal otherwise. */
+int avdtpACPHandlePacket(struct bt_config *cfg);
+/* Free state allocated in avdtpACPHandlePacket(), if any. */
+void avdtpACPFree(struct bt_config *cfg);
+
+#endif /* _AVDTP_SIGNAL_H_ */
diff --git a/lib/virtual_oss/bt/bt.c b/lib/virtual_oss/bt/bt.c
new file mode 100644
index 000000000000..57f000b067d5
--- /dev/null
+++ b/lib/virtual_oss/bt/bt.c
@@ -0,0 +1,1061 @@
+/*-
+ * Copyright (c) 2015-2019 Hans Petter Selasky
+ * Copyright (c) 2015 Nathanial Sloss <nathanialsloss@yahoo.com.au>
+ * Copyright (c) 2006 Itronix Inc
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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/queue.h>
+#include <sys/filio.h>
+#include <sys/soundcard.h>
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <err.h>
+#define L2CAP_SOCKET_CHECKED
+#include <bluetooth.h>
+#include <sdp.h>
+
+#include "backend.h"
+#include "int.h"
+
+#include "avdtp_signal.h"
+#include "bt.h"
+
+#define DPRINTF(...) printf("backend_bt: " __VA_ARGS__)
+
+struct l2cap_info {
+ bdaddr_t laddr;
+ bdaddr_t raddr;
+};
+
+static struct bt_config bt_play_cfg;
+static struct bt_config bt_rec_cfg;
+
+int
+bt_receive(struct bt_config *cfg, void *ptr, int len, int use_delay)
+{
+ struct sbc_header *phdr = (struct sbc_header *)cfg->mtu_data;
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ uint8_t *tmp = ptr;
+ int old_len = len;
+ int delta;
+ int err;
+
+ /* wait for service interval, if any */
+ if (use_delay)
+ virtual_oss_wait();
+
+ switch (cfg->blocks) {
+ case BLOCKS_4:
+ sbc->blocks = 4;
+ break;
+ case BLOCKS_8:
+ sbc->blocks = 8;
+ break;
+ case BLOCKS_12:
+ sbc->blocks = 12;
+ break;
+ default:
+ sbc->blocks = 16;
+ break;
+ }
+
+ switch (cfg->bands) {
+ case BANDS_4:
+ sbc->bands = 4;
+ break;
+ default:
+ sbc->bands = 8;
+ break;
+ }
+
+ if (cfg->chmode != MODE_MONO) {
+ sbc->channels = 2;
+ } else {
+ sbc->channels = 1;
+ }
+
+ while (1) {
+ delta = len & ~1;
+ if (delta > (int)(2 * sbc->rem_len))
+ delta = (2 * sbc->rem_len);
+
+ /* copy out samples, if any */
+ memcpy(tmp, (char *)sbc->music_data + sbc->rem_off, delta);
+ tmp += delta;
+ len -= delta;
+ sbc->rem_off += delta / 2;
+ sbc->rem_len -= delta / 2;
+ if (len == 0)
+ break;
+
+ if (sbc->rem_len == 0 &&
+ sbc->rem_data_frames != 0) {
+ err = sbc_decode_frame(cfg, sbc->rem_data_len * 8);
+ sbc->rem_data_frames--;
+ sbc->rem_data_ptr += err;
+ sbc->rem_data_len -= err;
+ continue;
+ }
+ /* TODO: Support fragmented SBC frames */
+ err = read(cfg->fd, cfg->mtu_data, cfg->mtu);
+
+ if (err == 0) {
+ break;
+ } else if (err < 0) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ break;
+ else
+ return (-1); /* disconnected */
+ }
+
+ /* verify RTP header */
+ if (err < (int)sizeof(*phdr) || phdr->id != 0x80)
+ continue;
+
+ sbc->rem_data_frames = phdr->numFrames;
+ sbc->rem_data_ptr = (uint8_t *)(phdr + 1);
+ sbc->rem_data_len = err - sizeof(*phdr);
+ }
+ return (old_len - len);
+}
+
+static int
+bt_set_format(int *format)
+{
+ int value;
+
+ value = *format & AFMT_S16_NE;
+ if (value != 0) {
+ *format = value;
+ return (0);
+ }
+ return (-1);
+}
+
+static void
+bt_close(struct voss_backend *pbe)
+{
+ struct bt_config *cfg = pbe->arg;
+
+ if (cfg->hc > 0) {
+ avdtpAbort(cfg->hc, cfg->sep);
+ avdtpClose(cfg->hc, cfg->sep);
+ close(cfg->hc);
+ cfg->hc = -1;
+ }
+ if (cfg->fd > 0) {
+ close(cfg->fd);
+ cfg->fd = -1;
+ }
+}
+
+static void
+bt_play_close(struct voss_backend *pbe)
+{
+ struct bt_config *cfg = pbe->arg;
+
+ switch (cfg->codec) {
+ case CODEC_SBC:
+ if (cfg->handle.sbc_enc == NULL)
+ break;
+ free(cfg->handle.sbc_enc);
+ cfg->handle.sbc_enc = NULL;
+ break;
+#ifdef HAVE_LIBAV
+ case CODEC_AAC:
+ if (cfg->handle.av.context == NULL)
+ break;
+ av_free(cfg->rem_in_data);
+ av_frame_free(&cfg->handle.av.frame);
+ avcodec_close(cfg->handle.av.context);
+ avformat_free_context(cfg->handle.av.format);
+ cfg->handle.av.context = NULL;
+ break;
+#endif
+ default:
+ break;
+ }
+ return (bt_close(pbe));
+}
+
+static void
+bt_rec_close(struct voss_backend *pbe)
+{
+ struct bt_config *cfg = pbe->arg;
+
+ switch (cfg->codec) {
+ case CODEC_SBC:
+ break;
+#ifdef HAVE_LIBAV
+ case CODEC_AAC:
+ break;
+#endif
+
+ default:
+ break;
+ }
+ return (bt_close(pbe));
+}
+
+static const uint32_t bt_attrs[] = {
+ SDP_ATTR_RANGE(SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
+ SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST),
+};
+
+#define BT_NUM_VALUES 32
+#define BT_BUF_SIZE 32
+
+static int
+bt_find_psm(const uint8_t *start, const uint8_t *end)
+{
+ uint32_t type;
+ uint32_t len;
+ int protover = 0;
+ int psm = -1;
+
+ if ((end - start) < 2)
+ return (-1);
+
+ SDP_GET8(type, start);
+ switch (type) {
+ case SDP_DATA_SEQ8:
+ SDP_GET8(len, start);
+ break;
+
+ case SDP_DATA_SEQ16:
+ SDP_GET16(len, start);
+ break;
+
+ case SDP_DATA_SEQ32:
+ SDP_GET32(len, start);
+ break;
+
+ default:
+ return (-1);
+ }
+
+ while (start < end) {
+ SDP_GET8(type, start);
+ switch (type) {
+ case SDP_DATA_SEQ8:
+ SDP_GET8(len, start);
+ break;
+
+ case SDP_DATA_SEQ16:
+ SDP_GET16(len, start);
+ break;
+
+ case SDP_DATA_SEQ32:
+ SDP_GET32(len, start);
+ break;
+
+ default:
+ return (-1);
+ }
+ /* check range */
+ if (len > (uint32_t)(end - start))
+ break;
+
+ if (len >= 6) {
+ const uint8_t *ptr = start;
+
+ SDP_GET8(type, ptr);
+ if (type == SDP_DATA_UUID16) {
+ uint16_t temp;
+
+ SDP_GET16(temp, ptr);
+ switch (temp) {
+ case SDP_UUID_PROTOCOL_L2CAP:
+ SDP_GET8(type, ptr);
+ SDP_GET16(psm, ptr);
+ break;
+ case SDP_UUID_PROTOCOL_AVDTP:
+ SDP_GET8(type, ptr);
+ SDP_GET16(protover, ptr);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ start += len;
+
+ if (protover >= 0x0100 && psm > -1)
+ return (htole16(psm));
+ }
+ return (-1);
+}
+
+static int
+bt_query(struct l2cap_info *info, uint16_t service_class)
+{
+ sdp_attr_t values[BT_NUM_VALUES];
+ uint8_t buffer[BT_NUM_VALUES][BT_BUF_SIZE];
+ void *ss;
+ int psm = -1;
+ int n;
+
+ memset(buffer, 0, sizeof(buffer));
+ memset(values, 0, sizeof(values));
+
+ ss = sdp_open(&info->laddr, &info->raddr);
+ if (ss == NULL || sdp_error(ss) != 0) {
+ DPRINTF("Could not open SDP\n");
+ sdp_close(ss);
+ return (psm);
+ }
+ /* Initialize attribute values array */
+ for (n = 0; n != BT_NUM_VALUES; n++) {
+ values[n].flags = SDP_ATTR_INVALID;
+ values[n].vlen = BT_BUF_SIZE;
+ values[n].value = buffer[n];
+ }
+
+ /* Do SDP Service Search Attribute Request */
+ n = sdp_search(ss, 1, &service_class, 1, bt_attrs, BT_NUM_VALUES, values);
+ if (n != 0) {
+ DPRINTF("SDP search failed\n");
+ goto done;
+ }
+ /* Print attributes values */
+ for (n = 0; n != BT_NUM_VALUES; n++) {
+ if (values[n].flags != SDP_ATTR_OK)
+ break;
+ if (values[n].attr != SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST)
+ continue;
+ psm = bt_find_psm(values[n].value, values[n].value + values[n].vlen);
+ if (psm > -1)
+ break;
+ }
+done:
+ sdp_close(ss);
+ return (psm);
+}
+
+static int
+bt_open(struct voss_backend *pbe __unused, const char *devname, int samplerate,
+ int bufsize __unused, int *pchannels, int *pformat, struct bt_config *cfg,
+ int service_class, int isSink)
+{
+ struct sockaddr_l2cap addr;
+ struct l2cap_info info;
+ socklen_t mtusize = sizeof(uint16_t);
+ int tmpbitpool;
+ int l2cap_psm;
+ int temp;
+
+ memset(&info, 0, sizeof(info));
+
+ if (strstr(devname, "/dev/bluetooth/") != devname) {
+ printf("Invalid device name '%s'", devname);
+ goto error;
+ }
+ /* skip prefix */
+ devname += sizeof("/dev/bluetooth/") - 1;
+
+ if (!bt_aton(devname, &info.raddr)) {
+ struct hostent *he = NULL;
+
+ if ((he = bt_gethostbyname(devname)) == NULL) {
+ DPRINTF("Could not get host by name\n");
+ goto error;
+ }
+ bdaddr_copy(&info.raddr, (bdaddr_t *)he->h_addr);
+ }
+ switch (samplerate) {
+ case 8000:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0x80;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 11025:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0x40;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 12000:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0x20;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 16000:
+ cfg->freq = FREQ_16K;
+ cfg->aacMode1 = 0x10;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 22050:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0x08;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 24000:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0x04;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 32000:
+ cfg->freq = FREQ_32K;
+ cfg->aacMode1 = 0x02;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 44100:
+ cfg->freq = FREQ_44_1K;
+ cfg->aacMode1 = 0x01;
+ cfg->aacMode2 = 0x0C;
+ break;
+ case 48000:
+ cfg->freq = FREQ_48K;
+ cfg->aacMode1 = 0;
+ cfg->aacMode2 = 0x8C;
+ break;
+ case 64000:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0;
+ cfg->aacMode2 = 0x4C;
+ break;
+ case 88200:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0;
+ cfg->aacMode2 = 0x2C;
+ break;
+ case 96000:
+ cfg->freq = FREQ_UNDEFINED;
+ cfg->aacMode1 = 0;
+ cfg->aacMode2 = 0x1C;
+ break;
+ default:
+ DPRINTF("Invalid samplerate %d", samplerate);
+ goto error;
+ }
+ cfg->bands = BANDS_8;
+ cfg->bitpool = 0;
+
+ switch (*pchannels) {
+ case 1:
+ cfg->aacMode2 &= 0xF8;
+ cfg->chmode = MODE_MONO;
+ break;
+ default:
+ cfg->aacMode2 &= 0xF4;
+ cfg->chmode = MODE_STEREO;
+ break;
+ }
+
+ cfg->allocm = ALLOC_LOUDNESS;
+
+ if (cfg->chmode == MODE_MONO || cfg->chmode == MODE_DUAL)
+ tmpbitpool = 16;
+ else
+ tmpbitpool = 32;
+
+ if (cfg->bands == BANDS_8)
+ tmpbitpool *= 8;
+ else
+ tmpbitpool *= 4;
+
+ if (tmpbitpool > DEFAULT_MAXBPOOL)
+ tmpbitpool = DEFAULT_MAXBPOOL;
+
+ cfg->bitpool = tmpbitpool;
+
+ if (bt_set_format(pformat)) {
+ DPRINTF("Unsupported sample format\n");
+ goto error;
+ }
+ l2cap_psm = bt_query(&info, service_class);
+ DPRINTF("PSM=0x%02x\n", l2cap_psm);
+ if (l2cap_psm < 0) {
+ DPRINTF("PSM not found\n");
+ goto error;
+ }
+ cfg->hc = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP);
+ if (cfg->hc < 0) {
+ DPRINTF("Could not create BT socket\n");
+ goto error;
+ }
+ memset(&addr, 0, sizeof(addr));
+ addr.l2cap_len = sizeof(addr);
+ addr.l2cap_family = AF_BLUETOOTH;
+ bdaddr_copy(&addr.l2cap_bdaddr, &info.laddr);
+
+ if (bind(cfg->hc, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ DPRINTF("Could not bind to HC\n");
+ goto error;
+ }
+ bdaddr_copy(&addr.l2cap_bdaddr, &info.raddr);
+ addr.l2cap_psm = l2cap_psm;
+ if (connect(cfg->hc, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ DPRINTF("Could not connect to HC: %d\n", errno);
+ goto error;
+ }
+ if (avdtpDiscoverAndConfig(cfg, isSink)) {
+ DPRINTF("DISCOVER FAILED\n");
+ goto error;
+ }
+ if (avdtpOpen(cfg->hc, cfg->sep)) {
+ DPRINTF("OPEN FAILED\n");
+ goto error;
+ }
+ cfg->fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP);
+ if (cfg->fd < 0) {
+ DPRINTF("Could not create BT socket\n");
+ goto error;
+ }
+ memset(&addr, 0, sizeof(addr));
+
+ addr.l2cap_len = sizeof(addr);
+ addr.l2cap_family = AF_BLUETOOTH;
+ bdaddr_copy(&addr.l2cap_bdaddr, &info.laddr);
+
+ if (bind(cfg->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ DPRINTF("Could not bind\n");
+ goto error;
+ }
+ bdaddr_copy(&addr.l2cap_bdaddr, &info.raddr);
+ addr.l2cap_psm = l2cap_psm;
+ if (connect(cfg->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ DPRINTF("Could not connect: %d\n", errno);
+ goto error;
+ }
+ if (isSink) {
+ if (getsockopt(cfg->fd, SOL_L2CAP, SO_L2CAP_OMTU, &cfg->mtu, &mtusize) == -1) {
+ DPRINTF("Could not get MTU\n");
+ goto error;
+ }
+ temp = cfg->mtu * 16;
+ if (setsockopt(cfg->fd, SOL_SOCKET, SO_SNDBUF, &temp, sizeof(temp)) == -1) {
+ DPRINTF("Could not set send buffer size\n");
+ goto error;
+ }
+ temp = cfg->mtu;
+ if (setsockopt(cfg->fd, SOL_SOCKET, SO_SNDLOWAT, &temp, sizeof(temp)) == -1) {
+ DPRINTF("Could not set low water mark\n");
+ goto error;
+ }
+ } else {
+ if (getsockopt(cfg->fd, SOL_L2CAP, SO_L2CAP_IMTU, &cfg->mtu, &mtusize) == -1) {
+ DPRINTF("Could not get MTU\n");
+ goto error;
+ }
+ temp = cfg->mtu * 16;
+ if (setsockopt(cfg->fd, SOL_SOCKET, SO_RCVBUF, &temp, sizeof(temp)) == -1) {
+ DPRINTF("Could not set receive buffer size\n");
+ goto error;
+ }
+ temp = 1;
+ if (setsockopt(cfg->fd, SOL_SOCKET, SO_RCVLOWAT, &temp, sizeof(temp)) == -1) {
+ DPRINTF("Could not set low water mark\n");
+ goto error;
+ }
+ temp = 1;
+ if (ioctl(cfg->fd, FIONBIO, &temp) == -1) {
+ DPRINTF("Could not set non-blocking I/O for receive direction\n");
+ goto error;
+ }
+ }
+
+ if (avdtpStart(cfg->hc, cfg->sep)) {
+ DPRINTF("START FAILED\n");
+ goto error;
+ }
+ switch (cfg->chmode) {
+ case MODE_MONO:
+ *pchannels = 1;
+ break;
+ default:
+ *pchannels = 2;
+ break;
+ }
+ return (0);
+
+error:
+ if (cfg->hc > 0) {
+ close(cfg->hc);
+ cfg->hc = -1;
+ }
+ if (cfg->fd > 0) {
+ close(cfg->fd);
+ cfg->fd = -1;
+ }
+ return (-1);
+}
+
+static void
+bt_init_cfg(struct bt_config *cfg)
+{
+ memset(cfg, 0, sizeof(*cfg));
+}
+
+static int
+bt_rec_open(struct voss_backend *pbe, const char *devname, int samplerate,
+ int bufsize, int *pchannels, int *pformat)
+{
+ struct bt_config *cfg = pbe->arg;
+ int retval;
+
+ bt_init_cfg(cfg);
+
+ retval = bt_open(pbe, devname, samplerate, bufsize, pchannels, pformat,
+ cfg, SDP_SERVICE_CLASS_AUDIO_SOURCE, 0);
+ if (retval != 0)
+ return (retval);
+ return (0);
+}
+
+static int
+bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
+ int bufsize, int *pchannels, int *pformat)
+{
+ struct bt_config *cfg = pbe->arg;
+ int retval;
+
+ bt_init_cfg(cfg);
+
+ retval = bt_open(pbe, devname, samplerate, bufsize, pchannels, pformat,
+ cfg, SDP_SERVICE_CLASS_AUDIO_SINK, 1);
+ if (retval != 0)
+ return (retval);
+
+ /* setup codec */
+ switch (cfg->codec) {
+ case CODEC_SBC:
+ cfg->handle.sbc_enc =
+ malloc(sizeof(*cfg->handle.sbc_enc));
+ if (cfg->handle.sbc_enc == NULL)
+ return (-1);
+ memset(cfg->handle.sbc_enc, 0, sizeof(*cfg->handle.sbc_enc));
+ break;
+#ifdef HAVE_LIBAV
+ case CODEC_AAC:
+ cfg->handle.av.codec = __DECONST(AVCodec *,
+ avcodec_find_encoder_by_name("aac"));
+ if (cfg->handle.av.codec == NULL) {
+ DPRINTF("Codec AAC encoder not found\n");
+ goto av_error_0;
+ }
+ cfg->handle.av.format = avformat_alloc_context();
+ if (cfg->handle.av.format == NULL) {
+ DPRINTF("Could not allocate format context\n");
+ goto av_error_0;
+ }
+ cfg->handle.av.format->oformat =
+ av_guess_format("latm", NULL, NULL);
+ if (cfg->handle.av.format->oformat == NULL) {
+ DPRINTF("Could not guess output format\n");
+ goto av_error_1;
+ }
+ cfg->handle.av.stream = avformat_new_stream(
+ cfg->handle.av.format, cfg->handle.av.codec);
+
+ if (cfg->handle.av.stream == NULL) {
+ DPRINTF("Could not create new stream\n");
+ goto av_error_1;
+ }
+ cfg->handle.av.context = avcodec_alloc_context3(cfg->handle.av.codec);
+ if (cfg->handle.av.context == NULL) {
+ DPRINTF("Could not allocate audio context\n");
+ goto av_error_1;
+ }
+ /*avcodec_get_context_defaults3(cfg->handle.av.context,*/
+ /*cfg->handle.av.codec);*/
+
+ cfg->handle.av.context->bit_rate = 128000;
+ cfg->handle.av.context->sample_fmt = AV_SAMPLE_FMT_FLTP;
+ cfg->handle.av.context->sample_rate = samplerate;
+ switch (*pchannels) {
+ case 1:
+ cfg->handle.av.context->ch_layout = *(AVChannelLayout *)AV_CH_LAYOUT_MONO;
+ break;
+ default:
+ cfg->handle.av.context->ch_layout = *(AVChannelLayout *)AV_CH_LAYOUT_STEREO;
+ break;
+ }
+
+ cfg->handle.av.context->profile = FF_PROFILE_AAC_LOW;
+ if (1) {
+ AVDictionary *opts = NULL;
+
+ av_dict_set(&opts, "strict", "-2", 0);
+ av_dict_set_int(&opts, "latm", 1, 0);
+
+ if (avcodec_open2(cfg->handle.av.context,
+ cfg->handle.av.codec, &opts) < 0) {
+ av_dict_free(&opts);
+
+ DPRINTF("Could not open codec\n");
+ goto av_error_1;
+ }
+ av_dict_free(&opts);
+ }
+ cfg->handle.av.frame = av_frame_alloc();
+ if (cfg->handle.av.frame == NULL) {
+ DPRINTF("Could not allocate audio frame\n");
+ goto av_error_2;
+ }
+ cfg->handle.av.frame->nb_samples = cfg->handle.av.context->frame_size;
+ cfg->handle.av.frame->format = cfg->handle.av.context->sample_fmt;
+ cfg->handle.av.frame->ch_layout = cfg->handle.av.context->ch_layout;
+ cfg->rem_in_size = av_samples_get_buffer_size(NULL,
+ cfg->handle.av.context->ch_layout.nb_channels,
+ cfg->handle.av.context->frame_size,
+ cfg->handle.av.context->sample_fmt, 0);
+
+ cfg->rem_in_data = av_malloc(cfg->rem_in_size);
+ if (cfg->rem_in_data == NULL) {
+ DPRINTF("Could not allocate %u bytes sample buffer\n",
+ (unsigned)cfg->rem_in_size);
+ goto av_error_3;
+ }
+ retval = avcodec_fill_audio_frame(cfg->handle.av.frame,
+ cfg->handle.av.context->ch_layout.nb_channels,
+ cfg->handle.av.context->sample_fmt,
+ cfg->rem_in_data, cfg->rem_in_size, 0);
+ if (retval < 0) {
+ DPRINTF("Could not setup audio frame\n");
+ goto av_error_4;
+ }
+ break;
+av_error_4:
+ av_free(cfg->rem_in_data);
+av_error_3:
+ av_frame_free(&cfg->handle.av.frame);
+av_error_2:
+ avcodec_close(cfg->handle.av.context);
+av_error_1:
+ avformat_free_context(cfg->handle.av.format);
+ cfg->handle.av.context = NULL;
+av_error_0:
+ bt_close(pbe);
+ return (-1);
+#endif
+ default:
+ bt_close(pbe);
+ return (-1);
+ }
+ return (0);
+}
+
+static int
+bt_rec_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ return (bt_receive(pbe->arg, ptr, len, 1));
+}
+
+static int
+bt_play_sbc_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ struct bt_config *cfg = pbe->arg;
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ int rem_size = 1;
+ int old_len = len;
+ int err = 0;
+
+ switch (cfg->blocks) {
+ case BLOCKS_4:
+ sbc->blocks = 4;
+ rem_size *= 4;
+ break;
+ case BLOCKS_8:
+ sbc->blocks = 8;
+ rem_size *= 8;
+ break;
+ case BLOCKS_12:
+ sbc->blocks = 12;
+ rem_size *= 12;
+ break;
+ default:
+ sbc->blocks = 16;
+ rem_size *= 16;
+ break;
+ }
+
+ switch (cfg->bands) {
+ case BANDS_4:
+ rem_size *= 4;
+ sbc->bands = 4;
+ break;
+ default:
+ rem_size *= 8;
+ sbc->bands = 8;
+ break;
+ }
+
+ /* store number of samples per frame */
+ sbc->framesamples = rem_size;
+
+ if (cfg->chmode != MODE_MONO) {
+ rem_size *= 2;
+ sbc->channels = 2;
+ } else {
+ sbc->channels = 1;
+ }
+
+ rem_size *= 2; /* 16-bit samples */
+
+ while (len > 0) {
+ int delta = len;
+
+ if (delta > (int)(rem_size - sbc->rem_len))
+ delta = (int)(rem_size - sbc->rem_len);
+
+ /* copy in samples */
+ memcpy((char *)sbc->music_data + sbc->rem_len, ptr, delta);
+
+ ptr = (char *)ptr + delta;
+ len -= delta;
+ sbc->rem_len += delta;
+
+ /* check if buffer is full */
+ if ((int)sbc->rem_len == rem_size) {
+ struct sbc_header *phdr = (struct sbc_header *)cfg->mtu_data;
+ uint32_t pkt_len;
+ uint32_t rem;
+
+ if (cfg->chmode == MODE_MONO)
+ sbc->channels = 1;
+ else
+ sbc->channels = 2;
+
+ pkt_len = sbc_encode_frame(cfg);
+
+ retry:
+ if (cfg->mtu_offset == 0) {
+ phdr->id = 0x80; /* RTP v2 */
+ phdr->id2 = 0x60; /* payload type 96. */
+ phdr->seqnumMSB = (uint8_t)(cfg->mtu_seqnumber >> 8);
+ phdr->seqnumLSB = (uint8_t)(cfg->mtu_seqnumber);
+ phdr->ts3 = (uint8_t)(cfg->mtu_timestamp >> 24);
+ phdr->ts2 = (uint8_t)(cfg->mtu_timestamp >> 16);
+ phdr->ts1 = (uint8_t)(cfg->mtu_timestamp >> 8);
+ phdr->ts0 = (uint8_t)(cfg->mtu_timestamp);
+ phdr->reserved0 = 0x01;
+ phdr->numFrames = 0;
+
+ cfg->mtu_seqnumber++;
+ cfg->mtu_offset += sizeof(*phdr);
+ }
+ /* compute bytes left */
+ rem = cfg->mtu - cfg->mtu_offset;
+
+ if (phdr->numFrames == 255 || rem < pkt_len) {
+ int xlen;
+
+ if (phdr->numFrames == 0)
+ return (-1);
+ do {
+ xlen = write(cfg->fd, cfg->mtu_data, cfg->mtu_offset);
+ } while (xlen < 0 && errno == EAGAIN);
+
+ if (xlen < 0)
+ return (-1);
+
+ cfg->mtu_offset = 0;
+ goto retry;
+ }
+ memcpy(cfg->mtu_data + cfg->mtu_offset, sbc->data, pkt_len);
+ memset(sbc->data, 0, pkt_len);
+ cfg->mtu_offset += pkt_len;
+ cfg->mtu_timestamp += sbc->framesamples;
+ phdr->numFrames++;
+
+ sbc->rem_len = 0;
+ }
+ }
+ if (err == 0)
+ return (old_len);
+ return (err);
+}
+
+#ifdef HAVE_LIBAV
+static int
+bt_play_aac_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ struct bt_config *cfg = pbe->arg;
+ struct aac_header {
+ uint8_t id;
+ uint8_t id2;
+ uint8_t seqnumMSB;
+ uint8_t seqnumLSB;
+ uint8_t ts3;
+ uint8_t ts2;
+ uint8_t ts1;
+ uint8_t ts0;
+ uint8_t sync3;
+ uint8_t sync2;
+ uint8_t sync1;
+ uint8_t sync0;
+ uint8_t fixed[8];
+ };
+ int old_len = len;
+ int err = 0;
+
+ while (len > 0) {
+ int delta = len;
+ int rem;
+
+ if (delta > (int)(cfg->rem_in_size - cfg->rem_in_len))
+ delta = (int)(cfg->rem_in_size - cfg->rem_in_len);
+
+ memcpy(cfg->rem_in_data + cfg->rem_in_len, ptr, delta);
+
+ ptr = (char *)ptr + delta;
+ len -= delta;
+ cfg->rem_in_len += delta;
+
+ /* check if buffer is full */
+ if (cfg->rem_in_len == cfg->rem_in_size) {
+ struct aac_header *phdr = (struct aac_header *)cfg->mtu_data;
+ AVPacket *pkt;
+ uint8_t *pkt_buf;
+ int pkt_len;
+
+ pkt = av_packet_alloc();
+ err = avcodec_send_frame(cfg->handle.av.context,
+ cfg->handle.av.frame);
+ if (err < 0) {
+ DPRINTF("Error encoding audio frame\n");
+ return (-1);
+ }
+ phdr->id = 0x80;/* RTP v2 */
+ phdr->id2 = 0x60; /* payload type 96. */
+ phdr->seqnumMSB = (uint8_t)(cfg->mtu_seqnumber >> 8);
+ phdr->seqnumLSB = (uint8_t)(cfg->mtu_seqnumber);
+ phdr->ts3 = (uint8_t)(cfg->mtu_timestamp >> 24);
+ phdr->ts2 = (uint8_t)(cfg->mtu_timestamp >> 16);
+ phdr->ts1 = (uint8_t)(cfg->mtu_timestamp >> 8);
+ phdr->ts0 = (uint8_t)(cfg->mtu_timestamp);
+ phdr->sync3 = 0;
+ phdr->sync2 = 0;
+ phdr->sync1 = 0;
+ phdr->sync0 = 0;
+ phdr->fixed[0] = 0xfc;
+ phdr->fixed[1] = 0x00;
+ phdr->fixed[2] = 0x00;
+ phdr->fixed[3] = 0xb0;
+ phdr->fixed[4] = 0x90;
+ phdr->fixed[5] = 0x80;
+ phdr->fixed[6] = 0x03;
+ phdr->fixed[7] = 0x00;
+
+ cfg->mtu_seqnumber++;
+ cfg->mtu_offset = sizeof(*phdr);
+
+ /* compute bytes left */
+ rem = cfg->mtu - cfg->mtu_offset;
+
+ if (avio_open_dyn_buf(&cfg->handle.av.format->pb) == 0) {
+ static int once = 0;
+
+ if (!once++)
+ (void)avformat_write_header(cfg->handle.av.format, NULL);
+ av_write_frame(cfg->handle.av.format, pkt);
+ av_packet_unref(pkt);
+ pkt_len = avio_close_dyn_buf(cfg->handle.av.format->pb, &pkt_buf);
+ if (rem < pkt_len)
+ DPRINTF("Out of buffer space\n");
+ if (pkt_len >= 3 && rem >= pkt_len) {
+ int xlen;
+
+ memcpy(cfg->mtu_data + cfg->mtu_offset, pkt_buf + 3, pkt_len - 3);
+
+ av_free(pkt_buf);
+
+ cfg->mtu_offset += pkt_len - 3;
+ if (cfg->chmode != MODE_MONO)
+ cfg->mtu_timestamp += cfg->rem_in_size / 4;
+ else
+ cfg->mtu_timestamp += cfg->rem_in_size / 2;
+ do {
+ xlen = write(cfg->fd, cfg->mtu_data, cfg->mtu_offset);
+ } while (xlen < 0 && errno == EAGAIN);
+
+ if (xlen < 0)
+ return (-1);
+ } else {
+ av_free(pkt_buf);
+ }
+ } else {
+ av_packet_unref(pkt);
+ }
+ /* reset remaining length */
+ cfg->rem_in_len = 0;
+ }
+ }
+ if (err == 0)
+ return (old_len);
+ return (err);
+}
+
+#endif
+
+static int
+bt_play_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ struct bt_config *cfg = pbe->arg;
+
+ switch (cfg->codec) {
+ case CODEC_SBC:
+ return (bt_play_sbc_transfer(pbe, ptr, len));
+#ifdef HAVE_LIBAV
+ case CODEC_AAC:
+ return (bt_play_aac_transfer(pbe, ptr, len));
+#endif
+ default:
+ return (-1);
+ }
+}
+
+static void
+bt_rec_delay(struct voss_backend *pbe __unused, int *pdelay)
+{
+ *pdelay = -1;
+}
+
+static void
+bt_play_delay(struct voss_backend *pbe __unused, int *pdelay)
+{
+ /* TODO */
+ *pdelay = -1;
+}
+
+struct voss_backend voss_backend_bt_rec = {
+ .open = bt_rec_open,
+ .close = bt_rec_close,
+ .transfer = bt_rec_transfer,
+ .delay = bt_rec_delay,
+ .arg = &bt_rec_cfg,
+};
+
+struct voss_backend voss_backend_bt_play = {
+ .open = bt_play_open,
+ .close = bt_play_close,
+ .transfer = bt_play_transfer,
+ .delay = bt_play_delay,
+ .arg = &bt_play_cfg,
+};
diff --git a/lib/virtual_oss/bt/bt.h b/lib/virtual_oss/bt/bt.h
new file mode 100644
index 000000000000..2abdb9eb021a
--- /dev/null
+++ b/lib/virtual_oss/bt/bt.h
@@ -0,0 +1,116 @@
+/*-
+ * Copyright (c) 2015 Hans Petter Selasky
+ *
+ * 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.
+ */
+
+#ifndef _BACKEND_BT_H_
+#define _BACKEND_BT_H_
+
+#ifdef HAVE_LIBAV
+#include <libavformat/avformat.h>
+#include <libavcodec/avcodec.h>
+#include <libavutil/opt.h>
+#endif
+
+#include "sbc_encode.h"
+
+struct bt_config {
+ uint8_t sep; /* SEID of the peer */
+ uint8_t media_Type;
+ uint8_t chmode;
+#define MODE_STEREO 2
+#define MODE_JOINT 3
+#define MODE_DUAL 1
+#define MODE_MONO 0
+ uint8_t allocm;
+#define ALLOC_LOUDNESS 0
+#define ALLOC_SNR 1
+ uint8_t bitpool;
+ uint8_t bands;
+#define BANDS_4 0
+#define BANDS_8 1
+ uint8_t blocks;
+#define BLOCKS_4 0
+#define BLOCKS_8 1
+#define BLOCKS_12 2
+#define BLOCKS_16 3
+ uint8_t freq;
+#define FREQ_UNDEFINED 255
+#define FREQ_16K 0
+#define FREQ_32K 1
+#define FREQ_44_1K 2
+#define FREQ_48K 3
+ uint16_t mtu;
+ uint8_t codec;
+#define CODEC_SBC 0x00
+#define CODEC_AAC 0x02
+ uint8_t aacMode1;
+ uint8_t aacMode2;
+
+ /* transcoding handle(s) */
+ union {
+#ifdef HAVE_LIBAV
+ struct {
+ AVCodec *codec;
+ AVCodecContext *context;
+ AVFormatContext *format;
+ AVFrame *frame;
+ AVStream *stream;
+ } av;
+#endif
+ struct sbc_encode *sbc_enc;
+ } handle;
+
+ /* audio input buffer */
+ uint32_t rem_in_len;
+ uint32_t rem_in_size;
+ uint8_t *rem_in_data;
+
+ /* data transport */
+ uint32_t mtu_seqnumber;
+ uint32_t mtu_timestamp;
+ uint32_t mtu_offset;
+
+ /* bluetooth file handles */
+ int fd;
+ int hc;
+
+ /* scratch buffer */
+ uint8_t mtu_data[65536];
+
+ /* acceptor state */
+ int8_t acceptor_state;
+#define acpInitial 1
+#define acpConfigurationSet 2
+#define acpStreamOpened 3
+#define acpStreamStarted 4
+#define acpStreamSuspended 5
+#define acpStreamClosed 6
+};
+
+size_t sbc_encode_frame(struct bt_config *);
+size_t sbc_decode_frame(struct bt_config *, int);
+
+int bt_receive(struct bt_config *cfg, void *ptr, int len, int use_delay);
+
+#endif /* _BACKEND_BT_H_ */
diff --git a/lib/virtual_oss/bt/cosdata-gen/Makefile b/lib/virtual_oss/bt/cosdata-gen/Makefile
new file mode 100644
index 000000000000..d08e263f32b5
--- /dev/null
+++ b/lib/virtual_oss/bt/cosdata-gen/Makefile
@@ -0,0 +1,12 @@
+# $NetBSD$
+
+WARNS?= 3
+
+PROG= cosdata
+SRCS= cosdata.c
+MAN=
+
+DPADD+= ${LIBMATH}
+LDADD+= -lm
+
+.include <bsd.prog.mk>
diff --git a/lib/virtual_oss/bt/cosdata-gen/cosdata.c b/lib/virtual_oss/bt/cosdata-gen/cosdata.c
new file mode 100644
index 000000000000..b8409cbd0216
--- /dev/null
+++ b/lib/virtual_oss/bt/cosdata-gen/cosdata.c
@@ -0,0 +1,177 @@
+/*-
+ * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
+ * All rights reserved.
+ *
+ * This software is dedicated to the memory of -
+ * Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
+ *
+ * Barry was a man who loved his music.
+ *
+ * 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 <math.h>
+#include <stdio.h>
+#include <stdint.h>
+
+static const double sbc8_coeffs[] = {
+ 0.00000000e+00, 1.56575398e-04, 3.43256425e-04, 5.54620202e-04,
+ 8.23919506e-04, 1.13992507e-03, 1.47640169e-03, 1.78371725e-03,
+ 2.01182542e-03, 2.10371989e-03, 1.99454554e-03, 1.61656283e-03,
+ 9.02154502e-04, -1.78805361e-04, -1.64973098e-03, -3.49717454e-03,
+ 5.65949473e-03, 8.02941163e-03, 1.04584443e-02, 1.27472335e-02,
+ 1.46525263e-02, 1.59045603e-02, 1.62208471e-02, 1.53184106e-02,
+ 1.29371806e-02, 8.85757540e-03, 2.92408442e-03, -4.91578024e-03,
+ -1.46404076e-02, -2.61098752e-02, -3.90751381e-02, -5.31873032e-02,
+ 6.79989431e-02, 8.29847578e-02, 9.75753918e-02, 1.11196689e-01,
+ 1.23264548e-01, 1.33264415e-01, 1.40753505e-01, 1.45389847e-01,
+ 1.46955068e-01, 1.45389847e-01, 1.40753505e-01, 1.33264415e-01,
+ 1.23264548e-01, 1.11196689e-01, 9.75753918e-02, 8.29847578e-02,
+ -6.79989431e-02, -5.31873032e-02, -3.90751381e-02, -2.61098752e-02,
+ -1.46404076e-02, -4.91578024e-03, 2.92408442e-03, 8.85757540e-03,
+ 1.29371806e-02, 1.53184106e-02, 1.62208471e-02, 1.59045603e-02,
+ 1.46525263e-02, 1.27472335e-02, 1.04584443e-02, 8.02941163e-03,
+ -5.65949473e-03, -3.49717454e-03, -1.64973098e-03, -1.78805361e-04,
+ 9.02154502e-04, 1.61656283e-03, 1.99454554e-03, 2.10371989e-03,
+ 2.01182542e-03, 1.78371725e-03, 1.47640169e-03, 1.13992507e-03,
+ 8.23919506e-04, 5.54620202e-04, 3.43256425e-04, 1.56575398e-04,
+};
+
+static const double sbc4_coeffs[] = {
+ 0.00000000e+00, 5.36548976e-04, 1.49188357e-03, 2.73370904e-03,
+ 3.83720193e-03, 3.89205149e-03, 1.86581691e-03, -3.06012286e-03,
+ 1.09137620e-02, 2.04385087e-02, 2.88757392e-02, 3.21939290e-02,
+ 2.58767811e-02, 6.13245186e-03, -2.88217274e-02, -7.76463494e-02,
+ 1.35593274e-01, 1.94987841e-01, 2.46636662e-01, 2.81828203e-01,
+ 2.94315332e-01, 2.81828203e-01, 2.46636662e-01, 1.94987841e-01,
+ -1.35593274e-01, -7.76463494e-02, -2.88217274e-02, 6.13245186e-03,
+ 2.58767811e-02, 3.21939290e-02, 2.88757392e-02, 2.04385087e-02,
+ -1.09137620e-02, -3.06012286e-03, 1.86581691e-03, 3.89205149e-03,
+ 3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04,
+};
+
+#define AC(x) (int)(sizeof(x) / sizeof((x)[0]))
+
+int
+main(int argc, char **argv)
+{
+ float S[8][16];
+ int i;
+ int k;
+ int count = 0;
+
+ printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n"
+ "\n");
+
+ printf("static const float sbc_coeffs8[] = {\n ");
+ for (k = 0; k < AC(sbc8_coeffs); k++) {
+ if ((count % 8) == 0 && count != 0)
+ printf("\n ");
+ printf("%0.12ff, ", (float)sbc8_coeffs[k]);
+ count++;
+ }
+ printf("\n};\n");
+
+ count = 0;
+ printf("static const float sbc_coeffs4[] = {\n ");
+ for (k = 0; k < AC(sbc4_coeffs); k++) {
+ if ((count % 8) == 0 && count != 0)
+ printf("\n ");
+ printf("%0.12ff, ", (float)sbc4_coeffs[k]);
+ count++;
+ }
+ printf("\n};\n");
+
+ count = 0;
+ printf("static const float cosdata8[8][16] = {\n ");
+ for (i = 0; i < 8; i++) {
+ for (k = 0; k < 16; k++) {
+ S[i][k] = cosf((float)((i + 0.5) * (k - 4) * (M_PI / 8.0)));
+
+ if ((count % 8) == 0 && count != 0)
+ printf("\n ");
+ if (k == 0)
+ printf("{ ");
+ printf("%0.12ff, ", S[i][k]);
+ if (k == 15)
+ printf("},");
+ count++;
+ }
+ }
+ printf("\n};\n");
+
+ count = 0;
+ printf("static const float cosdata4[4][8] = {\n ");
+ for (i = 0; i < 4; i++) {
+ for (k = 0; k < 8; k++) {
+ S[i][k] = cosf((float)((i + 0.5) * (k - 2) * (M_PI / 4.0)));
+
+ if ((count % 8) == 0 && count != 0)
+ printf("\n ");
+ if (k == 0)
+ printf("{ ");
+ printf("%0.12ff, ", S[i][k]);
+ if (k == 7)
+ printf("},");
+ count++;
+ }
+ }
+ printf("\n};\n");
+
+ count = 0;
+ printf("static const float cosdecdata8[8][16] = {\n ");
+ for (i = 0; i < 8; i++) {
+ for (k = 0; k < 16; k++) {
+ S[i][k] = cosf((float)((i + 0.5) * (k + 4) * (M_PI / 8.0)));
+
+ if ((count % 8) == 0 && count != 0)
+ printf("\n ");
+ if (k == 0)
+ printf("{ ");
+ printf("%0.12ff, ", S[i][k]);
+ if (k == 15)
+ printf("},");
+ count++;
+ }
+ }
+ printf("\n};\n");
+
+ count = 0;
+ printf("static const float cosdecdata4[4][8] = {\n ");
+ for (i = 0; i < 4; i++) {
+ for (k = 0; k < 8; k++) {
+ S[i][k] = cosf((float)((i + 0.5) * (k + 2) * (M_PI / 4.0)));
+
+ if ((count % 8) == 0 && count != 0)
+ printf("\n ");
+ if (k == 0)
+ printf("{ ");
+ printf("%0.12ff, ", S[i][k]);
+ if (k == 7)
+ printf("},");
+ count++;
+ }
+ }
+ printf("\n};\n");
+
+ return (0);
+}
diff --git a/lib/virtual_oss/bt/sbc_coeffs.h b/lib/virtual_oss/bt/sbc_coeffs.h
new file mode 100644
index 000000000000..b9428033d50b
--- /dev/null
+++ b/lib/virtual_oss/bt/sbc_coeffs.h
@@ -0,0 +1,69 @@
+/* sbc_coeffs.h - Automatically generated by cosdata.c. */
+
+static const float sbc_coeffs8[] = {
+ 0.000000000000f, 0.000156575392f, 0.000343256426f, 0.000554620230f, 0.000823919487f, 0.001139925094f, 0.001476401696f, 0.001783717307f,
+ 0.002011825331f, 0.002103719860f, 0.001994545572f, 0.001616562833f, 0.000902154483f, -0.000178805363f, -0.001649730955f, -0.003497174475f,
+ 0.005659494549f, 0.008029411547f, 0.010458444245f, 0.012747233734f, 0.014652526006f, 0.015904560685f, 0.016220847145f, 0.015318410471f,
+ 0.012937180698f, 0.008857575245f, 0.002924084431f, -0.004915780388f, -0.014640407637f, -0.026109876111f, -0.039075139910f, -0.053187303245f,
+ 0.067998945713f, 0.082984760404f, 0.097575388849f, 0.111196689308f, 0.123264551163f, 0.133264422417f, 0.140753507614f, 0.145389840007f,
+ 0.146955072880f, 0.145389840007f, 0.140753507614f, 0.133264422417f, 0.123264551163f, 0.111196689308f, 0.097575388849f, 0.082984760404f,
+ -0.067998945713f, -0.053187303245f, -0.039075139910f, -0.026109876111f, -0.014640407637f, -0.004915780388f, 0.002924084431f, 0.008857575245f,
+ 0.012937180698f, 0.015318410471f, 0.016220847145f, 0.015904560685f, 0.014652526006f, 0.012747233734f, 0.010458444245f, 0.008029411547f,
+ -0.005659494549f, -0.003497174475f, -0.001649730955f, -0.000178805363f, 0.000902154483f, 0.001616562833f, 0.001994545572f, 0.002103719860f,
+ 0.002011825331f, 0.001783717307f, 0.001476401696f, 0.001139925094f, 0.000823919487f, 0.000554620230f, 0.000343256426f, 0.000156575392f,
+};
+static const float sbc_coeffs4[] = {
+ 0.000000000000f, 0.000536548963f, 0.001491883537f, 0.002733709058f, 0.003837201977f, 0.003892051522f, 0.001865816885f, -0.003060122952f,
+ 0.010913762264f, 0.020438509062f, 0.028875738382f, 0.032193928957f, 0.025876780972f, 0.006132451817f, -0.028821727261f, -0.077646352351f,
+ 0.135593280196f, 0.194987848401f, 0.246636658907f, 0.281828194857f, 0.294315338135f, 0.281828194857f, 0.246636658907f, 0.194987848401f,
+ -0.135593280196f, -0.077646352351f, -0.028821727261f, 0.006132451817f, 0.025876780972f, 0.032193928957f, 0.028875738382f, 0.020438509062f,
+ -0.010913762264f, -0.003060122952f, 0.001865816885f, 0.003892051522f, 0.003837201977f, 0.002733709058f, 0.001491883537f, 0.000536548963f,
+};
+static const float cosdata8[8][16] = {
+ { 0.707106769085f, 0.831469595432f, 0.923879504204f, 0.980785250664f, 1.000000000000f, 0.980785250664f, 0.923879504204f, 0.831469595432f,
+ 0.707106769085f, 0.555570244789f, 0.382683426142f, 0.195090353489f, -0.000000043711f, -0.195090323687f, -0.382683396339f, -0.555570185184f, },
+ { -0.707106769085f, -0.195090323687f, 0.382683426142f, 0.831469595432f, 1.000000000000f, 0.831469595432f, 0.382683426142f, -0.195090323687f,
+ -0.707106769085f, -0.980785310268f, -0.923879504204f, -0.555570423603f, 0.000000011925f, 0.555570065975f, 0.923879563808f, 0.980785310268f, },
+ { -0.707106828690f, -0.980785310268f, -0.382683396339f, 0.555570244789f, 1.000000000000f, 0.555570244789f, -0.382683396339f, -0.980785310268f,
+ -0.707106828690f, 0.195090413094f, 0.923879563808f, 0.831469655037f, 0.000000139071f, -0.831469774246f, -0.923879444599f, -0.195090219378f, },
+ { 0.707106649876f, -0.555570423603f, -0.923879504204f, 0.195090353489f, 1.000000000000f, 0.195090353489f, -0.923879504204f, -0.555570423603f,
+ 0.707106649876f, 0.831469655037f, -0.382683008909f, -0.980785369873f, -0.000000290067f, 0.980785250664f, 0.382683545351f, -0.831469595432f, },
+ { 0.707106769085f, 0.555570065975f, -0.923879504204f, -0.195090323687f, 1.000000000000f, -0.195090323687f, -0.923879504204f, 0.555570065975f,
+ 0.707106769085f, -0.831469774246f, -0.382683843374f, 0.980785250664f, -0.000000035775f, -0.980785250664f, 0.382683902979f, 0.831469714642f, },
+ { -0.707106590271f, 0.980785310268f, -0.382683575153f, -0.555570185184f, 1.000000000000f, -0.555570185184f, -0.382683575153f, 0.980785310268f,
+ -0.707106590271f, -0.195090219378f, 0.923879683018f, -0.831469595432f, -0.000000592058f, 0.831469714642f, -0.923879623413f, 0.195090919733f, },
+ { -0.707106530666f, 0.195090532303f, 0.382683604956f, -0.831469655037f, 1.000000000000f, -0.831469655037f, 0.382683604956f, 0.195090532303f,
+ -0.707106530666f, 0.980785310268f, -0.923879384995f, 0.555569529533f, -0.000000687457f, -0.555570006371f, 0.923879563808f, -0.980785191059f, },
+ { 0.707106828690f, -0.831469774246f, 0.923879563808f, -0.980785310268f, 1.000000000000f, -0.980785310268f, 0.923879563808f, -0.831469774246f,
+ 0.707106828690f, -0.555570065975f, 0.382683902979f, -0.195089668036f, 0.000000059624f, 0.195089548826f, -0.382683813572f, 0.555569946766f, },
+};
+static const float cosdata4[4][8] = {
+ { 0.707106769085f, 0.923879504204f, 1.000000000000f, 0.923879504204f, 0.707106769085f, 0.382683426142f, -0.000000043711f, -0.382683396339f, },
+ { -0.707106769085f, 0.382683426142f, 1.000000000000f, 0.382683426142f, -0.707106769085f, -0.923879504204f, 0.000000011925f, 0.923879563808f, },
+ { -0.707106828690f, -0.382683396339f, 1.000000000000f, -0.382683396339f, -0.707106828690f, 0.923879563808f, 0.000000139071f, -0.923879444599f, },
+ { 0.707106649876f, -0.923879504204f, 1.000000000000f, -0.923879504204f, 0.707106649876f, -0.382683008909f, -0.000000290067f, 0.382683545351f, },
+};
+static const float cosdecdata8[8][16] = {
+ { 0.707106769085f, 0.555570244789f, 0.382683426142f, 0.195090353489f, -0.000000043711f, -0.195090323687f, -0.382683396339f, -0.555570185184f,
+ -0.707106769085f, -0.831469655037f, -0.923879504204f, -0.980785310268f, -1.000000000000f, -0.980785310268f, -0.923879504204f, -0.831469535828f, },
+ { -0.707106769085f, -0.980785310268f, -0.923879504204f, -0.555570423603f, 0.000000011925f, 0.555570065975f, 0.923879563808f, 0.980785310268f,
+ 0.707106769085f, 0.195090532303f, -0.382683008909f, -0.831469774246f, -1.000000000000f, -0.831469714642f, -0.382683843374f, 0.195090577006f, },
+ { -0.707106828690f, 0.195090413094f, 0.923879563808f, 0.831469655037f, 0.000000139071f, -0.831469774246f, -0.923879444599f, -0.195090219378f,
+ 0.707106828690f, 0.980785310268f, 0.382683545351f, -0.555570065975f, -1.000000000000f, -0.555570542812f, 0.382683902979f, 0.980785191059f, },
+ { 0.707106649876f, 0.831469655037f, -0.382683008909f, -0.980785369873f, -0.000000290067f, 0.980785250664f, 0.382683545351f, -0.831469595432f,
+ -0.707107424736f, 0.555569529533f, 0.923879802227f, -0.195089668036f, -1.000000000000f, -0.195090815425f, 0.923879384995f, 0.555570483208f, },
+ { 0.707106769085f, -0.831469774246f, -0.382683843374f, 0.980785250664f, -0.000000035775f, -0.980785250664f, 0.382683902979f, 0.831469714642f,
+ -0.707106173038f, -0.555570006371f, 0.923879384995f, 0.195089548826f, -1.000000000000f, 0.195089697838f, 0.923879325390f, -0.555570125580f, },
+ { -0.707106590271f, -0.195090219378f, 0.923879683018f, -0.831469595432f, -0.000000592058f, 0.831469714642f, -0.923879623413f, 0.195090919733f,
+ 0.707107424736f, -0.980785191059f, 0.382683366537f, 0.555569946766f, -1.000000000000f, 0.555571198463f, 0.382683783770f, -0.980785667896f, },
+ { -0.707106530666f, 0.980785310268f, -0.923879384995f, 0.555569529533f, -0.000000687457f, -0.555570006371f, 0.923879563808f, -0.980785191059f,
+ 0.707106173038f, -0.195089071989f, -0.382684975863f, 0.831468641758f, -1.000000000000f, 0.831470131874f, -0.382683992386f, -0.195090129972f, },
+ { 0.707106828690f, -0.555570065975f, 0.382683902979f, -0.195089668036f, 0.000000059624f, 0.195089548826f, -0.382683813572f, 0.555569946766f,
+ -0.707106053829f, 0.831468641758f, -0.923880040646f, 0.980785369873f, -1.000000000000f, 0.980785429478f, -0.923880159855f, 0.831468760967f, },
+};
+static const float cosdecdata4[4][8] = {
+ { 0.707106769085f, 0.382683426142f, -0.000000043711f, -0.382683396339f, -0.707106769085f, -0.923879504204f, -1.000000000000f, -0.923879504204f, },
+ { -0.707106769085f, -0.923879504204f, 0.000000011925f, 0.923879563808f, 0.707106769085f, -0.382683008909f, -1.000000000000f, -0.382683843374f, },
+ { -0.707106828690f, 0.923879563808f, 0.000000139071f, -0.923879444599f, 0.707106828690f, 0.382683545351f, -1.000000000000f, 0.382683902979f, },
+ { 0.707106649876f, -0.382683008909f, -0.000000290067f, 0.382683545351f, -0.707107424736f, 0.923879802227f, -1.000000000000f, 0.923879384995f, },
+};
diff --git a/lib/virtual_oss/bt/sbc_encode.c b/lib/virtual_oss/bt/sbc_encode.c
new file mode 100644
index 000000000000..153f2e69e76e
--- /dev/null
+++ b/lib/virtual_oss/bt/sbc_encode.c
@@ -0,0 +1,701 @@
+/*-
+ * Copyright (c) 2015 Nathanial Sloss <nathanialsloss@yahoo.com.au>
+ *
+ * This software is dedicated to the memory of -
+ * Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
+ *
+ * Barry was a man who loved his music.
+ *
+ * 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 <sys/types.h>
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <sys/uio.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <math.h>
+
+#include "sbc_coeffs.h"
+#include "bt.h"
+
+#define SYNCWORD 0x9c
+#define ABS(x) (((x) < 0) ? -(x) : (x))
+#define BIT30 (1U << 30)
+#define BM(x) ((1LL << (x)) - 1LL)
+
+/* Loudness offset allocations. */
+static const int loudnessoffset8[4][8] = {
+ {-2, 0, 0, 0, 0, 0, 0, 1},
+ {-3, 0, 0, 0, 0, 0, 1, 2},
+ {-4, 0, 0, 0, 0, 0, 1, 2},
+ {-4, 0, 0, 0, 0, 0, 1, 2},
+};
+
+static const int loudnessoffset4[4][4] = {
+ {-1, 0, 0, 0},
+ {-2, 0, 0, 1},
+ {-2, 0, 0, 1},
+ {-2, 0, 0, 1},
+};
+
+static uint8_t
+calc_scalefactors_joint(struct sbc_encode *sbc)
+{
+ float sb_j[16][2];
+ uint32_t x;
+ uint32_t y;
+ uint8_t block;
+ uint8_t joint;
+ uint8_t sb;
+ uint8_t lz;
+
+ joint = 0;
+ for (sb = 0; sb != sbc->bands - 1; sb++) {
+ for (block = 0; block < sbc->blocks; block++) {
+ sb_j[block][0] = (sbc->samples[block][0][sb] +
+ sbc->samples[block][1][sb]) / 2.0f;
+ sb_j[block][1] = (sbc->samples[block][0][sb] -
+ sbc->samples[block][1][sb]) / 2.0f;
+ }
+
+ x = 1 << 15;
+ y = 1 << 15;
+ for (block = 0; block < sbc->blocks; block++) {
+ x |= (uint32_t)ABS(sb_j[block][0]);
+ y |= (uint32_t)ABS(sb_j[block][1]);
+ }
+
+ lz = 1;
+ while (!(x & BIT30)) {
+ lz++;
+ x <<= 1;
+ }
+ x = 16 - lz;
+
+ lz = 1;
+ while (!(y & BIT30)) {
+ lz++;
+ y <<= 1;
+ }
+ y = 16 - lz;
+
+ if ((sbc->scalefactor[0][sb] + sbc->scalefactor[1][sb]) > x + y) {
+ joint |= 1 << (sbc->bands - sb - 1);
+ sbc->scalefactor[0][sb] = x;
+ sbc->scalefactor[1][sb] = y;
+ for (block = 0; block < sbc->blocks; block++) {
+ sbc->samples[block][0][sb] = sb_j[block][0];
+ sbc->samples[block][1][sb] = sb_j[block][1];
+ }
+ }
+ }
+ return (joint);
+}
+
+static void
+calc_scalefactors(struct sbc_encode *sbc)
+{
+ uint8_t block;
+ uint8_t ch;
+ uint8_t sb;
+
+ for (ch = 0; ch != sbc->channels; ch++) {
+ for (sb = 0; sb != sbc->bands; sb++) {
+ uint32_t x = 1 << 15;
+ uint8_t lx = 1;
+
+ for (block = 0; block != sbc->blocks; block++)
+ x |= (uint32_t)ABS(sbc->samples[block][ch][sb]);
+
+ while (!(x & BIT30)) {
+ lx++;
+ x <<= 1;
+ }
+ sbc->scalefactor[ch][sb] = 16 - lx;
+ }
+ }
+}
+
+static void
+calc_bitneed(struct bt_config *cfg)
+{
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ int32_t bitneed[2][8];
+ int32_t max_bitneed, bitcount;
+ int32_t slicecount, bitslice;
+ int32_t loudness;
+ int ch, sb, start_chan = 0;
+
+ if (cfg->chmode == MODE_DUAL)
+ sbc->channels = 1;
+
+next_chan:
+ max_bitneed = 0;
+ bitcount = 0;
+ slicecount = 0;
+
+ if (cfg->allocm == ALLOC_SNR) {
+ for (ch = start_chan; ch < sbc->channels; ch++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ bitneed[ch][sb] = sbc->scalefactor[ch][sb];
+
+ if (bitneed[ch][sb] > max_bitneed)
+ max_bitneed = bitneed[ch][sb];
+ }
+ }
+ } else {
+ for (ch = start_chan; ch < sbc->channels; ch++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->scalefactor[ch][sb] == 0) {
+ bitneed[ch][sb] = -5;
+ } else {
+ if (sbc->bands == 8) {
+ loudness = sbc->scalefactor[ch][sb] -
+ loudnessoffset8[cfg->freq][sb];
+ } else {
+ loudness = sbc->scalefactor[ch][sb] -
+ loudnessoffset4[cfg->freq][sb];
+ }
+ if (loudness > 0)
+ bitneed[ch][sb] = loudness / 2;
+ else
+ bitneed[ch][sb] = loudness;
+ }
+ if (bitneed[ch][sb] > max_bitneed)
+ max_bitneed = bitneed[ch][sb];
+ }
+ }
+ }
+
+ slicecount = bitcount = 0;
+ bitslice = max_bitneed + 1;
+ do {
+ bitslice--;
+ bitcount += slicecount;
+ slicecount = 0;
+ for (ch = start_chan; ch < sbc->channels; ch++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if ((bitneed[ch][sb] > bitslice + 1) &&
+ (bitneed[ch][sb] < bitslice + 16))
+ slicecount++;
+ else if (bitneed[ch][sb] == bitslice + 1)
+ slicecount += 2;
+ }
+ }
+ } while (bitcount + slicecount < cfg->bitpool);
+
+ /* check if exactly one more fits */
+ if (bitcount + slicecount == cfg->bitpool) {
+ bitcount += slicecount;
+ bitslice--;
+ }
+ for (ch = start_chan; ch < sbc->channels; ch++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (bitneed[ch][sb] < bitslice + 2) {
+ sbc->bits[ch][sb] = 0;
+ } else {
+ sbc->bits[ch][sb] = bitneed[ch][sb] - bitslice;
+ if (sbc->bits[ch][sb] > 16)
+ sbc->bits[ch][sb] = 16;
+ }
+ }
+ }
+
+ if (cfg->chmode == MODE_DUAL)
+ ch = start_chan;
+ else
+ ch = 0;
+ sb = 0;
+ while (bitcount < cfg->bitpool && sb < sbc->bands) {
+ if ((sbc->bits[ch][sb] >= 2) && (sbc->bits[ch][sb] < 16)) {
+ sbc->bits[ch][sb]++;
+ bitcount++;
+ } else if ((bitneed[ch][sb] == bitslice + 1) &&
+ (cfg->bitpool > bitcount + 1)) {
+ sbc->bits[ch][sb] = 2;
+ bitcount += 2;
+ }
+ if (sbc->channels == 1 || start_chan == 1)
+ sb++;
+ else if (ch == 1) {
+ ch = 0;
+ sb++;
+ } else
+ ch = 1;
+ }
+
+ if (cfg->chmode == MODE_DUAL)
+ ch = start_chan;
+ else
+ ch = 0;
+ sb = 0;
+ while (bitcount < cfg->bitpool && sb < sbc->bands) {
+ if (sbc->bits[ch][sb] < 16) {
+ sbc->bits[ch][sb]++;
+ bitcount++;
+ }
+ if (sbc->channels == 1 || start_chan == 1)
+ sb++;
+ else if (ch == 1) {
+ ch = 0;
+ sb++;
+ } else
+ ch = 1;
+ }
+
+ if (cfg->chmode == MODE_DUAL && start_chan == 0) {
+ start_chan = 1;
+ sbc->channels = 2;
+ goto next_chan;
+ }
+}
+
+static void
+sbc_store_bits_crc(struct sbc_encode *sbc, uint32_t numbits, uint32_t value)
+{
+ uint32_t off = sbc->bitoffset;
+
+ while (numbits-- && off != sbc->maxoffset) {
+ if (value & (1 << numbits)) {
+ sbc->data[off / 8] |= 1 << ((7 - off) & 7);
+ sbc->crc ^= 0x80;
+ }
+ sbc->crc *= 2;
+ if (sbc->crc & 0x100)
+ sbc->crc ^= 0x11d; /* CRC-8 polynomial */
+
+ off++;
+ }
+ sbc->bitoffset = off;
+}
+
+static int
+sbc_encode(struct bt_config *cfg)
+{
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ const int16_t *input = sbc->music_data;
+ float delta[2][8];
+ float levels[2][8];
+ float mask[2][8];
+ float S;
+ float *X;
+ float Z[80];
+ float Y[80];
+ float audioout;
+ int16_t left[8];
+ int16_t right[8];
+ int16_t *data;
+ int numsamples;
+ int i;
+ int k;
+ int block;
+ int chan;
+ int sb;
+
+ for (block = 0; block < sbc->blocks; block++) {
+
+ for (i = 0; i < sbc->bands; i++) {
+ left[i] = *input++;
+ if (sbc->channels == 2)
+ right[i] = *input++;
+ }
+
+ for (chan = 0; chan < sbc->channels; chan++) {
+
+ /* select right or left channel */
+ if (chan == 0) {
+ X = sbc->left;
+ data = left;
+ } else {
+ X = sbc->right;
+ data = right;
+ }
+
+ /* shift up old data */
+ for (i = (sbc->bands * 10) - 1; i > sbc->bands - 1; i--)
+ X[i] = X[i - sbc->bands];
+ k = 0;
+ for (i = sbc->bands - 1; i >= 0; i--)
+ X[i] = data[k++];
+ for (i = 0; i < sbc->bands * 10; i++) {
+ if (sbc->bands == 8)
+ Z[i] = sbc_coeffs8[i] * X[i];
+ else
+ Z[i] = sbc_coeffs4[i] * X[i];
+ }
+ for (i = 0; i < sbc->bands * 2; i++) {
+ Y[i] = 0;
+ for (k = 0; k < 5; k++)
+ Y[i] += Z[i + k * sbc->bands * 2];
+ }
+ for (i = 0; i < sbc->bands; i++) {
+ S = 0;
+ for (k = 0; k < sbc->bands * 2; k++) {
+ if (sbc->bands == 8) {
+ S += cosdata8[i][k] * Y[k];
+ } else {
+ S += cosdata4[i][k] * Y[k];
+ }
+ }
+ sbc->samples[block][chan][i] = S * (1 << 15);
+ }
+ }
+ }
+
+ calc_scalefactors(sbc);
+
+ if (cfg->chmode == MODE_JOINT)
+ sbc->join = calc_scalefactors_joint(sbc);
+ else
+ sbc->join = 0;
+
+ calc_bitneed(cfg);
+
+ for (chan = 0; chan < sbc->channels; chan++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->bits[chan][sb] == 0)
+ continue;
+ mask[chan][sb] = BM(sbc->bits[chan][sb]);
+ levels[chan][sb] = mask[chan][sb] *
+ (1LL << (15 - sbc->scalefactor[chan][sb]));
+ delta[chan][sb] =
+ (1LL << (sbc->scalefactor[chan][sb] + 16));
+ }
+ }
+
+ numsamples = 0;
+ for (block = 0; block < sbc->blocks; block++) {
+ for (chan = 0; chan < sbc->channels; chan++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->bits[chan][sb] == 0)
+ continue;
+ audioout = (levels[chan][sb] *
+ (delta[chan][sb] + sbc->samples[block][chan][sb]));
+ audioout /= (1LL << 32);
+
+ audioout = roundf(audioout);
+
+ /* range check */
+ if (audioout > mask[chan][sb])
+ audioout = mask[chan][sb];
+
+ sbc->output[numsamples++] = audioout;
+ }
+ }
+ }
+ return (numsamples);
+}
+
+static void
+sbc_decode(struct bt_config *cfg)
+{
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ float delta[2][8];
+ float levels[2][8];
+ float audioout;
+ float *X;
+ float *V;
+ float left[160];
+ float right[160];
+ float U[160];
+ float W[160];
+ float S[8];
+ int position;
+ int block;
+ int chan;
+ int sb;
+ int i;
+ int k;
+
+ for (chan = 0; chan < sbc->channels; chan++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ levels[chan][sb] = (1 << sbc->bits[chan][sb]) - 1;
+ delta[chan][sb] = (1 << sbc->scalefactor[chan][sb]);
+ }
+ }
+
+ i = 0;
+ for (block = 0; block < sbc->blocks; block++) {
+ for (chan = 0; chan < sbc->channels; chan++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->bits[chan][sb] == 0) {
+ audioout = 0;
+ } else {
+ audioout =
+ ((((sbc->output[i] * 2.0f) + 1.0f) * delta[chan][sb]) /
+ levels[chan][sb]) - delta[chan][sb];
+ }
+ sbc->output[i++] = audioout;
+ }
+ }
+ }
+
+ if (cfg->chmode == MODE_JOINT) {
+ i = 0;
+ while (i < (sbc->blocks * sbc->bands * sbc->channels)) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->join & (1 << (sbc->bands - sb - 1))) {
+ audioout = sbc->output[i];
+ sbc->output[i] = (2.0f * sbc->output[i]) +
+ (2.0f * sbc->output[i + sbc->bands]);
+ sbc->output[i + sbc->bands] =
+ (2.0f * audioout) -
+ (2.0f * sbc->output[i + sbc->bands]);
+ sbc->output[i] /= 2.0f;
+ sbc->output[i + sbc->bands] /= 2.0f;
+ }
+ i++;
+ }
+ i += sbc->bands;
+ }
+ }
+ position = 0;
+ for (block = 0; block < sbc->blocks; block++) {
+ for (chan = 0; chan < sbc->channels; chan++) {
+ /* select right or left channel */
+ if (chan == 0) {
+ X = left;
+ V = sbc->left;
+ } else {
+ X = right;
+ V = sbc->right;
+ }
+ for (i = 0; i < sbc->bands; i++)
+ S[i] = sbc->output[position++];
+
+ for (i = (sbc->bands * 20) - 1; i >= (sbc->bands * 2); i--)
+ V[i] = V[i - (sbc->bands * 2)];
+ for (k = 0; k < sbc->bands * 2; k++) {
+ float vk = 0;
+ for (i = 0; i < sbc->bands; i++) {
+ if (sbc->bands == 8) {
+ vk += cosdecdata8[i][k] * S[i];
+ } else {
+ vk += cosdecdata4[i][k] * S[i];
+ }
+ }
+ V[k] = vk;
+ }
+ for (i = 0; i <= 4; i++) {
+ for (k = 0; k < sbc->bands; k++) {
+ U[(i * sbc->bands * 2) + k] =
+ V[(i * sbc->bands * 4) + k];
+ U[(i * sbc->bands
+ * 2) + sbc->bands + k] =
+ V[(i * sbc->bands * 4) +
+ (sbc->bands * 3) + k];
+ }
+ }
+ for (i = 0; i < sbc->bands * 10; i++) {
+ if (sbc->bands == 4) {
+ W[i] = U[i] * (sbc_coeffs4[i] * -4.0f);
+ } else if (sbc->bands == 8) {
+ W[i] = U[i] * (sbc_coeffs8[i] * -8.0f);
+ } else {
+ W[i] = 0;
+ }
+ }
+
+ for (k = 0; k < sbc->bands; k++) {
+ unsigned int offset = k + (block * sbc->bands);
+
+ X[offset] = 0;
+ for (i = 0; i < 10; i++) {
+ X[offset] += W[k + (i * sbc->bands)];
+ }
+
+ if (X[offset] > 32767.0)
+ X[offset] = 32767.0;
+ else if (X[offset] < -32767.0)
+ X[offset] = -32767.0;
+ }
+ }
+ }
+
+ for (i = 0, k = 0; k != (sbc->blocks * sbc->bands); k++) {
+ sbc->music_data[i++] = left[k];
+ if (sbc->channels == 2)
+ sbc->music_data[i++] = right[k];
+ }
+}
+
+size_t
+sbc_encode_frame(struct bt_config *cfg)
+{
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ uint8_t config;
+ uint8_t block;
+ uint8_t chan;
+ uint8_t sb;
+ uint8_t j;
+ uint8_t i;
+
+ config = (cfg->freq << 6) | (cfg->blocks << 4) |
+ (cfg->chmode << 2) | (cfg->allocm << 1) | cfg->bands;
+
+ sbc_encode(cfg);
+
+ /* set initial CRC */
+ sbc->crc = 0x5e;
+
+ /* reset data position and size */
+ sbc->bitoffset = 0;
+ sbc->maxoffset = sizeof(sbc->data) * 8;
+
+ sbc_store_bits_crc(sbc, 8, SYNCWORD);
+ sbc_store_bits_crc(sbc, 8, config);
+ sbc_store_bits_crc(sbc, 8, cfg->bitpool);
+
+ /* skip 8-bit CRC */
+ sbc->bitoffset += 8;
+
+ if (cfg->chmode == MODE_JOINT) {
+ if (sbc->bands == 8)
+ sbc_store_bits_crc(sbc, 8, sbc->join);
+ else if (sbc->bands == 4)
+ sbc_store_bits_crc(sbc, 4, sbc->join);
+ }
+ for (i = 0; i < sbc->channels; i++) {
+ for (j = 0; j < sbc->bands; j++)
+ sbc_store_bits_crc(sbc, 4, sbc->scalefactor[i][j]);
+ }
+
+ /* store 8-bit CRC */
+ sbc->data[3] = (sbc->crc & 0xFF);
+
+ i = 0;
+ for (block = 0; block < sbc->blocks; block++) {
+ for (chan = 0; chan < sbc->channels; chan++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->bits[chan][sb] == 0)
+ continue;
+
+ sbc_store_bits_crc(sbc, sbc->bits[chan][sb], sbc->output[i++]);
+ }
+ }
+ }
+ return ((sbc->bitoffset + 7) / 8);
+}
+
+static uint32_t
+sbc_load_bits_crc(struct sbc_encode *sbc, uint32_t numbits)
+{
+ uint32_t off = sbc->bitoffset;
+ uint32_t value = 0;
+
+ while (numbits-- && off != sbc->maxoffset) {
+ if (sbc->rem_data_ptr[off / 8] & (1 << ((7 - off) & 7))) {
+ value |= (1 << numbits);
+ sbc->crc ^= 0x80;
+ }
+ sbc->crc *= 2;
+ if (sbc->crc & 0x100)
+ sbc->crc ^= 0x11d; /* CRC-8 polynomial */
+
+ off++;
+ }
+ sbc->bitoffset = off;
+ return (value);
+}
+
+size_t
+sbc_decode_frame(struct bt_config *cfg, int bits)
+{
+ struct sbc_encode *sbc = cfg->handle.sbc_enc;
+ uint8_t config;
+ uint8_t block;
+ uint8_t chan;
+ uint8_t sb;
+ uint8_t j;
+ uint8_t i;
+
+ sbc->rem_off = 0;
+ sbc->rem_len = 0;
+
+ config = (cfg->freq << 6) | (cfg->blocks << 4) |
+ (cfg->chmode << 2) | (cfg->allocm << 1) | cfg->bands;
+
+ /* set initial CRC */
+ sbc->crc = 0x5e;
+
+ /* reset data position and size */
+ sbc->bitoffset = 0;
+ sbc->maxoffset = bits;
+
+ /* verify SBC header */
+ if (sbc->maxoffset < (8 * 4))
+ return (0);
+ if (sbc_load_bits_crc(sbc, 8) != SYNCWORD)
+ return (0);
+ if (sbc_load_bits_crc(sbc, 8) != config)
+ return (0);
+ cfg->bitpool = sbc_load_bits_crc(sbc, 8);
+
+ (void)sbc_load_bits_crc(sbc, 8);/* CRC */
+
+ if (cfg->chmode == MODE_JOINT) {
+ if (sbc->bands == 8)
+ sbc->join = sbc_load_bits_crc(sbc, 8);
+ else if (sbc->bands == 4)
+ sbc->join = sbc_load_bits_crc(sbc, 4);
+ else
+ sbc->join = 0;
+ } else {
+ sbc->join = 0;
+ }
+
+ for (i = 0; i < sbc->channels; i++) {
+ for (j = 0; j < sbc->bands; j++)
+ sbc->scalefactor[i][j] = sbc_load_bits_crc(sbc, 4);
+ }
+
+ calc_bitneed(cfg);
+
+ i = 0;
+ for (block = 0; block < sbc->blocks; block++) {
+ for (chan = 0; chan < sbc->channels; chan++) {
+ for (sb = 0; sb < sbc->bands; sb++) {
+ if (sbc->bits[chan][sb] == 0) {
+ i++;
+ continue;
+ }
+ sbc->output[i++] =
+ sbc_load_bits_crc(sbc, sbc->bits[chan][sb]);
+ }
+ }
+ }
+
+ sbc_decode(cfg);
+
+ sbc->rem_off = 0;
+ sbc->rem_len = sbc->blocks * sbc->channels * sbc->bands;
+
+ return ((sbc->bitoffset + 7) / 8);
+}
diff --git a/lib/virtual_oss/bt/sbc_encode.h b/lib/virtual_oss/bt/sbc_encode.h
new file mode 100644
index 000000000000..71f8460a242e
--- /dev/null
+++ b/lib/virtual_oss/bt/sbc_encode.h
@@ -0,0 +1,82 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2015 Nathanial Sloss <nathanialsloss@yahoo.com.au>
+ *
+ * This software is dedicated to the memory of -
+ * Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012.
+ *
+ * Barry was a man who loved his music.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SBC_ENCODE_H_
+#define _SBC_ENCODE_H_
+
+#define MIN_BITPOOL 2
+#define DEFAULT_MAXBPOOL 250
+
+/*
+ * SBC header format
+ */
+struct sbc_header {
+ uint8_t id;
+ uint8_t id2;
+ uint8_t seqnumMSB;
+ uint8_t seqnumLSB;
+ uint8_t ts3;
+ uint8_t ts2;
+ uint8_t ts1;
+ uint8_t ts0;
+ uint8_t reserved3;
+ uint8_t reserved2;
+ uint8_t reserved1;
+ uint8_t reserved0;
+ uint8_t numFrames;
+};
+
+struct sbc_encode {
+ int16_t music_data[256];
+ uint8_t data[1024];
+ uint8_t *rem_data_ptr;
+ int rem_data_len;
+ int rem_data_frames;
+ int bits[2][8];
+ float output[256];
+ float left[160];
+ float right[160];
+ float samples[16][2][8];
+ uint32_t rem_len;
+ uint32_t rem_off;
+ uint32_t bitoffset;
+ uint32_t maxoffset;
+ uint32_t crc;
+ uint16_t framesamples;
+ uint8_t scalefactor[2][8];
+ uint8_t channels;
+ uint8_t bands;
+ uint8_t blocks;
+ uint8_t join;
+};
+
+#endif /* _SBC_ENCODE_H_ */
diff --git a/lib/virtual_oss/null/Makefile b/lib/virtual_oss/null/Makefile
new file mode 100644
index 000000000000..ec5c2d40f665
--- /dev/null
+++ b/lib/virtual_oss/null/Makefile
@@ -0,0 +1,10 @@
+SHLIB_NAME= voss_null.so
+SHLIBDIR= ${LIBDIR}/virtual_oss
+
+SRCS= null.c
+
+CFLAGS+= -I${SRCTOP}/usr.sbin/virtual_oss/virtual_oss \
+ -I${SRCTOP}/contrib/libsamplerate
+LIBADD= samplerate
+
+.include <bsd.lib.mk>
diff --git a/lib/virtual_oss/null/null.c b/lib/virtual_oss/null/null.c
new file mode 100644
index 000000000000..149c6e3e8c6a
--- /dev/null
+++ b/lib/virtual_oss/null/null.c
@@ -0,0 +1,102 @@
+/*-
+ * Copyright (c) 2015-2022 Hans Petter Selasky
+ *
+ * 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/queue.h>
+#include <sys/filio.h>
+#include <sys/soundcard.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <err.h>
+#include <time.h>
+
+#include "backend.h"
+#include "int.h"
+
+static void
+null_close(struct voss_backend *pbe __unused)
+{
+}
+
+static int
+null_open(struct voss_backend *pbe __unused, const char *devname __unused,
+ int samplerate __unused, int bufsize __unused, int *pchannels __unused,
+ int *pformat)
+{
+ int value[3];
+ int i;
+
+ value[0] = *pformat & VPREFERRED_SNE_AFMT;
+ value[1] = *pformat & VPREFERRED_SLE_AFMT;
+ value[2] = *pformat & VPREFERRED_SBE_AFMT;
+
+ for (i = 0; i != 3; i++) {
+ if (value[i] == 0)
+ continue;
+ *pformat = value[i];
+ return (0);
+ }
+ return (-1);
+}
+
+static int
+null_rec_transfer(struct voss_backend *pbe __unused, void *ptr, int len)
+{
+
+ if (voss_has_synchronization == 0)
+ virtual_oss_wait();
+ memset(ptr, 0, len);
+ return (len);
+}
+
+static int
+null_play_transfer(struct voss_backend *pbe __unused, void *ptr __unused,
+ int len)
+{
+ return (len);
+}
+
+static void
+null_delay(struct voss_backend *pbe __unused, int *pdelay)
+{
+ *pdelay = -1;
+}
+
+struct voss_backend voss_backend_null_rec = {
+ .open = null_open,
+ .close = null_close,
+ .transfer = null_rec_transfer,
+ .delay = null_delay,
+};
+
+struct voss_backend voss_backend_null_play = {
+ .open = null_open,
+ .close = null_close,
+ .transfer = null_play_transfer,
+ .delay = null_delay,
+};
diff --git a/lib/virtual_oss/oss/Makefile b/lib/virtual_oss/oss/Makefile
new file mode 100644
index 000000000000..257d7f0c0bae
--- /dev/null
+++ b/lib/virtual_oss/oss/Makefile
@@ -0,0 +1,10 @@
+SHLIB_NAME= voss_oss.so
+SHLIBDIR= ${LIBDIR}/virtual_oss
+
+SRCS= oss.c
+
+CFLAGS+= -I${SRCTOP}/usr.sbin/virtual_oss/virtual_oss \
+ -I${SRCTOP}/contrib/libsamplerate
+LIBADD= samplerate
+
+.include <bsd.lib.mk>
diff --git a/lib/virtual_oss/oss/oss.c b/lib/virtual_oss/oss/oss.c
new file mode 100644
index 000000000000..b4779f9108d9
--- /dev/null
+++ b/lib/virtual_oss/oss/oss.c
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 2015-2019 Hans Petter Selasky
+ *
+ * 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/queue.h>
+#include <sys/filio.h>
+#include <sys/soundcard.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <err.h>
+#include <poll.h>
+
+#include "backend.h"
+#include "int.h"
+
+static int
+oss_set_format(int fd, int *format)
+{
+ int value[6];
+ int error;
+ int fmt;
+ int i;
+
+ value[0] = *format & VPREFERRED_SNE_AFMT;
+ value[1] = *format & VPREFERRED_UNE_AFMT;
+ value[2] = *format & VPREFERRED_SLE_AFMT;
+ value[3] = *format & VPREFERRED_SBE_AFMT;
+ value[4] = *format & VPREFERRED_ULE_AFMT;
+ value[5] = *format & VPREFERRED_UBE_AFMT;
+
+ for (i = 0; i != 6; i++) {
+ fmt = value[i];
+ if (fmt == 0)
+ continue;
+ error = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
+ /* make sure we got the format we asked for */
+ if (error == 0 && fmt == value[i]) {
+ *format = fmt;
+ return (0);
+ }
+ }
+ return (-1);
+}
+
+static void
+oss_close(struct voss_backend *pbe)
+{
+ if (pbe->fd > -1) {
+ close(pbe->fd);
+ pbe->fd = -1;
+ }
+}
+
+static int
+oss_open(struct voss_backend *pbe, const char *devname, int samplerate,
+ int bufsize, int *pchannels, int *pformat, int attr, int fionbio)
+{
+ int temp;
+ int err;
+
+ pbe->fd = open(devname, attr);
+ if (pbe->fd < 0) {
+ warn("Could not open DSP device '%s'", devname);
+ return (-1);
+ }
+ err = ioctl(pbe->fd, FIONBIO, &fionbio);
+ if (err < 0) {
+ warn("Could not set blocking mode on DSP");
+ goto error;
+ }
+ err = oss_set_format(pbe->fd, pformat);
+ if (err < 0) {
+ warn("Could not set sample format 0x%08x", *pformat);
+ goto error;
+ }
+ temp = *pchannels;
+ bufsize /= temp; /* get buffer size per channel */
+ do {
+ err = ioctl(pbe->fd, SOUND_PCM_WRITE_CHANNELS, &temp);
+ } while (err < 0 && --temp > 0);
+
+ err = ioctl(pbe->fd, SOUND_PCM_READ_CHANNELS, &temp);
+ if (err < 0 || temp <= 0 || temp > *pchannels) {
+ warn("Could not set DSP channels: %d / %d", temp, *pchannels);
+ goto error;
+ }
+ *pchannels = temp;
+
+ temp = samplerate;
+ err = ioctl(pbe->fd, SNDCTL_DSP_SPEED, &temp);
+ if (err < 0 || temp != samplerate) {
+ warn("Could not set sample rate to %d / %d Hz", temp, samplerate);
+ goto error;
+ }
+
+ temp = bufsize * (*pchannels);
+ err = ioctl(pbe->fd, SNDCTL_DSP_SETBLKSIZE, &temp);
+ if (err < 0) {
+ warn("Could not set block size to %d", temp);
+ goto error;
+ }
+ return (0);
+error:
+ close(pbe->fd);
+ pbe->fd = -1;
+ return (-1);
+}
+
+static int
+oss_rec_open(struct voss_backend *pbe, const char *devname, int samplerate,
+ int bufsize, int *pchannels, int *pformat)
+{
+ return (oss_open(pbe, devname, samplerate, bufsize, pchannels, pformat, O_RDONLY, 0));
+}
+
+static int
+oss_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
+ int bufsize, int *pchannels, int *pformat)
+{
+ bufsize *= 4; /* XXX allow extra space for jitter */
+ return (oss_open(pbe, devname, samplerate, bufsize, pchannels, pformat, O_WRONLY, 0));
+}
+
+static int
+oss_rec_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ struct pollfd fds = { .fd = pbe->fd, .events = POLLIN | POLLRDNORM };
+ int err;
+
+ /* wait at maximum 2 seconds for data, else something is wrong */
+ err = poll(&fds, 1, 2000);
+ if (err < 1)
+ return (-1);
+ return (read(pbe->fd, ptr, len));
+}
+
+static int
+oss_play_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ return (write(pbe->fd, ptr, len));
+}
+
+static void
+oss_rec_delay(struct voss_backend *pbe, int *pdelay)
+{
+ if (ioctl(pbe->fd, FIONREAD, pdelay) != 0)
+ *pdelay = -1;
+}
+
+static void
+oss_play_delay(struct voss_backend *pbe, int *pdelay)
+{
+ if (voss_has_synchronization != 0 ||
+ ioctl(pbe->fd, SNDCTL_DSP_GETODELAY, pdelay) != 0)
+ *pdelay = -1;
+}
+
+struct voss_backend voss_backend_oss_rec = {
+ .open = oss_rec_open,
+ .close = oss_close,
+ .transfer = oss_rec_transfer,
+ .delay = oss_rec_delay,
+ .fd = -1,
+};
+
+struct voss_backend voss_backend_oss_play = {
+ .open = oss_play_open,
+ .close = oss_close,
+ .transfer = oss_play_transfer,
+ .delay = oss_play_delay,
+ .fd = -1,
+};
diff --git a/lib/virtual_oss/sndio/Makefile b/lib/virtual_oss/sndio/Makefile
new file mode 100644
index 000000000000..9b5af63a3246
--- /dev/null
+++ b/lib/virtual_oss/sndio/Makefile
@@ -0,0 +1,12 @@
+SHLIB_NAME= voss_sndio.so
+SHLIBDIR= ${LIBDIR}/virtual_oss
+
+SRCS= sndio.c
+
+CFLAGS+= -I${SRCTOP}/usr.sbin/virtual_oss/virtual_oss \
+ -I${SRCTOP}/contrib/libsamplerate \
+ -I${LOCALBASE:U/usr/local}/include
+LDFLAGS+= -L${LOCALBASE:U/usr/local}/lib -lsndio
+LIBADD= samplerate
+
+.include <bsd.lib.mk>
diff --git a/lib/virtual_oss/sndio/sndio.c b/lib/virtual_oss/sndio/sndio.c
new file mode 100644
index 000000000000..2d1a3411049b
--- /dev/null
+++ b/lib/virtual_oss/sndio/sndio.c
@@ -0,0 +1,203 @@
+/*-
+ * Copyright (c) 2021 Tim Creech <tcreech@tcreech.com>
+ *
+ * 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/queue.h>
+#include <sys/soundcard.h>
+
+#include <err.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sndio.h>
+
+#include "backend.h"
+#include "int.h"
+
+static struct sio_hdl *
+get_sio_hdl(struct voss_backend *pbe)
+{
+ if (pbe)
+ return (pbe->arg);
+
+ return (NULL);
+}
+
+static void
+sndio_close(struct voss_backend *pbe)
+{
+ if (!pbe)
+ return;
+
+ if (get_sio_hdl(pbe))
+ sio_close(get_sio_hdl(pbe));
+}
+
+static int
+sndio_get_signedness(int *fmt)
+{
+ int s_fmt = *fmt & (VPREFERRED_SLE_AFMT | VPREFERRED_SBE_AFMT);
+
+ if (s_fmt) {
+ *fmt = s_fmt;
+ return (1);
+ }
+ *fmt = *fmt & (VPREFERRED_ULE_AFMT | VPREFERRED_UBE_AFMT);
+ return (0);
+}
+
+static int
+sndio_get_endianness_is_le(int *fmt)
+{
+ int le_fmt = *fmt & (VPREFERRED_SLE_AFMT | VPREFERRED_ULE_AFMT);
+
+ if (le_fmt) {
+ *fmt = le_fmt;
+ return (1);
+ }
+ *fmt = *fmt & (VPREFERRED_SBE_AFMT | VPREFERRED_UBE_AFMT);
+ return (0);
+}
+
+static int
+sndio_get_bits(int *fmt)
+{
+ if (*fmt & AFMT_16BIT)
+ return (16);
+ if (*fmt & AFMT_24BIT)
+ return (24);
+ if (*fmt & AFMT_32BIT)
+ return (32);
+ if (*fmt & AFMT_8BIT)
+ return (8);
+ return (-1);
+ /* TODO AFMT_BIT */
+}
+
+static int
+sndio_open(struct voss_backend *pbe, const char *devname,
+ int samplerate, int bufsize, int *pchannels, int *pformat, int direction)
+{
+ const char *sndio_name = devname + strlen("/dev/sndio/");
+
+ int sig = sndio_get_signedness(pformat);
+ int le = sndio_get_endianness_is_le(pformat);
+ int bits = sndio_get_bits(pformat);
+
+ if (bits == -1) {
+ warn("unsupported format precision");
+ return (-1);
+ }
+
+ struct sio_hdl *hdl = sio_open(sndio_name, direction, 0);
+
+ if (hdl == 0) {
+ warn("sndio: failed to open device");
+ return (-1);
+ }
+
+ struct sio_par par;
+
+ sio_initpar(&par);
+ par.pchan = *pchannels;
+ par.sig = sig;
+ par.bits = bits;
+ par.bps = SIO_BPS(bits);
+ par.le = le;
+ par.rate = samplerate;
+ par.appbufsz = bufsize;
+ par.xrun = SIO_SYNC;
+ if (!sio_setpar(hdl, &par))
+ errx(1, "internal error, sio_setpar() failed");
+ if (!sio_getpar(hdl, &par))
+ errx(1, "internal error, sio_getpar() failed");
+ if ((int)par.pchan != *pchannels)
+ errx(1, "couldn't set number of channels");
+ if ((int)par.sig != sig || (int)par.bits != bits || (int)par.le != le)
+ errx(1, "couldn't set format");
+ if ((int)par.bits != bits)
+ errx(1, "couldn't set precision");
+ if ((int)par.rate < samplerate * 995 / 1000 ||
+ (int)par.rate > samplerate * 1005 / 1000)
+ errx(1, "couldn't set rate");
+ if (par.xrun != SIO_SYNC)
+ errx(1, "couldn't set xun policy");
+
+ /* Save the device handle with the backend */
+ pbe->arg = hdl;
+
+ /* Start the device. */
+ if (!sio_start(hdl))
+ errx(1, "couldn't start device");
+
+ return (0);
+}
+
+static int
+sndio_open_play(struct voss_backend *pbe, const char *devname,
+ int samplerate, int bufsize, int *pchannels, int *pformat)
+{
+ return (sndio_open(pbe, devname, samplerate, bufsize, pchannels, pformat, SIO_PLAY));
+}
+
+static int
+sndio_open_rec(struct voss_backend *pbe, const char *devname,
+ int samplerate, int bufsize, int *pchannels, int *pformat)
+{
+ return (sndio_open(pbe, devname, samplerate, bufsize, pchannels, pformat, SIO_REC));
+}
+
+static int
+sndio_play_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ return (sio_write(get_sio_hdl(pbe), ptr, len));
+}
+
+static int
+sndio_rec_transfer(struct voss_backend *pbe, void *ptr, int len)
+{
+ return (sio_read(get_sio_hdl(pbe), ptr, len));
+}
+
+static void
+sndio_delay(struct voss_backend *pbe __unused, int *pdelay)
+{
+ *pdelay = -1;
+}
+
+struct voss_backend voss_backend_sndio_rec = {
+ .open = sndio_open_rec,
+ .close = sndio_close,
+ .transfer = sndio_rec_transfer,
+ .delay = sndio_delay,
+ .fd = -1,
+};
+
+struct voss_backend voss_backend_sndio_play = {
+ .open = sndio_open_play,
+ .close = sndio_close,
+ .transfer = sndio_play_transfer,
+ .delay = sndio_delay,
+ .fd = -1,
+};