Skip to content

Commit 69e6b75

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

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)