Correct calculation of xHeapStructSize in heap_4 and heap_5.

Convert uint32_t types to size_t types in heap_5.c, as was previously done for heap_4.c.
pull/4/head
Richard Barry 10 years ago
parent 4ee2a96861
commit 95b73d40d9

@ -88,7 +88,7 @@ task.h is included from an application file. */
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/* Block sizes must not get too small. */ /* Block sizes must not get too small. */
#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize * 2 ) ) #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )
/* Assumes 8bit bytes! */ /* Assumes 8bit bytes! */
#define heapBITS_PER_BYTE ( ( size_t ) 8 ) #define heapBITS_PER_BYTE ( ( size_t ) 8 )
@ -130,7 +130,7 @@ static void prvHeapInit( void );
/* The size of the structure placed at the beginning of each allocated memory /* The size of the structure placed at the beginning of each allocated memory
block must by correctly byte aligned. */ block must by correctly byte aligned. */
static const size_t xHeapStructSize = ( ( sizeof( BlockLink_t ) + ( ( ( size_t ) portBYTE_ALIGNMENT_MASK ) - ( size_t ) 1 ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK ) ); static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
/* Create a couple of list links to mark the start and end of the list. */ /* Create a couple of list links to mark the start and end of the list. */
static BlockLink_t xStart, *pxEnd = NULL; static BlockLink_t xStart, *pxEnd = NULL;
@ -229,7 +229,7 @@ void *pvReturn = NULL;
cast is used to prevent byte alignment warnings from the cast is used to prevent byte alignment warnings from the
compiler. */ compiler. */
pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
configASSERT( ( ( ( uint32_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 ); configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );
/* Calculate the sizes of two blocks split from the /* Calculate the sizes of two blocks split from the
single block. */ single block. */

@ -122,7 +122,7 @@ task.h is included from an application file. */
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/* Block sizes must not get too small. */ /* Block sizes must not get too small. */
#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( uxHeapStructSize << 1 ) ) #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )
/* Assumes 8bit bytes! */ /* Assumes 8bit bytes! */
#define heapBITS_PER_BYTE ( ( size_t ) 8 ) #define heapBITS_PER_BYTE ( ( size_t ) 8 )
@ -149,15 +149,15 @@ static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert );
/* The size of the structure placed at the beginning of each allocated memory /* The size of the structure placed at the beginning of each allocated memory
block must by correctly byte aligned. */ block must by correctly byte aligned. */
static const uint32_t uxHeapStructSize = ( ( sizeof ( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK ); static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
/* Create a couple of list links to mark the start and end of the list. */ /* Create a couple of list links to mark the start and end of the list. */
static BlockLink_t xStart, *pxEnd = NULL; static BlockLink_t xStart, *pxEnd = NULL;
/* Keeps track of the number of free bytes remaining, but says nothing about /* Keeps track of the number of free bytes remaining, but says nothing about
fragmentation. */ fragmentation. */
static size_t xFreeBytesRemaining = 0; static size_t xFreeBytesRemaining = 0U;
static size_t xMinimumEverFreeBytesRemaining = 0; static size_t xMinimumEverFreeBytesRemaining = 0U;
/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize /* Gets set to the top bit of an size_t type. When this bit in the xBlockSize
member of an BlockLink_t structure is set then the block belongs to the member of an BlockLink_t structure is set then the block belongs to the
@ -188,7 +188,7 @@ void *pvReturn = NULL;
structure in addition to the requested amount of bytes. */ structure in addition to the requested amount of bytes. */
if( xWantedSize > 0 ) if( xWantedSize > 0 )
{ {
xWantedSize += uxHeapStructSize; xWantedSize += xHeapStructSize;
/* Ensure that blocks are always aligned to the required number /* Ensure that blocks are always aligned to the required number
of bytes. */ of bytes. */
@ -225,7 +225,7 @@ void *pvReturn = NULL;
{ {
/* Return the memory space pointed to - jumping over the /* Return the memory space pointed to - jumping over the
BlockLink_t structure at its start. */ BlockLink_t structure at its start. */
pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + uxHeapStructSize ); pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );
/* This block is being returned for use so must be taken out /* This block is being returned for use so must be taken out
of the list of free blocks. */ of the list of free blocks. */
@ -316,7 +316,7 @@ BlockLink_t *pxLink;
{ {
/* The memory being freed will have an BlockLink_t structure immediately /* The memory being freed will have an BlockLink_t structure immediately
before it. */ before it. */
puc -= uxHeapStructSize; puc -= xHeapStructSize;
/* This casting is to keep the compiler from issuing warnings. */ /* This casting is to keep the compiler from issuing warnings. */
pxLink = ( void * ) puc; pxLink = ( void * ) puc;
@ -434,7 +434,7 @@ BlockLink_t *pxFirstFreeBlockInRegion = NULL, *pxPreviousFreeBlock;
uint8_t *pucAlignedHeap; uint8_t *pucAlignedHeap;
size_t xTotalRegionSize, xTotalHeapSize = 0; size_t xTotalRegionSize, xTotalHeapSize = 0;
BaseType_t xDefinedRegions = 0; BaseType_t xDefinedRegions = 0;
uint32_t ulAddress; size_t xAddress;
const HeapRegion_t *pxHeapRegion; const HeapRegion_t *pxHeapRegion;
/* Can only call once! */ /* Can only call once! */
@ -447,17 +447,17 @@ const HeapRegion_t *pxHeapRegion;
xTotalRegionSize = pxHeapRegion->xSizeInBytes; xTotalRegionSize = pxHeapRegion->xSizeInBytes;
/* Ensure the heap region starts on a correctly aligned boundary. */ /* Ensure the heap region starts on a correctly aligned boundary. */
ulAddress = ( uint32_t ) pxHeapRegion->pucStartAddress; xAddress = ( size_t ) pxHeapRegion->pucStartAddress;
if( ( ulAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
{ {
ulAddress += ( portBYTE_ALIGNMENT - 1 ); xAddress += ( portBYTE_ALIGNMENT - 1 );
ulAddress &= ~portBYTE_ALIGNMENT_MASK; xAddress &= ~portBYTE_ALIGNMENT_MASK;
/* Adjust the size for the bytes lost to alignment. */ /* Adjust the size for the bytes lost to alignment. */
xTotalRegionSize -= ulAddress - ( uint32_t ) pxHeapRegion->pucStartAddress; xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress;
} }
pucAlignedHeap = ( uint8_t * ) ulAddress; pucAlignedHeap = ( uint8_t * ) xAddress;
/* Set xStart if it has not already been set. */ /* Set xStart if it has not already been set. */
if( xDefinedRegions == 0 ) if( xDefinedRegions == 0 )
@ -474,7 +474,7 @@ const HeapRegion_t *pxHeapRegion;
configASSERT( pxEnd != NULL ); configASSERT( pxEnd != NULL );
/* Check blocks are passed in with increasing start addresses. */ /* Check blocks are passed in with increasing start addresses. */
configASSERT( ulAddress > ( uint32_t ) pxEnd ); configASSERT( xAddress > ( size_t ) pxEnd );
} }
/* Remember the location of the end marker in the previous region, if /* Remember the location of the end marker in the previous region, if
@ -483,10 +483,10 @@ const HeapRegion_t *pxHeapRegion;
/* pxEnd is used to mark the end of the list of free blocks and is /* pxEnd is used to mark the end of the list of free blocks and is
inserted at the end of the region space. */ inserted at the end of the region space. */
ulAddress = ( ( uint32_t ) pucAlignedHeap ) + xTotalRegionSize; xAddress = ( ( size_t ) pucAlignedHeap ) + xTotalRegionSize;
ulAddress -= uxHeapStructSize; xAddress -= xHeapStructSize;
ulAddress &= ~portBYTE_ALIGNMENT_MASK; xAddress &= ~portBYTE_ALIGNMENT_MASK;
pxEnd = ( BlockLink_t * ) ulAddress; pxEnd = ( BlockLink_t * ) xAddress;
pxEnd->xBlockSize = 0; pxEnd->xBlockSize = 0;
pxEnd->pxNextFreeBlock = NULL; pxEnd->pxNextFreeBlock = NULL;
@ -494,7 +494,7 @@ const HeapRegion_t *pxHeapRegion;
sized to take up the entire heap region minus the space taken by the sized to take up the entire heap region minus the space taken by the
free block structure. */ free block structure. */
pxFirstFreeBlockInRegion = ( BlockLink_t * ) pucAlignedHeap; pxFirstFreeBlockInRegion = ( BlockLink_t * ) pucAlignedHeap;
pxFirstFreeBlockInRegion->xBlockSize = ulAddress - ( uint32_t ) pxFirstFreeBlockInRegion; pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion;
pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd; pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd;
/* If this is not the first region that makes up the entire heap space /* If this is not the first region that makes up the entire heap space

Loading…
Cancel
Save