summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorSahan Fernando <sahan.h.fernando@gmail.com>2021-05-02 03:22:00 +1000
committerAndreas Kling <kling@serenityos.org>2021-05-01 20:08:35 +0200
commitbd563f0b3c00fd09a3f8234e7cc55fa3fc4485e0 (patch)
treeb5ab46d7dd52728a03c8452901ec79e17e38cfa9 /Kernel/Syscalls
parentcf7df418edc922c0490c7969b4d5c1988daff7d3 (diff)
downloadserenity-bd563f0b3c00fd09a3f8234e7cc55fa3fc4485e0.zip
Kernel: Make processes start with a 16-byte-aligned stack
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/execve.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp
index a3658e52b0..4aba395cf7 100644
--- a/Kernel/Syscalls/execve.cpp
+++ b/Kernel/Syscalls/execve.cpp
@@ -131,12 +131,18 @@ static KResultOr<FlatPtr> make_userspace_stack_for_main_thread(Region& region, V
// NOTE: The stack needs to be 16-byte aligned.
new_esp -= new_esp % 16;
+ // GCC assumes that the return address has been pushed to the stack when it enters the function,
+ // so we need to reserve an extra pointer's worth of bytes below this to make GCC's stack alignment
+ // calculations work
+ new_esp -= sizeof(void*);
push_on_new_stack((FlatPtr)envp);
push_on_new_stack((FlatPtr)argv);
push_on_new_stack((FlatPtr)argv_entries.size());
push_on_new_stack(0);
+ VERIFY((new_esp + sizeof(void*)) % 16 == 0);
+
return new_esp;
}