2 * Copyright (C) 2012 ARM Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #ifndef __ASM_STACKTRACE_H
17 #define __ASM_STACKTRACE_H
19 #include <linux/percpu.h>
20 #include <linux/sched.h>
21 #include <linux/sched/task_stack.h>
23 #include <asm/memory.h>
24 #include <asm/ptrace.h>
30 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
40 STACK_TYPE_SDEI_NORMAL,
41 STACK_TYPE_SDEI_CRITICAL,
50 extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame);
51 extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
52 int (*fn)(struct stackframe *, void *), void *data);
53 extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
55 DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
57 static inline bool on_irq_stack(unsigned long sp,
58 struct stack_info *info)
60 unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
61 unsigned long high = low + IRQ_STACK_SIZE;
66 if (sp < low || sp >= high)
72 info->type = STACK_TYPE_IRQ;
78 static inline bool on_task_stack(struct task_struct *tsk, unsigned long sp,
79 struct stack_info *info)
81 unsigned long low = (unsigned long)task_stack_page(tsk);
82 unsigned long high = low + THREAD_SIZE;
84 if (sp < low || sp >= high)
90 info->type = STACK_TYPE_TASK;
96 #ifdef CONFIG_VMAP_STACK
97 DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack);
99 static inline bool on_overflow_stack(unsigned long sp,
100 struct stack_info *info)
102 unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack);
103 unsigned long high = low + OVERFLOW_STACK_SIZE;
105 if (sp < low || sp >= high)
111 info->type = STACK_TYPE_OVERFLOW;
117 static inline bool on_overflow_stack(unsigned long sp,
118 struct stack_info *info) { return false; }
123 * We can only safely access per-cpu stacks from current in a non-preemptible
126 static inline bool on_accessible_stack(struct task_struct *tsk,
128 struct stack_info *info)
130 if (on_task_stack(tsk, sp, info))
132 if (tsk != current || preemptible())
134 if (on_irq_stack(sp, info))
136 if (on_overflow_stack(sp, info))
138 if (on_sdei_stack(sp, info))
144 #endif /* __ASM_STACKTRACE_H */