@@ -90,8 +90,8 @@ mono_setmmapjit (int flag)
9090 /* Ignored on HOST_WASM */
9191}
9292
93- void *
94- mono_valloc (void * addr , size_t size , int flags , MonoMemAccountType type )
93+ static void *
94+ valloc_impl (void * addr , size_t size , int flags , MonoMemAccountType type )
9595{
9696 void * ptr ;
9797 int mflags = 0 ;
@@ -119,6 +119,19 @@ mono_valloc (void *addr, size_t size, int flags, MonoMemAccountType type)
119119 return ptr ;
120120}
121121
122+ void *
123+ mono_valloc (void * addr , size_t size , int flags , MonoMemAccountType type )
124+ {
125+ #if HOST_WASI
126+ // WASI implements mmap using malloc, so the returned address is not page aligned
127+ // and our code depends on it
128+ g_assert (!addr );
129+ return mono_valloc_aligned (size , mono_pagesize (), flags , type );
130+ #else
131+ return valloc_impl (addr , size , flags , type );
132+ #endif
133+ }
134+
122135static GHashTable * valloc_hash ;
123136
124137typedef struct {
@@ -130,7 +143,7 @@ void*
130143mono_valloc_aligned (size_t size , size_t alignment , int flags , MonoMemAccountType type )
131144{
132145 /* Allocate twice the memory to be able to put the block on an aligned address */
133- char * mem = (char * ) mono_valloc (NULL , size + alignment , flags , type );
146+ char * mem = (char * ) valloc_impl (NULL , size + alignment , flags , type );
134147 char * aligned ;
135148
136149 if (!mem )
0 commit comments