From dea8a90e81802664cb5c288f5c6da7b8f11b1543 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Mon, 3 Jul 2023 17:00:23 +0800 Subject: [PATCH 01/13] first stage first stage --- core/iwasm/aot/arch/aot_reloc_xtensa.c | 4 +-- core/shared/platform/nuttx/nuttx_platform.c | 26 ++++++++++++++++- .../shared/platform/nuttx/platform_internal.h | 29 +++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index 3327c396fb..46c4014e40 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -206,7 +206,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, switch (reloc_type) { case R_XTENSA_32: { - uint8 *insn_addr = target_section_addr + reloc_offset; + uint8 *insn_addr = target_section_addr + reloc_offset - BUS_CONVERT_OFFSET; int32 initial_addend; /* (S + A) */ if ((intptr_t)insn_addr & 3) { @@ -224,7 +224,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, case R_XTENSA_SLOT0_OP: { - uint8 *insn_addr = target_section_addr + reloc_offset; + uint8 *insn_addr = target_section_addr + reloc_offset - BUS_CONVERT_OFFSET; /* Currently only l32r instruction generates R_XTENSA_SLOT0_OP * relocation */ l32r_insn_t *l32r_insn = (l32r_insn_t *)insn_addr; diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 9cb123e017..2d742de05c 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -10,6 +10,17 @@ #include #endif + +#if defined(CONFIG_ARCH_CHIP_ESP32S3) +#if CONFIG_ARCH_CHIP_ESP32S3 != 0 +void IRAM_ATTR esp32s3_bus_sync(void) +{ + extern void cache_writeback_all(void); + cache_writeback_all(); +} +#endif +#endif + int bh_platform_init() { @@ -55,7 +66,16 @@ os_mmap(void *hint, size_t size, int prot, int flags) if ((uint64)size >= UINT32_MAX) return NULL; - return malloc((uint32)size); + + if((prot & MMAP_PROT_EXEC) != 0) { + void * addr = malloc((uint32)size); + esp32s3_bus_sync(); + return addr + BUS_CONVERT_OFFSET + + } else + { + return malloc((uint32)size); + } } void @@ -67,6 +87,10 @@ os_munmap(void *addr, size_t size) return; } #endif + if(check_psram_addr(addr)) + { + return free(addr - BUS_CONVERT_OFFSET); + } return free(addr); } diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index b5bbdacd04..d6d918b21c 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -33,6 +33,35 @@ extern "C" { #endif + +#if defined(CONFIG_ARCH_XTENSA) +#include +#endif + +#if defined(CONFIG_ARCH_CHIP_ESP32S3) +#if CONFIG_ARCH_CHIP_ESP32S3 != 0 +#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 +#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 +#define BUS_CONVERT_OFFSET (0x42000000 - 0x3C000000) + +__attribute__((always_inline)) +inline bool check_psram_addr(uint32_t addr_start) +{ + return ((addr_start >= IRAM0_CACHE_ADDRESS_LOW) && (addr_start < IRAM0_CACHE_ADDRESS_HIGH)); +} + +void IRAM_ATTR esp32s3_bus_sync(void); +#endif +#else +#define BUS_CONVERT_OFFSET 0 +__attribute__((always_inline)) +inline bool check_psram_addr(uint32_t addr_start) +{ + return 0; +} + +#endif + #ifndef BH_PLATFORM_NUTTX #define BH_PLATFORM_NUTTX #endif From 6bce421b096d7bc45908d73e259c2b0a03dfd3c3 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Tue, 4 Jul 2023 12:58:04 +0800 Subject: [PATCH 02/13] limit the scope to a specific chip of esp32-s3 1, define the iram checking function 2, define the ibus-dbus converting offset 3, modify address allocated by malloc 4, free the modified address allocated by malloc --- core/iwasm/aot/arch/aot_reloc_xtensa.c | 22 ++++++++++- core/shared/platform/nuttx/nuttx_platform.c | 38 +++++++++++-------- .../shared/platform/nuttx/platform_internal.h | 35 ++++++----------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index 46c4014e40..5a4913bf43 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -8,6 +8,14 @@ #define R_XTENSA_32 1 /* Direct 32 bit */ #define R_XTENSA_SLOT0_OP 20 /* PC relative */ +#ifndef BUS_CONVERT_OFFSET +#define BUS_CONVERT_OFFSET 0x0 +#endif + +#ifndef is_in_iram +#define is_in_iram(addr) 0x0 +#endif + /* clang-format off */ /* for soft-float */ void __floatsidf(); @@ -206,7 +214,11 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, switch (reloc_type) { case R_XTENSA_32: { - uint8 *insn_addr = target_section_addr + reloc_offset - BUS_CONVERT_OFFSET; + uint8 *insn_addr = target_section_addr + reloc_offset; + if (is_in_iram(insn_addr)) + { + insn_addr -= BUS_CONVERT_OFFSET; + } int32 initial_addend; /* (S + A) */ if ((intptr_t)insn_addr & 3) { @@ -224,7 +236,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, case R_XTENSA_SLOT0_OP: { - uint8 *insn_addr = target_section_addr + reloc_offset - BUS_CONVERT_OFFSET; + uint8 *insn_addr = target_section_addr + reloc_offset; /* Currently only l32r instruction generates R_XTENSA_SLOT0_OP * relocation */ l32r_insn_t *l32r_insn = (l32r_insn_t *)insn_addr; @@ -265,6 +277,12 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, return false; } + if (is_in_iram(insn_addr)) + { + insn_addr -= BUS_CONVERT_OFFSET; + l32r_insn = (l32r_insn_t *)insn_addr; + } + imm16 = (int16)(relative_offset >> 2); /* write back the imm16 to the l32r instruction */ diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 2d742de05c..5d9ccedd20 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -11,14 +11,17 @@ #endif -#if defined(CONFIG_ARCH_CHIP_ESP32S3) -#if CONFIG_ARCH_CHIP_ESP32S3 != 0 -void IRAM_ATTR esp32s3_bus_sync(void) +#if defined(CONFIG_ARCH_CHIP_ESP32S3) \ + && (CONFIG_ARCH_CHIP_ESP32S3 != 0) +static void bus_sync(void) { extern void cache_writeback_all(void); cache_writeback_all(); } -#endif +#else +static void bus_sync(void) +{ +} #endif int @@ -68,14 +71,15 @@ os_mmap(void *hint, size_t size, int prot, int flags) return NULL; if((prot & MMAP_PROT_EXEC) != 0) { - void * addr = malloc((uint32)size); - esp32s3_bus_sync(); - return addr + BUS_CONVERT_OFFSET - - } else - { - return malloc((uint32)size); + void * addr = malloc((uint32)size) + BUS_CONVERT_OFFSET; + if(is_in_iram(addr)) { + return addr; + } else { + return (addr - BUS_CONVERT_OFFSET); + } } + + return malloc((uint32)size); } void @@ -87,11 +91,13 @@ os_munmap(void *addr, size_t size) return; } #endif - if(check_psram_addr(addr)) + if(is_in_iram(addr)) { - return free(addr - BUS_CONVERT_OFFSET); + free(addr - BUS_CONVERT_OFFSET); + return; } - return free(addr); + + free(addr); } int @@ -102,7 +108,9 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush() -{} +{ + bus_sync(); +} /* If AT_FDCWD is provided, maybe we have openat family */ #if !defined(AT_FDCWD) diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index d6d918b21c..5dbf746ad2 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -33,33 +33,20 @@ extern "C" { #endif +#if defined(CONFIG_ARCH_CHIP_ESP32S3) \ + && (CONFIG_ARCH_CHIP_ESP32S3 != 0) -#if defined(CONFIG_ARCH_XTENSA) -#include -#endif - -#if defined(CONFIG_ARCH_CHIP_ESP32S3) -#if CONFIG_ARCH_CHIP_ESP32S3 != 0 -#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 -#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 -#define BUS_CONVERT_OFFSET (0x42000000 - 0x3C000000) - -__attribute__((always_inline)) -inline bool check_psram_addr(uint32_t addr_start) -{ - return ((addr_start >= IRAM0_CACHE_ADDRESS_LOW) && (addr_start < IRAM0_CACHE_ADDRESS_HIGH)); -} +#define BUS_CONVERT_OFFSET (0x42000000-0x3C000000) -void IRAM_ATTR esp32s3_bus_sync(void); -#endif +#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 +#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 +#define is_in_iram(addr) ( \ + ((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ + &&((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH) \ + ) #else -#define BUS_CONVERT_OFFSET 0 -__attribute__((always_inline)) -inline bool check_psram_addr(uint32_t addr_start) -{ - return 0; -} - +#define is_in_iram(addr) 0x0 +#define BUS_CONVERT_OFFSET 0x0 #endif #ifndef BH_PLATFORM_NUTTX From dd6505612bdd79d0b98de51776646f3a0d4b7dde Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Wed, 5 Jul 2023 10:18:53 +0800 Subject: [PATCH 03/13] rename the is_in_iram into in_ibus_ext --- core/iwasm/aot/arch/aot_reloc_xtensa.c | 8 ++++---- core/shared/platform/nuttx/nuttx_platform.c | 4 ++-- core/shared/platform/nuttx/platform_internal.h | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index 5a4913bf43..2172d827c3 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -12,8 +12,8 @@ #define BUS_CONVERT_OFFSET 0x0 #endif -#ifndef is_in_iram -#define is_in_iram(addr) 0x0 +#ifndef in_ibus_ext +#define in_ibus_ext(addr) 0x0 #endif /* clang-format off */ @@ -215,7 +215,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, case R_XTENSA_32: { uint8 *insn_addr = target_section_addr + reloc_offset; - if (is_in_iram(insn_addr)) + if (in_ibus_ext(insn_addr)) { insn_addr -= BUS_CONVERT_OFFSET; } @@ -277,7 +277,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, return false; } - if (is_in_iram(insn_addr)) + if (in_ibus_ext(insn_addr)) { insn_addr -= BUS_CONVERT_OFFSET; l32r_insn = (l32r_insn_t *)insn_addr; diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 5d9ccedd20..910945d238 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -72,7 +72,7 @@ os_mmap(void *hint, size_t size, int prot, int flags) if((prot & MMAP_PROT_EXEC) != 0) { void * addr = malloc((uint32)size) + BUS_CONVERT_OFFSET; - if(is_in_iram(addr)) { + if(in_ibus_ext(addr)) { return addr; } else { return (addr - BUS_CONVERT_OFFSET); @@ -91,7 +91,7 @@ os_munmap(void *addr, size_t size) return; } #endif - if(is_in_iram(addr)) + if(in_ibus_ext(addr)) { free(addr - BUS_CONVERT_OFFSET); return; diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index 5dbf746ad2..91e35ccdbb 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -38,15 +38,15 @@ extern "C" { #define BUS_CONVERT_OFFSET (0x42000000-0x3C000000) -#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 -#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 -#define is_in_iram(addr) ( \ - ((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ - &&((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH) \ +#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 +#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 +#define in_ibus_ext(addr) ( \ + ((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ + &&((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH) \ ) #else -#define is_in_iram(addr) 0x0 -#define BUS_CONVERT_OFFSET 0x0 +#define in_ibus_ext(addr) 0x0 +#define BUS_CONVERT_OFFSET 0x0 #endif #ifndef BH_PLATFORM_NUTTX From 0bc5d7c2a6f0da172a820af17805cb6384ce8a46 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Wed, 5 Jul 2023 14:14:26 +0800 Subject: [PATCH 04/13] add WASM_MEM_DUAL_BUS_MIRROR options in wamr add os_get_dbus_mirror(void *ibus) as system interface --- core/config.h | 4 +++ core/iwasm/aot/aot_loader.c | 15 ++++++++- core/iwasm/aot/arch/aot_reloc_xtensa.c | 29 +++++++---------- .../platform/include/platform_api_vmcore.h | 5 +++ core/shared/platform/nuttx/nuttx_platform.c | 32 ++++++++++++++++--- .../shared/platform/nuttx/platform_internal.h | 16 ---------- product-mini/platforms/nuttx/wamr.mk | 6 ++++ 7 files changed, 68 insertions(+), 39 deletions(-) diff --git a/core/config.h b/core/config.h index f33290f0d7..8324d35e43 100644 --- a/core/config.h +++ b/core/config.h @@ -461,4 +461,8 @@ #define WASM_CONFIGURABLE_BOUNDS_CHECKS 0 #endif +#ifndef WASM_MEM_DUAL_BUS_MIRROR +#define WASM_MEM_DUAL_BUS_MIRROR 0 +#endif + #endif /* end of _CONFIG_H_ */ diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 2f4dcd31ab..d718830525 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -20,6 +20,8 @@ #define XMM_PLT_PREFIX "__xmm@" #define REAL_PLT_PREFIX "__real@" +#define TEST_SIZE (2*1024*1024) + static void set_error_buf(char *error_buf, uint32 error_buf_size, const char *string) { @@ -3013,6 +3015,9 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, uint32 section_size; uint64 total_size; uint8 *aot_text; +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + uint8 *mirrored_text; +#endif if (!resolve_execute_mode(buf, size, &is_indirect_mode, error_buf, error_buf_size)) { @@ -3056,7 +3061,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, (uint64)section_size + aot_get_plt_table_size(); total_size = (total_size + 3) & ~((uint64)3); if (total_size >= UINT32_MAX - || !(aot_text = os_mmap(NULL, (uint32)total_size, + || !(aot_text = os_mmap(NULL, TEST_SIZE, map_prot, map_flags))) { wasm_runtime_free(section); set_error_buf(error_buf, error_buf_size, @@ -3071,8 +3076,16 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, bh_assert((uintptr_t)aot_text < INT32_MAX); #endif #endif + +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + mirrored_text = os_get_dbus_mirror(aot_text); + bh_memcpy_s(mirrored_text, (uint32)total_size, + section->section_body, (uint32)section_size); + os_dcache_flush(); +#else bh_memcpy_s(aot_text, (uint32)total_size, section->section_body, (uint32)section_size); +#endif section->section_body = aot_text; destroy_aot_text = true; diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index 2172d827c3..f5ed915620 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -8,14 +8,6 @@ #define R_XTENSA_32 1 /* Direct 32 bit */ #define R_XTENSA_SLOT0_OP 20 /* PC relative */ -#ifndef BUS_CONVERT_OFFSET -#define BUS_CONVERT_OFFSET 0x0 -#endif - -#ifndef in_ibus_ext -#define in_ibus_ext(addr) 0x0 -#endif - /* clang-format off */ /* for soft-float */ void __floatsidf(); @@ -215,10 +207,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, case R_XTENSA_32: { uint8 *insn_addr = target_section_addr + reloc_offset; - if (in_ibus_ext(insn_addr)) - { - insn_addr -= BUS_CONVERT_OFFSET; - } +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + insn_addr = os_get_dbus_mirror((void*)insn_addr); +#endif int32 initial_addend; /* (S + A) */ if ((intptr_t)insn_addr & 3) { @@ -231,6 +222,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, initial_addend = *(int32 *)insn_addr; *(uintptr_t *)insn_addr = (uintptr_t)symbol_addr + initial_addend + (intptr_t)reloc_addend; +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + os_dcache_flush(); +#endif break; } @@ -277,12 +271,10 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, return false; } - if (in_ibus_ext(insn_addr)) - { - insn_addr -= BUS_CONVERT_OFFSET; +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + insn_addr = os_get_dbus_mirror((void*)insn_addr); l32r_insn = (l32r_insn_t *)insn_addr; - } - +#endif imm16 = (int16)(relative_offset >> 2); /* write back the imm16 to the l32r instruction */ @@ -304,6 +296,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, #pragma GCC diagnostic pop #endif +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + os_dcache_flush(); +#endif break; } diff --git a/core/shared/platform/include/platform_api_vmcore.h b/core/shared/platform/include/platform_api_vmcore.h index c2f03c9e50..340b93b355 100644 --- a/core/shared/platform/include/platform_api_vmcore.h +++ b/core/shared/platform/include/platform_api_vmcore.h @@ -129,6 +129,11 @@ os_munmap(void *addr, size_t size); int os_mprotect(void *addr, size_t size, int prot); +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +void * +os_get_dbus_mirror(void *ibus); +#endif + /** * Flush cpu data cache, in some CPUs, after applying relocation to the * AOT code, the code may haven't been written back to the cpu data cache, diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 910945d238..40742a1f29 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -10,15 +10,26 @@ #include #endif - -#if defined(CONFIG_ARCH_CHIP_ESP32S3) \ +#if defined(CONFIG_ARCH_CHIP_ESP32S3) \ && (CONFIG_ARCH_CHIP_ESP32S3 != 0) +#define MEM_DUAL_BUS_OFFSET (0x42000000-0x3C000000) +#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 +#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 + +#define in_ibus_ext(addr) ( \ + ((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ + &&((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH) \ + ) static void bus_sync(void) { extern void cache_writeback_all(void); cache_writeback_all(); } #else +#define MEM_DUAL_BUS_OFFSET (0) +#define IRAM0_CACHE_ADDRESS_LOW (0) +#define IRAM0_CACHE_ADDRESS_HIGH (0) +#define in_ibus_ext(addr) (0) static void bus_sync(void) { } @@ -71,11 +82,13 @@ os_mmap(void *hint, size_t size, int prot, int flags) return NULL; if((prot & MMAP_PROT_EXEC) != 0) { - void * addr = malloc((uint32)size) + BUS_CONVERT_OFFSET; + void * addr = malloc((uint32)size) + MEM_DUAL_BUS_OFFSET; if(in_ibus_ext(addr)) { + printf("os_mmap: in_ibus_ext, addr=%p, size=%d\n", addr, size); return addr; } else { - return (addr - BUS_CONVERT_OFFSET); + printf("os_mmap: not in_ibus_ext, addr=%p, size=%d\n", addr, size); + return (addr - MEM_DUAL_BUS_OFFSET); } } @@ -93,7 +106,8 @@ os_munmap(void *addr, size_t size) #endif if(in_ibus_ext(addr)) { - free(addr - BUS_CONVERT_OFFSET); + printf("os_munmap: in_ibus_ext, addr=%p, size=%d\n", addr, size); + free(addr - MEM_DUAL_BUS_OFFSET); return; } @@ -112,6 +126,14 @@ os_dcache_flush() bus_sync(); } +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +void * +os_get_dbus_mirror(void *ibus) +{ + return ibus - MEM_DUAL_BUS_OFFSET; +} +#endif + /* If AT_FDCWD is provided, maybe we have openat family */ #if !defined(AT_FDCWD) diff --git a/core/shared/platform/nuttx/platform_internal.h b/core/shared/platform/nuttx/platform_internal.h index 91e35ccdbb..b5bbdacd04 100644 --- a/core/shared/platform/nuttx/platform_internal.h +++ b/core/shared/platform/nuttx/platform_internal.h @@ -33,22 +33,6 @@ extern "C" { #endif -#if defined(CONFIG_ARCH_CHIP_ESP32S3) \ - && (CONFIG_ARCH_CHIP_ESP32S3 != 0) - -#define BUS_CONVERT_OFFSET (0x42000000-0x3C000000) - -#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 -#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 -#define in_ibus_ext(addr) ( \ - ((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ - &&((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH) \ - ) -#else -#define in_ibus_ext(addr) 0x0 -#define BUS_CONVERT_OFFSET 0x0 -#endif - #ifndef BH_PLATFORM_NUTTX #define BH_PLATFORM_NUTTX #endif diff --git a/product-mini/platforms/nuttx/wamr.mk b/product-mini/platforms/nuttx/wamr.mk index da5cdcc27d..9a1afb24b2 100644 --- a/product-mini/platforms/nuttx/wamr.mk +++ b/product-mini/platforms/nuttx/wamr.mk @@ -141,6 +141,12 @@ else CFLAGS += -DWASM_ENABLE_WORD_ALIGN_READ=0 endif +ifeq ($(CONFIG_INTERPRETERS_WAMR_MEM_DUAL_BUS_MIRROR),y) +CFLAGS += -DWASM_MEM_DUAL_BUS_MIRROR=1 +else +CFLAGS += -DWASM_MEM_DUAL_BUS_MIRROR=0 +endif + ifeq ($(CONFIG_INTERPRETERS_WAMR_FAST), y) CFLAGS += -DWASM_ENABLE_FAST_INTERP=1 CFLAGS += -DWASM_ENABLE_INTERP=1 From a8a9c0d4c91159d1c1625933f1caba80b16b5d69 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Wed, 5 Jul 2023 14:53:45 +0800 Subject: [PATCH 05/13] only when ibus in its range, dbus has the offset only when ibus in its range, dbus has the offset --- core/iwasm/aot/aot_loader.c | 4 +--- core/shared/platform/nuttx/nuttx_platform.c | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index d718830525..c49541f7ac 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -20,8 +20,6 @@ #define XMM_PLT_PREFIX "__xmm@" #define REAL_PLT_PREFIX "__real@" -#define TEST_SIZE (2*1024*1024) - static void set_error_buf(char *error_buf, uint32 error_buf_size, const char *string) { @@ -3061,7 +3059,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, (uint64)section_size + aot_get_plt_table_size(); total_size = (total_size + 3) & ~((uint64)3); if (total_size >= UINT32_MAX - || !(aot_text = os_mmap(NULL, TEST_SIZE, + || !(aot_text = os_mmap(NULL, (uint32)total_size, map_prot, map_flags))) { wasm_runtime_free(section); set_error_buf(error_buf, error_buf_size, diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 40742a1f29..72e7ddb611 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -84,10 +84,8 @@ os_mmap(void *hint, size_t size, int prot, int flags) if((prot & MMAP_PROT_EXEC) != 0) { void * addr = malloc((uint32)size) + MEM_DUAL_BUS_OFFSET; if(in_ibus_ext(addr)) { - printf("os_mmap: in_ibus_ext, addr=%p, size=%d\n", addr, size); return addr; } else { - printf("os_mmap: not in_ibus_ext, addr=%p, size=%d\n", addr, size); return (addr - MEM_DUAL_BUS_OFFSET); } } @@ -106,7 +104,6 @@ os_munmap(void *addr, size_t size) #endif if(in_ibus_ext(addr)) { - printf("os_munmap: in_ibus_ext, addr=%p, size=%d\n", addr, size); free(addr - MEM_DUAL_BUS_OFFSET); return; } @@ -130,7 +127,12 @@ os_dcache_flush() void * os_get_dbus_mirror(void *ibus) { - return ibus - MEM_DUAL_BUS_OFFSET; + if(in_ibus_ext(ibus)) { + return ibus - MEM_DUAL_BUS_OFFSET; + } else + { + return ibus; + } } #endif From a353d462427f5c47abe875289cad37bd47129d72 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Thu, 6 Jul 2023 15:32:17 +0800 Subject: [PATCH 06/13] add compiler switch for os_mmap add compiler switch for os_mmap --- core/shared/platform/nuttx/nuttx_platform.c | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 72e7ddb611..5d4e14715d 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -72,6 +72,10 @@ os_dumps_proc_mem_info(char *out, unsigned int size) void * os_mmap(void *hint, size_t size, int prot, int flags) { +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) + void *i_addr, *d_addr; +#endif + #if defined(CONFIG_ARCH_USE_TEXT_HEAP) if ((prot & MMAP_PROT_EXEC) != 0) { return up_textheap_memalign(sizeof(void *), size); @@ -80,16 +84,14 @@ os_mmap(void *hint, size_t size, int prot, int flags) if ((uint64)size >= UINT32_MAX) return NULL; - + +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) if((prot & MMAP_PROT_EXEC) != 0) { - void * addr = malloc((uint32)size) + MEM_DUAL_BUS_OFFSET; - if(in_ibus_ext(addr)) { - return addr; - } else { - return (addr - MEM_DUAL_BUS_OFFSET); - } + d_addr = malloc((uint32)size); + i_addr = d_addr + MEM_DUAL_BUS_OFFSET; + return in_ibus_ext(i_addr) ? i_addr : d_addr; } - +#endif return malloc((uint32)size); } @@ -102,12 +104,14 @@ os_munmap(void *addr, size_t size) return; } #endif + +#if (WASM_MEM_DUAL_BUS_MIRROR!=0) if(in_ibus_ext(addr)) { free(addr - MEM_DUAL_BUS_OFFSET); return; } - +#endif free(addr); } From 6aba288dbbe083dd148812a4f34c8286f7b53672 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Thu, 6 Jul 2023 15:48:39 +0800 Subject: [PATCH 07/13] format using clang-format format using clang-format --- core/iwasm/aot/aot_loader.c | 4 +- core/iwasm/aot/arch/aot_reloc_xtensa.c | 14 ++--- .../platform/include/platform_api_vmcore.h | 2 +- core/shared/platform/nuttx/nuttx_platform.c | 55 ++++++++++--------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index c49541f7ac..8d0ba561a1 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -3013,7 +3013,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, uint32 section_size; uint64 total_size; uint8 *aot_text; -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) uint8 *mirrored_text; #endif @@ -3075,7 +3075,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, #endif #endif -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) mirrored_text = os_get_dbus_mirror(aot_text); bh_memcpy_s(mirrored_text, (uint32)total_size, section->section_body, (uint32)section_size); diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index f5ed915620..9e6b97656f 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -207,8 +207,8 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, case R_XTENSA_32: { uint8 *insn_addr = target_section_addr + reloc_offset; -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) - insn_addr = os_get_dbus_mirror((void*)insn_addr); +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + insn_addr = os_get_dbus_mirror((void *)insn_addr); #endif int32 initial_addend; /* (S + A) */ @@ -222,7 +222,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, initial_addend = *(int32 *)insn_addr; *(uintptr_t *)insn_addr = (uintptr_t)symbol_addr + initial_addend + (intptr_t)reloc_addend; -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) os_dcache_flush(); #endif break; @@ -271,9 +271,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, return false; } -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) - insn_addr = os_get_dbus_mirror((void*)insn_addr); - l32r_insn = (l32r_insn_t *)insn_addr; +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + insn_addr = os_get_dbus_mirror((void *)insn_addr); + l32r_insn = (l32r_insn_t *)insn_addr; #endif imm16 = (int16)(relative_offset >> 2); @@ -296,7 +296,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, #pragma GCC diagnostic pop #endif -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) os_dcache_flush(); #endif break; diff --git a/core/shared/platform/include/platform_api_vmcore.h b/core/shared/platform/include/platform_api_vmcore.h index 340b93b355..15fc1d3873 100644 --- a/core/shared/platform/include/platform_api_vmcore.h +++ b/core/shared/platform/include/platform_api_vmcore.h @@ -129,7 +129,7 @@ os_munmap(void *addr, size_t size); int os_mprotect(void *addr, size_t size, int prot); -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) void * os_get_dbus_mirror(void *ibus); #endif diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 5d4e14715d..ae06023ce9 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -10,29 +10,28 @@ #include #endif -#if defined(CONFIG_ARCH_CHIP_ESP32S3) \ - && (CONFIG_ARCH_CHIP_ESP32S3 != 0) -#define MEM_DUAL_BUS_OFFSET (0x42000000-0x3C000000) -#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 -#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 - -#define in_ibus_ext(addr) ( \ - ((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ - &&((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH) \ - ) -static void bus_sync(void) +#if defined(CONFIG_ARCH_CHIP_ESP32S3) && (CONFIG_ARCH_CHIP_ESP32S3 != 0) +#define MEM_DUAL_BUS_OFFSET (0x42000000 - 0x3C000000) +#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 +#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 + +#define in_ibus_ext(addr) \ + (((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ + && ((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH)) +static void +bus_sync(void) { extern void cache_writeback_all(void); cache_writeback_all(); } #else -#define MEM_DUAL_BUS_OFFSET (0) -#define IRAM0_CACHE_ADDRESS_LOW (0) -#define IRAM0_CACHE_ADDRESS_HIGH (0) -#define in_ibus_ext(addr) (0) -static void bus_sync(void) -{ -} +#define MEM_DUAL_BUS_OFFSET (0) +#define IRAM0_CACHE_ADDRESS_LOW (0) +#define IRAM0_CACHE_ADDRESS_HIGH (0) +#define in_ibus_ext(addr) (0) +static void +bus_sync(void) +{} #endif int @@ -72,7 +71,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size) void * os_mmap(void *hint, size_t size, int prot, int flags) { -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) void *i_addr, *d_addr; #endif @@ -85,8 +84,8 @@ os_mmap(void *hint, size_t size, int prot, int flags) if ((uint64)size >= UINT32_MAX) return NULL; -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) - if((prot & MMAP_PROT_EXEC) != 0) { +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + if ((prot & MMAP_PROT_EXEC) != 0) { d_addr = malloc((uint32)size); i_addr = d_addr + MEM_DUAL_BUS_OFFSET; return in_ibus_ext(i_addr) ? i_addr : d_addr; @@ -105,8 +104,8 @@ os_munmap(void *addr, size_t size) } #endif -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) - if(in_ibus_ext(addr)) +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + if (in_ibus_ext(addr)) { free(addr - MEM_DUAL_BUS_OFFSET); return; @@ -127,13 +126,15 @@ os_dcache_flush() bus_sync(); } -#if (WASM_MEM_DUAL_BUS_MIRROR!=0) -void * +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) +void * os_get_dbus_mirror(void *ibus) { - if(in_ibus_ext(ibus)) { + if (in_ibus_ext(ibus)) + { return ibus - MEM_DUAL_BUS_OFFSET; - } else + } + else { return ibus; } From 8f196529000aea61b12ab91940035e97519c874e Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Fri, 7 Jul 2023 10:19:46 +0800 Subject: [PATCH 08/13] use clang-format12 to format use clang-format12 to format check NULL when malloc --- core/shared/platform/nuttx/nuttx_platform.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index ae06023ce9..15a1cbee72 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -87,6 +87,9 @@ os_mmap(void *hint, size_t size, int prot, int flags) #if (WASM_MEM_DUAL_BUS_MIRROR != 0) if ((prot & MMAP_PROT_EXEC) != 0) { d_addr = malloc((uint32)size); + if (d_addr == NULL) { + return NULL; + } i_addr = d_addr + MEM_DUAL_BUS_OFFSET; return in_ibus_ext(i_addr) ? i_addr : d_addr; } @@ -105,8 +108,7 @@ os_munmap(void *addr, size_t size) #endif #if (WASM_MEM_DUAL_BUS_MIRROR != 0) - if (in_ibus_ext(addr)) - { + if (in_ibus_ext(addr)) { free(addr - MEM_DUAL_BUS_OFFSET); return; } @@ -130,12 +132,10 @@ os_dcache_flush() void * os_get_dbus_mirror(void *ibus) { - if (in_ibus_ext(ibus)) - { + if (in_ibus_ext(ibus)) { return ibus - MEM_DUAL_BUS_OFFSET; } - else - { + else { return ibus; } } From b3c0ccf2d05c4349ca2ed8307a2a74dbb46f6549 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Mon, 17 Jul 2023 11:28:28 +0800 Subject: [PATCH 09/13] remove the redundant dcache flush and add some comments for the PR motivation esp32-s3 requires special steps for cache flush --- core/config.h | 7 +++++++ core/iwasm/aot/arch/aot_reloc_xtensa.c | 7 ------- core/shared/platform/nuttx/nuttx_platform.c | 22 ++++++++++++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/core/config.h b/core/config.h index 8324d35e43..b6198811e3 100644 --- a/core/config.h +++ b/core/config.h @@ -461,6 +461,13 @@ #define WASM_CONFIGURABLE_BOUNDS_CHECKS 0 #endif +/* Some chip cannot support external ram with rwx attr at the same time, + it has to map it into 2 spaces of idbus and dbus, code in dbus can be + read/written and read/executed in ibus. so there are 2 steps to execute + the code, first, copy&do relocaiton in dbus space, and second execute + it in ibus space, since in the 2 spaces the contents are the same, + so we call it bus mirror. + */ #ifndef WASM_MEM_DUAL_BUS_MIRROR #define WASM_MEM_DUAL_BUS_MIRROR 0 #endif diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index 9e6b97656f..6c506cc8f0 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -222,9 +222,6 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, initial_addend = *(int32 *)insn_addr; *(uintptr_t *)insn_addr = (uintptr_t)symbol_addr + initial_addend + (intptr_t)reloc_addend; -#if (WASM_MEM_DUAL_BUS_MIRROR != 0) - os_dcache_flush(); -#endif break; } @@ -294,10 +291,6 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, put_imm16_to_addr(imm16, &l32r_insn->b.imm16); #if __GNUC__ >= 9 #pragma GCC diagnostic pop -#endif - -#if (WASM_MEM_DUAL_BUS_MIRROR != 0) - os_dcache_flush(); #endif break; } diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 15a1cbee72..1e782c2745 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -11,18 +11,34 @@ #endif #if defined(CONFIG_ARCH_CHIP_ESP32S3) && (CONFIG_ARCH_CHIP_ESP32S3 != 0) +/* + * TODO: Move these methods below the operating system level + */ #define MEM_DUAL_BUS_OFFSET (0x42000000 - 0x3C000000) #define IRAM0_CACHE_ADDRESS_LOW 0x42000000 #define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 +#define IRAM_ATTR locate_data(".iram1") #define in_ibus_ext(addr) \ (((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ && ((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH)) -static void +void IRAM_ATTR bus_sync(void) { extern void cache_writeback_all(void); + extern uint32_t Cache_Disable_ICache(void); + extern void Cache_Enable_ICache(uint32_t autoload); + + irqstate_t flags; + uint32_t preload; + + flags = enter_critical_section(); + cache_writeback_all(); + preload = Cache_Disable_ICache(); + Cache_Enable_ICache(preload); + + leave_critical_section(flags); } #else #define MEM_DUAL_BUS_OFFSET (0) @@ -90,7 +106,7 @@ os_mmap(void *hint, size_t size, int prot, int flags) if (d_addr == NULL) { return NULL; } - i_addr = d_addr + MEM_DUAL_BUS_OFFSET; + i_addr = (void *)((uint8 *)d_addr + MEM_DUAL_BUS_OFFSET); return in_ibus_ext(i_addr) ? i_addr : d_addr; } #endif @@ -109,7 +125,7 @@ os_munmap(void *addr, size_t size) #if (WASM_MEM_DUAL_BUS_MIRROR != 0) if (in_ibus_ext(addr)) { - free(addr - MEM_DUAL_BUS_OFFSET); + free((void *)((uint8 *)addr - MEM_DUAL_BUS_OFFSET)); return; } #endif From a6db8c4eecb0f23dd375a96d5f037f921ec18f85 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Mon, 17 Jul 2023 11:38:54 +0800 Subject: [PATCH 10/13] align the void* into int8* align the void* into int8* --- core/shared/platform/nuttx/nuttx_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 1e782c2745..210af32678 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -149,7 +149,7 @@ void * os_get_dbus_mirror(void *ibus) { if (in_ibus_ext(ibus)) { - return ibus - MEM_DUAL_BUS_OFFSET; + return (void *)((int8 *)ibus - MEM_DUAL_BUS_OFFSET); } else { return ibus; From ac9d38db902678d1f5608674aae314008eddca6f Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Mon, 17 Jul 2023 11:43:39 +0800 Subject: [PATCH 11/13] unit8 * not int8* unit8 * not int8* --- core/shared/platform/nuttx/nuttx_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index 210af32678..ef128df5b0 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -149,7 +149,7 @@ void * os_get_dbus_mirror(void *ibus) { if (in_ibus_ext(ibus)) { - return (void *)((int8 *)ibus - MEM_DUAL_BUS_OFFSET); + return (void *)((uint8 *)ibus - MEM_DUAL_BUS_OFFSET); } else { return ibus; From 9db220bec7081aeb42513aab8cc8142634a8381b Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Thu, 20 Jul 2023 13:52:54 +0800 Subject: [PATCH 12/13] Asserting the validity of memory address Asserting the validity of memory address --- core/iwasm/aot/aot_loader.c | 1 + core/iwasm/aot/arch/aot_reloc_xtensa.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 8d0ba561a1..50e36f9ee9 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -3077,6 +3077,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, #if (WASM_MEM_DUAL_BUS_MIRROR != 0) mirrored_text = os_get_dbus_mirror(aot_text); + bh_assert(mirrored_text != NULL); bh_memcpy_s(mirrored_text, (uint32)total_size, section->section_body, (uint32)section_size); os_dcache_flush(); diff --git a/core/iwasm/aot/arch/aot_reloc_xtensa.c b/core/iwasm/aot/arch/aot_reloc_xtensa.c index 6c506cc8f0..6ca6a08596 100644 --- a/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -209,6 +209,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, uint8 *insn_addr = target_section_addr + reloc_offset; #if (WASM_MEM_DUAL_BUS_MIRROR != 0) insn_addr = os_get_dbus_mirror((void *)insn_addr); + bh_assert(insn_addr != NULL); #endif int32 initial_addend; /* (S + A) */ @@ -270,6 +271,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, #if (WASM_MEM_DUAL_BUS_MIRROR != 0) insn_addr = os_get_dbus_mirror((void *)insn_addr); + bh_assert(insn_addr != NULL); l32r_insn = (l32r_insn_t *)insn_addr; #endif imm16 = (int16)(relative_offset >> 2); From 5ec6715a9480fbd0308c0540cd7eabff0bff3106 Mon Sep 17 00:00:00 2001 From: "Dongsheng.Yan" Date: Thu, 20 Jul 2023 14:54:46 +0800 Subject: [PATCH 13/13] compilation switch check Only check if the compilation switch exists on nuttx to determine the function on or off --- core/shared/platform/nuttx/nuttx_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/platform/nuttx/nuttx_platform.c b/core/shared/platform/nuttx/nuttx_platform.c index ef128df5b0..0bd1f68084 100644 --- a/core/shared/platform/nuttx/nuttx_platform.c +++ b/core/shared/platform/nuttx/nuttx_platform.c @@ -10,7 +10,7 @@ #include #endif -#if defined(CONFIG_ARCH_CHIP_ESP32S3) && (CONFIG_ARCH_CHIP_ESP32S3 != 0) +#if defined(CONFIG_ARCH_CHIP_ESP32S3) /* * TODO: Move these methods below the operating system level */