9
9
#include "aot_reloc.h"
10
10
#include "../common/wasm_runtime_common.h"
11
11
#include "../common/wasm_native.h"
12
+ #include "../common/wasm_loader_common.h"
12
13
#include "../compilation/aot.h"
13
14
14
15
#if WASM_ENABLE_DEBUG_AOT != 0
@@ -1043,6 +1044,12 @@ load_memory_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
1043
1044
1044
1045
for (i = 0 ; i < module -> memory_count ; i ++ ) {
1045
1046
read_uint32 (buf , buf_end , module -> memories [i ].memory_flags );
1047
+
1048
+ if (!wasm_memory_check_flags (module -> memories [i ].memory_flags ,
1049
+ error_buf , error_buf_size , true)) {
1050
+ return false;
1051
+ }
1052
+
1046
1053
read_uint32 (buf , buf_end , module -> memories [i ].num_bytes_per_page );
1047
1054
read_uint32 (buf , buf_end , module -> memories [i ].mem_init_page_count );
1048
1055
read_uint32 (buf , buf_end , module -> memories [i ].mem_max_page_count );
@@ -3634,6 +3641,21 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
3634
3641
return ret ;
3635
3642
}
3636
3643
3644
+ #if WASM_ENABLE_MEMORY64 != 0
3645
+ static bool
3646
+ has_module_memory64 (AOTModule * module )
3647
+ {
3648
+ /* TODO: multi-memories for now assuming the memory idx type is consistent
3649
+ * across multi-memories */
3650
+ if (module -> import_memory_count > 0 )
3651
+ return !!(module -> import_memories [0 ].memory_flags & MEMORY64_FLAG );
3652
+ else if (module -> memory_count > 0 )
3653
+ return !!(module -> memories [0 ].memory_flags & MEMORY64_FLAG );
3654
+
3655
+ return false;
3656
+ }
3657
+ #endif
3658
+
3637
3659
static bool
3638
3660
load_from_sections (AOTModule * module , AOTSection * sections ,
3639
3661
bool is_load_from_file_buf , char * error_buf ,
@@ -3645,6 +3667,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
3645
3667
uint32 i , func_index , func_type_index ;
3646
3668
AOTFuncType * func_type ;
3647
3669
AOTExport * exports ;
3670
+ uint8 malloc_free_io_type = VALUE_TYPE_I32 ;
3648
3671
3649
3672
while (section ) {
3650
3673
buf = section -> section_body ;
@@ -3719,7 +3742,10 @@ load_from_sections(AOTModule *module, AOTSection *sections,
3719
3742
module -> malloc_func_index = (uint32 )- 1 ;
3720
3743
module -> free_func_index = (uint32 )- 1 ;
3721
3744
module -> retain_func_index = (uint32 )- 1 ;
3722
-
3745
+ #if WASM_ENABLE_MEMORY64 != 0
3746
+ if (has_module_memory64 (module ))
3747
+ malloc_free_io_type = VALUE_TYPE_I64 ;
3748
+ #endif
3723
3749
exports = module -> exports ;
3724
3750
for (i = 0 ; i < module -> export_count ; i ++ ) {
3725
3751
if (exports [i ].kind == EXPORT_KIND_FUNC
@@ -3729,8 +3755,8 @@ load_from_sections(AOTModule *module, AOTSection *sections,
3729
3755
func_type_index = module -> func_type_indexes [func_index ];
3730
3756
func_type = (AOTFuncType * )module -> types [func_type_index ];
3731
3757
if (func_type -> param_count == 1 && func_type -> result_count == 1
3732
- && func_type -> types [0 ] == VALUE_TYPE_I32
3733
- && func_type -> types [1 ] == VALUE_TYPE_I32 ) {
3758
+ && func_type -> types [0 ] == malloc_free_io_type
3759
+ && func_type -> types [1 ] == malloc_free_io_type ) {
3734
3760
bh_assert (module -> malloc_func_index == (uint32 )- 1 );
3735
3761
module -> malloc_func_index = func_index ;
3736
3762
LOG_VERBOSE ("Found malloc function, name: %s, index: %u" ,
@@ -3742,9 +3768,9 @@ load_from_sections(AOTModule *module, AOTSection *sections,
3742
3768
func_type_index = module -> func_type_indexes [func_index ];
3743
3769
func_type = (AOTFuncType * )module -> types [func_type_index ];
3744
3770
if (func_type -> param_count == 2 && func_type -> result_count == 1
3745
- && func_type -> types [0 ] == VALUE_TYPE_I32
3771
+ && func_type -> types [0 ] == malloc_free_io_type
3746
3772
&& func_type -> types [1 ] == VALUE_TYPE_I32
3747
- && func_type -> types [2 ] == VALUE_TYPE_I32 ) {
3773
+ && func_type -> types [2 ] == malloc_free_io_type ) {
3748
3774
uint32 j ;
3749
3775
WASMExport * export_tmp ;
3750
3776
@@ -3768,8 +3794,8 @@ load_from_sections(AOTModule *module, AOTSection *sections,
3768
3794
(AOTFuncType * )module -> types [func_type_index ];
3769
3795
if (func_type -> param_count == 1
3770
3796
&& func_type -> result_count == 1
3771
- && func_type -> types [0 ] == VALUE_TYPE_I32
3772
- && func_type -> types [1 ] == VALUE_TYPE_I32 ) {
3797
+ && func_type -> types [0 ] == malloc_free_io_type
3798
+ && func_type -> types [1 ] == malloc_free_io_type ) {
3773
3799
bh_assert (module -> retain_func_index
3774
3800
== (uint32 )- 1 );
3775
3801
module -> retain_func_index = export_tmp -> index ;
@@ -3795,7 +3821,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
3795
3821
func_type_index = module -> func_type_indexes [func_index ];
3796
3822
func_type = (AOTFuncType * )module -> types [func_type_index ];
3797
3823
if (func_type -> param_count == 1 && func_type -> result_count == 0
3798
- && func_type -> types [0 ] == VALUE_TYPE_I32 ) {
3824
+ && func_type -> types [0 ] == malloc_free_io_type ) {
3799
3825
bh_assert (module -> free_func_index == (uint32 )- 1 );
3800
3826
module -> free_func_index = func_index ;
3801
3827
LOG_VERBOSE ("Found free function, name: %s, index: %u" ,
0 commit comments