ptrace32.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * ptrace for 32-bit processes running on a 64-bit kernel.
  3. *
  4. * PowerPC version
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  7. * Derived from "arch/m68k/kernel/ptrace.c"
  8. * Copyright (C) 1994 by Hamish Macdonald
  9. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  10. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  11. *
  12. * Modified by Cort Dougan (cort@hq.fsmlabs.com)
  13. * and Paul Mackerras (paulus@samba.org).
  14. *
  15. * This file is subject to the terms and conditions of the GNU General
  16. * Public License. See the file COPYING in the main directory of
  17. * this archive for more details.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/mm.h>
  22. #include <linux/smp.h>
  23. #include <linux/smp_lock.h>
  24. #include <linux/errno.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/regset.h>
  27. #include <linux/user.h>
  28. #include <linux/security.h>
  29. #include <linux/signal.h>
  30. #include <linux/compat.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/page.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/system.h>
  35. /*
  36. * does not yet catch signals sent when the child dies.
  37. * in exit.c or in signal.c.
  38. */
  39. /*
  40. * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
  41. * we mark them as obsolete now, they will be removed in a future version
  42. */
  43. static long compat_ptrace_old(struct task_struct *child, long request,
  44. long addr, long data)
  45. {
  46. switch (request) {
  47. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  48. return copy_regset_to_user(child,
  49. task_user_regset_view(current), 0,
  50. 0, 32 * sizeof(compat_long_t),
  51. compat_ptr(data));
  52. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  53. return copy_regset_from_user(child,
  54. task_user_regset_view(current), 0,
  55. 0, 32 * sizeof(compat_long_t),
  56. compat_ptr(data));
  57. }
  58. return -EPERM;
  59. }
  60. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  61. compat_ulong_t caddr, compat_ulong_t cdata)
  62. {
  63. unsigned long addr = caddr;
  64. unsigned long data = cdata;
  65. int ret;
  66. switch (request) {
  67. /*
  68. * Read 4 bytes of the other process' storage
  69. * data is a pointer specifying where the user wants the
  70. * 4 bytes copied into
  71. * addr is a pointer in the user's storage that contains an 8 byte
  72. * address in the other process of the 4 bytes that is to be read
  73. * (this is run in a 32-bit process looking at a 64-bit process)
  74. * when I and D space are separate, these will need to be fixed.
  75. */
  76. case PPC_PTRACE_PEEKTEXT_3264:
  77. case PPC_PTRACE_PEEKDATA_3264: {
  78. u32 tmp;
  79. int copied;
  80. u32 __user * addrOthers;
  81. ret = -EIO;
  82. /* Get the addr in the other process that we want to read */
  83. if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
  84. break;
  85. copied = access_process_vm(child, (u64)addrOthers, &tmp,
  86. sizeof(tmp), 0);
  87. if (copied != sizeof(tmp))
  88. break;
  89. ret = put_user(tmp, (u32 __user *)data);
  90. break;
  91. }
  92. /* Read a register (specified by ADDR) out of the "user area" */
  93. case PTRACE_PEEKUSR: {
  94. int index;
  95. unsigned long tmp;
  96. ret = -EIO;
  97. /* convert to index and check */
  98. index = (unsigned long) addr >> 2;
  99. if ((addr & 3) || (index > PT_FPSCR32))
  100. break;
  101. CHECK_FULL_REGS(child->thread.regs);
  102. if (index < PT_FPR0) {
  103. tmp = ptrace_get_reg(child, index);
  104. } else {
  105. flush_fp_to_thread(child);
  106. /*
  107. * the user space code considers the floating point
  108. * to be an array of unsigned int (32 bits) - the
  109. * index passed in is based on this assumption.
  110. */
  111. tmp = ((unsigned int *)child->thread.fpr)[index - PT_FPR0];
  112. }
  113. ret = put_user((unsigned int)tmp, (u32 __user *)data);
  114. break;
  115. }
  116. /*
  117. * Read 4 bytes out of the other process' pt_regs area
  118. * data is a pointer specifying where the user wants the
  119. * 4 bytes copied into
  120. * addr is the offset into the other process' pt_regs structure
  121. * that is to be read
  122. * (this is run in a 32-bit process looking at a 64-bit process)
  123. */
  124. case PPC_PTRACE_PEEKUSR_3264: {
  125. u32 index;
  126. u32 reg32bits;
  127. u64 tmp;
  128. u32 numReg;
  129. u32 part;
  130. ret = -EIO;
  131. /* Determine which register the user wants */
  132. index = (u64)addr >> 2;
  133. numReg = index / 2;
  134. /* Determine which part of the register the user wants */
  135. if (index % 2)
  136. part = 1; /* want the 2nd half of the register (right-most). */
  137. else
  138. part = 0; /* want the 1st half of the register (left-most). */
  139. /* Validate the input - check to see if address is on the wrong boundary
  140. * or beyond the end of the user area
  141. */
  142. if ((addr & 3) || numReg > PT_FPSCR)
  143. break;
  144. CHECK_FULL_REGS(child->thread.regs);
  145. if (numReg >= PT_FPR0) {
  146. flush_fp_to_thread(child);
  147. tmp = ((unsigned long int *)child->thread.fpr)[numReg - PT_FPR0];
  148. } else { /* register within PT_REGS struct */
  149. tmp = ptrace_get_reg(child, numReg);
  150. }
  151. reg32bits = ((u32*)&tmp)[part];
  152. ret = put_user(reg32bits, (u32 __user *)data);
  153. break;
  154. }
  155. /*
  156. * Write 4 bytes into the other process' storage
  157. * data is the 4 bytes that the user wants written
  158. * addr is a pointer in the user's storage that contains an
  159. * 8 byte address in the other process where the 4 bytes
  160. * that is to be written
  161. * (this is run in a 32-bit process looking at a 64-bit process)
  162. * when I and D space are separate, these will need to be fixed.
  163. */
  164. case PPC_PTRACE_POKETEXT_3264:
  165. case PPC_PTRACE_POKEDATA_3264: {
  166. u32 tmp = data;
  167. u32 __user * addrOthers;
  168. /* Get the addr in the other process that we want to write into */
  169. ret = -EIO;
  170. if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
  171. break;
  172. ret = 0;
  173. if (access_process_vm(child, (u64)addrOthers, &tmp,
  174. sizeof(tmp), 1) == sizeof(tmp))
  175. break;
  176. ret = -EIO;
  177. break;
  178. }
  179. /* write the word at location addr in the USER area */
  180. case PTRACE_POKEUSR: {
  181. unsigned long index;
  182. ret = -EIO;
  183. /* convert to index and check */
  184. index = (unsigned long) addr >> 2;
  185. if ((addr & 3) || (index > PT_FPSCR32))
  186. break;
  187. CHECK_FULL_REGS(child->thread.regs);
  188. if (index < PT_FPR0) {
  189. ret = ptrace_put_reg(child, index, data);
  190. } else {
  191. flush_fp_to_thread(child);
  192. /*
  193. * the user space code considers the floating point
  194. * to be an array of unsigned int (32 bits) - the
  195. * index passed in is based on this assumption.
  196. */
  197. ((unsigned int *)child->thread.fpr)[index - PT_FPR0] = data;
  198. ret = 0;
  199. }
  200. break;
  201. }
  202. /*
  203. * Write 4 bytes into the other process' pt_regs area
  204. * data is the 4 bytes that the user wants written
  205. * addr is the offset into the other process' pt_regs structure
  206. * that is to be written into
  207. * (this is run in a 32-bit process looking at a 64-bit process)
  208. */
  209. case PPC_PTRACE_POKEUSR_3264: {
  210. u32 index;
  211. u32 numReg;
  212. ret = -EIO;
  213. /* Determine which register the user wants */
  214. index = (u64)addr >> 2;
  215. numReg = index / 2;
  216. /*
  217. * Validate the input - check to see if address is on the
  218. * wrong boundary or beyond the end of the user area
  219. */
  220. if ((addr & 3) || (numReg > PT_FPSCR))
  221. break;
  222. CHECK_FULL_REGS(child->thread.regs);
  223. if (numReg < PT_FPR0) {
  224. unsigned long freg = ptrace_get_reg(child, numReg);
  225. if (index % 2)
  226. freg = (freg & ~0xfffffffful) | (data & 0xfffffffful);
  227. else
  228. freg = (freg & 0xfffffffful) | (data << 32);
  229. ret = ptrace_put_reg(child, numReg, freg);
  230. } else {
  231. flush_fp_to_thread(child);
  232. ((unsigned int *)child->thread.regs)[index] = data;
  233. ret = 0;
  234. }
  235. break;
  236. }
  237. case PTRACE_GET_DEBUGREG: {
  238. ret = -EINVAL;
  239. /* We only support one DABR and no IABRS at the moment */
  240. if (addr > 0)
  241. break;
  242. ret = put_user(child->thread.dabr, (u32 __user *)data);
  243. break;
  244. }
  245. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  246. return copy_regset_to_user(
  247. child, task_user_regset_view(current), 0,
  248. 0, PT_REGS_COUNT * sizeof(compat_long_t),
  249. compat_ptr(data));
  250. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  251. return copy_regset_from_user(
  252. child, task_user_regset_view(current), 0,
  253. 0, PT_REGS_COUNT * sizeof(compat_long_t),
  254. compat_ptr(data));
  255. case PTRACE_GETFPREGS:
  256. case PTRACE_SETFPREGS:
  257. case PTRACE_GETVRREGS:
  258. case PTRACE_SETVRREGS:
  259. case PTRACE_GETREGS64:
  260. case PTRACE_SETREGS64:
  261. case PPC_PTRACE_GETFPREGS:
  262. case PPC_PTRACE_SETFPREGS:
  263. case PTRACE_KILL:
  264. case PTRACE_SINGLESTEP:
  265. case PTRACE_DETACH:
  266. case PTRACE_SET_DEBUGREG:
  267. case PTRACE_SYSCALL:
  268. case PTRACE_CONT:
  269. ret = arch_ptrace(child, request, addr, data);
  270. break;
  271. /* Old reverse args ptrace callss */
  272. case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
  273. case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
  274. ret = compat_ptrace_old(child, request, addr, data);
  275. break;
  276. default:
  277. ret = compat_ptrace_request(child, request, addr, data);
  278. break;
  279. }
  280. return ret;
  281. }