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) {