trap_user.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. struct faultinfo * fi = UPT_FAULTINFO(regs);
  53. if(UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)){
  54. bad_segv(*fi, UPT_IP(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 = FAULT_ADDRESS(*fi);
  61. segfault_record[index].pid = os_getpid();
  62. segfault_record[index].is_write = FAULT_WRITE(*fi);
  63. segfault_record[index].sp = UPT_SP(regs);
  64. segfault_record[index].is_user = UPT_IS_USER(regs);
  65. segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs);
  66. }
  67. void usr2_handler(int sig, union uml_pt_regs *regs)
  68. {
  69. CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
  70. }
  71. struct signal_info sig_info[] = {
  72. [ SIGTRAP ] { .handler = relay_signal,
  73. .is_irq = 0 },
  74. [ SIGFPE ] { .handler = relay_signal,
  75. .is_irq = 0 },
  76. [ SIGILL ] { .handler = relay_signal,
  77. .is_irq = 0 },
  78. [ SIGWINCH ] { .handler = winch,
  79. .is_irq = 1 },
  80. [ SIGBUS ] { .handler = bus_handler,
  81. .is_irq = 0 },
  82. [ SIGSEGV] { .handler = segv_handler,
  83. .is_irq = 0 },
  84. [ SIGIO ] { .handler = sigio_handler,
  85. .is_irq = 1 },
  86. [ SIGVTALRM ] { .handler = timer_handler,
  87. .is_irq = 1 },
  88. [ SIGALRM ] { .handler = timer_handler,
  89. .is_irq = 1 },
  90. [ SIGUSR2 ] { .handler = usr2_handler,
  91. .is_irq = 0 },
  92. };
  93. void do_longjmp(void *b, int val)
  94. {
  95. sigjmp_buf *buf = b;
  96. siglongjmp(*buf, val);
  97. }
  98. /*
  99. * Overrides for Emacs so that we follow Linus's tabbing style.
  100. * Emacs will notice this stuff at the end of the file and automatically
  101. * adjust the settings for this buffer only. This must remain at the end
  102. * of the file.
  103. * ---------------------------------------------------------------------------
  104. * Local variables:
  105. * c-file-style: "linux"
  106. * End:
  107. */