From 1472c0629bdc62d082804d50650cd51ffb427c5e Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Tue, 19 Jul 2016 21:05:30 +0200 Subject: [PATCH] sel4: allocate thread selectors during bind_thread That seems nowadays the right place in order to tell the caller that the thread couldn't be completely constructed. The return value false of bind_thread causes in Cpu_thread_component the throwing of Thread_creation_failed. thread.run now passes pthread.run now passes Issue #2044 --- repos/base-sel4/src/core/include/platform_pd.h | 11 ++++++----- repos/base-sel4/src/core/platform_pd.cc | 13 +++++++++++++ repos/base-sel4/src/core/platform_thread.cc | 6 ------ .../include/base/internal/capability_space_sel4.h | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/repos/base-sel4/src/core/include/platform_pd.h b/repos/base-sel4/src/core/include/platform_pd.h index 4ef2fa3e5..04078a4d9 100644 --- a/repos/base-sel4/src/core/include/platform_pd.h +++ b/repos/base-sel4/src/core/include/platform_pd.h @@ -51,7 +51,9 @@ class Genode::Platform_pd : public Address_space /* * Allocator for core-managed selectors within the PD's CSpace */ - struct Sel_alloc : Bit_allocator<1 << NUM_CORE_MANAGED_SEL_LOG2> + typedef Bit_allocator<1 << NUM_CORE_MANAGED_SEL_LOG2> Sel_bit_alloc; + + struct Sel_alloc : Sel_bit_alloc { Sel_alloc() { _reserve(0, INITIAL_SEL_END); } }; @@ -59,6 +61,9 @@ class Genode::Platform_pd : public Address_space Sel_alloc _sel_alloc; Lock _sel_alloc_lock; + Cap_sel alloc_sel(); + void free_sel(Cap_sel sel); + public: /** @@ -101,10 +106,6 @@ class Genode::Platform_pd : public Address_space ** seL4-specific interface ** *****************************/ - Cap_sel alloc_sel(); - - void free_sel(Cap_sel sel); - Cnode &cspace_cnode(Cap_sel sel) { const unsigned index = sel.value() / (1 << CSPACE_SIZE_LOG2_2ND); diff --git a/repos/base-sel4/src/core/platform_pd.cc b/repos/base-sel4/src/core/platform_pd.cc index 37648b1bb..e29711371 100644 --- a/repos/base-sel4/src/core/platform_pd.cc +++ b/repos/base-sel4/src/core/platform_pd.cc @@ -56,6 +56,19 @@ bool Platform_pd::bind_thread(Platform_thread *thread) { ASSERT(thread); + try { + /* allocate fault handler selector in the PD's CSpace */ + thread->_fault_handler_sel = alloc_sel(); + /* allocate endpoint selector in the PD's CSpace */ + thread->_ep_sel = alloc_sel(); + } catch (Platform_pd::Sel_bit_alloc::Out_of_indices) { + if (thread->_fault_handler_sel.value()) { + free_sel(thread->_fault_handler_sel); + thread->_fault_handler_sel = Cap_sel(0); + } + return false; + } + thread->_pd = this; /* diff --git a/repos/base-sel4/src/core/platform_thread.cc b/repos/base-sel4/src/core/platform_thread.cc index 70606f65a..120a1e43e 100644 --- a/repos/base-sel4/src/core/platform_thread.cc +++ b/repos/base-sel4/src/core/platform_thread.cc @@ -117,9 +117,6 @@ int Platform_thread::start(void *ip, void *sp, unsigned int cpu_no) ASSERT(_pd); ASSERT(_pager); - /* allocate fault handler selector in the PD's CSpace */ - _fault_handler_sel = _pd->alloc_sel(); - /* pager endpoint in core */ Cap_sel const pager_sel(Capability_space::ipc_cap_data(_pager->cap()).sel); @@ -127,9 +124,6 @@ int Platform_thread::start(void *ip, void *sp, unsigned int cpu_no) _pd->cspace_cnode(_fault_handler_sel).copy(platform_specific()->core_cnode(), pager_sel, _fault_handler_sel); - /* allocate endpoint selector in the PD's CSpace */ - _ep_sel = _pd->alloc_sel(); - /* install the thread's endpoint selector to the PD's CSpace */ _pd->cspace_cnode(_ep_sel).copy(platform_specific()->core_cnode(), _info.ep_sel, _ep_sel); diff --git a/repos/base-sel4/src/include/base/internal/capability_space_sel4.h b/repos/base-sel4/src/include/base/internal/capability_space_sel4.h index 39d9580a8..342f3fd3c 100644 --- a/repos/base-sel4/src/include/base/internal/capability_space_sel4.h +++ b/repos/base-sel4/src/include/base/internal/capability_space_sel4.h @@ -104,7 +104,7 @@ namespace Genode CSPACE_SIZE_LOG2_1ST = 4, CSPACE_SIZE_LOG2_2ND = 8, CSPACE_SIZE_LOG2 = CSPACE_SIZE_LOG2_1ST + CSPACE_SIZE_LOG2_2ND, - NUM_CORE_MANAGED_SEL_LOG2 = 7, + NUM_CORE_MANAGED_SEL_LOG2 = 8, }; };