44 lines
1.1 KiB
C
Raw Normal View History

2026-01-21 18:59:54 +08:00
// SPDX-License-Identifier: GPL-2.0-only
/*
* Stack trace management functions
*
2026-01-29 22:25:33 +08:00
* Copyright (C) 2009-2021 Helge Deller <deller@gmx.de>
2026-01-21 18:59:54 +08:00
* based on arch/x86/kernel/stacktrace.c by Ingo Molnar <mingo@redhat.com>
* and parisc unwind functions by Randolph Chung <tausq@debian.org>
*
* TODO: Userspace stacktrace (CONFIG_USER_STACKTRACE_SUPPORT)
*/
2026-01-29 22:25:33 +08:00
#include <linux/kernel.h>
2026-01-21 18:59:54 +08:00
#include <linux/stacktrace.h>
#include <asm/unwind.h>
2026-01-29 22:25:33 +08:00
static void notrace walk_stackframe(struct task_struct *task,
struct pt_regs *regs, bool (*fn)(void *, unsigned long), void *cookie)
2026-01-21 18:59:54 +08:00
{
struct unwind_frame_info info;
unwind_frame_init_task(&info, task, NULL);
2026-01-29 22:25:33 +08:00
while (1) {
2026-01-21 18:59:54 +08:00
if (unwind_once(&info) < 0 || info.ip == 0)
break;
if (__kernel_text_address(info.ip))
2026-01-29 22:25:33 +08:00
if (!fn(cookie, info.ip))
break;
2026-01-21 18:59:54 +08:00
}
}
2026-01-29 22:25:33 +08:00
void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
struct task_struct *task, struct pt_regs *regs)
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
walk_stackframe(task, regs, consume_entry, cookie);
2026-01-21 18:59:54 +08:00
}
2026-01-29 22:25:33 +08:00
int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, void *cookie,
struct task_struct *task)
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
walk_stackframe(task, NULL, consume_entry, cookie);
return 1;
2026-01-21 18:59:54 +08:00
}