trap.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "as-layout.h"
  10. #include "task.h"
  11. #include "sigcontext.h"
  12. #include "skas.h"
  13. #include "ptrace_user.h"
  14. #include "sysdep/ptrace.h"
  15. #include "sysdep/ptrace_user.h"
  16. #include "os.h"
  17. void sig_handler_common_skas(int sig, void *sc_ptr)
  18. {
  19. struct sigcontext *sc = sc_ptr;
  20. struct skas_regs *r;
  21. void (*handler)(int, union uml_pt_regs *);
  22. int save_errno = errno;
  23. int save_user;
  24. /* This is done because to allow SIGSEGV to be delivered inside a SEGV
  25. * handler. This can happen in copy_user, and if SEGV is disabled,
  26. * the process will die.
  27. * XXX Figure out why this is better than SA_NODEFER
  28. */
  29. if(sig == SIGSEGV)
  30. change_sig(SIGSEGV, 1);
  31. r = &TASK_REGS(get_current())->skas;
  32. save_user = r->is_user;
  33. r->is_user = 0;
  34. if ( sig == SIGFPE || sig == SIGSEGV ||
  35. sig == SIGBUS || sig == SIGILL ||
  36. sig == SIGTRAP ) {
  37. GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
  38. }
  39. change_sig(SIGUSR1, 1);
  40. handler = sig_info[sig];
  41. /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
  42. if (sig != SIGIO && sig != SIGWINCH &&
  43. sig != SIGVTALRM && sig != SIGALRM)
  44. unblock_signals();
  45. handler(sig, (union uml_pt_regs *) r);
  46. errno = save_errno;
  47. r->is_user = save_user;
  48. }
  49. extern int ptrace_faultinfo;
  50. void user_signal(int sig, union uml_pt_regs *regs, int pid)
  51. {
  52. void (*handler)(int, union uml_pt_regs *);
  53. int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
  54. (sig == SIGILL) || (sig == SIGTRAP));
  55. if (segv)
  56. get_skas_faultinfo(pid, &regs->skas.faultinfo);
  57. handler = sig_info[sig];
  58. handler(sig, (union uml_pt_regs *) regs);
  59. unblock_signals();
  60. }