Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 2 | * Ptrace user space interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999,2010 |
| 5 | * Author(s): Denis Joseph Barrow |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/mm.h> |
| 12 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | #include <linux/ptrace.h> |
| 15 | #include <linux/user.h> |
| 16 | #include <linux/security.h> |
| 17 | #include <linux/audit.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 18 | #include <linux/signal.h> |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 19 | #include <linux/elf.h> |
| 20 | #include <linux/regset.h> |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 21 | #include <linux/tracehook.h> |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 22 | #include <linux/seccomp.h> |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 23 | #include <trace/syscall.h> |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 24 | #include <asm/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/segment.h> |
| 26 | #include <asm/page.h> |
| 27 | #include <asm/pgtable.h> |
| 28 | #include <asm/pgalloc.h> |
| 29 | #include <asm/system.h> |
| 30 | #include <asm/uaccess.h> |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 31 | #include <asm/unistd.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 32 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 34 | #ifdef CONFIG_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "compat_ptrace.h" |
| 36 | #endif |
| 37 | |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 38 | #define CREATE_TRACE_POINTS |
| 39 | #include <trace/events/syscalls.h> |
Ingo Molnar | 5e9ad7d | 2009-08-18 10:41:57 +0200 | [diff] [blame] | 40 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 41 | enum s390_regset { |
| 42 | REGSET_GENERAL, |
| 43 | REGSET_FP, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 44 | REGSET_LAST_BREAK, |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 45 | REGSET_SYSTEM_CALL, |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 46 | REGSET_GENERAL_EXTENDED, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 49 | void update_per_regs(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 51 | struct pt_regs *regs = task_pt_regs(task); |
| 52 | struct thread_struct *thread = &task->thread; |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 53 | struct per_regs old, new; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 55 | /* Copy user specified PER registers */ |
| 56 | new.control = thread->per_user.control; |
| 57 | new.start = thread->per_user.start; |
| 58 | new.end = thread->per_user.end; |
| 59 | |
| 60 | /* merge TIF_SINGLE_STEP into user specified PER registers. */ |
| 61 | if (test_tsk_thread_flag(task, TIF_SINGLE_STEP)) { |
| 62 | new.control |= PER_EVENT_IFETCH; |
| 63 | new.start = 0; |
| 64 | new.end = PSW_ADDR_INSN; |
| 65 | } |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 66 | |
| 67 | /* Take care of the PER enablement bit in the PSW. */ |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 68 | if (!(new.control & PER_EVENT_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | regs->psw.mask &= ~PSW_MASK_PER; |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 70 | return; |
Martin Schwidefsky | c3311c1 | 2010-01-13 20:44:25 +0100 | [diff] [blame] | 71 | } |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 72 | regs->psw.mask |= PSW_MASK_PER; |
| 73 | __ctl_store(old, 9, 11); |
Martin Schwidefsky | a45aff5 | 2011-10-30 15:16:07 +0100 | [diff] [blame] | 74 | if (memcmp(&new, &old, sizeof(struct per_regs)) != 0) |
| 75 | __ctl_load(new, 9, 11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 78 | void user_enable_single_step(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 80 | set_tsk_thread_flag(task, TIF_SINGLE_STEP); |
| 81 | if (task == current) |
| 82 | update_per_regs(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 85 | void user_disable_single_step(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 87 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); |
| 88 | if (task == current) |
| 89 | update_per_regs(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Called by kernel/ptrace.c when detaching.. |
| 94 | * |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 95 | * Clear all debugging related fields. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 97 | void ptrace_disable(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 99 | memset(&task->thread.per_user, 0, sizeof(task->thread.per_user)); |
| 100 | memset(&task->thread.per_event, 0, sizeof(task->thread.per_event)); |
| 101 | clear_tsk_thread_flag(task, TIF_SINGLE_STEP); |
| 102 | clear_tsk_thread_flag(task, TIF_PER_TRAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 105 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | # define __ADDR_MASK 3 |
| 107 | #else |
| 108 | # define __ADDR_MASK 7 |
| 109 | #endif |
| 110 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 111 | static inline unsigned long __peek_user_per(struct task_struct *child, |
| 112 | addr_t addr) |
| 113 | { |
| 114 | struct per_struct_kernel *dummy = NULL; |
| 115 | |
| 116 | if (addr == (addr_t) &dummy->cr9) |
| 117 | /* Control bits of the active per set. */ |
| 118 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 119 | PER_EVENT_IFETCH : child->thread.per_user.control; |
| 120 | else if (addr == (addr_t) &dummy->cr10) |
| 121 | /* Start address of the active per set. */ |
| 122 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 123 | 0 : child->thread.per_user.start; |
| 124 | else if (addr == (addr_t) &dummy->cr11) |
| 125 | /* End address of the active per set. */ |
| 126 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 127 | PSW_ADDR_INSN : child->thread.per_user.end; |
| 128 | else if (addr == (addr_t) &dummy->bits) |
| 129 | /* Single-step bit. */ |
| 130 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 131 | (1UL << (BITS_PER_LONG - 1)) : 0; |
| 132 | else if (addr == (addr_t) &dummy->starting_addr) |
| 133 | /* Start address of the user specified per set. */ |
| 134 | return child->thread.per_user.start; |
| 135 | else if (addr == (addr_t) &dummy->ending_addr) |
| 136 | /* End address of the user specified per set. */ |
| 137 | return child->thread.per_user.end; |
| 138 | else if (addr == (addr_t) &dummy->perc_atmid) |
| 139 | /* PER code, ATMID and AI of the last PER trap */ |
| 140 | return (unsigned long) |
| 141 | child->thread.per_event.cause << (BITS_PER_LONG - 16); |
| 142 | else if (addr == (addr_t) &dummy->address) |
| 143 | /* Address of the last PER trap */ |
| 144 | return child->thread.per_event.address; |
| 145 | else if (addr == (addr_t) &dummy->access_id) |
| 146 | /* Access id of the last PER trap */ |
| 147 | return (unsigned long) |
| 148 | child->thread.per_event.paid << (BITS_PER_LONG - 8); |
| 149 | return 0; |
| 150 | } |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* |
| 153 | * Read the word at offset addr from the user area of a process. The |
| 154 | * trouble here is that the information is littered over different |
| 155 | * locations. The process registers are found on the kernel stack, |
| 156 | * the floating point stuff and the trace settings are stored in |
| 157 | * the task structure. In addition the different structures in |
| 158 | * struct user contain pad bytes that should be read as zeroes. |
| 159 | * Lovely... |
| 160 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 161 | static unsigned long __peek_user(struct task_struct *child, addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
| 163 | struct user *dummy = NULL; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 164 | addr_t offset, tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | if (addr < (addr_t) &dummy->regs.acrs) { |
| 167 | /* |
| 168 | * psw and gprs are stored on the stack |
| 169 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 170 | tmp = *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | if (addr == (addr_t) &dummy->regs.psw.mask) |
| 172 | /* Remove per bit from user psw. */ |
| 173 | tmp &= ~PSW_MASK_PER; |
| 174 | |
| 175 | } else if (addr < (addr_t) &dummy->regs.orig_gpr2) { |
| 176 | /* |
| 177 | * access registers are stored in the thread structure |
| 178 | */ |
| 179 | offset = addr - (addr_t) &dummy->regs.acrs; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 180 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Very special case: old & broken 64 bit gdb reading |
| 183 | * from acrs[15]. Result is a 64 bit value. Read the |
| 184 | * 32 bit acrs[15] value and shift it by 32. Sick... |
| 185 | */ |
| 186 | if (addr == (addr_t) &dummy->regs.acrs[15]) |
| 187 | tmp = ((unsigned long) child->thread.acrs[15]) << 32; |
| 188 | else |
| 189 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | tmp = *(addr_t *)((addr_t) &child->thread.acrs + offset); |
| 191 | |
| 192 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { |
| 193 | /* |
| 194 | * orig_gpr2 is stored on the kernel stack |
| 195 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 196 | tmp = (addr_t) task_pt_regs(child)->orig_gpr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 198 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
| 199 | /* |
| 200 | * prevent reads of padding hole between |
| 201 | * orig_gpr2 and fp_regs on s390. |
| 202 | */ |
| 203 | tmp = 0; |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
| 206 | /* |
| 207 | * floating point regs. are stored in the thread structure |
| 208 | */ |
| 209 | offset = addr - (addr_t) &dummy->regs.fp_regs; |
| 210 | tmp = *(addr_t *)((addr_t) &child->thread.fp_regs + offset); |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 211 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc) |
| 212 | tmp &= (unsigned long) FPC_VALID_MASK |
| 213 | << (BITS_PER_LONG - 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { |
| 216 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 217 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 219 | addr -= (addr_t) &dummy->regs.per_info; |
| 220 | tmp = __peek_user_per(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | } else |
| 223 | tmp = 0; |
| 224 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 225 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | static int |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 229 | peek_user(struct task_struct *child, addr_t addr, addr_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 231 | addr_t tmp, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * Stupid gdb peeks/pokes the access registers in 64 bit with |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 235 | * an alignment of 4. Programmers from hell... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | */ |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 237 | mask = __ADDR_MASK; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 238 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 547e3ce | 2008-12-25 13:39:00 +0100 | [diff] [blame] | 239 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
| 240 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 241 | mask = 3; |
| 242 | #endif |
| 243 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return -EIO; |
| 245 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 246 | tmp = __peek_user(child, addr); |
| 247 | return put_user(tmp, (addr_t __user *) data); |
| 248 | } |
| 249 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 250 | static inline void __poke_user_per(struct task_struct *child, |
| 251 | addr_t addr, addr_t data) |
| 252 | { |
| 253 | struct per_struct_kernel *dummy = NULL; |
| 254 | |
| 255 | /* |
| 256 | * There are only three fields in the per_info struct that the |
| 257 | * debugger user can write to. |
| 258 | * 1) cr9: the debugger wants to set a new PER event mask |
| 259 | * 2) starting_addr: the debugger wants to set a new starting |
| 260 | * address to use with the PER event mask. |
| 261 | * 3) ending_addr: the debugger wants to set a new ending |
| 262 | * address to use with the PER event mask. |
| 263 | * The user specified PER event mask and the start and end |
| 264 | * addresses are used only if single stepping is not in effect. |
| 265 | * Writes to any other field in per_info are ignored. |
| 266 | */ |
| 267 | if (addr == (addr_t) &dummy->cr9) |
| 268 | /* PER event mask of the user specified per set. */ |
| 269 | child->thread.per_user.control = |
| 270 | data & (PER_EVENT_MASK | PER_CONTROL_MASK); |
| 271 | else if (addr == (addr_t) &dummy->starting_addr) |
| 272 | /* Starting address of the user specified per set. */ |
| 273 | child->thread.per_user.start = data; |
| 274 | else if (addr == (addr_t) &dummy->ending_addr) |
| 275 | /* Ending address of the user specified per set. */ |
| 276 | child->thread.per_user.end = data; |
| 277 | } |
| 278 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 279 | /* |
| 280 | * Write a word to the user area of a process at location addr. This |
| 281 | * operation does have an additional problem compared to peek_user. |
| 282 | * Stores to the program status word and on the floating point |
| 283 | * control register needs to get checked for validity. |
| 284 | */ |
| 285 | static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) |
| 286 | { |
| 287 | struct user *dummy = NULL; |
| 288 | addr_t offset; |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (addr < (addr_t) &dummy->regs.acrs) { |
| 291 | /* |
| 292 | * psw and gprs are stored on the stack |
| 293 | */ |
| 294 | if (addr == (addr_t) &dummy->regs.psw.mask && |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 295 | #ifdef CONFIG_COMPAT |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 296 | data != PSW_MASK_MERGE(psw_user32_bits, data) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | #endif |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 298 | data != PSW_MASK_MERGE(psw_user_bits, data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* Invalid psw mask. */ |
| 300 | return -EINVAL; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 301 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (addr == (addr_t) &dummy->regs.psw.addr) |
| 303 | /* I'd like to reject addresses without the |
| 304 | high order bit but older gdb's rely on it */ |
| 305 | data |= PSW_ADDR_AMODE; |
| 306 | #endif |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 307 | if (addr == (addr_t) &dummy->regs.psw.addr) |
| 308 | /* |
| 309 | * The debugger changed the instruction address, |
| 310 | * reset system call restart, see signal.c:do_signal |
| 311 | */ |
| 312 | task_thread_info(child)->system_call = 0; |
| 313 | |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 314 | *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { |
| 317 | /* |
| 318 | * access registers are stored in the thread structure |
| 319 | */ |
| 320 | offset = addr - (addr_t) &dummy->regs.acrs; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 321 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 322 | /* |
| 323 | * Very special case: old & broken 64 bit gdb writing |
| 324 | * to acrs[15] with a 64 bit value. Ignore the lower |
| 325 | * half of the value and write the upper 32 bit to |
| 326 | * acrs[15]. Sick... |
| 327 | */ |
| 328 | if (addr == (addr_t) &dummy->regs.acrs[15]) |
| 329 | child->thread.acrs[15] = (unsigned int) (data >> 32); |
| 330 | else |
| 331 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | *(addr_t *)((addr_t) &child->thread.acrs + offset) = data; |
| 333 | |
| 334 | } else if (addr == (addr_t) &dummy->regs.orig_gpr2) { |
| 335 | /* |
| 336 | * orig_gpr2 is stored on the kernel stack |
| 337 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 338 | task_pt_regs(child)->orig_gpr2 = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 340 | } else if (addr < (addr_t) &dummy->regs.fp_regs) { |
| 341 | /* |
| 342 | * prevent writes of padding hole between |
| 343 | * orig_gpr2 and fp_regs on s390. |
| 344 | */ |
| 345 | return 0; |
| 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) { |
| 348 | /* |
| 349 | * floating point regs. are stored in the thread structure |
| 350 | */ |
| 351 | if (addr == (addr_t) &dummy->regs.fp_regs.fpc && |
Martin Schwidefsky | 778959d | 2005-06-04 15:43:30 -0700 | [diff] [blame] | 352 | (data & ~((unsigned long) FPC_VALID_MASK |
| 353 | << (BITS_PER_LONG - 32))) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return -EINVAL; |
| 355 | offset = addr - (addr_t) &dummy->regs.fp_regs; |
| 356 | *(addr_t *)((addr_t) &child->thread.fp_regs + offset) = data; |
| 357 | |
| 358 | } else if (addr < (addr_t) (&dummy->regs.per_info + 1)) { |
| 359 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 360 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 362 | addr -= (addr_t) &dummy->regs.per_info; |
| 363 | __poke_user_per(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | } |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 370 | static int poke_user(struct task_struct *child, addr_t addr, addr_t data) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 371 | { |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 372 | addr_t mask; |
| 373 | |
| 374 | /* |
| 375 | * Stupid gdb peeks/pokes the access registers in 64 bit with |
| 376 | * an alignment of 4. Programmers from hell indeed... |
| 377 | */ |
| 378 | mask = __ADDR_MASK; |
| 379 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 547e3ce | 2008-12-25 13:39:00 +0100 | [diff] [blame] | 380 | if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs && |
| 381 | addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 382 | mask = 3; |
| 383 | #endif |
| 384 | if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK) |
| 385 | return -EIO; |
| 386 | |
| 387 | return __poke_user(child, addr, data); |
| 388 | } |
| 389 | |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 390 | long arch_ptrace(struct task_struct *child, long request, |
| 391 | unsigned long addr, unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | ptrace_area parea; |
| 394 | int copied, ret; |
| 395 | |
| 396 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | case PTRACE_PEEKUSR: |
| 398 | /* read the word at location addr in the USER area. */ |
| 399 | return peek_user(child, addr, data); |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | case PTRACE_POKEUSR: |
| 402 | /* write the word at location addr in the USER area */ |
| 403 | return poke_user(child, addr, data); |
| 404 | |
| 405 | case PTRACE_PEEKUSR_AREA: |
| 406 | case PTRACE_POKEUSR_AREA: |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 407 | if (copy_from_user(&parea, (void __force __user *) addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | sizeof(parea))) |
| 409 | return -EFAULT; |
| 410 | addr = parea.kernel_addr; |
| 411 | data = parea.process_addr; |
| 412 | copied = 0; |
| 413 | while (copied < parea.len) { |
| 414 | if (request == PTRACE_PEEKUSR_AREA) |
| 415 | ret = peek_user(child, addr, data); |
| 416 | else { |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 417 | addr_t utmp; |
| 418 | if (get_user(utmp, |
| 419 | (addr_t __force __user *) data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | return -EFAULT; |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 421 | ret = poke_user(child, addr, utmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | if (ret) |
| 424 | return ret; |
| 425 | addr += sizeof(unsigned long); |
| 426 | data += sizeof(unsigned long); |
| 427 | copied += sizeof(unsigned long); |
| 428 | } |
| 429 | return 0; |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 430 | case PTRACE_GET_LAST_BREAK: |
| 431 | put_user(task_thread_info(child)->last_break, |
| 432 | (unsigned long __user *) data); |
| 433 | return 0; |
Christian Borntraeger | 07805ac | 2009-09-22 22:58:48 +0200 | [diff] [blame] | 434 | default: |
| 435 | /* Removing high order bit from addr (only for 31 bit). */ |
| 436 | addr &= PSW_ADDR_INSN; |
| 437 | return ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 441 | #ifdef CONFIG_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | /* |
| 443 | * Now the fun part starts... a 31 bit program running in the |
| 444 | * 31 bit emulation tracing another program. PTRACE_PEEKTEXT, |
| 445 | * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy |
| 446 | * to handle, the difference to the 64 bit versions of the requests |
| 447 | * is that the access is done in multiples of 4 byte instead of |
| 448 | * 8 bytes (sizeof(unsigned long) on 31/64 bit). |
| 449 | * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA, |
| 450 | * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program |
| 451 | * is a 31 bit program too, the content of struct user can be |
| 452 | * emulated. A 31 bit program peeking into the struct user of |
| 453 | * a 64 bit program is a no-no. |
| 454 | */ |
| 455 | |
| 456 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 457 | * Same as peek_user_per but for a 31 bit program. |
| 458 | */ |
| 459 | static inline __u32 __peek_user_per_compat(struct task_struct *child, |
| 460 | addr_t addr) |
| 461 | { |
| 462 | struct compat_per_struct_kernel *dummy32 = NULL; |
| 463 | |
| 464 | if (addr == (addr_t) &dummy32->cr9) |
| 465 | /* Control bits of the active per set. */ |
| 466 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? |
| 467 | PER_EVENT_IFETCH : child->thread.per_user.control; |
| 468 | else if (addr == (addr_t) &dummy32->cr10) |
| 469 | /* Start address of the active per set. */ |
| 470 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? |
| 471 | 0 : child->thread.per_user.start; |
| 472 | else if (addr == (addr_t) &dummy32->cr11) |
| 473 | /* End address of the active per set. */ |
| 474 | return test_thread_flag(TIF_SINGLE_STEP) ? |
| 475 | PSW32_ADDR_INSN : child->thread.per_user.end; |
| 476 | else if (addr == (addr_t) &dummy32->bits) |
| 477 | /* Single-step bit. */ |
| 478 | return (__u32) test_thread_flag(TIF_SINGLE_STEP) ? |
| 479 | 0x80000000 : 0; |
| 480 | else if (addr == (addr_t) &dummy32->starting_addr) |
| 481 | /* Start address of the user specified per set. */ |
| 482 | return (__u32) child->thread.per_user.start; |
| 483 | else if (addr == (addr_t) &dummy32->ending_addr) |
| 484 | /* End address of the user specified per set. */ |
| 485 | return (__u32) child->thread.per_user.end; |
| 486 | else if (addr == (addr_t) &dummy32->perc_atmid) |
| 487 | /* PER code, ATMID and AI of the last PER trap */ |
| 488 | return (__u32) child->thread.per_event.cause << 16; |
| 489 | else if (addr == (addr_t) &dummy32->address) |
| 490 | /* Address of the last PER trap */ |
| 491 | return (__u32) child->thread.per_event.address; |
| 492 | else if (addr == (addr_t) &dummy32->access_id) |
| 493 | /* Access id of the last PER trap */ |
| 494 | return (__u32) child->thread.per_event.paid << 24; |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | * Same as peek_user but for a 31 bit program. |
| 500 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 501 | static u32 __peek_user_compat(struct task_struct *child, addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 503 | struct compat_user *dummy32 = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | addr_t offset; |
| 505 | __u32 tmp; |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | if (addr < (addr_t) &dummy32->regs.acrs) { |
| 508 | /* |
| 509 | * psw and gprs are stored on the stack |
| 510 | */ |
| 511 | if (addr == (addr_t) &dummy32->regs.psw.mask) { |
| 512 | /* Fake a 31 bit psw mask. */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 513 | tmp = (__u32)(task_pt_regs(child)->psw.mask >> 32); |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 514 | tmp = PSW32_MASK_MERGE(psw32_user_bits, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
| 516 | /* Fake a 31 bit psw address. */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 517 | tmp = (__u32) task_pt_regs(child)->psw.addr | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | PSW32_ADDR_AMODE31; |
| 519 | } else { |
| 520 | /* gpr 0-15 */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 521 | tmp = *(__u32 *)((addr_t) &task_pt_regs(child)->psw + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | addr*2 + 4); |
| 523 | } |
| 524 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 525 | /* |
| 526 | * access registers are stored in the thread structure |
| 527 | */ |
| 528 | offset = addr - (addr_t) &dummy32->regs.acrs; |
| 529 | tmp = *(__u32*)((addr_t) &child->thread.acrs + offset); |
| 530 | |
| 531 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 532 | /* |
| 533 | * orig_gpr2 is stored on the kernel stack |
| 534 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 535 | tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 537 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
| 538 | /* |
| 539 | * prevent reads of padding hole between |
| 540 | * orig_gpr2 and fp_regs on s390. |
| 541 | */ |
| 542 | tmp = 0; |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
| 545 | /* |
| 546 | * floating point regs. are stored in the thread structure |
| 547 | */ |
| 548 | offset = addr - (addr_t) &dummy32->regs.fp_regs; |
| 549 | tmp = *(__u32 *)((addr_t) &child->thread.fp_regs + offset); |
| 550 | |
| 551 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { |
| 552 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 553 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 555 | addr -= (addr_t) &dummy32->regs.per_info; |
| 556 | tmp = __peek_user_per_compat(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | } else |
| 559 | tmp = 0; |
| 560 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 561 | return tmp; |
| 562 | } |
| 563 | |
| 564 | static int peek_user_compat(struct task_struct *child, |
| 565 | addr_t addr, addr_t data) |
| 566 | { |
| 567 | __u32 tmp; |
| 568 | |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 569 | if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 570 | return -EIO; |
| 571 | |
| 572 | tmp = __peek_user_compat(child, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return put_user(tmp, (__u32 __user *) data); |
| 574 | } |
| 575 | |
| 576 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 577 | * Same as poke_user_per but for a 31 bit program. |
| 578 | */ |
| 579 | static inline void __poke_user_per_compat(struct task_struct *child, |
| 580 | addr_t addr, __u32 data) |
| 581 | { |
| 582 | struct compat_per_struct_kernel *dummy32 = NULL; |
| 583 | |
| 584 | if (addr == (addr_t) &dummy32->cr9) |
| 585 | /* PER event mask of the user specified per set. */ |
| 586 | child->thread.per_user.control = |
| 587 | data & (PER_EVENT_MASK | PER_CONTROL_MASK); |
| 588 | else if (addr == (addr_t) &dummy32->starting_addr) |
| 589 | /* Starting address of the user specified per set. */ |
| 590 | child->thread.per_user.start = data; |
| 591 | else if (addr == (addr_t) &dummy32->ending_addr) |
| 592 | /* Ending address of the user specified per set. */ |
| 593 | child->thread.per_user.end = data; |
| 594 | } |
| 595 | |
| 596 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | * Same as poke_user but for a 31 bit program. |
| 598 | */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 599 | static int __poke_user_compat(struct task_struct *child, |
| 600 | addr_t addr, addr_t data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 602 | struct compat_user *dummy32 = NULL; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 603 | __u32 tmp = (__u32) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | addr_t offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | if (addr < (addr_t) &dummy32->regs.acrs) { |
| 607 | /* |
| 608 | * psw, gprs, acrs and orig_gpr2 are stored on the stack |
| 609 | */ |
| 610 | if (addr == (addr_t) &dummy32->regs.psw.mask) { |
| 611 | /* Build a 64 bit psw mask from 31 bit mask. */ |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 612 | if (tmp != PSW32_MASK_MERGE(psw32_user_bits, tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* Invalid psw mask. */ |
| 614 | return -EINVAL; |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 615 | task_pt_regs(child)->psw.mask = |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 616 | PSW_MASK_MERGE(psw_user32_bits, (__u64) tmp << 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } else if (addr == (addr_t) &dummy32->regs.psw.addr) { |
| 618 | /* Build a 64 bit psw address from 31 bit address. */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 619 | task_pt_regs(child)->psw.addr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | (__u64) tmp & PSW32_ADDR_INSN; |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 621 | /* |
| 622 | * The debugger changed the instruction address, |
| 623 | * reset system call restart, see signal.c:do_signal |
| 624 | */ |
| 625 | task_thread_info(child)->system_call = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } else { |
| 627 | /* gpr 0-15 */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 628 | *(__u32*)((addr_t) &task_pt_regs(child)->psw |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | + addr*2 + 4) = tmp; |
| 630 | } |
| 631 | } else if (addr < (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 632 | /* |
| 633 | * access registers are stored in the thread structure |
| 634 | */ |
| 635 | offset = addr - (addr_t) &dummy32->regs.acrs; |
| 636 | *(__u32*)((addr_t) &child->thread.acrs + offset) = tmp; |
| 637 | |
| 638 | } else if (addr == (addr_t) (&dummy32->regs.orig_gpr2)) { |
| 639 | /* |
| 640 | * orig_gpr2 is stored on the kernel stack |
| 641 | */ |
Al Viro | c7584fb | 2006-01-12 01:05:49 -0800 | [diff] [blame] | 642 | *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Jarod Wilson | 3d6e48f | 2008-09-09 12:38:56 +0200 | [diff] [blame] | 644 | } else if (addr < (addr_t) &dummy32->regs.fp_regs) { |
| 645 | /* |
| 646 | * prevent writess of padding hole between |
| 647 | * orig_gpr2 and fp_regs on s390. |
| 648 | */ |
| 649 | return 0; |
| 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) { |
| 652 | /* |
| 653 | * floating point regs. are stored in the thread structure |
| 654 | */ |
| 655 | if (addr == (addr_t) &dummy32->regs.fp_regs.fpc && |
| 656 | (tmp & ~FPC_VALID_MASK) != 0) |
| 657 | /* Invalid floating point control. */ |
| 658 | return -EINVAL; |
| 659 | offset = addr - (addr_t) &dummy32->regs.fp_regs; |
| 660 | *(__u32 *)((addr_t) &child->thread.fp_regs + offset) = tmp; |
| 661 | |
| 662 | } else if (addr < (addr_t) (&dummy32->regs.per_info + 1)) { |
| 663 | /* |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 664 | * Handle access to the per_info structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | */ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 666 | addr -= (addr_t) &dummy32->regs.per_info; |
| 667 | __poke_user_per_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return 0; |
| 671 | } |
| 672 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 673 | static int poke_user_compat(struct task_struct *child, |
| 674 | addr_t addr, addr_t data) |
| 675 | { |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 676 | if (!is_compat_task() || (addr & 3) || |
| 677 | addr > sizeof(struct compat_user) - 3) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 678 | return -EIO; |
| 679 | |
| 680 | return __poke_user_compat(child, addr, data); |
| 681 | } |
| 682 | |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 683 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
| 684 | compat_ulong_t caddr, compat_ulong_t cdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 686 | unsigned long addr = caddr; |
| 687 | unsigned long data = cdata; |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 688 | compat_ptrace_area parea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | int copied, ret; |
| 690 | |
| 691 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | case PTRACE_PEEKUSR: |
| 693 | /* read the word at location addr in the USER area. */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 694 | return peek_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | case PTRACE_POKEUSR: |
| 697 | /* write the word at location addr in the USER area */ |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 698 | return poke_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | case PTRACE_PEEKUSR_AREA: |
| 701 | case PTRACE_POKEUSR_AREA: |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 702 | if (copy_from_user(&parea, (void __force __user *) addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | sizeof(parea))) |
| 704 | return -EFAULT; |
| 705 | addr = parea.kernel_addr; |
| 706 | data = parea.process_addr; |
| 707 | copied = 0; |
| 708 | while (copied < parea.len) { |
| 709 | if (request == PTRACE_PEEKUSR_AREA) |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 710 | ret = peek_user_compat(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | else { |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 712 | __u32 utmp; |
| 713 | if (get_user(utmp, |
| 714 | (__u32 __force __user *) data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | return -EFAULT; |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 716 | ret = poke_user_compat(child, addr, utmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | if (ret) |
| 719 | return ret; |
| 720 | addr += sizeof(unsigned int); |
| 721 | data += sizeof(unsigned int); |
| 722 | copied += sizeof(unsigned int); |
| 723 | } |
| 724 | return 0; |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 725 | case PTRACE_GET_LAST_BREAK: |
| 726 | put_user(task_thread_info(child)->last_break, |
| 727 | (unsigned int __user *) data); |
| 728 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
Roland McGrath | b499d76 | 2008-05-07 09:22:57 +0200 | [diff] [blame] | 730 | return compat_ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | #endif |
| 733 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 734 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
Gerald Schaefer | 545c174 | 2010-05-12 09:32:12 +0200 | [diff] [blame] | 736 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
Heiko Carstens | bcf5cef | 2009-06-12 10:26:26 +0200 | [diff] [blame] | 738 | /* Do the secure computing check first. */ |
| 739 | secure_computing(regs->gprs[2]); |
| 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | /* |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 742 | * The sysc_tracesys code in entry.S stored the system |
| 743 | * call number to gprs[2]. |
Bodo Stroesser | c5c3a6d | 2005-06-04 15:43:32 -0700 | [diff] [blame] | 744 | */ |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 745 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
| 746 | (tracehook_report_syscall_entry(regs) || |
| 747 | regs->gprs[2] >= NR_syscalls)) { |
| 748 | /* |
| 749 | * Tracing decided this syscall should not happen or the |
| 750 | * debugger stored an invalid system call number. Skip |
| 751 | * the system call and the system call restart handling. |
| 752 | */ |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame^] | 753 | clear_thread_flag(TIF_SYSCALL); |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 754 | ret = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 756 | |
Josh Stone | 6670000 | 2009-08-24 14:43:11 -0700 | [diff] [blame] | 757 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 758 | trace_sys_enter(regs, regs->gprs[2]); |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 759 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 760 | if (unlikely(current->audit_context)) |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 761 | audit_syscall_entry(is_compat_task() ? |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 762 | AUDIT_ARCH_S390 : AUDIT_ARCH_S390X, |
| 763 | regs->gprs[2], regs->orig_gpr2, |
| 764 | regs->gprs[3], regs->gprs[4], |
| 765 | regs->gprs[5]); |
Gerald Schaefer | 545c174 | 2010-05-12 09:32:12 +0200 | [diff] [blame] | 766 | return ret ?: regs->gprs[2]; |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) |
| 770 | { |
| 771 | if (unlikely(current->audit_context)) |
| 772 | audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), |
| 773 | regs->gprs[2]); |
| 774 | |
Josh Stone | 6670000 | 2009-08-24 14:43:11 -0700 | [diff] [blame] | 775 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 776 | trace_sys_exit(regs, regs->gprs[2]); |
Heiko Carstens | 9bf1226 | 2009-06-12 10:26:47 +0200 | [diff] [blame] | 777 | |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 778 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
| 779 | tracehook_report_syscall_exit(regs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 781 | |
| 782 | /* |
| 783 | * user_regset definitions. |
| 784 | */ |
| 785 | |
| 786 | static int s390_regs_get(struct task_struct *target, |
| 787 | const struct user_regset *regset, |
| 788 | unsigned int pos, unsigned int count, |
| 789 | void *kbuf, void __user *ubuf) |
| 790 | { |
| 791 | if (target == current) |
| 792 | save_access_regs(target->thread.acrs); |
| 793 | |
| 794 | if (kbuf) { |
| 795 | unsigned long *k = kbuf; |
| 796 | while (count > 0) { |
| 797 | *k++ = __peek_user(target, pos); |
| 798 | count -= sizeof(*k); |
| 799 | pos += sizeof(*k); |
| 800 | } |
| 801 | } else { |
| 802 | unsigned long __user *u = ubuf; |
| 803 | while (count > 0) { |
| 804 | if (__put_user(__peek_user(target, pos), u++)) |
| 805 | return -EFAULT; |
| 806 | count -= sizeof(*u); |
| 807 | pos += sizeof(*u); |
| 808 | } |
| 809 | } |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static int s390_regs_set(struct task_struct *target, |
| 814 | const struct user_regset *regset, |
| 815 | unsigned int pos, unsigned int count, |
| 816 | const void *kbuf, const void __user *ubuf) |
| 817 | { |
| 818 | int rc = 0; |
| 819 | |
| 820 | if (target == current) |
| 821 | save_access_regs(target->thread.acrs); |
| 822 | |
| 823 | if (kbuf) { |
| 824 | const unsigned long *k = kbuf; |
| 825 | while (count > 0 && !rc) { |
| 826 | rc = __poke_user(target, pos, *k++); |
| 827 | count -= sizeof(*k); |
| 828 | pos += sizeof(*k); |
| 829 | } |
| 830 | } else { |
| 831 | const unsigned long __user *u = ubuf; |
| 832 | while (count > 0 && !rc) { |
| 833 | unsigned long word; |
| 834 | rc = __get_user(word, u++); |
| 835 | if (rc) |
| 836 | break; |
| 837 | rc = __poke_user(target, pos, word); |
| 838 | count -= sizeof(*u); |
| 839 | pos += sizeof(*u); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | if (rc == 0 && target == current) |
| 844 | restore_access_regs(target->thread.acrs); |
| 845 | |
| 846 | return rc; |
| 847 | } |
| 848 | |
| 849 | static int s390_fpregs_get(struct task_struct *target, |
| 850 | const struct user_regset *regset, unsigned int pos, |
| 851 | unsigned int count, void *kbuf, void __user *ubuf) |
| 852 | { |
| 853 | if (target == current) |
| 854 | save_fp_regs(&target->thread.fp_regs); |
| 855 | |
| 856 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 857 | &target->thread.fp_regs, 0, -1); |
| 858 | } |
| 859 | |
| 860 | static int s390_fpregs_set(struct task_struct *target, |
| 861 | const struct user_regset *regset, unsigned int pos, |
| 862 | unsigned int count, const void *kbuf, |
| 863 | const void __user *ubuf) |
| 864 | { |
| 865 | int rc = 0; |
| 866 | |
| 867 | if (target == current) |
| 868 | save_fp_regs(&target->thread.fp_regs); |
| 869 | |
| 870 | /* If setting FPC, must validate it first. */ |
| 871 | if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) { |
| 872 | u32 fpc[2] = { target->thread.fp_regs.fpc, 0 }; |
| 873 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc, |
| 874 | 0, offsetof(s390_fp_regs, fprs)); |
| 875 | if (rc) |
| 876 | return rc; |
| 877 | if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0) |
| 878 | return -EINVAL; |
| 879 | target->thread.fp_regs.fpc = fpc[0]; |
| 880 | } |
| 881 | |
| 882 | if (rc == 0 && count > 0) |
| 883 | rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 884 | target->thread.fp_regs.fprs, |
| 885 | offsetof(s390_fp_regs, fprs), -1); |
| 886 | |
| 887 | if (rc == 0 && target == current) |
| 888 | restore_fp_regs(&target->thread.fp_regs); |
| 889 | |
| 890 | return rc; |
| 891 | } |
| 892 | |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 893 | #ifdef CONFIG_64BIT |
| 894 | |
| 895 | static int s390_last_break_get(struct task_struct *target, |
| 896 | const struct user_regset *regset, |
| 897 | unsigned int pos, unsigned int count, |
| 898 | void *kbuf, void __user *ubuf) |
| 899 | { |
| 900 | if (count > 0) { |
| 901 | if (kbuf) { |
| 902 | unsigned long *k = kbuf; |
| 903 | *k = task_thread_info(target)->last_break; |
| 904 | } else { |
| 905 | unsigned long __user *u = ubuf; |
| 906 | if (__put_user(task_thread_info(target)->last_break, u)) |
| 907 | return -EFAULT; |
| 908 | } |
| 909 | } |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | #endif |
| 914 | |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 915 | static int s390_system_call_get(struct task_struct *target, |
| 916 | const struct user_regset *regset, |
| 917 | unsigned int pos, unsigned int count, |
| 918 | void *kbuf, void __user *ubuf) |
| 919 | { |
| 920 | unsigned int *data = &task_thread_info(target)->system_call; |
| 921 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 922 | data, 0, sizeof(unsigned int)); |
| 923 | } |
| 924 | |
| 925 | static int s390_system_call_set(struct task_struct *target, |
| 926 | const struct user_regset *regset, |
| 927 | unsigned int pos, unsigned int count, |
| 928 | const void *kbuf, const void __user *ubuf) |
| 929 | { |
| 930 | unsigned int *data = &task_thread_info(target)->system_call; |
| 931 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 932 | data, 0, sizeof(unsigned int)); |
| 933 | } |
| 934 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 935 | static const struct user_regset s390_regsets[] = { |
| 936 | [REGSET_GENERAL] = { |
| 937 | .core_note_type = NT_PRSTATUS, |
| 938 | .n = sizeof(s390_regs) / sizeof(long), |
| 939 | .size = sizeof(long), |
| 940 | .align = sizeof(long), |
| 941 | .get = s390_regs_get, |
| 942 | .set = s390_regs_set, |
| 943 | }, |
| 944 | [REGSET_FP] = { |
| 945 | .core_note_type = NT_PRFPREG, |
| 946 | .n = sizeof(s390_fp_regs) / sizeof(long), |
| 947 | .size = sizeof(long), |
| 948 | .align = sizeof(long), |
| 949 | .get = s390_fpregs_get, |
| 950 | .set = s390_fpregs_set, |
| 951 | }, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 952 | #ifdef CONFIG_64BIT |
| 953 | [REGSET_LAST_BREAK] = { |
| 954 | .core_note_type = NT_S390_LAST_BREAK, |
| 955 | .n = 1, |
| 956 | .size = sizeof(long), |
| 957 | .align = sizeof(long), |
| 958 | .get = s390_last_break_get, |
| 959 | }, |
| 960 | #endif |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 961 | [REGSET_SYSTEM_CALL] = { |
| 962 | .core_note_type = NT_S390_SYSTEM_CALL, |
| 963 | .n = 1, |
| 964 | .size = sizeof(unsigned int), |
| 965 | .align = sizeof(unsigned int), |
| 966 | .get = s390_system_call_get, |
| 967 | .set = s390_system_call_set, |
| 968 | }, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 969 | }; |
| 970 | |
| 971 | static const struct user_regset_view user_s390_view = { |
| 972 | .name = UTS_MACHINE, |
| 973 | .e_machine = EM_S390, |
| 974 | .regsets = s390_regsets, |
| 975 | .n = ARRAY_SIZE(s390_regsets) |
| 976 | }; |
| 977 | |
| 978 | #ifdef CONFIG_COMPAT |
| 979 | static int s390_compat_regs_get(struct task_struct *target, |
| 980 | const struct user_regset *regset, |
| 981 | unsigned int pos, unsigned int count, |
| 982 | void *kbuf, void __user *ubuf) |
| 983 | { |
| 984 | if (target == current) |
| 985 | save_access_regs(target->thread.acrs); |
| 986 | |
| 987 | if (kbuf) { |
| 988 | compat_ulong_t *k = kbuf; |
| 989 | while (count > 0) { |
| 990 | *k++ = __peek_user_compat(target, pos); |
| 991 | count -= sizeof(*k); |
| 992 | pos += sizeof(*k); |
| 993 | } |
| 994 | } else { |
| 995 | compat_ulong_t __user *u = ubuf; |
| 996 | while (count > 0) { |
| 997 | if (__put_user(__peek_user_compat(target, pos), u++)) |
| 998 | return -EFAULT; |
| 999 | count -= sizeof(*u); |
| 1000 | pos += sizeof(*u); |
| 1001 | } |
| 1002 | } |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | static int s390_compat_regs_set(struct task_struct *target, |
| 1007 | const struct user_regset *regset, |
| 1008 | unsigned int pos, unsigned int count, |
| 1009 | const void *kbuf, const void __user *ubuf) |
| 1010 | { |
| 1011 | int rc = 0; |
| 1012 | |
| 1013 | if (target == current) |
| 1014 | save_access_regs(target->thread.acrs); |
| 1015 | |
| 1016 | if (kbuf) { |
| 1017 | const compat_ulong_t *k = kbuf; |
| 1018 | while (count > 0 && !rc) { |
| 1019 | rc = __poke_user_compat(target, pos, *k++); |
| 1020 | count -= sizeof(*k); |
| 1021 | pos += sizeof(*k); |
| 1022 | } |
| 1023 | } else { |
| 1024 | const compat_ulong_t __user *u = ubuf; |
| 1025 | while (count > 0 && !rc) { |
| 1026 | compat_ulong_t word; |
| 1027 | rc = __get_user(word, u++); |
| 1028 | if (rc) |
| 1029 | break; |
| 1030 | rc = __poke_user_compat(target, pos, word); |
| 1031 | count -= sizeof(*u); |
| 1032 | pos += sizeof(*u); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | if (rc == 0 && target == current) |
| 1037 | restore_access_regs(target->thread.acrs); |
| 1038 | |
| 1039 | return rc; |
| 1040 | } |
| 1041 | |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 1042 | static int s390_compat_regs_high_get(struct task_struct *target, |
| 1043 | const struct user_regset *regset, |
| 1044 | unsigned int pos, unsigned int count, |
| 1045 | void *kbuf, void __user *ubuf) |
| 1046 | { |
| 1047 | compat_ulong_t *gprs_high; |
| 1048 | |
| 1049 | gprs_high = (compat_ulong_t *) |
| 1050 | &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)]; |
| 1051 | if (kbuf) { |
| 1052 | compat_ulong_t *k = kbuf; |
| 1053 | while (count > 0) { |
| 1054 | *k++ = *gprs_high; |
| 1055 | gprs_high += 2; |
| 1056 | count -= sizeof(*k); |
| 1057 | } |
| 1058 | } else { |
| 1059 | compat_ulong_t __user *u = ubuf; |
| 1060 | while (count > 0) { |
| 1061 | if (__put_user(*gprs_high, u++)) |
| 1062 | return -EFAULT; |
| 1063 | gprs_high += 2; |
| 1064 | count -= sizeof(*u); |
| 1065 | } |
| 1066 | } |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | static int s390_compat_regs_high_set(struct task_struct *target, |
| 1071 | const struct user_regset *regset, |
| 1072 | unsigned int pos, unsigned int count, |
| 1073 | const void *kbuf, const void __user *ubuf) |
| 1074 | { |
| 1075 | compat_ulong_t *gprs_high; |
| 1076 | int rc = 0; |
| 1077 | |
| 1078 | gprs_high = (compat_ulong_t *) |
| 1079 | &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)]; |
| 1080 | if (kbuf) { |
| 1081 | const compat_ulong_t *k = kbuf; |
| 1082 | while (count > 0) { |
| 1083 | *gprs_high = *k++; |
| 1084 | *gprs_high += 2; |
| 1085 | count -= sizeof(*k); |
| 1086 | } |
| 1087 | } else { |
| 1088 | const compat_ulong_t __user *u = ubuf; |
| 1089 | while (count > 0 && !rc) { |
| 1090 | unsigned long word; |
| 1091 | rc = __get_user(word, u++); |
| 1092 | if (rc) |
| 1093 | break; |
| 1094 | *gprs_high = word; |
| 1095 | *gprs_high += 2; |
| 1096 | count -= sizeof(*u); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | return rc; |
| 1101 | } |
| 1102 | |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1103 | static int s390_compat_last_break_get(struct task_struct *target, |
| 1104 | const struct user_regset *regset, |
| 1105 | unsigned int pos, unsigned int count, |
| 1106 | void *kbuf, void __user *ubuf) |
| 1107 | { |
| 1108 | compat_ulong_t last_break; |
| 1109 | |
| 1110 | if (count > 0) { |
| 1111 | last_break = task_thread_info(target)->last_break; |
| 1112 | if (kbuf) { |
| 1113 | unsigned long *k = kbuf; |
| 1114 | *k = last_break; |
| 1115 | } else { |
| 1116 | unsigned long __user *u = ubuf; |
| 1117 | if (__put_user(last_break, u)) |
| 1118 | return -EFAULT; |
| 1119 | } |
| 1120 | } |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 1124 | static const struct user_regset s390_compat_regsets[] = { |
| 1125 | [REGSET_GENERAL] = { |
| 1126 | .core_note_type = NT_PRSTATUS, |
| 1127 | .n = sizeof(s390_compat_regs) / sizeof(compat_long_t), |
| 1128 | .size = sizeof(compat_long_t), |
| 1129 | .align = sizeof(compat_long_t), |
| 1130 | .get = s390_compat_regs_get, |
| 1131 | .set = s390_compat_regs_set, |
| 1132 | }, |
| 1133 | [REGSET_FP] = { |
| 1134 | .core_note_type = NT_PRFPREG, |
| 1135 | .n = sizeof(s390_fp_regs) / sizeof(compat_long_t), |
| 1136 | .size = sizeof(compat_long_t), |
| 1137 | .align = sizeof(compat_long_t), |
| 1138 | .get = s390_fpregs_get, |
| 1139 | .set = s390_fpregs_set, |
| 1140 | }, |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 1141 | [REGSET_LAST_BREAK] = { |
| 1142 | .core_note_type = NT_S390_LAST_BREAK, |
| 1143 | .n = 1, |
| 1144 | .size = sizeof(long), |
| 1145 | .align = sizeof(long), |
| 1146 | .get = s390_compat_last_break_get, |
| 1147 | }, |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 1148 | [REGSET_SYSTEM_CALL] = { |
| 1149 | .core_note_type = NT_S390_SYSTEM_CALL, |
| 1150 | .n = 1, |
| 1151 | .size = sizeof(compat_uint_t), |
| 1152 | .align = sizeof(compat_uint_t), |
| 1153 | .get = s390_system_call_get, |
| 1154 | .set = s390_system_call_set, |
| 1155 | }, |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 1156 | [REGSET_GENERAL_EXTENDED] = { |
Martin Schwidefsky | 622e99b | 2009-12-18 17:43:20 +0100 | [diff] [blame] | 1157 | .core_note_type = NT_S390_HIGH_GPRS, |
Heiko Carstens | ea2a4d3 | 2009-10-06 10:34:13 +0200 | [diff] [blame] | 1158 | .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t), |
| 1159 | .size = sizeof(compat_long_t), |
| 1160 | .align = sizeof(compat_long_t), |
| 1161 | .get = s390_compat_regs_high_get, |
| 1162 | .set = s390_compat_regs_high_set, |
| 1163 | }, |
Martin Schwidefsky | 63506c4 | 2008-07-14 09:58:54 +0200 | [diff] [blame] | 1164 | }; |
| 1165 | |
| 1166 | static const struct user_regset_view user_s390_compat_view = { |
| 1167 | .name = "s390", |
| 1168 | .e_machine = EM_S390, |
| 1169 | .regsets = s390_compat_regsets, |
| 1170 | .n = ARRAY_SIZE(s390_compat_regsets) |
| 1171 | }; |
| 1172 | #endif |
| 1173 | |
| 1174 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
| 1175 | { |
| 1176 | #ifdef CONFIG_COMPAT |
| 1177 | if (test_tsk_thread_flag(task, TIF_31BIT)) |
| 1178 | return &user_s390_compat_view; |
| 1179 | #endif |
| 1180 | return &user_s390_view; |
| 1181 | } |
Heiko Carstens | 952974ac6 | 2010-02-12 13:38:40 +0100 | [diff] [blame] | 1182 | |
| 1183 | static const char *gpr_names[NUM_GPRS] = { |
| 1184 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1185 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 1186 | }; |
| 1187 | |
| 1188 | unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset) |
| 1189 | { |
| 1190 | if (offset >= NUM_GPRS) |
| 1191 | return 0; |
| 1192 | return regs->gprs[offset]; |
| 1193 | } |
| 1194 | |
| 1195 | int regs_query_register_offset(const char *name) |
| 1196 | { |
| 1197 | unsigned long offset; |
| 1198 | |
| 1199 | if (!name || *name != 'r') |
| 1200 | return -EINVAL; |
| 1201 | if (strict_strtoul(name + 1, 10, &offset)) |
| 1202 | return -EINVAL; |
| 1203 | if (offset >= NUM_GPRS) |
| 1204 | return -EINVAL; |
| 1205 | return offset; |
| 1206 | } |
| 1207 | |
| 1208 | const char *regs_query_register_name(unsigned int offset) |
| 1209 | { |
| 1210 | if (offset >= NUM_GPRS) |
| 1211 | return NULL; |
| 1212 | return gpr_names[offset]; |
| 1213 | } |
| 1214 | |
| 1215 | static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) |
| 1216 | { |
| 1217 | unsigned long ksp = kernel_stack_pointer(regs); |
| 1218 | |
| 1219 | return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1)); |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * regs_get_kernel_stack_nth() - get Nth entry of the stack |
| 1224 | * @regs:pt_regs which contains kernel stack pointer. |
| 1225 | * @n:stack entry number. |
| 1226 | * |
| 1227 | * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which |
| 1228 | * is specifined by @regs. If the @n th entry is NOT in the kernel stack, |
| 1229 | * this returns 0. |
| 1230 | */ |
| 1231 | unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n) |
| 1232 | { |
| 1233 | unsigned long addr; |
| 1234 | |
| 1235 | addr = kernel_stack_pointer(regs) + n * sizeof(long); |
| 1236 | if (!regs_within_kernel_stack(regs, addr)) |
| 1237 | return 0; |
| 1238 | return *(unsigned long *)addr; |
| 1239 | } |