From ae01a311040d92bb9b4a3d173b91b456e623fd93 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 19 Jun 2023 10:41:32 +0200 Subject: [PATCH] kernel: Make sure the stack is 16-byte aligned on program startup This is required by the System V ABI and fixes some movaps-related GPFs in ndisasm. --- kernel/src/thread/ThreadImage.cpp | 3 ++- libluna/src/Stack.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/src/thread/ThreadImage.cpp b/kernel/src/thread/ThreadImage.cpp index d937223b..a16ab223 100644 --- a/kernel/src/thread/ThreadImage.cpp +++ b/kernel/src/thread/ThreadImage.cpp @@ -1,6 +1,7 @@ #include "thread/ThreadImage.h" #include "memory/MemoryManager.h" #include "thread/Thread.h" +#include #include static constexpr usize DEFAULT_USER_STACK_PAGES = 6; @@ -122,7 +123,7 @@ void ThreadImage::apply(Thread* thread) thread->kernel_stack = m_kernel_stack; thread->stack = m_user_stack; - thread->set_sp(m_sp); + thread->set_sp(align_down<16>(m_sp)); thread->directory = m_directory; diff --git a/libluna/src/Stack.cpp b/libluna/src/Stack.cpp index a4fb02ef..7f971403 100644 --- a/libluna/src/Stack.cpp +++ b/libluna/src/Stack.cpp @@ -6,5 +6,5 @@ Stack::Stack(u64 base, usize bytes) : m_base(base), m_bytes(bytes) u64 Stack::top() const { - return (m_base + m_bytes) - sizeof(void*); + return (m_base + m_bytes) - 16; }