]>
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 | ||
b02fcf9b JP |
10 | #define IRET_FRAME_OFFSET (offsetof(struct pt_regs, ip)) |
11 | #define IRET_FRAME_SIZE (sizeof(struct pt_regs) - IRET_FRAME_OFFSET) | |
12 | ||
7c7900f8 JP |
13 | struct unwind_state { |
14 | struct stack_info stack_info; | |
15 | unsigned long stack_mask; | |
16 | struct task_struct *task; | |
17 | int graph_idx; | |
af085d90 | 18 | bool error; |
11af8474 | 19 | #if defined(CONFIG_UNWINDER_ORC) |
ee9f8fce JP |
20 | bool signal, full_regs; |
21 | unsigned long sp, bp, ip; | |
81b67439 | 22 | struct pt_regs *regs, *prev_regs; |
11af8474 | 23 | #elif defined(CONFIG_UNWINDER_FRAME_POINTER) |
a8b7a923 | 24 | bool got_irq; |
ee9f8fce | 25 | unsigned long *bp, *orig_sp, ip; |
f4f34e1b JH |
26 | /* |
27 | * If non-NULL: The current frame is incomplete and doesn't contain a | |
28 | * valid BP. When looking for the next frame, use this instead of the | |
29 | * non-existent saved BP. | |
30 | */ | |
31 | unsigned long *next_bp; | |
946c1911 | 32 | struct pt_regs *regs; |
7c7900f8 JP |
33 | #else |
34 | unsigned long *sp; | |
35 | #endif | |
36 | }; | |
37 | ||
38 | void __unwind_start(struct unwind_state *state, struct task_struct *task, | |
39 | struct pt_regs *regs, unsigned long *first_frame); | |
7c7900f8 | 40 | bool unwind_next_frame(struct unwind_state *state); |
cfee9edd | 41 | unsigned long unwind_get_return_address(struct unwind_state *state); |
ee9f8fce | 42 | unsigned long *unwind_get_return_address_ptr(struct unwind_state *state); |
cfee9edd | 43 | |
7c7900f8 JP |
44 | static inline bool unwind_done(struct unwind_state *state) |
45 | { | |
46 | return state->stack_info.type == STACK_TYPE_UNKNOWN; | |
47 | } | |
48 | ||
af085d90 JP |
49 | static inline bool unwind_error(struct unwind_state *state) |
50 | { | |
51 | return state->error; | |
52 | } | |
53 | ||
7c7900f8 | 54 | static inline |
ee9f8fce JP |
55 | void unwind_start(struct unwind_state *state, struct task_struct *task, |
56 | struct pt_regs *regs, unsigned long *first_frame) | |
7c7900f8 | 57 | { |
ee9f8fce | 58 | first_frame = first_frame ? : get_stack_pointer(task, regs); |
7c7900f8 | 59 | |
ee9f8fce | 60 | __unwind_start(state, task, regs, first_frame); |
946c1911 JP |
61 | } |
62 | ||
11af8474 | 63 | #if defined(CONFIG_UNWINDER_ORC) || defined(CONFIG_UNWINDER_FRAME_POINTER) |
b02fcf9b | 64 | /* |
a9cdbe72 | 65 | * If 'partial' returns true, only the iret frame registers are valid. |
b02fcf9b | 66 | */ |
a9cdbe72 JP |
67 | static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state, |
68 | bool *partial) | |
946c1911 JP |
69 | { |
70 | if (unwind_done(state)) | |
71 | return NULL; | |
72 | ||
a9cdbe72 JP |
73 | if (partial) { |
74 | #ifdef CONFIG_UNWINDER_ORC | |
75 | *partial = !state->full_regs; | |
76 | #else | |
77 | *partial = false; | |
78 | #endif | |
79 | } | |
80 | ||
946c1911 | 81 | return state->regs; |
7c7900f8 | 82 | } |
ee9f8fce | 83 | #else |
a9cdbe72 JP |
84 | static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state, |
85 | bool *partial) | |
7c7900f8 JP |
86 | { |
87 | return NULL; | |
88 | } | |
ee9f8fce | 89 | #endif |
7c7900f8 | 90 | |
11af8474 | 91 | #ifdef CONFIG_UNWINDER_ORC |
ee9f8fce JP |
92 | void unwind_init(void); |
93 | void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size, | |
94 | void *orc, size_t orc_size); | |
95 | #else | |
96 | static inline void unwind_init(void) {} | |
97 | static inline | |
98 | void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size, | |
99 | void *orc, size_t orc_size) {} | |
100 | #endif | |
101 | ||
102 | /* | |
103 | * This disables KASAN checking when reading a value from another task's stack, | |
104 | * since the other task could be running on another CPU and could have poisoned | |
105 | * the stack in the meantime. | |
106 | */ | |
107 | #define READ_ONCE_TASK_STACK(task, x) \ | |
108 | ({ \ | |
109 | unsigned long val; \ | |
110 | if (task == current) \ | |
111 | val = READ_ONCE(x); \ | |
112 | else \ | |
113 | val = READ_ONCE_NOCHECK(x); \ | |
114 | val; \ | |
115 | }) | |
116 | ||
117 | static inline bool task_on_another_cpu(struct task_struct *task) | |
946c1911 | 118 | { |
ee9f8fce JP |
119 | #ifdef CONFIG_SMP |
120 | return task != current && task->on_cpu; | |
121 | #else | |
122 | return false; | |
123 | #endif | |
946c1911 JP |
124 | } |
125 | ||
7c7900f8 | 126 | #endif /* _ASM_X86_UNWIND_H */ |