diff options
Diffstat (limited to 'arch/um/os-Linux/tt.c')
-rw-r--r-- | arch/um/os-Linux/tt.c | 113 |
1 files changed, 113 insertions, 0 deletions
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 | |||