From cb076f20973c3459dfb35857dc65e88cf70a3151 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Wed, 12 Feb 2025 10:29:17 +0100 Subject: [PATCH] fix(memory-utils): Missing case in esp_ptr_executable logic esp_ptr_executable does not consider that the PSRAM and FLASH memory mapping are not always matching. Added a "pointer is in PSRAM" specific check in the logic to fix the issue. --- components/esp_hw_support/esp_memory_utils.c | 20 ++++++++++++++++++- .../esp_hw_support/include/esp_memory_utils.h | 16 +-------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/components/esp_hw_support/esp_memory_utils.c b/components/esp_hw_support/esp_memory_utils.c index 766ca5a2c1..70788a3daf 100644 --- a/components/esp_hw_support/esp_memory_utils.c +++ b/components/esp_hw_support/esp_memory_utils.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -29,6 +29,24 @@ bool esp_ptr_dma_ext_capable(const void *p) #endif //CONFIG_SPIRAM } +bool esp_ptr_executable(const void *p) +{ + intptr_t ip = (intptr_t) p; + return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH) + || (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH) + || (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH) +#if SOC_SPIRAM_SUPPORTED && CONFIG_SPIRAM + || esp_ptr_external_ram(p) +#endif +#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) + || (ip >= SOC_CACHE_APP_LOW && ip < SOC_CACHE_APP_HIGH) +#endif +#if SOC_RTC_FAST_MEM_SUPPORTED + || (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH) +#endif + ; +} + bool esp_ptr_byte_accessible(const void *p) { intptr_t ip = (intptr_t) p; diff --git a/components/esp_hw_support/include/esp_memory_utils.h b/components/esp_hw_support/include/esp_memory_utils.h index c6b4983588..502ab4ef2c 100644 --- a/components/esp_hw_support/include/esp_memory_utils.h +++ b/components/esp_hw_support/include/esp_memory_utils.h @@ -255,21 +255,7 @@ inline static bool esp_ptr_word_aligned(const void *p) * * @return true: is executable; false: not executable */ -__attribute__((always_inline)) -inline static bool esp_ptr_executable(const void *p) -{ - intptr_t ip = (intptr_t) p; - return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH) - || (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH) - || (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH) -#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) - || (ip >= SOC_CACHE_APP_LOW && ip < SOC_CACHE_APP_HIGH) -#endif -#if SOC_RTC_FAST_MEM_SUPPORTED - || (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH) -#endif - ; -} +bool esp_ptr_executable(const void *p); /** * @brief Check if the pointer is byte accessible