From aefd6e9ee176a7741bee1d72189dd32c10109af2 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Mon, 17 Apr 2023 15:13:39 +0200 Subject: Kernel: Don't get rbp from internal context switch structures This has been broken on x86_64 since its introduction, as it features more registers to be saved, and we never held up the "rbp has to be the last pushed register" there. Instead, just copy rbp from the thread structure, which is now properly updated since the last commit. --- Kernel/Arch/x86_64/Processor.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'Kernel/Arch') diff --git a/Kernel/Arch/x86_64/Processor.cpp b/Kernel/Arch/x86_64/Processor.cpp index 4bb7c09963..67c73eac9c 100644 --- a/Kernel/Arch/x86_64/Processor.cpp +++ b/Kernel/Arch/x86_64/Processor.cpp @@ -863,23 +863,11 @@ ErrorOr> Processor::capture_stack_trace(Thread& thread, size case Thread::State::Blocked: case Thread::State::Dying: case Thread::State::Dead: { - // We need to retrieve ebp from what was last pushed to the kernel - // stack. Before switching out of that thread, it switch_context - // pushed the callee-saved registers, and the last of them happens - // to be ebp. ScopedAddressSpaceSwitcher switcher(thread.process()); auto& regs = thread.regs(); - auto* stack_top = reinterpret_cast(regs.sp()); - if (Memory::is_user_range(VirtualAddress(stack_top), sizeof(FlatPtr))) { - if (copy_from_user(&frame_ptr, &((FlatPtr*)stack_top)[0]).is_error()) - frame_ptr = 0; - } else { - void* fault_at; - if (!safe_memcpy(&frame_ptr, &((FlatPtr*)stack_top)[0], sizeof(FlatPtr), fault_at)) - frame_ptr = 0; - } ip = regs.ip(); + frame_ptr = regs.rbp; // TODO: We need to leave the scheduler lock here, but we also // need to prevent the target thread from being run while -- cgit v1.2.3