genode/base-nova/include/nova/util.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

56 lines
1.3 KiB
C++

/*
* \brief Helper code used by core as base framework
* \author Alexander Boettcher
* \date 2012-08-08
*/
/*
* Copyright (C) 2012-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 _NOVA__INCLUDE__UTIL_H_
#define _NOVA__INCLUDE__UTIL_H_
#include <base/printf.h>
#include <base/thread.h>
__attribute__((always_inline))
inline void nova_die(const char * text = 0)
{
/*
* If thread is de-constructed the sessions are already gone.
* Be careful when enabling printf here.
*/
while (1)
asm volatile ("ud2a" : : "a"(text));
}
inline void request_event_portal(Genode::Native_capability cap,
Genode::addr_t exc_base, Genode::addr_t event)
{
using namespace Nova;
Utcb *utcb = (Utcb *)Genode::Thread_base::myself()->utcb();
/* save original receive window */
Crd orig_crd = utcb->crd_rcv;
/* request event-handler portal */
utcb->crd_rcv = Obj_crd(exc_base + event, 0);
utcb->msg[0] = event;
utcb->set_msg_word(1);
uint8_t res = call(cap.local_name());
if (res)
PERR("request of event (%lu) capability selector failed",
event);
/* restore original receive window */
utcb->crd_rcv = orig_crd;
}
#endif /* _NOVA__INCLUDE__UTIL_H_ */