Hi, I’m currently deep-diving into FreeRTOS and I noticed with a kernel-aware debugger, that FreeRTOS “wastes” space on the stack and I see no reason for it. My statically-allocated stack is 8-byte aligned and 512 bytes big.
For example: One stack is
FreeRTOS now does this to set the initial stack pointer in
pxTopOfStack = &( pxNewTCB->pxStack[ ulStackDepth - ( uint32_t ) 1 ] ); pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
This essentially gets the address
0x2400054C in the first line and truncates it to
0x24000548 in the second. This loses 8 bytes at the very bottom of the stack, which never gets written to. And if the stack is aligned to 4 bytes then, it might only loose 4 bytes sometimes (C>8>8 instead of 0>C>8), but I find this really strange.
Is there any explanation for this behaviour?