2 * arch/s390/kernel/ptrace.c
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Based on PowerPC version
10 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
12 * Derived from "arch/m68k/kernel/ptrace.c"
13 * Copyright (C) 1994 by Hamish Macdonald
14 * Taken from linux/kernel/ptrace.c and modified for M680x0.
15 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
17 * Modified by Cort Dougan (cort@cs.nmt.edu)
20 * This file is subject to the terms and conditions of the GNU General
21 * Public License. See the file README.legal in the main directory of
22 * this archive for more details.
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
28 #include <linux/smp.h>
29 #include <linux/errno.h>
30 #include <linux/ptrace.h>
31 #include <linux/user.h>
32 #include <linux/security.h>
33 #include <linux/audit.h>
34 #include <linux/signal.h>
35 #include <linux/elf.h>
36 #include <linux/regset.h>
37 #include <linux/tracehook.h>
38 #include <linux/seccomp.h>
39 #include <trace/syscall.h>
40 #include <asm/compat.h>
41 #include <asm/segment.h>
43 #include <asm/pgtable.h>
44 #include <asm/pgalloc.h>
45 #include <asm/system.h>
46 #include <asm/uaccess.h>
47 #include <asm/unistd.h>
51 #include "compat_ptrace.h"
54 #define CREATE_TRACE_POINTS
55 #include <trace/events/syscalls.h>
60 REGSET_GENERAL_EXTENDED
,
64 FixPerRegisters(struct task_struct
*task
)
69 regs
= task_pt_regs(task
);
70 per_info
= (per_struct
*) &task
->thread
.per_info
;
71 per_info
->control_regs
.bits
.em_instruction_fetch
=
72 per_info
->single_step
| per_info
->instruction_fetch
;
74 if (per_info
->single_step
) {
75 per_info
->control_regs
.bits
.starting_addr
= 0;
78 per_info
->control_regs
.bits
.ending_addr
= 0x7fffffffUL
;
81 per_info
->control_regs
.bits
.ending_addr
= PSW_ADDR_INSN
;
83 per_info
->control_regs
.bits
.starting_addr
=
84 per_info
->starting_addr
;
85 per_info
->control_regs
.bits
.ending_addr
=
86 per_info
->ending_addr
;
89 * if any of the control reg tracing bits are on
90 * we switch on per in the psw
92 if (per_info
->control_regs
.words
.cr
[0] & PER_EM_MASK
)
93 regs
->psw
.mask
|= PSW_MASK_PER
;
95 regs
->psw
.mask
&= ~PSW_MASK_PER
;
97 if (per_info
->control_regs
.bits
.em_storage_alteration
)
98 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 1;
100 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 0;
103 void user_enable_single_step(struct task_struct
*task
)
105 task
->thread
.per_info
.single_step
= 1;
106 FixPerRegisters(task
);
109 void user_disable_single_step(struct task_struct
*task
)
111 task
->thread
.per_info
.single_step
= 0;
112 FixPerRegisters(task
);
116 * Called by kernel/ptrace.c when detaching..
118 * Make sure single step bits etc are not set.
121 ptrace_disable(struct task_struct
*child
)
123 /* make sure the single step bit is not set. */
124 user_disable_single_step(child
);
128 # define __ADDR_MASK 3
130 # define __ADDR_MASK 7
134 * Read the word at offset addr from the user area of a process. The
135 * trouble here is that the information is littered over different
136 * locations. The process registers are found on the kernel stack,
137 * the floating point stuff and the trace settings are stored in
138 * the task structure. In addition the different structures in
139 * struct user contain pad bytes that should be read as zeroes.
142 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
144 struct user
*dummy
= NULL
;
147 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
149 * psw and gprs are stored on the stack
151 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
152 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
)
153 /* Remove per bit from user psw. */
154 tmp
&= ~PSW_MASK_PER
;
156 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
158 * access registers are stored in the thread structure
160 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
163 * Very special case: old & broken 64 bit gdb reading
164 * from acrs[15]. Result is a 64 bit value. Read the
165 * 32 bit acrs[15] value and shift it by 32. Sick...
167 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
168 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
171 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
173 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
175 * orig_gpr2 is stored on the kernel stack
177 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
179 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
181 * prevent reads of padding hole between
182 * orig_gpr2 and fp_regs on s390.
186 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
188 * floating point regs. are stored in the thread structure
190 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
191 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
192 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
)
193 tmp
&= (unsigned long) FPC_VALID_MASK
194 << (BITS_PER_LONG
- 32);
196 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
198 * per_info is found in the thread structure
200 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
201 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
);
210 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
215 * Stupid gdb peeks/pokes the access registers in 64 bit with
216 * an alignment of 4. Programmers from hell...
220 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
221 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
224 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
227 tmp
= __peek_user(child
, addr
);
228 return put_user(tmp
, (addr_t __user
*) data
);
232 * Write a word to the user area of a process at location addr. This
233 * operation does have an additional problem compared to peek_user.
234 * Stores to the program status word and on the floating point
235 * control register needs to get checked for validity.
237 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
239 struct user
*dummy
= NULL
;
242 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
244 * psw and gprs are stored on the stack
246 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
&&
248 data
!= PSW_MASK_MERGE(psw_user32_bits
, data
) &&
250 data
!= PSW_MASK_MERGE(psw_user_bits
, data
))
251 /* Invalid psw mask. */
254 if (addr
== (addr_t
) &dummy
->regs
.psw
.addr
)
255 /* I'd like to reject addresses without the
256 high order bit but older gdb's rely on it */
257 data
|= PSW_ADDR_AMODE
;
259 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
261 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
263 * access registers are stored in the thread structure
265 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
268 * Very special case: old & broken 64 bit gdb writing
269 * to acrs[15] with a 64 bit value. Ignore the lower
270 * half of the value and write the upper 32 bit to
273 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
274 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
277 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
279 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
281 * orig_gpr2 is stored on the kernel stack
283 task_pt_regs(child
)->orig_gpr2
= data
;
285 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
287 * prevent writes of padding hole between
288 * orig_gpr2 and fp_regs on s390.
292 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
294 * floating point regs. are stored in the thread structure
296 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
&&
297 (data
& ~((unsigned long) FPC_VALID_MASK
298 << (BITS_PER_LONG
- 32))) != 0)
300 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
301 *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = data
;
303 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
305 * per_info is found in the thread structure
307 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
308 *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
) = data
;
312 FixPerRegisters(child
);
317 poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
322 * Stupid gdb peeks/pokes the access registers in 64 bit with
323 * an alignment of 4. Programmers from hell indeed...
327 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
328 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
331 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
334 return __poke_user(child
, addr
, data
);
337 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
344 /* read the word at location addr in the USER area. */
345 return peek_user(child
, addr
, data
);
348 /* write the word at location addr in the USER area */
349 return poke_user(child
, addr
, data
);
351 case PTRACE_PEEKUSR_AREA
:
352 case PTRACE_POKEUSR_AREA
:
353 if (copy_from_user(&parea
, (void __force __user
*) addr
,
356 addr
= parea
.kernel_addr
;
357 data
= parea
.process_addr
;
359 while (copied
< parea
.len
) {
360 if (request
== PTRACE_PEEKUSR_AREA
)
361 ret
= peek_user(child
, addr
, data
);
365 (addr_t __force __user
*) data
))
367 ret
= poke_user(child
, addr
, utmp
);
371 addr
+= sizeof(unsigned long);
372 data
+= sizeof(unsigned long);
373 copied
+= sizeof(unsigned long);
377 /* Removing high order bit from addr (only for 31 bit). */
378 addr
&= PSW_ADDR_INSN
;
379 return ptrace_request(child
, request
, addr
, data
);
385 * Now the fun part starts... a 31 bit program running in the
386 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
387 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
388 * to handle, the difference to the 64 bit versions of the requests
389 * is that the access is done in multiples of 4 byte instead of
390 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
391 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
392 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
393 * is a 31 bit program too, the content of struct user can be
394 * emulated. A 31 bit program peeking into the struct user of
395 * a 64 bit program is a no-no.
399 * Same as peek_user but for a 31 bit program.
401 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
403 struct user32
*dummy32
= NULL
;
404 per_struct32
*dummy_per32
= NULL
;
408 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
410 * psw and gprs are stored on the stack
412 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
413 /* Fake a 31 bit psw mask. */
414 tmp
= (__u32
)(task_pt_regs(child
)->psw
.mask
>> 32);
415 tmp
= PSW32_MASK_MERGE(psw32_user_bits
, tmp
);
416 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
417 /* Fake a 31 bit psw address. */
418 tmp
= (__u32
) task_pt_regs(child
)->psw
.addr
|
422 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
+
425 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
427 * access registers are stored in the thread structure
429 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
430 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
432 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
434 * orig_gpr2 is stored on the kernel stack
436 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
438 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
440 * prevent reads of padding hole between
441 * orig_gpr2 and fp_regs on s390.
445 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
447 * floating point regs. are stored in the thread structure
449 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
450 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
452 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
454 * per_info is found in the thread structure
456 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
457 /* This is magic. See per_struct and per_struct32. */
458 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
459 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
460 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
461 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
462 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
463 offset
= offset
*2 + 4;
466 tmp
= *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
);
474 static int peek_user_compat(struct task_struct
*child
,
475 addr_t addr
, addr_t data
)
479 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user
) - 3)
482 tmp
= __peek_user_compat(child
, addr
);
483 return put_user(tmp
, (__u32 __user
*) data
);
487 * Same as poke_user but for a 31 bit program.
489 static int __poke_user_compat(struct task_struct
*child
,
490 addr_t addr
, addr_t data
)
492 struct user32
*dummy32
= NULL
;
493 per_struct32
*dummy_per32
= NULL
;
494 __u32 tmp
= (__u32
) data
;
497 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
499 * psw, gprs, acrs and orig_gpr2 are stored on the stack
501 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
502 /* Build a 64 bit psw mask from 31 bit mask. */
503 if (tmp
!= PSW32_MASK_MERGE(psw32_user_bits
, tmp
))
504 /* Invalid psw mask. */
506 task_pt_regs(child
)->psw
.mask
=
507 PSW_MASK_MERGE(psw_user32_bits
, (__u64
) tmp
<< 32);
508 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
509 /* Build a 64 bit psw address from 31 bit address. */
510 task_pt_regs(child
)->psw
.addr
=
511 (__u64
) tmp
& PSW32_ADDR_INSN
;
514 *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
517 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
519 * access registers are stored in the thread structure
521 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
522 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
524 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
526 * orig_gpr2 is stored on the kernel stack
528 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
530 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
532 * prevent writess of padding hole between
533 * orig_gpr2 and fp_regs on s390.
537 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
539 * floating point regs. are stored in the thread structure
541 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
542 (tmp
& ~FPC_VALID_MASK
) != 0)
543 /* Invalid floating point control. */
545 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
546 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
548 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
550 * per_info is found in the thread structure.
552 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
554 * This is magic. See per_struct and per_struct32.
555 * By incident the offsets in per_struct are exactly
556 * twice the offsets in per_struct32 for all fields.
557 * The 8 byte fields need special handling though,
558 * because the second half (bytes 4-7) is needed and
559 * not the first half.
561 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
562 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
563 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
564 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
565 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
566 offset
= offset
*2 + 4;
569 *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
) = tmp
;
573 FixPerRegisters(child
);
577 static int poke_user_compat(struct task_struct
*child
,
578 addr_t addr
, addr_t data
)
580 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user32
) - 3)
583 return __poke_user_compat(child
, addr
, data
);
586 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
587 compat_ulong_t caddr
, compat_ulong_t cdata
)
589 unsigned long addr
= caddr
;
590 unsigned long data
= cdata
;
591 ptrace_area_emu31 parea
;
596 /* read the word at location addr in the USER area. */
597 return peek_user_compat(child
, addr
, data
);
600 /* write the word at location addr in the USER area */
601 return poke_user_compat(child
, addr
, data
);
603 case PTRACE_PEEKUSR_AREA
:
604 case PTRACE_POKEUSR_AREA
:
605 if (copy_from_user(&parea
, (void __force __user
*) addr
,
608 addr
= parea
.kernel_addr
;
609 data
= parea
.process_addr
;
611 while (copied
< parea
.len
) {
612 if (request
== PTRACE_PEEKUSR_AREA
)
613 ret
= peek_user_compat(child
, addr
, data
);
617 (__u32 __force __user
*) data
))
619 ret
= poke_user_compat(child
, addr
, utmp
);
623 addr
+= sizeof(unsigned int);
624 data
+= sizeof(unsigned int);
625 copied
+= sizeof(unsigned int);
629 return compat_ptrace_request(child
, request
, addr
, data
);
633 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
637 /* Do the secure computing check first. */
638 secure_computing(regs
->gprs
[2]);
641 * The sysc_tracesys code in entry.S stored the system
642 * call number to gprs[2].
645 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
646 (tracehook_report_syscall_entry(regs
) ||
647 regs
->gprs
[2] >= NR_syscalls
)) {
649 * Tracing decided this syscall should not happen or the
650 * debugger stored an invalid system call number. Skip
651 * the system call and the system call restart handling.
657 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
658 trace_sys_enter(regs
, regs
->gprs
[2]);
660 if (unlikely(current
->audit_context
))
661 audit_syscall_entry(is_compat_task() ?
662 AUDIT_ARCH_S390
: AUDIT_ARCH_S390X
,
663 regs
->gprs
[2], regs
->orig_gpr2
,
664 regs
->gprs
[3], regs
->gprs
[4],
669 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
671 if (unlikely(current
->audit_context
))
672 audit_syscall_exit(AUDITSC_RESULT(regs
->gprs
[2]),
675 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
676 trace_sys_exit(regs
, regs
->gprs
[2]);
678 if (test_thread_flag(TIF_SYSCALL_TRACE
))
679 tracehook_report_syscall_exit(regs
, 0);
683 * user_regset definitions.
686 static int s390_regs_get(struct task_struct
*target
,
687 const struct user_regset
*regset
,
688 unsigned int pos
, unsigned int count
,
689 void *kbuf
, void __user
*ubuf
)
691 if (target
== current
)
692 save_access_regs(target
->thread
.acrs
);
695 unsigned long *k
= kbuf
;
697 *k
++ = __peek_user(target
, pos
);
702 unsigned long __user
*u
= ubuf
;
704 if (__put_user(__peek_user(target
, pos
), u
++))
713 static int s390_regs_set(struct task_struct
*target
,
714 const struct user_regset
*regset
,
715 unsigned int pos
, unsigned int count
,
716 const void *kbuf
, const void __user
*ubuf
)
720 if (target
== current
)
721 save_access_regs(target
->thread
.acrs
);
724 const unsigned long *k
= kbuf
;
725 while (count
> 0 && !rc
) {
726 rc
= __poke_user(target
, pos
, *k
++);
731 const unsigned long __user
*u
= ubuf
;
732 while (count
> 0 && !rc
) {
734 rc
= __get_user(word
, u
++);
737 rc
= __poke_user(target
, pos
, word
);
743 if (rc
== 0 && target
== current
)
744 restore_access_regs(target
->thread
.acrs
);
749 static int s390_fpregs_get(struct task_struct
*target
,
750 const struct user_regset
*regset
, unsigned int pos
,
751 unsigned int count
, void *kbuf
, void __user
*ubuf
)
753 if (target
== current
)
754 save_fp_regs(&target
->thread
.fp_regs
);
756 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
757 &target
->thread
.fp_regs
, 0, -1);
760 static int s390_fpregs_set(struct task_struct
*target
,
761 const struct user_regset
*regset
, unsigned int pos
,
762 unsigned int count
, const void *kbuf
,
763 const void __user
*ubuf
)
767 if (target
== current
)
768 save_fp_regs(&target
->thread
.fp_regs
);
770 /* If setting FPC, must validate it first. */
771 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
772 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
773 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
774 0, offsetof(s390_fp_regs
, fprs
));
777 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
779 target
->thread
.fp_regs
.fpc
= fpc
[0];
782 if (rc
== 0 && count
> 0)
783 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
784 target
->thread
.fp_regs
.fprs
,
785 offsetof(s390_fp_regs
, fprs
), -1);
787 if (rc
== 0 && target
== current
)
788 restore_fp_regs(&target
->thread
.fp_regs
);
793 static const struct user_regset s390_regsets
[] = {
795 .core_note_type
= NT_PRSTATUS
,
796 .n
= sizeof(s390_regs
) / sizeof(long),
797 .size
= sizeof(long),
798 .align
= sizeof(long),
799 .get
= s390_regs_get
,
800 .set
= s390_regs_set
,
803 .core_note_type
= NT_PRFPREG
,
804 .n
= sizeof(s390_fp_regs
) / sizeof(long),
805 .size
= sizeof(long),
806 .align
= sizeof(long),
807 .get
= s390_fpregs_get
,
808 .set
= s390_fpregs_set
,
812 static const struct user_regset_view user_s390_view
= {
814 .e_machine
= EM_S390
,
815 .regsets
= s390_regsets
,
816 .n
= ARRAY_SIZE(s390_regsets
)
820 static int s390_compat_regs_get(struct task_struct
*target
,
821 const struct user_regset
*regset
,
822 unsigned int pos
, unsigned int count
,
823 void *kbuf
, void __user
*ubuf
)
825 if (target
== current
)
826 save_access_regs(target
->thread
.acrs
);
829 compat_ulong_t
*k
= kbuf
;
831 *k
++ = __peek_user_compat(target
, pos
);
836 compat_ulong_t __user
*u
= ubuf
;
838 if (__put_user(__peek_user_compat(target
, pos
), u
++))
847 static int s390_compat_regs_set(struct task_struct
*target
,
848 const struct user_regset
*regset
,
849 unsigned int pos
, unsigned int count
,
850 const void *kbuf
, const void __user
*ubuf
)
854 if (target
== current
)
855 save_access_regs(target
->thread
.acrs
);
858 const compat_ulong_t
*k
= kbuf
;
859 while (count
> 0 && !rc
) {
860 rc
= __poke_user_compat(target
, pos
, *k
++);
865 const compat_ulong_t __user
*u
= ubuf
;
866 while (count
> 0 && !rc
) {
868 rc
= __get_user(word
, u
++);
871 rc
= __poke_user_compat(target
, pos
, word
);
877 if (rc
== 0 && target
== current
)
878 restore_access_regs(target
->thread
.acrs
);
883 static int s390_compat_regs_high_get(struct task_struct
*target
,
884 const struct user_regset
*regset
,
885 unsigned int pos
, unsigned int count
,
886 void *kbuf
, void __user
*ubuf
)
888 compat_ulong_t
*gprs_high
;
890 gprs_high
= (compat_ulong_t
*)
891 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
893 compat_ulong_t
*k
= kbuf
;
900 compat_ulong_t __user
*u
= ubuf
;
902 if (__put_user(*gprs_high
, u
++))
911 static int s390_compat_regs_high_set(struct task_struct
*target
,
912 const struct user_regset
*regset
,
913 unsigned int pos
, unsigned int count
,
914 const void *kbuf
, const void __user
*ubuf
)
916 compat_ulong_t
*gprs_high
;
919 gprs_high
= (compat_ulong_t
*)
920 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
922 const compat_ulong_t
*k
= kbuf
;
929 const compat_ulong_t __user
*u
= ubuf
;
930 while (count
> 0 && !rc
) {
932 rc
= __get_user(word
, u
++);
944 static const struct user_regset s390_compat_regsets
[] = {
946 .core_note_type
= NT_PRSTATUS
,
947 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
948 .size
= sizeof(compat_long_t
),
949 .align
= sizeof(compat_long_t
),
950 .get
= s390_compat_regs_get
,
951 .set
= s390_compat_regs_set
,
954 .core_note_type
= NT_PRFPREG
,
955 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
956 .size
= sizeof(compat_long_t
),
957 .align
= sizeof(compat_long_t
),
958 .get
= s390_fpregs_get
,
959 .set
= s390_fpregs_set
,
961 [REGSET_GENERAL_EXTENDED
] = {
962 .core_note_type
= NT_PRXSTATUS
,
963 .n
= sizeof(s390_compat_regs_high
) / sizeof(compat_long_t
),
964 .size
= sizeof(compat_long_t
),
965 .align
= sizeof(compat_long_t
),
966 .get
= s390_compat_regs_high_get
,
967 .set
= s390_compat_regs_high_set
,
971 static const struct user_regset_view user_s390_compat_view
= {
973 .e_machine
= EM_S390
,
974 .regsets
= s390_compat_regsets
,
975 .n
= ARRAY_SIZE(s390_compat_regsets
)
979 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
982 if (test_tsk_thread_flag(task
, TIF_31BIT
))
983 return &user_s390_compat_view
;
985 return &user_s390_view
;