Skip to content

Conversation

kylo5aby
Copy link
Contributor

@kylo5aby kylo5aby commented Sep 8, 2025

In scenarios that require permission control, users may want to know if a Wasm app has the authority to use the native APIs it's about to import. To address this, we've added a callback that executes when the Wasm module loads an imported function.

  • add a callback execute API
  • add a sample to demonstrate how to use it.

@lum1n0us lum1n0us added the enhancement Check if this issue/PR enhances a feature; scripts will use this info. label Sep 9, 2025
@kylo5aby kylo5aby force-pushed the import-callback branch 2 times, most recently from bd8d4ae to a3578eb Compare September 10, 2025 10:08
Copy link
Collaborator

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we should add some description in the comments of wasm_runtime_get_import_xxx() in wasm_export.h, perhaps introducing this sample.

Need to execute samples in CI.

cd build
cmake ..
make
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a section on how to run. Additionally, I believe we can simplify the execution by removing those options.

target_link_libraries (import-func-callback vmlib -lm -ldl -lpthread ${LLVM_AVAILABLE_LIBS})
else ()
target_link_libraries (import-func-callback vmlib -lm -ldl -lpthread -lrt ${LLVM_AVAILABLE_LIBS})
endif ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing CMake to generate Wasm.

@kylo5aby kylo5aby force-pushed the import-callback branch 3 times, most recently from ab0d448 to 500e809 Compare September 11, 2025 05:01
@yamt
Copy link
Collaborator

yamt commented Sep 11, 2025

the ci failure doesn't seem like a fault of this PR.
cf. #4616

@@ -1526,6 +1526,8 @@ wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
/**
* Get the number of import items for a WASM module
*
* Example usage (as shown in samples/import-func-callback)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe,

Suggested change
* Example usage (as shown in samples/import-func-callback)
* Example usage (as wasm_runtime_for_each_import_func() in samples/import-func-callback)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe,
resolved. thanks

@kylo5aby kylo5aby changed the title Add imported functions callback execute API Add imported functions callback samples Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Check if this issue/PR enhances a feature; scripts will use this info.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants