mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
POSIX Port: Round up stack sizes correctly on macOS
On macOS, pthread_attr_setstacksize requires the stack size to be a multiple of the system page size. The previous changes here assumed the use of pthread_attr_setstack, however the transition to pthread_attr_setstacksize means we can avoid rounding the pxEndOfStack pointer. This is additionally positive because pxEndOfStack was actually being rounded in the wrong direction -- it ought to have been rounded down (_trunc) instead of up due to the stack growth direction. In my case this actually caused pxEndOfStack to end up after pxTopOfStack, which underflowed and created a huge stack size request + EXC_BAD_ACCESS in pthread_create. Signed-off-by: Paul Hollinsky <paulhollinsky@gmail.com>
This commit is contained in:
parent
a49c35b5dc
commit
f9f0208daa
10
portable/ThirdParty/GCC/Posix/port.c
vendored
10
portable/ThirdParty/GCC/Posix/port.c
vendored
|
@ -165,14 +165,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__
|
||||
ulStackSize = mach_vm_trunc_page( ulStackSize );
|
||||
/*
|
||||
* On macOS, pthread_attr_setstacksize requires the stack to be a multiple of the system page size.
|
||||
* Round up to the next page boundary.
|
||||
*/
|
||||
ulStackSize = mach_vm_round_page( ulStackSize );
|
||||
#endif
|
||||
|
||||
thread->pxCode = pxCode;
|
||||
|
|
Loading…
Reference in a new issue