1 #ifndef _ASM_X86_PTRACE_H
2 #define _ASM_X86_PTRACE_H
4 #include <asm/segment.h>
5 #include <asm/page_types.h>
6 #include <uapi/asm/ptrace.h>
13 * NB: 32-bit x86 CPUs are inconsistent as what happens in the
14 * following cases (where %seg represents a segment register):
16 * - pushl %seg: some do a 16-bit write and leave the high
18 * - movl %seg, [mem]: some do a 16-bit write despite the movl
19 * - IDT entry: some (e.g. 486) will leave the high bits of CS
20 * and (if applicable) SS undefined.
22 * Fortunately, x86-32 doesn't read the high bits on POP or IRET,
23 * so we can just treat all of the segment registers as 16-bit
41 unsigned long orig_ax;
55 * C ABI says these regs are callee-preserved. They aren't saved on kernel entry
56 * unless syscall needs a complete, fully filled "struct pt_regs".
64 /* These regs are callee-clobbered. Always saved on kernel entry. */
75 * On syscall entry, this is syscall#. On CPU exception, this is error code.
76 * On hw interrupt, it's IRQ number:
78 unsigned long orig_ax;
79 /* Return frame for iretq */
85 /* top of stack page */
88 #endif /* !__i386__ */
90 #ifdef CONFIG_PARAVIRT
91 #include <asm/paravirt_types.h>
97 extern unsigned long profile_pc(struct pt_regs *regs);
98 #define profile_pc profile_pc
101 convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
102 extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
103 int error_code, int si_code);
106 static inline unsigned long regs_return_value(struct pt_regs *regs)
112 * user_mode(regs) determines whether a register set came from user
113 * mode. On x86_32, this is true if V8086 mode was enabled OR if the
114 * register set was from protected mode with RPL-3 CS value. This
115 * tricky test checks that with one comparison.
117 * On x86_64, vm86 mode is mercifully nonexistent, and we don't need
120 static inline int user_mode(struct pt_regs *regs)
123 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= USER_RPL;
125 return !!(regs->cs & 3);
129 static inline int v8086_mode(struct pt_regs *regs)
132 return (regs->flags & X86_VM_MASK);
134 return 0; /* No V86 mode support in long mode */
139 static inline bool user_64bit_mode(struct pt_regs *regs)
141 #ifndef CONFIG_PARAVIRT
143 * On non-paravirt systems, this is the only long mode CPL 3
144 * selector. We do not allow long mode selectors in the LDT.
146 return regs->cs == __USER_CS;
148 /* Headers are too twisted for this to go in paravirt.h. */
149 return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
153 #define current_user_stack_pointer() current_pt_regs()->sp
154 #define compat_user_stack_pointer() current_pt_regs()->sp
158 extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
160 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
166 #define GET_IP(regs) ((regs)->ip)
167 #define GET_FP(regs) ((regs)->bp)
168 #define GET_USP(regs) ((regs)->sp)
170 #include <asm-generic/ptrace.h>
172 /* Query offset/name of register from its name/offset */
173 extern int regs_query_register_offset(const char *name);
174 extern const char *regs_query_register_name(unsigned int offset);
175 #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
178 * regs_get_register() - get register value from its offset
179 * @regs: pt_regs from which register value is gotten.
180 * @offset: offset number of the register.
182 * regs_get_register returns the value of a register. The @offset is the
183 * offset of the register in struct pt_regs address which specified by @regs.
184 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
186 static inline unsigned long regs_get_register(struct pt_regs *regs,
189 if (unlikely(offset > MAX_REG_OFFSET))
193 * Traps from the kernel do not save sp and ss.
194 * Use the helper function to retrieve sp.
196 if (offset == offsetof(struct pt_regs, sp) &&
197 regs->cs == __KERNEL_CS)
198 return kernel_stack_pointer(regs);
200 /* The selector fields are 16-bit. */
201 if (offset == offsetof(struct pt_regs, cs) ||
202 offset == offsetof(struct pt_regs, ss) ||
203 offset == offsetof(struct pt_regs, ds) ||
204 offset == offsetof(struct pt_regs, es) ||
205 offset == offsetof(struct pt_regs, fs) ||
206 offset == offsetof(struct pt_regs, gs)) {
207 return *(u16 *)((unsigned long)regs + offset);
211 return *(unsigned long *)((unsigned long)regs + offset);
215 * regs_within_kernel_stack() - check the address in the stack
216 * @regs: pt_regs which contains kernel stack pointer.
217 * @addr: address which is checked.
219 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
220 * If @addr is within the kernel stack, it returns true. If not, returns false.
222 static inline int regs_within_kernel_stack(struct pt_regs *regs,
225 return ((addr & ~(THREAD_SIZE - 1)) ==
226 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
230 * regs_get_kernel_stack_nth() - get Nth entry of the stack
231 * @regs: pt_regs which contains kernel stack pointer.
232 * @n: stack entry number.
234 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
235 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
238 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
241 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
243 if (regs_within_kernel_stack(regs, (unsigned long)addr))
249 #define arch_has_single_step() (1)
250 #ifdef CONFIG_X86_DEBUGCTLMSR
251 #define arch_has_block_step() (1)
253 #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
256 #define ARCH_HAS_USER_SINGLE_STEP_INFO
259 * When hitting ptrace_stop(), we cannot return using SYSRET because
260 * that does not restore the full CPU state, only a minimal set. The
261 * ptracer can change arbitrary register values, which is usually okay
262 * because the usual ptrace stops run off the signal delivery path which
263 * forces IRET; however, ptrace_event() stops happen in arbitrary places
264 * in the kernel and don't force IRET path.
266 * So force IRET path after a ptrace stop.
268 #define arch_ptrace_stop_needed(code, info) \
275 extern int do_get_thread_area(struct task_struct *p, int idx,
276 struct user_desc __user *info);
277 extern int do_set_thread_area(struct task_struct *p, int idx,
278 struct user_desc __user *info, int can_allocate);
280 #endif /* !__ASSEMBLY__ */
281 #endif /* _ASM_X86_PTRACE_H */