2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
6 #include <linux/audit.h>
7 #include <linux/ptrace.h>
8 #include <linux/sched.h>
9 #include <linux/tracehook.h>
10 #include <asm/uaccess.h>
11 #include <skas_ptrace.h>
15 void user_enable_single_step(struct task_struct
*child
)
17 child
->ptrace
|= PT_DTRACE
;
18 child
->thread
.singlestep_syscall
= 0;
20 #ifdef SUBARCH_SET_SINGLESTEPPING
21 SUBARCH_SET_SINGLESTEPPING(child
, 1);
25 void user_disable_single_step(struct task_struct
*child
)
27 child
->ptrace
&= ~PT_DTRACE
;
28 child
->thread
.singlestep_syscall
= 0;
30 #ifdef SUBARCH_SET_SINGLESTEPPING
31 SUBARCH_SET_SINGLESTEPPING(child
, 0);
36 * Called by kernel/ptrace.c when detaching..
38 void ptrace_disable(struct task_struct
*child
)
40 user_disable_single_step(child
);
43 extern int peek_user(struct task_struct
* child
, long addr
, long data
);
44 extern int poke_user(struct task_struct
* child
, long addr
, long data
);
46 long arch_ptrace(struct task_struct
*child
, long request
,
47 unsigned long addr
, unsigned long data
)
50 unsigned long __user
*p
= (void __user
*)data
;
54 /* read the word at location addr in the USER area. */
56 ret
= peek_user(child
, addr
, data
);
59 /* write the word at location addr in the USER area */
61 ret
= poke_user(child
, addr
, data
);
65 case PTRACE_SYSEMU_SINGLESTEP
:
70 case PTRACE_GETREGS
: { /* Get all gp regs from the child. */
71 if (!access_ok(VERIFY_WRITE
, p
, MAX_REG_OFFSET
)) {
75 for ( i
= 0; i
< MAX_REG_OFFSET
; i
+= sizeof(long) ) {
76 __put_user(getreg(child
, i
), p
);
84 case PTRACE_SETREGS
: { /* Set all gp regs in the child. */
85 unsigned long tmp
= 0;
86 if (!access_ok(VERIFY_READ
, p
, MAX_REG_OFFSET
)) {
90 for ( i
= 0; i
< MAX_REG_OFFSET
; i
+= sizeof(long) ) {
92 putreg(child
, i
, tmp
);
99 case PTRACE_GET_THREAD_AREA
:
100 ret
= ptrace_get_thread_area(child
, addr
, vp
);
103 case PTRACE_SET_THREAD_AREA
:
104 ret
= ptrace_set_thread_area(child
, addr
, vp
);
107 case PTRACE_FAULTINFO
: {
109 * Take the info from thread->arch->faultinfo,
110 * but transfer max. sizeof(struct ptrace_faultinfo).
111 * On i386, ptrace_faultinfo is smaller!
113 ret
= copy_to_user(p
, &child
->thread
.arch
.faultinfo
,
114 sizeof(struct ptrace_faultinfo
)) ?
121 struct ptrace_ldt ldt
;
123 if (copy_from_user(&ldt
, p
, sizeof(ldt
))) {
129 * This one is confusing, so just punt and return -EIO for
137 ret
= ptrace_request(child
, request
, addr
, data
);
139 ret
= subarch_ptrace(child
, request
, addr
, data
);
146 static void send_sigtrap(struct task_struct
*tsk
, struct uml_pt_regs
*regs
,
151 memset(&info
, 0, sizeof(info
));
152 info
.si_signo
= SIGTRAP
;
153 info
.si_code
= TRAP_BRKPT
;
156 info
.si_addr
= UPT_IS_USER(regs
) ? (void __user
*) UPT_IP(regs
) : NULL
;
158 /* Send us the fake SIGTRAP */
159 force_sig_info(SIGTRAP
, &info
, tsk
);
163 * XXX Check PT_DTRACE vs TIF_SINGLESTEP for singlestepping check and
164 * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
166 void syscall_trace_enter(struct pt_regs
*regs
)
168 audit_syscall_entry(HOST_AUDIT_ARCH
,
169 UPT_SYSCALL_NR(®s
->regs
),
170 UPT_SYSCALL_ARG1(®s
->regs
),
171 UPT_SYSCALL_ARG2(®s
->regs
),
172 UPT_SYSCALL_ARG3(®s
->regs
),
173 UPT_SYSCALL_ARG4(®s
->regs
));
175 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
178 tracehook_report_syscall_entry(regs
);
181 void syscall_trace_leave(struct pt_regs
*regs
)
183 int ptraced
= current
->ptrace
;
185 audit_syscall_exit(regs
);
187 /* Fake a debug trap */
188 if (ptraced
& PT_DTRACE
)
189 send_sigtrap(current
, ®s
->regs
, 0);
191 if (!test_thread_flag(TIF_SYSCALL_TRACE
))
194 tracehook_report_syscall_exit(regs
, 0);
195 /* force do_signal() --> is_syscall() */
196 if (ptraced
& PT_PTRACED
)
197 set_thread_flag(TIF_SIGPENDING
);