ptrace32.c 8.1 KB

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