-
Notifications
You must be signed in to change notification settings - Fork 5
Description
It would be nice to be able to bounds-check accesses in a single operation. For example, an i32.load access at address 5 to a memory with length 7 must trap, and it would be nice to just be able to compare 5 to a limit instead of separately comparing 5 and 5+sizeof(u32) to a limit. I am assuming that with 1-byte pages, we get no OS support.
@eqrion suggested having an instance store memory limits for different-sized accesses, so in our example the limit for 32-bit accesses on a memory with length 7 would be 3; you just compare 5 against 3. This is a neat solution that works as long as the length is at least as long as the access size, or if the max size is set such that we can do signed comparisons. However I think as written the spec supports length=0, length=1, length=2^32-1, and also length=2^64-1 for memory64 configurations.
I have a terrible proposal :) Perhaps people have already considered it. Anyway, considering that the JS embedding specifies a max page count of 65536 (for memory32), I propose to keep the max page count to that size for 1-byte pages. It minimizes complexity for bounds checks, because we can do a simple signed comparison in all cases. If it is too constraining, we can raise it, but perhaps not to the whole address space.