Skip to content

Commit fd38a04

Browse files
committed
bugfix: correct computation of stack size on Mac Posix port
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.
1 parent 5a9d7c8 commit fd38a04

File tree

1 file changed

+5
-1
lines changed
  • portable/ThirdParty/GCC/Posix

1 file changed

+5
-1
lines changed

portable/ThirdParty/GCC/Posix/port.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
148148
*/
149149
thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1;
150150
pxTopOfStack = ( StackType_t * ) thread - 1;
151+
152+
#ifdef __APPLE__
153+
pxEndOfStack = ( StackType_t *) mach_vm_round_page( pxEndOfStack );
154+
#endif
155+
151156
ulStackSize = ( size_t ) ( pxTopOfStack + 1 - pxEndOfStack ) * sizeof( *pxTopOfStack );
152157

153158
#ifdef __APPLE__
154-
pxEndOfStack = mach_vm_round_page( pxEndOfStack );
155159
ulStackSize = mach_vm_trunc_page( ulStackSize );
156160
#endif
157161

0 commit comments

Comments
 (0)