From 22208274634ba17f5d184f130b16a42fd581979f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 8 Feb 2021 17:34:00 +0900 Subject: [PATCH] esp32_allocateheap.c: Add a sanity check --- arch/xtensa/src/esp32/esp32_allocateheap.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_allocateheap.c b/arch/xtensa/src/esp32/esp32_allocateheap.c index 757ef8e2fd..4b25677b6f 100644 --- a/arch/xtensa/src/esp32/esp32_allocateheap.c +++ b/arch/xtensa/src/esp32/esp32_allocateheap.c @@ -102,6 +102,12 @@ # define HEAP_REGION2_START 0x3ffe7e40 #endif +#ifdef CONFIG_XTENSA_USE_SEPARATE_IMEM +#define XTENSA_IMEM_REGION_SIZE CONFIG_XTENSA_IMEM_REGION_SIZE +#else +#define XTENSA_IMEM_REGION_SIZE 0 +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -124,13 +130,14 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size) { board_autoled_on(LED_HEAPALLOCATE); -#ifdef CONFIG_XTENSA_USE_SEPARATE_IMEM - *heap_start = (FAR void *)&_sheap + CONFIG_XTENSA_IMEM_REGION_SIZE; + *heap_start = (FAR void *)&_sheap + XTENSA_IMEM_REGION_SIZE; + + /* If the following DEBUGASSERT fails, + * probably you have too large CONFIG_XTENSA_IMEM_REGION_SIZE. + */ + + DEBUGASSERT(HEAP_REGION1_END > (uintptr_t)*heap_start); *heap_size = (size_t)(HEAP_REGION1_END - (uintptr_t)*heap_start); -#else - *heap_start = (FAR void *)&_sheap; - *heap_size = (size_t)(HEAP_REGION1_END - (uintptr_t)&_sheap); -#endif } /****************************************************************************