vserver 1.9.5.x5
[linux-2.6.git] / arch / um / kernel / trap_user.c
1 /* 
2  * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include <stdlib.h>
7 #include <errno.h>
8 #include <setjmp.h>
9 #include <signal.h>
10 #include <sys/time.h>
11 #include <sys/ptrace.h>
12 #include <sys/wait.h>
13 #include <asm/page.h>
14 #include <asm/unistd.h>
15 #include <asm/ptrace.h>
16 #include "init.h"
17 #include "sysdep/ptrace.h"
18 #include "sigcontext.h"
19 #include "sysdep/sigcontext.h"
20 #include "irq_user.h"
21 #include "signal_user.h"
22 #include "time_user.h"
23 #include "task.h"
24 #include "mode.h"
25 #include "choose-mode.h"
26 #include "kern_util.h"
27 #include "user_util.h"
28 #include "os.h"
29
30 void kill_child_dead(int pid)
31 {
32         kill(pid, SIGKILL);
33         kill(pid, SIGCONT);
34         do {
35                 int n;
36                 CATCH_EINTR(n = waitpid(pid, NULL, 0));
37                 if (n > 0)
38                         kill(pid, SIGCONT);
39                 else
40                         break;
41         } while(1);
42 }
43
44 /* Unlocked - don't care if this is a bit off */
45 int nsegfaults = 0;
46
47 struct {
48         unsigned long address;
49         int is_write;
50         int pid;
51         unsigned long sp;
52         int is_user;
53 } segfault_record[1024];
54
55 void segv_handler(int sig, union uml_pt_regs *regs)
56 {
57         int index, max;
58
59         if(UPT_IS_USER(regs) && !UPT_SEGV_IS_FIXABLE(regs)){
60                 bad_segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), 
61                          UPT_FAULT_WRITE(regs));
62                 return;
63         }
64         max = sizeof(segfault_record)/sizeof(segfault_record[0]);
65         index = next_trap_index(max);
66
67         nsegfaults++;
68         segfault_record[index].address = UPT_FAULT_ADDR(regs);
69         segfault_record[index].pid = os_getpid();
70         segfault_record[index].is_write = UPT_FAULT_WRITE(regs);
71         segfault_record[index].sp = UPT_SP(regs);
72         segfault_record[index].is_user = UPT_IS_USER(regs);
73         segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), UPT_FAULT_WRITE(regs),
74              UPT_IS_USER(regs), regs);
75 }
76
77 void usr2_handler(int sig, union uml_pt_regs *regs)
78 {
79         CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
80 }
81
82 struct signal_info sig_info[] = {
83         [ SIGTRAP ] { .handler          = relay_signal,
84                       .is_irq           = 0 },
85         [ SIGFPE ] { .handler           = relay_signal,
86                      .is_irq            = 0 },
87         [ SIGILL ] { .handler           = relay_signal,
88                      .is_irq            = 0 },
89         [ SIGWINCH ] { .handler         = winch,
90                        .is_irq          = 1 },
91         [ SIGBUS ] { .handler           = bus_handler,
92                      .is_irq            = 0 },
93         [ SIGSEGV] { .handler           = segv_handler,
94                      .is_irq            = 0 },
95         [ SIGIO ] { .handler            = sigio_handler,
96                     .is_irq             = 1 },
97         [ SIGVTALRM ] { .handler        = timer_handler,
98                         .is_irq         = 1 },
99         [ SIGALRM ] { .handler          = timer_handler,
100                       .is_irq           = 1 },
101         [ SIGUSR2 ] { .handler          = usr2_handler,
102                       .is_irq           = 0 },
103 };
104
105 void do_longjmp(void *b, int val)
106 {
107         sigjmp_buf *buf = b;
108
109         siglongjmp(*buf, val);
110 }
111
112 /*
113  * Overrides for Emacs so that we follow Linus's tabbing style.
114  * Emacs will notice this stuff at the end of the file and automatically
115  * adjust the settings for this buffer only.  This must remain at the end
116  * of the file.
117  * ---------------------------------------------------------------------------
118  * Local variables:
119  * c-file-style: "linux"
120  * End:
121  */