ptrace32.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1992 Ross Biro
  7. * Copyright (C) Linus Torvalds
  8. * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
  9. * Copyright (C) 1996 David S. Miller
  10. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  11. * Copyright (C) 1999 MIPS Technologies, Inc.
  12. * Copyright (C) 2000 Ulf Carlsson
  13. *
  14. * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit
  15. * binaries.
  16. */
  17. #include <linux/compiler.h>
  18. #include <linux/compat.h>
  19. #include <linux/kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/mm.h>
  22. #include <linux/errno.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/smp.h>
  25. #include <linux/security.h>
  26. #include <asm/cpu.h>
  27. #include <asm/dsp.h>
  28. #include <asm/fpu.h>
  29. #include <asm/mipsregs.h>
  30. #include <asm/mipsmtregs.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/page.h>
  33. #include <asm/reg.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/bootinfo.h>
  36. /*
  37. * Tracing a 32-bit process with a 64-bit strace and vice versa will not
  38. * work. I don't know how to fix this.
  39. */
  40. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  41. compat_ulong_t caddr, compat_ulong_t cdata)
  42. {
  43. int addr = caddr;
  44. int data = cdata;
  45. int ret;
  46. switch (request) {
  47. /*
  48. * Read 4 bytes of the other process' storage
  49. * data is a pointer specifying where the user wants the
  50. * 4 bytes copied into
  51. * addr is a pointer in the user's storage that contains an 8 byte
  52. * address in the other process of the 4 bytes that is to be read
  53. * (this is run in a 32-bit process looking at a 64-bit process)
  54. * when I and D space are separate, these will need to be fixed.
  55. */
  56. case PTRACE_PEEKTEXT_3264:
  57. case PTRACE_PEEKDATA_3264: {
  58. u32 tmp;
  59. int copied;
  60. u32 __user * addrOthers;
  61. ret = -EIO;
  62. /* Get the addr in the other process that we want to read */
  63. if (get_user(addrOthers, (u32 __user * __user *) (unsigned long) addr) != 0)
  64. break;
  65. copied = access_process_vm(child, (u64)addrOthers, &tmp,
  66. sizeof(tmp), 0);
  67. if (copied != sizeof(tmp))
  68. break;
  69. ret = put_user(tmp, (u32 __user *) (unsigned long) data);
  70. break;
  71. }
  72. /* Read the word at location addr in the USER area. */
  73. case PTRACE_PEEKUSR: {
  74. struct pt_regs *regs;
  75. union fpureg *fregs;
  76. unsigned int tmp;
  77. regs = task_pt_regs(child);
  78. ret = 0; /* Default return value. */
  79. switch (addr) {
  80. case 0 ... 31:
  81. tmp = regs->regs[addr];
  82. break;
  83. case FPR_BASE ... FPR_BASE + 31:
  84. if (!tsk_used_math(child)) {
  85. /* FP not yet used */
  86. tmp = -1;
  87. break;
  88. }
  89. fregs = get_fpu_regs(child);
  90. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  91. /*
  92. * The odd registers are actually the high
  93. * order bits of the values stored in the even
  94. * registers - unless we're using r2k_switch.S.
  95. */
  96. tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  97. addr & 1);
  98. break;
  99. }
  100. tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);
  101. break;
  102. case PC:
  103. tmp = regs->cp0_epc;
  104. break;
  105. case CAUSE:
  106. tmp = regs->cp0_cause;
  107. break;
  108. case BADVADDR:
  109. tmp = regs->cp0_badvaddr;
  110. break;
  111. case MMHI:
  112. tmp = regs->hi;
  113. break;
  114. case MMLO:
  115. tmp = regs->lo;
  116. break;
  117. case FPC_CSR:
  118. tmp = child->thread.fpu.fcr31;
  119. break;
  120. case FPC_EIR:
  121. /* implementation / version register */
  122. tmp = boot_cpu_data.fpu_id;
  123. break;
  124. case DSP_BASE ... DSP_BASE + 5: {
  125. dspreg_t *dregs;
  126. if (!cpu_has_dsp) {
  127. tmp = 0;
  128. ret = -EIO;
  129. goto out;
  130. }
  131. dregs = __get_dsp_regs(child);
  132. tmp = (unsigned long) (dregs[addr - DSP_BASE]);
  133. break;
  134. }
  135. case DSP_CONTROL:
  136. if (!cpu_has_dsp) {
  137. tmp = 0;
  138. ret = -EIO;
  139. goto out;
  140. }
  141. tmp = child->thread.dsp.dspcontrol;
  142. break;
  143. default:
  144. tmp = 0;
  145. ret = -EIO;
  146. goto out;
  147. }
  148. ret = put_user(tmp, (unsigned __user *) (unsigned long) data);
  149. break;
  150. }
  151. /*
  152. * Write 4 bytes into the other process' storage
  153. * data is the 4 bytes that the user wants written
  154. * addr is a pointer in the user's storage that contains an
  155. * 8 byte address in the other process where the 4 bytes
  156. * that is to be written
  157. * (this is run in a 32-bit process looking at a 64-bit process)
  158. * when I and D space are separate, these will need to be fixed.
  159. */
  160. case PTRACE_POKETEXT_3264:
  161. case PTRACE_POKEDATA_3264: {
  162. u32 __user * addrOthers;
  163. /* Get the addr in the other process that we want to write into */
  164. ret = -EIO;
  165. if (get_user(addrOthers, (u32 __user * __user *) (unsigned long) addr) != 0)
  166. break;
  167. ret = 0;
  168. if (access_process_vm(child, (u64)addrOthers, &data,
  169. sizeof(data), 1) == sizeof(data))
  170. break;
  171. ret = -EIO;
  172. break;
  173. }
  174. case PTRACE_POKEUSR: {
  175. struct pt_regs *regs;
  176. ret = 0;
  177. regs = task_pt_regs(child);
  178. switch (addr) {
  179. case 0 ... 31:
  180. regs->regs[addr] = data;
  181. break;
  182. case FPR_BASE ... FPR_BASE + 31: {
  183. union fpureg *fregs = get_fpu_regs(child);
  184. if (!tsk_used_math(child)) {
  185. /* FP not yet used */
  186. memset(&child->thread.fpu, ~0,
  187. sizeof(child->thread.fpu));
  188. child->thread.fpu.fcr31 = 0;
  189. }
  190. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  191. /*
  192. * The odd registers are actually the high
  193. * order bits of the values stored in the even
  194. * registers - unless we're using r2k_switch.S.
  195. */
  196. set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  197. addr & 1, data);
  198. break;
  199. }
  200. set_fpr64(&fregs[addr - FPR_BASE], 0, data);
  201. break;
  202. }
  203. case PC:
  204. regs->cp0_epc = data;
  205. break;
  206. case MMHI:
  207. regs->hi = data;
  208. break;
  209. case MMLO:
  210. regs->lo = data;
  211. break;
  212. case FPC_CSR:
  213. child->thread.fpu.fcr31 = data;
  214. break;
  215. case DSP_BASE ... DSP_BASE + 5: {
  216. dspreg_t *dregs;
  217. if (!cpu_has_dsp) {
  218. ret = -EIO;
  219. break;
  220. }
  221. dregs = __get_dsp_regs(child);
  222. dregs[addr - DSP_BASE] = data;
  223. break;
  224. }
  225. case DSP_CONTROL:
  226. if (!cpu_has_dsp) {
  227. ret = -EIO;
  228. break;
  229. }
  230. child->thread.dsp.dspcontrol = data;
  231. break;
  232. default:
  233. /* The rest are not allowed. */
  234. ret = -EIO;
  235. break;
  236. }
  237. break;
  238. }
  239. case PTRACE_GETREGS:
  240. ret = ptrace_getregs(child,
  241. (struct user_pt_regs __user *) (__u64) data);
  242. break;
  243. case PTRACE_SETREGS:
  244. ret = ptrace_setregs(child,
  245. (struct user_pt_regs __user *) (__u64) data);
  246. break;
  247. case PTRACE_GETFPREGS:
  248. ret = ptrace_getfpregs(child, (__u32 __user *) (__u64) data);
  249. break;
  250. case PTRACE_SETFPREGS:
  251. ret = ptrace_setfpregs(child, (__u32 __user *) (__u64) data);
  252. break;
  253. case PTRACE_GET_THREAD_AREA:
  254. ret = put_user(task_thread_info(child)->tp_value,
  255. (unsigned int __user *) (unsigned long) data);
  256. break;
  257. case PTRACE_GET_THREAD_AREA_3264:
  258. ret = put_user(task_thread_info(child)->tp_value,
  259. (unsigned long __user *) (unsigned long) data);
  260. break;
  261. case PTRACE_GET_WATCH_REGS:
  262. ret = ptrace_get_watch_regs(child,
  263. (struct pt_watch_regs __user *) (unsigned long) addr);
  264. break;
  265. case PTRACE_SET_WATCH_REGS:
  266. ret = ptrace_set_watch_regs(child,
  267. (struct pt_watch_regs __user *) (unsigned long) addr);
  268. break;
  269. default:
  270. ret = compat_ptrace_request(child, request, addr, data);
  271. break;
  272. }
  273. out:
  274. return ret;
  275. }