trap_user.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = 0;
  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. if (sc)
  35. is_user = user_context(SC_SP(sc));
  36. r->sc = sc;
  37. if(sig != SIGUSR2)
  38. r->syscall = -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. if(is_user){
  46. interrupt_end();
  47. block_signals();
  48. set_user_mode(NULL);
  49. }
  50. *r = save_regs;
  51. errno = save_errno;
  52. }
  53. /*
  54. * Overrides for Emacs so that we follow Linus's tabbing style.
  55. * Emacs will notice this stuff at the end of the file and automatically
  56. * adjust the settings for this buffer only. This must remain at the end
  57. * of the file.
  58. * ---------------------------------------------------------------------------
  59. * Local variables:
  60. * c-file-style: "linux"
  61. * End:
  62. */