From 2519db5ad5da187ff1c466c7175b8e02d8059ed2 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Wed, 2 Jul 2014 10:15:26 +0100 Subject: [PATCH] mini-os: x86_64: make thread stacks 16-byte aligned Otherwise, passing doubles to varargs functions causes a crash. Signed-off-by: Thomas Leonard --- extras/mini-os/arch/x86/sched.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extras/mini-os/arch/x86/sched.c b/extras/mini-os/arch/x86/sched.c index 8a05b58..e4a3dc2 100644 --- a/extras/mini-os/arch/x86/sched.c +++ b/extras/mini-os/arch/x86/sched.c @@ -107,6 +107,9 @@ struct thread* arch_create_thread(char *name, void (*function)(void *), thread->sp = (unsigned long)thread->stack + STACK_SIZE; /* Save pointer to the thread on the stack, used by current macro */ *((unsigned long *)thread->stack) = (unsigned long)thread; + + /* Must ensure that (%rsp + 8) is 16-byte aligned at the start of thread_starter. */ + thread->sp -= sizeof(unsigned long); stack_push(thread, (unsigned long) function); stack_push(thread, (unsigned long) data); -- 2.0.0