genode/base-nova/include/base/sleep.h
Alexander Boettcher 4342d0d234 NOVA: let thread die if SM cap is invalid
Patch prevents following bugs:

* In sleep_forever the thread return from semaphore down if cap is revoked
  during destruction of a thread. This causes an endless loop consuming time
  not available for other threads.
* In lock_helper and cap_sel_alloc the thread return from the lock() method
  even if the semaphore down call failed because of an revoked semaphore.

  This lead to the situation that a thread subject to de-construction returns
  from the lock method, but not holding the lock, entering the critical section
  and modifying state inside the critical section. Another thread in parallel
  already in the critical section or entering the critical section also
  modifies the state. This lead to curious bugs ...
* thread_nova, thread_start, irq_session
  Detect early bugs if the SM is gone unexpectedly where it should never
  happen.
2012-08-09 11:09:42 +02:00

44 lines
915 B
C++

/*
* \brief Lay back and relax
* \author Norman Feske
* \author Alexander Boettcher
* \date 2010-02-01
*/
/*
* Copyright (C) 2010-2012 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.
*/
#ifndef _INCLUDE__BASE__SLEEP_H_
#define _INCLUDE__BASE__SLEEP_H_
/* Genode includes */
#include <base/thread.h>
/* NOVA includes */
#include <nova/syscalls.h>
#include <nova/util.h>
extern int main_thread_running_semaphore();
namespace Genode {
__attribute__((noreturn)) inline void sleep_forever()
{
using namespace Nova;
Thread_base *myself = Thread_base::myself();
addr_t sem = myself ? myself->tid().exc_pt_sel + SM_SEL_EC :
main_thread_running_semaphore();
while (1) {
if (Nova::sm_ctrl(sem, SEMAPHORE_DOWNZERO))
nova_die();
}
}
}
#endif /* _INCLUDE__BASE__SLEEP_H_ */