mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 19:38:41 +03:00
Port to WebAssembly
This commit is contained in:
parent
8dc0b5345b
commit
9129ab0f64
5 changed files with 51 additions and 1 deletions
11
src/init.c
11
src/init.c
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue