vserver 1.9.3
[linux-2.6.git] / arch / um / kernel / skas / exec_user.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdlib.h>
7 #include <errno.h>
8 #include <signal.h>
9 #include <sched.h>
10 #include <sys/wait.h>
11 #include <sys/ptrace.h>
12 #include "user.h"
13 #include "kern_util.h"
14 #include "user_util.h"
15 #include "os.h"
16 #include "time_user.h"
17
18 static int user_thread_tramp(void *arg)
19 {
20         if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0)
21                 panic("user_thread_tramp - PTRACE_TRACEME failed, "
22                       "errno = %d\n", errno);
23         enable_timer();
24         os_stop_process(os_getpid());
25         return(0);
26 }
27
28 int user_thread(unsigned long stack, int flags)
29 {
30         int pid, status, err;
31
32         pid = clone(user_thread_tramp, (void *) stack_sp(stack), 
33                     flags | CLONE_FILES | SIGCHLD, NULL);
34         if(pid < 0){
35                 printk("user_thread - clone failed, errno = %d\n", errno);
36                 return(pid);
37         }
38
39         CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED));
40         if(err < 0){
41                 printk("user_thread - waitpid failed, errno = %d\n", errno);
42                 return(-errno);
43         }
44
45         if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)){
46                 printk("user_thread - trampoline didn't stop, status = %d\n", 
47                        status);
48                 return(-EINVAL);
49         }
50
51         return(pid);
52 }
53
54 /*
55  * Overrides for Emacs so that we follow Linus's tabbing style.
56  * Emacs will notice this stuff at the end of the file and automatically
57  * adjust the settings for this buffer only.  This must remain at the end
58  * of the file.
59  * ---------------------------------------------------------------------------
60  * Local variables:
61  * c-file-style: "linux"
62  * End:
63  */