Repository navigation
wasm2c: Initial implementation of memory64 - #2086
Conversation
dd05345 to
7221bb0
Compare
There was a problem hiding this comment.
I guess it's understandable, but I wish some of the memory64 tests tested growing a memory to
(Edit: or am I missing that somewhere in the tests?)
| uint64_t byte_length = initial_pages * PAGE_SIZE; | ||
| #if WASM_RT_MEMCHECK_SIGNAL_HANDLER | ||
| /* Reserve 8GiB. */ | ||
| void* addr = os_mmap(0x200000000ul); |
There was a problem hiding this comment.
I think we'll have to forbid using WASM_RT_MEMCHECK_SIGNAL_HANDLER (or find some other strategy?) if a memory address+offset is allowed to be more than
There was a problem hiding this comment.
Hmm, yes indeed. I guess maybe we are going to need a WASM_RT_MEMORY64 macro that is defined in memory64 mode.
There was a problem hiding this comment.
How do you feel about landing this simple change, as-is, and then continuing to iterate on full wasm64 in followup PRs? I guess we should probably remove the check mark from the README until later too?
There was a problem hiding this comment.
I don't know how much effort you feel this is worth, but maybe our "dream" solution here would involve:
-
Letting wasm2c emit explicit "sw_checked" versions (i.e. mandatory bounds check) of allocate_memory/grow_memory/free_memory and load and store, on a per-memory basis, depending on decisions made at wasm2c time. @angelamontemayor has already done this part for use in Fixpoint: dfc437b , which you'd be very welcome to take upstream if it proves more broadly useful.
-
By default, wasm2c generates "sw_checked" allocate calls and load/store instructions for 64-bit indexed memories, and keeps the allocates and load/store instructions for 32-bit indexed memories the same (either sw-checked or hw-checked depending on whether we have the signal handler).
-
Optionally, we could imagine wasm2c gets more clever by allocating some guard pages on memory64 memories and then issuing an optimized load/store instruction that only checks the operand in cases where the immediate offset is known to be small enough, as the memory64 overview suggests?
There was a problem hiding this comment.
I don't have a problem landing the simple change, sure, although maybe the 100% safe thing would be to bomb out if memory64 is enabled and WASM_RT_SIGNAL_HANDLER is also set. (And then the memory64 test .txt files would include --cflags="-DWASM_RT_SIGNAL_HANDLER=0" in the args or something.)
Anyway I'm not trying to stand in the way of doing this incrementally, and I'm happy to help port over @angelamontemayor's per-memory safety commit if I can be helpful.
There was a problem hiding this comment.
OK, I decided to revisit this.
For this initial version we don't support WASM_RT_MEMCHECK_SIGNAL_HANDLER at all when memory64 is enabled.
I've used __builtin_add_overflow to check for 64-bit overflow when calculating base + offset in RANGE_CHECK. This means we don't currently support non-clang/non-gcc compiler with wasm2c + memory64.
This keeps this change simple, and we can them improve on things incrementally if we wish.
7221bb0 to
ee1691d
Compare
ee1691d to
01fcb9a
Compare
|
This PR is actually much simpler now, and passes all the memory64 tests. |
|
Still lgtm... |
Note, there are still some issues here that needs to be resolved, mostly about memory sandboxing (bounds checking). Since this is still experimental I've also added a `--experimental` flag to wasm2c that is required in addition to passing `--enable-memory64`.
01fcb9a to
33f4c21
Compare
Note, there are still some issues here that needs to be resolved, mostly about memory sandboxing (bounds checking). Since this is still experimental I've also added a `--experimental` flag to wasm2c that is required in addition to passing `--enable-memory64`.
I mistakenly broke the wasm2c test runner in #2086. I guess we need tests for our test runner..
I mistakenly broke the wasm2c test runner in #2086. I guess we need tests for our test runner..
I mistakenly broke the wasm2c test runner in #2086. I guess we need tests for our test runner..
`run-spec-wasm2c.py` skips a test on Windows when memory64 is enabled. That skip was written when memory64 was opt-in (`--enable-memory64`, #2086). Since #2837 memory64 is on by default (`--disable-memory64`), so the condition holds for almost every test and 260 of the 262 wasm2c tests are skipped on `windows-latest`: the C that wasm2c writes is not compiled by cl.exe. This removes the skip. Split out of #2901 at @sbc100's request.
No description provided.