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 | |
Benjamin Herrenschmidt | acd8982 | 2007-06-04 15:15:41 +1000 | [diff] [blame] | 44 | #include "ptrace-common.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * does not yet catch signals sent when the child dies. |
| 48 | * in exit.c or in signal.c. |
| 49 | */ |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Called by kernel/ptrace.c when detaching.. |
| 53 | * |
| 54 | * Make sure single step bits etc are not set. |
| 55 | */ |
| 56 | void ptrace_disable(struct task_struct *child) |
| 57 | { |
| 58 | /* make sure the single step bit is not set. */ |
| 59 | clear_single_step(child); |
| 60 | } |
| 61 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 62 | /* |
| 63 | * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls, |
| 64 | * we mark them as obsolete now, they will be removed in a future version |
| 65 | */ |
| 66 | static long arch_ptrace_old(struct task_struct *child, long request, long addr, |
| 67 | long data) |
| 68 | { |
| 69 | int ret = -EPERM; |
| 70 | |
| 71 | switch(request) { |
| 72 | case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */ |
| 73 | int i; |
| 74 | unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; |
| 75 | unsigned long __user *tmp = (unsigned long __user *)addr; |
| 76 | |
| 77 | for (i = 0; i < 32; i++) { |
| 78 | ret = put_user(*reg, tmp); |
| 79 | if (ret) |
| 80 | break; |
| 81 | reg++; |
| 82 | tmp++; |
| 83 | } |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */ |
| 88 | int i; |
| 89 | unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; |
| 90 | unsigned long __user *tmp = (unsigned long __user *)addr; |
| 91 | |
| 92 | for (i = 0; i < 32; i++) { |
| 93 | ret = get_user(*reg, tmp); |
| 94 | if (ret) |
| 95 | break; |
| 96 | reg++; |
| 97 | tmp++; |
| 98 | } |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */ |
| 103 | flush_fp_to_thread(child); |
| 104 | ret = get_fpregs((void __user *)addr, child, 0); |
| 105 | break; |
| 106 | } |
| 107 | |
| 108 | case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */ |
| 109 | flush_fp_to_thread(child); |
| 110 | ret = set_fpregs((void __user *)addr, child, 0); |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | } |
| 115 | return ret; |
| 116 | } |
| 117 | |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 118 | 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] | 119 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | int ret = -EPERM; |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | switch (request) { |
| 123 | /* when I and D space are separate, these will need to be fixed. */ |
| 124 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
| 125 | case PTRACE_PEEKDATA: { |
| 126 | unsigned long tmp; |
| 127 | int copied; |
| 128 | |
| 129 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); |
| 130 | ret = -EIO; |
| 131 | if (copied != sizeof(tmp)) |
| 132 | break; |
| 133 | ret = put_user(tmp,(unsigned long __user *) data); |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | /* read the word at location addr in the USER area. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | case PTRACE_PEEKUSR: { |
| 139 | unsigned long index, tmp; |
| 140 | |
| 141 | ret = -EIO; |
| 142 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 143 | #ifdef CONFIG_PPC32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | index = (unsigned long) addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 145 | if ((addr & 3) || (index > PT_FPSCR) |
| 146 | || (child->thread.regs == NULL)) |
| 147 | #else |
| 148 | index = (unsigned long) addr >> 3; |
| 149 | if ((addr & 7) || (index > PT_FPSCR)) |
| 150 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | break; |
| 152 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 153 | #ifdef CONFIG_PPC32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | CHECK_FULL_REGS(child->thread.regs); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 155 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | if (index < PT_FPR0) { |
| 157 | tmp = get_reg(child, (int) index); |
| 158 | } else { |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 159 | flush_fp_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0]; |
| 161 | } |
| 162 | ret = put_user(tmp,(unsigned long __user *) data); |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | /* If I and D space are separate, this will have to be fixed. */ |
| 167 | case PTRACE_POKETEXT: /* write the word at location addr. */ |
| 168 | case PTRACE_POKEDATA: |
| 169 | ret = 0; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 170 | if (access_process_vm(child, addr, &data, sizeof(data), 1) |
| 171 | == sizeof(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | break; |
| 173 | ret = -EIO; |
| 174 | break; |
| 175 | |
| 176 | /* write the word at location addr in the USER area */ |
| 177 | case PTRACE_POKEUSR: { |
| 178 | unsigned long index; |
| 179 | |
| 180 | ret = -EIO; |
| 181 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 182 | #ifdef CONFIG_PPC32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | index = (unsigned long) addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 184 | if ((addr & 3) || (index > PT_FPSCR) |
| 185 | || (child->thread.regs == NULL)) |
| 186 | #else |
| 187 | index = (unsigned long) addr >> 3; |
| 188 | if ((addr & 7) || (index > PT_FPSCR)) |
| 189 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | break; |
| 191 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 192 | #ifdef CONFIG_PPC32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | CHECK_FULL_REGS(child->thread.regs); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 194 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (index == PT_ORIG_R3) |
| 196 | break; |
| 197 | if (index < PT_FPR0) { |
| 198 | ret = put_reg(child, index, data); |
| 199 | } else { |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 200 | flush_fp_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data; |
| 202 | ret = 0; |
| 203 | } |
| 204 | break; |
| 205 | } |
| 206 | |
| 207 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ |
| 208 | case PTRACE_CONT: { /* restart after signal. */ |
| 209 | ret = -EIO; |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 210 | if (!valid_signal(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | break; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 212 | if (request == PTRACE_SYSCALL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 214 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | child->exit_code = data; |
| 217 | /* make sure the single step bit is not set. */ |
| 218 | clear_single_step(child); |
| 219 | wake_up_process(child); |
| 220 | ret = 0; |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * make the child exit. Best I can do is send it a sigkill. |
| 226 | * perhaps it should be put in the status that it wants to |
| 227 | * exit. |
| 228 | */ |
| 229 | case PTRACE_KILL: { |
| 230 | ret = 0; |
| 231 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ |
| 232 | break; |
| 233 | child->exit_code = SIGKILL; |
| 234 | /* make sure the single step bit is not set. */ |
| 235 | clear_single_step(child); |
| 236 | wake_up_process(child); |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | case PTRACE_SINGLESTEP: { /* set the trap flag. */ |
| 241 | ret = -EIO; |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 242 | if (!valid_signal(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | break; |
| 244 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
| 245 | set_single_step(child); |
| 246 | child->exit_code = data; |
| 247 | /* give it a chance to run. */ |
| 248 | wake_up_process(child); |
| 249 | ret = 0; |
| 250 | break; |
| 251 | } |
| 252 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 253 | #ifdef CONFIG_PPC64 |
| 254 | case PTRACE_GET_DEBUGREG: { |
| 255 | ret = -EINVAL; |
| 256 | /* We only support one DABR and no IABRS at the moment */ |
| 257 | if (addr > 0) |
| 258 | break; |
| 259 | ret = put_user(child->thread.dabr, |
| 260 | (unsigned long __user *)data); |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | case PTRACE_SET_DEBUGREG: |
| 265 | ret = ptrace_set_debugreg(child, addr, data); |
| 266 | break; |
| 267 | #endif |
| 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | case PTRACE_DETACH: |
| 270 | ret = ptrace_detach(child, data); |
| 271 | break; |
| 272 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 273 | #ifdef CONFIG_PPC64 |
| 274 | case PTRACE_GETREGS64: |
| 275 | #endif |
| 276 | case PTRACE_GETREGS: { /* Get all pt_regs from the child. */ |
| 277 | int ui; |
| 278 | if (!access_ok(VERIFY_WRITE, (void __user *)data, |
| 279 | sizeof(struct pt_regs))) { |
| 280 | ret = -EIO; |
| 281 | break; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 282 | } |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 283 | ret = 0; |
| 284 | for (ui = 0; ui < PT_REGS_COUNT; ui ++) { |
| 285 | ret |= __put_user(get_reg(child, ui), |
| 286 | (unsigned long __user *) data); |
| 287 | data += sizeof(long); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 288 | } |
| 289 | break; |
| 290 | } |
| 291 | |
Benjamin Herrenschmidt | 0b3d5c4 | 2007-06-04 15:15:39 +1000 | [diff] [blame] | 292 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 293 | case PTRACE_SETREGS64: |
| 294 | #endif |
| 295 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ |
| 296 | unsigned long tmp; |
| 297 | int ui; |
| 298 | if (!access_ok(VERIFY_READ, (void __user *)data, |
| 299 | sizeof(struct pt_regs))) { |
| 300 | ret = -EIO; |
| 301 | break; |
| 302 | } |
| 303 | ret = 0; |
| 304 | for (ui = 0; ui < PT_REGS_COUNT; ui ++) { |
| 305 | ret = __get_user(tmp, (unsigned long __user *) data); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 306 | if (ret) |
| 307 | break; |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 308 | put_reg(child, ui, tmp); |
| 309 | data += sizeof(long); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 310 | } |
| 311 | break; |
| 312 | } |
| 313 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 314 | case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 315 | flush_fp_to_thread(child); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 316 | ret = get_fpregs((void __user *)data, child, 1); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 317 | break; |
| 318 | } |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 319 | |
| 320 | case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */ |
| 321 | flush_fp_to_thread(child); |
| 322 | ret = set_fpregs((void __user *)data, child, 1); |
| 323 | break; |
| 324 | } |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | #ifdef CONFIG_ALTIVEC |
| 327 | case PTRACE_GETVRREGS: |
| 328 | /* Get the child altivec register state. */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 329 | flush_altivec_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | ret = get_vrregs((unsigned long __user *)data, child); |
| 331 | break; |
| 332 | |
| 333 | case PTRACE_SETVRREGS: |
| 334 | /* Set the child altivec register state. */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 335 | flush_altivec_to_thread(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | ret = set_vrregs(child, (unsigned long __user *)data); |
| 337 | break; |
| 338 | #endif |
| 339 | #ifdef CONFIG_SPE |
| 340 | case PTRACE_GETEVRREGS: |
| 341 | /* Get the child spe register state. */ |
| 342 | if (child->thread.regs->msr & MSR_SPE) |
| 343 | giveup_spe(child); |
| 344 | ret = get_evrregs((unsigned long __user *)data, child); |
| 345 | break; |
| 346 | |
| 347 | case PTRACE_SETEVRREGS: |
| 348 | /* Set the child spe register state. */ |
| 349 | /* this is to clear the MSR_SPE bit to force a reload |
| 350 | * of register state from memory */ |
| 351 | if (child->thread.regs->msr & MSR_SPE) |
| 352 | giveup_spe(child); |
| 353 | ret = set_evrregs(child, (unsigned long __user *)data); |
| 354 | break; |
| 355 | #endif |
| 356 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame^] | 357 | /* Old reverse args ptrace callss */ |
| 358 | case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */ |
| 359 | case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */ |
| 360 | case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */ |
| 361 | case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */ |
| 362 | ret = arch_ptrace_old(child, request, addr, data); |
| 363 | break; |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | default: |
| 366 | ret = ptrace_request(child, request, addr, data); |
| 367 | break; |
| 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return ret; |
| 370 | } |
| 371 | |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 372 | static void do_syscall_trace(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 374 | /* the 0x80 provides a way for the tracing parent to distinguish |
| 375 | between a syscall stop and SIGTRAP delivery */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) |
| 377 | ? 0x80 : 0)); |
| 378 | |
| 379 | /* |
| 380 | * this isn't the same as continuing with a signal, but it will do |
| 381 | * for normal use. strace only continues with a signal if the |
| 382 | * stopping signal is not SIGTRAP. -brl |
| 383 | */ |
| 384 | if (current->exit_code) { |
| 385 | send_sig(current->exit_code, current, 1); |
| 386 | current->exit_code = 0; |
| 387 | } |
| 388 | } |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 389 | |
| 390 | void do_syscall_trace_enter(struct pt_regs *regs) |
| 391 | { |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 392 | secure_computing(regs->gpr[0]); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 393 | |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 394 | if (test_thread_flag(TIF_SYSCALL_TRACE) |
| 395 | && (current->ptrace & PT_PTRACED)) |
| 396 | do_syscall_trace(); |
| 397 | |
David Woodhouse | cfcd170 | 2007-01-14 09:38:18 +0800 | [diff] [blame] | 398 | if (unlikely(current->audit_context)) { |
| 399 | #ifdef CONFIG_PPC64 |
| 400 | if (!test_thread_flag(TIF_32BIT)) |
| 401 | audit_syscall_entry(AUDIT_ARCH_PPC64, |
| 402 | regs->gpr[0], |
| 403 | regs->gpr[3], regs->gpr[4], |
| 404 | regs->gpr[5], regs->gpr[6]); |
| 405 | else |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 406 | #endif |
David Woodhouse | cfcd170 | 2007-01-14 09:38:18 +0800 | [diff] [blame] | 407 | audit_syscall_entry(AUDIT_ARCH_PPC, |
| 408 | regs->gpr[0], |
| 409 | regs->gpr[3] & 0xffffffff, |
| 410 | regs->gpr[4] & 0xffffffff, |
| 411 | regs->gpr[5] & 0xffffffff, |
| 412 | regs->gpr[6] & 0xffffffff); |
| 413 | } |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void do_syscall_trace_leave(struct pt_regs *regs) |
| 417 | { |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 418 | if (unlikely(current->audit_context)) |
David Woodhouse | 4b9c876 | 2006-09-22 09:23:53 +0100 | [diff] [blame] | 419 | audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS, |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 420 | regs->result); |
| 421 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 422 | if ((test_thread_flag(TIF_SYSCALL_TRACE) |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 423 | || test_thread_flag(TIF_SINGLESTEP)) |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 424 | && (current->ptrace & PT_PTRACED)) |
| 425 | do_syscall_trace(); |
| 426 | } |