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>
41 void update_cr_regs(struct task_struct
*task
)
43 struct pt_regs
*regs
= task_pt_regs(task
);
44 struct thread_struct
*thread
= &task
->thread
;
45 struct per_regs old
, new;
47 /* Take care of the enable/disable of transactional execution. */
48 if (MACHINE_HAS_TE
|| MACHINE_HAS_VX
) {
49 unsigned long cr
, cr_new
;
51 __ctl_store(cr
, 0, 0);
54 /* Set or clear transaction execution TXC bit 8. */
55 cr_new
|= (1UL << 55);
56 if (task
->thread
.per_flags
& PER_FLAG_NO_TE
)
57 cr_new
&= ~(1UL << 55);
60 /* Enable/disable of vector extension */
61 cr_new
&= ~(1UL << 17);
62 if (task
->thread
.vxrs
)
63 cr_new
|= (1UL << 17);
66 __ctl_load(cr_new
, 0, 0);
68 /* Set/clear transaction execution TDC bits 62/63. */
69 __ctl_store(cr
, 2, 2);
71 if (task
->thread
.per_flags
& PER_FLAG_TE_ABORT_RAND
) {
72 if (task
->thread
.per_flags
&
73 PER_FLAG_TE_ABORT_RAND_TEND
)
79 __ctl_load(cr_new
, 2, 2);
82 /* Copy user specified PER registers */
83 new.control
= thread
->per_user
.control
;
84 new.start
= thread
->per_user
.start
;
85 new.end
= thread
->per_user
.end
;
87 /* merge TIF_SINGLE_STEP into user specified PER registers. */
88 if (test_tsk_thread_flag(task
, TIF_SINGLE_STEP
) ||
89 test_tsk_thread_flag(task
, TIF_UPROBE_SINGLESTEP
)) {
90 if (test_tsk_thread_flag(task
, TIF_BLOCK_STEP
))
91 new.control
|= PER_EVENT_BRANCH
;
93 new.control
|= PER_EVENT_IFETCH
;
94 new.control
|= PER_CONTROL_SUSPENSION
;
95 new.control
|= PER_EVENT_TRANSACTION_END
;
96 if (test_tsk_thread_flag(task
, TIF_UPROBE_SINGLESTEP
))
97 new.control
|= PER_EVENT_IFETCH
;
99 new.end
= PSW_ADDR_INSN
;
102 /* Take care of the PER enablement bit in the PSW. */
103 if (!(new.control
& PER_EVENT_MASK
)) {
104 regs
->psw
.mask
&= ~PSW_MASK_PER
;
107 regs
->psw
.mask
|= PSW_MASK_PER
;
108 __ctl_store(old
, 9, 11);
109 if (memcmp(&new, &old
, sizeof(struct per_regs
)) != 0)
110 __ctl_load(new, 9, 11);
113 void user_enable_single_step(struct task_struct
*task
)
115 clear_tsk_thread_flag(task
, TIF_BLOCK_STEP
);
116 set_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
119 void user_disable_single_step(struct task_struct
*task
)
121 clear_tsk_thread_flag(task
, TIF_BLOCK_STEP
);
122 clear_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
125 void user_enable_block_step(struct task_struct
*task
)
127 set_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
128 set_tsk_thread_flag(task
, TIF_BLOCK_STEP
);
132 * Called by kernel/ptrace.c when detaching..
134 * Clear all debugging related fields.
136 void ptrace_disable(struct task_struct
*task
)
138 memset(&task
->thread
.per_user
, 0, sizeof(task
->thread
.per_user
));
139 memset(&task
->thread
.per_event
, 0, sizeof(task
->thread
.per_event
));
140 clear_tsk_thread_flag(task
, TIF_SINGLE_STEP
);
141 clear_pt_regs_flag(task_pt_regs(task
), PIF_PER_TRAP
);
142 task
->thread
.per_flags
= 0;
145 #define __ADDR_MASK 7
147 static inline unsigned long __peek_user_per(struct task_struct
*child
,
150 struct per_struct_kernel
*dummy
= NULL
;
152 if (addr
== (addr_t
) &dummy
->cr9
)
153 /* Control bits of the active per set. */
154 return test_thread_flag(TIF_SINGLE_STEP
) ?
155 PER_EVENT_IFETCH
: child
->thread
.per_user
.control
;
156 else if (addr
== (addr_t
) &dummy
->cr10
)
157 /* Start address of the active per set. */
158 return test_thread_flag(TIF_SINGLE_STEP
) ?
159 0 : child
->thread
.per_user
.start
;
160 else if (addr
== (addr_t
) &dummy
->cr11
)
161 /* End address of the active per set. */
162 return test_thread_flag(TIF_SINGLE_STEP
) ?
163 PSW_ADDR_INSN
: child
->thread
.per_user
.end
;
164 else if (addr
== (addr_t
) &dummy
->bits
)
165 /* Single-step bit. */
166 return test_thread_flag(TIF_SINGLE_STEP
) ?
167 (1UL << (BITS_PER_LONG
- 1)) : 0;
168 else if (addr
== (addr_t
) &dummy
->starting_addr
)
169 /* Start address of the user specified per set. */
170 return child
->thread
.per_user
.start
;
171 else if (addr
== (addr_t
) &dummy
->ending_addr
)
172 /* End address of the user specified per set. */
173 return child
->thread
.per_user
.end
;
174 else if (addr
== (addr_t
) &dummy
->perc_atmid
)
175 /* PER code, ATMID and AI of the last PER trap */
176 return (unsigned long)
177 child
->thread
.per_event
.cause
<< (BITS_PER_LONG
- 16);
178 else if (addr
== (addr_t
) &dummy
->address
)
179 /* Address of the last PER trap */
180 return child
->thread
.per_event
.address
;
181 else if (addr
== (addr_t
) &dummy
->access_id
)
182 /* Access id of the last PER trap */
183 return (unsigned long)
184 child
->thread
.per_event
.paid
<< (BITS_PER_LONG
- 8);
189 * Read the word at offset addr from the user area of a process. The
190 * trouble here is that the information is littered over different
191 * locations. The process registers are found on the kernel stack,
192 * the floating point stuff and the trace settings are stored in
193 * the task structure. In addition the different structures in
194 * struct user contain pad bytes that should be read as zeroes.
197 static unsigned long __peek_user(struct task_struct
*child
, addr_t addr
)
199 struct user
*dummy
= NULL
;
202 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
204 * psw and gprs are stored on the stack
206 tmp
= *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
);
207 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
) {
208 /* Return a clean psw mask. */
209 tmp
&= PSW_MASK_USER
| PSW_MASK_RI
;
210 tmp
|= PSW_USER_BITS
;
213 } else if (addr
< (addr_t
) &dummy
->regs
.orig_gpr2
) {
215 * access registers are stored in the thread structure
217 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
219 * Very special case: old & broken 64 bit gdb reading
220 * from acrs[15]. Result is a 64 bit value. Read the
221 * 32 bit acrs[15] value and shift it by 32. Sick...
223 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
224 tmp
= ((unsigned long) child
->thread
.acrs
[15]) << 32;
226 tmp
= *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
);
228 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
230 * orig_gpr2 is stored on the kernel stack
232 tmp
= (addr_t
) task_pt_regs(child
)->orig_gpr2
;
234 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
236 * prevent reads of padding hole between
237 * orig_gpr2 and fp_regs on s390.
241 } else if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
) {
243 * floating point control reg. is in the thread structure
245 tmp
= child
->thread
.fp_regs
.fpc
;
246 tmp
<<= BITS_PER_LONG
- 32;
248 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
250 * floating point regs. are either in child->thread.fp_regs
251 * or the child->thread.vxrs array
253 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
.fprs
;
254 if (child
->thread
.vxrs
)
256 ((addr_t
) child
->thread
.vxrs
+ 2*offset
);
259 ((addr_t
) &child
->thread
.fp_regs
.fprs
+ offset
);
261 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
263 * Handle access to the per_info structure.
265 addr
-= (addr_t
) &dummy
->regs
.per_info
;
266 tmp
= __peek_user_per(child
, addr
);
275 peek_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
280 * Stupid gdb peeks/pokes the access registers in 64 bit with
281 * an alignment of 4. Programmers from hell...
284 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
285 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
287 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
290 tmp
= __peek_user(child
, addr
);
291 return put_user(tmp
, (addr_t __user
*) data
);
294 static inline void __poke_user_per(struct task_struct
*child
,
295 addr_t addr
, addr_t data
)
297 struct per_struct_kernel
*dummy
= NULL
;
300 * There are only three fields in the per_info struct that the
301 * debugger user can write to.
302 * 1) cr9: the debugger wants to set a new PER event mask
303 * 2) starting_addr: the debugger wants to set a new starting
304 * address to use with the PER event mask.
305 * 3) ending_addr: the debugger wants to set a new ending
306 * address to use with the PER event mask.
307 * The user specified PER event mask and the start and end
308 * addresses are used only if single stepping is not in effect.
309 * Writes to any other field in per_info are ignored.
311 if (addr
== (addr_t
) &dummy
->cr9
)
312 /* PER event mask of the user specified per set. */
313 child
->thread
.per_user
.control
=
314 data
& (PER_EVENT_MASK
| PER_CONTROL_MASK
);
315 else if (addr
== (addr_t
) &dummy
->starting_addr
)
316 /* Starting address of the user specified per set. */
317 child
->thread
.per_user
.start
= data
;
318 else if (addr
== (addr_t
) &dummy
->ending_addr
)
319 /* Ending address of the user specified per set. */
320 child
->thread
.per_user
.end
= data
;
324 * Write a word to the user area of a process at location addr. This
325 * operation does have an additional problem compared to peek_user.
326 * Stores to the program status word and on the floating point
327 * control register needs to get checked for validity.
329 static int __poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
331 struct user
*dummy
= NULL
;
334 if (addr
< (addr_t
) &dummy
->regs
.acrs
) {
336 * psw and gprs are stored on the stack
338 if (addr
== (addr_t
) &dummy
->regs
.psw
.mask
) {
339 unsigned long mask
= PSW_MASK_USER
;
341 mask
|= is_ri_task(child
) ? PSW_MASK_RI
: 0;
342 if ((data
^ PSW_USER_BITS
) & ~mask
)
343 /* Invalid psw mask. */
345 if ((data
& PSW_MASK_ASC
) == PSW_ASC_HOME
)
346 /* Invalid address-space-control bits */
348 if ((data
& PSW_MASK_EA
) && !(data
& PSW_MASK_BA
))
349 /* Invalid addressing mode bits */
352 *(addr_t
*)((addr_t
) &task_pt_regs(child
)->psw
+ addr
) = data
;
354 } else if (addr
< (addr_t
) (&dummy
->regs
.orig_gpr2
)) {
356 * access registers are stored in the thread structure
358 offset
= addr
- (addr_t
) &dummy
->regs
.acrs
;
360 * Very special case: old & broken 64 bit gdb writing
361 * to acrs[15] with a 64 bit value. Ignore the lower
362 * half of the value and write the upper 32 bit to
365 if (addr
== (addr_t
) &dummy
->regs
.acrs
[15])
366 child
->thread
.acrs
[15] = (unsigned int) (data
>> 32);
368 *(addr_t
*)((addr_t
) &child
->thread
.acrs
+ offset
) = data
;
370 } else if (addr
== (addr_t
) &dummy
->regs
.orig_gpr2
) {
372 * orig_gpr2 is stored on the kernel stack
374 task_pt_regs(child
)->orig_gpr2
= data
;
376 } else if (addr
< (addr_t
) &dummy
->regs
.fp_regs
) {
378 * prevent writes of padding hole between
379 * orig_gpr2 and fp_regs on s390.
383 } else if (addr
== (addr_t
) &dummy
->regs
.fp_regs
.fpc
) {
385 * floating point control reg. is in the thread structure
387 if ((unsigned int) data
!= 0 ||
388 test_fp_ctl(data
>> (BITS_PER_LONG
- 32)))
390 child
->thread
.fp_regs
.fpc
= data
>> (BITS_PER_LONG
- 32);
392 } else if (addr
< (addr_t
) (&dummy
->regs
.fp_regs
+ 1)) {
394 * floating point regs. are either in child->thread.fp_regs
395 * or the child->thread.vxrs array
397 offset
= addr
- (addr_t
) &dummy
->regs
.fp_regs
.fprs
;
398 if (child
->thread
.vxrs
)
400 child
->thread
.vxrs
+ 2*offset
) = data
;
403 &child
->thread
.fp_regs
.fprs
+ offset
) = data
;
405 } else if (addr
< (addr_t
) (&dummy
->regs
.per_info
+ 1)) {
407 * Handle access to the per_info structure.
409 addr
-= (addr_t
) &dummy
->regs
.per_info
;
410 __poke_user_per(child
, addr
, data
);
417 static int poke_user(struct task_struct
*child
, addr_t addr
, addr_t data
)
422 * Stupid gdb peeks/pokes the access registers in 64 bit with
423 * an alignment of 4. Programmers from hell indeed...
426 if (addr
>= (addr_t
) &((struct user
*) NULL
)->regs
.acrs
&&
427 addr
< (addr_t
) &((struct user
*) NULL
)->regs
.orig_gpr2
)
429 if ((addr
& mask
) || addr
> sizeof(struct user
) - __ADDR_MASK
)
432 return __poke_user(child
, addr
, data
);
435 long arch_ptrace(struct task_struct
*child
, long request
,
436 unsigned long addr
, unsigned long data
)
443 /* read the word at location addr in the USER area. */
444 return peek_user(child
, addr
, data
);
447 /* write the word at location addr in the USER area */
448 return poke_user(child
, addr
, data
);
450 case PTRACE_PEEKUSR_AREA
:
451 case PTRACE_POKEUSR_AREA
:
452 if (copy_from_user(&parea
, (void __force __user
*) addr
,
455 addr
= parea
.kernel_addr
;
456 data
= parea
.process_addr
;
458 while (copied
< parea
.len
) {
459 if (request
== PTRACE_PEEKUSR_AREA
)
460 ret
= peek_user(child
, addr
, data
);
464 (addr_t __force __user
*) data
))
466 ret
= poke_user(child
, addr
, utmp
);
470 addr
+= sizeof(unsigned long);
471 data
+= sizeof(unsigned long);
472 copied
+= sizeof(unsigned long);
475 case PTRACE_GET_LAST_BREAK
:
476 put_user(task_thread_info(child
)->last_break
,
477 (unsigned long __user
*) data
);
479 case PTRACE_ENABLE_TE
:
482 child
->thread
.per_flags
&= ~PER_FLAG_NO_TE
;
484 case PTRACE_DISABLE_TE
:
487 child
->thread
.per_flags
|= PER_FLAG_NO_TE
;
488 child
->thread
.per_flags
&= ~PER_FLAG_TE_ABORT_RAND
;
490 case PTRACE_TE_ABORT_RAND
:
491 if (!MACHINE_HAS_TE
|| (child
->thread
.per_flags
& PER_FLAG_NO_TE
))
495 child
->thread
.per_flags
&= ~PER_FLAG_TE_ABORT_RAND
;
498 child
->thread
.per_flags
|= PER_FLAG_TE_ABORT_RAND
;
499 child
->thread
.per_flags
|= PER_FLAG_TE_ABORT_RAND_TEND
;
502 child
->thread
.per_flags
|= PER_FLAG_TE_ABORT_RAND
;
503 child
->thread
.per_flags
&= ~PER_FLAG_TE_ABORT_RAND_TEND
;
510 /* Removing high order bit from addr (only for 31 bit). */
511 addr
&= PSW_ADDR_INSN
;
512 return ptrace_request(child
, request
, addr
, data
);
518 * Now the fun part starts... a 31 bit program running in the
519 * 31 bit emulation tracing another program. PTRACE_PEEKTEXT,
520 * PTRACE_PEEKDATA, PTRACE_POKETEXT and PTRACE_POKEDATA are easy
521 * to handle, the difference to the 64 bit versions of the requests
522 * is that the access is done in multiples of 4 byte instead of
523 * 8 bytes (sizeof(unsigned long) on 31/64 bit).
524 * The ugly part are PTRACE_PEEKUSR, PTRACE_PEEKUSR_AREA,
525 * PTRACE_POKEUSR and PTRACE_POKEUSR_AREA. If the traced program
526 * is a 31 bit program too, the content of struct user can be
527 * emulated. A 31 bit program peeking into the struct user of
528 * a 64 bit program is a no-no.
532 * Same as peek_user_per but for a 31 bit program.
534 static inline __u32
__peek_user_per_compat(struct task_struct
*child
,
537 struct compat_per_struct_kernel
*dummy32
= NULL
;
539 if (addr
== (addr_t
) &dummy32
->cr9
)
540 /* Control bits of the active per set. */
541 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
542 PER_EVENT_IFETCH
: child
->thread
.per_user
.control
;
543 else if (addr
== (addr_t
) &dummy32
->cr10
)
544 /* Start address of the active per set. */
545 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
546 0 : child
->thread
.per_user
.start
;
547 else if (addr
== (addr_t
) &dummy32
->cr11
)
548 /* End address of the active per set. */
549 return test_thread_flag(TIF_SINGLE_STEP
) ?
550 PSW32_ADDR_INSN
: child
->thread
.per_user
.end
;
551 else if (addr
== (addr_t
) &dummy32
->bits
)
552 /* Single-step bit. */
553 return (__u32
) test_thread_flag(TIF_SINGLE_STEP
) ?
555 else if (addr
== (addr_t
) &dummy32
->starting_addr
)
556 /* Start address of the user specified per set. */
557 return (__u32
) child
->thread
.per_user
.start
;
558 else if (addr
== (addr_t
) &dummy32
->ending_addr
)
559 /* End address of the user specified per set. */
560 return (__u32
) child
->thread
.per_user
.end
;
561 else if (addr
== (addr_t
) &dummy32
->perc_atmid
)
562 /* PER code, ATMID and AI of the last PER trap */
563 return (__u32
) child
->thread
.per_event
.cause
<< 16;
564 else if (addr
== (addr_t
) &dummy32
->address
)
565 /* Address of the last PER trap */
566 return (__u32
) child
->thread
.per_event
.address
;
567 else if (addr
== (addr_t
) &dummy32
->access_id
)
568 /* Access id of the last PER trap */
569 return (__u32
) child
->thread
.per_event
.paid
<< 24;
574 * Same as peek_user but for a 31 bit program.
576 static u32
__peek_user_compat(struct task_struct
*child
, addr_t addr
)
578 struct compat_user
*dummy32
= NULL
;
582 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
583 struct pt_regs
*regs
= task_pt_regs(child
);
585 * psw and gprs are stored on the stack
587 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
588 /* Fake a 31 bit psw mask. */
589 tmp
= (__u32
)(regs
->psw
.mask
>> 32);
590 tmp
&= PSW32_MASK_USER
| PSW32_MASK_RI
;
591 tmp
|= PSW32_USER_BITS
;
592 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
593 /* Fake a 31 bit psw address. */
594 tmp
= (__u32
) regs
->psw
.addr
|
595 (__u32
)(regs
->psw
.mask
& PSW_MASK_BA
);
598 tmp
= *(__u32
*)((addr_t
) ®s
->psw
+ addr
*2 + 4);
600 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
602 * access registers are stored in the thread structure
604 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
605 tmp
= *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
);
607 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
609 * orig_gpr2 is stored on the kernel stack
611 tmp
= *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4);
613 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
615 * prevent reads of padding hole between
616 * orig_gpr2 and fp_regs on s390.
620 } else if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
) {
622 * floating point control reg. is in the thread structure
624 tmp
= child
->thread
.fp_regs
.fpc
;
626 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
628 * floating point regs. are either in child->thread.fp_regs
629 * or the child->thread.vxrs array
631 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
.fprs
;
632 if (child
->thread
.vxrs
)
634 ((addr_t
) child
->thread
.vxrs
+ 2*offset
);
637 ((addr_t
) &child
->thread
.fp_regs
.fprs
+ offset
);
639 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
641 * Handle access to the per_info structure.
643 addr
-= (addr_t
) &dummy32
->regs
.per_info
;
644 tmp
= __peek_user_per_compat(child
, addr
);
652 static int peek_user_compat(struct task_struct
*child
,
653 addr_t addr
, addr_t data
)
657 if (!is_compat_task() || (addr
& 3) || addr
> sizeof(struct user
) - 3)
660 tmp
= __peek_user_compat(child
, addr
);
661 return put_user(tmp
, (__u32 __user
*) data
);
665 * Same as poke_user_per but for a 31 bit program.
667 static inline void __poke_user_per_compat(struct task_struct
*child
,
668 addr_t addr
, __u32 data
)
670 struct compat_per_struct_kernel
*dummy32
= NULL
;
672 if (addr
== (addr_t
) &dummy32
->cr9
)
673 /* PER event mask of the user specified per set. */
674 child
->thread
.per_user
.control
=
675 data
& (PER_EVENT_MASK
| PER_CONTROL_MASK
);
676 else if (addr
== (addr_t
) &dummy32
->starting_addr
)
677 /* Starting address of the user specified per set. */
678 child
->thread
.per_user
.start
= data
;
679 else if (addr
== (addr_t
) &dummy32
->ending_addr
)
680 /* Ending address of the user specified per set. */
681 child
->thread
.per_user
.end
= data
;
685 * Same as poke_user but for a 31 bit program.
687 static int __poke_user_compat(struct task_struct
*child
,
688 addr_t addr
, addr_t data
)
690 struct compat_user
*dummy32
= NULL
;
691 __u32 tmp
= (__u32
) data
;
694 if (addr
< (addr_t
) &dummy32
->regs
.acrs
) {
695 struct pt_regs
*regs
= task_pt_regs(child
);
697 * psw, gprs, acrs and orig_gpr2 are stored on the stack
699 if (addr
== (addr_t
) &dummy32
->regs
.psw
.mask
) {
700 __u32 mask
= PSW32_MASK_USER
;
702 mask
|= is_ri_task(child
) ? PSW32_MASK_RI
: 0;
703 /* Build a 64 bit psw mask from 31 bit mask. */
704 if ((tmp
^ PSW32_USER_BITS
) & ~mask
)
705 /* Invalid psw mask. */
707 if ((data
& PSW32_MASK_ASC
) == PSW32_ASC_HOME
)
708 /* Invalid address-space-control bits */
710 regs
->psw
.mask
= (regs
->psw
.mask
& ~PSW_MASK_USER
) |
711 (regs
->psw
.mask
& PSW_MASK_BA
) |
712 (__u64
)(tmp
& mask
) << 32;
713 } else if (addr
== (addr_t
) &dummy32
->regs
.psw
.addr
) {
714 /* Build a 64 bit psw address from 31 bit address. */
715 regs
->psw
.addr
= (__u64
) tmp
& PSW32_ADDR_INSN
;
716 /* Transfer 31 bit amode bit to psw mask. */
717 regs
->psw
.mask
= (regs
->psw
.mask
& ~PSW_MASK_BA
) |
718 (__u64
)(tmp
& PSW32_ADDR_AMODE
);
721 *(__u32
*)((addr_t
) ®s
->psw
+ addr
*2 + 4) = tmp
;
723 } else if (addr
< (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
725 * access registers are stored in the thread structure
727 offset
= addr
- (addr_t
) &dummy32
->regs
.acrs
;
728 *(__u32
*)((addr_t
) &child
->thread
.acrs
+ offset
) = tmp
;
730 } else if (addr
== (addr_t
) (&dummy32
->regs
.orig_gpr2
)) {
732 * orig_gpr2 is stored on the kernel stack
734 *(__u32
*)((addr_t
) &task_pt_regs(child
)->orig_gpr2
+ 4) = tmp
;
736 } else if (addr
< (addr_t
) &dummy32
->regs
.fp_regs
) {
738 * prevent writess of padding hole between
739 * orig_gpr2 and fp_regs on s390.
743 } else if (addr
== (addr_t
) &dummy32
->regs
.fp_regs
.fpc
) {
745 * floating point control reg. is in the thread structure
747 if (test_fp_ctl(tmp
))
749 child
->thread
.fp_regs
.fpc
= data
;
751 } else if (addr
< (addr_t
) (&dummy32
->regs
.fp_regs
+ 1)) {
753 * floating point regs. are either in child->thread.fp_regs
754 * or the child->thread.vxrs array
756 offset
= addr
- (addr_t
) &dummy32
->regs
.fp_regs
.fprs
;
757 if (child
->thread
.vxrs
)
759 child
->thread
.vxrs
+ 2*offset
) = tmp
;
762 &child
->thread
.fp_regs
.fprs
+ offset
) = tmp
;
764 } else if (addr
< (addr_t
) (&dummy32
->regs
.per_info
+ 1)) {
766 * Handle access to the per_info structure.
768 addr
-= (addr_t
) &dummy32
->regs
.per_info
;
769 __poke_user_per_compat(child
, addr
, data
);
775 static int poke_user_compat(struct task_struct
*child
,
776 addr_t addr
, addr_t data
)
778 if (!is_compat_task() || (addr
& 3) ||
779 addr
> sizeof(struct compat_user
) - 3)
782 return __poke_user_compat(child
, addr
, data
);
785 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
786 compat_ulong_t caddr
, compat_ulong_t cdata
)
788 unsigned long addr
= caddr
;
789 unsigned long data
= cdata
;
790 compat_ptrace_area parea
;
795 /* read the word at location addr in the USER area. */
796 return peek_user_compat(child
, addr
, data
);
799 /* write the word at location addr in the USER area */
800 return poke_user_compat(child
, addr
, data
);
802 case PTRACE_PEEKUSR_AREA
:
803 case PTRACE_POKEUSR_AREA
:
804 if (copy_from_user(&parea
, (void __force __user
*) addr
,
807 addr
= parea
.kernel_addr
;
808 data
= parea
.process_addr
;
810 while (copied
< parea
.len
) {
811 if (request
== PTRACE_PEEKUSR_AREA
)
812 ret
= peek_user_compat(child
, addr
, data
);
816 (__u32 __force __user
*) data
))
818 ret
= poke_user_compat(child
, addr
, utmp
);
822 addr
+= sizeof(unsigned int);
823 data
+= sizeof(unsigned int);
824 copied
+= sizeof(unsigned int);
827 case PTRACE_GET_LAST_BREAK
:
828 put_user(task_thread_info(child
)->last_break
,
829 (unsigned int __user
*) data
);
832 return compat_ptrace_request(child
, request
, addr
, data
);
836 asmlinkage
long do_syscall_trace_enter(struct pt_regs
*regs
)
840 /* Do the secure computing check first. */
841 if (secure_computing()) {
842 /* seccomp failures shouldn't expose any additional code. */
848 * The sysc_tracesys code in entry.S stored the system
849 * call number to gprs[2].
851 if (test_thread_flag(TIF_SYSCALL_TRACE
) &&
852 (tracehook_report_syscall_entry(regs
) ||
853 regs
->gprs
[2] >= NR_syscalls
)) {
855 * Tracing decided this syscall should not happen or the
856 * debugger stored an invalid system call number. Skip
857 * the system call and the system call restart handling.
859 clear_pt_regs_flag(regs
, PIF_SYSCALL
);
863 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
864 trace_sys_enter(regs
, regs
->gprs
[2]);
866 audit_syscall_entry(regs
->gprs
[2], regs
->orig_gpr2
,
867 regs
->gprs
[3], regs
->gprs
[4],
870 return ret
?: regs
->gprs
[2];
873 asmlinkage
void do_syscall_trace_exit(struct pt_regs
*regs
)
875 audit_syscall_exit(regs
);
877 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT
)))
878 trace_sys_exit(regs
, regs
->gprs
[2]);
880 if (test_thread_flag(TIF_SYSCALL_TRACE
))
881 tracehook_report_syscall_exit(regs
, 0);
885 * user_regset definitions.
888 static int s390_regs_get(struct task_struct
*target
,
889 const struct user_regset
*regset
,
890 unsigned int pos
, unsigned int count
,
891 void *kbuf
, void __user
*ubuf
)
893 if (target
== current
)
894 save_access_regs(target
->thread
.acrs
);
897 unsigned long *k
= kbuf
;
899 *k
++ = __peek_user(target
, pos
);
904 unsigned long __user
*u
= ubuf
;
906 if (__put_user(__peek_user(target
, pos
), u
++))
915 static int s390_regs_set(struct task_struct
*target
,
916 const struct user_regset
*regset
,
917 unsigned int pos
, unsigned int count
,
918 const void *kbuf
, const void __user
*ubuf
)
922 if (target
== current
)
923 save_access_regs(target
->thread
.acrs
);
926 const unsigned long *k
= kbuf
;
927 while (count
> 0 && !rc
) {
928 rc
= __poke_user(target
, pos
, *k
++);
933 const unsigned long __user
*u
= ubuf
;
934 while (count
> 0 && !rc
) {
936 rc
= __get_user(word
, u
++);
939 rc
= __poke_user(target
, pos
, word
);
945 if (rc
== 0 && target
== current
)
946 restore_access_regs(target
->thread
.acrs
);
951 static int s390_fpregs_get(struct task_struct
*target
,
952 const struct user_regset
*regset
, unsigned int pos
,
953 unsigned int count
, void *kbuf
, void __user
*ubuf
)
955 if (target
== current
) {
956 save_fp_ctl(&target
->thread
.fp_regs
.fpc
);
957 save_fp_regs(target
->thread
.fp_regs
.fprs
);
958 } else if (target
->thread
.vxrs
) {
961 for (i
= 0; i
< __NUM_VXRS_LOW
; i
++)
962 target
->thread
.fp_regs
.fprs
[i
] =
963 *(freg_t
*)(target
->thread
.vxrs
+ i
);
965 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
966 &target
->thread
.fp_regs
, 0, -1);
969 static int s390_fpregs_set(struct task_struct
*target
,
970 const struct user_regset
*regset
, unsigned int pos
,
971 unsigned int count
, const void *kbuf
,
972 const void __user
*ubuf
)
976 if (target
== current
) {
977 save_fp_ctl(&target
->thread
.fp_regs
.fpc
);
978 save_fp_regs(target
->thread
.fp_regs
.fprs
);
981 /* If setting FPC, must validate it first. */
982 if (count
> 0 && pos
< offsetof(s390_fp_regs
, fprs
)) {
983 u32 ufpc
[2] = { target
->thread
.fp_regs
.fpc
, 0 };
984 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &ufpc
,
985 0, offsetof(s390_fp_regs
, fprs
));
988 if (ufpc
[1] != 0 || test_fp_ctl(ufpc
[0]))
990 target
->thread
.fp_regs
.fpc
= ufpc
[0];
993 if (rc
== 0 && count
> 0)
994 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
995 target
->thread
.fp_regs
.fprs
,
996 offsetof(s390_fp_regs
, fprs
), -1);
999 if (target
== current
) {
1000 restore_fp_ctl(&target
->thread
.fp_regs
.fpc
);
1001 restore_fp_regs(target
->thread
.fp_regs
.fprs
);
1002 } else if (target
->thread
.vxrs
) {
1005 for (i
= 0; i
< __NUM_VXRS_LOW
; i
++)
1006 *(freg_t
*)(target
->thread
.vxrs
+ i
) =
1007 target
->thread
.fp_regs
.fprs
[i
];
1014 static int s390_last_break_get(struct task_struct
*target
,
1015 const struct user_regset
*regset
,
1016 unsigned int pos
, unsigned int count
,
1017 void *kbuf
, void __user
*ubuf
)
1021 unsigned long *k
= kbuf
;
1022 *k
= task_thread_info(target
)->last_break
;
1024 unsigned long __user
*u
= ubuf
;
1025 if (__put_user(task_thread_info(target
)->last_break
, u
))
1032 static int s390_last_break_set(struct task_struct
*target
,
1033 const struct user_regset
*regset
,
1034 unsigned int pos
, unsigned int count
,
1035 const void *kbuf
, const void __user
*ubuf
)
1040 static int s390_tdb_get(struct task_struct
*target
,
1041 const struct user_regset
*regset
,
1042 unsigned int pos
, unsigned int count
,
1043 void *kbuf
, void __user
*ubuf
)
1045 struct pt_regs
*regs
= task_pt_regs(target
);
1046 unsigned char *data
;
1048 if (!(regs
->int_code
& 0x200))
1050 data
= target
->thread
.trap_tdb
;
1051 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, data
, 0, 256);
1054 static int s390_tdb_set(struct task_struct
*target
,
1055 const struct user_regset
*regset
,
1056 unsigned int pos
, unsigned int count
,
1057 const void *kbuf
, const void __user
*ubuf
)
1062 static int s390_vxrs_low_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 __u64 vxrs
[__NUM_VXRS_LOW
];
1070 if (!MACHINE_HAS_VX
)
1072 if (target
->thread
.vxrs
) {
1073 if (target
== current
)
1074 save_vx_regs(target
->thread
.vxrs
);
1075 for (i
= 0; i
< __NUM_VXRS_LOW
; i
++)
1076 vxrs
[i
] = *((__u64
*)(target
->thread
.vxrs
+ i
) + 1);
1078 memset(vxrs
, 0, sizeof(vxrs
));
1079 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, vxrs
, 0, -1);
1082 static int s390_vxrs_low_set(struct task_struct
*target
,
1083 const struct user_regset
*regset
,
1084 unsigned int pos
, unsigned int count
,
1085 const void *kbuf
, const void __user
*ubuf
)
1087 __u64 vxrs
[__NUM_VXRS_LOW
];
1090 if (!MACHINE_HAS_VX
)
1092 if (!target
->thread
.vxrs
) {
1093 rc
= alloc_vector_registers(target
);
1096 } else if (target
== current
)
1097 save_vx_regs(target
->thread
.vxrs
);
1099 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, vxrs
, 0, -1);
1101 for (i
= 0; i
< __NUM_VXRS_LOW
; i
++)
1102 *((__u64
*)(target
->thread
.vxrs
+ i
) + 1) = vxrs
[i
];
1103 if (target
== current
)
1104 restore_vx_regs(target
->thread
.vxrs
);
1110 static int s390_vxrs_high_get(struct task_struct
*target
,
1111 const struct user_regset
*regset
,
1112 unsigned int pos
, unsigned int count
,
1113 void *kbuf
, void __user
*ubuf
)
1115 __vector128 vxrs
[__NUM_VXRS_HIGH
];
1117 if (!MACHINE_HAS_VX
)
1119 if (target
->thread
.vxrs
) {
1120 if (target
== current
)
1121 save_vx_regs(target
->thread
.vxrs
);
1122 memcpy(vxrs
, target
->thread
.vxrs
+ __NUM_VXRS_LOW
,
1125 memset(vxrs
, 0, sizeof(vxrs
));
1126 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
, vxrs
, 0, -1);
1129 static int s390_vxrs_high_set(struct task_struct
*target
,
1130 const struct user_regset
*regset
,
1131 unsigned int pos
, unsigned int count
,
1132 const void *kbuf
, const void __user
*ubuf
)
1136 if (!MACHINE_HAS_VX
)
1138 if (!target
->thread
.vxrs
) {
1139 rc
= alloc_vector_registers(target
);
1142 } else if (target
== current
)
1143 save_vx_regs(target
->thread
.vxrs
);
1145 rc
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1146 target
->thread
.vxrs
+ __NUM_VXRS_LOW
, 0, -1);
1147 if (rc
== 0 && target
== current
)
1148 restore_vx_regs(target
->thread
.vxrs
);
1153 static int s390_system_call_get(struct task_struct
*target
,
1154 const struct user_regset
*regset
,
1155 unsigned int pos
, unsigned int count
,
1156 void *kbuf
, void __user
*ubuf
)
1158 unsigned int *data
= &task_thread_info(target
)->system_call
;
1159 return user_regset_copyout(&pos
, &count
, &kbuf
, &ubuf
,
1160 data
, 0, sizeof(unsigned int));
1163 static int s390_system_call_set(struct task_struct
*target
,
1164 const struct user_regset
*regset
,
1165 unsigned int pos
, unsigned int count
,
1166 const void *kbuf
, const void __user
*ubuf
)
1168 unsigned int *data
= &task_thread_info(target
)->system_call
;
1169 return user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
1170 data
, 0, sizeof(unsigned int));
1173 static const struct user_regset s390_regsets
[] = {
1175 .core_note_type
= NT_PRSTATUS
,
1176 .n
= sizeof(s390_regs
) / sizeof(long),
1177 .size
= sizeof(long),
1178 .align
= sizeof(long),
1179 .get
= s390_regs_get
,
1180 .set
= s390_regs_set
,
1183 .core_note_type
= NT_PRFPREG
,
1184 .n
= sizeof(s390_fp_regs
) / sizeof(long),
1185 .size
= sizeof(long),
1186 .align
= sizeof(long),
1187 .get
= s390_fpregs_get
,
1188 .set
= s390_fpregs_set
,
1191 .core_note_type
= NT_S390_SYSTEM_CALL
,
1193 .size
= sizeof(unsigned int),
1194 .align
= sizeof(unsigned int),
1195 .get
= s390_system_call_get
,
1196 .set
= s390_system_call_set
,
1199 .core_note_type
= NT_S390_LAST_BREAK
,
1201 .size
= sizeof(long),
1202 .align
= sizeof(long),
1203 .get
= s390_last_break_get
,
1204 .set
= s390_last_break_set
,
1207 .core_note_type
= NT_S390_TDB
,
1211 .get
= s390_tdb_get
,
1212 .set
= s390_tdb_set
,
1215 .core_note_type
= NT_S390_VXRS_LOW
,
1216 .n
= __NUM_VXRS_LOW
,
1217 .size
= sizeof(__u64
),
1218 .align
= sizeof(__u64
),
1219 .get
= s390_vxrs_low_get
,
1220 .set
= s390_vxrs_low_set
,
1223 .core_note_type
= NT_S390_VXRS_HIGH
,
1224 .n
= __NUM_VXRS_HIGH
,
1225 .size
= sizeof(__vector128
),
1226 .align
= sizeof(__vector128
),
1227 .get
= s390_vxrs_high_get
,
1228 .set
= s390_vxrs_high_set
,
1232 static const struct user_regset_view user_s390_view
= {
1233 .name
= UTS_MACHINE
,
1234 .e_machine
= EM_S390
,
1235 .regsets
= s390_regsets
,
1236 .n
= ARRAY_SIZE(s390_regsets
)
1239 #ifdef CONFIG_COMPAT
1240 static int s390_compat_regs_get(struct task_struct
*target
,
1241 const struct user_regset
*regset
,
1242 unsigned int pos
, unsigned int count
,
1243 void *kbuf
, void __user
*ubuf
)
1245 if (target
== current
)
1246 save_access_regs(target
->thread
.acrs
);
1249 compat_ulong_t
*k
= kbuf
;
1251 *k
++ = __peek_user_compat(target
, pos
);
1252 count
-= sizeof(*k
);
1256 compat_ulong_t __user
*u
= ubuf
;
1258 if (__put_user(__peek_user_compat(target
, pos
), u
++))
1260 count
-= sizeof(*u
);
1267 static int s390_compat_regs_set(struct task_struct
*target
,
1268 const struct user_regset
*regset
,
1269 unsigned int pos
, unsigned int count
,
1270 const void *kbuf
, const void __user
*ubuf
)
1274 if (target
== current
)
1275 save_access_regs(target
->thread
.acrs
);
1278 const compat_ulong_t
*k
= kbuf
;
1279 while (count
> 0 && !rc
) {
1280 rc
= __poke_user_compat(target
, pos
, *k
++);
1281 count
-= sizeof(*k
);
1285 const compat_ulong_t __user
*u
= ubuf
;
1286 while (count
> 0 && !rc
) {
1287 compat_ulong_t word
;
1288 rc
= __get_user(word
, u
++);
1291 rc
= __poke_user_compat(target
, pos
, word
);
1292 count
-= sizeof(*u
);
1297 if (rc
== 0 && target
== current
)
1298 restore_access_regs(target
->thread
.acrs
);
1303 static int s390_compat_regs_high_get(struct task_struct
*target
,
1304 const struct user_regset
*regset
,
1305 unsigned int pos
, unsigned int count
,
1306 void *kbuf
, void __user
*ubuf
)
1308 compat_ulong_t
*gprs_high
;
1310 gprs_high
= (compat_ulong_t
*)
1311 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
1313 compat_ulong_t
*k
= kbuf
;
1317 count
-= sizeof(*k
);
1320 compat_ulong_t __user
*u
= ubuf
;
1322 if (__put_user(*gprs_high
, u
++))
1325 count
-= sizeof(*u
);
1331 static int s390_compat_regs_high_set(struct task_struct
*target
,
1332 const struct user_regset
*regset
,
1333 unsigned int pos
, unsigned int count
,
1334 const void *kbuf
, const void __user
*ubuf
)
1336 compat_ulong_t
*gprs_high
;
1339 gprs_high
= (compat_ulong_t
*)
1340 &task_pt_regs(target
)->gprs
[pos
/ sizeof(compat_ulong_t
)];
1342 const compat_ulong_t
*k
= kbuf
;
1346 count
-= sizeof(*k
);
1349 const compat_ulong_t __user
*u
= ubuf
;
1350 while (count
> 0 && !rc
) {
1352 rc
= __get_user(word
, u
++);
1357 count
-= sizeof(*u
);
1364 static int s390_compat_last_break_get(struct task_struct
*target
,
1365 const struct user_regset
*regset
,
1366 unsigned int pos
, unsigned int count
,
1367 void *kbuf
, void __user
*ubuf
)
1369 compat_ulong_t last_break
;
1372 last_break
= task_thread_info(target
)->last_break
;
1374 unsigned long *k
= kbuf
;
1377 unsigned long __user
*u
= ubuf
;
1378 if (__put_user(last_break
, u
))
1385 static int s390_compat_last_break_set(struct task_struct
*target
,
1386 const struct user_regset
*regset
,
1387 unsigned int pos
, unsigned int count
,
1388 const void *kbuf
, const void __user
*ubuf
)
1393 static const struct user_regset s390_compat_regsets
[] = {
1395 .core_note_type
= NT_PRSTATUS
,
1396 .n
= sizeof(s390_compat_regs
) / sizeof(compat_long_t
),
1397 .size
= sizeof(compat_long_t
),
1398 .align
= sizeof(compat_long_t
),
1399 .get
= s390_compat_regs_get
,
1400 .set
= s390_compat_regs_set
,
1403 .core_note_type
= NT_PRFPREG
,
1404 .n
= sizeof(s390_fp_regs
) / sizeof(compat_long_t
),
1405 .size
= sizeof(compat_long_t
),
1406 .align
= sizeof(compat_long_t
),
1407 .get
= s390_fpregs_get
,
1408 .set
= s390_fpregs_set
,
1411 .core_note_type
= NT_S390_SYSTEM_CALL
,
1413 .size
= sizeof(compat_uint_t
),
1414 .align
= sizeof(compat_uint_t
),
1415 .get
= s390_system_call_get
,
1416 .set
= s390_system_call_set
,
1419 .core_note_type
= NT_S390_LAST_BREAK
,
1421 .size
= sizeof(long),
1422 .align
= sizeof(long),
1423 .get
= s390_compat_last_break_get
,
1424 .set
= s390_compat_last_break_set
,
1427 .core_note_type
= NT_S390_TDB
,
1431 .get
= s390_tdb_get
,
1432 .set
= s390_tdb_set
,
1435 .core_note_type
= NT_S390_VXRS_LOW
,
1436 .n
= __NUM_VXRS_LOW
,
1437 .size
= sizeof(__u64
),
1438 .align
= sizeof(__u64
),
1439 .get
= s390_vxrs_low_get
,
1440 .set
= s390_vxrs_low_set
,
1443 .core_note_type
= NT_S390_VXRS_HIGH
,
1444 .n
= __NUM_VXRS_HIGH
,
1445 .size
= sizeof(__vector128
),
1446 .align
= sizeof(__vector128
),
1447 .get
= s390_vxrs_high_get
,
1448 .set
= s390_vxrs_high_set
,
1451 .core_note_type
= NT_S390_HIGH_GPRS
,
1452 .n
= sizeof(s390_compat_regs_high
) / sizeof(compat_long_t
),
1453 .size
= sizeof(compat_long_t
),
1454 .align
= sizeof(compat_long_t
),
1455 .get
= s390_compat_regs_high_get
,
1456 .set
= s390_compat_regs_high_set
,
1460 static const struct user_regset_view user_s390_compat_view
= {
1462 .e_machine
= EM_S390
,
1463 .regsets
= s390_compat_regsets
,
1464 .n
= ARRAY_SIZE(s390_compat_regsets
)
1468 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
1470 #ifdef CONFIG_COMPAT
1471 if (test_tsk_thread_flag(task
, TIF_31BIT
))
1472 return &user_s390_compat_view
;
1474 return &user_s390_view
;
1477 static const char *gpr_names
[NUM_GPRS
] = {
1478 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1479 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1482 unsigned long regs_get_register(struct pt_regs
*regs
, unsigned int offset
)
1484 if (offset
>= NUM_GPRS
)
1486 return regs
->gprs
[offset
];
1489 int regs_query_register_offset(const char *name
)
1491 unsigned long offset
;
1493 if (!name
|| *name
!= 'r')
1495 if (kstrtoul(name
+ 1, 10, &offset
))
1497 if (offset
>= NUM_GPRS
)
1502 const char *regs_query_register_name(unsigned int offset
)
1504 if (offset
>= NUM_GPRS
)
1506 return gpr_names
[offset
];
1509 static int regs_within_kernel_stack(struct pt_regs
*regs
, unsigned long addr
)
1511 unsigned long ksp
= kernel_stack_pointer(regs
);
1513 return (addr
& ~(THREAD_SIZE
- 1)) == (ksp
& ~(THREAD_SIZE
- 1));
1517 * regs_get_kernel_stack_nth() - get Nth entry of the stack
1518 * @regs:pt_regs which contains kernel stack pointer.
1519 * @n:stack entry number.
1521 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
1522 * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
1525 unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
, unsigned int n
)
1529 addr
= kernel_stack_pointer(regs
) + n
* sizeof(long);
1530 if (!regs_within_kernel_stack(regs
, addr
))
1532 return *(unsigned long *)addr
;