diff --git a/base-foc/src/platform/_main_helper.h b/base-foc/src/platform/_main_helper.h index 062412083..0c63dad70 100644 --- a/base-foc/src/platform/_main_helper.h +++ b/base-foc/src/platform/_main_helper.h @@ -21,15 +21,24 @@ namespace Fiasco { #include -#include } 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); + } }