trap_user.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stdlib.h>
  6. #include <errno.h>
  7. #include <signal.h>
  8. #include "sysdep/ptrace.h"
  9. #include "sysdep/sigcontext.h"
  10. #include "kern_util.h"
  11. #include "task.h"
  12. #include "tt.h"
  13. #include "os.h"
  14. void sig_handler_common_tt(int sig, void *sc_ptr)
  15. {
  16. struct sigcontext *sc = sc_ptr;
  17. struct tt_regs save_regs, *r;
  18. int save_errno = errno, is_user = 0;
  19. void (*handler)(int, union uml_pt_regs *);
  20. /* This is done because to allow SIGSEGV to be delivered inside a SEGV
  21. * handler. This can happen in copy_user, and if SEGV is disabled,
  22. * the process will die.
  23. */
  24. if(sig == SIGSEGV)
  25. change_sig(SIGSEGV, 1);
  26. r = &TASK_REGS(get_current())->tt;
  27. if ( sig == SIGFPE || sig == SIGSEGV ||
  28. sig == SIGBUS || sig == SIGILL ||
  29. sig == SIGTRAP ) {
  30. GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
  31. }
  32. save_regs = *r;
  33. if (sc)
  34. is_user = user_context(SC_SP(sc));
  35. r->sc = sc;
  36. if(sig != SIGUSR2)
  37. r->syscall = -1;
  38. handler = sig_info[sig];
  39. /* unblock SIGALRM, SIGVTALRM, SIGIO if sig isn't IRQ signal */
  40. if (sig != SIGIO && sig != SIGWINCH &&
  41. sig != SIGVTALRM && sig != SIGALRM)
  42. unblock_signals();
  43. handler(sig, (union uml_pt_regs *) r);
  44. if(is_user){
  45. interrupt_end();
  46. block_signals();
  47. set_user_mode(NULL);
  48. }
  49. *r = save_regs;
  50. errno = save_errno;
  51. }
  52. /*
  53. * Overrides for Emacs so that we follow Linus's tabbing style.
  54. * Emacs will notice this stuff at the end of the file and automatically
  55. * adjust the settings for this buffer only. This must remain at the end
  56. * of the file.
  57. * ---------------------------------------------------------------------------
  58. * Local variables:
  59. * c-file-style: "linux"
  60. * End:
  61. */