Skip to content

Commit 3121075

Browse files
Merge branch 'main' into main
2 parents dad7a5e + 231278e commit 3121075

File tree

3 files changed

+45
-39
lines changed

3 files changed

+45
-39
lines changed

portable/MemMang/heap_4.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ void * pvPortCalloc( size_t xNum,
444444
static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
445445
{
446446
BlockLink_t * pxFirstFreeBlock;
447-
uint8_t * pucAlignedHeap;
448447
portPOINTER_SIZE_TYPE uxAddress;
449448
size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
450449

@@ -458,8 +457,6 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
458457
xTotalHeapSize -= ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) ucHeap );
459458
}
460459

461-
pucAlignedHeap = ( uint8_t * ) uxAddress;
462-
463460
#if ( configENABLE_HEAP_PROTECTOR == 1 )
464461
{
465462
vApplicationGetRandomHeapCanary( &( xHeapCanary ) );
@@ -468,12 +465,12 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
468465

469466
/* xStart is used to hold a pointer to the first item in the list of free
470467
* blocks. The void cast is used to prevent compiler warnings. */
471-
xStart.pxNextFreeBlock = ( void * ) heapPROTECT_BLOCK_POINTER( pucAlignedHeap );
468+
xStart.pxNextFreeBlock = ( void * ) heapPROTECT_BLOCK_POINTER( uxAddress );
472469
xStart.xBlockSize = ( size_t ) 0;
473470

474471
/* pxEnd is used to mark the end of the list of free blocks and is inserted
475472
* at the end of the heap space. */
476-
uxAddress = ( portPOINTER_SIZE_TYPE ) ( pucAlignedHeap + xTotalHeapSize );
473+
uxAddress = ( portPOINTER_SIZE_TYPE ) ( uxAddress + xTotalHeapSize );
477474
uxAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
478475
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
479476
pxEnd = ( BlockLink_t * ) uxAddress;
@@ -482,7 +479,7 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
482479

483480
/* To start with there is a single free block that is sized to take up the
484481
* entire heap space, minus the space taken by pxEnd. */
485-
pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
482+
pxFirstFreeBlock = ( BlockLink_t * ) uxAddress;
486483
pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
487484
pxFirstFreeBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( pxEnd );
488485

portable/MemMang/heap_5.c

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,55 +117,42 @@
117117
#define heapALLOCATE_BLOCK( pxBlock ) ( ( pxBlock->xBlockSize ) |= heapBLOCK_ALLOCATED_BITMASK )
118118
#define heapFREE_BLOCK( pxBlock ) ( ( pxBlock->xBlockSize ) &= ~heapBLOCK_ALLOCATED_BITMASK )
119119

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-
130120
/* Setting configENABLE_HEAP_PROTECTOR to 1 enables heap block pointers
131121
* protection using an application supplied canary value to catch heap
132122
* corruption should a heap buffer overflow occur.
133123
*/
134124
#if ( configENABLE_HEAP_PROTECTOR == 1 )
135125

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-
147126
/* Macro to load/store BlockLink_t pointers to memory. By XORing the
148127
* pointers with a random canary value, heap overflows will result
149128
* in randomly unpredictable pointer values which will be caught by
150129
* heapVALIDATE_BLOCK_POINTER assert. */
151130
#define heapPROTECT_BLOCK_POINTER( pxBlock ) ( ( BlockLink_t * ) ( ( ( portPOINTER_SIZE_TYPE ) ( pxBlock ) ) ^ xHeapCanary ) )
152131

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+
153139
#else /* if ( configENABLE_HEAP_PROTECTOR == 1 ) */
154140

155141
#define heapPROTECT_BLOCK_POINTER( pxBlock ) ( pxBlock )
156142

143+
#define heapVALIDATE_BLOCK_POINTER( pxBlock )
144+
157145
#endif /* configENABLE_HEAP_PROTECTOR */
158146

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+
/*-----------------------------------------------------------*/
162148

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;
169156

170157
/*-----------------------------------------------------------*/
171158

@@ -177,6 +164,17 @@ PRIVILEGED_DATA static uint8_t * pucHeapLowAddress = NULL;
177164
*/
178165
static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert ) PRIVILEGED_FUNCTION;
179166
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+
180178
/*-----------------------------------------------------------*/
181179

182180
/* The size of the structure placed at the beginning of each allocated memory
@@ -194,6 +192,17 @@ PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U;
194192
PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = 0;
195193
PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = 0;
196194

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+
197206
/*-----------------------------------------------------------*/
198207

199208
void * pvPortMalloc( size_t xWantedSize )
@@ -553,7 +562,7 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) /* PRIVI
553562
if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
554563
{
555564
xAddress += ( portBYTE_ALIGNMENT - 1 );
556-
xAddress &= ~portBYTE_ALIGNMENT_MASK;
565+
xAddress &= ~( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK;
557566

558567
/* Adjust the size for the bytes lost to alignment. */
559568
xTotalRegionSize -= ( size_t ) ( xAddress - ( portPOINTER_SIZE_TYPE ) pxHeapRegion->pucStartAddress );

tasks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5118,7 +5118,7 @@ void vTaskMissedYield( void )
51185118

51195119
taskYIELD();
51205120

5121-
while( INFINITE_LOOP() )
5121+
for( ; INFINITE_LOOP(); )
51225122
{
51235123
#if ( configUSE_PREEMPTION == 0 )
51245124
{
@@ -5203,7 +5203,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
52035203
}
52045204
#endif /* #if ( configNUMBER_OF_CORES > 1 ) */
52055205

5206-
while( INFINITE_LOOP() )
5206+
for( ; INFINITE_LOOP(); )
52075207
{
52085208
/* See if any tasks have deleted themselves - if so then the idle task
52095209
* is responsible for freeing the deleted task's TCB and stack. */

0 commit comments

Comments
 (0)