mirror of
				https://github.com/FreeRTOS/FreeRTOS-Kernel.git
				synced 2025-11-04 11:09:01 +01:00 
			
		
		
		
	Fix heap address calculation issue (#781)
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
		
							parent
							
								
									231278eded
								
							
						
					
					
						commit
						d6bccb1f4c
					
				@ -444,17 +444,17 @@ void * pvPortCalloc( size_t xNum,
 | 
				
			|||||||
static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
 | 
					static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BlockLink_t * pxFirstFreeBlock;
 | 
					    BlockLink_t * pxFirstFreeBlock;
 | 
				
			||||||
    portPOINTER_SIZE_TYPE uxAddress;
 | 
					    portPOINTER_SIZE_TYPE uxStartAddress, uxEndAddress;
 | 
				
			||||||
    size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
 | 
					    size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Ensure the heap starts on a correctly aligned boundary. */
 | 
					    /* Ensure the heap starts on a correctly aligned boundary. */
 | 
				
			||||||
    uxAddress = ( portPOINTER_SIZE_TYPE ) ucHeap;
 | 
					    uxStartAddress = ( portPOINTER_SIZE_TYPE ) ucHeap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
 | 
					    if( ( uxStartAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        uxAddress += ( portBYTE_ALIGNMENT - 1 );
 | 
					        uxStartAddress += ( portBYTE_ALIGNMENT - 1 );
 | 
				
			||||||
        uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
 | 
					        uxStartAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
 | 
				
			||||||
        xTotalHeapSize -= ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) ucHeap );
 | 
					        xTotalHeapSize -= ( size_t ) ( uxStartAddress - ( portPOINTER_SIZE_TYPE ) ucHeap );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #if ( configENABLE_HEAP_PROTECTOR == 1 )
 | 
					    #if ( configENABLE_HEAP_PROTECTOR == 1 )
 | 
				
			||||||
@ -465,22 +465,22 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /* xStart is used to hold a pointer to the first item in the list of free
 | 
					    /* xStart is used to hold a pointer to the first item in the list of free
 | 
				
			||||||
     * blocks.  The void cast is used to prevent compiler warnings. */
 | 
					     * blocks.  The void cast is used to prevent compiler warnings. */
 | 
				
			||||||
    xStart.pxNextFreeBlock = ( void * ) heapPROTECT_BLOCK_POINTER( uxAddress );
 | 
					    xStart.pxNextFreeBlock = ( void * ) heapPROTECT_BLOCK_POINTER( uxStartAddress );
 | 
				
			||||||
    xStart.xBlockSize = ( size_t ) 0;
 | 
					    xStart.xBlockSize = ( size_t ) 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* pxEnd is used to mark the end of the list of free blocks and is inserted
 | 
					    /* pxEnd is used to mark the end of the list of free blocks and is inserted
 | 
				
			||||||
     * at the end of the heap space. */
 | 
					     * at the end of the heap space. */
 | 
				
			||||||
    uxAddress = ( portPOINTER_SIZE_TYPE ) ( uxAddress + xTotalHeapSize );
 | 
					    uxEndAddress = uxStartAddress + ( portPOINTER_SIZE_TYPE ) xTotalHeapSize;
 | 
				
			||||||
    uxAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
 | 
					    uxEndAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
 | 
				
			||||||
    uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
 | 
					    uxEndAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
 | 
				
			||||||
    pxEnd = ( BlockLink_t * ) uxAddress;
 | 
					    pxEnd = ( BlockLink_t * ) uxEndAddress;
 | 
				
			||||||
    pxEnd->xBlockSize = 0;
 | 
					    pxEnd->xBlockSize = 0;
 | 
				
			||||||
    pxEnd->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
 | 
					    pxEnd->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* To start with there is a single free block that is sized to take up the
 | 
					    /* To start with there is a single free block that is sized to take up the
 | 
				
			||||||
     * entire heap space, minus the space taken by pxEnd. */
 | 
					     * entire heap space, minus the space taken by pxEnd. */
 | 
				
			||||||
    pxFirstFreeBlock = ( BlockLink_t * ) uxAddress;
 | 
					    pxFirstFreeBlock = ( BlockLink_t * ) uxStartAddress;
 | 
				
			||||||
    pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
 | 
					    pxFirstFreeBlock->xBlockSize = ( size_t ) ( uxEndAddress - ( portPOINTER_SIZE_TYPE ) pxFirstFreeBlock );
 | 
				
			||||||
    pxFirstFreeBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( pxEnd );
 | 
					    pxFirstFreeBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( pxEnd );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Only one block exists - and it covers the entire usable heap space. */
 | 
					    /* Only one block exists - and it covers the entire usable heap space. */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user