mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-18 23:28:29 +00:00
linux: log diagnostic message on exceptions
Log the fact that a software exception will terminate the process and hint about more information available from the Linux kernel log. Fixes #1457
This commit is contained in:
@ -15,6 +15,8 @@
|
||||
#include <base/stdint.h>
|
||||
#include <base/env.h>
|
||||
|
||||
#include <linux_syscalls.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
extern addr_t * __initial_sp;
|
||||
@ -29,6 +31,31 @@ char **lx_environ;
|
||||
*/
|
||||
int main_thread_futex_counter __attribute__((aligned(sizeof(addr_t))));
|
||||
|
||||
/**
|
||||
* Signal handler for exceptions like segmentation faults
|
||||
*/
|
||||
static void exception_signal_handler(int signum)
|
||||
{
|
||||
char const *reason = nullptr;
|
||||
|
||||
switch (signum) {
|
||||
case LX_SIGILL: reason = "Illegal instruction"; break;
|
||||
case LX_SIGBUS: reason = "Bad memory access"; break;
|
||||
case LX_SIGFPE: reason = "Floating point exception"; break;
|
||||
case LX_SIGSEGV: reason = "Segmentation fault"; break;
|
||||
|
||||
default: /* unexpected signal */ return;
|
||||
}
|
||||
PERR("%s (signum=%d), see Linux kernel log for details", reason, signum);
|
||||
|
||||
/*
|
||||
* We reset the signal handler to SIG_DFL and trigger exception again,
|
||||
* i.e., terminate the process.
|
||||
*/
|
||||
lx_sigaction(signum, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*****************************
|
||||
** Startup library support **
|
||||
@ -46,4 +73,9 @@ void prepare_init_main_thread()
|
||||
* __initial_sp[3] = environ
|
||||
*/
|
||||
lx_environ = (char**)&__initial_sp[3];
|
||||
|
||||
lx_sigaction(LX_SIGILL, exception_signal_handler);
|
||||
lx_sigaction(LX_SIGBUS, exception_signal_handler);
|
||||
lx_sigaction(LX_SIGFPE, exception_signal_handler);
|
||||
lx_sigaction(LX_SIGSEGV, exception_signal_handler);
|
||||
}
|
||||
|
Reference in New Issue
Block a user