2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
14 #include <sys/ptrace.h>
15 #include <linux/ptrace.h>
18 #include <asm/ptrace.h>
19 #include <asm/unistd.h>
20 #include "kern_util.h"
22 #include "signal_kern.h"
23 #include "sysdep/ptrace.h"
24 #include "sysdep/sigcontext.h"
26 #include "ptrace_user.h"
29 #include "uml-config.h"
30 #include "choose-mode.h"
33 #include "kern_constants.h"
35 int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x,
40 err = os_protect_memory((void *) addr, len, r, w, x);
43 panic("protect failed, err = %d", -err);
49 void kill_child_dead(int pid)
55 CATCH_EINTR(n = waitpid(pid, NULL, 0));
65 while(1) sleep(1000000);
68 int wait_for_stop(int pid, int sig, int cont_type, void *relay)
70 sigset_t *relay_signals = relay;
74 CATCH_EINTR(ret = waitpid(pid, &status, WUNTRACED));
76 !WIFSTOPPED(status) || (WSTOPSIG(status) != sig)){
78 printk("wait failed, errno = %d\n",
81 else if(WIFEXITED(status))
82 printk("process %d exited with status %d\n",
83 pid, WEXITSTATUS(status));
84 else if(WIFSIGNALED(status))
85 printk("process %d exited with signal %d\n",
86 pid, WTERMSIG(status));
87 else if((WSTOPSIG(status) == SIGVTALRM) ||
88 (WSTOPSIG(status) == SIGALRM) ||
89 (WSTOPSIG(status) == SIGIO) ||
90 (WSTOPSIG(status) == SIGPROF) ||
91 (WSTOPSIG(status) == SIGCHLD) ||
92 (WSTOPSIG(status) == SIGWINCH) ||
93 (WSTOPSIG(status) == SIGINT)){
94 ptrace(cont_type, pid, 0, WSTOPSIG(status));
97 else if((relay_signals != NULL) &&
98 sigismember(relay_signals, WSTOPSIG(status))){
99 ptrace(cont_type, pid, 0, WSTOPSIG(status));
102 else printk("process %d stopped with signal %d\n",
103 pid, WSTOPSIG(status));
104 panic("wait_for_stop failed to wait for %d to stop "
105 "with %d\n", pid, sig);
111 void forward_ipi(int fd, int pid)
115 err = os_set_owner(fd, pid);
117 printk("forward_ipi: set_owner failed, fd = %d, me = %d, "
118 "target = %d, err = %d\n", fd, os_getpid(), pid, -err);
122 *-------------------------
123 * only for tt mode (will be deleted in future...)
124 *-------------------------
128 int (*tramp)(void *);
130 unsigned long temp_stack;
135 /* See above for why sigkill is here */
137 int sigkill = SIGKILL;
139 int outer_tramp(void *arg)
145 t->pid = clone(t->tramp, (void *) t->temp_stack + UM_KERN_PAGE_SIZE/2,
146 t->flags, t->tramp_data);
147 if(t->pid > 0) wait_for_stop(t->pid, SIGSTOP, PTRACE_CONT, NULL);
148 kill(os_getpid(), sig);
152 int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
153 int clone_flags, int (*tramp)(void *))
157 int new_pid, status, err;
159 /* The trampoline will run on the temporary stack */
160 sp = stack_sp(temp_stack);
162 clone_flags |= CLONE_FILES | SIGCHLD;
165 arg.tramp_data = thread_arg;
166 arg.temp_stack = temp_stack;
167 arg.flags = clone_flags;
169 /* Start the process and wait for it to kill itself */
170 new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg);
174 CATCH_EINTR(err = waitpid(new_pid, &status, 0));
176 panic("Waiting for outer trampoline failed - errno = %d",
179 if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL))
180 panic("outer trampoline didn't exit with SIGKILL, "
181 "status = %d", status);
186 void forward_pending_sigio(int target)
190 if(sigpending(&sigs))
191 panic("forward_pending_sigio : sigpending failed");
192 if(sigismember(&sigs, SIGIO))