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