ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 "os.h"
15 #include "time_user.h"
16
17 static int user_thread_tramp(void *arg)
18 {
19         if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0)
20                 panic("user_thread_tramp - PTRACE_TRACEME failed, "
21                       "errno = %d\n", errno);
22         enable_timer();
23         os_stop_process(os_getpid());
24         return(0);
25 }
26
27 int user_thread(unsigned long stack, int flags)
28 {
29         int pid, status;
30
31         pid = clone(user_thread_tramp, (void *) stack_sp(stack), 
32                     flags | CLONE_FILES | SIGCHLD, NULL);
33         if(pid < 0){
34                 printk("user_thread - clone failed, errno = %d\n", errno);
35                 return(pid);
36         }
37
38         if(waitpid(pid, &status, WUNTRACED) < 0){
39                 printk("user_thread - waitpid failed, errno = %d\n", errno);
40                 return(-errno);
41         }
42
43         if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)){
44                 printk("user_thread - trampoline didn't stop, status = %d\n", 
45                        status);
46                 return(-EINVAL);
47         }
48
49         return(pid);
50 }
51
52 /*
53  * Overrides for Emacs so that we follow Linus's tabbing style.
54  * Emacs will notice this stuff at the end of the file and automatically
55  * adjust the settings for this buffer only.  This must remain at the end
56  * of the file.
57  * ---------------------------------------------------------------------------
58  * Local variables:
59  * c-file-style: "linux"
60  * End:
61  */