base: remove integer return codes from PD-session

The return code of assign_parent remained unused. So this patch
removes it.

The bind_thread function fails only due to platform-specific limitations
such as the exhaustion of ID name spaces, which cannot be sensibly
handled by the PD-session client. If occurred, such conditions used to
be reflected by integer return codes that were used for diagnostic
messages only. The patch removes the return codes and leaves the
diagnostic output to core.

Fixes #1842
This commit is contained in:
Norman Feske 2016-04-14 16:29:07 +02:00 committed by Christian Helmuth
parent 93b82c14ac
commit e20bbe7002
29 changed files with 83 additions and 145 deletions

View File

@ -163,13 +163,8 @@ namespace Genode {
/**
* Bind thread to protection domain
*
* \return 0 on success or
* -1 if thread ID allocation failed.
*
* This function allocates the physical L4 thread ID.
*/
int bind_thread(Platform_thread *thread);
void bind_thread(Platform_thread *thread);
/**
* Unbind thread from protection domain
@ -181,7 +176,7 @@ namespace Genode {
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent) { return 0; }
void assign_parent(Native_capability parent) { }
int pd_id() const { return _pd_id; }

View File

@ -199,7 +199,7 @@ void Platform_pd::_free_thread(int thread_id)
** Public object members **
***************************/
int Platform_pd::bind_thread(Platform_thread *thread)
void Platform_pd::bind_thread(Platform_thread *thread)
{
/* thread_id is THREAD_INVALID by default - only core is the special case */
int thread_id = thread->thread_id();
@ -208,7 +208,7 @@ int Platform_pd::bind_thread(Platform_thread *thread)
int t = _alloc_thread(thread_id, thread);
if (t < 0) {
PERR("Thread alloc failed");
return -1;
return;
}
thread_id = t;
@ -219,7 +219,6 @@ int Platform_pd::bind_thread(Platform_thread *thread)
thread->bind(thread_id, l4_thread_id, this);
if (verbose) _debug_log_threads();
return 0;
}

View File

@ -56,9 +56,10 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
_thread_cap = _cpu_session->create_thread(weight, buf);
/* assign thread to protection domain */
if (!_thread_cap.valid() ||
env()->pd_session()->bind_thread(_thread_cap))
if (!_thread_cap.valid())
throw Cpu_session::Thread_creation_failed();
env()->pd_session()->bind_thread(_thread_cap);
return;
}
/* adjust values whose computation differs for a main thread */

View File

@ -81,13 +81,8 @@ namespace Genode {
/**
* Bind thread to protection domain
*
* \return 0 on success or
* -1 if thread ID allocation failed.
*
* This function allocates the physical L4 thread ID.
*/
int bind_thread(Platform_thread *thread);
void bind_thread(Platform_thread *thread);
/**
* Unbind thread from protection domain
@ -99,7 +94,7 @@ namespace Genode {
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent);
void assign_parent(Native_capability parent);
/*******************************

View File

@ -144,8 +144,7 @@ Platform::Core_pager::Core_pager(Platform_pd *core_pd, Sigma0 *sigma0)
{
Platform_thread::pager(sigma0);
if (core_pd->bind_thread(this))
panic("Binding thread failed");
core_pd->bind_thread(this);
cap(thread().local);
/* stack begins at the top end of the '_core_pager_stack' array */
@ -516,8 +515,7 @@ Platform::Platform() :
Platform_thread(thi, irqi, "core.main");
core_thread->pager(&_sigma0);
if (_core_pd->bind_thread(core_thread))
panic("Binding thread failed");
_core_pd->bind_thread(core_thread);
}

View File

@ -41,7 +41,7 @@ static addr_t core_utcb_base() {
** Public object members **
***************************/
int Platform_pd::bind_thread(Platform_thread *thread)
void Platform_pd::bind_thread(Platform_thread *thread)
{
/*
* Fiasco.OC limits the UTCB area for roottask to 16K. Therefore, the
@ -76,11 +76,10 @@ int Platform_pd::bind_thread(Platform_thread *thread)
/* inform thread about binding */
thread->bind(this);
return 0;
return;
}
PERR("thread alloc failed");
return -1;
}
@ -97,12 +96,12 @@ void Platform_pd::unbind_thread(Platform_thread *thread)
}
int Platform_pd::assign_parent(Native_capability parent)
void Platform_pd::assign_parent(Native_capability parent)
{
if (!parent.valid()) return -1;
_parent.local = parent;
_parent.remote = PARENT_CAP;
return 0;
if (_parent.remote == Fiasco::L4_INVALID_CAP && parent.valid()) {
_parent.local = parent;
_parent.remote = PARENT_CAP;
}
}

