ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 <fcntl.h>
9 #include <setjmp.h>
10 #include <signal.h>
11 #include <sys/time.h>
12 #include <sys/ioctl.h>
13 #include <sys/ptrace.h>
14 #include <sys/wait.h>
15 #include <asm/page.h>
16 #include <asm/unistd.h>
17 #include <asm/ptrace.h>
18 #include "init.h"
19 #include "sysdep/ptrace.h"
20 #include "sigcontext.h"
21 #include "sysdep/sigcontext.h"
22 #include "irq_user.h"
23 #include "frame_user.h"
24 #include "signal_user.h"
25 #include "time_user.h"
26 #include "task.h"
27 #include "mode.h"
28 #include "choose-mode.h"
29 #include "kern_util.h"
30 #include "user_util.h"
31 #include "os.h"
32
33 void kill_child_dead(int pid)
34 {
35         kill(pid, SIGKILL);
36         kill(pid, SIGCONT);
37         while(waitpid(pid, NULL, 0) > 0) kill(pid, SIGCONT);
38 }
39
40 /* Unlocked - don't care if this is a bit off */
41 int nsegfaults = 0;
42
43 struct {
44         unsigned long address;
45         int is_write;
46         int pid;
47         unsigned long sp;
48         int is_user;
49 } segfault_record[1024];
50
51 void segv_handler(int sig, union uml_pt_regs *regs)
52 {
53         int index, max;
54
55         if(UPT_IS_USER(regs) && !UPT_SEGV_IS_FIXABLE(regs)){
56                 bad_segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), 
57                          UPT_FAULT_WRITE(regs));
58                 return;
59         }
60         max = sizeof(segfault_record)/sizeof(segfault_record[0]);
61         index = next_trap_index(max);
62
63         nsegfaults++;
64         segfault_record[index].address = UPT_FAULT_ADDR(regs);
65         segfault_record[index].pid = os_getpid();
66         segfault_record[index].is_write = UPT_FAULT_WRITE(regs);
67         segfault_record[index].sp = UPT_SP(regs);
68         segfault_record[index].is_user = UPT_IS_USER(regs);
69         segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), UPT_FAULT_WRITE(regs),
70              UPT_IS_USER(regs), regs);
71 }
72
73 void usr2_handler(int sig, union uml_pt_regs *regs)
74 {
75         CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
76 }
77
78 struct signal_info sig_info[] = {
79         [ SIGTRAP ] { .handler          = relay_signal,
80                       .is_irq           = 0 },
81         [ SIGFPE ] { .handler           = relay_signal,
82                      .is_irq            = 0 },
83         [ SIGILL ] { .handler           = relay_signal,
84                      .is_irq            = 0 },
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, missed_ticks[];
106
107 void alarm_handler(int sig, struct sigcontext sc)
108 {
109         if(!timer_irq_inited) return;
110         missed_ticks[cpu()]++;
111
112         if(sig == SIGALRM)
113                 switch_timers(0);
114
115         CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
116                          sig, &sc);
117
118         if(sig == SIGALRM)
119                 switch_timers(1);
120 }
121
122 void do_longjmp(void *b, int val)
123 {
124         jmp_buf *buf = b;
125
126         longjmp(*buf, val);
127 }
128
129 /*
130  * Overrides for Emacs so that we follow Linus's tabbing style.
131  * Emacs will notice this stuff at the end of the file and automatically
132  * adjust the settings for this buffer only.  This must remain at the end
133  * of the file.
134  * ---------------------------------------------------------------------------
135  * Local variables:
136  * c-file-style: "linux"
137  * End:
138  */