]>
Commit | Line | Data |
---|---|---|
1965aae3 PA |
1 | #ifndef _ASM_X86_PTRACE_H |
2 | #define _ASM_X86_PTRACE_H | |
8fc37f2c | 3 | |
6330a30a | 4 | #include <asm/segment.h> |
b1cf540f | 5 | #include <asm/page_types.h> |
af170c50 | 6 | #include <uapi/asm/ptrace.h> |
eee3af4a | 7 | |
8fc37f2c | 8 | #ifndef __ASSEMBLY__ |
8fc37f2c | 9 | #ifdef __i386__ |
65ea5b03 PA |
10 | |
11 | struct pt_regs { | |
92bc2056 HH |
12 | unsigned long bx; |
13 | unsigned long cx; | |
14 | unsigned long dx; | |
15 | unsigned long si; | |
16 | unsigned long di; | |
17 | unsigned long bp; | |
9902a702 | 18 | unsigned long ax; |
92bc2056 HH |
19 | unsigned long ds; |
20 | unsigned long es; | |
21 | unsigned long fs; | |
ccbeed3a | 22 | unsigned long gs; |
9902a702 | 23 | unsigned long orig_ax; |
92bc2056 HH |
24 | unsigned long ip; |
25 | unsigned long cs; | |
26 | unsigned long flags; | |
27 | unsigned long sp; | |
28 | unsigned long ss; | |
65ea5b03 | 29 | }; |
8fc37f2c | 30 | |
8fc37f2c TG |
31 | #else /* __i386__ */ |
32 | ||
65ea5b03 PA |
33 | struct pt_regs { |
34 | unsigned long r15; | |
35 | unsigned long r14; | |
36 | unsigned long r13; | |
37 | unsigned long r12; | |
38 | unsigned long bp; | |
39 | unsigned long bx; | |
0d2eb44f | 40 | /* arguments: non interrupts/non tracing syscalls only save up to here*/ |
65ea5b03 PA |
41 | unsigned long r11; |
42 | unsigned long r10; | |
43 | unsigned long r9; | |
44 | unsigned long r8; | |
45 | unsigned long ax; | |
46 | unsigned long cx; | |
47 | unsigned long dx; | |
48 | unsigned long si; | |
49 | unsigned long di; | |
50 | unsigned long orig_ax; | |
51 | /* end of arguments */ | |
52 | /* cpu exception frame or undefined */ | |
53 | unsigned long ip; | |
54 | unsigned long cs; | |
55 | unsigned long flags; | |
56 | unsigned long sp; | |
57 | unsigned long ss; | |
58 | /* top of stack page */ | |
59 | }; | |
8fc37f2c | 60 | |
dbe3533b | 61 | #endif /* !__i386__ */ |
8fc37f2c | 62 | |
318f5a2a AL |
63 | #ifdef CONFIG_PARAVIRT |
64 | #include <asm/paravirt_types.h> | |
65 | #endif | |
8fc37f2c | 66 | |
93fa7636 | 67 | struct cpuinfo_x86; |
8fc37f2c TG |
68 | struct task_struct; |
69 | ||
dbe3533b | 70 | extern unsigned long profile_pc(struct pt_regs *regs); |
c46dd6b4 | 71 | #define profile_pc profile_pc |
dbe3533b | 72 | |
8fc37f2c | 73 | extern unsigned long |
37cd9cf3 | 74 | convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs); |
72f74fa2 | 75 | extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, |
da654b74 | 76 | int error_code, int si_code); |
72fa50f4 | 77 | |
c1686aea JS |
78 | extern long syscall_trace_enter(struct pt_regs *); |
79 | extern void syscall_trace_leave(struct pt_regs *); | |
80 | ||
9902a702 HH |
81 | static inline unsigned long regs_return_value(struct pt_regs *regs) |
82 | { | |
83 | return regs->ax; | |
84 | } | |
efd1ca52 | 85 | |
90d43d72 HH |
86 | /* |
87 | * user_mode_vm(regs) determines whether a register set came from user mode. | |
88 | * This is true if V8086 mode was enabled OR if the register set was from | |
89 | * protected mode with RPL-3 CS value. This tricky test checks that with | |
90 | * one comparison. Many places in the kernel can bypass this full check | |
91 | * if they have already ruled out V8086 mode, so user_mode(regs) can be used. | |
92 | */ | |
93 | static inline int user_mode(struct pt_regs *regs) | |
94 | { | |
95 | #ifdef CONFIG_X86_32 | |
96 | return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL; | |
97 | #else | |
98 | return !!(regs->cs & 3); | |
99 | #endif | |
100 | } | |
101 | ||
102 | static inline int user_mode_vm(struct pt_regs *regs) | |
103 | { | |
104 | #ifdef CONFIG_X86_32 | |
6b6891f9 | 105 | return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= |
72f74fa2 | 106 | USER_RPL; |
90d43d72 HH |
107 | #else |
108 | return user_mode(regs); | |
109 | #endif | |
110 | } | |
111 | ||
112 | static inline int v8086_mode(struct pt_regs *regs) | |
113 | { | |
114 | #ifdef CONFIG_X86_32 | |
6b6891f9 | 115 | return (regs->flags & X86_VM_MASK); |
90d43d72 HH |
116 | #else |
117 | return 0; /* No V86 mode support in long mode */ | |
118 | #endif | |
119 | } | |
120 | ||
318f5a2a AL |
121 | #ifdef CONFIG_X86_64 |
122 | static inline bool user_64bit_mode(struct pt_regs *regs) | |
123 | { | |
124 | #ifndef CONFIG_PARAVIRT | |
125 | /* | |
126 | * On non-paravirt systems, this is the only long mode CPL 3 | |
127 | * selector. We do not allow long mode selectors in the LDT. | |
128 | */ | |
129 | return regs->cs == __USER_CS; | |
130 | #else | |
131 | /* Headers are too twisted for this to go in paravirt.h. */ | |
132 | return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs; | |
133 | #endif | |
134 | } | |
9b064fc3 AV |
135 | |
136 | #define current_user_stack_pointer() this_cpu_read(old_rsp) | |
137 | /* ia32 vs. x32 difference */ | |
138 | #define compat_user_stack_pointer() \ | |
139 | (test_thread_flag(TIF_IA32) \ | |
140 | ? current_pt_regs()->sp \ | |
141 | : this_cpu_read(old_rsp)) | |
318f5a2a AL |
142 | #endif |
143 | ||
90d43d72 | 144 | #ifdef CONFIG_X86_32 |
10226238 | 145 | extern unsigned long kernel_stack_pointer(struct pt_regs *regs); |
90d43d72 | 146 | #else |
10226238 RR |
147 | static inline unsigned long kernel_stack_pointer(struct pt_regs *regs) |
148 | { | |
90d43d72 | 149 | return regs->sp; |
90d43d72 | 150 | } |
10226238 | 151 | #endif |
90d43d72 | 152 | |
c46dd6b4 MF |
153 | #define GET_IP(regs) ((regs)->ip) |
154 | #define GET_FP(regs) ((regs)->bp) | |
155 | #define GET_USP(regs) ((regs)->sp) | |
90d43d72 | 156 | |
c46dd6b4 | 157 | #include <asm-generic/ptrace.h> |
68bd0f4e | 158 | |
b1cf540f MH |
159 | /* Query offset/name of register from its name/offset */ |
160 | extern int regs_query_register_offset(const char *name); | |
161 | extern const char *regs_query_register_name(unsigned int offset); | |
162 | #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss)) | |
163 | ||
164 | /** | |
165 | * regs_get_register() - get register value from its offset | |
166 | * @regs: pt_regs from which register value is gotten. | |
167 | * @offset: offset number of the register. | |
168 | * | |
e859cf86 MH |
169 | * regs_get_register returns the value of a register. The @offset is the |
170 | * offset of the register in struct pt_regs address which specified by @regs. | |
b1cf540f MH |
171 | * If @offset is bigger than MAX_REG_OFFSET, this returns 0. |
172 | */ | |
173 | static inline unsigned long regs_get_register(struct pt_regs *regs, | |
174 | unsigned int offset) | |
175 | { | |
176 | if (unlikely(offset > MAX_REG_OFFSET)) | |
177 | return 0; | |
6c8d8b3c SR |
178 | #ifdef CONFIG_X86_32 |
179 | /* | |
180 | * Traps from the kernel do not save sp and ss. | |
181 | * Use the helper function to retrieve sp. | |
182 | */ | |
183 | if (offset == offsetof(struct pt_regs, sp) && | |
184 | regs->cs == __KERNEL_CS) | |
185 | return kernel_stack_pointer(regs); | |
186 | #endif | |
b1cf540f MH |
187 | return *(unsigned long *)((unsigned long)regs + offset); |
188 | } | |
189 | ||
190 | /** | |
191 | * regs_within_kernel_stack() - check the address in the stack | |
192 | * @regs: pt_regs which contains kernel stack pointer. | |
193 | * @addr: address which is checked. | |
194 | * | |
e859cf86 | 195 | * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). |
b1cf540f MH |
196 | * If @addr is within the kernel stack, it returns true. If not, returns false. |
197 | */ | |
198 | static inline int regs_within_kernel_stack(struct pt_regs *regs, | |
199 | unsigned long addr) | |
200 | { | |
201 | return ((addr & ~(THREAD_SIZE - 1)) == | |
202 | (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); | |
203 | } | |
204 | ||
205 | /** | |
206 | * regs_get_kernel_stack_nth() - get Nth entry of the stack | |
207 | * @regs: pt_regs which contains kernel stack pointer. | |
208 | * @n: stack entry number. | |
209 | * | |
210 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which | |
e859cf86 | 211 | * is specified by @regs. If the @n th entry is NOT in the kernel stack, |
b1cf540f MH |
212 | * this returns 0. |
213 | */ | |
214 | static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, | |
215 | unsigned int n) | |
216 | { | |
217 | unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); | |
218 | addr += n; | |
219 | if (regs_within_kernel_stack(regs, (unsigned long)addr)) | |
220 | return *addr; | |
221 | else | |
222 | return 0; | |
223 | } | |
224 | ||
7f232343 | 225 | #define arch_has_single_step() (1) |
10faa81e RM |
226 | #ifdef CONFIG_X86_DEBUGCTLMSR |
227 | #define arch_has_block_step() (1) | |
228 | #else | |
229 | #define arch_has_block_step() (boot_cpu_data.x86 >= 6) | |
230 | #endif | |
231 | ||
7f38551f ON |
232 | #define ARCH_HAS_USER_SINGLE_STEP_INFO |
233 | ||
b9cd18de TH |
234 | /* |
235 | * When hitting ptrace_stop(), we cannot return using SYSRET because | |
236 | * that does not restore the full CPU state, only a minimal set. The | |
237 | * ptracer can change arbitrary register values, which is usually okay | |
238 | * because the usual ptrace stops run off the signal delivery path which | |
239 | * forces IRET; however, ptrace_event() stops happen in arbitrary places | |
240 | * in the kernel and don't force IRET path. | |
241 | * | |
242 | * So force IRET path after a ptrace stop. | |
243 | */ | |
244 | #define arch_ptrace_stop_needed(code, info) \ | |
245 | ({ \ | |
246 | set_thread_flag(TIF_NOTIFY_RESUME); \ | |
247 | false; \ | |
248 | }) | |
249 | ||
efd1ca52 RM |
250 | struct user_desc; |
251 | extern int do_get_thread_area(struct task_struct *p, int idx, | |
252 | struct user_desc __user *info); | |
253 | extern int do_set_thread_area(struct task_struct *p, int idx, | |
254 | struct user_desc __user *info, int can_allocate); | |
255 | ||
8fc37f2c | 256 | #endif /* !__ASSEMBLY__ */ |
1965aae3 | 257 | #endif /* _ASM_X86_PTRACE_H */ |