segv_handler.cpp 765 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <util/system/platform.h>
  2. #include <util/system/yassert.h>
  3. #include <util/stream/output.h>
  4. #include <util/system/backtrace.h>
  5. #ifdef _unix_
  6. #include <signal.h>
  7. #include <errno.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #endif
  11. #include "segv_handler.h"
  12. #ifndef _win_
  13. static void SegvHandler(int sig) {
  14. Y_UNUSED(sig);
  15. const char msg[] = "Got SEGV\n";
  16. Y_UNUSED(write(STDERR_FILENO, msg, sizeof(msg)));
  17. //PrintBackTrace();
  18. sig_t r = signal(SIGSEGV, SIG_DFL);
  19. if (r == SIG_ERR) {
  20. abort();
  21. }
  22. // returning back and failing
  23. }
  24. #endif // !_win_
  25. void InstallSegvHandler() {
  26. #ifndef _win_
  27. sig_t r = signal(SIGSEGV, &SegvHandler);
  28. Y_ABORT_UNLESS(r != SIG_ERR, "signal failed: %s", strerror(errno));
  29. #endif // !_win_
  30. }