ptrace.c 16 KB

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