diff options
| author | Mike Pall <mike> | 2020-07-13 11:54:08 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2020-07-13 11:54:08 +0200 |
| commit | 570e758ca7dd14f93efdd43d68cf8979c1d7f984 (patch) | |
| tree | ac4f36ff252ee6a290a982a13a4cfb161bbd1a0b /src | |
| parent | 60ac12ed6fd612c84359d50ef3ceb3cfc85f7045 (diff) | |
| download | luajit-570e758ca7dd14f93efdd43d68cf8979c1d7f984.tar.gz luajit-570e758ca7dd14f93efdd43d68cf8979c1d7f984.tar.bz2 luajit-570e758ca7dd14f93efdd43d68cf8979c1d7f984.zip | |
Handle old OSX/iOS without getentropy().
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_prng.c | 18 |
1 files 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; | |||
| 107 | #if LJ_TARGET_LINUX | 107 | #if LJ_TARGET_LINUX |
| 108 | /* Avoid a dependency on glibc 2.25+ and use the getrandom syscall instead. */ | 108 | /* Avoid a dependency on glibc 2.25+ and use the getrandom syscall instead. */ |
| 109 | #include <sys/syscall.h> | 109 | #include <sys/syscall.h> |
| 110 | #elif LJ_TARGET_OSX || LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN | 110 | #else |
| 111 | |||
| 112 | #if LJ_TARGET_OSX | ||
| 113 | #include <Availability.h> | ||
| 114 | #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 || \ | ||
| 115 | __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000 | ||
| 116 | #define LJ_TARGET_HAS_GETENTROPY 1 | ||
| 117 | #endif | ||
| 118 | #elif LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN | ||
| 119 | #define LJ_TARGET_HAS_GETENTROPY 1 | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #if LJ_TARGET_HAS_GETENTROPY | ||
| 111 | extern int getentropy(void *buf, size_t len); | 123 | extern int getentropy(void *buf, size_t len); |
| 112 | #ifdef __ELF__ | 124 | #ifdef __ELF__ |
| 113 | __attribute__((weak)) | 125 | __attribute__((weak)) |
| @@ -115,6 +127,8 @@ extern int getentropy(void *buf, size_t len); | |||
| 115 | ; | 127 | ; |
| 116 | #endif | 128 | #endif |
| 117 | 129 | ||
| 130 | #endif | ||
| 131 | |||
| 118 | /* For the /dev/urandom fallback. */ | 132 | /* For the /dev/urandom fallback. */ |
| 119 | #include <fcntl.h> | 133 | #include <fcntl.h> |
| 120 | #include <unistd.h> | 134 | #include <unistd.h> |
| @@ -181,7 +195,7 @@ int LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs) | |||
| 181 | if (syscall(SYS_getrandom, rs->u, sizeof(rs->u), 0) == (long)sizeof(rs->u)) | 195 | if (syscall(SYS_getrandom, rs->u, sizeof(rs->u), 0) == (long)sizeof(rs->u)) |
| 182 | goto ok; | 196 | goto ok; |
| 183 | 197 | ||
| 184 | #elif LJ_TARGET_OSX || LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN | 198 | #elif LJ_TARGET_HAS_GETENTROPY |
| 185 | 199 | ||
| 186 | #ifdef __ELF__ | 200 | #ifdef __ELF__ |
| 187 | if (getentropy && getentropy(rs->u, sizeof(rs->u)) == 0) | 201 | if (getentropy && getentropy(rs->u, sizeof(rs->u)) == 0) |
