H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_PTRACE_H |
| 2 | #define _ASM_X86_PTRACE_H |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 3 | |
| 4 | #include <linux/compiler.h> /* For __user */ |
| 5 | #include <asm/ptrace-abi.h> |
Vegard Nossum | 6330a30 | 2008-05-28 09:46:19 +0200 | [diff] [blame] | 6 | #include <asm/processor-flags.h> |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 7 | |
Vegard Nossum | 6330a30 | 2008-05-28 09:46:19 +0200 | [diff] [blame] | 8 | #ifdef __KERNEL__ |
Vegard Nossum | 6330a30 | 2008-05-28 09:46:19 +0200 | [diff] [blame] | 9 | #include <asm/segment.h> |
| 10 | #endif |
Markus Metzger | eee3af4 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 11 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 12 | #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 Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 18 | #ifndef __KERNEL__ |
| 19 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 20 | struct 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 Heo | ccbeed3 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 31 | int xgs; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 32 | long orig_eax; |
| 33 | long eip; |
| 34 | int xcs; |
| 35 | long eflags; |
| 36 | long esp; |
| 37 | int xss; |
| 38 | }; |
| 39 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 40 | #else /* __KERNEL__ */ |
| 41 | |
| 42 | struct pt_regs { |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 43 | unsigned long bx; |
| 44 | unsigned long cx; |
| 45 | unsigned long dx; |
| 46 | unsigned long si; |
| 47 | unsigned long di; |
| 48 | unsigned long bp; |
Harvey Harrison | 9902a70 | 2008-02-08 12:09:57 -0800 | [diff] [blame] | 49 | unsigned long ax; |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 50 | unsigned long ds; |
| 51 | unsigned long es; |
| 52 | unsigned long fs; |
Tejun Heo | ccbeed3 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 53 | unsigned long gs; |
Harvey Harrison | 9902a70 | 2008-02-08 12:09:57 -0800 | [diff] [blame] | 54 | unsigned long orig_ax; |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 55 | unsigned long ip; |
| 56 | unsigned long cs; |
| 57 | unsigned long flags; |
| 58 | unsigned long sp; |
| 59 | unsigned long ss; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 60 | }; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 61 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 62 | #endif /* __KERNEL__ */ |
| 63 | |
| 64 | #else /* __i386__ */ |
| 65 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 66 | #ifndef __KERNEL__ |
| 67 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 68 | struct 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 Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 96 | #else /* __KERNEL__ */ |
| 97 | |
| 98 | struct 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 Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 125 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 126 | #endif /* __KERNEL__ */ |
| 127 | #endif /* !__i386__ */ |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 128 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame] | 129 | |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 130 | #ifdef __KERNEL__ |
| 131 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame] | 132 | #include <linux/init.h> |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 133 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame] | 134 | struct cpuinfo_x86; |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 135 | struct task_struct; |
| 136 | |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 137 | extern unsigned long profile_pc(struct pt_regs *regs); |
| 138 | |
| 139 | extern unsigned long |
| 140 | convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs); |
Joe Perches | 72f74fa2 | 2008-03-23 01:03:17 -0700 | [diff] [blame] | 141 | extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, |
Srinivasa Ds | da654b7 | 2008-09-23 15:23:52 +0530 | [diff] [blame] | 142 | int error_code, int si_code); |
Hiroshi Shimamoto | 72fa50f | 2008-09-05 16:27:11 -0700 | [diff] [blame] | 143 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where); |
| 144 | |
Jaswinder Singh | c1686ae | 2008-07-21 22:35:38 +0530 | [diff] [blame] | 145 | extern long syscall_trace_enter(struct pt_regs *); |
| 146 | extern void syscall_trace_leave(struct pt_regs *); |
| 147 | |
Harvey Harrison | 9902a70 | 2008-02-08 12:09:57 -0800 | [diff] [blame] | 148 | static inline unsigned long regs_return_value(struct pt_regs *regs) |
| 149 | { |
| 150 | return regs->ax; |
| 151 | } |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 152 | |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 153 | /* |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 154 | * 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 | */ |
| 160 | static 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 | |
| 169 | static inline int user_mode_vm(struct pt_regs *regs) |
| 170 | { |
| 171 | #ifdef CONFIG_X86_32 |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 172 | return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= |
Joe Perches | 72f74fa2 | 2008-03-23 01:03:17 -0700 | [diff] [blame] | 173 | USER_RPL; |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 174 | #else |
| 175 | return user_mode(regs); |
| 176 | #endif |
| 177 | } |
| 178 | |
| 179 | static inline int v8086_mode(struct pt_regs *regs) |
| 180 | { |
| 181 | #ifdef CONFIG_X86_32 |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 182 | return (regs->flags & X86_VM_MASK); |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 183 | #else |
| 184 | return 0; /* No V86 mode support in long mode */ |
| 185 | #endif |
| 186 | } |
| 187 | |
Harvey Harrison | f6e8e28 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 188 | /* |
| 189 | * X86_32 CPUs don't save ss and esp if the CPU is already in kernel mode |
Masami Hiramatsu | 7b6c6c7 | 2009-05-11 17:03:00 -0400 | [diff] [blame^] | 190 | * 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 '®s->sp'. |
Harvey Harrison | f6e8e28 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 192 | * |
| 193 | * This is valid only for kernel mode traps. |
| 194 | */ |
Masami Hiramatsu | 7b6c6c7 | 2009-05-11 17:03:00 -0400 | [diff] [blame^] | 195 | static inline unsigned long kernel_stack_pointer(struct pt_regs *regs) |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 196 | { |
| 197 | #ifdef CONFIG_X86_32 |
Masami Hiramatsu | 7b6c6c7 | 2009-05-11 17:03:00 -0400 | [diff] [blame^] | 198 | return (unsigned long)(®s->sp); |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 199 | #else |
| 200 | return regs->sp; |
| 201 | #endif |
| 202 | } |
| 203 | |
| 204 | static inline unsigned long instruction_pointer(struct pt_regs *regs) |
| 205 | { |
| 206 | return regs->ip; |
| 207 | } |
| 208 | |
| 209 | static inline unsigned long frame_pointer(struct pt_regs *regs) |
| 210 | { |
| 211 | return regs->bp; |
| 212 | } |
| 213 | |
Roland McGrath | 68bd0f4 | 2008-04-18 17:08:44 -0700 | [diff] [blame] | 214 | static inline unsigned long user_stack_pointer(struct pt_regs *regs) |
| 215 | { |
| 216 | return regs->sp; |
| 217 | } |
| 218 | |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 219 | /* |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 220 | * These are defined as per linux/ptrace.h, which see. |
| 221 | */ |
| 222 | #define arch_has_single_step() (1) |
| 223 | extern void user_enable_single_step(struct task_struct *); |
| 224 | extern void user_disable_single_step(struct task_struct *); |
| 225 | |
Roland McGrath | 10faa81 | 2008-01-30 13:30:54 +0100 | [diff] [blame] | 226 | extern 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 McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 233 | struct user_desc; |
| 234 | extern int do_get_thread_area(struct task_struct *p, int idx, |
| 235 | struct user_desc __user *info); |
| 236 | extern int do_set_thread_area(struct task_struct *p, int idx, |
| 237 | struct user_desc __user *info, int can_allocate); |
| 238 | |
Markus Metzger | bf53de9 | 2008-12-19 15:10:24 +0100 | [diff] [blame] | 239 | extern void x86_ptrace_untrace(struct task_struct *); |
| 240 | extern 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 McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 246 | #endif /* __KERNEL__ */ |
| 247 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 248 | #endif /* !__ASSEMBLY__ */ |
| 249 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 250 | #endif /* _ASM_X86_PTRACE_H */ |