-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Web assembly permanently breaks after calling function with large string #11135
Comments
If you want to pass a string to WebAssembly you somehow need to serialize
that string into the WebAssembly memory. You cannot pass JavaScript object
such as strings directly to WebAssembly.
See:
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
|
On your link I see this:
Doesn't that mean that I can pass a string? |
Oh sorry, I didn't that you are using cwrap. My apologies. Presumably you have some code that created the It looks to me like this should work. I think we should be able to create a test case from it and figure out what is going wrong. |
Yep!
|
If I'm not mistaken, that 5-megabyte string is being allocated onto the stack by It looks like the current |
Also, for strings |
Oh, I see.
How can I increase the stack size?
How can I malloc and pass a pointer to the string before even entering the C code? |
The stack size is controlled by the If you want to pass huge strings that exceed that stack size the perhaps To allocate space you should be able to call |
That fixed the 500MB case, but it doesn't let me increase the stack size past 2GB:
Oh thanks! Unfortunately it seems like I'm still limited to a maximum of 4GB total memory?
|
WebAssembly uses 32-bit pointers, so it there is literally no way to address more than 4Gb. Furthermore, if you want o run on the web you are currently limited practically to a lot less than this. |
Oh, I see. I guess that's it then. Should I leave this issue open so someone can add a check to fix the permanent break and print a nice error message? |
It turns out our normal stack checks fail to catch this, leading to the confusing error: WebAssembly/binaryen#2850 However, you should get a better error message using asan with |
-- the Emscripten ccall passes args on the stack (which is about 5Mb in size) -- if a FITS header is too large, it blows the stack -- see: emscripten-core/emscripten#11135 -- so we allocate space on the heap, copy the header, and pass the heap ptr -- (similar technique used in zscale) -- also, parameterize the size of hlength passed to initwcs (def: 256000)
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
I'm trying to make a WASM string parser from C but when I call the function with a large string it breaks. Not only that, all future calls to all WASM functions (with
ccall
/cwrap
) break!This is my C code:
Simple, right?
This is my compilation string, I added all the possible fixes I found online but none of them worked:
And this is what running looks like
And then when I try to call it again with the string that worked the first time, it no longer works!
The text was updated successfully, but these errors were encountered: