genode/repos/base/src/lib/base/thread_start.cc
Alexander Boettcher 027e89f91a base: catch uncaught exceptions of threads
and show some message about. On sel4 sometimes exceptions are thrown and no
message is shown, it just seems to hang. With this patch at least you get
an idea that something bad happened.

Issue #2044
2016-08-10 11:07:50 +02:00

90 lines
1.9 KiB
C++

/*
* \brief Implementation of the Thread API
* \author Norman Feske
* \date 2010-01-19
*/
/*
* Copyright (C) 2010-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/thread.h>
#include <base/log.h>
#include <base/sleep.h>
#include <base/env.h>
#include <cpu_thread/client.h>
/* base-internal includes */
#include <base/internal/stack.h>
using namespace Genode;
/**
* Entry point entered by new threads
*/
void Thread::_thread_start()
{
Thread::myself()->_thread_bootstrap();
/* catch any exception at this point and try to print an error message */
try {
Thread::myself()->entry();
} catch (...) {
try {
raw("Thread '", Thread::myself()->name().string(),
"' died because of an uncaught exception");
} catch (...) {
/* die in a noisy way */
*(unsigned long *)0 = 0xdead;
}
throw;
}
Thread::myself()->_join_lock.unlock();
/* sleep silently */
Genode::sleep_forever();
}
/************
** Thread **
************/
void Thread::_deinit_platform_thread()
{
if (!_cpu_session)
_cpu_session = env()->cpu_session();
_cpu_session->kill_thread(_thread_cap);
}
void Thread::start()
{
/* if no CPU session is given, use it from the environment */
if (!_cpu_session)
_cpu_session = env()->cpu_session();
/* create thread at core */
addr_t const utcb = (addr_t)&_stack->utcb();
_thread_cap = _cpu_session->create_thread(env()->pd_session_cap(), name(),
_affinity, Weight(), utcb);
if (!_thread_cap.valid())
throw Cpu_session::Thread_creation_failed();
/* start execution at initial instruction pointer and stack pointer */
Cpu_thread_client(_thread_cap).start((addr_t)_thread_start, _stack->top());
}
void Thread::cancel_blocking()
{
Cpu_thread_client(_thread_cap).cancel_blocking();
}