Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * PowerPC version |
| 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 4 | * |
| 5 | * Derived from "arch/m68k/kernel/ptrace.c" |
| 6 | * Copyright (C) 1994 by Hamish Macdonald |
| 7 | * Taken from linux/kernel/ptrace.c and modified for M680x0. |
| 8 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds |
| 9 | * |
| 10 | * Modified by Cort Dougan (cort@hq.fsmlabs.com) |
Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 11 | * and Paul Mackerras (paulus@samba.org). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
| 13 | * This file is subject to the terms and conditions of the GNU General |
| 14 | * Public License. See the file README.legal in the main directory of |
| 15 | * this archive for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/errno.h> |
| 23 | #include <linux/ptrace.h> |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 24 | #include <linux/regset.h> |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame^] | 25 | #include <linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/user.h> |
| 27 | #include <linux/security.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 28 | #include <linux/signal.h> |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 29 | #include <linux/seccomp.h> |
| 30 | #include <linux/audit.h> |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 31 | #ifdef CONFIG_PPC32 |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 32 | #include <linux/module.h> |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 33 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include <asm/uaccess.h> |
| 36 | #include <asm/page.h> |
| 37 | #include <asm/pgtable.h> |
| 38 | #include <asm/system.h> |
Paul Mackerras | 21a6290 | 2005-11-19 20:47:22 +1100 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* |
| 41 | * does not yet catch signals sent when the child dies. |
| 42 | * in exit.c or in signal.c. |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 46 | * Set of msr bits that gdb can change on behalf of a process. |
| 47 | */ |
| 48 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) |
| 49 | #define MSR_DEBUGCHANGE 0 |
| 50 | #else |
| 51 | #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE) |
| 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | * Max register writeable via put_reg |
| 56 | */ |
| 57 | #ifdef CONFIG_PPC32 |
| 58 | #define PT_MAX_PUT_REG PT_MQ |
| 59 | #else |
| 60 | #define PT_MAX_PUT_REG PT_CCR |
| 61 | #endif |
| 62 | |
| 63 | /* |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 64 | * Get contents of register REGNO in task TASK. |
| 65 | */ |
| 66 | unsigned long ptrace_get_reg(struct task_struct *task, int regno) |
| 67 | { |
| 68 | unsigned long tmp = 0; |
| 69 | |
| 70 | if (task->thread.regs == NULL) |
| 71 | return -EIO; |
| 72 | |
| 73 | if (regno == PT_MSR) { |
| 74 | tmp = ((unsigned long *)task->thread.regs)[PT_MSR]; |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 75 | return tmp | task->thread.fpexc_mode; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) |
| 79 | return ((unsigned long *)task->thread.regs)[regno]; |
| 80 | |
| 81 | return -EIO; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Write contents of register REGNO in task TASK. |
| 86 | */ |
| 87 | int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) |
| 88 | { |
| 89 | if (task->thread.regs == NULL) |
| 90 | return -EIO; |
| 91 | |
Benjamin Herrenschmidt | 912000e | 2007-06-04 15:15:46 +1000 | [diff] [blame] | 92 | if (regno <= PT_MAX_PUT_REG || regno == PT_TRAP) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 93 | if (regno == PT_MSR) |
| 94 | data = (data & MSR_DEBUGCHANGE) |
| 95 | | (task->thread.regs->msr & ~MSR_DEBUGCHANGE); |
Benjamin Herrenschmidt | 912000e | 2007-06-04 15:15:46 +1000 | [diff] [blame] | 96 | /* We prevent mucking around with the reserved area of trap |
| 97 | * which are used internally by the kernel |
| 98 | */ |
| 99 | if (regno == PT_TRAP) |
| 100 | data &= 0xfff0; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 101 | ((unsigned long *)task->thread.regs)[regno] = data; |
| 102 | return 0; |
| 103 | } |
| 104 | return -EIO; |
| 105 | } |
| 106 | |
| 107 | |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 108 | static int fpr_get(struct task_struct *target, const struct user_regset *regset, |
| 109 | unsigned int pos, unsigned int count, |
| 110 | void *kbuf, void __user *ubuf) |
| 111 | { |
| 112 | flush_fp_to_thread(target); |
| 113 | |
| 114 | BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) != |
| 115 | offsetof(struct thread_struct, fpr[32])); |
| 116 | |
| 117 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 118 | &target->thread.fpr, 0, -1); |
| 119 | } |
| 120 | |
| 121 | static int fpr_set(struct task_struct *target, const struct user_regset *regset, |
| 122 | unsigned int pos, unsigned int count, |
| 123 | const void *kbuf, const void __user *ubuf) |
| 124 | { |
| 125 | flush_fp_to_thread(target); |
| 126 | |
| 127 | BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) != |
| 128 | offsetof(struct thread_struct, fpr[32])); |
| 129 | |
| 130 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 131 | &target->thread.fpr, 0, -1); |
| 132 | } |
| 133 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 134 | static int get_fpregs(void __user *data, struct task_struct *task, |
| 135 | int has_fpscr) |
| 136 | { |
| 137 | unsigned int count = has_fpscr ? 33 : 32; |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 138 | if (!access_ok(VERIFY_WRITE, data, count * sizeof(double))) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 139 | return -EFAULT; |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 140 | return fpr_get(task, NULL, 0, count * sizeof(double), NULL, data); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static int set_fpregs(void __user *data, struct task_struct *task, |
| 144 | int has_fpscr) |
| 145 | { |
| 146 | unsigned int count = has_fpscr ? 33 : 32; |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 147 | if (!access_ok(VERIFY_READ, data, count * sizeof(double))) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 148 | return -EFAULT; |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 149 | return fpr_set(task, NULL, 0, count * sizeof(double), NULL, data); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | |
| 153 | #ifdef CONFIG_ALTIVEC |
| 154 | /* |
| 155 | * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. |
| 156 | * The transfer totals 34 quadword. Quadwords 0-31 contain the |
| 157 | * corresponding vector registers. Quadword 32 contains the vscr as the |
| 158 | * last word (offset 12) within that quadword. Quadword 33 contains the |
| 159 | * vrsave as the first word (offset 0) within the quadword. |
| 160 | * |
| 161 | * This definition of the VMX state is compatible with the current PPC32 |
| 162 | * ptrace interface. This allows signal handling and ptrace to use the |
| 163 | * same structures. This also simplifies the implementation of a bi-arch |
| 164 | * (combined (32- and 64-bit) gdb. |
| 165 | */ |
| 166 | |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame^] | 167 | static int vr_active(struct task_struct *target, |
| 168 | const struct user_regset *regset) |
| 169 | { |
| 170 | flush_altivec_to_thread(target); |
| 171 | return target->thread.used_vr ? regset->n : 0; |
| 172 | } |
| 173 | |
| 174 | static int vr_get(struct task_struct *target, const struct user_regset *regset, |
| 175 | unsigned int pos, unsigned int count, |
| 176 | void *kbuf, void __user *ubuf) |
| 177 | { |
| 178 | int ret; |
| 179 | |
| 180 | flush_altivec_to_thread(target); |
| 181 | |
| 182 | BUILD_BUG_ON(offsetof(struct thread_struct, vscr) != |
| 183 | offsetof(struct thread_struct, vr[32])); |
| 184 | |
| 185 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 186 | &target->thread.vr, 0, |
| 187 | 33 * sizeof(vector128)); |
| 188 | if (!ret) { |
| 189 | /* |
| 190 | * Copy out only the low-order word of vrsave. |
| 191 | */ |
| 192 | union { |
| 193 | elf_vrreg_t reg; |
| 194 | u32 word; |
| 195 | } vrsave; |
| 196 | memset(&vrsave, 0, sizeof(vrsave)); |
| 197 | vrsave.word = target->thread.vrsave; |
| 198 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, |
| 199 | 33 * sizeof(vector128), -1); |
| 200 | } |
| 201 | |
| 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | static int vr_set(struct task_struct *target, const struct user_regset *regset, |
| 206 | unsigned int pos, unsigned int count, |
| 207 | const void *kbuf, const void __user *ubuf) |
| 208 | { |
| 209 | int ret; |
| 210 | |
| 211 | flush_altivec_to_thread(target); |
| 212 | |
| 213 | BUILD_BUG_ON(offsetof(struct thread_struct, vscr) != |
| 214 | offsetof(struct thread_struct, vr[32])); |
| 215 | |
| 216 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 217 | &target->thread.vr, 0, 33 * sizeof(vector128)); |
| 218 | if (!ret && count > 0) { |
| 219 | /* |
| 220 | * We use only the first word of vrsave. |
| 221 | */ |
| 222 | union { |
| 223 | elf_vrreg_t reg; |
| 224 | u32 word; |
| 225 | } vrsave; |
| 226 | memset(&vrsave, 0, sizeof(vrsave)); |
| 227 | vrsave.word = target->thread.vrsave; |
| 228 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, |
| 229 | 33 * sizeof(vector128), -1); |
| 230 | if (!ret) |
| 231 | target->thread.vrsave = vrsave.word; |
| 232 | } |
| 233 | |
| 234 | return ret; |
| 235 | } |
| 236 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 237 | /* |
| 238 | * Get contents of AltiVec register state in task TASK |
| 239 | */ |
| 240 | static int get_vrregs(unsigned long __user *data, struct task_struct *task) |
| 241 | { |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame^] | 242 | if (!access_ok(VERIFY_WRITE, data, |
| 243 | 33 * sizeof(vector128) + sizeof(u32))) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 244 | return -EFAULT; |
| 245 | |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame^] | 246 | return vr_get(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32), |
| 247 | NULL, data); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Write contents of AltiVec register state into task TASK. |
| 252 | */ |
| 253 | static int set_vrregs(struct task_struct *task, unsigned long __user *data) |
| 254 | { |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame^] | 255 | if (!access_ok(VERIFY_READ, data, 33 * sizeof(vector128) + sizeof(u32))) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 256 | return -EFAULT; |
| 257 | |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame^] | 258 | return vr_set(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32), |
| 259 | NULL, data); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 260 | } |
| 261 | #endif /* CONFIG_ALTIVEC */ |
| 262 | |
| 263 | #ifdef CONFIG_SPE |
| 264 | |
| 265 | /* |
| 266 | * For get_evrregs/set_evrregs functions 'data' has the following layout: |
| 267 | * |
| 268 | * struct { |
| 269 | * u32 evr[32]; |
| 270 | * u64 acc; |
| 271 | * u32 spefscr; |
| 272 | * } |
| 273 | */ |
| 274 | |
| 275 | /* |
| 276 | * Get contents of SPE register state in task TASK. |
| 277 | */ |
| 278 | static int get_evrregs(unsigned long *data, struct task_struct *task) |
| 279 | { |
| 280 | int i; |
| 281 | |
| 282 | if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(unsigned long))) |
| 283 | return -EFAULT; |
| 284 | |
| 285 | /* copy SPEFSCR */ |
| 286 | if (__put_user(task->thread.spefscr, &data[34])) |
| 287 | return -EFAULT; |
| 288 | |
| 289 | /* copy SPE registers EVR[0] .. EVR[31] */ |
| 290 | for (i = 0; i < 32; i++, data++) |
| 291 | if (__put_user(task->thread.evr[i], data)) |
| 292 | return -EFAULT; |
| 293 | |
| 294 | /* copy ACC */ |
| 295 | if (__put_user64(task->thread.acc, (unsigned long long *)data)) |
| 296 | return -EFAULT; |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Write contents of SPE register state into task TASK. |
| 303 | */ |
| 304 | static int set_evrregs(struct task_struct *task, unsigned long *data) |
| 305 | { |
| 306 | int i; |
| 307 | |
| 308 | if (!access_ok(VERIFY_READ, data, 35 * sizeof(unsigned long))) |
| 309 | return -EFAULT; |
| 310 | |
| 311 | /* copy SPEFSCR */ |
| 312 | if (__get_user(task->thread.spefscr, &data[34])) |
| 313 | return -EFAULT; |
| 314 | |
| 315 | /* copy SPE registers EVR[0] .. EVR[31] */ |
| 316 | for (i = 0; i < 32; i++, data++) |
| 317 | if (__get_user(task->thread.evr[i], data)) |
| 318 | return -EFAULT; |
| 319 | /* copy ACC */ |
| 320 | if (__get_user64(task->thread.acc, (unsigned long long*)data)) |
| 321 | return -EFAULT; |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | #endif /* CONFIG_SPE */ |
| 326 | |
| 327 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 328 | void user_enable_single_step(struct task_struct *task) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 329 | { |
| 330 | struct pt_regs *regs = task->thread.regs; |
| 331 | |
| 332 | if (regs != NULL) { |
| 333 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) |
| 334 | task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC; |
| 335 | regs->msr |= MSR_DE; |
| 336 | #else |
| 337 | regs->msr |= MSR_SE; |
| 338 | #endif |
| 339 | } |
| 340 | set_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 341 | } |
| 342 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 343 | void user_disable_single_step(struct task_struct *task) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 344 | { |
| 345 | struct pt_regs *regs = task->thread.regs; |
| 346 | |
| 347 | if (regs != NULL) { |
| 348 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) |
| 349 | task->thread.dbcr0 = 0; |
| 350 | regs->msr &= ~MSR_DE; |
| 351 | #else |
| 352 | regs->msr &= ~MSR_SE; |
| 353 | #endif |
| 354 | } |
| 355 | clear_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 356 | } |
| 357 | |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 358 | static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, |
| 359 | unsigned long data) |
| 360 | { |
| 361 | /* We only support one DABR and no IABRS at the moment */ |
| 362 | if (addr > 0) |
| 363 | return -EINVAL; |
| 364 | |
| 365 | /* The bottom 3 bits are flags */ |
| 366 | if ((data & ~0x7UL) >= TASK_SIZE) |
| 367 | return -EIO; |
| 368 | |
| 369 | /* Ensure translation is on */ |
| 370 | if (data && !(data & DABR_TRANSLATION)) |
| 371 | return -EIO; |
| 372 | |
| 373 | task->thread.dabr = data; |
| 374 | return 0; |
| 375 | } |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 376 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 377 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | * Called by kernel/ptrace.c when detaching.. |
| 379 | * |
| 380 | * Make sure single step bits etc are not set. |
| 381 | */ |
| 382 | void ptrace_disable(struct task_struct *child) |
| 383 | { |
| 384 | /* make sure the single step bit is not set. */ |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 385 | user_disable_single_step(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 388 | /* |
| 389 | * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls, |
| 390 | * we mark them as obsolete now, they will be removed in a future version |
| 391 | */ |
| 392 | static long arch_ptrace_old(struct task_struct *child, long request, long addr, |
| 393 | long data) |
| 394 | { |
| 395 | int ret = -EPERM; |
| 396 | |
| 397 | switch(request) { |
| 398 | case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */ |
| 399 | int i; |
| 400 | unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; |
| 401 | unsigned long __user *tmp = (unsigned long __user *)addr; |
| 402 | |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 403 | CHECK_FULL_REGS(child->thread.regs); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 404 | for (i = 0; i < 32; i++) { |
| 405 | ret = put_user(*reg, tmp); |
| 406 | if (ret) |
| 407 | break; |
| 408 | reg++; |
| 409 | tmp++; |
| 410 | } |
| 411 | break; |
| 412 | } |
| 413 | |
| 414 | case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */ |
| 415 | int i; |
| 416 | unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; |
| 417 | unsigned long __user *tmp = (unsigned long __user *)addr; |
| 418 | |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 419 | CHECK_FULL_REGS(child->thread.regs); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 420 | for (i = 0; i < 32; i++) { |
| 421 | ret = get_user(*reg, tmp); |
| 422 | if (ret) |
| 423 | break; |
| 424 | reg++; |
| 425 | tmp++; |
| 426 | } |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */ |
| 431 | flush_fp_to_thread(child); |
| 432 | ret = get_fpregs((void __user *)addr, child, 0); |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */ |
| 437 | flush_fp_to_thread(child); |
| 438 | ret = set_fpregs((void __user *)addr, child, 0); |
| 439 | break; |
| 440 | } |
| 441 | |
| 442 | } |
| 443 | return ret; |
| 444 | } |
| 445 | |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 446 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | int ret = -EPERM; |
| 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | switch (request) { |
| 451 | /* when I and D space are separate, these will need to be fixed. */ |
| 452 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
Alexey Dobriyan | 7664732 | 2007-07-17 04:03:43 -0700 | [diff] [blame] | 453 | case PTRACE_PEEKDATA: |
| 454 | ret = generic_ptrace_peekdata(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
| 457 | /* read the word at location addr in the USER area. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | case PTRACE_PEEKUSR: { |
| 459 | unsigned long index, tmp; |
| 460 | |
| 461 | ret = -EIO; |
| 462 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 463 | #ifdef CONFIG_PPC32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | index = (unsigned long) addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 465 | if ((addr & 3) || (index > PT_FPSCR) |
| 466 | || (child->thread.regs == NULL)) |
| 467 | #else |
| 468 | index = (unsigned long) addr >> 3; |
| 469 | if ((addr & 7) || (index > PT_FPSCR)) |
| 470 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | break; |
| 472 | |
| 473 | CHECK_FULL_REGS(child->thread.regs); |
| 474 | if (index < PT_FPR0) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 475 | tmp = ptrace_get_reg(child, (int) index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } else { |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 477 | flush_fp_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0]; |
| 479 | } |
| 480 | ret = put_user(tmp,(unsigned long __user *) data); |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | /* If I and D space are separate, this will have to be fixed. */ |
| 485 | case PTRACE_POKETEXT: /* write the word at location addr. */ |
| 486 | case PTRACE_POKEDATA: |
Alexey Dobriyan | f284ce7 | 2007-07-17 04:03:44 -0700 | [diff] [blame] | 487 | ret = generic_ptrace_pokedata(child, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | break; |
| 489 | |
| 490 | /* write the word at location addr in the USER area */ |
| 491 | case PTRACE_POKEUSR: { |
| 492 | unsigned long index; |
| 493 | |
| 494 | ret = -EIO; |
| 495 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 496 | #ifdef CONFIG_PPC32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | index = (unsigned long) addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 498 | if ((addr & 3) || (index > PT_FPSCR) |
| 499 | || (child->thread.regs == NULL)) |
| 500 | #else |
| 501 | index = (unsigned long) addr >> 3; |
| 502 | if ((addr & 7) || (index > PT_FPSCR)) |
| 503 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | break; |
| 505 | |
| 506 | CHECK_FULL_REGS(child->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | if (index < PT_FPR0) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 508 | ret = ptrace_put_reg(child, index, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } else { |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 510 | flush_fp_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data; |
| 512 | ret = 0; |
| 513 | } |
| 514 | break; |
| 515 | } |
| 516 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 517 | case PTRACE_GET_DEBUGREG: { |
| 518 | ret = -EINVAL; |
| 519 | /* We only support one DABR and no IABRS at the moment */ |
| 520 | if (addr > 0) |
| 521 | break; |
| 522 | ret = put_user(child->thread.dabr, |
| 523 | (unsigned long __user *)data); |
| 524 | break; |
| 525 | } |
| 526 | |
| 527 | case PTRACE_SET_DEBUGREG: |
| 528 | ret = ptrace_set_debugreg(child, addr, data); |
| 529 | break; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 530 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 531 | #ifdef CONFIG_PPC64 |
| 532 | case PTRACE_GETREGS64: |
| 533 | #endif |
| 534 | case PTRACE_GETREGS: { /* Get all pt_regs from the child. */ |
| 535 | int ui; |
| 536 | if (!access_ok(VERIFY_WRITE, (void __user *)data, |
| 537 | sizeof(struct pt_regs))) { |
| 538 | ret = -EIO; |
| 539 | break; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 540 | } |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 541 | CHECK_FULL_REGS(child->thread.regs); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 542 | ret = 0; |
| 543 | for (ui = 0; ui < PT_REGS_COUNT; ui ++) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 544 | ret |= __put_user(ptrace_get_reg(child, ui), |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 545 | (unsigned long __user *) data); |
| 546 | data += sizeof(long); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 547 | } |
| 548 | break; |
| 549 | } |
| 550 | |
Benjamin Herrenschmidt | 0b3d5c4 | 2007-06-04 15:15:39 +1000 | [diff] [blame] | 551 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 552 | case PTRACE_SETREGS64: |
| 553 | #endif |
| 554 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ |
| 555 | unsigned long tmp; |
| 556 | int ui; |
| 557 | if (!access_ok(VERIFY_READ, (void __user *)data, |
| 558 | sizeof(struct pt_regs))) { |
| 559 | ret = -EIO; |
| 560 | break; |
| 561 | } |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 562 | CHECK_FULL_REGS(child->thread.regs); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 563 | ret = 0; |
| 564 | for (ui = 0; ui < PT_REGS_COUNT; ui ++) { |
| 565 | ret = __get_user(tmp, (unsigned long __user *) data); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 566 | if (ret) |
| 567 | break; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 568 | ptrace_put_reg(child, ui, tmp); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 569 | data += sizeof(long); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 570 | } |
| 571 | break; |
| 572 | } |
| 573 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 574 | case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 575 | flush_fp_to_thread(child); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 576 | ret = get_fpregs((void __user *)data, child, 1); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 577 | break; |
| 578 | } |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 579 | |
| 580 | case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */ |
| 581 | flush_fp_to_thread(child); |
| 582 | ret = set_fpregs((void __user *)data, child, 1); |
| 583 | break; |
| 584 | } |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | #ifdef CONFIG_ALTIVEC |
| 587 | case PTRACE_GETVRREGS: |
| 588 | /* Get the child altivec register state. */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 589 | flush_altivec_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | ret = get_vrregs((unsigned long __user *)data, child); |
| 591 | break; |
| 592 | |
| 593 | case PTRACE_SETVRREGS: |
| 594 | /* Set the child altivec register state. */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 595 | flush_altivec_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | ret = set_vrregs(child, (unsigned long __user *)data); |
| 597 | break; |
| 598 | #endif |
| 599 | #ifdef CONFIG_SPE |
| 600 | case PTRACE_GETEVRREGS: |
| 601 | /* Get the child spe register state. */ |
Kumar Gala | 5e14d21 | 2007-09-13 01:44:20 -0500 | [diff] [blame] | 602 | flush_spe_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | ret = get_evrregs((unsigned long __user *)data, child); |
| 604 | break; |
| 605 | |
| 606 | case PTRACE_SETEVRREGS: |
| 607 | /* Set the child spe register state. */ |
| 608 | /* this is to clear the MSR_SPE bit to force a reload |
| 609 | * of register state from memory */ |
Kumar Gala | 5e14d21 | 2007-09-13 01:44:20 -0500 | [diff] [blame] | 610 | flush_spe_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | ret = set_evrregs(child, (unsigned long __user *)data); |
| 612 | break; |
| 613 | #endif |
| 614 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 615 | /* Old reverse args ptrace callss */ |
| 616 | case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */ |
| 617 | case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */ |
| 618 | case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */ |
| 619 | case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */ |
| 620 | ret = arch_ptrace_old(child, request, addr, data); |
| 621 | break; |
| 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | default: |
| 624 | ret = ptrace_request(child, request, addr, data); |
| 625 | break; |
| 626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | return ret; |
| 628 | } |
| 629 | |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 630 | static void do_syscall_trace(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | { |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 632 | /* the 0x80 provides a way for the tracing parent to distinguish |
| 633 | between a syscall stop and SIGTRAP delivery */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) |
| 635 | ? 0x80 : 0)); |
| 636 | |
| 637 | /* |
| 638 | * this isn't the same as continuing with a signal, but it will do |
| 639 | * for normal use. strace only continues with a signal if the |
| 640 | * stopping signal is not SIGTRAP. -brl |
| 641 | */ |
| 642 | if (current->exit_code) { |
| 643 | send_sig(current->exit_code, current, 1); |
| 644 | current->exit_code = 0; |
| 645 | } |
| 646 | } |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 647 | |
| 648 | void do_syscall_trace_enter(struct pt_regs *regs) |
| 649 | { |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 650 | secure_computing(regs->gpr[0]); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 651 | |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 652 | if (test_thread_flag(TIF_SYSCALL_TRACE) |
| 653 | && (current->ptrace & PT_PTRACED)) |
| 654 | do_syscall_trace(); |
| 655 | |
David Woodhouse | cfcd170 | 2007-01-14 09:38:18 +0800 | [diff] [blame] | 656 | if (unlikely(current->audit_context)) { |
| 657 | #ifdef CONFIG_PPC64 |
| 658 | if (!test_thread_flag(TIF_32BIT)) |
| 659 | audit_syscall_entry(AUDIT_ARCH_PPC64, |
| 660 | regs->gpr[0], |
| 661 | regs->gpr[3], regs->gpr[4], |
| 662 | regs->gpr[5], regs->gpr[6]); |
| 663 | else |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 664 | #endif |
David Woodhouse | cfcd170 | 2007-01-14 09:38:18 +0800 | [diff] [blame] | 665 | audit_syscall_entry(AUDIT_ARCH_PPC, |
| 666 | regs->gpr[0], |
| 667 | regs->gpr[3] & 0xffffffff, |
| 668 | regs->gpr[4] & 0xffffffff, |
| 669 | regs->gpr[5] & 0xffffffff, |
| 670 | regs->gpr[6] & 0xffffffff); |
| 671 | } |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | void do_syscall_trace_leave(struct pt_regs *regs) |
| 675 | { |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 676 | if (unlikely(current->audit_context)) |
David Woodhouse | 4b9c876 | 2006-09-22 09:23:53 +0100 | [diff] [blame] | 677 | audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS, |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 678 | regs->result); |
| 679 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 680 | if ((test_thread_flag(TIF_SYSCALL_TRACE) |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 681 | || test_thread_flag(TIF_SINGLESTEP)) |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 682 | && (current->ptrace & PT_PTRACED)) |
| 683 | do_syscall_trace(); |
| 684 | } |