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>
21 #include "kern_util.h"
23 #include "signal_kern.h"
24 #include "sysdep/ptrace.h"
25 #include "sysdep/sigcontext.h"
27 #include "ptrace_user.h"
30 #include "uml-config.h"
31 #include "choose-mode.h"
34 #include "kern_constants.h"
36 int protect_memory(unsigned long addr
, unsigned long len
, int r
, int w
, int x
,
41 err
= os_protect_memory((void *) addr
, len
, r
, w
, x
);
44 panic("protect failed, err = %d", -err
);
50 void kill_child_dead(int pid
)
56 CATCH_EINTR(n
= waitpid(pid
, NULL
, 0));
66 while(1) sleep(1000000);
69 int wait_for_stop(int pid
, int sig
, int cont_type
, void *relay
)
71 sigset_t
*relay_signals
= relay
;
75 CATCH_EINTR(ret
= waitpid(pid
, &status
, WUNTRACED
));
77 !WIFSTOPPED(status
) || (WSTOPSIG(status
) != sig
)){
79 printk("wait failed, errno = %d\n",
82 else if(WIFEXITED(status
))
83 printk("process %d exited with status %d\n",
84 pid
, WEXITSTATUS(status
));
85 else if(WIFSIGNALED(status
))
86 printk("process %d exited with signal %d\n",
87 pid
, WTERMSIG(status
));
88 else if((WSTOPSIG(status
) == SIGVTALRM
) ||
89 (WSTOPSIG(status
) == SIGALRM
) ||
90 (WSTOPSIG(status
) == SIGIO
) ||
91 (WSTOPSIG(status
) == SIGPROF
) ||
92 (WSTOPSIG(status
) == SIGCHLD
) ||
93 (WSTOPSIG(status
) == SIGWINCH
) ||
94 (WSTOPSIG(status
) == SIGINT
)){
95 ptrace(cont_type
, pid
, 0, WSTOPSIG(status
));
98 else if((relay_signals
!= NULL
) &&
99 sigismember(relay_signals
, WSTOPSIG(status
))){
100 ptrace(cont_type
, pid
, 0, WSTOPSIG(status
));
103 else printk("process %d stopped with signal %d\n",
104 pid
, WSTOPSIG(status
));
105 panic("wait_for_stop failed to wait for %d to stop "
106 "with %d\n", pid
, sig
);
112 void forward_ipi(int fd
, int pid
)
116 err
= os_set_owner(fd
, pid
);
118 printk("forward_ipi: set_owner failed, fd = %d, me = %d, "
119 "target = %d, err = %d\n", fd
, os_getpid(), pid
, -err
);
123 *-------------------------
124 * only for tt mode (will be deleted in future...)
125 *-------------------------
129 int (*tramp
)(void *);
131 unsigned long temp_stack
;
136 /* See above for why sigkill is here */
138 int sigkill
= SIGKILL
;
140 int outer_tramp(void *arg
)
146 t
->pid
= clone(t
->tramp
, (void *) t
->temp_stack
+ UM_KERN_PAGE_SIZE
/2,
147 t
->flags
, t
->tramp_data
);
148 if(t
->pid
> 0) wait_for_stop(t
->pid
, SIGSTOP
, PTRACE_CONT
, NULL
);
149 kill(os_getpid(), sig
);
153 int start_fork_tramp(void *thread_arg
, unsigned long temp_stack
,
154 int clone_flags
, int (*tramp
)(void *))
158 int new_pid
, status
, err
;
160 /* The trampoline will run on the temporary stack */
161 sp
= stack_sp(temp_stack
);
163 clone_flags
|= CLONE_FILES
| SIGCHLD
;
166 arg
.tramp_data
= thread_arg
;
167 arg
.temp_stack
= temp_stack
;
168 arg
.flags
= clone_flags
;
170 /* Start the process and wait for it to kill itself */
171 new_pid
= clone(outer_tramp
, (void *) sp
, clone_flags
, &arg
);
175 CATCH_EINTR(err
= waitpid(new_pid
, &status
, 0));
177 panic("Waiting for outer trampoline failed - errno = %d",
180 if(!WIFSIGNALED(status
) || (WTERMSIG(status
) != SIGKILL
))
181 panic("outer trampoline didn't exit with SIGKILL, "
182 "status = %d", status
);
187 void forward_pending_sigio(int target
)
191 if(sigpending(&sigs
))
192 panic("forward_pending_sigio : sigpending failed");
193 if(sigismember(&sigs
, SIGIO
))