vserver 1.9.3
[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 "frame_user.h"
22 #include "signal_user.h"
23 #include "time_user.h"
24 #include "task.h"
25 #include "mode.h"
26 #include "choose-mode.h"
27 #include "kern_util.h"
28 #include "user_util.h"
29 #include "os.h"
30
31 void kill_child_dead(int pid)
32 {
33         kill(pid, SIGKILL);
34         kill(pid, SIGCONT);
35         do {
36                 int n;
37                 CATCH_EINTR(n = waitpid(pid, NULL, 0));
38                 if (n > 0)
39                         kill(pid, SIGCONT);
40                 else
41                         break;
42         } while(1);
43 }
44
45 /* Unlocked - don't care if this is a bit off */
46 int nsegfaults = 0;
47
48 struct {
49         unsigned long address;
50         int is_write;
51         int pid;
52         unsigned long sp;
53         int is_user;
54 } segfault_record[1024];
55
56 void segv_handler(int sig, union uml_pt_regs *regs)
57 {
58         int index, max;
59
60         if(UPT_IS_USER(regs) && !UPT_SEGV_IS_FIXABLE(regs)){
61                 bad_segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), 
62                          UPT_FAULT_WRITE(regs));
63                 return;
64         }
65         max = sizeof(segfault_record)/sizeof(segfault_record[0]);
66         index = next_trap_index(max);
67
68         nsegfaults++;
69         segfault_record[index].address = UPT_FAULT_ADDR(regs);
70         segfault_record[index].pid = os_getpid();
71         segfault_record[index].is_write = UPT_FAULT_WRITE(regs);
72         segfault_record[index].sp = UPT_SP(regs);
73         segfault_record[index].is_user = UPT_IS_USER(regs);
74         segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), UPT_FAULT_WRITE(regs),
75              UPT_IS_USER(regs), regs);
76 }
77
78 void usr2_handler(int sig, union uml_pt_regs *regs)
79 {
80         CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
81 }
82
83 struct signal_info sig_info[] = {
84         [ SIGTRAP ] { .handler          = relay_signal,
85                       .is_irq           = 0 },
86         [ SIGFPE ] { .handler           = relay_signal,
87                      .is_irq            = 0 },
88         [ SIGILL ] { .handler           = relay_signal,
89                      .is_irq            = 0 },
90         [ SIGWINCH ] { .handler         = winch,
91                        .is_irq          = 1 },
92         [ SIGBUS ] { .handler           = bus_handler,
93                      .is_irq            = 0 },
94         [ SIGSEGV] { .handler           = segv_handler,
95                      .is_irq            = 0 },
96         [ SIGIO ] { .handler            = sigio_handler,
97                     .is_irq             = 1 },
98         [ SIGVTALRM ] { .handler        = timer_handler,
99                         .is_irq         = 1 },
100         [ SIGALRM ] { .handler          = timer_handler,
101                       .is_irq           = 1 },
102         [ SIGUSR2 ] { .handler          = usr2_handler,
103                       .is_irq           = 0 },
104 };
105
106 void sig_handler(int sig, struct sigcontext sc)
107 {
108         CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
109                          sig, &sc);
110 }
111
112 extern int timer_irq_inited;
113
114 void alarm_handler(int sig, struct sigcontext sc)
115 {
116         if(!timer_irq_inited) return;
117
118         if(sig == SIGALRM)
119                 switch_timers(0);
120
121         CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
122                          sig, &sc);
123
124         if(sig == SIGALRM)
125                 switch_timers(1);
126 }
127
128 void do_longjmp(void *b, int val)
129 {
130         sigjmp_buf *buf = b;
131
132         siglongjmp(*buf, val);
133 }
134
135 /*
136  * Overrides for Emacs so that we follow Linus's tabbing style.
137  * Emacs will notice this stuff at the end of the file and automatically
138  * adjust the settings for this buffer only.  This must remain at the end
139  * of the file.
140  * ---------------------------------------------------------------------------
141  * Local variables:
142  * c-file-style: "linux"
143  * End:
144  */