Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 1 | #ifndef _ASM_X86_PTRACE_H |
| 2 | #define _ASM_X86_PTRACE_H |
| 3 | |
| 4 | #include <linux/compiler.h> /* For __user */ |
| 5 | #include <asm/ptrace-abi.h> |
| 6 | |
Markus Metzger | eee3af4 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 7 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 8 | #ifndef __ASSEMBLY__ |
| 9 | |
| 10 | #ifdef __i386__ |
| 11 | /* this struct defines the way the registers are stored on the |
| 12 | stack during a system call. */ |
| 13 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 14 | #ifndef __KERNEL__ |
| 15 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 16 | struct pt_regs { |
| 17 | long ebx; |
| 18 | long ecx; |
| 19 | long edx; |
| 20 | long esi; |
| 21 | long edi; |
| 22 | long ebp; |
| 23 | long eax; |
| 24 | int xds; |
| 25 | int xes; |
| 26 | int xfs; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 27 | /* int gs; */ |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 28 | long orig_eax; |
| 29 | long eip; |
| 30 | int xcs; |
| 31 | long eflags; |
| 32 | long esp; |
| 33 | int xss; |
| 34 | }; |
| 35 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 36 | #else /* __KERNEL__ */ |
| 37 | |
| 38 | struct pt_regs { |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 39 | unsigned long bx; |
| 40 | unsigned long cx; |
| 41 | unsigned long dx; |
| 42 | unsigned long si; |
| 43 | unsigned long di; |
| 44 | unsigned long bp; |
Harvey Harrison | 9902a70 | 2008-02-08 12:09:57 -0800 | [diff] [blame] | 45 | unsigned long ax; |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 46 | unsigned long ds; |
| 47 | unsigned long es; |
| 48 | unsigned long fs; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 49 | /* int gs; */ |
Harvey Harrison | 9902a70 | 2008-02-08 12:09:57 -0800 | [diff] [blame] | 50 | unsigned long orig_ax; |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 51 | unsigned long ip; |
| 52 | unsigned long cs; |
| 53 | unsigned long flags; |
| 54 | unsigned long sp; |
| 55 | unsigned long ss; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 56 | }; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 57 | |
| 58 | #include <asm/vm86.h> |
| 59 | #include <asm/segment.h> |
| 60 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 61 | #endif /* __KERNEL__ */ |
| 62 | |
| 63 | #else /* __i386__ */ |
| 64 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 65 | #ifndef __KERNEL__ |
| 66 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 67 | struct pt_regs { |
| 68 | unsigned long r15; |
| 69 | unsigned long r14; |
| 70 | unsigned long r13; |
| 71 | unsigned long r12; |
| 72 | unsigned long rbp; |
| 73 | unsigned long rbx; |
| 74 | /* arguments: non interrupts/non tracing syscalls only save upto here*/ |
| 75 | unsigned long r11; |
| 76 | unsigned long r10; |
| 77 | unsigned long r9; |
| 78 | unsigned long r8; |
| 79 | unsigned long rax; |
| 80 | unsigned long rcx; |
| 81 | unsigned long rdx; |
| 82 | unsigned long rsi; |
| 83 | unsigned long rdi; |
| 84 | unsigned long orig_rax; |
| 85 | /* end of arguments */ |
| 86 | /* cpu exception frame or undefined */ |
| 87 | unsigned long rip; |
| 88 | unsigned long cs; |
| 89 | unsigned long eflags; |
| 90 | unsigned long rsp; |
| 91 | unsigned long ss; |
| 92 | /* top of stack page */ |
| 93 | }; |
| 94 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 95 | #else /* __KERNEL__ */ |
| 96 | |
| 97 | struct pt_regs { |
| 98 | unsigned long r15; |
| 99 | unsigned long r14; |
| 100 | unsigned long r13; |
| 101 | unsigned long r12; |
| 102 | unsigned long bp; |
| 103 | unsigned long bx; |
| 104 | /* arguments: non interrupts/non tracing syscalls only save upto here*/ |
| 105 | unsigned long r11; |
| 106 | unsigned long r10; |
| 107 | unsigned long r9; |
| 108 | unsigned long r8; |
| 109 | unsigned long ax; |
| 110 | unsigned long cx; |
| 111 | unsigned long dx; |
| 112 | unsigned long si; |
| 113 | unsigned long di; |
| 114 | unsigned long orig_ax; |
| 115 | /* end of arguments */ |
| 116 | /* cpu exception frame or undefined */ |
| 117 | unsigned long ip; |
| 118 | unsigned long cs; |
| 119 | unsigned long flags; |
| 120 | unsigned long sp; |
| 121 | unsigned long ss; |
| 122 | /* top of stack page */ |
| 123 | }; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 124 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 125 | #endif /* __KERNEL__ */ |
| 126 | #endif /* !__i386__ */ |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 127 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame^] | 128 | |
| 129 | #ifdef CONFIG_X86_PTRACE_BTS |
| 130 | /* a branch trace record entry |
| 131 | * |
| 132 | * In order to unify the interface between various processor versions, |
| 133 | * we use the below data structure for all processors. |
| 134 | */ |
| 135 | enum bts_qualifier { |
| 136 | BTS_INVALID = 0, |
| 137 | BTS_BRANCH, |
| 138 | BTS_TASK_ARRIVES, |
| 139 | BTS_TASK_DEPARTS |
| 140 | }; |
| 141 | |
| 142 | struct bts_struct { |
| 143 | __u64 qualifier; |
| 144 | union { |
| 145 | /* BTS_BRANCH */ |
| 146 | struct { |
| 147 | __u64 from_ip; |
| 148 | __u64 to_ip; |
| 149 | } lbr; |
| 150 | /* BTS_TASK_ARRIVES or |
| 151 | BTS_TASK_DEPARTS */ |
| 152 | __u64 jiffies; |
| 153 | } variant; |
| 154 | }; |
| 155 | #endif /* CONFIG_X86_PTRACE_BTS */ |
| 156 | |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 157 | #ifdef __KERNEL__ |
| 158 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame^] | 159 | #include <linux/init.h> |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 160 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame^] | 161 | struct cpuinfo_x86; |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 162 | struct task_struct; |
| 163 | |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame^] | 164 | #ifdef CONFIG_X86_PTRACE_BTS |
| 165 | extern void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *); |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 166 | extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier); |
Markus Metzger | 93fa763 | 2008-04-08 11:01:58 +0200 | [diff] [blame^] | 167 | #else |
| 168 | #define ptrace_bts_init_intel(config) do {} while (0) |
| 169 | #endif /* CONFIG_X86_PTRACE_BTS */ |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 170 | |
| 171 | extern unsigned long profile_pc(struct pt_regs *regs); |
| 172 | |
| 173 | extern unsigned long |
| 174 | convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs); |
| 175 | |
| 176 | #ifdef CONFIG_X86_32 |
Joe Perches | 72f74fa2 | 2008-03-23 01:03:17 -0700 | [diff] [blame] | 177 | extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, |
| 178 | int error_code); |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 179 | #else |
| 180 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where); |
| 181 | #endif |
| 182 | |
Harvey Harrison | 9902a70 | 2008-02-08 12:09:57 -0800 | [diff] [blame] | 183 | static inline unsigned long regs_return_value(struct pt_regs *regs) |
| 184 | { |
| 185 | return regs->ax; |
| 186 | } |
Harvey Harrison | dbe3533 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 187 | |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 188 | /* |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 189 | * user_mode_vm(regs) determines whether a register set came from user mode. |
| 190 | * This is true if V8086 mode was enabled OR if the register set was from |
| 191 | * protected mode with RPL-3 CS value. This tricky test checks that with |
| 192 | * one comparison. Many places in the kernel can bypass this full check |
| 193 | * if they have already ruled out V8086 mode, so user_mode(regs) can be used. |
| 194 | */ |
| 195 | static inline int user_mode(struct pt_regs *regs) |
| 196 | { |
| 197 | #ifdef CONFIG_X86_32 |
| 198 | return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL; |
| 199 | #else |
| 200 | return !!(regs->cs & 3); |
| 201 | #endif |
| 202 | } |
| 203 | |
| 204 | static inline int user_mode_vm(struct pt_regs *regs) |
| 205 | { |
| 206 | #ifdef CONFIG_X86_32 |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 207 | return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= |
Joe Perches | 72f74fa2 | 2008-03-23 01:03:17 -0700 | [diff] [blame] | 208 | USER_RPL; |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 209 | #else |
| 210 | return user_mode(regs); |
| 211 | #endif |
| 212 | } |
| 213 | |
| 214 | static inline int v8086_mode(struct pt_regs *regs) |
| 215 | { |
| 216 | #ifdef CONFIG_X86_32 |
gorcunov@gmail.com | 6b6891f | 2008-03-28 17:56:57 +0300 | [diff] [blame] | 217 | return (regs->flags & X86_VM_MASK); |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 218 | #else |
| 219 | return 0; /* No V86 mode support in long mode */ |
| 220 | #endif |
| 221 | } |
| 222 | |
Harvey Harrison | f6e8e28 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 223 | /* |
| 224 | * X86_32 CPUs don't save ss and esp if the CPU is already in kernel mode |
| 225 | * when it traps. So regs will be the current sp. |
| 226 | * |
| 227 | * This is valid only for kernel mode traps. |
| 228 | */ |
| 229 | static inline unsigned long kernel_trap_sp(struct pt_regs *regs) |
Harvey Harrison | 90d43d7 | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 230 | { |
| 231 | #ifdef CONFIG_X86_32 |
| 232 | return (unsigned long)regs; |
| 233 | #else |
| 234 | return regs->sp; |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | static inline unsigned long instruction_pointer(struct pt_regs *regs) |
| 239 | { |
| 240 | return regs->ip; |
| 241 | } |
| 242 | |
| 243 | static inline unsigned long frame_pointer(struct pt_regs *regs) |
| 244 | { |
| 245 | return regs->bp; |
| 246 | } |
| 247 | |
| 248 | /* |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 249 | * These are defined as per linux/ptrace.h, which see. |
| 250 | */ |
| 251 | #define arch_has_single_step() (1) |
| 252 | extern void user_enable_single_step(struct task_struct *); |
| 253 | extern void user_disable_single_step(struct task_struct *); |
| 254 | |
Roland McGrath | 10faa81 | 2008-01-30 13:30:54 +0100 | [diff] [blame] | 255 | extern void user_enable_block_step(struct task_struct *); |
| 256 | #ifdef CONFIG_X86_DEBUGCTLMSR |
| 257 | #define arch_has_block_step() (1) |
| 258 | #else |
| 259 | #define arch_has_block_step() (boot_cpu_data.x86 >= 6) |
| 260 | #endif |
| 261 | |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 262 | struct user_desc; |
| 263 | extern int do_get_thread_area(struct task_struct *p, int idx, |
| 264 | struct user_desc __user *info); |
| 265 | extern int do_set_thread_area(struct task_struct *p, int idx, |
| 266 | struct user_desc __user *info, int can_allocate); |
| 267 | |
Roland McGrath | 562b80b | 2008-04-22 12:21:25 -0700 | [diff] [blame] | 268 | #define __ARCH_WANT_COMPAT_SYS_PTRACE |
| 269 | |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 270 | #endif /* __KERNEL__ */ |
| 271 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 272 | #endif /* !__ASSEMBLY__ */ |
| 273 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 274 | #endif |