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
)
207 struct user
*dummy
= NULL
;
211 * Stupid gdb peeks/pokes the access registers in 64 bit with
212 * an alignment of 4. Programmers from hell...
216 if (addr
>= (addr_t
) &dummy
->regs
.acrs
&&
217 addr
< (addr_t
) &dummy
->regs
.orig_gpr2
)
220 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
223 tmp
= __peek_user(child
, addr
);
224 return put_user(tmp
, (addr_t __user
*) data
);
228 * Write a word to the user area of a process at location addr. This
229 * operation does have an additional problem compared to peek_user.
230 * Stores to the program status word and on the floating point
231 * control register needs to get checked for validity.
233 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
235 struct user
*dummy
= NULL
;
238 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
240 * psw and gprs are stored on the stack
242 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
&&
244 data
!= PSW_MASK_MERGE(psw_user32_bits
, data
) &&
246 data
!= PSW_MASK_MERGE(psw_user_bits
, data
))
247 /* Invalid psw mask. */
250 if (addr
== (addr_t
) &dummy
->regs
.psw
.addr
)
251 /* I'd like to reject addresses without the
252 high order bit but older gdb's rely on it */
253 data
|= PSW_ADDR_AMODE
;
255 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
257 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
259 * access registers are stored in the thread structure
261 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
264 * Very special case: old & broken 64 bit gdb writing
265 * to acrs[15] with a 64 bit value. Ignore the lower
266 * half of the value and write the upper 32 bit to
269 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
270 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
273 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
275 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
277 * orig_gpr2 is stored on the kernel stack
279 task_pt_regs(child
)->orig_gpr2
= data
;
281 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
283 * prevent writes of padding hole between
284 * orig_gpr2 and fp_regs on s390.
288 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
290 * floating point regs. are stored in the thread structure
292 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
&&
293 (data
& ~((unsigned long) FPC_VALID_MASK
294 << (BITS_PER_LONG
- 32))) != 0)
296 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
297 *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = data
;
299 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
301 * per_info is found in the thread structure
303 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
304 *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
) = data
;
308 FixPerRegisters(child
);
313 poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
315 struct user
*dummy
= NULL
;
319 * Stupid gdb peeks/pokes the access registers in 64 bit with
320 * an alignment of 4. Programmers from hell indeed...
324 if (addr
>= (addr_t
) &dummy
->regs
.acrs
&&
325 addr
< (addr_t
) &dummy
->regs
.orig_gpr2
)
328 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
331 return __poke_user(child
, addr
, data
);
334 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
340 case PTRACE_PEEKTEXT
:
341 case PTRACE_PEEKDATA
:
342 /* Remove high order bit from address (only for 31 bit). */
343 addr
&= PSW_ADDR_INSN
;
344 /* read word at location addr. */
345 return generic_ptrace_peekdata(child
, addr
, data
);
348 /* read the word at location addr in the USER area. */
349 return peek_user(child
, addr
, data
);
351 case PTRACE_POKETEXT
:
352 case PTRACE_POKEDATA
:
353 /* Remove high order bit from address (only for 31 bit). */
354 addr
&= PSW_ADDR_INSN
;
355 /* write the word at location addr. */
356 return generic_ptrace_pokedata(child
, addr
, data
);
359 /* write the word at location addr in the USER area */
360 return poke_user(child
, addr
, data
);
362 case PTRACE_PEEKUSR_AREA
:
363 case PTRACE_POKEUSR_AREA
:
364 if (copy_from_user(&parea
, (void __force __user
*) addr
,
367 addr
= parea
.kernel_addr
;
368 data
= parea
.process_addr
;
370 while (copied
< parea
.len
) {
371 if (request
== PTRACE_PEEKUSR_AREA
)
372 ret
= peek_user(child
, addr
, data
);
376 (addr_t __force __user
*) data
))
378 ret
= poke_user(child
, addr
, utmp
);
382 addr
+= sizeof(unsigned long);
383 data
+= sizeof(unsigned long);
384 copied
+= sizeof(unsigned long);
388 return ptrace_request(child
, request
, addr
, data
);
393 * Now the fun part starts... a 31 bit program running in the
394 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
395 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
396 * to handle, the difference to the 64 bit versions of the requests
397 * is that the access is done in multiples of 4 byte instead of
398 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
399 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
400 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
401 * is a 31 bit program too, the content of struct user can be
402 * emulated. A 31 bit program peeking into the struct user of
403 * a 64 bit program is a no-no.
407 * Same as peek_user but for a 31 bit program.
409 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
411 struct user32
*dummy32
= NULL
;
412 per_struct32
*dummy_per32
= NULL
;
416 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
418 * psw and gprs are stored on the stack
420 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
421 /* Fake a 31 bit psw mask. */
422 tmp
= (__u32
)(task_pt_regs(child
)->psw
.mask
>> 32);
423 tmp
= PSW32_MASK_MERGE(psw32_user_bits
, tmp
);
424 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
425 /* Fake a 31 bit psw address. */
426 tmp
= (__u32
) task_pt_regs(child
)->psw
.addr
|
430 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
+
433 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
435 * access registers are stored in the thread structure
437 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
438 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
440 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
442 * orig_gpr2 is stored on the kernel stack
444 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
446 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
448 * prevent reads of padding hole between
449 * orig_gpr2 and fp_regs on s390.
453 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
455 * floating point regs. are stored in the thread structure
457 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
458 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
460 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
462 * per_info is found in the thread structure
464 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
465 /* This is magic. See per_struct and per_struct32. */
466 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
467 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
468 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
469 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
470 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
471 offset
= offset
*2 + 4;
474 tmp
= *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
);
482 static int peek_user_compat(struct task_struct
*child
,
483 addr_t addr
, addr_t data
)
487 if (!test_thread_flag(TIF_31BIT
) ||
488 (addr
& 3) || addr
> sizeof(struct user
) - 3)
491 tmp
= __peek_user_compat(child
, addr
);
492 return put_user(tmp
, (__u32 __user
*) data
);
496 * Same as poke_user but for a 31 bit program.
498 static int __poke_user_compat(struct task_struct
*child
,
499 addr_t addr
, addr_t data
)
501 struct user32
*dummy32
= NULL
;
502 per_struct32
*dummy_per32
= NULL
;
503 __u32 tmp
= (__u32
) data
;
506 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
508 * psw, gprs, acrs and orig_gpr2 are stored on the stack
510 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
511 /* Build a 64 bit psw mask from 31 bit mask. */
512 if (tmp
!= PSW32_MASK_MERGE(psw32_user_bits
, tmp
))
513 /* Invalid psw mask. */
515 task_pt_regs(child
)->psw
.mask
=
516 PSW_MASK_MERGE(psw_user32_bits
, (__u64
) tmp
<< 32);
517 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
518 /* Build a 64 bit psw address from 31 bit address. */
519 task_pt_regs(child
)->psw
.addr
=
520 (__u64
) tmp
& PSW32_ADDR_INSN
;
523 *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
526 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
528 * access registers are stored in the thread structure
530 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
531 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
533 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
535 * orig_gpr2 is stored on the kernel stack
537 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
539 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
541 * prevent writess of padding hole between
542 * orig_gpr2 and fp_regs on s390.
546 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
548 * floating point regs. are stored in the thread structure
550 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
551 (tmp
& ~FPC_VALID_MASK
) != 0)
552 /* Invalid floating point control. */
554 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
555 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
557 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
559 * per_info is found in the thread structure.
561 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
563 * This is magic. See per_struct and per_struct32.
564 * By incident the offsets in per_struct are exactly
565 * twice the offsets in per_struct32 for all fields.
566 * The 8 byte fields need special handling though,
567 * because the second half (bytes 4-7) is needed and
568 * not the first half.
570 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
571 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
572 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
573 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
574 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
575 offset
= offset
*2 + 4;
578 *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
) = tmp
;
582 FixPerRegisters(child
);
586 static int poke_user_compat(struct task_struct
*child
,
587 addr_t addr
, addr_t data
)
589 if (!test_thread_flag(TIF_31BIT
) ||
590 (addr
& 3) || addr
> sizeof(struct user32
) - 3)
593 return __poke_user_compat(child
, addr
, data
);
596 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
597 compat_ulong_t caddr
, compat_ulong_t cdata
)
599 unsigned long addr
= caddr
;
600 unsigned long data
= cdata
;
601 ptrace_area_emu31 parea
;
606 /* read the word at location addr in the USER area. */
607 return peek_user_compat(child
, addr
, data
);
610 /* write the word at location addr in the USER area */
611 return poke_user_compat(child
, addr
, data
);
613 case PTRACE_PEEKUSR_AREA
:
614 case PTRACE_POKEUSR_AREA
:
615 if (copy_from_user(&parea
, (void __force __user
*) addr
,
618 addr
= parea
.kernel_addr
;
619 data
= parea
.process_addr
;
621 while (copied
< parea
.len
) {
622 if (request
== PTRACE_PEEKUSR_AREA
)
623 ret
= peek_user_compat(child
, addr
, data
);
627 (__u32 __force __user
*) data
))
629 ret
= poke_user_compat(child
, addr
, utmp
);
633 addr
+= sizeof(unsigned int);
634 data
+= sizeof(unsigned int);
635 copied
+= sizeof(unsigned int);
639 return compat_ptrace_request(child
, request
, addr
, data
);
643 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
648 * The sysc_tracesys code in entry.S stored the system
649 * call number to gprs[2].
652 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
653 (tracehook_report_syscall_entry(regs
) ||
654 regs
->gprs
[2] >= NR_syscalls
)) {
656 * Tracing decided this syscall should not happen or the
657 * debugger stored an invalid system call number. Skip
658 * the system call and the system call restart handling.
664 if (unlikely(current
->audit_context
))
665 audit_syscall_entry(test_thread_flag(TIF_31BIT
) ?
666 AUDIT_ARCH_S390
: AUDIT_ARCH_S390X
,
667 regs
->gprs
[2], regs
->orig_gpr2
,
668 regs
->gprs
[3], regs
->gprs
[4],
673 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
675 if (unlikely(current
->audit_context
))
676 audit_syscall_exit(AUDITSC_RESULT(regs
->gprs
[2]),
679 if (test_thread_flag(TIF_SYSCALL_TRACE
))
680 tracehook_report_syscall_exit(regs
, 0);
684 * user_regset definitions.
687 static int s390_regs_get(struct task_struct
*target
,
688 const struct user_regset
*regset
,
689 unsigned int pos
, unsigned int count
,
690 void *kbuf
, void __user
*ubuf
)
692 if (target
== current
)
693 save_access_regs(target
->thread
.acrs
);
696 unsigned long *k
= kbuf
;
698 *k
++ = __peek_user(target
, pos
);
703 unsigned long __user
*u
= ubuf
;
705 if (__put_user(__peek_user(target
, pos
), u
++))
714 static int s390_regs_set(struct task_struct
*target
,
715 const struct user_regset
*regset
,
716 unsigned int pos
, unsigned int count
,
717 const void *kbuf
, const void __user
*ubuf
)
721 if (target
== current
)
722 save_access_regs(target
->thread
.acrs
);
725 const unsigned long *k
= kbuf
;
726 while (count
> 0 && !rc
) {
727 rc
= __poke_user(target
, pos
, *k
++);
732 const unsigned long __user
*u
= ubuf
;
733 while (count
> 0 && !rc
) {
735 rc
= __get_user(word
, u
++);
738 rc
= __poke_user(target
, pos
, word
);
744 if (rc
== 0 && target
== current
)
745 restore_access_regs(target
->thread
.acrs
);
750 static int s390_fpregs_get(struct task_struct
*target
,
751 const struct user_regset
*regset
, unsigned int pos
,
752 unsigned int count
, void *kbuf
, void __user
*ubuf
)
754 if (target
== current
)
755 save_fp_regs(&target
->thread
.fp_regs
);
757 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
758 &target
->thread
.fp_regs
, 0, -1);
761 static int s390_fpregs_set(struct task_struct
*target
,
762 const struct user_regset
*regset
, unsigned int pos
,
763 unsigned int count
, const void *kbuf
,
764 const void __user
*ubuf
)
768 if (target
== current
)
769 save_fp_regs(&target
->thread
.fp_regs
);
771 /* If setting FPC, must validate it first. */
772 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
773 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
774 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
775 0, offsetof(s390_fp_regs
, fprs
));
778 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
780 target
->thread
.fp_regs
.fpc
= fpc
[0];
783 if (rc
== 0 && count
> 0)
784 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
785 target
->thread
.fp_regs
.fprs
,
786 offsetof(s390_fp_regs
, fprs
), -1);
788 if (rc
== 0 && target
== current
)
789 restore_fp_regs(&target
->thread
.fp_regs
);
794 static const struct user_regset s390_regsets
[] = {
796 .core_note_type
= NT_PRSTATUS
,
797 .n
= sizeof(s390_regs
) / sizeof(long),
798 .size
= sizeof(long),
799 .align
= sizeof(long),
800 .get
= s390_regs_get
,
801 .set
= s390_regs_set
,
804 .core_note_type
= NT_PRFPREG
,
805 .n
= sizeof(s390_fp_regs
) / sizeof(long),
806 .size
= sizeof(long),
807 .align
= sizeof(long),
808 .get
= s390_fpregs_get
,
809 .set
= s390_fpregs_set
,
813 static const struct user_regset_view user_s390_view
= {
815 .e_machine
= EM_S390
,
816 .regsets
= s390_regsets
,
817 .n
= ARRAY_SIZE(s390_regsets
)
821 static int s390_compat_regs_get(struct task_struct
*target
,
822 const struct user_regset
*regset
,
823 unsigned int pos
, unsigned int count
,
824 void *kbuf
, void __user
*ubuf
)
826 if (target
== current
)
827 save_access_regs(target
->thread
.acrs
);
830 compat_ulong_t
*k
= kbuf
;
832 *k
++ = __peek_user_compat(target
, pos
);
837 compat_ulong_t __user
*u
= ubuf
;
839 if (__put_user(__peek_user_compat(target
, pos
), u
++))
848 static int s390_compat_regs_set(struct task_struct
*target
,
849 const struct user_regset
*regset
,
850 unsigned int pos
, unsigned int count
,
851 const void *kbuf
, const void __user
*ubuf
)
855 if (target
== current
)
856 save_access_regs(target
->thread
.acrs
);
859 const compat_ulong_t
*k
= kbuf
;
860 while (count
> 0 && !rc
) {
861 rc
= __poke_user_compat(target
, pos
, *k
++);
866 const compat_ulong_t __user
*u
= ubuf
;
867 while (count
> 0 && !rc
) {
869 rc
= __get_user(word
, u
++);
872 rc
= __poke_user_compat(target
, pos
, word
);
878 if (rc
== 0 && target
== current
)
879 restore_access_regs(target
->thread
.acrs
);
884 static const struct user_regset s390_compat_regsets
[] = {
886 .core_note_type
= NT_PRSTATUS
,
887 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
888 .size
= sizeof(compat_long_t
),
889 .align
= sizeof(compat_long_t
),
890 .get
= s390_compat_regs_get
,
891 .set
= s390_compat_regs_set
,
894 .core_note_type
= NT_PRFPREG
,
895 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
896 .size
= sizeof(compat_long_t
),
897 .align
= sizeof(compat_long_t
),
898 .get
= s390_fpregs_get
,
899 .set
= s390_fpregs_set
,
903 static const struct user_regset_view user_s390_compat_view
= {
905 .e_machine
= EM_S390
,
906 .regsets
= s390_compat_regsets
,
907 .n
= ARRAY_SIZE(s390_compat_regsets
)
911 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
914 if (test_tsk_thread_flag(task
, TIF_31BIT
))
915 return &user_s390_compat_view
;
917 return &user_s390_view
;