Skip to content

Commit eac35ed

Browse files
[wasm] Stop using mprotect(PROT_NONE) on WASI
we had been using a stub weak definition of `mprotect` in wasm/missing.c so far, but wasi-sdk 23 added mprotect emulation to wasi-libc[^1], so the emulation is now linked instead. However, the emulation doesn't support PROT_NONE and fails with ENOSYS, so we need to avoid calling mprotect completely on WASI. [^1]: WebAssembly/wasi-libc@7528b13
1 parent 4f7dfbe commit eac35ed

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

cont.c

+3
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ fiber_pool_expand(struct fiber_pool * fiber_pool, size_t count)
551551
VirtualFree(allocation->base, 0, MEM_RELEASE);
552552
rb_raise(rb_eFiberError, "can't set a guard page: %s", ERRNOMSG);
553553
}
554+
#elif defined(__wasi__)
555+
// wasi-libc's mprotect emulation doesn't support PROT_NONE.
556+
(void)page;
554557
#else
555558
if (mprotect(page, RB_PAGE_SIZE, PROT_NONE) < 0) {
556559
munmap(allocation->base, count*stride);

gc/default/default.c

+4
Original file line numberDiff line numberDiff line change
@@ -3199,6 +3199,10 @@ protect_page_body(struct heap_page_body *body, DWORD protect)
31993199
DWORD old_protect;
32003200
return VirtualProtect(body, HEAP_PAGE_SIZE, protect, &old_protect) != 0;
32013201
}
3202+
#elif defined(__wasi__)
3203+
// wasi-libc's mprotect emulation does not support PROT_NONE
3204+
enum {HEAP_PAGE_LOCK, HEAP_PAGE_UNLOCK};
3205+
#define protect_page_body(body, protect) 1
32023206
#else
32033207
enum {HEAP_PAGE_LOCK = PROT_NONE, HEAP_PAGE_UNLOCK = PROT_READ | PROT_WRITE};
32043208
#define protect_page_body(body, protect) !mprotect((body), HEAP_PAGE_SIZE, (protect))

wasm/missing.c

-7
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ umask(rb_mode_t mask)
119119
return 0;
120120
}
121121

122-
WASM_MISSING_LIBC_FUNC
123-
int
124-
mprotect(const void *addr, size_t len, int prot)
125-
{
126-
return 0;
127-
}
128-
129122
WASM_MISSING_LIBC_FUNC
130123
int
131124
pclose(FILE *stream)

0 commit comments

Comments
 (0)