uml: create as-layout.h
[powerpc.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 "user_util.h"
9 #include "kern_util.h"
10 #include "as-layout.h"
11 #include "task.h"
12 #include "sigcontext.h"
13 #include "skas.h"
14 #include "ptrace_user.h"
15 #include "sysdep/ptrace.h"
16 #include "sysdep/ptrace_user.h"
17 #include "os.h"
18
19 void sig_handler_common_skas(int sig, void *sc_ptr)
20 {
21         struct sigcontext *sc = sc_ptr;
22         struct skas_regs *r;
23         void (*handler)(int, union uml_pt_regs *);
24         int save_errno = errno;
25         int save_user;
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
35         r = &TASK_REGS(get_current())->skas;
36         save_user = r->is_user;
37         r->is_user = 0;
38         if ( sig == SIGFPE || sig == SIGSEGV ||
39              sig == SIGBUS || sig == SIGILL ||
40              sig == SIGTRAP ) {
41                 GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
42         }
43
44         change_sig(SIGUSR1, 1);
45
46         handler = sig_info[sig];
47
48         /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
49         if (sig != SIGIO && sig != SIGWINCH &&
50             sig != SIGVTALRM && sig != SIGALRM)
51                 unblock_signals();
52
53         handler(sig, (union uml_pt_regs *) r);
54
55         errno = save_errno;
56         r->is_user = save_user;
57 }
58
59 extern int ptrace_faultinfo;
60
61 void user_signal(int sig, union uml_pt_regs *regs, int pid)
62 {
63         void (*handler)(int, union uml_pt_regs *);
64         int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
65                     (sig == SIGILL) || (sig == SIGTRAP));
66
67         if (segv)
68                 get_skas_faultinfo(pid, &regs->skas.faultinfo);
69
70         handler = sig_info[sig];
71         handler(sig, (union uml_pt_regs *) regs);
72
73         unblock_signals();
74 }