Repository navigation
Description
Problem
The wasm64 mmap compatibility wrapper ignores protection and mapping flags and returns ordinary writable linear memory. A PROT_READ request succeeds and can be written through. Its signature currently gives callers no indication that their requested memory protection was not applied.
Starting points: std/sys/wasm64/memory.wave, std/sys/memory.wave.
Reproduction
Executed at 4c3372157d8889fa8bbef0a7ccd2e72aab1c5c6c with Node.js 22.22.1 memory64 and checkout std, O0/O2. Prepare the checkout std alias as below and save the program as probe.wave:
python3 - <<'PYSETUP'
from pathlib import Path
import tempfile
root = Path(tempfile.mkdtemp(prefix="wave-std-audit-"))
for source in Path("std").rglob("*.wave"):
dest = root / source.relative_to("std")
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text(source.read_text().replace('"std::', '"audit_std::'))
Path("/tmp/wave-audit-std-path").write_text(str(root))
PYSETUP
audit_std="$(cat /tmp/wave-audit-std-path)"import("audit_std::sys::memory")::{mmap, munmap, PROT_READ, MAP_PRIVATE, MAP_ANONYMOUS};
fun main() -> i32 {
var p: ptr<i8> = mmap(null, 16, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == null) { return 0; }
deref p = 42;
if (deref p == 42) { munmap(p, 16); return 1; }
return 2;
}
target/debug/wavec build probe.wave --dep "audit_std=$audit_std" --target wasm64-unknown-unknown --out-dir /tmp/wave-mmap-audit --run -O0Observed exit 1 at O0/O2: the read-only request returns a writable allocation.
Scope
Set an explicit supported subset for this wrapper, then reject requests it cannot fulfill. Keep normal sys_alloc/sys_free behavior separate from OS-style mmap options. This is for wasm64-unknown-unknown; it does not require adding a WASI64 ABI or removing existing wasm32 support.
Difficulty: medium.
Completion criteria
- Accepted protection/flag combinations are explicit and tested.
- Unsupported requests return the agreed failure result without consuming allocator space.
- Read/write anonymous allocation, freeing and reuse remain covered under a memory64 runtime.
Design decision needed: Agree on the exact accepted mmap subset and unsupported-request result before changing the compatibility API.
Please mention @LunaStev to discuss the design before starting implementation.
Activity