2 * Kernel support for the ptrace() and syscall tracing interfaces.
4 * Copyright (C) 1999-2005 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
7 * Derived from the x86 and Alpha versions.
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/slab.h>
13 #include <linux/errno.h>
14 #include <linux/ptrace.h>
15 #include <linux/smp_lock.h>
16 #include <linux/user.h>
17 #include <linux/security.h>
18 #include <linux/audit.h>
19 #include <linux/signal.h>
21 #include <asm/pgtable.h>
22 #include <asm/processor.h>
23 #include <asm/ptrace_offsets.h>
25 #include <asm/system.h>
26 #include <asm/uaccess.h>
27 #include <asm/unwind.h>
29 #include <asm/perfmon.h>
35 * Bits in the PSR that we allow ptrace() to change:
36 * be, up, ac, mfl, mfh (the user mask; five bits total)
37 * db (debug breakpoint fault; one bit)
38 * id (instruction debug fault disable; one bit)
39 * dd (data debug fault disable; one bit)
40 * ri (restart instruction; two bits)
41 * is (instruction set; one bit)
43 #define IPSR_MASK (IA64_PSR_UM | IA64_PSR_DB | IA64_PSR_IS \
44 | IA64_PSR_ID | IA64_PSR_DD | IA64_PSR_RI)
46 #define MASK(nbits) ((1UL << (nbits)) - 1) /* mask with NBITS bits set */
47 #define PFM_MASK MASK(38)
49 #define PTRACE_DEBUG 0
52 # define dprintk(format...) printk(format)
55 # define dprintk(format...)
58 /* Return TRUE if PT was created due to kernel-entry via a system-call. */
61 in_syscall (struct pt_regs
*pt
)
63 return (long) pt
->cr_ifs
>= 0;
67 * Collect the NaT bits for r1-r31 from scratch_unat and return a NaT
68 * bitset where bit i is set iff the NaT bit of register i is set.
71 ia64_get_scratch_nat_bits (struct pt_regs
*pt
, unsigned long scratch_unat
)
73 # define GET_BITS(first, last, unat) \
75 unsigned long bit = ia64_unat_pos(&pt->r##first); \
76 unsigned long nbits = (last - first + 1); \
77 unsigned long mask = MASK(nbits) << first; \
80 dist = 64 + bit - first; \
83 ia64_rotr(unat, dist) & mask; \
88 * Registers that are stored consecutively in struct pt_regs
89 * can be handled in parallel. If the register order in
90 * struct_pt_regs changes, this code MUST be updated.
92 val
= GET_BITS( 1, 1, scratch_unat
);
93 val
|= GET_BITS( 2, 3, scratch_unat
);
94 val
|= GET_BITS(12, 13, scratch_unat
);
95 val
|= GET_BITS(14, 14, scratch_unat
);
96 val
|= GET_BITS(15, 15, scratch_unat
);
97 val
|= GET_BITS( 8, 11, scratch_unat
);
98 val
|= GET_BITS(16, 31, scratch_unat
);
105 * Set the NaT bits for the scratch registers according to NAT and
106 * return the resulting unat (assuming the scratch registers are
110 ia64_put_scratch_nat_bits (struct pt_regs
*pt
, unsigned long nat
)
112 # define PUT_BITS(first, last, nat) \
114 unsigned long bit = ia64_unat_pos(&pt->r##first); \
115 unsigned long nbits = (last - first + 1); \
116 unsigned long mask = MASK(nbits) << first; \
119 dist = 64 + bit - first; \
121 dist = bit - first; \
122 ia64_rotl(nat & mask, dist); \
124 unsigned long scratch_unat
;
127 * Registers that are stored consecutively in struct pt_regs
128 * can be handled in parallel. If the register order in
129 * struct_pt_regs changes, this code MUST be updated.
131 scratch_unat
= PUT_BITS( 1, 1, nat
);
132 scratch_unat
|= PUT_BITS( 2, 3, nat
);
133 scratch_unat
|= PUT_BITS(12, 13, nat
);
134 scratch_unat
|= PUT_BITS(14, 14, nat
);
135 scratch_unat
|= PUT_BITS(15, 15, nat
);
136 scratch_unat
|= PUT_BITS( 8, 11, nat
);
137 scratch_unat
|= PUT_BITS(16, 31, nat
);
144 #define IA64_MLX_TEMPLATE 0x2
145 #define IA64_MOVL_OPCODE 6
148 ia64_increment_ip (struct pt_regs
*regs
)
150 unsigned long w0
, ri
= ia64_psr(regs
)->ri
+ 1;
155 } else if (ri
== 2) {
156 get_user(w0
, (char __user
*) regs
->cr_iip
+ 0);
157 if (((w0
>> 1) & 0xf) == IA64_MLX_TEMPLATE
) {
159 * rfi'ing to slot 2 of an MLX bundle causes
160 * an illegal operation fault. We don't want
167 ia64_psr(regs
)->ri
= ri
;
171 ia64_decrement_ip (struct pt_regs
*regs
)
173 unsigned long w0
, ri
= ia64_psr(regs
)->ri
- 1;
175 if (ia64_psr(regs
)->ri
== 0) {
178 get_user(w0
, (char __user
*) regs
->cr_iip
+ 0);
179 if (((w0
>> 1) & 0xf) == IA64_MLX_TEMPLATE
) {
181 * rfi'ing to slot 2 of an MLX bundle causes
182 * an illegal operation fault. We don't want
188 ia64_psr(regs
)->ri
= ri
;
192 * This routine is used to read an rnat bits that are stored on the
193 * kernel backing store. Since, in general, the alignment of the user
194 * and kernel are different, this is not completely trivial. In
195 * essence, we need to construct the user RNAT based on up to two
196 * kernel RNAT values and/or the RNAT value saved in the child's
201 * +--------+ <-- lowest address
208 * | slot01 | > child_regs->ar_rnat
210 * | slot02 | / kernel rbs
211 * +--------+ +--------+
212 * <- child_regs->ar_bspstore | slot61 | <-- krbs
213 * +- - - - + +--------+
215 * +- - - - + +--------+
217 * +- - - - + +--------+
219 * +- - - - + +--------+
224 * | slot01 | > child_stack->ar_rnat
228 * <--- child_stack->ar_bspstore
230 * The way to think of this code is as follows: bit 0 in the user rnat
231 * corresponds to some bit N (0 <= N <= 62) in one of the kernel rnat
232 * value. The kernel rnat value holding this bit is stored in
233 * variable rnat0. rnat1 is loaded with the kernel rnat value that
234 * form the upper bits of the user rnat value.
238 * o when reading the rnat "below" the first rnat slot on the kernel
239 * backing store, rnat0/rnat1 are set to 0 and the low order bits are
240 * merged in from pt->ar_rnat.
242 * o when reading the rnat "above" the last rnat slot on the kernel
243 * backing store, rnat0/rnat1 gets its value from sw->ar_rnat.
246 get_rnat (struct task_struct
*task
, struct switch_stack
*sw
,
247 unsigned long *krbs
, unsigned long *urnat_addr
,
248 unsigned long *urbs_end
)
250 unsigned long rnat0
= 0, rnat1
= 0, urnat
= 0, *slot0_kaddr
;
251 unsigned long umask
= 0, mask
, m
;
252 unsigned long *kbsp
, *ubspstore
, *rnat0_kaddr
, *rnat1_kaddr
, shift
;
253 long num_regs
, nbits
;
256 pt
= task_pt_regs(task
);
257 kbsp
= (unsigned long *) sw
->ar_bspstore
;
258 ubspstore
= (unsigned long *) pt
->ar_bspstore
;
260 if (urbs_end
< urnat_addr
)
261 nbits
= ia64_rse_num_regs(urnat_addr
- 63, urbs_end
);
266 * First, figure out which bit number slot 0 in user-land maps
267 * to in the kernel rnat. Do this by figuring out how many
268 * register slots we're beyond the user's backingstore and
269 * then computing the equivalent address in kernel space.
271 num_regs
= ia64_rse_num_regs(ubspstore
, urnat_addr
+ 1);
272 slot0_kaddr
= ia64_rse_skip_regs(krbs
, num_regs
);
273 shift
= ia64_rse_slot_num(slot0_kaddr
);
274 rnat1_kaddr
= ia64_rse_rnat_addr(slot0_kaddr
);
275 rnat0_kaddr
= rnat1_kaddr
- 64;
277 if (ubspstore
+ 63 > urnat_addr
) {
278 /* some bits need to be merged in from pt->ar_rnat */
279 umask
= MASK(ia64_rse_slot_num(ubspstore
)) & mask
;
280 urnat
= (pt
->ar_rnat
& umask
);
287 if (rnat0_kaddr
>= kbsp
)
289 else if (rnat0_kaddr
> krbs
)
290 rnat0
= *rnat0_kaddr
;
291 urnat
|= (rnat0
& m
) >> shift
;
293 m
= mask
>> (63 - shift
);
294 if (rnat1_kaddr
>= kbsp
)
296 else if (rnat1_kaddr
> krbs
)
297 rnat1
= *rnat1_kaddr
;
298 urnat
|= (rnat1
& m
) << (63 - shift
);
303 * The reverse of get_rnat.
306 put_rnat (struct task_struct
*task
, struct switch_stack
*sw
,
307 unsigned long *krbs
, unsigned long *urnat_addr
, unsigned long urnat
,
308 unsigned long *urbs_end
)
310 unsigned long rnat0
= 0, rnat1
= 0, *slot0_kaddr
, umask
= 0, mask
, m
;
311 unsigned long *kbsp
, *ubspstore
, *rnat0_kaddr
, *rnat1_kaddr
, shift
;
312 long num_regs
, nbits
;
314 unsigned long cfm
, *urbs_kargs
;
316 pt
= task_pt_regs(task
);
317 kbsp
= (unsigned long *) sw
->ar_bspstore
;
318 ubspstore
= (unsigned long *) pt
->ar_bspstore
;
320 urbs_kargs
= urbs_end
;
321 if (in_syscall(pt
)) {
323 * If entered via syscall, don't allow user to set rnat bits
327 urbs_kargs
= ia64_rse_skip_regs(urbs_end
, -(cfm
& 0x7f));
330 if (urbs_kargs
>= urnat_addr
)
333 if ((urnat_addr
- 63) >= urbs_kargs
)
335 nbits
= ia64_rse_num_regs(urnat_addr
- 63, urbs_kargs
);
340 * First, figure out which bit number slot 0 in user-land maps
341 * to in the kernel rnat. Do this by figuring out how many
342 * register slots we're beyond the user's backingstore and
343 * then computing the equivalent address in kernel space.
345 num_regs
= ia64_rse_num_regs(ubspstore
, urnat_addr
+ 1);
346 slot0_kaddr
= ia64_rse_skip_regs(krbs
, num_regs
);
347 shift
= ia64_rse_slot_num(slot0_kaddr
);
348 rnat1_kaddr
= ia64_rse_rnat_addr(slot0_kaddr
);
349 rnat0_kaddr
= rnat1_kaddr
- 64;
351 if (ubspstore
+ 63 > urnat_addr
) {
352 /* some bits need to be place in pt->ar_rnat: */
353 umask
= MASK(ia64_rse_slot_num(ubspstore
)) & mask
;
354 pt
->ar_rnat
= (pt
->ar_rnat
& ~umask
) | (urnat
& umask
);
360 * Note: Section 11.1 of the EAS guarantees that bit 63 of an
361 * rnat slot is ignored. so we don't have to clear it here.
363 rnat0
= (urnat
<< shift
);
365 if (rnat0_kaddr
>= kbsp
)
366 sw
->ar_rnat
= (sw
->ar_rnat
& ~m
) | (rnat0
& m
);
367 else if (rnat0_kaddr
> krbs
)
368 *rnat0_kaddr
= ((*rnat0_kaddr
& ~m
) | (rnat0
& m
));
370 rnat1
= (urnat
>> (63 - shift
));
371 m
= mask
>> (63 - shift
);
372 if (rnat1_kaddr
>= kbsp
)
373 sw
->ar_rnat
= (sw
->ar_rnat
& ~m
) | (rnat1
& m
);
374 else if (rnat1_kaddr
> krbs
)
375 *rnat1_kaddr
= ((*rnat1_kaddr
& ~m
) | (rnat1
& m
));
379 on_kernel_rbs (unsigned long addr
, unsigned long bspstore
,
380 unsigned long urbs_end
)
382 unsigned long *rnat_addr
= ia64_rse_rnat_addr((unsigned long *)
384 return (addr
>= bspstore
&& addr
<= (unsigned long) rnat_addr
);
388 * Read a word from the user-level backing store of task CHILD. ADDR
389 * is the user-level address to read the word from, VAL a pointer to
390 * the return value, and USER_BSP gives the end of the user-level
391 * backing store (i.e., it's the address that would be in ar.bsp after
392 * the user executed a "cover" instruction).
394 * This routine takes care of accessing the kernel register backing
395 * store for those registers that got spilled there. It also takes
396 * care of calculating the appropriate RNaT collection words.
399 ia64_peek (struct task_struct
*child
, struct switch_stack
*child_stack
,
400 unsigned long user_rbs_end
, unsigned long addr
, long *val
)
402 unsigned long *bspstore
, *krbs
, regnum
, *laddr
, *urbs_end
, *rnat_addr
;
403 struct pt_regs
*child_regs
;
407 urbs_end
= (long *) user_rbs_end
;
408 laddr
= (unsigned long *) addr
;
409 child_regs
= task_pt_regs(child
);
410 bspstore
= (unsigned long *) child_regs
->ar_bspstore
;
411 krbs
= (unsigned long *) child
+ IA64_RBS_OFFSET
/8;
412 if (on_kernel_rbs(addr
, (unsigned long) bspstore
,
413 (unsigned long) urbs_end
))
416 * Attempt to read the RBS in an area that's actually
417 * on the kernel RBS => read the corresponding bits in
420 rnat_addr
= ia64_rse_rnat_addr(laddr
);
421 ret
= get_rnat(child
, child_stack
, krbs
, rnat_addr
, urbs_end
);
423 if (laddr
== rnat_addr
) {
424 /* return NaT collection word itself */
429 if (((1UL << ia64_rse_slot_num(laddr
)) & ret
) != 0) {
431 * It is implementation dependent whether the
432 * data portion of a NaT value gets saved on a
433 * st8.spill or RSE spill (e.g., see EAS 2.6,
434 * 4.4.4.6 Register Spill and Fill). To get
435 * consistent behavior across all possible
436 * IA-64 implementations, we return zero in
443 if (laddr
< urbs_end
) {
445 * The desired word is on the kernel RBS and
448 regnum
= ia64_rse_num_regs(bspstore
, laddr
);
449 *val
= *ia64_rse_skip_regs(krbs
, regnum
);
453 copied
= access_process_vm(child
, addr
, &ret
, sizeof(ret
), 0);
454 if (copied
!= sizeof(ret
))
461 ia64_poke (struct task_struct
*child
, struct switch_stack
*child_stack
,
462 unsigned long user_rbs_end
, unsigned long addr
, long val
)
464 unsigned long *bspstore
, *krbs
, regnum
, *laddr
;
465 unsigned long *urbs_end
= (long *) user_rbs_end
;
466 struct pt_regs
*child_regs
;
468 laddr
= (unsigned long *) addr
;
469 child_regs
= task_pt_regs(child
);
470 bspstore
= (unsigned long *) child_regs
->ar_bspstore
;
471 krbs
= (unsigned long *) child
+ IA64_RBS_OFFSET
/8;
472 if (on_kernel_rbs(addr
, (unsigned long) bspstore
,
473 (unsigned long) urbs_end
))
476 * Attempt to write the RBS in an area that's actually
477 * on the kernel RBS => write the corresponding bits
480 if (ia64_rse_is_rnat_slot(laddr
))
481 put_rnat(child
, child_stack
, krbs
, laddr
, val
,
484 if (laddr
< urbs_end
) {
485 regnum
= ia64_rse_num_regs(bspstore
, laddr
);
486 *ia64_rse_skip_regs(krbs
, regnum
) = val
;
489 } else if (access_process_vm(child
, addr
, &val
, sizeof(val
), 1)
496 * Calculate the address of the end of the user-level register backing
497 * store. This is the address that would have been stored in ar.bsp
498 * if the user had executed a "cover" instruction right before
499 * entering the kernel. If CFMP is not NULL, it is used to return the
500 * "current frame mask" that was active at the time the kernel was
504 ia64_get_user_rbs_end (struct task_struct
*child
, struct pt_regs
*pt
,
507 unsigned long *krbs
, *bspstore
, cfm
= pt
->cr_ifs
;
510 krbs
= (unsigned long *) child
+ IA64_RBS_OFFSET
/8;
511 bspstore
= (unsigned long *) pt
->ar_bspstore
;
512 ndirty
= ia64_rse_num_regs(krbs
, krbs
+ (pt
->loadrs
>> 19));
515 ndirty
+= (cfm
& 0x7f);
517 cfm
&= ~(1UL << 63); /* clear valid bit */
521 return (unsigned long) ia64_rse_skip_regs(bspstore
, ndirty
);
525 * Synchronize (i.e, write) the RSE backing store living in kernel
526 * space to the VM of the CHILD task. SW and PT are the pointers to
527 * the switch_stack and pt_regs structures, respectively.
528 * USER_RBS_END is the user-level address at which the backing store
532 ia64_sync_user_rbs (struct task_struct
*child
, struct switch_stack
*sw
,
533 unsigned long user_rbs_start
, unsigned long user_rbs_end
)
535 unsigned long addr
, val
;
538 /* now copy word for word from kernel rbs to user rbs: */
539 for (addr
= user_rbs_start
; addr
< user_rbs_end
; addr
+= 8) {
540 ret
= ia64_peek(child
, sw
, user_rbs_end
, addr
, &val
);
543 if (access_process_vm(child
, addr
, &val
, sizeof(val
), 1)
551 thread_matches (struct task_struct
*thread
, unsigned long addr
)
553 unsigned long thread_rbs_end
;
554 struct pt_regs
*thread_regs
;
556 if (ptrace_check_attach(thread
, 0) < 0)
558 * If the thread is not in an attachable state, we'll
559 * ignore it. The net effect is that if ADDR happens
560 * to overlap with the portion of the thread's
561 * register backing store that is currently residing
562 * on the thread's kernel stack, then ptrace() may end
563 * up accessing a stale value. But if the thread
564 * isn't stopped, that's a problem anyhow, so we're
565 * doing as well as we can...
569 thread_regs
= task_pt_regs(thread
);
570 thread_rbs_end
= ia64_get_user_rbs_end(thread
, thread_regs
, NULL
);
571 if (!on_kernel_rbs(addr
, thread_regs
->ar_bspstore
, thread_rbs_end
))
574 return 1; /* looks like we've got a winner */
578 * GDB apparently wants to be able to read the register-backing store
579 * of any thread when attached to a given process. If we are peeking
580 * or poking an address that happens to reside in the kernel-backing
581 * store of another thread, we need to attach to that thread, because
582 * otherwise we end up accessing stale data.
584 * task_list_lock must be read-locked before calling this routine!
586 static struct task_struct
*
587 find_thread_for_addr (struct task_struct
*child
, unsigned long addr
)
589 struct task_struct
*p
;
590 struct mm_struct
*mm
;
591 struct list_head
*this, *next
;
594 if (!(mm
= get_task_mm(child
)))
597 /* -1 because of our get_task_mm(): */
598 mm_users
= atomic_read(&mm
->mm_users
) - 1;
600 goto out
; /* not multi-threaded */
603 * Traverse the current process' children list. Every task that
604 * one attaches to becomes a child. And it is only attached children
605 * of the debugger that are of interest (ptrace_check_attach checks
608 list_for_each_safe(this, next
, ¤t
->children
) {
609 p
= list_entry(this, struct task_struct
, sibling
);
610 if (p
->tgid
!= child
->tgid
)
612 if (thread_matches(p
, addr
)) {
624 * Write f32-f127 back to task->thread.fph if it has been modified.
627 ia64_flush_fph (struct task_struct
*task
)
629 struct ia64_psr
*psr
= ia64_psr(task_pt_regs(task
));
632 * Prevent migrating this task while
633 * we're fiddling with the FPU state
636 if (ia64_is_local_fpu_owner(task
) && psr
->mfh
) {
638 task
->thread
.flags
|= IA64_THREAD_FPH_VALID
;
639 ia64_save_fpu(&task
->thread
.fph
[0]);
645 * Sync the fph state of the task so that it can be manipulated
646 * through thread.fph. If necessary, f32-f127 are written back to
647 * thread.fph or, if the fph state hasn't been used before, thread.fph
648 * is cleared to zeroes. Also, access to f32-f127 is disabled to
649 * ensure that the task picks up the state from thread.fph when it
653 ia64_sync_fph (struct task_struct
*task
)
655 struct ia64_psr
*psr
= ia64_psr(task_pt_regs(task
));
657 ia64_flush_fph(task
);
658 if (!(task
->thread
.flags
& IA64_THREAD_FPH_VALID
)) {
659 task
->thread
.flags
|= IA64_THREAD_FPH_VALID
;
660 memset(&task
->thread
.fph
, 0, sizeof(task
->thread
.fph
));
667 access_fr (struct unw_frame_info
*info
, int regnum
, int hi
,
668 unsigned long *data
, int write_access
)
670 struct ia64_fpreg fpval
;
673 ret
= unw_get_fr(info
, regnum
, &fpval
);
678 fpval
.u
.bits
[hi
] = *data
;
679 ret
= unw_set_fr(info
, regnum
, fpval
);
681 *data
= fpval
.u
.bits
[hi
];
686 * Change the machine-state of CHILD such that it will return via the normal
687 * kernel exit-path, rather than the syscall-exit path.
690 convert_to_non_syscall (struct task_struct
*child
, struct pt_regs
*pt
,
693 struct unw_frame_info info
, prev_info
;
694 unsigned long ip
, sp
, pr
;
696 unw_init_from_blocked_task(&info
, child
);
699 if (unw_unwind(&info
) < 0)
702 unw_get_sp(&info
, &sp
);
703 if ((long)((unsigned long)child
+ IA64_STK_OFFSET
- sp
)
704 < IA64_PT_REGS_SIZE
) {
705 dprintk("ptrace.%s: ran off the top of the kernel "
706 "stack\n", __FUNCTION__
);
709 if (unw_get_pr (&prev_info
, &pr
) < 0) {
710 unw_get_rp(&prev_info
, &ip
);
711 dprintk("ptrace.%s: failed to read "
712 "predicate register (ip=0x%lx)\n",
716 if (unw_is_intr_frame(&info
)
717 && (pr
& (1UL << PRED_USER_STACK
)))
722 * Note: at the time of this call, the target task is blocked
723 * in notify_resume_user() and by clearling PRED_LEAVE_SYSCALL
724 * (aka, "pLvSys") we redirect execution from
725 * .work_pending_syscall_end to .work_processed_kernel.
727 unw_get_pr(&prev_info
, &pr
);
728 pr
&= ~((1UL << PRED_SYSCALL
) | (1UL << PRED_LEAVE_SYSCALL
));
729 pr
|= (1UL << PRED_NON_SYSCALL
);
730 unw_set_pr(&prev_info
, pr
);
732 pt
->cr_ifs
= (1UL << 63) | cfm
;
734 * Clear the memory that is NOT written on syscall-entry to
735 * ensure we do not leak kernel-state to user when execution
741 memset(&pt
->r16
, 0, 16*8); /* clear r16-r31 */
742 memset(&pt
->f6
, 0, 6*16); /* clear f6-f11 */
750 access_nat_bits (struct task_struct
*child
, struct pt_regs
*pt
,
751 struct unw_frame_info
*info
,
752 unsigned long *data
, int write_access
)
754 unsigned long regnum
, nat_bits
, scratch_unat
, dummy
= 0;
759 scratch_unat
= ia64_put_scratch_nat_bits(pt
, nat_bits
);
760 if (unw_set_ar(info
, UNW_AR_UNAT
, scratch_unat
) < 0) {
761 dprintk("ptrace: failed to set ar.unat\n");
764 for (regnum
= 4; regnum
<= 7; ++regnum
) {
765 unw_get_gr(info
, regnum
, &dummy
, &nat
);
766 unw_set_gr(info
, regnum
, dummy
,
767 (nat_bits
>> regnum
) & 1);
770 if (unw_get_ar(info
, UNW_AR_UNAT
, &scratch_unat
) < 0) {
771 dprintk("ptrace: failed to read ar.unat\n");
774 nat_bits
= ia64_get_scratch_nat_bits(pt
, scratch_unat
);
775 for (regnum
= 4; regnum
<= 7; ++regnum
) {
776 unw_get_gr(info
, regnum
, &dummy
, &nat
);
777 nat_bits
|= (nat
!= 0) << regnum
;
785 access_uarea (struct task_struct
*child
, unsigned long addr
,
786 unsigned long *data
, int write_access
)
788 unsigned long *ptr
, regnum
, urbs_end
, rnat_addr
, cfm
;
789 struct switch_stack
*sw
;
791 # define pt_reg_addr(pt, reg) ((void *) \
792 ((unsigned long) (pt) \
793 + offsetof(struct pt_regs, reg)))
796 pt
= task_pt_regs(child
);
797 sw
= (struct switch_stack
*) (child
->thread
.ksp
+ 16);
799 if ((addr
& 0x7) != 0) {
800 dprintk("ptrace: unaligned register address 0x%lx\n", addr
);
804 if (addr
< PT_F127
+ 16) {
807 ia64_sync_fph(child
);
809 ia64_flush_fph(child
);
810 ptr
= (unsigned long *)
811 ((unsigned long) &child
->thread
.fph
+ addr
);
812 } else if ((addr
>= PT_F10
) && (addr
< PT_F11
+ 16)) {
813 /* scratch registers untouched by kernel (saved in pt_regs) */
814 ptr
= pt_reg_addr(pt
, f10
) + (addr
- PT_F10
);
815 } else if (addr
>= PT_F12
&& addr
< PT_F15
+ 16) {
817 * Scratch registers untouched by kernel (saved in
820 ptr
= (unsigned long *) ((long) sw
821 + (addr
- PT_NAT_BITS
- 32));
822 } else if (addr
< PT_AR_LC
+ 8) {
823 /* preserved state: */
824 struct unw_frame_info info
;
828 unw_init_from_blocked_task(&info
, child
);
829 if (unw_unwind_to_user(&info
) < 0)
834 return access_nat_bits(child
, pt
, &info
,
837 case PT_R4
: case PT_R5
: case PT_R6
: case PT_R7
:
839 /* read NaT bit first: */
842 ret
= unw_get_gr(&info
, (addr
- PT_R4
)/8 + 4,
847 return unw_access_gr(&info
, (addr
- PT_R4
)/8 + 4, data
,
850 case PT_B1
: case PT_B2
: case PT_B3
:
851 case PT_B4
: case PT_B5
:
852 return unw_access_br(&info
, (addr
- PT_B1
)/8 + 1, data
,
856 return unw_access_ar(&info
, UNW_AR_EC
, data
,
860 return unw_access_ar(&info
, UNW_AR_LC
, data
,
864 if (addr
>= PT_F2
&& addr
< PT_F5
+ 16)
865 return access_fr(&info
, (addr
- PT_F2
)/16 + 2,
866 (addr
& 8) != 0, data
,
868 else if (addr
>= PT_F16
&& addr
< PT_F31
+ 16)
869 return access_fr(&info
,
870 (addr
- PT_F16
)/16 + 16,
874 dprintk("ptrace: rejecting access to register "
875 "address 0x%lx\n", addr
);
879 } else if (addr
< PT_F9
+16) {
884 * By convention, we use PT_AR_BSP to refer to
885 * the end of the user-level backing store.
886 * Use ia64_rse_skip_regs(PT_AR_BSP, -CFM.sof)
887 * to get the real value of ar.bsp at the time
888 * the kernel was entered.
890 * Furthermore, when changing the contents of
891 * PT_AR_BSP (or PT_CFM) we MUST copy any
892 * users-level stacked registers that are
893 * stored on the kernel stack back to
894 * user-space because otherwise, we might end
895 * up clobbering kernel stacked registers.
896 * Also, if this happens while the task is
897 * blocked in a system call, which convert the
898 * state such that the non-system-call exit
899 * path is used. This ensures that the proper
900 * state will be picked up when resuming
901 * execution. However, it *also* means that
902 * once we write PT_AR_BSP/PT_CFM, it won't be
903 * possible to modify the syscall arguments of
904 * the pending system call any longer. This
905 * shouldn't be an issue because modifying
906 * PT_AR_BSP/PT_CFM generally implies that
907 * we're either abandoning the pending system
908 * call or that we defer it's re-execution
909 * (e.g., due to GDB doing an inferior
912 urbs_end
= ia64_get_user_rbs_end(child
, pt
, &cfm
);
914 if (*data
!= urbs_end
) {
915 if (ia64_sync_user_rbs(child
, sw
,
920 convert_to_non_syscall(child
,
924 * Simulate user-level write
928 pt
->ar_bspstore
= *data
;
935 urbs_end
= ia64_get_user_rbs_end(child
, pt
, &cfm
);
937 if (((cfm
^ *data
) & PFM_MASK
) != 0) {
938 if (ia64_sync_user_rbs(child
, sw
,
943 convert_to_non_syscall(child
,
946 pt
->cr_ifs
= ((pt
->cr_ifs
& ~PFM_MASK
)
947 | (*data
& PFM_MASK
));
955 unsigned long tmp
= *data
;
956 /* psr.ri==3 is a reserved value: SDM 2:25 */
957 if ((tmp
& IA64_PSR_RI
) == IA64_PSR_RI
)
959 pt
->cr_ipsr
= ((tmp
& IPSR_MASK
)
960 | (pt
->cr_ipsr
& ~IPSR_MASK
));
962 *data
= (pt
->cr_ipsr
& IPSR_MASK
);
967 pt
->ar_rsc
= *data
| (3 << 2); /* force PL3 */
973 urbs_end
= ia64_get_user_rbs_end(child
, pt
, NULL
);
974 rnat_addr
= (long) ia64_rse_rnat_addr((long *)
977 return ia64_poke(child
, sw
, urbs_end
,
980 return ia64_peek(child
, sw
, urbs_end
,
984 ptr
= pt_reg_addr(pt
, r1
);
986 case PT_R2
: case PT_R3
:
987 ptr
= pt_reg_addr(pt
, r2
) + (addr
- PT_R2
);
989 case PT_R8
: case PT_R9
: case PT_R10
: case PT_R11
:
990 ptr
= pt_reg_addr(pt
, r8
) + (addr
- PT_R8
);
992 case PT_R12
: case PT_R13
:
993 ptr
= pt_reg_addr(pt
, r12
) + (addr
- PT_R12
);
996 ptr
= pt_reg_addr(pt
, r14
);
999 ptr
= pt_reg_addr(pt
, r15
);
1001 case PT_R16
: case PT_R17
: case PT_R18
: case PT_R19
:
1002 case PT_R20
: case PT_R21
: case PT_R22
: case PT_R23
:
1003 case PT_R24
: case PT_R25
: case PT_R26
: case PT_R27
:
1004 case PT_R28
: case PT_R29
: case PT_R30
: case PT_R31
:
1005 ptr
= pt_reg_addr(pt
, r16
) + (addr
- PT_R16
);
1008 ptr
= pt_reg_addr(pt
, b0
);
1011 ptr
= pt_reg_addr(pt
, b6
);
1014 ptr
= pt_reg_addr(pt
, b7
);
1016 case PT_F6
: case PT_F6
+8: case PT_F7
: case PT_F7
+8:
1017 case PT_F8
: case PT_F8
+8: case PT_F9
: case PT_F9
+8:
1018 ptr
= pt_reg_addr(pt
, f6
) + (addr
- PT_F6
);
1020 case PT_AR_BSPSTORE
:
1021 ptr
= pt_reg_addr(pt
, ar_bspstore
);
1024 ptr
= pt_reg_addr(pt
, ar_unat
);
1027 ptr
= pt_reg_addr(pt
, ar_pfs
);
1030 ptr
= pt_reg_addr(pt
, ar_ccv
);
1033 ptr
= pt_reg_addr(pt
, ar_fpsr
);
1036 ptr
= pt_reg_addr(pt
, cr_iip
);
1039 ptr
= pt_reg_addr(pt
, pr
);
1041 /* scratch register */
1044 /* disallow accessing anything else... */
1045 dprintk("ptrace: rejecting access to register "
1046 "address 0x%lx\n", addr
);
1049 } else if (addr
<= PT_AR_SSD
) {
1050 ptr
= pt_reg_addr(pt
, ar_csd
) + (addr
- PT_AR_CSD
);
1052 /* access debug registers */
1054 if (addr
>= PT_IBR
) {
1055 regnum
= (addr
- PT_IBR
) >> 3;
1056 ptr
= &child
->thread
.ibr
[0];
1058 regnum
= (addr
- PT_DBR
) >> 3;
1059 ptr
= &child
->thread
.dbr
[0];
1063 dprintk("ptrace: rejecting access to register "
1064 "address 0x%lx\n", addr
);
1067 #ifdef CONFIG_PERFMON
1069 * Check if debug registers are used by perfmon. This
1070 * test must be done once we know that we can do the
1071 * operation, i.e. the arguments are all valid, but
1072 * before we start modifying the state.
1074 * Perfmon needs to keep a count of how many processes
1075 * are trying to modify the debug registers for system
1076 * wide monitoring sessions.
1078 * We also include read access here, because they may
1079 * cause the PMU-installed debug register state
1080 * (dbr[], ibr[]) to be reset. The two arrays are also
1081 * used by perfmon, but we do not use
1082 * IA64_THREAD_DBG_VALID. The registers are restored
1083 * by the PMU context switch code.
1085 if (pfm_use_debug_registers(child
)) return -1;
1088 if (!(child
->thread
.flags
& IA64_THREAD_DBG_VALID
)) {
1089 child
->thread
.flags
|= IA64_THREAD_DBG_VALID
;
1090 memset(child
->thread
.dbr
, 0,
1091 sizeof(child
->thread
.dbr
));
1092 memset(child
->thread
.ibr
, 0,
1093 sizeof(child
->thread
.ibr
));
1098 if ((regnum
& 1) && write_access
) {
1099 /* don't let the user set kernel-level breakpoints: */
1100 *ptr
= *data
& ~(7UL << 56);
1112 ptrace_getregs (struct task_struct
*child
, struct pt_all_user_regs __user
*ppr
)
1114 unsigned long psr
, ec
, lc
, rnat
, bsp
, cfm
, nat_bits
, val
;
1115 struct unw_frame_info info
;
1116 struct ia64_fpreg fpval
;
1117 struct switch_stack
*sw
;
1119 long ret
, retval
= 0;
1123 if (!access_ok(VERIFY_WRITE
, ppr
, sizeof(struct pt_all_user_regs
)))
1126 pt
= task_pt_regs(child
);
1127 sw
= (struct switch_stack
*) (child
->thread
.ksp
+ 16);
1128 unw_init_from_blocked_task(&info
, child
);
1129 if (unw_unwind_to_user(&info
) < 0) {
1133 if (((unsigned long) ppr
& 0x7) != 0) {
1134 dprintk("ptrace:unaligned register address %p\n", ppr
);
1138 if (access_uarea(child
, PT_CR_IPSR
, &psr
, 0) < 0
1139 || access_uarea(child
, PT_AR_EC
, &ec
, 0) < 0
1140 || access_uarea(child
, PT_AR_LC
, &lc
, 0) < 0
1141 || access_uarea(child
, PT_AR_RNAT
, &rnat
, 0) < 0
1142 || access_uarea(child
, PT_AR_BSP
, &bsp
, 0) < 0
1143 || access_uarea(child
, PT_CFM
, &cfm
, 0)
1144 || access_uarea(child
, PT_NAT_BITS
, &nat_bits
, 0))
1149 retval
|= __put_user(pt
->cr_iip
, &ppr
->cr_iip
);
1150 retval
|= __put_user(psr
, &ppr
->cr_ipsr
);
1154 retval
|= __put_user(pt
->ar_pfs
, &ppr
->ar
[PT_AUR_PFS
]);
1155 retval
|= __put_user(pt
->ar_rsc
, &ppr
->ar
[PT_AUR_RSC
]);
1156 retval
|= __put_user(pt
->ar_bspstore
, &ppr
->ar
[PT_AUR_BSPSTORE
]);
1157 retval
|= __put_user(pt
->ar_unat
, &ppr
->ar
[PT_AUR_UNAT
]);
1158 retval
|= __put_user(pt
->ar_ccv
, &ppr
->ar
[PT_AUR_CCV
]);
1159 retval
|= __put_user(pt
->ar_fpsr
, &ppr
->ar
[PT_AUR_FPSR
]);
1161 retval
|= __put_user(ec
, &ppr
->ar
[PT_AUR_EC
]);
1162 retval
|= __put_user(lc
, &ppr
->ar
[PT_AUR_LC
]);
1163 retval
|= __put_user(rnat
, &ppr
->ar
[PT_AUR_RNAT
]);
1164 retval
|= __put_user(bsp
, &ppr
->ar
[PT_AUR_BSP
]);
1165 retval
|= __put_user(cfm
, &ppr
->cfm
);
1169 retval
|= __copy_to_user(&ppr
->gr
[1], &pt
->r1
, sizeof(long));
1170 retval
|= __copy_to_user(&ppr
->gr
[2], &pt
->r2
, sizeof(long) *2);
1174 for (i
= 4; i
< 8; i
++) {
1175 if (unw_access_gr(&info
, i
, &val
, &nat
, 0) < 0)
1177 retval
|= __put_user(val
, &ppr
->gr
[i
]);
1182 retval
|= __copy_to_user(&ppr
->gr
[8], &pt
->r8
, sizeof(long) * 4);
1186 retval
|= __copy_to_user(&ppr
->gr
[12], &pt
->r12
, sizeof(long) * 2);
1187 retval
|= __copy_to_user(&ppr
->gr
[14], &pt
->r14
, sizeof(long));
1188 retval
|= __copy_to_user(&ppr
->gr
[15], &pt
->r15
, sizeof(long));
1192 retval
|= __copy_to_user(&ppr
->gr
[16], &pt
->r16
, sizeof(long) * 16);
1196 retval
|= __put_user(pt
->b0
, &ppr
->br
[0]);
1200 for (i
= 1; i
< 6; i
++) {
1201 if (unw_access_br(&info
, i
, &val
, 0) < 0)
1203 __put_user(val
, &ppr
->br
[i
]);
1208 retval
|= __put_user(pt
->b6
, &ppr
->br
[6]);
1209 retval
|= __put_user(pt
->b7
, &ppr
->br
[7]);
1213 for (i
= 2; i
< 6; i
++) {
1214 if (unw_get_fr(&info
, i
, &fpval
) < 0)
1216 retval
|= __copy_to_user(&ppr
->fr
[i
], &fpval
, sizeof (fpval
));
1221 retval
|= __copy_to_user(&ppr
->fr
[6], &pt
->f6
,
1222 sizeof(struct ia64_fpreg
) * 6);
1224 /* fp scratch regs(12-15) */
1226 retval
|= __copy_to_user(&ppr
->fr
[12], &sw
->f12
,
1227 sizeof(struct ia64_fpreg
) * 4);
1231 for (i
= 16; i
< 32; i
++) {
1232 if (unw_get_fr(&info
, i
, &fpval
) < 0)
1234 retval
|= __copy_to_user(&ppr
->fr
[i
], &fpval
, sizeof (fpval
));
1239 ia64_flush_fph(child
);
1240 retval
|= __copy_to_user(&ppr
->fr
[32], &child
->thread
.fph
,
1241 sizeof(ppr
->fr
[32]) * 96);
1245 retval
|= __put_user(pt
->pr
, &ppr
->pr
);
1249 retval
|= __put_user(nat_bits
, &ppr
->nat
);
1251 ret
= retval
? -EIO
: 0;
1256 ptrace_setregs (struct task_struct
*child
, struct pt_all_user_regs __user
*ppr
)
1258 unsigned long psr
, rsc
, ec
, lc
, rnat
, bsp
, cfm
, nat_bits
, val
= 0;
1259 struct unw_frame_info info
;
1260 struct switch_stack
*sw
;
1261 struct ia64_fpreg fpval
;
1263 long ret
, retval
= 0;
1266 memset(&fpval
, 0, sizeof(fpval
));
1268 if (!access_ok(VERIFY_READ
, ppr
, sizeof(struct pt_all_user_regs
)))
1271 pt
= task_pt_regs(child
);
1272 sw
= (struct switch_stack
*) (child
->thread
.ksp
+ 16);
1273 unw_init_from_blocked_task(&info
, child
);
1274 if (unw_unwind_to_user(&info
) < 0) {
1278 if (((unsigned long) ppr
& 0x7) != 0) {
1279 dprintk("ptrace:unaligned register address %p\n", ppr
);
1285 retval
|= __get_user(pt
->cr_iip
, &ppr
->cr_iip
);
1286 retval
|= __get_user(psr
, &ppr
->cr_ipsr
);
1290 retval
|= __get_user(pt
->ar_pfs
, &ppr
->ar
[PT_AUR_PFS
]);
1291 retval
|= __get_user(rsc
, &ppr
->ar
[PT_AUR_RSC
]);
1292 retval
|= __get_user(pt
->ar_bspstore
, &ppr
->ar
[PT_AUR_BSPSTORE
]);
1293 retval
|= __get_user(pt
->ar_unat
, &ppr
->ar
[PT_AUR_UNAT
]);
1294 retval
|= __get_user(pt
->ar_ccv
, &ppr
->ar
[PT_AUR_CCV
]);
1295 retval
|= __get_user(pt
->ar_fpsr
, &ppr
->ar
[PT_AUR_FPSR
]);
1297 retval
|= __get_user(ec
, &ppr
->ar
[PT_AUR_EC
]);
1298 retval
|= __get_user(lc
, &ppr
->ar
[PT_AUR_LC
]);
1299 retval
|= __get_user(rnat
, &ppr
->ar
[PT_AUR_RNAT
]);
1300 retval
|= __get_user(bsp
, &ppr
->ar
[PT_AUR_BSP
]);
1301 retval
|= __get_user(cfm
, &ppr
->cfm
);
1305 retval
|= __copy_from_user(&pt
->r1
, &ppr
->gr
[1], sizeof(long));
1306 retval
|= __copy_from_user(&pt
->r2
, &ppr
->gr
[2], sizeof(long) * 2);
1310 for (i
= 4; i
< 8; i
++) {
1311 retval
|= __get_user(val
, &ppr
->gr
[i
]);
1312 /* NaT bit will be set via PT_NAT_BITS: */
1313 if (unw_set_gr(&info
, i
, val
, 0) < 0)
1319 retval
|= __copy_from_user(&pt
->r8
, &ppr
->gr
[8], sizeof(long) * 4);
1323 retval
|= __copy_from_user(&pt
->r12
, &ppr
->gr
[12], sizeof(long) * 2);
1324 retval
|= __copy_from_user(&pt
->r14
, &ppr
->gr
[14], sizeof(long));
1325 retval
|= __copy_from_user(&pt
->r15
, &ppr
->gr
[15], sizeof(long));
1329 retval
|= __copy_from_user(&pt
->r16
, &ppr
->gr
[16], sizeof(long) * 16);
1333 retval
|= __get_user(pt
->b0
, &ppr
->br
[0]);
1337 for (i
= 1; i
< 6; i
++) {
1338 retval
|= __get_user(val
, &ppr
->br
[i
]);
1339 unw_set_br(&info
, i
, val
);
1344 retval
|= __get_user(pt
->b6
, &ppr
->br
[6]);
1345 retval
|= __get_user(pt
->b7
, &ppr
->br
[7]);
1349 for (i
= 2; i
< 6; i
++) {
1350 retval
|= __copy_from_user(&fpval
, &ppr
->fr
[i
], sizeof(fpval
));
1351 if (unw_set_fr(&info
, i
, fpval
) < 0)
1357 retval
|= __copy_from_user(&pt
->f6
, &ppr
->fr
[6],
1358 sizeof(ppr
->fr
[6]) * 6);
1360 /* fp scratch regs(12-15) */
1362 retval
|= __copy_from_user(&sw
->f12
, &ppr
->fr
[12],
1363 sizeof(ppr
->fr
[12]) * 4);
1367 for (i
= 16; i
< 32; i
++) {
1368 retval
|= __copy_from_user(&fpval
, &ppr
->fr
[i
],
1370 if (unw_set_fr(&info
, i
, fpval
) < 0)
1376 ia64_sync_fph(child
);
1377 retval
|= __copy_from_user(&child
->thread
.fph
, &ppr
->fr
[32],
1378 sizeof(ppr
->fr
[32]) * 96);
1382 retval
|= __get_user(pt
->pr
, &ppr
->pr
);
1386 retval
|= __get_user(nat_bits
, &ppr
->nat
);
1388 retval
|= access_uarea(child
, PT_CR_IPSR
, &psr
, 1);
1389 retval
|= access_uarea(child
, PT_AR_RSC
, &rsc
, 1);
1390 retval
|= access_uarea(child
, PT_AR_EC
, &ec
, 1);
1391 retval
|= access_uarea(child
, PT_AR_LC
, &lc
, 1);
1392 retval
|= access_uarea(child
, PT_AR_RNAT
, &rnat
, 1);
1393 retval
|= access_uarea(child
, PT_AR_BSP
, &bsp
, 1);
1394 retval
|= access_uarea(child
, PT_CFM
, &cfm
, 1);
1395 retval
|= access_uarea(child
, PT_NAT_BITS
, &nat_bits
, 1);
1397 ret
= retval
? -EIO
: 0;
1402 * Called by kernel/ptrace.c when detaching..
1404 * Make sure the single step bit is not set.
1407 ptrace_disable (struct task_struct
*child
)
1409 struct ia64_psr
*child_psr
= ia64_psr(task_pt_regs(child
));
1411 /* make sure the single step/taken-branch trap bits are not set: */
1412 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
1418 sys_ptrace (long request
, pid_t pid
, unsigned long addr
, unsigned long data
)
1421 unsigned long urbs_end
, peek_or_poke
;
1422 struct task_struct
*child
;
1423 struct switch_stack
*sw
;
1428 if (request
== PTRACE_TRACEME
) {
1429 ret
= ptrace_traceme();
1433 peek_or_poke
= (request
== PTRACE_PEEKTEXT
1434 || request
== PTRACE_PEEKDATA
1435 || request
== PTRACE_POKETEXT
1436 || request
== PTRACE_POKEDATA
);
1438 read_lock(&tasklist_lock
);
1440 child
= find_task_by_pid(pid
);
1443 child
= find_thread_for_addr(child
, addr
);
1444 get_task_struct(child
);
1447 read_unlock(&tasklist_lock
);
1451 if (pid
== 1) /* no messing around with init! */
1454 if (request
== PTRACE_ATTACH
) {
1455 ret
= ptrace_attach(child
);
1459 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
1463 pt
= task_pt_regs(child
);
1464 sw
= (struct switch_stack
*) (child
->thread
.ksp
+ 16);
1467 case PTRACE_PEEKTEXT
:
1468 case PTRACE_PEEKDATA
:
1469 /* read word at location addr */
1470 urbs_end
= ia64_get_user_rbs_end(child
, pt
, NULL
);
1471 ret
= ia64_peek(child
, sw
, urbs_end
, addr
, &data
);
1474 /* ensure "ret" is not mistaken as an error code: */
1475 force_successful_syscall_return();
1479 case PTRACE_POKETEXT
:
1480 case PTRACE_POKEDATA
:
1481 /* write the word at location addr */
1482 urbs_end
= ia64_get_user_rbs_end(child
, pt
, NULL
);
1483 ret
= ia64_poke(child
, sw
, urbs_end
, addr
, data
);
1486 case PTRACE_PEEKUSR
:
1487 /* read the word at addr in the USER area */
1488 if (access_uarea(child
, addr
, &data
, 0) < 0) {
1493 /* ensure "ret" is not mistaken as an error code */
1494 force_successful_syscall_return();
1497 case PTRACE_POKEUSR
:
1498 /* write the word at addr in the USER area */
1499 if (access_uarea(child
, addr
, &data
, 1) < 0) {
1506 case PTRACE_OLD_GETSIGINFO
:
1507 /* for backwards-compatibility */
1508 ret
= ptrace_request(child
, PTRACE_GETSIGINFO
, addr
, data
);
1511 case PTRACE_OLD_SETSIGINFO
:
1512 /* for backwards-compatibility */
1513 ret
= ptrace_request(child
, PTRACE_SETSIGINFO
, addr
, data
);
1516 case PTRACE_SYSCALL
:
1517 /* continue and stop at next (return from) syscall */
1519 /* restart after signal. */
1521 if (!valid_signal(data
))
1523 if (request
== PTRACE_SYSCALL
)
1524 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
1526 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
1527 child
->exit_code
= data
;
1530 * Make sure the single step/taken-branch trap bits
1533 clear_tsk_thread_flag(child
, TIF_SINGLESTEP
);
1534 ia64_psr(pt
)->ss
= 0;
1535 ia64_psr(pt
)->tb
= 0;
1537 wake_up_process(child
);
1543 * Make the child exit. Best I can do is send it a
1544 * sigkill. Perhaps it should be put in the status
1545 * that it wants to exit.
1547 if (child
->exit_state
== EXIT_ZOMBIE
)
1550 child
->exit_code
= SIGKILL
;
1552 ptrace_disable(child
);
1553 wake_up_process(child
);
1557 case PTRACE_SINGLESTEP
:
1558 /* let child execute for one instruction */
1559 case PTRACE_SINGLEBLOCK
:
1561 if (!valid_signal(data
))
1564 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
1565 set_tsk_thread_flag(child
, TIF_SINGLESTEP
);
1566 if (request
== PTRACE_SINGLESTEP
) {
1567 ia64_psr(pt
)->ss
= 1;
1569 ia64_psr(pt
)->tb
= 1;
1571 child
->exit_code
= data
;
1573 /* give it a chance to run. */
1574 wake_up_process(child
);
1579 /* detach a process that was attached. */
1580 ret
= ptrace_detach(child
, data
);
1583 case PTRACE_GETREGS
:
1584 ret
= ptrace_getregs(child
,
1585 (struct pt_all_user_regs __user
*) data
);
1588 case PTRACE_SETREGS
:
1589 ret
= ptrace_setregs(child
,
1590 (struct pt_all_user_regs __user
*) data
);
1594 ret
= ptrace_request(child
, request
, addr
, data
);
1598 put_task_struct(child
);
1606 syscall_trace (void)
1609 * The 0x80 provides a way for the tracing parent to
1610 * distinguish between a syscall stop and SIGTRAP delivery.
1612 ptrace_notify(SIGTRAP
1613 | ((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80 : 0));
1616 * This isn't the same as continuing with a signal, but it
1617 * will do for normal use. strace only continues with a
1618 * signal if the stopping signal is not SIGTRAP. -brl
1620 if (current
->exit_code
) {
1621 send_sig(current
->exit_code
, current
, 1);
1622 current
->exit_code
= 0;
1626 /* "asmlinkage" so the input arguments are preserved... */
1629 syscall_trace_enter (long arg0
, long arg1
, long arg2
, long arg3
,
1630 long arg4
, long arg5
, long arg6
, long arg7
,
1631 struct pt_regs regs
)
1633 if (test_thread_flag(TIF_SYSCALL_TRACE
)
1634 && (current
->ptrace
& PT_PTRACED
))
1637 if (unlikely(current
->audit_context
)) {
1641 if (IS_IA32_PROCESS(®s
)) {
1643 arch
= AUDIT_ARCH_I386
;
1646 arch
= AUDIT_ARCH_IA64
;
1649 audit_syscall_entry(arch
, syscall
, arg0
, arg1
, arg2
, arg3
);
1654 /* "asmlinkage" so the input arguments are preserved... */
1657 syscall_trace_leave (long arg0
, long arg1
, long arg2
, long arg3
,
1658 long arg4
, long arg5
, long arg6
, long arg7
,
1659 struct pt_regs regs
)
1661 if (unlikely(current
->audit_context
)) {
1662 int success
= AUDITSC_RESULT(regs
.r10
);
1663 long result
= regs
.r8
;
1665 if (success
!= AUDITSC_SUCCESS
)
1667 audit_syscall_exit(success
, result
);
1670 if ((test_thread_flag(TIF_SYSCALL_TRACE
)
1671 || test_thread_flag(TIF_SINGLESTEP
))
1672 && (current
->ptrace
& PT_PTRACED
))