Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1992 Ross Biro |
| 7 | * Copyright (C) Linus Torvalds |
| 8 | * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle |
| 9 | * Copyright (C) 1996 David S. Miller |
| 10 | * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com |
| 11 | * Copyright (C) 1999 MIPS Technologies, Inc. |
| 12 | * Copyright (C) 2000 Ulf Carlsson |
| 13 | * |
| 14 | * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit |
| 15 | * binaries. |
| 16 | */ |
| 17 | #include <linux/config.h> |
| 18 | #include <linux/compiler.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/ptrace.h> |
| 24 | #include <linux/audit.h> |
| 25 | #include <linux/smp.h> |
| 26 | #include <linux/smp_lock.h> |
| 27 | #include <linux/user.h> |
| 28 | #include <linux/security.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 29 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Ralf Baechle | f8280c8 | 2005-05-19 12:08:04 +0000 | [diff] [blame] | 31 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/cpu.h> |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 33 | #include <asm/dsp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/fpu.h> |
| 35 | #include <asm/mipsregs.h> |
Ralf Baechle | 101b353 | 2005-10-06 17:39:32 +0100 | [diff] [blame] | 36 | #include <asm/mipsmtregs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <asm/pgtable.h> |
| 38 | #include <asm/page.h> |
| 39 | #include <asm/system.h> |
| 40 | #include <asm/uaccess.h> |
| 41 | #include <asm/bootinfo.h> |
Daniel Jacobowitz | ea3d710 | 2005-09-28 18:11:15 -0400 | [diff] [blame] | 42 | #include <asm/reg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Called by kernel/ptrace.c when detaching.. |
| 46 | * |
| 47 | * Make sure single step bits etc are not set. |
| 48 | */ |
| 49 | void ptrace_disable(struct task_struct *child) |
| 50 | { |
| 51 | /* Nothing to do.. */ |
| 52 | } |
| 53 | |
Daniel Jacobowitz | ea3d710 | 2005-09-28 18:11:15 -0400 | [diff] [blame] | 54 | /* |
| 55 | * Read a general register set. We always use the 64-bit format, even |
| 56 | * for 32-bit kernels and for 32-bit processes on a 64-bit kernel. |
| 57 | * Registers are sign extended to fill the available space. |
| 58 | */ |
| 59 | int ptrace_getregs (struct task_struct *child, __s64 __user *data) |
| 60 | { |
| 61 | struct pt_regs *regs; |
| 62 | int i; |
| 63 | |
| 64 | if (!access_ok(VERIFY_WRITE, data, 38 * 8)) |
| 65 | return -EIO; |
| 66 | |
| 67 | regs = (struct pt_regs *) ((unsigned long) child->thread_info + |
| 68 | THREAD_SIZE - 32 - sizeof(struct pt_regs)); |
| 69 | |
| 70 | for (i = 0; i < 32; i++) |
| 71 | __put_user (regs->regs[i], data + i); |
| 72 | __put_user (regs->lo, data + EF_LO - EF_R0); |
| 73 | __put_user (regs->hi, data + EF_HI - EF_R0); |
| 74 | __put_user (regs->cp0_epc, data + EF_CP0_EPC - EF_R0); |
| 75 | __put_user (regs->cp0_badvaddr, data + EF_CP0_BADVADDR - EF_R0); |
| 76 | __put_user (regs->cp0_status, data + EF_CP0_STATUS - EF_R0); |
| 77 | __put_user (regs->cp0_cause, data + EF_CP0_CAUSE - EF_R0); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Write a general register set. As for PTRACE_GETREGS, we always use |
| 84 | * the 64-bit format. On a 32-bit kernel only the lower order half |
| 85 | * (according to endianness) will be used. |
| 86 | */ |
| 87 | int ptrace_setregs (struct task_struct *child, __s64 __user *data) |
| 88 | { |
| 89 | struct pt_regs *regs; |
| 90 | int i; |
| 91 | |
| 92 | if (!access_ok(VERIFY_READ, data, 38 * 8)) |
| 93 | return -EIO; |
| 94 | |
| 95 | regs = (struct pt_regs *) ((unsigned long) child->thread_info + |
| 96 | THREAD_SIZE - 32 - sizeof(struct pt_regs)); |
| 97 | |
| 98 | for (i = 0; i < 32; i++) |
| 99 | __get_user (regs->regs[i], data + i); |
| 100 | __get_user (regs->lo, data + EF_LO - EF_R0); |
| 101 | __get_user (regs->hi, data + EF_HI - EF_R0); |
| 102 | __get_user (regs->cp0_epc, data + EF_CP0_EPC - EF_R0); |
| 103 | |
| 104 | /* badvaddr, status, and cause may not be written. */ |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | int ptrace_getfpregs (struct task_struct *child, __u32 __user *data) |
| 110 | { |
| 111 | int i; |
| 112 | |
| 113 | if (!access_ok(VERIFY_WRITE, data, 33 * 8)) |
| 114 | return -EIO; |
| 115 | |
| 116 | if (tsk_used_math(child)) { |
| 117 | fpureg_t *fregs = get_fpu_regs(child); |
| 118 | for (i = 0; i < 32; i++) |
| 119 | __put_user (fregs[i], i + (__u64 __user *) data); |
| 120 | } else { |
| 121 | for (i = 0; i < 32; i++) |
| 122 | __put_user ((__u64) -1, i + (__u64 __user *) data); |
| 123 | } |
| 124 | |
| 125 | if (cpu_has_fpu) { |
| 126 | unsigned int flags, tmp; |
| 127 | |
| 128 | __put_user (child->thread.fpu.hard.fcr31, data + 64); |
| 129 | |
Ralf Baechle | 101b353 | 2005-10-06 17:39:32 +0100 | [diff] [blame] | 130 | preempt_disable(); |
| 131 | if (cpu_has_mipsmt) { |
| 132 | unsigned int vpflags = dvpe(); |
| 133 | flags = read_c0_status(); |
| 134 | __enable_fpu(); |
| 135 | __asm__ __volatile__("cfc1\t%0,$0" : "=r" (tmp)); |
| 136 | write_c0_status(flags); |
| 137 | evpe(vpflags); |
| 138 | } else { |
| 139 | flags = read_c0_status(); |
| 140 | __enable_fpu(); |
| 141 | __asm__ __volatile__("cfc1\t%0,$0" : "=r" (tmp)); |
| 142 | write_c0_status(flags); |
| 143 | } |
| 144 | preempt_enable(); |
Daniel Jacobowitz | ea3d710 | 2005-09-28 18:11:15 -0400 | [diff] [blame] | 145 | __put_user (tmp, data + 65); |
| 146 | } else { |
| 147 | __put_user (child->thread.fpu.soft.fcr31, data + 64); |
| 148 | __put_user ((__u32) 0, data + 65); |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int ptrace_setfpregs (struct task_struct *child, __u32 __user *data) |
| 155 | { |
| 156 | fpureg_t *fregs; |
| 157 | int i; |
| 158 | |
| 159 | if (!access_ok(VERIFY_READ, data, 33 * 8)) |
| 160 | return -EIO; |
| 161 | |
| 162 | fregs = get_fpu_regs(child); |
| 163 | |
| 164 | for (i = 0; i < 32; i++) |
| 165 | __get_user (fregs[i], i + (__u64 __user *) data); |
| 166 | |
| 167 | if (cpu_has_fpu) |
| 168 | __get_user (child->thread.fpu.hard.fcr31, data + 64); |
| 169 | else |
| 170 | __get_user (child->thread.fpu.soft.fcr31, data + 64); |
| 171 | |
| 172 | /* FIR may not be written. */ |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 177 | 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] | 178 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | int ret; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | switch (request) { |
| 182 | /* when I and D space are separate, these will need to be fixed. */ |
| 183 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
| 184 | case PTRACE_PEEKDATA: { |
| 185 | unsigned long tmp; |
| 186 | int copied; |
| 187 | |
| 188 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); |
| 189 | ret = -EIO; |
| 190 | if (copied != sizeof(tmp)) |
| 191 | break; |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 192 | ret = put_user(tmp,(unsigned long __user *) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | break; |
| 194 | } |
| 195 | |
| 196 | /* Read the word at location addr in the USER area. */ |
| 197 | case PTRACE_PEEKUSR: { |
| 198 | struct pt_regs *regs; |
| 199 | unsigned long tmp = 0; |
| 200 | |
| 201 | regs = (struct pt_regs *) ((unsigned long) child->thread_info + |
| 202 | THREAD_SIZE - 32 - sizeof(struct pt_regs)); |
| 203 | ret = 0; /* Default return value. */ |
| 204 | |
| 205 | switch (addr) { |
| 206 | case 0 ... 31: |
| 207 | tmp = regs->regs[addr]; |
| 208 | break; |
| 209 | case FPR_BASE ... FPR_BASE + 31: |
| 210 | if (tsk_used_math(child)) { |
| 211 | fpureg_t *fregs = get_fpu_regs(child); |
| 212 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 213 | #ifdef CONFIG_32BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | /* |
| 215 | * The odd registers are actually the high |
| 216 | * order bits of the values stored in the even |
| 217 | * registers - unless we're using r2k_switch.S. |
| 218 | */ |
| 219 | if (addr & 1) |
| 220 | tmp = (unsigned long) (fregs[((addr & ~1) - 32)] >> 32); |
| 221 | else |
| 222 | tmp = (unsigned long) (fregs[(addr - 32)] & 0xffffffff); |
| 223 | #endif |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 224 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | tmp = fregs[addr - FPR_BASE]; |
| 226 | #endif |
| 227 | } else { |
| 228 | tmp = -1; /* FP not yet used */ |
| 229 | } |
| 230 | break; |
| 231 | case PC: |
| 232 | tmp = regs->cp0_epc; |
| 233 | break; |
| 234 | case CAUSE: |
| 235 | tmp = regs->cp0_cause; |
| 236 | break; |
| 237 | case BADVADDR: |
| 238 | tmp = regs->cp0_badvaddr; |
| 239 | break; |
| 240 | case MMHI: |
| 241 | tmp = regs->hi; |
| 242 | break; |
| 243 | case MMLO: |
| 244 | tmp = regs->lo; |
| 245 | break; |
| 246 | case FPC_CSR: |
| 247 | if (cpu_has_fpu) |
| 248 | tmp = child->thread.fpu.hard.fcr31; |
| 249 | else |
| 250 | tmp = child->thread.fpu.soft.fcr31; |
| 251 | break; |
| 252 | case FPC_EIR: { /* implementation / version register */ |
| 253 | unsigned int flags; |
| 254 | |
| 255 | if (!cpu_has_fpu) |
| 256 | break; |
| 257 | |
Ralf Baechle | 101b353 | 2005-10-06 17:39:32 +0100 | [diff] [blame] | 258 | preempt_disable(); |
| 259 | if (cpu_has_mipsmt) { |
| 260 | unsigned int vpflags = dvpe(); |
| 261 | flags = read_c0_status(); |
| 262 | __enable_fpu(); |
| 263 | __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp)); |
| 264 | write_c0_status(flags); |
| 265 | evpe(vpflags); |
| 266 | } else { |
| 267 | flags = read_c0_status(); |
| 268 | __enable_fpu(); |
| 269 | __asm__ __volatile__("cfc1\t%0,$0": "=r" (tmp)); |
| 270 | write_c0_status(flags); |
| 271 | } |
| 272 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | break; |
| 274 | } |
Ralf Baechle | c134a5e | 2005-06-30 09:42:00 +0000 | [diff] [blame] | 275 | case DSP_BASE ... DSP_BASE + 5: { |
| 276 | dspreg_t *dregs; |
| 277 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 278 | if (!cpu_has_dsp) { |
| 279 | tmp = 0; |
| 280 | ret = -EIO; |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 281 | goto out; |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 282 | } |
Ralf Baechle | 6c35585 | 2005-12-05 13:47:25 +0000 | [diff] [blame^] | 283 | dregs = __get_dsp_regs(child); |
| 284 | tmp = (unsigned long) (dregs[addr - DSP_BASE]); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 285 | break; |
Ralf Baechle | c134a5e | 2005-06-30 09:42:00 +0000 | [diff] [blame] | 286 | } |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 287 | case DSP_CONTROL: |
| 288 | if (!cpu_has_dsp) { |
| 289 | tmp = 0; |
| 290 | ret = -EIO; |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 291 | goto out; |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 292 | } |
| 293 | tmp = child->thread.dsp.dspcontrol; |
| 294 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | default: |
| 296 | tmp = 0; |
| 297 | ret = -EIO; |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 298 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 300 | ret = put_user(tmp, (unsigned long __user *) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | |
| 304 | /* when I and D space are separate, this will have to be fixed. */ |
| 305 | case PTRACE_POKETEXT: /* write the word at location addr. */ |
| 306 | case PTRACE_POKEDATA: |
| 307 | ret = 0; |
| 308 | if (access_process_vm(child, addr, &data, sizeof(data), 1) |
| 309 | == sizeof(data)) |
| 310 | break; |
| 311 | ret = -EIO; |
| 312 | break; |
| 313 | |
| 314 | case PTRACE_POKEUSR: { |
| 315 | struct pt_regs *regs; |
| 316 | ret = 0; |
| 317 | regs = (struct pt_regs *) ((unsigned long) child->thread_info + |
| 318 | THREAD_SIZE - 32 - sizeof(struct pt_regs)); |
| 319 | |
| 320 | switch (addr) { |
| 321 | case 0 ... 31: |
| 322 | regs->regs[addr] = data; |
| 323 | break; |
| 324 | case FPR_BASE ... FPR_BASE + 31: { |
| 325 | fpureg_t *fregs = get_fpu_regs(child); |
| 326 | |
| 327 | if (!tsk_used_math(child)) { |
| 328 | /* FP not yet used */ |
| 329 | memset(&child->thread.fpu.hard, ~0, |
| 330 | sizeof(child->thread.fpu.hard)); |
| 331 | child->thread.fpu.hard.fcr31 = 0; |
| 332 | } |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 333 | #ifdef CONFIG_32BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* |
| 335 | * The odd registers are actually the high order bits |
| 336 | * of the values stored in the even registers - unless |
| 337 | * we're using r2k_switch.S. |
| 338 | */ |
| 339 | if (addr & 1) { |
| 340 | fregs[(addr & ~1) - FPR_BASE] &= 0xffffffff; |
| 341 | fregs[(addr & ~1) - FPR_BASE] |= ((unsigned long long) data) << 32; |
| 342 | } else { |
| 343 | fregs[addr - FPR_BASE] &= ~0xffffffffLL; |
| 344 | fregs[addr - FPR_BASE] |= data; |
| 345 | } |
| 346 | #endif |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 347 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | fregs[addr - FPR_BASE] = data; |
| 349 | #endif |
| 350 | break; |
| 351 | } |
| 352 | case PC: |
| 353 | regs->cp0_epc = data; |
| 354 | break; |
| 355 | case MMHI: |
| 356 | regs->hi = data; |
| 357 | break; |
| 358 | case MMLO: |
| 359 | regs->lo = data; |
| 360 | break; |
| 361 | case FPC_CSR: |
| 362 | if (cpu_has_fpu) |
| 363 | child->thread.fpu.hard.fcr31 = data; |
| 364 | else |
| 365 | child->thread.fpu.soft.fcr31 = data; |
| 366 | break; |
Ralf Baechle | c134a5e | 2005-06-30 09:42:00 +0000 | [diff] [blame] | 367 | case DSP_BASE ... DSP_BASE + 5: { |
| 368 | dspreg_t *dregs; |
| 369 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 370 | if (!cpu_has_dsp) { |
| 371 | ret = -EIO; |
| 372 | break; |
| 373 | } |
| 374 | |
Ralf Baechle | c134a5e | 2005-06-30 09:42:00 +0000 | [diff] [blame] | 375 | dregs = __get_dsp_regs(child); |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 376 | dregs[addr - DSP_BASE] = data; |
| 377 | break; |
Ralf Baechle | c134a5e | 2005-06-30 09:42:00 +0000 | [diff] [blame] | 378 | } |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 379 | case DSP_CONTROL: |
| 380 | if (!cpu_has_dsp) { |
| 381 | ret = -EIO; |
| 382 | break; |
| 383 | } |
| 384 | child->thread.dsp.dspcontrol = data; |
| 385 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | default: |
| 387 | /* The rest are not allowed. */ |
| 388 | ret = -EIO; |
| 389 | break; |
| 390 | } |
| 391 | break; |
| 392 | } |
| 393 | |
Daniel Jacobowitz | ea3d710 | 2005-09-28 18:11:15 -0400 | [diff] [blame] | 394 | case PTRACE_GETREGS: |
| 395 | ret = ptrace_getregs (child, (__u64 __user *) data); |
| 396 | break; |
| 397 | |
| 398 | case PTRACE_SETREGS: |
| 399 | ret = ptrace_setregs (child, (__u64 __user *) data); |
| 400 | break; |
| 401 | |
| 402 | case PTRACE_GETFPREGS: |
| 403 | ret = ptrace_getfpregs (child, (__u32 __user *) data); |
| 404 | break; |
| 405 | |
| 406 | case PTRACE_SETFPREGS: |
| 407 | ret = ptrace_setfpregs (child, (__u32 __user *) data); |
| 408 | break; |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ |
| 411 | case PTRACE_CONT: { /* restart after signal. */ |
| 412 | ret = -EIO; |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 413 | if (!valid_signal(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | break; |
| 415 | if (request == PTRACE_SYSCALL) { |
| 416 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
| 417 | } |
| 418 | else { |
| 419 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
| 420 | } |
| 421 | child->exit_code = data; |
| 422 | wake_up_process(child); |
| 423 | ret = 0; |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * make the child exit. Best I can do is send it a sigkill. |
| 429 | * perhaps it should be put in the status that it wants to |
| 430 | * exit. |
| 431 | */ |
| 432 | case PTRACE_KILL: |
| 433 | ret = 0; |
| 434 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ |
| 435 | break; |
| 436 | child->exit_code = SIGKILL; |
| 437 | wake_up_process(child); |
| 438 | break; |
| 439 | |
| 440 | case PTRACE_DETACH: /* detach a process that was attached. */ |
| 441 | ret = ptrace_detach(child, data); |
| 442 | break; |
| 443 | |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 444 | case PTRACE_GET_THREAD_AREA: |
| 445 | ret = put_user(child->thread_info->tp_value, |
| 446 | (unsigned long __user *) data); |
| 447 | break; |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | default: |
| 450 | ret = ptrace_request(child, request, addr, data); |
| 451 | break; |
| 452 | } |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 453 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | return ret; |
| 455 | } |
| 456 | |
Yoichi Yuasa | 67eb81e | 2005-04-29 16:13:35 +0100 | [diff] [blame] | 457 | static inline int audit_arch(void) |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 458 | { |
Ralf Baechle | f8280c8 | 2005-05-19 12:08:04 +0000 | [diff] [blame] | 459 | int arch = EM_MIPS; |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 460 | #ifdef CONFIG_64BIT |
Ralf Baechle | f8280c8 | 2005-05-19 12:08:04 +0000 | [diff] [blame] | 461 | arch |= __AUDIT_ARCH_64BIT; |
| 462 | #endif |
| 463 | #if defined(__LITTLE_ENDIAN) |
| 464 | arch |= __AUDIT_ARCH_LE; |
| 465 | #endif |
| 466 | return arch; |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | /* |
| 470 | * Notification of system call entry/exit |
| 471 | * - triggered by current->work.syscall_trace |
| 472 | */ |
| 473 | asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit) |
| 474 | { |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 475 | if (unlikely(current->audit_context) && entryexit) |
Ralf Baechle | f8280c8 | 2005-05-19 12:08:04 +0000 | [diff] [blame] | 476 | audit_syscall_exit(current, AUDITSC_RESULT(regs->regs[2]), |
| 477 | regs->regs[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (!(current->ptrace & PT_PTRACED)) |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 480 | goto out; |
Ralf Baechle | f8280c8 | 2005-05-19 12:08:04 +0000 | [diff] [blame] | 481 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
| 482 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | /* The 0x80 provides a way for the tracing parent to distinguish |
| 485 | between a syscall stop and SIGTRAP delivery */ |
| 486 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? |
| 487 | 0x80 : 0)); |
| 488 | |
| 489 | /* |
| 490 | * this isn't the same as continuing with a signal, but it will do |
| 491 | * for normal use. strace only continues with a signal if the |
| 492 | * stopping signal is not SIGTRAP. -brl |
| 493 | */ |
| 494 | if (current->exit_code) { |
| 495 | send_sig(current->exit_code, current, 1); |
| 496 | current->exit_code = 0; |
| 497 | } |
| 2fd6f58 | 2005-04-29 16:08:28 +0100 | [diff] [blame] | 498 | out: |
| 499 | if (unlikely(current->audit_context) && !entryexit) |
| 500 | audit_syscall_entry(current, audit_arch(), regs->regs[2], |
| 501 | regs->regs[4], regs->regs[5], |
| 502 | regs->regs[6], regs->regs[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |