ptrace.c 19 KB

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