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