Skip to content

Commit

Permalink
bugfix: correct computation of stack size on Mac Posix port
Browse files Browse the repository at this point in the history
Computes the stack size after the end is aligned to a page
boundary.  The original code in (FreeRTOS#674) did not account for
this so some combinations of stack address alignments and
sizes would cause a segfault.

Tested on ARM64 and Intel MacOS, as well as ARM64 and Intel
Linux.
  • Loading branch information
tegimeki committed Oct 1, 2023
1 parent 5a9d7c8 commit fd38a04
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion portable/ThirdParty/GCC/Posix/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
*/
thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1;
pxTopOfStack = ( StackType_t * ) thread - 1;

#ifdef __APPLE__
pxEndOfStack = ( StackType_t *) mach_vm_round_page( pxEndOfStack );
#endif

ulStackSize = ( size_t ) ( pxTopOfStack + 1 - pxEndOfStack ) * sizeof( *pxTopOfStack );

#ifdef __APPLE__
pxEndOfStack = mach_vm_round_page( pxEndOfStack );
ulStackSize = mach_vm_trunc_page( ulStackSize );
#endif

Expand Down

0 comments on commit fd38a04

Please sign in to comment.