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