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>
23 unsigned long orig_ax;
40 /* arguments: non interrupts/non tracing syscalls only save up to here*/
50 unsigned long orig_ax;
51 /* end of arguments */
52 /* cpu exception frame or undefined */
58 /* top of stack page */
61 #endif /* !__i386__ */
63 #ifdef CONFIG_PARAVIRT
64 #include <asm/paravirt_types.h>
70 extern unsigned long profile_pc(struct pt_regs *regs);
71 #define profile_pc profile_pc
74 convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
75 extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
76 int error_code, int si_code);
79 extern unsigned long syscall_trace_enter_phase1(struct pt_regs *, u32 arch);
80 extern long syscall_trace_enter_phase2(struct pt_regs *, u32 arch,
81 unsigned long phase1_result);
83 extern long syscall_trace_enter(struct pt_regs *);
84 extern void syscall_trace_leave(struct pt_regs *);
86 static inline unsigned long regs_return_value(struct pt_regs *regs)
92 * user_mode_vm(regs) determines whether a register set came from user mode.
93 * This is true if V8086 mode was enabled OR if the register set was from
94 * protected mode with RPL-3 CS value. This tricky test checks that with
95 * one comparison. Many places in the kernel can bypass this full check
96 * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
98 static inline int user_mode(struct pt_regs *regs)
101 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
103 return !!(regs->cs & 3);
107 static inline int user_mode_vm(struct pt_regs *regs)
110 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
113 return user_mode(regs);
117 static inline int v8086_mode(struct pt_regs *regs)
120 return (regs->flags & X86_VM_MASK);
122 return 0; /* No V86 mode support in long mode */
127 static inline bool user_64bit_mode(struct pt_regs *regs)
129 #ifndef CONFIG_PARAVIRT
131 * On non-paravirt systems, this is the only long mode CPL 3
132 * selector. We do not allow long mode selectors in the LDT.
134 return regs->cs == __USER_CS;
136 /* Headers are too twisted for this to go in paravirt.h. */
137 return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
141 #define current_user_stack_pointer() this_cpu_read(old_rsp)
142 /* ia32 vs. x32 difference */
143 #define compat_user_stack_pointer() \
144 (test_thread_flag(TIF_IA32) \
145 ? current_pt_regs()->sp \
146 : this_cpu_read(old_rsp))
150 extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
152 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
158 #define GET_IP(regs) ((regs)->ip)
159 #define GET_FP(regs) ((regs)->bp)
160 #define GET_USP(regs) ((regs)->sp)
162 #include <asm-generic/ptrace.h>
164 /* Query offset/name of register from its name/offset */
165 extern int regs_query_register_offset(const char *name);
166 extern const char *regs_query_register_name(unsigned int offset);
167 #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
170 * regs_get_register() - get register value from its offset
171 * @regs: pt_regs from which register value is gotten.
172 * @offset: offset number of the register.
174 * regs_get_register returns the value of a register. The @offset is the
175 * offset of the register in struct pt_regs address which specified by @regs.
176 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
178 static inline unsigned long regs_get_register(struct pt_regs *regs,
181 if (unlikely(offset > MAX_REG_OFFSET))
185 * Traps from the kernel do not save sp and ss.
186 * Use the helper function to retrieve sp.
188 if (offset == offsetof(struct pt_regs, sp) &&
189 regs->cs == __KERNEL_CS)
190 return kernel_stack_pointer(regs);
192 return *(unsigned long *)((unsigned long)regs + offset);
196 * regs_within_kernel_stack() - check the address in the stack
197 * @regs: pt_regs which contains kernel stack pointer.
198 * @addr: address which is checked.
200 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
201 * If @addr is within the kernel stack, it returns true. If not, returns false.
203 static inline int regs_within_kernel_stack(struct pt_regs *regs,
206 return ((addr & ~(THREAD_SIZE - 1)) ==
207 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
211 * regs_get_kernel_stack_nth() - get Nth entry of the stack
212 * @regs: pt_regs which contains kernel stack pointer.
213 * @n: stack entry number.
215 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
216 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
219 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
222 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
224 if (regs_within_kernel_stack(regs, (unsigned long)addr))
230 #define arch_has_single_step() (1)
231 #ifdef CONFIG_X86_DEBUGCTLMSR
232 #define arch_has_block_step() (1)
234 #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
237 #define ARCH_HAS_USER_SINGLE_STEP_INFO
240 * When hitting ptrace_stop(), we cannot return using SYSRET because
241 * that does not restore the full CPU state, only a minimal set. The
242 * ptracer can change arbitrary register values, which is usually okay
243 * because the usual ptrace stops run off the signal delivery path which
244 * forces IRET; however, ptrace_event() stops happen in arbitrary places
245 * in the kernel and don't force IRET path.
247 * So force IRET path after a ptrace stop.
249 #define arch_ptrace_stop_needed(code, info) \
251 set_thread_flag(TIF_NOTIFY_RESUME); \
256 extern int do_get_thread_area(struct task_struct *p, int idx,
257 struct user_desc __user *info);
258 extern int do_set_thread_area(struct task_struct *p, int idx,
259 struct user_desc __user *info, int can_allocate);
261 #endif /* !__ASSEMBLY__ */
262 #endif /* _ASM_X86_PTRACE_H */