From 570e758ca7dd14f93efdd43d68cf8979c1d7f984 Mon Sep 17 00:00:00 2001
From: Mike Pall <mike>
Date: Mon, 13 Jul 2020 11:54:08 +0200
Subject: Handle old OSX/iOS without getentropy().

---
 src/lj_prng.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/lj_prng.c b/src/lj_prng.c
index c24fe630..a8b8b6de 100644
--- a/src/lj_prng.c
+++ b/src/lj_prng.c
@@ -107,7 +107,19 @@ static PRGR libfunc_rgr;
 #if LJ_TARGET_LINUX
 /* Avoid a dependency on glibc 2.25+ and use the getrandom syscall instead. */
 #include <sys/syscall.h>
-#elif LJ_TARGET_OSX || LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN
+#else
+
+#if LJ_TARGET_OSX
+#include <Availability.h>
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 || \
+    __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
+#define LJ_TARGET_HAS_GETENTROPY	1
+#endif
+#elif LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN
+#define LJ_TARGET_HAS_GETENTROPY	1
+#endif
+
+#if LJ_TARGET_HAS_GETENTROPY
 extern int getentropy(void *buf, size_t len);
 #ifdef __ELF__
   __attribute__((weak))
@@ -115,6 +127,8 @@ extern int getentropy(void *buf, size_t len);
 ;
 #endif
 
+#endif
+
 /* For the /dev/urandom fallback. */
 #include <fcntl.h>
 #include <unistd.h>
@@ -181,7 +195,7 @@ int LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs)
   if (syscall(SYS_getrandom, rs->u, sizeof(rs->u), 0) == (long)sizeof(rs->u))
     goto ok;
 
-#elif LJ_TARGET_OSX || LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN
+#elif LJ_TARGET_HAS_GETENTROPY
 
 #ifdef __ELF__
   if (getentropy && getentropy(rs->u, sizeof(rs->u)) == 0)
-- 
cgit v1.2.3-55-g6feb