Skip to content

Commit

Permalink
[compiler-rt] making getrandom call blocking. (#78340)
Browse files Browse the repository at this point in the history
except when `GRND_NONBLOCK` is present in the flags.
  • Loading branch information
devnexen committed Jan 18, 2024
1 parent f01b6ca commit d83d1cb
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d83d1cb

Please sign in to comment.