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