summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-01-19 09:54:58 +0100
committerAndreas Kling <kling@serenityos.org>2020-01-19 10:33:17 +0100
commit38fc31ff11f02473e7ef04297feacaa4cf23981e (patch)
tree126b2221deaf0c67a42ec1302f882f324b14ee40
parentf7b394e9a1dbf5bb7285b317532c21f84e583e61 (diff)
downloadserenity-38fc31ff11f02473e7ef04297feacaa4cf23981e.zip
Kernel: Always switch to own page tables when crashing/asserting
I noticed this while debugging a crash in backtrace generation. If a process would crash while temporarily inspecting another process's address space, the crashing thread would still use the other process's page tables while handling the crash, causing all kinds of confusion when trying to walk the stack of the crashing thread.
-rw-r--r--Kernel/Arch/i386/CPU.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp
index b83899136b..d1ef90e6a4 100644
--- a/Kernel/Arch/i386/CPU.cpp
+++ b/Kernel/Arch/i386/CPU.cpp
@@ -208,6 +208,10 @@ void handle_crash(RegisterDump& regs, const char* description, int signal)
hang();
}
+ // If a process crashed while inspecting another process,
+ // make sure we switch back to the right page tables.
+ MM.enter_process_paging_scope(current->process());
+
kprintf("\033[31;1mCRASH: %s. %s: %s(%u)\033[0m\n",
description,
current->process().is_ring0() ? "Kernel" : "Process",
@@ -547,6 +551,12 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const
{
asm volatile("cli");
kprintf("ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func);
+
+ // Switch back to the current process's page tables if there are any.
+ // Otherwise stack walking will be a disaster.
+ if (current)
+ MM.enter_process_paging_scope(current->process());
+
dump_backtrace();
asm volatile("hlt");
for (;;)