Skip to content

Commit

Permalink
[libc] Align the new thread stack as required by the target ABI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Chandra committed Jun 6, 2022
1 parent eaed07e commit 0539a6b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libc/src/__support/threads/linux/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ template <typename ReturnType> using ThreadRunner = ReturnType(void *);
// 16-byte boundary to satisfy the x86_64 and aarch64 ABI requirements.
// If different architecture in future requires higher alignment, then we
// can add a platform specific alignment spec.
template <typename ReturnType> struct alignas(16) StartArgs {
template <typename ReturnType> struct alignas(STACK_ALIGNMENT) StartArgs {
Thread<ReturnType> *thread;
ThreadRunner<ReturnType> *func;
void *arg;
Expand Down Expand Up @@ -133,6 +133,7 @@ template <typename ReturnType> struct Thread {
sizeof(StartArgs<ReturnType>) -
sizeof(ThreadAttributes<ReturnType>) -
sizeof(cpp::Atomic<FutexWordType>);
adjusted_stack &= ~(uintptr_t(STACK_ALIGNMENT) - 1);

auto *start_args =
reinterpret_cast<StartArgs<ReturnType> *>(adjusted_stack);
Expand Down

0 comments on commit 0539a6b

Please sign in to comment.