| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/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" | 
|  | 28 |  | 
|  | 29 | void kill_child_dead(int pid) | 
|  | 30 | { | 
|  | 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); | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | /* Unlocked - don't care if this is a bit off */ | 
|  | 44 | int nsegfaults = 0; | 
|  | 45 |  | 
|  | 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]; | 
|  | 53 |  | 
|  | 54 | void segv_handler(int sig, union uml_pt_regs *regs) | 
|  | 55 | { | 
|  | 56 | int index, max; | 
| Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 57 | struct faultinfo * fi = UPT_FAULTINFO(regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
| Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 59 | if(UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)){ | 
|  | 60 | bad_segv(*fi, UPT_IP(regs)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | return; | 
|  | 62 | } | 
|  | 63 | max = sizeof(segfault_record)/sizeof(segfault_record[0]); | 
|  | 64 | index = next_trap_index(max); | 
|  | 65 |  | 
|  | 66 | nsegfaults++; | 
| Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 67 | segfault_record[index].address = FAULT_ADDRESS(*fi); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | segfault_record[index].pid = os_getpid(); | 
| Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 69 | segfault_record[index].is_write = FAULT_WRITE(*fi); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | segfault_record[index].sp = UPT_SP(regs); | 
|  | 71 | segfault_record[index].is_user = UPT_IS_USER(regs); | 
| Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 72 | segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
|  | 75 | void usr2_handler(int sig, union uml_pt_regs *regs) | 
|  | 76 | { | 
|  | 77 | CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0); | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | struct signal_info sig_info[] = { | 
|  | 81 | [ SIGTRAP ] { .handler 		= relay_signal, | 
|  | 82 | .is_irq 		= 0 }, | 
|  | 83 | [ SIGFPE ] { .handler 		= relay_signal, | 
|  | 84 | .is_irq 		= 0 }, | 
|  | 85 | [ SIGILL ] { .handler 		= relay_signal, | 
|  | 86 | .is_irq 		= 0 }, | 
|  | 87 | [ SIGWINCH ] { .handler		= winch, | 
|  | 88 | .is_irq		= 1 }, | 
|  | 89 | [ SIGBUS ] { .handler 		= bus_handler, | 
|  | 90 | .is_irq 		= 0 }, | 
|  | 91 | [ SIGSEGV] { .handler 		= segv_handler, | 
|  | 92 | .is_irq 		= 0 }, | 
|  | 93 | [ SIGIO ] { .handler 		= sigio_handler, | 
|  | 94 | .is_irq 		= 1 }, | 
|  | 95 | [ SIGVTALRM ] { .handler 	= timer_handler, | 
|  | 96 | .is_irq 	= 1 }, | 
|  | 97 | [ SIGALRM ] { .handler          = timer_handler, | 
|  | 98 | .is_irq           = 1 }, | 
|  | 99 | [ SIGUSR2 ] { .handler 		= usr2_handler, | 
|  | 100 | .is_irq 		= 0 }, | 
|  | 101 | }; | 
|  | 102 |  | 
|  | 103 | void do_longjmp(void *b, int val) | 
|  | 104 | { | 
|  | 105 | sigjmp_buf *buf = b; | 
|  | 106 |  | 
|  | 107 | siglongjmp(*buf, val); | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | /* | 
|  | 111 | * Overrides for Emacs so that we follow Linus's tabbing style. | 
|  | 112 | * Emacs will notice this stuff at the end of the file and automatically | 
|  | 113 | * adjust the settings for this buffer only.  This must remain at the end | 
|  | 114 | * of the file. | 
|  | 115 | * --------------------------------------------------------------------------- | 
|  | 116 | * Local variables: | 
|  | 117 | * c-file-style: "linux" | 
|  | 118 | * End: | 
|  | 119 | */ |