[SPARC64]: Make use of compat_sys_ptrace()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sparc64 / kernel / ptrace.c
blob9a1ba1fe859d96a4e41bccd51342d214a0bea6a4
1 /* ptrace.c: Sparc process tracing support.
3 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
7 * and David Mosberger.
9 * Added Linux support -miguel (weird, eh?, the original code was meant
10 * to emulate SunOS).
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16 #include <linux/errno.h>
17 #include <linux/ptrace.h>
18 #include <linux/user.h>
19 #include <linux/smp.h>
20 #include <linux/smp_lock.h>
21 #include <linux/security.h>
22 #include <linux/seccomp.h>
23 #include <linux/audit.h>
24 #include <linux/signal.h>
25 #include <linux/regset.h>
26 #include <linux/compat.h>
27 #include <linux/elf.h>
29 #include <asm/asi.h>
30 #include <asm/pgtable.h>
31 #include <asm/system.h>
32 #include <asm/uaccess.h>
33 #include <asm/psrcompat.h>
34 #include <asm/visasm.h>
35 #include <asm/spitfire.h>
36 #include <asm/page.h>
37 #include <asm/cpudata.h>
39 /* #define ALLOW_INIT_TRACING */
42 * Called by kernel/ptrace.c when detaching..
44 * Make sure single step bits etc are not set.
46 void ptrace_disable(struct task_struct *child)
48 /* nothing to do */
51 /* To get the necessary page struct, access_process_vm() first calls
52 * get_user_pages(). This has done a flush_dcache_page() on the
53 * accessed page. Then our caller (copy_{to,from}_user_page()) did
54 * to memcpy to read/write the data from that page.
56 * Now, the only thing we have to do is:
57 * 1) flush the D-cache if it's possible than an illegal alias
58 * has been created
59 * 2) flush the I-cache if this is pre-cheetah and we did a write
61 void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
62 unsigned long uaddr, void *kaddr,
63 unsigned long len, int write)
65 BUG_ON(len > PAGE_SIZE);
67 if (tlb_type == hypervisor)
68 return;
70 #ifdef DCACHE_ALIASING_POSSIBLE
71 /* If bit 13 of the kernel address we used to access the
72 * user page is the same as the virtual address that page
73 * is mapped to in the user's address space, we can skip the
74 * D-cache flush.
76 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
77 unsigned long start = __pa(kaddr);
78 unsigned long end = start + len;
79 unsigned long dcache_line_size;
81 dcache_line_size = local_cpu_data().dcache_line_size;
83 if (tlb_type == spitfire) {
84 for (; start < end; start += dcache_line_size)
85 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
86 } else {
87 start &= ~(dcache_line_size - 1);
88 for (; start < end; start += dcache_line_size)
89 __asm__ __volatile__(
90 "stxa %%g0, [%0] %1\n\t"
91 "membar #Sync"
92 : /* no outputs */
93 : "r" (start),
94 "i" (ASI_DCACHE_INVALIDATE));
97 #endif
98 if (write && tlb_type == spitfire) {
99 unsigned long start = (unsigned long) kaddr;
100 unsigned long end = start + len;
101 unsigned long icache_line_size;
103 icache_line_size = local_cpu_data().icache_line_size;
105 for (; start < end; start += icache_line_size)
106 flushi(start);
110 enum sparc_regset {
111 REGSET_GENERAL,
112 REGSET_FP,
115 static int genregs64_get(struct task_struct *target,
116 const struct user_regset *regset,
117 unsigned int pos, unsigned int count,
118 void *kbuf, void __user *ubuf)
120 const struct pt_regs *regs = task_pt_regs(target);
121 int ret;
123 if (target == current)
124 flushw_user();
126 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
127 regs->u_regs,
128 0, 16 * sizeof(u64));
129 if (!ret) {
130 unsigned long __user *reg_window = (unsigned long __user *)
131 (regs->u_regs[UREG_I6] + STACK_BIAS);
132 unsigned long window[16];
134 if (copy_from_user(window, reg_window, sizeof(window)))
135 return -EFAULT;
137 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
138 window,
139 16 * sizeof(u64),
140 32 * sizeof(u64));
143 if (!ret) {
144 /* TSTATE, TPC, TNPC */
145 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
146 &regs->tstate,
147 32 * sizeof(u64),
148 35 * sizeof(u64));
151 if (!ret) {
152 unsigned long y = regs->y;
154 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
156 35 * sizeof(u64),
157 36 * sizeof(u64));
160 if (!ret)
161 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
162 36 * sizeof(u64), -1);
164 return ret;
167 static int genregs64_set(struct task_struct *target,
168 const struct user_regset *regset,
169 unsigned int pos, unsigned int count,
170 const void *kbuf, const void __user *ubuf)
172 struct pt_regs *regs = task_pt_regs(target);
173 int ret;
175 if (target == current)
176 flushw_user();
178 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
179 regs->u_regs,
180 0, 16 * sizeof(u64));
181 if (!ret && count > 0) {
182 unsigned long __user *reg_window = (unsigned long __user *)
183 (regs->u_regs[UREG_I6] + STACK_BIAS);
184 unsigned long window[16];
186 if (copy_from_user(window, reg_window, sizeof(window)))
187 return -EFAULT;
189 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
190 window,
191 16 * sizeof(u64),
192 32 * sizeof(u64));
193 if (!ret &&
194 copy_to_user(reg_window, window, sizeof(window)))
195 return -EFAULT;
198 if (!ret && count > 0) {
199 unsigned long tstate;
201 /* TSTATE */
202 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
203 &tstate,
204 32 * sizeof(u64),
205 33 * sizeof(u64));
206 if (!ret) {
207 /* Only the condition codes can be modified
208 * in the %tstate register.
210 tstate &= (TSTATE_ICC | TSTATE_XCC);
211 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
212 regs->tstate |= tstate;
216 if (!ret) {
217 /* TPC, TNPC */
218 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
219 &regs->tpc,
220 33 * sizeof(u64),
221 35 * sizeof(u64));
224 if (!ret) {
225 unsigned long y;
227 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
229 35 * sizeof(u64),
230 36 * sizeof(u64));
231 if (!ret)
232 regs->y = y;
235 if (!ret)
236 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
237 36 * sizeof(u64), -1);
239 return ret;
242 static int fpregs64_get(struct task_struct *target,
243 const struct user_regset *regset,
244 unsigned int pos, unsigned int count,
245 void *kbuf, void __user *ubuf)
247 const unsigned long *fpregs = task_thread_info(target)->fpregs;
248 unsigned long fprs, fsr, gsr;
249 int ret;
251 if (target == current)
252 save_and_clear_fpu();
254 fprs = task_thread_info(target)->fpsaved[0];
256 if (fprs & FPRS_DL)
257 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
258 fpregs,
259 0, 16 * sizeof(u64));
260 else
261 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
263 16 * sizeof(u64));
265 if (!ret) {
266 if (fprs & FPRS_DU)
267 ret = user_regset_copyout(&pos, &count,
268 &kbuf, &ubuf,
269 fpregs + 16,
270 16 * sizeof(u64),
271 32 * sizeof(u64));
272 else
273 ret = user_regset_copyout_zero(&pos, &count,
274 &kbuf, &ubuf,
275 16 * sizeof(u64),
276 32 * sizeof(u64));
279 if (fprs & FPRS_FEF) {
280 fsr = task_thread_info(target)->xfsr[0];
281 gsr = task_thread_info(target)->gsr[0];
282 } else {
283 fsr = gsr = 0;
286 if (!ret)
287 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
288 &fsr,
289 32 * sizeof(u64),
290 33 * sizeof(u64));
291 if (!ret)
292 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
293 &gsr,
294 33 * sizeof(u64),
295 34 * sizeof(u64));
296 if (!ret)
297 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
298 &fprs,
299 34 * sizeof(u64),
300 35 * sizeof(u64));
302 if (!ret)
303 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
304 35 * sizeof(u64), -1);
306 return ret;
309 static int fpregs64_set(struct task_struct *target,
310 const struct user_regset *regset,
311 unsigned int pos, unsigned int count,
312 const void *kbuf, const void __user *ubuf)
314 unsigned long *fpregs = task_thread_info(target)->fpregs;
315 unsigned long fprs;
316 int ret;
318 if (target == current)
319 save_and_clear_fpu();
321 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
322 fpregs,
323 0, 32 * sizeof(u64));
324 if (!ret)
325 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
326 task_thread_info(target)->xfsr,
327 32 * sizeof(u64),
328 33 * sizeof(u64));
329 if (!ret)
330 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
331 task_thread_info(target)->gsr,
332 33 * sizeof(u64),
333 34 * sizeof(u64));
335 fprs = task_thread_info(target)->fpsaved[0];
336 if (!ret && count > 0) {
337 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
338 &fprs,
339 34 * sizeof(u64),
340 35 * sizeof(u64));
343 fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
344 task_thread_info(target)->fpsaved[0] = fprs;
346 if (!ret)
347 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
348 35 * sizeof(u64), -1);
349 return ret;
352 static const struct user_regset sparc64_regsets[] = {
353 /* Format is:
354 * G0 --> G7
355 * O0 --> O7
356 * L0 --> L7
357 * I0 --> I7
358 * TSTATE, TPC, TNPC, Y
360 [REGSET_GENERAL] = {
361 .core_note_type = NT_PRSTATUS,
362 .n = 36 * sizeof(u64),
363 .size = sizeof(u64), .align = sizeof(u64),
364 .get = genregs64_get, .set = genregs64_set
366 /* Format is:
367 * F0 --> F63
368 * FSR
369 * GSR
370 * FPRS
372 [REGSET_FP] = {
373 .core_note_type = NT_PRFPREG,
374 .n = 35 * sizeof(u64),
375 .size = sizeof(u64), .align = sizeof(u64),
376 .get = fpregs64_get, .set = fpregs64_set
380 static const struct user_regset_view user_sparc64_view = {
381 .name = "sparc64", .e_machine = EM_SPARCV9,
382 .regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
385 static int genregs32_get(struct task_struct *target,
386 const struct user_regset *regset,
387 unsigned int pos, unsigned int count,
388 void *kbuf, void __user *ubuf)
390 const struct pt_regs *regs = task_pt_regs(target);
391 compat_ulong_t __user *reg_window;
392 compat_ulong_t *k = kbuf;
393 compat_ulong_t __user *u = ubuf;
394 compat_ulong_t reg;
396 if (target == current)
397 flushw_user();
399 pos /= sizeof(reg);
400 count /= sizeof(reg);
402 if (kbuf) {
403 for (; count > 0 && pos < 16; count--)
404 *k++ = regs->u_regs[pos++];
406 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
407 for (; count > 0 && pos < 32; count--) {
408 if (get_user(*k++, &reg_window[pos++]))
409 return -EFAULT;
411 } else {
412 for (; count > 0 && pos < 16; count--) {
413 if (put_user((compat_ulong_t) regs->u_regs[pos++], u++))
414 return -EFAULT;
417 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
418 for (; count > 0 && pos < 32; count--) {
419 if (get_user(reg, &reg_window[pos++]) ||
420 put_user(reg, u++))
421 return -EFAULT;
424 while (count > 0) {
425 switch (pos) {
426 case 32: /* PSR */
427 reg = tstate_to_psr(regs->tstate);
428 break;
429 case 33: /* PC */
430 reg = regs->tpc;
431 break;
432 case 34: /* NPC */
433 reg = regs->tnpc;
434 break;
435 case 35: /* Y */
436 reg = regs->y;
437 break;
438 case 36: /* WIM */
439 case 37: /* TBR */
440 reg = 0;
441 break;
442 default:
443 goto finish;
446 if (kbuf)
447 *k++ = reg;
448 else if (put_user(reg, u++))
449 return -EFAULT;
450 pos++;
451 count--;
453 finish:
454 pos *= sizeof(reg);
455 count *= sizeof(reg);
457 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
458 38 * sizeof(reg), -1);
461 static int genregs32_set(struct task_struct *target,
462 const struct user_regset *regset,
463 unsigned int pos, unsigned int count,
464 const void *kbuf, const void __user *ubuf)
466 struct pt_regs *regs = task_pt_regs(target);
467 compat_ulong_t __user *reg_window;
468 const compat_ulong_t *k = kbuf;
469 const compat_ulong_t __user *u = ubuf;
470 compat_ulong_t reg;
472 if (target == current)
473 flushw_user();
475 pos /= sizeof(reg);
476 count /= sizeof(reg);
478 if (kbuf) {
479 for (; count > 0 && pos < 16; count--)
480 regs->u_regs[pos++] = *k++;
482 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
483 for (; count > 0 && pos < 32; count--) {
484 if (put_user(*k++, &reg_window[pos++]))
485 return -EFAULT;
487 } else {
488 for (; count > 0 && pos < 16; count--) {
489 if (get_user(reg, u++))
490 return -EFAULT;
491 regs->u_regs[pos++] = reg;
494 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
495 for (; count > 0 && pos < 32; count--) {
496 if (get_user(reg, u++) ||
497 put_user(reg, &reg_window[pos++]))
498 return -EFAULT;
501 while (count > 0) {
502 unsigned long tstate;
504 if (kbuf)
505 reg = *k++;
506 else if (get_user(reg, u++))
507 return -EFAULT;
509 switch (pos) {
510 case 32: /* PSR */
511 tstate = regs->tstate;
512 tstate &= ~(TSTATE_ICC | TSTATE_XCC);
513 tstate |= psr_to_tstate_icc(reg);
514 regs->tstate = tstate;
515 break;
516 case 33: /* PC */
517 regs->tpc = reg;
518 break;
519 case 34: /* NPC */
520 regs->tnpc = reg;
521 break;
522 case 35: /* Y */
523 regs->y = reg;
524 break;
525 case 36: /* WIM */
526 case 37: /* TBR */
527 break;
528 default:
529 goto finish;
532 pos++;
533 count--;
535 finish:
536 pos *= sizeof(reg);
537 count *= sizeof(reg);
539 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
540 38 * sizeof(reg), -1);
543 static int fpregs32_get(struct task_struct *target,
544 const struct user_regset *regset,
545 unsigned int pos, unsigned int count,
546 void *kbuf, void __user *ubuf)
548 const unsigned long *fpregs = task_thread_info(target)->fpregs;
549 compat_ulong_t enabled;
550 unsigned long fprs;
551 compat_ulong_t fsr;
552 int ret = 0;
554 if (target == current)
555 save_and_clear_fpu();
557 fprs = task_thread_info(target)->fpsaved[0];
558 if (fprs & FPRS_FEF) {
559 fsr = task_thread_info(target)->xfsr[0];
560 enabled = 1;
561 } else {
562 fsr = 0;
563 enabled = 0;
566 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
567 fpregs,
568 0, 32 * sizeof(u32));
570 if (!ret)
571 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
572 32 * sizeof(u32),
573 33 * sizeof(u32));
574 if (!ret)
575 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
576 &fsr,
577 33 * sizeof(u32),
578 34 * sizeof(u32));
580 if (!ret) {
581 compat_ulong_t val;
583 val = (enabled << 8) | (8 << 16);
584 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
585 &val,
586 34 * sizeof(u32),
587 35 * sizeof(u32));
590 if (!ret)
591 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
592 35 * sizeof(u32), -1);
594 return ret;
597 static int fpregs32_set(struct task_struct *target,
598 const struct user_regset *regset,
599 unsigned int pos, unsigned int count,
600 const void *kbuf, const void __user *ubuf)
602 unsigned long *fpregs = task_thread_info(target)->fpregs;
603 unsigned long fprs;
604 int ret;
606 if (target == current)
607 save_and_clear_fpu();
609 fprs = task_thread_info(target)->fpsaved[0];
611 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
612 fpregs,
613 0, 32 * sizeof(u32));
614 if (!ret)
615 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
616 32 * sizeof(u32),
617 33 * sizeof(u32));
618 if (!ret && count > 0) {
619 compat_ulong_t fsr;
620 unsigned long val;
622 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
623 &fsr,
624 33 * sizeof(u32),
625 34 * sizeof(u32));
626 if (!ret) {
627 val = task_thread_info(target)->xfsr[0];
628 val &= 0xffffffff00000000UL;
629 val |= fsr;
630 task_thread_info(target)->xfsr[0] = val;
634 fprs |= (FPRS_FEF | FPRS_DL);
635 task_thread_info(target)->fpsaved[0] = fprs;
637 if (!ret)
638 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
639 34 * sizeof(u32), -1);
640 return ret;
643 static const struct user_regset sparc32_regsets[] = {
644 /* Format is:
645 * G0 --> G7
646 * O0 --> O7
647 * L0 --> L7
648 * I0 --> I7
649 * PSR, PC, nPC, Y, WIM, TBR
651 [REGSET_GENERAL] = {
652 .core_note_type = NT_PRSTATUS,
653 .n = 38 * sizeof(u32),
654 .size = sizeof(u32), .align = sizeof(u32),
655 .get = genregs32_get, .set = genregs32_set
657 /* Format is:
658 * F0 --> F31
659 * empty 32-bit word
660 * FSR (32--bit word)
661 * FPU QUEUE COUNT (8-bit char)
662 * FPU QUEUE ENTRYSIZE (8-bit char)
663 * FPU ENABLED (8-bit char)
664 * empty 8-bit char
665 * FPU QUEUE (64 32-bit ints)
667 [REGSET_FP] = {
668 .core_note_type = NT_PRFPREG,
669 .n = 99 * sizeof(u32),
670 .size = sizeof(u32), .align = sizeof(u32),
671 .get = fpregs32_get, .set = fpregs32_set
675 static const struct user_regset_view user_sparc32_view = {
676 .name = "sparc", .e_machine = EM_SPARC,
677 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
680 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
682 if (test_tsk_thread_flag(task, TIF_32BIT))
683 return &user_sparc32_view;
684 return &user_sparc64_view;
687 struct compat_fps {
688 unsigned int regs[32];
689 unsigned int fsr;
690 unsigned int flags;
691 unsigned int extra;
692 unsigned int fpqd;
693 struct compat_fq {
694 unsigned int insnaddr;
695 unsigned int insn;
696 } fpq[16];
699 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
700 compat_ulong_t caddr, compat_ulong_t cdata)
702 const struct user_regset_view *view = task_user_regset_view(child);
703 compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
704 struct pt_regs32 __user *pregs;
705 struct compat_fps __user *fps;
706 unsigned long addr2 = caddr2;
707 unsigned long addr = caddr;
708 unsigned long data = cdata;
709 int ret;
711 pregs = (struct pt_regs32 __user *) addr;
712 fps = (struct compat_fps __user *) addr;
714 switch (request) {
715 case PTRACE_PEEKUSR:
716 ret = (addr != 0) ? -EIO : 0;
717 break;
719 case PTRACE_GETREGS:
720 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
721 32 * sizeof(u32),
722 4 * sizeof(u32),
723 &pregs->psr);
724 if (!ret)
725 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
726 1 * sizeof(u32),
727 15 * sizeof(u32),
728 &pregs->u_regs[0]);
729 break;
731 case PTRACE_SETREGS:
732 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
733 32 * sizeof(u32),
734 4 * sizeof(u32),
735 &pregs->psr);
736 if (!ret)
737 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
738 1 * sizeof(u32),
739 15 * sizeof(u32),
740 &pregs->u_regs[0]);
741 break;
743 case PTRACE_GETFPREGS:
744 ret = copy_regset_to_user(child, view, REGSET_FP,
745 0 * sizeof(u32),
746 32 * sizeof(u32),
747 &fps->regs[0]);
748 if (!ret)
749 ret = copy_regset_to_user(child, view, REGSET_FP,
750 33 * sizeof(u32),
751 1 * sizeof(u32),
752 &fps->fsr);
753 if (!ret) {
754 if (__put_user(0, &fps->flags) ||
755 __put_user(0, &fps->extra) ||
756 __put_user(0, &fps->fpqd) ||
757 clear_user(&fps->fpq[0], 32 * sizeof(unsigned int)))
758 ret = -EFAULT;
760 break;
762 case PTRACE_SETFPREGS:
763 ret = copy_regset_from_user(child, view, REGSET_FP,
764 0 * sizeof(u32),
765 32 * sizeof(u32),
766 &fps->regs[0]);
767 if (!ret)
768 ret = copy_regset_from_user(child, view, REGSET_FP,
769 33 * sizeof(u32),
770 1 * sizeof(u32),
771 &fps->fsr);
772 break;
774 case PTRACE_READTEXT:
775 case PTRACE_READDATA:
776 ret = ptrace_readdata(child, addr,
777 (char __user *)addr2, data);
778 if (ret == data)
779 ret = 0;
780 else if (ret >= 0)
781 ret = -EIO;
782 break;
784 case PTRACE_WRITETEXT:
785 case PTRACE_WRITEDATA:
786 ret = ptrace_writedata(child, (char __user *) addr2,
787 addr, data);
788 if (ret == data)
789 ret = 0;
790 else if (ret >= 0)
791 ret = -EIO;
792 break;
794 default:
795 ret = compat_ptrace_request(child, request, addr, data);
796 break;
799 return ret;
802 struct fps {
803 unsigned int regs[64];
804 unsigned long fsr;
807 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
809 const struct user_regset_view *view = task_user_regset_view(child);
810 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
811 unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
812 struct fps __user *fps = (struct fps __user *) addr;
813 int ret;
815 switch (request) {
816 case PTRACE_PEEKUSR:
817 ret = (addr != 0) ? -EIO : 0;
818 break;
820 case PTRACE_GETREGS64:
821 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
822 1 * sizeof(u64),
823 15 * sizeof(u64),
824 &pregs->u_regs[0]);
825 if (!ret) {
826 /* XXX doesn't handle 'y' register correctly XXX */
827 ret = copy_regset_to_user(child, view, REGSET_GENERAL,
828 32 * sizeof(u64),
829 4 * sizeof(u64),
830 &pregs->tstate);
832 break;
834 case PTRACE_SETREGS64:
835 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
836 1 * sizeof(u64),
837 15 * sizeof(u64),
838 &pregs->u_regs[0]);
839 if (!ret) {
840 /* XXX doesn't handle 'y' register correctly XXX */
841 ret = copy_regset_from_user(child, view, REGSET_GENERAL,
842 32 * sizeof(u64),
843 4 * sizeof(u64),
844 &pregs->tstate);
846 break;
848 case PTRACE_GETFPREGS64:
849 ret = copy_regset_to_user(child, view, REGSET_FP,
850 0 * sizeof(u64),
851 33 * sizeof(u64),
852 fps);
853 break;
855 case PTRACE_SETFPREGS64:
856 ret = copy_regset_to_user(child, view, REGSET_FP,
857 0 * sizeof(u64),
858 33 * sizeof(u64),
859 fps);
860 break;
862 case PTRACE_READTEXT:
863 case PTRACE_READDATA:
864 ret = ptrace_readdata(child, addr,
865 (char __user *)addr2, data);
866 if (ret == data)
867 ret = 0;
868 else if (ret >= 0)
869 ret = -EIO;
870 break;
872 case PTRACE_WRITETEXT:
873 case PTRACE_WRITEDATA:
874 ret = ptrace_writedata(child, (char __user *) addr2,
875 addr, data);
876 if (ret == data)
877 ret = 0;
878 else if (ret >= 0)
879 ret = -EIO;
880 break;
882 default:
883 ret = ptrace_request(child, request, addr, data);
884 break;
887 return ret;
890 asmlinkage void syscall_trace(struct pt_regs *regs, int syscall_exit_p)
892 /* do the secure computing check first */
893 secure_computing(regs->u_regs[UREG_G1]);
895 if (unlikely(current->audit_context) && syscall_exit_p) {
896 unsigned long tstate = regs->tstate;
897 int result = AUDITSC_SUCCESS;
899 if (unlikely(tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
900 result = AUDITSC_FAILURE;
902 audit_syscall_exit(result, regs->u_regs[UREG_I0]);
905 if (!(current->ptrace & PT_PTRACED))
906 goto out;
908 if (!test_thread_flag(TIF_SYSCALL_TRACE))
909 goto out;
911 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
912 ? 0x80 : 0));
915 * this isn't the same as continuing with a signal, but it will do
916 * for normal use. strace only continues with a signal if the
917 * stopping signal is not SIGTRAP. -brl
919 if (current->exit_code) {
920 send_sig(current->exit_code, current, 1);
921 current->exit_code = 0;
924 out:
925 if (unlikely(current->audit_context) && !syscall_exit_p)
926 audit_syscall_entry((test_thread_flag(TIF_32BIT) ?
927 AUDIT_ARCH_SPARC :
928 AUDIT_ARCH_SPARC64),
929 regs->u_regs[UREG_G1],
930 regs->u_regs[UREG_I0],
931 regs->u_regs[UREG_I1],
932 regs->u_regs[UREG_I2],
933 regs->u_regs[UREG_I3]);