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