[compiler-rt] making getrandom call blocking. (#78340)

except when `GRND_NONBLOCK` is present in the flags.
This commit is contained in:
David CARLIER 2024-01-18 05:46:50 +00:00 committed by GitHub
parent f01b6ca8be
commit d83d1cb89c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9965,7 +9965,13 @@ INTERCEPTOR(void, sl_free, void *sl, int freeall) {
INTERCEPTOR(SSIZE_T, getrandom, void *buf, SIZE_T buflen, unsigned int flags) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getrandom, buf, buflen, flags);
SSIZE_T n = REAL(getrandom)(buf, buflen, flags);
// If GRND_NONBLOCK is set in the flags, it is non blocking.
static const int grnd_nonblock = 1;
SSIZE_T n;
if ((flags & grnd_nonblock))
n = REAL(getrandom)(buf, buflen, flags);
else
n = COMMON_INTERCEPTOR_BLOCK_REAL(getrandom)(buf, buflen, flags);
if (n > 0) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, n);
}