WebAssembly/wasi-libc

Support `mprotect` in wasi-emulated-mman

Closed this issue · 6 comments

Is there any interest in supporting mprotect in the emulation library? The main utility would be to compile programming language runtimes that link, but not execute at runtime, a JIT (what prompted me to write the issue was LLVM, similar to #447).

I think the semantics should be that mapping in-bounds memory is only possible as PROT_READ|PROT_WRITE, and out-of-bounds memory as PROT_NONE.

That sounds reasonable to me. I'm not sure about the PROT_NONE case because memory.grow can cause previously out-of-bounds memory to become in-bounds, but allowing PROT_READ|PROT_WRITE for in-bounds memory sounds fine.

How do you find out the current memory size from C?

__builtin_wasm_memory_size(0) returns the number of 64KiB pages currently allocated (in memory 0).

Thanks. Do you think mprotect should require the address to be page-aligned, or should it accept just any? I'm leaning towards the latter since it's a stub anyways.

It looks like POSIX requires the address to be page-aligned so I chose to do that.

This is now implemented in #500.