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 | |
Markus Metzger | eee3af4 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 10 | #ifdef __KERNEL__ |
| 11 | |
Markus Metzger | a95d67f | 2008-01-30 13:31:20 +0100 | [diff] [blame^] | 12 | /* the DS BTS struct is used for ptrace as well */ |
Markus Metzger | eee3af4 | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 13 | #include <asm/ds.h> |
| 14 | |
| 15 | struct task_struct; |
| 16 | extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier); |
| 17 | |
| 18 | #endif /* __KERNEL__ */ |
| 19 | |
| 20 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 21 | #ifdef __i386__ |
| 22 | /* this struct defines the way the registers are stored on the |
| 23 | stack during a system call. */ |
| 24 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 25 | #ifndef __KERNEL__ |
| 26 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 27 | struct pt_regs { |
| 28 | long ebx; |
| 29 | long ecx; |
| 30 | long edx; |
| 31 | long esi; |
| 32 | long edi; |
| 33 | long ebp; |
| 34 | long eax; |
| 35 | int xds; |
| 36 | int xes; |
| 37 | int xfs; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 38 | /* int gs; */ |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 39 | long orig_eax; |
| 40 | long eip; |
| 41 | int xcs; |
| 42 | long eflags; |
| 43 | long esp; |
| 44 | int xss; |
| 45 | }; |
| 46 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 47 | #else /* __KERNEL__ */ |
| 48 | |
| 49 | struct pt_regs { |
| 50 | long bx; |
| 51 | long cx; |
| 52 | long dx; |
| 53 | long si; |
| 54 | long di; |
| 55 | long bp; |
| 56 | long ax; |
| 57 | int ds; |
| 58 | int es; |
| 59 | int fs; |
| 60 | /* int gs; */ |
| 61 | long orig_ax; |
| 62 | long ip; |
| 63 | int cs; |
| 64 | long flags; |
| 65 | long sp; |
| 66 | int ss; |
| 67 | }; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 68 | |
| 69 | #include <asm/vm86.h> |
| 70 | #include <asm/segment.h> |
| 71 | |
| 72 | struct task_struct; |
| 73 | extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code); |
| 74 | |
| 75 | /* |
| 76 | * user_mode_vm(regs) determines whether a register set came from user mode. |
| 77 | * This is true if V8086 mode was enabled OR if the register set was from |
| 78 | * protected mode with RPL-3 CS value. This tricky test checks that with |
| 79 | * one comparison. Many places in the kernel can bypass this full check |
| 80 | * if they have already ruled out V8086 mode, so user_mode(regs) can be used. |
| 81 | */ |
| 82 | static inline int user_mode(struct pt_regs *regs) |
| 83 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 84 | return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 85 | } |
| 86 | static inline int user_mode_vm(struct pt_regs *regs) |
| 87 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 88 | return ((regs->cs & SEGMENT_RPL_MASK) | |
| 89 | (regs->flags & VM_MASK)) >= USER_RPL; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 90 | } |
| 91 | static inline int v8086_mode(struct pt_regs *regs) |
| 92 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 93 | return (regs->flags & VM_MASK); |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 94 | } |
| 95 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 96 | #define instruction_pointer(regs) ((regs)->ip) |
| 97 | #define frame_pointer(regs) ((regs)->bp) |
Jan Blunck | 77f2878 | 2007-11-14 17:00:42 -0800 | [diff] [blame] | 98 | #define stack_pointer(regs) ((unsigned long)(regs)) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 99 | #define regs_return_value(regs) ((regs)->ax) |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 100 | |
| 101 | extern unsigned long profile_pc(struct pt_regs *regs); |
| 102 | #endif /* __KERNEL__ */ |
| 103 | |
| 104 | #else /* __i386__ */ |
| 105 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 106 | #ifndef __KERNEL__ |
| 107 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 108 | struct pt_regs { |
| 109 | unsigned long r15; |
| 110 | unsigned long r14; |
| 111 | unsigned long r13; |
| 112 | unsigned long r12; |
| 113 | unsigned long rbp; |
| 114 | unsigned long rbx; |
| 115 | /* arguments: non interrupts/non tracing syscalls only save upto here*/ |
| 116 | unsigned long r11; |
| 117 | unsigned long r10; |
| 118 | unsigned long r9; |
| 119 | unsigned long r8; |
| 120 | unsigned long rax; |
| 121 | unsigned long rcx; |
| 122 | unsigned long rdx; |
| 123 | unsigned long rsi; |
| 124 | unsigned long rdi; |
| 125 | unsigned long orig_rax; |
| 126 | /* end of arguments */ |
| 127 | /* cpu exception frame or undefined */ |
| 128 | unsigned long rip; |
| 129 | unsigned long cs; |
| 130 | unsigned long eflags; |
| 131 | unsigned long rsp; |
| 132 | unsigned long ss; |
| 133 | /* top of stack page */ |
| 134 | }; |
| 135 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 136 | #else /* __KERNEL__ */ |
| 137 | |
| 138 | struct pt_regs { |
| 139 | unsigned long r15; |
| 140 | unsigned long r14; |
| 141 | unsigned long r13; |
| 142 | unsigned long r12; |
| 143 | unsigned long bp; |
| 144 | unsigned long bx; |
| 145 | /* arguments: non interrupts/non tracing syscalls only save upto here*/ |
| 146 | unsigned long r11; |
| 147 | unsigned long r10; |
| 148 | unsigned long r9; |
| 149 | unsigned long r8; |
| 150 | unsigned long ax; |
| 151 | unsigned long cx; |
| 152 | unsigned long dx; |
| 153 | unsigned long si; |
| 154 | unsigned long di; |
| 155 | unsigned long orig_ax; |
| 156 | /* end of arguments */ |
| 157 | /* cpu exception frame or undefined */ |
| 158 | unsigned long ip; |
| 159 | unsigned long cs; |
| 160 | unsigned long flags; |
| 161 | unsigned long sp; |
| 162 | unsigned long ss; |
| 163 | /* top of stack page */ |
| 164 | }; |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 165 | |
| 166 | #define user_mode(regs) (!!((regs)->cs & 3)) |
| 167 | #define user_mode_vm(regs) user_mode(regs) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 168 | #define v8086_mode(regs) 0 /* No V86 mode support in long mode */ |
| 169 | #define instruction_pointer(regs) ((regs)->ip) |
| 170 | #define frame_pointer(regs) ((regs)->bp) |
| 171 | #define stack_pointer(regs) ((regs)->sp) |
| 172 | #define regs_return_value(regs) ((regs)->ax) |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 173 | |
| 174 | extern unsigned long profile_pc(struct pt_regs *regs); |
| 175 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where); |
| 176 | |
| 177 | struct task_struct; |
| 178 | |
| 179 | extern unsigned long |
| 180 | convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs); |
| 181 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 182 | #endif /* __KERNEL__ */ |
| 183 | #endif /* !__i386__ */ |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 184 | |
| 185 | #ifdef __KERNEL__ |
| 186 | |
Roland McGrath | 7f23234 | 2008-01-30 13:30:48 +0100 | [diff] [blame] | 187 | /* |
| 188 | * These are defined as per linux/ptrace.h, which see. |
| 189 | */ |
| 190 | #define arch_has_single_step() (1) |
| 191 | extern void user_enable_single_step(struct task_struct *); |
| 192 | extern void user_disable_single_step(struct task_struct *); |
| 193 | |
Roland McGrath | 10faa81 | 2008-01-30 13:30:54 +0100 | [diff] [blame] | 194 | extern void user_enable_block_step(struct task_struct *); |
| 195 | #ifdef CONFIG_X86_DEBUGCTLMSR |
| 196 | #define arch_has_block_step() (1) |
| 197 | #else |
| 198 | #define arch_has_block_step() (boot_cpu_data.x86 >= 6) |
| 199 | #endif |
| 200 | |
Roland McGrath | efd1ca5 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 201 | struct user_desc; |
| 202 | extern int do_get_thread_area(struct task_struct *p, int idx, |
| 203 | struct user_desc __user *info); |
| 204 | extern int do_set_thread_area(struct task_struct *p, int idx, |
| 205 | struct user_desc __user *info, int can_allocate); |
| 206 | |
| 207 | #endif /* __KERNEL__ */ |
| 208 | |
Thomas Gleixner | 8fc37f2 | 2007-10-23 22:37:24 +0200 | [diff] [blame] | 209 | #endif /* !__ASSEMBLY__ */ |
| 210 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 211 | #endif |