blob: 8c25b003365080bba3c5944bbfc94aaefdf8b18e [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>
Roland McGrath3caf06c2007-12-20 03:57:39 -080025#include <linux/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/user.h>
27#include <linux/security.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070028#include <linux/signal.h>
David Woodhouseea9c1022005-05-08 15:56:09 +010029#include <linux/seccomp.h>
30#include <linux/audit.h>
Stephen Rothwelle8a30302005-10-13 15:52:04 +100031#ifdef CONFIG_PPC32
David Woodhouseea9c1022005-05-08 15:56:09 +010032#include <linux/module.h>
Stephen Rothwelle8a30302005-10-13 15:52:04 +100033#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#include <asm/uaccess.h>
36#include <asm/page.h>
37#include <asm/pgtable.h>
38#include <asm/system.h>
Paul Mackerras21a62902005-11-19 20:47:22 +110039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/*
41 * does not yet catch signals sent when the child dies.
42 * in exit.c or in signal.c.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +100046 * Set of msr bits that gdb can change on behalf of a process.
47 */
48#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
49#define MSR_DEBUGCHANGE 0
50#else
51#define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
52#endif
53
54/*
55 * Max register writeable via put_reg
56 */
57#ifdef CONFIG_PPC32
58#define PT_MAX_PUT_REG PT_MQ
59#else
60#define PT_MAX_PUT_REG PT_CCR
61#endif
62
63/*
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100064 * Get contents of register REGNO in task TASK.
65 */
66unsigned long ptrace_get_reg(struct task_struct *task, int regno)
67{
68 unsigned long tmp = 0;
69
70 if (task->thread.regs == NULL)
71 return -EIO;
72
73 if (regno == PT_MSR) {
74 tmp = ((unsigned long *)task->thread.regs)[PT_MSR];
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +100075 return tmp | task->thread.fpexc_mode;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100076 }
77
78 if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
79 return ((unsigned long *)task->thread.regs)[regno];
80
81 return -EIO;
82}
83
84/*
85 * Write contents of register REGNO in task TASK.
86 */
87int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
88{
89 if (task->thread.regs == NULL)
90 return -EIO;
91
Benjamin Herrenschmidt912000e2007-06-04 15:15:46 +100092 if (regno <= PT_MAX_PUT_REG || regno == PT_TRAP) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +100093 if (regno == PT_MSR)
94 data = (data & MSR_DEBUGCHANGE)
95 | (task->thread.regs->msr & ~MSR_DEBUGCHANGE);
Benjamin Herrenschmidt912000e2007-06-04 15:15:46 +100096 /* We prevent mucking around with the reserved area of trap
97 * which are used internally by the kernel
98 */
99 if (regno == PT_TRAP)
100 data &= 0xfff0;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000101 ((unsigned long *)task->thread.regs)[regno] = data;
102 return 0;
103 }
104 return -EIO;
105}
106
107
Roland McGrathf65255e2007-12-20 03:57:34 -0800108static int fpr_get(struct task_struct *target, const struct user_regset *regset,
109 unsigned int pos, unsigned int count,
110 void *kbuf, void __user *ubuf)
111{
112 flush_fp_to_thread(target);
113
114 BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
115 offsetof(struct thread_struct, fpr[32]));
116
117 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
118 &target->thread.fpr, 0, -1);
119}
120
121static int fpr_set(struct task_struct *target, const struct user_regset *regset,
122 unsigned int pos, unsigned int count,
123 const void *kbuf, const void __user *ubuf)
124{
125 flush_fp_to_thread(target);
126
127 BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
128 offsetof(struct thread_struct, fpr[32]));
129
130 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
131 &target->thread.fpr, 0, -1);
132}
133
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000134static int get_fpregs(void __user *data, struct task_struct *task,
135 int has_fpscr)
136{
137 unsigned int count = has_fpscr ? 33 : 32;
Roland McGrathf65255e2007-12-20 03:57:34 -0800138 if (!access_ok(VERIFY_WRITE, data, count * sizeof(double)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000139 return -EFAULT;
Roland McGrathf65255e2007-12-20 03:57:34 -0800140 return fpr_get(task, NULL, 0, count * sizeof(double), NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000141}
142
143static int set_fpregs(void __user *data, struct task_struct *task,
144 int has_fpscr)
145{
146 unsigned int count = has_fpscr ? 33 : 32;
Roland McGrathf65255e2007-12-20 03:57:34 -0800147 if (!access_ok(VERIFY_READ, data, count * sizeof(double)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000148 return -EFAULT;
Roland McGrathf65255e2007-12-20 03:57:34 -0800149 return fpr_set(task, NULL, 0, count * sizeof(double), NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000150}
151
152
153#ifdef CONFIG_ALTIVEC
154/*
155 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
156 * The transfer totals 34 quadword. Quadwords 0-31 contain the
157 * corresponding vector registers. Quadword 32 contains the vscr as the
158 * last word (offset 12) within that quadword. Quadword 33 contains the
159 * vrsave as the first word (offset 0) within the quadword.
160 *
161 * This definition of the VMX state is compatible with the current PPC32
162 * ptrace interface. This allows signal handling and ptrace to use the
163 * same structures. This also simplifies the implementation of a bi-arch
164 * (combined (32- and 64-bit) gdb.
165 */
166
Roland McGrath3caf06c2007-12-20 03:57:39 -0800167static int vr_active(struct task_struct *target,
168 const struct user_regset *regset)
169{
170 flush_altivec_to_thread(target);
171 return target->thread.used_vr ? regset->n : 0;
172}
173
174static int vr_get(struct task_struct *target, const struct user_regset *regset,
175 unsigned int pos, unsigned int count,
176 void *kbuf, void __user *ubuf)
177{
178 int ret;
179
180 flush_altivec_to_thread(target);
181
182 BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
183 offsetof(struct thread_struct, vr[32]));
184
185 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
186 &target->thread.vr, 0,
187 33 * sizeof(vector128));
188 if (!ret) {
189 /*
190 * Copy out only the low-order word of vrsave.
191 */
192 union {
193 elf_vrreg_t reg;
194 u32 word;
195 } vrsave;
196 memset(&vrsave, 0, sizeof(vrsave));
197 vrsave.word = target->thread.vrsave;
198 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
199 33 * sizeof(vector128), -1);
200 }
201
202 return ret;
203}
204
205static int vr_set(struct task_struct *target, const struct user_regset *regset,
206 unsigned int pos, unsigned int count,
207 const void *kbuf, const void __user *ubuf)
208{
209 int ret;
210
211 flush_altivec_to_thread(target);
212
213 BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
214 offsetof(struct thread_struct, vr[32]));
215
216 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
217 &target->thread.vr, 0, 33 * sizeof(vector128));
218 if (!ret && count > 0) {
219 /*
220 * We use only the first word of vrsave.
221 */
222 union {
223 elf_vrreg_t reg;
224 u32 word;
225 } vrsave;
226 memset(&vrsave, 0, sizeof(vrsave));
227 vrsave.word = target->thread.vrsave;
228 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
229 33 * sizeof(vector128), -1);
230 if (!ret)
231 target->thread.vrsave = vrsave.word;
232 }
233
234 return ret;
235}
236
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000237/*
238 * Get contents of AltiVec register state in task TASK
239 */
240static int get_vrregs(unsigned long __user *data, struct task_struct *task)
241{
Roland McGrath3caf06c2007-12-20 03:57:39 -0800242 if (!access_ok(VERIFY_WRITE, data,
243 33 * sizeof(vector128) + sizeof(u32)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000244 return -EFAULT;
245
Roland McGrath3caf06c2007-12-20 03:57:39 -0800246 return vr_get(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32),
247 NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000248}
249
250/*
251 * Write contents of AltiVec register state into task TASK.
252 */
253static int set_vrregs(struct task_struct *task, unsigned long __user *data)
254{
Roland McGrath3caf06c2007-12-20 03:57:39 -0800255 if (!access_ok(VERIFY_READ, data, 33 * sizeof(vector128) + sizeof(u32)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000256 return -EFAULT;
257
Roland McGrath3caf06c2007-12-20 03:57:39 -0800258 return vr_set(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32),
259 NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000260}
261#endif /* CONFIG_ALTIVEC */
262
263#ifdef CONFIG_SPE
264
265/*
266 * For get_evrregs/set_evrregs functions 'data' has the following layout:
267 *
268 * struct {
269 * u32 evr[32];
270 * u64 acc;
271 * u32 spefscr;
272 * }
273 */
274
Roland McGratha4e4b172007-12-20 03:57:48 -0800275static int evr_active(struct task_struct *target,
276 const struct user_regset *regset)
277{
278 flush_spe_to_thread(target);
279 return target->thread.used_spe ? regset->n : 0;
280}
281
282static int evr_get(struct task_struct *target, const struct user_regset *regset,
283 unsigned int pos, unsigned int count,
284 void *kbuf, void __user *ubuf)
285{
286 int ret;
287
288 flush_spe_to_thread(target);
289
290 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
291 &target->thread.evr,
292 0, sizeof(target->thread.evr));
293
294 BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
295 offsetof(struct thread_struct, spefscr));
296
297 if (!ret)
298 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
299 &target->thread.acc,
300 sizeof(target->thread.evr), -1);
301
302 return ret;
303}
304
305static int evr_set(struct task_struct *target, const struct user_regset *regset,
306 unsigned int pos, unsigned int count,
307 const void *kbuf, const void __user *ubuf)
308{
309 int ret;
310
311 flush_spe_to_thread(target);
312
313 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
314 &target->thread.evr,
315 0, sizeof(target->thread.evr));
316
317 BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
318 offsetof(struct thread_struct, spefscr));
319
320 if (!ret)
321 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
322 &target->thread.acc,
323 sizeof(target->thread.evr), -1);
324
325 return ret;
326}
327
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000328/*
329 * Get contents of SPE register state in task TASK.
330 */
Roland McGratha4e4b172007-12-20 03:57:48 -0800331static int get_evrregs(unsigned long __user *data, struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000332{
Roland McGratha4e4b172007-12-20 03:57:48 -0800333 if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(u32)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000334 return -EFAULT;
335
Roland McGratha4e4b172007-12-20 03:57:48 -0800336 return evr_get(task, NULL, 0, 35 * sizeof(u32), NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000337}
338
339/*
340 * Write contents of SPE register state into task TASK.
341 */
342static int set_evrregs(struct task_struct *task, unsigned long *data)
343{
Roland McGratha4e4b172007-12-20 03:57:48 -0800344 if (!access_ok(VERIFY_READ, data, 35 * sizeof(u32)))
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000345 return -EFAULT;
346
Roland McGratha4e4b172007-12-20 03:57:48 -0800347 return evr_set(task, NULL, 0, 35 * sizeof(u32), NULL, data);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000348}
349#endif /* CONFIG_SPE */
350
351
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100352void user_enable_single_step(struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000353{
354 struct pt_regs *regs = task->thread.regs;
355
356 if (regs != NULL) {
357#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
358 task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
359 regs->msr |= MSR_DE;
360#else
361 regs->msr |= MSR_SE;
362#endif
363 }
364 set_tsk_thread_flag(task, TIF_SINGLESTEP);
365}
366
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100367void user_disable_single_step(struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000368{
369 struct pt_regs *regs = task->thread.regs;
370
371 if (regs != NULL) {
372#if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
373 task->thread.dbcr0 = 0;
374 regs->msr &= ~MSR_DE;
375#else
376 regs->msr &= ~MSR_SE;
377#endif
378 }
379 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
380}
381
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000382static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
383 unsigned long data)
384{
385 /* We only support one DABR and no IABRS at the moment */
386 if (addr > 0)
387 return -EINVAL;
388
389 /* The bottom 3 bits are flags */
390 if ((data & ~0x7UL) >= TASK_SIZE)
391 return -EIO;
392
393 /* Ensure translation is on */
394 if (data && !(data & DABR_TRANSLATION))
395 return -EIO;
396
397 task->thread.dabr = data;
398 return 0;
399}
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000400
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000401/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 * Called by kernel/ptrace.c when detaching..
403 *
404 * Make sure single step bits etc are not set.
405 */
406void ptrace_disable(struct task_struct *child)
407{
408 /* make sure the single step bit is not set. */
Roland McGrath2a84b0d2008-01-30 13:30:51 +0100409 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000412/*
413 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
414 * we mark them as obsolete now, they will be removed in a future version
415 */
416static long arch_ptrace_old(struct task_struct *child, long request, long addr,
417 long data)
418{
419 int ret = -EPERM;
420
421 switch(request) {
422 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
423 int i;
424 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
425 unsigned long __user *tmp = (unsigned long __user *)addr;
426
Roland McGrathfabca2c2007-09-25 09:50:52 +1000427 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000428 for (i = 0; i < 32; i++) {
429 ret = put_user(*reg, tmp);
430 if (ret)
431 break;
432 reg++;
433 tmp++;
434 }
435 break;
436 }
437
438 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
439 int i;
440 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
441 unsigned long __user *tmp = (unsigned long __user *)addr;
442
Roland McGrathfabca2c2007-09-25 09:50:52 +1000443 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000444 for (i = 0; i < 32; i++) {
445 ret = get_user(*reg, tmp);
446 if (ret)
447 break;
448 reg++;
449 tmp++;
450 }
451 break;
452 }
453
454 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
455 flush_fp_to_thread(child);
456 ret = get_fpregs((void __user *)addr, child, 0);
457 break;
458 }
459
460 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
461 flush_fp_to_thread(child);
462 ret = set_fpregs((void __user *)addr, child, 0);
463 break;
464 }
465
466 }
467 return ret;
468}
469
Christoph Hellwig481bed42005-11-07 00:59:47 -0800470long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 int ret = -EPERM;
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 switch (request) {
475 /* when I and D space are separate, these will need to be fixed. */
476 case PTRACE_PEEKTEXT: /* read word at location addr. */
Alexey Dobriyan76647322007-07-17 04:03:43 -0700477 case PTRACE_PEEKDATA:
478 ret = generic_ptrace_peekdata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 /* read the word at location addr in the USER area. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 case PTRACE_PEEKUSR: {
483 unsigned long index, tmp;
484
485 ret = -EIO;
486 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000487#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000489 if ((addr & 3) || (index > PT_FPSCR)
490 || (child->thread.regs == NULL))
491#else
492 index = (unsigned long) addr >> 3;
493 if ((addr & 7) || (index > PT_FPSCR))
494#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 break;
496
497 CHECK_FULL_REGS(child->thread.regs);
498 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000499 tmp = ptrace_get_reg(child, (int) index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000501 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
503 }
504 ret = put_user(tmp,(unsigned long __user *) data);
505 break;
506 }
507
508 /* If I and D space are separate, this will have to be fixed. */
509 case PTRACE_POKETEXT: /* write the word at location addr. */
510 case PTRACE_POKEDATA:
Alexey Dobriyanf284ce72007-07-17 04:03:44 -0700511 ret = generic_ptrace_pokedata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 break;
513
514 /* write the word at location addr in the USER area */
515 case PTRACE_POKEUSR: {
516 unsigned long index;
517
518 ret = -EIO;
519 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000520#ifdef CONFIG_PPC32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 index = (unsigned long) addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000522 if ((addr & 3) || (index > PT_FPSCR)
523 || (child->thread.regs == NULL))
524#else
525 index = (unsigned long) addr >> 3;
526 if ((addr & 7) || (index > PT_FPSCR))
527#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529
530 CHECK_FULL_REGS(child->thread.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000532 ret = ptrace_put_reg(child, index, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 } else {
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000534 flush_fp_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
536 ret = 0;
537 }
538 break;
539 }
540
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000541 case PTRACE_GET_DEBUGREG: {
542 ret = -EINVAL;
543 /* We only support one DABR and no IABRS at the moment */
544 if (addr > 0)
545 break;
546 ret = put_user(child->thread.dabr,
547 (unsigned long __user *)data);
548 break;
549 }
550
551 case PTRACE_SET_DEBUGREG:
552 ret = ptrace_set_debugreg(child, addr, data);
553 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000554
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000555#ifdef CONFIG_PPC64
556 case PTRACE_GETREGS64:
557#endif
558 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
559 int ui;
560 if (!access_ok(VERIFY_WRITE, (void __user *)data,
561 sizeof(struct pt_regs))) {
562 ret = -EIO;
563 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000564 }
Roland McGrathfabca2c2007-09-25 09:50:52 +1000565 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000566 ret = 0;
567 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000568 ret |= __put_user(ptrace_get_reg(child, ui),
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000569 (unsigned long __user *) data);
570 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000571 }
572 break;
573 }
574
Benjamin Herrenschmidt0b3d5c42007-06-04 15:15:39 +1000575#ifdef CONFIG_PPC64
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000576 case PTRACE_SETREGS64:
577#endif
578 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
579 unsigned long tmp;
580 int ui;
581 if (!access_ok(VERIFY_READ, (void __user *)data,
582 sizeof(struct pt_regs))) {
583 ret = -EIO;
584 break;
585 }
Roland McGrathfabca2c2007-09-25 09:50:52 +1000586 CHECK_FULL_REGS(child->thread.regs);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000587 ret = 0;
588 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
589 ret = __get_user(tmp, (unsigned long __user *) data);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000590 if (ret)
591 break;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000592 ptrace_put_reg(child, ui, tmp);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000593 data += sizeof(long);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000594 }
595 break;
596 }
597
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000598 case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000599 flush_fp_to_thread(child);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000600 ret = get_fpregs((void __user *)data, child, 1);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000601 break;
602 }
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000603
604 case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */
605 flush_fp_to_thread(child);
606 ret = set_fpregs((void __user *)data, child, 1);
607 break;
608 }
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#ifdef CONFIG_ALTIVEC
611 case PTRACE_GETVRREGS:
612 /* Get the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000613 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 ret = get_vrregs((unsigned long __user *)data, child);
615 break;
616
617 case PTRACE_SETVRREGS:
618 /* Set the child altivec register state. */
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000619 flush_altivec_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 ret = set_vrregs(child, (unsigned long __user *)data);
621 break;
622#endif
623#ifdef CONFIG_SPE
624 case PTRACE_GETEVRREGS:
625 /* Get the child spe register state. */
Kumar Gala5e14d212007-09-13 01:44:20 -0500626 flush_spe_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 ret = get_evrregs((unsigned long __user *)data, child);
628 break;
629
630 case PTRACE_SETEVRREGS:
631 /* Set the child spe register state. */
632 /* this is to clear the MSR_SPE bit to force a reload
633 * of register state from memory */
Kumar Gala5e14d212007-09-13 01:44:20 -0500634 flush_spe_to_thread(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 ret = set_evrregs(child, (unsigned long __user *)data);
636 break;
637#endif
638
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +1000639 /* Old reverse args ptrace callss */
640 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
641 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
642 case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
643 case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
644 ret = arch_ptrace_old(child, request, addr, data);
645 break;
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 default:
648 ret = ptrace_request(child, request, addr, data);
649 break;
650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 return ret;
652}
653
David Woodhouseea9c1022005-05-08 15:56:09 +0100654static void do_syscall_trace(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
David Woodhouseea9c1022005-05-08 15:56:09 +0100656 /* the 0x80 provides a way for the tracing parent to distinguish
657 between a syscall stop and SIGTRAP delivery */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
659 ? 0x80 : 0));
660
661 /*
662 * this isn't the same as continuing with a signal, but it will do
663 * for normal use. strace only continues with a signal if the
664 * stopping signal is not SIGTRAP. -brl
665 */
666 if (current->exit_code) {
667 send_sig(current->exit_code, current, 1);
668 current->exit_code = 0;
669 }
670}
David Woodhouseea9c1022005-05-08 15:56:09 +0100671
672void do_syscall_trace_enter(struct pt_regs *regs)
673{
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000674 secure_computing(regs->gpr[0]);
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000675
David Woodhouseea9c1022005-05-08 15:56:09 +0100676 if (test_thread_flag(TIF_SYSCALL_TRACE)
677 && (current->ptrace & PT_PTRACED))
678 do_syscall_trace();
679
David Woodhousecfcd1702007-01-14 09:38:18 +0800680 if (unlikely(current->audit_context)) {
681#ifdef CONFIG_PPC64
682 if (!test_thread_flag(TIF_32BIT))
683 audit_syscall_entry(AUDIT_ARCH_PPC64,
684 regs->gpr[0],
685 regs->gpr[3], regs->gpr[4],
686 regs->gpr[5], regs->gpr[6]);
687 else
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000688#endif
David Woodhousecfcd1702007-01-14 09:38:18 +0800689 audit_syscall_entry(AUDIT_ARCH_PPC,
690 regs->gpr[0],
691 regs->gpr[3] & 0xffffffff,
692 regs->gpr[4] & 0xffffffff,
693 regs->gpr[5] & 0xffffffff,
694 regs->gpr[6] & 0xffffffff);
695 }
David Woodhouseea9c1022005-05-08 15:56:09 +0100696}
697
698void do_syscall_trace_leave(struct pt_regs *regs)
699{
David Woodhouseea9c1022005-05-08 15:56:09 +0100700 if (unlikely(current->audit_context))
David Woodhouse4b9c8762006-09-22 09:23:53 +0100701 audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
David Woodhouseea9c1022005-05-08 15:56:09 +0100702 regs->result);
703
Stephen Rothwelle8a30302005-10-13 15:52:04 +1000704 if ((test_thread_flag(TIF_SYSCALL_TRACE)
Paul Mackerras1bd79332006-03-08 13:24:22 +1100705 || test_thread_flag(TIF_SINGLESTEP))
David Woodhouseea9c1022005-05-08 15:56:09 +0100706 && (current->ptrace & PT_PTRACED))
707 do_syscall_trace();
708}