2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
15 #include <sys/ptrace.h>
16 #include <linux/ptrace.h>
19 #include <asm/ptrace.h>
20 #include <asm/unistd.h>
22 #include "user_util.h"
23 #include "kern_util.h"
25 #include "signal_kern.h"
26 #include "sysdep/ptrace.h"
27 #include "sysdep/sigcontext.h"
29 #include "ptrace_user.h"
30 #include "time_user.h"
33 #include "uml-config.h"
34 #include "choose-mode.h"
38 int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x,
43 err = os_protect_memory((void *) addr, len, r, w, x);
46 panic("protect failed, err = %d", -err);
52 void kill_child_dead(int pid)
58 CATCH_EINTR(n = waitpid(pid, NULL, 0));
67 *-------------------------
68 * only for tt mode (will be deleted in future...)
69 *-------------------------
75 unsigned long temp_stack;
80 /* See above for why sigkill is here */
82 int sigkill = SIGKILL;
84 int outer_tramp(void *arg)
90 t->pid = clone(t->tramp, (void *) t->temp_stack + page_size()/2,
91 t->flags, t->tramp_data);
92 if(t->pid > 0) wait_for_stop(t->pid, SIGSTOP, PTRACE_CONT, NULL);
93 kill(os_getpid(), sig);
97 int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
98 int clone_flags, int (*tramp)(void *))
102 int new_pid, status, err;
104 /* The trampoline will run on the temporary stack */
105 sp = stack_sp(temp_stack);
107 clone_flags |= CLONE_FILES | SIGCHLD;
110 arg.tramp_data = thread_arg;
111 arg.temp_stack = temp_stack;
112 arg.flags = clone_flags;
114 /* Start the process and wait for it to kill itself */
115 new_pid = clone(outer_tramp, (void *) sp, clone_flags, &arg);
119 CATCH_EINTR(err = waitpid(new_pid, &status, 0));
121 panic("Waiting for outer trampoline failed - errno = %d",
124 if(!WIFSIGNALED(status) || (WTERMSIG(status) != SIGKILL))
125 panic("outer trampoline didn't exit with SIGKILL, "
126 "status = %d", status);
131 void forward_pending_sigio(int target)
135 if(sigpending(&sigs))
136 panic("forward_pending_sigio : sigpending failed");
137 if(sigismember(&sigs, SIGIO))