Improve detection of getrandom / getentropy

It's been reported that the 500th system call getentropy() isn't present
on Darwin Kernel Version 15.6.0 virtual machines. We work around this by
ignoring SIGSYS temporarily.
This commit is contained in:
Justine Tunney 2022-06-23 14:09:32 -07:00
parent 49905fed0b
commit e4258015b7

View file

@ -19,6 +19,8 @@
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
@ -37,6 +39,7 @@
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/grnd.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/errfuns.h"
static bool have_getrandom;
@ -123,10 +126,20 @@ ssize_t getrandom(void *p, size_t n, unsigned f) {
static textstartup void getrandom_init(void) {
int e, rc;
e = errno;
struct sigaction sa, oldsa;
if (IsBsd()) {
sa.sa_flags = 0;
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sigaction(SIGSYS, &sa, &oldsa);
}
if (!(rc = sys_getrandom(0, 0, 0))) {
have_getrandom = true;
}
KERNTRACE("sys_getrandom(0,0,0) → %d% m");
STRACE("sys_getrandom(0,0,0) → %d% m", rc);
if (IsBsd()) {
sigaction(SIGSYS, &oldsa, 0);
}
errno = e;
}