| 110 | } |
| 111 | |
| 112 | __attribute__((constructor)) static void duckgres_crashhandler_install(void) { |
| 113 | struct sigaction sa; |
| 114 | memset(&sa, 0, sizeof(sa)); |
| 115 | sa.sa_sigaction = duckgres_crash_handler; |
| 116 | // SA_ONSTACK: the Go runtime forwards signals while running on the |
| 117 | // per-thread alternate signal stack; the handler must be willing to run |
| 118 | // there. |
| 119 | sa.sa_flags = SA_SIGINFO | SA_ONSTACK; |
| 120 | sigemptyset(&sa.sa_mask); |
| 121 | |
| 122 | const int sigs[] = {SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT}; |
| 123 | for (size_t i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++) { |
| 124 | sigaction(sigs[i], &sa, NULL); |
| 125 | } |
| 126 | g_installed = true; |
| 127 | } |
| 128 | |
| 129 | bool duckgres_crashhandler_installed(void) { return g_installed; } |