aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/Darwin-x86_64-swapcontext.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libthread/Darwin-x86_64-swapcontext.c')
-rw-r--r--src/libthread/Darwin-x86_64-swapcontext.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libthread/Darwin-x86_64-swapcontext.c b/src/libthread/Darwin-x86_64-swapcontext.c
index 27931456..c29ddb5e 100644
--- a/src/libthread/Darwin-x86_64-swapcontext.c
+++ b/src/libthread/Darwin-x86_64-swapcontext.c
@@ -16,6 +16,14 @@ makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
va_end(arg);
sp = (uintptr*)((char*)uc->uc_stack.ss_sp+uc->uc_stack.ss_size);
+ /*
+ * Stack pointer at call instruction (before return address
+ * gets pushed) must be 16-byte aligned.
+ */
+ if((uintptr)sp%4)
+ abort();
+ while((uintptr)sp%16 != 0)
+ sp--;
*--sp = 0; // fn's return address
*--sp = (uintptr)fn; // return address of setcontext
uc->mc.sp = (uintptr)sp;