glibc/sysdeps/generic
Adhemerval Zanella 461cab1de7 linux: Add support for getrandom vDSO
Linux 6.11 has getrandom() in vDSO. It operates on a thread-local opaque
state allocated with mmap using flags specified by the vDSO.

Multiple states are allocated at once, as many as fit into a page, and
these are held in an array of available states to be doled out to each
thread upon first use, and recycled when a thread terminates. As these
states run low, more are allocated.

To make this procedure async-signal-safe, a simple guard is used in the
LSB of the opaque state address, falling back to the syscall if there's
reentrancy contention.

Also, _Fork() is handled by blocking signals on opaque state allocation
(so _Fork() always sees a consistent state even if it interrupts a
getrandom() call) and by iterating over the thread stack cache on
reclaim_stack. Each opaque state will be in the free states list
(grnd_alloc.states) or allocated to a running thread.

The cancellation is handled by always using GRND_NONBLOCK flags while
calling the vDSO, and falling back to the cancellable syscall if the
kernel returns EAGAIN (would block). Since getrandom is not defined by
POSIX and cancellation is supported as an extension, the cancellation is
handled as 'may occur' instead of 'shall occur' [1], meaning that if
vDSO does not block (the expected behavior) getrandom will not act as a
cancellation entrypoint. It avoids a pthread_testcancel call on the fast
path (different than 'shall occur' functions, like sem_wait()).

It is currently enabled for x86_64, which is available in Linux 6.11,
and aarch64, powerpc32, powerpc64, loongarch64, and s390x, which are
available in Linux 6.12.

