diff options
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r-- | arch/um/os-Linux/Makefile | 8 | ||||
-rw-r--r-- | arch/um/os-Linux/main.c | 1 | ||||
-rw-r--r-- | arch/um/os-Linux/process.c | 1 | ||||
-rw-r--r-- | arch/um/os-Linux/signal.c | 158 | ||||
-rw-r--r-- | arch/um/os-Linux/skas/Makefile | 10 | ||||
-rw-r--r-- | arch/um/os-Linux/skas/trap.c | 73 | ||||
-rw-r--r-- | arch/um/os-Linux/start_up.c | 1 | ||||
-rw-r--r-- | arch/um/os-Linux/trap.c | 40 | ||||
-rw-r--r-- | arch/um/os-Linux/tt.c | 15 |
9 files changed, 290 insertions, 17 deletions
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 11e30b13e318..40c7d6b1df68 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
@@ -4,11 +4,13 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ | 6 | obj-y = aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ |
7 | start_up.o time.o tt.o tty.o uaccess.o umid.o user_syms.o drivers/ \ | 7 | start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o user_syms.o \ |
8 | sys-$(SUBARCH)/ | 8 | drivers/ sys-$(SUBARCH)/ |
9 | |||
10 | obj-$(CONFIG_MODE_SKAS) += skas/ | ||
9 | 11 | ||
10 | USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ | 12 | USER_OBJS := aio.o elf_aux.o file.o helper.o main.o mem.o process.o signal.o \ |
11 | start_up.o time.o tt.o tty.o uaccess.o umid.o | 13 | start_up.o time.o trap.o tt.o tty.o uaccess.o umid.o |
12 | 14 | ||
13 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h | 15 | elf_aux.o: $(ARCH_DIR)/kernel-offsets.h |
14 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um | 16 | CFLAGS_elf_aux.o += -I$(objtree)/arch/um |
diff --git a/arch/um/os-Linux/main.c b/arch/um/os-Linux/main.c index 23da27d22569..172c8474453c 100644 --- a/arch/um/os-Linux/main.c +++ b/arch/um/os-Linux/main.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include "user_util.h" | 16 | #include "user_util.h" |
17 | #include "kern_util.h" | 17 | #include "kern_util.h" |
18 | #include "mem_user.h" | 18 | #include "mem_user.h" |
19 | #include "signal_user.h" | ||
20 | #include "time_user.h" | 19 | #include "time_user.h" |
21 | #include "irq_user.h" | 20 | #include "irq_user.h" |
22 | #include "user.h" | 21 | #include "user.h" |
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index d9c52387c4a1..39815c6b5e45 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include "os.h" | 15 | #include "os.h" |
16 | #include "user.h" | 16 | #include "user.h" |
17 | #include "user_util.h" | 17 | #include "user_util.h" |
18 | #include "signal_user.h" | ||
19 | #include "process.h" | 18 | #include "process.h" |
20 | #include "irq_user.h" | 19 | #include "irq_user.h" |
21 | #include "kern_util.h" | 20 | #include "kern_util.h" |
diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index c7bfd5ee3925..c1f46a0fef13 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c | |||
@@ -4,9 +4,22 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <signal.h> | 6 | #include <signal.h> |
7 | #include <stdio.h> | ||
8 | #include <unistd.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <errno.h> | ||
11 | #include <stdarg.h> | ||
12 | #include <string.h> | ||
13 | #include <sys/mman.h> | ||
14 | #include "user_util.h" | ||
15 | #include "kern_util.h" | ||
16 | #include "user.h" | ||
17 | #include "signal_kern.h" | ||
18 | #include "sysdep/sigcontext.h" | ||
19 | #include "sysdep/signal.h" | ||
20 | #include "sigcontext.h" | ||
7 | #include "time_user.h" | 21 | #include "time_user.h" |
8 | #include "mode.h" | 22 | #include "mode.h" |
9 | #include "sysdep/signal.h" | ||
10 | 23 | ||
11 | void sig_handler(ARCH_SIGHDLR_PARAM) | 24 | void sig_handler(ARCH_SIGHDLR_PARAM) |
12 | { | 25 | { |
@@ -36,13 +49,138 @@ void alarm_handler(ARCH_SIGHDLR_PARAM) | |||
36 | switch_timers(1); | 49 | switch_timers(1); |
37 | } | 50 | } |
38 | 51 | ||
39 | /* | 52 | void set_sigstack(void *sig_stack, int size) |
40 | * Overrides for Emacs so that we follow Linus's tabbing style. | 53 | { |
41 | * Emacs will notice this stuff at the end of the file and automatically | 54 | stack_t stack = ((stack_t) { .ss_flags = 0, |
42 | * adjust the settings for this buffer only. This must remain at the end | 55 | .ss_sp = (__ptr_t) sig_stack, |
43 | * of the file. | 56 | .ss_size = size - sizeof(void *) }); |
44 | * --------------------------------------------------------------------------- | 57 | |
45 | * Local variables: | 58 | if(sigaltstack(&stack, NULL) != 0) |
46 | * c-file-style: "linux" | 59 | panic("enabling signal stack failed, errno = %d\n", errno); |
47 | * End: | 60 | } |
61 | |||
62 | void remove_sigstack(void) | ||
63 | { | ||
64 | stack_t stack = ((stack_t) { .ss_flags = SS_DISABLE, | ||
65 | .ss_sp = NULL, | ||
66 | .ss_size = 0 }); | ||
67 | |||
68 | if(sigaltstack(&stack, NULL) != 0) | ||
69 | panic("disabling signal stack failed, errno = %d\n", errno); | ||
70 | } | ||
71 | |||
72 | void set_handler(int sig, void (*handler)(int), int flags, ...) | ||
73 | { | ||
74 | struct sigaction action; | ||
75 | va_list ap; | ||
76 | int mask; | ||
77 | |||
78 | va_start(ap, flags); | ||
79 | action.sa_handler = handler; | ||
80 | sigemptyset(&action.sa_mask); | ||
81 | while((mask = va_arg(ap, int)) != -1){ | ||
82 | sigaddset(&action.sa_mask, mask); | ||
83 | } | ||
84 | va_end(ap); | ||
85 | action.sa_flags = flags; | ||
86 | action.sa_restorer = NULL; | ||
87 | if(sigaction(sig, &action, NULL) < 0) | ||
88 | panic("sigaction failed"); | ||
89 | } | ||
90 | |||
91 | int change_sig(int signal, int on) | ||
92 | { | ||
93 | sigset_t sigset, old; | ||
94 | |||
95 | sigemptyset(&sigset); | ||
96 | sigaddset(&sigset, signal); | ||
97 | sigprocmask(on ? SIG_UNBLOCK : SIG_BLOCK, &sigset, &old); | ||
98 | return(!sigismember(&old, signal)); | ||
99 | } | ||
100 | |||
101 | /* Both here and in set/get_signal we don't touch SIGPROF, because we must not | ||
102 | * disable profiling; it's safe because the profiling code does not interact | ||
103 | * with the kernel code at all.*/ | ||
104 | |||
105 | static void change_signals(int type) | ||
106 | { | ||
107 | sigset_t mask; | ||
108 | |||
109 | sigemptyset(&mask); | ||
110 | sigaddset(&mask, SIGVTALRM); | ||
111 | sigaddset(&mask, SIGALRM); | ||
112 | sigaddset(&mask, SIGIO); | ||
113 | if(sigprocmask(type, &mask, NULL) < 0) | ||
114 | panic("Failed to change signal mask - errno = %d", errno); | ||
115 | } | ||
116 | |||
117 | void block_signals(void) | ||
118 | { | ||
119 | change_signals(SIG_BLOCK); | ||
120 | } | ||
121 | |||
122 | void unblock_signals(void) | ||
123 | { | ||
124 | change_signals(SIG_UNBLOCK); | ||
125 | } | ||
126 | |||
127 | /* These are the asynchronous signals. SIGVTALRM and SIGARLM are handled | ||
128 | * together under SIGVTALRM_BIT. SIGPROF is excluded because we want to | ||
129 | * be able to profile all of UML, not just the non-critical sections. If | ||
130 | * profiling is not thread-safe, then that is not my problem. We can disable | ||
131 | * profiling when SMP is enabled in that case. | ||
48 | */ | 132 | */ |
133 | #define SIGIO_BIT 0 | ||
134 | #define SIGVTALRM_BIT 1 | ||
135 | |||
136 | static int enable_mask(sigset_t *mask) | ||
137 | { | ||
138 | int sigs; | ||
139 | |||
140 | sigs = sigismember(mask, SIGIO) ? 0 : 1 << SIGIO_BIT; | ||
141 | sigs |= sigismember(mask, SIGVTALRM) ? 0 : 1 << SIGVTALRM_BIT; | ||
142 | sigs |= sigismember(mask, SIGALRM) ? 0 : 1 << SIGVTALRM_BIT; | ||
143 | return(sigs); | ||
144 | } | ||
145 | |||
146 | int get_signals(void) | ||
147 | { | ||
148 | sigset_t mask; | ||
149 | |||
150 | if(sigprocmask(SIG_SETMASK, NULL, &mask) < 0) | ||
151 | panic("Failed to get signal mask"); | ||
152 | return(enable_mask(&mask)); | ||
153 | } | ||
154 | |||
155 | int set_signals(int enable) | ||
156 | { | ||
157 | sigset_t mask; | ||
158 | int ret; | ||
159 | |||
160 | sigemptyset(&mask); | ||
161 | if(enable & (1 << SIGIO_BIT)) | ||
162 | sigaddset(&mask, SIGIO); | ||
163 | if(enable & (1 << SIGVTALRM_BIT)){ | ||
164 | sigaddset(&mask, SIGVTALRM); | ||
165 | sigaddset(&mask, SIGALRM); | ||
166 | } | ||
167 | |||
168 | /* This is safe - sigprocmask is guaranteed to copy locally the | ||
169 | * value of new_set, do his work and then, at the end, write to | ||
170 | * old_set. | ||
171 | */ | ||
172 | if(sigprocmask(SIG_UNBLOCK, &mask, &mask) < 0) | ||
173 | panic("Failed to enable signals"); | ||
174 | ret = enable_mask(&mask); | ||
175 | sigemptyset(&mask); | ||
176 | if((enable & (1 << SIGIO_BIT)) == 0) | ||
177 | sigaddset(&mask, SIGIO); | ||
178 | if((enable & (1 << SIGVTALRM_BIT)) == 0){ | ||
179 | sigaddset(&mask, SIGVTALRM); | ||
180 | sigaddset(&mask, SIGALRM); | ||
181 | } | ||
182 | if(sigprocmask(SIG_BLOCK, &mask, NULL) < 0) | ||
183 | panic("Failed to block signals"); | ||
184 | |||
185 | return(ret); | ||
186 | } | ||
diff --git a/arch/um/os-Linux/skas/Makefile b/arch/um/os-Linux/skas/Makefile new file mode 100644 index 000000000000..eab5386d60a7 --- /dev/null +++ b/arch/um/os-Linux/skas/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # | ||
2 | # Copyright (C) 2002 - 2004 Jeff Dike (jdike@addtoit.com) | ||
3 | # Licensed under the GPL | ||
4 | # | ||
5 | |||
6 | obj-y := trap.o | ||
7 | |||
8 | USER_OBJS := trap.o | ||
9 | |||
10 | include arch/um/scripts/Makefile.rules | ||
diff --git a/arch/um/os-Linux/skas/trap.c b/arch/um/os-Linux/skas/trap.c new file mode 100644 index 000000000000..9ad5fbec4593 --- /dev/null +++ b/arch/um/os-Linux/skas/trap.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #include <signal.h> | ||
7 | #include <errno.h> | ||
8 | #include "user_util.h" | ||
9 | #include "kern_util.h" | ||
10 | #include "task.h" | ||
11 | #include "sigcontext.h" | ||
12 | #include "skas.h" | ||
13 | #include "ptrace_user.h" | ||
14 | #include "sysdep/ptrace.h" | ||
15 | #include "sysdep/ptrace_user.h" | ||
16 | #include "os.h" | ||
17 | |||
18 | void sig_handler_common_skas(int sig, void *sc_ptr) | ||
19 | { | ||
20 | struct sigcontext *sc = sc_ptr; | ||
21 | struct skas_regs *r; | ||
22 | void (*handler)(int, union uml_pt_regs *); | ||
23 | int save_errno = errno; | ||
24 | int save_user; | ||
25 | |||
26 | /* This is done because to allow SIGSEGV to be delivered inside a SEGV | ||
27 | * handler. This can happen in copy_user, and if SEGV is disabled, | ||
28 | * the process will die. | ||
29 | * XXX Figure out why this is better than SA_NODEFER | ||
30 | */ | ||
31 | if(sig == SIGSEGV) | ||
32 | change_sig(SIGSEGV, 1); | ||
33 | |||
34 | r = &TASK_REGS(get_current())->skas; | ||
35 | save_user = r->is_user; | ||
36 | r->is_user = 0; | ||
37 | if ( sig == SIGFPE || sig == SIGSEGV || | ||
38 | sig == SIGBUS || sig == SIGILL || | ||
39 | sig == SIGTRAP ) { | ||
40 | GET_FAULTINFO_FROM_SC(r->faultinfo, sc); | ||
41 | } | ||
42 | |||
43 | change_sig(SIGUSR1, 1); | ||
44 | |||
45 | handler = sig_info[sig]; | ||
46 | |||
47 | /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */ | ||
48 | if (sig != SIGIO && sig != SIGWINCH && | ||
49 | sig != SIGVTALRM && sig != SIGALRM) | ||
50 | unblock_signals(); | ||
51 | |||
52 | handler(sig, (union uml_pt_regs *) r); | ||
53 | |||
54 | errno = save_errno; | ||
55 | r->is_user = save_user; | ||
56 | } | ||
57 | |||
58 | extern int ptrace_faultinfo; | ||
59 | |||
60 | void user_signal(int sig, union uml_pt_regs *regs, int pid) | ||
61 | { | ||
62 | void (*handler)(int, union uml_pt_regs *); | ||
63 | int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) || | ||
64 | (sig == SIGILL) || (sig == SIGTRAP)); | ||
65 | |||
66 | if (segv) | ||
67 | get_skas_faultinfo(pid, ®s->skas.faultinfo); | ||
68 | |||
69 | handler = sig_info[sig]; | ||
70 | handler(sig, (union uml_pt_regs *) regs); | ||
71 | |||
72 | unblock_signals(); | ||
73 | } | ||
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 29a9e3f43763..b47e5e71d1a5 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include "kern_util.h" | 24 | #include "kern_util.h" |
25 | #include "user.h" | 25 | #include "user.h" |
26 | #include "signal_kern.h" | 26 | #include "signal_kern.h" |
27 | #include "signal_user.h" | ||
28 | #include "sysdep/ptrace.h" | 27 | #include "sysdep/ptrace.h" |
29 | #include "sysdep/sigcontext.h" | 28 | #include "sysdep/sigcontext.h" |
30 | #include "irq_user.h" | 29 | #include "irq_user.h" |
diff --git a/arch/um/os-Linux/trap.c b/arch/um/os-Linux/trap.c new file mode 100644 index 000000000000..321e1c8e227d --- /dev/null +++ b/arch/um/os-Linux/trap.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #include <stdlib.h> | ||
7 | #include <signal.h> | ||
8 | #include <setjmp.h> | ||
9 | #include "kern_util.h" | ||
10 | #include "user_util.h" | ||
11 | #include "os.h" | ||
12 | #include "mode.h" | ||
13 | |||
14 | void usr2_handler(int sig, union uml_pt_regs *regs) | ||
15 | { | ||
16 | CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0); | ||
17 | } | ||
18 | |||
19 | void (*sig_info[NSIG])(int, union uml_pt_regs *); | ||
20 | |||
21 | void os_fill_handlinfo(struct kern_handlers h) | ||
22 | { | ||
23 | sig_info[SIGTRAP] = h.relay_signal; | ||
24 | sig_info[SIGFPE] = h.relay_signal; | ||
25 | sig_info[SIGILL] = h.relay_signal; | ||
26 | sig_info[SIGWINCH] = h.winch; | ||
27 | sig_info[SIGBUS] = h.bus_handler; | ||
28 | sig_info[SIGSEGV] = h.page_fault; | ||
29 | sig_info[SIGIO] = h.sigio_handler; | ||
30 | sig_info[SIGVTALRM] = h.timer_handler; | ||
31 | sig_info[SIGALRM] = h.timer_handler; | ||
32 | sig_info[SIGUSR2] = usr2_handler; | ||
33 | } | ||
34 | |||
35 | void do_longjmp(void *b, int val) | ||
36 | { | ||
37 | sigjmp_buf *buf = b; | ||
38 | |||
39 | siglongjmp(*buf, val); | ||
40 | } | ||
diff --git a/arch/um/os-Linux/tt.c b/arch/um/os-Linux/tt.c index a6db8877931a..cb2648b79d0f 100644 --- a/arch/um/os-Linux/tt.c +++ b/arch/um/os-Linux/tt.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include "kern_util.h" | 23 | #include "kern_util.h" |
24 | #include "user.h" | 24 | #include "user.h" |
25 | #include "signal_kern.h" | 25 | #include "signal_kern.h" |
26 | #include "signal_user.h" | ||
27 | #include "sysdep/ptrace.h" | 26 | #include "sysdep/ptrace.h" |
28 | #include "sysdep/sigcontext.h" | 27 | #include "sysdep/sigcontext.h" |
29 | #include "irq_user.h" | 28 | #include "irq_user.h" |
@@ -50,6 +49,20 @@ int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x, | |||
50 | return(0); | 49 | return(0); |
51 | } | 50 | } |
52 | 51 | ||
52 | void kill_child_dead(int pid) | ||
53 | { | ||
54 | kill(pid, SIGKILL); | ||
55 | kill(pid, SIGCONT); | ||
56 | do { | ||
57 | int n; | ||
58 | CATCH_EINTR(n = waitpid(pid, NULL, 0)); | ||
59 | if (n > 0) | ||
60 | kill(pid, SIGCONT); | ||
61 | else | ||
62 | break; | ||
63 | } while(1); | ||
64 | } | ||
65 | |||
53 | /* | 66 | /* |
54 | *------------------------- | 67 | *------------------------- |
55 | * only for tt mode (will be deleted in future...) | 68 | * only for tt mode (will be deleted in future...) |