-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix large pointers from WASM #3310
Conversation
9094c36
to
2b0803e
Compare
Hmm, looking at the changes to the reference files it might be simpler to remove |
Also it looks like the multithreading tests aren't happy about gg-alloc. I tried writing tests for this without using it, but I couldn't figure out how to force allocations above 2GB in the test environment without being extremely slow. If anyone has ideas for that let me know. |
Thanks! And yeah I think it's fine to fix without tests for now, allocating 2G in the browser tests is likely going to cause flakiness as well. |
Pointers being passed from WASM to JS are interpreted as signed, so large pointers ended up negative. This prevented WASM programs from allocating more than 2GB. To fix it we make all pointers unsigned (via >>> 0) for all malloc/realloc calls and inside shim functions. Ideally we would have an abstraction that guarantees we catch all cases, but that would require a major refactor. To test it we add gg-alloc as an optional system allocator for wasm-bindgen-test. It only allocates in the upper 2GB range and was made to test this exact issue but was never upstreamed. Fixes rustwasm#2388 Fixes rustwasm#2957
I decided to only change stuff in I also made gg-alloc an optional feature for wasm-bindgen-test, and with it the tests now pass, and they fail if I remove the fix. |
Thanks for fixing this - we run into this issue problem frequently in our memory intensive application. Any plans for a new release with this critical fix? 🙏 EDIT we've worked around it for now with out own fork, so no stress from our side. For others that want this: just use See https://github.com/rerun-io/wasm-bindgen/commits/0.2.84-patch |
Pointers being passed from WASM to JS are interpreted as signed, so large pointers ended up negative. This prevented WASM programs from allocating more than 2GB. To fix it we make all pointers unsigned (via >>> 0) for all malloc/realloc calls and inside shim functions. Ideally we would have an abstraction that guarantees we catch all cases, but that would require a major refactor. To test it we add gg-alloc as an optional system allocator for wasm-bindgen-test. It only allocates in the upper 2GB range and was made to test this exact issue but was never upstreamed. Fixes rustwasm#2388 Fixes rustwasm#2957
@kristoff3r @alexcrichton quick question: does this fix double the available memory from 2GB to 4GB, or does it increase the cap beyond 4GB (to what?)? As a secondary (slightly off-topic) question, what's the release process like? Once wasm-bindgen is given a release, do we also have to wait for wasm-pack to update to the latest wasm-bindgen, or is wasm-pack's version unrelated to wasm-bindgen's version? Thanks! |
Only to 4GB. Beyond 4GB requires wasm64 support. |
Pointers being passed from WASM to JS are interpreted as signed, so large pointers ended up negative. This prevented WASM programs from allocating more than 2GB.
To fix it we make pointer use unsigned (via >>> 0) for all malloc/realloc calls, and for all pointer arguments while generating the shim functions. Ideally there would be an abstraction that guarantees we do it in all cases, but that would require a major refactor.
To test it we use gg-alloc as the global allocator while running tests. This allocator was made specifically for testing this issue, but was never upstreamed. It only allocates memory above 2GiB.
Fixes #2388
Fixes #2957