]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1965aae3 PA |
2 | #ifndef _ASM_X86_PTRACE_H |
3 | #define _ASM_X86_PTRACE_H | |
8fc37f2c | 4 | |
6330a30a | 5 | #include <asm/segment.h> |
b1cf540f | 6 | #include <asm/page_types.h> |
af170c50 | 7 | #include <uapi/asm/ptrace.h> |
eee3af4a | 8 | |
8fc37f2c | 9 | #ifndef __ASSEMBLY__ |
8fc37f2c | 10 | #ifdef __i386__ |
65ea5b03 PA |
11 | |
12 | struct pt_regs { | |
385eca8f AL |
13 | /* |
14 | * NB: 32-bit x86 CPUs are inconsistent as what happens in the | |
15 | * following cases (where %seg represents a segment register): | |
16 | * | |
17 | * - pushl %seg: some do a 16-bit write and leave the high | |
18 | * bits alone | |
19 | * - movl %seg, [mem]: some do a 16-bit write despite the movl | |
20 | * - IDT entry: some (e.g. 486) will leave the high bits of CS | |
21 | * and (if applicable) SS undefined. | |
22 | * | |
23 | * Fortunately, x86-32 doesn't read the high bits on POP or IRET, | |
24 | * so we can just treat all of the segment registers as 16-bit | |
25 | * values. | |
26 | */ | |
92bc2056 HH |
27 | unsigned long bx; |
28 | unsigned long cx; | |
29 | unsigned long dx; | |
30 | unsigned long si; | |
31 | unsigned long di; | |
32 | unsigned long bp; | |
9902a702 | 33 | unsigned long ax; |
385eca8f AL |
34 | unsigned short ds; |
35 | unsigned short __dsh; | |
36 | unsigned short es; | |
37 | unsigned short __esh; | |
38 | unsigned short fs; | |
39 | unsigned short __fsh; | |
40 | unsigned short gs; | |
41 | unsigned short __gsh; | |
9902a702 | 42 | unsigned long orig_ax; |
92bc2056 | 43 | unsigned long ip; |
385eca8f AL |
44 | unsigned short cs; |
45 | unsigned short __csh; | |
92bc2056 HH |
46 | unsigned long flags; |
47 | unsigned long sp; | |
385eca8f AL |
48 | unsigned short ss; |
49 | unsigned short __ssh; | |
65ea5b03 | 50 | }; |
8fc37f2c | 51 | |
8fc37f2c TG |
52 | #else /* __i386__ */ |
53 | ||
65ea5b03 | 54 | struct pt_regs { |
e90e147c DV |
55 | /* |
56 | * C ABI says these regs are callee-preserved. They aren't saved on kernel entry | |
57 | * unless syscall needs a complete, fully filled "struct pt_regs". | |
58 | */ | |
65ea5b03 PA |
59 | unsigned long r15; |
60 | unsigned long r14; | |
61 | unsigned long r13; | |
62 | unsigned long r12; | |
63 | unsigned long bp; | |
64 | unsigned long bx; | |
e90e147c | 65 | /* These regs are callee-clobbered. Always saved on kernel entry. */ |
65ea5b03 PA |
66 | unsigned long r11; |
67 | unsigned long r10; | |
68 | unsigned long r9; | |
69 | unsigned long r8; | |
70 | unsigned long ax; | |
71 | unsigned long cx; | |
72 | unsigned long dx; | |
73 | unsigned long si; | |
74 | unsigned long di; | |
e90e147c DV |
75 | /* |
76 | * On syscall entry, this is syscall#. On CPU exception, this is error code. | |
77 | * On hw interrupt, it's IRQ number: | |
78 | */ | |
65ea5b03 | 79 | unsigned long orig_ax; |
e90e147c | 80 | /* Return frame for iretq */ |
65ea5b03 PA |
81 | unsigned long ip; |
82 | unsigned long cs; | |
83 | unsigned long flags; | |
84 | unsigned long sp; | |
85 | unsigned long ss; | |
86 | /* top of stack page */ | |
87 | }; | |
8fc37f2c | 88 | |
dbe3533b | 89 | #endif /* !__i386__ */ |
8fc37f2c | 90 | |
318f5a2a AL |
91 | #ifdef CONFIG_PARAVIRT |
92 | #include <asm/paravirt_types.h> | |
93 | #endif | |
8fc37f2c | 94 | |
93fa7636 | 95 | struct cpuinfo_x86; |
8fc37f2c TG |
96 | struct task_struct; |
97 | ||
dbe3533b | 98 | extern unsigned long profile_pc(struct pt_regs *regs); |
c46dd6b4 | 99 | #define profile_pc profile_pc |
dbe3533b | 100 | |
8fc37f2c | 101 | extern unsigned long |
37cd9cf3 | 102 | convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs); |
72f74fa2 | 103 | extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, |
da654b74 | 104 | int error_code, int si_code); |
72fa50f4 | 105 | |
e0ffbaab | 106 | |
9902a702 HH |
107 | static inline unsigned long regs_return_value(struct pt_regs *regs) |
108 | { | |
109 | return regs->ax; | |
110 | } | |
efd1ca52 | 111 | |
90d43d72 | 112 | /* |
efa70451 AL |
113 | * user_mode(regs) determines whether a register set came from user |
114 | * mode. On x86_32, this is true if V8086 mode was enabled OR if the | |
115 | * register set was from protected mode with RPL-3 CS value. This | |
116 | * tricky test checks that with one comparison. | |
117 | * | |
118 | * On x86_64, vm86 mode is mercifully nonexistent, and we don't need | |
119 | * the extra check. | |
90d43d72 HH |
120 | */ |
121 | static inline int user_mode(struct pt_regs *regs) | |
122 | { | |
123 | #ifdef CONFIG_X86_32 | |
7ba554b5 | 124 | return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= USER_RPL; |
90d43d72 HH |
125 | #else |
126 | return !!(regs->cs & 3); | |
127 | #endif | |
128 | } | |
129 | ||
90d43d72 HH |
130 | static inline int v8086_mode(struct pt_regs *regs) |
131 | { | |
132 | #ifdef CONFIG_X86_32 | |
6b6891f9 | 133 | return (regs->flags & X86_VM_MASK); |
90d43d72 HH |
134 | #else |
135 | return 0; /* No V86 mode support in long mode */ | |
136 | #endif | |
137 | } | |
138 | ||
318f5a2a AL |
139 | #ifdef CONFIG_X86_64 |
140 | static inline bool user_64bit_mode(struct pt_regs *regs) | |
141 | { | |
142 | #ifndef CONFIG_PARAVIRT | |
143 | /* | |
144 | * On non-paravirt systems, this is the only long mode CPL 3 | |
145 | * selector. We do not allow long mode selectors in the LDT. | |
146 | */ | |
147 | return regs->cs == __USER_CS; | |
148 | #else | |
149 | /* Headers are too twisted for this to go in paravirt.h. */ | |
150 | return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs; | |
151 | #endif | |
152 | } | |
9b064fc3 | 153 | |
263042e4 DV |
154 | #define current_user_stack_pointer() current_pt_regs()->sp |
155 | #define compat_user_stack_pointer() current_pt_regs()->sp | |
318f5a2a AL |
156 | #endif |
157 | ||
90d43d72 | 158 | #ifdef CONFIG_X86_32 |
10226238 | 159 | extern unsigned long kernel_stack_pointer(struct pt_regs *regs); |
90d43d72 | 160 | #else |
10226238 RR |
161 | static inline unsigned long kernel_stack_pointer(struct pt_regs *regs) |
162 | { | |
90d43d72 | 163 | return regs->sp; |
90d43d72 | 164 | } |
10226238 | 165 | #endif |
90d43d72 | 166 | |
c46dd6b4 MF |
167 | #define GET_IP(regs) ((regs)->ip) |
168 | #define GET_FP(regs) ((regs)->bp) | |
169 | #define GET_USP(regs) ((regs)->sp) | |
90d43d72 | 170 | |
c46dd6b4 | 171 | #include <asm-generic/ptrace.h> |
68bd0f4e | 172 | |
b1cf540f MH |
173 | /* Query offset/name of register from its name/offset */ |
174 | extern int regs_query_register_offset(const char *name); | |
175 | extern const char *regs_query_register_name(unsigned int offset); | |
176 | #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss)) | |
177 | ||
178 | /** | |
179 | * regs_get_register() - get register value from its offset | |
180 | * @regs: pt_regs from which register value is gotten. | |
181 | * @offset: offset number of the register. | |
182 | * | |
e859cf86 MH |
183 | * regs_get_register returns the value of a register. The @offset is the |
184 | * offset of the register in struct pt_regs address which specified by @regs. | |
b1cf540f MH |
185 | * If @offset is bigger than MAX_REG_OFFSET, this returns 0. |
186 | */ | |
187 | static inline unsigned long regs_get_register(struct pt_regs *regs, | |
188 | unsigned int offset) | |
189 | { | |
190 | if (unlikely(offset > MAX_REG_OFFSET)) | |
191 | return 0; | |
6c8d8b3c SR |
192 | #ifdef CONFIG_X86_32 |
193 | /* | |
194 | * Traps from the kernel do not save sp and ss. | |
195 | * Use the helper function to retrieve sp. | |
196 | */ | |
197 | if (offset == offsetof(struct pt_regs, sp) && | |
198 | regs->cs == __KERNEL_CS) | |
199 | return kernel_stack_pointer(regs); | |
603e492e AL |
200 | |
201 | /* The selector fields are 16-bit. */ | |
202 | if (offset == offsetof(struct pt_regs, cs) || | |
203 | offset == offsetof(struct pt_regs, ss) || | |
204 | offset == offsetof(struct pt_regs, ds) || | |
205 | offset == offsetof(struct pt_regs, es) || | |
206 | offset == offsetof(struct pt_regs, fs) || | |
207 | offset == offsetof(struct pt_regs, gs)) { | |
208 | return *(u16 *)((unsigned long)regs + offset); | |
209 | ||
210 | } | |
6c8d8b3c | 211 | #endif |
b1cf540f MH |
212 | return *(unsigned long *)((unsigned long)regs + offset); |
213 | } | |
214 | ||
215 | /** | |
216 | * regs_within_kernel_stack() - check the address in the stack | |
217 | * @regs: pt_regs which contains kernel stack pointer. | |
218 | * @addr: address which is checked. | |
219 | * | |
e859cf86 | 220 | * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). |
b1cf540f MH |
221 | * If @addr is within the kernel stack, it returns true. If not, returns false. |
222 | */ | |
223 | static inline int regs_within_kernel_stack(struct pt_regs *regs, | |
224 | unsigned long addr) | |
225 | { | |
226 | return ((addr & ~(THREAD_SIZE - 1)) == | |
227 | (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); | |
228 | } | |
229 | ||
230 | /** | |
231 | * regs_get_kernel_stack_nth() - get Nth entry of the stack | |
232 | * @regs: pt_regs which contains kernel stack pointer. | |
233 | * @n: stack entry number. | |
234 | * | |
235 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which | |
e859cf86 | 236 | * is specified by @regs. If the @n th entry is NOT in the kernel stack, |
b1cf540f MH |
237 | * this returns 0. |
238 | */ | |
239 | static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, | |
240 | unsigned int n) | |
241 | { | |
242 | unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); | |
243 | addr += n; | |
244 | if (regs_within_kernel_stack(regs, (unsigned long)addr)) | |
245 | return *addr; | |
246 | else | |
247 | return 0; | |
248 | } | |
249 | ||
7f232343 | 250 | #define arch_has_single_step() (1) |
10faa81e RM |
251 | #ifdef CONFIG_X86_DEBUGCTLMSR |
252 | #define arch_has_block_step() (1) | |
253 | #else | |
254 | #define arch_has_block_step() (boot_cpu_data.x86 >= 6) | |
255 | #endif | |
256 | ||
7f38551f ON |
257 | #define ARCH_HAS_USER_SINGLE_STEP_INFO |
258 | ||
b9cd18de TH |
259 | /* |
260 | * When hitting ptrace_stop(), we cannot return using SYSRET because | |
261 | * that does not restore the full CPU state, only a minimal set. The | |
262 | * ptracer can change arbitrary register values, which is usually okay | |
263 | * because the usual ptrace stops run off the signal delivery path which | |
264 | * forces IRET; however, ptrace_event() stops happen in arbitrary places | |
265 | * in the kernel and don't force IRET path. | |
266 | * | |
267 | * So force IRET path after a ptrace stop. | |
268 | */ | |
269 | #define arch_ptrace_stop_needed(code, info) \ | |
270 | ({ \ | |
1daeaa31 | 271 | force_iret(); \ |
b9cd18de TH |
272 | false; \ |
273 | }) | |
274 | ||
efd1ca52 RM |
275 | struct user_desc; |
276 | extern int do_get_thread_area(struct task_struct *p, int idx, | |
277 | struct user_desc __user *info); | |
278 | extern int do_set_thread_area(struct task_struct *p, int idx, | |
279 | struct user_desc __user *info, int can_allocate); | |
280 | ||
8fc37f2c | 281 | #endif /* !__ASSEMBLY__ */ |
1965aae3 | 282 | #endif /* _ASM_X86_PTRACE_H */ |