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 unsigned short gs;
41 unsigned short __gsh;
42 unsigned long orig_ax;
43 unsigned long ip;
44 unsigned short cs;
45 unsigned short __csh;
46 unsigned long flags;
47 unsigned long sp;
48 unsigned short ss;
49 unsigned short __ssh;
50};
51
52#else
53
54struct pt_regs {
55
56
57
58
59 unsigned long r15;
60 unsigned long r14;
61 unsigned long r13;
62 unsigned long r12;
63 unsigned long bp;
64 unsigned long bx;
65
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;
75
76
77
78
79 unsigned long orig_ax;
80
81 unsigned long ip;
82 unsigned long cs;
83 unsigned long flags;
84 unsigned long sp;
85 unsigned long ss;
86
87};
88
89#endif
90
91#ifdef CONFIG_PARAVIRT
92#include <asm/paravirt_types.h>
93#endif
94
95struct cpuinfo_x86;
96struct task_struct;
97
98extern unsigned long profile_pc(struct pt_regs *regs);
99#define profile_pc profile_pc
100
101extern unsigned long
102convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
103extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
104 int error_code, int si_code);
105
106
107static inline unsigned long regs_return_value(struct pt_regs *regs)
108{
109 return regs->ax;
110}
111
112static 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
126static 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
135static 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
144static inline bool user_64bit_mode(struct pt_regs *regs)
145{
146#ifdef CONFIG_X86_64
147#ifndef CONFIG_PARAVIRT
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#ifdef CONFIG_X86_32
168extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
169#else
170static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
171{
172 return regs->sp;
173}
174#endif
175
176#define GET_IP(regs) ((regs)->ip)
177#define GET_FP(regs) ((regs)->bp)
178#define GET_USP(regs) ((regs)->sp)
179
180#include <asm-generic/ptrace.h>
181
182
183extern int regs_query_register_offset(const char *name);
184extern const char *regs_query_register_name(unsigned int offset);
185#define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
186
187
188
189
190
191
192
193
194
195
196static inline unsigned long regs_get_register(struct pt_regs *regs,
197 unsigned int offset)
198{
199 if (unlikely(offset > MAX_REG_OFFSET))
200 return 0;
201#ifdef CONFIG_X86_32
202
203
204
205
206 if (offset == offsetof(struct pt_regs, sp) &&
207 regs->cs == __KERNEL_CS)
208 return kernel_stack_pointer(regs);
209
210
211 if (offset == offsetof(struct pt_regs, cs) ||
212 offset == offsetof(struct pt_regs, ss) ||
213 offset == offsetof(struct pt_regs, ds) ||
214 offset == offsetof(struct pt_regs, es) ||
215 offset == offsetof(struct pt_regs, fs) ||
216 offset == offsetof(struct pt_regs, gs)) {
217 return *(u16 *)((unsigned long)regs + offset);
218
219 }
220#endif
221 return *(unsigned long *)((unsigned long)regs + offset);
222}
223
224
225
226
227
228
229
230
231
232static inline int regs_within_kernel_stack(struct pt_regs *regs,
233 unsigned long addr)
234{
235 return ((addr & ~(THREAD_SIZE - 1)) ==
236 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
237}
238
239
240
241
242
243
244
245
246
247
248static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
249 unsigned int n)
250{
251 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
252 addr += n;
253 if (regs_within_kernel_stack(regs, (unsigned long)addr))
254 return *addr;
255 else
256 return 0;
257}
258
259#define arch_has_single_step() (1)
260#ifdef CONFIG_X86_DEBUGCTLMSR
261#define arch_has_block_step() (1)
262#else
263#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
264#endif
265
266#define ARCH_HAS_USER_SINGLE_STEP_INFO
267
268
269
270
271
272
273
274
275
276
277
278#define arch_ptrace_stop_needed(code, info) \
279({ \
280 force_iret(); \
281 false; \
282})
283
284struct user_desc;
285extern int do_get_thread_area(struct task_struct *p, int idx,
286 struct user_desc __user *info);
287extern int do_set_thread_area(struct task_struct *p, int idx,
288 struct user_desc __user *info, int can_allocate);
289
290#endif
291#endif
292