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"
32 #include "uml-config.h"
33 #include "choose-mode.h"
37 int protect_memory(unsigned long addr
, unsigned long len
, int r
, int w
, int x
,
42 err
= os_protect_memory((void *) addr
, len
, r
, w
, x
);
45 panic("protect failed, err = %d", -err
);
51 void kill_child_dead(int pid
)
57 CATCH_EINTR(n
= waitpid(pid
, NULL
, 0));
67 while(1) sleep(1000000);
70 int wait_for_stop(int pid
, int sig
, int cont_type
, void *relay
)
72 sigset_t
*relay_signals
= relay
;
76 CATCH_EINTR(ret
= waitpid(pid
, &status
, WUNTRACED
));
78 !WIFSTOPPED(status
) || (WSTOPSIG(status
) != sig
)){
80 printk("wait failed, errno = %d\n",
83 else if(WIFEXITED(status
))
84 printk("process %d exited with status %d\n",
85 pid
, WEXITSTATUS(status
));
86 else if(WIFSIGNALED(status
))
87 printk("process %d exited with signal %d\n",
88 pid
, WTERMSIG(status
));
89 else if((WSTOPSIG(status
) == SIGVTALRM
) ||
90 (WSTOPSIG(status
) == SIGALRM
) ||
91 (WSTOPSIG(status
) == SIGIO
) ||
92 (WSTOPSIG(status
) == SIGPROF
) ||
93 (WSTOPSIG(status
) == SIGCHLD
) ||
94 (WSTOPSIG(status
) == SIGWINCH
) ||
95 (WSTOPSIG(status
) == SIGINT
)){
96 ptrace(cont_type
, pid
, 0, WSTOPSIG(status
));
99 else if((relay_signals
!= NULL
) &&
100 sigismember(relay_signals
, WSTOPSIG(status
))){
101 ptrace(cont_type
, pid
, 0, WSTOPSIG(status
));
104 else printk("process %d stopped with signal %d\n",
105 pid
, WSTOPSIG(status
));
106 panic("wait_for_stop failed to wait for %d to stop "
107 "with %d\n", pid
, sig
);
114 *-------------------------
115 * only for tt mode (will be deleted in future...)
116 *-------------------------
120 int (*tramp
)(void *);
122 unsigned long temp_stack
;
127 /* See above for why sigkill is here */
129 int sigkill
= SIGKILL
;
131 int outer_tramp(void *arg
)
137 t
->pid
= clone(t
->tramp
, (void *) t
->temp_stack
+ page_size()/2,
138 t
->flags
, t
->tramp_data
);
139 if(t
->pid
> 0) wait_for_stop(t
->pid
, SIGSTOP
, PTRACE_CONT
, NULL
);
140 kill(os_getpid(), sig
);
144 int start_fork_tramp(void *thread_arg
, unsigned long temp_stack
,
145 int clone_flags
, int (*tramp
)(void *))
149 int new_pid
, status
, err
;
151 /* The trampoline will run on the temporary stack */
152 sp
= stack_sp(temp_stack
);
154 clone_flags
|= CLONE_FILES
| SIGCHLD
;
157 arg
.tramp_data
= thread_arg
;
158 arg
.temp_stack
= temp_stack
;
159 arg
.flags
= clone_flags
;
161 /* Start the process and wait for it to kill itself */
162 new_pid
= clone(outer_tramp
, (void *) sp
, clone_flags
, &arg
);
166 CATCH_EINTR(err
= waitpid(new_pid
, &status
, 0));
168 panic("Waiting for outer trampoline failed - errno = %d",
171 if(!WIFSIGNALED(status
) || (WTERMSIG(status
) != SIGKILL
))
172 panic("outer trampoline didn't exit with SIGKILL, "
173 "status = %d", status
);
178 void forward_pending_sigio(int target
)
182 if(sigpending(&sigs
))
183 panic("forward_pending_sigio : sigpending failed");
184 if(sigismember(&sigs
, SIGIO
))