]> Pileus Git - ~andy/linux/blob - arch/x86/include/asm/ptrace.h
Merge tag 'byteswap-for-linus-20121219' of git://git.infradead.org/users/dwmw2/byteswap
[~andy/linux] / arch / x86 / include / asm / ptrace.h
1 #ifndef _ASM_X86_PTRACE_H
2 #define _ASM_X86_PTRACE_H
3
4 #include <asm/segment.h>
5 #include <asm/page_types.h>
6 #include <uapi/asm/ptrace.h>
7
8 #ifndef __ASSEMBLY__
9 #ifdef __i386__
10
11 struct pt_regs {
12         unsigned long bx;
13         unsigned long cx;
14         unsigned long dx;
15         unsigned long si;
16         unsigned long di;
17         unsigned long bp;
18         unsigned long ax;
19         unsigned long ds;
20         unsigned long es;
21         unsigned long fs;
22         unsigned long gs;
23         unsigned long orig_ax;
24         unsigned long ip;
25         unsigned long cs;
26         unsigned long flags;
27         unsigned long sp;
28         unsigned long ss;
29 };
30
31 #else /* __i386__ */
32
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;
40 /* arguments: non interrupts/non tracing syscalls only save up to here*/
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 };
60
61 #endif /* !__i386__ */
62
63 #include <linux/init.h>
64 #ifdef CONFIG_PARAVIRT
65 #include <asm/paravirt_types.h>
66 #endif
67
68 struct cpuinfo_x86;
69 struct task_struct;
70
71 extern unsigned long profile_pc(struct pt_regs *regs);
72 #define profile_pc profile_pc
73
74 extern unsigned long
75 convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
76 extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
77                          int error_code, int si_code);
78
79 extern long syscall_trace_enter(struct pt_regs *);
80 extern void syscall_trace_leave(struct pt_regs *);
81
82 static inline unsigned long regs_return_value(struct pt_regs *regs)
83 {
84         return regs->ax;
85 }
86
87 /*
88  * user_mode_vm(regs) determines whether a register set came from user mode.
89  * This is true if V8086 mode was enabled OR if the register set was from
90  * protected mode with RPL-3 CS value.  This tricky test checks that with
91  * one comparison.  Many places in the kernel can bypass this full check
92  * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
93  */
94 static inline int user_mode(struct pt_regs *regs)
95 {
96 #ifdef CONFIG_X86_32
97         return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
98 #else
99         return !!(regs->cs & 3);
100 #endif
101 }
102
103 static inline int user_mode_vm(struct pt_regs *regs)
104 {
105 #ifdef CONFIG_X86_32
106         return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
107                 USER_RPL;
108 #else
109         return user_mode(regs);
110 #endif
111 }
112
113 static inline int v8086_mode(struct pt_regs *regs)
114 {
115 #ifdef CONFIG_X86_32
116         return (regs->flags & X86_VM_MASK);
117 #else
118         return 0;       /* No V86 mode support in long mode */
119 #endif
120 }
121
122 #ifdef CONFIG_X86_64
123 static inline bool user_64bit_mode(struct pt_regs *regs)
124 {
125 #ifndef CONFIG_PARAVIRT
126         /*
127          * On non-paravirt systems, this is the only long mode CPL 3
128          * selector.  We do not allow long mode selectors in the LDT.
129          */
130         return regs->cs == __USER_CS;
131 #else
132         /* Headers are too twisted for this to go in paravirt.h. */
133         return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
134 #endif
135 }
136 #endif
137
138 #ifdef CONFIG_X86_32
139 extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
140 #else
141 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
142 {
143         return regs->sp;
144 }
145 #endif
146
147 #define GET_IP(regs) ((regs)->ip)
148 #define GET_FP(regs) ((regs)->bp)
149 #define GET_USP(regs) ((regs)->sp)
150
151 #include <asm-generic/ptrace.h>
152
153 /* Query offset/name of register from its name/offset */
154 extern int regs_query_register_offset(const char *name);
155 extern const char *regs_query_register_name(unsigned int offset);
156 #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
157
158 /**
159  * regs_get_register() - get register value from its offset
160  * @regs:       pt_regs from which register value is gotten.
161  * @offset:     offset number of the register.
162  *
163  * regs_get_register returns the value of a register. The @offset is the
164  * offset of the register in struct pt_regs address which specified by @regs.
165  * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
166  */
167 static inline unsigned long regs_get_register(struct pt_regs *regs,
168                                               unsigned int offset)
169 {
170         if (unlikely(offset > MAX_REG_OFFSET))
171                 return 0;
172 #ifdef CONFIG_X86_32
173         /*
174          * Traps from the kernel do not save sp and ss.
175          * Use the helper function to retrieve sp.
176          */
177         if (offset == offsetof(struct pt_regs, sp) &&
178             regs->cs == __KERNEL_CS)
179                 return kernel_stack_pointer(regs);
180 #endif
181         return *(unsigned long *)((unsigned long)regs + offset);
182 }
183
184 /**
185  * regs_within_kernel_stack() - check the address in the stack
186  * @regs:       pt_regs which contains kernel stack pointer.
187  * @addr:       address which is checked.
188  *
189  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
190  * If @addr is within the kernel stack, it returns true. If not, returns false.
191  */
192 static inline int regs_within_kernel_stack(struct pt_regs *regs,
193                                            unsigned long addr)
194 {
195         return ((addr & ~(THREAD_SIZE - 1))  ==
196                 (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
197 }
198
199 /**
200  * regs_get_kernel_stack_nth() - get Nth entry of the stack
201  * @regs:       pt_regs which contains kernel stack pointer.
202  * @n:          stack entry number.
203  *
204  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
205  * is specified by @regs. If the @n th entry is NOT in the kernel stack,
206  * this returns 0.
207  */
208 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
209                                                       unsigned int n)
210 {
211         unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
212         addr += n;
213         if (regs_within_kernel_stack(regs, (unsigned long)addr))
214                 return *addr;
215         else
216                 return 0;
217 }
218
219 #define arch_has_single_step()  (1)
220 #ifdef CONFIG_X86_DEBUGCTLMSR
221 #define arch_has_block_step()   (1)
222 #else
223 #define arch_has_block_step()   (boot_cpu_data.x86 >= 6)
224 #endif
225
226 #define ARCH_HAS_USER_SINGLE_STEP_INFO
227
228 struct user_desc;
229 extern int do_get_thread_area(struct task_struct *p, int idx,
230                               struct user_desc __user *info);
231 extern int do_set_thread_area(struct task_struct *p, int idx,
232                               struct user_desc __user *info, int can_allocate);
233
234 #endif /* !__ASSEMBLY__ */
235 #endif /* _ASM_X86_PTRACE_H */