diff options
author | Hediadyoin1 <leon2002.la@gmail.com> | 2021-07-02 00:57:48 +0200 |
---|---|---|
committer | Gunnar Beutner <gunnar@beutner.name> | 2021-07-03 13:20:04 +0200 |
commit | d12e14fa959c9ed35bec0d2d6d4676d550465340 (patch) | |
tree | 14e88fd44c06a686473c0d8d2a1dab7529608db9 /Kernel/Thread.cpp | |
parent | 0fcb04844805c8a02c5b1cf9786422d54278f0a9 (diff) | |
download | serenity-d12e14fa959c9ed35bec0d2d6d4676d550465340.zip |
Userland: Respect red-zone for signal handlers
We were building with red-zone before, but were not accounting for it on
signal handler entries. This should fix that.
Also shorten the stack alignment calculations for this.
Diffstat (limited to 'Kernel/Thread.cpp')
-rw-r--r-- | Kernel/Thread.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 296d73a193..2f8bd20fd7 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -846,7 +846,9 @@ DispatchSignalResult Thread::dispatch_signal(u8 signal) // Align the stack to 16 bytes. // Note that we push 56 bytes (4 * 14) on to the stack, // so we need to account for this here. - FlatPtr stack_alignment = (*stack - 56) % 16; + // 56 % 16 = 8, so we only need to take 8 bytes into consideration for + // the stack alignment. + FlatPtr stack_alignment = (*stack - 8) % 16; *stack -= stack_alignment; push_value_on_user_stack(stack, ret_eflags); @@ -864,8 +866,11 @@ DispatchSignalResult Thread::dispatch_signal(u8 signal) // Align the stack to 16 bytes. // Note that we push 176 bytes (8 * 22) on to the stack, // so we need to account for this here. - FlatPtr stack_alignment = (*stack - 112) % 16; - *stack -= stack_alignment; + // 22 % 2 = 0, so we dont need to take anything into consideration + // for the alignment. + // We also are not allowed to touch the thread's red-zone of 128 bytes + FlatPtr stack_alignment = *stack % 16; + *stack -= 128 + stack_alignment; push_value_on_user_stack(stack, ret_rflags); |