Commit | Line | Data |
---|---|---|
7c7900f8 JP |
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; | |
af085d90 | 14 | bool error; |
11af8474 | 15 | #if defined(CONFIG_UNWINDER_ORC) |
ee9f8fce JP |
16 | bool signal, full_regs; |
17 | unsigned long sp, bp, ip; | |
18 | struct pt_regs *regs; | |
11af8474 | 19 | #elif defined(CONFIG_UNWINDER_FRAME_POINTER) |
a8b7a923 | 20 | bool got_irq; |
ee9f8fce | 21 | unsigned long *bp, *orig_sp, ip; |
946c1911 | 22 | struct pt_regs *regs; |
7c7900f8 JP |
23 | #else |
24 | unsigned long *sp; | |
25 | #endif | |
26 | }; | |
27 | ||
28 | void __unwind_start(struct unwind_state *state, struct task_struct *task, | |
29 | struct pt_regs *regs, unsigned long *first_frame); | |
7c7900f8 | 30 | bool unwind_next_frame(struct unwind_state *state); |
cfee9edd | 31 | unsigned long unwind_get_return_address(struct unwind_state *state); |
ee9f8fce | 32 | unsigned long *unwind_get_return_address_ptr(struct unwind_state *state); |
cfee9edd | 33 | |
7c7900f8 JP |
34 | static inline bool unwind_done(struct unwind_state *state) |
35 | { | |
36 | return state->stack_info.type == STACK_TYPE_UNKNOWN; | |
37 | } | |
38 | ||
af085d90 JP |
39 | static inline bool unwind_error(struct unwind_state *state) |
40 | { | |
41 | return state->error; | |
42 | } | |
43 | ||
7c7900f8 | 44 | static inline |
ee9f8fce JP |
45 | void unwind_start(struct unwind_state *state, struct task_struct *task, |
46 | struct pt_regs *regs, unsigned long *first_frame) | |
7c7900f8 | 47 | { |
ee9f8fce | 48 | first_frame = first_frame ? : get_stack_pointer(task, regs); |
7c7900f8 | 49 | |
ee9f8fce | 50 | __unwind_start(state, task, regs, first_frame); |
946c1911 JP |
51 | } |
52 | ||
11af8474 | 53 | #if defined(CONFIG_UNWINDER_ORC) || defined(CONFIG_UNWINDER_FRAME_POINTER) |
946c1911 JP |
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; | |
7c7900f8 | 60 | } |
ee9f8fce JP |
61 | #else |
62 | static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state) | |
7c7900f8 JP |
63 | { |
64 | return NULL; | |
65 | } | |
ee9f8fce | 66 | #endif |
7c7900f8 | 67 | |
11af8474 | 68 | #ifdef CONFIG_UNWINDER_ORC |
ee9f8fce JP |
69 | void unwind_init(void); |
70 | void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size, | |
71 | void *orc, size_t orc_size); | |
72 | #else | |
73 | static inline void unwind_init(void) {} | |
74 | static inline | |
75 | void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size, | |
76 | void *orc, size_t orc_size) {} | |
77 | #endif | |
78 | ||
79 | /* | |
80 | * This disables KASAN checking when reading a value from another task's stack, | |
81 | * since the other task could be running on another CPU and could have poisoned | |
82 | * the stack in the meantime. | |
83 | */ | |
84 | #define READ_ONCE_TASK_STACK(task, x) \ | |
85 | ({ \ | |
86 | unsigned long val; \ | |
87 | if (task == current) \ | |
88 | val = READ_ONCE(x); \ | |
89 | else \ | |
90 | val = READ_ONCE_NOCHECK(x); \ | |
91 | val; \ | |
92 | }) | |
93 | ||
94 | static inline bool task_on_another_cpu(struct task_struct *task) | |
946c1911 | 95 | { |
ee9f8fce JP |
96 | #ifdef CONFIG_SMP |
97 | return task != current && task->on_cpu; | |
98 | #else | |
99 | return false; | |
100 | #endif | |
946c1911 JP |
101 | } |
102 | ||
7c7900f8 | 103 | #endif /* _ASM_X86_UNWIND_H */ |