blob: f1ce64649256cc491c7e1852cbbad28773fbb52a [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>
Roland McGrathf65255e2007-12-20 03:57:34 -080024#include <linux/regset.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/user.h>
26#include <linux/security.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070027#include <linux/signal.h>
David Woodhouseea9c1022005-05-08 15:56:09 +010028#include <linux/seccomp.h>
29#include <linux/audit.h>
Stephen Rothwelle8a30302005-10-13 15:52:04 +100030#ifdef CONFIG_PPC32
David Woodhouseea9c1022005-05-08 15:56:09 +010031#include <linux/module.h>
Stephen Rothwelle8a30302005-10-13 15:52:04 +100032#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#include <asm/uaccess.h>
35#include <asm/page.h>
36#include <asm/pgtable.h>
37#include <asm/system.h>
Paul Mackerras21a62902005-11-19 20:47:22 +110038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/*
40 * does not yet catch signals sent when the child dies.
41 * in exit.c or in signal.c.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +100045 * Set of msr bits that gdb can change on behalf of a process.
46 */
47#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
48#define MSR_DEBUGCHANGE 0
49#else
50#define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
51#endif
52
53/*
54 * Max register writeable via put_reg
55 */
56#ifdef CONFIG_PPC32
57#define PT_MAX_PUT_REG PT_MQ
58#else
59#define PT_MAX_PUT_REG PT_CCR
60#endif
61
62/*
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100063 * Get contents of register REGNO in task TASK.
64 */
65unsigned long ptrace_get_reg(struct task_struct *task, int regno)
66{
67 unsigned long tmp = 0;
68
69 if (task->thread.regs == NULL)
70 return -EIO;
71
72 if (regno == PT_MSR) {
73 tmp = ((unsigned long *)task->thread.regs)[PT_MSR];
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +100074 return tmp | task->thread.fpexc_mode;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100075 }
76
77 if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
78 return ((unsigned long *)task->thread.regs)[regno];
79
80 return -EIO;
81}
82
83/*
84 * Write contents of register REGNO in task TASK.
85 */
86int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
87{
88 if (task->thread.regs == NULL)
89 return -EIO;
90
Benjamin Herrenschmidt912000e2007-06-04 15:15:46 +100091 if (regno <= PT_MAX_PUT_REG || regno == PT_TRAP) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100092 if (regno == PT_MSR)
93 data = (data & MSR_DEBUGCHANGE)
94 | (task->thread.regs->msr & ~MSR_DEBUGCHANGE);
Benjamin Herrenschmidt912000e2007-06-04 15:15:46 +100095 /* We prevent mucking around with the reserved area of trap
96 * which are used internally by the kernel
97 */
98 if (regno == PT_TRAP)
99 data &= 0xfff0;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000100 ((unsigned long *)task->thread.regs)[regno] = data;
101 return 0;
102 }
103 return -EIO;
104}
105
106
Roland McGrathf65255e2007-12-20 03:57:34 -0800107static int fpr_get(struct task_struct *target, const struct user_regset *regset,
108 unsigned int pos, unsigned int count,
109 void *kbuf, void __user *ubuf)
110{
111 flush_fp_to_thread(target);
112
113 BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
114 offsetof(struct thread_struct, fpr[32]));
115
116 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
117 &target->thread.fpr, 0, -1);
118}
119
120static int fpr_set(struct task_struct *target, const struct user_regset *regset,
121 unsigned int pos, unsigned int count,
122 const void *kbuf, const void __user *ubuf)
123{
124 flush_fp_to_thread(target);
125
126 BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
127 offsetof(struct thread_struct, fpr[32]));
128
129 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
130 &target->thread.fpr, 0, -1);
131}
132
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000133static int get_fpregs(void __user *data, struct task_struct *task,
134 int has_fpscr)
135{
136 unsigned int count = has_fpscr ? 33 : 32;
Roland McGrathf65255e2007-12-20 03:57:34 -0800137 if (!access_ok(VERIFY_WRITE, data, count * sizeof(double)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000138 return -EFAULT;
Roland McGrathf65255e2007-12-20 03:57:34 -0800139 return fpr_get(task, NULL, 0, count * sizeof(double), NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000140}
141
142static int set_fpregs(void __user *data, struct task_struct *task,
143 int has_fpscr)
144{
145 unsigned int count = has_fpscr ? 33 : 32;
Roland McGrathf65255e2007-12-20 03:57:34 -0800146 if (!access_ok(VERIFY_READ, data, count * sizeof(double)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000147 return -EFAULT;
Roland McGrathf65255e2007-12-20 03:57:34 -0800148 return fpr_set(task, NULL, 0, count * sizeof(double), NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000149}
150
151
152#ifdef CONFIG_ALTIVEC
153/*
154 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
155 * The transfer totals 34 quadword. Quadwords 0-31 contain the
156 * corresponding vector registers. Quadword 32 contains the vscr as the
157 * last word (offset 12) within that quadword. Quadword 33 contains the
158 * vrsave as the first word (offset 0) within the quadword.
159 *
160 * This definition of the VMX state is compatible with the current PPC32
161 * ptrace interface. This allows signal handling and ptrace to use the
162 * same structures. This also simplifies the implementation of a bi-arch
163 * (combined (32- and 64-bit) gdb.
164 */
165
166/*
167 * Get contents of AltiVec register state in task TASK
168 */
169static int get_vrregs(unsigned long __user *data, struct task_struct *task)
170{
171 unsigned long regsize;
172
173 /* copy AltiVec registers VR[0] .. VR[31] */
174 regsize = 32 * sizeof(vector128);
175 if (copy_to_user(data, task->thread.vr, regsize))
176 return -EFAULT;
177 data += (regsize / sizeof(unsigned long));
178
179 /* copy VSCR */
180 regsize = 1 * sizeof(vector128);
181 if (copy_to_user(data, &task->thread.vscr, regsize))
182 return -EFAULT;
183 data += (regsize / sizeof(unsigned long));
184
185 /* copy VRSAVE */
186 if (put_user(task->thread.vrsave, (u32 __user *)data))
187 return -EFAULT;
188
189 return 0;
190}
191
192/*
193 * Write contents of AltiVec register state into task TASK.
194 */
195static int set_vrregs(struct task_struct *task, unsigned long __user *data)
196{
197 unsigned long regsize;
198
199 /* copy AltiVec registers VR[0] .. VR[31] */
200 regsize = 32 * sizeof(vector128);
201 if (copy_from_user(task->thread.vr, data, regsize))
202 return -EFAULT;
203 data += (regsize / sizeof(unsigned long));
204
205 /* copy VSCR */
206 regsize = 1 * sizeof(vector128);
207 if (copy_from_user(&task->thread.vscr, data, regsize))
208 return -EFAULT;
209 data += (regsize / sizeof(unsigned long));
210
211 /* copy VRSAVE */
212 if (get_user(task->thread.vrsave, (u32 __user *)data))
213 return -EFAULT;
214
215 return 0;
216}
217#endif /* CONFIG_ALTIVEC */
218
219#ifdef CONFIG_SPE
220
221/*
222 * For get_evrregs/set_evrregs functions 'data' has the following layout:
223 *
224 * struct {
225 * u32 evr[32];
226 * u64 acc;
227 * u32 spefscr;
228 * }
229 */
230
231/*
232 * Get contents of SPE register state in task TASK.
233 */
234static int get_evrregs(unsigned long *data, struct task_struct *task)
235{
236 int i;
237
238 if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(unsigned long)))
239 return -EFAULT;
240
241 /* copy SPEFSCR */
242 if (__put_user(task->thread.spefscr, &data[34]))
243 return -EFAULT;
244
245 /* copy SPE registers EVR[0] .. EVR[31] */
246 for (i = 0; i < 32; i++, data++)
247 if (__put_user(task->thread.evr[i], data))
248 return -EFAULT;
249
250 /* copy ACC */
251 if (__put_user64(task->thread.acc, (unsigned long long *)data))
252 return -EFAULT;
253
254 return 0;
255}
256
257/*
258 * Write contents of SPE register state into task TASK.
259 */
260static int set_evrregs(struct task_struct *task, unsigned long *data)
261{
262 int i;
263
264 if (!access_ok(VERIFY_READ, data, 35 * sizeof(unsigned long)))
265 return -EFAULT;
266
267 /* copy SPEFSCR */
268 if (__get_user(task->thread.spefscr, &data[34]))
269 return -EFAULT;
270
271 /* copy SPE registers EVR[0] .. EVR[31] */
272 for (i = 0; i < 32; i++, data++)
273 if (__get_user(task->thread.evr[i], data))
274 return -EFAULT;
275 /* copy ACC */
276 if (__get_user64(task->thread.acc, (unsigned long long*)data))
277 return -EFAULT;
278
279 return 0;
280}
281#endif /* CONFIG_SPE */
282
283
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100284void user_enable_single_step(struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000285{
286 struct pt_regs *regs = task->thread.regs;
287
288 if (regs != NULL) {
289#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
290 task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
291 regs->msr |= MSR_DE;
292#else
293 regs->msr |= MSR_SE;
294#endif
295 }
296 set_tsk_thread_flag(task, TIF_SINGLESTEP);
297}
298
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100299void user_disable_single_step(struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000300{
301 struct pt_regs *regs = task->thread.regs;
302
303 if (regs != NULL) {
304#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
305 task->thread.dbcr0 = 0;
306 regs->msr &= ~MSR_DE;
307#else
308 regs->msr &= ~MSR_SE;
309#endif
310 }
311 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
312}
313
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000314static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
315 unsigned long data)
316{
317 /* We only support one DABR and no IABRS at the moment */
318 if (addr > 0)
319 return -EINVAL;
320
321 /* The bottom 3 bits are flags */
322 if ((data & ~0x7UL) >= TASK_SIZE)
323 return -EIO;
324
325 /* Ensure translation is on */
326 if (data && !(data & DABR_TRANSLATION))
327 return -EIO;
328
329 task->thread.dabr = data;
330 return 0;
331}
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000332
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000333/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 * Called by kernel/ptrace.c when detaching..
335 *
336 * Make sure single step bits etc are not set.
337 */
338void ptrace_disable(struct task_struct *child)
339{
340 /* make sure the single step bit is not set. */
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100341 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000344/*
345 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
346 * we mark them as obsolete now, they will be removed in a future version
347 */
348static long arch_ptrace_old(struct task_struct *child, long request, long addr,
349 long data)
350{
351 int ret = -EPERM;
352
353 switch(request) {
354 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
355 int i;
356 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
357 unsigned long __user *tmp = (unsigned long __user *)addr;
358
Roland McGrathfabca2c2007-09-25 09:50:52 +1000359 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000360 for (i = 0; i < 32; i++) {
361 ret = put_user(*reg, tmp);
362 if (ret)
363 break;
364 reg++;
365 tmp++;
366 }
367 break;
368 }
369
370 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
371 int i;
372 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
373 unsigned long __user *tmp = (unsigned long __user *)addr;
374
Roland McGrathfabca2c2007-09-25 09:50:52 +1000375 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000376 for (i = 0; i < 32; i++) {
377 ret = get_user(*reg, tmp);
378 if (ret)
379 break;
380 reg++;
381 tmp++;
382 }
383 break;
384 }
385
386 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
387 flush_fp_to_thread(child);
388 ret = get_fpregs((void __user *)addr, child, 0);
389 break;
390 }
391
392 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
393 flush_fp_to_thread(child);
394 ret = set_fpregs((void __user *)addr, child, 0);
395 break;
396 }
397
398 }
399 return ret;
400}
401
Christoph Hellwig481bed42005-11-07 00:59:47 -0800402long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 int ret = -EPERM;
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 switch (request) {
407 /* when I and D space are separate, these will need to be fixed. */
408 case PTRACE_PEEKTEXT: /* read word at location addr. */
Alexey Dobriyan76647322007-07-17 04:03:43 -0700409 case PTRACE_PEEKDATA:
410 ret = generic_ptrace_peekdata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /* read the word at location addr in the USER area. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 case PTRACE_PEEKUSR: {
415 unsigned long index, tmp;
416
417 ret = -EIO;
418 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000419#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000421 if ((addr & 3) || (index > PT_FPSCR)
422 || (child->thread.regs == NULL))
423#else
424 index = (unsigned long) addr >> 3;
425 if ((addr & 7) || (index > PT_FPSCR))
426#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 break;
428
429 CHECK_FULL_REGS(child->thread.regs);
430 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000431 tmp = ptrace_get_reg(child, (int) index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000433 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
435 }
436 ret = put_user(tmp,(unsigned long __user *) data);
437 break;
438 }
439
440 /* If I and D space are separate, this will have to be fixed. */
441 case PTRACE_POKETEXT: /* write the word at location addr. */
442 case PTRACE_POKEDATA:
Alexey Dobriyanf284ce72007-07-17 04:03:44 -0700443 ret = generic_ptrace_pokedata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 break;
445
446 /* write the word at location addr in the USER area */
447 case PTRACE_POKEUSR: {
448 unsigned long index;
449
450 ret = -EIO;
451 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000452#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000454 if ((addr & 3) || (index > PT_FPSCR)
455 || (child->thread.regs == NULL))
456#else
457 index = (unsigned long) addr >> 3;
458 if ((addr & 7) || (index > PT_FPSCR))
459#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 break;
461
462 CHECK_FULL_REGS(child->thread.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000464 ret = ptrace_put_reg(child, index, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000466 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
468 ret = 0;
469 }
470 break;
471 }
472
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000473 case PTRACE_GET_DEBUGREG: {
474 ret = -EINVAL;
475 /* We only support one DABR and no IABRS at the moment */
476 if (addr > 0)
477 break;
478 ret = put_user(child->thread.dabr,
479 (unsigned long __user *)data);
480 break;
481 }
482
483 case PTRACE_SET_DEBUGREG:
484 ret = ptrace_set_debugreg(child, addr, data);
485 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000486
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000487#ifdef CONFIG_PPC64
488 case PTRACE_GETREGS64:
489#endif
490 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
491 int ui;
492 if (!access_ok(VERIFY_WRITE, (void __user *)data,
493 sizeof(struct pt_regs))) {
494 ret = -EIO;
495 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000496 }
Roland McGrathfabca2c2007-09-25 09:50:52 +1000497 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000498 ret = 0;
499 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000500 ret |= __put_user(ptrace_get_reg(child, ui),
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000501 (unsigned long __user *) data);
502 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000503 }
504 break;
505 }
506
Benjamin Herrenschmidt0b3d5c42007-06-04 15:15:39 +1000507#ifdef CONFIG_PPC64
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000508 case PTRACE_SETREGS64:
509#endif
510 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
511 unsigned long tmp;
512 int ui;
513 if (!access_ok(VERIFY_READ, (void __user *)data,
514 sizeof(struct pt_regs))) {
515 ret = -EIO;
516 break;
517 }
Roland McGrathfabca2c2007-09-25 09:50:52 +1000518 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000519 ret = 0;
520 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
521 ret = __get_user(tmp, (unsigned long __user *) data);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000522 if (ret)
523 break;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000524 ptrace_put_reg(child, ui, tmp);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000525 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000526 }
527 break;
528 }
529
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000530 case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000531 flush_fp_to_thread(child);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000532 ret = get_fpregs((void __user *)data, child, 1);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000533 break;
534 }
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000535
536 case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */
537 flush_fp_to_thread(child);
538 ret = set_fpregs((void __user *)data, child, 1);
539 break;
540 }
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#ifdef CONFIG_ALTIVEC
543 case PTRACE_GETVRREGS:
544 /* Get the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000545 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 ret = get_vrregs((unsigned long __user *)data, child);
547 break;
548
549 case PTRACE_SETVRREGS:
550 /* Set the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000551 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 ret = set_vrregs(child, (unsigned long __user *)data);
553 break;
554#endif
555#ifdef CONFIG_SPE
556 case PTRACE_GETEVRREGS:
557 /* Get the child spe register state. */
Kumar Gala5e14d212007-09-13 01:44:20 -0500558 flush_spe_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 ret = get_evrregs((unsigned long __user *)data, child);
560 break;
561
562 case PTRACE_SETEVRREGS:
563 /* Set the child spe register state. */
564 /* this is to clear the MSR_SPE bit to force a reload
565 * of register state from memory */
Kumar Gala5e14d212007-09-13 01:44:20 -0500566 flush_spe_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 ret = set_evrregs(child, (unsigned long __user *)data);
568 break;
569#endif
570
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000571 /* Old reverse args ptrace callss */
572 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
573 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
574 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
575 case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
576 ret = arch_ptrace_old(child, request, addr, data);
577 break;
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 default:
580 ret = ptrace_request(child, request, addr, data);
581 break;
582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 return ret;
584}
585
David Woodhouseea9c1022005-05-08 15:56:09 +0100586static void do_syscall_trace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
David Woodhouseea9c1022005-05-08 15:56:09 +0100588 /* the 0x80 provides a way for the tracing parent to distinguish
589 between a syscall stop and SIGTRAP delivery */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
591 ? 0x80 : 0));
592
593 /*
594 * this isn't the same as continuing with a signal, but it will do
595 * for normal use. strace only continues with a signal if the
596 * stopping signal is not SIGTRAP. -brl
597 */
598 if (current->exit_code) {
599 send_sig(current->exit_code, current, 1);
600 current->exit_code = 0;
601 }
602}
David Woodhouseea9c1022005-05-08 15:56:09 +0100603
604void do_syscall_trace_enter(struct pt_regs *regs)
605{
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000606 secure_computing(regs->gpr[0]);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000607
David Woodhouseea9c1022005-05-08 15:56:09 +0100608 if (test_thread_flag(TIF_SYSCALL_TRACE)
609 && (current->ptrace & PT_PTRACED))
610 do_syscall_trace();
611
David Woodhousecfcd1702007-01-14 09:38:18 +0800612 if (unlikely(current->audit_context)) {
613#ifdef CONFIG_PPC64
614 if (!test_thread_flag(TIF_32BIT))
615 audit_syscall_entry(AUDIT_ARCH_PPC64,
616 regs->gpr[0],
617 regs->gpr[3], regs->gpr[4],
618 regs->gpr[5], regs->gpr[6]);
619 else
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000620#endif
David Woodhousecfcd1702007-01-14 09:38:18 +0800621 audit_syscall_entry(AUDIT_ARCH_PPC,
622 regs->gpr[0],
623 regs->gpr[3] & 0xffffffff,
624 regs->gpr[4] & 0xffffffff,
625 regs->gpr[5] & 0xffffffff,
626 regs->gpr[6] & 0xffffffff);
627 }
David Woodhouseea9c1022005-05-08 15:56:09 +0100628}
629
630void do_syscall_trace_leave(struct pt_regs *regs)
631{
David Woodhouseea9c1022005-05-08 15:56:09 +0100632 if (unlikely(current->audit_context))
David Woodhouse4b9c8762006-09-22 09:23:53 +0100633 audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
David Woodhouseea9c1022005-05-08 15:56:09 +0100634 regs->result);
635
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000636 if ((test_thread_flag(TIF_SYSCALL_TRACE)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100637 || test_thread_flag(TIF_SINGLESTEP))
David Woodhouseea9c1022005-05-08 15:56:09 +0100638 && (current->ptrace & PT_PTRACED))
639 do_syscall_trace();
640}