View File

@ -48,8 +48,7 @@ void Thread_base::start()
Platform_thread *pt =
new(platform()->core_mem_alloc()) Platform_thread(_stack->name().string());
if (platform_specific()->core_pd()->bind_thread(pt))
throw Cpu_session::Thread_creation_failed();
platform_specific()->core_pd()->bind_thread(pt);
l4_utcb_t *foc_utcb = (l4_utcb_t *)(pt->utcb());

View File

@ -187,11 +187,8 @@ class Genode::Platform_pd : public Hw::Address_space,
/**
* Bind thread 't' to protection domain
*
* \return 0 on success or
* -1 if failed
*/
int bind_thread(Platform_thread * t);
void bind_thread(Platform_thread * t);
/**
* Unbind thread 't' from protection domain
@ -202,7 +199,7 @@ class Genode::Platform_pd : public Hw::Address_space,
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent);
void assign_parent(Native_capability parent);
/***************

View File

@ -115,11 +115,11 @@ namespace Genode {
* \param main_thread wether thread is the first in protection domain
* \param address_space corresponding Genode address space
*
* \retval 0 succeeded
* \retval -1 failed
* This function has no effect when called more twice for a
* given thread.
*/
int join_pd(Platform_pd * const pd, bool const main_thread,
Weak_ptr<Address_space> address_space);
void join_pd(Platform_pd * const pd, bool const main_thread,
Weak_ptr<Address_space> address_space);
/**
* Run this thread

View File

@ -131,12 +131,12 @@ void Capability_space::upgrade_slab(Allocator &alloc)
** Platform_pd implementation **
********************************/
int Platform_pd::bind_thread(Platform_thread * t)
void Platform_pd::bind_thread(Platform_thread * t)
{
/* is this the first and therefore main thread in this PD? */
bool main_thread = !_thread_associated;
_thread_associated = true;
return t->join_pd(this, main_thread, Address_space::weak_ptr());
t->join_pd(this, main_thread, Address_space::weak_ptr());
}
@ -144,14 +144,10 @@ void Platform_pd::unbind_thread(Platform_thread *t) {
t->join_pd(nullptr, false, Address_space::weak_ptr()); }
int Platform_pd::assign_parent(Native_capability parent)
void Platform_pd::assign_parent(Native_capability parent)
{
if (!parent.valid()) {
PERR("parent invalid");
return -1;
}
_parent = parent;
return 0;
if (!_parent.valid() && parent.valid())
_parent = parent;
}

View File

@ -99,20 +99,19 @@ Platform_thread::Platform_thread(size_t const quota,
}
int Platform_thread::join_pd(Platform_pd * pd, bool const main_thread,
Weak_ptr<Address_space> address_space)
void Platform_thread::join_pd(Platform_pd * pd, bool const main_thread,
Weak_ptr<Address_space> address_space)
{
/* check if thread is already in another protection domain */
if (_pd && _pd != pd) {
PERR("thread already in another protection domain");
return -1;
return;
}
/* join protection domain */
_pd = pd;
_main_thread = main_thread;
_address_space = address_space;
return 0;
}

View File

@ -17,13 +17,12 @@
using namespace Genode;
int Pd_session_component::bind_thread(Thread_capability) { return -1; }
void Pd_session_component::bind_thread(Thread_capability) { }
int Pd_session_component::assign_parent(Capability<Parent> parent)
void Pd_session_component::assign_parent(Capability<Parent> parent)
{
_parent = parent;
return 0;
}

View File

@ -121,9 +121,7 @@ void Thread_base::_init_platform_thread(size_t weight, Type type)
throw Cpu_session::Thread_creation_failed();
/* assign thread to protection domain */
if (env()->pd_session()->bind_thread(_thread_cap))
throw Cpu_session::Thread_creation_failed();
env()->pd_session()->bind_thread(_thread_cap);
}

