You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a global variable in wasm static memory that is initialized with a call to function. That function is native function linked from the host. This native function is called during wasm_runtime_instantiate, before it returns. That means, that the function is called before I have access to the instance pointer returned from wasm_runtime_instantiate. Therefore I cannot use wasm_runtime_set_user_data on the execute env in the instance. However, I need the user data pointer inside the native function.
// snippet of host c++ code for the instantiation
String err;
instance = wasm_runtime_instantiate(module->module, 1'000'000, 1'000'000, err.rawData(), err.MaxLength - 100); // the native function is called within wasm_runtime_instantiateif (!instance)
throw;
exec = wasm_runtime_get_exec_env_singleton(instance);
if (!exec)
throw;
wasm_runtime_set_user_data(exec, this); // before I get the chance to call this
I hope the description of the example is clear?
Is there a solution to this problem?
If not, possible solution is to split wasm_runtime_instantiate into two functions, where the first returns the instance pointer, and the second initializes the global memory inside the wasm, while calling the native functions.
Note, that passing user data pointer to wasm_runtime_instantiate would be insufficient, as that would not allow me to initialize the instance pointer.
The text was updated successfully, but these errors were encountered:
malytomas
changed the title
wasm_runtime_instantiate calls native function, which needs access to instance pointer
wasm_runtime_instantiate calls native function, which needs access to user data pointer
Jan 19, 2025
Assume this c++ code compiled to wasm.
There is a global variable in wasm static memory that is initialized with a call to function. That function is native function linked from the host. This native function is called during wasm_runtime_instantiate, before it returns. That means, that the function is called before I have access to the instance pointer returned from wasm_runtime_instantiate. Therefore I cannot use wasm_runtime_set_user_data on the execute env in the instance. However, I need the user data pointer inside the native function.
I hope the description of the example is clear?
Is there a solution to this problem?
If not, possible solution is to split wasm_runtime_instantiate into two functions, where the first returns the instance pointer, and the second initializes the global memory inside the wasm, while calling the native functions.
Note, that passing user data pointer to wasm_runtime_instantiate would be insufficient, as that would not allow me to initialize the instance pointer.
The text was updated successfully, but these errors were encountered: