ptrace.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. BUILD_BUG_ON(sizeof(fpr_val) != sizeof(elf_fpreg_t));
  388. for (i = 0; i < NUM_FPU_REGS && count >= sizeof(elf_fpreg_t); i++) {
  389. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  390. &fpr_val, i * sizeof(elf_fpreg_t),
  391. (i + 1) * sizeof(elf_fpreg_t));
  392. if (err)
  393. return err;
  394. set_fpr64(&target->thread.fpu.fpr[i], 0, fpr_val);
  395. }
  396. return 0;
  397. }
  398. enum mips_regset {
  399. REGSET_GPR,
  400. REGSET_FPR,
  401. };
  402. struct pt_regs_offset {
  403. const char *name;
  404. int offset;
  405. };
  406. #define REG_OFFSET_NAME(reg, r) { \
  407. .name = #reg, \
  408. .offset = offsetof(struct pt_regs, r) \
  409. }
  410. #define REG_OFFSET_END { \
  411. .name = NULL, \
  412. .offset = 0 \
  413. }
  414. static const struct pt_regs_offset regoffset_table[] = {
  415. REG_OFFSET_NAME(r0, regs[0]),
  416. REG_OFFSET_NAME(r1, regs[1]),
  417. REG_OFFSET_NAME(r2, regs[2]),
  418. REG_OFFSET_NAME(r3, regs[3]),
  419. REG_OFFSET_NAME(r4, regs[4]),
  420. REG_OFFSET_NAME(r5, regs[5]),
  421. REG_OFFSET_NAME(r6, regs[6]),
  422. REG_OFFSET_NAME(r7, regs[7]),
  423. REG_OFFSET_NAME(r8, regs[8]),
  424. REG_OFFSET_NAME(r9, regs[9]),
  425. REG_OFFSET_NAME(r10, regs[10]),
  426. REG_OFFSET_NAME(r11, regs[11]),
  427. REG_OFFSET_NAME(r12, regs[12]),
  428. REG_OFFSET_NAME(r13, regs[13]),
  429. REG_OFFSET_NAME(r14, regs[14]),
  430. REG_OFFSET_NAME(r15, regs[15]),
  431. REG_OFFSET_NAME(r16, regs[16]),
  432. REG_OFFSET_NAME(r17, regs[17]),
  433. REG_OFFSET_NAME(r18, regs[18]),
  434. REG_OFFSET_NAME(r19, regs[19]),
  435. REG_OFFSET_NAME(r20, regs[20]),
  436. REG_OFFSET_NAME(r21, regs[21]),
  437. REG_OFFSET_NAME(r22, regs[22]),
  438. REG_OFFSET_NAME(r23, regs[23]),
  439. REG_OFFSET_NAME(r24, regs[24]),
  440. REG_OFFSET_NAME(r25, regs[25]),
  441. REG_OFFSET_NAME(r26, regs[26]),
  442. REG_OFFSET_NAME(r27, regs[27]),
  443. REG_OFFSET_NAME(r28, regs[28]),
  444. REG_OFFSET_NAME(r29, regs[29]),
  445. REG_OFFSET_NAME(r30, regs[30]),
  446. REG_OFFSET_NAME(r31, regs[31]),
  447. REG_OFFSET_NAME(c0_status, cp0_status),
  448. REG_OFFSET_NAME(hi, hi),
  449. REG_OFFSET_NAME(lo, lo),
  450. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  451. REG_OFFSET_NAME(acx, acx),
  452. #endif
  453. REG_OFFSET_NAME(c0_badvaddr, cp0_badvaddr),
  454. REG_OFFSET_NAME(c0_cause, cp0_cause),
  455. REG_OFFSET_NAME(c0_epc, cp0_epc),
  456. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  457. REG_OFFSET_NAME(mpl0, mpl[0]),
  458. REG_OFFSET_NAME(mpl1, mpl[1]),
  459. REG_OFFSET_NAME(mpl2, mpl[2]),
  460. REG_OFFSET_NAME(mtp0, mtp[0]),
  461. REG_OFFSET_NAME(mtp1, mtp[1]),
  462. REG_OFFSET_NAME(mtp2, mtp[2]),
  463. #endif
  464. REG_OFFSET_END,
  465. };
  466. /**
  467. * regs_query_register_offset() - query register offset from its name
  468. * @name: the name of a register
  469. *
  470. * regs_query_register_offset() returns the offset of a register in struct
  471. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  472. */
  473. int regs_query_register_offset(const char *name)
  474. {
  475. const struct pt_regs_offset *roff;
  476. for (roff = regoffset_table; roff->name != NULL; roff++)
  477. if (!strcmp(roff->name, name))
  478. return roff->offset;
  479. return -EINVAL;
  480. }
  481. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  482. static const struct user_regset mips_regsets[] = {
  483. [REGSET_GPR] = {
  484. .core_note_type = NT_PRSTATUS,
  485. .n = ELF_NGREG,
  486. .size = sizeof(unsigned int),
  487. .align = sizeof(unsigned int),
  488. .get = gpr32_get,
  489. .set = gpr32_set,
  490. },
  491. [REGSET_FPR] = {
  492. .core_note_type = NT_PRFPREG,
  493. .n = ELF_NFPREG,
  494. .size = sizeof(elf_fpreg_t),
  495. .align = sizeof(elf_fpreg_t),
  496. .get = fpr_get,
  497. .set = fpr_set,
  498. },
  499. };
  500. static const struct user_regset_view user_mips_view = {
  501. .name = "mips",
  502. .e_machine = ELF_ARCH,
  503. .ei_osabi = ELF_OSABI,
  504. .regsets = mips_regsets,
  505. .n = ARRAY_SIZE(mips_regsets),
  506. };
  507. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  508. #ifdef CONFIG_64BIT
  509. static const struct user_regset mips64_regsets[] = {
  510. [REGSET_GPR] = {
  511. .core_note_type = NT_PRSTATUS,
  512. .n = ELF_NGREG,
  513. .size = sizeof(unsigned long),
  514. .align = sizeof(unsigned long),
  515. .get = gpr64_get,
  516. .set = gpr64_set,
  517. },
  518. [REGSET_FPR] = {
  519. .core_note_type = NT_PRFPREG,
  520. .n = ELF_NFPREG,
  521. .size = sizeof(elf_fpreg_t),
  522. .align = sizeof(elf_fpreg_t),
  523. .get = fpr_get,
  524. .set = fpr_set,
  525. },
  526. };
  527. static const struct user_regset_view user_mips64_view = {
  528. .name = "mips64",
  529. .e_machine = ELF_ARCH,
  530. .ei_osabi = ELF_OSABI,
  531. .regsets = mips64_regsets,
  532. .n = ARRAY_SIZE(mips64_regsets),
  533. };
  534. #endif /* CONFIG_64BIT */
  535. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  536. {
  537. #ifdef CONFIG_32BIT
  538. return &user_mips_view;
  539. #else
  540. #ifdef CONFIG_MIPS32_O32
  541. if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
  542. return &user_mips_view;
  543. #endif
  544. return &user_mips64_view;
  545. #endif
  546. }
  547. long arch_ptrace(struct task_struct *child, long request,
  548. unsigned long addr, unsigned long data)
  549. {
  550. int ret;
  551. void __user *addrp = (void __user *) addr;
  552. void __user *datavp = (void __user *) data;
  553. unsigned long __user *datalp = (void __user *) data;
  554. switch (request) {
  555. /* when I and D space are separate, these will need to be fixed. */
  556. case PTRACE_PEEKTEXT: /* read word at location addr. */
  557. case PTRACE_PEEKDATA:
  558. ret = generic_ptrace_peekdata(child, addr, data);
  559. break;
  560. /* Read the word at location addr in the USER area. */
  561. case PTRACE_PEEKUSR: {
  562. struct pt_regs *regs;
  563. union fpureg *fregs;
  564. unsigned long tmp = 0;
  565. regs = task_pt_regs(child);
  566. ret = 0; /* Default return value. */
  567. switch (addr) {
  568. case 0 ... 31:
  569. tmp = regs->regs[addr];
  570. break;
  571. case FPR_BASE ... FPR_BASE + 31:
  572. if (!tsk_used_math(child)) {
  573. /* FP not yet used */
  574. tmp = -1;
  575. break;
  576. }
  577. fregs = get_fpu_regs(child);
  578. #ifdef CONFIG_32BIT
  579. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  580. /*
  581. * The odd registers are actually the high
  582. * order bits of the values stored in the even
  583. * registers - unless we're using r2k_switch.S.
  584. */
  585. tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  586. addr & 1);
  587. break;
  588. }
  589. #endif
  590. tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);
  591. break;
  592. case PC:
  593. tmp = regs->cp0_epc;
  594. break;
  595. case CAUSE:
  596. tmp = regs->cp0_cause;
  597. break;
  598. case BADVADDR:
  599. tmp = regs->cp0_badvaddr;
  600. break;
  601. case MMHI:
  602. tmp = regs->hi;
  603. break;
  604. case MMLO:
  605. tmp = regs->lo;
  606. break;
  607. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  608. case ACX:
  609. tmp = regs->acx;
  610. break;
  611. #endif
  612. case FPC_CSR:
  613. tmp = child->thread.fpu.fcr31;
  614. break;
  615. case FPC_EIR:
  616. /* implementation / version register */
  617. tmp = boot_cpu_data.fpu_id;
  618. break;
  619. case DSP_BASE ... DSP_BASE + 5: {
  620. dspreg_t *dregs;
  621. if (!cpu_has_dsp) {
  622. tmp = 0;
  623. ret = -EIO;
  624. goto out;
  625. }
  626. dregs = __get_dsp_regs(child);
  627. tmp = (unsigned long) (dregs[addr - DSP_BASE]);
  628. break;
  629. }
  630. case DSP_CONTROL:
  631. if (!cpu_has_dsp) {
  632. tmp = 0;
  633. ret = -EIO;
  634. goto out;
  635. }
  636. tmp = child->thread.dsp.dspcontrol;
  637. break;
  638. default:
  639. tmp = 0;
  640. ret = -EIO;
  641. goto out;
  642. }
  643. ret = put_user(tmp, datalp);
  644. break;
  645. }
  646. /* when I and D space are separate, this will have to be fixed. */
  647. case PTRACE_POKETEXT: /* write the word at location addr. */
  648. case PTRACE_POKEDATA:
  649. ret = generic_ptrace_pokedata(child, addr, data);
  650. break;
  651. case PTRACE_POKEUSR: {
  652. struct pt_regs *regs;
  653. ret = 0;
  654. regs = task_pt_regs(child);
  655. switch (addr) {
  656. case 0 ... 31:
  657. regs->regs[addr] = data;
  658. break;
  659. case FPR_BASE ... FPR_BASE + 31: {
  660. union fpureg *fregs = get_fpu_regs(child);
  661. init_fp_ctx(child);
  662. #ifdef CONFIG_32BIT
  663. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  664. /*
  665. * The odd registers are actually the high
  666. * order bits of the values stored in the even
  667. * registers - unless we're using r2k_switch.S.
  668. */
  669. set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  670. addr & 1, data);
  671. break;
  672. }
  673. #endif
  674. set_fpr64(&fregs[addr - FPR_BASE], 0, data);
  675. break;
  676. }
  677. case PC:
  678. regs->cp0_epc = data;
  679. break;
  680. case MMHI:
  681. regs->hi = data;
  682. break;
  683. case MMLO:
  684. regs->lo = data;
  685. break;
  686. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  687. case ACX:
  688. regs->acx = data;
  689. break;
  690. #endif
  691. case FPC_CSR:
  692. init_fp_ctx(child);
  693. ptrace_setfcr31(child, data);
  694. break;
  695. case DSP_BASE ... DSP_BASE + 5: {
  696. dspreg_t *dregs;
  697. if (!cpu_has_dsp) {
  698. ret = -EIO;
  699. break;
  700. }
  701. dregs = __get_dsp_regs(child);
  702. dregs[addr - DSP_BASE] = data;
  703. break;
  704. }
  705. case DSP_CONTROL:
  706. if (!cpu_has_dsp) {
  707. ret = -EIO;
  708. break;
  709. }
  710. child->thread.dsp.dspcontrol = data;
  711. break;
  712. default:
  713. /* The rest are not allowed. */
  714. ret = -EIO;
  715. break;
  716. }
  717. break;
  718. }
  719. case PTRACE_GETREGS:
  720. ret = ptrace_getregs(child, datavp);
  721. break;
  722. case PTRACE_SETREGS:
  723. ret = ptrace_setregs(child, datavp);
  724. break;
  725. case PTRACE_GETFPREGS:
  726. ret = ptrace_getfpregs(child, datavp);
  727. break;
  728. case PTRACE_SETFPREGS:
  729. ret = ptrace_setfpregs(child, datavp);
  730. break;
  731. case PTRACE_GET_THREAD_AREA:
  732. ret = put_user(task_thread_info(child)->tp_value, datalp);
  733. break;
  734. case PTRACE_GET_WATCH_REGS:
  735. ret = ptrace_get_watch_regs(child, addrp);
  736. break;
  737. case PTRACE_SET_WATCH_REGS:
  738. ret = ptrace_set_watch_regs(child, addrp);
  739. break;
  740. default:
  741. ret = ptrace_request(child, request, addr, data);
  742. break;
  743. }
  744. out:
  745. return ret;
  746. }
  747. /*
  748. * Notification of system call entry/exit
  749. * - triggered by current->work.syscall_trace
  750. */
  751. asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
  752. {
  753. user_exit();
  754. current_thread_info()->syscall = syscall;
  755. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  756. tracehook_report_syscall_entry(regs))
  757. return -1;
  758. if (secure_computing(NULL) == -1)
  759. return -1;
  760. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  761. trace_sys_enter(regs, regs->regs[2]);
  762. audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
  763. regs->regs[6], regs->regs[7]);
  764. return syscall;
  765. }
  766. /*
  767. * Notification of system call entry/exit
  768. * - triggered by current->work.syscall_trace
  769. */
  770. asmlinkage void syscall_trace_leave(struct pt_regs *regs)
  771. {
  772. /*
  773. * We may come here right after calling schedule_user()
  774. * or do_notify_resume(), in which case we can be in RCU
  775. * user mode.
  776. */
  777. user_exit();
  778. audit_syscall_exit(regs);
  779. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  780. trace_sys_exit(regs, regs->regs[2]);
  781. if (test_thread_flag(TIF_SYSCALL_TRACE))
  782. tracehook_report_syscall_exit(regs, 0);
  783. user_enter();
  784. }