Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-drm-fsl-dcu.git] / arch / um / os-Linux / skas / trap.c
1 /*
2  * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
3  * Licensed under the GPL
4  */
5
6 #include <signal.h>
7 #include <errno.h>
8 #include "kern_util.h"
9 #include "as-layout.h"
10 #include "task.h"
11 #include "sigcontext.h"
12 #include "skas.h"
13 #include "ptrace_user.h"
14 #include "sysdep/ptrace.h"
15 #include "sysdep/ptrace_user.h"
16 #include "os.h"
17
18 static union uml_pt_regs ksig_regs[UM_NR_CPUS];
19
20 void sig_handler_common_skas(int sig, void *sc_ptr)
21 {
22         struct sigcontext *sc = sc_ptr;
23         union uml_pt_regs *r;
24         void (*handler)(int, union uml_pt_regs *);
25         int save_user, save_errno = errno;
26
27         /* This is done because to allow SIGSEGV to be delivered inside a SEGV
28          * handler.  This can happen in copy_user, and if SEGV is disabled,
29          * the process will die.
30          * XXX Figure out why this is better than SA_NODEFER
31          */
32         if(sig == SIGSEGV) {
33                 change_sig(SIGSEGV, 1);
34                 /* For segfaults, we want the data from the
35                  * sigcontext.  In this case, we don't want to mangle
36                  * the process registers, so use a static set of
37                  * registers.  For other signals, the process
38                  * registers are OK.
39                  */
40                 r = &ksig_regs[cpu()];
41                 copy_sc(r, sc_ptr);
42         }
43         else r = TASK_REGS(get_current());
44
45         save_user = r->skas.is_user;
46         r->skas.is_user = 0;
47         if ( sig == SIGFPE || sig == SIGSEGV ||
48              sig == SIGBUS || sig == SIGILL ||
49              sig == SIGTRAP ) {
50                 GET_FAULTINFO_FROM_SC(r->skas.faultinfo, sc);
51         }
52
53         change_sig(SIGUSR1, 1);
54
55         handler = sig_info[sig];
56
57         /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
58         if (sig != SIGIO && sig != SIGWINCH &&
59             sig != SIGVTALRM && sig != SIGALRM)
60                 unblock_signals();
61
62         handler(sig, r);
63
64         errno = save_errno;
65         r->skas.is_user = save_user;
66 }