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