From 105ed79f8f0a89fbc4791e8ef7136c36a9b101a8 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 25 Jul 2023 17:02:09 +0200 Subject: [PATCH] kernel: Reenable userspace stack tracing, but hidden behind a config flag Sometimes this is needed for userspace program debugging (such as ports), but sometimes it can crash, so we leave it off by default. --- kernel/config.cmake.template | 4 ++++ kernel/src/arch/x86_64/CPU.cpp | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/config.cmake.template b/kernel/config.cmake.template index 8efb8a9c..d7d98b77 100644 --- a/kernel/config.cmake.template +++ b/kernel/config.cmake.template @@ -15,3 +15,7 @@ # control characters, leading/trailing spaces, problematic characters and invalid UTF-8). Keep in mind that this restriction # is only enforced when creating files; existing files with such illegal filenames are parsed correctly and fully usable. # target_compile_definitions(moon PRIVATE MOON_DISABLE_FILENAME_RESTRICTIONS) + +# Uncomment the line below to make the kernel also calculate stack traces for userspace addresses on program crashes. +# This can aid in debugging, but makes the kernel more unstable as stack tracing will access arbitrary userspace memory. +# target_compile_definitions(moon PRIVATE MOON_ENABLE_USERSPACE_STACK_TRACES) diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index 316a4181..c1dd3e8d 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -326,7 +326,10 @@ namespace CPU static void backtrace_impl(u64 base_pointer, void (*callback)(u64, void*), void* arg) { StackFrame* current_frame = (StackFrame*)base_pointer; - while (current_frame && (u64)current_frame >= 0xFFFF'FFFF'8000'0000 && + while (current_frame && +#ifndef MOON_ENABLE_USERSPACE_STACK_TRACES + (u64)current_frame >= 0xFFFF'FFFF'8000'0000 && +#endif MemoryManager::validate_access(current_frame, sizeof(*current_frame), MemoryManager::DEFAULT_ACCESS) && current_frame->instruction) {