Skip to content

Commit 92d5753

Browse files
committed
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.
1 parent 68b79fc commit 92d5753

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

components/esp_hw_support/esp_memory_utils.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -29,6 +29,24 @@ bool esp_ptr_dma_ext_capable(const void *p)
2929
#endif //CONFIG_SPIRAM
3030
}
3131

32+
bool esp_ptr_executable(const void *p)
33+
{
34+
intptr_t ip = (intptr_t) p;
35+
return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH)
36+
|| (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH)
37+
|| (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH)
38+
#if SOC_SPIRAM_SUPPORTED && CONFIG_SPIRAM
39+
|| esp_ptr_external_ram(p)
40+
#endif
41+
#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE)
42+
|| (ip >= SOC_CACHE_APP_LOW && ip < SOC_CACHE_APP_HIGH)
43+
#endif
44+
#if SOC_RTC_FAST_MEM_SUPPORTED
45+
|| (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH)
46+
#endif
47+
;
48+
}
49+
3250
bool esp_ptr_byte_accessible(const void *p)
3351
{
3452
intptr_t ip = (intptr_t) p;

components/esp_hw_support/include/esp_memory_utils.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,7 @@ inline static bool esp_ptr_word_aligned(const void *p)
246246
*
247247
* @return true: is executable; false: not executable
248248
*/
249-
__attribute__((always_inline))
250-
inline static bool esp_ptr_executable(const void *p)
251-
{
252-
intptr_t ip = (intptr_t) p;
253-
return (ip >= SOC_IROM_LOW && ip < SOC_IROM_HIGH)
254-
|| (ip >= SOC_IRAM_LOW && ip < SOC_IRAM_HIGH)
255-
|| (ip >= SOC_IROM_MASK_LOW && ip < SOC_IROM_MASK_HIGH)
256-
#if defined(SOC_CACHE_APP_LOW) && defined(CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE)
257-
|| (ip >= SOC_CACHE_APP_LOW && ip < SOC_CACHE_APP_HIGH)
258-
#endif
259-
#if SOC_RTC_FAST_MEM_SUPPORTED
260-
|| (ip >= SOC_RTC_IRAM_LOW && ip < SOC_RTC_IRAM_HIGH)
261-
#endif
262-
;
263-
}
249+
bool esp_ptr_executable(const void *p);
264250

265251
/**
266252
* @brief Check if the pointer is byte accessible

0 commit comments

Comments
 (0)