ptrace.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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/context_tracking.h>
  19. #include <linux/elf.h>
  20. #include <linux/kernel.h>
  21. #include <linux/sched.h>
  22. #include <linux/sched/task_stack.h>
  23. #include <linux/mm.h>
  24. #include <linux/errno.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/regset.h>
  27. #include <linux/smp.h>
  28. #include <linux/security.h>
  29. #include <linux/stddef.h>
  30. #include <linux/tracehook.h>
  31. #include <linux/audit.h>
  32. #include <linux/seccomp.h>
  33. #include <linux/ftrace.h>
  34. #include <asm/byteorder.h>
  35. #include <asm/cpu.h>
  36. #include <asm/cpu-info.h>
  37. #include <asm/dsp.h>
  38. #include <asm/fpu.h>
  39. #include <asm/mipsregs.h>
  40. #include <asm/mipsmtregs.h>
  41. #include <asm/pgtable.h>
  42. #include <asm/page.h>
  43. #include <asm/syscall.h>
  44. #include <linux/uaccess.h>
  45. #include <asm/bootinfo.h>
  46. #include <asm/reg.h>
  47. #define CREATE_TRACE_POINTS
  48. #include <trace/events/syscalls.h>
  49. static void init_fp_ctx(struct task_struct *target)
  50. {
  51. /* If FP has been used then the target already has context */
  52. if (tsk_used_math(target))
  53. return;
  54. /* Begin with data registers set to all 1s... */
  55. memset(&target->thread.fpu.fpr, ~0, sizeof(target->thread.fpu.fpr));
  56. /* FCSR has been preset by `mips_set_personality_nan'. */
  57. /*
  58. * Record that the target has "used" math, such that the context
  59. * just initialised, and any modifications made by the caller,
  60. * aren't discarded.
  61. */
  62. set_stopped_child_used_math(target);
  63. }
  64. /*
  65. * Called by kernel/ptrace.c when detaching..
  66. *
  67. * Make sure single step bits etc are not set.
  68. */
  69. void ptrace_disable(struct task_struct *child)
  70. {
  71. /* Don't load the watchpoint registers for the ex-child. */
  72. clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
  73. }
  74. /*
  75. * Poke at FCSR according to its mask. Set the Cause bits even
  76. * if a corresponding Enable bit is set. This will be noticed at
  77. * the time the thread is switched to and SIGFPE thrown accordingly.
  78. */
  79. static void ptrace_setfcr31(struct task_struct *child, u32 value)
  80. {
  81. u32 fcr31;
  82. u32 mask;
  83. fcr31 = child->thread.fpu.fcr31;
  84. mask = boot_cpu_data.fpu_msk31;
  85. child->thread.fpu.fcr31 = (value & ~mask) | (fcr31 & mask);
  86. }
  87. /*
  88. * Read a general register set. We always use the 64-bit format, even
  89. * for 32-bit kernels and for 32-bit processes on a 64-bit kernel.
  90. * Registers are sign extended to fill the available space.
  91. */
  92. int ptrace_getregs(struct task_struct *child, struct user_pt_regs __user *data)
  93. {
  94. struct pt_regs *regs;
  95. int i;
  96. if (!access_ok(VERIFY_WRITE, data, 38 * 8))
  97. return -EIO;
  98. regs = task_pt_regs(child);
  99. for (i = 0; i < 32; i++)
  100. __put_user((long)regs->regs[i], (__s64 __user *)&data->regs[i]);
  101. __put_user((long)regs->lo, (__s64 __user *)&data->lo);
  102. __put_user((long)regs->hi, (__s64 __user *)&data->hi);
  103. __put_user((long)regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
  104. __put_user((long)regs->cp0_badvaddr, (__s64 __user *)&data->cp0_badvaddr);
  105. __put_user((long)regs->cp0_status, (__s64 __user *)&data->cp0_status);
  106. __put_user((long)regs->cp0_cause, (__s64 __user *)&data->cp0_cause);
  107. return 0;
  108. }
  109. /*
  110. * Write a general register set. As for PTRACE_GETREGS, we always use
  111. * the 64-bit format. On a 32-bit kernel only the lower order half
  112. * (according to endianness) will be used.
  113. */
  114. int ptrace_setregs(struct task_struct *child, struct user_pt_regs __user *data)
  115. {
  116. struct pt_regs *regs;
  117. int i;
  118. if (!access_ok(VERIFY_READ, data, 38 * 8))
  119. return -EIO;
  120. regs = task_pt_regs(child);
  121. for (i = 0; i < 32; i++)
  122. __get_user(regs->regs[i], (__s64 __user *)&data->regs[i]);
  123. __get_user(regs->lo, (__s64 __user *)&data->lo);
  124. __get_user(regs->hi, (__s64 __user *)&data->hi);
  125. __get_user(regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
  126. /* badvaddr, status, and cause may not be written. */
  127. return 0;
  128. }
  129. int ptrace_getfpregs(struct task_struct *child, __u32 __user *data)
  130. {
  131. int i;
  132. if (!access_ok(VERIFY_WRITE, data, 33 * 8))
  133. return -EIO;
  134. if (tsk_used_math(child)) {
  135. union fpureg *fregs = get_fpu_regs(child);
  136. for (i = 0; i < 32; i++)
  137. __put_user(get_fpr64(&fregs[i], 0),
  138. i + (__u64 __user *)data);
  139. } else {
  140. for (i = 0; i < 32; i++)
  141. __put_user((__u64) -1, i + (__u64 __user *) data);
  142. }
  143. __put_user(child->thread.fpu.fcr31, data + 64);
  144. __put_user(boot_cpu_data.fpu_id, data + 65);
  145. return 0;
  146. }
  147. int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
  148. {
  149. union fpureg *fregs;
  150. u64 fpr_val;
  151. u32 value;
  152. int i;
  153. if (!access_ok(VERIFY_READ, data, 33 * 8))
  154. return -EIO;
  155. init_fp_ctx(child);
  156. fregs = get_fpu_regs(child);
  157. for (i = 0; i < 32; i++) {
  158. __get_user(fpr_val, i + (__u64 __user *)data);
  159. set_fpr64(&fregs[i], 0, fpr_val);
  160. }
  161. __get_user(value, data + 64);
  162. ptrace_setfcr31(child, value);
  163. /* FIR may not be written. */
  164. return 0;
  165. }
  166. int ptrace_get_watch_regs(struct task_struct *child,
  167. struct pt_watch_regs __user *addr)
  168. {
  169. enum pt_watch_style style;
  170. int i;
  171. if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
  172. return -EIO;
  173. if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs)))
  174. return -EIO;
  175. #ifdef CONFIG_32BIT
  176. style = pt_watch_style_mips32;
  177. #define WATCH_STYLE mips32
  178. #else
  179. style = pt_watch_style_mips64;
  180. #define WATCH_STYLE mips64
  181. #endif
  182. __put_user(style, &addr->style);
  183. __put_user(boot_cpu_data.watch_reg_use_cnt,
  184. &addr->WATCH_STYLE.num_valid);
  185. for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
  186. __put_user(child->thread.watch.mips3264.watchlo[i],
  187. &addr->WATCH_STYLE.watchlo[i]);
  188. __put_user(child->thread.watch.mips3264.watchhi[i] &
  189. (MIPS_WATCHHI_MASK | MIPS_WATCHHI_IRW),
  190. &addr->WATCH_STYLE.watchhi[i]);
  191. __put_user(boot_cpu_data.watch_reg_masks[i],
  192. &addr->WATCH_STYLE.watch_masks[i]);
  193. }
  194. for (; i < 8; i++) {
  195. __put_user(0, &addr->WATCH_STYLE.watchlo[i]);
  196. __put_user(0, &addr->WATCH_STYLE.watchhi[i]);
  197. __put_user(0, &addr->WATCH_STYLE.watch_masks[i]);
  198. }
  199. return 0;
  200. }
  201. int ptrace_set_watch_regs(struct task_struct *child,
  202. struct pt_watch_regs __user *addr)
  203. {
  204. int i;
  205. int watch_active = 0;
  206. unsigned long lt[NUM_WATCH_REGS];
  207. u16 ht[NUM_WATCH_REGS];
  208. if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
  209. return -EIO;
  210. if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs)))
  211. return -EIO;
  212. /* Check the values. */
  213. for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
  214. __get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]);
  215. #ifdef CONFIG_32BIT
  216. if (lt[i] & __UA_LIMIT)
  217. return -EINVAL;
  218. #else
  219. if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
  220. if (lt[i] & 0xffffffff80000000UL)
  221. return -EINVAL;
  222. } else {
  223. if (lt[i] & __UA_LIMIT)
  224. return -EINVAL;
  225. }
  226. #endif
  227. __get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]);
  228. if (ht[i] & ~MIPS_WATCHHI_MASK)
  229. return -EINVAL;
  230. }
  231. /* Install them. */
  232. for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
  233. if (lt[i] & MIPS_WATCHLO_IRW)
  234. watch_active = 1;
  235. child->thread.watch.mips3264.watchlo[i] = lt[i];
  236. /* Set the G bit. */
  237. child->thread.watch.mips3264.watchhi[i] = ht[i];
  238. }
  239. if (watch_active)
  240. set_tsk_thread_flag(child, TIF_LOAD_WATCH);
  241. else
  242. clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
  243. return 0;
  244. }
  245. /* regset get/set implementations */
  246. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  247. static int gpr32_get(struct task_struct *target,
  248. const struct user_regset *regset,
  249. unsigned int pos, unsigned int count,
  250. void *kbuf, void __user *ubuf)
  251. {
  252. struct pt_regs *regs = task_pt_regs(target);
  253. u32 uregs[ELF_NGREG] = {};
  254. mips_dump_regs32(uregs, regs);
  255. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
  256. sizeof(uregs));
  257. }
  258. static int gpr32_set(struct task_struct *target,
  259. const struct user_regset *regset,
  260. unsigned int pos, unsigned int count,
  261. const void *kbuf, const void __user *ubuf)
  262. {
  263. struct pt_regs *regs = task_pt_regs(target);
  264. u32 uregs[ELF_NGREG];
  265. unsigned start, num_regs, i;
  266. int err;
  267. start = pos / sizeof(u32);
  268. num_regs = count / sizeof(u32);
  269. if (start + num_regs > ELF_NGREG)
  270. return -EIO;
  271. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
  272. sizeof(uregs));
  273. if (err)
  274. return err;
  275. for (i = start; i < num_regs; i++) {
  276. /*
  277. * Cast all values to signed here so that if this is a 64-bit
  278. * kernel, the supplied 32-bit values will be sign extended.
  279. */
  280. switch (i) {
  281. case MIPS32_EF_R1 ... MIPS32_EF_R25:
  282. /* k0/k1 are ignored. */
  283. case MIPS32_EF_R28 ... MIPS32_EF_R31:
  284. regs->regs[i - MIPS32_EF_R0] = (s32)uregs[i];
  285. break;
  286. case MIPS32_EF_LO:
  287. regs->lo = (s32)uregs[i];
  288. break;
  289. case MIPS32_EF_HI:
  290. regs->hi = (s32)uregs[i];
  291. break;
  292. case MIPS32_EF_CP0_EPC:
  293. regs->cp0_epc = (s32)uregs[i];
  294. break;
  295. }
  296. }
  297. return 0;
  298. }
  299. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  300. #ifdef CONFIG_64BIT
  301. static int gpr64_get(struct task_struct *target,
  302. const struct user_regset *regset,
  303. unsigned int pos, unsigned int count,
  304. void *kbuf, void __user *ubuf)
  305. {
  306. struct pt_regs *regs = task_pt_regs(target);
  307. u64 uregs[ELF_NGREG] = {};
  308. mips_dump_regs64(uregs, regs);
  309. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
  310. sizeof(uregs));
  311. }
  312. static int gpr64_set(struct task_struct *target,
  313. const struct user_regset *regset,
  314. unsigned int pos, unsigned int count,
  315. const void *kbuf, const void __user *ubuf)
  316. {
  317. struct pt_regs *regs = task_pt_regs(target);
  318. u64 uregs[ELF_NGREG];
  319. unsigned start, num_regs, i;
  320. int err;
  321. start = pos / sizeof(u64);
  322. num_regs = count / sizeof(u64);
  323. if (start + num_regs > ELF_NGREG)
  324. return -EIO;
  325. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
  326. sizeof(uregs));
  327. if (err)
  328. return err;
  329. for (i = start; i < num_regs; i++) {
  330. switch (i) {
  331. case MIPS64_EF_R1 ... MIPS64_EF_R25:
  332. /* k0/k1 are ignored. */
  333. case MIPS64_EF_R28 ... MIPS64_EF_R31:
  334. regs->regs[i - MIPS64_EF_R0] = uregs[i];
  335. break;
  336. case MIPS64_EF_LO:
  337. regs->lo = uregs[i];
  338. break;
  339. case MIPS64_EF_HI:
  340. regs->hi = uregs[i];
  341. break;
  342. case MIPS64_EF_CP0_EPC:
  343. regs->cp0_epc = uregs[i];
  344. break;
  345. }
  346. }
  347. return 0;
  348. }
  349. #endif /* CONFIG_64BIT */
  350. static int fpr_get(struct task_struct *target,
  351. const struct user_regset *regset,
  352. unsigned int pos, unsigned int count,
  353. void *kbuf, void __user *ubuf)
  354. {
  355. unsigned i;
  356. int err;
  357. u64 fpr_val;
  358. /* XXX fcr31 */
  359. if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
  360. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  361. &target->thread.fpu,
  362. 0, sizeof(elf_fpregset_t));
  363. for (i = 0; i < NUM_FPU_REGS; i++) {
  364. fpr_val = get_fpr64(&target->thread.fpu.fpr[i], 0);
  365. err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  366. &fpr_val, i * sizeof(elf_fpreg_t),
  367. (i + 1) * sizeof(elf_fpreg_t));
  368. if (err)
  369. return err;
  370. }
  371. return 0;
  372. }
  373. static int fpr_set(struct task_struct *target,
  374. const struct user_regset *regset,
  375. unsigned int pos, unsigned int count,
  376. const void *kbuf, const void __user *ubuf)
  377. {
  378. unsigned i;
  379. int err;
  380. u64 fpr_val;
  381. /* XXX fcr31 */
  382. init_fp_ctx(target);
  383. if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
  384. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  385. &target->thread.fpu,
  386. 0, sizeof(elf_fpregset_t));
  387. for (i = 0; i < NUM_FPU_REGS; i++) {
  388. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  389. &fpr_val, i * sizeof(elf_fpreg_t),
  390. (i + 1) * sizeof(elf_fpreg_t));
  391. if (err)
  392. return err;
  393. set_fpr64(&target->thread.fpu.fpr[i], 0, fpr_val);
  394. }
  395. return 0;
  396. }
  397. enum mips_regset {
  398. REGSET_GPR,
  399. REGSET_FPR,
  400. };
  401. struct pt_regs_offset {
  402. const char *name;
  403. int offset;
  404. };
  405. #define REG_OFFSET_NAME(reg, r) { \
  406. .name = #reg, \
  407. .offset = offsetof(struct pt_regs, r) \
  408. }
  409. #define REG_OFFSET_END { \
  410. .name = NULL, \
  411. .offset = 0 \
  412. }
  413. static const struct pt_regs_offset regoffset_table[] = {
  414. REG_OFFSET_NAME(r0, regs[0]),
  415. REG_OFFSET_NAME(r1, regs[1]),
  416. REG_OFFSET_NAME(r2, regs[2]),
  417. REG_OFFSET_NAME(r3, regs[3]),
  418. REG_OFFSET_NAME(r4, regs[4]),
  419. REG_OFFSET_NAME(r5, regs[5]),
  420. REG_OFFSET_NAME(r6, regs[6]),
  421. REG_OFFSET_NAME(r7, regs[7]),
  422. REG_OFFSET_NAME(r8, regs[8]),
  423. REG_OFFSET_NAME(r9, regs[9]),
  424. REG_OFFSET_NAME(r10, regs[10]),
  425. REG_OFFSET_NAME(r11, regs[11]),
  426. REG_OFFSET_NAME(r12, regs[12]),
  427. REG_OFFSET_NAME(r13, regs[13]),
  428. REG_OFFSET_NAME(r14, regs[14]),
  429. REG_OFFSET_NAME(r15, regs[15]),
  430. REG_OFFSET_NAME(r16, regs[16]),
  431. REG_OFFSET_NAME(r17, regs[17]),
  432. REG_OFFSET_NAME(r18, regs[18]),
  433. REG_OFFSET_NAME(r19, regs[19]),
  434. REG_OFFSET_NAME(r20, regs[20]),
  435. REG_OFFSET_NAME(r21, regs[21]),
  436. REG_OFFSET_NAME(r22, regs[22]),
  437. REG_OFFSET_NAME(r23, regs[23]),
  438. REG_OFFSET_NAME(r24, regs[24]),
  439. REG_OFFSET_NAME(r25, regs[25]),
  440. REG_OFFSET_NAME(r26, regs[26]),
  441. REG_OFFSET_NAME(r27, regs[27]),
  442. REG_OFFSET_NAME(r28, regs[28]),
  443. REG_OFFSET_NAME(r29, regs[29]),
  444. REG_OFFSET_NAME(r30, regs[30]),
  445. REG_OFFSET_NAME(r31, regs[31]),
  446. REG_OFFSET_NAME(c0_status, cp0_status),
  447. REG_OFFSET_NAME(hi, hi),
  448. REG_OFFSET_NAME(lo, lo),
  449. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  450. REG_OFFSET_NAME(acx, acx),
  451. #endif
  452. REG_OFFSET_NAME(c0_badvaddr, cp0_badvaddr),
  453. REG_OFFSET_NAME(c0_cause, cp0_cause),
  454. REG_OFFSET_NAME(c0_epc, cp0_epc),
  455. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  456. REG_OFFSET_NAME(mpl0, mpl[0]),
  457. REG_OFFSET_NAME(mpl1, mpl[1]),
  458. REG_OFFSET_NAME(mpl2, mpl[2]),
  459. REG_OFFSET_NAME(mtp0, mtp[0]),
  460. REG_OFFSET_NAME(mtp1, mtp[1]),
  461. REG_OFFSET_NAME(mtp2, mtp[2]),
  462. #endif
  463. REG_OFFSET_END,
  464. };
  465. /**
  466. * regs_query_register_offset() - query register offset from its name
  467. * @name: the name of a register
  468. *
  469. * regs_query_register_offset() returns the offset of a register in struct
  470. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  471. */
  472. int regs_query_register_offset(const char *name)
  473. {
  474. const struct pt_regs_offset *roff;
  475. for (roff = regoffset_table; roff->name != NULL; roff++)
  476. if (!strcmp(roff->name, name))
  477. return roff->offset;
  478. return -EINVAL;
  479. }
  480. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  481. static const struct user_regset mips_regsets[] = {
  482. [REGSET_GPR] = {
  483. .core_note_type = NT_PRSTATUS,
  484. .n = ELF_NGREG,
  485. .size = sizeof(unsigned int),
  486. .align = sizeof(unsigned int),
  487. .get = gpr32_get,
  488. .set = gpr32_set,
  489. },
  490. [REGSET_FPR] = {
  491. .core_note_type = NT_PRFPREG,
  492. .n = ELF_NFPREG,
  493. .size = sizeof(elf_fpreg_t),
  494. .align = sizeof(elf_fpreg_t),
  495. .get = fpr_get,
  496. .set = fpr_set,
  497. },
  498. };
  499. static const struct user_regset_view user_mips_view = {
  500. .name = "mips",
  501. .e_machine = ELF_ARCH,
  502. .ei_osabi = ELF_OSABI,
  503. .regsets = mips_regsets,
  504. .n = ARRAY_SIZE(mips_regsets),
  505. };
  506. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  507. #ifdef CONFIG_64BIT
  508. static const struct user_regset mips64_regsets[] = {
  509. [REGSET_GPR] = {
  510. .core_note_type = NT_PRSTATUS,
  511. .n = ELF_NGREG,
  512. .size = sizeof(unsigned long),
  513. .align = sizeof(unsigned long),
  514. .get = gpr64_get,
  515. .set = gpr64_set,
  516. },
  517. [REGSET_FPR] = {
  518. .core_note_type = NT_PRFPREG,
  519. .n = ELF_NFPREG,
  520. .size = sizeof(elf_fpreg_t),
  521. .align = sizeof(elf_fpreg_t),
  522. .get = fpr_get,
  523. .set = fpr_set,
  524. },
  525. };
  526. static const struct user_regset_view user_mips64_view = {
  527. .name = "mips64",
  528. .e_machine = ELF_ARCH,
  529. .ei_osabi = ELF_OSABI,
  530. .regsets = mips64_regsets,
  531. .n = ARRAY_SIZE(mips64_regsets),
  532. };
  533. #endif /* CONFIG_64BIT */
  534. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  535. {
  536. #ifdef CONFIG_32BIT
  537. return &user_mips_view;
  538. #else
  539. #ifdef CONFIG_MIPS32_O32
  540. if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
  541. return &user_mips_view;
  542. #endif
  543. return &user_mips64_view;
  544. #endif
  545. }
  546. long arch_ptrace(struct task_struct *child, long request,
  547. unsigned long addr, unsigned long data)
  548. {
  549. int ret;
  550. void __user *addrp = (void __user *) addr;
  551. void __user *datavp = (void __user *) data;
  552. unsigned long __user *datalp = (void __user *) data;
  553. switch (request) {
  554. /* when I and D space are separate, these will need to be fixed. */
  555. case PTRACE_PEEKTEXT: /* read word at location addr. */
  556. case PTRACE_PEEKDATA:
  557. ret = generic_ptrace_peekdata(child, addr, data);
  558. break;
  559. /* Read the word at location addr in the USER area. */
  560. case PTRACE_PEEKUSR: {
  561. struct pt_regs *regs;
  562. union fpureg *fregs;
  563. unsigned long tmp = 0;
  564. regs = task_pt_regs(child);
  565. ret = 0; /* Default return value. */
  566. switch (addr) {
  567. case 0 ... 31:
  568. tmp = regs->regs[addr];
  569. break;
  570. case FPR_BASE ... FPR_BASE + 31:
  571. if (!tsk_used_math(child)) {
  572. /* FP not yet used */
  573. tmp = -1;
  574. break;
  575. }
  576. fregs = get_fpu_regs(child);
  577. #ifdef CONFIG_32BIT
  578. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  579. /*
  580. * The odd registers are actually the high
  581. * order bits of the values stored in the even
  582. * registers - unless we're using r2k_switch.S.
  583. */
  584. tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  585. addr & 1);
  586. break;
  587. }
  588. #endif
  589. tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);
  590. break;
  591. case PC:
  592. tmp = regs->cp0_epc;
  593. break;
  594. case CAUSE:
  595. tmp = regs->cp0_cause;
  596. break;
  597. case BADVADDR:
  598. tmp = regs->cp0_badvaddr;
  599. break;
  600. case MMHI:
  601. tmp = regs->hi;
  602. break;
  603. case MMLO:
  604. tmp = regs->lo;
  605. break;
  606. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  607. case ACX:
  608. tmp = regs->acx;
  609. break;
  610. #endif
  611. case FPC_CSR:
  612. tmp = child->thread.fpu.fcr31;
  613. break;
  614. case FPC_EIR:
  615. /* implementation / version register */
  616. tmp = boot_cpu_data.fpu_id;
  617. break;
  618. case DSP_BASE ... DSP_BASE + 5: {
  619. dspreg_t *dregs;
  620. if (!cpu_has_dsp) {
  621. tmp = 0;
  622. ret = -EIO;
  623. goto out;
  624. }
  625. dregs = __get_dsp_regs(child);
  626. tmp = (unsigned long) (dregs[addr - DSP_BASE]);
  627. break;
  628. }
  629. case DSP_CONTROL:
  630. if (!cpu_has_dsp) {
  631. tmp = 0;
  632. ret = -EIO;
  633. goto out;
  634. }
  635. tmp = child->thread.dsp.dspcontrol;
  636. break;
  637. default:
  638. tmp = 0;
  639. ret = -EIO;
  640. goto out;
  641. }
  642. ret = put_user(tmp, datalp);
  643. break;
  644. }
  645. /* when I and D space are separate, this will have to be fixed. */
  646. case PTRACE_POKETEXT: /* write the word at location addr. */
  647. case PTRACE_POKEDATA:
  648. ret = generic_ptrace_pokedata(child, addr, data);
  649. break;
  650. case PTRACE_POKEUSR: {
  651. struct pt_regs *regs;
  652. ret = 0;
  653. regs = task_pt_regs(child);
  654. switch (addr) {
  655. case 0 ... 31:
  656. regs->regs[addr] = data;
  657. break;
  658. case FPR_BASE ... FPR_BASE + 31: {
  659. union fpureg *fregs = get_fpu_regs(child);
  660. init_fp_ctx(child);
  661. #ifdef CONFIG_32BIT
  662. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  663. /*
  664. * The odd registers are actually the high
  665. * order bits of the values stored in the even
  666. * registers - unless we're using r2k_switch.S.
  667. */
  668. set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  669. addr & 1, data);
  670. break;
  671. }
  672. #endif
  673. set_fpr64(&fregs[addr - FPR_BASE], 0, data);
  674. break;
  675. }
  676. case PC:
  677. regs->cp0_epc = data;
  678. break;
  679. case MMHI:
  680. regs->hi = data;
  681. break;
  682. case MMLO:
  683. regs->lo = data;
  684. break;
  685. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  686. case ACX:
  687. regs->acx = data;
  688. break;
  689. #endif
  690. case FPC_CSR:
  691. init_fp_ctx(child);
  692. ptrace_setfcr31(child, data);
  693. break;
  694. case DSP_BASE ... DSP_BASE + 5: {
  695. dspreg_t *dregs;
  696. if (!cpu_has_dsp) {
  697. ret = -EIO;
  698. break;
  699. }
  700. dregs = __get_dsp_regs(child);
  701. dregs[addr - DSP_BASE] = data;
  702. break;
  703. }
  704. case DSP_CONTROL:
  705. if (!cpu_has_dsp) {
  706. ret = -EIO;
  707. break;
  708. }
  709. child->thread.dsp.dspcontrol = data;
  710. break;
  711. default:
  712. /* The rest are not allowed. */
  713. ret = -EIO;
  714. break;
  715. }
  716. break;
  717. }
  718. case PTRACE_GETREGS:
  719. ret = ptrace_getregs(child, datavp);
  720. break;
  721. case PTRACE_SETREGS:
  722. ret = ptrace_setregs(child, datavp);
  723. break;
  724. case PTRACE_GETFPREGS:
  725. ret = ptrace_getfpregs(child, datavp);
  726. break;
  727. case PTRACE_SETFPREGS:
  728. ret = ptrace_setfpregs(child, datavp);
  729. break;
  730. case PTRACE_GET_THREAD_AREA:
  731. ret = put_user(task_thread_info(child)->tp_value, datalp);
  732. break;
  733. case PTRACE_GET_WATCH_REGS:
  734. ret = ptrace_get_watch_regs(child, addrp);
  735. break;
  736. case PTRACE_SET_WATCH_REGS:
  737. ret = ptrace_set_watch_regs(child, addrp);
  738. break;
  739. default:
  740. ret = ptrace_request(child, request, addr, data);
  741. break;
  742. }
  743. out:
  744. return ret;
  745. }
  746. /*
  747. * Notification of system call entry/exit
  748. * - triggered by current->work.syscall_trace
  749. */
  750. asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
  751. {
  752. user_exit();
  753. current_thread_info()->syscall = syscall;
  754. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  755. tracehook_report_syscall_entry(regs))
  756. return -1;
  757. if (secure_computing(NULL) == -1)
  758. return -1;
  759. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  760. trace_sys_enter(regs, regs->regs[2]);
  761. audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
  762. regs->regs[6], regs->regs[7]);
  763. return syscall;
  764. }
  765. /*
  766. * Notification of system call entry/exit
  767. * - triggered by current->work.syscall_trace
  768. */
  769. asmlinkage void syscall_trace_leave(struct pt_regs *regs)
  770. {
  771. /*
  772. * We may come here right after calling schedule_user()
  773. * or do_notify_resume(), in which case we can be in RCU
  774. * user mode.
  775. */
  776. user_exit();
  777. audit_syscall_exit(regs);
  778. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  779. trace_sys_exit(regs, regs->regs[2]);
  780. if (test_thread_flag(TIF_SYSCALL_TRACE))
  781. tracehook_report_syscall_exit(regs, 0);
  782. user_enter();
  783. }