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/smp_lock.h>
30 #include <linux/errno.h>
31 #include <linux/ptrace.h>
32 #include <linux/user.h>
33 #include <linux/security.h>
34 #include <linux/audit.h>
35 #include <linux/signal.h>
36 #include <linux/elf.h>
37 #include <linux/regset.h>
39 #include <asm/segment.h>
41 #include <asm/pgtable.h>
42 #include <asm/pgalloc.h>
43 #include <asm/system.h>
44 #include <asm/uaccess.h>
45 #include <asm/unistd.h>
49 #include "compat_ptrace.h"
58 FixPerRegisters(struct task_struct
*task
)
63 regs
= task_pt_regs(task
);
64 per_info
= (per_struct
*) &task
->thread
.per_info
;
65 per_info
->control_regs
.bits
.em_instruction_fetch
=
66 per_info
->single_step
| per_info
->instruction_fetch
;
68 if (per_info
->single_step
) {
69 per_info
->control_regs
.bits
.starting_addr
= 0;
71 if (test_thread_flag(TIF_31BIT
))
72 per_info
->control_regs
.bits
.ending_addr
= 0x7fffffffUL
;
75 per_info
->control_regs
.bits
.ending_addr
= PSW_ADDR_INSN
;
77 per_info
->control_regs
.bits
.starting_addr
=
78 per_info
->starting_addr
;
79 per_info
->control_regs
.bits
.ending_addr
=
80 per_info
->ending_addr
;
83 * if any of the control reg tracing bits are on
84 * we switch on per in the psw
86 if (per_info
->control_regs
.words
.cr
[0] & PER_EM_MASK
)
87 regs
->psw
.mask
|= PSW_MASK_PER
;
89 regs
->psw
.mask
&= ~PSW_MASK_PER
;
91 if (per_info
->control_regs
.bits
.em_storage_alteration
)
92 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 1;
94 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 0;
97 void user_enable_single_step(struct task_struct
*task
)
99 task
->thread
.per_info
.single_step
= 1;
100 FixPerRegisters(task
);
103 void user_disable_single_step(struct task_struct
*task
)
105 task
->thread
.per_info
.single_step
= 0;
106 FixPerRegisters(task
);
110 * Called by kernel/ptrace.c when detaching..
112 * Make sure single step bits etc are not set.
115 ptrace_disable(struct task_struct
*child
)
117 /* make sure the single step bit is not set. */
118 user_disable_single_step(child
);
122 # define __ADDR_MASK 3
124 # define __ADDR_MASK 7
128 * Read the word at offset addr from the user area of a process. The
129 * trouble here is that the information is littered over different
130 * locations. The process registers are found on the kernel stack,
131 * the floating point stuff and the trace settings are stored in
132 * the task structure. In addition the different structures in
133 * struct user contain pad bytes that should be read as zeroes.
136 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
138 struct user
*dummy
= NULL
;
141 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
143 * psw and gprs are stored on the stack
145 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
146 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
)
147 /* Remove per bit from user psw. */
148 tmp
&= ~PSW_MASK_PER
;
150 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
152 * access registers are stored in the thread structure
154 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
157 * Very special case: old & broken 64 bit gdb reading
158 * from acrs[15]. Result is a 64 bit value. Read the
159 * 32 bit acrs[15] value and shift it by 32. Sick...
161 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
162 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
165 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
167 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
169 * orig_gpr2 is stored on the kernel stack
171 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
173 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
175 * prevent reads of padding hole between
176 * orig_gpr2 and fp_regs on s390.
180 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
182 * floating point regs. are stored in the thread structure
184 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
185 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
186 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
)
187 tmp
&= (unsigned long) FPC_VALID_MASK
188 << (BITS_PER_LONG
- 32);
190 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
192 * per_info is found in the thread structure
194 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
195 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
);
204 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
206 struct user
*dummy
= NULL
;
210 * Stupid gdb peeks/pokes the access registers in 64 bit with
211 * an alignment of 4. Programmers from hell...
215 if (addr
>= (addr_t
) &dummy
->regs
.acrs
&&
216 addr
< (addr_t
) &dummy
->regs
.orig_gpr2
)
219 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
222 tmp
= __peek_user(child
, addr
);
223 return put_user(tmp
, (addr_t __user
*) data
);
227 * Write a word to the user area of a process at location addr. This
228 * operation does have an additional problem compared to peek_user.
229 * Stores to the program status word and on the floating point
230 * control register needs to get checked for validity.
232 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
234 struct user
*dummy
= NULL
;
237 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
239 * psw and gprs are stored on the stack
241 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
&&
243 data
!= PSW_MASK_MERGE(psw_user32_bits
, data
) &&
245 data
!= PSW_MASK_MERGE(psw_user_bits
, data
))
246 /* Invalid psw mask. */
249 if (addr
== (addr_t
) &dummy
->regs
.psw
.addr
)
250 /* I'd like to reject addresses without the
251 high order bit but older gdb's rely on it */
252 data
|= PSW_ADDR_AMODE
;
254 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
256 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
258 * access registers are stored in the thread structure
260 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
263 * Very special case: old & broken 64 bit gdb writing
264 * to acrs[15] with a 64 bit value. Ignore the lower
265 * half of the value and write the upper 32 bit to
268 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
269 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
272 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
274 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
276 * orig_gpr2 is stored on the kernel stack
278 task_pt_regs(child
)->orig_gpr2
= data
;
280 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
282 * prevent writes of padding hole between
283 * orig_gpr2 and fp_regs on s390.
287 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
289 * floating point regs. are stored in the thread structure
291 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
&&
292 (data
& ~((unsigned long) FPC_VALID_MASK
293 << (BITS_PER_LONG
- 32))) != 0)
295 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
296 *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = data
;
298 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
300 * per_info is found in the thread structure
302 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
303 *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
) = data
;
307 FixPerRegisters(child
);
312 poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
314 struct user
*dummy
= NULL
;
318 * Stupid gdb peeks/pokes the access registers in 64 bit with
319 * an alignment of 4. Programmers from hell indeed...
323 if (addr
>= (addr_t
) &dummy
->regs
.acrs
&&
324 addr
< (addr_t
) &dummy
->regs
.orig_gpr2
)
327 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
330 return __poke_user(child
, addr
, data
);
333 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
339 case PTRACE_PEEKTEXT
:
340 case PTRACE_PEEKDATA
:
341 /* Remove high order bit from address (only for 31 bit). */
342 addr
&= PSW_ADDR_INSN
;
343 /* read word at location addr. */
344 return generic_ptrace_peekdata(child
, addr
, data
);
347 /* read the word at location addr in the USER area. */
348 return peek_user(child
, addr
, data
);
350 case PTRACE_POKETEXT
:
351 case PTRACE_POKEDATA
:
352 /* Remove high order bit from address (only for 31 bit). */
353 addr
&= PSW_ADDR_INSN
;
354 /* write the word at location addr. */
355 return generic_ptrace_pokedata(child
, addr
, data
);
358 /* write the word at location addr in the USER area */
359 return poke_user(child
, addr
, data
);
361 case PTRACE_PEEKUSR_AREA
:
362 case PTRACE_POKEUSR_AREA
:
363 if (copy_from_user(&parea
, (void __force __user
*) addr
,
366 addr
= parea
.kernel_addr
;
367 data
= parea
.process_addr
;
369 while (copied
< parea
.len
) {
370 if (request
== PTRACE_PEEKUSR_AREA
)
371 ret
= peek_user(child
, addr
, data
);
375 (addr_t __force __user
*) data
))
377 ret
= poke_user(child
, addr
, utmp
);
381 addr
+= sizeof(unsigned long);
382 data
+= sizeof(unsigned long);
383 copied
+= sizeof(unsigned long);
387 return ptrace_request(child
, request
, addr
, data
);
392 * Now the fun part starts... a 31 bit program running in the
393 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
394 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
395 * to handle, the difference to the 64 bit versions of the requests
396 * is that the access is done in multiples of 4 byte instead of
397 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
398 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
399 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
400 * is a 31 bit program too, the content of struct user can be
401 * emulated. A 31 bit program peeking into the struct user of
402 * a 64 bit program is a no-no.
406 * Same as peek_user but for a 31 bit program.
408 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
410 struct user32
*dummy32
= NULL
;
411 per_struct32
*dummy_per32
= NULL
;
415 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
417 * psw and gprs are stored on the stack
419 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
420 /* Fake a 31 bit psw mask. */
421 tmp
= (__u32
)(task_pt_regs(child
)->psw
.mask
>> 32);
422 tmp
= PSW32_MASK_MERGE(psw32_user_bits
, tmp
);
423 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
424 /* Fake a 31 bit psw address. */
425 tmp
= (__u32
) task_pt_regs(child
)->psw
.addr
|
429 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
+
432 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
434 * access registers are stored in the thread structure
436 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
437 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
439 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
441 * orig_gpr2 is stored on the kernel stack
443 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
445 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
447 * prevent reads of padding hole between
448 * orig_gpr2 and fp_regs on s390.
452 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
454 * floating point regs. are stored in the thread structure
456 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
457 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
459 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
461 * per_info is found in the thread structure
463 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
464 /* This is magic. See per_struct and per_struct32. */
465 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
466 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
467 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
468 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
469 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
470 offset
= offset
*2 + 4;
473 tmp
= *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
);
481 static int peek_user_compat(struct task_struct
*child
,
482 addr_t addr
, addr_t data
)
486 if (!test_thread_flag(TIF_31BIT
) ||
487 (addr
& 3) || addr
> sizeof(struct user
) - 3)
490 tmp
= __peek_user_compat(child
, addr
);
491 return put_user(tmp
, (__u32 __user
*) data
);
495 * Same as poke_user but for a 31 bit program.
497 static int __poke_user_compat(struct task_struct
*child
,
498 addr_t addr
, addr_t data
)
500 struct user32
*dummy32
= NULL
;
501 per_struct32
*dummy_per32
= NULL
;
502 __u32 tmp
= (__u32
) data
;
505 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
507 * psw, gprs, acrs and orig_gpr2 are stored on the stack
509 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
510 /* Build a 64 bit psw mask from 31 bit mask. */
511 if (tmp
!= PSW32_MASK_MERGE(psw32_user_bits
, tmp
))
512 /* Invalid psw mask. */
514 task_pt_regs(child
)->psw
.mask
=
515 PSW_MASK_MERGE(psw_user32_bits
, (__u64
) tmp
<< 32);
516 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
517 /* Build a 64 bit psw address from 31 bit address. */
518 task_pt_regs(child
)->psw
.addr
=
519 (__u64
) tmp
& PSW32_ADDR_INSN
;
522 *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
525 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
527 * access registers are stored in the thread structure
529 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
530 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
532 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
534 * orig_gpr2 is stored on the kernel stack
536 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
538 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
540 * prevent writess of padding hole between
541 * orig_gpr2 and fp_regs on s390.
545 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
547 * floating point regs. are stored in the thread structure
549 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
550 (tmp
& ~FPC_VALID_MASK
) != 0)
551 /* Invalid floating point control. */
553 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
554 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
556 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
558 * per_info is found in the thread structure.
560 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
562 * This is magic. See per_struct and per_struct32.
563 * By incident the offsets in per_struct are exactly
564 * twice the offsets in per_struct32 for all fields.
565 * The 8 byte fields need special handling though,
566 * because the second half (bytes 4-7) is needed and
567 * not the first half.
569 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
570 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
571 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
572 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
573 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
574 offset
= offset
*2 + 4;
577 *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
) = tmp
;
581 FixPerRegisters(child
);
585 static int poke_user_compat(struct task_struct
*child
,
586 addr_t addr
, addr_t data
)
588 if (!test_thread_flag(TIF_31BIT
) ||
589 (addr
& 3) || addr
> sizeof(struct user32
) - 3)
592 return __poke_user_compat(child
, addr
, data
);
595 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
596 compat_ulong_t caddr
, compat_ulong_t cdata
)
598 unsigned long addr
= caddr
;
599 unsigned long data
= cdata
;
600 ptrace_area_emu31 parea
;
605 /* read the word at location addr in the USER area. */
606 return peek_user_compat(child
, addr
, data
);
609 /* write the word at location addr in the USER area */
610 return poke_user_compat(child
, addr
, data
);
612 case PTRACE_PEEKUSR_AREA
:
613 case PTRACE_POKEUSR_AREA
:
614 if (copy_from_user(&parea
, (void __force __user
*) addr
,
617 addr
= parea
.kernel_addr
;
618 data
= parea
.process_addr
;
620 while (copied
< parea
.len
) {
621 if (request
== PTRACE_PEEKUSR_AREA
)
622 ret
= peek_user_compat(child
, addr
, data
);
626 (__u32 __force __user
*) data
))
628 ret
= poke_user_compat(child
, addr
, utmp
);
632 addr
+= sizeof(unsigned int);
633 data
+= sizeof(unsigned int);
634 copied
+= sizeof(unsigned int);
638 return compat_ptrace_request(child
, request
, addr
, data
);
643 syscall_trace(struct pt_regs
*regs
, int entryexit
)
645 if (unlikely(current
->audit_context
) && entryexit
)
646 audit_syscall_exit(AUDITSC_RESULT(regs
->gprs
[2]), regs
->gprs
[2]);
648 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
650 if (!(current
->ptrace
& PT_PTRACED
))
652 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
656 * If the debuffer has set an invalid system call number,
657 * we prepare to skip the system call restart handling.
659 if (!entryexit
&& regs
->gprs
[2] >= NR_syscalls
)
663 * this isn't the same as continuing with a signal, but it will do
664 * for normal use. strace only continues with a signal if the
665 * stopping signal is not SIGTRAP. -brl
667 if (current
->exit_code
) {
668 send_sig(current
->exit_code
, current
, 1);
669 current
->exit_code
= 0;
672 if (unlikely(current
->audit_context
) && !entryexit
)
673 audit_syscall_entry(test_thread_flag(TIF_31BIT
)?AUDIT_ARCH_S390
:AUDIT_ARCH_S390X
,
674 regs
->gprs
[2], regs
->orig_gpr2
, regs
->gprs
[3],
675 regs
->gprs
[4], regs
->gprs
[5]);
679 * user_regset definitions.
682 static int s390_regs_get(struct task_struct
*target
,
683 const struct user_regset
*regset
,
684 unsigned int pos
, unsigned int count
,
685 void *kbuf
, void __user
*ubuf
)
687 if (target
== current
)
688 save_access_regs(target
->thread
.acrs
);
691 unsigned long *k
= kbuf
;
693 *k
++ = __peek_user(target
, pos
);
698 unsigned long __user
*u
= ubuf
;
700 if (__put_user(__peek_user(target
, pos
), u
++))
709 static int s390_regs_set(struct task_struct
*target
,
710 const struct user_regset
*regset
,
711 unsigned int pos
, unsigned int count
,
712 const void *kbuf
, const void __user
*ubuf
)
716 if (target
== current
)
717 save_access_regs(target
->thread
.acrs
);
720 const unsigned long *k
= kbuf
;
721 while (count
> 0 && !rc
) {
722 rc
= __poke_user(target
, pos
, *k
++);
727 const unsigned long __user
*u
= ubuf
;
728 while (count
> 0 && !rc
) {
730 rc
= __get_user(word
, u
++);
733 rc
= __poke_user(target
, pos
, word
);
739 if (rc
== 0 && target
== current
)
740 restore_access_regs(target
->thread
.acrs
);
745 static int s390_fpregs_get(struct task_struct
*target
,
746 const struct user_regset
*regset
, unsigned int pos
,
747 unsigned int count
, void *kbuf
, void __user
*ubuf
)
749 if (target
== current
)
750 save_fp_regs(&target
->thread
.fp_regs
);
752 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
753 &target
->thread
.fp_regs
, 0, -1);
756 static int s390_fpregs_set(struct task_struct
*target
,
757 const struct user_regset
*regset
, unsigned int pos
,
758 unsigned int count
, const void *kbuf
,
759 const void __user
*ubuf
)
763 if (target
== current
)
764 save_fp_regs(&target
->thread
.fp_regs
);
766 /* If setting FPC, must validate it first. */
767 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
768 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
769 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
770 0, offsetof(s390_fp_regs
, fprs
));
773 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
775 target
->thread
.fp_regs
.fpc
= fpc
[0];
778 if (rc
== 0 && count
> 0)
779 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
780 target
->thread
.fp_regs
.fprs
,
781 offsetof(s390_fp_regs
, fprs
), -1);
783 if (rc
== 0 && target
== current
)
784 restore_fp_regs(&target
->thread
.fp_regs
);
789 static const struct user_regset s390_regsets
[] = {
791 .core_note_type
= NT_PRSTATUS
,
792 .n
= sizeof(s390_regs
) / sizeof(long),
793 .size
= sizeof(long),
794 .align
= sizeof(long),
795 .get
= s390_regs_get
,
796 .set
= s390_regs_set
,
799 .core_note_type
= NT_PRFPREG
,
800 .n
= sizeof(s390_fp_regs
) / sizeof(long),
801 .size
= sizeof(long),
802 .align
= sizeof(long),
803 .get
= s390_fpregs_get
,
804 .set
= s390_fpregs_set
,
808 static const struct user_regset_view user_s390_view
= {
810 .e_machine
= EM_S390
,
811 .regsets
= s390_regsets
,
812 .n
= ARRAY_SIZE(s390_regsets
)
816 static int s390_compat_regs_get(struct task_struct
*target
,
817 const struct user_regset
*regset
,
818 unsigned int pos
, unsigned int count
,
819 void *kbuf
, void __user
*ubuf
)
821 if (target
== current
)
822 save_access_regs(target
->thread
.acrs
);
825 compat_ulong_t
*k
= kbuf
;
827 *k
++ = __peek_user_compat(target
, pos
);
832 compat_ulong_t __user
*u
= ubuf
;
834 if (__put_user(__peek_user_compat(target
, pos
), u
++))
843 static int s390_compat_regs_set(struct task_struct
*target
,
844 const struct user_regset
*regset
,
845 unsigned int pos
, unsigned int count
,
846 const void *kbuf
, const void __user
*ubuf
)
850 if (target
== current
)
851 save_access_regs(target
->thread
.acrs
);
854 const compat_ulong_t
*k
= kbuf
;
855 while (count
> 0 && !rc
) {
856 rc
= __poke_user_compat(target
, pos
, *k
++);
861 const compat_ulong_t __user
*u
= ubuf
;
862 while (count
> 0 && !rc
) {
864 rc
= __get_user(word
, u
++);
867 rc
= __poke_user_compat(target
, pos
, word
);
873 if (rc
== 0 && target
== current
)
874 restore_access_regs(target
->thread
.acrs
);
879 static const struct user_regset s390_compat_regsets
[] = {
881 .core_note_type
= NT_PRSTATUS
,
882 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
883 .size
= sizeof(compat_long_t
),
884 .align
= sizeof(compat_long_t
),
885 .get
= s390_compat_regs_get
,
886 .set
= s390_compat_regs_set
,
889 .core_note_type
= NT_PRFPREG
,
890 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
891 .size
= sizeof(compat_long_t
),
892 .align
= sizeof(compat_long_t
),
893 .get
= s390_fpregs_get
,
894 .set
= s390_fpregs_set
,
898 static const struct user_regset_view user_s390_compat_view
= {
900 .e_machine
= EM_S390
,
901 .regsets
= s390_compat_regsets
,
902 .n
= ARRAY_SIZE(s390_compat_regsets
)
906 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
909 if (test_tsk_thread_flag(task
, TIF_31BIT
))
910 return &user_s390_compat_view
;
912 return &user_s390_view
;