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 "user_util.h"
  11. #include "kern_util.h"
  12. #include "task.h"
  13. #include "tt.h"
  14. #include "os.h"
  15. void sig_handler_common_tt(int sig, void *sc_ptr)
  16. {
  17. struct sigcontext *sc = sc_ptr;
  18. struct tt_regs save_regs, *r;
  19. int save_errno = errno, is_user;
  20. void (*handler)(int, union uml_pt_regs *);
  21. /* This is done because to allow SIGSEGV to be delivered inside a SEGV
  22. * handler. This can happen in copy_user, and if SEGV is disabled,
  23. * the process will die.
  24. */
  25. if(sig == SIGSEGV)
  26. change_sig(SIGSEGV, 1);
  27. r = &TASK_REGS(get_current())->tt;
  28. if ( sig == SIGFPE || sig == SIGSEGV ||
  29. sig == SIGBUS || sig == SIGILL ||
  30. sig == SIGTRAP ) {
  31. GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
  32. }
  33. save_regs = *r;
  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. */