mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
bugfix: correct computation of stack size on Mac Posix port (#816)
Aligns the stack end to a page boundary before computing its size, since the size depends on both the start and end. The original change which introduced stack alignment (#674) only worked for cases where the round + trunc operation would wind up within the same area, but would lead to segfaults in other cases. Also adds a typecast to the `mach_vm_round_page()` call, as it is actually a macro which casts to `mach_vm_offset_t` and the result here is used as a `StackType_t` pointer. Tested on ARM64 and Intel MacOS, as well as ARM64 and Intel Linux. The test code included a single-task case, as well as a case with two tasks passing queue messages.
This commit is contained in:
parent
5a9d7c8388
commit
57f9eed00d
6
portable/ThirdParty/GCC/Posix/port.c
vendored
6
portable/ThirdParty/GCC/Posix/port.c
vendored
|
@ -148,10 +148,14 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
|
||||||
*/
|
*/
|
||||||
thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1;
|
thread = ( Thread_t * ) ( pxTopOfStack + 1 ) - 1;
|
||||||
pxTopOfStack = ( StackType_t * ) thread - 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 );
|
ulStackSize = ( size_t ) ( pxTopOfStack + 1 - pxEndOfStack ) * sizeof( *pxTopOfStack );
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
pxEndOfStack = mach_vm_round_page( pxEndOfStack );
|
|
||||||
ulStackSize = mach_vm_trunc_page( ulStackSize );
|
ulStackSize = mach_vm_trunc_page( ulStackSize );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue