@@ -91,6 +91,9 @@ wasm_runtime_destroy_registered_module_list();
9191
9292#define E_TYPE_XIP 4
9393
94+ static uint8
95+ val_type_to_val_kind (uint8 value_type );
96+
9497#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
9598/* Initialize externref hashmap */
9699static bool
@@ -1900,6 +1903,67 @@ wasm_runtime_set_module_inst(WASMExecEnv *exec_env,
19001903 wasm_exec_env_set_module_inst (exec_env , module_inst );
19011904}
19021905
1906+ bool
1907+ wasm_runtime_get_export_global_inst (WASMModuleInstanceCommon * const module_inst ,
1908+ char const * name ,
1909+ wasm_global_inst_t * global_inst )
1910+ {
1911+ #if WASM_ENABLE_INTERP != 0
1912+ if (module_inst -> module_type == Wasm_Module_Bytecode ) {
1913+ const WASMModuleInstance * wasm_module_inst =
1914+ (const WASMModuleInstance * )module_inst ;
1915+ const WASMModule * wasm_module = wasm_module_inst -> module ;
1916+ uint32 i ;
1917+ for (i = 0 ; i < wasm_module -> export_count ; i ++ ) {
1918+ const WASMExport * wasm_export = & wasm_module -> exports [i ];
1919+ if ((wasm_export -> kind == WASM_IMPORT_EXPORT_KIND_GLOBAL )
1920+ && !strcmp (wasm_export -> name , name )) {
1921+ const WASMModuleInstanceExtra * e =
1922+ (WASMModuleInstanceExtra * )wasm_module_inst -> e ;
1923+ const WASMGlobalInstance * global =
1924+ & e -> globals [wasm_export -> index ];
1925+ global_inst -> kind = val_type_to_val_kind (global -> type );
1926+ global_inst -> is_mutable = global -> is_mutable ;
1927+ #if WASM_ENABLE_MULTI_MODULE == 0
1928+ global_inst -> global_data =
1929+ wasm_module_inst -> global_data + global -> data_offset ;
1930+ #else
1931+ global_inst -> global_data =
1932+ global -> import_global_inst
1933+ ? global -> import_module_inst -> global_data
1934+ + global -> import_global_inst -> data_offset
1935+ : wasm_module_inst -> global_data + global -> data_offset ;
1936+ #endif
1937+ return true;
1938+ }
1939+ }
1940+ }
1941+ #endif
1942+ #if WASM_ENABLE_AOT != 0
1943+ if (module_inst -> module_type == Wasm_Module_AoT ) {
1944+ const AOTModuleInstance * aot_module_inst =
1945+ (AOTModuleInstance * )module_inst ;
1946+ const AOTModule * aot_module = (AOTModule * )aot_module_inst -> module ;
1947+ uint32 i ;
1948+ for (i = 0 ; i < aot_module -> export_count ; i ++ ) {
1949+ const AOTExport * aot_export = & aot_module -> exports [i ];
1950+ if ((aot_export -> kind == WASM_IMPORT_EXPORT_KIND_GLOBAL )
1951+ && !strcmp (aot_export -> name , name )) {
1952+ const AOTGlobal * global =
1953+ & aot_module -> globals [aot_export -> index ];
1954+ global_inst -> kind = val_type_to_val_kind (global -> type .val_type );
1955+ global_inst -> is_mutable = global -> type .is_mutable ;
1956+ global_inst -> global_data =
1957+ aot_module_inst -> global_data + global -> data_offset ;
1958+ return true;
1959+ }
1960+ }
1961+ }
1962+ #endif
1963+
1964+ return false;
1965+ }
1966+
19031967void *
19041968wasm_runtime_get_function_attachment (WASMExecEnv * exec_env )
19051969{
0 commit comments