ptrace.c 17 KB

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