Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0] [wasi] Work around WASI's mmap implementation not returning aligned m… #92061

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/mono/mono/utils/mono-mmap-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mono_setmmapjit (int flag)
/* Ignored on HOST_WASM */
}

void*
mono_valloc (void *addr, size_t size, int flags, MonoMemAccountType type)
static void*
valloc_impl (void *addr, size_t size, int flags, MonoMemAccountType type)
{
void *ptr;
int mflags = 0;
Expand Down Expand Up @@ -119,6 +119,19 @@ mono_valloc (void *addr, size_t size, int flags, MonoMemAccountType type)
return ptr;
}

void*
mono_valloc (void *addr, size_t size, int flags, MonoMemAccountType type)
{
#if HOST_WASI
// WASI implements mmap using malloc, so the returned address is not page aligned
// and our code depends on it
g_assert (!addr);
return mono_valloc_aligned (size, mono_pagesize (), flags, type);
#else
return valloc_impl (addr, size, flags, type);
#endif
}

static GHashTable *valloc_hash;

typedef struct {
Expand All @@ -130,7 +143,7 @@ void*
mono_valloc_aligned (size_t size, size_t alignment, int flags, MonoMemAccountType type)
{
/* Allocate twice the memory to be able to put the block on an aligned address */
char *mem = (char *) mono_valloc (NULL, size + alignment, flags, type);
char *mem = (char *) valloc_impl (NULL, size + alignment, flags, type);
char *aligned;

if (!mem)
Expand Down
Loading