1
2#ifndef _ASM_X86_PTRACE_H
3#define _ASM_X86_PTRACE_H
4
5#include <asm/segment.h>
6#include <asm/page_types.h>
7#include <uapi/asm/ptrace.h>
8
9#ifndef __ASSEMBLY__
10#ifdef __i386__
11
12struct pt_regs {
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 unsigned long bx;
28 unsigned long cx;
29 unsigned long dx;
30 unsigned long si;
31 unsigned long di;
32 unsigned long bp;
33 unsigned long ax;
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
41
42
43
44 unsigned short gs;
45 unsigned short __gsh;
46
47 unsigned long orig_ax;
48 unsigned long ip;
49 unsigned short cs;
50 unsigned short __csh;
51 unsigned long flags;
52 unsigned long sp;
53 unsigned short ss;
54 unsigned short __ssh;
55};
56
57#else
58
59struct pt_regs {
60
61
62
63
64 unsigned long r15;
65 unsigned long r14;
66 unsigned long r13;
67 unsigned long r12;
68 unsigned long bp;
69 unsigned long bx;
70
71 unsigned long r11;
72 unsigned long r10;
73 unsigned long r9;
74 unsigned long r8;
75 unsigned long ax;
76 unsigned long cx;
77 unsigned long dx;
78 unsigned long si;
79 unsigned long di;
80
81
82
83
84 unsigned long orig_ax;
85
86 unsigned long ip;
87 unsigned long cs;
88 unsigned long flags;
89 unsigned long sp;
90 unsigned long ss;
91
92};
93
94#endif
95
96#ifdef CONFIG_PARAVIRT
97#include <asm/paravirt_types.h>
98#endif
99
100#include <asm/proto.h>
101
102struct cpuinfo_x86;
103struct task_struct;
104
105extern unsigned long profile_pc(struct pt_regs *regs);
106
107extern unsigned long
108convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
109extern void send_sigtrap(struct pt_regs *regs, int error_code, int si_code);
110
111
112static inline unsigned long regs_return_value(struct pt_regs *regs)
113{
114 return regs->ax;
115}
116
117static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
118{
119 regs->ax = rc;
120}
121
122
123
124
125
126
127
128
129
130
131static __always_inline int user_mode(struct pt_regs *regs)
132{
133#ifdef CONFIG_X86_32
134 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= USER_RPL;
135#else
136 return !!(regs->cs & 3);
137#endif
138}
139
140static inline int v8086_mode(struct pt_regs *regs)
141{
142#ifdef CONFIG_X86_32
143 return (regs->flags & X86_VM_MASK);
144#else
145 return 0;
146#endif
147}
148
149static inline bool user_64bit_mode(struct pt_regs *regs)
150{
151#ifdef CONFIG_X86_64
152#ifndef CONFIG_PARAVIRT_XXL
153
154
155
156
157 return regs->cs == __USER_CS;
158#else
159
160 return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
161#endif
162#else
163 return false;
164#endif
165}
166
167
168
169
170
171static inline bool any_64bit_mode(struct pt_regs *regs)
172{
173#ifdef CONFIG_X86_64
174 return !user_mode(regs) || user_64bit_mode(regs);
175#else
176 return false;
177#endif
178}
179
180#ifdef CONFIG_X86_64
181#define current_user_stack_pointer() current_pt_regs()->sp
182#define compat_user_stack_pointer() current_pt_regs()->sp
183
184static __always_inline bool ip_within_syscall_gap(struct pt_regs *regs)
185{
186 bool ret = (regs->ip >= (unsigned long)entry_SYSCALL_64 &&
187 regs->ip < (unsigned long)entry_SYSCALL_64_safe_stack);
188
189#ifdef CONFIG_IA32_EMULATION
190 ret = ret || (regs->ip >= (unsigned long)entry_SYSCALL_compat &&
191 regs->ip < (unsigned long)entry_SYSCALL_compat_safe_stack);
192#endif
193
194 return ret;
195}
196#endif
197
198static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
199{
200 return regs->sp;
201}
202
203static inline unsigned long instruction_pointer(struct pt_regs *regs)
204{
205 return regs->ip;
206}
207
208static inline void instruction_pointer_set(struct pt_regs *regs,
209 unsigned long val)
210{
211 regs->ip = val;
212}
213
214static inline unsigned long frame_pointer(struct pt_regs *regs)
215{
216 return regs->bp;
217}
218
219static inline unsigned long user_stack_pointer(struct pt_regs *regs)
220{
221 return regs->sp;
222}
223
224static inline void user_stack_pointer_set(struct pt_regs *regs,
225 unsigned long val)
226{
227 regs->sp = val;
228}
229
230static __always_inline bool regs_irqs_disabled(struct pt_regs *regs)
231{
232 return !(regs->flags & X86_EFLAGS_IF);
233}
234
235
236extern int regs_query_register_offset(const char *name);
237extern const char *regs_query_register_name(unsigned int offset);
238#define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
239
240
241
242
243
244
245
246
247
248
249static inline unsigned long regs_get_register(struct pt_regs *regs,
250 unsigned int offset)
251{
252 if (unlikely(offset > MAX_REG_OFFSET))
253 return 0;
254#ifdef CONFIG_X86_32
255
256 if (offset == offsetof(struct pt_regs, cs) ||
257 offset == offsetof(struct pt_regs, ss) ||
258 offset == offsetof(struct pt_regs, ds) ||
259 offset == offsetof(struct pt_regs, es) ||
260 offset == offsetof(struct pt_regs, fs) ||
261 offset == offsetof(struct pt_regs, gs)) {
262 return *(u16 *)((unsigned long)regs + offset);
263
264 }
265#endif
266 return *(unsigned long *)((unsigned long)regs + offset);
267}
268
269
270
271
272
273
274
275
276
277static inline int regs_within_kernel_stack(struct pt_regs *regs,
278 unsigned long addr)
279{
280 return ((addr & ~(THREAD_SIZE - 1)) == (regs->sp & ~(THREAD_SIZE - 1)));
281}
282
283
284
285
286
287
288
289
290
291
292static inline unsigned long *regs_get_kernel_stack_nth_addr(struct pt_regs *regs, unsigned int n)
293{
294 unsigned long *addr = (unsigned long *)regs->sp;
295
296 addr += n;
297 if (regs_within_kernel_stack(regs, (unsigned long)addr))
298 return addr;
299 else
300 return NULL;
301}
302
303
304extern long copy_from_kernel_nofault(void *dst, const void *src, size_t size);
305
306
307
308
309
310
311
312
313
314
315static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
316 unsigned int n)
317{
318 unsigned long *addr;
319 unsigned long val;
320 long ret;
321
322 addr = regs_get_kernel_stack_nth_addr(regs, n);
323 if (addr) {
324 ret = copy_from_kernel_nofault(&val, addr, sizeof(val));
325 if (!ret)
326 return val;
327 }
328 return 0;
329}
330
331
332
333
334
335
336
337
338
339
340
341
342static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
343 unsigned int n)
344{
345 static const unsigned int argument_offs[] = {
346#ifdef __i386__
347 offsetof(struct pt_regs, ax),
348 offsetof(struct pt_regs, dx),
349 offsetof(struct pt_regs, cx),
350#define NR_REG_ARGUMENTS 3
351#else
352 offsetof(struct pt_regs, di),
353 offsetof(struct pt_regs, si),
354 offsetof(struct pt_regs, dx),
355 offsetof(struct pt_regs, cx),
356 offsetof(struct pt_regs, r8),
357 offsetof(struct pt_regs, r9),
358#define NR_REG_ARGUMENTS 6
359#endif
360 };
361
362 if (n >= NR_REG_ARGUMENTS) {
363 n -= NR_REG_ARGUMENTS - 1;
364 return regs_get_kernel_stack_nth(regs, n);
365 } else
366 return regs_get_register(regs, argument_offs[n]);
367}
368
369#define arch_has_single_step() (1)
370#ifdef CONFIG_X86_DEBUGCTLMSR
371#define arch_has_block_step() (1)
372#else
373#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
374#endif
375
376#define ARCH_HAS_USER_SINGLE_STEP_REPORT
377
378struct user_desc;
379extern int do_get_thread_area(struct task_struct *p, int idx,
380 struct user_desc __user *info);
381extern int do_set_thread_area(struct task_struct *p, int idx,
382 struct user_desc __user *info, int can_allocate);
383
384#ifdef CONFIG_X86_64
385# define do_set_thread_area_64(p, s, t) do_arch_prctl_64(p, s, t)
386#else
387# define do_set_thread_area_64(p, s, t) (0)
388#endif
389
390#endif
391#endif
392