Skip to content

Commit d83d1cb

Browse files
authored
[compiler-rt] making getrandom call blocking. (llvm#78340)
except when `GRND_NONBLOCK` is present in the flags.
1 parent f01b6ca commit d83d1cb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9965,7 +9965,13 @@ INTERCEPTOR(void, sl_free, void *sl, int freeall) {
99659965
INTERCEPTOR(SSIZE_T, getrandom, void *buf, SIZE_T buflen, unsigned int flags) {
99669966
void *ctx;
99679967
COMMON_INTERCEPTOR_ENTER(ctx, getrandom, buf, buflen, flags);
9968-
SSIZE_T n = REAL(getrandom)(buf, buflen, flags);
9968+
// If GRND_NONBLOCK is set in the flags, it is non blocking.
9969+
static const int grnd_nonblock = 1;
9970+
SSIZE_T n;
9971+
if ((flags & grnd_nonblock))
9972+
n = REAL(getrandom)(buf, buflen, flags);
9973+
else
9974+
n = COMMON_INTERCEPTOR_BLOCK_REAL(getrandom)(buf, buflen, flags);
99699975
if (n > 0) {
99709976
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, n);
99719977
}

0 commit comments

Comments
 (0)