From e1f6516fdade536905ebbcf76d4f7f1911019359 Mon Sep 17 00:00:00 2001 From: Daan Date: Sat, 2 Mar 2024 17:05:29 -0800 Subject: [PATCH] Fix undefined symbol errors when building for wasi #758, by @anuraaga --- include/mimalloc/internal.h | 6 ++++++ src/os.c | 4 ---- src/prim/wasi/prim.c | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index 40401736..21cb42bf 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -296,6 +296,12 @@ static inline uintptr_t _mi_align_up(uintptr_t sz, size_t alignment) { } } +// Align a pointer upwards +static inline void* mi_align_up_ptr(void* p, size_t alignment) { + return (void*)_mi_align_up((uintptr_t)p, alignment); +} + + // Divide upwards: `s <= _mi_divide_up(s,d)*d < s+d`. static inline uintptr_t _mi_divide_up(uintptr_t size, size_t divider) { mi_assert_internal(divider != 0); diff --git a/src/os.c b/src/os.c index 69ad2bf9..b98950a4 100644 --- a/src/os.c +++ b/src/os.c @@ -73,10 +73,6 @@ void _mi_os_init(void) { bool _mi_os_decommit(void* addr, size_t size, mi_stats_t* stats); bool _mi_os_commit(void* addr, size_t size, bool* is_zero, mi_stats_t* tld_stats); -static void* mi_align_up_ptr(void* p, size_t alignment) { - return (void*)_mi_align_up((uintptr_t)p, alignment); -} - static inline uintptr_t _mi_align_down(uintptr_t sz, size_t alignment) { mi_assert_internal(alignment != 0); uintptr_t mask = alignment - 1; diff --git a/src/prim/wasi/prim.c b/src/prim/wasi/prim.c index 50511f0b..f74acd2a 100644 --- a/src/prim/wasi/prim.c +++ b/src/prim/wasi/prim.c @@ -12,6 +12,9 @@ terms of the MIT license. A copy of the license can be found in the file #include "mimalloc/atomic.h" #include "mimalloc/prim.h" +#include // fputs +#include // getenv + //--------------------------------------------- // Initialize //--------------------------------------------- @@ -40,6 +43,8 @@ int _mi_prim_free(void* addr, size_t size ) { //--------------------------------------------- #if defined(MI_USE_SBRK) + #include // for sbrk + static void* mi_memory_grow( size_t size ) { void* p = sbrk(size); if (p == (void*)(-1)) return NULL;