glibc/stdlib
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
..
bits Fix name space violation in fortify wrappers (bug 32052) 2024-08-05 16:49:58 +02:00
sys
a64l.c
abort.c stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
abs.c
add_n.c
addmul_1.c
alloca.h
arc4random_uniform.c
arc4random.c
at_quick_exit.c
atexit.c
atof.c
atoi.c
atol.c
atoll.c
bsearch.c
bug-fmtmsg1.c
bug-getcontext.c
bug-strtod2.c
bug-strtod.c
canonicalize.c
cmp.c
cxa_at_quick_exit.c
cxa_atexit.c
cxa_finalize.c
cxa_thread_atexit_impl.c
dbl2mpn.c
Depend
div.c
divmod_1.c
divrem.c
drand48_r.c
drand48-iter.c
drand48.c
erand48_r.c
erand48.c
errno.h
exit.c stdlib: Allow concurrent quick_exit (BZ 31997) 2024-08-05 17:07:57 -03:00
exit.h
fmtmsg.c
fmtmsg.h
fpioconst.c
fpioconst.h
gen-fpioconst.c
gen-tst-strtod-round.c More thoroughly test underflow / errno in tst-strtod-round 2024-08-27 12:38:01 +00:00
getcontext.c
getentropy.c
getenv.c
getrandom.c
getsubopt.c
gmp-impl.h
gmp.h
grouping.c
grouping.h
groupingwc.c
inlines.c
inttypes.h
isomac.c
jrand48_r.c
jrand48.c
l64a.c
labs.c
lcong48_r.c
lcong48.c
ldbl2mpn.c
ldiv.c
llabs.c
lldiv.c
longlong.h
lrand48_r.c
lrand48.c
lshift.c
makecontext.c
Makefile linux: Add support for getrandom vDSO 2024-11-12 14:42:12 -03:00
mblen.c
mbstowcs.c
mbtowc.c
mod_1.c
monetary.h
mp_clz_tab.c
mpn2dbl.c
mpn2flt.c
mpn2ldbl.c
mrand48_r.c
mrand48.c
mul_1.c
mul_n.c
mul.c
nrand48_r.c
nrand48.c
old_atexit.c
on_exit.c
putenv.c
qsort.c
quick_exit.c
rand_r.c
rand.c
random_r.c
random.c
rpmatch.c
rshift.c
secure-getenv.c
seed48_r.c
seed48.c
setcontext.c
setenv.c
srand48_r.c
srand48.c
stdbit.h
stdc_bit_ceil_uc.c
stdc_bit_ceil_ui.c
stdc_bit_ceil_ul.c
stdc_bit_ceil_ull.c
stdc_bit_ceil_us.c
stdc_bit_floor_uc.c
stdc_bit_floor_ui.c
stdc_bit_floor_ul.c
stdc_bit_floor_ull.c
stdc_bit_floor_us.c
stdc_bit_width_uc.c
stdc_bit_width_ui.c
stdc_bit_width_ul.c
stdc_bit_width_ull.c
stdc_bit_width_us.c
stdc_count_ones_uc.c
stdc_count_ones_ui.c
stdc_count_ones_ul.c
stdc_count_ones_ull.c
stdc_count_ones_us.c
stdc_count_zeros_uc.c
stdc_count_zeros_ui.c
stdc_count_zeros_ul.c
stdc_count_zeros_ull.c
stdc_count_zeros_us.c
stdc_first_leading_one_uc.c
stdc_first_leading_one_ui.c
stdc_first_leading_one_ul.c
stdc_first_leading_one_ull.c
stdc_first_leading_one_us.c
stdc_first_leading_zero_uc.c
stdc_first_leading_zero_ui.c
stdc_first_leading_zero_ul.c
stdc_first_leading_zero_ull.c
stdc_first_leading_zero_us.c
stdc_first_trailing_one_uc.c
stdc_first_trailing_one_ui.c
stdc_first_trailing_one_ul.c
stdc_first_trailing_one_ull.c
stdc_first_trailing_one_us.c
stdc_first_trailing_zero_uc.c
stdc_first_trailing_zero_ui.c
stdc_first_trailing_zero_ul.c
stdc_first_trailing_zero_ull.c
stdc_first_trailing_zero_us.c
stdc_has_single_bit_uc.c
stdc_has_single_bit_ui.c
stdc_has_single_bit_ul.c
stdc_has_single_bit_ull.c
stdc_has_single_bit_us.c
stdc_leading_ones_uc.c
stdc_leading_ones_ui.c
stdc_leading_ones_ul.c
stdc_leading_ones_ull.c
stdc_leading_ones_us.c
stdc_leading_zeros_uc.c
stdc_leading_zeros_ui.c
stdc_leading_zeros_ul.c
stdc_leading_zeros_ull.c
stdc_leading_zeros_us.c
stdc_trailing_ones_uc.c
stdc_trailing_ones_ui.c
stdc_trailing_ones_ul.c
stdc_trailing_ones_ull.c
stdc_trailing_ones_us.c
stdc_trailing_zeros_uc.c
stdc_trailing_zeros_ui.c
stdc_trailing_zeros_ul.c
stdc_trailing_zeros_ull.c
stdc_trailing_zeros_us.c
stdint.h
stdlib.h stdlib: Mark abort as cold 2024-07-31 14:26:00 +08:00
strfmon_l.c
strfmon.c
strfrom-skeleton.c
strfromd.c
strfromf.c
strfroml.c
strtod_l.c Fix strtod subnormal rounding (bug 30220) 2024-08-27 12:41:02 +00:00
strtod_nan_main.c Do not set errno for overflowing NaN payload in strtod/nan (bug 32045) 2024-09-04 13:21:23 +00:00
strtod_nan_narrow.h
strtod_nan_wide.h
strtod_nan.c
strtod.c
strtof_l.c
strtof_nan.c
strtof.c
strtol_l.c
strtol.c
strtold_l.c
strtold_nan.c
strtold.c
strtoll_l.c
strtoll.c
strtoul_l.c
strtoul.c
strtoull_l.c
strtoull.c
sub_n.c
submul_1.c
swapcontext.c
system.c
tens_in_limb.c
test-a64l.c
test-at_quick_exit-race.c
test-atexit-race-common.c
test-atexit-race.c
test-atexit-recursive.c
test-bz22786.c
test-canon2.c
test-canon.c
test-cxa_atexit-race2.c
test-cxa_atexit-race.c
test-dlclose-exit-race-helper.c
test-dlclose-exit-race.c
test-on_exit-race.c
testdiv.c
testdiv.input
testmb2.c
testmb.c
testrand.c
testsort.c
tst-abs.c
tst-arc4random-fork.c
tst-arc4random-stats.c
tst-arc4random-thread.c
tst-at_quick_exit.c
tst-atexit-common.c
tst-atexit.c
tst-atof1.c
tst-atof2.c
tst-bsearch.c
tst-bz20544.c
tst-canon-bz26341.c
tst-concurrent-exit-skeleton.c stdlib: Allow concurrent quick_exit (BZ 31997) 2024-08-05 17:07:57 -03:00
tst-concurrent-exit.c stdlib: Allow concurrent quick_exit (BZ 31997) 2024-08-05 17:07:57 -03:00
tst-concurrent-quick_exit.c stdlib: Allow concurrent quick_exit (BZ 31997) 2024-08-05 17:07:57 -03:00
tst-cxa_atexit.c
tst-empty-env.c
tst-environ.c
tst-fmtmsg.c
tst-fmtmsg.sh
tst-getrandom2.c linux: Add support for getrandom vDSO 2024-11-12 14:42:12 -03:00
tst-getrandom.c
tst-labs.c
tst-limits.c
tst-llabs.c
tst-makecontext2.c
tst-makecontext3.c
tst-makecontext-align.c
tst-makecontext.c
tst-on_exit.c
tst-putenv.c
tst-putenvmod.c
tst-qsort2.c
tst-qsort3.c
tst-qsort4.c
tst-qsort6.c
tst-qsort.c
tst-quick_exit.cc
tst-rand48-2.c
tst-rand48.c
tst-random2.c
tst-random.c
tst-realpath-toolong.c
tst-realpath.c
tst-secure-getenv.c
tst-setcontext2.c
tst-setcontext3.c
tst-setcontext3.sh
tst-setcontext4.c
tst-setcontext5.c
tst-setcontext6.c
tst-setcontext7.c
tst-setcontext8.c
tst-setcontext9.c
tst-setcontext10.c
tst-setcontext11.c
tst-setcontext.c
tst-stdbit-builtins.c
tst-stdbit-Wconversion.c
tst-stdbit.h
tst-stdc_bit_ceil.c
tst-stdc_bit_floor.c
tst-stdc_bit_width.c
tst-stdc_count_ones.c
tst-stdc_count_zeros.c
tst-stdc_first_leading_one.c
tst-stdc_first_leading_zero.c
tst-stdc_first_trailing_one.c
tst-stdc_first_trailing_zero.c
tst-stdc_has_single_bit.c
tst-stdc_leading_ones.c
tst-stdc_leading_zeros.c
tst-stdc_trailing_ones.c
tst-stdc_trailing_zeros.c
tst-strfmon_l.c
tst-strfrom-locale.c
tst-strfrom.c
tst-strfrom.h
tst-strtod1i.c Make __strtod_internal tests type-generic 2024-08-27 20:41:54 +00:00
tst-strtod2.c Add tests of more strtod special cases 2024-09-20 23:24:45 +00:00
tst-strtod3.c Make __strtod_internal tests type-generic 2024-08-27 20:41:54 +00:00
tst-strtod4.c Make __strtod_internal tests type-generic 2024-08-27 20:41:54 +00:00
tst-strtod5.c Make tst-strtod2 and tst-strtod5 type-generic 2024-09-20 23:23:13 +00:00
tst-strtod5i.c Make __strtod_internal tests type-generic 2024-08-27 20:41:54 +00:00
tst-strtod6.c
tst-strtod-nan-locale-main.c
tst-strtod-nan-locale.c
tst-strtod-nan-sign-main.c
tst-strtod-nan-sign.c
tst-strtod-overflow.c
tst-strtod-round-data Fix strtod subnormal rounding (bug 30220) 2024-08-27 12:41:02 +00:00
tst-strtod-round-data.h Fix strtod subnormal rounding (bug 30220) 2024-08-27 12:41:02 +00:00
tst-strtod-round-skeleton.c More thoroughly test underflow / errno in tst-strtod-round 2024-08-27 12:38:01 +00:00
tst-strtod-round.c
tst-strtod-underflow.c Make tst-strtod-underflow type-generic 2024-09-20 23:25:32 +00:00
tst-strtod.c
tst-strtod.h
tst-strtol-binary-c11.c
tst-strtol-binary-c23.c
tst-strtol-binary-gnu11.c
tst-strtol-binary-gnu23.c
tst-strtol-binary-main.c
tst-strtol-locale-main.c
tst-strtol-locale.c
tst-strtol.c
tst-strtoll.c
tst-swapcontext1.c
tst-swapcontext2.c Fix usage of _STACK_GROWS_DOWN and _STACK_GROWS_UP defines [BZ 31989] 2024-07-19 10:10:17 -04:00
tst-system.c support: Use macros for *stat wrappers 2024-08-16 16:05:20 +02:00
tst-thread-quick_exit.cc
tst-tininess.c
tst-tls-atexit-lib.c
tst-tls-atexit-nodelete.c
tst-tls-atexit.c
tst-unsetenv1.c
tst-width-stdint.c
tst-width.c
tst-xpg-basename.c
ucontext.h
udiv_qrnnd.c
Versions
wcstombs.c
wctomb.c
xpg_basename.c