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