[PATCH] uml: Fix process exit race
[linux-2.6] / arch / um / kernel / tt / exec_kern.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/kernel.h"
7 #include "linux/mm.h"
8 #include "asm/signal.h"
9 #include "asm/ptrace.h"
10 #include "asm/uaccess.h"
11 #include "asm/pgalloc.h"
12 #include "asm/tlbflush.h"
13 #include "user_util.h"
14 #include "kern_util.h"
15 #include "irq_user.h"
16 #include "time_user.h"
17 #include "signal_user.h"
18 #include "mem_user.h"
19 #include "os.h"
20 #include "tlb.h"
21 #include "mode.h"
22
23 static int exec_tramp(void *sig_stack)
24 {
25         init_new_thread_stack(sig_stack, NULL);
26         init_new_thread_signals(1);
27         os_stop_process(os_getpid());
28         return(0);
29 }
30
31 void flush_thread_tt(void)
32 {
33         unsigned long stack;
34         int new_pid;
35
36         stack = alloc_stack(0, 0);
37         if(stack == 0){
38                 printk(KERN_ERR 
39                        "flush_thread : failed to allocate temporary stack\n");
40                 do_exit(SIGKILL);
41         }
42                 
43         new_pid = start_fork_tramp(current->thread_info, stack, 0, exec_tramp);
44         if(new_pid < 0){
45                 printk(KERN_ERR 
46                        "flush_thread : new thread failed, errno = %d\n",
47                        -new_pid);
48                 do_exit(SIGKILL);
49         }
50
51         if(current_thread->cpu == 0)
52                 forward_interrupts(new_pid);
53         current->thread.request.op = OP_EXEC;
54         current->thread.request.u.exec.pid = new_pid;
55         unprotect_stack((unsigned long) current_thread);
56         os_usr1_process(os_getpid());
57         change_sig(SIGUSR1, 1);
58
59         change_sig(SIGUSR1, 0);
60         enable_timer();
61         free_page(stack);
62         protect_memory(uml_reserved, high_physmem - uml_reserved, 1, 1, 0, 1);
63         task_protections((unsigned long) current_thread);
64         force_flush_all();
65         unblock_signals();
66 }
67
68 void start_thread_tt(struct pt_regs *regs, unsigned long eip, 
69                      unsigned long esp)
70 {
71         set_fs(USER_DS);
72         flush_tlb_mm(current->mm);
73         PT_REGS_IP(regs) = eip;
74         PT_REGS_SP(regs) = esp;
75         PT_FIX_EXEC_STACK(esp);
76 }
77
78 /*
79  * Overrides for Emacs so that we follow Linus's tabbing style.
80  * Emacs will notice this stuff at the end of the file and automatically
81  * adjust the settings for this buffer only.  This must remain at the end
82  * of the file.
83  * ---------------------------------------------------------------------------
84  * Local variables:
85  * c-file-style: "linux"
86  * End:
87  */