Port to WebAssembly

This commit is contained in:
Frank Denis 2019-07-10 20:23:20 +02:00
parent 8dc0b5345b
commit 9129ab0f64
5 changed files with 51 additions and 1 deletions

View file

@ -148,6 +148,10 @@ uintptr_t _mi_random_shuffle(uintptr_t x) {
}
uintptr_t _mi_random_init(uintptr_t seed /* can be zero */) {
#ifdef __wasi__ // no ASLR when using WebAssembly, and time granularity may be coarse
uintptr_t x;
arc4random_buf(&x, sizeof x);
#else
// Hopefully, ASLR makes our function address random
uintptr_t x = (uintptr_t)((void*)&_mi_random_init);
x ^= seed;
@ -169,6 +173,7 @@ uintptr_t _mi_random_init(uintptr_t seed /* can be zero */) {
for (uintptr_t i = 0; i < max; i++) {
x = _mi_random_shuffle(x);
}
#endif
return x;
}
@ -269,7 +274,9 @@ static bool _mi_heap_done(void) {
// to set up the thread local keys.
// --------------------------------------------------------
#ifndef _WIN32
#ifdef __wasi__
// no pthreads in the WebAssembly Standard Interface
#elif !defined(_WIN32)
#define MI_USE_PTHREADS
#endif
@ -290,6 +297,8 @@ static bool _mi_heap_done(void) {
static void mi_pthread_done(void* value) {
if (value!=NULL) mi_thread_done();
}
#elif defined(__wasi__)
// no pthreads in the WebAssembly Standard Interface
#else
#pragma message("define a way to call mi_thread_done when a thread is done")
#endif