trap.c 1.8 KB
Newer Older
1
/*
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11
 * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com)
 * Licensed under the GPL
 */

#include <signal.h>
#include <errno.h>
#include "user_util.h"
#include "kern_util.h"
#include "task.h"
#include "sigcontext.h"
12 13 14 15
#include "skas.h"
#include "ptrace_user.h"
#include "sysdep/ptrace.h"
#include "sysdep/ptrace_user.h"
16
#include "os.h"
L
Linus Torvalds 已提交
17 18 19 20 21

void sig_handler_common_skas(int sig, void *sc_ptr)
{
	struct sigcontext *sc = sc_ptr;
	struct skas_regs *r;
22
	void (*handler)(int, union uml_pt_regs *);
L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36
	int save_errno = errno;
	int save_user;

	/* This is done because to allow SIGSEGV to be delivered inside a SEGV
	 * handler.  This can happen in copy_user, and if SEGV is disabled,
	 * the process will die.
	 * XXX Figure out why this is better than SA_NODEFER
	 */
	if(sig == SIGSEGV)
		change_sig(SIGSEGV, 1);

	r = &TASK_REGS(get_current())->skas;
	save_user = r->is_user;
	r->is_user = 0;
37 38 39 40 41
        if ( sig == SIGFPE || sig == SIGSEGV ||
             sig == SIGBUS || sig == SIGILL ||
             sig == SIGTRAP ) {
                GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
        }
L
Linus Torvalds 已提交
42 43 44

	change_sig(SIGUSR1, 1);

45 46 47 48 49 50 51 52
	handler = sig_info[sig];

	/* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
	if (sig != SIGIO && sig != SIGWINCH &&
	    sig != SIGVTALRM && sig != SIGALRM)
		unblock_signals();

	handler(sig, (union uml_pt_regs *) r);
L
Linus Torvalds 已提交
53 54 55 56 57

	errno = save_errno;
	r->is_user = save_user;
}

58 59 60
extern int ptrace_faultinfo;

void user_signal(int sig, union uml_pt_regs *regs, int pid)
L
Linus Torvalds 已提交
61
{
62
	void (*handler)(int, union uml_pt_regs *);
63 64
        int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
                    (sig == SIGILL) || (sig == SIGTRAP));
L
Linus Torvalds 已提交
65

66 67
	if (segv)
		get_skas_faultinfo(pid, &regs->skas.faultinfo);
68 69 70

	handler = sig_info[sig];
	handler(sig, (union uml_pt_regs *) regs);
L
Linus Torvalds 已提交
71 72 73

	unblock_signals();
}