blob: 875bfda90b21f44f9ee4d6cc4cc978824c800901 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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 Mackerrasb1239232005-10-20 09:11:29 +100011 * and Paul Mackerras (paulus@samba.org).
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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 Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/errno.h>
23#include <linux/ptrace.h>
24#include <linux/user.h>
25#include <linux/security.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070026#include <linux/signal.h>
David Woodhouseea9c1022005-05-08 15:56:09 +010027#include <linux/seccomp.h>
28#include <linux/audit.h>
Stephen Rothwelle8a30302005-10-13 15:52:04 +100029#ifdef CONFIG_PPC32
David Woodhouseea9c1022005-05-08 15:56:09 +010030#include <linux/module.h>
Stephen Rothwelle8a30302005-10-13 15:52:04 +100031#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include <asm/uaccess.h>
34#include <asm/page.h>
35#include <asm/pgtable.h>
36#include <asm/system.h>
Paul Mackerras21a62902005-11-19 20:47:22 +110037
Stephen Rothwelle8a30302005-10-13 15:52:04 +100038#ifdef CONFIG_PPC64
Benjamin Herrenschmidtacd89822007-06-04 15:15:41 +100039#include "ptrace-ppc64.h"
40#else
41#include "ptrace-ppc32.h"
Stephen Rothwelle8a30302005-10-13 15:52:04 +100042#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*
45 * does not yet catch signals sent when the child dies.
46 * in exit.c or in signal.c.
47 */
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/*
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100050 * Get contents of register REGNO in task TASK.
51 */
52unsigned 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 */
73int 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
89static 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
99static 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 */
127static 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 */
153static 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 */
192static 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 */
218static 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
242static 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
257static 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 Torvalds1da177e2005-04-16 15:20:36 -0700273 * Called by kernel/ptrace.c when detaching..
274 *
275 * Make sure single step bits etc are not set.
276 */
277void 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 Herrenschmidte17666b2007-06-04 15:15:43 +1000283/*
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 */
287static 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 Hellwig481bed42005-11-07 00:59:47 -0800339long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 int ret = -EPERM;
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 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 Torvalds1da177e2005-04-16 15:20:36 -0700359 case PTRACE_PEEKUSR: {
360 unsigned long index, tmp;
361
362 ret = -EIO;
363 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000364#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000366 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 Torvalds1da177e2005-04-16 15:20:36 -0700372 break;
373
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000374#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 CHECK_FULL_REGS(child->thread.regs);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000376#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000378 tmp = ptrace_get_reg(child, (int) index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000380 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 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 Rothwelle8a30302005-10-13 15:52:04 +1000391 if (access_process_vm(child, addr, &data, sizeof(data), 1)
392 == sizeof(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 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 Rothwelle8a30302005-10-13 15:52:04 +1000403#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000405 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 Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
412
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000413#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 CHECK_FULL_REGS(child->thread.regs);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000415#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (index == PT_ORIG_R3)
417 break;
418 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000419 ret = ptrace_put_reg(child, index, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000421 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 ((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 Juhl7ed20e12005-05-01 08:59:14 -0700431 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000433 if (request == PTRACE_SYSCALL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000435 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 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 Juhl7ed20e12005-05-01 08:59:14 -0700463 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 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 Rothwelle8a30302005-10-13 15:52:04 +1000474#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 Torvalds1da177e2005-04-16 15:20:36 -0700490 case PTRACE_DETACH:
491 ret = ptrace_detach(child, data);
492 break;
493
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000494#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 Rothwelle8a30302005-10-13 15:52:04 +1000503 }
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000504 ret = 0;
505 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000506 ret |= __put_user(ptrace_get_reg(child, ui),
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000507 (unsigned long __user *) data);
508 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000509 }
510 break;
511 }
512
Benjamin Herrenschmidt0b3d5c42007-06-04 15:15:39 +1000513#ifdef CONFIG_PPC64
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000514 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 Rothwelle8a30302005-10-13 15:52:04 +1000527 if (ret)
528 break;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000529 ptrace_put_reg(child, ui, tmp);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000530 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000531 }
532 break;
533 }
534
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000535 case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000536 flush_fp_to_thread(child);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000537 ret = get_fpregs((void __user *)data, child, 1);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000538 break;
539 }
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000540
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 Rothwelle8a30302005-10-13 15:52:04 +1000546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#ifdef CONFIG_ALTIVEC
548 case PTRACE_GETVRREGS:
549 /* Get the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000550 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 ret = get_vrregs((unsigned long __user *)data, child);
552 break;
553
554 case PTRACE_SETVRREGS:
555 /* Set the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000556 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 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 Herrenschmidte17666b2007-06-04 15:15:43 +1000578 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700586 default:
587 ret = ptrace_request(child, request, addr, data);
588 break;
589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return ret;
591}
592
David Woodhouseea9c1022005-05-08 15:56:09 +0100593static void do_syscall_trace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
David Woodhouseea9c1022005-05-08 15:56:09 +0100595 /* the 0x80 provides a way for the tracing parent to distinguish
596 between a syscall stop and SIGTRAP delivery */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 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 Woodhouseea9c1022005-05-08 15:56:09 +0100610
611void do_syscall_trace_enter(struct pt_regs *regs)
612{
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000613 secure_computing(regs->gpr[0]);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000614
David Woodhouseea9c1022005-05-08 15:56:09 +0100615 if (test_thread_flag(TIF_SYSCALL_TRACE)
616 && (current->ptrace & PT_PTRACED))
617 do_syscall_trace();
618
David Woodhousecfcd1702007-01-14 09:38:18 +0800619 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 Rothwelle8a30302005-10-13 15:52:04 +1000627#endif
David Woodhousecfcd1702007-01-14 09:38:18 +0800628 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 Woodhouseea9c1022005-05-08 15:56:09 +0100635}
636
637void do_syscall_trace_leave(struct pt_regs *regs)
638{
David Woodhouseea9c1022005-05-08 15:56:09 +0100639 if (unlikely(current->audit_context))
David Woodhouse4b9c8762006-09-22 09:23:53 +0100640 audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
David Woodhouseea9c1022005-05-08 15:56:09 +0100641 regs->result);
642
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000643 if ((test_thread_flag(TIF_SYSCALL_TRACE)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100644 || test_thread_flag(TIF_SINGLESTEP))
David Woodhouseea9c1022005-05-08 15:56:09 +0100645 && (current->ptrace & PT_PTRACED))
646 do_syscall_trace();
647}