Allow third party sigsegv handler

For example from sanitizers.
This commit is contained in:
Christian Göttsche 2020-09-10 00:17:59 +02:00 committed by cgzones
parent 00665e2a2b
commit 5d4061732f
3 changed files with 13 additions and 2 deletions

8
CRT.c
View File

@ -552,6 +552,8 @@ void CRT_restorePrivileges() {
// TODO: pass an instance of Settings instead. // TODO: pass an instance of Settings instead.
struct sigaction old_sigsegv_handler;
void CRT_init(int delay, int colorScheme, bool allowUnicode) { void CRT_init(int delay, int colorScheme, bool allowUnicode) {
initscr(); initscr();
noecho(); noecho();
@ -605,7 +607,11 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) {
} }
} }
#ifndef DEBUG #ifndef DEBUG
signal(11, CRT_handleSIGSEGV); struct sigaction act;
sigemptyset (&act.sa_mask);
act.sa_flags = (int)SA_RESETHAND;
act.sa_handler = CRT_handleSIGSEGV;
sigaction (SIGSEGV, &act, &old_sigsegv_handler);
#endif #endif
signal(SIGTERM, CRT_handleSIGTERM); signal(SIGTERM, CRT_handleSIGTERM);
signal(SIGQUIT, CRT_handleSIGTERM); signal(SIGQUIT, CRT_handleSIGTERM);

1
CRT.h
View File

@ -108,6 +108,7 @@ typedef enum ColorElements_ {
void CRT_fatalError(const char* note) __attribute__ ((noreturn)); void CRT_fatalError(const char* note) __attribute__ ((noreturn));
extern struct sigaction old_sigsegv_handler;
void CRT_handleSIGSEGV(int sgn); void CRT_handleSIGSEGV(int sgn);
#define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A'))

View File

@ -7,6 +7,8 @@ in the source distribution for its full text.
#include "config.h" #include "config.h"
#include "CRT.h" #include "CRT.h"
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_EXECINFO_H #ifdef HAVE_EXECINFO_H
@ -32,5 +34,7 @@ void CRT_handleSIGSEGV(int sgn) {
fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!");
fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n");
#endif #endif
abort();
/* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */
sigaction (SIGSEGV, &old_sigsegv_handler, NULL);
} }