aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/terminate_handler/segv_handler.cpp
blob: 732e8021599b733507c76c085a2b13b9238fb245 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <util/system/platform.h>
#include <util/system/yassert.h>
#include <util/stream/output.h>
#include <util/system/backtrace.h>

#ifdef _unix_
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#endif

#include "segv_handler.h"

#ifndef _win_
static void SegvHandler(int sig) {
    Y_UNUSED(sig);
    const char msg[] = "Got SEGV\n";
    Y_UNUSED(write(STDERR_FILENO, msg, sizeof(msg)));
    //PrintBackTrace();
    sig_t r = signal(SIGSEGV, SIG_DFL);
    if (r == SIG_ERR) {
        abort();
    }
    // returning back and failing
}
#endif // !_win_

void InstallSegvHandler() {
#ifndef _win_
    sig_t r = signal(SIGSEGV, &SegvHandler);
    Y_ABORT_UNLESS(r != SIG_ERR, "signal failed: %s", strerror(errno));
#endif // !_win_
}