trap_user.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stdlib.h>
  6. #include <errno.h>
  7. #include <setjmp.h>
  8. #include <signal.h>
  9. #include <sys/time.h>
  10. #include <sys/wait.h>
  11. #include <asm/page.h>
  12. #include <asm/unistd.h>
  13. #include <asm/ptrace.h>
  14. #include "init.h"
  15. #include "sysdep/ptrace.h"
  16. #include "sigcontext.h"
  17. #include "sysdep/sigcontext.h"
  18. #include "irq_user.h"
  19. #include "signal_user.h"
  20. #include "time_user.h"
  21. #include "task.h"
  22. #include "mode.h"
  23. #include "choose-mode.h"
  24. #include "kern_util.h"
  25. #include "user_util.h"
  26. #include "os.h"
  27. void kill_child_dead(int pid)
  28. {
  29. kill(pid, SIGKILL);
  30. kill(pid, SIGCONT);
  31. do {
  32. int n;
  33. CATCH_EINTR(n = waitpid(pid, NULL, 0));
  34. if (n > 0)
  35. kill(pid, SIGCONT);
  36. else
  37. break;
  38. } while(1);
  39. }
  40. /* Unlocked - don't care if this is a bit off */
  41. int nsegfaults = 0;
  42. struct {
  43. unsigned long address;
  44. int is_write;
  45. int pid;
  46. unsigned long sp;
  47. int is_user;
  48. } segfault_record[1024];
  49. void segv_handler(int sig, union uml_pt_regs *regs)
  50. {
  51. int index, max;
  52. if(UPT_IS_USER(regs) && !UPT_SEGV_IS_FIXABLE(regs)){
  53. bad_segv(UPT_FAULT_ADDR(regs), UPT_IP(regs),
  54. UPT_FAULT_WRITE(regs));
  55. return;
  56. }
  57. max = sizeof(segfault_record)/sizeof(segfault_record[0]);
  58. index = next_trap_index(max);
  59. nsegfaults++;
  60. segfault_record[index].address = UPT_FAULT_ADDR(regs);
  61. segfault_record[index].pid = os_getpid();
  62. segfault_record[index].is_write = UPT_FAULT_WRITE(regs);
  63. segfault_record[index].sp = UPT_SP(regs);
  64. segfault_record[index].is_user = UPT_IS_USER(regs);
  65. segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), UPT_FAULT_WRITE(regs),
  66. UPT_IS_USER(regs), regs);
  67. }
  68. void usr2_handler(int sig, union uml_pt_regs *regs)
  69. {
  70. CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
  71. }
  72. struct signal_info sig_info[] = {
  73. [ SIGTRAP ] { .handler = relay_signal,
  74. .is_irq = 0 },
  75. [ SIGFPE ] { .handler = relay_signal,
  76. .is_irq = 0 },
  77. [ SIGILL ] { .handler = relay_signal,
  78. .is_irq = 0 },
  79. [ SIGWINCH ] { .handler = winch,
  80. .is_irq = 1 },
  81. [ SIGBUS ] { .handler = bus_handler,
  82. .is_irq = 0 },
  83. [ SIGSEGV] { .handler = segv_handler,
  84. .is_irq = 0 },
  85. [ SIGIO ] { .handler = sigio_handler,
  86. .is_irq = 1 },
  87. [ SIGVTALRM ] { .handler = timer_handler,
  88. .is_irq = 1 },
  89. [ SIGALRM ] { .handler = timer_handler,
  90. .is_irq = 1 },
  91. [ SIGUSR2 ] { .handler = usr2_handler,
  92. .is_irq = 0 },
  93. };
  94. void do_longjmp(void *b, int val)
  95. {
  96. sigjmp_buf *buf = b;
  97. siglongjmp(*buf, val);
  98. }
  99. /*
  100. * Overrides for Emacs so that we follow Linus's tabbing style.
  101. * Emacs will notice this stuff at the end of the file and automatically
  102. * adjust the settings for this buffer only. This must remain at the end
  103. * of the file.
  104. * ---------------------------------------------------------------------------
  105. * Local variables:
  106. * c-file-style: "linux"
  107. * End:
  108. */