blob: 624f133943ed71293aaba1477b9ca20ad0836da8 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_PTRACE_H
2#define _ASM_X86_PTRACE_H
Thomas Gleixner8fc37f22007-10-23 22:37:24 +02003
4#include <linux/compiler.h> /* For __user */
5#include <asm/ptrace-abi.h>
Vegard Nossum6330a302008-05-28 09:46:19 +02006#include <asm/processor-flags.h>
Thomas Gleixner8fc37f22007-10-23 22:37:24 +02007
Vegard Nossum6330a302008-05-28 09:46:19 +02008#ifdef __KERNEL__
Vegard Nossum6330a302008-05-28 09:46:19 +02009#include <asm/segment.h>
10#endif
Markus Metzgereee3af42008-01-30 13:31:09 +010011
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020012#ifndef __ASSEMBLY__
13
14#ifdef __i386__
15/* this struct defines the way the registers are stored on the
16 stack during a system call. */
17
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010018#ifndef __KERNEL__
19
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020020struct pt_regs {
21 long ebx;
22 long ecx;
23 long edx;
24 long esi;
25 long edi;
26 long ebp;
27 long eax;
28 int xds;
29 int xes;
30 int xfs;
Tejun Heoccbeed32009-02-09 22:17:40 +090031 int xgs;
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020032 long orig_eax;
33 long eip;
34 int xcs;
35 long eflags;
36 long esp;
37 int xss;
38};
39
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010040#else /* __KERNEL__ */
41
42struct pt_regs {
Harvey Harrison92bc2052008-02-08 12:09:56 -080043 unsigned long bx;
44 unsigned long cx;
45 unsigned long dx;
46 unsigned long si;
47 unsigned long di;
48 unsigned long bp;
Harvey Harrison9902a702008-02-08 12:09:57 -080049 unsigned long ax;
Harvey Harrison92bc2052008-02-08 12:09:56 -080050 unsigned long ds;
51 unsigned long es;
52 unsigned long fs;
Tejun Heoccbeed32009-02-09 22:17:40 +090053 unsigned long gs;
Harvey Harrison9902a702008-02-08 12:09:57 -080054 unsigned long orig_ax;
Harvey Harrison92bc2052008-02-08 12:09:56 -080055 unsigned long ip;
56 unsigned long cs;
57 unsigned long flags;
58 unsigned long sp;
59 unsigned long ss;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010060};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020061
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020062#endif /* __KERNEL__ */
63
64#else /* __i386__ */
65
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010066#ifndef __KERNEL__
67
Thomas Gleixner8fc37f22007-10-23 22:37:24 +020068struct pt_regs {
69 unsigned long r15;
70 unsigned long r14;
71 unsigned long r13;
72 unsigned long r12;
73 unsigned long rbp;
74 unsigned long rbx;
75/* arguments: non interrupts/non tracing syscalls only save upto here*/
76 unsigned long r11;
77 unsigned long r10;
78 unsigned long r9;
79 unsigned long r8;
80 unsigned long rax;
81 unsigned long rcx;
82 unsigned long rdx;
83 unsigned long rsi;
84 unsigned long rdi;
85 unsigned long orig_rax;
86/* end of arguments */
87/* cpu exception frame or undefined */
88 unsigned long rip;
89 unsigned long cs;
90 unsigned long eflags;
91 unsigned long rsp;
92 unsigned long ss;
93/* top of stack page */
94};
95
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010096#else /* __KERNEL__ */
97
98struct pt_regs {
99 unsigned long r15;
100 unsigned long r14;
101 unsigned long r13;
102 unsigned long r12;
103 unsigned long bp;
104 unsigned long bx;
105/* arguments: non interrupts/non tracing syscalls only save upto here*/
106 unsigned long r11;
107 unsigned long r10;
108 unsigned long r9;
109 unsigned long r8;
110 unsigned long ax;
111 unsigned long cx;
112 unsigned long dx;
113 unsigned long si;
114 unsigned long di;
115 unsigned long orig_ax;
116/* end of arguments */
117/* cpu exception frame or undefined */
118 unsigned long ip;
119 unsigned long cs;
120 unsigned long flags;
121 unsigned long sp;
122 unsigned long ss;
123/* top of stack page */
124};
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200125
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200126#endif /* __KERNEL__ */
127#endif /* !__i386__ */
Roland McGrathefd1ca52008-01-30 13:30:46 +0100128
Markus Metzger93fa7632008-04-08 11:01:58 +0200129
Roland McGrathefd1ca52008-01-30 13:30:46 +0100130#ifdef __KERNEL__
131
Markus Metzger93fa7632008-04-08 11:01:58 +0200132#include <linux/init.h>
Harvey Harrisondbe35332008-01-30 13:33:16 +0100133
Markus Metzger93fa7632008-04-08 11:01:58 +0200134struct cpuinfo_x86;
Harvey Harrisondbe35332008-01-30 13:33:16 +0100135struct task_struct;
136
Harvey Harrisondbe35332008-01-30 13:33:16 +0100137extern unsigned long profile_pc(struct pt_regs *regs);
138
139extern unsigned long
140convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
Joe Perches72f74fa22008-03-23 01:03:17 -0700141extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
Srinivasa Dsda654b72008-09-23 15:23:52 +0530142 int error_code, int si_code);
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700143void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
144
Jaswinder Singhc1686ae2008-07-21 22:35:38 +0530145extern long syscall_trace_enter(struct pt_regs *);
146extern void syscall_trace_leave(struct pt_regs *);
147
Harvey Harrison9902a702008-02-08 12:09:57 -0800148static inline unsigned long regs_return_value(struct pt_regs *regs)
149{
150 return regs->ax;
151}
Harvey Harrisondbe35332008-01-30 13:33:16 +0100152
Roland McGrath7f232342008-01-30 13:30:48 +0100153/*
Harvey Harrison90d43d72008-01-30 13:33:16 +0100154 * user_mode_vm(regs) determines whether a register set came from user mode.
155 * This is true if V8086 mode was enabled OR if the register set was from
156 * protected mode with RPL-3 CS value. This tricky test checks that with
157 * one comparison. Many places in the kernel can bypass this full check
158 * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
159 */
160static inline int user_mode(struct pt_regs *regs)
161{
162#ifdef CONFIG_X86_32
163 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
164#else
165 return !!(regs->cs & 3);
166#endif
167}
168
169static inline int user_mode_vm(struct pt_regs *regs)
170{
171#ifdef CONFIG_X86_32
gorcunov@gmail.com6b6891f2008-03-28 17:56:57 +0300172 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
Joe Perches72f74fa22008-03-23 01:03:17 -0700173 USER_RPL;
Harvey Harrison90d43d72008-01-30 13:33:16 +0100174#else
175 return user_mode(regs);
176#endif
177}
178
179static inline int v8086_mode(struct pt_regs *regs)
180{
181#ifdef CONFIG_X86_32
gorcunov@gmail.com6b6891f2008-03-28 17:56:57 +0300182 return (regs->flags & X86_VM_MASK);
Harvey Harrison90d43d72008-01-30 13:33:16 +0100183#else
184 return 0; /* No V86 mode support in long mode */
185#endif
186}
187
Harvey Harrisonf6e8e282008-01-30 13:33:16 +0100188/*
189 * X86_32 CPUs don't save ss and esp if the CPU is already in kernel mode
Masami Hiramatsu7b6c6c72009-05-11 17:03:00 -0400190 * when it traps. The previous stack will be directly underneath the saved
191 * registers, and 'sp/ss' won't even have been saved. Thus the '&regs->sp'.
Harvey Harrisonf6e8e282008-01-30 13:33:16 +0100192 *
193 * This is valid only for kernel mode traps.
194 */
Masami Hiramatsu7b6c6c72009-05-11 17:03:00 -0400195static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
Harvey Harrison90d43d72008-01-30 13:33:16 +0100196{
197#ifdef CONFIG_X86_32
Masami Hiramatsu7b6c6c72009-05-11 17:03:00 -0400198 return (unsigned long)(&regs->sp);
Harvey Harrison90d43d72008-01-30 13:33:16 +0100199#else
200 return regs->sp;
201#endif
202}
203
204static inline unsigned long instruction_pointer(struct pt_regs *regs)
205{
206 return regs->ip;
207}
208
209static inline unsigned long frame_pointer(struct pt_regs *regs)
210{
211 return regs->bp;
212}
213
Roland McGrath68bd0f42008-04-18 17:08:44 -0700214static inline unsigned long user_stack_pointer(struct pt_regs *regs)
215{
216 return regs->sp;
217}
218
Harvey Harrison90d43d72008-01-30 13:33:16 +0100219/*
Roland McGrath7f232342008-01-30 13:30:48 +0100220 * These are defined as per linux/ptrace.h, which see.
221 */
222#define arch_has_single_step() (1)
223extern void user_enable_single_step(struct task_struct *);
224extern void user_disable_single_step(struct task_struct *);
225
Roland McGrath10faa812008-01-30 13:30:54 +0100226extern void user_enable_block_step(struct task_struct *);
227#ifdef CONFIG_X86_DEBUGCTLMSR
228#define arch_has_block_step() (1)
229#else
230#define arch_has_block_step() (boot_cpu_data.x86 >= 6)
231#endif
232
Roland McGrathefd1ca52008-01-30 13:30:46 +0100233struct user_desc;
234extern int do_get_thread_area(struct task_struct *p, int idx,
235 struct user_desc __user *info);
236extern int do_set_thread_area(struct task_struct *p, int idx,
237 struct user_desc __user *info, int can_allocate);
238
Markus Metzgerbf53de92008-12-19 15:10:24 +0100239extern void x86_ptrace_untrace(struct task_struct *);
240extern void x86_ptrace_fork(struct task_struct *child,
241 unsigned long clone_flags);
242
243#define arch_ptrace_untrace(tsk) x86_ptrace_untrace(tsk)
244#define arch_ptrace_fork(child, flags) x86_ptrace_fork(child, flags)
245
Roland McGrathefd1ca52008-01-30 13:30:46 +0100246#endif /* __KERNEL__ */
247
Thomas Gleixner8fc37f22007-10-23 22:37:24 +0200248#endif /* !__ASSEMBLY__ */
249
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700250#endif /* _ASM_X86_PTRACE_H */