Permalink
Browse files

Fiasco.OC: prevent first exception in ldso apps

In applications that use ldso the main_thread_bootstrap() function is called
twice which results in the main thread's gate-capability to be inserted twice
in the Capability_map which results in an exception. Unfortunately at least
on ARM this exception cannot be handled that early, so this commit prevents
the exception by checking, whether the capability is inserted already or not.
Fixes #164.
  • Loading branch information...
1 parent 9a9f49b commit 76c106dac07ef9b3458b9e7a5d6c0677b0dbeb16 @skalk skalk committed with nfeske Mar 26, 2012
Showing with 13 additions and 4 deletions.
  1. +13 −4 base-foc/src/platform/_main_helper.h
@@ -21,15 +21,24 @@
namespace Fiasco {
#include <l4/sys/utcb.h>
-#include <l4/sys/kdebug.h>
}
enum { MAIN_THREAD_CAP_ID = 1 };
static void main_thread_bootstrap() {
- Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_BADGE] = MAIN_THREAD_CAP_ID;
- Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_THREAD_OBJ] = 0;
- Genode::cap_map()->insert(MAIN_THREAD_CAP_ID, Fiasco::MAIN_THREAD_CAP);
+ /**
+ * Unfortunately ldso calls this function twice. So the second time when
+ * inserting the main thread's gate-capability an exception would be raised.
+ * At least on ARM we got problems when raising an exception that early,
+ * that's why we first check if the cap is already registered before
+ * inserting it.
+ */
+ Genode::Cap_index *idx = Genode::cap_map()->find(MAIN_THREAD_CAP_ID);
+ if (!idx) {
+ Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_BADGE] = MAIN_THREAD_CAP_ID;
+ Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_THREAD_OBJ] = 0;
+ Genode::cap_map()->insert(MAIN_THREAD_CAP_ID, Fiasco::MAIN_THREAD_CAP);
+ }
}

0 comments on commit 76c106d

Please sign in to comment.