[libc-commits] [libc] [libc] Simplify getrandom syscall error handling (PR #242602)

Connector Switch via libc-commits libc-commits at lists.llvm.org
Fri Nov 13 22:57:08 PST 2026


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/242602

Use syscall_checked<ssize_t> in the getrandom wrapper instead of converting syscall errors by hand. This keeps the same byte counts and errors and does not add retries or change the syscall arguments.

All five existing getrandom tests pass.


>From 3e9817b74cccf354af0d0fb0d3323e19bb61597f Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Sat, 14 Nov 2026 14:56:45 +0800
Subject: [PATCH] [libc] Simplify getrandom syscall error handling

---
 .../__support/OSUtil/linux/syscall_wrappers/getrandom.h    | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h
index b5ef6201a2dc5e..63d365ac7806dd 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getrandom.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_GETRANDOM_H
 
 #include "hdr/types/ssize_t.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -21,10 +21,7 @@ namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
                                        unsigned int flags) {
-  ssize_t ret = syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
-  if (ret < 0)
-    return Error(-static_cast<int>(ret));
-  return ret;
+  return syscall_checked<ssize_t>(SYS_getrandom, buf, buflen, flags);
 }
 
 } // namespace linux_syscalls



More information about the libc-commits mailing list