ptrace.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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 gpr_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. int ret;
  111. if (target->thread.regs == NULL)
  112. return -EIO;
  113. CHECK_FULL_REGS(target->thread.regs);
  114. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  115. target->thread.regs,
  116. 0, offsetof(struct pt_regs, msr));
  117. if (!ret) {
  118. unsigned long msr = get_user_msr(target);
  119. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  120. offsetof(struct pt_regs, msr),
  121. offsetof(struct pt_regs, msr) +
  122. sizeof(msr));
  123. }
  124. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  125. offsetof(struct pt_regs, msr) + sizeof(long));
  126. if (!ret)
  127. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  128. &target->thread.regs->orig_gpr3,
  129. offsetof(struct pt_regs, orig_gpr3),
  130. sizeof(struct pt_regs));
  131. if (!ret)
  132. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  133. sizeof(struct pt_regs), -1);
  134. return ret;
  135. }
  136. static int gpr_set(struct task_struct *target, const struct user_regset *regset,
  137. unsigned int pos, unsigned int count,
  138. const void *kbuf, const void __user *ubuf)
  139. {
  140. unsigned long reg;
  141. int ret;
  142. if (target->thread.regs == NULL)
  143. return -EIO;
  144. CHECK_FULL_REGS(target->thread.regs);
  145. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  146. target->thread.regs,
  147. 0, PT_MSR * sizeof(reg));
  148. if (!ret && count > 0) {
  149. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  150. PT_MSR * sizeof(reg),
  151. (PT_MSR + 1) * sizeof(reg));
  152. if (!ret)
  153. ret = set_user_msr(target, reg);
  154. }
  155. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  156. offsetof(struct pt_regs, msr) + sizeof(long));
  157. if (!ret)
  158. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  159. &target->thread.regs->orig_gpr3,
  160. PT_ORIG_R3 * sizeof(reg),
  161. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  162. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  163. ret = user_regset_copyin_ignore(
  164. &pos, &count, &kbuf, &ubuf,
  165. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  166. PT_TRAP * sizeof(reg));
  167. if (!ret && count > 0) {
  168. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  169. PT_TRAP * sizeof(reg),
  170. (PT_TRAP + 1) * sizeof(reg));
  171. if (!ret)
  172. ret = set_user_trap(target, reg);
  173. }
  174. if (!ret)
  175. ret = user_regset_copyin_ignore(
  176. &pos, &count, &kbuf, &ubuf,
  177. (PT_TRAP + 1) * sizeof(reg), -1);
  178. return ret;
  179. }
  180. static int fpr_get(struct task_struct *target, const struct user_regset *regset,
  181. unsigned int pos, unsigned int count,
  182. void *kbuf, void __user *ubuf)
  183. {
  184. flush_fp_to_thread(target);
  185. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  186. offsetof(struct thread_struct, fpr[32]));
  187. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  188. &target->thread.fpr, 0, -1);
  189. }
  190. static int fpr_set(struct task_struct *target, const struct user_regset *regset,
  191. unsigned int pos, unsigned int count,
  192. const void *kbuf, const void __user *ubuf)
  193. {
  194. flush_fp_to_thread(target);
  195. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  196. offsetof(struct thread_struct, fpr[32]));
  197. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  198. &target->thread.fpr, 0, -1);
  199. }
  200. #ifdef CONFIG_ALTIVEC
  201. /*
  202. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  203. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  204. * corresponding vector registers. Quadword 32 contains the vscr as the
  205. * last word (offset 12) within that quadword. Quadword 33 contains the
  206. * vrsave as the first word (offset 0) within the quadword.
  207. *
  208. * This definition of the VMX state is compatible with the current PPC32
  209. * ptrace interface. This allows signal handling and ptrace to use the
  210. * same structures. This also simplifies the implementation of a bi-arch
  211. * (combined (32- and 64-bit) gdb.
  212. */
  213. static int vr_active(struct task_struct *target,
  214. const struct user_regset *regset)
  215. {
  216. flush_altivec_to_thread(target);
  217. return target->thread.used_vr ? regset->n : 0;
  218. }
  219. static int vr_get(struct task_struct *target, const struct user_regset *regset,
  220. unsigned int pos, unsigned int count,
  221. void *kbuf, void __user *ubuf)
  222. {
  223. int ret;
  224. flush_altivec_to_thread(target);
  225. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  226. offsetof(struct thread_struct, vr[32]));
  227. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  228. &target->thread.vr, 0,
  229. 33 * sizeof(vector128));
  230. if (!ret) {
  231. /*
  232. * Copy out only the low-order word of vrsave.
  233. */
  234. union {
  235. elf_vrreg_t reg;
  236. u32 word;
  237. } vrsave;
  238. memset(&vrsave, 0, sizeof(vrsave));
  239. vrsave.word = target->thread.vrsave;
  240. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  241. 33 * sizeof(vector128), -1);
  242. }
  243. return ret;
  244. }
  245. static int vr_set(struct task_struct *target, const struct user_regset *regset,
  246. unsigned int pos, unsigned int count,
  247. const void *kbuf, const void __user *ubuf)
  248. {
  249. int ret;
  250. flush_altivec_to_thread(target);
  251. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  252. offsetof(struct thread_struct, vr[32]));
  253. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  254. &target->thread.vr, 0, 33 * sizeof(vector128));
  255. if (!ret && count > 0) {
  256. /*
  257. * We use only the first word of vrsave.
  258. */
  259. union {
  260. elf_vrreg_t reg;
  261. u32 word;
  262. } vrsave;
  263. memset(&vrsave, 0, sizeof(vrsave));
  264. vrsave.word = target->thread.vrsave;
  265. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  266. 33 * sizeof(vector128), -1);
  267. if (!ret)
  268. target->thread.vrsave = vrsave.word;
  269. }
  270. return ret;
  271. }
  272. #endif /* CONFIG_ALTIVEC */
  273. #ifdef CONFIG_SPE
  274. /*
  275. * For get_evrregs/set_evrregs functions 'data' has the following layout:
  276. *
  277. * struct {
  278. * u32 evr[32];
  279. * u64 acc;
  280. * u32 spefscr;
  281. * }
  282. */
  283. static int evr_active(struct task_struct *target,
  284. const struct user_regset *regset)
  285. {
  286. flush_spe_to_thread(target);
  287. return target->thread.used_spe ? regset->n : 0;
  288. }
  289. static int evr_get(struct task_struct *target, const struct user_regset *regset,
  290. unsigned int pos, unsigned int count,
  291. void *kbuf, void __user *ubuf)
  292. {
  293. int ret;
  294. flush_spe_to_thread(target);
  295. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  296. &target->thread.evr,
  297. 0, sizeof(target->thread.evr));
  298. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  299. offsetof(struct thread_struct, spefscr));
  300. if (!ret)
  301. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  302. &target->thread.acc,
  303. sizeof(target->thread.evr), -1);
  304. return ret;
  305. }
  306. static int evr_set(struct task_struct *target, const struct user_regset *regset,
  307. unsigned int pos, unsigned int count,
  308. const void *kbuf, const void __user *ubuf)
  309. {
  310. int ret;
  311. flush_spe_to_thread(target);
  312. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  313. &target->thread.evr,
  314. 0, sizeof(target->thread.evr));
  315. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  316. offsetof(struct thread_struct, spefscr));
  317. if (!ret)
  318. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  319. &target->thread.acc,
  320. sizeof(target->thread.evr), -1);
  321. return ret;
  322. }
  323. #endif /* CONFIG_SPE */
  324. /*
  325. * These are our native regset flavors.
  326. */
  327. enum powerpc_regset {
  328. REGSET_GPR,
  329. REGSET_FPR,
  330. #ifdef CONFIG_ALTIVEC
  331. REGSET_VMX,
  332. #endif
  333. #ifdef CONFIG_SPE
  334. REGSET_SPE,
  335. #endif
  336. };
  337. static const struct user_regset native_regsets[] = {
  338. [REGSET_GPR] = {
  339. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  340. .size = sizeof(long), .align = sizeof(long),
  341. .get = gpr_get, .set = gpr_set
  342. },
  343. [REGSET_FPR] = {
  344. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  345. .size = sizeof(double), .align = sizeof(double),
  346. .get = fpr_get, .set = fpr_set
  347. },
  348. #ifdef CONFIG_ALTIVEC
  349. [REGSET_VMX] = {
  350. .core_note_type = NT_PPC_VMX, .n = 34,
  351. .size = sizeof(vector128), .align = sizeof(vector128),
  352. .active = vr_active, .get = vr_get, .set = vr_set
  353. },
  354. #endif
  355. #ifdef CONFIG_SPE
  356. [REGSET_SPE] = {
  357. .n = 35,
  358. .size = sizeof(u32), .align = sizeof(u32),
  359. .active = evr_active, .get = evr_get, .set = evr_set
  360. },
  361. #endif
  362. };
  363. static const struct user_regset_view user_ppc_native_view = {
  364. .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
  365. .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
  366. };
  367. #ifdef CONFIG_PPC64
  368. #include <linux/compat.h>
  369. static int gpr32_get(struct task_struct *target,
  370. const struct user_regset *regset,
  371. unsigned int pos, unsigned int count,
  372. void *kbuf, void __user *ubuf)
  373. {
  374. const unsigned long *regs = &target->thread.regs->gpr[0];
  375. compat_ulong_t *k = kbuf;
  376. compat_ulong_t __user *u = ubuf;
  377. compat_ulong_t reg;
  378. if (target->thread.regs == NULL)
  379. return -EIO;
  380. CHECK_FULL_REGS(target->thread.regs);
  381. pos /= sizeof(reg);
  382. count /= sizeof(reg);
  383. if (kbuf)
  384. for (; count > 0 && pos < PT_MSR; --count)
  385. *k++ = regs[pos++];
  386. else
  387. for (; count > 0 && pos < PT_MSR; --count)
  388. if (__put_user((compat_ulong_t) regs[pos++], u++))
  389. return -EFAULT;
  390. if (count > 0 && pos == PT_MSR) {
  391. reg = get_user_msr(target);
  392. if (kbuf)
  393. *k++ = reg;
  394. else if (__put_user(reg, u++))
  395. return -EFAULT;
  396. ++pos;
  397. --count;
  398. }
  399. if (kbuf)
  400. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  401. *k++ = regs[pos++];
  402. else
  403. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  404. if (__put_user((compat_ulong_t) regs[pos++], u++))
  405. return -EFAULT;
  406. kbuf = k;
  407. ubuf = u;
  408. pos *= sizeof(reg);
  409. count *= sizeof(reg);
  410. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  411. PT_REGS_COUNT * sizeof(reg), -1);
  412. }
  413. static int gpr32_set(struct task_struct *target,
  414. const struct user_regset *regset,
  415. unsigned int pos, unsigned int count,
  416. const void *kbuf, const void __user *ubuf)
  417. {
  418. unsigned long *regs = &target->thread.regs->gpr[0];
  419. const compat_ulong_t *k = kbuf;
  420. const compat_ulong_t __user *u = ubuf;
  421. compat_ulong_t reg;
  422. if (target->thread.regs == NULL)
  423. return -EIO;
  424. CHECK_FULL_REGS(target->thread.regs);
  425. pos /= sizeof(reg);
  426. count /= sizeof(reg);
  427. if (kbuf)
  428. for (; count > 0 && pos < PT_MSR; --count)
  429. regs[pos++] = *k++;
  430. else
  431. for (; count > 0 && pos < PT_MSR; --count) {
  432. if (__get_user(reg, u++))
  433. return -EFAULT;
  434. regs[pos++] = reg;
  435. }
  436. if (count > 0 && pos == PT_MSR) {
  437. if (kbuf)
  438. reg = *k++;
  439. else if (__get_user(reg, u++))
  440. return -EFAULT;
  441. set_user_msr(target, reg);
  442. ++pos;
  443. --count;
  444. }
  445. if (kbuf)
  446. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
  447. regs[pos++] = *k++;
  448. else
  449. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
  450. if (__get_user(reg, u++))
  451. return -EFAULT;
  452. regs[pos++] = reg;
  453. }
  454. if (count > 0 && pos == PT_TRAP) {
  455. if (kbuf)
  456. reg = *k++;
  457. else if (__get_user(reg, u++))
  458. return -EFAULT;
  459. set_user_trap(target, reg);
  460. ++pos;
  461. --count;
  462. }
  463. kbuf = k;
  464. ubuf = u;
  465. pos *= sizeof(reg);
  466. count *= sizeof(reg);
  467. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  468. (PT_TRAP + 1) * sizeof(reg), -1);
  469. }
  470. /*
  471. * These are the regset flavors matching the CONFIG_PPC32 native set.
  472. */
  473. static const struct user_regset compat_regsets[] = {
  474. [REGSET_GPR] = {
  475. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  476. .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
  477. .get = gpr32_get, .set = gpr32_set
  478. },
  479. [REGSET_FPR] = {
  480. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  481. .size = sizeof(double), .align = sizeof(double),
  482. .get = fpr_get, .set = fpr_set
  483. },
  484. #ifdef CONFIG_ALTIVEC
  485. [REGSET_VMX] = {
  486. .core_note_type = NT_PPC_VMX, .n = 34,
  487. .size = sizeof(vector128), .align = sizeof(vector128),
  488. .active = vr_active, .get = vr_get, .set = vr_set
  489. },
  490. #endif
  491. #ifdef CONFIG_SPE
  492. [REGSET_SPE] = {
  493. .core_note_type = NT_PPC_SPE, .n = 35,
  494. .size = sizeof(u32), .align = sizeof(u32),
  495. .active = evr_active, .get = evr_get, .set = evr_set
  496. },
  497. #endif
  498. };
  499. static const struct user_regset_view user_ppc_compat_view = {
  500. .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
  501. .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
  502. };
  503. #endif /* CONFIG_PPC64 */
  504. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  505. {
  506. #ifdef CONFIG_PPC64
  507. if (test_tsk_thread_flag(task, TIF_32BIT))
  508. return &user_ppc_compat_view;
  509. #endif
  510. return &user_ppc_native_view;
  511. }
  512. void user_enable_single_step(struct task_struct *task)
  513. {
  514. struct pt_regs *regs = task->thread.regs;
  515. if (regs != NULL) {
  516. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  517. task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
  518. regs->msr |= MSR_DE;
  519. #else
  520. regs->msr |= MSR_SE;
  521. #endif
  522. }
  523. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  524. }
  525. void user_disable_single_step(struct task_struct *task)
  526. {
  527. struct pt_regs *regs = task->thread.regs;
  528. if (regs != NULL) {
  529. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  530. task->thread.dbcr0 = 0;
  531. regs->msr &= ~MSR_DE;
  532. #else
  533. regs->msr &= ~MSR_SE;
  534. #endif
  535. }
  536. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  537. }
  538. static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
  539. unsigned long data)
  540. {
  541. /* We only support one DABR and no IABRS at the moment */
  542. if (addr > 0)
  543. return -EINVAL;
  544. /* The bottom 3 bits are flags */
  545. if ((data & ~0x7UL) >= TASK_SIZE)
  546. return -EIO;
  547. /* Ensure translation is on */
  548. if (data && !(data & DABR_TRANSLATION))
  549. return -EIO;
  550. task->thread.dabr = data;
  551. return 0;
  552. }
  553. /*
  554. * Called by kernel/ptrace.c when detaching..
  555. *
  556. * Make sure single step bits etc are not set.
  557. */
  558. void ptrace_disable(struct task_struct *child)
  559. {
  560. /* make sure the single step bit is not set. */
  561. user_disable_single_step(child);
  562. }
  563. /*
  564. * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
  565. * we mark them as obsolete now, they will be removed in a future version
  566. */
  567. static long arch_ptrace_old(struct task_struct *child, long request, long addr,
  568. long data)
  569. {
  570. switch (request) {
  571. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  572. return copy_regset_to_user(child, &user_ppc_native_view,
  573. REGSET_GPR, 0, 32 * sizeof(long),
  574. (void __user *) data);
  575. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  576. return copy_regset_from_user(child, &user_ppc_native_view,
  577. REGSET_GPR, 0, 32 * sizeof(long),
  578. (const void __user *) data);
  579. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  580. return copy_regset_to_user(child, &user_ppc_native_view,
  581. REGSET_FPR, 0, 32 * sizeof(double),
  582. (void __user *) data);
  583. case PPC_PTRACE_SETFPREGS: /* Set FPRs 0 - 31. */
  584. return copy_regset_from_user(child, &user_ppc_native_view,
  585. REGSET_FPR, 0, 32 * sizeof(double),
  586. (const void __user *) data);
  587. }
  588. return -EPERM;
  589. }
  590. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  591. {
  592. int ret = -EPERM;
  593. switch (request) {
  594. /* read the word at location addr in the USER area. */
  595. case PTRACE_PEEKUSR: {
  596. unsigned long index, tmp;
  597. ret = -EIO;
  598. /* convert to index and check */
  599. #ifdef CONFIG_PPC32
  600. index = (unsigned long) addr >> 2;
  601. if ((addr & 3) || (index > PT_FPSCR)
  602. || (child->thread.regs == NULL))
  603. #else
  604. index = (unsigned long) addr >> 3;
  605. if ((addr & 7) || (index > PT_FPSCR))
  606. #endif
  607. break;
  608. CHECK_FULL_REGS(child->thread.regs);
  609. if (index < PT_FPR0) {
  610. tmp = ptrace_get_reg(child, (int) index);
  611. } else {
  612. flush_fp_to_thread(child);
  613. tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
  614. }
  615. ret = put_user(tmp,(unsigned long __user *) data);
  616. break;
  617. }
  618. /* write the word at location addr in the USER area */
  619. case PTRACE_POKEUSR: {
  620. unsigned long index;
  621. ret = -EIO;
  622. /* convert to index and check */
  623. #ifdef CONFIG_PPC32
  624. index = (unsigned long) addr >> 2;
  625. if ((addr & 3) || (index > PT_FPSCR)
  626. || (child->thread.regs == NULL))
  627. #else
  628. index = (unsigned long) addr >> 3;
  629. if ((addr & 7) || (index > PT_FPSCR))
  630. #endif
  631. break;
  632. CHECK_FULL_REGS(child->thread.regs);
  633. if (index < PT_FPR0) {
  634. ret = ptrace_put_reg(child, index, data);
  635. } else {
  636. flush_fp_to_thread(child);
  637. ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
  638. ret = 0;
  639. }
  640. break;
  641. }
  642. case PTRACE_GET_DEBUGREG: {
  643. ret = -EINVAL;
  644. /* We only support one DABR and no IABRS at the moment */
  645. if (addr > 0)
  646. break;
  647. ret = put_user(child->thread.dabr,
  648. (unsigned long __user *)data);
  649. break;
  650. }
  651. case PTRACE_SET_DEBUGREG:
  652. ret = ptrace_set_debugreg(child, addr, data);
  653. break;
  654. #ifdef CONFIG_PPC64
  655. case PTRACE_GETREGS64:
  656. #endif
  657. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  658. return copy_regset_to_user(child, &user_ppc_native_view,
  659. REGSET_GPR,
  660. 0, sizeof(struct pt_regs),
  661. (void __user *) data);
  662. #ifdef CONFIG_PPC64
  663. case PTRACE_SETREGS64:
  664. #endif
  665. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  666. return copy_regset_from_user(child, &user_ppc_native_view,
  667. REGSET_GPR,
  668. 0, sizeof(struct pt_regs),
  669. (const void __user *) data);
  670. case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
  671. return copy_regset_to_user(child, &user_ppc_native_view,
  672. REGSET_FPR,
  673. 0, sizeof(elf_fpregset_t),
  674. (void __user *) data);
  675. case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
  676. return copy_regset_from_user(child, &user_ppc_native_view,
  677. REGSET_FPR,
  678. 0, sizeof(elf_fpregset_t),
  679. (const void __user *) data);
  680. #ifdef CONFIG_ALTIVEC
  681. case PTRACE_GETVRREGS:
  682. return copy_regset_to_user(child, &user_ppc_native_view,
  683. REGSET_VMX,
  684. 0, (33 * sizeof(vector128) +
  685. sizeof(u32)),
  686. (void __user *) data);
  687. case PTRACE_SETVRREGS:
  688. return copy_regset_from_user(child, &user_ppc_native_view,
  689. REGSET_VMX,
  690. 0, (33 * sizeof(vector128) +
  691. sizeof(u32)),
  692. (const void __user *) data);
  693. #endif
  694. #ifdef CONFIG_SPE
  695. case PTRACE_GETEVRREGS:
  696. /* Get the child spe register state. */
  697. return copy_regset_to_user(child, &user_ppc_native_view,
  698. REGSET_SPE, 0, 35 * sizeof(u32),
  699. (void __user *) data);
  700. case PTRACE_SETEVRREGS:
  701. /* Set the child spe register state. */
  702. return copy_regset_from_user(child, &user_ppc_native_view,
  703. REGSET_SPE, 0, 35 * sizeof(u32),
  704. (const void __user *) data);
  705. #endif
  706. /* Old reverse args ptrace callss */
  707. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  708. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  709. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  710. case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
  711. ret = arch_ptrace_old(child, request, addr, data);
  712. break;
  713. default:
  714. ret = ptrace_request(child, request, addr, data);
  715. break;
  716. }
  717. return ret;
  718. }
  719. static void do_syscall_trace(void)
  720. {
  721. /* the 0x80 provides a way for the tracing parent to distinguish
  722. between a syscall stop and SIGTRAP delivery */
  723. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  724. ? 0x80 : 0));
  725. /*
  726. * this isn't the same as continuing with a signal, but it will do
  727. * for normal use. strace only continues with a signal if the
  728. * stopping signal is not SIGTRAP. -brl
  729. */
  730. if (current->exit_code) {
  731. send_sig(current->exit_code, current, 1);
  732. current->exit_code = 0;
  733. }
  734. }
  735. void do_syscall_trace_enter(struct pt_regs *regs)
  736. {
  737. secure_computing(regs->gpr[0]);
  738. if (test_thread_flag(TIF_SYSCALL_TRACE)
  739. && (current->ptrace & PT_PTRACED))
  740. do_syscall_trace();
  741. if (unlikely(current->audit_context)) {
  742. #ifdef CONFIG_PPC64
  743. if (!test_thread_flag(TIF_32BIT))
  744. audit_syscall_entry(AUDIT_ARCH_PPC64,
  745. regs->gpr[0],
  746. regs->gpr[3], regs->gpr[4],
  747. regs->gpr[5], regs->gpr[6]);
  748. else
  749. #endif
  750. audit_syscall_entry(AUDIT_ARCH_PPC,
  751. regs->gpr[0],
  752. regs->gpr[3] & 0xffffffff,
  753. regs->gpr[4] & 0xffffffff,
  754. regs->gpr[5] & 0xffffffff,
  755. regs->gpr[6] & 0xffffffff);
  756. }
  757. }
  758. void do_syscall_trace_leave(struct pt_regs *regs)
  759. {
  760. if (unlikely(current->audit_context))
  761. audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
  762. regs->result);
  763. if ((test_thread_flag(TIF_SYSCALL_TRACE)
  764. || test_thread_flag(TIF_SINGLESTEP))
  765. && (current->ptrace & PT_PTRACED))
  766. do_syscall_trace();
  767. }