1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +00:00

Kernel+Userland: Make the stack alignment comply with the System V ABI

The System V ABI for both x86 and x86_64 requires that the stack pointer
is 16-byte aligned on entry. Previously we did not align the stack
pointer properly.

As far as "main" was concerned the stack alignment was correct even
without this patch due to how the C++ _start function and the kernel
interacted, i.e. the kernel misaligned the stack as far as the ABI
was concerned but that misalignment (read: it was properly aligned for
a regular function call - but misaligned in terms of what the ABI
dictates) was actually expected by our _start function.
This commit is contained in:
Gunnar Beutner 2021-07-09 00:58:43 +02:00 committed by Andreas Kling
parent f4a318ee2d
commit 06883ed8a3
8 changed files with 69 additions and 17 deletions

View file

@ -147,10 +147,10 @@ static KResultOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]
regs.rsi = argv;
regs.rdx = envp;
#endif
push_on_new_stack(0); // return address
VERIFY((new_sp + sizeof(void*)) % 16 == 0);
VERIFY(new_sp % 16 == 0);
// FIXME: The way we're setting up the stack and passing arguments to the entry point isn't ABI-compliant
return new_sp;
}