ptrace.c 16 KB

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