Skip to content

Commit 61440fc

Browse files
authored
Refine heap_5 heap protector (FreeRTOS#1146)
Add configVALIDATE_HEAP_BLOCK_POINTER on heap_5 heap_5 is used for multiple separated memory spaces. In the previous implementation, it only verifies the highest and lowest addresses. A pointer may not be within heap regions, but is still located between the highest and lowest addressed. Add maco configVALIDATE_HEAP_BLOCK_POINTER to provide customized heap block pointers detection based on the settings of heap regions. Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn>
1 parent d3052f1 commit 61440fc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

portable/MemMang/heap_5.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,19 @@
129129
* heapVALIDATE_BLOCK_POINTER assert. */
130130
#define heapPROTECT_BLOCK_POINTER( pxBlock ) ( ( BlockLink_t * ) ( ( ( portPOINTER_SIZE_TYPE ) ( pxBlock ) ) ^ xHeapCanary ) )
131131

132-
/* Assert that a heap block pointer is within the heap bounds. */
133-
#define heapVALIDATE_BLOCK_POINTER( pxBlock ) \
134-
configASSERT( ( pucHeapHighAddress != NULL ) && \
135-
( pucHeapLowAddress != NULL ) && \
136-
( ( uint8_t * ) ( pxBlock ) >= pucHeapLowAddress ) && \
137-
( ( uint8_t * ) ( pxBlock ) < pucHeapHighAddress ) )
132+
/* Assert that a heap block pointer is within the heap bounds.
133+
* Setting configVALIDATE_HEAP_BLOCK_POINTER to 1 enables customized heap block pointers
134+
* protection on heap_5. */
135+
#ifndef configVALIDATE_HEAP_BLOCK_POINTER
136+
#define heapVALIDATE_BLOCK_POINTER( pxBlock ) \
137+
configASSERT( ( pucHeapHighAddress != NULL ) && \
138+
( pucHeapLowAddress != NULL ) && \
139+
( ( uint8_t * ) ( pxBlock ) >= pucHeapLowAddress ) && \
140+
( ( uint8_t * ) ( pxBlock ) < pucHeapHighAddress ) )
141+
#else /* ifndef configVALIDATE_HEAP_BLOCK_POINTER */
142+
#define heapVALIDATE_BLOCK_POINTER( pxBlock ) \
143+
configVALIDATE_HEAP_BLOCK_POINTER( pxBlock )
144+
#endif /* configVALIDATE_HEAP_BLOCK_POINTER */
138145

139146
#else /* if ( configENABLE_HEAP_PROTECTOR == 1 ) */
140147

0 commit comments

Comments
 (0)