Allow not copying the wasm binary in wasm-c-api and not referring to the binary in wasm/aot loader (#3389)

Add flag `LoadArgs.clone_wasm_binary` to control whether to clone the wasm/aot
binary in wasm-c-api module. If false, API `wasm_module_new_ex` won't clone the
binary, which may reduce the footprint.

Add flag `LoadArgs.wasm_binary_freeable` to control whether the wasm/aot binary
may be freed after instantiation for wamr API `wasm_runtime_load_ex`, if yes, then
for some running modes, the wasm/aot module doesn't refer to the input binary
again so developer can free it after instantiation to reduce the footprint.

And add API `wasm_module_is_underlying_binary_freeable` and
`wasm_runtime_is_underlying_binary_freeable` to check whether the input binary
can be freed after instantiation for wasm-c-api and wamr api.

And add sample to illustrate it.
This commit is contained in:
Enrico Loparco
2024-05-17 03:00:08 +02:00
committed by GitHub
parent 51ecfd6673
commit 6b1d81650d
14 changed files with 276 additions and 28 deletions

View File

@ -79,12 +79,16 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable (basic src/main.c src/native_impl.c ${UNCOMMON_SHARED_SOURCE})
add_executable (free_buffer_early src/free_buffer_early.c ${UNCOMMON_SHARED_SOURCE})
check_pie_supported()
set_target_properties (basic PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties (free_buffer_early PROPERTIES POSITION_INDEPENDENT_CODE ON)
if (APPLE)
target_link_libraries (basic vmlib -lm -ldl -lpthread)
target_link_libraries (free_buffer_early vmlib -lm -ldl -lpthread)
else ()
target_link_libraries (basic vmlib -lm -ldl -lpthread -lrt)
target_link_libraries (free_buffer_early vmlib -lm -ldl -lpthread -lrt)
endif ()