trap.c 1.6 KB

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