Add sigaltstack support to Unix crashlog

This commit is contained in:
Jonathan G Rennison 2019-04-23 18:41:20 +01:00
parent 61a4ecf078
commit 145fee04fa
2 changed files with 35 additions and 1 deletions

View File

@ -1807,6 +1807,29 @@ EOL
log 1 "checking ucontext... found"
CFLAGS="$CFLAGS -DWITH_UCONTEXT"
fi
log 2 "executing $cc_host $CFLAGS $CFLAGS_ENV $LDFLAGS $LDFLAGS_ENV $STATIC_FLAGS -o tmp.config.sigaltstack -x c++ - -ldl"
"$cc_host" $CFLAGS $CFLAGS_ENV $LDFLAGS $LDFLAGS_ENV $STATIC_FLAGS -o tmp.config.sigaltstack -x c++ - -ldl 2> /dev/null << EOL
#include <signal.h>
#include <stdlib.h>
int main() {
stack_t ss;
ss.ss_sp = calloc(SIGSTKSZ, 1);
ss.ss_size = SIGSTKSZ;
ss.ss_flags = 0;
sigaltstack(&ss, nullptr);
return 0;
}
EOL
ret=$?
rm -f tmp.config.sigaltstack
log 2 " exit code $ret"
if [ $ret -ne 0 ]; then
log 1 "checking sigaltstack... no"
else
log 1 "checking sigaltstack... found"
CFLAGS="$CFLAGS -DWITH_SIGALTSTACK"
fi
fi
if [ "$os" = "MINGW" ]; then

View File

@ -341,7 +341,7 @@ class CrashLogUnix : public CrashLog {
args.push_back("-ex");
args.push_back("echo \\nBacktrace:\\n");
args.push_back("-ex");
args.push_back("bt full");
args.push_back("bt full 100");
#ifdef WITH_SIGACTION
if (this->GetMessage() == NULL && this->signal_instruction_ptr_valid) {
@ -584,11 +584,22 @@ static void CDECL HandleCrash(int signum)
/* static */ void CrashLog::InitialiseCrashLog()
{
#ifdef WITH_SIGALTSTACK
const size_t stack_size = max<size_t>(SIGSTKSZ, 512*1024);
stack_t ss;
ss.ss_sp = CallocT<byte>(stack_size);
ss.ss_size = stack_size;
ss.ss_flags = 0;
sigaltstack(&ss, nullptr);
#endif
for (const int *i = _signals_to_handle; i != endof(_signals_to_handle); i++) {
#ifdef WITH_SIGACTION
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_SIGINFO | SA_RESTART;
#ifdef WITH_SIGALTSTACK
sa.sa_flags |= SA_ONSTACK;
#endif
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = HandleCrash;
sigaction(*i, &sa, NULL);