Kernel: Limit Thread::raw_backtrace() to the max profiler stack size

Let's avoid walking overly long stacks here, since kmalloc() is finite.
This commit is contained in:
Andreas Kling 2020-01-19 13:53:22 +01:00
parent 6ca1a46afd
commit 1d02ac35fc
Notes: sideshowbarker 2024-07-19 09:57:30 +09:00

View file

@ -29,6 +29,7 @@
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Process.h>
#include <Kernel/Profiling.h>
#include <Kernel/Scheduler.h>
#include <Kernel/Thread.h>
#include <Kernel/VM/MemoryManager.h>
@ -798,11 +799,13 @@ Vector<u32> Thread::raw_backtrace(u32 ebp) const
{
auto& process = const_cast<Process&>(this->process());
ProcessPagingScope paging_scope(process);
Vector<u32> backtrace;
Vector<u32, Profiling::max_stack_frame_count> backtrace;
backtrace.append(ebp);
for (u32* stack_ptr = (u32*)ebp; process.validate_read_from_kernel(VirtualAddress((u32)stack_ptr), sizeof(void*) * 2); stack_ptr = (u32*)*stack_ptr) {
u32 retaddr = stack_ptr[1];
backtrace.append(retaddr);
if (backtrace.size() == Profiling::max_stack_frame_count)
break;
}
return backtrace;
}