blob: 668f569498b69f0f59bc74c7372215e87db37527 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* ptrace.c: Sparc process tracing support.
2 *
David S. Millerd09c2a22008-02-06 23:02:08 -08003 * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 *
6 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
7 * and David Mosberger.
8 *
9 * Added Linux support -miguel (weird, eh?, the original code was meant
10 * to emulate SunOS).
11 */
12
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>
David S. Millerf7ceba32005-07-10 19:29:45 -070022#include <linux/seccomp.h>
23#include <linux/audit.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070024#include <linux/signal.h>
David S. Millerd09c2a22008-02-06 23:02:08 -080025#include <linux/regset.h>
26#include <linux/compat.h>
27#include <linux/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
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>
David S. Miller6a9b4902005-09-19 20:11:57 -070036#include <asm/page.h>
David S. Miller717463d2005-09-29 18:50:34 -070037#include <asm/cpudata.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/* Returning from ptrace is a bit tricky because the syscall return
40 * low level code assumes any value returned which is negative and
41 * is a valid errno will mean setting the condition codes to indicate
42 * an error return. This doesn't work, so we have this hook.
43 */
44static inline void pt_error_return(struct pt_regs *regs, unsigned long error)
45{
46 regs->u_regs[UREG_I0] = error;
47 regs->tstate |= (TSTATE_ICARRY | TSTATE_XCARRY);
48 regs->tpc = regs->tnpc;
49 regs->tnpc += 4;
50}
51
52static inline void pt_succ_return(struct pt_regs *regs, unsigned long value)
53{
54 regs->u_regs[UREG_I0] = value;
55 regs->tstate &= ~(TSTATE_ICARRY | TSTATE_XCARRY);
56 regs->tpc = regs->tnpc;
57 regs->tnpc += 4;
58}
59
60static inline void
61pt_succ_return_linux(struct pt_regs *regs, unsigned long value, void __user *addr)
62{
63 if (test_thread_flag(TIF_32BIT)) {
64 if (put_user(value, (unsigned int __user *) addr)) {
65 pt_error_return(regs, EFAULT);
66 return;
67 }
68 } else {
69 if (put_user(value, (long __user *) addr)) {
70 pt_error_return(regs, EFAULT);
71 return;
72 }
73 }
74 regs->u_regs[UREG_I0] = 0;
75 regs->tstate &= ~(TSTATE_ICARRY | TSTATE_XCARRY);
76 regs->tpc = regs->tnpc;
77 regs->tnpc += 4;
78}
79
80static void
81pt_os_succ_return (struct pt_regs *regs, unsigned long val, void __user *addr)
82{
83 if (current->personality == PER_SUNOS)
84 pt_succ_return (regs, val);
85 else
86 pt_succ_return_linux (regs, val, addr);
87}
88
89/* #define ALLOW_INIT_TRACING */
90/* #define DEBUG_PTRACE */
91
92#ifdef DEBUG_PTRACE
93char *pt_rq [] = {
94 /* 0 */ "TRACEME", "PEEKTEXT", "PEEKDATA", "PEEKUSR",
95 /* 4 */ "POKETEXT", "POKEDATA", "POKEUSR", "CONT",
96 /* 8 */ "KILL", "SINGLESTEP", "SUNATTACH", "SUNDETACH",
97 /* 12 */ "GETREGS", "SETREGS", "GETFPREGS", "SETFPREGS",
98 /* 16 */ "READDATA", "WRITEDATA", "READTEXT", "WRITETEXT",
99 /* 20 */ "GETFPAREGS", "SETFPAREGS", "unknown", "unknown",
100 /* 24 */ "SYSCALL", ""
101};
102#endif
103
104/*
105 * Called by kernel/ptrace.c when detaching..
106 *
107 * Make sure single step bits etc are not set.
108 */
109void ptrace_disable(struct task_struct *child)
110{
111 /* nothing to do */
112}
113
David S. Millerdadeafd2005-04-17 18:03:11 -0700114/* To get the necessary page struct, access_process_vm() first calls
115 * get_user_pages(). This has done a flush_dcache_page() on the
116 * accessed page. Then our caller (copy_{to,from}_user_page()) did
117 * to memcpy to read/write the data from that page.
118 *
119 * Now, the only thing we have to do is:
120 * 1) flush the D-cache if it's possible than an illegal alias
121 * has been created
122 * 2) flush the I-cache if this is pre-cheetah and we did a write
123 */
124void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
125 unsigned long uaddr, void *kaddr,
126 unsigned long len, int write)
127{
128 BUG_ON(len > PAGE_SIZE);
129
David S. Miller7adb37f2006-02-17 15:07:43 -0800130 if (tlb_type == hypervisor)
131 return;
132
David S. Millerdadeafd2005-04-17 18:03:11 -0700133#ifdef DCACHE_ALIASING_POSSIBLE
134 /* If bit 13 of the kernel address we used to access the
135 * user page is the same as the virtual address that page
136 * is mapped to in the user's address space, we can skip the
137 * D-cache flush.
138 */
David S. Miller6a9b4902005-09-19 20:11:57 -0700139 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
David S. Millerdadeafd2005-04-17 18:03:11 -0700140 unsigned long start = __pa(kaddr);
141 unsigned long end = start + len;
David S. Miller717463d2005-09-29 18:50:34 -0700142 unsigned long dcache_line_size;
143
144 dcache_line_size = local_cpu_data().dcache_line_size;
David S. Millerdadeafd2005-04-17 18:03:11 -0700145
146 if (tlb_type == spitfire) {
David S. Miller717463d2005-09-29 18:50:34 -0700147 for (; start < end; start += dcache_line_size)
David S. Miller6a9b4902005-09-19 20:11:57 -0700148 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
David S. Millerdadeafd2005-04-17 18:03:11 -0700149 } else {
David S. Miller717463d2005-09-29 18:50:34 -0700150 start &= ~(dcache_line_size - 1);
151 for (; start < end; start += dcache_line_size)
David S. Millerdadeafd2005-04-17 18:03:11 -0700152 __asm__ __volatile__(
153 "stxa %%g0, [%0] %1\n\t"
154 "membar #Sync"
155 : /* no outputs */
David S. Miller6a9b4902005-09-19 20:11:57 -0700156 : "r" (start),
David S. Millerdadeafd2005-04-17 18:03:11 -0700157 "i" (ASI_DCACHE_INVALIDATE));
158 }
159 }
160#endif
161 if (write && tlb_type == spitfire) {
162 unsigned long start = (unsigned long) kaddr;
163 unsigned long end = start + len;
David S. Miller717463d2005-09-29 18:50:34 -0700164 unsigned long icache_line_size;
David S. Millerdadeafd2005-04-17 18:03:11 -0700165
David S. Miller717463d2005-09-29 18:50:34 -0700166 icache_line_size = local_cpu_data().icache_line_size;
167
168 for (; start < end; start += icache_line_size)
David S. Millerdadeafd2005-04-17 18:03:11 -0700169 flushi(start);
170 }
171}
172
David S. Millerd09c2a22008-02-06 23:02:08 -0800173enum sparc_regset {
174 REGSET_GENERAL,
175 REGSET_FP,
176};
177
178static int genregs64_get(struct task_struct *target,
179 const struct user_regset *regset,
180 unsigned int pos, unsigned int count,
181 void *kbuf, void __user *ubuf)
182{
183 const struct pt_regs *regs = task_pt_regs(target);
184 int ret;
185
186 if (target == current)
187 flushw_user();
188
189 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
190 regs->u_regs,
191 0, 16 * sizeof(u64));
192 if (!ret) {
193 unsigned long __user *reg_window = (unsigned long __user *)
194 (regs->u_regs[UREG_I6] + STACK_BIAS);
195 unsigned long window[16];
196
197 if (copy_from_user(window, reg_window, sizeof(window)))
198 return -EFAULT;
199
200 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
201 window,
202 16 * sizeof(u64),
203 32 * sizeof(u64));
204 }
205
206 if (!ret) {
207 /* TSTATE, TPC, TNPC */
208 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
209 &regs->tstate,
210 32 * sizeof(u64),
211 35 * sizeof(u64));
212 }
213
214 if (!ret) {
215 unsigned long y = regs->y;
216
217 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
218 &y,
219 35 * sizeof(u64),
220 36 * sizeof(u64));
221 }
222
223 if (!ret)
224 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
225 36 * sizeof(u64), -1);
226
227 return ret;
228}
229
230static int genregs64_set(struct task_struct *target,
231 const struct user_regset *regset,
232 unsigned int pos, unsigned int count,
233 const void *kbuf, const void __user *ubuf)
234{
235 struct pt_regs *regs = task_pt_regs(target);
236 int ret;
237
238 if (target == current)
239 flushw_user();
240
241 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
242 regs->u_regs,
243 0, 16 * sizeof(u64));
244 if (!ret && count > 0) {
245 unsigned long __user *reg_window = (unsigned long __user *)
246 (regs->u_regs[UREG_I6] + STACK_BIAS);
247 unsigned long window[16];
248
249 if (copy_from_user(window, reg_window, sizeof(window)))
250 return -EFAULT;
251
252 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
253 window,
254 16 * sizeof(u64),
255 32 * sizeof(u64));
256 if (!ret &&
257 copy_to_user(reg_window, window, sizeof(window)))
258 return -EFAULT;
259 }
260
261 if (!ret && count > 0) {
262 unsigned long tstate;
263
264 /* TSTATE */
265 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
266 &tstate,
267 32 * sizeof(u64),
268 33 * sizeof(u64));
269 if (!ret) {
270 /* Only the condition codes can be modified
271 * in the %tstate register.
272 */
273 tstate &= (TSTATE_ICC | TSTATE_XCC);
274 regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
275 regs->tstate |= tstate;
276 }
277 }
278
279 if (!ret) {
280 /* TPC, TNPC */
281 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
282 &regs->tpc,
283 33 * sizeof(u64),
284 35 * sizeof(u64));
285 }
286
287 if (!ret) {
288 unsigned long y;
289
290 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
291 &y,
292 35 * sizeof(u64),
293 36 * sizeof(u64));
294 if (!ret)
295 regs->y = y;
296 }
297
298 if (!ret)
299 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
300 36 * sizeof(u64), -1);
301
302 return ret;
303}
304
305static int fpregs64_get(struct task_struct *target,
306 const struct user_regset *regset,
307 unsigned int pos, unsigned int count,
308 void *kbuf, void __user *ubuf)
309{
310 const unsigned long *fpregs = task_thread_info(target)->fpregs;
311 unsigned long fprs, fsr, gsr;
312 int ret;
313
314 if (target == current)
315 save_and_clear_fpu();
316
317 fprs = task_thread_info(target)->fpsaved[0];
318
319 if (fprs & FPRS_DL)
320 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
321 fpregs,
322 0, 16 * sizeof(u64));
323 else
324 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
325 0,
326 16 * sizeof(u64));
327
328 if (!ret) {
329 if (fprs & FPRS_DU)
330 ret = user_regset_copyout(&pos, &count,
331 &kbuf, &ubuf,
332 fpregs + 16,
333 16 * sizeof(u64),
334 32 * sizeof(u64));
335 else
336 ret = user_regset_copyout_zero(&pos, &count,
337 &kbuf, &ubuf,
338 16 * sizeof(u64),
339 32 * sizeof(u64));
340 }
341
342 if (fprs & FPRS_FEF) {
343 fsr = task_thread_info(target)->xfsr[0];
344 gsr = task_thread_info(target)->gsr[0];
345 } else {
346 fsr = gsr = 0;
347 }
348
349 if (!ret)
350 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
351 &fsr,
352 32 * sizeof(u64),
353 33 * sizeof(u64));
354 if (!ret)
355 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
356 &gsr,
357 33 * sizeof(u64),
358 34 * sizeof(u64));
359 if (!ret)
360 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
361 &fprs,
362 34 * sizeof(u64),
363 35 * sizeof(u64));
364
365 if (!ret)
366 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
367 35 * sizeof(u64), -1);
368
369 return ret;
370}
371
372static int fpregs64_set(struct task_struct *target,
373 const struct user_regset *regset,
374 unsigned int pos, unsigned int count,
375 const void *kbuf, const void __user *ubuf)
376{
377 unsigned long *fpregs = task_thread_info(target)->fpregs;
378 unsigned long fprs;
379 int ret;
380
381 if (target == current)
382 save_and_clear_fpu();
383
384 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
385 fpregs,
386 0, 32 * sizeof(u64));
387 if (!ret)
388 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
389 task_thread_info(target)->xfsr,
390 32 * sizeof(u64),
391 33 * sizeof(u64));
392 if (!ret)
393 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
394 task_thread_info(target)->gsr,
395 33 * sizeof(u64),
396 34 * sizeof(u64));
397
398 fprs = task_thread_info(target)->fpsaved[0];
399 if (!ret && count > 0) {
400 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
401 &fprs,
402 34 * sizeof(u64),
403 35 * sizeof(u64));
404 }
405
406 fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
407 task_thread_info(target)->fpsaved[0] = fprs;
408
409 if (!ret)
410 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
411 35 * sizeof(u64), -1);
412 return ret;
413}
414
415static const struct user_regset sparc64_regsets[] = {
416 /* Format is:
417 * G0 --> G7
418 * O0 --> O7
419 * L0 --> L7
420 * I0 --> I7
421 * TSTATE, TPC, TNPC, Y
422 */
423 [REGSET_GENERAL] = {
424 .core_note_type = NT_PRSTATUS,
425 .n = 36 * sizeof(u64),
426 .size = sizeof(u64), .align = sizeof(u64),
427 .get = genregs64_get, .set = genregs64_set
428 },
429 /* Format is:
430 * F0 --> F63
431 * FSR
432 * GSR
433 * FPRS
434 */
435 [REGSET_FP] = {
436 .core_note_type = NT_PRFPREG,
437 .n = 35 * sizeof(u64),
438 .size = sizeof(u64), .align = sizeof(u64),
439 .get = fpregs64_get, .set = fpregs64_set
440 },
441};
442
443static const struct user_regset_view user_sparc64_view = {
444 .name = "sparc64", .e_machine = EM_SPARCV9,
445 .regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
446};
447
448static int genregs32_get(struct task_struct *target,
449 const struct user_regset *regset,
450 unsigned int pos, unsigned int count,
451 void *kbuf, void __user *ubuf)
452{
453 const struct pt_regs *regs = task_pt_regs(target);
454 compat_ulong_t __user *reg_window;
455 compat_ulong_t *k = kbuf;
456 compat_ulong_t __user *u = ubuf;
457 compat_ulong_t reg;
458
459 if (target == current)
460 flushw_user();
461
462 pos /= sizeof(reg);
463 count /= sizeof(reg);
464
465 if (kbuf) {
466 for (; count > 0 && pos < 16; count--)
467 *k++ = regs->u_regs[pos++];
468
469 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
470 for (; count > 0 && pos < 32; count--) {
471 if (get_user(*k++, &reg_window[pos++]))
472 return -EFAULT;
473 }
474 } else {
475 for (; count > 0 && pos < 16; count--) {
476 if (put_user((compat_ulong_t) regs->u_regs[pos++], u++))
477 return -EFAULT;
478 }
479
480 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
481 for (; count > 0 && pos < 32; count--) {
482 if (get_user(reg, &reg_window[pos++]) ||
483 put_user(reg, u++))
484 return -EFAULT;
485 }
486 }
487 while (count > 0) {
488 switch (pos) {
489 case 32: /* PSR */
490 reg = tstate_to_psr(regs->tstate);
491 break;
492 case 33: /* PC */
493 reg = regs->tpc;
494 break;
495 case 34: /* NPC */
496 reg = regs->tnpc;
497 break;
498 case 35: /* Y */
499 reg = regs->y;
500 break;
501 case 36: /* WIM */
502 case 37: /* TBR */
503 reg = 0;
504 break;
505 default:
506 goto finish;
507 }
508
509 if (kbuf)
510 *k++ = reg;
511 else if (put_user(reg, u++))
512 return -EFAULT;
513 pos++;
514 count--;
515 }
516finish:
517 pos *= sizeof(reg);
518 count *= sizeof(reg);
519
520 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
521 38 * sizeof(reg), -1);
522}
523
524static int genregs32_set(struct task_struct *target,
525 const struct user_regset *regset,
526 unsigned int pos, unsigned int count,
527 const void *kbuf, const void __user *ubuf)
528{
529 struct pt_regs *regs = task_pt_regs(target);
530 compat_ulong_t __user *reg_window;
531 const compat_ulong_t *k = kbuf;
532 const compat_ulong_t __user *u = ubuf;
533 compat_ulong_t reg;
534
535 if (target == current)
536 flushw_user();
537
538 pos /= sizeof(reg);
539 count /= sizeof(reg);
540
541 if (kbuf) {
542 for (; count > 0 && pos < 16; count--)
543 regs->u_regs[pos++] = *k++;
544
545 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
546 for (; count > 0 && pos < 32; count--) {
547 if (put_user(*k++, &reg_window[pos++]))
548 return -EFAULT;
549 }
550 } else {
551 for (; count > 0 && pos < 16; count--) {
552 if (get_user(reg, u++))
553 return -EFAULT;
554 regs->u_regs[pos++] = reg;
555 }
556
557 reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
558 for (; count > 0 && pos < 32; count--) {
559 if (get_user(reg, u++) ||
560 put_user(reg, &reg_window[pos++]))
561 return -EFAULT;
562 }
563 }
564 while (count > 0) {
565 unsigned long tstate;
566
567 if (kbuf)
568 reg = *k++;
569 else if (get_user(reg, u++))
570 return -EFAULT;
571
572 switch (pos) {
573 case 32: /* PSR */
574 tstate = regs->tstate;
575 tstate &= ~(TSTATE_ICC | TSTATE_XCC);
576 tstate |= psr_to_tstate_icc(reg);
577 regs->tstate = tstate;
578 break;
579 case 33: /* PC */
580 regs->tpc = reg;
581 break;
582 case 34: /* NPC */
583 regs->tnpc = reg;
584 break;
585 case 35: /* Y */
586 regs->y = reg;
587 break;
588 case 36: /* WIM */
589 case 37: /* TBR */
590 break;
591 default:
592 goto finish;
593 }
594
595 pos++;
596 count--;
597 }
598finish:
599 pos *= sizeof(reg);
600 count *= sizeof(reg);
601
602 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
603 38 * sizeof(reg), -1);
604}
605
606static int fpregs32_get(struct task_struct *target,
607 const struct user_regset *regset,
608 unsigned int pos, unsigned int count,
609 void *kbuf, void __user *ubuf)
610{
611 const unsigned long *fpregs = task_thread_info(target)->fpregs;
612 compat_ulong_t enabled;
613 unsigned long fprs;
614 compat_ulong_t fsr;
615 int ret = 0;
616
617 if (target == current)
618 save_and_clear_fpu();
619
620 fprs = task_thread_info(target)->fpsaved[0];
621 if (fprs & FPRS_FEF) {
622 fsr = task_thread_info(target)->xfsr[0];
623 enabled = 1;
624 } else {
625 fsr = 0;
626 enabled = 0;
627 }
628
629 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
630 fpregs,
631 0, 32 * sizeof(u32));
632
633 if (!ret)
634 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
635 32 * sizeof(u32),
636 33 * sizeof(u32));
637 if (!ret)
638 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
639 &fsr,
640 33 * sizeof(u32),
641 34 * sizeof(u32));
642
643 if (!ret) {
644 compat_ulong_t val;
645
646 val = (enabled << 8) | (8 << 16);
647 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
648 &val,
649 34 * sizeof(u32),
650 35 * sizeof(u32));
651 }
652
653 if (!ret)
654 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
655 35 * sizeof(u32), -1);
656
657 return ret;
658}
659
660static int fpregs32_set(struct task_struct *target,
661 const struct user_regset *regset,
662 unsigned int pos, unsigned int count,
663 const void *kbuf, const void __user *ubuf)
664{
665 unsigned long *fpregs = task_thread_info(target)->fpregs;
666 unsigned long fprs;
667 int ret;
668
669 if (target == current)
670 save_and_clear_fpu();
671
672 fprs = task_thread_info(target)->fpsaved[0];
673
674 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
675 fpregs,
676 0, 32 * sizeof(u32));
677 if (!ret)
678 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
679 32 * sizeof(u32),
680 33 * sizeof(u32));
681 if (!ret && count > 0) {
682 compat_ulong_t fsr;
683 unsigned long val;
684
685 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
686 &fsr,
687 33 * sizeof(u32),
688 34 * sizeof(u32));
689 if (!ret) {
690 val = task_thread_info(target)->xfsr[0];
691 val &= 0xffffffff00000000UL;
692 val |= fsr;
693 task_thread_info(target)->xfsr[0] = val;
694 }
695 }
696
697 fprs |= (FPRS_FEF | FPRS_DL);
698 task_thread_info(target)->fpsaved[0] = fprs;
699
700 if (!ret)
701 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
702 34 * sizeof(u32), -1);
703 return ret;
704}
705
706static const struct user_regset sparc32_regsets[] = {
707 /* Format is:
708 * G0 --> G7
709 * O0 --> O7
710 * L0 --> L7
711 * I0 --> I7
712 * PSR, PC, nPC, Y, WIM, TBR
713 */
714 [REGSET_GENERAL] = {
715 .core_note_type = NT_PRSTATUS,
716 .n = 38 * sizeof(u32),
717 .size = sizeof(u32), .align = sizeof(u32),
718 .get = genregs32_get, .set = genregs32_set
719 },
720 /* Format is:
721 * F0 --> F31
722 * empty 32-bit word
723 * FSR (32--bit word)
724 * FPU QUEUE COUNT (8-bit char)
725 * FPU QUEUE ENTRYSIZE (8-bit char)
726 * FPU ENABLED (8-bit char)
727 * empty 8-bit char
728 * FPU QUEUE (64 32-bit ints)
729 */
730 [REGSET_FP] = {
731 .core_note_type = NT_PRFPREG,
732 .n = 99 * sizeof(u32),
733 .size = sizeof(u32), .align = sizeof(u32),
734 .get = fpregs32_get, .set = fpregs32_set
735 },
736};
737
738static const struct user_regset_view user_sparc32_view = {
739 .name = "sparc", .e_machine = EM_SPARC,
740 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
741};
742
743const struct user_regset_view *task_user_regset_view(struct task_struct *task)
744{
745 if (test_tsk_thread_flag(task, TIF_32BIT))
746 return &user_sparc32_view;
747 return &user_sparc64_view;
748}
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750asmlinkage void do_ptrace(struct pt_regs *regs)
751{
752 int request = regs->u_regs[UREG_I0];
753 pid_t pid = regs->u_regs[UREG_I1];
754 unsigned long addr = regs->u_regs[UREG_I2];
755 unsigned long data = regs->u_regs[UREG_I3];
756 unsigned long addr2 = regs->u_regs[UREG_I4];
757 struct task_struct *child;
758 int ret;
759
760 if (test_thread_flag(TIF_32BIT)) {
761 addr &= 0xffffffffUL;
762 data &= 0xffffffffUL;
763 addr2 &= 0xffffffffUL;
764 }
765 lock_kernel();
766#ifdef DEBUG_PTRACE
767 {
768 char *s;
769
770 if ((request >= 0) && (request <= 24))
771 s = pt_rq [request];
772 else
773 s = "unknown";
774
775 if (request == PTRACE_POKEDATA && data == 0x91d02001){
776 printk ("do_ptrace: breakpoint pid=%d, addr=%016lx addr2=%016lx\n",
777 pid, addr, addr2);
778 } else
779 printk("do_ptrace: rq=%s(%d) pid=%d addr=%016lx data=%016lx addr2=%016lx\n",
780 s, request, pid, addr, data, addr2);
781 }
782#endif
783 if (request == PTRACE_TRACEME) {
Christoph Hellwig6b9c7ed2006-01-08 01:02:33 -0800784 ret = ptrace_traceme();
Alexey Dobriyan35bca362006-12-01 20:18:40 -0800785 if (ret < 0)
786 pt_error_return(regs, -ret);
787 else
788 pt_succ_return(regs, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 goto out;
790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Christoph Hellwig6b9c7ed2006-01-08 01:02:33 -0800792 child = ptrace_get_task_struct(pid);
793 if (IS_ERR(child)) {
794 ret = PTR_ERR(child);
795 pt_error_return(regs, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 goto out;
797 }
798
799 if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
800 || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
801 if (ptrace_attach(child)) {
802 pt_error_return(regs, EPERM);
803 goto out_tsk;
804 }
805 pt_succ_return(regs, 0);
806 goto out_tsk;
807 }
808
809 ret = ptrace_check_attach(child, request == PTRACE_KILL);
810 if (ret < 0) {
811 pt_error_return(regs, -ret);
812 goto out_tsk;
813 }
814
815 if (!(test_thread_flag(TIF_32BIT)) &&
816 ((request == PTRACE_READDATA64) ||
817 (request == PTRACE_WRITEDATA64) ||
818 (request == PTRACE_READTEXT64) ||
819 (request == PTRACE_WRITETEXT64) ||
820 (request == PTRACE_PEEKTEXT64) ||
821 (request == PTRACE_POKETEXT64) ||
822 (request == PTRACE_PEEKDATA64) ||
823 (request == PTRACE_POKEDATA64))) {
824 addr = regs->u_regs[UREG_G2];
825 addr2 = regs->u_regs[UREG_G3];
826 request -= 30; /* wheee... */
827 }
828
829 switch(request) {
David S. Miller1759e582006-04-01 23:28:10 -0800830 case PTRACE_PEEKUSR:
831 if (addr != 0)
832 pt_error_return(regs, EIO);
833 else
834 pt_succ_return(regs, 0);
835 goto out_tsk;
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 case PTRACE_PEEKTEXT: /* read word at location addr. */
838 case PTRACE_PEEKDATA: {
839 unsigned long tmp64;
840 unsigned int tmp32;
841 int res, copied;
842
843 res = -EIO;
844 if (test_thread_flag(TIF_32BIT)) {
845 copied = access_process_vm(child, addr,
846 &tmp32, sizeof(tmp32), 0);
847 tmp64 = (unsigned long) tmp32;
848 if (copied == sizeof(tmp32))
849 res = 0;
850 } else {
851 copied = access_process_vm(child, addr,
852 &tmp64, sizeof(tmp64), 0);
853 if (copied == sizeof(tmp64))
854 res = 0;
855 }
856 if (res < 0)
857 pt_error_return(regs, -res);
858 else
859 pt_os_succ_return(regs, tmp64, (void __user *) data);
David S. Millerdadeafd2005-04-17 18:03:11 -0700860 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862
863 case PTRACE_POKETEXT: /* write the word at location addr. */
864 case PTRACE_POKEDATA: {
865 unsigned long tmp64;
866 unsigned int tmp32;
867 int copied, res = -EIO;
868
869 if (test_thread_flag(TIF_32BIT)) {
870 tmp32 = data;
871 copied = access_process_vm(child, addr,
872 &tmp32, sizeof(tmp32), 1);
873 if (copied == sizeof(tmp32))
874 res = 0;
875 } else {
876 tmp64 = data;
877 copied = access_process_vm(child, addr,
878 &tmp64, sizeof(tmp64), 1);
879 if (copied == sizeof(tmp64))
880 res = 0;
881 }
882 if (res < 0)
883 pt_error_return(regs, -res);
884 else
885 pt_succ_return(regs, res);
David S. Millerdadeafd2005-04-17 18:03:11 -0700886 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 }
888
889 case PTRACE_GETREGS: {
890 struct pt_regs32 __user *pregs =
891 (struct pt_regs32 __user *) addr;
Al Viro26ecbde2006-01-12 01:05:43 -0800892 struct pt_regs *cregs = task_pt_regs(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 int rval;
894
895 if (__put_user(tstate_to_psr(cregs->tstate), (&pregs->psr)) ||
896 __put_user(cregs->tpc, (&pregs->pc)) ||
897 __put_user(cregs->tnpc, (&pregs->npc)) ||
898 __put_user(cregs->y, (&pregs->y))) {
899 pt_error_return(regs, EFAULT);
900 goto out_tsk;
901 }
902 for (rval = 1; rval < 16; rval++)
903 if (__put_user(cregs->u_regs[rval], (&pregs->u_regs[rval - 1]))) {
904 pt_error_return(regs, EFAULT);
905 goto out_tsk;
906 }
907 pt_succ_return(regs, 0);
908#ifdef DEBUG_PTRACE
909 printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);
910#endif
911 goto out_tsk;
912 }
913
914 case PTRACE_GETREGS64: {
915 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
Al Viro26ecbde2006-01-12 01:05:43 -0800916 struct pt_regs *cregs = task_pt_regs(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 unsigned long tpc = cregs->tpc;
918 int rval;
919
Al Virof3169642006-01-12 01:05:42 -0800920 if ((task_thread_info(child)->flags & _TIF_32BIT) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 tpc &= 0xffffffff;
922 if (__put_user(cregs->tstate, (&pregs->tstate)) ||
923 __put_user(tpc, (&pregs->tpc)) ||
924 __put_user(cregs->tnpc, (&pregs->tnpc)) ||
925 __put_user(cregs->y, (&pregs->y))) {
926 pt_error_return(regs, EFAULT);
927 goto out_tsk;
928 }
929 for (rval = 1; rval < 16; rval++)
930 if (__put_user(cregs->u_regs[rval], (&pregs->u_regs[rval - 1]))) {
931 pt_error_return(regs, EFAULT);
932 goto out_tsk;
933 }
934 pt_succ_return(regs, 0);
935#ifdef DEBUG_PTRACE
936 printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);
937#endif
938 goto out_tsk;
939 }
940
941 case PTRACE_SETREGS: {
942 struct pt_regs32 __user *pregs =
943 (struct pt_regs32 __user *) addr;
Al Viro26ecbde2006-01-12 01:05:43 -0800944 struct pt_regs *cregs = task_pt_regs(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 unsigned int psr, pc, npc, y;
946 int i;
947
948 /* Must be careful, tracing process can only set certain
949 * bits in the psr.
950 */
951 if (__get_user(psr, (&pregs->psr)) ||
952 __get_user(pc, (&pregs->pc)) ||
953 __get_user(npc, (&pregs->npc)) ||
954 __get_user(y, (&pregs->y))) {
955 pt_error_return(regs, EFAULT);
956 goto out_tsk;
957 }
958 cregs->tstate &= ~(TSTATE_ICC);
959 cregs->tstate |= psr_to_tstate_icc(psr);
960 if (!((pc | npc) & 3)) {
961 cregs->tpc = pc;
962 cregs->tnpc = npc;
963 }
964 cregs->y = y;
965 for (i = 1; i < 16; i++) {
966 if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {
967 pt_error_return(regs, EFAULT);
968 goto out_tsk;
969 }
970 }
971 pt_succ_return(regs, 0);
972 goto out_tsk;
973 }
974
975 case PTRACE_SETREGS64: {
976 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
Al Viro26ecbde2006-01-12 01:05:43 -0800977 struct pt_regs *cregs = task_pt_regs(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 unsigned long tstate, tpc, tnpc, y;
979 int i;
980
981 /* Must be careful, tracing process can only set certain
982 * bits in the psr.
983 */
984 if (__get_user(tstate, (&pregs->tstate)) ||
985 __get_user(tpc, (&pregs->tpc)) ||
986 __get_user(tnpc, (&pregs->tnpc)) ||
987 __get_user(y, (&pregs->y))) {
988 pt_error_return(regs, EFAULT);
989 goto out_tsk;
990 }
Al Virof3169642006-01-12 01:05:42 -0800991 if ((task_thread_info(child)->flags & _TIF_32BIT) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 tpc &= 0xffffffff;
993 tnpc &= 0xffffffff;
994 }
995 tstate &= (TSTATE_ICC | TSTATE_XCC);
996 cregs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
997 cregs->tstate |= tstate;
998 if (!((tpc | tnpc) & 3)) {
999 cregs->tpc = tpc;
1000 cregs->tnpc = tnpc;
1001 }
1002 cregs->y = y;
1003 for (i = 1; i < 16; i++) {
1004 if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {
1005 pt_error_return(regs, EFAULT);
1006 goto out_tsk;
1007 }
1008 }
1009 pt_succ_return(regs, 0);
1010 goto out_tsk;
1011 }
1012
1013 case PTRACE_GETFPREGS: {
1014 struct fps {
1015 unsigned int regs[32];
1016 unsigned int fsr;
1017 unsigned int flags;
1018 unsigned int extra;
1019 unsigned int fpqd;
1020 struct fq {
1021 unsigned int insnaddr;
1022 unsigned int insn;
1023 } fpq[16];
1024 };
1025 struct fps __user *fps = (struct fps __user *) addr;
Al Virof3169642006-01-12 01:05:42 -08001026 unsigned long *fpregs = task_thread_info(child)->fpregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028 if (copy_to_user(&fps->regs[0], fpregs,
1029 (32 * sizeof(unsigned int))) ||
Al Virof3169642006-01-12 01:05:42 -08001030 __put_user(task_thread_info(child)->xfsr[0], (&fps->fsr)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 __put_user(0, (&fps->fpqd)) ||
1032 __put_user(0, (&fps->flags)) ||
1033 __put_user(0, (&fps->extra)) ||
1034 clear_user(&fps->fpq[0], 32 * sizeof(unsigned int))) {
1035 pt_error_return(regs, EFAULT);
1036 goto out_tsk;
1037 }
1038 pt_succ_return(regs, 0);
1039 goto out_tsk;
1040 }
1041
1042 case PTRACE_GETFPREGS64: {
1043 struct fps {
1044 unsigned int regs[64];
1045 unsigned long fsr;
1046 };
1047 struct fps __user *fps = (struct fps __user *) addr;
Al Virof3169642006-01-12 01:05:42 -08001048 unsigned long *fpregs = task_thread_info(child)->fpregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 if (copy_to_user(&fps->regs[0], fpregs,
1051 (64 * sizeof(unsigned int))) ||
Al Virof3169642006-01-12 01:05:42 -08001052 __put_user(task_thread_info(child)->xfsr[0], (&fps->fsr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 pt_error_return(regs, EFAULT);
1054 goto out_tsk;
1055 }
1056 pt_succ_return(regs, 0);
1057 goto out_tsk;
1058 }
1059
1060 case PTRACE_SETFPREGS: {
1061 struct fps {
1062 unsigned int regs[32];
1063 unsigned int fsr;
1064 unsigned int flags;
1065 unsigned int extra;
1066 unsigned int fpqd;
1067 struct fq {
1068 unsigned int insnaddr;
1069 unsigned int insn;
1070 } fpq[16];
1071 };
1072 struct fps __user *fps = (struct fps __user *) addr;
Al Virof3169642006-01-12 01:05:42 -08001073 unsigned long *fpregs = task_thread_info(child)->fpregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 unsigned fsr;
1075
1076 if (copy_from_user(fpregs, &fps->regs[0],
1077 (32 * sizeof(unsigned int))) ||
1078 __get_user(fsr, (&fps->fsr))) {
1079 pt_error_return(regs, EFAULT);
1080 goto out_tsk;
1081 }
Al Virof3169642006-01-12 01:05:42 -08001082 task_thread_info(child)->xfsr[0] &= 0xffffffff00000000UL;
1083 task_thread_info(child)->xfsr[0] |= fsr;
1084 if (!(task_thread_info(child)->fpsaved[0] & FPRS_FEF))
1085 task_thread_info(child)->gsr[0] = 0;
1086 task_thread_info(child)->fpsaved[0] |= (FPRS_FEF | FPRS_DL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 pt_succ_return(regs, 0);
1088 goto out_tsk;
1089 }
1090
1091 case PTRACE_SETFPREGS64: {
1092 struct fps {
1093 unsigned int regs[64];
1094 unsigned long fsr;
1095 };
1096 struct fps __user *fps = (struct fps __user *) addr;
Al Virof3169642006-01-12 01:05:42 -08001097 unsigned long *fpregs = task_thread_info(child)->fpregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if (copy_from_user(fpregs, &fps->regs[0],
1100 (64 * sizeof(unsigned int))) ||
Al Virof3169642006-01-12 01:05:42 -08001101 __get_user(task_thread_info(child)->xfsr[0], (&fps->fsr))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 pt_error_return(regs, EFAULT);
1103 goto out_tsk;
1104 }
Al Virof3169642006-01-12 01:05:42 -08001105 if (!(task_thread_info(child)->fpsaved[0] & FPRS_FEF))
1106 task_thread_info(child)->gsr[0] = 0;
1107 task_thread_info(child)->fpsaved[0] |= (FPRS_FEF | FPRS_DL | FPRS_DU);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 pt_succ_return(regs, 0);
1109 goto out_tsk;
1110 }
1111
1112 case PTRACE_READTEXT:
1113 case PTRACE_READDATA: {
1114 int res = ptrace_readdata(child, addr,
1115 (char __user *)addr2, data);
1116 if (res == data) {
1117 pt_succ_return(regs, 0);
David S. Millerdadeafd2005-04-17 18:03:11 -07001118 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 if (res >= 0)
1121 res = -EIO;
1122 pt_error_return(regs, -res);
David S. Millerdadeafd2005-04-17 18:03:11 -07001123 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
1125
1126 case PTRACE_WRITETEXT:
1127 case PTRACE_WRITEDATA: {
1128 int res = ptrace_writedata(child, (char __user *) addr2,
1129 addr, data);
1130 if (res == data) {
1131 pt_succ_return(regs, 0);
David S. Millerdadeafd2005-04-17 18:03:11 -07001132 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
1134 if (res >= 0)
1135 res = -EIO;
1136 pt_error_return(regs, -res);
David S. Millerdadeafd2005-04-17 18:03:11 -07001137 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 }
1139 case PTRACE_SYSCALL: /* continue and stop at (return from) syscall */
1140 addr = 1;
1141
1142 case PTRACE_CONT: { /* restart after signal. */
Jesper Juhl7ed20e12005-05-01 08:59:14 -07001143 if (!valid_signal(data)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 pt_error_return(regs, EIO);
1145 goto out_tsk;
1146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 if (request == PTRACE_SYSCALL) {
1149 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
1150 } else {
1151 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
1152 }
1153
1154 child->exit_code = data;
1155#ifdef DEBUG_PTRACE
1156 printk("CONT: %s [%d]: set exit_code = %x %lx %lx\n", child->comm,
1157 child->pid, child->exit_code,
Al Viro26ecbde2006-01-12 01:05:43 -08001158 task_pt_regs(child)->tpc,
1159 task_pt_regs(child)->tnpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161#endif
1162 wake_up_process(child);
1163 pt_succ_return(regs, 0);
1164 goto out_tsk;
1165 }
1166
1167/*
1168 * make the child exit. Best I can do is send it a sigkill.
1169 * perhaps it should be put in the status that it wants to
1170 * exit.
1171 */
1172 case PTRACE_KILL: {
1173 if (child->exit_state == EXIT_ZOMBIE) { /* already dead */
1174 pt_succ_return(regs, 0);
1175 goto out_tsk;
1176 }
1177 child->exit_code = SIGKILL;
1178 wake_up_process(child);
1179 pt_succ_return(regs, 0);
1180 goto out_tsk;
1181 }
1182
1183 case PTRACE_SUNDETACH: { /* detach a process that was attached. */
1184 int error = ptrace_detach(child, data);
1185 if (error) {
1186 pt_error_return(regs, EIO);
1187 goto out_tsk;
1188 }
1189 pt_succ_return(regs, 0);
1190 goto out_tsk;
1191 }
1192
1193 /* PTRACE_DUMPCORE unsupported... */
1194
David S. Miller731bbe42006-04-04 16:54:40 -07001195 case PTRACE_GETEVENTMSG: {
1196 int err;
1197
1198 if (test_thread_flag(TIF_32BIT))
1199 err = put_user(child->ptrace_message,
1200 (unsigned int __user *) data);
1201 else
1202 err = put_user(child->ptrace_message,
1203 (unsigned long __user *) data);
1204 if (err)
1205 pt_error_return(regs, -err);
1206 else
1207 pt_succ_return(regs, 0);
1208 break;
1209 }
1210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 default: {
1212 int err = ptrace_request(child, request, addr, data);
1213 if (err)
1214 pt_error_return(regs, -err);
1215 else
1216 pt_succ_return(regs, 0);
1217 goto out_tsk;
1218 }
1219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220out_tsk:
1221 if (child)
1222 put_task_struct(child);
1223out:
1224 unlock_kernel();
1225}
1226
David S. Miller8d8a6472005-07-10 16:55:48 -07001227asmlinkage void syscall_trace(struct pt_regs *regs, int syscall_exit_p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
David S. Millerbb49bcd2005-07-10 16:49:28 -07001229 /* do the secure computing check first */
David S. Miller8d8a6472005-07-10 16:55:48 -07001230 secure_computing(regs->u_regs[UREG_G1]);
David S. Millerbb49bcd2005-07-10 16:49:28 -07001231
David S. Millerf7ceba32005-07-10 19:29:45 -07001232 if (unlikely(current->audit_context) && syscall_exit_p) {
1233 unsigned long tstate = regs->tstate;
1234 int result = AUDITSC_SUCCESS;
1235
1236 if (unlikely(tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
1237 result = AUDITSC_FAILURE;
1238
Al Viro5411be52006-03-29 20:23:36 -05001239 audit_syscall_exit(result, regs->u_regs[UREG_I0]);
David S. Millerf7ceba32005-07-10 19:29:45 -07001240 }
1241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 if (!(current->ptrace & PT_PTRACED))
David S. Millerf7ceba32005-07-10 19:29:45 -07001243 goto out;
1244
1245 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1246 goto out;
1247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
1249 ? 0x80 : 0));
1250
1251 /*
1252 * this isn't the same as continuing with a signal, but it will do
1253 * for normal use. strace only continues with a signal if the
1254 * stopping signal is not SIGTRAP. -brl
1255 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 if (current->exit_code) {
David S. Millerbb49bcd2005-07-10 16:49:28 -07001257 send_sig(current->exit_code, current, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 current->exit_code = 0;
1259 }
David S. Millerf7ceba32005-07-10 19:29:45 -07001260
1261out:
1262 if (unlikely(current->audit_context) && !syscall_exit_p)
Al Viro5411be52006-03-29 20:23:36 -05001263 audit_syscall_entry((test_thread_flag(TIF_32BIT) ?
David S. Millerf7ceba32005-07-10 19:29:45 -07001264 AUDIT_ARCH_SPARC :
1265 AUDIT_ARCH_SPARC64),
1266 regs->u_regs[UREG_G1],
1267 regs->u_regs[UREG_I0],
1268 regs->u_regs[UREG_I1],
1269 regs->u_regs[UREG_I2],
1270 regs->u_regs[UREG_I3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271}