[libc-commits] [libc] [libc] Internal getrandom implementation (PR #144427)
via libc-commits
libc-commits at lists.llvm.org
Tue Jun 17 10:32:28 PDT 2025
https://github.com/sribee8 updated https://github.com/llvm/llvm-project/pull/144427
>From 75a66dc41daf2a68cffac40ce9d5fa2cea17e99b Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Mon, 16 Jun 2025 20:07:11 +0000
Subject: [PATCH 1/9] [libc] Internal getrandom implementation
Implemented an internal getrandom to avoid calls to the public one in table.h
---
libc/src/__support/HashTable/randomness.h | 4 +--
libc/src/__support/OSUtil/getrandom.h | 23 ++++++++++++++
.../src/__support/OSUtil/linux/CMakeLists.txt | 1 +
libc/src/__support/OSUtil/linux/getrandom.cpp | 30 +++++++++++++++++++
libc/src/sys/random/linux/getrandom.cpp | 9 ++----
5 files changed, 58 insertions(+), 9 deletions(-)
create mode 100644 libc/src/__support/OSUtil/getrandom.h
create mode 100644 libc/src/__support/OSUtil/linux/getrandom.cpp
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index 6b58a4125f785..54fb9e51a5d67 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -14,8 +14,8 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#if defined(LIBC_HASHTABLE_USE_GETRANDOM)
+#include "src/__support/OSUtil/getrandom.h"
#include "src/__support/libc_errno.h"
-#include "src/sys/random/getrandom.h"
#endif
namespace LIBC_NAMESPACE_DECL {
@@ -39,7 +39,7 @@ LIBC_INLINE uint64_t next_random_seed() {
size_t count = sizeof(entropy);
uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
while (count > 0) {
- ssize_t len = getrandom(buffer, count, 0);
+ ssize_t len = internal::getrandom(buffer, count, 0);
if (len == -1) {
if (libc_errno == ENOSYS)
break;
diff --git a/libc/src/__support/OSUtil/getrandom.h b/libc/src/__support/OSUtil/getrandom.h
new file mode 100644
index 0000000000000..69468d7a5882c
--- /dev/null
+++ b/libc/src/__support/OSUtil/getrandom.h
@@ -0,0 +1,23 @@
+//===------------ Implementation of getrandom function ----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
+
+#include "src/__support/macros/config.h"
+#include <sys/random.h>
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index 4681d8c2bb73c..a725a7a6b318b 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -9,6 +9,7 @@ add_object_library(
SRCS
exit.cpp
fcntl.cpp
+ getrandom.cpp
HDRS
io.h
syscall.h
diff --git a/libc/src/__support/OSUtil/linux/getrandom.cpp b/libc/src/__support/OSUtil/linux/getrandom.cpp
new file mode 100644
index 0000000000000..225c381e3540f
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/getrandom.cpp
@@ -0,0 +1,30 @@
+//===------------ Linux implementation of getrandom -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/OSUtil/getrandom.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
+ ssize_t ret =
+ LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
+ if (ret < 0) {
+ libc_errno = static_cast<int>(-ret);
+ return -1;
+ }
+ return ret;
+}
+
+} // namespace internal
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index 0b8471ed8b374..c58c4c1857037 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -10,6 +10,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
+#include "src/__support/OSUtil/getrandom.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
@@ -19,13 +20,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, getrandom,
(void *buf, size_t buflen, unsigned int flags)) {
- ssize_t ret =
- LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
- if (ret < 0) {
- libc_errno = static_cast<int>(-ret);
- return -1;
- }
- return ret;
+ return internal::getrandom(buf, buflen, flags);
}
} // namespace LIBC_NAMESPACE_DECL
>From 0ec5b335b95f9c0cfd8e31b6f61713bb9dc9fc9a Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Mon, 16 Jun 2025 20:27:59 +0000
Subject: [PATCH 2/9] fixed formatting
---
libc/src/sys/random/linux/getrandom.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index c58c4c1857037..d42df207073b6 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -8,9 +8,9 @@
#include "src/sys/random/getrandom.h"
+#include "src/__support/OSUtil/getrandom.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
-#include "src/__support/OSUtil/getrandom.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
>From 5420382b55f62c1b410eae4d3a8931256c41eccf Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Mon, 16 Jun 2025 21:57:58 +0000
Subject: [PATCH 3/9] fixed internal error handling and moved implementation to
header file
---
libc/src/__support/HashTable/randomness.h | 10 ++++----
libc/src/__support/OSUtil/getrandom.h | 23 -------------------
.../src/__support/OSUtil/linux/CMakeLists.txt | 2 +-
.../linux/{getrandom.cpp => getrandom.h} | 19 +++++++++------
libc/src/sys/random/linux/getrandom.cpp | 9 ++++++--
5 files changed, 25 insertions(+), 38 deletions(-)
delete mode 100644 libc/src/__support/OSUtil/getrandom.h
rename libc/src/__support/OSUtil/linux/{getrandom.cpp => getrandom.h} (57%)
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index 54fb9e51a5d67..62d1f475fe63c 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -14,7 +14,7 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#if defined(LIBC_HASHTABLE_USE_GETRANDOM)
-#include "src/__support/OSUtil/getrandom.h"
+#include "src/__support/OSUtil/linux/getrandom.h"
#include "src/__support/libc_errno.h"
#endif
@@ -39,14 +39,14 @@ LIBC_INLINE uint64_t next_random_seed() {
size_t count = sizeof(entropy);
uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
while (count > 0) {
- ssize_t len = internal::getrandom(buffer, count, 0);
- if (len == -1) {
+ auto len = internal::getrandom(buffer, count, 0);
+ if (!len.has_value()) {
if (libc_errno == ENOSYS)
break;
continue;
}
- count -= len;
- buffer += len;
+ count -= len.value();
+ buffer += len.value();
}
libc_errno = errno_backup;
#endif
diff --git a/libc/src/__support/OSUtil/getrandom.h b/libc/src/__support/OSUtil/getrandom.h
deleted file mode 100644
index 69468d7a5882c..0000000000000
--- a/libc/src/__support/OSUtil/getrandom.h
+++ /dev/null
@@ -1,23 +0,0 @@
-//===------------ Implementation of getrandom function ----------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
-#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
-
-#include "src/__support/macros/config.h"
-#include <sys/random.h>
-
-namespace LIBC_NAMESPACE_DECL {
-namespace internal {
-
-ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
-
-} // namespace internal
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index a725a7a6b318b..0a0fbf18ce7a9 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -9,10 +9,10 @@ add_object_library(
SRCS
exit.cpp
fcntl.cpp
- getrandom.cpp
HDRS
io.h
syscall.h
+ getrandom.h
DEPENDS
.${LIBC_TARGET_ARCHITECTURE}.linux_${LIBC_TARGET_ARCHITECTURE}_util
libc.src.__support.common
diff --git a/libc/src/__support/OSUtil/linux/getrandom.cpp b/libc/src/__support/OSUtil/linux/getrandom.h
similarity index 57%
rename from libc/src/__support/OSUtil/linux/getrandom.cpp
rename to libc/src/__support/OSUtil/linux/getrandom.h
index 225c381e3540f..4737dca965770 100644
--- a/libc/src/__support/OSUtil/linux/getrandom.cpp
+++ b/libc/src/__support/OSUtil/linux/getrandom.h
@@ -1,4 +1,4 @@
-//===------------ Linux implementation of getrandom -------------*- C++ -*-===//
+//===------------ Implementation of getrandom function ----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,25 +6,30 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/OSUtil/getrandom.h"
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
+
+#include "hdr/types/ssize_t.h"
#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
+#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
-#include <sys/syscall.h> // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers
namespace LIBC_NAMESPACE_DECL {
namespace internal {
-ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
+static inline ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
+ unsigned int flags) {
ssize_t ret =
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
if (ret < 0) {
- libc_errno = static_cast<int>(-ret);
- return -1;
+ return Error(-static_cast<int>(ret));
}
return ret;
}
} // namespace internal
} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index d42df207073b6..01a53f794b6f5 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -8,9 +8,10 @@
#include "src/sys/random/getrandom.h"
-#include "src/__support/OSUtil/getrandom.h"
+#include "src/__support/OSUtil/linux/getrandom.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
+#include "src/__support/error_or.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
@@ -20,7 +21,11 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, getrandom,
(void *buf, size_t buflen, unsigned int flags)) {
- return internal::getrandom(buf, buflen, flags);
+ auto rand = internal::getrandom(buf, buflen, flags);
+ if (rand.has_value())
+ return rand.value();
+ libc_errno = static_cast<int>(-(rand.error()));
+ return -1;
}
} // namespace LIBC_NAMESPACE_DECL
>From 411fd43efe5b57bd10953c76a7b61edbc2d3c753 Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Mon, 16 Jun 2025 23:19:28 +0000
Subject: [PATCH 4/9] updated cmake and removed double negative
---
libc/src/__support/OSUtil/linux/CMakeLists.txt | 14 +++++++++++++-
libc/src/sys/random/linux/getrandom.cpp | 3 +--
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index 0a0fbf18ce7a9..719d004fcf4a3 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -12,7 +12,6 @@ add_object_library(
HDRS
io.h
syscall.h
- getrandom.h
DEPENDS
.${LIBC_TARGET_ARCHITECTURE}.linux_${LIBC_TARGET_ARCHITECTURE}_util
libc.src.__support.common
@@ -25,6 +24,19 @@ add_object_library(
libc.include.sys_syscall
)
+add_header_library(
+ getrandom
+ HDRS
+ getrandom.h
+ DEPENDS
+ libc.src.__support.OSUtil.linux.syscall
+ libc.src.__support.common
+ libc.src.__support.error_or
+ libc.src.__support.macros.config.h
+ libc.hdr.types.ssize_t
+ libc.include.sys_syscall
+)
+
add_header_library(
vdso_sym
HDRS
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index 01a53f794b6f5..8c53cd6f21e45 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -12,7 +12,6 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include "src/__support/error_or.h"
-
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include <sys/syscall.h> // For syscall numbers.
@@ -24,7 +23,7 @@ LLVM_LIBC_FUNCTION(ssize_t, getrandom,
auto rand = internal::getrandom(buf, buflen, flags);
if (rand.has_value())
return rand.value();
- libc_errno = static_cast<int>(-(rand.error()));
+ libc_errno = static_cast<int>(rand.error());
return -1;
}
>From 57c0a2c268369a4e8c96db21e2539763b3a0dbae Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Mon, 16 Jun 2025 23:34:28 +0000
Subject: [PATCH 5/9] style changes
---
libc/src/__support/HashTable/randomness.h | 2 +-
libc/src/sys/random/linux/getrandom.cpp | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index 62d1f475fe63c..af139f9d9748e 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -40,7 +40,7 @@ LIBC_INLINE uint64_t next_random_seed() {
uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
while (count > 0) {
auto len = internal::getrandom(buffer, count, 0);
- if (!len.has_value()) {
+ if (len.error()) {
if (libc_errno == ENOSYS)
break;
continue;
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index 8c53cd6f21e45..c403ee71a9cc4 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -21,10 +21,11 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, getrandom,
(void *buf, size_t buflen, unsigned int flags)) {
auto rand = internal::getrandom(buf, buflen, flags);
- if (rand.has_value())
- return rand.value();
- libc_errno = static_cast<int>(rand.error());
- return -1;
+ if (rand.error()) {
+ libc_errno = static_cast<int>(rand.error());
+ return -1;
+ }
+ return rand.value();
}
} // namespace LIBC_NAMESPACE_DECL
>From b8fedfe0e9ccea596298225ea3c6701e967db2c6 Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Tue, 17 Jun 2025 16:18:56 +0000
Subject: [PATCH 6/9] changed check to correct variable
---
libc/src/__support/HashTable/randomness.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index af139f9d9748e..24bbfb6cf34fb 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -41,7 +41,7 @@ LIBC_INLINE uint64_t next_random_seed() {
while (count > 0) {
auto len = internal::getrandom(buffer, count, 0);
if (len.error()) {
- if (libc_errno == ENOSYS)
+ if (len.error() == ENOSYS)
break;
continue;
}
>From 02fab9e9fb25eb063f0a0d486ac9be870554ab27 Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Tue, 17 Jun 2025 16:53:56 +0000
Subject: [PATCH 7/9] fixed logic for error_or
---
libc/src/__support/HashTable/randomness.h | 2 +-
libc/src/__support/OSUtil/linux/getrandom.h | 2 +-
libc/src/sys/random/linux/getrandom.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index 24bbfb6cf34fb..d6a99b2378618 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -40,7 +40,7 @@ LIBC_INLINE uint64_t next_random_seed() {
uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
while (count > 0) {
auto len = internal::getrandom(buffer, count, 0);
- if (len.error()) {
+ if (!len.has_value()) {
if (len.error() == ENOSYS)
break;
continue;
diff --git a/libc/src/__support/OSUtil/linux/getrandom.h b/libc/src/__support/OSUtil/linux/getrandom.h
index 4737dca965770..0dda04b3950b6 100644
--- a/libc/src/__support/OSUtil/linux/getrandom.h
+++ b/libc/src/__support/OSUtil/linux/getrandom.h
@@ -19,7 +19,7 @@
namespace LIBC_NAMESPACE_DECL {
namespace internal {
-static inline ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
+LIBC_INLINE static ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
unsigned int flags) {
ssize_t ret =
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index c403ee71a9cc4..c4ba56e794018 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -21,7 +21,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(ssize_t, getrandom,
(void *buf, size_t buflen, unsigned int flags)) {
auto rand = internal::getrandom(buf, buflen, flags);
- if (rand.error()) {
+ if (!rand.has_value()) {
libc_errno = static_cast<int>(rand.error());
return -1;
}
>From 32535421189472c3aca41a533ca12c69fb26c3b2 Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Tue, 17 Jun 2025 17:14:40 +0000
Subject: [PATCH 8/9] fixed formatting
---
libc/src/__support/OSUtil/linux/getrandom.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/OSUtil/linux/getrandom.h b/libc/src/__support/OSUtil/linux/getrandom.h
index 0dda04b3950b6..793639472fee7 100644
--- a/libc/src/__support/OSUtil/linux/getrandom.h
+++ b/libc/src/__support/OSUtil/linux/getrandom.h
@@ -20,7 +20,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace internal {
LIBC_INLINE static ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,
- unsigned int flags) {
+ unsigned int flags) {
ssize_t ret =
LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);
if (ret < 0) {
>From c7d6c4ca18c3990e987d4811fdb18e9703534bb9 Mon Sep 17 00:00:00 2001
From: Sriya Pratipati <sriyap at google.com>
Date: Tue, 17 Jun 2025 17:32:08 +0000
Subject: [PATCH 9/9] removed unnecessary code
---
libc/src/__support/HashTable/randomness.h | 1 -
libc/src/sys/random/linux/getrandom.cpp | 1 -
2 files changed, 2 deletions(-)
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index d6a99b2378618..2c9b1d3091b48 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -48,7 +48,6 @@ LIBC_INLINE uint64_t next_random_seed() {
count -= len.value();
buffer += len.value();
}
- libc_errno = errno_backup;
#endif
state.update(&entropy, sizeof(entropy));
}
diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp
index c4ba56e794018..4a95bddfa428e 100644
--- a/libc/src/sys/random/linux/getrandom.cpp
+++ b/libc/src/sys/random/linux/getrandom.cpp
@@ -14,7 +14,6 @@
#include "src/__support/error_or.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
More information about the libc-commits
mailing list