ptrace32.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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/errno.h>
  24. #include <linux/ptrace.h>
  25. #include <linux/regset.h>
  26. #include <linux/user.h>
  27. #include <linux/security.h>
  28. #include <linux/signal.h>
  29. #include <linux/compat.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/page.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/switch_to.h>
  34. /*
  35. * does not yet catch signals sent when the child dies.
  36. * in exit.c or in signal.c.
  37. */
  38. /* Macros to workout the correct index for the FPR in the thread struct */
  39. #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
  40. #define FPRHALF(i) (((i) - PT_FPR0) & 1)
  41. #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
  42. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  43. compat_ulong_t caddr, compat_ulong_t cdata)
  44. {
  45. unsigned long addr = caddr;
  46. unsigned long data = cdata;
  47. int ret;
  48. switch (request) {
  49. /*
  50. * Read 4 bytes of the other process' storage
  51. * data is a pointer specifying where the user wants the
  52. * 4 bytes copied into
  53. * addr is a pointer in the user's storage that contains an 8 byte
  54. * address in the other process of the 4 bytes that is to be read
  55. * (this is run in a 32-bit process looking at a 64-bit process)
  56. * when I and D space are separate, these will need to be fixed.
  57. */
  58. case PPC_PTRACE_PEEKTEXT_3264:
  59. case PPC_PTRACE_PEEKDATA_3264: {
  60. u32 tmp;
  61. int copied;
  62. u32 __user * addrOthers;
  63. ret = -EIO;
  64. /* Get the addr in the other process that we want to read */
  65. if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
  66. break;
  67. copied = access_process_vm(child, (u64)addrOthers, &tmp,
  68. sizeof(tmp), 0);
  69. if (copied != sizeof(tmp))
  70. break;
  71. ret = put_user(tmp, (u32 __user *)data);
  72. break;
  73. }
  74. /* Read a register (specified by ADDR) out of the "user area" */
  75. case PTRACE_PEEKUSR: {
  76. int index;
  77. unsigned long tmp;
  78. ret = -EIO;
  79. /* convert to index and check */
  80. index = (unsigned long) addr >> 2;
  81. if ((addr & 3) || (index > PT_FPSCR32))
  82. break;
  83. CHECK_FULL_REGS(child->thread.regs);
  84. if (index < PT_FPR0) {
  85. ret = ptrace_get_reg(child, index, &tmp);
  86. if (ret)
  87. break;
  88. } else {
  89. flush_fp_to_thread(child);
  90. /*
  91. * the user space code considers the floating point
  92. * to be an array of unsigned int (32 bits) - the
  93. * index passed in is based on this assumption.
  94. */
  95. tmp = ((unsigned int *)child->thread.fp_state.fpr)
  96. [FPRINDEX(index)];
  97. }
  98. ret = put_user((unsigned int)tmp, (u32 __user *)data);
  99. break;
  100. }
  101. /*
  102. * Read 4 bytes out of the other process' pt_regs area
  103. * data is a pointer specifying where the user wants the
  104. * 4 bytes copied into
  105. * addr is the offset into the other process' pt_regs structure
  106. * that is to be read
  107. * (this is run in a 32-bit process looking at a 64-bit process)
  108. */
  109. case PPC_PTRACE_PEEKUSR_3264: {
  110. u32 index;
  111. u32 reg32bits;
  112. u64 tmp;
  113. u32 numReg;
  114. u32 part;
  115. ret = -EIO;
  116. /* Determine which register the user wants */
  117. index = (u64)addr >> 2;
  118. numReg = index / 2;
  119. /* Determine which part of the register the user wants */
  120. if (index % 2)
  121. part = 1; /* want the 2nd half of the register (right-most). */
  122. else
  123. part = 0; /* want the 1st half of the register (left-most). */
  124. /* Validate the input - check to see if address is on the wrong boundary
  125. * or beyond the end of the user area
  126. */
  127. if ((addr & 3) || numReg > PT_FPSCR)
  128. break;
  129. CHECK_FULL_REGS(child->thread.regs);
  130. if (numReg >= PT_FPR0) {
  131. flush_fp_to_thread(child);
  132. /* get 64 bit FPR */
  133. tmp = child->thread.fp_state.fpr[numReg - PT_FPR0][0];
  134. } else { /* register within PT_REGS struct */
  135. unsigned long tmp2;
  136. ret = ptrace_get_reg(child, numReg, &tmp2);
  137. if (ret)
  138. break;
  139. tmp = tmp2;
  140. }
  141. reg32bits = ((u32*)&tmp)[part];
  142. ret = put_user(reg32bits, (u32 __user *)data);
  143. break;
  144. }
  145. /*
  146. * Write 4 bytes into the other process' storage
  147. * data is the 4 bytes that the user wants written
  148. * addr is a pointer in the user's storage that contains an
  149. * 8 byte address in the other process where the 4 bytes
  150. * that is to be written
  151. * (this is run in a 32-bit process looking at a 64-bit process)
  152. * when I and D space are separate, these will need to be fixed.
  153. */
  154. case PPC_PTRACE_POKETEXT_3264:
  155. case PPC_PTRACE_POKEDATA_3264: {
  156. u32 tmp = data;
  157. u32 __user * addrOthers;
  158. /* Get the addr in the other process that we want to write into */
  159. ret = -EIO;
  160. if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
  161. break;
  162. ret = 0;
  163. if (access_process_vm(child, (u64)addrOthers, &tmp,
  164. sizeof(tmp), 1) == sizeof(tmp))
  165. break;
  166. ret = -EIO;
  167. break;
  168. }
  169. /* write the word at location addr in the USER area */
  170. case PTRACE_POKEUSR: {
  171. unsigned long index;
  172. ret = -EIO;
  173. /* convert to index and check */
  174. index = (unsigned long) addr >> 2;
  175. if ((addr & 3) || (index > PT_FPSCR32))
  176. break;
  177. CHECK_FULL_REGS(child->thread.regs);
  178. if (index < PT_FPR0) {
  179. ret = ptrace_put_reg(child, index, data);
  180. } else {
  181. flush_fp_to_thread(child);
  182. /*
  183. * the user space code considers the floating point
  184. * to be an array of unsigned int (32 bits) - the
  185. * index passed in is based on this assumption.
  186. */
  187. ((unsigned int *)child->thread.fp_state.fpr)
  188. [FPRINDEX(index)] = data;
  189. ret = 0;
  190. }
  191. break;
  192. }
  193. /*
  194. * Write 4 bytes into the other process' pt_regs area
  195. * data is the 4 bytes that the user wants written
  196. * addr is the offset into the other process' pt_regs structure
  197. * that is to be written into
  198. * (this is run in a 32-bit process looking at a 64-bit process)
  199. */
  200. case PPC_PTRACE_POKEUSR_3264: {
  201. u32 index;
  202. u32 numReg;
  203. ret = -EIO;
  204. /* Determine which register the user wants */
  205. index = (u64)addr >> 2;
  206. numReg = index / 2;
  207. /*
  208. * Validate the input - check to see if address is on the
  209. * wrong boundary or beyond the end of the user area
  210. */
  211. if ((addr & 3) || (numReg > PT_FPSCR))
  212. break;
  213. CHECK_FULL_REGS(child->thread.regs);
  214. if (numReg < PT_FPR0) {
  215. unsigned long freg;
  216. ret = ptrace_get_reg(child, numReg, &freg);
  217. if (ret)
  218. break;
  219. if (index % 2)
  220. freg = (freg & ~0xfffffffful) | (data & 0xfffffffful);
  221. else
  222. freg = (freg & 0xfffffffful) | (data << 32);
  223. ret = ptrace_put_reg(child, numReg, freg);
  224. } else {
  225. u64 *tmp;
  226. flush_fp_to_thread(child);
  227. /* get 64 bit FPR ... */
  228. tmp = &child->thread.fp_state.fpr[numReg - PT_FPR0][0];
  229. /* ... write the 32 bit part we want */
  230. ((u32 *)tmp)[index % 2] = data;
  231. ret = 0;
  232. }
  233. break;
  234. }
  235. case PTRACE_GET_DEBUGREG: {
  236. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  237. unsigned long dabr_fake;
  238. #endif
  239. ret = -EINVAL;
  240. /* We only support one DABR and no IABRS at the moment */
  241. if (addr > 0)
  242. break;
  243. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  244. ret = put_user(child->thread.debug.dac1, (u32 __user *)data);
  245. #else
  246. dabr_fake = (
  247. (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
  248. (child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
  249. ret = put_user(dabr_fake, (u32 __user *)data);
  250. #endif
  251. break;
  252. }
  253. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  254. return copy_regset_to_user(
  255. child, task_user_regset_view(current), 0,
  256. 0, PT_REGS_COUNT * sizeof(compat_long_t),
  257. compat_ptr(data));
  258. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  259. return copy_regset_from_user(
  260. child, task_user_regset_view(current), 0,
  261. 0, PT_REGS_COUNT * sizeof(compat_long_t),
  262. compat_ptr(data));
  263. case PTRACE_GETFPREGS:
  264. case PTRACE_SETFPREGS:
  265. case PTRACE_GETVRREGS:
  266. case PTRACE_SETVRREGS:
  267. case PTRACE_GETVSRREGS:
  268. case PTRACE_SETVSRREGS:
  269. case PTRACE_GETREGS64:
  270. case PTRACE_SETREGS64:
  271. case PTRACE_KILL:
  272. case PTRACE_SINGLESTEP:
  273. case PTRACE_DETACH:
  274. case PTRACE_SET_DEBUGREG:
  275. case PTRACE_SYSCALL:
  276. case PTRACE_CONT:
  277. case PPC_PTRACE_GETHWDBGINFO:
  278. case PPC_PTRACE_SETHWDEBUG:
  279. case PPC_PTRACE_DELHWDEBUG:
  280. ret = arch_ptrace(child, request, addr, data);
  281. break;
  282. default:
  283. ret = compat_ptrace_request(child, request, addr, data);
  284. break;
  285. }
  286. return ret;
  287. }