WebAssembly / wabt

The WebAssembly Binary Toolkit
Apache License 2.0
6.91k stars 702 forks source link

wasm2c: parametrize memory bounds checks on a per-memory basis #2507

Open keithw opened 2 weeks ago

keithw commented 2 weeks ago

(Sequenced behind #2506)

This PR allows "software-bounds-checked" memories and "guard-page-checked" memories to coexist in the same module.

It creates two versions of every memory operation: an unrestricted version (that works with any memory) and a _default32 version (for memories with default page size and i32 indexing).

The unrestricted version calls MEMCHECK_GENERAL, which does a 64-bit software RANGE_CHECK to check that the operation reads/writes within the bounds of the memory.

The _default32 version calls MEMCHECK_DEFAULT32, which is the same as the old MEMCHECK: if the runtime declares WASM_RT_MEMCHECK_GUARD_PAGES, it will do nothing. Otherwise it will do a 32-bit software RANGE_CHECK (which seems to be one less instruction than the 64-bit RANGE_CHECK).

This is a stepping stone to supporting custom-page-sizes (which will need to be software bounds-checked) (#2508).

keithw commented 1 week ago

@sbc100 Did you want to review this one? @shravanrn would prefer to land #2506 and #2507 together, so I was planning to wait until everybody is comfortable with this one before merging either.