blob: 75bc744a621779de7406592ee73e071635a180a9 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * does not yet catch signals sent when the child dies.
40 * in exit.c or in signal.c.
41 */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +100044 * 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
51
52/*
53 * Max register writeable via put_reg
54 */
55#ifdef CONFIG_PPC32
56#define PT_MAX_PUT_REG PT_MQ
57#else
58#define PT_MAX_PUT_REG PT_CCR
59#endif
60
61/*
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100062 * Get contents of register REGNO in task TASK.
63 */
64unsigned long ptrace_get_reg(struct task_struct *task, int regno)
65{
66 unsigned long tmp = 0;
67
68 if (task->thread.regs == NULL)
69 return -EIO;
70
71 if (regno == PT_MSR) {
72 tmp = ((unsigned long *)task->thread.regs)[PT_MSR];
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +100073 return tmp | task->thread.fpexc_mode;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100074 }
75
76 if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
77 return ((unsigned long *)task->thread.regs)[regno];
78
79 return -EIO;
80}
81
82/*
83 * Write contents of register REGNO in task TASK.
84 */
85int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
86{
87 if (task->thread.regs == NULL)
88 return -EIO;
89
Benjamin Herrenschmidt912000e2007-06-04 15:15:46 +100090 if (regno <= PT_MAX_PUT_REG || regno == PT_TRAP) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100091 if (regno == PT_MSR)
92 data = (data & MSR_DEBUGCHANGE)
93 | (task->thread.regs->msr & ~MSR_DEBUGCHANGE);
Benjamin Herrenschmidt912000e2007-06-04 15:15:46 +100094 /* We prevent mucking around with the reserved area of trap
95 * which are used internally by the kernel
96 */
97 if (regno == PT_TRAP)
98 data &= 0xfff0;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100099 ((unsigned long *)task->thread.regs)[regno] = data;
100 return 0;
101 }
102 return -EIO;
103}
104
105
106static int get_fpregs(void __user *data, struct task_struct *task,
107 int has_fpscr)
108{
109 unsigned int count = has_fpscr ? 33 : 32;
110
111 if (copy_to_user(data, task->thread.fpr, count * sizeof(double)))
112 return -EFAULT;
113 return 0;
114}
115
116static int set_fpregs(void __user *data, struct task_struct *task,
117 int has_fpscr)
118{
119 unsigned int count = has_fpscr ? 33 : 32;
120
121 if (copy_from_user(task->thread.fpr, data, count * sizeof(double)))
122 return -EFAULT;
123 return 0;
124}
125
126
127#ifdef CONFIG_ALTIVEC
128/*
129 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
130 * The transfer totals 34 quadword. Quadwords 0-31 contain the
131 * corresponding vector registers. Quadword 32 contains the vscr as the
132 * last word (offset 12) within that quadword. Quadword 33 contains the
133 * vrsave as the first word (offset 0) within the quadword.
134 *
135 * This definition of the VMX state is compatible with the current PPC32
136 * ptrace interface. This allows signal handling and ptrace to use the
137 * same structures. This also simplifies the implementation of a bi-arch
138 * (combined (32- and 64-bit) gdb.
139 */
140
141/*
142 * Get contents of AltiVec register state in task TASK
143 */
144static int get_vrregs(unsigned long __user *data, struct task_struct *task)
145{
146 unsigned long regsize;
147
148 /* copy AltiVec registers VR[0] .. VR[31] */
149 regsize = 32 * sizeof(vector128);
150 if (copy_to_user(data, task->thread.vr, regsize))
151 return -EFAULT;
152 data += (regsize / sizeof(unsigned long));
153
154 /* copy VSCR */
155 regsize = 1 * sizeof(vector128);
156 if (copy_to_user(data, &task->thread.vscr, regsize))
157 return -EFAULT;
158 data += (regsize / sizeof(unsigned long));
159
160 /* copy VRSAVE */
161 if (put_user(task->thread.vrsave, (u32 __user *)data))
162 return -EFAULT;
163
164 return 0;
165}
166
167/*
168 * Write contents of AltiVec register state into task TASK.
169 */
170static int set_vrregs(struct task_struct *task, unsigned long __user *data)
171{
172 unsigned long regsize;
173
174 /* copy AltiVec registers VR[0] .. VR[31] */
175 regsize = 32 * sizeof(vector128);
176 if (copy_from_user(task->thread.vr, data, regsize))
177 return -EFAULT;
178 data += (regsize / sizeof(unsigned long));
179
180 /* copy VSCR */
181 regsize = 1 * sizeof(vector128);
182 if (copy_from_user(&task->thread.vscr, data, regsize))
183 return -EFAULT;
184 data += (regsize / sizeof(unsigned long));
185
186 /* copy VRSAVE */
187 if (get_user(task->thread.vrsave, (u32 __user *)data))
188 return -EFAULT;
189
190 return 0;
191}
192#endif /* CONFIG_ALTIVEC */
193
194#ifdef CONFIG_SPE
195
196/*
197 * For get_evrregs/set_evrregs functions 'data' has the following layout:
198 *
199 * struct {
200 * u32 evr[32];
201 * u64 acc;
202 * u32 spefscr;
203 * }
204 */
205
206/*
207 * Get contents of SPE register state in task TASK.
208 */
209static int get_evrregs(unsigned long *data, struct task_struct *task)
210{
211 int i;
212
213 if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(unsigned long)))
214 return -EFAULT;
215
216 /* copy SPEFSCR */
217 if (__put_user(task->thread.spefscr, &data[34]))
218 return -EFAULT;
219
220 /* copy SPE registers EVR[0] .. EVR[31] */
221 for (i = 0; i < 32; i++, data++)
222 if (__put_user(task->thread.evr[i], data))
223 return -EFAULT;
224
225 /* copy ACC */
226 if (__put_user64(task->thread.acc, (unsigned long long *)data))
227 return -EFAULT;
228
229 return 0;
230}
231
232/*
233 * Write contents of SPE register state into task TASK.
234 */
235static int set_evrregs(struct task_struct *task, unsigned long *data)
236{
237 int i;
238
239 if (!access_ok(VERIFY_READ, data, 35 * sizeof(unsigned long)))
240 return -EFAULT;
241
242 /* copy SPEFSCR */
243 if (__get_user(task->thread.spefscr, &data[34]))
244 return -EFAULT;
245
246 /* copy SPE registers EVR[0] .. EVR[31] */
247 for (i = 0; i < 32; i++, data++)
248 if (__get_user(task->thread.evr[i], data))
249 return -EFAULT;
250 /* copy ACC */
251 if (__get_user64(task->thread.acc, (unsigned long long*)data))
252 return -EFAULT;
253
254 return 0;
255}
256#endif /* CONFIG_SPE */
257
258
259static void set_single_step(struct task_struct *task)
260{
261 struct pt_regs *regs = task->thread.regs;
262
263 if (regs != NULL) {
264#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
265 task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
266 regs->msr |= MSR_DE;
267#else
268 regs->msr |= MSR_SE;
269#endif
270 }
271 set_tsk_thread_flag(task, TIF_SINGLESTEP);
272}
273
274static void clear_single_step(struct task_struct *task)
275{
276 struct pt_regs *regs = task->thread.regs;
277
278 if (regs != NULL) {
279#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
280 task->thread.dbcr0 = 0;
281 regs->msr &= ~MSR_DE;
282#else
283 regs->msr &= ~MSR_SE;
284#endif
285 }
286 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
287}
288
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000289#ifdef CONFIG_PPC64
290static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
291 unsigned long data)
292{
293 /* We only support one DABR and no IABRS at the moment */
294 if (addr > 0)
295 return -EINVAL;
296
297 /* The bottom 3 bits are flags */
298 if ((data & ~0x7UL) >= TASK_SIZE)
299 return -EIO;
300
301 /* Ensure translation is on */
302 if (data && !(data & DABR_TRANSLATION))
303 return -EIO;
304
305 task->thread.dabr = data;
306 return 0;
307}
308#endif
309
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000310/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 * Called by kernel/ptrace.c when detaching..
312 *
313 * Make sure single step bits etc are not set.
314 */
315void ptrace_disable(struct task_struct *child)
316{
317 /* make sure the single step bit is not set. */
318 clear_single_step(child);
319}
320
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000321/*
322 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
323 * we mark them as obsolete now, they will be removed in a future version
324 */
325static long arch_ptrace_old(struct task_struct *child, long request, long addr,
326 long data)
327{
328 int ret = -EPERM;
329
330 switch(request) {
331 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
332 int i;
333 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
334 unsigned long __user *tmp = (unsigned long __user *)addr;
335
336 for (i = 0; i < 32; i++) {
337 ret = put_user(*reg, tmp);
338 if (ret)
339 break;
340 reg++;
341 tmp++;
342 }
343 break;
344 }
345
346 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
347 int i;
348 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
349 unsigned long __user *tmp = (unsigned long __user *)addr;
350
351 for (i = 0; i < 32; i++) {
352 ret = get_user(*reg, tmp);
353 if (ret)
354 break;
355 reg++;
356 tmp++;
357 }
358 break;
359 }
360
361 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
362 flush_fp_to_thread(child);
363 ret = get_fpregs((void __user *)addr, child, 0);
364 break;
365 }
366
367 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
368 flush_fp_to_thread(child);
369 ret = set_fpregs((void __user *)addr, child, 0);
370 break;
371 }
372
373 }
374 return ret;
375}
376
Christoph Hellwig481bed42005-11-07 00:59:47 -0800377long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 int ret = -EPERM;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 switch (request) {
382 /* when I and D space are separate, these will need to be fixed. */
383 case PTRACE_PEEKTEXT: /* read word at location addr. */
384 case PTRACE_PEEKDATA: {
385 unsigned long tmp;
386 int copied;
387
388 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
389 ret = -EIO;
390 if (copied != sizeof(tmp))
391 break;
392 ret = put_user(tmp,(unsigned long __user *) data);
393 break;
394 }
395
396 /* read the word at location addr in the USER area. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 case PTRACE_PEEKUSR: {
398 unsigned long index, tmp;
399
400 ret = -EIO;
401 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000402#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000404 if ((addr & 3) || (index > PT_FPSCR)
405 || (child->thread.regs == NULL))
406#else
407 index = (unsigned long) addr >> 3;
408 if ((addr & 7) || (index > PT_FPSCR))
409#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 break;
411
412 CHECK_FULL_REGS(child->thread.regs);
413 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000414 tmp = ptrace_get_reg(child, (int) index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000416 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
418 }
419 ret = put_user(tmp,(unsigned long __user *) data);
420 break;
421 }
422
423 /* If I and D space are separate, this will have to be fixed. */
424 case PTRACE_POKETEXT: /* write the word at location addr. */
425 case PTRACE_POKEDATA:
426 ret = 0;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000427 if (access_process_vm(child, addr, &data, sizeof(data), 1)
428 == sizeof(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 break;
430 ret = -EIO;
431 break;
432
433 /* write the word at location addr in the USER area */
434 case PTRACE_POKEUSR: {
435 unsigned long index;
436
437 ret = -EIO;
438 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000439#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000441 if ((addr & 3) || (index > PT_FPSCR)
442 || (child->thread.regs == NULL))
443#else
444 index = (unsigned long) addr >> 3;
445 if ((addr & 7) || (index > PT_FPSCR))
446#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 break;
448
449 CHECK_FULL_REGS(child->thread.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000451 ret = ptrace_put_reg(child, index, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000453 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
455 ret = 0;
456 }
457 break;
458 }
459
460 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
461 case PTRACE_CONT: { /* restart after signal. */
462 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700463 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000465 if (request == PTRACE_SYSCALL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000467 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 child->exit_code = data;
470 /* make sure the single step bit is not set. */
471 clear_single_step(child);
472 wake_up_process(child);
473 ret = 0;
474 break;
475 }
476
477/*
478 * make the child exit. Best I can do is send it a sigkill.
479 * perhaps it should be put in the status that it wants to
480 * exit.
481 */
482 case PTRACE_KILL: {
483 ret = 0;
484 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
485 break;
486 child->exit_code = SIGKILL;
487 /* make sure the single step bit is not set. */
488 clear_single_step(child);
489 wake_up_process(child);
490 break;
491 }
492
493 case PTRACE_SINGLESTEP: { /* set the trap flag. */
494 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700495 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
497 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
498 set_single_step(child);
499 child->exit_code = data;
500 /* give it a chance to run. */
501 wake_up_process(child);
502 ret = 0;
503 break;
504 }
505
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000506#ifdef CONFIG_PPC64
507 case PTRACE_GET_DEBUGREG: {
508 ret = -EINVAL;
509 /* We only support one DABR and no IABRS at the moment */
510 if (addr > 0)
511 break;
512 ret = put_user(child->thread.dabr,
513 (unsigned long __user *)data);
514 break;
515 }
516
517 case PTRACE_SET_DEBUGREG:
518 ret = ptrace_set_debugreg(child, addr, data);
519 break;
520#endif
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 case PTRACE_DETACH:
523 ret = ptrace_detach(child, data);
524 break;
525
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000526#ifdef CONFIG_PPC64
527 case PTRACE_GETREGS64:
528#endif
529 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
530 int ui;
531 if (!access_ok(VERIFY_WRITE, (void __user *)data,
532 sizeof(struct pt_regs))) {
533 ret = -EIO;
534 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000535 }
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000536 ret = 0;
537 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000538 ret |= __put_user(ptrace_get_reg(child, ui),
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000539 (unsigned long __user *) data);
540 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000541 }
542 break;
543 }
544
Benjamin Herrenschmidt0b3d5c42007-06-04 15:15:39 +1000545#ifdef CONFIG_PPC64
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000546 case PTRACE_SETREGS64:
547#endif
548 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
549 unsigned long tmp;
550 int ui;
551 if (!access_ok(VERIFY_READ, (void __user *)data,
552 sizeof(struct pt_regs))) {
553 ret = -EIO;
554 break;
555 }
556 ret = 0;
557 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
558 ret = __get_user(tmp, (unsigned long __user *) data);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000559 if (ret)
560 break;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000561 ptrace_put_reg(child, ui, tmp);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000562 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000563 }
564 break;
565 }
566
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000567 case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000568 flush_fp_to_thread(child);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000569 ret = get_fpregs((void __user *)data, child, 1);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000570 break;
571 }
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000572
573 case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */
574 flush_fp_to_thread(child);
575 ret = set_fpregs((void __user *)data, child, 1);
576 break;
577 }
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#ifdef CONFIG_ALTIVEC
580 case PTRACE_GETVRREGS:
581 /* Get the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000582 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 ret = get_vrregs((unsigned long __user *)data, child);
584 break;
585
586 case PTRACE_SETVRREGS:
587 /* Set the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000588 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 ret = set_vrregs(child, (unsigned long __user *)data);
590 break;
591#endif
592#ifdef CONFIG_SPE
593 case PTRACE_GETEVRREGS:
594 /* Get the child spe register state. */
595 if (child->thread.regs->msr & MSR_SPE)
596 giveup_spe(child);
597 ret = get_evrregs((unsigned long __user *)data, child);
598 break;
599
600 case PTRACE_SETEVRREGS:
601 /* Set the child spe register state. */
602 /* this is to clear the MSR_SPE bit to force a reload
603 * of register state from memory */
604 if (child->thread.regs->msr & MSR_SPE)
605 giveup_spe(child);
606 ret = set_evrregs(child, (unsigned long __user *)data);
607 break;
608#endif
609
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000610 /* Old reverse args ptrace callss */
611 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
612 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
613 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
614 case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
615 ret = arch_ptrace_old(child, request, addr, data);
616 break;
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 default:
619 ret = ptrace_request(child, request, addr, data);
620 break;
621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return ret;
623}
624
David Woodhouseea9c1022005-05-08 15:56:09 +0100625static void do_syscall_trace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
David Woodhouseea9c1022005-05-08 15:56:09 +0100627 /* the 0x80 provides a way for the tracing parent to distinguish
628 between a syscall stop and SIGTRAP delivery */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
630 ? 0x80 : 0));
631
632 /*
633 * this isn't the same as continuing with a signal, but it will do
634 * for normal use. strace only continues with a signal if the
635 * stopping signal is not SIGTRAP. -brl
636 */
637 if (current->exit_code) {
638 send_sig(current->exit_code, current, 1);
639 current->exit_code = 0;
640 }
641}
David Woodhouseea9c1022005-05-08 15:56:09 +0100642
643void do_syscall_trace_enter(struct pt_regs *regs)
644{
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000645 secure_computing(regs->gpr[0]);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000646
David Woodhouseea9c1022005-05-08 15:56:09 +0100647 if (test_thread_flag(TIF_SYSCALL_TRACE)
648 && (current->ptrace & PT_PTRACED))
649 do_syscall_trace();
650
David Woodhousecfcd1702007-01-14 09:38:18 +0800651 if (unlikely(current->audit_context)) {
652#ifdef CONFIG_PPC64
653 if (!test_thread_flag(TIF_32BIT))
654 audit_syscall_entry(AUDIT_ARCH_PPC64,
655 regs->gpr[0],
656 regs->gpr[3], regs->gpr[4],
657 regs->gpr[5], regs->gpr[6]);
658 else
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000659#endif
David Woodhousecfcd1702007-01-14 09:38:18 +0800660 audit_syscall_entry(AUDIT_ARCH_PPC,
661 regs->gpr[0],
662 regs->gpr[3] & 0xffffffff,
663 regs->gpr[4] & 0xffffffff,
664 regs->gpr[5] & 0xffffffff,
665 regs->gpr[6] & 0xffffffff);
666 }
David Woodhouseea9c1022005-05-08 15:56:09 +0100667}
668
669void do_syscall_trace_leave(struct pt_regs *regs)
670{
David Woodhouseea9c1022005-05-08 15:56:09 +0100671 if (unlikely(current->audit_context))
David Woodhouse4b9c8762006-09-22 09:23:53 +0100672 audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
David Woodhouseea9c1022005-05-08 15:56:09 +0100673 regs->result);
674
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000675 if ((test_thread_flag(TIF_SYSCALL_TRACE)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100676 || test_thread_flag(TIF_SINGLESTEP))
David Woodhouseea9c1022005-05-08 15:56:09 +0100677 && (current->ptrace & PT_PTRACED))
678 do_syscall_trace();
679}