ptrace32.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 = ptrace_access_vm(child, (u64)addrOthers, &tmp,
  66. sizeof(tmp), FOLL_FORCE);
  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_tsk_thread_flag(child, 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_fpr64(&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 (ptrace_access_vm(child, (u64)addrOthers, &data,
  169. sizeof(data),
  170. FOLL_FORCE | FOLL_WRITE) == sizeof(data))
  171. break;
  172. ret = -EIO;
  173. break;
  174. }
  175. case PTRACE_POKEUSR: {
  176. struct pt_regs *regs;
  177. ret = 0;
  178. regs = task_pt_regs(child);
  179. switch (addr) {
  180. case 0 ... 31:
  181. regs->regs[addr] = data;
  182. break;
  183. case FPR_BASE ... FPR_BASE + 31: {
  184. union fpureg *fregs = get_fpu_regs(child);
  185. if (!tsk_used_math(child)) {
  186. /* FP not yet used */
  187. memset(&child->thread.fpu, ~0,
  188. sizeof(child->thread.fpu));
  189. child->thread.fpu.fcr31 = 0;
  190. }
  191. if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) {
  192. /*
  193. * The odd registers are actually the high
  194. * order bits of the values stored in the even
  195. * registers - unless we're using r2k_switch.S.
  196. */
  197. set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  198. addr & 1, data);
  199. break;
  200. }
  201. set_fpr64(&fregs[addr - FPR_BASE], 0, data);
  202. break;
  203. }
  204. case PC:
  205. regs->cp0_epc = data;
  206. break;
  207. case MMHI:
  208. regs->hi = data;
  209. break;
  210. case MMLO:
  211. regs->lo = data;
  212. break;
  213. case FPC_CSR:
  214. child->thread.fpu.fcr31 = data;
  215. break;
  216. case DSP_BASE ... DSP_BASE + 5: {
  217. dspreg_t *dregs;
  218. if (!cpu_has_dsp) {
  219. ret = -EIO;
  220. break;
  221. }
  222. dregs = __get_dsp_regs(child);
  223. dregs[addr - DSP_BASE] = data;
  224. break;
  225. }
  226. case DSP_CONTROL:
  227. if (!cpu_has_dsp) {
  228. ret = -EIO;
  229. break;
  230. }
  231. child->thread.dsp.dspcontrol = data;
  232. break;
  233. default:
  234. /* The rest are not allowed. */
  235. ret = -EIO;
  236. break;
  237. }
  238. break;
  239. }
  240. case PTRACE_GETREGS:
  241. ret = ptrace_getregs(child,
  242. (struct user_pt_regs __user *) (__u64) data);
  243. break;
  244. case PTRACE_SETREGS:
  245. ret = ptrace_setregs(child,
  246. (struct user_pt_regs __user *) (__u64) data);
  247. break;
  248. case PTRACE_GETFPREGS:
  249. ret = ptrace_getfpregs(child, (__u32 __user *) (__u64) data);
  250. break;
  251. case PTRACE_SETFPREGS:
  252. ret = ptrace_setfpregs(child, (__u32 __user *) (__u64) data);
  253. break;
  254. case PTRACE_GET_THREAD_AREA:
  255. ret = put_user(task_thread_info(child)->tp_value,
  256. (unsigned int __user *) (unsigned long) data);
  257. break;
  258. case PTRACE_GET_THREAD_AREA_3264:
  259. ret = put_user(task_thread_info(child)->tp_value,
  260. (unsigned long __user *) (unsigned long) data);
  261. break;
  262. case PTRACE_GET_WATCH_REGS:
  263. ret = ptrace_get_watch_regs(child,
  264. (struct pt_watch_regs __user *) (unsigned long) addr);
  265. break;
  266. case PTRACE_SET_WATCH_REGS:
  267. ret = ptrace_set_watch_regs(child,
  268. (struct pt_watch_regs __user *) (unsigned long) addr);
  269. break;
  270. default:
  271. ret = compat_ptrace_request(child, request, addr, data);
  272. break;
  273. }
  274. out:
  275. return ret;
  276. }