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