ptrace.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * linux/arch/m32r/kernel/ptrace.c
  3. *
  4. * Copyright (C) 2002 Hirokazu Takata, Takeo Takahashi
  5. * Copyright (C) 2004 Hirokazu Takata, Kei Sakamoto
  6. *
  7. * Original x86 implementation:
  8. * By Ross Biro 1/23/92
  9. * edited by Linus Torvalds
  10. *
  11. * Some code taken from sh version:
  12. * Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
  13. * Some code taken from arm version:
  14. * Copyright (C) 2000 Russell King
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/mm.h>
  19. #include <linux/err.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/user.h>
  24. #include <linux/string.h>
  25. #include <linux/signal.h>
  26. #include <asm/cacheflush.h>
  27. #include <asm/io.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/system.h>
  31. #include <asm/processor.h>
  32. #include <asm/mmu_context.h>
  33. /*
  34. * This routine will get a word off of the process kernel stack.
  35. */
  36. static inline unsigned long int
  37. get_stack_long(struct task_struct *task, int offset)
  38. {
  39. unsigned long *stack;
  40. stack = (unsigned long *)task_pt_regs(task);
  41. return stack[offset];
  42. }
  43. /*
  44. * This routine will put a word on the process kernel stack.
  45. */
  46. static inline int
  47. put_stack_long(struct task_struct *task, int offset, unsigned long data)
  48. {
  49. unsigned long *stack;
  50. stack = (unsigned long *)task_pt_regs(task);
  51. stack[offset] = data;
  52. return 0;
  53. }
  54. static int reg_offset[] = {
  55. PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
  56. PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_FP, PT_LR, PT_SPU,
  57. };
  58. /*
  59. * Read the word at offset "off" into the "struct user". We
  60. * actually access the pt_regs stored on the kernel stack.
  61. */
  62. static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
  63. unsigned long __user *data)
  64. {
  65. unsigned long tmp;
  66. #ifndef NO_FPU
  67. struct user * dummy = NULL;
  68. #endif
  69. if ((off & 3) || off > sizeof(struct user) - 3)
  70. return -EIO;
  71. off >>= 2;
  72. switch (off) {
  73. case PT_EVB:
  74. __asm__ __volatile__ (
  75. "mvfc %0, cr5 \n\t"
  76. : "=r" (tmp)
  77. );
  78. break;
  79. case PT_CBR: {
  80. unsigned long psw;
  81. psw = get_stack_long(tsk, PT_PSW);
  82. tmp = ((psw >> 8) & 1);
  83. }
  84. break;
  85. case PT_PSW: {
  86. unsigned long psw, bbpsw;
  87. psw = get_stack_long(tsk, PT_PSW);
  88. bbpsw = get_stack_long(tsk, PT_BBPSW);
  89. tmp = ((psw >> 8) & 0xff) | ((bbpsw & 0xff) << 8);
  90. }
  91. break;
  92. case PT_PC:
  93. tmp = get_stack_long(tsk, PT_BPC);
  94. break;
  95. case PT_BPC:
  96. off = PT_BBPC;
  97. /* fall through */
  98. default:
  99. if (off < (sizeof(struct pt_regs) >> 2))
  100. tmp = get_stack_long(tsk, off);
  101. #ifndef NO_FPU
  102. else if (off >= (long)(&dummy->fpu >> 2) &&
  103. off < (long)(&dummy->u_fpvalid >> 2)) {
  104. if (!tsk_used_math(tsk)) {
  105. if (off == (long)(&dummy->fpu.fpscr >> 2))
  106. tmp = FPSCR_INIT;
  107. else
  108. tmp = 0;
  109. } else
  110. tmp = ((long *)(&tsk->thread.fpu >> 2))
  111. [off - (long)&dummy->fpu];
  112. } else if (off == (long)(&dummy->u_fpvalid >> 2))
  113. tmp = !!tsk_used_math(tsk);
  114. #endif /* not NO_FPU */
  115. else
  116. tmp = 0;
  117. }
  118. return put_user(tmp, data);
  119. }
  120. static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
  121. unsigned long data)
  122. {
  123. int ret = -EIO;
  124. #ifndef NO_FPU
  125. struct user * dummy = NULL;
  126. #endif
  127. if ((off & 3) || off > sizeof(struct user) - 3)
  128. return -EIO;
  129. off >>= 2;
  130. switch (off) {
  131. case PT_EVB:
  132. case PT_BPC:
  133. case PT_SPI:
  134. /* We don't allow to modify evb. */
  135. ret = 0;
  136. break;
  137. case PT_PSW:
  138. case PT_CBR: {
  139. /* We allow to modify only cbr in psw */
  140. unsigned long psw;
  141. psw = get_stack_long(tsk, PT_PSW);
  142. psw = (psw & ~0x100) | ((data & 1) << 8);
  143. ret = put_stack_long(tsk, PT_PSW, psw);
  144. }
  145. break;
  146. case PT_PC:
  147. off = PT_BPC;
  148. data &= ~1;
  149. /* fall through */
  150. default:
  151. if (off < (sizeof(struct pt_regs) >> 2))
  152. ret = put_stack_long(tsk, off, data);
  153. #ifndef NO_FPU
  154. else if (off >= (long)(&dummy->fpu >> 2) &&
  155. off < (long)(&dummy->u_fpvalid >> 2)) {
  156. set_stopped_child_used_math(tsk);
  157. ((long *)&tsk->thread.fpu)
  158. [off - (long)&dummy->fpu] = data;
  159. ret = 0;
  160. } else if (off == (long)(&dummy->u_fpvalid >> 2)) {
  161. conditional_stopped_child_used_math(data, tsk);
  162. ret = 0;
  163. }
  164. #endif /* not NO_FPU */
  165. break;
  166. }
  167. return ret;
  168. }
  169. /*
  170. * Get all user integer registers.
  171. */
  172. static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
  173. {
  174. struct pt_regs *regs = task_pt_regs(tsk);
  175. return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
  176. }
  177. /*
  178. * Set all user integer registers.
  179. */
  180. static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
  181. {
  182. struct pt_regs newregs;
  183. int ret;
  184. ret = -EFAULT;
  185. if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
  186. struct pt_regs *regs = task_pt_regs(tsk);
  187. *regs = newregs;
  188. ret = 0;
  189. }
  190. return ret;
  191. }
  192. static inline int
  193. check_condition_bit(struct task_struct *child)
  194. {
  195. return (int)((get_stack_long(child, PT_PSW) >> 8) & 1);
  196. }
  197. static int
  198. check_condition_src(unsigned long op, unsigned long regno1,
  199. unsigned long regno2, struct task_struct *child)
  200. {
  201. unsigned long reg1, reg2;
  202. reg2 = get_stack_long(child, reg_offset[regno2]);
  203. switch (op) {
  204. case 0x0: /* BEQ */
  205. reg1 = get_stack_long(child, reg_offset[regno1]);
  206. return reg1 == reg2;
  207. case 0x1: /* BNE */
  208. reg1 = get_stack_long(child, reg_offset[regno1]);
  209. return reg1 != reg2;
  210. case 0x8: /* BEQZ */
  211. return reg2 == 0;
  212. case 0x9: /* BNEZ */
  213. return reg2 != 0;
  214. case 0xa: /* BLTZ */
  215. return (int)reg2 < 0;
  216. case 0xb: /* BGEZ */
  217. return (int)reg2 >= 0;
  218. case 0xc: /* BLEZ */
  219. return (int)reg2 <= 0;
  220. case 0xd: /* BGTZ */
  221. return (int)reg2 > 0;
  222. default:
  223. /* never reached */
  224. return 0;
  225. }
  226. }
  227. static void
  228. compute_next_pc_for_16bit_insn(unsigned long insn, unsigned long pc,
  229. unsigned long *next_pc,
  230. struct task_struct *child)
  231. {
  232. unsigned long op, op2, op3;
  233. unsigned long disp;
  234. unsigned long regno;
  235. int parallel = 0;
  236. if (insn & 0x00008000)
  237. parallel = 1;
  238. if (pc & 3)
  239. insn &= 0x7fff; /* right slot */
  240. else
  241. insn >>= 16; /* left slot */
  242. op = (insn >> 12) & 0xf;
  243. op2 = (insn >> 8) & 0xf;
  244. op3 = (insn >> 4) & 0xf;
  245. if (op == 0x7) {
  246. switch (op2) {
  247. case 0xd: /* BNC */
  248. case 0x9: /* BNCL */
  249. if (!check_condition_bit(child)) {
  250. disp = (long)(insn << 24) >> 22;
  251. *next_pc = (pc & ~0x3) + disp;
  252. return;
  253. }
  254. break;
  255. case 0x8: /* BCL */
  256. case 0xc: /* BC */
  257. if (check_condition_bit(child)) {
  258. disp = (long)(insn << 24) >> 22;
  259. *next_pc = (pc & ~0x3) + disp;
  260. return;
  261. }
  262. break;
  263. case 0xe: /* BL */
  264. case 0xf: /* BRA */
  265. disp = (long)(insn << 24) >> 22;
  266. *next_pc = (pc & ~0x3) + disp;
  267. return;
  268. break;
  269. }
  270. } else if (op == 0x1) {
  271. switch (op2) {
  272. case 0x0:
  273. if (op3 == 0xf) { /* TRAP */
  274. #if 1
  275. /* pass through */
  276. #else
  277. /* kernel space is not allowed as next_pc */
  278. unsigned long evb;
  279. unsigned long trapno;
  280. trapno = insn & 0xf;
  281. __asm__ __volatile__ (
  282. "mvfc %0, cr5\n"
  283. :"=r"(evb)
  284. :
  285. );
  286. *next_pc = evb + (trapno << 2);
  287. return;
  288. #endif
  289. } else if (op3 == 0xd) { /* RTE */
  290. *next_pc = get_stack_long(child, PT_BPC);
  291. return;
  292. }
  293. break;
  294. case 0xc: /* JC */
  295. if (op3 == 0xc && check_condition_bit(child)) {
  296. regno = insn & 0xf;
  297. *next_pc = get_stack_long(child,
  298. reg_offset[regno]);
  299. return;
  300. }
  301. break;
  302. case 0xd: /* JNC */
  303. if (op3 == 0xc && !check_condition_bit(child)) {
  304. regno = insn & 0xf;
  305. *next_pc = get_stack_long(child,
  306. reg_offset[regno]);
  307. return;
  308. }
  309. break;
  310. case 0xe: /* JL */
  311. case 0xf: /* JMP */
  312. if (op3 == 0xc) { /* JMP */
  313. regno = insn & 0xf;
  314. *next_pc = get_stack_long(child,
  315. reg_offset[regno]);
  316. return;
  317. }
  318. break;
  319. }
  320. }
  321. if (parallel)
  322. *next_pc = pc + 4;
  323. else
  324. *next_pc = pc + 2;
  325. }
  326. static void
  327. compute_next_pc_for_32bit_insn(unsigned long insn, unsigned long pc,
  328. unsigned long *next_pc,
  329. struct task_struct *child)
  330. {
  331. unsigned long op;
  332. unsigned long op2;
  333. unsigned long disp;
  334. unsigned long regno1, regno2;
  335. op = (insn >> 28) & 0xf;
  336. if (op == 0xf) { /* branch 24-bit relative */
  337. op2 = (insn >> 24) & 0xf;
  338. switch (op2) {
  339. case 0xd: /* BNC */
  340. case 0x9: /* BNCL */
  341. if (!check_condition_bit(child)) {
  342. disp = (long)(insn << 8) >> 6;
  343. *next_pc = (pc & ~0x3) + disp;
  344. return;
  345. }
  346. break;
  347. case 0x8: /* BCL */
  348. case 0xc: /* BC */
  349. if (check_condition_bit(child)) {
  350. disp = (long)(insn << 8) >> 6;
  351. *next_pc = (pc & ~0x3) + disp;
  352. return;
  353. }
  354. break;
  355. case 0xe: /* BL */
  356. case 0xf: /* BRA */
  357. disp = (long)(insn << 8) >> 6;
  358. *next_pc = (pc & ~0x3) + disp;
  359. return;
  360. }
  361. } else if (op == 0xb) { /* branch 16-bit relative */
  362. op2 = (insn >> 20) & 0xf;
  363. switch (op2) {
  364. case 0x0: /* BEQ */
  365. case 0x1: /* BNE */
  366. case 0x8: /* BEQZ */
  367. case 0x9: /* BNEZ */
  368. case 0xa: /* BLTZ */
  369. case 0xb: /* BGEZ */
  370. case 0xc: /* BLEZ */
  371. case 0xd: /* BGTZ */
  372. regno1 = ((insn >> 24) & 0xf);
  373. regno2 = ((insn >> 16) & 0xf);
  374. if (check_condition_src(op2, regno1, regno2, child)) {
  375. disp = (long)(insn << 16) >> 14;
  376. *next_pc = (pc & ~0x3) + disp;
  377. return;
  378. }
  379. break;
  380. }
  381. }
  382. *next_pc = pc + 4;
  383. }
  384. static inline void
  385. compute_next_pc(unsigned long insn, unsigned long pc,
  386. unsigned long *next_pc, struct task_struct *child)
  387. {
  388. if (insn & 0x80000000)
  389. compute_next_pc_for_32bit_insn(insn, pc, next_pc, child);
  390. else
  391. compute_next_pc_for_16bit_insn(insn, pc, next_pc, child);
  392. }
  393. static int
  394. register_debug_trap(struct task_struct *child, unsigned long next_pc,
  395. unsigned long next_insn, unsigned long *code)
  396. {
  397. struct debug_trap *p = &child->thread.debug_trap;
  398. unsigned long addr = next_pc & ~3;
  399. if (p->nr_trap == MAX_TRAPS) {
  400. printk("kernel BUG at %s %d: p->nr_trap = %d\n",
  401. __FILE__, __LINE__, p->nr_trap);
  402. return -1;
  403. }
  404. p->addr[p->nr_trap] = addr;
  405. p->insn[p->nr_trap] = next_insn;
  406. p->nr_trap++;
  407. if (next_pc & 3) {
  408. *code = (next_insn & 0xffff0000) | 0x10f1;
  409. /* xxx --> TRAP1 */
  410. } else {
  411. if ((next_insn & 0x80000000) || (next_insn & 0x8000)) {
  412. *code = 0x10f17000;
  413. /* TRAP1 --> NOP */
  414. } else {
  415. *code = (next_insn & 0xffff) | 0x10f10000;
  416. /* TRAP1 --> xxx */
  417. }
  418. }
  419. return 0;
  420. }
  421. static int
  422. unregister_debug_trap(struct task_struct *child, unsigned long addr,
  423. unsigned long *code)
  424. {
  425. struct debug_trap *p = &child->thread.debug_trap;
  426. int i;
  427. /* Search debug trap entry. */
  428. for (i = 0; i < p->nr_trap; i++) {
  429. if (p->addr[i] == addr)
  430. break;
  431. }
  432. if (i >= p->nr_trap) {
  433. /* The trap may be requested from debugger.
  434. * ptrace should do nothing in this case.
  435. */
  436. return 0;
  437. }
  438. /* Recover original instruction code. */
  439. *code = p->insn[i];
  440. /* Shift debug trap entries. */
  441. while (i < p->nr_trap - 1) {
  442. p->insn[i] = p->insn[i + 1];
  443. p->addr[i] = p->addr[i + 1];
  444. i++;
  445. }
  446. p->nr_trap--;
  447. return 1;
  448. }
  449. static void
  450. unregister_all_debug_traps(struct task_struct *child)
  451. {
  452. struct debug_trap *p = &child->thread.debug_trap;
  453. int i;
  454. for (i = 0; i < p->nr_trap; i++)
  455. access_process_vm(child, p->addr[i], &p->insn[i], sizeof(p->insn[i]), 1);
  456. p->nr_trap = 0;
  457. }
  458. static inline void
  459. invalidate_cache(void)
  460. {
  461. #if defined(CONFIG_CHIP_M32700) || defined(CONFIG_CHIP_OPSP)
  462. _flush_cache_copyback_all();
  463. #else /* ! CONFIG_CHIP_M32700 */
  464. /* Invalidate cache */
  465. __asm__ __volatile__ (
  466. "ldi r0, #-1 \n\t"
  467. "ldi r1, #0 \n\t"
  468. "stb r1, @r0 ; cache off \n\t"
  469. "; \n\t"
  470. "ldi r0, #-2 \n\t"
  471. "ldi r1, #1 \n\t"
  472. "stb r1, @r0 ; cache invalidate \n\t"
  473. ".fillinsn \n"
  474. "0: \n\t"
  475. "ldb r1, @r0 ; invalidate check \n\t"
  476. "bnez r1, 0b \n\t"
  477. "; \n\t"
  478. "ldi r0, #-1 \n\t"
  479. "ldi r1, #1 \n\t"
  480. "stb r1, @r0 ; cache on \n\t"
  481. : : : "r0", "r1", "memory"
  482. );
  483. /* FIXME: copying-back d-cache and invalidating i-cache are needed.
  484. */
  485. #endif /* CONFIG_CHIP_M32700 */
  486. }
  487. /* Embed a debug trap (TRAP1) code */
  488. static int
  489. embed_debug_trap(struct task_struct *child, unsigned long next_pc)
  490. {
  491. unsigned long next_insn, code;
  492. unsigned long addr = next_pc & ~3;
  493. if (access_process_vm(child, addr, &next_insn, sizeof(next_insn), 0)
  494. != sizeof(next_insn)) {
  495. return -1; /* error */
  496. }
  497. /* Set a trap code. */
  498. if (register_debug_trap(child, next_pc, next_insn, &code)) {
  499. return -1; /* error */
  500. }
  501. if (access_process_vm(child, addr, &code, sizeof(code), 1)
  502. != sizeof(code)) {
  503. return -1; /* error */
  504. }
  505. return 0; /* success */
  506. }
  507. void
  508. withdraw_debug_trap(struct pt_regs *regs)
  509. {
  510. unsigned long addr;
  511. unsigned long code;
  512. addr = (regs->bpc - 2) & ~3;
  513. regs->bpc -= 2;
  514. if (unregister_debug_trap(current, addr, &code)) {
  515. access_process_vm(current, addr, &code, sizeof(code), 1);
  516. invalidate_cache();
  517. }
  518. }
  519. void
  520. init_debug_traps(struct task_struct *child)
  521. {
  522. struct debug_trap *p = &child->thread.debug_trap;
  523. int i;
  524. p->nr_trap = 0;
  525. for (i = 0; i < MAX_TRAPS; i++) {
  526. p->addr[i] = 0;
  527. p->insn[i] = 0;
  528. }
  529. }
  530. /*
  531. * Called by kernel/ptrace.c when detaching..
  532. *
  533. * Make sure single step bits etc are not set.
  534. */
  535. void ptrace_disable(struct task_struct *child)
  536. {
  537. /* nothing to do.. */
  538. }
  539. long
  540. arch_ptrace(struct task_struct *child, long request, long addr, long data)
  541. {
  542. int ret;
  543. switch (request) {
  544. /*
  545. * read word at location "addr" in the child process.
  546. */
  547. case PTRACE_PEEKTEXT:
  548. case PTRACE_PEEKDATA:
  549. ret = generic_ptrace_peekdata(child, addr, data);
  550. break;
  551. /*
  552. * read the word at location addr in the USER area.
  553. */
  554. case PTRACE_PEEKUSR:
  555. ret = ptrace_read_user(child, addr,
  556. (unsigned long __user *)data);
  557. break;
  558. /*
  559. * write the word at location addr.
  560. */
  561. case PTRACE_POKETEXT:
  562. case PTRACE_POKEDATA:
  563. ret = generic_ptrace_pokedata(child, addr, data);
  564. if (ret == 0 && request == PTRACE_POKETEXT)
  565. invalidate_cache();
  566. break;
  567. /*
  568. * write the word at location addr in the USER area.
  569. */
  570. case PTRACE_POKEUSR:
  571. ret = ptrace_write_user(child, addr, data);
  572. break;
  573. /*
  574. * continue/restart and stop at next (return from) syscall
  575. */
  576. case PTRACE_SYSCALL:
  577. case PTRACE_CONT:
  578. ret = -EIO;
  579. if (!valid_signal(data))
  580. break;
  581. if (request == PTRACE_SYSCALL)
  582. set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  583. else
  584. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  585. child->exit_code = data;
  586. wake_up_process(child);
  587. ret = 0;
  588. break;
  589. /*
  590. * make the child exit. Best I can do is send it a sigkill.
  591. * perhaps it should be put in the status that it wants to
  592. * exit.
  593. */
  594. case PTRACE_KILL: {
  595. ret = 0;
  596. unregister_all_debug_traps(child);
  597. invalidate_cache();
  598. if (child->exit_state == EXIT_ZOMBIE) /* already dead */
  599. break;
  600. child->exit_code = SIGKILL;
  601. wake_up_process(child);
  602. break;
  603. }
  604. /*
  605. * execute single instruction.
  606. */
  607. case PTRACE_SINGLESTEP: {
  608. unsigned long next_pc;
  609. unsigned long pc, insn;
  610. ret = -EIO;
  611. if (!valid_signal(data))
  612. break;
  613. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  614. /* Compute next pc. */
  615. pc = get_stack_long(child, PT_BPC);
  616. if (access_process_vm(child, pc&~3, &insn, sizeof(insn), 0)
  617. != sizeof(insn))
  618. break;
  619. compute_next_pc(insn, pc, &next_pc, child);
  620. if (next_pc & 0x80000000)
  621. break;
  622. if (embed_debug_trap(child, next_pc))
  623. break;
  624. invalidate_cache();
  625. child->exit_code = data;
  626. /* give it a chance to run. */
  627. wake_up_process(child);
  628. ret = 0;
  629. break;
  630. }
  631. case PTRACE_GETREGS:
  632. ret = ptrace_getregs(child, (void __user *)data);
  633. break;
  634. case PTRACE_SETREGS:
  635. ret = ptrace_setregs(child, (void __user *)data);
  636. break;
  637. default:
  638. ret = ptrace_request(child, request, addr, data);
  639. break;
  640. }
  641. return ret;
  642. }
  643. /* notification of system call entry/exit
  644. * - triggered by current->work.syscall_trace
  645. */
  646. void do_syscall_trace(void)
  647. {
  648. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  649. return;
  650. if (!(current->ptrace & PT_PTRACED))
  651. return;
  652. /* the 0x80 provides a way for the tracing parent to distinguish
  653. between a syscall stop and SIGTRAP delivery */
  654. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  655. ? 0x80 : 0));
  656. /*
  657. * this isn't the same as continuing with a signal, but it will do
  658. * for normal use. strace only continues with a signal if the
  659. * stopping signal is not SIGTRAP. -brl
  660. */
  661. if (current->exit_code) {
  662. send_sig(current->exit_code, current, 1);
  663. current->exit_code = 0;
  664. }
  665. }