[libc] Align the new thread stack as required by the target ABI.
authorSiva Chandra <sivachandra@google.com>
Mon, 6 Jun 2022 21:44:35 +0000 (14:44 -0700)
committerSiva Chandra <sivachandra@google.com>
Mon, 6 Jun 2022 21:45:43 +0000 (14:45 -0700)
libc/src/__support/threads/linux/thread.h

index 23e26be..a354f2d 100644 (file)
@@ -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;
@@ -133,6 +133,7 @@ public:
                                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);