88 * SuperH version: Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
99 *
1010 */
11-
1211#include <linux/kernel.h>
1312#include <linux/sched.h>
1413#include <linux/mm.h>
2019#include <linux/slab.h>
2120#include <linux/security.h>
2221#include <linux/signal.h>
23-
24- #include <asm/io.h>
22+ #include <linux/io.h>
2523#include <asm/uaccess.h>
2624#include <asm/pgtable.h>
2725#include <asm/system.h>
@@ -59,14 +57,31 @@ static inline int put_stack_long(struct task_struct *task, int offset,
5957 return 0 ;
6058}
6159
60+ static void ptrace_disable_singlestep (struct task_struct * child )
61+ {
62+ clear_tsk_thread_flag (child , TIF_SINGLESTEP );
63+
64+ /*
65+ * Ensure the UBC is not programmed at the next context switch.
66+ *
67+ * Normally this is not needed but there are sequences such as
68+ * singlestep, signal delivery, and continue that leave the
69+ * ubc_pc non-zero leading to spurious SIGTRAPs.
70+ */
71+ if (child -> thread .ubc_pc != 0 ) {
72+ ubc_usercnt -= 1 ;
73+ child -> thread .ubc_pc = 0 ;
74+ }
75+ }
76+
6277/*
6378 * Called by kernel/ptrace.c when detaching..
6479 *
6580 * Make sure single step bits etc are not set.
6681 */
6782void ptrace_disable (struct task_struct * child )
6883{
69- /* nothing to do.. */
84+ ptrace_disable_singlestep ( child );
7085}
7186
7287long arch_ptrace (struct task_struct * child , long request , long addr , long data )
@@ -76,7 +91,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
7691
7792 switch (request ) {
7893 /* when I and D space are separate, these will need to be fixed. */
79- case PTRACE_PEEKTEXT : /* read word at location addr. */
94+ case PTRACE_PEEKTEXT : /* read word at location addr. */
8095 case PTRACE_PEEKDATA : {
8196 unsigned long tmp ;
8297 int copied ;
@@ -94,7 +109,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
94109 unsigned long tmp ;
95110
96111 ret = - EIO ;
97- if ((addr & 3 ) || addr < 0 ||
112+ if ((addr & 3 ) || addr < 0 ||
98113 addr > sizeof (struct user ) - 3 )
99114 break ;
100115
@@ -129,7 +144,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
129144
130145 case PTRACE_POKEUSR : /* write the word at location addr in the USER area */
131146 ret = - EIO ;
132- if ((addr & 3 ) || addr < 0 ||
147+ if ((addr & 3 ) || addr < 0 ||
133148 addr > sizeof (struct user ) - 3 )
134149 break ;
135150
@@ -156,21 +171,25 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
156171 set_tsk_thread_flag (child , TIF_SYSCALL_TRACE );
157172 else
158173 clear_tsk_thread_flag (child , TIF_SYSCALL_TRACE );
174+
175+ ptrace_disable_singlestep (child );
176+
159177 child -> exit_code = data ;
160178 wake_up_process (child );
161179 ret = 0 ;
162180 break ;
163181 }
164182
165183/*
166- * make the child exit. Best I can do is send it a sigkill.
167- * perhaps it should be put in the status that it wants to
184+ * make the child exit. Best I can do is send it a sigkill.
185+ * perhaps it should be put in the status that it wants to
168186 * exit.
169187 */
170188 case PTRACE_KILL : {
171189 ret = 0 ;
172190 if (child -> exit_state == EXIT_ZOMBIE ) /* already dead */
173191 break ;
192+ ptrace_disable_singlestep (child );
174193 child -> exit_code = SIGKILL ;
175194 wake_up_process (child );
176195 break ;
@@ -196,6 +215,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
196215 ubc_usercnt += 1 ;
197216 child -> thread .ubc_pc = pc ;
198217
218+ set_tsk_thread_flag (child , TIF_SINGLESTEP );
199219 child -> exit_code = data ;
200220 /* give it a chance to run. */
201221 wake_up_process (child );
@@ -248,14 +268,15 @@ asmlinkage void do_syscall_trace(void)
248268{
249269 struct task_struct * tsk = current ;
250270
251- if (!test_thread_flag (TIF_SYSCALL_TRACE ))
271+ if (!test_thread_flag (TIF_SYSCALL_TRACE ) &&
272+ !test_thread_flag (TIF_SINGLESTEP ))
252273 return ;
253274 if (!(tsk -> ptrace & PT_PTRACED ))
254275 return ;
255276 /* the 0x80 provides a way for the tracing parent to distinguish
256277 between a syscall stop and SIGTRAP delivery */
257- ptrace_notify (SIGTRAP | ((current -> ptrace & PT_TRACESYSGOOD )
258- ? 0x80 : 0 ));
278+ ptrace_notify (SIGTRAP | ((current -> ptrace & PT_TRACESYSGOOD ) &&
279+ ! test_thread_flag ( TIF_SINGLESTEP ) ? 0x80 : 0 ));
259280
260281 /*
261282 * this isn't the same as continuing with a signal, but it will do
0 commit comments