Merge "Add aligned_alloc to libc."
diff --git a/libc/bionic/bionic_arc4random.cpp b/libc/bionic/bionic_arc4random.cpp
index 391eb0c..fa2617f 100644
--- a/libc/bionic/bionic_arc4random.cpp
+++ b/libc/bionic/bionic_arc4random.cpp
@@ -28,8 +28,6 @@
#include "private/bionic_arc4random.h"
-#include <errno.h>
-#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
#include <sys/auxv.h>
@@ -39,15 +37,12 @@
#include "private/KernelArgumentBlock.h"
-bool __libc_arc4random_has_unlimited_entropy() {
- static bool have_urandom = access("/dev/urandom", R_OK) == 0;
- return have_urandom;
-}
-
void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args) {
- // Only call arc4random_buf once we `have_urandom', since in getentropy_getrandom we may fallback
- // to use /dev/urandom, if the kernel entropy pool hasn't been initialized or not enough bytes
- if (__libc_arc4random_has_unlimited_entropy()) {
+ // Only call arc4random_buf once we have `/dev/urandom` because getentropy(3)
+ // will fall back to using `/dev/urandom` if getrandom(2) fails, and abort if
+ // if can't use `/dev/urandom`.
+ static bool have_urandom = access("/dev/urandom", R_OK) == 0;
+ if (have_urandom) {
arc4random_buf(buf, n);
return;
}
diff --git a/libc/bionic/sigaction.cpp b/libc/bionic/sigaction.cpp
index e5a7d5f..53b2a02 100644
--- a/libc/bionic/sigaction.cpp
+++ b/libc/bionic/sigaction.cpp
@@ -81,7 +81,6 @@
#else
extern "C" int __rt_sigaction(int, const struct sigaction64*, struct sigaction64*, size_t);
-extern "C" int __sigaction(int, const struct sigaction*, struct sigaction*);
int sigaction(int signal, const struct sigaction* bionic_new, struct sigaction* bionic_old) {
// The 32-bit ABI is broken. struct sigaction includes a too-small sigset_t,
@@ -91,6 +90,7 @@
kernel_new = {};
kernel_new.sa_flags = bionic_new->sa_flags;
kernel_new.sa_handler = bionic_new->sa_handler;
+ kernel_new.sa_restorer = bionic_new->sa_restorer;
memcpy(&kernel_new.sa_mask, &bionic_new->sa_mask, sizeof(bionic_new->sa_mask));
}
@@ -100,6 +100,7 @@
*bionic_old = {};
bionic_old->sa_flags = kernel_old.sa_flags;
bionic_old->sa_handler = kernel_old.sa_handler;
+ bionic_old->sa_restorer = kernel_old.sa_restorer;
memcpy(&bionic_old->sa_mask, &kernel_old.sa_mask, sizeof(bionic_old->sa_mask));
}
return result;
diff --git a/libc/private/bionic_arc4random.h b/libc/private/bionic_arc4random.h
index b51f818..0e9376e 100644
--- a/libc/private/bionic_arc4random.h
+++ b/libc/private/bionic_arc4random.h
@@ -33,18 +33,11 @@
#include "private/KernelArgumentBlock.h"
-/*
- * arc4random aborts if it's unable to fetch entropy, which is always the case
- * for init on devices without getrandom(2), since /dev/random hasn't been
- * created yet. Provide a wrapper function that falls back to AT_RANDOM if
- * we don't have getrandom and /dev/urandom is missing.
- */
+// arc4random(3) aborts if it's unable to fetch entropy, which is always
+// the case for init on devices. GCE kernels have a workaround to ensure
+// sufficient entropy during early boot, but no device kernels do. This
+// wrapper falls back to AT_RANDOM if the kernel doesn't have enough
+// entropy for getrandom(2) or /dev/urandom.
void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args);
-/*
- * Return true if libc has an unlimited entropy source (something other than
- * AT_RANDOM), and arc4random* calls will always succeed.
- */
-bool __libc_arc4random_has_unlimited_entropy();
-
#endif
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 87a918f..2b414e5 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -285,6 +285,7 @@
ASSERT_TRUE(original_sa.sa_handler == NULL);
ASSERT_TRUE(original_sa.sa_sigaction == NULL);
ASSERT_EQ(0U, original_sa.sa_flags & ~sa_restorer);
+ ASSERT_EQ(bool(original_sa.sa_flags & sa_restorer), bool(original_sa.sa_restorer));
// Set a traditional sa_handler signal handler.
auto no_op_signal_handler = [](int) {};
@@ -300,6 +301,7 @@
ASSERT_TRUE(sa.sa_handler == no_op_signal_handler);
ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler);
ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK), sa.sa_flags & ~sa_restorer);
+ ASSERT_EQ(bool(sa.sa_flags & sa_restorer), bool(sa.sa_restorer));
// Set a new-style sa_sigaction signal handler.
auto no_op_sigaction = [](int, siginfo_t*, void*) {};
@@ -315,6 +317,7 @@
ASSERT_TRUE(sa.sa_sigaction == no_op_sigaction);
ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler);
ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK | SA_SIGINFO), sa.sa_flags & ~sa_restorer);
+ ASSERT_EQ(bool(sa.sa_flags & sa_restorer), bool(sa.sa_restorer));
// Put everything back how it was.
ASSERT_EQ(0, sigaction_fn(sig, &original_sa, NULL));