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