You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2021/02/09 07:51:24 UTC
[incubator-nuttx] 02/02: esp32_allocateheap.c: Add a sanity check
This is an automated email from the ASF dual-hosted git repository.
aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 22208274634ba17f5d184f130b16a42fd581979f
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Feb 8 17:34:00 2021 +0900
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 757ef8e..4b25677 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
}
/****************************************************************************