View File

@ -50,11 +50,8 @@ namespace Genode {
/**
* Bind thread to protection domain
*
* \return 0 on success or
* -1 if thread ID allocation failed.
*/
int bind_thread(Platform_thread *thread);
void bind_thread(Platform_thread *thread);
/**
* Unbind thread from protection domain
@ -66,7 +63,7 @@ namespace Genode {
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent);
void assign_parent(Native_capability parent);
/**
* Return portal capability selector for parent interface

View File

@ -25,11 +25,10 @@ using namespace Genode;
** Public object members **
***************************/
int Platform_pd::bind_thread(Platform_thread *thread)
void Platform_pd::bind_thread(Platform_thread *thread)
{
thread->bind_to_pd(this, _thread_cnt == 0);
_thread_cnt++;
return 0;
}
@ -39,13 +38,10 @@ void Platform_pd::unbind_thread(Platform_thread *thread)
}
int Platform_pd::assign_parent(Native_capability parent)
void Platform_pd::assign_parent(Native_capability parent)
{
if (_parent.valid()) return -1;
if (!parent.valid()) return -2;
_parent = parent;
return 0;
if (!_parent.valid() && parent.valid())
_parent = parent;
}

View File

@ -171,12 +171,9 @@ namespace Genode {
/**
* Bind thread to protection domain
*
* \return 0 on success or
* -1 if thread ID allocation failed.
*
* This function allocates the physical L4 thread ID.
*/
int bind_thread(Platform_thread *thread);
void bind_thread(Platform_thread *thread);
/**
* Unbind thread from protection domain
@ -188,7 +185,7 @@ namespace Genode {
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent) { return 0; }
void assign_parent(Native_capability parent) { }
Platform_thread* space_pager() const { return _space_pager; }

View File

@ -176,7 +176,7 @@ void Platform_pd::_free_thread(int thread_id)
** Public object members **
***************************/
int Platform_pd::bind_thread(Platform_thread *thread)
void Platform_pd::bind_thread(Platform_thread *thread)
{
using namespace Okl4;
@ -187,14 +187,13 @@ int Platform_pd::bind_thread(Platform_thread *thread)
int t = _alloc_thread(thread_id, thread);
if (t < 0) {
PERR("thread alloc failed");
return -1;
return;
}
thread_id = t;
l4_thread_id = make_l4_id(_pd_id, thread_id);
/* finally inform thread about binding */
thread->bind(thread_id, l4_thread_id, this);
return 0;
}

View File

@ -40,8 +40,7 @@ void Thread_base::start()
native_thread().pt = new(platform_specific()->thread_slab())
Platform_thread(0, _stack->name().string());
if (platform_specific()->core_pd()->bind_thread(native_thread().pt))
throw Cpu_session::Thread_creation_failed();
platform_specific()->core_pd()->bind_thread(native_thread().pt);
native_thread().pt->start((void *)_thread_start, stack_top());
}

View File

