blob: 5efbff90d66862054ce827bb3c327bd636d280bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* ptrace.c: Sparc process tracing support.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@caipfs.rutgers.edu)
4 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/asi.h>
27#include <asm/pgtable.h>
28#include <asm/system.h>
29#include <asm/uaccess.h>
30#include <asm/psrcompat.h>
31#include <asm/visasm.h>
32#include <asm/spitfire.h>
David S. Miller6a9b4902005-09-19 20:11:57 -070033#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/* Returning from ptrace is a bit tricky because the syscall return
36 * low level code assumes any value returned which is negative and
37 * is a valid errno will mean setting the condition codes to indicate
38 * an error return. This doesn't work, so we have this hook.
39 */
40static inline void pt_error_return(struct pt_regs *regs, unsigned long error)
41{
42 regs->u_regs[UREG_I0] = error;
43 regs->tstate |= (TSTATE_ICARRY | TSTATE_XCARRY);
44 regs->tpc = regs->tnpc;
45 regs->tnpc += 4;
46}
47
48static inline void pt_succ_return(struct pt_regs *regs, unsigned long value)
49{
50 regs->u_regs[UREG_I0] = value;
51 regs->tstate &= ~(TSTATE_ICARRY | TSTATE_XCARRY);
52 regs->tpc = regs->tnpc;
53 regs->tnpc += 4;
54}
55
56static inline void
57pt_succ_return_linux(struct pt_regs *regs, unsigned long value, void __user *addr)
58{
59 if (test_thread_flag(TIF_32BIT)) {
60 if (put_user(value, (unsigned int __user *) addr)) {
61 pt_error_return(regs, EFAULT);
62 return;
63 }
64 } else {
65 if (put_user(value, (long __user *) addr)) {
66 pt_error_return(regs, EFAULT);
67 return;
68 }
69 }
70 regs->u_regs[UREG_I0] = 0;
71 regs->tstate &= ~(TSTATE_ICARRY | TSTATE_XCARRY);
72 regs->tpc = regs->tnpc;
73 regs->tnpc += 4;
74}
75
76static void
77pt_os_succ_return (struct pt_regs *regs, unsigned long val, void __user *addr)
78{
79 if (current->personality == PER_SUNOS)
80 pt_succ_return (regs, val);
81 else
82 pt_succ_return_linux (regs, val, addr);
83}
84
85/* #define ALLOW_INIT_TRACING */
86/* #define DEBUG_PTRACE */
87
88#ifdef DEBUG_PTRACE
89char *pt_rq [] = {
90 /* 0 */ "TRACEME", "PEEKTEXT", "PEEKDATA", "PEEKUSR",
91 /* 4 */ "POKETEXT", "POKEDATA", "POKEUSR", "CONT",
92 /* 8 */ "KILL", "SINGLESTEP", "SUNATTACH", "SUNDETACH",
93 /* 12 */ "GETREGS", "SETREGS", "GETFPREGS", "SETFPREGS",
94 /* 16 */ "READDATA", "WRITEDATA", "READTEXT", "WRITETEXT",
95 /* 20 */ "GETFPAREGS", "SETFPAREGS", "unknown", "unknown",
96 /* 24 */ "SYSCALL", ""
97};
98#endif
99
100/*
101 * Called by kernel/ptrace.c when detaching..
102 *
103 * Make sure single step bits etc are not set.
104 */
105void ptrace_disable(struct task_struct *child)
106{
107 /* nothing to do */
108}
109
David S. Millerdadeafd2005-04-17 18:03:11 -0700110/* To get the necessary page struct, access_process_vm() first calls
111 * get_user_pages(). This has done a flush_dcache_page() on the
112 * accessed page. Then our caller (copy_{to,from}_user_page()) did
113 * to memcpy to read/write the data from that page.
114 *
115 * Now, the only thing we have to do is:
116 * 1) flush the D-cache if it's possible than an illegal alias
117 * has been created
118 * 2) flush the I-cache if this is pre-cheetah and we did a write
119 */
120void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
121 unsigned long uaddr, void *kaddr,
122 unsigned long len, int write)
123{
124 BUG_ON(len > PAGE_SIZE);
125
126#ifdef DCACHE_ALIASING_POSSIBLE
127 /* If bit 13 of the kernel address we used to access the
128 * user page is the same as the virtual address that page
129 * is mapped to in the user's address space, we can skip the
130 * D-cache flush.
131 */
David S. Miller6a9b4902005-09-19 20:11:57 -0700132 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
David S. Millerdadeafd2005-04-17 18:03:11 -0700133 unsigned long start = __pa(kaddr);
134 unsigned long end = start + len;
135
136 if (tlb_type == spitfire) {
137 for (; start < end; start += 32)
David S. Miller6a9b4902005-09-19 20:11:57 -0700138 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
David S. Millerdadeafd2005-04-17 18:03:11 -0700139 } else {
140 for (; start < end; start += 32)
141 __asm__ __volatile__(
142 "stxa %%g0, [%0] %1\n\t"
143 "membar #Sync"
144 : /* no outputs */
David S. Miller6a9b4902005-09-19 20:11:57 -0700145 : "r" (start),
David S. Millerdadeafd2005-04-17 18:03:11 -0700146 "i" (ASI_DCACHE_INVALIDATE));
147 }
148 }
149#endif
150 if (write && tlb_type == spitfire) {
151 unsigned long start = (unsigned long) kaddr;
152 unsigned long end = start + len;
153
154 for (; start < end; start += 32)
155 flushi(start);
156 }
157}
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159asmlinkage void do_ptrace(struct pt_regs *regs)
160{
161 int request = regs->u_regs[UREG_I0];
162 pid_t pid = regs->u_regs[UREG_I1];
163 unsigned long addr = regs->u_regs[UREG_I2];
164 unsigned long data = regs->u_regs[UREG_I3];
165 unsigned long addr2 = regs->u_regs[UREG_I4];
166 struct task_struct *child;
167 int ret;
168
169 if (test_thread_flag(TIF_32BIT)) {
170 addr &= 0xffffffffUL;
171 data &= 0xffffffffUL;
172 addr2 &= 0xffffffffUL;
173 }
174 lock_kernel();
175#ifdef DEBUG_PTRACE
176 {
177 char *s;
178
179 if ((request >= 0) && (request <= 24))
180 s = pt_rq [request];
181 else
182 s = "unknown";
183
184 if (request == PTRACE_POKEDATA && data == 0x91d02001){
185 printk ("do_ptrace: breakpoint pid=%d, addr=%016lx addr2=%016lx\n",
186 pid, addr, addr2);
187 } else
188 printk("do_ptrace: rq=%s(%d) pid=%d addr=%016lx data=%016lx addr2=%016lx\n",
189 s, request, pid, addr, data, addr2);
190 }
191#endif
192 if (request == PTRACE_TRACEME) {
193 int ret;
194
195 /* are we already being traced? */
196 if (current->ptrace & PT_PTRACED) {
197 pt_error_return(regs, EPERM);
198 goto out;
199 }
200 ret = security_ptrace(current->parent, current);
201 if (ret) {
202 pt_error_return(regs, -ret);
203 goto out;
204 }
205
206 /* set the ptrace bit in the process flags. */
207 current->ptrace |= PT_PTRACED;
208 pt_succ_return(regs, 0);
209 goto out;
210 }
211#ifndef ALLOW_INIT_TRACING
212 if (pid == 1) {
213 /* Can't dork with init. */
214 pt_error_return(regs, EPERM);
215 goto out;
216 }
217#endif
218 read_lock(&tasklist_lock);
219 child = find_task_by_pid(pid);
220 if (child)
221 get_task_struct(child);
222 read_unlock(&tasklist_lock);
223
224 if (!child) {
225 pt_error_return(regs, ESRCH);
226 goto out;
227 }
228
229 if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
230 || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
231 if (ptrace_attach(child)) {
232 pt_error_return(regs, EPERM);
233 goto out_tsk;
234 }
235 pt_succ_return(regs, 0);
236 goto out_tsk;
237 }
238
239 ret = ptrace_check_attach(child, request == PTRACE_KILL);
240 if (ret < 0) {
241 pt_error_return(regs, -ret);
242 goto out_tsk;
243 }
244
245 if (!(test_thread_flag(TIF_32BIT)) &&
246 ((request == PTRACE_READDATA64) ||
247 (request == PTRACE_WRITEDATA64) ||
248 (request == PTRACE_READTEXT64) ||
249 (request == PTRACE_WRITETEXT64) ||
250 (request == PTRACE_PEEKTEXT64) ||
251 (request == PTRACE_POKETEXT64) ||
252 (request == PTRACE_PEEKDATA64) ||
253 (request == PTRACE_POKEDATA64))) {
254 addr = regs->u_regs[UREG_G2];
255 addr2 = regs->u_regs[UREG_G3];
256 request -= 30; /* wheee... */
257 }
258
259 switch(request) {
260 case PTRACE_PEEKTEXT: /* read word at location addr. */
261 case PTRACE_PEEKDATA: {
262 unsigned long tmp64;
263 unsigned int tmp32;
264 int res, copied;
265
266 res = -EIO;
267 if (test_thread_flag(TIF_32BIT)) {
268 copied = access_process_vm(child, addr,
269 &tmp32, sizeof(tmp32), 0);
270 tmp64 = (unsigned long) tmp32;
271 if (copied == sizeof(tmp32))
272 res = 0;
273 } else {
274 copied = access_process_vm(child, addr,
275 &tmp64, sizeof(tmp64), 0);
276 if (copied == sizeof(tmp64))
277 res = 0;
278 }
279 if (res < 0)
280 pt_error_return(regs, -res);
281 else
282 pt_os_succ_return(regs, tmp64, (void __user *) data);
David S. Millerdadeafd2005-04-17 18:03:11 -0700283 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 case PTRACE_POKETEXT: /* write the word at location addr. */
287 case PTRACE_POKEDATA: {
288 unsigned long tmp64;
289 unsigned int tmp32;
290 int copied, res = -EIO;
291
292 if (test_thread_flag(TIF_32BIT)) {
293 tmp32 = data;
294 copied = access_process_vm(child, addr,
295 &tmp32, sizeof(tmp32), 1);
296 if (copied == sizeof(tmp32))
297 res = 0;
298 } else {
299 tmp64 = data;
300 copied = access_process_vm(child, addr,
301 &tmp64, sizeof(tmp64), 1);
302 if (copied == sizeof(tmp64))
303 res = 0;
304 }
305 if (res < 0)
306 pt_error_return(regs, -res);
307 else
308 pt_succ_return(regs, res);
David S. Millerdadeafd2005-04-17 18:03:11 -0700309 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312 case PTRACE_GETREGS: {
313 struct pt_regs32 __user *pregs =
314 (struct pt_regs32 __user *) addr;
315 struct pt_regs *cregs = child->thread_info->kregs;
316 int rval;
317
318 if (__put_user(tstate_to_psr(cregs->tstate), (&pregs->psr)) ||
319 __put_user(cregs->tpc, (&pregs->pc)) ||
320 __put_user(cregs->tnpc, (&pregs->npc)) ||
321 __put_user(cregs->y, (&pregs->y))) {
322 pt_error_return(regs, EFAULT);
323 goto out_tsk;
324 }
325 for (rval = 1; rval < 16; rval++)
326 if (__put_user(cregs->u_regs[rval], (&pregs->u_regs[rval - 1]))) {
327 pt_error_return(regs, EFAULT);
328 goto out_tsk;
329 }
330 pt_succ_return(regs, 0);
331#ifdef DEBUG_PTRACE
332 printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);
333#endif
334 goto out_tsk;
335 }
336
337 case PTRACE_GETREGS64: {
338 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
339 struct pt_regs *cregs = child->thread_info->kregs;
340 unsigned long tpc = cregs->tpc;
341 int rval;
342
343 if ((child->thread_info->flags & _TIF_32BIT) != 0)
344 tpc &= 0xffffffff;
345 if (__put_user(cregs->tstate, (&pregs->tstate)) ||
346 __put_user(tpc, (&pregs->tpc)) ||
347 __put_user(cregs->tnpc, (&pregs->tnpc)) ||
348 __put_user(cregs->y, (&pregs->y))) {
349 pt_error_return(regs, EFAULT);
350 goto out_tsk;
351 }
352 for (rval = 1; rval < 16; rval++)
353 if (__put_user(cregs->u_regs[rval], (&pregs->u_regs[rval - 1]))) {
354 pt_error_return(regs, EFAULT);
355 goto out_tsk;
356 }
357 pt_succ_return(regs, 0);
358#ifdef DEBUG_PTRACE
359 printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);
360#endif
361 goto out_tsk;
362 }
363
364 case PTRACE_SETREGS: {
365 struct pt_regs32 __user *pregs =
366 (struct pt_regs32 __user *) addr;
367 struct pt_regs *cregs = child->thread_info->kregs;
368 unsigned int psr, pc, npc, y;
369 int i;
370
371 /* Must be careful, tracing process can only set certain
372 * bits in the psr.
373 */
374 if (__get_user(psr, (&pregs->psr)) ||
375 __get_user(pc, (&pregs->pc)) ||
376 __get_user(npc, (&pregs->npc)) ||
377 __get_user(y, (&pregs->y))) {
378 pt_error_return(regs, EFAULT);
379 goto out_tsk;
380 }
381 cregs->tstate &= ~(TSTATE_ICC);
382 cregs->tstate |= psr_to_tstate_icc(psr);
383 if (!((pc | npc) & 3)) {
384 cregs->tpc = pc;
385 cregs->tnpc = npc;
386 }
387 cregs->y = y;
388 for (i = 1; i < 16; i++) {
389 if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {
390 pt_error_return(regs, EFAULT);
391 goto out_tsk;
392 }
393 }
394 pt_succ_return(regs, 0);
395 goto out_tsk;
396 }
397
398 case PTRACE_SETREGS64: {
399 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
400 struct pt_regs *cregs = child->thread_info->kregs;
401 unsigned long tstate, tpc, tnpc, y;
402 int i;
403
404 /* Must be careful, tracing process can only set certain
405 * bits in the psr.
406 */
407 if (__get_user(tstate, (&pregs->tstate)) ||
408 __get_user(tpc, (&pregs->tpc)) ||
409 __get_user(tnpc, (&pregs->tnpc)) ||
410 __get_user(y, (&pregs->y))) {
411 pt_error_return(regs, EFAULT);
412 goto out_tsk;
413 }
414 if ((child->thread_info->flags & _TIF_32BIT) != 0) {
415 tpc &= 0xffffffff;
416 tnpc &= 0xffffffff;
417 }
418 tstate &= (TSTATE_ICC | TSTATE_XCC);
419 cregs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
420 cregs->tstate |= tstate;
421 if (!((tpc | tnpc) & 3)) {
422 cregs->tpc = tpc;
423 cregs->tnpc = tnpc;
424 }
425 cregs->y = y;
426 for (i = 1; i < 16; i++) {
427 if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {
428 pt_error_return(regs, EFAULT);
429 goto out_tsk;
430 }
431 }
432 pt_succ_return(regs, 0);
433 goto out_tsk;
434 }
435
436 case PTRACE_GETFPREGS: {
437 struct fps {
438 unsigned int regs[32];
439 unsigned int fsr;
440 unsigned int flags;
441 unsigned int extra;
442 unsigned int fpqd;
443 struct fq {
444 unsigned int insnaddr;
445 unsigned int insn;
446 } fpq[16];
447 };
448 struct fps __user *fps = (struct fps __user *) addr;
449 unsigned long *fpregs = child->thread_info->fpregs;
450
451 if (copy_to_user(&fps->regs[0], fpregs,
452 (32 * sizeof(unsigned int))) ||
453 __put_user(child->thread_info->xfsr[0], (&fps->fsr)) ||
454 __put_user(0, (&fps->fpqd)) ||
455 __put_user(0, (&fps->flags)) ||
456 __put_user(0, (&fps->extra)) ||
457 clear_user(&fps->fpq[0], 32 * sizeof(unsigned int))) {
458 pt_error_return(regs, EFAULT);
459 goto out_tsk;
460 }
461 pt_succ_return(regs, 0);
462 goto out_tsk;
463 }
464
465 case PTRACE_GETFPREGS64: {
466 struct fps {
467 unsigned int regs[64];
468 unsigned long fsr;
469 };
470 struct fps __user *fps = (struct fps __user *) addr;
471 unsigned long *fpregs = child->thread_info->fpregs;
472
473 if (copy_to_user(&fps->regs[0], fpregs,
474 (64 * sizeof(unsigned int))) ||
475 __put_user(child->thread_info->xfsr[0], (&fps->fsr))) {
476 pt_error_return(regs, EFAULT);
477 goto out_tsk;
478 }
479 pt_succ_return(regs, 0);
480 goto out_tsk;
481 }
482
483 case PTRACE_SETFPREGS: {
484 struct fps {
485 unsigned int regs[32];
486 unsigned int fsr;
487 unsigned int flags;
488 unsigned int extra;
489 unsigned int fpqd;
490 struct fq {
491 unsigned int insnaddr;
492 unsigned int insn;
493 } fpq[16];
494 };
495 struct fps __user *fps = (struct fps __user *) addr;
496 unsigned long *fpregs = child->thread_info->fpregs;
497 unsigned fsr;
498
499 if (copy_from_user(fpregs, &fps->regs[0],
500 (32 * sizeof(unsigned int))) ||
501 __get_user(fsr, (&fps->fsr))) {
502 pt_error_return(regs, EFAULT);
503 goto out_tsk;
504 }
505 child->thread_info->xfsr[0] &= 0xffffffff00000000UL;
506 child->thread_info->xfsr[0] |= fsr;
507 if (!(child->thread_info->fpsaved[0] & FPRS_FEF))
508 child->thread_info->gsr[0] = 0;
509 child->thread_info->fpsaved[0] |= (FPRS_FEF | FPRS_DL);
510 pt_succ_return(regs, 0);
511 goto out_tsk;
512 }
513
514 case PTRACE_SETFPREGS64: {
515 struct fps {
516 unsigned int regs[64];
517 unsigned long fsr;
518 };
519 struct fps __user *fps = (struct fps __user *) addr;
520 unsigned long *fpregs = child->thread_info->fpregs;
521
522 if (copy_from_user(fpregs, &fps->regs[0],
523 (64 * sizeof(unsigned int))) ||
524 __get_user(child->thread_info->xfsr[0], (&fps->fsr))) {
525 pt_error_return(regs, EFAULT);
526 goto out_tsk;
527 }
528 if (!(child->thread_info->fpsaved[0] & FPRS_FEF))
529 child->thread_info->gsr[0] = 0;
530 child->thread_info->fpsaved[0] |= (FPRS_FEF | FPRS_DL | FPRS_DU);
531 pt_succ_return(regs, 0);
532 goto out_tsk;
533 }
534
535 case PTRACE_READTEXT:
536 case PTRACE_READDATA: {
537 int res = ptrace_readdata(child, addr,
538 (char __user *)addr2, data);
539 if (res == data) {
540 pt_succ_return(regs, 0);
David S. Millerdadeafd2005-04-17 18:03:11 -0700541 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543 if (res >= 0)
544 res = -EIO;
545 pt_error_return(regs, -res);
David S. Millerdadeafd2005-04-17 18:03:11 -0700546 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
548
549 case PTRACE_WRITETEXT:
550 case PTRACE_WRITEDATA: {
551 int res = ptrace_writedata(child, (char __user *) addr2,
552 addr, data);
553 if (res == data) {
554 pt_succ_return(regs, 0);
David S. Millerdadeafd2005-04-17 18:03:11 -0700555 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557 if (res >= 0)
558 res = -EIO;
559 pt_error_return(regs, -res);
David S. Millerdadeafd2005-04-17 18:03:11 -0700560 goto out_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562 case PTRACE_SYSCALL: /* continue and stop at (return from) syscall */
563 addr = 1;
564
565 case PTRACE_CONT: { /* restart after signal. */
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700566 if (!valid_signal(data)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 pt_error_return(regs, EIO);
568 goto out_tsk;
569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 if (request == PTRACE_SYSCALL) {
572 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
573 } else {
574 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
575 }
576
577 child->exit_code = data;
578#ifdef DEBUG_PTRACE
579 printk("CONT: %s [%d]: set exit_code = %x %lx %lx\n", child->comm,
580 child->pid, child->exit_code,
581 child->thread_info->kregs->tpc,
582 child->thread_info->kregs->tnpc);
583
584#endif
585 wake_up_process(child);
586 pt_succ_return(regs, 0);
587 goto out_tsk;
588 }
589
590/*
591 * make the child exit. Best I can do is send it a sigkill.
592 * perhaps it should be put in the status that it wants to
593 * exit.
594 */
595 case PTRACE_KILL: {
596 if (child->exit_state == EXIT_ZOMBIE) { /* already dead */
597 pt_succ_return(regs, 0);
598 goto out_tsk;
599 }
600 child->exit_code = SIGKILL;
601 wake_up_process(child);
602 pt_succ_return(regs, 0);
603 goto out_tsk;
604 }
605
606 case PTRACE_SUNDETACH: { /* detach a process that was attached. */
607 int error = ptrace_detach(child, data);
608 if (error) {
609 pt_error_return(regs, EIO);
610 goto out_tsk;
611 }
612 pt_succ_return(regs, 0);
613 goto out_tsk;
614 }
615
616 /* PTRACE_DUMPCORE unsupported... */
617
618 default: {
619 int err = ptrace_request(child, request, addr, data);
620 if (err)
621 pt_error_return(regs, -err);
622 else
623 pt_succ_return(regs, 0);
624 goto out_tsk;
625 }
626 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627out_tsk:
628 if (child)
629 put_task_struct(child);
630out:
631 unlock_kernel();
632}
633
David S. Miller8d8a6472005-07-10 16:55:48 -0700634asmlinkage void syscall_trace(struct pt_regs *regs, int syscall_exit_p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
David S. Millerbb49bcd2005-07-10 16:49:28 -0700636 /* do the secure computing check first */
David S. Miller8d8a6472005-07-10 16:55:48 -0700637 secure_computing(regs->u_regs[UREG_G1]);
David S. Millerbb49bcd2005-07-10 16:49:28 -0700638
David S. Millerf7ceba32005-07-10 19:29:45 -0700639 if (unlikely(current->audit_context) && syscall_exit_p) {
640 unsigned long tstate = regs->tstate;
641 int result = AUDITSC_SUCCESS;
642
643 if (unlikely(tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
644 result = AUDITSC_FAILURE;
645
646 audit_syscall_exit(current, result, regs->u_regs[UREG_I0]);
647 }
648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 if (!(current->ptrace & PT_PTRACED))
David S. Millerf7ceba32005-07-10 19:29:45 -0700650 goto out;
651
652 if (!test_thread_flag(TIF_SYSCALL_TRACE))
653 goto out;
654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
656 ? 0x80 : 0));
657
658 /*
659 * this isn't the same as continuing with a signal, but it will do
660 * for normal use. strace only continues with a signal if the
661 * stopping signal is not SIGTRAP. -brl
662 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 if (current->exit_code) {
David S. Millerbb49bcd2005-07-10 16:49:28 -0700664 send_sig(current->exit_code, current, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 current->exit_code = 0;
666 }
David S. Millerf7ceba32005-07-10 19:29:45 -0700667
668out:
669 if (unlikely(current->audit_context) && !syscall_exit_p)
670 audit_syscall_entry(current,
671 (test_thread_flag(TIF_32BIT) ?
672 AUDIT_ARCH_SPARC :
673 AUDIT_ARCH_SPARC64),
674 regs->u_regs[UREG_G1],
675 regs->u_regs[UREG_I0],
676 regs->u_regs[UREG_I1],
677 regs->u_regs[UREG_I2],
678 regs->u_regs[UREG_I3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}