diff options
author | Jeff Dike <jdike@addtoit.com> | 2008-02-05 01:30:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:28 -0500 |
commit | ee3d9bd4de1ed93d2a7ee41c331ed30a1c7b8acd (patch) | |
tree | f49369c9f941066bdb8bbb2b4fd9d40bf2fda292 /arch | |
parent | ca77b555c0aafa3070fbb67592abaaa1b8d31913 (diff) |
uml: simplify SIGSEGV handling
Simplify the page fault stub by not masking signals while it is running. This
allows it to signal that it is done by executing an instruction which will
generate a SIGTRAP (int3 on x86) rather than running sigreturn by hand after
queueing a blocked SIGUSR1.
userspace_tramp now no longer puts anything in the SIGSEGV sa_mask, but it
does add SA_NODEFER to sa_flags so that SIGSEGV is still enabled after the
signal handler fails to run sigreturn.
SIGWINCH is just blocked so that we don't have to deal with it and the signal
masks used by wait_stub_done are updated to reflect the smaller number of
signals that it has to worry about.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/um/os-Linux/skas/process.c | 11 | ||||
-rw-r--r-- | arch/um/sys-i386/stub_segv.c | 19 | ||||
-rw-r--r-- | arch/um/sys-x86_64/stub_segv.c | 39 |
3 files changed, 11 insertions, 58 deletions
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index 765cfa6ddbcd..2cc2071112bc 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c | |||
@@ -55,10 +55,10 @@ static int ptrace_dump_regs(int pid) | |||
55 | * Signals that are OK to receive in the stub - we'll just continue it. | 55 | * Signals that are OK to receive in the stub - we'll just continue it. |
56 | * SIGWINCH will happen when UML is inside a detached screen. | 56 | * SIGWINCH will happen when UML is inside a detached screen. |
57 | */ | 57 | */ |
58 | #define STUB_SIG_MASK ((1 << SIGVTALRM) | (1 << SIGWINCH)) | 58 | #define STUB_SIG_MASK (1 << SIGVTALRM) |
59 | 59 | ||
60 | /* Signals that the stub will finish with - anything else is an error */ | 60 | /* Signals that the stub will finish with - anything else is an error */ |
61 | #define STUB_DONE_MASK ((1 << SIGUSR1) | (1 << SIGTRAP)) | 61 | #define STUB_DONE_MASK (1 << SIGTRAP) |
62 | 62 | ||
63 | void wait_stub_done(int pid) | 63 | void wait_stub_done(int pid) |
64 | { | 64 | { |
@@ -179,6 +179,7 @@ static int userspace_tramp(void *stack) | |||
179 | ptrace(PTRACE_TRACEME, 0, 0, 0); | 179 | ptrace(PTRACE_TRACEME, 0, 0, 0); |
180 | 180 | ||
181 | signal(SIGTERM, SIG_DFL); | 181 | signal(SIGTERM, SIG_DFL); |
182 | signal(SIGWINCH, SIG_IGN); | ||
182 | err = set_interval(); | 183 | err = set_interval(); |
183 | if (err) | 184 | if (err) |
184 | panic("userspace_tramp - setting timer failed, errno = %d\n", | 185 | panic("userspace_tramp - setting timer failed, errno = %d\n", |
@@ -222,11 +223,7 @@ static int userspace_tramp(void *stack) | |||
222 | 223 | ||
223 | set_sigstack((void *) STUB_DATA, UM_KERN_PAGE_SIZE); | 224 | set_sigstack((void *) STUB_DATA, UM_KERN_PAGE_SIZE); |
224 | sigemptyset(&sa.sa_mask); | 225 | sigemptyset(&sa.sa_mask); |
225 | sigaddset(&sa.sa_mask, SIGIO); | 226 | sa.sa_flags = SA_ONSTACK | SA_NODEFER; |
226 | sigaddset(&sa.sa_mask, SIGWINCH); | ||
227 | sigaddset(&sa.sa_mask, SIGVTALRM); | ||
228 | sigaddset(&sa.sa_mask, SIGUSR1); | ||
229 | sa.sa_flags = SA_ONSTACK; | ||
230 | sa.sa_handler = (void *) v; | 227 | sa.sa_handler = (void *) v; |
231 | sa.sa_restorer = NULL; | 228 | sa.sa_restorer = NULL; |
232 | if (sigaction(SIGSEGV, &sa, NULL) < 0) | 229 | if (sigaction(SIGSEGV, &sa, NULL) < 0) |
diff --git a/arch/um/sys-i386/stub_segv.c b/arch/um/sys-i386/stub_segv.c index b3999cb76bfd..28ccf737a79f 100644 --- a/arch/um/sys-i386/stub_segv.c +++ b/arch/um/sys-i386/stub_segv.c | |||
@@ -1,32 +1,17 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com) | 2 | * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <signal.h> | ||
7 | #include <sys/select.h> /* The only way I can see to get sigset_t */ | ||
8 | #include <asm/unistd.h> | ||
9 | #include "as-layout.h" | ||
10 | #include "uml-config.h" | ||
11 | #include "sysdep/stub.h" | 6 | #include "sysdep/stub.h" |
12 | #include "sysdep/sigcontext.h" | 7 | #include "sysdep/sigcontext.h" |
13 | #include "sysdep/faultinfo.h" | ||
14 | 8 | ||
15 | void __attribute__ ((__section__ (".__syscall_stub"))) | 9 | void __attribute__ ((__section__ (".__syscall_stub"))) |
16 | stub_segv_handler(int sig) | 10 | stub_segv_handler(int sig) |
17 | { | 11 | { |
18 | struct sigcontext *sc = (struct sigcontext *) (&sig + 1); | 12 | struct sigcontext *sc = (struct sigcontext *) (&sig + 1); |
19 | int pid; | ||
20 | 13 | ||
21 | GET_FAULTINFO_FROM_SC(*((struct faultinfo *) STUB_DATA), sc); | 14 | GET_FAULTINFO_FROM_SC(*((struct faultinfo *) STUB_DATA), sc); |
22 | 15 | ||
23 | pid = stub_syscall0(__NR_getpid); | 16 | trap_myself(); |
24 | stub_syscall2(__NR_kill, pid, SIGUSR1); | ||
25 | |||
26 | /* Load pointer to sigcontext into esp, since we need to leave | ||
27 | * the stack in its original form when we do the sigreturn here, by | ||
28 | * hand. | ||
29 | */ | ||
30 | __asm__ __volatile__("mov %0,%%esp ; movl %1, %%eax ; " | ||
31 | "int $0x80" : : "a" (sc), "g" (__NR_sigreturn)); | ||
32 | } | 17 | } |
diff --git a/arch/um/sys-x86_64/stub_segv.c b/arch/um/sys-x86_64/stub_segv.c index 3afb590f0072..ced051afc705 100644 --- a/arch/um/sys-x86_64/stub_segv.c +++ b/arch/um/sys-x86_64/stub_segv.c | |||
@@ -1,51 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com) | 2 | * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <stddef.h> | ||
7 | #include <signal.h> | 6 | #include <signal.h> |
8 | #include <asm/unistd.h> | ||
9 | #include "as-layout.h" | 7 | #include "as-layout.h" |
10 | #include "uml-config.h" | ||
11 | #include "sysdep/sigcontext.h" | ||
12 | #include "sysdep/faultinfo.h" | ||
13 | #include "sysdep/stub.h" | 8 | #include "sysdep/stub.h" |
14 | 9 | #include "sysdep/faultinfo.h" | |
15 | /* Copied from sys-x86_64/signal.c - Can't find an equivalent definition | 10 | #include "sysdep/sigcontext.h" |
16 | * in the libc headers anywhere. | ||
17 | */ | ||
18 | struct rt_sigframe | ||
19 | { | ||
20 | char *pretcode; | ||
21 | struct ucontext uc; | ||
22 | struct siginfo info; | ||
23 | }; | ||
24 | |||
25 | /* Copied here from <linux/kernel.h> - we're userspace. */ | ||
26 | #define container_of(ptr, type, member) ({ \ | ||
27 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | ||
28 | (type *)( (char *)__mptr - offsetof(type,member) );}) | ||
29 | 11 | ||
30 | void __attribute__ ((__section__ (".__syscall_stub"))) | 12 | void __attribute__ ((__section__ (".__syscall_stub"))) |
31 | stub_segv_handler(int sig) | 13 | stub_segv_handler(int sig) |
32 | { | 14 | { |
33 | struct ucontext *uc; | 15 | struct ucontext *uc; |
34 | int pid; | ||
35 | 16 | ||
36 | __asm__ __volatile__("movq %%rdx, %0" : "=g" (uc) :); | 17 | __asm__ __volatile__("movq %%rdx, %0" : "=g" (uc) :); |
37 | GET_FAULTINFO_FROM_SC(*((struct faultinfo *) STUB_DATA), | 18 | GET_FAULTINFO_FROM_SC(*((struct faultinfo *) STUB_DATA), |
38 | &uc->uc_mcontext); | 19 | &uc->uc_mcontext); |
39 | 20 | trap_myself(); | |
40 | pid = stub_syscall0(__NR_getpid); | ||
41 | stub_syscall2(__NR_kill, pid, SIGUSR1); | ||
42 | |||
43 | /* sys_sigreturn expects that the stack pointer will be 8 bytes into | ||
44 | * the signal frame. So, we use the ucontext pointer, which we know | ||
45 | * already, to get the signal frame pointer, and add 8 to that. | ||
46 | */ | ||
47 | __asm__ __volatile__("movq %0, %%rsp; movq %1, %%rax ; syscall": : | ||
48 | "g" ((unsigned long) | ||
49 | container_of(uc, struct rt_sigframe, uc) + 8), | ||
50 | "g" (__NR_rt_sigreturn)); | ||
51 | } | 21 | } |
22 | |||