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>
38 #include <linux/tracehook.h>
40 #include <asm/segment.h>
42 #include <asm/pgtable.h>
43 #include <asm/pgalloc.h>
44 #include <asm/system.h>
45 #include <asm/uaccess.h>
46 #include <asm/unistd.h>
50 #include "compat_ptrace.h"
59 FixPerRegisters(struct task_struct
*task
)
64 regs
= task_pt_regs(task
);
65 per_info
= (per_struct
*) &task
->thread
.per_info
;
66 per_info
->control_regs
.bits
.em_instruction_fetch
=
67 per_info
->single_step
| per_info
->instruction_fetch
;
69 if (per_info
->single_step
) {
70 per_info
->control_regs
.bits
.starting_addr
= 0;
72 if (test_thread_flag(TIF_31BIT
))
73 per_info
->control_regs
.bits
.ending_addr
= 0x7fffffffUL
;
76 per_info
->control_regs
.bits
.ending_addr
= PSW_ADDR_INSN
;
78 per_info
->control_regs
.bits
.starting_addr
=
79 per_info
->starting_addr
;
80 per_info
->control_regs
.bits
.ending_addr
=
81 per_info
->ending_addr
;
84 * if any of the control reg tracing bits are on
85 * we switch on per in the psw
87 if (per_info
->control_regs
.words
.cr
[0] & PER_EM_MASK
)
88 regs
->psw
.mask
|= PSW_MASK_PER
;
90 regs
->psw
.mask
&= ~PSW_MASK_PER
;
92 if (per_info
->control_regs
.bits
.em_storage_alteration
)
93 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 1;
95 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 0;
98 void user_enable_single_step(struct task_struct
*task
)
100 task
->thread
.per_info
.single_step
= 1;
101 FixPerRegisters(task
);
104 void user_disable_single_step(struct task_struct
*task
)
106 task
->thread
.per_info
.single_step
= 0;
107 FixPerRegisters(task
);
111 * Called by kernel/ptrace.c when detaching..
113 * Make sure single step bits etc are not set.
116 ptrace_disable(struct task_struct
*child
)
118 /* make sure the single step bit is not set. */
119 user_disable_single_step(child
);
123 # define __ADDR_MASK 3
125 # define __ADDR_MASK 7
129 * Read the word at offset addr from the user area of a process. The
130 * trouble here is that the information is littered over different
131 * locations. The process registers are found on the kernel stack,
132 * the floating point stuff and the trace settings are stored in
133 * the task structure. In addition the different structures in
134 * struct user contain pad bytes that should be read as zeroes.
137 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
139 struct user
*dummy
= NULL
;
142 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
144 * psw and gprs are stored on the stack
146 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
147 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
)
148 /* Remove per bit from user psw. */
149 tmp
&= ~PSW_MASK_PER
;
151 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
153 * access registers are stored in the thread structure
155 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
158 * Very special case: old & broken 64 bit gdb reading
159 * from acrs[15]. Result is a 64 bit value. Read the
160 * 32 bit acrs[15] value and shift it by 32. Sick...
162 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
163 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
166 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
168 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
170 * orig_gpr2 is stored on the kernel stack
172 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
174 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
176 * prevent reads of padding hole between
177 * orig_gpr2 and fp_regs on s390.
181 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
183 * floating point regs. are stored in the thread structure
185 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
186 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
187 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
)
188 tmp
&= (unsigned long) FPC_VALID_MASK
189 << (BITS_PER_LONG
- 32);
191 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
193 * per_info is found in the thread structure
195 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
196 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
);
205 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
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
) &((struct user
*) NULL
)->regs
.acrs
&&
216 addr
< (addr_t
) &((struct user
*) NULL
)->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
)
317 * Stupid gdb peeks/pokes the access registers in 64 bit with
318 * an alignment of 4. Programmers from hell indeed...
322 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
323 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
326 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
329 return __poke_user(child
, addr
, data
);
332 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
338 case PTRACE_PEEKTEXT
:
339 case PTRACE_PEEKDATA
:
340 /* Remove high order bit from address (only for 31 bit). */
341 addr
&= PSW_ADDR_INSN
;
342 /* read word at location addr. */
343 return generic_ptrace_peekdata(child
, addr
, data
);
346 /* read the word at location addr in the USER area. */
347 return peek_user(child
, addr
, data
);
349 case PTRACE_POKETEXT
:
350 case PTRACE_POKEDATA
:
351 /* Remove high order bit from address (only for 31 bit). */
352 addr
&= PSW_ADDR_INSN
;
353 /* write the word at location addr. */
354 return generic_ptrace_pokedata(child
, addr
, data
);
357 /* write the word at location addr in the USER area */
358 return poke_user(child
, addr
, data
);
360 case PTRACE_PEEKUSR_AREA
:
361 case PTRACE_POKEUSR_AREA
:
362 if (copy_from_user(&parea
, (void __force __user
*) addr
,
365 addr
= parea
.kernel_addr
;
366 data
= parea
.process_addr
;
368 while (copied
< parea
.len
) {
369 if (request
== PTRACE_PEEKUSR_AREA
)
370 ret
= peek_user(child
, addr
, data
);
374 (addr_t __force __user
*) data
))
376 ret
= poke_user(child
, addr
, utmp
);
380 addr
+= sizeof(unsigned long);
381 data
+= sizeof(unsigned long);
382 copied
+= sizeof(unsigned long);
386 return ptrace_request(child
, request
, addr
, data
);
391 * Now the fun part starts... a 31 bit program running in the
392 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
393 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
394 * to handle, the difference to the 64 bit versions of the requests
395 * is that the access is done in multiples of 4 byte instead of
396 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
397 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
398 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
399 * is a 31 bit program too, the content of struct user can be
400 * emulated. A 31 bit program peeking into the struct user of
401 * a 64 bit program is a no-no.
405 * Same as peek_user but for a 31 bit program.
407 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
409 struct user32
*dummy32
= NULL
;
410 per_struct32
*dummy_per32
= NULL
;
414 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
416 * psw and gprs are stored on the stack
418 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
419 /* Fake a 31 bit psw mask. */
420 tmp
= (__u32
)(task_pt_regs(child
)->psw
.mask
>> 32);
421 tmp
= PSW32_MASK_MERGE(psw32_user_bits
, tmp
);
422 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
423 /* Fake a 31 bit psw address. */
424 tmp
= (__u32
) task_pt_regs(child
)->psw
.addr
|
428 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
+
431 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
433 * access registers are stored in the thread structure
435 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
436 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
438 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
440 * orig_gpr2 is stored on the kernel stack
442 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
444 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
446 * prevent reads of padding hole between
447 * orig_gpr2 and fp_regs on s390.
451 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
453 * floating point regs. are stored in the thread structure
455 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
456 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
458 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
460 * per_info is found in the thread structure
462 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
463 /* This is magic. See per_struct and per_struct32. */
464 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
465 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
466 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
467 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
468 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
469 offset
= offset
*2 + 4;
472 tmp
= *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
);
480 static int peek_user_compat(struct task_struct
*child
,
481 addr_t addr
, addr_t data
)
485 if (!test_thread_flag(TIF_31BIT
) ||
486 (addr
& 3) || addr
> sizeof(struct user
) - 3)
489 tmp
= __peek_user_compat(child
, addr
);
490 return put_user(tmp
, (__u32 __user
*) data
);
494 * Same as poke_user but for a 31 bit program.
496 static int __poke_user_compat(struct task_struct
*child
,
497 addr_t addr
, addr_t data
)
499 struct user32
*dummy32
= NULL
;
500 per_struct32
*dummy_per32
= NULL
;
501 __u32 tmp
= (__u32
) data
;
504 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
506 * psw, gprs, acrs and orig_gpr2 are stored on the stack
508 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
509 /* Build a 64 bit psw mask from 31 bit mask. */
510 if (tmp
!= PSW32_MASK_MERGE(psw32_user_bits
, tmp
))
511 /* Invalid psw mask. */
513 task_pt_regs(child
)->psw
.mask
=
514 PSW_MASK_MERGE(psw_user32_bits
, (__u64
) tmp
<< 32);
515 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
516 /* Build a 64 bit psw address from 31 bit address. */
517 task_pt_regs(child
)->psw
.addr
=
518 (__u64
) tmp
& PSW32_ADDR_INSN
;
521 *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
524 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
526 * access registers are stored in the thread structure
528 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
529 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
531 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
533 * orig_gpr2 is stored on the kernel stack
535 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
537 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
539 * prevent writess of padding hole between
540 * orig_gpr2 and fp_regs on s390.
544 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
546 * floating point regs. are stored in the thread structure
548 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
549 (tmp
& ~FPC_VALID_MASK
) != 0)
550 /* Invalid floating point control. */
552 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
553 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
555 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
557 * per_info is found in the thread structure.
559 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
561 * This is magic. See per_struct and per_struct32.
562 * By incident the offsets in per_struct are exactly
563 * twice the offsets in per_struct32 for all fields.
564 * The 8 byte fields need special handling though,
565 * because the second half (bytes 4-7) is needed and
566 * not the first half.
568 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
569 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
570 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
571 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
572 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
573 offset
= offset
*2 + 4;
576 *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
) = tmp
;
580 FixPerRegisters(child
);
584 static int poke_user_compat(struct task_struct
*child
,
585 addr_t addr
, addr_t data
)
587 if (!test_thread_flag(TIF_31BIT
) ||
588 (addr
& 3) || addr
> sizeof(struct user32
) - 3)
591 return __poke_user_compat(child
, addr
, data
);
594 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
595 compat_ulong_t caddr
, compat_ulong_t cdata
)
597 unsigned long addr
= caddr
;
598 unsigned long data
= cdata
;
599 ptrace_area_emu31 parea
;
604 /* read the word at location addr in the USER area. */
605 return peek_user_compat(child
, addr
, data
);
608 /* write the word at location addr in the USER area */
609 return poke_user_compat(child
, addr
, data
);
611 case PTRACE_PEEKUSR_AREA
:
612 case PTRACE_POKEUSR_AREA
:
613 if (copy_from_user(&parea
, (void __force __user
*) addr
,
616 addr
= parea
.kernel_addr
;
617 data
= parea
.process_addr
;
619 while (copied
< parea
.len
) {
620 if (request
== PTRACE_PEEKUSR_AREA
)
621 ret
= peek_user_compat(child
, addr
, data
);
625 (__u32 __force __user
*) data
))
627 ret
= poke_user_compat(child
, addr
, utmp
);
631 addr
+= sizeof(unsigned int);
632 data
+= sizeof(unsigned int);
633 copied
+= sizeof(unsigned int);
637 return compat_ptrace_request(child
, request
, addr
, data
);
641 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
646 * The sysc_tracesys code in entry.S stored the system
647 * call number to gprs[2].
650 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
651 (tracehook_report_syscall_entry(regs
) ||
652 regs
->gprs
[2] >= NR_syscalls
)) {
654 * Tracing decided this syscall should not happen or the
655 * debugger stored an invalid system call number. Skip
656 * the system call and the system call restart handling.
662 if (unlikely(current
->audit_context
))
663 audit_syscall_entry(test_thread_flag(TIF_31BIT
) ?
664 AUDIT_ARCH_S390
: AUDIT_ARCH_S390X
,
665 regs
->gprs
[2], regs
->orig_gpr2
,
666 regs
->gprs
[3], regs
->gprs
[4],
671 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
673 if (unlikely(current
->audit_context
))
674 audit_syscall_exit(AUDITSC_RESULT(regs
->gprs
[2]),
677 if (test_thread_flag(TIF_SYSCALL_TRACE
))
678 tracehook_report_syscall_exit(regs
, 0);
682 * user_regset definitions.
685 static int s390_regs_get(struct task_struct
*target
,
686 const struct user_regset
*regset
,
687 unsigned int pos
, unsigned int count
,
688 void *kbuf
, void __user
*ubuf
)
690 if (target
== current
)
691 save_access_regs(target
->thread
.acrs
);
694 unsigned long *k
= kbuf
;
696 *k
++ = __peek_user(target
, pos
);
701 unsigned long __user
*u
= ubuf
;
703 if (__put_user(__peek_user(target
, pos
), u
++))
712 static int s390_regs_set(struct task_struct
*target
,
713 const struct user_regset
*regset
,
714 unsigned int pos
, unsigned int count
,
715 const void *kbuf
, const void __user
*ubuf
)
719 if (target
== current
)
720 save_access_regs(target
->thread
.acrs
);
723 const unsigned long *k
= kbuf
;
724 while (count
> 0 && !rc
) {
725 rc
= __poke_user(target
, pos
, *k
++);
730 const unsigned long __user
*u
= ubuf
;
731 while (count
> 0 && !rc
) {
733 rc
= __get_user(word
, u
++);
736 rc
= __poke_user(target
, pos
, word
);
742 if (rc
== 0 && target
== current
)
743 restore_access_regs(target
->thread
.acrs
);
748 static int s390_fpregs_get(struct task_struct
*target
,
749 const struct user_regset
*regset
, unsigned int pos
,
750 unsigned int count
, void *kbuf
, void __user
*ubuf
)
752 if (target
== current
)
753 save_fp_regs(&target
->thread
.fp_regs
);
755 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
756 &target
->thread
.fp_regs
, 0, -1);
759 static int s390_fpregs_set(struct task_struct
*target
,
760 const struct user_regset
*regset
, unsigned int pos
,
761 unsigned int count
, const void *kbuf
,
762 const void __user
*ubuf
)
766 if (target
== current
)
767 save_fp_regs(&target
->thread
.fp_regs
);
769 /* If setting FPC, must validate it first. */
770 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
771 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
772 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
773 0, offsetof(s390_fp_regs
, fprs
));
776 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
778 target
->thread
.fp_regs
.fpc
= fpc
[0];
781 if (rc
== 0 && count
> 0)
782 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
783 target
->thread
.fp_regs
.fprs
,
784 offsetof(s390_fp_regs
, fprs
), -1);
786 if (rc
== 0 && target
== current
)
787 restore_fp_regs(&target
->thread
.fp_regs
);
792 static const struct user_regset s390_regsets
[] = {
794 .core_note_type
= NT_PRSTATUS
,
795 .n
= sizeof(s390_regs
) / sizeof(long),
796 .size
= sizeof(long),
797 .align
= sizeof(long),
798 .get
= s390_regs_get
,
799 .set
= s390_regs_set
,
802 .core_note_type
= NT_PRFPREG
,
803 .n
= sizeof(s390_fp_regs
) / sizeof(long),
804 .size
= sizeof(long),
805 .align
= sizeof(long),
806 .get
= s390_fpregs_get
,
807 .set
= s390_fpregs_set
,
811 static const struct user_regset_view user_s390_view
= {
813 .e_machine
= EM_S390
,
814 .regsets
= s390_regsets
,
815 .n
= ARRAY_SIZE(s390_regsets
)
819 static int s390_compat_regs_get(struct task_struct
*target
,
820 const struct user_regset
*regset
,
821 unsigned int pos
, unsigned int count
,
822 void *kbuf
, void __user
*ubuf
)
824 if (target
== current
)
825 save_access_regs(target
->thread
.acrs
);
828 compat_ulong_t
*k
= kbuf
;
830 *k
++ = __peek_user_compat(target
, pos
);
835 compat_ulong_t __user
*u
= ubuf
;
837 if (__put_user(__peek_user_compat(target
, pos
), u
++))
846 static int s390_compat_regs_set(struct task_struct
*target
,
847 const struct user_regset
*regset
,
848 unsigned int pos
, unsigned int count
,
849 const void *kbuf
, const void __user
*ubuf
)
853 if (target
== current
)
854 save_access_regs(target
->thread
.acrs
);
857 const compat_ulong_t
*k
= kbuf
;
858 while (count
> 0 && !rc
) {
859 rc
= __poke_user_compat(target
, pos
, *k
++);
864 const compat_ulong_t __user
*u
= ubuf
;
865 while (count
> 0 && !rc
) {
867 rc
= __get_user(word
, u
++);
870 rc
= __poke_user_compat(target
, pos
, word
);
876 if (rc
== 0 && target
== current
)
877 restore_access_regs(target
->thread
.acrs
);
882 static const struct user_regset s390_compat_regsets
[] = {
884 .core_note_type
= NT_PRSTATUS
,
885 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
886 .size
= sizeof(compat_long_t
),
887 .align
= sizeof(compat_long_t
),
888 .get
= s390_compat_regs_get
,
889 .set
= s390_compat_regs_set
,
892 .core_note_type
= NT_PRFPREG
,
893 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
894 .size
= sizeof(compat_long_t
),
895 .align
= sizeof(compat_long_t
),
896 .get
= s390_fpregs_get
,
897 .set
= s390_fpregs_set
,
901 static const struct user_regset_view user_s390_compat_view
= {
903 .e_machine
= EM_S390
,
904 .regsets
= s390_compat_regsets
,
905 .n
= ARRAY_SIZE(s390_compat_regsets
)
909 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
912 if (test_tsk_thread_flag(task
, TIF_31BIT
))
913 return &user_s390_compat_view
;
915 return &user_s390_view
;