From e6c7125851d6302668ee358cce755c2d2e87a53f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 13 Oct 2022 19:33:06 +0900 Subject: [PATCH] export_native_api.md: Partially revert "Relax the ground rule" (#1588) And add some clarifications --- doc/export_native_api.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/export_native_api.md b/doc/export_native_api.md index 7b7dd17d..b87d9255 100644 --- a/doc/export_native_api.md +++ b/doc/export_native_api.md @@ -189,12 +189,22 @@ void foo2(wasm_exec_env_t exec_env, The runtime builder should ensure not broking the memory sandbox when exporting the native function to WASM. +A ground rule: + +- Do the pointer address conversion in the native API if "$\*" is not used for the pointer in the function signature + A few recommendations: - Never pass any structure/class object pointer to native (do data serialization instead) -- Do the pointer address conversion in the native API if "$\*" is not used for the pointer in the function signature - Never pass a function pointer to the native +Note: while not recommended here, nothing prevents you from passing +structure/function pointers as far as the native API is aware of +and careful about the ABI used in the wasm module. For example, +C function pointers are usually represented as table indexes which +the native API can call with wasm_runtime_call_indirect() or similar. +However, in this document, we don't recommend to implement your native +API that way unless necessary because it needs extra carefulness. ## Pass structured data or class object