ptrace.c 24 KB

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