Add wasm_runtime_unregister_natives (#1647)

Allow to unregister (or unload) the previously registered native libs,
so that no need to restart the whole engine by using
`wasm_runtime_destroy/wasm_runtime_init`.
This commit is contained in:
YAMAMOTO Takashi
2022-10-28 12:03:39 +09:00
committed by GitHub
parent bc58778c34
commit 77ff7daaf4
6 changed files with 96 additions and 4 deletions

View File

@ -356,6 +356,26 @@ wasm_native_register_natives_raw(const char *module_name,
true);
}
bool
wasm_native_unregister_natives(const char *module_name,
NativeSymbol *native_symbols)
{
NativeSymbolsNode **prevp;
NativeSymbolsNode *node;
prevp = &g_native_symbols_list;
while ((node = *prevp) != NULL) {
if (node->native_symbols == native_symbols
&& !strcmp(node->module_name, module_name)) {
*prevp = node->next;
wasm_runtime_free(node);
return true;
}
prevp = &node->next;
}
return false;
}
bool
wasm_native_init()
{

View File

@ -64,6 +64,10 @@ wasm_native_register_natives_raw(const char *module_name,
NativeSymbol *native_symbols,
uint32 n_native_symbols);
bool
wasm_native_unregister_natives(const char *module_name,
NativeSymbol *native_symbols);
bool
wasm_native_init();

View File

@ -2904,6 +2904,13 @@ wasm_runtime_register_natives_raw(const char *module_name,
n_native_symbols);
}
bool
wasm_runtime_unregister_natives(const char *module_name,
NativeSymbol *native_symbols)
{
return wasm_native_unregister_natives(module_name, native_symbols);
}
bool
wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
const WASMType *func_type, const char *signature,

View File

@ -864,6 +864,11 @@ wasm_runtime_register_natives_raw(const char *module_name,
NativeSymbol *native_symbols,
uint32 n_native_symbols);
/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_unregister_natives(const char *module_name,
NativeSymbol *native_symbols);
bool
wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
const WASMType *func_type, const char *signature,

View File

@ -972,6 +972,24 @@ wasm_runtime_register_natives_raw(const char *module_name,
NativeSymbol *native_symbols,
uint32_t n_native_symbols);
/**
* Undo wasm_runtime_register_natives or wasm_runtime_register_natives_raw
*
* @param module_name Should be the same as the corresponding
* wasm_runtime_register_natives.
* (Same in term of strcmp.)
*
* @param native_symbols Should be the same as the corresponding
* wasm_runtime_register_natives.
* (Same in term of pointer comparison.)
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_unregister_natives(const char *module_name,
NativeSymbol *native_symbols);
/**
* Get attachment of native function from execution environment
*