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.
This commit is contained in:
Guillaume Souchere 2025-02-12 10:29:17 +01:00
parent 68b79fc138
commit 92d575379f
2 changed files with 20 additions and 16 deletions

View File

@ -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 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -29,6 +29,24 @@ bool esp_ptr_dma_ext_capable(const void *p)
#endif //CONFIG_SPIRAM #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) bool esp_ptr_byte_accessible(const void *p)
{ {
intptr_t ip = (intptr_t) p; intptr_t ip = (intptr_t) p;

View File

@ -246,21 +246,7 @@ inline static bool esp_ptr_word_aligned(const void *p)
* *
* @return true: is executable; false: not executable * @return true: is executable; false: not executable
*/ */
__attribute__((always_inline)) bool esp_ptr_executable(const void *p);
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
;
}
/** /**
* @brief Check if the pointer is byte accessible * @brief Check if the pointer is byte accessible