ptrace.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  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/mm.h>
  23. #include <linux/errno.h>
  24. #include <linux/ptrace.h>
  25. #include <linux/regset.h>
  26. #include <linux/smp.h>
  27. #include <linux/security.h>
  28. #include <linux/stddef.h>
  29. #include <linux/tracehook.h>
  30. #include <linux/audit.h>
  31. #include <linux/seccomp.h>
  32. #include <linux/ftrace.h>
  33. #include <asm/byteorder.h>
  34. #include <asm/cpu.h>
  35. #include <asm/cpu-info.h>
  36. #include <asm/dsp.h>
  37. #include <asm/fpu.h>
  38. #include <asm/mipsregs.h>
  39. #include <asm/mipsmtregs.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/page.h>
  42. #include <asm/syscall.h>
  43. #include <asm/uaccess.h>
  44. #include <asm/bootinfo.h>
  45. #include <asm/reg.h>
  46. #define CREATE_TRACE_POINTS
  47. #include <trace/events/syscalls.h>
  48. static void init_fp_ctx(struct task_struct *target)
  49. {
  50. /* If FP has been used then the target already has context */
  51. if (tsk_used_math(target))
  52. return;
  53. /* Begin with data registers set to all 1s... */
  54. memset(&target->thread.fpu.fpr, ~0, sizeof(target->thread.fpu.fpr));
  55. /* FCSR has been preset by `mips_set_personality_nan'. */
  56. /*
  57. * Record that the target has "used" math, such that the context
  58. * just initialised, and any modifications made by the caller,
  59. * aren't discarded.
  60. */
  61. set_stopped_child_used_math(target);
  62. }
  63. /*
  64. * Called by kernel/ptrace.c when detaching..
  65. *
  66. * Make sure single step bits etc are not set.
  67. */
  68. void ptrace_disable(struct task_struct *child)
  69. {
  70. /* Don't load the watchpoint registers for the ex-child. */
  71. clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
  72. }
  73. /*
  74. * Poke at FCSR according to its mask. Don't set the cause bits as
  75. * this is currently not handled correctly in FP context restoration
  76. * and will cause an oops if a corresponding enable bit is set.
  77. */
  78. static void ptrace_setfcr31(struct task_struct *child, u32 value)
  79. {
  80. u32 fcr31;
  81. u32 mask;
  82. value &= ~FPU_CSR_ALL_X;
  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. unsigned i;
  255. for (i = MIPS32_EF_R1; i <= MIPS32_EF_R31; i++) {
  256. /* k0/k1 are copied as zero. */
  257. if (i == MIPS32_EF_R26 || i == MIPS32_EF_R27)
  258. continue;
  259. uregs[i] = regs->regs[i - MIPS32_EF_R0];
  260. }
  261. uregs[MIPS32_EF_LO] = regs->lo;
  262. uregs[MIPS32_EF_HI] = regs->hi;
  263. uregs[MIPS32_EF_CP0_EPC] = regs->cp0_epc;
  264. uregs[MIPS32_EF_CP0_BADVADDR] = regs->cp0_badvaddr;
  265. uregs[MIPS32_EF_CP0_STATUS] = regs->cp0_status;
  266. uregs[MIPS32_EF_CP0_CAUSE] = regs->cp0_cause;
  267. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
  268. sizeof(uregs));
  269. }
  270. static int gpr32_set(struct task_struct *target,
  271. const struct user_regset *regset,
  272. unsigned int pos, unsigned int count,
  273. const void *kbuf, const void __user *ubuf)
  274. {
  275. struct pt_regs *regs = task_pt_regs(target);
  276. u32 uregs[ELF_NGREG];
  277. unsigned start, num_regs, i;
  278. int err;
  279. start = pos / sizeof(u32);
  280. num_regs = count / sizeof(u32);
  281. if (start + num_regs > ELF_NGREG)
  282. return -EIO;
  283. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
  284. sizeof(uregs));
  285. if (err)
  286. return err;
  287. for (i = start; i < num_regs; i++) {
  288. /*
  289. * Cast all values to signed here so that if this is a 64-bit
  290. * kernel, the supplied 32-bit values will be sign extended.
  291. */
  292. switch (i) {
  293. case MIPS32_EF_R1 ... MIPS32_EF_R25:
  294. /* k0/k1 are ignored. */
  295. case MIPS32_EF_R28 ... MIPS32_EF_R31:
  296. regs->regs[i - MIPS32_EF_R0] = (s32)uregs[i];
  297. break;
  298. case MIPS32_EF_LO:
  299. regs->lo = (s32)uregs[i];
  300. break;
  301. case MIPS32_EF_HI:
  302. regs->hi = (s32)uregs[i];
  303. break;
  304. case MIPS32_EF_CP0_EPC:
  305. regs->cp0_epc = (s32)uregs[i];
  306. break;
  307. }
  308. }
  309. return 0;
  310. }
  311. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  312. #ifdef CONFIG_64BIT
  313. static int gpr64_get(struct task_struct *target,
  314. const struct user_regset *regset,
  315. unsigned int pos, unsigned int count,
  316. void *kbuf, void __user *ubuf)
  317. {
  318. struct pt_regs *regs = task_pt_regs(target);
  319. u64 uregs[ELF_NGREG] = {};
  320. unsigned i;
  321. for (i = MIPS64_EF_R1; i <= MIPS64_EF_R31; i++) {
  322. /* k0/k1 are copied as zero. */
  323. if (i == MIPS64_EF_R26 || i == MIPS64_EF_R27)
  324. continue;
  325. uregs[i] = regs->regs[i - MIPS64_EF_R0];
  326. }
  327. uregs[MIPS64_EF_LO] = regs->lo;
  328. uregs[MIPS64_EF_HI] = regs->hi;
  329. uregs[MIPS64_EF_CP0_EPC] = regs->cp0_epc;
  330. uregs[MIPS64_EF_CP0_BADVADDR] = regs->cp0_badvaddr;
  331. uregs[MIPS64_EF_CP0_STATUS] = regs->cp0_status;
  332. uregs[MIPS64_EF_CP0_CAUSE] = regs->cp0_cause;
  333. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
  334. sizeof(uregs));
  335. }
  336. static int gpr64_set(struct task_struct *target,
  337. const struct user_regset *regset,
  338. unsigned int pos, unsigned int count,
  339. const void *kbuf, const void __user *ubuf)
  340. {
  341. struct pt_regs *regs = task_pt_regs(target);
  342. u64 uregs[ELF_NGREG];
  343. unsigned start, num_regs, i;
  344. int err;
  345. start = pos / sizeof(u64);
  346. num_regs = count / sizeof(u64);
  347. if (start + num_regs > ELF_NGREG)
  348. return -EIO;
  349. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
  350. sizeof(uregs));
  351. if (err)
  352. return err;
  353. for (i = start; i < num_regs; i++) {
  354. switch (i) {
  355. case MIPS64_EF_R1 ... MIPS64_EF_R25:
  356. /* k0/k1 are ignored. */
  357. case MIPS64_EF_R28 ... MIPS64_EF_R31:
  358. regs->regs[i - MIPS64_EF_R0] = uregs[i];
  359. break;
  360. case MIPS64_EF_LO:
  361. regs->lo = uregs[i];
  362. break;
  363. case MIPS64_EF_HI:
  364. regs->hi = uregs[i];
  365. break;
  366. case MIPS64_EF_CP0_EPC:
  367. regs->cp0_epc = uregs[i];
  368. break;
  369. }
  370. }
  371. return 0;
  372. }
  373. #endif /* CONFIG_64BIT */
  374. static int fpr_get(struct task_struct *target,
  375. const struct user_regset *regset,
  376. unsigned int pos, unsigned int count,
  377. void *kbuf, void __user *ubuf)
  378. {
  379. unsigned i;
  380. int err;
  381. u64 fpr_val;
  382. /* XXX fcr31 */
  383. if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
  384. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  385. &target->thread.fpu,
  386. 0, sizeof(elf_fpregset_t));
  387. for (i = 0; i < NUM_FPU_REGS; i++) {
  388. fpr_val = get_fpr64(&target->thread.fpu.fpr[i], 0);
  389. err = user_regset_copyout(&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. }
  395. return 0;
  396. }
  397. static int fpr_set(struct task_struct *target,
  398. const struct user_regset *regset,
  399. unsigned int pos, unsigned int count,
  400. const void *kbuf, const void __user *ubuf)
  401. {
  402. unsigned i;
  403. int err;
  404. u64 fpr_val;
  405. /* XXX fcr31 */
  406. init_fp_ctx(target);
  407. if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
  408. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  409. &target->thread.fpu,
  410. 0, sizeof(elf_fpregset_t));
  411. for (i = 0; i < NUM_FPU_REGS; i++) {
  412. err = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  413. &fpr_val, i * sizeof(elf_fpreg_t),
  414. (i + 1) * sizeof(elf_fpreg_t));
  415. if (err)
  416. return err;
  417. set_fpr64(&target->thread.fpu.fpr[i], 0, fpr_val);
  418. }
  419. return 0;
  420. }
  421. enum mips_regset {
  422. REGSET_GPR,
  423. REGSET_FPR,
  424. };
  425. struct pt_regs_offset {
  426. const char *name;
  427. int offset;
  428. };
  429. #define REG_OFFSET_NAME(reg, r) { \
  430. .name = #reg, \
  431. .offset = offsetof(struct pt_regs, r) \
  432. }
  433. #define REG_OFFSET_END { \
  434. .name = NULL, \
  435. .offset = 0 \
  436. }
  437. static const struct pt_regs_offset regoffset_table[] = {
  438. REG_OFFSET_NAME(r0, regs[0]),
  439. REG_OFFSET_NAME(r1, regs[1]),
  440. REG_OFFSET_NAME(r2, regs[2]),
  441. REG_OFFSET_NAME(r3, regs[3]),
  442. REG_OFFSET_NAME(r4, regs[4]),
  443. REG_OFFSET_NAME(r5, regs[5]),
  444. REG_OFFSET_NAME(r6, regs[6]),
  445. REG_OFFSET_NAME(r7, regs[7]),
  446. REG_OFFSET_NAME(r8, regs[8]),
  447. REG_OFFSET_NAME(r9, regs[9]),
  448. REG_OFFSET_NAME(r10, regs[10]),
  449. REG_OFFSET_NAME(r11, regs[11]),
  450. REG_OFFSET_NAME(r12, regs[12]),
  451. REG_OFFSET_NAME(r13, regs[13]),
  452. REG_OFFSET_NAME(r14, regs[14]),
  453. REG_OFFSET_NAME(r15, regs[15]),
  454. REG_OFFSET_NAME(r16, regs[16]),
  455. REG_OFFSET_NAME(r17, regs[17]),
  456. REG_OFFSET_NAME(r18, regs[18]),
  457. REG_OFFSET_NAME(r19, regs[19]),
  458. REG_OFFSET_NAME(r20, regs[20]),
  459. REG_OFFSET_NAME(r21, regs[21]),
  460. REG_OFFSET_NAME(r22, regs[22]),
  461. REG_OFFSET_NAME(r23, regs[23]),
  462. REG_OFFSET_NAME(r24, regs[24]),
  463. REG_OFFSET_NAME(r25, regs[25]),
  464. REG_OFFSET_NAME(r26, regs[26]),
  465. REG_OFFSET_NAME(r27, regs[27]),
  466. REG_OFFSET_NAME(r28, regs[28]),
  467. REG_OFFSET_NAME(r29, regs[29]),
  468. REG_OFFSET_NAME(r30, regs[30]),
  469. REG_OFFSET_NAME(r31, regs[31]),
  470. REG_OFFSET_NAME(c0_status, cp0_status),
  471. REG_OFFSET_NAME(hi, hi),
  472. REG_OFFSET_NAME(lo, lo),
  473. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  474. REG_OFFSET_NAME(acx, acx),
  475. #endif
  476. REG_OFFSET_NAME(c0_badvaddr, cp0_badvaddr),
  477. REG_OFFSET_NAME(c0_cause, cp0_cause),
  478. REG_OFFSET_NAME(c0_epc, cp0_epc),
  479. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  480. REG_OFFSET_NAME(mpl0, mpl[0]),
  481. REG_OFFSET_NAME(mpl1, mpl[1]),
  482. REG_OFFSET_NAME(mpl2, mpl[2]),
  483. REG_OFFSET_NAME(mtp0, mtp[0]),
  484. REG_OFFSET_NAME(mtp1, mtp[1]),
  485. REG_OFFSET_NAME(mtp2, mtp[2]),
  486. #endif
  487. REG_OFFSET_END,
  488. };
  489. /**
  490. * regs_query_register_offset() - query register offset from its name
  491. * @name: the name of a register
  492. *
  493. * regs_query_register_offset() returns the offset of a register in struct
  494. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  495. */
  496. int regs_query_register_offset(const char *name)
  497. {
  498. const struct pt_regs_offset *roff;
  499. for (roff = regoffset_table; roff->name != NULL; roff++)
  500. if (!strcmp(roff->name, name))
  501. return roff->offset;
  502. return -EINVAL;
  503. }
  504. #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
  505. static const struct user_regset mips_regsets[] = {
  506. [REGSET_GPR] = {
  507. .core_note_type = NT_PRSTATUS,
  508. .n = ELF_NGREG,
  509. .size = sizeof(unsigned int),
  510. .align = sizeof(unsigned int),
  511. .get = gpr32_get,
  512. .set = gpr32_set,
  513. },
  514. [REGSET_FPR] = {
  515. .core_note_type = NT_PRFPREG,
  516. .n = ELF_NFPREG,
  517. .size = sizeof(elf_fpreg_t),
  518. .align = sizeof(elf_fpreg_t),
  519. .get = fpr_get,
  520. .set = fpr_set,
  521. },
  522. };
  523. static const struct user_regset_view user_mips_view = {
  524. .name = "mips",
  525. .e_machine = ELF_ARCH,
  526. .ei_osabi = ELF_OSABI,
  527. .regsets = mips_regsets,
  528. .n = ARRAY_SIZE(mips_regsets),
  529. };
  530. #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
  531. #ifdef CONFIG_64BIT
  532. static const struct user_regset mips64_regsets[] = {
  533. [REGSET_GPR] = {
  534. .core_note_type = NT_PRSTATUS,
  535. .n = ELF_NGREG,
  536. .size = sizeof(unsigned long),
  537. .align = sizeof(unsigned long),
  538. .get = gpr64_get,
  539. .set = gpr64_set,
  540. },
  541. [REGSET_FPR] = {
  542. .core_note_type = NT_PRFPREG,
  543. .n = ELF_NFPREG,
  544. .size = sizeof(elf_fpreg_t),
  545. .align = sizeof(elf_fpreg_t),
  546. .get = fpr_get,
  547. .set = fpr_set,
  548. },
  549. };
  550. static const struct user_regset_view user_mips64_view = {
  551. .name = "mips64",
  552. .e_machine = ELF_ARCH,
  553. .ei_osabi = ELF_OSABI,
  554. .regsets = mips64_regsets,
  555. .n = ARRAY_SIZE(mips64_regsets),
  556. };
  557. #endif /* CONFIG_64BIT */
  558. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  559. {
  560. #ifdef CONFIG_32BIT
  561. return &user_mips_view;
  562. #else
  563. #ifdef CONFIG_MIPS32_O32
  564. if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
  565. return &user_mips_view;
  566. #endif
  567. return &user_mips64_view;
  568. #endif
  569. }
  570. long arch_ptrace(struct task_struct *child, long request,
  571. unsigned long addr, unsigned long data)
  572. {
  573. int ret;
  574. void __user *addrp = (void __user *) addr;
  575. void __user *datavp = (void __user *) data;
  576. unsigned long __user *datalp = (void __user *) data;
  577. switch (request) {
  578. /* when I and D space are separate, these will need to be fixed. */
  579. case PTRACE_PEEKTEXT: /* read word at location addr. */
  580. case PTRACE_PEEKDATA:
  581. ret = generic_ptrace_peekdata(child, addr, data);
  582. break;
  583. /* Read the word at location addr in the USER area. */
  584. case PTRACE_PEEKUSR: {
  585. struct pt_regs *regs;
  586. union fpureg *fregs;
  587. unsigned long tmp = 0;
  588. regs = task_pt_regs(child);
  589. ret = 0; /* Default return value. */
  590. switch (addr) {
  591. case 0 ... 31:
  592. tmp = regs->regs[addr];
  593. break;
  594. case FPR_BASE ... FPR_BASE + 31:
  595. if (!tsk_used_math(child)) {
  596. /* FP not yet used */
  597. tmp = -1;
  598. break;
  599. }
  600. fregs = get_fpu_regs(child);
  601. #ifdef CONFIG_32BIT
  602. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  603. /*
  604. * The odd registers are actually the high
  605. * order bits of the values stored in the even
  606. * registers - unless we're using r2k_switch.S.
  607. */
  608. tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  609. addr & 1);
  610. break;
  611. }
  612. #endif
  613. tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);
  614. break;
  615. case PC:
  616. tmp = regs->cp0_epc;
  617. break;
  618. case CAUSE:
  619. tmp = regs->cp0_cause;
  620. break;
  621. case BADVADDR:
  622. tmp = regs->cp0_badvaddr;
  623. break;
  624. case MMHI:
  625. tmp = regs->hi;
  626. break;
  627. case MMLO:
  628. tmp = regs->lo;
  629. break;
  630. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  631. case ACX:
  632. tmp = regs->acx;
  633. break;
  634. #endif
  635. case FPC_CSR:
  636. tmp = child->thread.fpu.fcr31;
  637. break;
  638. case FPC_EIR:
  639. /* implementation / version register */
  640. tmp = boot_cpu_data.fpu_id;
  641. break;
  642. case DSP_BASE ... DSP_BASE + 5: {
  643. dspreg_t *dregs;
  644. if (!cpu_has_dsp) {
  645. tmp = 0;
  646. ret = -EIO;
  647. goto out;
  648. }
  649. dregs = __get_dsp_regs(child);
  650. tmp = (unsigned long) (dregs[addr - DSP_BASE]);
  651. break;
  652. }
  653. case DSP_CONTROL:
  654. if (!cpu_has_dsp) {
  655. tmp = 0;
  656. ret = -EIO;
  657. goto out;
  658. }
  659. tmp = child->thread.dsp.dspcontrol;
  660. break;
  661. default:
  662. tmp = 0;
  663. ret = -EIO;
  664. goto out;
  665. }
  666. ret = put_user(tmp, datalp);
  667. break;
  668. }
  669. /* when I and D space are separate, this will have to be fixed. */
  670. case PTRACE_POKETEXT: /* write the word at location addr. */
  671. case PTRACE_POKEDATA:
  672. ret = generic_ptrace_pokedata(child, addr, data);
  673. break;
  674. case PTRACE_POKEUSR: {
  675. struct pt_regs *regs;
  676. ret = 0;
  677. regs = task_pt_regs(child);
  678. switch (addr) {
  679. case 0 ... 31:
  680. regs->regs[addr] = data;
  681. break;
  682. case FPR_BASE ... FPR_BASE + 31: {
  683. union fpureg *fregs = get_fpu_regs(child);
  684. init_fp_ctx(child);
  685. #ifdef CONFIG_32BIT
  686. if (test_thread_flag(TIF_32BIT_FPREGS)) {
  687. /*
  688. * The odd registers are actually the high
  689. * order bits of the values stored in the even
  690. * registers - unless we're using r2k_switch.S.
  691. */
  692. set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
  693. addr & 1, data);
  694. break;
  695. }
  696. #endif
  697. set_fpr64(&fregs[addr - FPR_BASE], 0, data);
  698. break;
  699. }
  700. case PC:
  701. regs->cp0_epc = data;
  702. break;
  703. case MMHI:
  704. regs->hi = data;
  705. break;
  706. case MMLO:
  707. regs->lo = data;
  708. break;
  709. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  710. case ACX:
  711. regs->acx = data;
  712. break;
  713. #endif
  714. case FPC_CSR:
  715. ptrace_setfcr31(child, data);
  716. break;
  717. case DSP_BASE ... DSP_BASE + 5: {
  718. dspreg_t *dregs;
  719. if (!cpu_has_dsp) {
  720. ret = -EIO;
  721. break;
  722. }
  723. dregs = __get_dsp_regs(child);
  724. dregs[addr - DSP_BASE] = data;
  725. break;
  726. }
  727. case DSP_CONTROL:
  728. if (!cpu_has_dsp) {
  729. ret = -EIO;
  730. break;
  731. }
  732. child->thread.dsp.dspcontrol = data;
  733. break;
  734. default:
  735. /* The rest are not allowed. */
  736. ret = -EIO;
  737. break;
  738. }
  739. break;
  740. }
  741. case PTRACE_GETREGS:
  742. ret = ptrace_getregs(child, datavp);
  743. break;
  744. case PTRACE_SETREGS:
  745. ret = ptrace_setregs(child, datavp);
  746. break;
  747. case PTRACE_GETFPREGS:
  748. ret = ptrace_getfpregs(child, datavp);
  749. break;
  750. case PTRACE_SETFPREGS:
  751. ret = ptrace_setfpregs(child, datavp);
  752. break;
  753. case PTRACE_GET_THREAD_AREA:
  754. ret = put_user(task_thread_info(child)->tp_value, datalp);
  755. break;
  756. case PTRACE_GET_WATCH_REGS:
  757. ret = ptrace_get_watch_regs(child, addrp);
  758. break;
  759. case PTRACE_SET_WATCH_REGS:
  760. ret = ptrace_set_watch_regs(child, addrp);
  761. break;
  762. default:
  763. ret = ptrace_request(child, request, addr, data);
  764. break;
  765. }
  766. out:
  767. return ret;
  768. }
  769. /*
  770. * Notification of system call entry/exit
  771. * - triggered by current->work.syscall_trace
  772. */
  773. asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
  774. {
  775. user_exit();
  776. current_thread_info()->syscall = syscall;
  777. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  778. tracehook_report_syscall_entry(regs))
  779. return -1;
  780. if (secure_computing(NULL) == -1)
  781. return -1;
  782. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  783. trace_sys_enter(regs, regs->regs[2]);
  784. audit_syscall_entry(syscall, regs->regs[4], regs->regs[5],
  785. regs->regs[6], regs->regs[7]);
  786. return syscall;
  787. }
  788. /*
  789. * Notification of system call entry/exit
  790. * - triggered by current->work.syscall_trace
  791. */
  792. asmlinkage void syscall_trace_leave(struct pt_regs *regs)
  793. {
  794. /*
  795. * We may come here right after calling schedule_user()
  796. * or do_notify_resume(), in which case we can be in RCU
  797. * user mode.
  798. */
  799. user_exit();
  800. audit_syscall_exit(regs);
  801. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  802. trace_sys_exit(regs, regs->regs[2]);
  803. if (test_thread_flag(TIF_SYSCALL_TRACE))
  804. tracehook_report_syscall_exit(regs, 0);
  805. user_enter();
  806. }