diff options
author | Gennady Sharapov <gennady.v.sharapov@intel.com> | 2005-09-03 18:57:47 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@evo.osdl.org> | 2005-09-05 03:06:24 -0400 |
commit | 60d339f6fe0831060600c62418b71a62ad26c281 (patch) | |
tree | a2f9527bbcfe85b3eb7c063b8af7d2f499ba4cbb /arch/um | |
parent | 09ace81c1d737bcbb2423db235ac980cac4d5de9 (diff) |
[PATCH] uml: move libc-dependent startup and signal code
The serial UML OS-abstraction layer patch (um/kernel dir).
This moves all systemcalls from process.c file under os-Linux dir and join
process.c and process_kern.c files.
Signed-off-by: Gennady Sharapov <gennady.v.sharapov@intel.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/include/os.h | 15 | ||||
-rw-r--r-- | arch/um/include/user_util.h | 8 | ||||
-rw-r--r-- | arch/um/kernel/Makefile | 13 | ||||
-rw-r--r-- | arch/um/kernel/um_arch.c | 2 | ||||
-rw-r--r-- | arch/um/os-Linux/Makefile | 7 | ||||
-rw-r--r-- | arch/um/os-Linux/process.c | 58 | ||||
-rw-r--r-- | arch/um/os-Linux/start_up.c (renamed from arch/um/kernel/process.c) | 182 | ||||
-rw-r--r-- | arch/um/os-Linux/tt.c | 113 |
8 files changed, 230 insertions, 168 deletions
diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 881d2988d2d8..4c362458052c 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h | |||
@@ -153,6 +153,11 @@ extern int os_file_type(char *file); | |||
153 | extern int os_file_mode(char *file, struct openflags *mode_out); | 153 | extern int os_file_mode(char *file, struct openflags *mode_out); |
154 | extern int os_lock_file(int fd, int excl); | 154 | extern int os_lock_file(int fd, int excl); |
155 | 155 | ||
156 | /* start_up.c */ | ||
157 | extern void os_early_checks(void); | ||
158 | extern int can_do_skas(void); | ||
159 | |||
160 | /* process.c */ | ||
156 | extern unsigned long os_process_pc(int pid); | 161 | extern unsigned long os_process_pc(int pid); |
157 | extern int os_process_parent(int pid); | 162 | extern int os_process_parent(int pid); |
158 | extern void os_stop_process(int pid); | 163 | extern void os_stop_process(int pid); |
@@ -161,6 +166,9 @@ extern void os_kill_ptraced_process(int pid, int reap_child); | |||
161 | extern void os_usr1_process(int pid); | 166 | extern void os_usr1_process(int pid); |
162 | extern int os_getpid(void); | 167 | extern int os_getpid(void); |
163 | extern int os_getpgrp(void); | 168 | extern int os_getpgrp(void); |
169 | extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)); | ||
170 | extern void init_new_thread_signals(int altstack); | ||
171 | extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr); | ||
164 | 172 | ||
165 | extern int os_map_memory(void *virt, int fd, unsigned long long off, | 173 | extern int os_map_memory(void *virt, int fd, unsigned long long off, |
166 | unsigned long len, int r, int w, int x); | 174 | unsigned long len, int r, int w, int x); |
@@ -170,6 +178,13 @@ extern int os_unmap_memory(void *addr, int len); | |||
170 | extern void os_flush_stdout(void); | 178 | extern void os_flush_stdout(void); |
171 | extern unsigned long long os_usecs(void); | 179 | extern unsigned long long os_usecs(void); |
172 | 180 | ||
181 | /* tt.c | ||
182 | * for tt mode only (will be deleted in future...) | ||
183 | */ | ||
184 | extern void forward_pending_sigio(int target); | ||
185 | extern int start_fork_tramp(void *arg, unsigned long temp_stack, | ||
186 | int clone_flags, int (*tramp)(void *)); | ||
187 | |||
173 | #endif | 188 | #endif |
174 | 189 | ||
175 | /* | 190 | /* |
diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index 7b6a24dfd302..bb505e01d994 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h | |||
@@ -54,8 +54,6 @@ extern void stack_protections(unsigned long address); | |||
54 | extern void task_protections(unsigned long address); | 54 | extern void task_protections(unsigned long address); |
55 | extern int wait_for_stop(int pid, int sig, int cont_type, void *relay); | 55 | extern int wait_for_stop(int pid, int sig, int cont_type, void *relay); |
56 | extern void *add_signal_handler(int sig, void (*handler)(int)); | 56 | extern void *add_signal_handler(int sig, void (*handler)(int)); |
57 | extern int start_fork_tramp(void *arg, unsigned long temp_stack, | ||
58 | int clone_flags, int (*tramp)(void *)); | ||
59 | extern int linux_main(int argc, char **argv); | 57 | extern int linux_main(int argc, char **argv); |
60 | extern void set_cmdline(char *cmd); | 58 | extern void set_cmdline(char *cmd); |
61 | extern void input_cb(void (*proc)(void *), void *arg, int arg_len); | 59 | extern void input_cb(void (*proc)(void *), void *arg, int arg_len); |
@@ -64,8 +62,6 @@ extern void *um_kmalloc(int size); | |||
64 | extern int switcheroo(int fd, int prot, void *from, void *to, int size); | 62 | extern int switcheroo(int fd, int prot, void *from, void *to, int size); |
65 | extern void setup_machinename(char *machine_out); | 63 | extern void setup_machinename(char *machine_out); |
66 | extern void setup_hostinfo(void); | 64 | extern void setup_hostinfo(void); |
67 | extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)); | ||
68 | extern void init_new_thread_signals(int altstack); | ||
69 | extern void do_exec(int old_pid, int new_pid); | 65 | extern void do_exec(int old_pid, int new_pid); |
70 | extern void tracer_panic(char *msg, ...); | 66 | extern void tracer_panic(char *msg, ...); |
71 | extern char *get_umid(int only_if_set); | 67 | extern char *get_umid(int only_if_set); |
@@ -74,16 +70,12 @@ extern int detach(int pid, int sig); | |||
74 | extern int attach(int pid); | 70 | extern int attach(int pid); |
75 | extern void kill_child_dead(int pid); | 71 | extern void kill_child_dead(int pid); |
76 | extern int cont(int pid); | 72 | extern int cont(int pid); |
77 | extern void check_ptrace(void); | ||
78 | extern void check_sigio(void); | 73 | extern void check_sigio(void); |
79 | extern int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr); | ||
80 | extern void write_sigio_workaround(void); | 74 | extern void write_sigio_workaround(void); |
81 | extern void arch_check_bugs(void); | 75 | extern void arch_check_bugs(void); |
82 | extern int cpu_feature(char *what, char *buf, int len); | 76 | extern int cpu_feature(char *what, char *buf, int len); |
83 | extern int arch_handle_signal(int sig, union uml_pt_regs *regs); | 77 | extern int arch_handle_signal(int sig, union uml_pt_regs *regs); |
84 | extern int arch_fixup(unsigned long address, void *sc_ptr); | 78 | extern int arch_fixup(unsigned long address, void *sc_ptr); |
85 | extern void forward_pending_sigio(int target); | ||
86 | extern int can_do_skas(void); | ||
87 | extern void arch_init_thread(void); | 79 | extern void arch_init_thread(void); |
88 | extern int setjmp_wrapper(void (*proc)(void *, void *), ...); | 80 | extern int setjmp_wrapper(void (*proc)(void *, void *), ...); |
89 | extern int raw(int fd); | 81 | extern int raw(int fd); |
diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index a9cdd00775a3..614b8ebeb0ed 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile | |||
@@ -8,11 +8,10 @@ clean-files := | |||
8 | 8 | ||
9 | obj-y = config.o exec_kern.o exitcode.o \ | 9 | obj-y = config.o exec_kern.o exitcode.o \ |
10 | helper.o init_task.o irq.o irq_user.o ksyms.o main.o mem.o mem_user.o \ | 10 | helper.o init_task.o irq.o irq_user.o ksyms.o main.o mem.o mem_user.o \ |
11 | physmem.o process.o process_kern.o ptrace.o reboot.o resource.o \ | 11 | physmem.o process_kern.o ptrace.o reboot.o resource.o sigio_user.o \ |
12 | sigio_user.o sigio_kern.o signal_kern.o signal_user.o smp.o \ | 12 | sigio_kern.o signal_kern.o signal_user.o smp.o syscall_kern.o sysrq.o \ |
13 | syscall_kern.o sysrq.o tempfile.o time.o time_kern.o \ | 13 | tempfile.o time.o time_kern.o tlb.o trap_kern.o trap_user.o \ |
14 | tlb.o trap_kern.o trap_user.o uaccess_user.o um_arch.o umid.o \ | 14 | uaccess_user.o um_arch.o umid.o user_util.o |
15 | user_util.o | ||
16 | 15 | ||
17 | obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o | 16 | obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o |
18 | obj-$(CONFIG_GPROF) += gprof_syms.o | 17 | obj-$(CONFIG_GPROF) += gprof_syms.o |
@@ -25,8 +24,8 @@ obj-$(CONFIG_MODE_SKAS) += skas/ | |||
25 | 24 | ||
26 | user-objs-$(CONFIG_TTY_LOG) += tty_log.o | 25 | user-objs-$(CONFIG_TTY_LOG) += tty_log.o |
27 | 26 | ||
28 | USER_OBJS := $(user-objs-y) config.o helper.o main.o process.o tempfile.o \ | 27 | USER_OBJS := $(user-objs-y) config.o helper.o main.o tempfile.o time.o \ |
29 | time.o tty_log.o umid.o user_util.o | 28 | tty_log.o umid.o user_util.o |
30 | 29 | ||
31 | include arch/um/scripts/Makefile.rules | 30 | include arch/um/scripts/Makefile.rules |
32 | 31 | ||
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index b781b6f94283..09f6f7ce4695 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c | |||
@@ -333,6 +333,7 @@ int linux_main(int argc, char **argv) | |||
333 | if(have_root == 0) | 333 | if(have_root == 0) |
334 | add_arg(DEFAULT_COMMAND_LINE); | 334 | add_arg(DEFAULT_COMMAND_LINE); |
335 | 335 | ||
336 | os_early_checks(); | ||
336 | mode_tt = force_tt ? 1 : !can_do_skas(); | 337 | mode_tt = force_tt ? 1 : !can_do_skas(); |
337 | #ifndef CONFIG_MODE_TT | 338 | #ifndef CONFIG_MODE_TT |
338 | if (mode_tt) { | 339 | if (mode_tt) { |
@@ -470,7 +471,6 @@ void __init setup_arch(char **cmdline_p) | |||
470 | void __init check_bugs(void) | 471 | void __init check_bugs(void) |
471 | { | 472 | { |
472 | arch_check_bugs(); | 473 | arch_check_bugs(); |
473 | check_ptrace(); | ||
474 | check_sigio(); | 474 | check_sigio(); |
475 | check_devanon(); | 475 | check_devanon(); |
476 | } | 476 | } |
diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 351d96934679..d3c1560e3ed8 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile | |||
@@ -3,10 +3,11 @@ | |||
3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
4 | # | 4 | # |
5 | 5 | ||
6 | obj-y = aio.o elf_aux.o file.o process.o signal.o time.o tty.o user_syms.o \ | 6 | obj-y = aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ |
7 | drivers/ sys-$(SUBARCH)/ | 7 | tty.o user_syms.o drivers/ sys-$(SUBARCH)/ |
8 | 8 | ||
9 | USER_OBJS := aio.o elf_aux.o file.o process.o signal.o time.o tty.o | 9 | USER_OBJS := aio.o elf_aux.o file.o process.o signal.o start_up.o time.o tt.o \ |
10 | tty.o | ||
10 | 11 | ||
11 | CFLAGS_user_syms.o += -DSUBARCH_$(SUBARCH) | 12 | CFLAGS_user_syms.o += -DSUBARCH_$(SUBARCH) |
12 | 13 | ||
diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 1e126bfd31a7..d32413e4b4ce 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c | |||
@@ -3,10 +3,10 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <unistd.h> | ||
7 | #include <stdio.h> | 6 | #include <stdio.h> |
8 | #include <errno.h> | 7 | #include <errno.h> |
9 | #include <signal.h> | 8 | #include <signal.h> |
9 | #include <setjmp.h> | ||
10 | #include <linux/unistd.h> | 10 | #include <linux/unistd.h> |
11 | #include <sys/mman.h> | 11 | #include <sys/mman.h> |
12 | #include <sys/wait.h> | 12 | #include <sys/wait.h> |
@@ -14,6 +14,10 @@ | |||
14 | #include "os.h" | 14 | #include "os.h" |
15 | #include "user.h" | 15 | #include "user.h" |
16 | #include "user_util.h" | 16 | #include "user_util.h" |
17 | #include "signal_user.h" | ||
18 | #include "process.h" | ||
19 | #include "irq_user.h" | ||
20 | #include "kern_util.h" | ||
17 | 21 | ||
18 | #define ARBITRARY_ADDR -1 | 22 | #define ARBITRARY_ADDR -1 |
19 | #define FAILURE_PID -1 | 23 | #define FAILURE_PID -1 |
@@ -114,8 +118,10 @@ void os_usr1_process(int pid) | |||
114 | kill(pid, SIGUSR1); | 118 | kill(pid, SIGUSR1); |
115 | } | 119 | } |
116 | 120 | ||
117 | /*Don't use the glibc version, which caches the result in TLS. It misses some | 121 | /* Don't use the glibc version, which caches the result in TLS. It misses some |
118 | * syscalls, and also breaks with clone(), which does not unshare the TLS.*/ | 122 | * syscalls, and also breaks with clone(), which does not unshare the TLS. |
123 | */ | ||
124 | |||
119 | inline _syscall0(pid_t, getpid) | 125 | inline _syscall0(pid_t, getpid) |
120 | 126 | ||
121 | int os_getpid(void) | 127 | int os_getpid(void) |
@@ -164,6 +170,52 @@ int os_unmap_memory(void *addr, int len) | |||
164 | return(0); | 170 | return(0); |
165 | } | 171 | } |
166 | 172 | ||
173 | void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)) | ||
174 | { | ||
175 | int flags = 0, pages; | ||
176 | |||
177 | if(sig_stack != NULL){ | ||
178 | pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER); | ||
179 | set_sigstack(sig_stack, pages * page_size()); | ||
180 | flags = SA_ONSTACK; | ||
181 | } | ||
182 | if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1); | ||
183 | } | ||
184 | |||
185 | void init_new_thread_signals(int altstack) | ||
186 | { | ||
187 | int flags = altstack ? SA_ONSTACK : 0; | ||
188 | |||
189 | set_handler(SIGSEGV, (__sighandler_t) sig_handler, flags, | ||
190 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
191 | set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags, | ||
192 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
193 | set_handler(SIGFPE, (__sighandler_t) sig_handler, flags, | ||
194 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
195 | set_handler(SIGILL, (__sighandler_t) sig_handler, flags, | ||
196 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
197 | set_handler(SIGBUS, (__sighandler_t) sig_handler, flags, | ||
198 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
199 | set_handler(SIGUSR2, (__sighandler_t) sig_handler, | ||
200 | flags, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
201 | signal(SIGHUP, SIG_IGN); | ||
202 | |||
203 | init_irq_signals(altstack); | ||
204 | } | ||
205 | |||
206 | int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr) | ||
207 | { | ||
208 | sigjmp_buf buf; | ||
209 | int n; | ||
210 | |||
211 | *jmp_ptr = &buf; | ||
212 | n = sigsetjmp(buf, 1); | ||
213 | if(n != 0) | ||
214 | return(n); | ||
215 | (*fn)(arg); | ||
216 | return(0); | ||
217 | } | ||
218 | |||
167 | /* | 219 | /* |
168 | * Overrides for Emacs so that we follow Linus's tabbing style. | 220 | * Overrides for Emacs so that we follow Linus's tabbing style. |
169 | * Emacs will notice this stuff at the end of the file and automatically | 221 | * Emacs will notice this stuff at the end of the file and automatically |
diff --git a/arch/um/kernel/process.c b/arch/um/os-Linux/start_up.c index 67acd92c5322..a3eab25f3791 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/os-Linux/start_up.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
@@ -19,7 +19,6 @@ | |||
19 | #include "user_util.h" | 19 | #include "user_util.h" |
20 | #include "kern_util.h" | 20 | #include "kern_util.h" |
21 | #include "user.h" | 21 | #include "user.h" |
22 | #include "process.h" | ||
23 | #include "signal_kern.h" | 22 | #include "signal_kern.h" |
24 | #include "signal_user.h" | 23 | #include "signal_user.h" |
25 | #include "sysdep/ptrace.h" | 24 | #include "sysdep/ptrace.h" |
@@ -39,98 +38,6 @@ | |||
39 | #include "registers.h" | 38 | #include "registers.h" |
40 | #endif | 39 | #endif |
41 | 40 | ||
42 | void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)) | ||
43 | { | ||
44 | int flags = 0, pages; | ||
45 | |||
46 | if(sig_stack != NULL){ | ||
47 | pages = (1 << UML_CONFIG_KERNEL_STACK_ORDER); | ||
48 | set_sigstack(sig_stack, pages * page_size()); | ||
49 | flags = SA_ONSTACK; | ||
50 | } | ||
51 | if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1); | ||
52 | } | ||
53 | |||
54 | void init_new_thread_signals(int altstack) | ||
55 | { | ||
56 | int flags = altstack ? SA_ONSTACK : 0; | ||
57 | |||
58 | set_handler(SIGSEGV, (__sighandler_t) sig_handler, flags, | ||
59 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
60 | set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags, | ||
61 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
62 | set_handler(SIGFPE, (__sighandler_t) sig_handler, flags, | ||
63 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
64 | set_handler(SIGILL, (__sighandler_t) sig_handler, flags, | ||
65 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
66 | set_handler(SIGBUS, (__sighandler_t) sig_handler, flags, | ||
67 | SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
68 | set_handler(SIGUSR2, (__sighandler_t) sig_handler, | ||
69 | flags, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); | ||
70 | signal(SIGHUP, SIG_IGN); | ||
71 | |||
72 | init_irq_signals(altstack); | ||
73 | } | ||
74 | |||
75 | struct tramp { | ||
76 | int (*tramp)(void *); | ||
77 | void *tramp_data; | ||
78 | unsigned long temp_stack; | ||
79 | int flags; | ||
80 | int pid; | ||
81 | }; | ||
82 | |||
83 | /* See above for why sigkill is here */ | ||
84 | |||
85 | int sigkill = SIGKILL; | ||
86 | |||
87 | int outer_tramp(void *arg) | ||
88 | { | ||
89 | struct tramp *t; | ||
90 | int sig = sigkill; | ||
91 | |||
92 | t = arg; | ||
93 | t->pid = clone(t->tramp, (void *) t->temp_stack + page_size()/2, | ||
94 | t->flags, t->tramp_data); | ||
95 | if(t->pid > 0) wait_for_stop(t->pid, SIGSTOP, PTRACE_CONT, NULL); | ||
96 | kill(os_getpid(), sig); | ||
97 | _exit(0); | ||
98 | } | ||
99 | |||
100 | int start_fork_tramp(void *thread_arg, unsigned long temp_stack, | ||
101 | int clone_flags, int (*tramp)(void *)) | ||
102 | { | ||
103 | struct tramp arg; | ||
104 | unsigned long sp; | ||
105 | int new_pid, status, err; | ||
106 | |||
107 | /* The trampoline will run on the temporary stack */ | ||
108 | sp = stack_sp(temp_stack); | ||
109 | |||
110 | clone_flags |= CLONE_FILES | SIGCHLD; | ||
111 | |||
112 | arg.tramp = tramp; | ||
113 | arg.tramp_data = thread_arg; | ||
114 | arg.temp_stack = temp_stack; | ||
115 | arg.flags = clone_flags; | ||
116 | |||
117 | /* Start the process and wait for it to kill itself */ | ||
118 | new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg); | ||
119 | if(new_pid < 0) | ||
120 | return(new_pid); | ||
121 | |||
122 | CATCH_EINTR(err = waitpid(new_pid, &status, 0)); | ||
123 | if(err < 0) | ||
124 | panic("Waiting for outer trampoline failed - errno = %d", | ||
125 | errno); | ||
126 | |||
127 | if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL)) | ||
128 | panic("outer trampoline didn't exit with SIGKILL, " | ||
129 | "status = %d", status); | ||
130 | |||
131 | return(arg.pid); | ||
132 | } | ||
133 | |||
134 | static int ptrace_child(void *arg) | 41 | static int ptrace_child(void *arg) |
135 | { | 42 | { |
136 | int ret; | 43 | int ret; |
@@ -165,7 +72,7 @@ static int start_ptraced_child(void **stack_out) | |||
165 | void *stack; | 72 | void *stack; |
166 | unsigned long sp; | 73 | unsigned long sp; |
167 | int pid, n, status; | 74 | int pid, n, status; |
168 | 75 | ||
169 | stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, | 76 | stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, |
170 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 77 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
171 | if(stack == MAP_FAILED) | 78 | if(stack == MAP_FAILED) |
@@ -173,10 +80,10 @@ static int start_ptraced_child(void **stack_out) | |||
173 | sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); | 80 | sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); |
174 | pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL); | 81 | pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL); |
175 | if(pid < 0) | 82 | if(pid < 0) |
176 | panic("check_ptrace : clone failed, errno = %d", errno); | 83 | panic("start_ptraced_child : clone failed, errno = %d", errno); |
177 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); | 84 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
178 | if(n < 0) | 85 | if(n < 0) |
179 | panic("check_ptrace : wait failed, errno = %d", errno); | 86 | panic("check_ptrace : clone failed, errno = %d", errno); |
180 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) | 87 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) |
181 | panic("check_ptrace : expected SIGSTOP, got status = %d", | 88 | panic("check_ptrace : expected SIGSTOP, got status = %d", |
182 | status); | 89 | status); |
@@ -185,11 +92,14 @@ static int start_ptraced_child(void **stack_out) | |||
185 | return(pid); | 92 | return(pid); |
186 | } | 93 | } |
187 | 94 | ||
188 | /* When testing for SYSEMU support, if it is one of the broken versions, we must | 95 | /* When testing for SYSEMU support, if it is one of the broken versions, we |
189 | * just avoid using sysemu, not panic, but only if SYSEMU features are broken. | 96 | * must just avoid using sysemu, not panic, but only if SYSEMU features are |
97 | * broken. | ||
190 | * So only for SYSEMU features we test mustpanic, while normal host features | 98 | * So only for SYSEMU features we test mustpanic, while normal host features |
191 | * must work anyway!*/ | 99 | * must work anyway! |
192 | static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic) | 100 | */ |
101 | static int stop_ptraced_child(int pid, void *stack, int exitcode, | ||
102 | int mustpanic) | ||
193 | { | 103 | { |
194 | int status, n, ret = 0; | 104 | int status, n, ret = 0; |
195 | 105 | ||
@@ -217,8 +127,6 @@ static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic) | |||
217 | return ret; | 127 | return ret; |
218 | } | 128 | } |
219 | 129 | ||
220 | static int force_sysemu_disabled = 0; | ||
221 | |||
222 | int ptrace_faultinfo = 1; | 130 | int ptrace_faultinfo = 1; |
223 | int proc_mm = 1; | 131 | int proc_mm = 1; |
224 | 132 | ||
@@ -228,24 +136,27 @@ static int __init skas0_cmd_param(char *str, int* add) | |||
228 | return 0; | 136 | return 0; |
229 | } | 137 | } |
230 | 138 | ||
139 | __uml_setup("skas0", skas0_cmd_param, | ||
140 | "skas0\n" | ||
141 | " Disables SKAS3 usage, so that SKAS0 is used, unless \n" | ||
142 | " you specify mode=tt.\n\n"); | ||
143 | |||
144 | static int force_sysemu_disabled = 0; | ||
145 | |||
231 | static int __init nosysemu_cmd_param(char *str, int* add) | 146 | static int __init nosysemu_cmd_param(char *str, int* add) |
232 | { | 147 | { |
233 | force_sysemu_disabled = 1; | 148 | force_sysemu_disabled = 1; |
234 | return 0; | 149 | return 0; |
235 | } | 150 | } |
236 | 151 | ||
237 | __uml_setup("skas0", skas0_cmd_param, | ||
238 | "skas0\n" | ||
239 | " Disables SKAS3 usage, so that SKAS0 is used, unless you \n" | ||
240 | " specify mode=tt.\n\n"); | ||
241 | |||
242 | __uml_setup("nosysemu", nosysemu_cmd_param, | 152 | __uml_setup("nosysemu", nosysemu_cmd_param, |
243 | "nosysemu\n" | 153 | "nosysemu\n" |
244 | " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n" | 154 | " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n" |
245 | " SYSEMU is a performance-patch introduced by Laurent Vivier. It changes\n" | 155 | " SYSEMU is a performance-patch introduced by Laurent Vivier. It changes\n" |
246 | " behaviour of ptrace() and helps reducing host context switch rate.\n" | 156 | " behaviour of ptrace() and helps reducing host context switch rate.\n" |
247 | " To make it working, you need a kernel patch for your host, too.\n" | 157 | " To make it working, you need a kernel patch for your host, too.\n" |
248 | " See http://perso.wanadoo.fr/laurent.vivier/UML/ for further information.\n\n"); | 158 | " See http://perso.wanadoo.fr/laurent.vivier/UML/ for further \n" |
159 | " information.\n\n"); | ||
249 | 160 | ||
250 | static void __init check_sysemu(void) | 161 | static void __init check_sysemu(void) |
251 | { | 162 | { |
@@ -321,7 +232,7 @@ fail_stopped: | |||
321 | printk("missing\n"); | 232 | printk("missing\n"); |
322 | } | 233 | } |
323 | 234 | ||
324 | void __init check_ptrace(void) | 235 | static void __init check_ptrace(void) |
325 | { | 236 | { |
326 | void *stack; | 237 | void *stack; |
327 | int pid, syscall, n, status; | 238 | int pid, syscall, n, status; |
@@ -329,12 +240,12 @@ void __init check_ptrace(void) | |||
329 | printk("Checking that ptrace can change system call numbers..."); | 240 | printk("Checking that ptrace can change system call numbers..."); |
330 | pid = start_ptraced_child(&stack); | 241 | pid = start_ptraced_child(&stack); |
331 | 242 | ||
332 | if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0) | 243 | if(ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0) |
333 | panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno); | 244 | panic("check_ptrace: PTRACE_OLDSETOPTIONS failed, errno = %d", errno); |
334 | 245 | ||
335 | while(1){ | 246 | while(1){ |
336 | if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) | 247 | if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) |
337 | panic("check_ptrace : ptrace failed, errno = %d", | 248 | panic("check_ptrace : ptrace failed, errno = %d", |
338 | errno); | 249 | errno); |
339 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); | 250 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
340 | if(n < 0) | 251 | if(n < 0) |
@@ -342,7 +253,7 @@ void __init check_ptrace(void) | |||
342 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP + 0x80)) | 253 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP + 0x80)) |
343 | panic("check_ptrace : expected SIGTRAP + 0x80, " | 254 | panic("check_ptrace : expected SIGTRAP + 0x80, " |
344 | "got status = %d", status); | 255 | "got status = %d", status); |
345 | 256 | ||
346 | syscall = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET, | 257 | syscall = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET, |
347 | 0); | 258 | 0); |
348 | if(syscall == __NR_getpid){ | 259 | if(syscall == __NR_getpid){ |
@@ -359,33 +270,12 @@ void __init check_ptrace(void) | |||
359 | check_sysemu(); | 270 | check_sysemu(); |
360 | } | 271 | } |
361 | 272 | ||
362 | int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr) | 273 | void os_early_checks(void) |
363 | { | ||
364 | sigjmp_buf buf; | ||
365 | int n; | ||
366 | |||
367 | *jmp_ptr = &buf; | ||
368 | n = sigsetjmp(buf, 1); | ||
369 | if(n != 0) | ||
370 | return(n); | ||
371 | (*fn)(arg); | ||
372 | return(0); | ||
373 | } | ||
374 | |||
375 | void forward_pending_sigio(int target) | ||
376 | { | 274 | { |
377 | sigset_t sigs; | 275 | check_ptrace(); |
378 | |||
379 | if(sigpending(&sigs)) | ||
380 | panic("forward_pending_sigio : sigpending failed"); | ||
381 | if(sigismember(&sigs, SIGIO)) | ||
382 | kill(target, SIGIO); | ||
383 | } | 276 | } |
384 | 277 | ||
385 | extern void *__syscall_stub_start, __syscall_stub_end; | ||
386 | |||
387 | #ifdef UML_CONFIG_MODE_SKAS | 278 | #ifdef UML_CONFIG_MODE_SKAS |
388 | |||
389 | static inline void check_skas3_ptrace_support(void) | 279 | static inline void check_skas3_ptrace_support(void) |
390 | { | 280 | { |
391 | struct ptrace_faultinfo fi; | 281 | struct ptrace_faultinfo fi; |
@@ -400,9 +290,8 @@ static inline void check_skas3_ptrace_support(void) | |||
400 | ptrace_faultinfo = 0; | 290 | ptrace_faultinfo = 0; |
401 | if(errno == EIO) | 291 | if(errno == EIO) |
402 | printf("not found\n"); | 292 | printf("not found\n"); |
403 | else { | 293 | else |
404 | perror("not found"); | 294 | perror("not found"); |
405 | } | ||
406 | } | 295 | } |
407 | else { | 296 | else { |
408 | if (!ptrace_faultinfo) | 297 | if (!ptrace_faultinfo) |
@@ -419,9 +308,10 @@ int can_do_skas(void) | |||
419 | { | 308 | { |
420 | printf("Checking for /proc/mm..."); | 309 | printf("Checking for /proc/mm..."); |
421 | if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { | 310 | if (os_access("/proc/mm", OS_ACC_W_OK) < 0) { |
422 | proc_mm = 0; | 311 | proc_mm = 0; |
423 | printf("not found\n"); | 312 | printf("not found\n"); |
424 | } else { | 313 | } |
314 | else { | ||
425 | if (!proc_mm) | 315 | if (!proc_mm) |
426 | printf("found but disabled on command line\n"); | 316 | printf("found but disabled on command line\n"); |
427 | else | 317 | else |
diff --git a/arch/um/os-Linux/tt.c b/arch/um/os-Linux/tt.c new file mode 100644 index 000000000000..5b047ab8416a --- /dev/null +++ b/arch/um/os-Linux/tt.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <unistd.h> | ||
8 | #include <signal.h> | ||
9 | #include <sched.h> | ||
10 | #include <errno.h> | ||
11 | #include <stdarg.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <setjmp.h> | ||
14 | #include <sys/time.h> | ||
15 | #include <sys/ptrace.h> | ||
16 | #include <linux/ptrace.h> | ||
17 | #include <sys/wait.h> | ||
18 | #include <sys/mman.h> | ||
19 | #include <asm/ptrace.h> | ||
20 | #include <asm/unistd.h> | ||
21 | #include <asm/page.h> | ||
22 | #include "user_util.h" | ||
23 | #include "kern_util.h" | ||
24 | #include "user.h" | ||
25 | #include "signal_kern.h" | ||
26 | #include "signal_user.h" | ||
27 | #include "sysdep/ptrace.h" | ||
28 | #include "sysdep/sigcontext.h" | ||
29 | #include "irq_user.h" | ||
30 | #include "ptrace_user.h" | ||
31 | #include "time_user.h" | ||
32 | #include "init.h" | ||
33 | #include "os.h" | ||
34 | #include "uml-config.h" | ||
35 | #include "choose-mode.h" | ||
36 | #include "mode.h" | ||
37 | #include "tempfile.h" | ||
38 | |||
39 | /* | ||
40 | *------------------------- | ||
41 | * only for tt mode (will be deleted in future...) | ||
42 | *------------------------- | ||
43 | */ | ||
44 | |||
45 | struct tramp { | ||
46 | int (*tramp)(void *); | ||
47 | void *tramp_data; | ||
48 | unsigned long temp_stack; | ||
49 | int flags; | ||
50 | int pid; | ||
51 | }; | ||
52 | |||
53 | /* See above for why sigkill is here */ | ||
54 | |||
55 | int sigkill = SIGKILL; | ||
56 | |||
57 | int outer_tramp(void *arg) | ||
58 | { | ||
59 | struct tramp *t; | ||
60 | int sig = sigkill; | ||
61 | |||
62 | t = arg; | ||
63 | t->pid = clone(t->tramp, (void *) t->temp_stack + page_size()/2, | ||
64 | t->flags, t->tramp_data); | ||
65 | if(t->pid > 0) wait_for_stop(t->pid, SIGSTOP, PTRACE_CONT, NULL); | ||
66 | kill(os_getpid(), sig); | ||
67 | _exit(0); | ||
68 | } | ||
69 | |||
70 | int start_fork_tramp(void *thread_arg, unsigned long temp_stack, | ||
71 | int clone_flags, int (*tramp)(void *)) | ||
72 | { | ||
73 | struct tramp arg; | ||
74 | unsigned long sp; | ||
75 | int new_pid, status, err; | ||
76 | |||
77 | /* The trampoline will run on the temporary stack */ | ||
78 | sp = stack_sp(temp_stack); | ||
79 | |||
80 | clone_flags |= CLONE_FILES | SIGCHLD; | ||
81 | |||
82 | arg.tramp = tramp; | ||
83 | arg.tramp_data = thread_arg; | ||
84 | arg.temp_stack = temp_stack; | ||
85 | arg.flags = clone_flags; | ||
86 | |||
87 | /* Start the process and wait for it to kill itself */ | ||
88 | new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg); | ||
89 | if(new_pid < 0) | ||
90 | return(new_pid); | ||
91 | |||
92 | CATCH_EINTR(err = waitpid(new_pid, &status, 0)); | ||
93 | if(err < 0) | ||
94 | panic("Waiting for outer trampoline failed - errno = %d", | ||
95 | errno); | ||
96 | |||
97 | if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL)) | ||
98 | panic("outer trampoline didn't exit with SIGKILL, " | ||
99 | "status = %d", status); | ||
100 | |||
101 | return(arg.pid); | ||
102 | } | ||
103 | |||
104 | void forward_pending_sigio(int target) | ||
105 | { | ||
106 | sigset_t sigs; | ||
107 | |||
108 | if(sigpending(&sigs)) | ||
109 | panic("forward_pending_sigio : sigpending failed"); | ||
110 | if(sigismember(&sigs, SIGIO)) | ||
111 | kill(target, SIGIO); | ||
112 | } | ||
113 | |||