iwasm: call native lib init/deinit if exists (#2439)
This commit is contained in:
@ -284,6 +284,8 @@ validate_env_str(char *env)
|
||||
#if BH_HAS_DLFCN
|
||||
typedef uint32 (*get_native_lib_func)(char **p_module_name,
|
||||
NativeSymbol **p_native_symbols);
|
||||
typedef int (*init_native_lib_func)(void);
|
||||
typedef void (*deinit_native_lib_func)(void);
|
||||
|
||||
static uint32
|
||||
load_and_register_native_libs(const char **native_lib_list,
|
||||
@ -304,6 +306,18 @@ load_and_register_native_libs(const char **native_lib_list,
|
||||
continue;
|
||||
}
|
||||
|
||||
init_native_lib_func init_native_lib = dlsym(handle, "init_native_lib");
|
||||
if (init_native_lib) {
|
||||
int ret = init_native_lib();
|
||||
if (ret != 0) {
|
||||
LOG_WARNING("warning: `init_native_lib` function from native "
|
||||
"lib %s failed with %d",
|
||||
native_lib_list[i], ret);
|
||||
dlclose(handle);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* lookup get_native_lib func */
|
||||
get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib");
|
||||
if (!get_native_lib) {
|
||||
@ -368,6 +382,12 @@ unregister_and_unload_native_libs(uint32 native_lib_count,
|
||||
continue;
|
||||
}
|
||||
|
||||
deinit_native_lib_func deinit_native_lib =
|
||||
dlsym(handle, "deinit_native_lib");
|
||||
if (deinit_native_lib) {
|
||||
deinit_native_lib();
|
||||
}
|
||||
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user