ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / kernel / tt / exec_user.c
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 <stdlib.h>
9 #include <sched.h>
10 #include <errno.h>
11 #include <sys/wait.h>
12 #include <sys/ptrace.h>
13 #include <signal.h>
14 #include "user_util.h"
15 #include "kern_util.h"
16 #include "user.h"
17 #include "ptrace_user.h"
18
19 void do_exec(int old_pid, int new_pid)
20 {
21         unsigned long regs[FRAME_SIZE];
22
23         if((ptrace(PTRACE_ATTACH, new_pid, 0, 0) < 0) ||
24            (ptrace(PTRACE_CONT, new_pid, 0, 0) < 0) ||
25            (waitpid(new_pid, 0, WUNTRACED) < 0))
26                 tracer_panic("do_exec failed to attach proc - errno = %d",
27                              errno);
28
29         if(ptrace_getregs(old_pid, regs) < 0)
30                 tracer_panic("do_exec failed to get registers - errno = %d",
31                              errno);
32
33         kill(old_pid, SIGKILL);
34
35         if(ptrace_setregs(new_pid, regs) < 0)
36                 tracer_panic("do_exec failed to start new proc - errno = %d",
37                              errno);
38 }
39
40 /*
41  * Overrides for Emacs so that we follow Linus's tabbing style.
42  * Emacs will notice this stuff at the end of the file and automatically
43  * adjust the settings for this buffer only.  This must remain at the end
44  * of the file.
45  * ---------------------------------------------------------------------------
46  * Local variables:
47  * c-file-style: "linux"
48  * End:
49  */