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