ptrace.c 17 KB

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