2 * Ptrace user space interface.
4 * Copyright IBM Corp. 1999, 2010
5 * Author(s): Denis Joseph Barrow
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
12 #include <linux/smp.h>
13 #include <linux/errno.h>
14 #include <linux/ptrace.h>
15 #include <linux/user.h>
16 #include <linux/security.h>
17 #include <linux/audit.h>
18 #include <linux/signal.h>
19 #include <linux/elf.h>
20 #include <linux/regset.h>
21 #include <linux/tracehook.h>
22 #include <linux/seccomp.h>
23 #include <linux/compat.h>
24 #include <trace/syscall.h>
25 #include <asm/segment.h>
27 #include <asm/pgtable.h>
28 #include <asm/pgalloc.h>
29 #include <asm/uaccess.h>
30 #include <asm/unistd.h>
31 #include <asm/switch_to.h>
35 #include "compat_ptrace.h"
38 #define CREATE_TRACE_POINTS
39 #include <trace/events/syscalls.h>
47 REGSET_GENERAL_EXTENDED
,
50 void update_cr_regs(struct task_struct
*task
)
52 struct pt_regs
*regs
= task_pt_regs(task
);
53 struct thread_struct
*thread
= &task
->thread
;
54 struct per_regs old
, new;
57 /* Take care of the enable/disable of transactional execution. */
59 unsigned long cr
[3], cr_new
[3];
61 __ctl_store(cr
, 0, 2);
63 /* Set or clear transaction execution TXC bit 8. */
64 if (task
->thread
.per_flags
& PER_FLAG_NO_TE
)
65 cr_new
[0] = cr
[0] & ~(1UL << 55);
67 cr_new
[0] = cr
[0] | (1UL << 55);
68 /* Set or clear transaction execution TDC bits 62 and 63. */
69 cr_new
[2] = cr
[2] & ~3UL;
70 if (task
->thread
.per_flags
& PER_FLAG_TE_ABORT_RAND
) {
71 if (task
->thread
.per_flags
& PER_FLAG_TE_ABORT_RAND_TEND
)
76 if (memcmp(&cr_new
, &cr
, sizeof(cr
)))
77 __ctl_load(cr_new
, 0, 2);
80 /* Copy user specified PER registers */
81 new.control
= thread
->per_user
.control
;
82 new.start
= thread
->per_user
.start
;
83 new.end
= thread
->per_user
.end
;
85 /* merge TIF_SINGLE_STEP into user specified PER registers. */
86 if (test_tsk_thread_flag(task
, TIF_SINGLE_STEP
)) {
87 new.control
|= PER_EVENT_IFETCH
;
89 new.control
|= PER_CONTROL_SUSPENSION
;
90 new.control
|= PER_EVENT_TRANSACTION_END
;
93 new.end
= PSW_ADDR_INSN
;
96 /* Take care of the PER enablement bit in the PSW. */
97 if (!(new.control
& PER_EVENT_MASK
)) {
98 regs
->psw
.mask
&= ~PSW_MASK_PER
;
101 regs
->psw
.mask
|= PSW_MASK_PER
;
102 __ctl_store(old
, 9, 11);
103 if (memcmp(&new, &old
, sizeof(struct per_regs
)) != 0)
104 __ctl_load(new, 9, 11);
107 void user_enable_single_step(struct task_struct
*task
)
109 set_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
111 update_cr_regs(task
);
114 void user_disable_single_step(struct task_struct
*task
)
116 clear_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
118 update_cr_regs(task
);
122 * Called by kernel/ptrace.c when detaching..
124 * Clear all debugging related fields.
126 void ptrace_disable(struct task_struct
*task
)
128 memset(&task
->thread
.per_user
, 0, sizeof(task
->thread
.per_user
));
129 memset(&task
->thread
.per_event
, 0, sizeof(task
->thread
.per_event
));
130 clear_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
131 clear_tsk_thread_flag(task
, TIF_PER_TRAP
);
132 task
->thread
.per_flags
= 0;
136 # define __ADDR_MASK 3
138 # define __ADDR_MASK 7
141 static inline unsigned long __peek_user_per(struct task_struct
*child
,
144 struct per_struct_kernel
*dummy
= NULL
;
146 if (addr
== (addr_t
) &dummy
->cr9
)
147 /* Control bits of the active per set. */
148 return test_thread_flag(TIF_SINGLE_STEP
) ?
149 PER_EVENT_IFETCH
: child
->thread
.per_user
.control
;
150 else if (addr
== (addr_t
) &dummy
->cr10
)
151 /* Start address of the active per set. */
152 return test_thread_flag(TIF_SINGLE_STEP
) ?
153 0 : child
->thread
.per_user
.start
;
154 else if (addr
== (addr_t
) &dummy
->cr11
)
155 /* End address of the active per set. */
156 return test_thread_flag(TIF_SINGLE_STEP
) ?
157 PSW_ADDR_INSN
: child
->thread
.per_user
.end
;
158 else if (addr
== (addr_t
) &dummy
->bits
)
159 /* Single-step bit. */
160 return test_thread_flag(TIF_SINGLE_STEP
) ?
161 (1UL << (BITS_PER_LONG
- 1)) : 0;
162 else if (addr
== (addr_t
) &dummy
->starting_addr
)
163 /* Start address of the user specified per set. */
164 return child
->thread
.per_user
.start
;
165 else if (addr
== (addr_t
) &dummy
->ending_addr
)
166 /* End address of the user specified per set. */
167 return child
->thread
.per_user
.end
;
168 else if (addr
== (addr_t
) &dummy
->perc_atmid
)
169 /* PER code, ATMID and AI of the last PER trap */
170 return (unsigned long)
171 child
->thread
.per_event
.cause
<< (BITS_PER_LONG
- 16);
172 else if (addr
== (addr_t
) &dummy
->address
)
173 /* Address of the last PER trap */
174 return child
->thread
.per_event
.address
;
175 else if (addr
== (addr_t
) &dummy
->access_id
)
176 /* Access id of the last PER trap */
177 return (unsigned long)
178 child
->thread
.per_event
.paid
<< (BITS_PER_LONG
- 8);
183 * Read the word at offset addr from the user area of a process. The
184 * trouble here is that the information is littered over different
185 * locations. The process registers are found on the kernel stack,
186 * the floating point stuff and the trace settings are stored in
187 * the task structure. In addition the different structures in
188 * struct user contain pad bytes that should be read as zeroes.
191 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
193 struct user
*dummy
= NULL
;
196 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
198 * psw and gprs are stored on the stack
200 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
201 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
)
202 /* Return a clean psw mask. */
203 tmp
= psw_user_bits
| (tmp
& PSW_MASK_USER
);
205 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
207 * access registers are stored in the thread structure
209 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
212 * Very special case: old & broken 64 bit gdb reading
213 * from acrs[15]. Result is a 64 bit value. Read the
214 * 32 bit acrs[15] value and shift it by 32. Sick...
216 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
217 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
220 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
222 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
224 * orig_gpr2 is stored on the kernel stack
226 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
228 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
230 * prevent reads of padding hole between
231 * orig_gpr2 and fp_regs on s390.
235 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
237 * floating point regs. are stored in the thread structure
239 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
240 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
241 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
)
242 tmp
&= (unsigned long) FPC_VALID_MASK
243 << (BITS_PER_LONG
- 32);
245 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
247 * Handle access to the per_info structure.
249 addr
-= (addr_t
) &dummy
->regs
.per_info
;
250 tmp
= __peek_user_per(child
, addr
);
259 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
264 * Stupid gdb peeks/pokes the access registers in 64 bit with
265 * an alignment of 4. Programmers from hell...
269 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
270 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
273 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
276 tmp
= __peek_user(child
, addr
);
277 return put_user(tmp
, (addr_t __user
*) data
);
280 static inline void __poke_user_per(struct task_struct
*child
,
281 addr_t addr
, addr_t data
)
283 struct per_struct_kernel
*dummy
= NULL
;
286 * There are only three fields in the per_info struct that the
287 * debugger user can write to.
288 * 1) cr9: the debugger wants to set a new PER event mask
289 * 2) starting_addr: the debugger wants to set a new starting
290 * address to use with the PER event mask.
291 * 3) ending_addr: the debugger wants to set a new ending
292 * address to use with the PER event mask.
293 * The user specified PER event mask and the start and end
294 * addresses are used only if single stepping is not in effect.
295 * Writes to any other field in per_info are ignored.
297 if (addr
== (addr_t
) &dummy
->cr9
)
298 /* PER event mask of the user specified per set. */
299 child
->thread
.per_user
.control
=
300 data
& (PER_EVENT_MASK
| PER_CONTROL_MASK
);
301 else if (addr
== (addr_t
) &dummy
->starting_addr
)
302 /* Starting address of the user specified per set. */
303 child
->thread
.per_user
.start
= data
;
304 else if (addr
== (addr_t
) &dummy
->ending_addr
)
305 /* Ending address of the user specified per set. */
306 child
->thread
.per_user
.end
= data
;
310 * Write a word to the user area of a process at location addr. This
311 * operation does have an additional problem compared to peek_user.
312 * Stores to the program status word and on the floating point
313 * control register needs to get checked for validity.
315 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
317 struct user
*dummy
= NULL
;
320 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
322 * psw and gprs are stored on the stack
324 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
&&
325 (((data
^psw_user_bits
) & ~PSW_MASK_USER
) ||
326 (((data
^psw_user_bits
) & PSW_MASK_ASC
) &&
327 ((data
|psw_user_bits
) & PSW_MASK_ASC
) == PSW_MASK_ASC
) ||
328 ((data
& PSW_MASK_EA
) && !(data
& PSW_MASK_BA
))))
329 /* Invalid psw mask. */
331 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
333 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
335 * access registers are stored in the thread structure
337 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
340 * Very special case: old & broken 64 bit gdb writing
341 * to acrs[15] with a 64 bit value. Ignore the lower
342 * half of the value and write the upper 32 bit to
345 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
346 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
349 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
351 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
353 * orig_gpr2 is stored on the kernel stack
355 task_pt_regs(child
)->orig_gpr2
= data
;
357 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
359 * prevent writes of padding hole between
360 * orig_gpr2 and fp_regs on s390.
364 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
366 * floating point regs. are stored in the thread structure
368 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
&&
369 (data
& ~((unsigned long) FPC_VALID_MASK
370 << (BITS_PER_LONG
- 32))) != 0)
372 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
373 *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = data
;
375 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
377 * Handle access to the per_info structure.
379 addr
-= (addr_t
) &dummy
->regs
.per_info
;
380 __poke_user_per(child
, addr
, data
);
387 static int poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
392 * Stupid gdb peeks/pokes the access registers in 64 bit with
393 * an alignment of 4. Programmers from hell indeed...
397 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
398 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
401 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
404 return __poke_user(child
, addr
, data
);
407 long arch_ptrace(struct task_struct
*child
, long request
,
408 unsigned long addr
, unsigned long data
)
415 /* read the word at location addr in the USER area. */
416 return peek_user(child
, addr
, data
);
419 /* write the word at location addr in the USER area */
420 return poke_user(child
, addr
, data
);
422 case PTRACE_PEEKUSR_AREA
:
423 case PTRACE_POKEUSR_AREA
:
424 if (copy_from_user(&parea
, (void __force __user
*) addr
,
427 addr
= parea
.kernel_addr
;
428 data
= parea
.process_addr
;
430 while (copied
< parea
.len
) {
431 if (request
== PTRACE_PEEKUSR_AREA
)
432 ret
= peek_user(child
, addr
, data
);
436 (addr_t __force __user
*) data
))
438 ret
= poke_user(child
, addr
, utmp
);
442 addr
+= sizeof(unsigned long);
443 data
+= sizeof(unsigned long);
444 copied
+= sizeof(unsigned long);
447 case PTRACE_GET_LAST_BREAK
:
448 put_user(task_thread_info(child
)->last_break
,
449 (unsigned long __user
*) data
);
451 case PTRACE_ENABLE_TE
:
454 child
->thread
.per_flags
&= ~PER_FLAG_NO_TE
;
456 case PTRACE_DISABLE_TE
:
459 child
->thread
.per_flags
|= PER_FLAG_NO_TE
;
460 child
->thread
.per_flags
&= ~PER_FLAG_TE_ABORT_RAND
;
462 case PTRACE_TE_ABORT_RAND
:
463 if (!MACHINE_HAS_TE
|| (child
->thread
.per_flags
& PER_FLAG_NO_TE
))
467 child
->thread
.per_flags
&= ~PER_FLAG_TE_ABORT_RAND
;
470 child
->thread
.per_flags
|= PER_FLAG_TE_ABORT_RAND
;
471 child
->thread
.per_flags
|= PER_FLAG_TE_ABORT_RAND_TEND
;
474 child
->thread
.per_flags
|= PER_FLAG_TE_ABORT_RAND
;
475 child
->thread
.per_flags
&= ~PER_FLAG_TE_ABORT_RAND_TEND
;
482 /* Removing high order bit from addr (only for 31 bit). */
483 addr
&= PSW_ADDR_INSN
;
484 return ptrace_request(child
, request
, addr
, data
);
490 * Now the fun part starts... a 31 bit program running in the
491 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
492 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
493 * to handle, the difference to the 64 bit versions of the requests
494 * is that the access is done in multiples of 4 byte instead of
495 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
496 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
497 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
498 * is a 31 bit program too, the content of struct user can be
499 * emulated. A 31 bit program peeking into the struct user of
500 * a 64 bit program is a no-no.
504 * Same as peek_user_per but for a 31 bit program.
506 static inline __u32
__peek_user_per_compat(struct task_struct
*child
,
509 struct compat_per_struct_kernel
*dummy32
= NULL
;
511 if (addr
== (addr_t
) &dummy32
->cr9
)
512 /* Control bits of the active per set. */
513 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
514 PER_EVENT_IFETCH
: child
->thread
.per_user
.control
;
515 else if (addr
== (addr_t
) &dummy32
->cr10
)
516 /* Start address of the active per set. */
517 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
518 0 : child
->thread
.per_user
.start
;
519 else if (addr
== (addr_t
) &dummy32
->cr11
)
520 /* End address of the active per set. */
521 return test_thread_flag(TIF_SINGLE_STEP
) ?
522 PSW32_ADDR_INSN
: child
->thread
.per_user
.end
;
523 else if (addr
== (addr_t
) &dummy32
->bits
)
524 /* Single-step bit. */
525 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
527 else if (addr
== (addr_t
) &dummy32
->starting_addr
)
528 /* Start address of the user specified per set. */
529 return (__u32
) child
->thread
.per_user
.start
;
530 else if (addr
== (addr_t
) &dummy32
->ending_addr
)
531 /* End address of the user specified per set. */
532 return (__u32
) child
->thread
.per_user
.end
;
533 else if (addr
== (addr_t
) &dummy32
->perc_atmid
)
534 /* PER code, ATMID and AI of the last PER trap */
535 return (__u32
) child
->thread
.per_event
.cause
<< 16;
536 else if (addr
== (addr_t
) &dummy32
->address
)
537 /* Address of the last PER trap */
538 return (__u32
) child
->thread
.per_event
.address
;
539 else if (addr
== (addr_t
) &dummy32
->access_id
)
540 /* Access id of the last PER trap */
541 return (__u32
) child
->thread
.per_event
.paid
<< 24;
546 * Same as peek_user but for a 31 bit program.
548 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
550 struct compat_user
*dummy32
= NULL
;
554 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
555 struct pt_regs
*regs
= task_pt_regs(child
);
557 * psw and gprs are stored on the stack
559 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
560 /* Fake a 31 bit psw mask. */
561 tmp
= (__u32
)(regs
->psw
.mask
>> 32);
562 tmp
= psw32_user_bits
| (tmp
& PSW32_MASK_USER
);
563 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
564 /* Fake a 31 bit psw address. */
565 tmp
= (__u32
) regs
->psw
.addr
|
566 (__u32
)(regs
->psw
.mask
& PSW_MASK_BA
);
569 tmp
= *(__u32
*)((addr_t
) ®s
->psw
+ addr
*2 + 4);
571 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
573 * access registers are stored in the thread structure
575 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
576 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
578 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
580 * orig_gpr2 is stored on the kernel stack
582 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
584 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
586 * prevent reads of padding hole between
587 * orig_gpr2 and fp_regs on s390.
591 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
593 * floating point regs. are stored in the thread structure
595 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
596 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
598 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
600 * Handle access to the per_info structure.
602 addr
-= (addr_t
) &dummy32
->regs
.per_info
;
603 tmp
= __peek_user_per_compat(child
, addr
);
611 static int peek_user_compat(struct task_struct
*child
,
612 addr_t addr
, addr_t data
)
616 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user
) - 3)
619 tmp
= __peek_user_compat(child
, addr
);
620 return put_user(tmp
, (__u32 __user
*) data
);
624 * Same as poke_user_per but for a 31 bit program.
626 static inline void __poke_user_per_compat(struct task_struct
*child
,
627 addr_t addr
, __u32 data
)
629 struct compat_per_struct_kernel
*dummy32
= NULL
;
631 if (addr
== (addr_t
) &dummy32
->cr9
)
632 /* PER event mask of the user specified per set. */
633 child
->thread
.per_user
.control
=
634 data
& (PER_EVENT_MASK
| PER_CONTROL_MASK
);
635 else if (addr
== (addr_t
) &dummy32
->starting_addr
)
636 /* Starting address of the user specified per set. */
637 child
->thread
.per_user
.start
= data
;
638 else if (addr
== (addr_t
) &dummy32
->ending_addr
)
639 /* Ending address of the user specified per set. */
640 child
->thread
.per_user
.end
= data
;
644 * Same as poke_user but for a 31 bit program.
646 static int __poke_user_compat(struct task_struct
*child
,
647 addr_t addr
, addr_t data
)
649 struct compat_user
*dummy32
= NULL
;
650 __u32 tmp
= (__u32
) data
;
653 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
654 struct pt_regs
*regs
= task_pt_regs(child
);
656 * psw, gprs, acrs and orig_gpr2 are stored on the stack
658 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
659 /* Build a 64 bit psw mask from 31 bit mask. */
660 if (((tmp
^psw32_user_bits
) & ~PSW32_MASK_USER
) ||
661 (((tmp
^psw32_user_bits
) & PSW32_MASK_ASC
) &&
662 ((tmp
|psw32_user_bits
) & PSW32_MASK_ASC
)
664 /* Invalid psw mask. */
666 regs
->psw
.mask
= (regs
->psw
.mask
& ~PSW_MASK_USER
) |
667 (regs
->psw
.mask
& PSW_MASK_BA
) |
668 (__u64
)(tmp
& PSW32_MASK_USER
) << 32;
669 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
670 /* Build a 64 bit psw address from 31 bit address. */
671 regs
->psw
.addr
= (__u64
) tmp
& PSW32_ADDR_INSN
;
672 /* Transfer 31 bit amode bit to psw mask. */
673 regs
->psw
.mask
= (regs
->psw
.mask
& ~PSW_MASK_BA
) |
674 (__u64
)(tmp
& PSW32_ADDR_AMODE
);
677 *(__u32
*)((addr_t
) ®s
->psw
+ addr
*2 + 4) = tmp
;
679 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
681 * access registers are stored in the thread structure
683 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
684 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
686 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
688 * orig_gpr2 is stored on the kernel stack
690 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
692 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
694 * prevent writess of padding hole between
695 * orig_gpr2 and fp_regs on s390.
699 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
701 * floating point regs. are stored in the thread structure
703 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
704 (tmp
& ~FPC_VALID_MASK
) != 0)
705 /* Invalid floating point control. */
707 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
708 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
710 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
712 * Handle access to the per_info structure.
714 addr
-= (addr_t
) &dummy32
->regs
.per_info
;
715 __poke_user_per_compat(child
, addr
, data
);
721 static int poke_user_compat(struct task_struct
*child
,
722 addr_t addr
, addr_t data
)
724 if (!is_compat_task() || (addr
& 3) ||
725 addr
> sizeof(struct compat_user
) - 3)
728 return __poke_user_compat(child
, addr
, data
);
731 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
732 compat_ulong_t caddr
, compat_ulong_t cdata
)
734 unsigned long addr
= caddr
;
735 unsigned long data
= cdata
;
736 compat_ptrace_area parea
;
741 /* read the word at location addr in the USER area. */
742 return peek_user_compat(child
, addr
, data
);
745 /* write the word at location addr in the USER area */
746 return poke_user_compat(child
, addr
, data
);
748 case PTRACE_PEEKUSR_AREA
:
749 case PTRACE_POKEUSR_AREA
:
750 if (copy_from_user(&parea
, (void __force __user
*) addr
,
753 addr
= parea
.kernel_addr
;
754 data
= parea
.process_addr
;
756 while (copied
< parea
.len
) {
757 if (request
== PTRACE_PEEKUSR_AREA
)
758 ret
= peek_user_compat(child
, addr
, data
);
762 (__u32 __force __user
*) data
))
764 ret
= poke_user_compat(child
, addr
, utmp
);
768 addr
+= sizeof(unsigned int);
769 data
+= sizeof(unsigned int);
770 copied
+= sizeof(unsigned int);
773 case PTRACE_GET_LAST_BREAK
:
774 put_user(task_thread_info(child
)->last_break
,
775 (unsigned int __user
*) data
);
778 return compat_ptrace_request(child
, request
, addr
, data
);
782 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
786 /* Do the secure computing check first. */
787 if (secure_computing(regs
->gprs
[2])) {
788 /* seccomp failures shouldn't expose any additional code. */
794 * The sysc_tracesys code in entry.S stored the system
795 * call number to gprs[2].
797 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
798 (tracehook_report_syscall_entry(regs
) ||
799 regs
->gprs
[2] >= NR_syscalls
)) {
801 * Tracing decided this syscall should not happen or the
802 * debugger stored an invalid system call number. Skip
803 * the system call and the system call restart handling.
805 clear_thread_flag(TIF_SYSCALL
);
809 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
810 trace_sys_enter(regs
, regs
->gprs
[2]);
812 audit_syscall_entry(is_compat_task() ?
813 AUDIT_ARCH_S390
: AUDIT_ARCH_S390X
,
814 regs
->gprs
[2], regs
->orig_gpr2
,
815 regs
->gprs
[3], regs
->gprs
[4],
818 return ret
?: regs
->gprs
[2];
821 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
823 audit_syscall_exit(regs
);
825 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
826 trace_sys_exit(regs
, regs
->gprs
[2]);
828 if (test_thread_flag(TIF_SYSCALL_TRACE
))
829 tracehook_report_syscall_exit(regs
, 0);
833 * user_regset definitions.
836 static int s390_regs_get(struct task_struct
*target
,
837 const struct user_regset
*regset
,
838 unsigned int pos
, unsigned int count
,
839 void *kbuf
, void __user
*ubuf
)
841 if (target
== current
)
842 save_access_regs(target
->thread
.acrs
);
845 unsigned long *k
= kbuf
;
847 *k
++ = __peek_user(target
, pos
);
852 unsigned long __user
*u
= ubuf
;
854 if (__put_user(__peek_user(target
, pos
), u
++))
863 static int s390_regs_set(struct task_struct
*target
,
864 const struct user_regset
*regset
,
865 unsigned int pos
, unsigned int count
,
866 const void *kbuf
, const void __user
*ubuf
)
870 if (target
== current
)
871 save_access_regs(target
->thread
.acrs
);
874 const unsigned long *k
= kbuf
;
875 while (count
> 0 && !rc
) {
876 rc
= __poke_user(target
, pos
, *k
++);
881 const unsigned long __user
*u
= ubuf
;
882 while (count
> 0 && !rc
) {
884 rc
= __get_user(word
, u
++);
887 rc
= __poke_user(target
, pos
, word
);
893 if (rc
== 0 && target
== current
)
894 restore_access_regs(target
->thread
.acrs
);
899 static int s390_fpregs_get(struct task_struct
*target
,
900 const struct user_regset
*regset
, unsigned int pos
,
901 unsigned int count
, void *kbuf
, void __user
*ubuf
)
903 if (target
== current
)
904 save_fp_regs(&target
->thread
.fp_regs
);
906 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
907 &target
->thread
.fp_regs
, 0, -1);
910 static int s390_fpregs_set(struct task_struct
*target
,
911 const struct user_regset
*regset
, unsigned int pos
,
912 unsigned int count
, const void *kbuf
,
913 const void __user
*ubuf
)
917 if (target
== current
)
918 save_fp_regs(&target
->thread
.fp_regs
);
920 /* If setting FPC, must validate it first. */
921 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
922 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
923 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
924 0, offsetof(s390_fp_regs
, fprs
));
927 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
929 target
->thread
.fp_regs
.fpc
= fpc
[0];
932 if (rc
== 0 && count
> 0)
933 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
934 target
->thread
.fp_regs
.fprs
,
935 offsetof(s390_fp_regs
, fprs
), -1);
937 if (rc
== 0 && target
== current
)
938 restore_fp_regs(&target
->thread
.fp_regs
);
945 static int s390_last_break_get(struct task_struct
*target
,
946 const struct user_regset
*regset
,
947 unsigned int pos
, unsigned int count
,
948 void *kbuf
, void __user
*ubuf
)
952 unsigned long *k
= kbuf
;
953 *k
= task_thread_info(target
)->last_break
;
955 unsigned long __user
*u
= ubuf
;
956 if (__put_user(task_thread_info(target
)->last_break
, u
))
963 static int s390_last_break_set(struct task_struct
*target
,
964 const struct user_regset
*regset
,
965 unsigned int pos
, unsigned int count
,
966 const void *kbuf
, const void __user
*ubuf
)
971 static int s390_tdb_get(struct task_struct
*target
,
972 const struct user_regset
*regset
,
973 unsigned int pos
, unsigned int count
,
974 void *kbuf
, void __user
*ubuf
)
976 struct pt_regs
*regs
= task_pt_regs(target
);
979 if (!(regs
->int_code
& 0x200))
981 data
= target
->thread
.trap_tdb
;
982 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, data
, 0, 256);
985 static int s390_tdb_set(struct task_struct
*target
,
986 const struct user_regset
*regset
,
987 unsigned int pos
, unsigned int count
,
988 const void *kbuf
, const void __user
*ubuf
)
995 static int s390_system_call_get(struct task_struct
*target
,
996 const struct user_regset
*regset
,
997 unsigned int pos
, unsigned int count
,
998 void *kbuf
, void __user
*ubuf
)
1000 unsigned int *data
= &task_thread_info(target
)->system_call
;
1001 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1002 data
, 0, sizeof(unsigned int));
1005 static int s390_system_call_set(struct task_struct
*target
,
1006 const struct user_regset
*regset
,
1007 unsigned int pos
, unsigned int count
,
1008 const void *kbuf
, const void __user
*ubuf
)
1010 unsigned int *data
= &task_thread_info(target
)->system_call
;
1011 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1012 data
, 0, sizeof(unsigned int));
1015 static const struct user_regset s390_regsets
[] = {
1016 [REGSET_GENERAL
] = {
1017 .core_note_type
= NT_PRSTATUS
,
1018 .n
= sizeof(s390_regs
) / sizeof(long),
1019 .size
= sizeof(long),
1020 .align
= sizeof(long),
1021 .get
= s390_regs_get
,
1022 .set
= s390_regs_set
,
1025 .core_note_type
= NT_PRFPREG
,
1026 .n
= sizeof(s390_fp_regs
) / sizeof(long),
1027 .size
= sizeof(long),
1028 .align
= sizeof(long),
1029 .get
= s390_fpregs_get
,
1030 .set
= s390_fpregs_set
,
1033 [REGSET_LAST_BREAK
] = {
1034 .core_note_type
= NT_S390_LAST_BREAK
,
1036 .size
= sizeof(long),
1037 .align
= sizeof(long),
1038 .get
= s390_last_break_get
,
1039 .set
= s390_last_break_set
,
1042 .core_note_type
= NT_S390_TDB
,
1046 .get
= s390_tdb_get
,
1047 .set
= s390_tdb_set
,
1050 [REGSET_SYSTEM_CALL
] = {
1051 .core_note_type
= NT_S390_SYSTEM_CALL
,
1053 .size
= sizeof(unsigned int),
1054 .align
= sizeof(unsigned int),
1055 .get
= s390_system_call_get
,
1056 .set
= s390_system_call_set
,
1060 static const struct user_regset_view user_s390_view
= {
1061 .name
= UTS_MACHINE
,
1062 .e_machine
= EM_S390
,
1063 .regsets
= s390_regsets
,
1064 .n
= ARRAY_SIZE(s390_regsets
)
1067 #ifdef CONFIG_COMPAT
1068 static int s390_compat_regs_get(struct task_struct
*target
,
1069 const struct user_regset
*regset
,
1070 unsigned int pos
, unsigned int count
,
1071 void *kbuf
, void __user
*ubuf
)
1073 if (target
== current
)
1074 save_access_regs(target
->thread
.acrs
);
1077 compat_ulong_t
*k
= kbuf
;
1079 *k
++ = __peek_user_compat(target
, pos
);
1080 count
-= sizeof(*k
);
1084 compat_ulong_t __user
*u
= ubuf
;
1086 if (__put_user(__peek_user_compat(target
, pos
), u
++))
1088 count
-= sizeof(*u
);
1095 static int s390_compat_regs_set(struct task_struct
*target
,
1096 const struct user_regset
*regset
,
1097 unsigned int pos
, unsigned int count
,
1098 const void *kbuf
, const void __user
*ubuf
)
1102 if (target
== current
)
1103 save_access_regs(target
->thread
.acrs
);
1106 const compat_ulong_t
*k
= kbuf
;
1107 while (count
> 0 && !rc
) {
1108 rc
= __poke_user_compat(target
, pos
, *k
++);
1109 count
-= sizeof(*k
);
1113 const compat_ulong_t __user
*u
= ubuf
;
1114 while (count
> 0 && !rc
) {
1115 compat_ulong_t word
;
1116 rc
= __get_user(word
, u
++);
1119 rc
= __poke_user_compat(target
, pos
, word
);
1120 count
-= sizeof(*u
);
1125 if (rc
== 0 && target
== current
)
1126 restore_access_regs(target
->thread
.acrs
);
1131 static int s390_compat_regs_high_get(struct task_struct
*target
,
1132 const struct user_regset
*regset
,
1133 unsigned int pos
, unsigned int count
,
1134 void *kbuf
, void __user
*ubuf
)
1136 compat_ulong_t
*gprs_high
;
1138 gprs_high
= (compat_ulong_t
*)
1139 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
1141 compat_ulong_t
*k
= kbuf
;
1145 count
-= sizeof(*k
);
1148 compat_ulong_t __user
*u
= ubuf
;
1150 if (__put_user(*gprs_high
, u
++))
1153 count
-= sizeof(*u
);
1159 static int s390_compat_regs_high_set(struct task_struct
*target
,
1160 const struct user_regset
*regset
,
1161 unsigned int pos
, unsigned int count
,
1162 const void *kbuf
, const void __user
*ubuf
)
1164 compat_ulong_t
*gprs_high
;
1167 gprs_high
= (compat_ulong_t
*)
1168 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
1170 const compat_ulong_t
*k
= kbuf
;
1174 count
-= sizeof(*k
);
1177 const compat_ulong_t __user
*u
= ubuf
;
1178 while (count
> 0 && !rc
) {
1180 rc
= __get_user(word
, u
++);
1185 count
-= sizeof(*u
);
1192 static int s390_compat_last_break_get(struct task_struct
*target
,
1193 const struct user_regset
*regset
,
1194 unsigned int pos
, unsigned int count
,
1195 void *kbuf
, void __user
*ubuf
)
1197 compat_ulong_t last_break
;
1200 last_break
= task_thread_info(target
)->last_break
;
1202 unsigned long *k
= kbuf
;
1205 unsigned long __user
*u
= ubuf
;
1206 if (__put_user(last_break
, u
))
1213 static int s390_compat_last_break_set(struct task_struct
*target
,
1214 const struct user_regset
*regset
,
1215 unsigned int pos
, unsigned int count
,
1216 const void *kbuf
, const void __user
*ubuf
)
1221 static const struct user_regset s390_compat_regsets
[] = {
1222 [REGSET_GENERAL
] = {
1223 .core_note_type
= NT_PRSTATUS
,
1224 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
1225 .size
= sizeof(compat_long_t
),
1226 .align
= sizeof(compat_long_t
),
1227 .get
= s390_compat_regs_get
,
1228 .set
= s390_compat_regs_set
,
1231 .core_note_type
= NT_PRFPREG
,
1232 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
1233 .size
= sizeof(compat_long_t
),
1234 .align
= sizeof(compat_long_t
),
1235 .get
= s390_fpregs_get
,
1236 .set
= s390_fpregs_set
,
1238 [REGSET_LAST_BREAK
] = {
1239 .core_note_type
= NT_S390_LAST_BREAK
,
1241 .size
= sizeof(long),
1242 .align
= sizeof(long),
1243 .get
= s390_compat_last_break_get
,
1244 .set
= s390_compat_last_break_set
,
1247 .core_note_type
= NT_S390_TDB
,
1251 .get
= s390_tdb_get
,
1252 .set
= s390_tdb_set
,
1254 [REGSET_SYSTEM_CALL
] = {
1255 .core_note_type
= NT_S390_SYSTEM_CALL
,
1257 .size
= sizeof(compat_uint_t
),
1258 .align
= sizeof(compat_uint_t
),
1259 .get
= s390_system_call_get
,
1260 .set
= s390_system_call_set
,
1262 [REGSET_GENERAL_EXTENDED
] = {
1263 .core_note_type
= NT_S390_HIGH_GPRS
,
1264 .n
= sizeof(s390_compat_regs_high
) / sizeof(compat_long_t
),
1265 .size
= sizeof(compat_long_t
),
1266 .align
= sizeof(compat_long_t
),
1267 .get
= s390_compat_regs_high_get
,
1268 .set
= s390_compat_regs_high_set
,
1272 static const struct user_regset_view user_s390_compat_view
= {
1274 .e_machine
= EM_S390
,
1275 .regsets
= s390_compat_regsets
,
1276 .n
= ARRAY_SIZE(s390_compat_regsets
)
1280 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
1282 #ifdef CONFIG_COMPAT
1283 if (test_tsk_thread_flag(task
, TIF_31BIT
))
1284 return &user_s390_compat_view
;
1286 return &user_s390_view
;
1289 static const char *gpr_names
[NUM_GPRS
] = {
1290 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1291 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1294 unsigned long regs_get_register(struct pt_regs
*regs
, unsigned int offset
)
1296 if (offset
>= NUM_GPRS
)
1298 return regs
->gprs
[offset
];
1301 int regs_query_register_offset(const char *name
)
1303 unsigned long offset
;
1305 if (!name
|| *name
!= 'r')
1307 if (kstrtoul(name
+ 1, 10, &offset
))
1309 if (offset
>= NUM_GPRS
)
1314 const char *regs_query_register_name(unsigned int offset
)
1316 if (offset
>= NUM_GPRS
)
1318 return gpr_names
[offset
];
1321 static int regs_within_kernel_stack(struct pt_regs
*regs
, unsigned long addr
)
1323 unsigned long ksp
= kernel_stack_pointer(regs
);
1325 return (addr
& ~(THREAD_SIZE
- 1)) == (ksp
& ~(THREAD_SIZE
- 1));
1329 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1330 * @regs:pt_regs which contains kernel stack pointer.
1331 * @n:stack entry number.
1333 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1334 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1337 unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
, unsigned int n
)
1341 addr
= kernel_stack_pointer(regs
) + n
* sizeof(long);
1342 if (!regs_within_kernel_stack(regs
, addr
))
1344 return *(unsigned long *)addr
;