Skip to content
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

wasm_application_execute_func does not return the return value #3840

Open
greenaddress opened this issue Oct 5, 2024 · 0 comments
Open

wasm_application_execute_func does not return the return value #3840

greenaddress opened this issue Oct 5, 2024 · 0 comments

Comments

@greenaddress
Copy link

greenaddress commented Oct 5, 2024

Thanks for filing a bug or defect report! Please fill out the TODOs below.

Subject of the issue

Describe the bug or defect here.

When calling wasm_application_execute_func the returned value is not passed back to the caller.

Test case

Upload the related wasm file, wast file or the source files if you can.

int32_t run_me(void) {
return 10;
}

You can't get 10 by calling wasm_application_execute_func and looking in argv[0] for it.

Your environment

  • Linux
  • WAMR version 2.1.2, platform, cpu architecture, running mode, etc.

Steps to reproduce

Tell us how to reproduce this bug or defect.

Expected behavior

Tell us what should happen
argv[0] should have the returned value of the function, at least for simple types (i32 for example)

Actual behavior

Tell us what happens instead

Extra Info

Anything else you'd like to add?

a patch that works at least for i32 is

diff --git i/core/iwasm/common/wasm_application.c w/core/iwasm/common/wasm_application.c
index 3b3be16c..42a21a99 100644
--- i/core/iwasm/common/wasm_application.c
+++ w/core/iwasm/common/wasm_application.c
@@ -685,6 +685,10 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
         goto fail;
     }
 
+    if (argv && type->result_count == 1 && type->types[type->param_count] == VALUE_TYPE_I32)
+        /* copy the return value */
+        *(int *)argv = (int)argv1[0];
+
 #if WASM_ENABLE_GC != 0
     ref_type_map = type->result_ref_type_maps;
 #endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant