ptrace.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. * Kernel support for the ptrace() and syscall tracing interfaces.
  3. *
  4. * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc.
  5. * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx>
  6. * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
  7. * Copyright (C) 2008-2016 Helge Deller <deller@gmx.de>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/mm.h>
  12. #include <linux/smp.h>
  13. #include <linux/elf.h>
  14. #include <linux/errno.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/tracehook.h>
  17. #include <linux/user.h>
  18. #include <linux/personality.h>
  19. #include <linux/regset.h>
  20. #include <linux/security.h>
  21. #include <linux/seccomp.h>
  22. #include <linux/compat.h>
  23. #include <linux/signal.h>
  24. #include <linux/audit.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/processor.h>
  28. #include <asm/asm-offsets.h>
  29. /* PSW bits we allow the debugger to modify */
  30. #define USER_PSW_BITS (PSW_N | PSW_B | PSW_V | PSW_CB)
  31. #define CREATE_TRACE_POINTS
  32. #include <trace/events/syscalls.h>
  33. /*
  34. * These are our native regset flavors.
  35. */
  36. enum parisc_regset {
  37. REGSET_GENERAL,
  38. REGSET_FP
  39. };
  40. /*
  41. * Called by kernel/ptrace.c when detaching..
  42. *
  43. * Make sure single step bits etc are not set.
  44. */
  45. void ptrace_disable(struct task_struct *task)
  46. {
  47. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  48. clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
  49. /* make sure the trap bits are not set */
  50. pa_psw(task)->r = 0;
  51. pa_psw(task)->t = 0;
  52. pa_psw(task)->h = 0;
  53. pa_psw(task)->l = 0;
  54. }
  55. /*
  56. * The following functions are called by ptrace_resume() when
  57. * enabling or disabling single/block tracing.
  58. */
  59. void user_disable_single_step(struct task_struct *task)
  60. {
  61. ptrace_disable(task);
  62. }
  63. void user_enable_single_step(struct task_struct *task)
  64. {
  65. clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
  66. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  67. if (pa_psw(task)->n) {
  68. struct siginfo si;
  69. /* Nullified, just crank over the queue. */
  70. task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
  71. task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
  72. task_regs(task)->iaoq[1] = task_regs(task)->iaoq[0] + 4;
  73. pa_psw(task)->n = 0;
  74. pa_psw(task)->x = 0;
  75. pa_psw(task)->y = 0;
  76. pa_psw(task)->z = 0;
  77. pa_psw(task)->b = 0;
  78. ptrace_disable(task);
  79. /* Don't wake up the task, but let the
  80. parent know something happened. */
  81. si.si_code = TRAP_TRACE;
  82. si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3);
  83. si.si_signo = SIGTRAP;
  84. si.si_errno = 0;
  85. force_sig_info(SIGTRAP, &si, task);
  86. /* notify_parent(task, SIGCHLD); */
  87. return;
  88. }
  89. /* Enable recovery counter traps. The recovery counter
  90. * itself will be set to zero on a task switch. If the
  91. * task is suspended on a syscall then the syscall return
  92. * path will overwrite the recovery counter with a suitable
  93. * value such that it traps once back in user space. We
  94. * disable interrupts in the tasks PSW here also, to avoid
  95. * interrupts while the recovery counter is decrementing.
  96. */
  97. pa_psw(task)->r = 1;
  98. pa_psw(task)->t = 0;
  99. pa_psw(task)->h = 0;
  100. pa_psw(task)->l = 0;
  101. }
  102. void user_enable_block_step(struct task_struct *task)
  103. {
  104. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  105. set_tsk_thread_flag(task, TIF_BLOCKSTEP);
  106. /* Enable taken branch trap. */
  107. pa_psw(task)->r = 0;
  108. pa_psw(task)->t = 1;
  109. pa_psw(task)->h = 0;
  110. pa_psw(task)->l = 0;
  111. }
  112. long arch_ptrace(struct task_struct *child, long request,
  113. unsigned long addr, unsigned long data)
  114. {
  115. unsigned long __user *datap = (unsigned long __user *)data;
  116. unsigned long tmp;
  117. long ret = -EIO;
  118. switch (request) {
  119. /* Read the word at location addr in the USER area. For ptraced
  120. processes, the kernel saves all regs on a syscall. */
  121. case PTRACE_PEEKUSR:
  122. if ((addr & (sizeof(unsigned long)-1)) ||
  123. addr >= sizeof(struct pt_regs))
  124. break;
  125. tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
  126. ret = put_user(tmp, datap);
  127. break;
  128. /* Write the word at location addr in the USER area. This will need
  129. to change when the kernel no longer saves all regs on a syscall.
  130. FIXME. There is a problem at the moment in that r3-r18 are only
  131. saved if the process is ptraced on syscall entry, and even then
  132. those values are overwritten by actual register values on syscall
  133. exit. */
  134. case PTRACE_POKEUSR:
  135. /* Some register values written here may be ignored in
  136. * entry.S:syscall_restore_rfi; e.g. iaoq is written with
  137. * r31/r31+4, and not with the values in pt_regs.
  138. */
  139. if (addr == PT_PSW) {
  140. /* Allow writing to Nullify, Divide-step-correction,
  141. * and carry/borrow bits.
  142. * BEWARE, if you set N, and then single step, it won't
  143. * stop on the nullified instruction.
  144. */
  145. data &= USER_PSW_BITS;
  146. task_regs(child)->gr[0] &= ~USER_PSW_BITS;
  147. task_regs(child)->gr[0] |= data;
  148. ret = 0;
  149. break;
  150. }
  151. if ((addr & (sizeof(unsigned long)-1)) ||
  152. addr >= sizeof(struct pt_regs))
  153. break;
  154. if ((addr >= PT_GR1 && addr <= PT_GR31) ||
  155. addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
  156. (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
  157. addr == PT_SAR) {
  158. *(unsigned long *) ((char *) task_regs(child) + addr) = data;
  159. ret = 0;
  160. }
  161. break;
  162. case PTRACE_GETREGS: /* Get all gp regs from the child. */
  163. return copy_regset_to_user(child,
  164. task_user_regset_view(current),
  165. REGSET_GENERAL,
  166. 0, sizeof(struct user_regs_struct),
  167. datap);
  168. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  169. return copy_regset_from_user(child,
  170. task_user_regset_view(current),
  171. REGSET_GENERAL,
  172. 0, sizeof(struct user_regs_struct),
  173. datap);
  174. case PTRACE_GETFPREGS: /* Get the child FPU state. */
  175. return copy_regset_to_user(child,
  176. task_user_regset_view(current),
  177. REGSET_FP,
  178. 0, sizeof(struct user_fp_struct),
  179. datap);
  180. case PTRACE_SETFPREGS: /* Set the child FPU state. */
  181. return copy_regset_from_user(child,
  182. task_user_regset_view(current),
  183. REGSET_FP,
  184. 0, sizeof(struct user_fp_struct),
  185. datap);
  186. default:
  187. ret = ptrace_request(child, request, addr, data);
  188. break;
  189. }
  190. return ret;
  191. }
  192. #ifdef CONFIG_COMPAT
  193. /* This function is needed to translate 32 bit pt_regs offsets in to
  194. * 64 bit pt_regs offsets. For example, a 32 bit gdb under a 64 bit kernel
  195. * will request offset 12 if it wants gr3, but the lower 32 bits of
  196. * the 64 bit kernels view of gr3 will be at offset 28 (3*8 + 4).
  197. * This code relies on a 32 bit pt_regs being comprised of 32 bit values
  198. * except for the fp registers which (a) are 64 bits, and (b) follow
  199. * the gr registers at the start of pt_regs. The 32 bit pt_regs should
  200. * be half the size of the 64 bit pt_regs, plus 32*4 to allow for fr[]
  201. * being 64 bit in both cases.
  202. */
  203. static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
  204. {
  205. if (offset < 0)
  206. return sizeof(struct pt_regs);
  207. else if (offset <= 32*4) /* gr[0..31] */
  208. return offset * 2 + 4;
  209. else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */
  210. return offset + 32*4;
  211. else if (offset < sizeof(struct pt_regs)/2 + 32*4)
  212. return offset * 2 + 4 - 32*8;
  213. else
  214. return sizeof(struct pt_regs);
  215. }
  216. long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
  217. compat_ulong_t addr, compat_ulong_t data)
  218. {
  219. compat_uint_t tmp;
  220. long ret = -EIO;
  221. switch (request) {
  222. case PTRACE_PEEKUSR:
  223. if (addr & (sizeof(compat_uint_t)-1))
  224. break;
  225. addr = translate_usr_offset(addr);
  226. if (addr >= sizeof(struct pt_regs))
  227. break;
  228. tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
  229. ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
  230. break;
  231. /* Write the word at location addr in the USER area. This will need
  232. to change when the kernel no longer saves all regs on a syscall.
  233. FIXME. There is a problem at the moment in that r3-r18 are only
  234. saved if the process is ptraced on syscall entry, and even then
  235. those values are overwritten by actual register values on syscall
  236. exit. */
  237. case PTRACE_POKEUSR:
  238. /* Some register values written here may be ignored in
  239. * entry.S:syscall_restore_rfi; e.g. iaoq is written with
  240. * r31/r31+4, and not with the values in pt_regs.
  241. */
  242. if (addr == PT_PSW) {
  243. /* Since PT_PSW==0, it is valid for 32 bit processes
  244. * under 64 bit kernels as well.
  245. */
  246. ret = arch_ptrace(child, request, addr, data);
  247. } else {
  248. if (addr & (sizeof(compat_uint_t)-1))
  249. break;
  250. addr = translate_usr_offset(addr);
  251. if (addr >= sizeof(struct pt_regs))
  252. break;
  253. if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
  254. /* Special case, fp regs are 64 bits anyway */
  255. *(__u64 *) ((char *) task_regs(child) + addr) = data;
  256. ret = 0;
  257. }
  258. else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
  259. addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 ||
  260. addr == PT_SAR+4) {
  261. /* Zero the top 32 bits */
  262. *(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
  263. *(__u32 *) ((char *) task_regs(child) + addr) = data;
  264. ret = 0;
  265. }
  266. }
  267. break;
  268. default:
  269. ret = compat_ptrace_request(child, request, addr, data);
  270. break;
  271. }
  272. return ret;
  273. }
  274. #endif
  275. long do_syscall_trace_enter(struct pt_regs *regs)
  276. {
  277. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  278. tracehook_report_syscall_entry(regs)) {
  279. /*
  280. * Tracing decided this syscall should not happen or the
  281. * debugger stored an invalid system call number. Skip
  282. * the system call and the system call restart handling.
  283. */
  284. regs->gr[20] = -1UL;
  285. goto out;
  286. }
  287. /* Do the secure computing check after ptrace. */
  288. if (secure_computing(NULL) == -1)
  289. return -1;
  290. #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
  291. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  292. trace_sys_enter(regs, regs->gr[20]);
  293. #endif
  294. #ifdef CONFIG_64BIT
  295. if (!is_compat_task())
  296. audit_syscall_entry(regs->gr[20], regs->gr[26], regs->gr[25],
  297. regs->gr[24], regs->gr[23]);
  298. else
  299. #endif
  300. audit_syscall_entry(regs->gr[20] & 0xffffffff,
  301. regs->gr[26] & 0xffffffff,
  302. regs->gr[25] & 0xffffffff,
  303. regs->gr[24] & 0xffffffff,
  304. regs->gr[23] & 0xffffffff);
  305. out:
  306. /*
  307. * Sign extend the syscall number to 64bit since it may have been
  308. * modified by a compat ptrace call
  309. */
  310. return (int) ((u32) regs->gr[20]);
  311. }
  312. void do_syscall_trace_exit(struct pt_regs *regs)
  313. {
  314. int stepping = test_thread_flag(TIF_SINGLESTEP) ||
  315. test_thread_flag(TIF_BLOCKSTEP);
  316. audit_syscall_exit(regs);
  317. #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
  318. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  319. trace_sys_exit(regs, regs->gr[20]);
  320. #endif
  321. if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
  322. tracehook_report_syscall_exit(regs, stepping);
  323. }
  324. /*
  325. * regset functions.
  326. */
  327. static int fpr_get(struct task_struct *target,
  328. const struct user_regset *regset,
  329. unsigned int pos, unsigned int count,
  330. void *kbuf, void __user *ubuf)
  331. {
  332. struct pt_regs *regs = task_regs(target);
  333. __u64 *k = kbuf;
  334. __u64 __user *u = ubuf;
  335. __u64 reg;
  336. pos /= sizeof(reg);
  337. count /= sizeof(reg);
  338. if (kbuf)
  339. for (; count > 0 && pos < ELF_NFPREG; --count)
  340. *k++ = regs->fr[pos++];
  341. else
  342. for (; count > 0 && pos < ELF_NFPREG; --count)
  343. if (__put_user(regs->fr[pos++], u++))
  344. return -EFAULT;
  345. kbuf = k;
  346. ubuf = u;
  347. pos *= sizeof(reg);
  348. count *= sizeof(reg);
  349. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  350. ELF_NFPREG * sizeof(reg), -1);
  351. }
  352. static int fpr_set(struct task_struct *target,
  353. const struct user_regset *regset,
  354. unsigned int pos, unsigned int count,
  355. const void *kbuf, const void __user *ubuf)
  356. {
  357. struct pt_regs *regs = task_regs(target);
  358. const __u64 *k = kbuf;
  359. const __u64 __user *u = ubuf;
  360. __u64 reg;
  361. pos /= sizeof(reg);
  362. count /= sizeof(reg);
  363. if (kbuf)
  364. for (; count > 0 && pos < ELF_NFPREG; --count)
  365. regs->fr[pos++] = *k++;
  366. else
  367. for (; count > 0 && pos < ELF_NFPREG; --count) {
  368. if (__get_user(reg, u++))
  369. return -EFAULT;
  370. regs->fr[pos++] = reg;
  371. }
  372. kbuf = k;
  373. ubuf = u;
  374. pos *= sizeof(reg);
  375. count *= sizeof(reg);
  376. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  377. ELF_NFPREG * sizeof(reg), -1);
  378. }
  379. #define RI(reg) (offsetof(struct user_regs_struct,reg) / sizeof(long))
  380. static unsigned long get_reg(struct pt_regs *regs, int num)
  381. {
  382. switch (num) {
  383. case RI(gr[0]) ... RI(gr[31]): return regs->gr[num - RI(gr[0])];
  384. case RI(sr[0]) ... RI(sr[7]): return regs->sr[num - RI(sr[0])];
  385. case RI(iasq[0]): return regs->iasq[0];
  386. case RI(iasq[1]): return regs->iasq[1];
  387. case RI(iaoq[0]): return regs->iaoq[0];
  388. case RI(iaoq[1]): return regs->iaoq[1];
  389. case RI(sar): return regs->sar;
  390. case RI(iir): return regs->iir;
  391. case RI(isr): return regs->isr;
  392. case RI(ior): return regs->ior;
  393. case RI(ipsw): return regs->ipsw;
  394. case RI(cr27): return regs->cr27;
  395. case RI(cr0): return mfctl(0);
  396. case RI(cr24): return mfctl(24);
  397. case RI(cr25): return mfctl(25);
  398. case RI(cr26): return mfctl(26);
  399. case RI(cr28): return mfctl(28);
  400. case RI(cr29): return mfctl(29);
  401. case RI(cr30): return mfctl(30);
  402. case RI(cr31): return mfctl(31);
  403. case RI(cr8): return mfctl(8);
  404. case RI(cr9): return mfctl(9);
  405. case RI(cr12): return mfctl(12);
  406. case RI(cr13): return mfctl(13);
  407. case RI(cr10): return mfctl(10);
  408. case RI(cr15): return mfctl(15);
  409. default: return 0;
  410. }
  411. }
  412. static void set_reg(struct pt_regs *regs, int num, unsigned long val)
  413. {
  414. switch (num) {
  415. case RI(gr[0]): /*
  416. * PSW is in gr[0].
  417. * Allow writing to Nullify, Divide-step-correction,
  418. * and carry/borrow bits.
  419. * BEWARE, if you set N, and then single step, it won't
  420. * stop on the nullified instruction.
  421. */
  422. val &= USER_PSW_BITS;
  423. regs->gr[0] &= ~USER_PSW_BITS;
  424. regs->gr[0] |= val;
  425. return;
  426. case RI(gr[1]) ... RI(gr[31]):
  427. regs->gr[num - RI(gr[0])] = val;
  428. return;
  429. case RI(iaoq[0]):
  430. case RI(iaoq[1]):
  431. regs->iaoq[num - RI(iaoq[0])] = val;
  432. return;
  433. case RI(sar): regs->sar = val;
  434. return;
  435. default: return;
  436. #if 0
  437. /* do not allow to change any of the following registers (yet) */
  438. case RI(sr[0]) ... RI(sr[7]): return regs->sr[num - RI(sr[0])];
  439. case RI(iasq[0]): return regs->iasq[0];
  440. case RI(iasq[1]): return regs->iasq[1];
  441. case RI(iir): return regs->iir;
  442. case RI(isr): return regs->isr;
  443. case RI(ior): return regs->ior;
  444. case RI(ipsw): return regs->ipsw;
  445. case RI(cr27): return regs->cr27;
  446. case cr0, cr24, cr25, cr26, cr27, cr28, cr29, cr30, cr31;
  447. case cr8, cr9, cr12, cr13, cr10, cr15;
  448. #endif
  449. }
  450. }
  451. static int gpr_get(struct task_struct *target,
  452. const struct user_regset *regset,
  453. unsigned int pos, unsigned int count,
  454. void *kbuf, void __user *ubuf)
  455. {
  456. struct pt_regs *regs = task_regs(target);
  457. unsigned long *k = kbuf;
  458. unsigned long __user *u = ubuf;
  459. unsigned long reg;
  460. pos /= sizeof(reg);
  461. count /= sizeof(reg);
  462. if (kbuf)
  463. for (; count > 0 && pos < ELF_NGREG; --count)
  464. *k++ = get_reg(regs, pos++);
  465. else
  466. for (; count > 0 && pos < ELF_NGREG; --count)
  467. if (__put_user(get_reg(regs, pos++), u++))
  468. return -EFAULT;
  469. kbuf = k;
  470. ubuf = u;
  471. pos *= sizeof(reg);
  472. count *= sizeof(reg);
  473. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  474. ELF_NGREG * sizeof(reg), -1);
  475. }
  476. static int gpr_set(struct task_struct *target,
  477. const struct user_regset *regset,
  478. unsigned int pos, unsigned int count,
  479. const void *kbuf, const void __user *ubuf)
  480. {
  481. struct pt_regs *regs = task_regs(target);
  482. const unsigned long *k = kbuf;
  483. const unsigned long __user *u = ubuf;
  484. unsigned long reg;
  485. pos /= sizeof(reg);
  486. count /= sizeof(reg);
  487. if (kbuf)
  488. for (; count > 0 && pos < ELF_NGREG; --count)
  489. set_reg(regs, pos++, *k++);
  490. else
  491. for (; count > 0 && pos < ELF_NGREG; --count) {
  492. if (__get_user(reg, u++))
  493. return -EFAULT;
  494. set_reg(regs, pos++, reg);
  495. }
  496. kbuf = k;
  497. ubuf = u;
  498. pos *= sizeof(reg);
  499. count *= sizeof(reg);
  500. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  501. ELF_NGREG * sizeof(reg), -1);
  502. }
  503. static const struct user_regset native_regsets[] = {
  504. [REGSET_GENERAL] = {
  505. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  506. .size = sizeof(long), .align = sizeof(long),
  507. .get = gpr_get, .set = gpr_set
  508. },
  509. [REGSET_FP] = {
  510. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  511. .size = sizeof(__u64), .align = sizeof(__u64),
  512. .get = fpr_get, .set = fpr_set
  513. }
  514. };
  515. static const struct user_regset_view user_parisc_native_view = {
  516. .name = "parisc", .e_machine = ELF_ARCH, .ei_osabi = ELFOSABI_LINUX,
  517. .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
  518. };
  519. #ifdef CONFIG_64BIT
  520. #include <linux/compat.h>
  521. static int gpr32_get(struct task_struct *target,
  522. const struct user_regset *regset,
  523. unsigned int pos, unsigned int count,
  524. void *kbuf, void __user *ubuf)
  525. {
  526. struct pt_regs *regs = task_regs(target);
  527. compat_ulong_t *k = kbuf;
  528. compat_ulong_t __user *u = ubuf;
  529. compat_ulong_t reg;
  530. pos /= sizeof(reg);
  531. count /= sizeof(reg);
  532. if (kbuf)
  533. for (; count > 0 && pos < ELF_NGREG; --count)
  534. *k++ = get_reg(regs, pos++);
  535. else
  536. for (; count > 0 && pos < ELF_NGREG; --count)
  537. if (__put_user((compat_ulong_t) get_reg(regs, pos++), u++))
  538. return -EFAULT;
  539. kbuf = k;
  540. ubuf = u;
  541. pos *= sizeof(reg);
  542. count *= sizeof(reg);
  543. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  544. ELF_NGREG * sizeof(reg), -1);
  545. }
  546. static int gpr32_set(struct task_struct *target,
  547. const struct user_regset *regset,
  548. unsigned int pos, unsigned int count,
  549. const void *kbuf, const void __user *ubuf)
  550. {
  551. struct pt_regs *regs = task_regs(target);
  552. const compat_ulong_t *k = kbuf;
  553. const compat_ulong_t __user *u = ubuf;
  554. compat_ulong_t reg;
  555. pos /= sizeof(reg);
  556. count /= sizeof(reg);
  557. if (kbuf)
  558. for (; count > 0 && pos < ELF_NGREG; --count)
  559. set_reg(regs, pos++, *k++);
  560. else
  561. for (; count > 0 && pos < ELF_NGREG; --count) {
  562. if (__get_user(reg, u++))
  563. return -EFAULT;
  564. set_reg(regs, pos++, reg);
  565. }
  566. kbuf = k;
  567. ubuf = u;
  568. pos *= sizeof(reg);
  569. count *= sizeof(reg);
  570. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  571. ELF_NGREG * sizeof(reg), -1);
  572. }
  573. /*
  574. * These are the regset flavors matching the 32bit native set.
  575. */
  576. static const struct user_regset compat_regsets[] = {
  577. [REGSET_GENERAL] = {
  578. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  579. .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
  580. .get = gpr32_get, .set = gpr32_set
  581. },
  582. [REGSET_FP] = {
  583. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  584. .size = sizeof(__u64), .align = sizeof(__u64),
  585. .get = fpr_get, .set = fpr_set
  586. }
  587. };
  588. static const struct user_regset_view user_parisc_compat_view = {
  589. .name = "parisc", .e_machine = EM_PARISC, .ei_osabi = ELFOSABI_LINUX,
  590. .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
  591. };
  592. #endif /* CONFIG_64BIT */
  593. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  594. {
  595. BUILD_BUG_ON(sizeof(struct user_regs_struct)/sizeof(long) != ELF_NGREG);
  596. BUILD_BUG_ON(sizeof(struct user_fp_struct)/sizeof(__u64) != ELF_NFPREG);
  597. #ifdef CONFIG_64BIT
  598. if (is_compat_task())
  599. return &user_parisc_compat_view;
  600. #endif
  601. return &user_parisc_native_view;
  602. }