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>
61 REGSET_GENERAL_EXTENDED
,
65 FixPerRegisters(struct task_struct
*task
)
69 per_cr_words cr_words
;
71 regs
= task_pt_regs(task
);
72 per_info
= (per_struct
*) &task
->thread
.per_info
;
73 per_info
->control_regs
.bits
.em_instruction_fetch
=
74 per_info
->single_step
| per_info
->instruction_fetch
;
76 if (per_info
->single_step
) {
77 per_info
->control_regs
.bits
.starting_addr
= 0;
80 per_info
->control_regs
.bits
.ending_addr
= 0x7fffffffUL
;
83 per_info
->control_regs
.bits
.ending_addr
= PSW_ADDR_INSN
;
85 per_info
->control_regs
.bits
.starting_addr
=
86 per_info
->starting_addr
;
87 per_info
->control_regs
.bits
.ending_addr
=
88 per_info
->ending_addr
;
91 * if any of the control reg tracing bits are on
92 * we switch on per in the psw
94 if (per_info
->control_regs
.words
.cr
[0] & PER_EM_MASK
)
95 regs
->psw
.mask
|= PSW_MASK_PER
;
97 regs
->psw
.mask
&= ~PSW_MASK_PER
;
99 if (per_info
->control_regs
.bits
.em_storage_alteration
)
100 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 1;
102 per_info
->control_regs
.bits
.storage_alt_space_ctl
= 0;
104 if (task
== current
) {
105 __ctl_store(cr_words
, 9, 11);
106 if (memcmp(&cr_words
, &per_info
->control_regs
.words
,
107 sizeof(cr_words
)) != 0)
108 __ctl_load(per_info
->control_regs
.words
, 9, 11);
112 void user_enable_single_step(struct task_struct
*task
)
114 task
->thread
.per_info
.single_step
= 1;
115 FixPerRegisters(task
);
118 void user_disable_single_step(struct task_struct
*task
)
120 task
->thread
.per_info
.single_step
= 0;
121 FixPerRegisters(task
);
125 * Called by kernel/ptrace.c when detaching..
127 * Make sure single step bits etc are not set.
130 ptrace_disable(struct task_struct
*child
)
132 /* make sure the single step bit is not set. */
133 user_disable_single_step(child
);
137 # define __ADDR_MASK 3
139 # define __ADDR_MASK 7
143 * Read the word at offset addr from the user area of a process. The
144 * trouble here is that the information is littered over different
145 * locations. The process registers are found on the kernel stack,
146 * the floating point stuff and the trace settings are stored in
147 * the task structure. In addition the different structures in
148 * struct user contain pad bytes that should be read as zeroes.
151 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
153 struct user
*dummy
= NULL
;
156 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
158 * psw and gprs are stored on the stack
160 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
161 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
)
162 /* Remove per bit from user psw. */
163 tmp
&= ~PSW_MASK_PER
;
165 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
167 * access registers are stored in the thread structure
169 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
172 * Very special case: old & broken 64 bit gdb reading
173 * from acrs[15]. Result is a 64 bit value. Read the
174 * 32 bit acrs[15] value and shift it by 32. Sick...
176 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
177 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
180 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
182 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
184 * orig_gpr2 is stored on the kernel stack
186 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
188 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
190 * prevent reads of padding hole between
191 * orig_gpr2 and fp_regs on s390.
195 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
197 * floating point regs. are stored in the thread structure
199 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
200 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
201 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
)
202 tmp
&= (unsigned long) FPC_VALID_MASK
203 << (BITS_PER_LONG
- 32);
205 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
207 * per_info is found in the thread structure
209 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
210 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
);
219 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
224 * Stupid gdb peeks/pokes the access registers in 64 bit with
225 * an alignment of 4. Programmers from hell...
229 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
230 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
233 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
236 tmp
= __peek_user(child
, addr
);
237 return put_user(tmp
, (addr_t __user
*) data
);
241 * Write a word to the user area of a process at location addr. This
242 * operation does have an additional problem compared to peek_user.
243 * Stores to the program status word and on the floating point
244 * control register needs to get checked for validity.
246 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
248 struct user
*dummy
= NULL
;
251 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
253 * psw and gprs are stored on the stack
255 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
&&
257 data
!= PSW_MASK_MERGE(psw_user32_bits
, data
) &&
259 data
!= PSW_MASK_MERGE(psw_user_bits
, data
))
260 /* Invalid psw mask. */
263 if (addr
== (addr_t
) &dummy
->regs
.psw
.addr
)
264 /* I'd like to reject addresses without the
265 high order bit but older gdb's rely on it */
266 data
|= PSW_ADDR_AMODE
;
268 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
270 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
272 * access registers are stored in the thread structure
274 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
277 * Very special case: old & broken 64 bit gdb writing
278 * to acrs[15] with a 64 bit value. Ignore the lower
279 * half of the value and write the upper 32 bit to
282 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
283 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
286 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
288 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
290 * orig_gpr2 is stored on the kernel stack
292 task_pt_regs(child
)->orig_gpr2
= data
;
294 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
296 * prevent writes of padding hole between
297 * orig_gpr2 and fp_regs on s390.
301 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
303 * floating point regs. are stored in the thread structure
305 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
&&
306 (data
& ~((unsigned long) FPC_VALID_MASK
307 << (BITS_PER_LONG
- 32))) != 0)
309 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
310 *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = data
;
312 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
314 * per_info is found in the thread structure
316 offset
= addr
- (addr_t
) &dummy
->regs
.per_info
;
317 *(addr_t
*)((addr_t
) &child
->thread
.per_info
+ offset
) = data
;
321 FixPerRegisters(child
);
326 poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
331 * Stupid gdb peeks/pokes the access registers in 64 bit with
332 * an alignment of 4. Programmers from hell indeed...
336 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
337 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
340 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
343 return __poke_user(child
, addr
, data
);
346 long arch_ptrace(struct task_struct
*child
, long request
,
347 unsigned long addr
, unsigned long data
)
354 /* read the word at location addr in the USER area. */
355 return peek_user(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);
386 case PTRACE_GET_LAST_BREAK
:
387 put_user(task_thread_info(child
)->last_break
,
388 (unsigned long __user
*) data
);
391 /* Removing high order bit from addr (only for 31 bit). */
392 addr
&= PSW_ADDR_INSN
;
393 return ptrace_request(child
, request
, addr
, data
);
399 * Now the fun part starts... a 31 bit program running in the
400 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
401 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
402 * to handle, the difference to the 64 bit versions of the requests
403 * is that the access is done in multiples of 4 byte instead of
404 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
405 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
406 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
407 * is a 31 bit program too, the content of struct user can be
408 * emulated. A 31 bit program peeking into the struct user of
409 * a 64 bit program is a no-no.
413 * Same as peek_user but for a 31 bit program.
415 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
417 struct user32
*dummy32
= NULL
;
418 per_struct32
*dummy_per32
= NULL
;
422 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
424 * psw and gprs are stored on the stack
426 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
427 /* Fake a 31 bit psw mask. */
428 tmp
= (__u32
)(task_pt_regs(child
)->psw
.mask
>> 32);
429 tmp
= PSW32_MASK_MERGE(psw32_user_bits
, tmp
);
430 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
431 /* Fake a 31 bit psw address. */
432 tmp
= (__u32
) task_pt_regs(child
)->psw
.addr
|
436 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
+
439 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
441 * access registers are stored in the thread structure
443 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
444 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
446 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
448 * orig_gpr2 is stored on the kernel stack
450 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
452 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
454 * prevent reads of padding hole between
455 * orig_gpr2 and fp_regs on s390.
459 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
461 * floating point regs. are stored in the thread structure
463 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
464 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
466 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
468 * per_info is found in the thread structure
470 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
471 /* This is magic. See per_struct and per_struct32. */
472 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
473 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
474 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
475 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
476 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
477 offset
= offset
*2 + 4;
480 tmp
= *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
);
488 static int peek_user_compat(struct task_struct
*child
,
489 addr_t addr
, addr_t data
)
493 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user
) - 3)
496 tmp
= __peek_user_compat(child
, addr
);
497 return put_user(tmp
, (__u32 __user
*) data
);
501 * Same as poke_user but for a 31 bit program.
503 static int __poke_user_compat(struct task_struct
*child
,
504 addr_t addr
, addr_t data
)
506 struct user32
*dummy32
= NULL
;
507 per_struct32
*dummy_per32
= NULL
;
508 __u32 tmp
= (__u32
) data
;
511 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
513 * psw, gprs, acrs and orig_gpr2 are stored on the stack
515 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
516 /* Build a 64 bit psw mask from 31 bit mask. */
517 if (tmp
!= PSW32_MASK_MERGE(psw32_user_bits
, tmp
))
518 /* Invalid psw mask. */
520 task_pt_regs(child
)->psw
.mask
=
521 PSW_MASK_MERGE(psw_user32_bits
, (__u64
) tmp
<< 32);
522 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
523 /* Build a 64 bit psw address from 31 bit address. */
524 task_pt_regs(child
)->psw
.addr
=
525 (__u64
) tmp
& PSW32_ADDR_INSN
;
528 *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
531 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
533 * access registers are stored in the thread structure
535 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
536 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
538 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
540 * orig_gpr2 is stored on the kernel stack
542 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
544 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
546 * prevent writess of padding hole between
547 * orig_gpr2 and fp_regs on s390.
551 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
553 * floating point regs. are stored in the thread structure
555 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
556 (tmp
& ~FPC_VALID_MASK
) != 0)
557 /* Invalid floating point control. */
559 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
560 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
562 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
564 * per_info is found in the thread structure.
566 offset
= addr
- (addr_t
) &dummy32
->regs
.per_info
;
568 * This is magic. See per_struct and per_struct32.
569 * By incident the offsets in per_struct are exactly
570 * twice the offsets in per_struct32 for all fields.
571 * The 8 byte fields need special handling though,
572 * because the second half (bytes 4-7) is needed and
573 * not the first half.
575 if ((offset
>= (addr_t
) &dummy_per32
->control_regs
&&
576 offset
< (addr_t
) (&dummy_per32
->control_regs
+ 1)) ||
577 (offset
>= (addr_t
) &dummy_per32
->starting_addr
&&
578 offset
<= (addr_t
) &dummy_per32
->ending_addr
) ||
579 offset
== (addr_t
) &dummy_per32
->lowcore
.words
.address
)
580 offset
= offset
*2 + 4;
583 *(__u32
*)((addr_t
) &child
->thread
.per_info
+ offset
) = tmp
;
587 FixPerRegisters(child
);
591 static int poke_user_compat(struct task_struct
*child
,
592 addr_t addr
, addr_t data
)
594 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user32
) - 3)
597 return __poke_user_compat(child
, addr
, data
);
600 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
601 compat_ulong_t caddr
, compat_ulong_t cdata
)
603 unsigned long addr
= caddr
;
604 unsigned long data
= cdata
;
605 ptrace_area_emu31 parea
;
610 /* read the word at location addr in the USER area. */
611 return peek_user_compat(child
, addr
, data
);
614 /* write the word at location addr in the USER area */
615 return poke_user_compat(child
, addr
, data
);
617 case PTRACE_PEEKUSR_AREA
:
618 case PTRACE_POKEUSR_AREA
:
619 if (copy_from_user(&parea
, (void __force __user
*) addr
,
622 addr
= parea
.kernel_addr
;
623 data
= parea
.process_addr
;
625 while (copied
< parea
.len
) {
626 if (request
== PTRACE_PEEKUSR_AREA
)
627 ret
= peek_user_compat(child
, addr
, data
);
631 (__u32 __force __user
*) data
))
633 ret
= poke_user_compat(child
, addr
, utmp
);
637 addr
+= sizeof(unsigned int);
638 data
+= sizeof(unsigned int);
639 copied
+= sizeof(unsigned int);
642 case PTRACE_GET_LAST_BREAK
:
643 put_user(task_thread_info(child
)->last_break
,
644 (unsigned int __user
*) data
);
647 return compat_ptrace_request(child
, request
, addr
, data
);
651 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
655 /* Do the secure computing check first. */
656 secure_computing(regs
->gprs
[2]);
659 * The sysc_tracesys code in entry.S stored the system
660 * call number to gprs[2].
662 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
663 (tracehook_report_syscall_entry(regs
) ||
664 regs
->gprs
[2] >= NR_syscalls
)) {
666 * Tracing decided this syscall should not happen or the
667 * debugger stored an invalid system call number. Skip
668 * the system call and the system call restart handling.
674 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
675 trace_sys_enter(regs
, regs
->gprs
[2]);
677 if (unlikely(current
->audit_context
))
678 audit_syscall_entry(is_compat_task() ?
679 AUDIT_ARCH_S390
: AUDIT_ARCH_S390X
,
680 regs
->gprs
[2], regs
->orig_gpr2
,
681 regs
->gprs
[3], regs
->gprs
[4],
683 return ret
?: regs
->gprs
[2];
686 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
688 if (unlikely(current
->audit_context
))
689 audit_syscall_exit(AUDITSC_RESULT(regs
->gprs
[2]),
692 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
693 trace_sys_exit(regs
, regs
->gprs
[2]);
695 if (test_thread_flag(TIF_SYSCALL_TRACE
))
696 tracehook_report_syscall_exit(regs
, 0);
700 * user_regset definitions.
703 static int s390_regs_get(struct task_struct
*target
,
704 const struct user_regset
*regset
,
705 unsigned int pos
, unsigned int count
,
706 void *kbuf
, void __user
*ubuf
)
708 if (target
== current
)
709 save_access_regs(target
->thread
.acrs
);
712 unsigned long *k
= kbuf
;
714 *k
++ = __peek_user(target
, pos
);
719 unsigned long __user
*u
= ubuf
;
721 if (__put_user(__peek_user(target
, pos
), u
++))
730 static int s390_regs_set(struct task_struct
*target
,
731 const struct user_regset
*regset
,
732 unsigned int pos
, unsigned int count
,
733 const void *kbuf
, const void __user
*ubuf
)
737 if (target
== current
)
738 save_access_regs(target
->thread
.acrs
);
741 const unsigned long *k
= kbuf
;
742 while (count
> 0 && !rc
) {
743 rc
= __poke_user(target
, pos
, *k
++);
748 const unsigned long __user
*u
= ubuf
;
749 while (count
> 0 && !rc
) {
751 rc
= __get_user(word
, u
++);
754 rc
= __poke_user(target
, pos
, word
);
760 if (rc
== 0 && target
== current
)
761 restore_access_regs(target
->thread
.acrs
);
766 static int s390_fpregs_get(struct task_struct
*target
,
767 const struct user_regset
*regset
, unsigned int pos
,
768 unsigned int count
, void *kbuf
, void __user
*ubuf
)
770 if (target
== current
)
771 save_fp_regs(&target
->thread
.fp_regs
);
773 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
774 &target
->thread
.fp_regs
, 0, -1);
777 static int s390_fpregs_set(struct task_struct
*target
,
778 const struct user_regset
*regset
, unsigned int pos
,
779 unsigned int count
, const void *kbuf
,
780 const void __user
*ubuf
)
784 if (target
== current
)
785 save_fp_regs(&target
->thread
.fp_regs
);
787 /* If setting FPC, must validate it first. */
788 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
789 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
790 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
791 0, offsetof(s390_fp_regs
, fprs
));
794 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
796 target
->thread
.fp_regs
.fpc
= fpc
[0];
799 if (rc
== 0 && count
> 0)
800 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
801 target
->thread
.fp_regs
.fprs
,
802 offsetof(s390_fp_regs
, fprs
), -1);
804 if (rc
== 0 && target
== current
)
805 restore_fp_regs(&target
->thread
.fp_regs
);
812 static int s390_last_break_get(struct task_struct
*target
,
813 const struct user_regset
*regset
,
814 unsigned int pos
, unsigned int count
,
815 void *kbuf
, void __user
*ubuf
)
819 unsigned long *k
= kbuf
;
820 *k
= task_thread_info(target
)->last_break
;
822 unsigned long __user
*u
= ubuf
;
823 if (__put_user(task_thread_info(target
)->last_break
, u
))
832 static const struct user_regset s390_regsets
[] = {
834 .core_note_type
= NT_PRSTATUS
,
835 .n
= sizeof(s390_regs
) / sizeof(long),
836 .size
= sizeof(long),
837 .align
= sizeof(long),
838 .get
= s390_regs_get
,
839 .set
= s390_regs_set
,
842 .core_note_type
= NT_PRFPREG
,
843 .n
= sizeof(s390_fp_regs
) / sizeof(long),
844 .size
= sizeof(long),
845 .align
= sizeof(long),
846 .get
= s390_fpregs_get
,
847 .set
= s390_fpregs_set
,
850 [REGSET_LAST_BREAK
] = {
851 .core_note_type
= NT_S390_LAST_BREAK
,
853 .size
= sizeof(long),
854 .align
= sizeof(long),
855 .get
= s390_last_break_get
,
860 static const struct user_regset_view user_s390_view
= {
862 .e_machine
= EM_S390
,
863 .regsets
= s390_regsets
,
864 .n
= ARRAY_SIZE(s390_regsets
)
868 static int s390_compat_regs_get(struct task_struct
*target
,
869 const struct user_regset
*regset
,
870 unsigned int pos
, unsigned int count
,
871 void *kbuf
, void __user
*ubuf
)
873 if (target
== current
)
874 save_access_regs(target
->thread
.acrs
);
877 compat_ulong_t
*k
= kbuf
;
879 *k
++ = __peek_user_compat(target
, pos
);
884 compat_ulong_t __user
*u
= ubuf
;
886 if (__put_user(__peek_user_compat(target
, pos
), u
++))
895 static int s390_compat_regs_set(struct task_struct
*target
,
896 const struct user_regset
*regset
,
897 unsigned int pos
, unsigned int count
,
898 const void *kbuf
, const void __user
*ubuf
)
902 if (target
== current
)
903 save_access_regs(target
->thread
.acrs
);
906 const compat_ulong_t
*k
= kbuf
;
907 while (count
> 0 && !rc
) {
908 rc
= __poke_user_compat(target
, pos
, *k
++);
913 const compat_ulong_t __user
*u
= ubuf
;
914 while (count
> 0 && !rc
) {
916 rc
= __get_user(word
, u
++);
919 rc
= __poke_user_compat(target
, pos
, word
);
925 if (rc
== 0 && target
== current
)
926 restore_access_regs(target
->thread
.acrs
);
931 static int s390_compat_regs_high_get(struct task_struct
*target
,
932 const struct user_regset
*regset
,
933 unsigned int pos
, unsigned int count
,
934 void *kbuf
, void __user
*ubuf
)
936 compat_ulong_t
*gprs_high
;
938 gprs_high
= (compat_ulong_t
*)
939 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
941 compat_ulong_t
*k
= kbuf
;
948 compat_ulong_t __user
*u
= ubuf
;
950 if (__put_user(*gprs_high
, u
++))
959 static int s390_compat_regs_high_set(struct task_struct
*target
,
960 const struct user_regset
*regset
,
961 unsigned int pos
, unsigned int count
,
962 const void *kbuf
, const void __user
*ubuf
)
964 compat_ulong_t
*gprs_high
;
967 gprs_high
= (compat_ulong_t
*)
968 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
970 const compat_ulong_t
*k
= kbuf
;
977 const compat_ulong_t __user
*u
= ubuf
;
978 while (count
> 0 && !rc
) {
980 rc
= __get_user(word
, u
++);
992 static int s390_compat_last_break_get(struct task_struct
*target
,
993 const struct user_regset
*regset
,
994 unsigned int pos
, unsigned int count
,
995 void *kbuf
, void __user
*ubuf
)
997 compat_ulong_t last_break
;
1000 last_break
= task_thread_info(target
)->last_break
;
1002 unsigned long *k
= kbuf
;
1005 unsigned long __user
*u
= ubuf
;
1006 if (__put_user(last_break
, u
))
1013 static const struct user_regset s390_compat_regsets
[] = {
1014 [REGSET_GENERAL
] = {
1015 .core_note_type
= NT_PRSTATUS
,
1016 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
1017 .size
= sizeof(compat_long_t
),
1018 .align
= sizeof(compat_long_t
),
1019 .get
= s390_compat_regs_get
,
1020 .set
= s390_compat_regs_set
,
1023 .core_note_type
= NT_PRFPREG
,
1024 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
1025 .size
= sizeof(compat_long_t
),
1026 .align
= sizeof(compat_long_t
),
1027 .get
= s390_fpregs_get
,
1028 .set
= s390_fpregs_set
,
1030 [REGSET_LAST_BREAK
] = {
1031 .core_note_type
= NT_S390_LAST_BREAK
,
1033 .size
= sizeof(long),
1034 .align
= sizeof(long),
1035 .get
= s390_compat_last_break_get
,
1037 [REGSET_GENERAL_EXTENDED
] = {
1038 .core_note_type
= NT_S390_HIGH_GPRS
,
1039 .n
= sizeof(s390_compat_regs_high
) / sizeof(compat_long_t
),
1040 .size
= sizeof(compat_long_t
),
1041 .align
= sizeof(compat_long_t
),
1042 .get
= s390_compat_regs_high_get
,
1043 .set
= s390_compat_regs_high_set
,
1047 static const struct user_regset_view user_s390_compat_view
= {
1049 .e_machine
= EM_S390
,
1050 .regsets
= s390_compat_regsets
,
1051 .n
= ARRAY_SIZE(s390_compat_regsets
)
1055 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
1057 #ifdef CONFIG_COMPAT
1058 if (test_tsk_thread_flag(task
, TIF_31BIT
))
1059 return &user_s390_compat_view
;
1061 return &user_s390_view
;
1064 static const char *gpr_names
[NUM_GPRS
] = {
1065 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1066 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1069 unsigned long regs_get_register(struct pt_regs
*regs
, unsigned int offset
)
1071 if (offset
>= NUM_GPRS
)
1073 return regs
->gprs
[offset
];
1076 int regs_query_register_offset(const char *name
)
1078 unsigned long offset
;
1080 if (!name
|| *name
!= 'r')
1082 if (strict_strtoul(name
+ 1, 10, &offset
))
1084 if (offset
>= NUM_GPRS
)
1089 const char *regs_query_register_name(unsigned int offset
)
1091 if (offset
>= NUM_GPRS
)
1093 return gpr_names
[offset
];
1096 static int regs_within_kernel_stack(struct pt_regs
*regs
, unsigned long addr
)
1098 unsigned long ksp
= kernel_stack_pointer(regs
);
1100 return (addr
& ~(THREAD_SIZE
- 1)) == (ksp
& ~(THREAD_SIZE
- 1));
1104 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1105 * @regs:pt_regs which contains kernel stack pointer.
1106 * @n:stack entry number.
1108 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1109 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1112 unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
, unsigned int n
)
1116 addr
= kernel_stack_pointer(regs
) + n
* sizeof(long);
1117 if (!regs_within_kernel_stack(regs
, addr
))
1119 return *(unsigned long *)addr
;