xref: /linux/arch/x86/include/asm/unwind.h (revision 59024954a1e7e26b62680e1f2b5725249a6c09f7)
1 #ifndef _ASM_X86_UNWIND_H
2 #define _ASM_X86_UNWIND_H
3 
4 #include <linux/sched.h>
5 #include <linux/ftrace.h>
6 #include <asm/ptrace.h>
7 #include <asm/stacktrace.h>
8 
9 struct unwind_state {
10 	struct stack_info stack_info;
11 	unsigned long stack_mask;
12 	struct task_struct *task;
13 	int graph_idx;
14 #ifdef CONFIG_FRAME_POINTER
15 	unsigned long *bp;
16 #else
17 	unsigned long *sp;
18 #endif
19 };
20 
21 void __unwind_start(struct unwind_state *state, struct task_struct *task,
22 		    struct pt_regs *regs, unsigned long *first_frame);
23 
24 bool unwind_next_frame(struct unwind_state *state);
25 
26 static inline bool unwind_done(struct unwind_state *state)
27 {
28 	return state->stack_info.type == STACK_TYPE_UNKNOWN;
29 }
30 
31 static inline
32 void unwind_start(struct unwind_state *state, struct task_struct *task,
33 		  struct pt_regs *regs, unsigned long *first_frame)
34 {
35 	first_frame = first_frame ? : get_stack_pointer(task, regs);
36 
37 	__unwind_start(state, task, regs, first_frame);
38 }
39 
40 #ifdef CONFIG_FRAME_POINTER
41 
42 static inline
43 unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
44 {
45 	if (unwind_done(state))
46 		return NULL;
47 
48 	return state->bp + 1;
49 }
50 
51 unsigned long unwind_get_return_address(struct unwind_state *state);
52 
53 #else /* !CONFIG_FRAME_POINTER */
54 
55 static inline
56 unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
57 {
58 	return NULL;
59 }
60 
61 static inline
62 unsigned long unwind_get_return_address(struct unwind_state *state)
63 {
64 	if (unwind_done(state))
65 		return 0;
66 
67 	return ftrace_graph_ret_addr(state->task, &state->graph_idx,
68 				     *state->sp, state->sp);
69 }
70 
71 #endif /* CONFIG_FRAME_POINTER */
72 
73 #endif /* _ASM_X86_UNWIND_H */
74