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 <trace/syscall.h>
24 #include <asm/compat.h>
25 #include <asm/segment.h>
27 #include <asm/pgtable.h>
28 #include <asm/pgalloc.h>
29 #include <asm/system.h>
30 #include <asm/uaccess.h>
31 #include <asm/unistd.h>
35 #include "compat_ptrace.h"
38 #define CREATE_TRACE_POINTS
39 #include <trace/events/syscalls.h>
45 REGSET_GENERAL_EXTENDED
,
48 void update_per_regs(struct task_struct
*task
)
50 struct pt_regs
*regs
= task_pt_regs(task
);
51 struct thread_struct
*thread
= &task
->thread
;
52 struct per_regs old
, new;
54 /* Copy user specified PER registers */
55 new.control
= thread
->per_user
.control
;
56 new.start
= thread
->per_user
.start
;
57 new.end
= thread
->per_user
.end
;
59 /* merge TIF_SINGLE_STEP into user specified PER registers. */
60 if (test_tsk_thread_flag(task
, TIF_SINGLE_STEP
)) {
61 new.control
|= PER_EVENT_IFETCH
;
63 new.end
= PSW_ADDR_INSN
;
66 /* Take care of the PER enablement bit in the PSW. */
67 if (!(new.control
& PER_EVENT_MASK
)) {
68 regs
->psw
.mask
&= ~PSW_MASK_PER
;
71 regs
->psw
.mask
|= PSW_MASK_PER
;
72 __ctl_store(old
, 9, 11);
73 if (memcmp(&new, &old
, sizeof(struct per_regs
)) != 0)
74 __ctl_load(new, 9, 11);
77 void user_enable_single_step(struct task_struct
*task
)
79 set_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
81 update_per_regs(task
);
84 void user_disable_single_step(struct task_struct
*task
)
86 clear_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
88 update_per_regs(task
);
92 * Called by kernel/ptrace.c when detaching..
94 * Clear all debugging related fields.
96 void ptrace_disable(struct task_struct
*task
)
98 memset(&task
->thread
.per_user
, 0, sizeof(task
->thread
.per_user
));
99 memset(&task
->thread
.per_event
, 0, sizeof(task
->thread
.per_event
));
100 clear_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
101 clear_tsk_thread_flag(task
, TIF_PER_TRAP
);
105 # define __ADDR_MASK 3
107 # define __ADDR_MASK 7
110 static inline unsigned long __peek_user_per(struct task_struct
*child
,
113 struct per_struct_kernel
*dummy
= NULL
;
115 if (addr
== (addr_t
) &dummy
->cr9
)
116 /* Control bits of the active per set. */
117 return test_thread_flag(TIF_SINGLE_STEP
) ?
118 PER_EVENT_IFETCH
: child
->thread
.per_user
.control
;
119 else if (addr
== (addr_t
) &dummy
->cr10
)
120 /* Start address of the active per set. */
121 return test_thread_flag(TIF_SINGLE_STEP
) ?
122 0 : child
->thread
.per_user
.start
;
123 else if (addr
== (addr_t
) &dummy
->cr11
)
124 /* End address of the active per set. */
125 return test_thread_flag(TIF_SINGLE_STEP
) ?
126 PSW_ADDR_INSN
: child
->thread
.per_user
.end
;
127 else if (addr
== (addr_t
) &dummy
->bits
)
128 /* Single-step bit. */
129 return test_thread_flag(TIF_SINGLE_STEP
) ?
130 (1UL << (BITS_PER_LONG
- 1)) : 0;
131 else if (addr
== (addr_t
) &dummy
->starting_addr
)
132 /* Start address of the user specified per set. */
133 return child
->thread
.per_user
.start
;
134 else if (addr
== (addr_t
) &dummy
->ending_addr
)
135 /* End address of the user specified per set. */
136 return child
->thread
.per_user
.end
;
137 else if (addr
== (addr_t
) &dummy
->perc_atmid
)
138 /* PER code, ATMID and AI of the last PER trap */
139 return (unsigned long)
140 child
->thread
.per_event
.cause
<< (BITS_PER_LONG
- 16);
141 else if (addr
== (addr_t
) &dummy
->address
)
142 /* Address of the last PER trap */
143 return child
->thread
.per_event
.address
;
144 else if (addr
== (addr_t
) &dummy
->access_id
)
145 /* Access id of the last PER trap */
146 return (unsigned long)
147 child
->thread
.per_event
.paid
<< (BITS_PER_LONG
- 8);
152 * Read the word at offset addr from the user area of a process. The
153 * trouble here is that the information is littered over different
154 * locations. The process registers are found on the kernel stack,
155 * the floating point stuff and the trace settings are stored in
156 * the task structure. In addition the different structures in
157 * struct user contain pad bytes that should be read as zeroes.
160 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
162 struct user
*dummy
= NULL
;
165 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
167 * psw and gprs are stored on the stack
169 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
170 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
)
171 /* Remove per bit from user psw. */
172 tmp
&= ~PSW_MASK_PER
;
174 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
176 * access registers are stored in the thread structure
178 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
181 * Very special case: old & broken 64 bit gdb reading
182 * from acrs[15]. Result is a 64 bit value. Read the
183 * 32 bit acrs[15] value and shift it by 32. Sick...
185 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
186 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
189 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
191 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
193 * orig_gpr2 is stored on the kernel stack
195 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
197 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
199 * prevent reads of padding hole between
200 * orig_gpr2 and fp_regs on s390.
204 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
206 * floating point regs. are stored in the thread structure
208 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
209 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
210 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
)
211 tmp
&= (unsigned long) FPC_VALID_MASK
212 << (BITS_PER_LONG
- 32);
214 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
216 * Handle access to the per_info structure.
218 addr
-= (addr_t
) &dummy
->regs
.per_info
;
219 tmp
= __peek_user_per(child
, addr
);
228 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
233 * Stupid gdb peeks/pokes the access registers in 64 bit with
234 * an alignment of 4. Programmers from hell...
238 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
239 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
242 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
245 tmp
= __peek_user(child
, addr
);
246 return put_user(tmp
, (addr_t __user
*) data
);
249 static inline void __poke_user_per(struct task_struct
*child
,
250 addr_t addr
, addr_t data
)
252 struct per_struct_kernel
*dummy
= NULL
;
255 * There are only three fields in the per_info struct that the
256 * debugger user can write to.
257 * 1) cr9: the debugger wants to set a new PER event mask
258 * 2) starting_addr: the debugger wants to set a new starting
259 * address to use with the PER event mask.
260 * 3) ending_addr: the debugger wants to set a new ending
261 * address to use with the PER event mask.
262 * The user specified PER event mask and the start and end
263 * addresses are used only if single stepping is not in effect.
264 * Writes to any other field in per_info are ignored.
266 if (addr
== (addr_t
) &dummy
->cr9
)
267 /* PER event mask of the user specified per set. */
268 child
->thread
.per_user
.control
=
269 data
& (PER_EVENT_MASK
| PER_CONTROL_MASK
);
270 else if (addr
== (addr_t
) &dummy
->starting_addr
)
271 /* Starting address of the user specified per set. */
272 child
->thread
.per_user
.start
= data
;
273 else if (addr
== (addr_t
) &dummy
->ending_addr
)
274 /* Ending address of the user specified per set. */
275 child
->thread
.per_user
.end
= data
;
279 * Write a word to the user area of a process at location addr. This
280 * operation does have an additional problem compared to peek_user.
281 * Stores to the program status word and on the floating point
282 * control register needs to get checked for validity.
284 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
286 struct user
*dummy
= NULL
;
289 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
291 * psw and gprs are stored on the stack
293 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
&&
295 data
!= PSW_MASK_MERGE(psw_user32_bits
, data
) &&
297 data
!= PSW_MASK_MERGE(psw_user_bits
, data
))
298 /* Invalid psw mask. */
301 if (addr
== (addr_t
) &dummy
->regs
.psw
.addr
)
302 /* I'd like to reject addresses without the
303 high order bit but older gdb's rely on it */
304 data
|= PSW_ADDR_AMODE
;
306 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
308 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
310 * access registers are stored in the thread structure
312 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
315 * Very special case: old & broken 64 bit gdb writing
316 * to acrs[15] with a 64 bit value. Ignore the lower
317 * half of the value and write the upper 32 bit to
320 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
321 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
324 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
326 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
328 * orig_gpr2 is stored on the kernel stack
330 task_pt_regs(child
)->orig_gpr2
= data
;
332 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
334 * prevent writes of padding hole between
335 * orig_gpr2 and fp_regs on s390.
339 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
341 * floating point regs. are stored in the thread structure
343 if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
&&
344 (data
& ~((unsigned long) FPC_VALID_MASK
345 << (BITS_PER_LONG
- 32))) != 0)
347 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
;
348 *(addr_t
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = data
;
350 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
352 * Handle access to the per_info structure.
354 addr
-= (addr_t
) &dummy
->regs
.per_info
;
355 __poke_user_per(child
, addr
, data
);
362 static int poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
367 * Stupid gdb peeks/pokes the access registers in 64 bit with
368 * an alignment of 4. Programmers from hell indeed...
372 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
373 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
376 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
379 return __poke_user(child
, addr
, data
);
382 long arch_ptrace(struct task_struct
*child
, long request
,
383 unsigned long addr
, unsigned long data
)
390 /* read the word at location addr in the USER area. */
391 return peek_user(child
, addr
, data
);
394 /* write the word at location addr in the USER area */
395 return poke_user(child
, addr
, data
);
397 case PTRACE_PEEKUSR_AREA
:
398 case PTRACE_POKEUSR_AREA
:
399 if (copy_from_user(&parea
, (void __force __user
*) addr
,
402 addr
= parea
.kernel_addr
;
403 data
= parea
.process_addr
;
405 while (copied
< parea
.len
) {
406 if (request
== PTRACE_PEEKUSR_AREA
)
407 ret
= peek_user(child
, addr
, data
);
411 (addr_t __force __user
*) data
))
413 ret
= poke_user(child
, addr
, utmp
);
417 addr
+= sizeof(unsigned long);
418 data
+= sizeof(unsigned long);
419 copied
+= sizeof(unsigned long);
422 case PTRACE_GET_LAST_BREAK
:
423 put_user(task_thread_info(child
)->last_break
,
424 (unsigned long __user
*) data
);
427 /* Removing high order bit from addr (only for 31 bit). */
428 addr
&= PSW_ADDR_INSN
;
429 return ptrace_request(child
, request
, addr
, data
);
435 * Now the fun part starts... a 31 bit program running in the
436 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
437 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
438 * to handle, the difference to the 64 bit versions of the requests
439 * is that the access is done in multiples of 4 byte instead of
440 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
441 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
442 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
443 * is a 31 bit program too, the content of struct user can be
444 * emulated. A 31 bit program peeking into the struct user of
445 * a 64 bit program is a no-no.
449 * Same as peek_user_per but for a 31 bit program.
451 static inline __u32
__peek_user_per_compat(struct task_struct
*child
,
454 struct compat_per_struct_kernel
*dummy32
= NULL
;
456 if (addr
== (addr_t
) &dummy32
->cr9
)
457 /* Control bits of the active per set. */
458 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
459 PER_EVENT_IFETCH
: child
->thread
.per_user
.control
;
460 else if (addr
== (addr_t
) &dummy32
->cr10
)
461 /* Start address of the active per set. */
462 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
463 0 : child
->thread
.per_user
.start
;
464 else if (addr
== (addr_t
) &dummy32
->cr11
)
465 /* End address of the active per set. */
466 return test_thread_flag(TIF_SINGLE_STEP
) ?
467 PSW32_ADDR_INSN
: child
->thread
.per_user
.end
;
468 else if (addr
== (addr_t
) &dummy32
->bits
)
469 /* Single-step bit. */
470 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
472 else if (addr
== (addr_t
) &dummy32
->starting_addr
)
473 /* Start address of the user specified per set. */
474 return (__u32
) child
->thread
.per_user
.start
;
475 else if (addr
== (addr_t
) &dummy32
->ending_addr
)
476 /* End address of the user specified per set. */
477 return (__u32
) child
->thread
.per_user
.end
;
478 else if (addr
== (addr_t
) &dummy32
->perc_atmid
)
479 /* PER code, ATMID and AI of the last PER trap */
480 return (__u32
) child
->thread
.per_event
.cause
<< 16;
481 else if (addr
== (addr_t
) &dummy32
->address
)
482 /* Address of the last PER trap */
483 return (__u32
) child
->thread
.per_event
.address
;
484 else if (addr
== (addr_t
) &dummy32
->access_id
)
485 /* Access id of the last PER trap */
486 return (__u32
) child
->thread
.per_event
.paid
<< 24;
491 * Same as peek_user but for a 31 bit program.
493 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
495 struct compat_user
*dummy32
= NULL
;
499 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
501 * psw and gprs are stored on the stack
503 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
504 /* Fake a 31 bit psw mask. */
505 tmp
= (__u32
)(task_pt_regs(child
)->psw
.mask
>> 32);
506 tmp
= PSW32_MASK_MERGE(psw32_user_bits
, tmp
);
507 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
508 /* Fake a 31 bit psw address. */
509 tmp
= (__u32
) task_pt_regs(child
)->psw
.addr
|
513 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
+
516 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
518 * access registers are stored in the thread structure
520 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
521 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
523 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
525 * orig_gpr2 is stored on the kernel stack
527 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
529 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
531 * prevent reads of padding hole between
532 * orig_gpr2 and fp_regs on s390.
536 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
538 * floating point regs. are stored in the thread structure
540 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
541 tmp
= *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
);
543 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
545 * Handle access to the per_info structure.
547 addr
-= (addr_t
) &dummy32
->regs
.per_info
;
548 tmp
= __peek_user_per_compat(child
, addr
);
556 static int peek_user_compat(struct task_struct
*child
,
557 addr_t addr
, addr_t data
)
561 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user
) - 3)
564 tmp
= __peek_user_compat(child
, addr
);
565 return put_user(tmp
, (__u32 __user
*) data
);
569 * Same as poke_user_per but for a 31 bit program.
571 static inline void __poke_user_per_compat(struct task_struct
*child
,
572 addr_t addr
, __u32 data
)
574 struct compat_per_struct_kernel
*dummy32
= NULL
;
576 if (addr
== (addr_t
) &dummy32
->cr9
)
577 /* PER event mask of the user specified per set. */
578 child
->thread
.per_user
.control
=
579 data
& (PER_EVENT_MASK
| PER_CONTROL_MASK
);
580 else if (addr
== (addr_t
) &dummy32
->starting_addr
)
581 /* Starting address of the user specified per set. */
582 child
->thread
.per_user
.start
= data
;
583 else if (addr
== (addr_t
) &dummy32
->ending_addr
)
584 /* Ending address of the user specified per set. */
585 child
->thread
.per_user
.end
= data
;
589 * Same as poke_user but for a 31 bit program.
591 static int __poke_user_compat(struct task_struct
*child
,
592 addr_t addr
, addr_t data
)
594 struct compat_user
*dummy32
= NULL
;
595 __u32 tmp
= (__u32
) data
;
598 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
600 * psw, gprs, acrs and orig_gpr2 are stored on the stack
602 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
603 /* Build a 64 bit psw mask from 31 bit mask. */
604 if (tmp
!= PSW32_MASK_MERGE(psw32_user_bits
, tmp
))
605 /* Invalid psw mask. */
607 task_pt_regs(child
)->psw
.mask
=
608 PSW_MASK_MERGE(psw_user32_bits
, (__u64
) tmp
<< 32);
609 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
610 /* Build a 64 bit psw address from 31 bit address. */
611 task_pt_regs(child
)->psw
.addr
=
612 (__u64
) tmp
& PSW32_ADDR_INSN
;
615 *(__u32
*)((addr_t
) &task_pt_regs(child
)->psw
618 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
620 * access registers are stored in the thread structure
622 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
623 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
625 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
627 * orig_gpr2 is stored on the kernel stack
629 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
631 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
633 * prevent writess of padding hole between
634 * orig_gpr2 and fp_regs on s390.
638 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
640 * floating point regs. are stored in the thread structure
642 if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
&&
643 (tmp
& ~FPC_VALID_MASK
) != 0)
644 /* Invalid floating point control. */
646 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
;
647 *(__u32
*)((addr_t
) &child
->thread
.fp_regs
+ offset
) = tmp
;
649 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
651 * Handle access to the per_info structure.
653 addr
-= (addr_t
) &dummy32
->regs
.per_info
;
654 __poke_user_per_compat(child
, addr
, data
);
660 static int poke_user_compat(struct task_struct
*child
,
661 addr_t addr
, addr_t data
)
663 if (!is_compat_task() || (addr
& 3) ||
664 addr
> sizeof(struct compat_user
) - 3)
667 return __poke_user_compat(child
, addr
, data
);
670 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
671 compat_ulong_t caddr
, compat_ulong_t cdata
)
673 unsigned long addr
= caddr
;
674 unsigned long data
= cdata
;
675 compat_ptrace_area parea
;
680 /* read the word at location addr in the USER area. */
681 return peek_user_compat(child
, addr
, data
);
684 /* write the word at location addr in the USER area */
685 return poke_user_compat(child
, addr
, data
);
687 case PTRACE_PEEKUSR_AREA
:
688 case PTRACE_POKEUSR_AREA
:
689 if (copy_from_user(&parea
, (void __force __user
*) addr
,
692 addr
= parea
.kernel_addr
;
693 data
= parea
.process_addr
;
695 while (copied
< parea
.len
) {
696 if (request
== PTRACE_PEEKUSR_AREA
)
697 ret
= peek_user_compat(child
, addr
, data
);
701 (__u32 __force __user
*) data
))
703 ret
= poke_user_compat(child
, addr
, utmp
);
707 addr
+= sizeof(unsigned int);
708 data
+= sizeof(unsigned int);
709 copied
+= sizeof(unsigned int);
712 case PTRACE_GET_LAST_BREAK
:
713 put_user(task_thread_info(child
)->last_break
,
714 (unsigned int __user
*) data
);
717 return compat_ptrace_request(child
, request
, addr
, data
);
721 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
725 /* Do the secure computing check first. */
726 secure_computing(regs
->gprs
[2]);
729 * The sysc_tracesys code in entry.S stored the system
730 * call number to gprs[2].
732 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
733 (tracehook_report_syscall_entry(regs
) ||
734 regs
->gprs
[2] >= NR_syscalls
)) {
736 * Tracing decided this syscall should not happen or the
737 * debugger stored an invalid system call number. Skip
738 * the system call and the system call restart handling.
744 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
745 trace_sys_enter(regs
, regs
->gprs
[2]);
747 if (unlikely(current
->audit_context
))
748 audit_syscall_entry(is_compat_task() ?
749 AUDIT_ARCH_S390
: AUDIT_ARCH_S390X
,
750 regs
->gprs
[2], regs
->orig_gpr2
,
751 regs
->gprs
[3], regs
->gprs
[4],
753 return ret
?: regs
->gprs
[2];
756 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
758 if (unlikely(current
->audit_context
))
759 audit_syscall_exit(AUDITSC_RESULT(regs
->gprs
[2]),
762 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
763 trace_sys_exit(regs
, regs
->gprs
[2]);
765 if (test_thread_flag(TIF_SYSCALL_TRACE
))
766 tracehook_report_syscall_exit(regs
, 0);
770 * user_regset definitions.
773 static int s390_regs_get(struct task_struct
*target
,
774 const struct user_regset
*regset
,
775 unsigned int pos
, unsigned int count
,
776 void *kbuf
, void __user
*ubuf
)
778 if (target
== current
)
779 save_access_regs(target
->thread
.acrs
);
782 unsigned long *k
= kbuf
;
784 *k
++ = __peek_user(target
, pos
);
789 unsigned long __user
*u
= ubuf
;
791 if (__put_user(__peek_user(target
, pos
), u
++))
800 static int s390_regs_set(struct task_struct
*target
,
801 const struct user_regset
*regset
,
802 unsigned int pos
, unsigned int count
,
803 const void *kbuf
, const void __user
*ubuf
)
807 if (target
== current
)
808 save_access_regs(target
->thread
.acrs
);
811 const unsigned long *k
= kbuf
;
812 while (count
> 0 && !rc
) {
813 rc
= __poke_user(target
, pos
, *k
++);
818 const unsigned long __user
*u
= ubuf
;
819 while (count
> 0 && !rc
) {
821 rc
= __get_user(word
, u
++);
824 rc
= __poke_user(target
, pos
, word
);
830 if (rc
== 0 && target
== current
)
831 restore_access_regs(target
->thread
.acrs
);
836 static int s390_fpregs_get(struct task_struct
*target
,
837 const struct user_regset
*regset
, unsigned int pos
,
838 unsigned int count
, void *kbuf
, void __user
*ubuf
)
840 if (target
== current
)
841 save_fp_regs(&target
->thread
.fp_regs
);
843 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
844 &target
->thread
.fp_regs
, 0, -1);
847 static int s390_fpregs_set(struct task_struct
*target
,
848 const struct user_regset
*regset
, unsigned int pos
,
849 unsigned int count
, const void *kbuf
,
850 const void __user
*ubuf
)
854 if (target
== current
)
855 save_fp_regs(&target
->thread
.fp_regs
);
857 /* If setting FPC, must validate it first. */
858 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
859 u32 fpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
860 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &fpc
,
861 0, offsetof(s390_fp_regs
, fprs
));
864 if ((fpc
[0] & ~FPC_VALID_MASK
) != 0 || fpc
[1] != 0)
866 target
->thread
.fp_regs
.fpc
= fpc
[0];
869 if (rc
== 0 && count
> 0)
870 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
871 target
->thread
.fp_regs
.fprs
,
872 offsetof(s390_fp_regs
, fprs
), -1);
874 if (rc
== 0 && target
== current
)
875 restore_fp_regs(&target
->thread
.fp_regs
);
882 static int s390_last_break_get(struct task_struct
*target
,
883 const struct user_regset
*regset
,
884 unsigned int pos
, unsigned int count
,
885 void *kbuf
, void __user
*ubuf
)
889 unsigned long *k
= kbuf
;
890 *k
= task_thread_info(target
)->last_break
;
892 unsigned long __user
*u
= ubuf
;
893 if (__put_user(task_thread_info(target
)->last_break
, u
))
902 static const struct user_regset s390_regsets
[] = {
904 .core_note_type
= NT_PRSTATUS
,
905 .n
= sizeof(s390_regs
) / sizeof(long),
906 .size
= sizeof(long),
907 .align
= sizeof(long),
908 .get
= s390_regs_get
,
909 .set
= s390_regs_set
,
912 .core_note_type
= NT_PRFPREG
,
913 .n
= sizeof(s390_fp_regs
) / sizeof(long),
914 .size
= sizeof(long),
915 .align
= sizeof(long),
916 .get
= s390_fpregs_get
,
917 .set
= s390_fpregs_set
,
920 [REGSET_LAST_BREAK
] = {
921 .core_note_type
= NT_S390_LAST_BREAK
,
923 .size
= sizeof(long),
924 .align
= sizeof(long),
925 .get
= s390_last_break_get
,
930 static const struct user_regset_view user_s390_view
= {
932 .e_machine
= EM_S390
,
933 .regsets
= s390_regsets
,
934 .n
= ARRAY_SIZE(s390_regsets
)
938 static int s390_compat_regs_get(struct task_struct
*target
,
939 const struct user_regset
*regset
,
940 unsigned int pos
, unsigned int count
,
941 void *kbuf
, void __user
*ubuf
)
943 if (target
== current
)
944 save_access_regs(target
->thread
.acrs
);
947 compat_ulong_t
*k
= kbuf
;
949 *k
++ = __peek_user_compat(target
, pos
);
954 compat_ulong_t __user
*u
= ubuf
;
956 if (__put_user(__peek_user_compat(target
, pos
), u
++))
965 static int s390_compat_regs_set(struct task_struct
*target
,
966 const struct user_regset
*regset
,
967 unsigned int pos
, unsigned int count
,
968 const void *kbuf
, const void __user
*ubuf
)
972 if (target
== current
)
973 save_access_regs(target
->thread
.acrs
);
976 const compat_ulong_t
*k
= kbuf
;
977 while (count
> 0 && !rc
) {
978 rc
= __poke_user_compat(target
, pos
, *k
++);
983 const compat_ulong_t __user
*u
= ubuf
;
984 while (count
> 0 && !rc
) {
986 rc
= __get_user(word
, u
++);
989 rc
= __poke_user_compat(target
, pos
, word
);
995 if (rc
== 0 && target
== current
)
996 restore_access_regs(target
->thread
.acrs
);
1001 static int s390_compat_regs_high_get(struct task_struct
*target
,
1002 const struct user_regset
*regset
,
1003 unsigned int pos
, unsigned int count
,
1004 void *kbuf
, void __user
*ubuf
)
1006 compat_ulong_t
*gprs_high
;
1008 gprs_high
= (compat_ulong_t
*)
1009 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
1011 compat_ulong_t
*k
= kbuf
;
1015 count
-= sizeof(*k
);
1018 compat_ulong_t __user
*u
= ubuf
;
1020 if (__put_user(*gprs_high
, u
++))
1023 count
-= sizeof(*u
);
1029 static int s390_compat_regs_high_set(struct task_struct
*target
,
1030 const struct user_regset
*regset
,
1031 unsigned int pos
, unsigned int count
,
1032 const void *kbuf
, const void __user
*ubuf
)
1034 compat_ulong_t
*gprs_high
;
1037 gprs_high
= (compat_ulong_t
*)
1038 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
1040 const compat_ulong_t
*k
= kbuf
;
1044 count
-= sizeof(*k
);
1047 const compat_ulong_t __user
*u
= ubuf
;
1048 while (count
> 0 && !rc
) {
1050 rc
= __get_user(word
, u
++);
1055 count
-= sizeof(*u
);
1062 static int s390_compat_last_break_get(struct task_struct
*target
,
1063 const struct user_regset
*regset
,
1064 unsigned int pos
, unsigned int count
,
1065 void *kbuf
, void __user
*ubuf
)
1067 compat_ulong_t last_break
;
1070 last_break
= task_thread_info(target
)->last_break
;
1072 unsigned long *k
= kbuf
;
1075 unsigned long __user
*u
= ubuf
;
1076 if (__put_user(last_break
, u
))
1083 static const struct user_regset s390_compat_regsets
[] = {
1084 [REGSET_GENERAL
] = {
1085 .core_note_type
= NT_PRSTATUS
,
1086 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
1087 .size
= sizeof(compat_long_t
),
1088 .align
= sizeof(compat_long_t
),
1089 .get
= s390_compat_regs_get
,
1090 .set
= s390_compat_regs_set
,
1093 .core_note_type
= NT_PRFPREG
,
1094 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
1095 .size
= sizeof(compat_long_t
),
1096 .align
= sizeof(compat_long_t
),
1097 .get
= s390_fpregs_get
,
1098 .set
= s390_fpregs_set
,
1100 [REGSET_LAST_BREAK
] = {
1101 .core_note_type
= NT_S390_LAST_BREAK
,
1103 .size
= sizeof(long),
1104 .align
= sizeof(long),
1105 .get
= s390_compat_last_break_get
,
1107 [REGSET_GENERAL_EXTENDED
] = {
1108 .core_note_type
= NT_S390_HIGH_GPRS
,
1109 .n
= sizeof(s390_compat_regs_high
) / sizeof(compat_long_t
),
1110 .size
= sizeof(compat_long_t
),
1111 .align
= sizeof(compat_long_t
),
1112 .get
= s390_compat_regs_high_get
,
1113 .set
= s390_compat_regs_high_set
,
1117 static const struct user_regset_view user_s390_compat_view
= {
1119 .e_machine
= EM_S390
,
1120 .regsets
= s390_compat_regsets
,
1121 .n
= ARRAY_SIZE(s390_compat_regsets
)
1125 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
1127 #ifdef CONFIG_COMPAT
1128 if (test_tsk_thread_flag(task
, TIF_31BIT
))
1129 return &user_s390_compat_view
;
1131 return &user_s390_view
;
1134 static const char *gpr_names
[NUM_GPRS
] = {
1135 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1136 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1139 unsigned long regs_get_register(struct pt_regs
*regs
, unsigned int offset
)
1141 if (offset
>= NUM_GPRS
)
1143 return regs
->gprs
[offset
];
1146 int regs_query_register_offset(const char *name
)
1148 unsigned long offset
;
1150 if (!name
|| *name
!= 'r')
1152 if (strict_strtoul(name
+ 1, 10, &offset
))
1154 if (offset
>= NUM_GPRS
)
1159 const char *regs_query_register_name(unsigned int offset
)
1161 if (offset
>= NUM_GPRS
)
1163 return gpr_names
[offset
];
1166 static int regs_within_kernel_stack(struct pt_regs
*regs
, unsigned long addr
)
1168 unsigned long ksp
= kernel_stack_pointer(regs
);
1170 return (addr
& ~(THREAD_SIZE
- 1)) == (ksp
& ~(THREAD_SIZE
- 1));
1174 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1175 * @regs:pt_regs which contains kernel stack pointer.
1176 * @n:stack entry number.
1178 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1179 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1182 unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
, unsigned int n
)
1186 addr
= kernel_stack_pointer(regs
) + n
* sizeof(long);
1187 if (!regs_within_kernel_stack(regs
, addr
))
1189 return *(unsigned long *)addr
;