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