-
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
How should I access the WebAssembly.Memory instance? #19832
Comments
I think Line 55 in 8b5c868
It might get renamed or such as this isn't a public API, but in general it should be ok to use. |
I'm guessing I'll need to explicitly export this like the functions from preamble? |
If you want to access it from outside of the Emscripten JS, then yes. Using |
Doesn't seem to be working, maybe it needs to be an accessor function? |
Hmm, maybe I'm not sure how you are trying to use it? This is the impact of that flag: $ ./emcc test/hello_world.c -O3 --profiling
$ ./emcc test/hello_world.c -O3 --profiling -o b.out.js -sEXPORTED_RUNTIME_METHODS=wasmMemory
$ diff a.out.js b.out.js
276c276
< wasmBinaryFile = "a.out.wasm";
---
> wasmBinaryFile = "b.out.wasm";
496a497,498
>
> Module["wasmMemory"] = wasmMemory; That flag exports it, so accessing |
I've tried Module["wasmMemory"] and Module["asm"]["wasmMemory"] and they're both undefined in a single-threaded build. I added wasmMemory to the list of exported runtime methods right next to ccall, cwrap, etc. I'll see if maybe something is wrong with our build system. |
Are you using If you are using |
Specifically the |
Also, I guess |
I found our .rsp file and it contains:
So I think I'm doing the right thing. Your PR looks good to me. I haven't tried |
Yeah, checking the rsp we are compiling in modularized mode. |
|
i.e. |
An accessor function like getMemory() would fix this, since it would get the current value, right? |
Indeed, and in fact and accessor function would be necessary if one wanted to import it like For the time being it would get easy to just write your own accessory function in |
I managed to get somewhere by exporting an accessor in my pre js, but I'm getting an error I don't know how to make sense of:
Is this something I need to change in my emcc configuration, or do I need to change how I'm generating my modules? |
Ah, I see the binary encoding for memory limits was changed to add a new shared flag, so that's what I'm missing. And it looks like the module now will have an explicit maximum memory size and I'll need to match it when generating... so I'll need to make sure I have a way to match what emcc generates there. |
I'm jitting WASM modules inside of a running emscripten-compiled application, which means I need to grab the function table and heap to share them with the jitted code.
In a single-threaded app this seems to work fine, but I'm having trouble getting the Memory object in a threaded app. I've been doing
Module["asm"]["memory"]
but that doesn't seem to work. How should I be doing this? Looking through the code in the emscripten repo I wasn't able to figure it out.EDIT: To be clear, in the threaded app I get 'error: memory import must be a WebAssembly.Memory object'.
The text was updated successfully, but these errors were encountered: