-
Notifications
You must be signed in to change notification settings - Fork 574
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 to load and run another wasm in a running wasm? #3433
Comments
Hi, for the first one, could you check whether the native method is called successfully (e.g. add a printf in the native method), and whether the exception is thrown when calling For the second one, please refer to samples/multi-module. |
It is a little confusing that it runs good in Ubuntu while failed in your environment. What target and what platform do you use? And did you create another exec_env to call the app's method? BTW, for multi-module, maybe you can try |
target:windows10 The compilation of wasm is completed using the following: Code: |
In the thread created by method A, should not call wasm_runtime_init and wasm_runtime_init_thread_env again since they have been inited. Could you try removing them? |
This is the A method:
} ` If remove wasm_runtime_init_thread_env and wasm_runtime_init method,an error will occur when run wasm_runtime_instantiate: |
Don't remove wasm_runtime_init_thread_env in ThreadLoadWasm as the thread is not created by runtime, and ensure that wasm_runtime_destroy_thread_env is called before ThreadLoadWasm returns. And keep removing wasm_runtime_init and wasm_runtime_destroy int ThreadLoadWasm since we just need to init runtime one time. BTW, will the first module instance exits before ThreadLoadWasm calls the wasm function? Since |
Is it better to create threads using the 'wasm_runtime_spawn_thread' function? Maybe the printf method can display msg since the first module can use printf to display msg. The first module will not exit before ThreadLoadWasm calls the wasm function. |
No, if the thread is to run a function of the same module instance that the thread belongs to, I think we had better use Could you print string param and buffer1 to ensure they are correct in the code below before calling wasm function: int bufLen = strlen((char*)param)+1;
char* buffer1 = NULL;
uint32_t wasmBuffer = wasm_runtime_module_malloc(wasm_module_inst, bufLen, (void**)&buffer1);
if (wasmBuffer != 0)
{
uint32_t argv[2];
strncpy(buffer1, (char*)param, bufLen);
argv[0] = wasmBuffer; /* pass the buffer address for WASM space */
argv[1] = bufLen;
if (!wasm_runtime_call_wasm(exec_env, init, 2, argv)) BTW, did you add |
Could you check whether the pointers of param are the same to ensure that the pointer is correctly passed into NativeApi_Print? e.g. in ThreadLoadWasm, before calling wasm function, and in NativeApi_Print. |
How to load and run another wasm application in a running wasm?
The text was updated successfully, but these errors were encountered: