@@ -50,7 +50,7 @@ bh_static_assert(offsetof(AOTModuleInstance, cur_exception)
50
50
bh_static_assert (offsetof(AOTModuleInstance , global_table_data )
51
51
== 13 * sizeof (uint64 ) + 128 + 11 * sizeof (uint64 ));
52
52
53
- bh_static_assert (sizeof (AOTMemoryInstance ) == 104 );
53
+ bh_static_assert (sizeof (AOTMemoryInstance ) == 112 );
54
54
bh_static_assert (offsetof(AOTTableInstance , elems ) == 24 );
55
55
56
56
bh_static_assert (offsetof(AOTModuleInstanceExtra , stack_sizes ) == 0 );
@@ -792,9 +792,10 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
792
792
uint32 max_page_count =
793
793
wasm_runtime_get_max_mem (max_memory_pages , memory -> mem_init_page_count ,
794
794
memory -> mem_max_page_count );
795
- uint32 inc_page_count , aux_heap_base , global_idx ;
795
+ uint32 inc_page_count , global_idx ;
796
796
uint32 bytes_of_last_page , bytes_to_page_end ;
797
- uint32 heap_offset = num_bytes_per_page * init_page_count ;
797
+ uint64 aux_heap_base ,
798
+ heap_offset = (uint64 )num_bytes_per_page * init_page_count ;
798
799
uint64 memory_data_size , max_memory_data_size ;
799
800
uint8 * p = NULL , * global_addr ;
800
801
@@ -819,6 +820,15 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
819
820
heap_size = 0 ;
820
821
}
821
822
823
+ /* If initial memory is the largest size allowed, disallowing insert host
824
+ * managed heap */
825
+ if (heap_size > 0 && heap_offset == MAX_LINEAR_MEMORY_SIZE ) {
826
+ set_error_buf (error_buf , error_buf_size ,
827
+ "failed to insert app heap into linear memory, "
828
+ "try using `--heap-size=0` option" );
829
+ return NULL ;
830
+ }
831
+
822
832
if (init_page_count == max_page_count && init_page_count == 1 ) {
823
833
/* If only one page and at most one page, we just append
824
834
the app heap to the end of linear memory, enlarge the
@@ -842,7 +852,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
842
852
}
843
853
else if (module -> aux_heap_base_global_index != (uint32 )- 1
844
854
&& module -> aux_heap_base
845
- < num_bytes_per_page * init_page_count ) {
855
+ < ( uint64 ) num_bytes_per_page * init_page_count ) {
846
856
/* Insert app heap before __heap_base */
847
857
aux_heap_base = module -> aux_heap_base ;
848
858
bytes_of_last_page = aux_heap_base % num_bytes_per_page ;
@@ -869,15 +879,15 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
869
879
- module -> import_global_count ;
870
880
global_addr = module_inst -> global_data
871
881
+ module -> globals [global_idx ].data_offset ;
872
- * (uint32 * )global_addr = aux_heap_base ;
882
+ * (uint32 * )global_addr = ( uint32 ) aux_heap_base ;
873
883
LOG_VERBOSE ("Reset __heap_base global to %u" , aux_heap_base );
874
884
}
875
885
else {
876
886
/* Insert app heap before new page */
877
887
inc_page_count =
878
888
(heap_size + num_bytes_per_page - 1 ) / num_bytes_per_page ;
879
- heap_offset = num_bytes_per_page * init_page_count ;
880
- heap_size = num_bytes_per_page * inc_page_count ;
889
+ heap_offset = ( uint64 ) num_bytes_per_page * init_page_count ;
890
+ heap_size = ( uint64 ) num_bytes_per_page * inc_page_count ;
881
891
if (heap_size > 0 )
882
892
heap_size -= 1 * BH_KB ;
883
893
}
@@ -889,19 +899,9 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
889
899
"try using `--heap-size=0` option" );
890
900
return NULL ;
891
901
}
892
- else if (init_page_count == DEFAULT_MAX_PAGES ) {
893
- num_bytes_per_page = UINT32_MAX ;
894
- init_page_count = max_page_count = 1 ;
895
- }
896
902
if (max_page_count > DEFAULT_MAX_PAGES )
897
903
max_page_count = DEFAULT_MAX_PAGES ;
898
904
}
899
- else { /* heap_size == 0 */
900
- if (init_page_count == DEFAULT_MAX_PAGES ) {
901
- num_bytes_per_page = UINT32_MAX ;
902
- init_page_count = max_page_count = 1 ;
903
- }
904
- }
905
905
906
906
LOG_VERBOSE ("Memory instantiate:" );
907
907
LOG_VERBOSE (" page bytes: %u, init pages: %u, max pages: %u" ,
@@ -911,7 +911,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
911
911
LOG_VERBOSE (" heap offset: %u, heap size: %d\n" , heap_offset , heap_size );
912
912
913
913
max_memory_data_size = (uint64 )num_bytes_per_page * max_page_count ;
914
- bh_assert (max_memory_data_size <= 4 * ( uint64 ) BH_GB );
914
+ bh_assert (max_memory_data_size <= MAX_LINEAR_MEMORY_SIZE );
915
915
(void )max_memory_data_size ;
916
916
917
917
if (wasm_allocate_linear_memory (& p , is_shared_memory , num_bytes_per_page ,
@@ -927,11 +927,11 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
927
927
memory_inst -> num_bytes_per_page = num_bytes_per_page ;
928
928
memory_inst -> cur_page_count = init_page_count ;
929
929
memory_inst -> max_page_count = max_page_count ;
930
- memory_inst -> memory_data_size = ( uint32 ) memory_data_size ;
930
+ memory_inst -> memory_data_size = memory_data_size ;
931
931
932
932
/* Init memory info */
933
933
memory_inst -> memory_data = p ;
934
- memory_inst -> memory_data_end = p + ( uint32 ) memory_data_size ;
934
+ memory_inst -> memory_data_end = p + memory_data_size ;
935
935
936
936
/* Initialize heap info */
937
937
memory_inst -> heap_data = p + heap_offset ;
@@ -1098,7 +1098,7 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
1098
1098
1099
1099
if (memory_inst -> memory_data ) {
1100
1100
bh_memcpy_s ((uint8 * )memory_inst -> memory_data + base_offset ,
1101
- memory_inst -> memory_data_size - base_offset ,
1101
+ ( uint32 ) memory_inst -> memory_data_size - base_offset ,
1102
1102
data_seg -> bytes , length );
1103
1103
}
1104
1104
}
@@ -2472,23 +2472,26 @@ execute_free_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
2472
2472
return ret ;
2473
2473
}
2474
2474
2475
- uint32
2475
+ uint64
2476
2476
aot_module_malloc_internal (AOTModuleInstance * module_inst ,
2477
- WASMExecEnv * exec_env , uint32 size ,
2477
+ WASMExecEnv * exec_env , uint64 size ,
2478
2478
void * * p_native_addr )
2479
2479
{
2480
2480
AOTMemoryInstance * memory_inst = aot_get_default_memory (module_inst );
2481
2481
AOTModule * module = (AOTModule * )module_inst -> module ;
2482
2482
uint8 * addr = NULL ;
2483
2483
uint32 offset = 0 ;
2484
2484
2485
+ /* TODO: Memory64 size check based on memory idx type */
2486
+ bh_assert (size <= UINT32_MAX );
2487
+
2485
2488
if (!memory_inst ) {
2486
2489
aot_set_exception (module_inst , "uninitialized memory" );
2487
2490
return 0 ;
2488
2491
}
2489
2492
2490
2493
if (memory_inst -> heap_handle ) {
2491
- addr = mem_allocator_malloc (memory_inst -> heap_handle , size );
2494
+ addr = mem_allocator_malloc (memory_inst -> heap_handle , ( uint32 ) size );
2492
2495
}
2493
2496
else if (module -> malloc_func_index != (uint32 )- 1
2494
2497
&& module -> free_func_index != (uint32 )- 1 ) {
@@ -2513,7 +2516,7 @@ aot_module_malloc_internal(AOTModuleInstance *module_inst,
2513
2516
2514
2517
if (!malloc_func
2515
2518
|| !execute_malloc_function (module_inst , exec_env , malloc_func ,
2516
- retain_func , size , & offset )) {
2519
+ retain_func , ( uint32 ) size , & offset )) {
2517
2520
return 0 ;
2518
2521
}
2519
2522
addr = offset ? (uint8 * )memory_inst -> memory_data + offset : NULL ;
@@ -2532,17 +2535,21 @@ aot_module_malloc_internal(AOTModuleInstance *module_inst,
2532
2535
}
2533
2536
if (p_native_addr )
2534
2537
* p_native_addr = addr ;
2535
- return (uint32 )(addr - memory_inst -> memory_data );
2538
+ return (uint64 )(addr - memory_inst -> memory_data );
2536
2539
}
2537
2540
2538
- uint32
2541
+ uint64
2539
2542
aot_module_realloc_internal (AOTModuleInstance * module_inst ,
2540
- WASMExecEnv * exec_env , uint32 ptr , uint32 size ,
2543
+ WASMExecEnv * exec_env , uint64 ptr , uint64 size ,
2541
2544
void * * p_native_addr )
2542
2545
{
2543
2546
AOTMemoryInstance * memory_inst = aot_get_default_memory (module_inst );
2544
2547
uint8 * addr = NULL ;
2545
2548
2549
+ /* TODO: Memory64 ptr and size check based on memory idx type */
2550
+ bh_assert (ptr <= UINT32_MAX );
2551
+ bh_assert (size <= UINT32_MAX );
2552
+
2546
2553
if (!memory_inst ) {
2547
2554
aot_set_exception (module_inst , "uninitialized memory" );
2548
2555
return 0 ;
@@ -2551,7 +2558,8 @@ aot_module_realloc_internal(AOTModuleInstance *module_inst,
2551
2558
if (memory_inst -> heap_handle ) {
2552
2559
addr = mem_allocator_realloc (
2553
2560
memory_inst -> heap_handle ,
2554
- ptr ? memory_inst -> memory_data + ptr : NULL , size );
2561
+ (uint32 )ptr ? memory_inst -> memory_data + (uint32 )ptr : NULL ,
2562
+ (uint32 )size );
2555
2563
}
2556
2564
2557
2565
/* Only support realloc in WAMR's app heap */
@@ -2570,12 +2578,12 @@ aot_module_realloc_internal(AOTModuleInstance *module_inst,
2570
2578
2571
2579
if (p_native_addr )
2572
2580
* p_native_addr = addr ;
2573
- return (uint32 )(addr - memory_inst -> memory_data );
2581
+ return (uint64 )(addr - memory_inst -> memory_data );
2574
2582
}
2575
2583
2576
2584
void
2577
2585
aot_module_free_internal (AOTModuleInstance * module_inst , WASMExecEnv * exec_env ,
2578
- uint32 ptr )
2586
+ uint64 ptr )
2579
2587
{
2580
2588
AOTMemoryInstance * memory_inst = aot_get_default_memory (module_inst );
2581
2589
AOTModule * module = (AOTModule * )module_inst -> module ;
@@ -2584,8 +2592,11 @@ aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
2584
2592
return ;
2585
2593
}
2586
2594
2595
+ /* TODO: Memory64 ptr and size check based on memory idx type */
2596
+ bh_assert (ptr <= UINT32_MAX );
2597
+
2587
2598
if (ptr ) {
2588
- uint8 * addr = memory_inst -> memory_data + ptr ;
2599
+ uint8 * addr = memory_inst -> memory_data + ( uint32 ) ptr ;
2589
2600
uint8 * memory_data_end ;
2590
2601
2591
2602
/* memory->memory_data_end may be changed in memory grow */
@@ -2616,44 +2627,49 @@ aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
2616
2627
free_func = aot_lookup_function (module_inst , "__unpin" , "(i)i" );
2617
2628
2618
2629
if (free_func )
2619
- execute_free_function (module_inst , exec_env , free_func , ptr );
2630
+ execute_free_function (module_inst , exec_env , free_func ,
2631
+ (uint32 )ptr );
2620
2632
}
2621
2633
}
2622
2634
}
2623
2635
2624
- uint32
2625
- aot_module_malloc (AOTModuleInstance * module_inst , uint32 size ,
2636
+ uint64
2637
+ aot_module_malloc (AOTModuleInstance * module_inst , uint64 size ,
2626
2638
void * * p_native_addr )
2627
2639
{
2628
2640
return aot_module_malloc_internal (module_inst , NULL , size , p_native_addr );
2629
2641
}
2630
2642
2631
- uint32
2632
- aot_module_realloc (AOTModuleInstance * module_inst , uint32 ptr , uint32 size ,
2643
+ uint64
2644
+ aot_module_realloc (AOTModuleInstance * module_inst , uint64 ptr , uint64 size ,
2633
2645
void * * p_native_addr )
2634
2646
{
2635
2647
return aot_module_realloc_internal (module_inst , NULL , ptr , size ,
2636
2648
p_native_addr );
2637
2649
}
2638
2650
2639
2651
void
2640
- aot_module_free (AOTModuleInstance * module_inst , uint32 ptr )
2652
+ aot_module_free (AOTModuleInstance * module_inst , uint64 ptr )
2641
2653
{
2642
2654
aot_module_free_internal (module_inst , NULL , ptr );
2643
2655
}
2644
2656
2645
- uint32
2657
+ uint64
2646
2658
aot_module_dup_data (AOTModuleInstance * module_inst , const char * src ,
2647
- uint32 size )
2659
+ uint64 size )
2648
2660
{
2649
2661
char * buffer ;
2650
- uint32 buffer_offset =
2651
- aot_module_malloc (module_inst , size , (void * * )& buffer );
2662
+ uint64 buffer_offset ;
2663
+
2664
+ /* TODO: Memory64 size check based on memory idx type */
2665
+ bh_assert (size <= UINT32_MAX );
2666
+
2667
+ buffer_offset = aot_module_malloc (module_inst , size , (void * * )& buffer );
2652
2668
2653
2669
if (buffer_offset != 0 ) {
2654
2670
buffer = wasm_runtime_addr_app_to_native (
2655
2671
(WASMModuleInstanceCommon * )module_inst , buffer_offset );
2656
- bh_memcpy_s (buffer , size , src , size );
2672
+ bh_memcpy_s (buffer , ( uint32 ) size , src , ( uint32 ) size );
2657
2673
}
2658
2674
return buffer_offset ;
2659
2675
}
@@ -2935,7 +2951,7 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
2935
2951
2936
2952
bool
2937
2953
aot_check_app_addr_and_convert (AOTModuleInstance * module_inst , bool is_str ,
2938
- uint32 app_buf_addr , uint32 app_buf_size ,
2954
+ uint64 app_buf_addr , uint64 app_buf_size ,
2939
2955
void * * p_native_addr )
2940
2956
{
2941
2957
bool ret ;
@@ -2999,7 +3015,7 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
2999
3015
}
3000
3016
3001
3017
if (!wasm_runtime_validate_app_addr ((WASMModuleInstanceCommon * )module_inst ,
3002
- dst , len ))
3018
+ ( uint64 ) dst , ( uint64 ) len ))
3003
3019
return false;
3004
3020
3005
3021
if ((uint64 )offset + (uint64 )len > seg_len ) {
@@ -3008,10 +3024,11 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
3008
3024
}
3009
3025
3010
3026
maddr = wasm_runtime_addr_app_to_native (
3011
- (WASMModuleInstanceCommon * )module_inst , dst );
3027
+ (WASMModuleInstanceCommon * )module_inst , ( uint64 ) dst );
3012
3028
3013
3029
SHARED_MEMORY_LOCK (memory_inst );
3014
- bh_memcpy_s (maddr , memory_inst -> memory_data_size - dst , data + offset , len );
3030
+ bh_memcpy_s (maddr , (uint32 )(memory_inst -> memory_data_size - dst ),
3031
+ data + offset , len );
3015
3032
SHARED_MEMORY_UNLOCK (memory_inst );
3016
3033
return true;
3017
3034
}
@@ -3030,14 +3047,14 @@ aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index)
3030
3047
3031
3048
#if WASM_ENABLE_THREAD_MGR != 0
3032
3049
bool
3033
- aot_set_aux_stack (WASMExecEnv * exec_env , uint32 start_offset , uint32 size )
3050
+ aot_set_aux_stack (WASMExecEnv * exec_env , uint64 start_offset , uint32 size )
3034
3051
{
3035
3052
AOTModuleInstance * module_inst = (AOTModuleInstance * )exec_env -> module_inst ;
3036
3053
AOTModule * module = (AOTModule * )module_inst -> module ;
3037
3054
3038
3055
uint32 stack_top_idx = module -> aux_stack_top_global_index ;
3039
- uint32 data_end = module -> aux_data_end ;
3040
- uint32 stack_bottom = module -> aux_stack_bottom ;
3056
+ uint64 data_end = module -> aux_data_end ;
3057
+ uint64 stack_bottom = module -> aux_stack_bottom ;
3041
3058
bool is_stack_before_data = stack_bottom < data_end ? true : false;
3042
3059
3043
3060
/* Check the aux stack space, currently we don't allocate space in heap */
@@ -3050,27 +3067,28 @@ aot_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size)
3050
3067
set the initial value for the global */
3051
3068
uint32 global_offset = module -> globals [stack_top_idx ].data_offset ;
3052
3069
uint8 * global_addr = module_inst -> global_data + global_offset ;
3053
- * (int32 * )global_addr = start_offset ;
3070
+ /* TODO: Memory64 the type i32/i64 depends on memory idx type*/
3071
+ * (int32 * )global_addr = (uint32 )start_offset ;
3054
3072
3055
3073
/* The aux stack boundary is a constant value,
3056
3074
set the value to exec_env */
3057
- exec_env -> aux_stack_boundary . boundary = start_offset - size ;
3058
- exec_env -> aux_stack_bottom . bottom = start_offset ;
3075
+ exec_env -> aux_stack_boundary = ( uintptr_t ) start_offset - size ;
3076
+ exec_env -> aux_stack_bottom = ( uintptr_t ) start_offset ;
3059
3077
return true;
3060
3078
}
3061
3079
3062
3080
return false;
3063
3081
}
3064
3082
3065
3083
bool
3066
- aot_get_aux_stack (WASMExecEnv * exec_env , uint32 * start_offset , uint32 * size )
3084
+ aot_get_aux_stack (WASMExecEnv * exec_env , uint64 * start_offset , uint32 * size )
3067
3085
{
3068
3086
AOTModuleInstance * module_inst = (AOTModuleInstance * )exec_env -> module_inst ;
3069
3087
AOTModule * module = (AOTModule * )module_inst -> module ;
3070
3088
3071
3089
/* The aux stack information is resolved in loader
3072
3090
and store in module */
3073
- uint32 stack_bottom = module -> aux_stack_bottom ;
3091
+ uint64 stack_bottom = module -> aux_stack_bottom ;
3074
3092
uint32 total_aux_stack_size = module -> aux_stack_size ;
3075
3093
3076
3094
if (stack_bottom != 0 && total_aux_stack_size != 0 ) {
0 commit comments