@@ -1413,6 +1413,36 @@ create_export_funcs(AOTModuleInstance *module_inst, AOTModule *module,
14131413 return true;
14141414}
14151415
1416+ #if WASM_ENABLE_MULTI_MEMORY != 0
1417+ static WASMExportMemInstance *
1418+ export_memories_instantiate (const AOTModule * module ,
1419+ AOTModuleInstance * module_inst ,
1420+ uint32 export_mem_count , char * error_buf ,
1421+ uint32 error_buf_size )
1422+ {
1423+ WASMExportMemInstance * export_memories , * export_memory ;
1424+ AOTExport * export = module -> exports ;
1425+ uint32 i ;
1426+ uint64 total_size =
1427+ sizeof (WASMExportMemInstance ) * (uint64 )export_mem_count ;
1428+
1429+ if (!(export_memory = export_memories =
1430+ runtime_malloc (total_size , error_buf , error_buf_size ))) {
1431+ return NULL ;
1432+ }
1433+
1434+ for (i = 0 ; i < module -> export_count ; i ++ , export ++ )
1435+ if (export -> kind == EXPORT_KIND_MEMORY ) {
1436+ export_memory -> name = export -> name ;
1437+ export_memory -> memory = module_inst -> memories [export -> index ];
1438+ export_memory ++ ;
1439+ }
1440+
1441+ bh_assert ((uint32 )(export_memory - export_memories ) == export_mem_count );
1442+ return export_memories ;
1443+ }
1444+ #endif /* end of if WASM_ENABLE_MULTI_MEMORY != 0 */
1445+
14161446static bool
14171447create_exports (AOTModuleInstance * module_inst , AOTModule * module ,
14181448 char * error_buf , uint32 error_buf_size )
@@ -1439,6 +1469,19 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module,
14391469 }
14401470 }
14411471
1472+ #if WASM_ENABLE_MULTI_MEMORY == 0
1473+ bh_assert (module_inst -> export_memory_count <= 1 );
1474+ #else
1475+ if (module_inst -> export_memory_count ) {
1476+ module_inst -> export_memories = export_memories_instantiate (
1477+ module , module_inst , module_inst -> export_memory_count , error_buf ,
1478+ error_buf_size );
1479+ if (!module_inst -> export_memories ) {
1480+ return false;
1481+ }
1482+ }
1483+ #endif
1484+
14421485 return create_export_funcs (module_inst , module , error_buf , error_buf_size );
14431486}
14441487
@@ -2082,6 +2125,11 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
20822125 if (module_inst -> export_functions )
20832126 wasm_runtime_free (module_inst -> export_functions );
20842127
2128+ #if WASM_ENABLE_MULTI_MEMORY != 0
2129+ if (module_inst -> export_memories )
2130+ wasm_runtime_free (module_inst -> export_memories );
2131+ #endif
2132+
20852133 if (extra -> functions ) {
20862134 uint32 func_idx ;
20872135 for (func_idx = 0 ; func_idx < extra -> function_count ; ++ func_idx ) {
0 commit comments