aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-05-11 05:07:19 -0400
committerDavid S. Miller <davem@davemloft.net>2008-05-11 05:07:19 -0400
commit28e6103665301ce60634e8a77f0b657c6cc099de (patch)
tree1ba78c7db8d139529b8f0db5f0de60a6fbf701cb /include
parent986bef854fab44012df678a5b51817d5274d3ca1 (diff)
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation which tries to handle all of the nasties that can occur when the debugger looks at a process about to take a signal. It's meant to address all of these issues inside of the kernel so that the debugger need not be mindful of such things. Problem is, this doesn't work. The idea was that we should do the syscall restart business first, so that the debugger captures that state. Otherwise, if the debugger for example saves the child's state, makes the child execute something else, then restores the saved state, we won't handle the syscall restart properly because we lose the "we're in a syscall" state. The code here worked for most cases, but if the debugger actually passes the signal through to the child unaltered, it's possible that we would do a syscall restart when we shouldn't have. In particular this breaks the case of debugging a process under a gdb which is being debugged by yet another gdb. gdb uses sigsuspend to wait for SIGCHLD of the inferior, but if gdb itself is being debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the signal. But ptrace_signal_deliver() assumed the debugger would cancel out the signal and therefore did a syscall restart, because the return error was ERESTARTNOHAND. Fix this by simply making ptrace_signal_deliver() a nop, and providing a way for the debugger to control system call restarting properly: 1) Report a "in syscall" software bit in regs->{tstate,psr}. It is set early on in trap entry to a system call and is fully visible to the debugger via ptrace() and regsets. 2) Test this bit right before doing a syscall restart. We have to do a final recheck right after get_signal_to_deliver() in case the debugger cleared the bit during ptrace_stop(). 3) Clear the bit in trap return so we don't accidently try to set that bit in the real register. As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just like sparc64 has. M68K has this same exact bug, and is now the only other user of the ptrace_signal_deliver hook. It needs to be fixed in the same exact way as sparc. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/asm-sparc/psr.h1
-rw-r--r--include/asm-sparc/ptrace.h10
-rw-r--r--include/asm-sparc/signal.h8
-rw-r--r--include/asm-sparc64/psrcompat.h2
-rw-r--r--include/asm-sparc64/pstate.h1
-rw-r--r--include/asm-sparc64/ptrace.h10
-rw-r--r--include/asm-sparc64/signal.h8
-rw-r--r--include/asm-sparc64/ttable.h7
8 files changed, 24 insertions, 23 deletions
diff --git a/include/asm-sparc/psr.h b/include/asm-sparc/psr.h
index 19c978051118..213970477a24 100644
--- a/include/asm-sparc/psr.h
+++ b/include/asm-sparc/psr.h
@@ -25,6 +25,7 @@
25#define PSR_PIL 0x00000f00 /* processor interrupt level */ 25#define PSR_PIL 0x00000f00 /* processor interrupt level */
26#define PSR_EF 0x00001000 /* enable floating point */ 26#define PSR_EF 0x00001000 /* enable floating point */
27#define PSR_EC 0x00002000 /* enable co-processor */ 27#define PSR_EC 0x00002000 /* enable co-processor */
28#define PSR_SYSCALL 0x00004000 /* inside of a syscall */
28#define PSR_LE 0x00008000 /* SuperSparcII little-endian */ 29#define PSR_LE 0x00008000 /* SuperSparcII little-endian */
29#define PSR_ICC 0x00f00000 /* integer condition codes */ 30#define PSR_ICC 0x00f00000 /* integer condition codes */
30#define PSR_C 0x00100000 /* carry bit */ 31#define PSR_C 0x00100000 /* carry bit */
diff --git a/include/asm-sparc/ptrace.h b/include/asm-sparc/ptrace.h
index c25334234a6f..6b5e6ce5043c 100644
--- a/include/asm-sparc/ptrace.h
+++ b/include/asm-sparc/ptrace.h
@@ -39,6 +39,16 @@ struct pt_regs {
39#define UREG_FP UREG_I6 39#define UREG_FP UREG_I6
40#define UREG_RETPC UREG_I7 40#define UREG_RETPC UREG_I7
41 41
42static inline bool pt_regs_is_syscall(struct pt_regs *regs)
43{
44 return (regs->psr & PSR_SYSCALL);
45}
46
47static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
48{
49 return (regs->psr &= ~PSR_SYSCALL);
50}
51
42/* A register window */ 52/* A register window */
43struct reg_window { 53struct reg_window {
44 unsigned long locals[8]; 54 unsigned long locals[8];
diff --git a/include/asm-sparc/signal.h b/include/asm-sparc/signal.h
index d03a21c97abb..94071c75701f 100644
--- a/include/asm-sparc/signal.h
+++ b/include/asm-sparc/signal.h
@@ -199,13 +199,7 @@ typedef struct sigaltstack {
199 size_t ss_size; 199 size_t ss_size;
200} stack_t; 200} stack_t;
201 201
202struct sparc_deliver_cookie { 202#define ptrace_signal_deliver(regs, cookie) do { } while (0)
203 int restart_syscall;
204 unsigned long orig_i0;
205};
206
207struct pt_regs;
208extern void ptrace_signal_deliver(struct pt_regs *regs, void *cookie);
209 203
210#endif /* !(__KERNEL__) */ 204#endif /* !(__KERNEL__) */
211 205
diff --git a/include/asm-sparc64/psrcompat.h b/include/asm-sparc64/psrcompat.h
index 5590ce6bd076..3614ca04753f 100644
--- a/include/asm-sparc64/psrcompat.h
+++ b/include/asm-sparc64/psrcompat.h
@@ -12,6 +12,7 @@
12#define PSR_PIL 0x00000f00 /* processor interrupt level */ 12#define PSR_PIL 0x00000f00 /* processor interrupt level */
13#define PSR_EF 0x00001000 /* enable floating point */ 13#define PSR_EF 0x00001000 /* enable floating point */
14#define PSR_EC 0x00002000 /* enable co-processor */ 14#define PSR_EC 0x00002000 /* enable co-processor */
15#define PSR_SYSCALL 0x00004000 /* inside of a syscall */
15#define PSR_LE 0x00008000 /* SuperSparcII little-endian */ 16#define PSR_LE 0x00008000 /* SuperSparcII little-endian */
16#define PSR_ICC 0x00f00000 /* integer condition codes */ 17#define PSR_ICC 0x00f00000 /* integer condition codes */
17#define PSR_C 0x00100000 /* carry bit */ 18#define PSR_C 0x00100000 /* carry bit */
@@ -30,6 +31,7 @@ static inline unsigned int tstate_to_psr(unsigned long tstate)
30 PSR_S | 31 PSR_S |
31 ((tstate & TSTATE_ICC) >> 12) | 32 ((tstate & TSTATE_ICC) >> 12) |
32 ((tstate & TSTATE_XCC) >> 20) | 33 ((tstate & TSTATE_XCC) >> 20) |
34 ((tstate & TSTATE_SYSCALL) ? PSR_SYSCALL : 0) |
33 PSR_V8PLUS); 35 PSR_V8PLUS);
34} 36}
35 37
diff --git a/include/asm-sparc64/pstate.h b/include/asm-sparc64/pstate.h
index f3c45484c636..949aebaf991d 100644
--- a/include/asm-sparc64/pstate.h
+++ b/include/asm-sparc64/pstate.h
@@ -62,6 +62,7 @@
62#define TSTATE_PRIV _AC(0x0000000000000400,UL) /* Privilege. */ 62#define TSTATE_PRIV _AC(0x0000000000000400,UL) /* Privilege. */
63#define TSTATE_IE _AC(0x0000000000000200,UL) /* Interrupt Enable. */ 63#define TSTATE_IE _AC(0x0000000000000200,UL) /* Interrupt Enable. */
64#define TSTATE_AG _AC(0x0000000000000100,UL) /* Alternate Globals.*/ 64#define TSTATE_AG _AC(0x0000000000000100,UL) /* Alternate Globals.*/
65#define TSTATE_SYSCALL _AC(0x0000000000000020,UL) /* in syscall trap */
65#define TSTATE_CWP _AC(0x000000000000001f,UL) /* Curr Win-Pointer. */ 66#define TSTATE_CWP _AC(0x000000000000001f,UL) /* Curr Win-Pointer. */
66 67
67/* Floating-Point Registers State Register. 68/* Floating-Point Registers State Register.
diff --git a/include/asm-sparc64/ptrace.h b/include/asm-sparc64/ptrace.h
index 823656559d1a..90972a5ada59 100644
--- a/include/asm-sparc64/ptrace.h
+++ b/include/asm-sparc64/ptrace.h
@@ -42,16 +42,14 @@ static inline int pt_regs_trap_type(struct pt_regs *regs)
42 return regs->magic & 0x1ff; 42 return regs->magic & 0x1ff;
43} 43}
44 44
45static inline int pt_regs_clear_trap_type(struct pt_regs *regs) 45static inline bool pt_regs_is_syscall(struct pt_regs *regs)
46{ 46{
47 return regs->magic &= ~0x1ff; 47 return (regs->tstate & TSTATE_SYSCALL);
48} 48}
49 49
50static inline bool pt_regs_is_syscall(struct pt_regs *regs) 50static inline bool pt_regs_clear_syscall(struct pt_regs *regs)
51{ 51{
52 int tt = pt_regs_trap_type(regs); 52 return (regs->tstate &= ~TSTATE_SYSCALL);
53
54 return (tt == 0x110 || tt == 0x111 || tt == 0x16d);
55} 53}
56 54
57struct pt_regs32 { 55struct pt_regs32 {
diff --git a/include/asm-sparc64/signal.h b/include/asm-sparc64/signal.h
index fa6f467389db..c49f32d38707 100644
--- a/include/asm-sparc64/signal.h
+++ b/include/asm-sparc64/signal.h
@@ -186,13 +186,7 @@ struct k_sigaction {
186 void __user *ka_restorer; 186 void __user *ka_restorer;
187}; 187};
188 188
189struct signal_deliver_cookie { 189#define ptrace_signal_deliver(regs, cookie) do { } while (0)
190 int restart_syscall;
191 unsigned long orig_i0;
192};
193
194struct pt_regs;
195extern void ptrace_signal_deliver(struct pt_regs *regs, void *cookie);
196 190
197#endif /* !(__KERNEL__) */ 191#endif /* !(__KERNEL__) */
198 192
diff --git a/include/asm-sparc64/ttable.h b/include/asm-sparc64/ttable.h
index 1b55538b944f..52d67d394107 100644
--- a/include/asm-sparc64/ttable.h
+++ b/include/asm-sparc64/ttable.h
@@ -91,13 +91,14 @@
91 nop; 91 nop;
92 92
93#define SYSCALL_TRAP(routine, systbl) \ 93#define SYSCALL_TRAP(routine, systbl) \
94 rdpr %pil, %g2; \
95 mov TSTATE_SYSCALL, %g3; \
94 sethi %hi(109f), %g7; \ 96 sethi %hi(109f), %g7; \
95 ba,pt %xcc, etrap; \ 97 ba,pt %xcc, etrap_syscall; \
96109: or %g7, %lo(109b), %g7; \ 98109: or %g7, %lo(109b), %g7; \
97 sethi %hi(systbl), %l7; \ 99 sethi %hi(systbl), %l7; \
98 ba,pt %xcc, routine; \ 100 ba,pt %xcc, routine; \
99 or %l7, %lo(systbl), %l7; \ 101 or %l7, %lo(systbl), %l7;
100 nop; nop;
101 102
102#define TRAP_UTRAP(handler,lvl) \ 103#define TRAP_UTRAP(handler,lvl) \
103 mov handler, %g3; \ 104 mov handler, %g3; \