From 79509b76a656db25c098cb7fa2107fec2e68cc8b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 14 Aug 2023 11:23:48 +0100 Subject: [PATCH] Crashlog: Unix: Decode REG_ERR for SIGSEGV --- src/os/unix/crashlog_unix.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/os/unix/crashlog_unix.cpp b/src/os/unix/crashlog_unix.cpp index ea63357c71..17f9f5dabf 100644 --- a/src/os/unix/crashlog_unix.cpp +++ b/src/os/unix/crashlog_unix.cpp @@ -337,8 +337,23 @@ class CrashLogUnix : public CrashLog { this->signal_instruction_ptr); } } + +#if defined(WITH_UCONTEXT) && (defined(__x86_64__) || defined(__i386)) + if (this->signal_instruction_ptr_valid && this->signum == SIGSEGV) { + auto err = static_cast(this->context)->uc_mcontext.gregs[REG_ERR]; + buffer += seprintf(buffer, last, + " REG_ERR: %s%s%s%s%s\n", + (err & 1) ? "protection fault" : "no page", + (err & 2) ? ", write" : ", read", + (err & 4) ? "" : ", kernel", + (err & 8) ? ", reserved bit" : "", + (err & 16) ? ", instruction fetch" : "" + ); + } +#endif /* defined(WITH_UCONTEXT) && (defined(__x86_64__) || defined(__i386)) */ + } -#endif +#endif /* WITH_SIGACTION */ this->CrashLogFaultSectionCheckpoint(buffer); buffer += seprintf(buffer, last, " Message: %s\n\n",