ptrace.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Derived from "arch/m68k/kernel/ptrace.c"
  6. * Copyright (C) 1994 by Hamish Macdonald
  7. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  8. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  9. *
  10. * Modified by Cort Dougan (cort@hq.fsmlabs.com)
  11. * and Paul Mackerras (paulus@samba.org).
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file README.legal in the main directory of
  15. * this archive for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/regset.h>
  24. #include <linux/elf.h>
  25. #include <linux/user.h>
  26. #include <linux/security.h>
  27. #include <linux/signal.h>
  28. #include <linux/seccomp.h>
  29. #include <linux/audit.h>
  30. #ifdef CONFIG_PPC32
  31. #include <linux/module.h>
  32. #endif
  33. #include <asm/uaccess.h>
  34. #include <asm/page.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/system.h>
  37. /*
  38. * does not yet catch signals sent when the child dies.
  39. * in exit.c or in signal.c.
  40. */
  41. /*
  42. * Set of msr bits that gdb can change on behalf of a process.
  43. */
  44. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  45. #define MSR_DEBUGCHANGE 0
  46. #else
  47. #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
  48. #endif
  49. /*
  50. * Max register writeable via put_reg
  51. */
  52. #ifdef CONFIG_PPC32
  53. #define PT_MAX_PUT_REG PT_MQ
  54. #else
  55. #define PT_MAX_PUT_REG PT_CCR
  56. #endif
  57. static unsigned long get_user_msr(struct task_struct *task)
  58. {
  59. return task->thread.regs->msr | task->thread.fpexc_mode;
  60. }
  61. static int set_user_msr(struct task_struct *task, unsigned long msr)
  62. {
  63. task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
  64. task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
  65. return 0;
  66. }
  67. /*
  68. * We prevent mucking around with the reserved area of trap
  69. * which are used internally by the kernel.
  70. */
  71. static int set_user_trap(struct task_struct *task, unsigned long trap)
  72. {
  73. task->thread.regs->trap = trap & 0xfff0;
  74. return 0;
  75. }
  76. /*
  77. * Get contents of register REGNO in task TASK.
  78. */
  79. unsigned long ptrace_get_reg(struct task_struct *task, int regno)
  80. {
  81. if (task->thread.regs == NULL)
  82. return -EIO;
  83. if (regno == PT_MSR)
  84. return get_user_msr(task);
  85. if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long)))
  86. return ((unsigned long *)task->thread.regs)[regno];
  87. return -EIO;
  88. }
  89. /*
  90. * Write contents of register REGNO in task TASK.
  91. */
  92. int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
  93. {
  94. if (task->thread.regs == NULL)
  95. return -EIO;
  96. if (regno == PT_MSR)
  97. return set_user_msr(task, data);
  98. if (regno == PT_TRAP)
  99. return set_user_trap(task, data);
  100. if (regno <= PT_MAX_PUT_REG) {
  101. ((unsigned long *)task->thread.regs)[regno] = data;
  102. return 0;
  103. }
  104. return -EIO;
  105. }
  106. static int fpr_get(struct task_struct *target, const struct user_regset *regset,
  107. unsigned int pos, unsigned int count,
  108. void *kbuf, void __user *ubuf)
  109. {
  110. flush_fp_to_thread(target);
  111. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  112. offsetof(struct thread_struct, fpr[32]));
  113. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  114. &target->thread.fpr, 0, -1);
  115. }
  116. static int fpr_set(struct task_struct *target, const struct user_regset *regset,
  117. unsigned int pos, unsigned int count,
  118. const void *kbuf, const void __user *ubuf)
  119. {
  120. flush_fp_to_thread(target);
  121. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  122. offsetof(struct thread_struct, fpr[32]));
  123. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  124. &target->thread.fpr, 0, -1);
  125. }
  126. static int get_fpregs(void __user *data, struct task_struct *task,
  127. int has_fpscr)
  128. {
  129. unsigned int count = has_fpscr ? 33 : 32;
  130. if (!access_ok(VERIFY_WRITE, data, count * sizeof(double)))
  131. return -EFAULT;
  132. return fpr_get(task, NULL, 0, count * sizeof(double), NULL, data);
  133. }
  134. static int set_fpregs(void __user *data, struct task_struct *task,
  135. int has_fpscr)
  136. {
  137. unsigned int count = has_fpscr ? 33 : 32;
  138. if (!access_ok(VERIFY_READ, data, count * sizeof(double)))
  139. return -EFAULT;
  140. return fpr_set(task, NULL, 0, count * sizeof(double), NULL, data);
  141. }
  142. #ifdef CONFIG_ALTIVEC
  143. /*
  144. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  145. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  146. * corresponding vector registers. Quadword 32 contains the vscr as the
  147. * last word (offset 12) within that quadword. Quadword 33 contains the
  148. * vrsave as the first word (offset 0) within the quadword.
  149. *
  150. * This definition of the VMX state is compatible with the current PPC32
  151. * ptrace interface. This allows signal handling and ptrace to use the
  152. * same structures. This also simplifies the implementation of a bi-arch
  153. * (combined (32- and 64-bit) gdb.
  154. */
  155. static int vr_active(struct task_struct *target,
  156. const struct user_regset *regset)
  157. {
  158. flush_altivec_to_thread(target);
  159. return target->thread.used_vr ? regset->n : 0;
  160. }
  161. static int vr_get(struct task_struct *target, const struct user_regset *regset,
  162. unsigned int pos, unsigned int count,
  163. void *kbuf, void __user *ubuf)
  164. {
  165. int ret;
  166. flush_altivec_to_thread(target);
  167. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  168. offsetof(struct thread_struct, vr[32]));
  169. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  170. &target->thread.vr, 0,
  171. 33 * sizeof(vector128));
  172. if (!ret) {
  173. /*
  174. * Copy out only the low-order word of vrsave.
  175. */
  176. union {
  177. elf_vrreg_t reg;
  178. u32 word;
  179. } vrsave;
  180. memset(&vrsave, 0, sizeof(vrsave));
  181. vrsave.word = target->thread.vrsave;
  182. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  183. 33 * sizeof(vector128), -1);
  184. }
  185. return ret;
  186. }
  187. static int vr_set(struct task_struct *target, const struct user_regset *regset,
  188. unsigned int pos, unsigned int count,
  189. const void *kbuf, const void __user *ubuf)
  190. {
  191. int ret;
  192. flush_altivec_to_thread(target);
  193. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  194. offsetof(struct thread_struct, vr[32]));
  195. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  196. &target->thread.vr, 0, 33 * sizeof(vector128));
  197. if (!ret && count > 0) {
  198. /*
  199. * We use only the first word of vrsave.
  200. */
  201. union {
  202. elf_vrreg_t reg;
  203. u32 word;
  204. } vrsave;
  205. memset(&vrsave, 0, sizeof(vrsave));
  206. vrsave.word = target->thread.vrsave;
  207. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  208. 33 * sizeof(vector128), -1);
  209. if (!ret)
  210. target->thread.vrsave = vrsave.word;
  211. }
  212. return ret;
  213. }
  214. /*
  215. * Get contents of AltiVec register state in task TASK
  216. */
  217. static int get_vrregs(unsigned long __user *data, struct task_struct *task)
  218. {
  219. if (!access_ok(VERIFY_WRITE, data,
  220. 33 * sizeof(vector128) + sizeof(u32)))
  221. return -EFAULT;
  222. return vr_get(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32),
  223. NULL, data);
  224. }
  225. /*
  226. * Write contents of AltiVec register state into task TASK.
  227. */
  228. static int set_vrregs(struct task_struct *task, unsigned long __user *data)
  229. {
  230. if (!access_ok(VERIFY_READ, data, 33 * sizeof(vector128) + sizeof(u32)))
  231. return -EFAULT;
  232. return vr_set(task, NULL, 0, 33 * sizeof(vector128) + sizeof(u32),
  233. NULL, data);
  234. }
  235. #endif /* CONFIG_ALTIVEC */
  236. #ifdef CONFIG_SPE
  237. /*
  238. * For get_evrregs/set_evrregs functions 'data' has the following layout:
  239. *
  240. * struct {
  241. * u32 evr[32];
  242. * u64 acc;
  243. * u32 spefscr;
  244. * }
  245. */
  246. static int evr_active(struct task_struct *target,
  247. const struct user_regset *regset)
  248. {
  249. flush_spe_to_thread(target);
  250. return target->thread.used_spe ? regset->n : 0;
  251. }
  252. static int evr_get(struct task_struct *target, const struct user_regset *regset,
  253. unsigned int pos, unsigned int count,
  254. void *kbuf, void __user *ubuf)
  255. {
  256. int ret;
  257. flush_spe_to_thread(target);
  258. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  259. &target->thread.evr,
  260. 0, sizeof(target->thread.evr));
  261. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  262. offsetof(struct thread_struct, spefscr));
  263. if (!ret)
  264. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  265. &target->thread.acc,
  266. sizeof(target->thread.evr), -1);
  267. return ret;
  268. }
  269. static int evr_set(struct task_struct *target, const struct user_regset *regset,
  270. unsigned int pos, unsigned int count,
  271. const void *kbuf, const void __user *ubuf)
  272. {
  273. int ret;
  274. flush_spe_to_thread(target);
  275. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  276. &target->thread.evr,
  277. 0, sizeof(target->thread.evr));
  278. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  279. offsetof(struct thread_struct, spefscr));
  280. if (!ret)
  281. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  282. &target->thread.acc,
  283. sizeof(target->thread.evr), -1);
  284. return ret;
  285. }
  286. /*
  287. * Get contents of SPE register state in task TASK.
  288. */
  289. static int get_evrregs(unsigned long __user *data, struct task_struct *task)
  290. {
  291. if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(u32)))
  292. return -EFAULT;
  293. return evr_get(task, NULL, 0, 35 * sizeof(u32), NULL, data);
  294. }
  295. /*
  296. * Write contents of SPE register state into task TASK.
  297. */
  298. static int set_evrregs(struct task_struct *task, unsigned long *data)
  299. {
  300. if (!access_ok(VERIFY_READ, data, 35 * sizeof(u32)))
  301. return -EFAULT;
  302. return evr_set(task, NULL, 0, 35 * sizeof(u32), NULL, data);
  303. }
  304. #endif /* CONFIG_SPE */
  305. void user_enable_single_step(struct task_struct *task)
  306. {
  307. struct pt_regs *regs = task->thread.regs;
  308. if (regs != NULL) {
  309. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  310. task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
  311. regs->msr |= MSR_DE;
  312. #else
  313. regs->msr |= MSR_SE;
  314. #endif
  315. }
  316. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  317. }
  318. void user_disable_single_step(struct task_struct *task)
  319. {
  320. struct pt_regs *regs = task->thread.regs;
  321. if (regs != NULL) {
  322. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  323. task->thread.dbcr0 = 0;
  324. regs->msr &= ~MSR_DE;
  325. #else
  326. regs->msr &= ~MSR_SE;
  327. #endif
  328. }
  329. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  330. }
  331. static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
  332. unsigned long data)
  333. {
  334. /* We only support one DABR and no IABRS at the moment */
  335. if (addr > 0)
  336. return -EINVAL;
  337. /* The bottom 3 bits are flags */
  338. if ((data & ~0x7UL) >= TASK_SIZE)
  339. return -EIO;
  340. /* Ensure translation is on */
  341. if (data && !(data & DABR_TRANSLATION))
  342. return -EIO;
  343. task->thread.dabr = data;
  344. return 0;
  345. }
  346. /*
  347. * Called by kernel/ptrace.c when detaching..
  348. *
  349. * Make sure single step bits etc are not set.
  350. */
  351. void ptrace_disable(struct task_struct *child)
  352. {
  353. /* make sure the single step bit is not set. */
  354. user_disable_single_step(child);
  355. }
  356. /*
  357. * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
  358. * we mark them as obsolete now, they will be removed in a future version
  359. */
  360. static long arch_ptrace_old(struct task_struct *child, long request, long addr,
  361. long data)
  362. {
  363. int ret = -EPERM;
  364. switch(request) {
  365. case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
  366. int i;
  367. unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
  368. unsigned long __user *tmp = (unsigned long __user *)addr;
  369. CHECK_FULL_REGS(child->thread.regs);
  370. for (i = 0; i < 32; i++) {
  371. ret = put_user(*reg, tmp);
  372. if (ret)
  373. break;
  374. reg++;
  375. tmp++;
  376. }
  377. break;
  378. }
  379. case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
  380. int i;
  381. unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
  382. unsigned long __user *tmp = (unsigned long __user *)addr;
  383. CHECK_FULL_REGS(child->thread.regs);
  384. for (i = 0; i < 32; i++) {
  385. ret = get_user(*reg, tmp);
  386. if (ret)
  387. break;
  388. reg++;
  389. tmp++;
  390. }
  391. break;
  392. }
  393. case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
  394. flush_fp_to_thread(child);
  395. ret = get_fpregs((void __user *)addr, child, 0);
  396. break;
  397. }
  398. case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
  399. flush_fp_to_thread(child);
  400. ret = set_fpregs((void __user *)addr, child, 0);
  401. break;
  402. }
  403. }
  404. return ret;
  405. }
  406. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  407. {
  408. int ret = -EPERM;
  409. switch (request) {
  410. /* when I and D space are separate, these will need to be fixed. */
  411. case PTRACE_PEEKTEXT: /* read word at location addr. */
  412. case PTRACE_PEEKDATA:
  413. ret = generic_ptrace_peekdata(child, addr, data);
  414. break;
  415. /* read the word at location addr in the USER area. */
  416. case PTRACE_PEEKUSR: {
  417. unsigned long index, tmp;
  418. ret = -EIO;
  419. /* convert to index and check */
  420. #ifdef CONFIG_PPC32
  421. index = (unsigned long) addr >> 2;
  422. if ((addr & 3) || (index > PT_FPSCR)
  423. || (child->thread.regs == NULL))
  424. #else
  425. index = (unsigned long) addr >> 3;
  426. if ((addr & 7) || (index > PT_FPSCR))
  427. #endif
  428. break;
  429. CHECK_FULL_REGS(child->thread.regs);
  430. if (index < PT_FPR0) {
  431. tmp = ptrace_get_reg(child, (int) index);
  432. } else {
  433. flush_fp_to_thread(child);
  434. tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
  435. }
  436. ret = put_user(tmp,(unsigned long __user *) data);
  437. break;
  438. }
  439. /* If I and D space are separate, this will have to be fixed. */
  440. case PTRACE_POKETEXT: /* write the word at location addr. */
  441. case PTRACE_POKEDATA:
  442. ret = generic_ptrace_pokedata(child, addr, data);
  443. break;
  444. /* write the word at location addr in the USER area */
  445. case PTRACE_POKEUSR: {
  446. unsigned long index;
  447. ret = -EIO;
  448. /* convert to index and check */
  449. #ifdef CONFIG_PPC32
  450. index = (unsigned long) addr >> 2;
  451. if ((addr & 3) || (index > PT_FPSCR)
  452. || (child->thread.regs == NULL))
  453. #else
  454. index = (unsigned long) addr >> 3;
  455. if ((addr & 7) || (index > PT_FPSCR))
  456. #endif
  457. break;
  458. CHECK_FULL_REGS(child->thread.regs);
  459. if (index < PT_FPR0) {
  460. ret = ptrace_put_reg(child, index, data);
  461. } else {
  462. flush_fp_to_thread(child);
  463. ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
  464. ret = 0;
  465. }
  466. break;
  467. }
  468. case PTRACE_GET_DEBUGREG: {
  469. ret = -EINVAL;
  470. /* We only support one DABR and no IABRS at the moment */
  471. if (addr > 0)
  472. break;
  473. ret = put_user(child->thread.dabr,
  474. (unsigned long __user *)data);
  475. break;
  476. }
  477. case PTRACE_SET_DEBUGREG:
  478. ret = ptrace_set_debugreg(child, addr, data);
  479. break;
  480. #ifdef CONFIG_PPC64
  481. case PTRACE_GETREGS64:
  482. #endif
  483. case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
  484. int ui;
  485. if (!access_ok(VERIFY_WRITE, (void __user *)data,
  486. sizeof(struct pt_regs))) {
  487. ret = -EIO;
  488. break;
  489. }
  490. CHECK_FULL_REGS(child->thread.regs);
  491. ret = 0;
  492. for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
  493. ret |= __put_user(ptrace_get_reg(child, ui),
  494. (unsigned long __user *) data);
  495. data += sizeof(long);
  496. }
  497. break;
  498. }
  499. #ifdef CONFIG_PPC64
  500. case PTRACE_SETREGS64:
  501. #endif
  502. case PTRACE_SETREGS: { /* Set all gp regs in the child. */
  503. unsigned long tmp;
  504. int ui;
  505. if (!access_ok(VERIFY_READ, (void __user *)data,
  506. sizeof(struct pt_regs))) {
  507. ret = -EIO;
  508. break;
  509. }
  510. CHECK_FULL_REGS(child->thread.regs);
  511. ret = 0;
  512. for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
  513. ret = __get_user(tmp, (unsigned long __user *) data);
  514. if (ret)
  515. break;
  516. ptrace_put_reg(child, ui, tmp);
  517. data += sizeof(long);
  518. }
  519. break;
  520. }
  521. case PTRACE_GETFPREGS: { /* Get the child FPU state (FPR0...31 + FPSCR) */
  522. flush_fp_to_thread(child);
  523. ret = get_fpregs((void __user *)data, child, 1);
  524. break;
  525. }
  526. case PTRACE_SETFPREGS: { /* Set the child FPU state (FPR0...31 + FPSCR) */
  527. flush_fp_to_thread(child);
  528. ret = set_fpregs((void __user *)data, child, 1);
  529. break;
  530. }
  531. #ifdef CONFIG_ALTIVEC
  532. case PTRACE_GETVRREGS:
  533. /* Get the child altivec register state. */
  534. flush_altivec_to_thread(child);
  535. ret = get_vrregs((unsigned long __user *)data, child);
  536. break;
  537. case PTRACE_SETVRREGS:
  538. /* Set the child altivec register state. */
  539. flush_altivec_to_thread(child);
  540. ret = set_vrregs(child, (unsigned long __user *)data);
  541. break;
  542. #endif
  543. #ifdef CONFIG_SPE
  544. case PTRACE_GETEVRREGS:
  545. /* Get the child spe register state. */
  546. flush_spe_to_thread(child);
  547. ret = get_evrregs((unsigned long __user *)data, child);
  548. break;
  549. case PTRACE_SETEVRREGS:
  550. /* Set the child spe register state. */
  551. /* this is to clear the MSR_SPE bit to force a reload
  552. * of register state from memory */
  553. flush_spe_to_thread(child);
  554. ret = set_evrregs(child, (unsigned long __user *)data);
  555. break;
  556. #endif
  557. /* Old reverse args ptrace callss */
  558. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  559. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  560. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  561. case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
  562. ret = arch_ptrace_old(child, request, addr, data);
  563. break;
  564. default:
  565. ret = ptrace_request(child, request, addr, data);
  566. break;
  567. }
  568. return ret;
  569. }
  570. static void do_syscall_trace(void)
  571. {
  572. /* the 0x80 provides a way for the tracing parent to distinguish
  573. between a syscall stop and SIGTRAP delivery */
  574. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  575. ? 0x80 : 0));
  576. /*
  577. * this isn't the same as continuing with a signal, but it will do
  578. * for normal use. strace only continues with a signal if the
  579. * stopping signal is not SIGTRAP. -brl
  580. */
  581. if (current->exit_code) {
  582. send_sig(current->exit_code, current, 1);
  583. current->exit_code = 0;
  584. }
  585. }
  586. void do_syscall_trace_enter(struct pt_regs *regs)
  587. {
  588. secure_computing(regs->gpr[0]);
  589. if (test_thread_flag(TIF_SYSCALL_TRACE)
  590. && (current->ptrace & PT_PTRACED))
  591. do_syscall_trace();
  592. if (unlikely(current->audit_context)) {
  593. #ifdef CONFIG_PPC64
  594. if (!test_thread_flag(TIF_32BIT))
  595. audit_syscall_entry(AUDIT_ARCH_PPC64,
  596. regs->gpr[0],
  597. regs->gpr[3], regs->gpr[4],
  598. regs->gpr[5], regs->gpr[6]);
  599. else
  600. #endif
  601. audit_syscall_entry(AUDIT_ARCH_PPC,
  602. regs->gpr[0],
  603. regs->gpr[3] & 0xffffffff,
  604. regs->gpr[4] & 0xffffffff,
  605. regs->gpr[5] & 0xffffffff,
  606. regs->gpr[6] & 0xffffffff);
  607. }
  608. }
  609. void do_syscall_trace_leave(struct pt_regs *regs)
  610. {
  611. if (unlikely(current->audit_context))
  612. audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
  613. regs->result);
  614. if ((test_thread_flag(TIF_SYSCALL_TRACE)
  615. || test_thread_flag(TIF_SINGLESTEP))
  616. && (current->ptrace & PT_PTRACED))
  617. do_syscall_trace();
  618. }