genode/ports/src/app/gdb_monitor/signal_handler_thread.cc
Christian Prochaska a6acab6d0d Synchronize signal context destruction
With this patch, the 'Signal_receiver::dissolve()' function does not return
as long as the signal context to be dissolved is still referenced by one
or more 'Signal' objects. This is supposed to delay the destruction of the
signal context while it is still in use.

Fixes #594.
2013-01-15 15:03:21 +01:00

60 lines
1.1 KiB
C++

/*
* \brief Signal handler thread implementation
* \author Christian Prochaska
* \date 2011-08-15
*/
/*
* Copyright (C) 2011-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/sleep.h>
/* libc includes */
#include <unistd.h>
/* GDB monitor includes */
#include "thread_info.h"
#include "signal_handler_thread.h"
using namespace Genode;
using namespace Gdb_monitor;
static bool const verbose = false;
Signal_handler_thread::Signal_handler_thread(Signal_receiver *receiver)
:
Thread<2*4096>("sig_handler"),
_signal_receiver(receiver)
{
if (pipe(_pipefd))
PERR("could not create pipe");
}
void Signal_handler_thread::entry()
{
while(1) {
Signal s = _signal_receiver->wait_for_signal();
if (verbose)
PDBG("received exception signal");
/* default is segmentation fault */
unsigned long sig = 0;
if (Thread_info *thread_info = dynamic_cast<Thread_info*>(s.context()))
/* thread trapped */
sig = thread_info->lwpid();
write(_pipefd[1], &sig, sizeof(sig));
}
sleep_forever();
};