trap.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "user_util.h"
  8. #include "kern_util.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. void sig_handler_common_skas(int sig, void *sc_ptr)
  17. {
  18. struct sigcontext *sc = sc_ptr;
  19. struct skas_regs *r;
  20. void (*handler)(int, union uml_pt_regs *);
  21. int save_errno = errno;
  22. int save_user;
  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. r = &TASK_REGS(get_current())->skas;
  31. save_user = r->is_user;
  32. r->is_user = 0;
  33. if ( sig == SIGFPE || sig == SIGSEGV ||
  34. sig == SIGBUS || sig == SIGILL ||
  35. sig == SIGTRAP ) {
  36. GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
  37. }
  38. change_sig(SIGUSR1, 1);
  39. handler = sig_info[sig];
  40. /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
  41. if (sig != SIGIO && sig != SIGWINCH &&
  42. sig != SIGVTALRM && sig != SIGALRM)
  43. unblock_signals();
  44. handler(sig, (union uml_pt_regs *) r);
  45. errno = save_errno;
  46. r->is_user = save_user;
  47. }
  48. extern int ptrace_faultinfo;
  49. void user_signal(int sig, union uml_pt_regs *regs, int pid)
  50. {
  51. void (*handler)(int, union uml_pt_regs *);
  52. int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
  53. (sig == SIGILL) || (sig == SIGTRAP));
  54. if (segv)
  55. get_skas_faultinfo(pid, &regs->skas.faultinfo);
  56. handler = sig_info[sig];
  57. handler(sig, (union uml_pt_regs *) regs);
  58. unblock_signals();
  59. }