@@ -1413,6 +1413,36 @@ create_export_funcs(AOTModuleInstance *module_inst, AOTModule *module,
1413
1413
return true;
1414
1414
}
1415
1415
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
+
1416
1446
static bool
1417
1447
create_exports (AOTModuleInstance * module_inst , AOTModule * module ,
1418
1448
char * error_buf , uint32 error_buf_size )
@@ -1439,6 +1469,19 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module,
1439
1469
}
1440
1470
}
1441
1471
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
+
1442
1485
return create_export_funcs (module_inst , module , error_buf , error_buf_size );
1443
1486
}
1444
1487
@@ -2082,6 +2125,11 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
2082
2125
if (module_inst -> export_functions )
2083
2126
wasm_runtime_free (module_inst -> export_functions );
2084
2127
2128
+ #if WASM_ENABLE_MULTI_MEMORY != 0
2129
+ if (module_inst -> export_memories )
2130
+ wasm_runtime_free (module_inst -> export_memories );
2131
+ #endif
2132
+
2085
2133
if (extra -> functions ) {
2086
2134
uint32 func_idx ;
2087
2135
for (func_idx = 0 ; func_idx < extra -> function_count ; ++ func_idx ) {
0 commit comments