@@ -340,9 +340,6 @@ tables_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
340
340
static void
341
341
memories_deinstantiate (AOTModuleInstance * module_inst )
342
342
{
343
- #ifdef WASM_LINEAR_MEMORY_MMAP
344
- uint64 map_size ;
345
- #endif
346
343
uint32 i ;
347
344
AOTMemoryInstance * memory_inst ;
348
345
@@ -364,23 +361,7 @@ memories_deinstantiate(AOTModuleInstance *module_inst)
364
361
}
365
362
366
363
if (memory_inst -> memory_data ) {
367
- #ifndef OS_ENABLE_HW_BOUND_CHECK
368
- #ifdef WASM_LINEAR_MEMORY_MMAP
369
- if (shared_memory_is_shared (memory_inst )) {
370
- map_size = (uint64 )memory_inst -> num_bytes_per_page
371
- * memory_inst -> max_page_count ;
372
- wasm_munmap_linear_memory (memory_inst -> memory_data ,
373
- map_size , map_size );
374
- }
375
- else
376
- #endif
377
- wasm_runtime_free (memory_inst -> memory_data );
378
- #else
379
- map_size = (uint64 )memory_inst -> num_bytes_per_page
380
- * memory_inst -> cur_page_count ;
381
- wasm_munmap_linear_memory (memory_inst -> memory_data , map_size ,
382
- 8 * (uint64 )BH_GB );
383
- #endif
364
+ wasm_deallocate_linear_memory (memory_inst );
384
365
}
385
366
}
386
367
}
@@ -402,14 +383,10 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
402
383
uint32 heap_offset = num_bytes_per_page * init_page_count ;
403
384
uint64 memory_data_size , max_memory_data_size ;
404
385
uint8 * p = NULL , * global_addr ;
405
- #ifdef WASM_LINEAR_MEMORY_MMAP
406
- uint8 * mapped_mem = NULL ;
407
- uint64 map_size ;
408
- #endif
409
386
387
+ bool is_shared_memory = false;
410
388
#if WASM_ENABLE_SHARED_MEMORY != 0
411
- bool is_shared_memory = memory -> memory_flags & 0x02 ? true : false;
412
-
389
+ is_shared_memory = memory -> memory_flags & 0x02 ? true : false;
413
390
/* Shared memory */
414
391
if (is_shared_memory && parent != NULL ) {
415
392
AOTMemoryInstance * shared_memory_instance ;
@@ -519,55 +496,18 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
519
496
module -> aux_stack_size );
520
497
LOG_VERBOSE (" heap offset: %u, heap size: %d\n" , heap_offset , heap_size );
521
498
522
- memory_data_size = (uint64 )num_bytes_per_page * init_page_count ;
523
499
max_memory_data_size = (uint64 )num_bytes_per_page * max_page_count ;
524
- bh_assert (memory_data_size <= UINT32_MAX );
525
500
bh_assert (max_memory_data_size <= 4 * (uint64 )BH_GB );
526
501
(void )max_memory_data_size ;
527
502
528
- #ifndef OS_ENABLE_HW_BOUND_CHECK
529
- #if WASM_ENABLE_SHARED_MEMORY != 0
530
- if (is_shared_memory ) {
531
- #if WASM_ENABLE_SHARED_MEMORY_MMAP != 0
532
- map_size = max_memory_data_size ;
533
- if (max_memory_data_size > 0
534
- && !(p = mapped_mem =
535
- wasm_mmap_linear_memory (map_size , & max_memory_data_size ,
536
- error_buf , error_buf_size ))) {
537
- return NULL ;
538
- }
539
- #else
540
- /* Allocate maximum memory size when memory is shared */
541
- if (max_memory_data_size > 0
542
- && !(p = runtime_malloc (max_memory_data_size , error_buf ,
543
- error_buf_size ))) {
544
- return NULL ;
545
- }
546
- #endif
547
- }
548
- else
549
- #endif /* end of WASM_ENABLE_SHARED_MEMORY != 0 */
550
- {
551
- /* Allocate initial memory size when memory is not shared */
552
- if (memory_data_size > 0
553
- && !(p = runtime_malloc (memory_data_size , error_buf ,
554
- error_buf_size ))) {
555
- return NULL ;
556
- }
557
- }
558
- #else /* else of OS_ENABLE_HW_BOUND_CHECK */
559
- /* Totally 8G is mapped, the opcode load/store address range is 0 to 8G:
560
- * ea = i + memarg.offset
561
- * both i and memarg.offset are u32 in range 0 to 4G
562
- * so the range of ea is 0 to 8G
563
- */
564
- map_size = 8 * (uint64 )BH_GB ;
565
- if (!(p = mapped_mem = wasm_mmap_linear_memory (
566
- map_size , & memory_data_size , error_buf , error_buf_size ))) {
567
- set_error_buf (error_buf , error_buf_size , "mmap memory failed" );
503
+ if (wasm_allocate_linear_memory (& p , is_shared_memory , num_bytes_per_page ,
504
+ init_page_count , max_page_count ,
505
+ & memory_data_size )
506
+ != BHT_OK ) {
507
+ set_error_buf (error_buf , error_buf_size ,
508
+ "allocate linear memory failed" );
568
509
return NULL ;
569
510
}
570
- #endif /* end of OS_ENABLE_HW_BOUND_CHECK */
571
511
572
512
memory_inst -> module_type = Wasm_Module_AoT ;
573
513
memory_inst -> num_bytes_per_page = num_bytes_per_page ;
@@ -617,16 +557,8 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
617
557
if (heap_size > 0 )
618
558
wasm_runtime_free (memory_inst -> heap_handle );
619
559
fail1 :
620
- #ifdef WASM_LINEAR_MEMORY_MMAP
621
- if (mapped_mem )
622
- wasm_munmap_linear_memory (mapped_mem , memory_data_size , map_size );
623
- else
624
- #endif
625
- {
626
- if (memory_inst -> memory_data )
627
- wasm_runtime_free (memory_inst -> memory_data );
628
- }
629
- memory_inst -> memory_data = NULL ;
560
+ wasm_deallocate_linear_memory (memory_inst );
561
+
630
562
return NULL ;
631
563
}
632
564
0 commit comments