1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:37:34 +00:00

Kernel: Track previous mode when entering/exiting traps

This allows us to determine what the previous mode (user or kernel)
was, e.g. in the timer interrupt. This is used e.g. to determine
whether a signal handler should be set up.

Fixes #5096
This commit is contained in:
Tom 2021-01-25 13:19:34 -07:00 committed by Andreas Kling
parent fa18010477
commit 0bd558081e
6 changed files with 70 additions and 7 deletions

View file

@ -137,6 +137,7 @@ void syscall_handler(TrapFrame* trap)
{
auto& regs = *trap->regs;
auto current_thread = Thread::current();
ASSERT(current_thread->previous_mode() == Thread::PreviousMode::UserMode);
auto& process = current_thread->process();
if (auto tracer = process.tracer(); tracer && tracer->is_tracing_syscalls()) {
@ -206,6 +207,9 @@ void syscall_handler(TrapFrame* trap)
current_thread->check_dispatch_pending_signal();
// If the previous mode somehow changed something is seriously messed up...
ASSERT(current_thread->previous_mode() == Thread::PreviousMode::UserMode);
// Check if we're supposed to return to userspace or just die.
current_thread->die_if_needed();