Sfoglia il codice sorgente

libc-emcc: Use alternate method to check getrandom support (#3848)

Benbuck Nason 1 anno fa
parent
commit
2b5e2d9c2c
1 ha cambiato i file con 10 aggiunte e 6 eliminazioni
  1. 10 6
      core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c

+ 10 - 6
core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c

@@ -7,8 +7,13 @@
 #include "bh_log.h"
 #include "wasm_export.h"
 #include "../interpreter/wasm.h"
-#if !defined(_DEFAULT_SOURCE) && !defined(BH_PLATFORM_LINUX_SGX)
-#include "sys/syscall.h"
+
+#if defined(__linux__)
+#include <linux/version.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
+#define HAVE_SYSCALL_GETRANDOM
+#include <sys/syscall.h>
+#endif
 #endif
 
 /* clang-format off */
@@ -270,11 +275,10 @@ getentropy_wrapper(wasm_exec_env_t exec_env, void *buffer, uint32 length)
 {
     if (buffer == NULL)
         return -1;
-#if defined(_DEFAULT_SOURCE) || defined(BH_PLATFORM_LINUX_SGX) \
-    || defined(__APPLE__)
-    return getentropy(buffer, length);
-#else
+#if defined(HAVE_SYSCALL_GETRANDOM)
     return syscall(SYS_getrandom, buffer, length, 0);
+#else
+    return getentropy(buffer, length);
 #endif
 }