xref: /linux/arch/x86/include/asm/unwind.h (revision e98bdb3059cbf2b1cd4261e126b08429f64466c3)
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, *orig_sp;
16 	struct pt_regs *regs;
17 #else
18 	unsigned long *sp;
19 #endif
20 };
21 
22 void __unwind_start(struct unwind_state *state, struct task_struct *task,
23 		    struct pt_regs *regs, unsigned long *first_frame);
24 
25 bool unwind_next_frame(struct unwind_state *state);
26 
27 unsigned long unwind_get_return_address(struct unwind_state *state);
28 
29 static inline bool unwind_done(struct unwind_state *state)
30 {
31 	return state->stack_info.type == STACK_TYPE_UNKNOWN;
32 }
33 
34 static inline
35 void unwind_start(struct unwind_state *state, struct task_struct *task,
36 		  struct pt_regs *regs, unsigned long *first_frame)
37 {
38 	first_frame = first_frame ? : get_stack_pointer(task, regs);
39 
40 	__unwind_start(state, task, regs, first_frame);
41 }
42 
43 #ifdef CONFIG_FRAME_POINTER
44 
45 static inline
46 unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
47 {
48 	if (unwind_done(state))
49 		return NULL;
50 
51 	return state->regs ? &state->regs->ip : state->bp + 1;
52 }
53 
54 static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
55 {
56 	if (unwind_done(state))
57 		return NULL;
58 
59 	return state->regs;
60 }
61 
62 #else /* !CONFIG_FRAME_POINTER */
63 
64 static inline
65 unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
66 {
67 	return NULL;
68 }
69 
70 static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
71 {
72 	return NULL;
73 }
74 
75 #endif /* CONFIG_FRAME_POINTER */
76 
77 #endif /* _ASM_X86_UNWIND_H */
78