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