mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 07:38:28 +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/stdint.h>
|
||||||
#include <base/env.h>
|
#include <base/env.h>
|
||||||
|
|
||||||
|
#include <linux_syscalls.h>
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
extern addr_t * __initial_sp;
|
extern addr_t * __initial_sp;
|
||||||
@ -29,6 +31,31 @@ char **lx_environ;
|
|||||||
*/
|
*/
|
||||||
int main_thread_futex_counter __attribute__((aligned(sizeof(addr_t))));
|
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 **
|
** Startup library support **
|
||||||
@ -46,4 +73,9 @@ void prepare_init_main_thread()
|
|||||||
* __initial_sp[3] = environ
|
* __initial_sp[3] = environ
|
||||||
*/
|
*/
|
||||||
lx_environ = (char**)&__initial_sp[3];
|
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);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,11 @@ inline int lx_munmap(void *addr, size_t length)
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
LX_SIGINT = 2, /* used by core to catch Control-C */
|
LX_SIGINT = 2, /* used by core to catch Control-C */
|
||||||
|
LX_SIGILL = 4, /* exception: illegal instruction */
|
||||||
|
LX_SIGBUS = 7, /* exception: bus error, i.e., bad memory access */
|
||||||
|
LX_SIGFPE = 8, /* exception: floating point */
|
||||||
LX_SIGUSR1 = 10, /* used for cancel-blocking mechanism */
|
LX_SIGUSR1 = 10, /* used for cancel-blocking mechanism */
|
||||||
|
LX_SIGSEGV = 11, /* exception: segmentation violation */
|
||||||
LX_SIGCHLD = 17, /* child process changed state, i.e., terminated */
|
LX_SIGCHLD = 17, /* child process changed state, i.e., terminated */
|
||||||
LX_SIGCANCEL = 32, /* accoring to glibc, this equals SIGRTMIN,
|
LX_SIGCANCEL = 32, /* accoring to glibc, this equals SIGRTMIN,
|
||||||
used for killing threads */
|
used for killing threads */
|
||||||
|
Reference in New Issue
Block a user