From 401012952d13f966f7cd04d41725619a9c8caf02 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 30 Apr 2019 15:05:10 -0700 Subject: [PATCH] Declare getentropy in Some systems, such as Darwin, only declare getentropy in , so declare it there on WASI too for compatibility. Also, give getentropy the underscore-prefix/weak-symbol treatment, as it's not a standard-reserved identifier. --- expected/wasm32-wasi/defined-symbols.txt | 1 + expected/wasm32-wasi/predefined-macros.txt | 2 -- libc-bottom-half/sources/getentropy.c | 3 ++- libc-top-half/musl/include/sys/random.h | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt index c974a13..4a4294f 100644 --- a/expected/wasm32-wasi/defined-symbols.txt +++ b/expected/wasm32-wasi/defined-symbols.txt @@ -80,6 +80,7 @@ __fwritex __fwriting __get_locale __getdelim +__getentropy __getopt_msg __gmtime_r __hwcap diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt index 59e83c5..f4e8591 100644 --- a/expected/wasm32-wasi/predefined-macros.txt +++ b/expected/wasm32-wasi/predefined-macros.txt @@ -711,8 +711,6 @@ #define GLOB_NOSPACE 1 #define GLOB_NOSYS 4 #define GLOB_PERIOD 0x80 -#define GRND_NONBLOCK 0x0001 -#define GRND_RANDOM 0x0002 #define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) + (numsrc) * sizeof(struct sockaddr_storage)) #define HFIXEDSZ NS_HFIXEDSZ #define HIBITL MINLONG diff --git a/libc-bottom-half/sources/getentropy.c b/libc-bottom-half/sources/getentropy.c index 83bee6e..cb5eb5f 100644 --- a/libc-bottom-half/sources/getentropy.c +++ b/libc-bottom-half/sources/getentropy.c @@ -6,7 +6,7 @@ #error With threads support, getentropy is not intended to be a cancellation point. #endif -int getentropy(void *buffer, size_t len) { +int __getentropy(void *buffer, size_t len) { if (len > 256) { errno = EIO; return -1; @@ -21,3 +21,4 @@ int getentropy(void *buffer, size_t len) { return 0; } +extern __typeof(__getentropy) getentropy __attribute__((weak, alias("__getentropy"))); diff --git a/libc-top-half/musl/include/sys/random.h b/libc-top-half/musl/include/sys/random.h index 4ee7bf2..0920425 100644 --- a/libc-top-half/musl/include/sys/random.h +++ b/libc-top-half/musl/include/sys/random.h @@ -4,6 +4,7 @@ extern "C" { #endif +#ifdef __wasilibc_unmodified_upstream /* WASI has no getrandom, but it does have getentropy */ #define __NEED_size_t #define __NEED_ssize_t #include @@ -12,6 +13,12 @@ extern "C" { #define GRND_RANDOM 0x0002 ssize_t getrandom(void *, size_t, unsigned); +#else +#define __NEED_size_t +#include + +int getentropy(void *, size_t); +#endif #ifdef __cplusplus } -- 2.39.5