mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
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:
parent
49905fed0b
commit
e4258015b7
1 changed files with 14 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue