ptrace.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  449. ++k;
  450. } else {
  451. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
  452. if (__get_user(reg, u++))
  453. return -EFAULT;
  454. regs[pos++] = reg;
  455. }
  456. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  457. if (__get_user(reg, u++))
  458. return -EFAULT;
  459. }
  460. if (count > 0 && pos == PT_TRAP) {
  461. if (kbuf)
  462. reg = *k++;
  463. else if (__get_user(reg, u++))
  464. return -EFAULT;
  465. set_user_trap(target, reg);
  466. ++pos;
  467. --count;
  468. }
  469. kbuf = k;
  470. ubuf = u;
  471. pos *= sizeof(reg);
  472. count *= sizeof(reg);
  473. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  474. (PT_TRAP + 1) * sizeof(reg), -1);
  475. }
  476. /*
  477. * These are the regset flavors matching the CONFIG_PPC32 native set.
  478. */
  479. static const struct user_regset compat_regsets[] = {
  480. [REGSET_GPR] = {
  481. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  482. .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
  483. .get = gpr32_get, .set = gpr32_set
  484. },
  485. [REGSET_FPR] = {
  486. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  487. .size = sizeof(double), .align = sizeof(double),
  488. .get = fpr_get, .set = fpr_set
  489. },
  490. #ifdef CONFIG_ALTIVEC
  491. [REGSET_VMX] = {
  492. .core_note_type = NT_PPC_VMX, .n = 34,
  493. .size = sizeof(vector128), .align = sizeof(vector128),
  494. .active = vr_active, .get = vr_get, .set = vr_set
  495. },
  496. #endif
  497. #ifdef CONFIG_SPE
  498. [REGSET_SPE] = {
  499. .core_note_type = NT_PPC_SPE, .n = 35,
  500. .size = sizeof(u32), .align = sizeof(u32),
  501. .active = evr_active, .get = evr_get, .set = evr_set
  502. },
  503. #endif
  504. };
  505. static const struct user_regset_view user_ppc_compat_view = {
  506. .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
  507. .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
  508. };
  509. #endif /* CONFIG_PPC64 */
  510. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  511. {
  512. #ifdef CONFIG_PPC64
  513. if (test_tsk_thread_flag(task, TIF_32BIT))
  514. return &user_ppc_compat_view;
  515. #endif
  516. return &user_ppc_native_view;
  517. }
  518. void user_enable_single_step(struct task_struct *task)
  519. {
  520. struct pt_regs *regs = task->thread.regs;
  521. if (regs != NULL) {
  522. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  523. task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC;
  524. regs->msr |= MSR_DE;
  525. #else
  526. regs->msr |= MSR_SE;
  527. #endif
  528. }
  529. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  530. }
  531. void user_disable_single_step(struct task_struct *task)
  532. {
  533. struct pt_regs *regs = task->thread.regs;
  534. if (regs != NULL) {
  535. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  536. task->thread.dbcr0 = 0;
  537. regs->msr &= ~MSR_DE;
  538. #else
  539. regs->msr &= ~MSR_SE;
  540. #endif
  541. }
  542. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  543. }
  544. static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
  545. unsigned long data)
  546. {
  547. /* We only support one DABR and no IABRS at the moment */
  548. if (addr > 0)
  549. return -EINVAL;
  550. /* The bottom 3 bits are flags */
  551. if ((data & ~0x7UL) >= TASK_SIZE)
  552. return -EIO;
  553. /* Ensure translation is on */
  554. if (data && !(data & DABR_TRANSLATION))
  555. return -EIO;
  556. task->thread.dabr = data;
  557. return 0;
  558. }
  559. /*
  560. * Called by kernel/ptrace.c when detaching..
  561. *
  562. * Make sure single step bits etc are not set.
  563. */
  564. void ptrace_disable(struct task_struct *child)
  565. {
  566. /* make sure the single step bit is not set. */
  567. user_disable_single_step(child);
  568. }
  569. /*
  570. * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
  571. * we mark them as obsolete now, they will be removed in a future version
  572. */
  573. static long arch_ptrace_old(struct task_struct *child, long request, long addr,
  574. long data)
  575. {
  576. switch (request) {
  577. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  578. return copy_regset_to_user(child, &user_ppc_native_view,
  579. REGSET_GPR, 0, 32 * sizeof(long),
  580. (void __user *) data);
  581. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  582. return copy_regset_from_user(child, &user_ppc_native_view,
  583. REGSET_GPR, 0, 32 * sizeof(long),
  584. (const void __user *) data);
  585. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  586. return copy_regset_to_user(child, &user_ppc_native_view,
  587. REGSET_FPR, 0, 32 * sizeof(double),
  588. (void __user *) data);
  589. case PPC_PTRACE_SETFPREGS: /* Set FPRs 0 - 31. */
  590. return copy_regset_from_user(child, &user_ppc_native_view,
  591. REGSET_FPR, 0, 32 * sizeof(double),
  592. (const void __user *) data);
  593. }
  594. return -EPERM;
  595. }
  596. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  597. {
  598. int ret = -EPERM;
  599. switch (request) {
  600. /* read the word at location addr in the USER area. */
  601. case PTRACE_PEEKUSR: {
  602. unsigned long index, tmp;
  603. ret = -EIO;
  604. /* convert to index and check */
  605. #ifdef CONFIG_PPC32
  606. index = (unsigned long) addr >> 2;
  607. if ((addr & 3) || (index > PT_FPSCR)
  608. || (child->thread.regs == NULL))
  609. #else
  610. index = (unsigned long) addr >> 3;
  611. if ((addr & 7) || (index > PT_FPSCR))
  612. #endif
  613. break;
  614. CHECK_FULL_REGS(child->thread.regs);
  615. if (index < PT_FPR0) {
  616. tmp = ptrace_get_reg(child, (int) index);
  617. } else {
  618. flush_fp_to_thread(child);
  619. tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
  620. }
  621. ret = put_user(tmp,(unsigned long __user *) data);
  622. break;
  623. }
  624. /* write the word at location addr in the USER area */
  625. case PTRACE_POKEUSR: {
  626. unsigned long index;
  627. ret = -EIO;
  628. /* convert to index and check */
  629. #ifdef CONFIG_PPC32
  630. index = (unsigned long) addr >> 2;
  631. if ((addr & 3) || (index > PT_FPSCR)
  632. || (child->thread.regs == NULL))
  633. #else
  634. index = (unsigned long) addr >> 3;
  635. if ((addr & 7) || (index > PT_FPSCR))
  636. #endif
  637. break;
  638. CHECK_FULL_REGS(child->thread.regs);
  639. if (index < PT_FPR0) {
  640. ret = ptrace_put_reg(child, index, data);
  641. } else {
  642. flush_fp_to_thread(child);
  643. ((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data;
  644. ret = 0;
  645. }
  646. break;
  647. }
  648. case PTRACE_GET_DEBUGREG: {
  649. ret = -EINVAL;
  650. /* We only support one DABR and no IABRS at the moment */
  651. if (addr > 0)
  652. break;
  653. ret = put_user(child->thread.dabr,
  654. (unsigned long __user *)data);
  655. break;
  656. }
  657. case PTRACE_SET_DEBUGREG:
  658. ret = ptrace_set_debugreg(child, addr, data);
  659. break;
  660. #ifdef CONFIG_PPC64
  661. case PTRACE_GETREGS64:
  662. #endif
  663. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  664. return copy_regset_to_user(child, &user_ppc_native_view,
  665. REGSET_GPR,
  666. 0, sizeof(struct pt_regs),
  667. (void __user *) data);
  668. #ifdef CONFIG_PPC64
  669. case PTRACE_SETREGS64:
  670. #endif
  671. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  672. return copy_regset_from_user(child, &user_ppc_native_view,
  673. REGSET_GPR,
  674. 0, sizeof(struct pt_regs),
  675. (const void __user *) data);
  676. case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
  677. return copy_regset_to_user(child, &user_ppc_native_view,
  678. REGSET_FPR,
  679. 0, sizeof(elf_fpregset_t),
  680. (void __user *) data);
  681. case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
  682. return copy_regset_from_user(child, &user_ppc_native_view,
  683. REGSET_FPR,
  684. 0, sizeof(elf_fpregset_t),
  685. (const void __user *) data);
  686. #ifdef CONFIG_ALTIVEC
  687. case PTRACE_GETVRREGS:
  688. return copy_regset_to_user(child, &user_ppc_native_view,
  689. REGSET_VMX,
  690. 0, (33 * sizeof(vector128) +
  691. sizeof(u32)),
  692. (void __user *) data);
  693. case PTRACE_SETVRREGS:
  694. return copy_regset_from_user(child, &user_ppc_native_view,
  695. REGSET_VMX,
  696. 0, (33 * sizeof(vector128) +
  697. sizeof(u32)),
  698. (const void __user *) data);
  699. #endif
  700. #ifdef CONFIG_SPE
  701. case PTRACE_GETEVRREGS:
  702. /* Get the child spe register state. */
  703. return copy_regset_to_user(child, &user_ppc_native_view,
  704. REGSET_SPE, 0, 35 * sizeof(u32),
  705. (void __user *) data);
  706. case PTRACE_SETEVRREGS:
  707. /* Set the child spe register state. */
  708. return copy_regset_from_user(child, &user_ppc_native_view,
  709. REGSET_SPE, 0, 35 * sizeof(u32),
  710. (const void __user *) data);
  711. #endif
  712. /* Old reverse args ptrace callss */
  713. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  714. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  715. case PPC_PTRACE_GETFPREGS: /* Get FPRs 0 - 31. */
  716. case PPC_PTRACE_SETFPREGS: /* Get FPRs 0 - 31. */
  717. ret = arch_ptrace_old(child, request, addr, data);
  718. break;
  719. default:
  720. ret = ptrace_request(child, request, addr, data);
  721. break;
  722. }
  723. return ret;
  724. }
  725. static void do_syscall_trace(void)
  726. {
  727. /* the 0x80 provides a way for the tracing parent to distinguish
  728. between a syscall stop and SIGTRAP delivery */
  729. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  730. ? 0x80 : 0));
  731. /*
  732. * this isn't the same as continuing with a signal, but it will do
  733. * for normal use. strace only continues with a signal if the
  734. * stopping signal is not SIGTRAP. -brl
  735. */
  736. if (current->exit_code) {
  737. send_sig(current->exit_code, current, 1);
  738. current->exit_code = 0;
  739. }
  740. }
  741. void do_syscall_trace_enter(struct pt_regs *regs)
  742. {
  743. secure_computing(regs->gpr[0]);
  744. if (test_thread_flag(TIF_SYSCALL_TRACE)
  745. && (current->ptrace & PT_PTRACED))
  746. do_syscall_trace();
  747. if (unlikely(current->audit_context)) {
  748. #ifdef CONFIG_PPC64
  749. if (!test_thread_flag(TIF_32BIT))
  750. audit_syscall_entry(AUDIT_ARCH_PPC64,
  751. regs->gpr[0],
  752. regs->gpr[3], regs->gpr[4],
  753. regs->gpr[5], regs->gpr[6]);
  754. else
  755. #endif
  756. audit_syscall_entry(AUDIT_ARCH_PPC,
  757. regs->gpr[0],
  758. regs->gpr[3] & 0xffffffff,
  759. regs->gpr[4] & 0xffffffff,
  760. regs->gpr[5] & 0xffffffff,
  761. regs->gpr[6] & 0xffffffff);
  762. }
  763. }
  764. void do_syscall_trace_leave(struct pt_regs *regs)
  765. {
  766. if (unlikely(current->audit_context))
  767. audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS,
  768. regs->result);
  769. if ((test_thread_flag(TIF_SYSCALL_TRACE)
  770. || test_thread_flag(TIF_SINGLESTEP))
  771. && (current->ptrace & PT_PTRACED))
  772. do_syscall_trace();
  773. }