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
This commit is contained in:
Alexander Boettcher 2016-07-19 21:05:30 +02:00 committed by Christian Helmuth
parent 997f5e8e27
commit 1472c0629b
4 changed files with 20 additions and 12 deletions

View File

@ -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);

View File

@ -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;
/*

View File

@ -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);

View File

@ -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,
};
};