From 98861b23fccabe552c1bc3b4082aa2991d615001 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 5 Jan 2025 20:15:34 -0800 Subject: [PATCH] Make some style fixes to prng code --- libc/calls/getrandom.c | 5 ++--- libc/calls/read-nt.c | 6 ++++-- libc/stdio/getentropy.c | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libc/calls/getrandom.c b/libc/calls/getrandom.c index 9bb079c77..a0c53383b 100644 --- a/libc/calls/getrandom.c +++ b/libc/calls/getrandom.c @@ -114,7 +114,8 @@ static ssize_t GetDevUrandom(char *p, size_t n, unsigned f) { ssize_t __getrandom(void *p, size_t n, unsigned f) { ssize_t rc; if (IsWindows()) { - rc = ProcessPrng(p, n) ? n : __winerr(); + ProcessPrng(p, n); // never fails + rc = n; } else if (have_getrandom) { if (IsXnu() || IsOpenbsd()) { rc = GetRandomBsd(p, n, GetRandomEntropy); @@ -184,9 +185,7 @@ ssize_t __getrandom(void *p, size_t n, unsigned f) { * @raise EFAULT if the `n` bytes at `p` aren't valid memory * @raise EINTR if we needed to block and a signal was delivered instead * @cancelationpoint - * @asyncsignalsafe * @restartable - * @vforksafe */ ssize_t getrandom(void *p, size_t n, unsigned f) { ssize_t rc; diff --git a/libc/calls/read-nt.c b/libc/calls/read-nt.c index e66e54c37..b50f428e2 100644 --- a/libc/calls/read-nt.c +++ b/libc/calls/read-nt.c @@ -997,8 +997,10 @@ textwindows ssize_t ReadBuffer(int fd, void *data, size_t size, int64_t offset, if (f->kind == kFdDevNull) return 0; - if (f->kind == kFdDevRandom) - return ProcessPrng(data, size) ? size : __winerr(); + if (f->kind == kFdDevRandom) { + ProcessPrng(data, size); + return size; + } if (f->kind == kFdConsole) return ReadFromConsole(f, data, size, waitmask); diff --git a/libc/stdio/getentropy.c b/libc/stdio/getentropy.c index 2d171247f..ad8d357a8 100644 --- a/libc/stdio/getentropy.c +++ b/libc/stdio/getentropy.c @@ -21,6 +21,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/intrin/strace.h" +#include "libc/runtime/syslib.internal.h" #include "libc/sysv/errfuns.h" int sys_getentropy(void *, size_t) asm("sys_getrandom"); @@ -39,6 +40,8 @@ int getentropy(void *p, size_t n) { rc = eio(); } else if ((!p && n)) { rc = efault(); + } else if (IsXnuSilicon()) { + rc = __syslib->__getentropy(p, n); } else if (IsXnu() || IsOpenbsd()) { rc = sys_getentropy(p, n); } else {