ptrace.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /* ptrace.c: Sparc process tracing support.
  2. *
  3. * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. *
  6. * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
  7. * and David Mosberger.
  8. *
  9. * Added Linux support -miguel (weird, eh?, the original code was meant
  10. * to emulate SunOS).
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/errno.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/user.h>
  18. #include <linux/smp.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/security.h>
  21. #include <linux/seccomp.h>
  22. #include <linux/audit.h>
  23. #include <linux/signal.h>
  24. #include <linux/regset.h>
  25. #include <linux/compat.h>
  26. #include <linux/elf.h>
  27. #include <asm/asi.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/system.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/psrcompat.h>
  32. #include <asm/visasm.h>
  33. #include <asm/spitfire.h>
  34. #include <asm/page.h>
  35. #include <asm/cpudata.h>
  36. #include <asm/cacheflush.h>
  37. #include "entry.h"
  38. /* #define ALLOW_INIT_TRACING */
  39. /*
  40. * Called by kernel/ptrace.c when detaching..
  41. *
  42. * Make sure single step bits etc are not set.
  43. */
  44. void ptrace_disable(struct task_struct *child)
  45. {
  46. /* nothing to do */
  47. }
  48. /* To get the necessary page struct, access_process_vm() first calls
  49. * get_user_pages(). This has done a flush_dcache_page() on the
  50. * accessed page. Then our caller (copy_{to,from}_user_page()) did
  51. * to memcpy to read/write the data from that page.
  52. *
  53. * Now, the only thing we have to do is:
  54. * 1) flush the D-cache if it's possible than an illegal alias
  55. * has been created
  56. * 2) flush the I-cache if this is pre-cheetah and we did a write
  57. */
  58. void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  59. unsigned long uaddr, void *kaddr,
  60. unsigned long len, int write)
  61. {
  62. BUG_ON(len > PAGE_SIZE);
  63. if (tlb_type == hypervisor)
  64. return;
  65. #ifdef DCACHE_ALIASING_POSSIBLE
  66. /* If bit 13 of the kernel address we used to access the
  67. * user page is the same as the virtual address that page
  68. * is mapped to in the user's address space, we can skip the
  69. * D-cache flush.
  70. */
  71. if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
  72. unsigned long start = __pa(kaddr);
  73. unsigned long end = start + len;
  74. unsigned long dcache_line_size;
  75. dcache_line_size = local_cpu_data().dcache_line_size;
  76. if (tlb_type == spitfire) {
  77. for (; start < end; start += dcache_line_size)
  78. spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
  79. } else {
  80. start &= ~(dcache_line_size - 1);
  81. for (; start < end; start += dcache_line_size)
  82. __asm__ __volatile__(
  83. "stxa %%g0, [%0] %1\n\t"
  84. "membar #Sync"
  85. : /* no outputs */
  86. : "r" (start),
  87. "i" (ASI_DCACHE_INVALIDATE));
  88. }
  89. }
  90. #endif
  91. if (write && tlb_type == spitfire) {
  92. unsigned long start = (unsigned long) kaddr;
  93. unsigned long end = start + len;
  94. unsigned long icache_line_size;
  95. icache_line_size = local_cpu_data().icache_line_size;
  96. for (; start < end; start += icache_line_size)
  97. flushi(start);
  98. }
  99. }
  100. enum sparc_regset {
  101. REGSET_GENERAL,
  102. REGSET_FP,
  103. };
  104. static int genregs64_get(struct task_struct *target,
  105. const struct user_regset *regset,
  106. unsigned int pos, unsigned int count,
  107. void *kbuf, void __user *ubuf)
  108. {
  109. const struct pt_regs *regs = task_pt_regs(target);
  110. int ret;
  111. if (target == current)
  112. flushw_user();
  113. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  114. regs->u_regs,
  115. 0, 16 * sizeof(u64));
  116. if (!ret) {
  117. unsigned long __user *reg_window = (unsigned long __user *)
  118. (regs->u_regs[UREG_I6] + STACK_BIAS);
  119. unsigned long window[16];
  120. if (copy_from_user(window, reg_window, sizeof(window)))
  121. return -EFAULT;
  122. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  123. window,
  124. 16 * sizeof(u64),
  125. 32 * sizeof(u64));
  126. }
  127. if (!ret) {
  128. /* TSTATE, TPC, TNPC */
  129. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  130. &regs->tstate,
  131. 32 * sizeof(u64),
  132. 35 * sizeof(u64));
  133. }
  134. if (!ret) {
  135. unsigned long y = regs->y;
  136. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  137. &y,
  138. 35 * sizeof(u64),
  139. 36 * sizeof(u64));
  140. }
  141. if (!ret)
  142. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  143. 36 * sizeof(u64), -1);
  144. return ret;
  145. }
  146. static int genregs64_set(struct task_struct *target,
  147. const struct user_regset *regset,
  148. unsigned int pos, unsigned int count,
  149. const void *kbuf, const void __user *ubuf)
  150. {
  151. struct pt_regs *regs = task_pt_regs(target);
  152. int ret;
  153. if (target == current)
  154. flushw_user();
  155. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  156. regs->u_regs,
  157. 0, 16 * sizeof(u64));
  158. if (!ret && count > 0) {
  159. unsigned long __user *reg_window = (unsigned long __user *)
  160. (regs->u_regs[UREG_I6] + STACK_BIAS);
  161. unsigned long window[16];
  162. if (copy_from_user(window, reg_window, sizeof(window)))
  163. return -EFAULT;
  164. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  165. window,
  166. 16 * sizeof(u64),
  167. 32 * sizeof(u64));
  168. if (!ret &&
  169. copy_to_user(reg_window, window, sizeof(window)))
  170. return -EFAULT;
  171. }
  172. if (!ret && count > 0) {
  173. unsigned long tstate;
  174. /* TSTATE */
  175. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  176. &tstate,
  177. 32 * sizeof(u64),
  178. 33 * sizeof(u64));
  179. if (!ret) {
  180. /* Only the condition codes can be modified
  181. * in the %tstate register.
  182. */
  183. tstate &= (TSTATE_ICC | TSTATE_XCC);
  184. regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
  185. regs->tstate |= tstate;
  186. }
  187. }
  188. if (!ret) {
  189. /* TPC, TNPC */
  190. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  191. &regs->tpc,
  192. 33 * sizeof(u64),
  193. 35 * sizeof(u64));
  194. }
  195. if (!ret) {
  196. unsigned long y;
  197. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  198. &y,
  199. 35 * sizeof(u64),
  200. 36 * sizeof(u64));
  201. if (!ret)
  202. regs->y = y;
  203. }
  204. if (!ret)
  205. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  206. 36 * sizeof(u64), -1);
  207. return ret;
  208. }
  209. static int fpregs64_get(struct task_struct *target,
  210. const struct user_regset *regset,
  211. unsigned int pos, unsigned int count,
  212. void *kbuf, void __user *ubuf)
  213. {
  214. const unsigned long *fpregs = task_thread_info(target)->fpregs;
  215. unsigned long fprs, fsr, gsr;
  216. int ret;
  217. if (target == current)
  218. save_and_clear_fpu();
  219. fprs = task_thread_info(target)->fpsaved[0];
  220. if (fprs & FPRS_DL)
  221. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  222. fpregs,
  223. 0, 16 * sizeof(u64));
  224. else
  225. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  226. 0,
  227. 16 * sizeof(u64));
  228. if (!ret) {
  229. if (fprs & FPRS_DU)
  230. ret = user_regset_copyout(&pos, &count,
  231. &kbuf, &ubuf,
  232. fpregs + 16,
  233. 16 * sizeof(u64),
  234. 32 * sizeof(u64));
  235. else
  236. ret = user_regset_copyout_zero(&pos, &count,
  237. &kbuf, &ubuf,
  238. 16 * sizeof(u64),
  239. 32 * sizeof(u64));
  240. }
  241. if (fprs & FPRS_FEF) {
  242. fsr = task_thread_info(target)->xfsr[0];
  243. gsr = task_thread_info(target)->gsr[0];
  244. } else {
  245. fsr = gsr = 0;
  246. }
  247. if (!ret)
  248. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  249. &fsr,
  250. 32 * sizeof(u64),
  251. 33 * sizeof(u64));
  252. if (!ret)
  253. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  254. &gsr,
  255. 33 * sizeof(u64),
  256. 34 * sizeof(u64));
  257. if (!ret)
  258. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  259. &fprs,
  260. 34 * sizeof(u64),
  261. 35 * sizeof(u64));
  262. if (!ret)
  263. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  264. 35 * sizeof(u64), -1);
  265. return ret;
  266. }
  267. static int fpregs64_set(struct task_struct *target,
  268. const struct user_regset *regset,
  269. unsigned int pos, unsigned int count,
  270. const void *kbuf, const void __user *ubuf)
  271. {
  272. unsigned long *fpregs = task_thread_info(target)->fpregs;
  273. unsigned long fprs;
  274. int ret;
  275. if (target == current)
  276. save_and_clear_fpu();
  277. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  278. fpregs,
  279. 0, 32 * sizeof(u64));
  280. if (!ret)
  281. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  282. task_thread_info(target)->xfsr,
  283. 32 * sizeof(u64),
  284. 33 * sizeof(u64));
  285. if (!ret)
  286. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  287. task_thread_info(target)->gsr,
  288. 33 * sizeof(u64),
  289. 34 * sizeof(u64));
  290. fprs = task_thread_info(target)->fpsaved[0];
  291. if (!ret && count > 0) {
  292. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  293. &fprs,
  294. 34 * sizeof(u64),
  295. 35 * sizeof(u64));
  296. }
  297. fprs |= (FPRS_FEF | FPRS_DL | FPRS_DU);
  298. task_thread_info(target)->fpsaved[0] = fprs;
  299. if (!ret)
  300. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  301. 35 * sizeof(u64), -1);
  302. return ret;
  303. }
  304. static const struct user_regset sparc64_regsets[] = {
  305. /* Format is:
  306. * G0 --> G7
  307. * O0 --> O7
  308. * L0 --> L7
  309. * I0 --> I7
  310. * TSTATE, TPC, TNPC, Y
  311. */
  312. [REGSET_GENERAL] = {
  313. .core_note_type = NT_PRSTATUS,
  314. .n = 36 * sizeof(u64),
  315. .size = sizeof(u64), .align = sizeof(u64),
  316. .get = genregs64_get, .set = genregs64_set
  317. },
  318. /* Format is:
  319. * F0 --> F63
  320. * FSR
  321. * GSR
  322. * FPRS
  323. */
  324. [REGSET_FP] = {
  325. .core_note_type = NT_PRFPREG,
  326. .n = 35 * sizeof(u64),
  327. .size = sizeof(u64), .align = sizeof(u64),
  328. .get = fpregs64_get, .set = fpregs64_set
  329. },
  330. };
  331. static const struct user_regset_view user_sparc64_view = {
  332. .name = "sparc64", .e_machine = EM_SPARCV9,
  333. .regsets = sparc64_regsets, .n = ARRAY_SIZE(sparc64_regsets)
  334. };
  335. static int genregs32_get(struct task_struct *target,
  336. const struct user_regset *regset,
  337. unsigned int pos, unsigned int count,
  338. void *kbuf, void __user *ubuf)
  339. {
  340. const struct pt_regs *regs = task_pt_regs(target);
  341. compat_ulong_t __user *reg_window;
  342. compat_ulong_t *k = kbuf;
  343. compat_ulong_t __user *u = ubuf;
  344. compat_ulong_t reg;
  345. if (target == current)
  346. flushw_user();
  347. pos /= sizeof(reg);
  348. count /= sizeof(reg);
  349. if (kbuf) {
  350. for (; count > 0 && pos < 16; count--)
  351. *k++ = regs->u_regs[pos++];
  352. reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
  353. for (; count > 0 && pos < 32; count--) {
  354. if (get_user(*k++, &reg_window[pos++]))
  355. return -EFAULT;
  356. }
  357. } else {
  358. for (; count > 0 && pos < 16; count--) {
  359. if (put_user((compat_ulong_t) regs->u_regs[pos++], u++))
  360. return -EFAULT;
  361. }
  362. reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
  363. for (; count > 0 && pos < 32; count--) {
  364. if (get_user(reg, &reg_window[pos++]) ||
  365. put_user(reg, u++))
  366. return -EFAULT;
  367. }
  368. }
  369. while (count > 0) {
  370. switch (pos) {
  371. case 32: /* PSR */
  372. reg = tstate_to_psr(regs->tstate);
  373. break;
  374. case 33: /* PC */
  375. reg = regs->tpc;
  376. break;
  377. case 34: /* NPC */
  378. reg = regs->tnpc;
  379. break;
  380. case 35: /* Y */
  381. reg = regs->y;
  382. break;
  383. case 36: /* WIM */
  384. case 37: /* TBR */
  385. reg = 0;
  386. break;
  387. default:
  388. goto finish;
  389. }
  390. if (kbuf)
  391. *k++ = reg;
  392. else if (put_user(reg, u++))
  393. return -EFAULT;
  394. pos++;
  395. count--;
  396. }
  397. finish:
  398. pos *= sizeof(reg);
  399. count *= sizeof(reg);
  400. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  401. 38 * sizeof(reg), -1);
  402. }
  403. static int genregs32_set(struct task_struct *target,
  404. const struct user_regset *regset,
  405. unsigned int pos, unsigned int count,
  406. const void *kbuf, const void __user *ubuf)
  407. {
  408. struct pt_regs *regs = task_pt_regs(target);
  409. compat_ulong_t __user *reg_window;
  410. const compat_ulong_t *k = kbuf;
  411. const compat_ulong_t __user *u = ubuf;
  412. compat_ulong_t reg;
  413. if (target == current)
  414. flushw_user();
  415. pos /= sizeof(reg);
  416. count /= sizeof(reg);
  417. if (kbuf) {
  418. for (; count > 0 && pos < 16; count--)
  419. regs->u_regs[pos++] = *k++;
  420. reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
  421. for (; count > 0 && pos < 32; count--) {
  422. if (put_user(*k++, &reg_window[pos++]))
  423. return -EFAULT;
  424. }
  425. } else {
  426. for (; count > 0 && pos < 16; count--) {
  427. if (get_user(reg, u++))
  428. return -EFAULT;
  429. regs->u_regs[pos++] = reg;
  430. }
  431. reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6];
  432. for (; count > 0 && pos < 32; count--) {
  433. if (get_user(reg, u++) ||
  434. put_user(reg, &reg_window[pos++]))
  435. return -EFAULT;
  436. }
  437. }
  438. while (count > 0) {
  439. unsigned long tstate;
  440. if (kbuf)
  441. reg = *k++;
  442. else if (get_user(reg, u++))
  443. return -EFAULT;
  444. switch (pos) {
  445. case 32: /* PSR */
  446. tstate = regs->tstate;
  447. tstate &= ~(TSTATE_ICC | TSTATE_XCC);
  448. tstate |= psr_to_tstate_icc(reg);
  449. regs->tstate = tstate;
  450. break;
  451. case 33: /* PC */
  452. regs->tpc = reg;
  453. break;
  454. case 34: /* NPC */
  455. regs->tnpc = reg;
  456. break;
  457. case 35: /* Y */
  458. regs->y = reg;
  459. break;
  460. case 36: /* WIM */
  461. case 37: /* TBR */
  462. break;
  463. default:
  464. goto finish;
  465. }
  466. pos++;
  467. count--;
  468. }
  469. finish:
  470. pos *= sizeof(reg);
  471. count *= sizeof(reg);
  472. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  473. 38 * sizeof(reg), -1);
  474. }
  475. static int fpregs32_get(struct task_struct *target,
  476. const struct user_regset *regset,
  477. unsigned int pos, unsigned int count,
  478. void *kbuf, void __user *ubuf)
  479. {
  480. const unsigned long *fpregs = task_thread_info(target)->fpregs;
  481. compat_ulong_t enabled;
  482. unsigned long fprs;
  483. compat_ulong_t fsr;
  484. int ret = 0;
  485. if (target == current)
  486. save_and_clear_fpu();
  487. fprs = task_thread_info(target)->fpsaved[0];
  488. if (fprs & FPRS_FEF) {
  489. fsr = task_thread_info(target)->xfsr[0];
  490. enabled = 1;
  491. } else {
  492. fsr = 0;
  493. enabled = 0;
  494. }
  495. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  496. fpregs,
  497. 0, 32 * sizeof(u32));
  498. if (!ret)
  499. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  500. 32 * sizeof(u32),
  501. 33 * sizeof(u32));
  502. if (!ret)
  503. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  504. &fsr,
  505. 33 * sizeof(u32),
  506. 34 * sizeof(u32));
  507. if (!ret) {
  508. compat_ulong_t val;
  509. val = (enabled << 8) | (8 << 16);
  510. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  511. &val,
  512. 34 * sizeof(u32),
  513. 35 * sizeof(u32));
  514. }
  515. if (!ret)
  516. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  517. 35 * sizeof(u32), -1);
  518. return ret;
  519. }
  520. static int fpregs32_set(struct task_struct *target,
  521. const struct user_regset *regset,
  522. unsigned int pos, unsigned int count,
  523. const void *kbuf, const void __user *ubuf)
  524. {
  525. unsigned long *fpregs = task_thread_info(target)->fpregs;
  526. unsigned long fprs;
  527. int ret;
  528. if (target == current)
  529. save_and_clear_fpu();
  530. fprs = task_thread_info(target)->fpsaved[0];
  531. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  532. fpregs,
  533. 0, 32 * sizeof(u32));
  534. if (!ret)
  535. user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  536. 32 * sizeof(u32),
  537. 33 * sizeof(u32));
  538. if (!ret && count > 0) {
  539. compat_ulong_t fsr;
  540. unsigned long val;
  541. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  542. &fsr,
  543. 33 * sizeof(u32),
  544. 34 * sizeof(u32));
  545. if (!ret) {
  546. val = task_thread_info(target)->xfsr[0];
  547. val &= 0xffffffff00000000UL;
  548. val |= fsr;
  549. task_thread_info(target)->xfsr[0] = val;
  550. }
  551. }
  552. fprs |= (FPRS_FEF | FPRS_DL);
  553. task_thread_info(target)->fpsaved[0] = fprs;
  554. if (!ret)
  555. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  556. 34 * sizeof(u32), -1);
  557. return ret;
  558. }
  559. static const struct user_regset sparc32_regsets[] = {
  560. /* Format is:
  561. * G0 --> G7
  562. * O0 --> O7
  563. * L0 --> L7
  564. * I0 --> I7
  565. * PSR, PC, nPC, Y, WIM, TBR
  566. */
  567. [REGSET_GENERAL] = {
  568. .core_note_type = NT_PRSTATUS,
  569. .n = 38 * sizeof(u32),
  570. .size = sizeof(u32), .align = sizeof(u32),
  571. .get = genregs32_get, .set = genregs32_set
  572. },
  573. /* Format is:
  574. * F0 --> F31
  575. * empty 32-bit word
  576. * FSR (32--bit word)
  577. * FPU QUEUE COUNT (8-bit char)
  578. * FPU QUEUE ENTRYSIZE (8-bit char)
  579. * FPU ENABLED (8-bit char)
  580. * empty 8-bit char
  581. * FPU QUEUE (64 32-bit ints)
  582. */
  583. [REGSET_FP] = {
  584. .core_note_type = NT_PRFPREG,
  585. .n = 99 * sizeof(u32),
  586. .size = sizeof(u32), .align = sizeof(u32),
  587. .get = fpregs32_get, .set = fpregs32_set
  588. },
  589. };
  590. static const struct user_regset_view user_sparc32_view = {
  591. .name = "sparc", .e_machine = EM_SPARC,
  592. .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
  593. };
  594. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  595. {
  596. if (test_tsk_thread_flag(task, TIF_32BIT))
  597. return &user_sparc32_view;
  598. return &user_sparc64_view;
  599. }
  600. struct compat_fps {
  601. unsigned int regs[32];
  602. unsigned int fsr;
  603. unsigned int flags;
  604. unsigned int extra;
  605. unsigned int fpqd;
  606. struct compat_fq {
  607. unsigned int insnaddr;
  608. unsigned int insn;
  609. } fpq[16];
  610. };
  611. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  612. compat_ulong_t caddr, compat_ulong_t cdata)
  613. {
  614. const struct user_regset_view *view = task_user_regset_view(child);
  615. compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4];
  616. struct pt_regs32 __user *pregs;
  617. struct compat_fps __user *fps;
  618. unsigned long addr2 = caddr2;
  619. unsigned long addr = caddr;
  620. unsigned long data = cdata;
  621. int ret;
  622. pregs = (struct pt_regs32 __user *) addr;
  623. fps = (struct compat_fps __user *) addr;
  624. switch (request) {
  625. case PTRACE_PEEKUSR:
  626. ret = (addr != 0) ? -EIO : 0;
  627. break;
  628. case PTRACE_GETREGS:
  629. ret = copy_regset_to_user(child, view, REGSET_GENERAL,
  630. 32 * sizeof(u32),
  631. 4 * sizeof(u32),
  632. &pregs->psr);
  633. if (!ret)
  634. ret = copy_regset_to_user(child, view, REGSET_GENERAL,
  635. 1 * sizeof(u32),
  636. 15 * sizeof(u32),
  637. &pregs->u_regs[0]);
  638. break;
  639. case PTRACE_SETREGS:
  640. ret = copy_regset_from_user(child, view, REGSET_GENERAL,
  641. 32 * sizeof(u32),
  642. 4 * sizeof(u32),
  643. &pregs->psr);
  644. if (!ret)
  645. ret = copy_regset_from_user(child, view, REGSET_GENERAL,
  646. 1 * sizeof(u32),
  647. 15 * sizeof(u32),
  648. &pregs->u_regs[0]);
  649. break;
  650. case PTRACE_GETFPREGS:
  651. ret = copy_regset_to_user(child, view, REGSET_FP,
  652. 0 * sizeof(u32),
  653. 32 * sizeof(u32),
  654. &fps->regs[0]);
  655. if (!ret)
  656. ret = copy_regset_to_user(child, view, REGSET_FP,
  657. 33 * sizeof(u32),
  658. 1 * sizeof(u32),
  659. &fps->fsr);
  660. if (!ret) {
  661. if (__put_user(0, &fps->flags) ||
  662. __put_user(0, &fps->extra) ||
  663. __put_user(0, &fps->fpqd) ||
  664. clear_user(&fps->fpq[0], 32 * sizeof(unsigned int)))
  665. ret = -EFAULT;
  666. }
  667. break;
  668. case PTRACE_SETFPREGS:
  669. ret = copy_regset_from_user(child, view, REGSET_FP,
  670. 0 * sizeof(u32),
  671. 32 * sizeof(u32),
  672. &fps->regs[0]);
  673. if (!ret)
  674. ret = copy_regset_from_user(child, view, REGSET_FP,
  675. 33 * sizeof(u32),
  676. 1 * sizeof(u32),
  677. &fps->fsr);
  678. break;
  679. case PTRACE_READTEXT:
  680. case PTRACE_READDATA:
  681. ret = ptrace_readdata(child, addr,
  682. (char __user *)addr2, data);
  683. if (ret == data)
  684. ret = 0;
  685. else if (ret >= 0)
  686. ret = -EIO;
  687. break;
  688. case PTRACE_WRITETEXT:
  689. case PTRACE_WRITEDATA:
  690. ret = ptrace_writedata(child, (char __user *) addr2,
  691. addr, data);
  692. if (ret == data)
  693. ret = 0;
  694. else if (ret >= 0)
  695. ret = -EIO;
  696. break;
  697. default:
  698. ret = compat_ptrace_request(child, request, addr, data);
  699. break;
  700. }
  701. return ret;
  702. }
  703. struct fps {
  704. unsigned int regs[64];
  705. unsigned long fsr;
  706. };
  707. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  708. {
  709. const struct user_regset_view *view = task_user_regset_view(child);
  710. unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
  711. struct pt_regs __user *pregs;
  712. struct fps __user *fps;
  713. int ret;
  714. pregs = (struct pt_regs __user *) (unsigned long) addr;
  715. fps = (struct fps __user *) (unsigned long) addr;
  716. switch (request) {
  717. case PTRACE_PEEKUSR:
  718. ret = (addr != 0) ? -EIO : 0;
  719. break;
  720. case PTRACE_GETREGS64:
  721. ret = copy_regset_to_user(child, view, REGSET_GENERAL,
  722. 1 * sizeof(u64),
  723. 15 * sizeof(u64),
  724. &pregs->u_regs[0]);
  725. if (!ret) {
  726. /* XXX doesn't handle 'y' register correctly XXX */
  727. ret = copy_regset_to_user(child, view, REGSET_GENERAL,
  728. 32 * sizeof(u64),
  729. 4 * sizeof(u64),
  730. &pregs->tstate);
  731. }
  732. break;
  733. case PTRACE_SETREGS64:
  734. ret = copy_regset_from_user(child, view, REGSET_GENERAL,
  735. 1 * sizeof(u64),
  736. 15 * sizeof(u64),
  737. &pregs->u_regs[0]);
  738. if (!ret) {
  739. /* XXX doesn't handle 'y' register correctly XXX */
  740. ret = copy_regset_from_user(child, view, REGSET_GENERAL,
  741. 32 * sizeof(u64),
  742. 4 * sizeof(u64),
  743. &pregs->tstate);
  744. }
  745. break;
  746. case PTRACE_GETFPREGS64:
  747. ret = copy_regset_to_user(child, view, REGSET_FP,
  748. 0 * sizeof(u64),
  749. 33 * sizeof(u64),
  750. fps);
  751. break;
  752. case PTRACE_SETFPREGS64:
  753. ret = copy_regset_to_user(child, view, REGSET_FP,
  754. 0 * sizeof(u64),
  755. 33 * sizeof(u64),
  756. fps);
  757. break;
  758. case PTRACE_READTEXT:
  759. case PTRACE_READDATA:
  760. ret = ptrace_readdata(child, addr,
  761. (char __user *)addr2, data);
  762. if (ret == data)
  763. ret = 0;
  764. else if (ret >= 0)
  765. ret = -EIO;
  766. break;
  767. case PTRACE_WRITETEXT:
  768. case PTRACE_WRITEDATA:
  769. ret = ptrace_writedata(child, (char __user *) addr2,
  770. addr, data);
  771. if (ret == data)
  772. ret = 0;
  773. else if (ret >= 0)
  774. ret = -EIO;
  775. break;
  776. default:
  777. ret = ptrace_request(child, request, addr, data);
  778. break;
  779. }
  780. return ret;
  781. }
  782. asmlinkage void syscall_trace(struct pt_regs *regs, int syscall_exit_p)
  783. {
  784. /* do the secure computing check first */
  785. secure_computing(regs->u_regs[UREG_G1]);
  786. if (unlikely(current->audit_context) && syscall_exit_p) {
  787. unsigned long tstate = regs->tstate;
  788. int result = AUDITSC_SUCCESS;
  789. if (unlikely(tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
  790. result = AUDITSC_FAILURE;
  791. audit_syscall_exit(result, regs->u_regs[UREG_I0]);
  792. }
  793. if (!(current->ptrace & PT_PTRACED))
  794. goto out;
  795. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  796. goto out;
  797. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  798. ? 0x80 : 0));
  799. /*
  800. * this isn't the same as continuing with a signal, but it will do
  801. * for normal use. strace only continues with a signal if the
  802. * stopping signal is not SIGTRAP. -brl
  803. */
  804. if (current->exit_code) {
  805. send_sig(current->exit_code, current, 1);
  806. current->exit_code = 0;
  807. }
  808. out:
  809. if (unlikely(current->audit_context) && !syscall_exit_p)
  810. audit_syscall_entry((test_thread_flag(TIF_32BIT) ?
  811. AUDIT_ARCH_SPARC :
  812. AUDIT_ARCH_SPARC64),
  813. regs->u_regs[UREG_G1],
  814. regs->u_regs[UREG_I0],
  815. regs->u_regs[UREG_I1],
  816. regs->u_regs[UREG_I2],
  817. regs->u_regs[UREG_I3]);
  818. }