From 76c106dac07ef9b3458b9e7a5d6c0677b0dbeb16 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Mon, 26 Mar 2012 09:43:06 +0200 Subject: [PATCH] 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. --- base-foc/src/platform/_main_helper.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/base-foc/src/platform/_main_helper.h b/base-foc/src/platform/_main_helper.h index 062412083f..0c63dad703 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); + } }