Przeglądaj źródła

Merge branch main into dev/gc_refactor

Wenyong Huang 1 rok temu
rodzic
commit
2f6e4b9378

+ 23 - 8
core/iwasm/interpreter/wasm_loader.c

@@ -6367,14 +6367,22 @@ check_wasi_abi_compatibility(const WASMModule *module,
     /* clang-format on */
 
     WASMExport *initialize = NULL, *memory = NULL, *start = NULL;
+    uint32 import_function_count = module->import_function_count;
+    WASMFuncType *func_type;
 
     /* (func (export "_start") (...) */
     start = wasm_loader_find_export(module, "", "_start", EXPORT_KIND_FUNC,
                                     error_buf, error_buf_size);
     if (start) {
-        WASMFuncType *func_type =
-            module->functions[start->index - module->import_function_count]
-                ->func_type;
+        if (start->index < import_function_count) {
+            set_error_buf(
+                error_buf, error_buf_size,
+                "the builtin _start function can not be an import function");
+            return false;
+        }
+
+        func_type =
+            module->functions[start->index - import_function_count]->func_type;
         if (func_type->param_count || func_type->result_count) {
             set_error_buf(error_buf, error_buf_size,
                           "the signature of builtin _start function is wrong");
@@ -6386,11 +6394,17 @@ check_wasi_abi_compatibility(const WASMModule *module,
         initialize =
             wasm_loader_find_export(module, "", "_initialize", EXPORT_KIND_FUNC,
                                     error_buf, error_buf_size);
+
         if (initialize) {
-            WASMFuncType *func_type =
-                module
-                    ->functions[initialize->index
-                                - module->import_function_count]
+            if (initialize->index < import_function_count) {
+                set_error_buf(error_buf, error_buf_size,
+                              "the builtin _initialize function can not be an "
+                              "import function");
+                return false;
+            }
+
+            func_type =
+                module->functions[initialize->index - import_function_count]
                     ->func_type;
             if (func_type->param_count || func_type->result_count) {
                 set_error_buf(
@@ -9899,7 +9913,8 @@ wasm_loader_check_br(WASMLoaderContext *loader_ctx, uint32 depth,
     bool is_type_multi_byte;
 #endif
 
-    if (loader_ctx->csp_num < depth + 1) {
+    bh_assert(loader_ctx->csp_num > 0);
+    if (loader_ctx->csp_num - 1 < depth) {
         set_error_buf(error_buf, error_buf_size,
                       "unknown label, "
                       "unexpected end of section or function");

+ 2 - 1
core/iwasm/interpreter/wasm_mini_loader.c

@@ -5451,7 +5451,8 @@ wasm_loader_check_br(WASMLoaderContext *loader_ctx, uint32 depth,
     int32 i, available_stack_cell;
     uint16 cell_num;
 
-    if (loader_ctx->csp_num < depth + 1) {
+    bh_assert(loader_ctx->csp_num > 0);
+    if (loader_ctx->csp_num - 1 < depth) {
         set_error_buf(error_buf, error_buf_size,
                       "unknown label, "
                       "unexpected end of section or function");

+ 14 - 2
core/shared/platform/nuttx/nuttx_platform.c

@@ -94,7 +94,11 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
 
 #if defined(CONFIG_ARCH_USE_TEXT_HEAP)
     if ((prot & MMAP_PROT_EXEC) != 0) {
-        return up_textheap_memalign(sizeof(void *), size);
+        p = up_textheap_memalign(sizeof(void *), size);
+        if (p) {
+            memset(p, 0, size);
+        }
+        return p;
     }
 #endif
 
@@ -108,7 +112,11 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
             return NULL;
         }
         i_addr = (void *)((uint8 *)d_addr + MEM_DUAL_BUS_OFFSET);
-        return in_ibus_ext(i_addr) ? i_addr : d_addr;
+        p = in_ibus_ext(i_addr) ? i_addr : d_addr;
+        if (p) {
+            memset(p, 0, size);
+        }
+        return p;
     }
 #endif
     /* Note: aot_loader.c assumes that os_mmap provides large enough
@@ -125,6 +133,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
     if (posix_memalign(&p, 32, size)) {
         return NULL;
     }
+
+    /* Zero the memory which is required by os_mmap */
+    memset(p, 0, size);
+
     return p;
 }