117
117
#define heapALLOCATE_BLOCK ( pxBlock ) ( ( pxBlock->xBlockSize ) |= heapBLOCK_ALLOCATED_BITMASK )
118
118
#define heapFREE_BLOCK ( pxBlock ) ( ( pxBlock->xBlockSize ) &= ~heapBLOCK_ALLOCATED_BITMASK )
119
119
120
- /*-----------------------------------------------------------*/
121
-
122
- /* Define the linked list structure. This is used to link free blocks in order
123
- * of their memory address. */
124
- typedef struct A_BLOCK_LINK
125
- {
126
- struct A_BLOCK_LINK * pxNextFreeBlock ; /**< The next free block in the list. */
127
- size_t xBlockSize ; /**< The size of the free block. */
128
- } BlockLink_t ;
129
-
130
120
/* Setting configENABLE_HEAP_PROTECTOR to 1 enables heap block pointers
131
121
* protection using an application supplied canary value to catch heap
132
122
* corruption should a heap buffer overflow occur.
133
123
*/
134
124
#if ( configENABLE_HEAP_PROTECTOR == 1 )
135
125
136
- /**
137
- * @brief Application provided function to get a random value to be used as canary.
138
- *
139
- * @param pxHeapCanary [out] Output parameter to return the canary value.
140
- */
141
- extern void vApplicationGetRandomHeapCanary ( portPOINTER_SIZE_TYPE * pxHeapCanary );
142
-
143
- /* Canary value for protecting internal heap pointers. */
144
- PRIVILEGED_DATA static portPOINTER_SIZE_TYPE xHeapCanary ;
145
-
146
-
147
126
/* Macro to load/store BlockLink_t pointers to memory. By XORing the
148
127
* pointers with a random canary value, heap overflows will result
149
128
* in randomly unpredictable pointer values which will be caught by
150
129
* heapVALIDATE_BLOCK_POINTER assert. */
151
130
#define heapPROTECT_BLOCK_POINTER ( pxBlock ) ( ( BlockLink_t * ) ( ( ( portPOINTER_SIZE_TYPE ) ( pxBlock ) ) ^ xHeapCanary ) )
152
131
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 ) )
138
+
153
139
#else /* if ( configENABLE_HEAP_PROTECTOR == 1 ) */
154
140
155
- #define heapPROTECT_BLOCK_POINTER ( pxBlock ) ( pxBlock )
141
+ #define heapPROTECT_BLOCK_POINTER ( pxBlock ) ( pxBlock )
142
+
143
+ #define heapVALIDATE_BLOCK_POINTER ( pxBlock ) ( pxBlock )
156
144
157
145
#endif /* configENABLE_HEAP_PROTECTOR */
158
146
159
- /* Highest and lowest heap addresses used for heap block bounds checking. */
160
- PRIVILEGED_DATA static uint8_t * pucHeapHighAddress = NULL ;
161
- PRIVILEGED_DATA static uint8_t * pucHeapLowAddress = NULL ;
147
+ /*-----------------------------------------------------------*/
162
148
163
- /* Assert that a heap block pointer is within the heap bounds. */
164
- #define heapVALIDATE_BLOCK_POINTER ( pxBlock ) \
165
- configASSERT( ( pucHeapHighAddress != NULL ) && \
166
- ( pucHeapLowAddress != NULL ) && \
167
- ( ( uint8_t * ) ( pxBlock ) >= pucHeapLowAddress ) && \
168
- ( ( uint8_t * ) ( pxBlock ) < pucHeapHighAddress ) )
149
+ /* Define the linked list structure. This is used to link free blocks in order
150
+ * of their memory address. */
151
+ typedef struct A_BLOCK_LINK
152
+ {
153
+ struct A_BLOCK_LINK * pxNextFreeBlock ; /**< The next free block in the list. */
154
+ size_t xBlockSize ; /**< The size of the free block. */
155
+ } BlockLink_t ;
169
156
170
157
/*-----------------------------------------------------------*/
171
158
@@ -177,6 +164,17 @@ PRIVILEGED_DATA static uint8_t * pucHeapLowAddress = NULL;
177
164
*/
178
165
static void prvInsertBlockIntoFreeList ( BlockLink_t * pxBlockToInsert ) PRIVILEGED_FUNCTION ;
179
166
void vPortDefineHeapRegions ( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION ;
167
+
168
+ #if ( configENABLE_HEAP_PROTECTOR == 1 )
169
+
170
+ /**
171
+ * @brief Application provided function to get a random value to be used as canary.
172
+ *
173
+ * @param pxHeapCanary [out] Output parameter to return the canary value.
174
+ */
175
+ extern void vApplicationGetRandomHeapCanary ( portPOINTER_SIZE_TYPE * pxHeapCanary );
176
+ #endif /* configENABLE_HEAP_PROTECTOR */
177
+
180
178
/*-----------------------------------------------------------*/
181
179
182
180
/* The size of the structure placed at the beginning of each allocated memory
@@ -194,6 +192,17 @@ PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U;
194
192
PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = 0 ;
195
193
PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = 0 ;
196
194
195
+ #if ( configENABLE_HEAP_PROTECTOR == 1 )
196
+
197
+ /* Canary value for protecting internal heap pointers. */
198
+ PRIVILEGED_DATA static portPOINTER_SIZE_TYPE xHeapCanary ;
199
+
200
+ /* Highest and lowest heap addresses used for heap block bounds checking. */
201
+ PRIVILEGED_DATA static uint8_t * pucHeapHighAddress = NULL ;
202
+ PRIVILEGED_DATA static uint8_t * pucHeapLowAddress = NULL ;
203
+
204
+ #endif /* configENABLE_HEAP_PROTECTOR */
205
+
197
206
/*-----------------------------------------------------------*/
198
207
199
208
void * pvPortMalloc ( size_t xWantedSize )
0 commit comments