-
Notifications
You must be signed in to change notification settings - Fork 15
Question regarding _innative_to_c #23
Description
Hi,
I do have a question regarding conversion between linear memory addresses and C addresses.
Say I have an embedding library that exposes a print function. void print(const char*)
The wasm binary relies on the following import
(type (;0;) (func (param i32)))
(import "env" "print" (func (;0;) (type 0)))
If I just call print like this from wasm print("Hello, world!");
The print function is called with the address in linear memory, unfortunately I didn't find a way to implement the conversion from linear memory to the actual address space from inside the embedding library.
There is the helper function _innative_to_c but it's an intrisic that is only usable in wasm code.
So, at the moment the only way I found to make this work is to change the print function signature to take a i64 parameter and have the wasm module do the conversion like so print(_innative_to_c("Hello, world!"));
But this comes with a few caveats
- We need to write the call to the _innative_to_c function each time (I don't really want to impose this constraint on whoever writes a wasm module for my app)
- We need to disable ENV_CHECK_MEMORY_ACCESS and whitelist _innative_to_c (I don't want to compromise on sandboxing or expose to much to the wasm module)
Is there a way to do that conversion from the embedding library ? conceptually it would make more sense since the API we expose to the wasm code only deals with linear memory.