trap.c 1.7 KB
Newer Older
1
/*
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9
 * 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"
J
Jeff Dike 已提交
10
#include "as-layout.h"
L
Linus Torvalds 已提交
11 12
#include "task.h"
#include "sigcontext.h"
13 14 15 16
#include "skas.h"
#include "ptrace_user.h"
#include "sysdep/ptrace.h"
#include "sysdep/ptrace_user.h"
17
#include "os.h"
L
Linus Torvalds 已提交
18 19 20 21 22

void sig_handler_common_skas(int sig, void *sc_ptr)
{
	struct sigcontext *sc = sc_ptr;
	struct skas_regs *r;
23
	void (*handler)(int, union uml_pt_regs *);
L
Linus Torvalds 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37
	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;
J
Jeff Dike 已提交
38 39 40 41 42
	if ( sig == SIGFPE || sig == SIGSEGV ||
	     sig == SIGBUS || sig == SIGILL ||
	     sig == SIGTRAP ) {
		GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
	}
L
Linus Torvalds 已提交
43 44 45

	change_sig(SIGUSR1, 1);

46 47 48 49 50 51 52 53
	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 已提交
54 55 56 57 58

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

59 60 61
extern int ptrace_faultinfo;

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

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

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

	unblock_signals();
}