@ -203,12 +203,10 @@ namespace Genode {
/**
* Bind thread to protection domain
*
* \return 0 on success or
* -1 if thread ID allocation failed.
*
* This function allocates the physical L4 thread ID.
*/
int bind_thread(Platform_thread *thread);
void bind_thread(Platform_thread *thread);
int bind_initial_thread(Platform_thread *thread);
/**
@ -221,7 +219,7 @@ namespace Genode {
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent) { return 0; }
void assign_parent(Native_capability parent) { }
int pd_id() const { return _pd_id; }

View File

@ -192,7 +192,7 @@ void Platform_pd::_free_thread(int thread_id)
** Public object members **
***************************/
int Platform_pd::bind_thread(Platform_thread *thread)
void Platform_pd::bind_thread(Platform_thread *thread)
{
using namespace Pistachio;
@ -203,7 +203,7 @@ int Platform_pd::bind_thread(Platform_thread *thread)
int t = _alloc_thread(thread_id, thread);
if (t < 0) {
PERR("thread alloc failed");
return -1;
return;
}
thread_id = t;
l4_thread_id = make_l4_id(_pd_id, thread_id, _version);
@ -212,7 +212,6 @@ int Platform_pd::bind_thread(Platform_thread *thread)
thread->bind(thread_id, l4_thread_id, this);
if (verbose) _debug_log_threads();
return 0;
}

View File

@ -74,11 +74,8 @@ class Genode::Platform_pd : public Address_space
/**
* Bind thread to protection domain
*
* \return 0 on success or
* -1 if thread ID allocation failed.
*/
int bind_thread(Platform_thread *thread);
void bind_thread(Platform_thread *thread);
/**
* Unbind thread from protection domain
@ -90,7 +87,7 @@ class Genode::Platform_pd : public Address_space
/**
* Assign parent interface to protection domain
*/
int assign_parent(Native_capability parent);
void assign_parent(Native_capability parent);
/*****************************

View File

@ -52,7 +52,7 @@ static Pd_id_alloc &pd_id_alloc()
}
int Platform_pd::bind_thread(Platform_thread *thread)
void Platform_pd::bind_thread(Platform_thread *thread)
{
ASSERT(thread);
@ -73,8 +73,6 @@ int Platform_pd::bind_thread(Platform_thread *thread)
} else {
_vm_space.map(thread->_info.ipc_buffer_phys, thread->INITIAL_IPC_BUFFER_VIRT, 1);
}
return 0;
}
@ -84,7 +82,7 @@ void Platform_pd::unbind_thread(Platform_thread *thread)
}
int Platform_pd::assign_parent(Native_capability parent)
void Platform_pd::assign_parent(Native_capability parent)
{
Capability_space::Ipc_cap_data const ipc_cap_data =
Capability_space::ipc_cap_data(parent);
@ -98,7 +96,6 @@ int Platform_pd::assign_parent(Native_capability parent)
_cspace_cnode.copy(platform_specific()->core_cnode(),
Cnode_index(ipc_cap_data.sel),
Cnode_index(INITIAL_SEL_PARENT));
return 0;
}

View File

@ -25,11 +25,11 @@ struct Genode::Pd_session_client : Rpc_client<Pd_session>
explicit Pd_session_client(Pd_session_capability session)
: Rpc_client<Pd_session>(session) { }
int bind_thread(Thread_capability thread) override {
return call<Rpc_bind_thread>(thread); }
void bind_thread(Thread_capability thread) override {
call<Rpc_bind_thread>(thread); }
int assign_parent(Capability<Parent> parent) override {
return call<Rpc_assign_parent>(parent); }
void assign_parent(Capability<Parent> parent) override {
call<Rpc_assign_parent>(parent); }
bool assign_pci(addr_t pci_config_memory_address, uint16_t bdf) override {
return call<Rpc_assign_pci>(pci_config_memory_address, bdf); }

View File

@ -41,20 +41,18 @@ struct Genode::Pd_session : Session
*
* \param thread capability of thread to bind
*
* \return 0 on success or negative error code
*
* After successful bind, the thread will execute inside this
* protection domain when started.
* After binding, the thread will execute inside this protection domain
* when started. A thread can be bound to a PD only once. Subsequent
* attempts to bind the thread to another PD are ignored.
*/
virtual int bind_thread(Thread_capability thread) = 0;
virtual void bind_thread(Thread_capability thread) = 0;
/**
* Assign parent to protection domain
*
* \param parent capability of parent interface
* \return 0 on success, or negative error code
*/
virtual int assign_parent(Capability<Parent> parent) = 0;
virtual void assign_parent(Capability<Parent> parent) = 0;
/**
* Assign PCI device to PD
@ -176,8 +174,8 @@ struct Genode::Pd_session : Session
** RPC declaration **
*********************/
GENODE_RPC(Rpc_bind_thread, int, bind_thread, Thread_capability);
GENODE_RPC(Rpc_assign_parent, int, assign_parent, Capability<Parent>);
GENODE_RPC(Rpc_bind_thread, void, bind_thread, Thread_capability);
GENODE_RPC(Rpc_assign_parent, void, assign_parent, Capability<Parent>);
GENODE_RPC(Rpc_assign_pci, bool, assign_pci, addr_t, uint16_t);
GENODE_RPC_THROW(Rpc_alloc_signal_source, Signal_source_capability,

View File

@ -188,8 +188,8 @@ Process::Process(Dataspace_capability elf_ds_cap,
enum Local_exception
{
THREAD_FAIL, ELF_FAIL, ASSIGN_PARENT_FAIL, THREAD_ADD_FAIL,
THREAD_BIND_FAIL, THREAD_PAGER_FAIL, THREAD_START_FAIL,
THREAD_FAIL, ELF_FAIL, THREAD_ADD_FAIL,
THREAD_PAGER_FAIL, THREAD_START_FAIL,
};
/* XXX this only catches local exceptions */
@ -240,24 +240,17 @@ Process::Process(Dataspace_capability elf_ds_cap,
}
/* register parent interface for new protection domain */
if (_pd_session_client.assign_parent(parent_cap)) {
PERR("Could not assign parent interface to new PD");
throw ASSIGN_PARENT_FAIL;
}
_pd_session_client.assign_parent(parent_cap);
/* bind thread0 */
err = _pd_session_client.bind_thread(_thread0_cap);
if (err) {
PERR("Thread binding failed (%d)", err);
throw THREAD_BIND_FAIL;
}
_pd_session_client.bind_thread(_thread0_cap);
/* register thread0 at region manager session */
Pager_capability pager;
try {
pager = _rm_session_client.add_client(_thread0_cap);
} catch (...) {
PERR("Pager setup failed (%d)", err);
PERR("Pager setup failed");
throw THREAD_ADD_FAIL;
}
@ -290,8 +283,6 @@ Process::Process(Dataspace_capability elf_ds_cap,
case THREAD_START_FAIL:
case THREAD_PAGER_FAIL:
case THREAD_ADD_FAIL:
case THREAD_BIND_FAIL:
case ASSIGN_PARENT_FAIL:
case ELF_FAIL:
_cpu_session_client.kill_thread(_thread0_cap);

View File

@ -64,8 +64,7 @@ void Thread_base::start()
throw Cpu_session::Thread_creation_failed();
/* assign thread to protection domain */
if (env()->pd_session()->bind_thread(_thread_cap))
throw Cpu_session::Thread_creation_failed();
env()->pd_session()->bind_thread(_thread_cap);
/* create new pager object and assign it to the new thread */
Pager_capability pager_cap = env()->rm_session()->add_client(_thread_cap);

View File

@ -45,12 +45,12 @@ class Genode::Core_pd_session_component : public Rpc_object<Pd_session>
_signal_source_ep(signal_source_ep)
{ }
int bind_thread(Thread_capability thread) override
void bind_thread(Thread_capability thread) override
{
ASSERT_NEVER_CALLED;
}
int assign_parent(Capability<Parent> parent) override
void assign_parent(Capability<Parent> parent) override
{
ASSERT_NEVER_CALLED;
}

View File

@ -106,8 +106,8 @@ class Genode::Pd_session_component : public Rpc_object<Pd_session>
** PD session interface **
**************************/
int bind_thread(Thread_capability) override;
int assign_parent(Capability<Parent>) override;
void bind_thread(Thread_capability) override;
void assign_parent(Capability<Parent>) override;
bool assign_pci(addr_t, uint16_t) override;
Signal_source_capability alloc_signal_source() override

View File

@ -24,30 +24,26 @@
using namespace Genode;
int Pd_session_component::bind_thread(Thread_capability thread)
void Pd_session_component::bind_thread(Thread_capability thread)
{
return _thread_ep.apply(thread, [&] (Cpu_thread_component *cpu_thread) {
if (!cpu_thread) return -1;
if (!cpu_thread) return;
if (cpu_thread->bound()) {
PWRN("rebinding of threads not supported");
return -2;
return;
}
Platform_thread *p_thread = cpu_thread->platform_thread();
int res = _pd.bind_thread(p_thread);
if (res)
return res;
_pd.bind_thread(p_thread);
cpu_thread->bound(true);
return 0;
});
}
int Pd_session_component::assign_parent(Parent_capability parent)
void Pd_session_component::assign_parent(Parent_capability parent)
{
return _pd.assign_parent(parent);
_pd.assign_parent(parent);
}