Link: https://pubs.opengroup.org/onlinepubs/9799919799/nframe.html [1]
Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com> # x86_64
Tested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> # x86_64, aarch64
Tested-by: Xi Ruoyao <xry111@xry111.site> # x86_64, aarch64, loongarch64
Tested-by: Stefan Liebler <stli@linux.ibm.com> # s390x
2024-11-12 14:42:12 -03:00
..
net
netinet
nfs
sys
_G_config.h
_itoa.h
a.out.h
abort-instr.h
adaptive_spin_count.h
aio_misc.h
allocalim.h
arch-fd_to_filename.h
asm-syntax.h
atomic-machine.h
c++-types.data
confstr.h
crti.S
crtn.S
device-nrs.h
dirstream.h
dl-affinity.h
dl-audit-check.h
dl-auxv.h
dl-cache.h
dl-call_tls_init_tp.h
dl-debug.h
dl-dtprocnum.h
dl-dtv.h
dl-execve.h
dl-fcntl.h
dl-fileid.h
dl-fixup-attribute.h
dl-hash.h
dl-hwcap-check.h
dl-irel.h
dl-isa-level.h
dl-lookupcfg.h
dl-machine-rel.h
dl-machine.h
dl-minimal-malloc.h
dl-mman.h
dl-new-hash.h
dl-osinfo.h
dl-procinfo.c
dl-procinfo.h
dl-procruntime.c
dl-prop.h
dl-protected.h
dl-r_debug.h
dl-relocate-ld.h
dl-symbol-redir-ifunc.h
dl-sysdep.h
dl-tls.h
dl-tunables-parse.h
dl-unistd.h
dl-vdso-setup.c
dl-vdso-setup.h
dl-vdso.h
dwarf2.h
elf_machine_sym_no_match.h
elf-initfini.h
elf-read-prop.h
elide.h
eloop-threshold.h
entry.h
errqueue.h
fast-jitter.h
fd_to_filename.h
features-time64.h
fenv_private.h
fix-float-double-convert-nan.h
fix-fp-int-compare-invalid.h
fix-fp-int-convert-overflow.h
fix-int-fp-convert-zero.h
float128-abi.h
fork.h
fpu_control.h
framestate.c
gcc-compat.h
gccframe.h
get-rounding-mode.h
getrandom-internal.h linux: Add support for getrandom vDSO 2024-11-12 14:42:12 -03:00
gmp-mparam.h
hp-timing-common.h
hp-timing.h
ifreq.h
ifunc-init.h
ifunc-sel.h
internal-signals.h stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
internal-sigset.h stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
intr-msg.h
ld.abilist
ldbl-classify-compat.h
ldconfig.h
ldsodefs.h elf: Introduce _dl_relocate_object_no_relro 2024-11-06 10:33:44 +01:00
libanl.abilist
libBrokenLocale.abilist
libc_malloc_debug.abilist
libc_start_call_main.h
libc-lock-arch.h
libc-lock.h
libc-mmap.h
libc-mtag.h
libc-start.h
libc-symver.h
libc-tsd.h
libc.abilist
libdl.abilist
libm-alias-double.h
libm-alias-float128.h
libm-alias-float.h
libm-alias-ldouble.h
libm-test-ulps
libm-test-ulps-name
libm.abilist
libnsl.abilist
libnss_compat.abilist
libnss_db.abilist
libnss_dns.abilist
libnss_files.abilist
libnss_hesiod.abilist
libnss_nis.abilist
libnss_nisplus.abilist
libpthread.abilist
libresolv.abilist
librt.abilist
libutil.abilist
link_map.h
linkmap.h
local-setxid.h
localplt.data
machine-gmon.h
machine-lock.h
machine-sp.h
Makefile
malloc-alignment.h
malloc-hugepages.c
malloc-hugepages.h
malloc-machine.h
malloc-size.h
malloc-sysdep.h
math_ldbl_opt.h
math_ldbl.h
math_private_calls.h
math_private.h
math-barriers.h
math-nan-payload-double.h
math-nan-payload-float.h
math-narrow-alias-float128.h
math-narrow-alias.h
math-tests-arch.h
math-tests-exceptions.h
math-tests-rounding.h
math-tests-snan-cast.h
math-tests-snan-payload.h
math-tests-snan.h
math-tests-trap-force.h
math-tests-trap.h
math-tests.h
math-type-macros-double.h
math-type-macros-float128.h
math-type-macros-float.h
math-type-macros-ldouble.h
math-type-macros.h
math-use-builtins-ceil.h
math-use-builtins-copysign.h
math-use-builtins-fabs.h
math-use-builtins-ffs.h
math-use-builtins-floor.h
math-use-builtins-fma.h
math-use-builtins-fmax.h
math-use-builtins-fmin.h
math-use-builtins-llrint.h
math-use-builtins-logb.h
math-use-builtins-lrint.h
math-use-builtins-nearbyint.h
math-use-builtins-rint.h
math-use-builtins-round.h
math-use-builtins-roundeven.h
math-use-builtins-sqrt.h
math-use-builtins-trunc.h
math-use-builtins.h
memcopy.h
memswap.h
mmap_info.h
mremap-failure.h
nan-high-order-bit.h
not-cancel.h linux: Add support for getrandom vDSO 2024-11-12 14:42:12 -03:00
not-errno.h
nscd-types.h
pagecopy.h
paths.h
pointer_guard.h
profil-counter.h
pty-private.h
rtld_static_init.h
rtld-lowlevel.h
safe-fatal.h
set-freeres-fp.h
set-freeres-os.h
set-freeres-system.h
set-hooks-arch.h
setjmpP.h
setvmaname.h
sigcontextinfo.h
siglist-compat-def.h
siglist.h
sigset-cvt-mask.h
sigsetops.h
single-thread.h
spawn_int_def.h
stackguard-macros.h
stackinfo.h
stap-probe-machine.h
startup.h
stdio-lock.h
string-fza.h
string-fzb.h
string-fzc.h
string-fzi.h
string-misc.h
string-opthr.h
string-optype.h
string-shift.h
struct_stat_time64.h
symbol-hacks.h
syscall_types.h nptl: Fix Race conditions in pthread cancellation [BZ#12683] 2024-08-23 14:27:43 -03:00
sysdep-cancel.h
sysdep.h
thread_state.h
time64-compat.h
time-clockid.h
tininess.h
tls-internal-struct.h
tls-internal.c
tls-internal.h
tls-setup.h
tls.h
tst-audit.h
tst-file-align.h
tst-stack-align.h
unsecvars.h
unwind-arch.h
unwind-dw2-fde-glibc.c
unwind-dw2-fde.c
unwind-dw2-fde.h
unwind-dw2.c
unwind-link.h
unwind-pe.c
unwind-pe.h
unwind-resume.c
unwind-resume.h
unwind.h
utmp-equal.h
utmp-size.h
xstatver.h