mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-20 22:23:16 +00:00
base: redesign object pool using lambda interface
Instead of returning pointers to locked objects via a lookup function, the new object pool implementation restricts object access to functors resp. lambda expressions that are applied to the objects within the pool itself. Fix #884 Fix #1658
This commit is contained in:
parent
555835c95b
commit
458b4d6fc4
@ -30,7 +30,7 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
{
|
||||
using namespace Codezero;
|
||||
|
||||
Object_pool<Dataspace_component>::Guard ds(_ds_ep->lookup_and_lock(ds_cap));
|
||||
auto lambda = [&] (Dataspace_component *ds) -> Local_addr {
|
||||
if (!ds)
|
||||
throw Invalid_dataspace();
|
||||
|
||||
@ -42,12 +42,12 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
|
||||
if (use_local_addr) {
|
||||
PERR("Parameter 'use_local_addr' not supported within core");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
PERR("Parameter 'offset' not supported within core");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* allocate range in core's virtual address space */
|
||||
@ -55,14 +55,16 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
if (!platform()->region_alloc()->alloc(page_rounded_size, &virt_addr)) {
|
||||
PERR("Could not allocate virtual address range in core of size %zd\n",
|
||||
page_rounded_size);
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!map_local(ds->phys_addr(), (addr_t)virt_addr, num_pages)) {
|
||||
PERR("core-local memory mapping failed virt=%lx, phys=%lx\n",
|
||||
(addr_t)virt_addr, ds->phys_addr());
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return virt_addr;
|
||||
};
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ void Ipc_pager::acknowledge_wakeup()
|
||||
** Pager entrypoint **
|
||||
**********************/
|
||||
|
||||
Untyped_capability Pager_entrypoint::_manage(Pager_object *obj)
|
||||
Untyped_capability Pager_entrypoint::_pager_object_cap(unsigned long badge)
|
||||
{
|
||||
return Untyped_capability(_tid.l4id, obj->badge());
|
||||
return Untyped_capability(_tid.l4id, badge);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void Ipc_pager::acknowledge_wakeup()
|
||||
** Pager Entrypoint **
|
||||
**********************/
|
||||
|
||||
Untyped_capability Pager_entrypoint::_manage(Pager_object *obj)
|
||||
Untyped_capability Pager_entrypoint::_pager_object_cap(unsigned long badge)
|
||||
{
|
||||
return Untyped_capability(_tid.l4id, obj->badge());
|
||||
return Untyped_capability(_tid.l4id, badge);
|
||||
}
|
||||
|
@ -70,24 +70,13 @@ void Rpc_entrypoint::entry()
|
||||
continue;
|
||||
}
|
||||
|
||||
/* atomically lookup and lock referenced object */
|
||||
Object_pool<Rpc_object_base>::Guard curr_obj(lookup_and_lock(srv.badge()));
|
||||
if (!curr_obj)
|
||||
continue;
|
||||
apply(srv.badge(), [&] (Rpc_object_base *obj) {
|
||||
if (!obj) return;
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = curr_obj;
|
||||
}
|
||||
|
||||
/* dispatch request */
|
||||
try { srv.ret(_curr_obj->dispatch(opcode, srv, srv)); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = 0;
|
||||
}
|
||||
try {
|
||||
srv.ret(obj->dispatch(opcode, srv, srv));
|
||||
} catch(Blocking_canceled&) { }
|
||||
});
|
||||
}
|
||||
|
||||
/* answer exit call, thereby wake up '~Rpc_entrypoint' */
|
||||
@ -95,6 +84,4 @@ void Rpc_entrypoint::entry()
|
||||
|
||||
/* defer the destruction of 'Ipc_server' until '~Rpc_entrypoint' is ready */
|
||||
_delay_exit.lock();
|
||||
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ void Genode::Cpu_session_component::enable_vcpu(Genode::Thread_capability thread
|
||||
using namespace Genode;
|
||||
using namespace Fiasco;
|
||||
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
Native_thread tid = thread->platform_thread()->thread().local.dst();
|
||||
@ -48,6 +48,8 @@ void Genode::Cpu_session_component::enable_vcpu(Genode::Thread_capability thread
|
||||
l4_msgtag_t tag = l4_thread_vcpu_control(tid, vcpu_state);
|
||||
if (l4_msgtag_has_error(tag))
|
||||
PWRN("l4_thread_vcpu_control failed");
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -56,10 +58,11 @@ Genode::Cpu_session_component::native_cap(Genode::Thread_capability cap)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(cap));
|
||||
if (!thread) return Native_capability();
|
||||
|
||||
return thread->platform_thread()->thread().local;
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
return (!thread) ? Native_capability()
|
||||
: thread->platform_thread()->thread().local;
|
||||
};
|
||||
return _thread_ep->apply(cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -97,7 +100,7 @@ void Genode::Cpu_session_component::single_step(Genode::Thread_capability thread
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
Native_thread tid = thread->platform_thread()->thread().local.dst();
|
||||
@ -106,6 +109,8 @@ void Genode::Cpu_session_component::single_step(Genode::Thread_capability thread
|
||||
int flags = enable ? THREAD_SINGLE_STEP : 0;
|
||||
|
||||
Fiasco::l4_thread_ex_regs(tid, ~0UL, ~0UL, flags);
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,13 +42,11 @@ void Pager_entrypoint::entry()
|
||||
|
||||
reply_pending = false;
|
||||
|
||||
/* lookup referenced object */
|
||||
Object_pool<Pager_object>::Guard obj(lookup_and_lock(_pager.badge()));
|
||||
|
||||
apply(_pager.badge(), [&] (Pager_object *obj) {
|
||||
/* the pager_object might be destroyed, while we got the message */
|
||||
if (!obj) {
|
||||
PWRN("No pager object found!");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (_pager.msg_type()) {
|
||||
@ -62,7 +60,7 @@ void Pager_entrypoint::entry()
|
||||
obj->state.exceptions++;
|
||||
obj->state.in_exception = true;
|
||||
obj->submit_exception_signal();
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
/* handle request */
|
||||
@ -73,7 +71,7 @@ void Pager_entrypoint::entry()
|
||||
} else {
|
||||
_pager.set_reply_dst(obj->badge());
|
||||
reply_pending = true;
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -132,6 +130,7 @@ void Pager_entrypoint::entry()
|
||||
default:
|
||||
PERR("Got unknown message type %x!", _pager.msg_type());
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -141,7 +140,7 @@ void Pager_entrypoint::dissolve(Pager_object *obj)
|
||||
/* cleanup at cap session */
|
||||
_cap_session->free(obj->Object_pool<Pager_object>::Entry::cap());
|
||||
|
||||
remove_locked(obj);
|
||||
remove(obj);
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,23 +72,13 @@ void Rpc_entrypoint::entry()
|
||||
srv.ret(Ipc_client::ERR_INVALID_OBJECT);
|
||||
|
||||
/* atomically lookup and lock referenced object */
|
||||
Object_pool<Rpc_object_base>::Guard curr_obj(lookup_and_lock(srv.badge()));
|
||||
if (!curr_obj)
|
||||
continue;
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = curr_obj;
|
||||
}
|
||||
apply(srv.badge(), [&] (Rpc_object_base *curr_obj) {
|
||||
if (!curr_obj) return;
|
||||
|
||||
/* dispatch request */
|
||||
try { srv.ret(_curr_obj->dispatch(opcode, srv, srv)); }
|
||||
try { srv.ret(curr_obj->dispatch(opcode, srv, srv)); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* answer exit call, thereby wake up '~Rpc_entrypoint' */
|
||||
|
@ -28,7 +28,7 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
off_t offset, bool use_local_addr,
|
||||
Rm_session::Local_addr, bool executable)
|
||||
{
|
||||
Object_pool<Dataspace_component>::Guard ds(_ds_ep->lookup_and_lock(ds_cap));
|
||||
auto lambda = [&] (Dataspace_component *ds) -> Local_addr {
|
||||
if (!ds)
|
||||
throw Invalid_dataspace();
|
||||
|
||||
@ -39,12 +39,12 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
|
||||
if (use_local_addr) {
|
||||
PERR("Parameter 'use_local_addr' not supported within core");
|
||||
return 0UL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
PERR("Parameter 'offset' not supported within core");
|
||||
return 0UL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* allocate range in core's virtual address space */
|
||||
@ -54,16 +54,18 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
get_page_size_log2()).is_ok()) {
|
||||
PERR("Could not allocate virtual address range in core of size %zd\n",
|
||||
page_rounded_size);
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* map the dataspace's physical pages to corresponding virtual addresses */
|
||||
unsigned num_pages = page_rounded_size >> get_page_size_log2();
|
||||
Page_flags const flags = Page_flags::apply_mapping(ds.object()->writable(),
|
||||
ds.object()->cacheability(),
|
||||
ds.object()->is_io_mem());
|
||||
Page_flags const flags = Page_flags::apply_mapping(ds->writable(),
|
||||
ds->cacheability(),
|
||||
ds->is_io_mem());
|
||||
if (!map_local(ds->phys_addr(), (addr_t)virt_addr, num_pages, flags))
|
||||
return 0UL;
|
||||
return nullptr;
|
||||
|
||||
return virt_addr;
|
||||
};
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
@ -25,10 +25,11 @@ Ram_dataspace_capability
|
||||
Cpu_session_component::utcb(Thread_capability thread_cap)
|
||||
{
|
||||
/* look up requested UTCB dataspace */
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
t(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [] (Cpu_thread_component *t) {
|
||||
if (!t) return Ram_dataspace_capability();
|
||||
return t->platform_thread()->utcb();
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,7 +104,7 @@ Pager_object::Pager_object(unsigned const badge, Affinity::Location)
|
||||
|
||||
void Pager_entrypoint::dissolve(Pager_object * const o)
|
||||
{
|
||||
remove_locked(o);
|
||||
remove(o);
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,8 +129,7 @@ int Platform_thread::start(void * const ip, void * const sp)
|
||||
if (_main_thread) {
|
||||
|
||||
/* lookup dataspace component for physical address */
|
||||
Rpc_entrypoint * ep = core_env()->entrypoint();
|
||||
Object_pool<Dataspace_component>::Guard dsc(ep->lookup_and_lock(_utcb));
|
||||
auto lambda = [&] (Dataspace_component *dsc) {
|
||||
if (!dsc) return -1;
|
||||
|
||||
/* lock the address space */
|
||||
@ -147,6 +146,9 @@ int Platform_thread::start(void * const ip, void * const sp)
|
||||
PERR("failed to attach UTCB");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
if (core_env()->entrypoint()->apply(_utcb, lambda)) return -1;
|
||||
}
|
||||
|
||||
/* initialize thread registers */
|
||||
|
@ -60,23 +60,23 @@ void Pager_entrypoint::entry()
|
||||
{
|
||||
/* receive fault */
|
||||
if (Kernel::await_signal(_cap.dst())) continue;
|
||||
Pager_object * po =
|
||||
*(Pager_object**)Thread_base::myself()->utcb()->base();
|
||||
|
||||
Untyped_capability cap =
|
||||
(*(Pager_object**)Thread_base::myself()->utcb()->base())->cap();
|
||||
|
||||
/*
|
||||
* Synchronize access and ensure that the object is still managed
|
||||
*
|
||||
* FIXME: The implicit lookup of the oject isn't needed.
|
||||
*/
|
||||
unsigned const pon = po->cap().local_name();
|
||||
Object_pool<Pager_object>::Guard pog(lookup_and_lock(pon));
|
||||
if (!pog) continue;
|
||||
auto lambda = [&] (Pager_object *po) {
|
||||
if (!po) return;
|
||||
|
||||
/* fetch fault data */
|
||||
Platform_thread * const pt = (Platform_thread *)pog->badge();
|
||||
Platform_thread * const pt = (Platform_thread *)po->badge();
|
||||
if (!pt) {
|
||||
PWRN("failed to get platform thread of faulter");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
_fault.pd = pt->kernel_object()->fault_pd();
|
||||
@ -86,14 +86,16 @@ void Pager_entrypoint::entry()
|
||||
_fault.signal = pt->kernel_object()->fault_signal();
|
||||
|
||||
/* try to resolve fault directly via local region managers */
|
||||
if (pog->pager(*this)) { continue; }
|
||||
if (po->pager(*this)) return;
|
||||
|
||||
/* apply mapping that was determined by the local region managers */
|
||||
if (apply_mapping()) {
|
||||
PWRN("failed to apply mapping");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
/* let pager object go back to no-fault state */
|
||||
pog->wake_up();
|
||||
po->wake_up();
|
||||
};
|
||||
apply(cap, lambda);
|
||||
}
|
||||
}
|
||||
|
@ -52,14 +52,16 @@ Signal_receiver_capability Signal_session_component::alloc_receiver()
|
||||
void Signal_session_component::free_receiver(Signal_receiver_capability cap)
|
||||
{
|
||||
/* look up ressource info */
|
||||
Receiver::Pool::Guard r(_receivers.lookup_and_lock(cap));
|
||||
auto lambda = [&] (Receiver *r) {
|
||||
if (!r) {
|
||||
PERR("unknown signal receiver");
|
||||
throw Kill_receiver_failed();
|
||||
}
|
||||
/* release resources */
|
||||
_receivers.remove_locked(r);
|
||||
destroy(&_receivers_slab, r.object());
|
||||
_receivers.remove(r);
|
||||
destroy(&_receivers_slab, r);
|
||||
};
|
||||
_receivers.apply(cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -68,14 +70,14 @@ Signal_session_component::alloc_context(Signal_receiver_capability src,
|
||||
unsigned const imprint)
|
||||
{
|
||||
/* look up ressource info */
|
||||
Receiver::Pool::Guard r(_receivers.lookup_and_lock(src));
|
||||
auto lambda = [&] (Receiver *r) {
|
||||
if (!r) {
|
||||
PERR("unknown signal receiver");
|
||||
throw Create_context_failed();
|
||||
}
|
||||
|
||||
try {
|
||||
Context * c = new (_contexts_slab) Context(*r.object(), imprint);
|
||||
Context * c = new (_contexts_slab) Context(*r, imprint);
|
||||
_contexts.insert(c);
|
||||
return reinterpret_cap_cast<Signal_context>(c->cap());
|
||||
} catch (Allocator::Out_of_memory&) {
|
||||
@ -83,20 +85,24 @@ Signal_session_component::alloc_context(Signal_receiver_capability src,
|
||||
throw Out_of_metadata();
|
||||
}
|
||||
return reinterpret_cap_cast<Signal_context>(Untyped_capability());
|
||||
};
|
||||
return _receivers.apply(src, lambda);
|
||||
}
|
||||
|
||||
|
||||
void Signal_session_component::free_context(Signal_context_capability cap)
|
||||
{
|
||||
/* look up ressource info */
|
||||
Context::Pool::Guard c(_contexts.lookup_and_lock(cap));
|
||||
auto lambda = [&] (Context *c) {
|
||||
if (!c) {
|
||||
PERR("unknown signal context");
|
||||
throw Kill_context_failed();
|
||||
}
|
||||
/* release resources */
|
||||
_contexts.remove_locked(c);
|
||||
destroy(&_contexts_slab, c.object());
|
||||
_contexts.remove(c);
|
||||
destroy(&_contexts_slab, c);
|
||||
};
|
||||
_contexts.apply(cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -108,12 +114,8 @@ Signal_session_component::Signal_session_component(Allocator * const allocator,
|
||||
|
||||
Signal_session_component::~Signal_session_component()
|
||||
{
|
||||
while (Context * const c = _contexts.first_locked()) {
|
||||
_contexts.remove_locked(c);
|
||||
destroy(&_contexts_slab, c);
|
||||
}
|
||||
while (Receiver * const r = _receivers.first_locked()) {
|
||||
_receivers.remove_locked(r);
|
||||
destroy(&_receivers_slab, r);
|
||||
}
|
||||
_contexts.remove_all([this] (Context * c) {
|
||||
destroy(&_contexts_slab, c);});
|
||||
_receivers.remove_all([this] (Receiver * r) {
|
||||
destroy(&_receivers_slab, r);});
|
||||
}
|
||||
|
@ -53,10 +53,11 @@ void Vm_session_component::_attach(addr_t phys_addr, addr_t vm_addr, size_t size
|
||||
void Vm_session_component::attach(Dataspace_capability ds_cap, addr_t vm_addr)
|
||||
{
|
||||
/* check dataspace validity */
|
||||
Object_pool<Dataspace_component>::Guard dsc(_ds_ep->lookup_and_lock(ds_cap));
|
||||
_ds_ep->apply(ds_cap, [&] (Dataspace_component *dsc) {
|
||||
if (!dsc) throw Invalid_dataspace();
|
||||
|
||||
_attach(dsc->phys_addr(), vm_addr, dsc->size());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,35 +15,34 @@ using namespace Genode;
|
||||
|
||||
void Cpu_session_component::thread_id(Thread_capability thread_cap, int pid, int tid)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
if (!thread) return;
|
||||
|
||||
thread->platform_thread()->thread_id(pid, tid);
|
||||
_thread_ep->apply(thread_cap, [&] (Cpu_thread_component *thread) {
|
||||
if (thread) thread->platform_thread()->thread_id(pid, tid); });
|
||||
}
|
||||
|
||||
|
||||
Untyped_capability Cpu_session_component::server_sd(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [] (Cpu_thread_component *thread) {
|
||||
if (!thread) return Untyped_capability();
|
||||
|
||||
enum { DUMMY_LOCAL_NAME = 0 };
|
||||
typedef Native_capability::Dst Dst;
|
||||
return Untyped_capability(Dst(thread->platform_thread()->server_sd()),
|
||||
DUMMY_LOCAL_NAME);
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
Untyped_capability Cpu_session_component::client_sd(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [] (Cpu_thread_component *thread) {
|
||||
if (!thread) return Untyped_capability();
|
||||
|
||||
enum { DUMMY_LOCAL_NAME = 0 };
|
||||
typedef Native_capability::Dst Dst;
|
||||
return Untyped_capability(Dst(thread->platform_thread()->client_sd()),
|
||||
DUMMY_LOCAL_NAME);
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
@ -40,16 +40,15 @@ namespace Genode {
|
||||
*/
|
||||
Thread_capability thread_cap() { return _thread_cap; } const
|
||||
void thread_cap(Thread_capability cap) { _thread_cap = cap; }
|
||||
|
||||
/* required by lookup_and_lock, provided by Object_pool::Entry normally */
|
||||
void release() { }
|
||||
};
|
||||
|
||||
struct Pager_entrypoint
|
||||
{
|
||||
Pager_entrypoint(Cap_session *) { }
|
||||
|
||||
Pager_object *lookup_and_lock(Pager_capability) { return 0; }
|
||||
template <typename FUNC>
|
||||
auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) {
|
||||
return f(nullptr); }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
namespace Genode {
|
||||
|
||||
class Dataspace_component;
|
||||
class Pd_session_component : public Rpc_object<Linux_pd_session, Pd_session_component>
|
||||
{
|
||||
private:
|
||||
@ -39,6 +40,8 @@ namespace Genode {
|
||||
Parent_capability _parent;
|
||||
Rpc_entrypoint *_ds_ep;
|
||||
|
||||
void _start(Dataspace_component *ds);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -305,72 +305,10 @@ static const char *get_env(const char *key)
|
||||
** PD session interface **
|
||||
**************************/
|
||||
|
||||
Pd_session_component::Pd_session_component(Rpc_entrypoint * ep,
|
||||
Allocator * md_alloc,
|
||||
const char * args)
|
||||
:
|
||||
_pid(0), _uid(0), _gid(0), _ds_ep(ep)
|
||||
{
|
||||
Arg_string::find_arg(args, "label").string(_label, sizeof(_label),
|
||||
"<unlabeled>");
|
||||
|
||||
/*
|
||||
* Read Linux-specific session arguments
|
||||
*/
|
||||
Arg_string::find_arg(args, "root").string(_root, sizeof(_root), "");
|
||||
|
||||
_uid = Arg_string::find_arg(args, "uid").ulong_value(0);
|
||||
_gid = Arg_string::find_arg(args, "gid").ulong_value(0);
|
||||
|
||||
bool const is_chroot = (Genode::strcmp(_root, "") != 0);
|
||||
|
||||
/*
|
||||
* If a UID is specified but no GID, we use the UID as GID. This way, a
|
||||
* configuration error where the UID is defined but the GID is left
|
||||
* undefined won't result in the execution of the new process with the
|
||||
* root user's GID.
|
||||
*/
|
||||
if (_gid == 0)
|
||||
_gid = _uid;
|
||||
|
||||
/*
|
||||
* Print Linux-specific session arguments if specified
|
||||
*
|
||||
* This output used for the automated 'lx_pd_args' test.
|
||||
*/
|
||||
if (is_chroot || _uid || _gid)
|
||||
printf("PD session for '%s'\n", _label);
|
||||
|
||||
if (is_chroot) printf(" root: %s\n", _root);
|
||||
if (_uid) printf(" uid: %u\n", _uid);
|
||||
if (_gid) printf(" gid: %u\n", _gid);
|
||||
}
|
||||
|
||||
|
||||
Pd_session_component::~Pd_session_component()
|
||||
{
|
||||
if (_pid)
|
||||
lx_kill(_pid, 9);
|
||||
}
|
||||
|
||||
|
||||
int Pd_session_component::bind_thread(Thread_capability) { return -1; }
|
||||
|
||||
|
||||
int Pd_session_component::assign_parent(Parent_capability parent)
|
||||
{
|
||||
_parent = parent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Pd_session_component::start(Capability<Dataspace> binary)
|
||||
void Pd_session_component::_start(Dataspace_component *ds)
|
||||
{
|
||||
const char *tmp_filename = "temporary_executable_elf_dataspace_file_for_execve";
|
||||
|
||||
/* lookup binary dataspace */
|
||||
Object_pool<Dataspace_component>::Guard ds(_ds_ep->lookup_and_lock(binary));
|
||||
|
||||
if (!ds) {
|
||||
PERR("could not lookup binary, aborted PD startup");
|
||||
return; /* XXX reflect error to client */
|
||||
@ -456,4 +394,71 @@ void Pd_session_component::start(Capability<Dataspace> binary)
|
||||
|
||||
if (strcmp(filename, tmp_filename) == 0)
|
||||
lx_unlink(filename);
|
||||
}
|
||||
|
||||
|
||||
Pd_session_component::Pd_session_component(Rpc_entrypoint * ep,
|
||||
Allocator * md_alloc,
|
||||
const char * args)
|
||||
:
|
||||
_pid(0), _uid(0), _gid(0), _ds_ep(ep)
|
||||
{
|
||||
Arg_string::find_arg(args, "label").string(_label, sizeof(_label),
|
||||
"<unlabeled>");
|
||||
|
||||
/*
|
||||
* Read Linux-specific session arguments
|
||||
*/
|
||||
Arg_string::find_arg(args, "root").string(_root, sizeof(_root), "");
|
||||
|
||||
_uid = Arg_string::find_arg(args, "uid").ulong_value(0);
|
||||
_gid = Arg_string::find_arg(args, "gid").ulong_value(0);
|
||||
|
||||
bool const is_chroot = (Genode::strcmp(_root, "") != 0);
|
||||
|
||||
/*
|
||||
* If a UID is specified but no GID, we use the UID as GID. This way, a
|
||||
* configuration error where the UID is defined but the GID is left
|
||||
* undefined won't result in the execution of the new process with the
|
||||
* root user's GID.
|
||||
*/
|
||||
if (_gid == 0)
|
||||
_gid = _uid;
|
||||
|
||||
/*
|
||||
* Print Linux-specific session arguments if specified
|
||||
*
|
||||
* This output used for the automated 'lx_pd_args' test.
|
||||
*/
|
||||
if (is_chroot || _uid || _gid)
|
||||
printf("PD session for '%s'\n", _label);
|
||||
|
||||
if (is_chroot) printf(" root: %s\n", _root);
|
||||
if (_uid) printf(" uid: %u\n", _uid);
|
||||
if (_gid) printf(" gid: %u\n", _gid);
|
||||
}
|
||||
|
||||
|
||||
Pd_session_component::~Pd_session_component()
|
||||
{
|
||||
if (_pid)
|
||||
lx_kill(_pid, 9);
|
||||
}
|
||||
|
||||
|
||||
int Pd_session_component::bind_thread(Thread_capability) { return -1; }
|
||||
|
||||
|
||||
int Pd_session_component::assign_parent(Parent_capability parent)
|
||||
{
|
||||
_parent = parent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Pd_session_component::start(Capability<Dataspace> binary)
|
||||
{
|
||||
/* lookup binary dataspace */
|
||||
_ds_ep->apply(binary, [&] (Dataspace_component *ds) {
|
||||
_start(ds); });
|
||||
};
|
||||
|
@ -193,10 +193,8 @@ Platform_env_base::Rm_session_mmap::_dataspace_size(Capability<Dataspace> ds_cap
|
||||
}
|
||||
|
||||
/* use local function call if called from the entrypoint */
|
||||
Object_pool<Rpc_object_base>::Guard
|
||||
ds_rpc(core_env()->entrypoint()->lookup_and_lock(ds_cap));
|
||||
Dataspace * ds = dynamic_cast<Dataspace *>(&*ds_rpc);
|
||||
return ds ? ds->size() : 0;
|
||||
return core_env()->entrypoint()->apply(ds_cap, [] (Dataspace *ds) {
|
||||
return ds ? ds->size() : 0; });
|
||||
}
|
||||
|
||||
|
||||
@ -212,10 +210,6 @@ int Platform_env_base::Rm_session_mmap::_dataspace_fd(Capability<Dataspace> ds_c
|
||||
|
||||
Capability<Linux_dataspace> lx_ds_cap = static_cap_cast<Linux_dataspace>(ds_cap);
|
||||
|
||||
Object_pool<Rpc_object_base>::Guard
|
||||
ds_rpc(core_env()->entrypoint()->lookup_and_lock(lx_ds_cap));
|
||||
Linux_dataspace * ds = dynamic_cast<Linux_dataspace *>(&*ds_rpc);
|
||||
|
||||
/*
|
||||
* Return a duplicate of the dataspace file descriptor, which will be freed
|
||||
* immediately after mmap'ing the file (see 'Rm_session_mmap').
|
||||
@ -225,7 +219,8 @@ int Platform_env_base::Rm_session_mmap::_dataspace_fd(Capability<Dataspace> ds_c
|
||||
* socket descriptor during the RPC handling). When later destroying the
|
||||
* dataspace, the descriptor would unexpectedly be closed again.
|
||||
*/
|
||||
return ds ? lx_dup(ds->fd().dst().socket) : -1;
|
||||
return core_env()->entrypoint()->apply(lx_ds_cap, [] (Linux_dataspace *ds) {
|
||||
return ds ? lx_dup(ds->fd().dst().socket) : -1; });
|
||||
}
|
||||
|
||||
|
||||
@ -239,9 +234,6 @@ bool Platform_env_base::Rm_session_mmap::_dataspace_writable(Dataspace_capabilit
|
||||
return writable;
|
||||
}
|
||||
|
||||
Object_pool<Rpc_object_base>::Guard
|
||||
ds_rpc(core_env()->entrypoint()->lookup_and_lock(ds_cap));
|
||||
Dataspace * ds = dynamic_cast<Dataspace *>(&*ds_rpc);
|
||||
|
||||
return ds ? ds->writable() : false;
|
||||
return core_env()->entrypoint()->apply(ds_cap, [] (Dataspace *ds) {
|
||||
return ds ? ds->writable() : false; });
|
||||
}
|
||||
|
@ -89,19 +89,7 @@ void Rpc_entrypoint::_dissolve(Rpc_object_base *obj)
|
||||
Nova::revoke(Nova::Obj_crd(obj->cap().local_name(), 0), true);
|
||||
|
||||
/* make sure nobody is able to find this object */
|
||||
remove_locked(obj);
|
||||
|
||||
/*
|
||||
* The activation may execute a blocking operation in a dispatch function.
|
||||
* Before resolving the corresponding object, we need to ensure that it is
|
||||
* no longer used by an activation. Therefore, we to need cancel an
|
||||
* eventually blocking operation and let the activation leave the context
|
||||
* of the object.
|
||||
*/
|
||||
_leave_server_object(obj);
|
||||
|
||||
/* wait until nobody is inside dispatch */
|
||||
obj->acquire();
|
||||
remove(obj);
|
||||
}
|
||||
|
||||
void Rpc_entrypoint::_activation_entry()
|
||||
@ -115,10 +103,9 @@ void Rpc_entrypoint::_activation_entry()
|
||||
|
||||
Rpc_entrypoint *ep = static_cast<Rpc_entrypoint *>(Thread_base::myself());
|
||||
|
||||
/* delay start if requested so */
|
||||
if (ep->_curr_obj) {
|
||||
ep->_delay_start.lock();
|
||||
ep->_delay_start.unlock();
|
||||
{
|
||||
/* potentially delay start */
|
||||
Lock::Guard lock_guard(ep->_delay_start);
|
||||
}
|
||||
|
||||
/* required to decrease ref count of capability used during last reply */
|
||||
@ -134,8 +121,8 @@ void Rpc_entrypoint::_activation_entry()
|
||||
srv.ret(Ipc_client::ERR_INVALID_OBJECT);
|
||||
|
||||
/* atomically lookup and lock referenced object */
|
||||
ep->_curr_obj = ep->lookup_and_lock(id_pt);
|
||||
if (!ep->_curr_obj) {
|
||||
auto lambda = [&] (Rpc_object_base *obj) {
|
||||
if (!obj) {
|
||||
|
||||
/*
|
||||
* Badge is used to suppress error message solely.
|
||||
@ -144,20 +131,15 @@ void Rpc_entrypoint::_activation_entry()
|
||||
*/
|
||||
if (!srv.badge())
|
||||
PERR("could not look up server object, "
|
||||
" return from call id_pt=%lx",
|
||||
id_pt);
|
||||
|
||||
} else {
|
||||
" return from call id_pt=%lx", id_pt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* dispatch request */
|
||||
try { srv.ret(ep->_curr_obj->dispatch(opcode, srv, srv)); }
|
||||
try { srv.ret(obj->dispatch(opcode, srv, srv)); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
Rpc_object_base * tmp = ep->_curr_obj;
|
||||
ep->_curr_obj = 0;
|
||||
|
||||
tmp->release();
|
||||
}
|
||||
};
|
||||
ep->apply(id_pt, lambda);
|
||||
|
||||
if (!ep->_rcv_buf.prepare_rcv_window((Nova::Utcb *)ep->utcb()))
|
||||
PWRN("out of capability selectors for handling server requests");
|
||||
@ -174,30 +156,6 @@ void Rpc_entrypoint::entry()
|
||||
}
|
||||
|
||||
|
||||
void Rpc_entrypoint::_leave_server_object(Rpc_object_base *)
|
||||
{
|
||||
using namespace Nova;
|
||||
|
||||
Utcb *utcb = reinterpret_cast<Utcb *>(Thread_base::myself()->utcb());
|
||||
/* don't call ourself */
|
||||
if (utcb == reinterpret_cast<Utcb *>(this->utcb()))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Required outside of core. E.g. launchpad needs it to forcefully kill
|
||||
* a client which blocks on a session opening request where the service
|
||||
* is not up yet.
|
||||
*/
|
||||
cancel_blocking();
|
||||
|
||||
utcb->msg[0] = 0xdead;
|
||||
utcb->set_msg_word(1);
|
||||
if (uint8_t res = call(_cap.local_name()))
|
||||
PERR("%8p - could not clean up entry point of thread 0x%p - res %u",
|
||||
utcb, this->utcb(), res);
|
||||
}
|
||||
|
||||
|
||||
void Rpc_entrypoint::_block_until_cap_valid() { }
|
||||
|
||||
|
||||
@ -220,7 +178,6 @@ Rpc_entrypoint::Rpc_entrypoint(Cap_session *cap_session, size_t stack_size,
|
||||
Affinity::Location location)
|
||||
:
|
||||
Thread_base(Cpu_session::DEFAULT_WEIGHT, name, stack_size),
|
||||
_curr_obj(start_on_construction ? 0 : (Rpc_object_base *)~0UL),
|
||||
_delay_start(Lock::LOCKED),
|
||||
_cap_session(cap_session)
|
||||
{
|
||||
@ -260,13 +217,10 @@ Rpc_entrypoint::~Rpc_entrypoint()
|
||||
{
|
||||
typedef Object_pool<Rpc_object_base> Pool;
|
||||
|
||||
if (Pool::first()) {
|
||||
Pool::remove_all([&] (Rpc_object_base *obj) {
|
||||
PWRN("Object pool not empty in %s", __func__);
|
||||
|
||||
/* dissolve all objects - objects are not destroyed! */
|
||||
while (Rpc_object_base *obj = Pool::first())
|
||||
_dissolve(obj);
|
||||
}
|
||||
});
|
||||
|
||||
if (!_cap.valid())
|
||||
return;
|
||||
|
@ -32,20 +32,22 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
Rm_session::Local_addr local_addr,
|
||||
bool executable)
|
||||
{
|
||||
Object_pool<Dataspace_component>::Guard ds(_ds_ep->lookup_and_lock(ds_cap));
|
||||
auto lambda = [&] (Dataspace_component *ds) -> Local_addr {
|
||||
if (!ds)
|
||||
throw Invalid_dataspace();
|
||||
|
||||
if (use_local_addr) {
|
||||
PERR("Parameter 'use_local_addr' not supported within core");
|
||||
return 0UL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
PERR("Parameter 'offset' not supported within core");
|
||||
return 0UL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* allocate range in core's virtual address space */
|
||||
return ds->core_local_addr();
|
||||
};
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
@ -23,12 +23,13 @@ using namespace Genode;
|
||||
Native_capability
|
||||
Cpu_session_component::pause_sync(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [] (Cpu_thread_component *thread) {
|
||||
if (!thread || !thread->platform_thread())
|
||||
return Native_capability();
|
||||
|
||||
return thread->platform_thread()->pause();
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -37,12 +38,13 @@ Cpu_session_component::single_step_sync(Thread_capability thread_cap, bool enabl
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [enable] (Cpu_thread_component *thread) {
|
||||
if (!thread || !thread->platform_thread())
|
||||
return Native_capability();
|
||||
|
||||
return thread->platform_thread()->single_step(enable);
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
|
@ -170,7 +170,6 @@ namespace Genode {
|
||||
*/
|
||||
void assign_pd(addr_t pd_sel) { _pd = pd_sel; }
|
||||
addr_t pd_sel() const { return _pd; }
|
||||
void dump_kernel_quota_usage(Pager_object * = (Pager_object *)~0UL);
|
||||
|
||||
void exception(uint8_t exit_id);
|
||||
|
||||
@ -386,12 +385,6 @@ namespace Genode {
|
||||
*/
|
||||
void ep(Pager_entrypoint *ep) { _ep = ep; }
|
||||
|
||||
/*
|
||||
* Used for diagnostic/debugging purposes
|
||||
* - see Pager_object::dump_kernel_quota_usage
|
||||
*/
|
||||
Pager_object * pager_head();
|
||||
|
||||
/**
|
||||
* Thread interface
|
||||
*/
|
||||
|
@ -500,29 +500,6 @@ Exception_handlers::Exception_handlers(Pager_object *obj)
|
||||
******************/
|
||||
|
||||
|
||||
void Pager_object::dump_kernel_quota_usage(Pager_object *obj)
|
||||
{
|
||||
if (obj == (Pager_object *)~0UL) {
|
||||
unsigned use_cpu = location.xpos();
|
||||
obj = pager_threads[use_cpu]->pager_head();
|
||||
PINF("-- kernel memory usage of Genode PDs --");
|
||||
}
|
||||
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
addr_t limit = 0; addr_t usage = 0;
|
||||
Nova::pd_ctrl_debug(obj->pd_sel(), limit, usage);
|
||||
|
||||
char const * thread_name = reinterpret_cast<char const *>(obj->badge());
|
||||
PINF("pd=0x%lx pager=%p thread='%s' limit=0x%lx usage=0x%lx",
|
||||
obj->pd_sel(), obj, thread_name, limit, usage);
|
||||
|
||||
dump_kernel_quota_usage(static_cast<Pager_object *>(obj->child(Genode::Avl_node_base::LEFT)));
|
||||
dump_kernel_quota_usage(static_cast<Pager_object *>(obj->child(Genode::Avl_node_base::RIGHT)));
|
||||
}
|
||||
|
||||
|
||||
Pager_object::Pager_object(unsigned long badge, Affinity::Location location)
|
||||
:
|
||||
_badge(badge),
|
||||
@ -847,9 +824,6 @@ Pager_activation_base::Pager_activation_base(const char *name, size_t stack_size
|
||||
void Pager_activation_base::entry() { }
|
||||
|
||||
|
||||
Pager_object * Pager_activation_base::pager_head() {
|
||||
return _ep ? _ep->first() : nullptr; }
|
||||
|
||||
/**********************
|
||||
** Pager entrypoint **
|
||||
**********************/
|
||||
@ -918,7 +892,7 @@ void Pager_entrypoint::dissolve(Pager_object *obj)
|
||||
/* revoke cap selector locally */
|
||||
revoke(pager_obj.dst(), true);
|
||||
/* remove object from pool */
|
||||
remove_locked(obj);
|
||||
remove(obj);
|
||||
/* take care that no faults are in-flight */
|
||||
obj->cleanup_call();
|
||||
}
|
||||
|
@ -146,9 +146,6 @@ int Platform_thread::start(void *ip, void *sp)
|
||||
KEEP_FREE_PAGES_NOT_AVAILABLE_FOR_UPGRADE, UPPER_LIMIT_PAGES);
|
||||
if (res != NOVA_OK) {
|
||||
PERR("create_pd returned %d", res);
|
||||
|
||||
_pager->dump_kernel_quota_usage();
|
||||
|
||||
goto cleanup_pd;
|
||||
}
|
||||
|
||||
|
@ -87,19 +87,20 @@ Signal_context_capability Signal_session_component::alloc_context(long imprint)
|
||||
|
||||
void Signal_session_component::free_context(Signal_context_capability context_cap)
|
||||
{
|
||||
Signal_context_component * context =
|
||||
dynamic_cast<Signal_context_component *>(_signal_queue.lookup_and_lock(context_cap.local_name()));
|
||||
auto lambda = [&] (Signal_context_component *context) {
|
||||
if (!context) {
|
||||
PWRN("%p - specified signal-context capability has wrong type %lx",
|
||||
this, context_cap.local_name());
|
||||
return;
|
||||
}
|
||||
|
||||
_signal_queue.remove_locked(context);
|
||||
_signal_queue.remove(context);
|
||||
destroy(&_contexts_slab, context);
|
||||
|
||||
Nova::revoke(Nova::Obj_crd(context_cap.local_name(), 0));
|
||||
cap_map()->remove(context_cap.local_name(), 0);
|
||||
};
|
||||
_signal_queue.apply(context_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,23 +26,24 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
{
|
||||
using namespace Okl4;
|
||||
|
||||
Object_pool<Dataspace_component>::Guard ds(_ds_ep->lookup_and_lock(ds_cap));
|
||||
auto lambda = [&] (Dataspace_component *ds) -> void* {
|
||||
if (!ds)
|
||||
throw Invalid_dataspace();
|
||||
|
||||
if (size == 0)
|
||||
size = ds->size();
|
||||
|
||||
size_t page_rounded_size = (size + get_page_size() - 1) & get_page_mask();
|
||||
size_t page_rounded_size = (size + get_page_size() - 1)
|
||||
& get_page_mask();
|
||||
|
||||
if (use_local_addr) {
|
||||
PERR("Parameter 'use_local_addr' not supported within core");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
PERR("Parameter 'offset' not supported within core");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* allocate range in core's virtual address space */
|
||||
@ -50,13 +51,15 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
if (!platform()->region_alloc()->alloc(page_rounded_size, &virt_addr)) {
|
||||
PERR("Could not allocate virtual address range in core of size %zd\n",
|
||||
page_rounded_size);
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* map the dataspace's physical pages to corresponding virtual addresses */
|
||||
unsigned num_pages = page_rounded_size >> get_page_size_log2();
|
||||
if (!map_local(ds->phys_addr(), (addr_t)virt_addr, num_pages))
|
||||
return 0;
|
||||
|
||||
return nullptr;
|
||||
return virt_addr;
|
||||
};
|
||||
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
@ -21,8 +21,9 @@ using namespace Genode;
|
||||
|
||||
void Pd_session_component::space_pager(Thread_capability thread)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
cpu_thread(_thread_ep->lookup_and_lock(thread));
|
||||
_thread_ep->apply(thread, [this] (Cpu_thread_component *cpu_thread)
|
||||
{
|
||||
if (!cpu_thread) return;
|
||||
_pd.space_pager(cpu_thread->platform_thread());
|
||||
});
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ void Ipc_pager::acknowledge_wakeup()
|
||||
** Pager entrypoint **
|
||||
**********************/
|
||||
|
||||
Untyped_capability Pager_entrypoint::_manage(Pager_object *obj)
|
||||
Untyped_capability Pager_entrypoint::_pager_object_cap(unsigned long badge)
|
||||
{
|
||||
return Untyped_capability(_tid.l4id, obj->badge());
|
||||
return Untyped_capability(_tid.l4id, badge);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ void Ipc_pager::acknowledge_wakeup()
|
||||
** Pager entrypoint **
|
||||
**********************/
|
||||
|
||||
Untyped_capability Pager_entrypoint::_manage(Pager_object *obj)
|
||||
Untyped_capability Pager_entrypoint::_pager_object_cap(unsigned long badge)
|
||||
{
|
||||
return Untyped_capability(_tid.l4id, obj->badge());
|
||||
return Untyped_capability(_tid.l4id, badge);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <internal/capability_space_sel4.h>
|
||||
#include <base/rpc_server.h>
|
||||
|
||||
using namespace Genode;
|
||||
@ -65,23 +66,14 @@ void Rpc_entrypoint::entry()
|
||||
srv.ret(Ipc_client::ERR_INVALID_OBJECT);
|
||||
|
||||
/* atomically lookup and lock referenced object */
|
||||
Object_pool<Rpc_object_base>::Guard curr_obj(lookup_and_lock(srv.badge()));
|
||||
if (!curr_obj)
|
||||
continue;
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = curr_obj;
|
||||
}
|
||||
auto lambda = [&] (Rpc_object_base *obj) {
|
||||
if (!obj) return;
|
||||
|
||||
/* dispatch request */
|
||||
try { srv.ret(_curr_obj->dispatch(opcode, srv, srv)); }
|
||||
try { srv.ret(obj->dispatch(opcode, srv, srv)); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = 0;
|
||||
}
|
||||
};
|
||||
apply(srv.badge(), lambda);
|
||||
}
|
||||
|
||||
/* answer exit call, thereby wake up '~Rpc_entrypoint' */
|
||||
@ -89,6 +81,4 @@ void Rpc_entrypoint::entry()
|
||||
|
||||
/* defer the destruction of 'Ipc_server' until '~Rpc_entrypoint' is ready */
|
||||
_delay_exit.lock();
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
Rm_session::Local_addr local_addr,
|
||||
bool executable)
|
||||
{
|
||||
Object_pool<Dataspace_component>::Guard ds(_ds_ep->lookup_and_lock(ds_cap));
|
||||
auto lambda = [&] (Dataspace_component *ds) -> Local_addr {
|
||||
if (!ds)
|
||||
throw Invalid_dataspace();
|
||||
|
||||
@ -39,12 +39,12 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
|
||||
if (use_local_addr) {
|
||||
PERR("Parameter 'use_local_addr' not supported within core");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
PERR("Parameter 'offset' not supported within core");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* allocate range in core's virtual address space */
|
||||
@ -52,7 +52,7 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
if (!platform()->region_alloc()->alloc(page_rounded_size, &virt_addr)) {
|
||||
PERR("Could not allocate virtual address range in core of size %zd\n",
|
||||
page_rounded_size);
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* map the dataspace's physical pages to core-local virtual addresses */
|
||||
@ -60,4 +60,7 @@ Core_rm_session::attach(Dataspace_capability ds_cap, size_t size,
|
||||
map_local(ds->phys_addr(), (addr_t)virt_addr, num_pages);
|
||||
|
||||
return virt_addr;
|
||||
};
|
||||
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
@ -120,14 +120,14 @@ void Pager_object::unresolved_page_fault_occurred()
|
||||
** Pager entrypoint **
|
||||
**********************/
|
||||
|
||||
Untyped_capability Pager_entrypoint::_manage(Pager_object *obj)
|
||||
Untyped_capability Pager_entrypoint::_pager_object_cap(unsigned long badge)
|
||||
{
|
||||
/*
|
||||
* Create minted endpoint capability of the pager entrypoint.
|
||||
* The badge of the page-fault message is used to find the pager
|
||||
* object for faulted thread.
|
||||
*/
|
||||
Rpc_obj_key rpc_obj_key((addr_t)obj->badge());
|
||||
Rpc_obj_key rpc_obj_key((addr_t)badge);
|
||||
|
||||
Untyped_capability ep_cap(Capability_space::create_ep_cap(*this));
|
||||
return Capability_space::create_rpc_obj_cap(ep_cap, nullptr, rpc_obj_key);
|
||||
|
@ -224,6 +224,8 @@ class Genode::Child : protected Rpc_object<Parent>
|
||||
*/
|
||||
void _remove_session(Session *s);
|
||||
|
||||
void _close(Session *s);
|
||||
|
||||
/**
|
||||
* Return service interface targetting the parent
|
||||
*
|
||||
|
@ -1,7 +1,8 @@
|
||||
/*
|
||||
* \brief Object pool - map ids to objects
|
||||
* \brief Object pool - map capabilities to objects
|
||||
* \author Norman Feske
|
||||
* \author Alexander Boettcher
|
||||
* \author Stafen Kalkowski
|
||||
* \date 2006-06-26
|
||||
*/
|
||||
|
||||
@ -23,7 +24,7 @@ namespace Genode { template <typename> class Object_pool; }
|
||||
|
||||
|
||||
/**
|
||||
* Map object ids to local objects
|
||||
* Map capabilities to local objects
|
||||
*
|
||||
* \param OBJ_TYPE object type (must be inherited from Object_pool::Entry)
|
||||
*
|
||||
@ -35,66 +36,25 @@ class Genode::Object_pool
|
||||
{
|
||||
public:
|
||||
|
||||
class Guard
|
||||
{
|
||||
private:
|
||||
|
||||
OBJ_TYPE * _object;
|
||||
|
||||
public:
|
||||
operator OBJ_TYPE*() const { return _object; }
|
||||
OBJ_TYPE * operator->() const { return _object; }
|
||||
OBJ_TYPE * object() const { return _object; }
|
||||
|
||||
template <class X>
|
||||
explicit Guard(X * object) {
|
||||
_object = dynamic_cast<OBJ_TYPE *>(object); }
|
||||
|
||||
~Guard()
|
||||
{
|
||||
if (!_object) return;
|
||||
|
||||
_object->release();
|
||||
}
|
||||
};
|
||||
|
||||
class Entry : public Avl_node<Entry>
|
||||
{
|
||||
private:
|
||||
|
||||
Untyped_capability _cap;
|
||||
short int _ref;
|
||||
bool _dead;
|
||||
|
||||
Lock _entry_lock;
|
||||
Lock _lock;
|
||||
|
||||
inline unsigned long _obj_id() { return _cap.local_name(); }
|
||||
|
||||
friend class Object_pool;
|
||||
friend class Avl_tree<Entry>;
|
||||
|
||||
/*
|
||||
* Support methods for atomic lookup and lock functionality of
|
||||
* class Object_pool.
|
||||
*/
|
||||
|
||||
void lock() { _entry_lock.lock(); };
|
||||
void unlock() { _entry_lock.unlock(); };
|
||||
|
||||
void add_ref() { _ref += 1; }
|
||||
void del_ref() { _ref -= 1; }
|
||||
|
||||
bool is_dead(bool set_dead = false) {
|
||||
return (set_dead ? (_dead = true) : _dead); }
|
||||
bool is_ref_zero() { return _ref <= 0; }
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
Entry() : _ref(0), _dead(false) { }
|
||||
Entry(Untyped_capability cap) : _cap(cap), _ref(0), _dead(false) { }
|
||||
Entry() { }
|
||||
Entry(Untyped_capability cap) : _cap(cap) { }
|
||||
|
||||
/**
|
||||
* Avl_node interface
|
||||
@ -120,12 +80,7 @@ class Genode::Object_pool
|
||||
void cap(Untyped_capability c) { _cap = c; }
|
||||
|
||||
Untyped_capability const cap() const { return _cap; }
|
||||
|
||||
/**
|
||||
* Function used - ideally - solely by the Guard.
|
||||
*/
|
||||
void release() { del_ref(); unlock(); }
|
||||
void acquire() { lock(); add_ref(); }
|
||||
Lock& lock() { return _lock; }
|
||||
};
|
||||
|
||||
private:
|
||||
@ -133,6 +88,58 @@ class Genode::Object_pool
|
||||
Avl_tree<Entry> _tree;
|
||||
Lock _lock;
|
||||
|
||||
OBJ_TYPE* _obj_by_capid(unsigned long capid)
|
||||
{
|
||||
Entry *ret = _tree.first() ? _tree.first()->find_by_obj_id(capid)
|
||||
: nullptr;
|
||||
return static_cast<OBJ_TYPE*>(ret);
|
||||
}
|
||||
|
||||
template <typename FUNC, typename RET>
|
||||
struct Apply_functor
|
||||
{
|
||||
RET operator()(OBJ_TYPE *obj, FUNC f)
|
||||
{
|
||||
using Functor = Trait::Functor<decltype(&FUNC::operator())>;
|
||||
using Object_pointer = typename Functor::template Argument<0>::Type;
|
||||
|
||||
try {
|
||||
auto ret = f(dynamic_cast<Object_pointer>(obj));
|
||||
if (obj) obj->_lock.unlock();
|
||||
return ret;
|
||||
} catch(...) {
|
||||
if (obj) obj->_lock.unlock();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FUNC>
|
||||
struct Apply_functor<FUNC, void>
|
||||
{
|
||||
void operator()(OBJ_TYPE *obj, FUNC f)
|
||||
{
|
||||
using Functor = Trait::Functor<decltype(&FUNC::operator())>;
|
||||
using Object_pointer = typename Functor::template Argument<0>::Type;
|
||||
|
||||
try {
|
||||
f(dynamic_cast<Object_pointer>(obj));
|
||||
if (obj) obj->_lock.unlock();
|
||||
} catch(...) {
|
||||
if (obj) obj->_lock.unlock();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
bool empty()
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
return _tree.first() == nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void insert(OBJ_TYPE *obj)
|
||||
@ -141,74 +148,60 @@ class Genode::Object_pool
|
||||
_tree.insert(obj);
|
||||
}
|
||||
|
||||
void remove_locked(OBJ_TYPE *obj)
|
||||
{
|
||||
obj->is_dead(true);
|
||||
obj->del_ref();
|
||||
|
||||
while (true) {
|
||||
obj->unlock();
|
||||
void remove(OBJ_TYPE *obj)
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
if (obj->is_ref_zero()) {
|
||||
_tree.remove(obj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
obj->lock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup object
|
||||
*/
|
||||
OBJ_TYPE *lookup_and_lock(addr_t obj_id)
|
||||
template <typename FUNC>
|
||||
auto apply(unsigned long capid, FUNC func)
|
||||
-> typename Trait::Functor<decltype(&FUNC::operator())>::Return_type
|
||||
{
|
||||
OBJ_TYPE * obj_typed;
|
||||
using Functor = Trait::Functor<decltype(&FUNC::operator())>;
|
||||
|
||||
OBJ_TYPE * obj;
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
Entry *obj = _tree.first();
|
||||
if (!obj) return 0;
|
||||
|
||||
obj_typed = (OBJ_TYPE *)obj->find_by_obj_id(obj_id);
|
||||
if (!obj_typed || obj_typed->is_dead())
|
||||
return 0;
|
||||
obj = _obj_by_capid(capid);
|
||||
|
||||
obj_typed->add_ref();
|
||||
if (obj) obj->_lock.lock();
|
||||
}
|
||||
|
||||
obj_typed->lock();
|
||||
return obj_typed;
|
||||
Apply_functor<FUNC, typename Functor::Return_type> hf;
|
||||
return hf(obj, func);
|
||||
}
|
||||
|
||||
OBJ_TYPE *lookup_and_lock(Untyped_capability cap)
|
||||
template <typename FUNC>
|
||||
auto apply(Untyped_capability cap, FUNC func)
|
||||
-> typename Trait::Functor<decltype(&FUNC::operator())>::Return_type
|
||||
{
|
||||
return lookup_and_lock(cap.local_name());
|
||||
return apply(cap.local_name(), func);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return first element of tree
|
||||
*
|
||||
* This function is used for removing tree elements step by step.
|
||||
*/
|
||||
OBJ_TYPE *first()
|
||||
template <typename FUNC>
|
||||
void remove_all(FUNC func)
|
||||
{
|
||||
for (;;) {
|
||||
OBJ_TYPE * obj;
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
return (OBJ_TYPE *)_tree.first();
|
||||
|
||||
obj = (OBJ_TYPE*) _tree.first();
|
||||
|
||||
if (!obj) return;
|
||||
|
||||
{
|
||||
Lock::Guard object_guard(obj->_lock);
|
||||
_tree.remove(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return first element of tree locked
|
||||
*
|
||||
* This function is used for removing tree elements step by step.
|
||||
*/
|
||||
OBJ_TYPE *first_locked()
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
OBJ_TYPE * const obj_typed = (OBJ_TYPE *)_tree.first();
|
||||
if (!obj_typed) { return 0; }
|
||||
obj_typed->lock();
|
||||
return obj_typed;
|
||||
func(obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -275,8 +275,6 @@ class Genode::Rpc_entrypoint : Thread_base, public Object_pool<Rpc_object_base>
|
||||
protected:
|
||||
|
||||
Ipc_server *_ipc_server;
|
||||
Rpc_object_base *_curr_obj; /* currently dispatched RPC object */
|
||||
Lock _curr_obj_lock; /* for the protection of '_curr_obj' */
|
||||
Lock _cap_valid; /* thread startup synchronization */
|
||||
Lock _delay_start; /* delay start of request dispatching */
|
||||
Lock _delay_exit; /* delay destructor until server settled */
|
||||
@ -298,13 +296,6 @@ class Genode::Rpc_entrypoint : Thread_base, public Object_pool<Rpc_object_base>
|
||||
*/
|
||||
void _dissolve(Rpc_object_base *obj);
|
||||
|
||||
/**
|
||||
* Force activation to cancel dispatching the specified server object
|
||||
*
|
||||
* \noapi
|
||||
*/
|
||||
void _leave_server_object(Rpc_object_base *obj);
|
||||
|
||||
/**
|
||||
* Wait until the entrypoint activation is initialized
|
||||
*
|
||||
|
@ -248,26 +248,29 @@ class Genode::Root_component : public Rpc_object<Typed_root<SESSION_TYPE> >,
|
||||
{
|
||||
if (!args.is_valid_string()) throw Root::Invalid_args();
|
||||
|
||||
typedef typename Object_pool<SESSION_TYPE>::Guard Object_guard;
|
||||
Object_guard s(_ep->lookup_and_lock(session));
|
||||
_ep->apply(session, [&] (SESSION_TYPE *s) {
|
||||
if (!s) return;
|
||||
|
||||
_upgrade_session(s, args.string());
|
||||
});
|
||||
}
|
||||
|
||||
void close(Session_capability session) override
|
||||
void close(Session_capability session_cap) override
|
||||
{
|
||||
SESSION_TYPE * s =
|
||||
dynamic_cast<SESSION_TYPE *>(_ep->lookup_and_lock(session));
|
||||
if (!s) return;
|
||||
SESSION_TYPE * session;
|
||||
|
||||
_ep->apply(session_cap, [&] (SESSION_TYPE *s) {
|
||||
session = s;
|
||||
|
||||
/* let the entry point forget the session object */
|
||||
_ep->dissolve(s);
|
||||
if (session) _ep->dissolve(session);
|
||||
});
|
||||
|
||||
_destroy_session(s);
|
||||
if (!session) return;
|
||||
|
||||
_destroy_session(session);
|
||||
|
||||
POLICY::release();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,6 +43,23 @@ namespace Genode {
|
||||
|
||||
namespace Meta {
|
||||
|
||||
/***********************************
|
||||
** Variadic template type access **
|
||||
***********************************/
|
||||
|
||||
template <unsigned long N, typename HEAD, typename... TAIL>
|
||||
struct Variadic_type_tuple
|
||||
{
|
||||
using Type = typename Variadic_type_tuple<N-1, TAIL...>::Type;
|
||||
};
|
||||
|
||||
template <typename HEAD, typename... TAIL>
|
||||
struct Variadic_type_tuple<0, HEAD, TAIL...>
|
||||
{
|
||||
using Type = HEAD;
|
||||
};
|
||||
|
||||
|
||||
/***************
|
||||
** Type list **
|
||||
***************/
|
||||
@ -643,6 +660,28 @@ namespace Genode {
|
||||
template <bool VALUE> struct Bool_to_type { enum { V = VALUE }; };
|
||||
|
||||
} /* namespace Meta */
|
||||
|
||||
namespace Trait {
|
||||
|
||||
template<typename T> struct Functor;
|
||||
|
||||
template<typename RET, typename T, typename... ARGS>
|
||||
struct Functor<RET (T::*)(ARGS...) const>
|
||||
{
|
||||
static constexpr unsigned long argument_count = sizeof...(ARGS);
|
||||
|
||||
using Return_type = RET;
|
||||
|
||||
template <unsigned long N>
|
||||
struct Argument
|
||||
{
|
||||
static_assert(N < argument_count, "Invalid index");
|
||||
|
||||
using Type =
|
||||
typename Meta::Variadic_type_tuple<N, ARGS...>::Type;
|
||||
};
|
||||
};
|
||||
} /* namespace Trait */
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__UTIL__META_H_ */
|
||||
|
@ -198,7 +198,6 @@ void Child::_add_session(Child::Session const &s)
|
||||
void Child::_remove_session(Child::Session *s)
|
||||
{
|
||||
/* forget about this session */
|
||||
_session_pool.remove_locked(s);
|
||||
_session_list.remove(s);
|
||||
|
||||
/* return session quota to the ram session of the child */
|
||||
@ -216,6 +215,51 @@ Service *Child::_parent_service()
|
||||
}
|
||||
|
||||
|
||||
void Child::_close(Session* s)
|
||||
{
|
||||
if (!s) {
|
||||
PWRN("no session structure found");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* There is a chance that the server is not responding to the 'close' call,
|
||||
* making us block infinitely. However, by using core's cancel-blocking
|
||||
* mechanism, we can cancel the 'close' call by another (watchdog) thread
|
||||
* that invokes 'cancel_blocking' at our thread after a timeout. The
|
||||
* unblocking is reflected at the API level as an 'Blocking_canceled'
|
||||
* exception. We catch this exception to proceed with normal operation
|
||||
* after being unblocked.
|
||||
*/
|
||||
try { s->service()->close(s->cap()); }
|
||||
catch (Blocking_canceled) {
|
||||
PDBG("Got Blocking_canceled exception during %s->close call\n",
|
||||
s->ident()); }
|
||||
|
||||
/*
|
||||
* If the session was provided by a child of us,
|
||||
* 'server()->ram_session_cap()' returns the RAM session of the
|
||||
* corresponding child. Since the session to the server is closed now, we
|
||||
* expect that the server released all donated resources and we can
|
||||
* decrease the servers' quota.
|
||||
*
|
||||
* If this goes wrong, the server is misbehaving.
|
||||
*/
|
||||
if (s->service()->ram_session_cap().valid()) {
|
||||
Ram_session_client server_ram(s->service()->ram_session_cap());
|
||||
if (server_ram.transfer_quota(env()->ram_session_cap(),
|
||||
s->donated_ram_quota())) {
|
||||
PERR("Misbehaving server '%s'!", s->service()->name());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
_remove_session(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Child::revoke_server(Server const *server)
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
@ -228,6 +272,8 @@ void Child::revoke_server(Server const *server)
|
||||
/* if no matching session exists, we are done */
|
||||
if (!s) return;
|
||||
|
||||
_session_pool.apply(s->cap(), [&] (Session *s) {
|
||||
if (s) _session_pool.remove(s); });
|
||||
_remove_session(s);
|
||||
}
|
||||
}
|
||||
@ -329,7 +375,8 @@ void Child::upgrade(Session_capability to_session, Parent::Upgrade_args const &a
|
||||
targeted_service = &_pd_service;
|
||||
|
||||
/* check if upgrade refers to server */
|
||||
Object_pool<Session>::Guard session(_session_pool.lookup_and_lock(to_session));
|
||||
_session_pool.apply(to_session, [&] (Session *session)
|
||||
{
|
||||
if (session)
|
||||
targeted_service = session->service();
|
||||
|
||||
@ -364,6 +411,7 @@ void Child::upgrade(Session_capability to_session, Parent::Upgrade_args const &a
|
||||
/* finish transaction */
|
||||
donation_from_child.acknowledge();
|
||||
donation_to_service.acknowledge();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -376,46 +424,13 @@ void Child::close(Session_capability session_cap)
|
||||
|| session_cap.local_name() == _pd.local_name())
|
||||
return;
|
||||
|
||||
Session *s = _session_pool.lookup_and_lock(session_cap);
|
||||
|
||||
if (!s) {
|
||||
PWRN("no session structure found");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* There is a chance that the server is not responding to the 'close' call,
|
||||
* making us block infinitely. However, by using core's cancel-blocking
|
||||
* mechanism, we can cancel the 'close' call by another (watchdog) thread
|
||||
* that invokes 'cancel_blocking' at our thread after a timeout. The
|
||||
* unblocking is reflected at the API level as an 'Blocking_canceled'
|
||||
* exception. We catch this exception to proceed with normal operation
|
||||
* after being unblocked.
|
||||
*/
|
||||
try { s->service()->close(s->cap()); }
|
||||
catch (Blocking_canceled) {
|
||||
PDBG("Got Blocking_canceled exception during %s->close call\n",
|
||||
s->ident()); }
|
||||
|
||||
/*
|
||||
* If the session was provided by a child of us,
|
||||
* 'server()->ram_session_cap()' returns the RAM session of the
|
||||
* corresponding child. Since the session to the server is closed now, we
|
||||
* expect that the server released all donated resources and we can
|
||||
* decrease the servers' quota.
|
||||
*
|
||||
* If this goes wrong, the server is misbehaving.
|
||||
*/
|
||||
if (s->service()->ram_session_cap().valid()) {
|
||||
Ram_session_client server_ram(s->service()->ram_session_cap());
|
||||
if (server_ram.transfer_quota(env()->ram_session_cap(),
|
||||
s->donated_ram_quota())) {
|
||||
PERR("Misbehaving server '%s'!", s->service()->name());
|
||||
}
|
||||
}
|
||||
|
||||
Lock::Guard lock_guard(_lock);
|
||||
_remove_session(s);
|
||||
Session *session = nullptr;
|
||||
_session_pool.apply(session_cap, [&] (Session *s)
|
||||
{
|
||||
session = s;
|
||||
if (s) _session_pool.remove(s);
|
||||
});
|
||||
_close(session);
|
||||
}
|
||||
|
||||
|
||||
@ -495,7 +510,6 @@ Child::~Child()
|
||||
_entrypoint->dissolve(this);
|
||||
_policy->unregister_services();
|
||||
|
||||
for (Session *s; (s = _session_pool.first()); )
|
||||
close(s->cap());
|
||||
_session_pool.remove_all([&] (Session *s) { _close(s); });
|
||||
}
|
||||
|
||||
|
@ -22,18 +22,7 @@ using namespace Genode;
|
||||
void Rpc_entrypoint::_dissolve(Rpc_object_base *obj)
|
||||
{
|
||||
/* make sure nobody is able to find this object */
|
||||
remove_locked(obj);
|
||||
|
||||
/*
|
||||
* The activation may execute a blocking operation in a dispatch function.
|
||||
* Before resolving the corresponding object, we need to ensure that it is
|
||||
* no longer used. Therefore, we to need cancel an eventually blocking
|
||||
* operation and let the activation leave the context of the object.
|
||||
*/
|
||||
_leave_server_object(obj);
|
||||
|
||||
/* wait until nobody is inside dispatch */
|
||||
obj->acquire();
|
||||
remove(obj);
|
||||
|
||||
_cap_session->free(obj->cap());
|
||||
|
||||
@ -41,15 +30,6 @@ void Rpc_entrypoint::_dissolve(Rpc_object_base *obj)
|
||||
}
|
||||
|
||||
|
||||
void Rpc_entrypoint::_leave_server_object(Rpc_object_base *obj)
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
|
||||
if (obj == _curr_obj)
|
||||
cancel_blocking();
|
||||
}
|
||||
|
||||
|
||||
void Rpc_entrypoint::_block_until_cap_valid()
|
||||
{
|
||||
_cap_valid.lock();
|
||||
@ -104,7 +84,7 @@ Rpc_entrypoint::Rpc_entrypoint(Cap_session *cap_session, size_t stack_size,
|
||||
:
|
||||
Thread_base(Cpu_session::DEFAULT_WEIGHT, name, stack_size),
|
||||
_cap(Untyped_capability()),
|
||||
_curr_obj(0), _cap_valid(Lock::LOCKED), _delay_start(Lock::LOCKED),
|
||||
_cap_valid(Lock::LOCKED), _delay_start(Lock::LOCKED),
|
||||
_delay_exit(Lock::LOCKED),
|
||||
_cap_session(cap_session)
|
||||
{
|
||||
@ -124,8 +104,6 @@ Rpc_entrypoint::Rpc_entrypoint(Cap_session *cap_session, size_t stack_size,
|
||||
|
||||
Rpc_entrypoint::~Rpc_entrypoint()
|
||||
{
|
||||
typedef Object_pool<Rpc_object_base> Pool;
|
||||
|
||||
/*
|
||||
* We have to make sure the server loop is running which is only the case
|
||||
* if the Rpc_entrypoint was actived before we execute the RPC call.
|
||||
@ -137,14 +115,9 @@ Rpc_entrypoint::~Rpc_entrypoint()
|
||||
|
||||
dissolve(&_exit_handler);
|
||||
|
||||
if (Pool::first()) {
|
||||
if (!empty())
|
||||
PWRN("Object pool not empty in %s", __func__);
|
||||
|
||||
/* dissolve all objects - objects are not destroyed! */
|
||||
while (Rpc_object_base *obj = Pool::first())
|
||||
_dissolve(obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now that we finished the 'dissolve' steps above (which need a working
|
||||
* 'Ipc_server' in the context of the entrypoint thread), we can allow the
|
||||
|
@ -42,6 +42,8 @@ Untyped_capability Rpc_entrypoint::_manage(Rpc_object_base *obj)
|
||||
|
||||
void Rpc_entrypoint::entry()
|
||||
{
|
||||
using Pool = Object_pool<Rpc_object_base>;
|
||||
|
||||
Ipc_server srv(&_snd_buf, &_rcv_buf);
|
||||
_ipc_server = &srv;
|
||||
_cap = srv;
|
||||
@ -65,24 +67,13 @@ void Rpc_entrypoint::entry()
|
||||
/* set default return value */
|
||||
srv.ret(Ipc_client::ERR_INVALID_OBJECT);
|
||||
|
||||
/* atomically lookup and lock referenced object */
|
||||
Object_pool<Rpc_object_base>::Guard curr_obj(lookup_and_lock(srv.badge()));
|
||||
if (!curr_obj)
|
||||
continue;
|
||||
|
||||
Pool::apply(srv.badge(), [&] (Rpc_object_base *obj)
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = curr_obj;
|
||||
}
|
||||
|
||||
/* dispatch request */
|
||||
try { srv.ret(_curr_obj->dispatch(opcode, srv, srv)); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = 0;
|
||||
}
|
||||
if (!obj) { return;}
|
||||
try {
|
||||
srv.ret(obj->dispatch(opcode, srv, srv));
|
||||
} catch(Blocking_canceled&) { }
|
||||
});
|
||||
}
|
||||
|
||||
/* answer exit call, thereby wake up '~Rpc_entrypoint' */
|
||||
|
@ -103,22 +103,23 @@ void Cpu_session_component::_unsynchronized_kill_thread(Cpu_thread_component *th
|
||||
|
||||
void Cpu_session_component::kill_thread(Thread_capability thread_cap)
|
||||
{
|
||||
Cpu_thread_component * thread =
|
||||
dynamic_cast<Cpu_thread_component *>(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
_unsynchronized_kill_thread(thread);
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
int Cpu_session_component::set_pager(Thread_capability thread_cap,
|
||||
Pager_capability pager_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) return -1;
|
||||
|
||||
Object_pool<Pager_object>::Guard p(_pager_ep->lookup_and_lock(pager_cap));
|
||||
auto p_lambda = [&] (Pager_object *p) {
|
||||
if (!p) return -2;
|
||||
|
||||
thread->platform_thread()->pager(p);
|
||||
@ -126,13 +127,17 @@ int Cpu_session_component::set_pager(Thread_capability thread_cap,
|
||||
p->thread_cap(thread->cap());
|
||||
|
||||
return 0;
|
||||
};
|
||||
return _pager_ep->apply(pager_cap, p_lambda);
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
int Cpu_session_component::start(Thread_capability thread_cap,
|
||||
addr_t ip, addr_t sp)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) return -1;
|
||||
|
||||
/*
|
||||
@ -142,52 +147,64 @@ int Cpu_session_component::start(Thread_capability thread_cap,
|
||||
thread->update_exception_sigh();
|
||||
|
||||
return thread->platform_thread()->start((void *)ip, (void *)sp);
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
void Cpu_session_component::pause(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
thread->platform_thread()->pause();
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
void Cpu_session_component::resume(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
thread->platform_thread()->resume();
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
void Cpu_session_component::cancel_blocking(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
thread->platform_thread()->cancel_blocking();
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
Thread_state Cpu_session_component::state(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) throw State_access_failed();
|
||||
|
||||
return thread->platform_thread()->state();
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
void Cpu_session_component::state(Thread_capability thread_cap,
|
||||
Thread_state const &state)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) throw State_access_failed();
|
||||
|
||||
thread->platform_thread()->state(state);
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -212,10 +229,12 @@ Cpu_session_component::exception_handler(Thread_capability thread_cap,
|
||||
sigh_cap = _default_exception_handler;
|
||||
}
|
||||
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
thread->sigh(sigh_cap);
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -232,7 +251,7 @@ Affinity::Space Cpu_session_component::affinity_space() const
|
||||
void Cpu_session_component::affinity(Thread_capability thread_cap,
|
||||
Affinity::Location location)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *thread) {
|
||||
if (!thread) return;
|
||||
|
||||
/* convert session-local location to physical location */
|
||||
@ -249,6 +268,8 @@ void Cpu_session_component::affinity(Thread_capability thread_cap,
|
||||
thread->platform_thread()->affinity(Affinity::Location(clipped_x1, clipped_y1,
|
||||
clipped_x2 - clipped_x1 + 1,
|
||||
clipped_y2 - clipped_y1 + 1));
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -260,28 +281,34 @@ Dataspace_capability Cpu_session_component::trace_control()
|
||||
|
||||
unsigned Cpu_session_component::trace_control_index(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [] (Cpu_thread_component *thread) -> unsigned {
|
||||
if (!thread) return 0;
|
||||
|
||||
return thread->trace_control_index();
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
Dataspace_capability Cpu_session_component::trace_buffer(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) return Dataspace_capability();
|
||||
|
||||
return thread->trace_source()->buffer();
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
Dataspace_capability Cpu_session_component::trace_policy(Thread_capability thread_cap)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [this] (Cpu_thread_component *thread) {
|
||||
if (!thread) return Dataspace_capability();
|
||||
|
||||
return thread->trace_source()->policy();
|
||||
};
|
||||
return _thread_ep->apply(thread_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -309,8 +336,7 @@ int Cpu_session_component::transfer_quota(Cpu_session_capability dst_cap,
|
||||
size_t amount)
|
||||
{
|
||||
/* lookup targeted CPU session */
|
||||
Object_pool<Cpu_session_component>::Guard
|
||||
dst(_session_ep->lookup_and_lock(dst_cap));
|
||||
auto lambda = [&] (Cpu_session_component *dst) {
|
||||
if (!dst) {
|
||||
PWRN("Transfer CPU quota, %s, targeted session not found",
|
||||
_label.string());
|
||||
@ -332,6 +358,8 @@ int Cpu_session_component::transfer_quota(Cpu_session_capability dst_cap,
|
||||
/* transfer quota */
|
||||
_transfer_quota(dst, quota);
|
||||
return 0;
|
||||
};
|
||||
return _session_ep->apply(dst_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -348,8 +376,7 @@ int Cpu_session_component::ref_account(Cpu_session_capability ref_cap)
|
||||
return -2; }
|
||||
|
||||
/* lookup and check targeted CPU-session */
|
||||
Object_pool<Cpu_session_component>::Guard
|
||||
ref(_session_ep->lookup_and_lock(ref_cap));
|
||||
auto lambda = [&] (Cpu_session_component *ref) {
|
||||
if (!ref) {
|
||||
PWRN("Set ref account, %s, targeted session not found",
|
||||
_label.string());
|
||||
@ -364,6 +391,8 @@ int Cpu_session_component::ref_account(Cpu_session_capability ref_cap)
|
||||
_ref = ref;
|
||||
_ref->_insert_ref_member(this);
|
||||
return 0;
|
||||
};
|
||||
return _session_ep->apply(ref_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,12 +41,13 @@ namespace Genode {
|
||||
Local_addr local_addr = 0,
|
||||
bool executable = false)
|
||||
{
|
||||
Object_pool<Dataspace_component>::Guard
|
||||
ds(_ds_ep->lookup_and_lock(ds_cap));
|
||||
auto lambda = [] (Dataspace_component *ds) {
|
||||
if (!ds)
|
||||
throw Invalid_dataspace();
|
||||
|
||||
return (void *)ds->phys_addr();
|
||||
};
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
||||
void detach(Local_addr local_addr) { }
|
||||
|
@ -134,7 +134,7 @@ class Genode::Pager_entrypoint : public Object_pool<Pager_object>,
|
||||
Ipc_pager _pager;
|
||||
Cap_session *_cap_session;
|
||||
|
||||
Untyped_capability _manage(Pager_object *obj);
|
||||
Untyped_capability _pager_object_cap(unsigned long badge);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -56,10 +56,10 @@ namespace Genode {
|
||||
Session_capability cap = Root_component<Rm_session_component>::session(args, affinity);
|
||||
|
||||
/* lookup rm_session_component object */
|
||||
Object_pool<Rm_session_component>::Guard rm_session(ep()->lookup_and_lock(cap));
|
||||
auto lambda = [] (Rm_session_component *rm_session) {
|
||||
if (!rm_session)
|
||||
/* should never happen */
|
||||
return cap;
|
||||
return;
|
||||
|
||||
/**
|
||||
* Assign rm_session capability to dataspace component. It can
|
||||
@ -68,6 +68,8 @@ namespace Genode {
|
||||
*/
|
||||
if (rm_session->dataspace_component())
|
||||
rm_session->dataspace_component()->sub_rm_session(rm_session->cap());
|
||||
};
|
||||
ep()->apply(cap, lambda);
|
||||
return cap;
|
||||
}
|
||||
|
||||
|
@ -282,6 +282,43 @@ namespace Genode {
|
||||
Rm_dataspace_component _ds; /* dataspace representation of region map */
|
||||
Dataspace_capability _ds_cap;
|
||||
|
||||
template <typename F>
|
||||
auto _apply_to_dataspace(addr_t addr, F f, addr_t offset, unsigned level)
|
||||
-> typename Trait::Functor<decltype(&F::operator())>::Return_type
|
||||
{
|
||||
using Functor = Trait::Functor<decltype(&F::operator())>;
|
||||
using Return_type = typename Functor::Return_type;
|
||||
|
||||
Lock::Guard lock_guard(_lock);
|
||||
|
||||
/* skip further lookup when reaching the recursion limit */
|
||||
if (!level) return f(this, nullptr, 0, 0);
|
||||
|
||||
/* lookup region and dataspace */
|
||||
Rm_region *region = _map.metadata((void*)addr);
|
||||
Dataspace_component *dsc = region ? region->dataspace()
|
||||
: nullptr;
|
||||
|
||||
/* calculate offset in dataspace */
|
||||
addr_t ds_offset = region ? (addr - region->base()
|
||||
+ region->offset()) : 0;
|
||||
|
||||
/* check for nested dataspace */
|
||||
Native_capability cap = dsc ? dsc->sub_rm_session()
|
||||
: Native_capability();
|
||||
if (!cap.valid()) return f(this, region, ds_offset, offset);
|
||||
|
||||
/* in case of a nested dataspace perform a recursive lookup */
|
||||
auto lambda = [&] (Rm_session_component *rsc) -> Return_type
|
||||
{
|
||||
return (!rsc) ? f(nullptr, nullptr, ds_offset, offset)
|
||||
: rsc->_apply_to_dataspace(ds_offset, f,
|
||||
offset+region->base(),
|
||||
--level);
|
||||
};
|
||||
return _session_ep->apply(cap, lambda);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -300,17 +337,6 @@ namespace Genode {
|
||||
|
||||
class Fault_area;
|
||||
|
||||
/**
|
||||
* Reversely lookup dataspace and offset matching the specified address
|
||||
*
|
||||
* \return true lookup succeeded
|
||||
*/
|
||||
bool reverse_lookup(addr_t dst_base,
|
||||
Fault_area *dst_fault_region,
|
||||
Dataspace_component **src_dataspace,
|
||||
Fault_area *src_fault_region,
|
||||
Rm_session_component **sub_rm_session);
|
||||
|
||||
/**
|
||||
* Register fault
|
||||
*
|
||||
@ -341,6 +367,20 @@ namespace Genode {
|
||||
*/
|
||||
void upgrade_ram_quota(size_t ram_quota) { _md_alloc.upgrade(ram_quota); }
|
||||
|
||||
/**
|
||||
* Apply a function to dataspace attached at a given address
|
||||
*
|
||||
* /param addr address where the dataspace is attached
|
||||
* /param f functor or lambda to apply
|
||||
*/
|
||||
template <typename F>
|
||||
auto apply_to_dataspace(addr_t addr, F f)
|
||||
-> typename Trait::Functor<decltype(&F::operator())>::Return_type
|
||||
{
|
||||
enum { RECURSION_LIMIT = 5 };
|
||||
|
||||
return _apply_to_dataspace(addr, f, 0, RECURSION_LIMIT);
|
||||
}
|
||||
|
||||
/**************************************
|
||||
** Region manager session interface **
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* \brief Generic implmentation of pager entrypoint
|
||||
* \brief Generic implementation of pager entrypoint
|
||||
* \author Norman Feske
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2009-03-31
|
||||
@ -20,6 +20,8 @@ using namespace Genode;
|
||||
|
||||
void Pager_entrypoint::entry()
|
||||
{
|
||||
using Pool = Object_pool<Pager_object>;
|
||||
|
||||
bool reply_pending = false;
|
||||
|
||||
while (1) {
|
||||
@ -31,21 +33,13 @@ void Pager_entrypoint::entry()
|
||||
|
||||
reply_pending = false;
|
||||
|
||||
/* lookup referenced object */
|
||||
Object_pool<Pager_object>::Guard _obj(lookup_and_lock(_pager.badge()));
|
||||
Pager_object *obj = _obj;
|
||||
|
||||
/* handle request */
|
||||
Pool::apply(_pager.badge(), [&] (Pager_object *obj) {
|
||||
if (obj) {
|
||||
if (_pager.is_exception()) {
|
||||
if (_pager.is_exception())
|
||||
obj->submit_exception_signal();
|
||||
continue;
|
||||
}
|
||||
|
||||
else
|
||||
/* send reply if page-fault handling succeeded */
|
||||
reply_pending = !obj->pager(_pager);
|
||||
continue;
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
@ -80,19 +74,22 @@ void Pager_entrypoint::entry()
|
||||
_pager.acknowledge_wakeup();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Pager_entrypoint::dissolve(Pager_object *obj)
|
||||
{
|
||||
remove_locked(obj);
|
||||
using Pool = Object_pool<Pager_object>;
|
||||
|
||||
if (obj) Pool::remove(obj);
|
||||
}
|
||||
|
||||
|
||||
Pager_capability Pager_entrypoint::manage(Pager_object *obj)
|
||||
{
|
||||
Native_capability cap = _manage(obj);
|
||||
Native_capability cap = _pager_object_cap(obj->badge());
|
||||
|
||||
/* add server object to object pool */
|
||||
obj->cap(cap);
|
||||
|
@ -26,7 +26,7 @@ using namespace Genode;
|
||||
|
||||
int Pd_session_component::bind_thread(Thread_capability thread)
|
||||
{
|
||||
Object_pool<Cpu_thread_component>::Guard cpu_thread(_thread_ep->lookup_and_lock(thread));
|
||||
return _thread_ep->apply(thread, [&] (Cpu_thread_component *cpu_thread) {
|
||||
if (!cpu_thread) return -1;
|
||||
|
||||
if (cpu_thread->bound()) {
|
||||
@ -43,6 +43,7 @@ int Pd_session_component::bind_thread(Thread_capability thread)
|
||||
|
||||
cpu_thread->bound(true);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,9 +26,12 @@ static const bool verbose = false;
|
||||
|
||||
addr_t Ram_session_component::phys_addr(Ram_dataspace_capability ds)
|
||||
{
|
||||
Object_pool<Dataspace_component>::Guard dsc(_ds_ep->lookup_and_lock(ds));
|
||||
auto lambda = [] (Dataspace_component *dsc) {
|
||||
if (!dsc) throw Invalid_dataspace();
|
||||
return dsc->phys_addr();
|
||||
};
|
||||
|
||||
return _ds_ep->apply(ds, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -217,12 +220,12 @@ Ram_dataspace_capability Ram_session_component::alloc(size_t ds_size, Cache_attr
|
||||
|
||||
void Ram_session_component::free(Ram_dataspace_capability ds_cap)
|
||||
{
|
||||
Dataspace_component * ds =
|
||||
dynamic_cast<Dataspace_component *>(_ds_ep->lookup_and_lock(ds_cap));
|
||||
if (!ds)
|
||||
return;
|
||||
|
||||
auto lambda = [this] (Dataspace_component *ds) {
|
||||
if (!ds) return;
|
||||
_free_ds(ds);
|
||||
};
|
||||
|
||||
_ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -231,7 +234,7 @@ int Ram_session_component::ref_account(Ram_session_capability ram_session_cap)
|
||||
/* the reference account cannot be defined twice */
|
||||
if (_ref_account) return -2;
|
||||
|
||||
Object_pool<Ram_session_component>::Guard ref(_ram_session_ep->lookup_and_lock(ram_session_cap));
|
||||
auto lambda = [this] (Ram_session_component *ref) {
|
||||
|
||||
/* check if recipient is a valid Ram_session_component */
|
||||
if (!ref) return -1;
|
||||
@ -243,6 +246,9 @@ int Ram_session_component::ref_account(Ram_session_capability ram_session_cap)
|
||||
_ref_account = ref;
|
||||
_ref_account->_register_ref_account_member(this);
|
||||
return 0;
|
||||
};
|
||||
|
||||
return _ram_session_ep->apply(ram_session_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -252,8 +258,9 @@ int Ram_session_component::transfer_quota(Ram_session_capability ram_session_cap
|
||||
if (verbose)
|
||||
PDBG("amount=%zu", amount);
|
||||
|
||||
Object_pool<Ram_session_component>::Guard dst(_ram_session_ep->lookup_and_lock(ram_session_cap));
|
||||
return _transfer_quota(dst, amount);
|
||||
auto lambda = [&] (Ram_session_component *dst) {
|
||||
return _transfer_quota(dst, amount); };
|
||||
return _ram_session_ep->apply(ram_session_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
|
@ -165,6 +165,8 @@ namespace Genode {
|
||||
|
||||
int Rm_client::pager(Ipc_pager &pager)
|
||||
{
|
||||
using Fault_area = Rm_session_component::Fault_area;
|
||||
|
||||
Rm_session::Fault_type pf_type = pager.is_write_fault() ? Rm_session::WRITE_FAULT
|
||||
: Rm_session::READ_FAULT;
|
||||
addr_t pf_addr = pager.fault_addr();
|
||||
@ -173,68 +175,13 @@ int Rm_client::pager(Ipc_pager &pager)
|
||||
if (verbose_page_faults)
|
||||
print_page_fault("page fault", pf_addr, pf_ip, pf_type, badge());
|
||||
|
||||
Rm_session_component *curr_rm_session = member_rm_session();
|
||||
Rm_session_component *sub_rm_session = 0;
|
||||
addr_t curr_rm_base = 0;
|
||||
Dataspace_component *src_dataspace = 0;
|
||||
Rm_session_component::Fault_area src_fault_area;
|
||||
Rm_session_component::Fault_area dst_fault_area(pf_addr);
|
||||
bool lookup;
|
||||
|
||||
unsigned level;
|
||||
enum { MAX_NESTING_LEVELS = 5 };
|
||||
|
||||
/* helper guard to release the rm_session lock on return */
|
||||
class Guard {
|
||||
private:
|
||||
|
||||
Rm_session_component ** _release_session;
|
||||
unsigned * _level;
|
||||
|
||||
public:
|
||||
|
||||
explicit Guard(Rm_session_component ** rs, unsigned * level)
|
||||
: _release_session(rs), _level(level) {}
|
||||
|
||||
~Guard() {
|
||||
if ((*_level > 0) && (*_release_session))
|
||||
(*_release_session)->release();
|
||||
}
|
||||
} release_guard(&curr_rm_session, &level);
|
||||
|
||||
/* traverse potentially nested dataspaces until we hit a leaf dataspace */
|
||||
for (level = 0; level < MAX_NESTING_LEVELS; level++) {
|
||||
lookup = curr_rm_session->reverse_lookup(curr_rm_base,
|
||||
&dst_fault_area,
|
||||
&src_dataspace,
|
||||
&src_fault_area,
|
||||
&sub_rm_session);
|
||||
/* check if we need to traverse into a nested dataspace */
|
||||
if (!sub_rm_session)
|
||||
break;
|
||||
|
||||
if (!lookup) {
|
||||
sub_rm_session->release();
|
||||
break;
|
||||
}
|
||||
|
||||
/* set up next iteration */
|
||||
|
||||
curr_rm_base = dst_fault_area.fault_addr()
|
||||
- src_fault_area.fault_addr() + src_dataspace->map_src_addr();
|
||||
|
||||
if (level > 0)
|
||||
curr_rm_session->release();
|
||||
curr_rm_session = sub_rm_session;
|
||||
sub_rm_session = 0;
|
||||
}
|
||||
|
||||
if (level == MAX_NESTING_LEVELS) {
|
||||
PWRN("Too many nesting levels of managed dataspaces");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!lookup) {
|
||||
auto lambda = [&] (Rm_session_component *rm_session,
|
||||
Rm_region *region,
|
||||
addr_t ds_offset,
|
||||
addr_t region_offset) -> int
|
||||
{
|
||||
Dataspace_component * dsc = region ? region->dataspace() : nullptr;
|
||||
if (!dsc) {
|
||||
|
||||
/*
|
||||
* We found no attachment at the page-fault address and therefore have
|
||||
@ -244,15 +191,24 @@ int Rm_client::pager(Ipc_pager &pager)
|
||||
*/
|
||||
|
||||
/* print a warning if it's no managed-dataspace */
|
||||
if (curr_rm_session == member_rm_session())
|
||||
print_page_fault("no RM attachment", pf_addr, pf_ip, pf_type, badge());
|
||||
if (rm_session == member_rm_session())
|
||||
print_page_fault("no RM attachment", pf_addr, pf_ip,
|
||||
pf_type, badge());
|
||||
|
||||
/* register fault at responsible region-manager session */
|
||||
curr_rm_session->fault(this, dst_fault_area.fault_addr() - curr_rm_base, pf_type);
|
||||
if (rm_session)
|
||||
rm_session->fault(this, pf_addr - region_offset, pf_type);
|
||||
|
||||
/* there is no attachment return an error condition */
|
||||
return 1;
|
||||
}
|
||||
|
||||
addr_t ds_base = dsc->map_src_addr();
|
||||
Fault_area src_fault_area(ds_base + ds_offset);
|
||||
Fault_area dst_fault_area(pf_addr);
|
||||
src_fault_area.constrain(ds_base, dsc->size());
|
||||
dst_fault_area.constrain(region_offset + region->base(), region->size());
|
||||
|
||||
/*
|
||||
* Determine mapping size compatible with source and destination,
|
||||
* and apply platform-specific constraint of mapping sizes.
|
||||
@ -263,27 +219,26 @@ int Rm_client::pager(Ipc_pager &pager)
|
||||
|
||||
src_fault_area.constrain(map_size_log2);
|
||||
dst_fault_area.constrain(map_size_log2);
|
||||
if (!src_fault_area.valid() || !dst_fault_area.valid())
|
||||
PERR("Invalid mapping");
|
||||
|
||||
/*
|
||||
* Check if dataspace is compatible with page-fault type
|
||||
*/
|
||||
if (pf_type == Rm_session::WRITE_FAULT && !src_dataspace->writable()) {
|
||||
if (pf_type == Rm_session::WRITE_FAULT && !dsc->writable()) {
|
||||
|
||||
/* attempted there is no attachment return an error condition */
|
||||
print_page_fault("attempted write at read-only memory",
|
||||
pf_addr, pf_ip, pf_type, badge());
|
||||
|
||||
/* register fault at responsible region-manager session */
|
||||
curr_rm_session->fault(this, src_fault_area.fault_addr(), pf_type);
|
||||
rm_session->fault(this, src_fault_area.fault_addr(), pf_type);
|
||||
return 2;
|
||||
}
|
||||
|
||||
Mapping mapping(dst_fault_area.base(),
|
||||
src_fault_area.base(),
|
||||
src_dataspace->cacheability(),
|
||||
src_dataspace->is_io_mem(),
|
||||
map_size_log2,
|
||||
src_dataspace->writable());
|
||||
Mapping mapping(dst_fault_area.base(), src_fault_area.base(),
|
||||
dsc->cacheability(), dsc->is_io_mem(),
|
||||
map_size_log2, dsc->writable());
|
||||
|
||||
/*
|
||||
* On kernels with a mapping database, the 'dsc' dataspace is a leaf
|
||||
@ -293,12 +248,14 @@ int Rm_client::pager(Ipc_pager &pager)
|
||||
* pages that are not locally mapped, the 'map_core_local' function may be
|
||||
* empty.
|
||||
*/
|
||||
if (!src_dataspace->is_io_mem())
|
||||
if (!dsc->is_io_mem())
|
||||
mapping.prepare_map_operation();
|
||||
|
||||
/* answer page fault with a flex-page mapping */
|
||||
pager.set_reply_mapping(mapping);
|
||||
return 0;
|
||||
};
|
||||
return member_rm_session()->apply_to_dataspace(pf_addr, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -357,8 +314,8 @@ Rm_session_component::attach(Dataspace_capability ds_cap, size_t size,
|
||||
if (offset < 0 || align_addr(offset, get_page_size_log2()) != offset)
|
||||
throw Invalid_args();
|
||||
|
||||
auto lambda = [&] (Dataspace_component *dsc) {
|
||||
/* check dataspace validity */
|
||||
Object_pool<Dataspace_component>::Guard dsc(_ds_ep->lookup_and_lock(ds_cap));
|
||||
if (!dsc) throw Invalid_dataspace();
|
||||
|
||||
if (!size)
|
||||
@ -441,7 +398,8 @@ Rm_session_component::attach(Dataspace_capability ds_cap, size_t size,
|
||||
|
||||
if (verbose)
|
||||
PDBG("attach ds %p (a=%lx,s=%zx,o=%lx) @ [%lx,%lx)",
|
||||
(Dataspace_component *)dsc, dsc->phys_addr(), dsc->size(), offset, (addr_t)r, (addr_t)r + size);
|
||||
(Dataspace_component *)dsc, dsc->phys_addr(), dsc->size(),
|
||||
offset, (addr_t)r, (addr_t)r + size);
|
||||
|
||||
/* check if attach operation resolves any faulting region-manager clients */
|
||||
for (Rm_faulter *faulter = _faulters.head(); faulter; ) {
|
||||
@ -458,6 +416,9 @@ Rm_session_component::attach(Dataspace_capability ds_cap, size_t size,
|
||||
}
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
return _ds_ep->apply(ds_cap, lambda);
|
||||
}
|
||||
|
||||
|
||||
@ -612,8 +573,7 @@ Pager_capability Rm_session_component::add_client(Thread_capability thread)
|
||||
|
||||
{
|
||||
/* lookup thread and setup correct parameters */
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
cpu_thread(_thread_ep->lookup_and_lock(thread));
|
||||
auto lambda = [&] (Cpu_thread_component *cpu_thread) {
|
||||
if (!cpu_thread) throw Invalid_thread();
|
||||
|
||||
/* determine identification of client when faulting */
|
||||
@ -625,6 +585,8 @@ Pager_capability Rm_session_component::add_client(Thread_capability thread)
|
||||
address_space = cpu_thread->platform_thread()->address_space();
|
||||
if (!Locked_ptr<Address_space>(address_space).is_valid())
|
||||
throw Unbound_thread();
|
||||
};
|
||||
_thread_ep->apply(thread, lambda);
|
||||
}
|
||||
|
||||
/* serialize access */
|
||||
@ -644,9 +606,12 @@ Pager_capability Rm_session_component::add_client(Thread_capability thread)
|
||||
|
||||
void Rm_session_component::remove_client(Pager_capability pager_cap)
|
||||
{
|
||||
Rm_client *client;
|
||||
|
||||
Rm_client * cl = dynamic_cast<Rm_client *>(_pager_ep->lookup_and_lock(pager_cap));
|
||||
if (!cl) return;
|
||||
auto lambda = [&] (Rm_client *cl) {
|
||||
client = cl;
|
||||
|
||||
if (!client) return;
|
||||
|
||||
/*
|
||||
* Rm_client is derived from Pager_object. If the Pager_object is also
|
||||
@ -660,96 +625,26 @@ void Rm_session_component::remove_client(Pager_capability pager_cap)
|
||||
*/
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
_clients.remove(cl);
|
||||
_clients.remove(client);
|
||||
}
|
||||
|
||||
/* call platform specific dissolve routines */
|
||||
_pager_ep->dissolve(cl);
|
||||
_pager_ep->dissolve(client);
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
cl->dissolve_from_faulting_rm_session(this);
|
||||
client->dissolve_from_faulting_rm_session(this);
|
||||
}
|
||||
};
|
||||
_pager_ep->apply(pager_cap, lambda);
|
||||
|
||||
destroy(&_client_slab, cl);
|
||||
}
|
||||
|
||||
|
||||
bool Rm_session_component::reverse_lookup(addr_t dst_base,
|
||||
Fault_area *dst_fault_area,
|
||||
Dataspace_component **src_dataspace,
|
||||
Fault_area *src_fault_area,
|
||||
Rm_session_component **sub_rm_session)
|
||||
{
|
||||
/* serialize access */
|
||||
Lock::Guard lock_guard(_lock);
|
||||
|
||||
/* rm-session-relative fault address */
|
||||
addr_t fault_addr = dst_fault_area->fault_addr() - dst_base;
|
||||
|
||||
/* lookup region */
|
||||
Rm_region *region = _map.metadata((void*)fault_addr);
|
||||
if (!region)
|
||||
return false;
|
||||
|
||||
/* request dataspace backing the region */
|
||||
*src_dataspace = region->dataspace();
|
||||
if (!*src_dataspace)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Constrain destination fault area to region
|
||||
*
|
||||
* Handle corner case when the 'dst_base' is negative. In this case, we
|
||||
* determine the largest flexpage within the positive portion of the
|
||||
* region.
|
||||
*/
|
||||
addr_t region_base = region->base() + dst_base;
|
||||
size_t region_size = region->size();
|
||||
|
||||
/* check for overflow condition */
|
||||
while ((long)region_base < 0 && (long)(region_base + region_size) > 0) {
|
||||
|
||||
/* increment base address by half of the region size */
|
||||
region_base += region_size >> 1;
|
||||
|
||||
/* lower the region size by one log2 step */
|
||||
region_size >>= 1;
|
||||
}
|
||||
dst_fault_area->constrain(region_base, region_size);
|
||||
|
||||
/* calculate source fault address relative to 'src_dataspace' */
|
||||
addr_t src_fault_offset = fault_addr - region->base() + region->offset();
|
||||
|
||||
addr_t src_base = (*src_dataspace)->map_src_addr();
|
||||
*src_fault_area = Fault_area(src_base + src_fault_offset);
|
||||
|
||||
/* constrain source fault area by the source dataspace dimensions */
|
||||
src_fault_area->constrain(src_base, (*src_dataspace)->size());
|
||||
|
||||
if (!src_fault_area->valid() || !dst_fault_area->valid())
|
||||
return false;
|
||||
|
||||
/* lookup and lock nested dataspace if required */
|
||||
Native_capability session_cap = (*src_dataspace)->sub_rm_session();
|
||||
if (session_cap.valid()) {
|
||||
*sub_rm_session = dynamic_cast<Rm_session_component *>(_session_ep->lookup_and_lock(session_cap));
|
||||
return (*sub_rm_session != 0);
|
||||
}
|
||||
|
||||
/* loop refer to leaf */
|
||||
*sub_rm_session = 0;
|
||||
return true;
|
||||
destroy(&_client_slab, client);
|
||||
}
|
||||
|
||||
|
||||
void Rm_session_component::fault(Rm_faulter *faulter, addr_t pf_addr,
|
||||
Rm_session::Fault_type pf_type)
|
||||
{
|
||||
|
||||
/* serialize access */
|
||||
Lock::Guard lock_guard(_lock);
|
||||
|
||||
/* remember fault state in faulting thread */
|
||||
faulter->fault(this, Rm_session::State(pf_type, pf_addr));
|
||||
|
||||
@ -869,13 +764,12 @@ Rm_session_component::~Rm_session_component()
|
||||
|
||||
_lock.unlock();
|
||||
|
||||
{
|
||||
/* lookup thread and reset pager pointer */
|
||||
Object_pool<Cpu_thread_component>::Guard
|
||||
cpu_thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
auto lambda = [&] (Cpu_thread_component *cpu_thread) {
|
||||
if (cpu_thread && (cpu_thread->platform_thread()->pager() == cl))
|
||||
cpu_thread->platform_thread()->pager(0);
|
||||
}
|
||||
};
|
||||
_thread_ep->apply(thread_cap, lambda);
|
||||
|
||||
destroy(&_client_slab, cl);
|
||||
|
||||
|
@ -71,8 +71,7 @@ Signal_context_capability Signal_session_component::alloc_context(long imprint)
|
||||
|
||||
void Signal_session_component::free_context(Signal_context_capability context_cap)
|
||||
{
|
||||
Signal_context_component * context =
|
||||
dynamic_cast<Signal_context_component *>(_context_ep->lookup_and_lock(context_cap));
|
||||
_context_ep->apply(context_cap, [this] (Signal_context_component *context) {
|
||||
if (!context) {
|
||||
PWRN("specified signal-context capability has wrong type");
|
||||
return;
|
||||
@ -80,14 +79,14 @@ void Signal_session_component::free_context(Signal_context_capability context_ca
|
||||
|
||||
_context_ep->dissolve(context);
|
||||
destroy(&_contexts_slab, context);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void Signal_session_component::submit(Signal_context_capability context_cap,
|
||||
unsigned cnt)
|
||||
{
|
||||
Object_pool<Signal_context_component>::Guard
|
||||
context(_context_ep->lookup_and_lock(context_cap));
|
||||
_context_ep->apply(context_cap, [&] (Signal_context_component *context) {
|
||||
if (!context) {
|
||||
/*
|
||||
* We do not use PWRN() to enable the build system to suppress this
|
||||
@ -98,6 +97,7 @@ void Signal_session_component::submit(Signal_context_capability context_cap,
|
||||
}
|
||||
|
||||
context->source()->submit(context, _ipc_ostream, cnt);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -540,13 +540,17 @@ void Backend_memory::free(Genode::Ram_dataspace_capability cap)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Memory_object_base *o = memory_pool.lookup_and_lock(cap);
|
||||
if (!o)
|
||||
return;
|
||||
Memory_object_base *object;
|
||||
auto lambda = [&] (Memory_object_base *o) {
|
||||
object = o;
|
||||
|
||||
o->free();
|
||||
memory_pool.remove_locked(o);
|
||||
destroy(env()->heap(), o);
|
||||
if (object) {
|
||||
object->free();
|
||||
memory_pool.remove(object);
|
||||
}
|
||||
};
|
||||
memory_pool.apply(cap, lambda);
|
||||
destroy(env()->heap(), object);
|
||||
}
|
||||
|
||||
|
||||
|
@ -480,11 +480,14 @@ void Lx::backend_free(Genode::Ram_dataspace_capability cap)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Memory_object_base *o = memory_pool.lookup_and_lock(cap);
|
||||
if (!o)
|
||||
return;
|
||||
|
||||
Memory_object_base *object;
|
||||
auto lambda = [&] (Memory_object_base *o) {
|
||||
object = o;
|
||||
if (object) {
|
||||
o->free();
|
||||
memory_pool.remove_locked(o);
|
||||
destroy(env()->heap(), o);
|
||||
memory_pool.remove(o);
|
||||
}
|
||||
};
|
||||
memory_pool.apply(cap, lambda);
|
||||
destroy(env()->heap(), object);
|
||||
}
|
||||
|
@ -807,12 +807,9 @@ class Wm::Nitpicker::Session_component : public Rpc_object<Nitpicker::Session>,
|
||||
|
||||
View_handle view_handle(View_capability view_cap, View_handle handle) override
|
||||
{
|
||||
View *view = dynamic_cast<View *>(_ep.rpc_ep().lookup_and_lock(view_cap));
|
||||
if (!view) return View_handle();
|
||||
|
||||
Object_pool<Rpc_object_base>::Guard guard(view);
|
||||
|
||||
return _view_handle_registry.alloc(*view, handle);
|
||||
return _ep.rpc_ep().apply(view_cap, [&] (View *view) {
|
||||
return (view) ? _view_handle_registry.alloc(*view, handle)
|
||||
: View_handle(); });
|
||||
}
|
||||
|
||||
View_capability view_capability(View_handle handle) override
|
||||
@ -1071,8 +1068,7 @@ class Wm::Nitpicker::Root : public Genode::Rpc_object<Genode::Typed_root<Session
|
||||
{
|
||||
if (!args.is_valid_string()) throw Root::Invalid_args();
|
||||
|
||||
Rpc_object_base *session = _ep.rpc_ep().lookup_and_lock(session_cap);
|
||||
|
||||
auto lambda = [&] (Rpc_object_base *session) {
|
||||
if (!session) {
|
||||
PDBG("session lookup failed");
|
||||
return;
|
||||
@ -1089,32 +1085,47 @@ class Wm::Nitpicker::Root : public Genode::Rpc_object<Genode::Typed_root<Session
|
||||
|
||||
if (decorator_session)
|
||||
decorator_session->upgrade(args.string());
|
||||
|
||||
session->release();
|
||||
};
|
||||
_ep.rpc_ep().apply(session_cap, lambda);
|
||||
}
|
||||
|
||||
void close(Genode::Session_capability session_cap) override
|
||||
{
|
||||
Rpc_object_base *session = _ep.rpc_ep().lookup_and_lock(session_cap);
|
||||
Genode::Rpc_entrypoint &ep = _ep.rpc_ep();
|
||||
|
||||
Session_component *regular_session = dynamic_cast<Session_component *>(session);
|
||||
Session_component *regular_session =
|
||||
ep.apply(session_cap, [this] (Session_component *session) {
|
||||
if (session) {
|
||||
_sessions.remove(session);
|
||||
_ep.dissolve(*session);
|
||||
}
|
||||
return session;
|
||||
});
|
||||
if (regular_session) {
|
||||
_sessions.remove(regular_session);
|
||||
_ep.dissolve(*regular_session);
|
||||
Genode::destroy(_md_alloc, regular_session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (session == _decorator_session) {
|
||||
auto decorator_lambda = [this] (Decorator_nitpicker_session *session) {
|
||||
_ep.dissolve(*_decorator_session);
|
||||
Genode::destroy(_md_alloc, _decorator_session);
|
||||
_decorator_session = nullptr;
|
||||
return session;
|
||||
};
|
||||
|
||||
if (ep.apply(session_cap, decorator_lambda) == _decorator_session) {
|
||||
Genode::destroy(_md_alloc, _decorator_session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (session == _layouter_session) {
|
||||
auto layouter_lambda = [this] (Layouter_nitpicker_session *session) {
|
||||
_ep.dissolve(*_layouter_session);
|
||||
Genode::destroy(_md_alloc, _layouter_session);
|
||||
_layouter_session = nullptr;
|
||||
return session;
|
||||
};
|
||||
|
||||
if (ep.apply(session_cap, layouter_lambda) == _layouter_session) {
|
||||
Genode::destroy(_md_alloc, _layouter_session);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,13 +479,13 @@ namespace Platform {
|
||||
Config_access config_access;
|
||||
|
||||
/* lookup device component for previous device */
|
||||
Genode::Object_pool<Device_component>::Guard
|
||||
prev(_ep->lookup_and_lock(prev_device));
|
||||
auto lambda = [&] (Device_component *prev)
|
||||
{
|
||||
|
||||
/*
|
||||
* Start bus scanning after the previous device's location.
|
||||
* If no valid device was specified for 'prev_device', start at
|
||||
* the beginning.
|
||||
* If no valid device was specified for 'prev_device',
|
||||
* start at the beginning.
|
||||
*/
|
||||
int bus = 0, device = 0, function = -1;
|
||||
|
||||
@ -504,7 +504,8 @@ namespace Platform {
|
||||
|
||||
while (true) {
|
||||
function += 1;
|
||||
if (!_find_next(bus, device, function, &config, &config_access))
|
||||
if (!_find_next(bus, device, function, &config,
|
||||
&config_access))
|
||||
return Device_capability();
|
||||
|
||||
/* get new bdf values */
|
||||
@ -523,15 +524,17 @@ namespace Platform {
|
||||
}
|
||||
|
||||
/* lookup if we have a extended pci config space */
|
||||
Genode::addr_t config_space = lookup_config_space(bus, device,
|
||||
function);
|
||||
Genode::addr_t config_space =
|
||||
lookup_config_space(bus, device, function);
|
||||
|
||||
/*
|
||||
* A device was found. Create a new device component for the
|
||||
* device and return its capability.
|
||||
*/
|
||||
try {
|
||||
Device_component * dev = new (_device_slab) Device_component(config, config_space, _ep, this, msi_usage());
|
||||
Device_component * dev = new (_device_slab)
|
||||
Device_component(config, config_space, _ep, this,
|
||||
msi_usage());
|
||||
|
||||
/* if more than one driver uses the device - warn about */
|
||||
if (bdf_in_use.get(Device_config::MAX_BUSES * bus +
|
||||
@ -550,14 +553,14 @@ namespace Platform {
|
||||
} catch (Genode::Allocator::Out_of_memory) {
|
||||
throw Device::Quota_exceeded();
|
||||
}
|
||||
};
|
||||
return _ep->apply(prev_device, lambda);
|
||||
}
|
||||
|
||||
void release_device(Device_capability device_cap)
|
||||
{
|
||||
/* lookup device component for previous device */
|
||||
Device_component *device = dynamic_cast<Device_component *>
|
||||
(_ep->lookup_and_lock(device_cap));
|
||||
|
||||
auto lambda = [&] (Device_component *device)
|
||||
{
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
@ -575,6 +578,10 @@ namespace Platform {
|
||||
destroy(_device_slab, device);
|
||||
else
|
||||
destroy(_md_alloc, device);
|
||||
};
|
||||
|
||||
/* lookup device component for previous device */
|
||||
_ep->apply(device_cap, lambda);
|
||||
}
|
||||
|
||||
Genode::Io_mem_dataspace_capability assign_device(Device_component * device)
|
||||
@ -601,10 +608,8 @@ namespace Platform {
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Object_pool<Device_component>::Guard
|
||||
device(_ep->lookup_and_lock(device_cap));
|
||||
|
||||
return assign_device(device);
|
||||
return _ep->apply(device_cap, [&] (Device_component *device) {
|
||||
return assign_device(device);});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,6 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
|
||||
void _close(Rom_session_component *rom)
|
||||
{
|
||||
_ep.dissolve(rom);
|
||||
_rom_sessions.remove(rom);
|
||||
destroy(&_md_alloc, rom);
|
||||
}
|
||||
@ -73,7 +72,9 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
Lock::Guard guard(_lock);
|
||||
|
||||
while (_rom_sessions.first()) {
|
||||
_close(_rom_sessions.first()); }
|
||||
_ep.remove(_rom_sessions.first());
|
||||
_close(_rom_sessions.first());
|
||||
}
|
||||
}
|
||||
|
||||
Genode::Session_capability session(char const *args,
|
||||
@ -108,10 +109,12 @@ class Loader::Session_component : public Rpc_object<Session>
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
|
||||
Rpc_object_base *rom = _ep.lookup_and_lock(session);
|
||||
Rom_session_component *component;
|
||||
|
||||
Rom_session_component *component =
|
||||
dynamic_cast<Rom_session_component *>(rom);
|
||||
_ep.apply(session, [&] (Rom_session_component *rsc) {
|
||||
component = rsc;
|
||||
if (component) _ep.remove(component);
|
||||
});
|
||||
|
||||
if (component) {
|
||||
_close(component);
|
||||
|
@ -841,12 +841,12 @@ class Nitpicker::Session_component : public Genode::Rpc_object<Session>,
|
||||
|
||||
View_handle view_handle(View_capability view_cap, View_handle handle) override
|
||||
{
|
||||
View *view = dynamic_cast<View *>(_ep.lookup_and_lock(view_cap));
|
||||
if (!view) return View_handle();
|
||||
|
||||
Object_pool<Rpc_object_base>::Guard guard(view);
|
||||
|
||||
return _view_handle_registry.alloc(*view, handle);
|
||||
auto lambda = [&] (View *view)
|
||||
{
|
||||
return (view) ? _view_handle_registry.alloc(*view, handle)
|
||||
: View_handle();
|
||||
};
|
||||
return _ep.apply(view_cap, lambda);
|
||||
}
|
||||
|
||||
View_capability view_capability(View_handle handle) override
|
||||
@ -924,15 +924,12 @@ class Nitpicker::Session_component : public Genode::Rpc_object<Session>,
|
||||
return;
|
||||
|
||||
/* lookup targeted session object */
|
||||
Session_component * const session =
|
||||
session_cap.valid() ? dynamic_cast<Session_component *>(_ep.lookup_and_lock(session_cap)) : 0;
|
||||
|
||||
auto lambda = [this] (Session_component *session)
|
||||
{
|
||||
_mode.focused_session(session);
|
||||
|
||||
if (session)
|
||||
session->release();
|
||||
|
||||
report_session(_focus_reporter, session);
|
||||
};
|
||||
_ep.apply(session_cap, lambda);
|
||||
}
|
||||
|
||||
void session_control(Label suffix, Session_control control) override
|
||||
|
@ -44,8 +44,8 @@ Genode::Session_capability Session_component::cap()
|
||||
|
||||
bool Session_component::belongs_to(Genode::Session_capability cap)
|
||||
{
|
||||
Object_pool<Session_component>::Guard session(_ep.lookup_and_lock(cap));
|
||||
return session == this;
|
||||
return _ep.apply(cap, [this] (Session_component *session) {
|
||||
return session == this; });
|
||||
}
|
||||
|
||||
|
||||
|
@ -204,7 +204,7 @@ namespace Gdb_monitor {
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Child_session *session = _sessions.lookup_and_lock(session_cap);
|
||||
auto lambda = [&] (Child_session *session) {
|
||||
if (!session) {
|
||||
PERR("attempt to upgrade unknown session");
|
||||
return;
|
||||
@ -221,19 +221,29 @@ namespace Gdb_monitor {
|
||||
|
||||
/* inform child about quota upgrade */
|
||||
_child_root.upgrade(session_cap, args);
|
||||
};
|
||||
|
||||
_sessions.apply(session_cap, lambda);
|
||||
}
|
||||
|
||||
void close(Session_capability session_cap)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Child_session *session = _sessions.lookup_and_lock(session_cap);
|
||||
Child_session *session;
|
||||
|
||||
auto lambda = [&] (Child_session *s) {
|
||||
session = s;
|
||||
|
||||
if (!session) {
|
||||
PERR("attempt to close unknown session");
|
||||
return;
|
||||
}
|
||||
_sessions.remove(session);
|
||||
};
|
||||
_sessions.apply(session_cap, lambda);
|
||||
|
||||
Genode::size_t ram_quota = session->ram_quota;
|
||||
_sessions.remove_locked(session);
|
||||
destroy(env()->heap(), session);
|
||||
|
||||
_child_root.close(session_cap);
|
||||
|
@ -42,13 +42,12 @@ Rm_session_component::Region *Rm_session_component::find_region(void *local_addr
|
||||
*offset_in_region = ((addr_t)local_addr - (addr_t)region->start());
|
||||
// PDBG("offset_in_region = %lx", *offset_in_region);
|
||||
|
||||
Object_pool<Dataspace_object>::Guard managed_ds_obj(_managed_ds_map->lookup_and_lock(region->ds_cap()));
|
||||
if (managed_ds_obj) {
|
||||
// PDBG("managed dataspace detected");
|
||||
region = managed_ds_obj->rm_session_component()->find_region((void*)*offset_in_region, offset_in_region);
|
||||
// if (region)
|
||||
// PDBG("found sub region: start = %p, offset = %lx", region->start(), *offset_in_region);
|
||||
}
|
||||
_managed_ds_map->apply(region->ds_cap(), [&] (Dataspace_object *managed_ds_obj) {
|
||||
if (managed_ds_obj)
|
||||
region =
|
||||
managed_ds_obj->rm_session_component()->find_region((void*)*offset_in_region,
|
||||
offset_in_region);
|
||||
});
|
||||
|
||||
return region;
|
||||
}
|
||||
|
@ -118,12 +118,8 @@ namespace Noux {
|
||||
};
|
||||
|
||||
|
||||
class Dataspace_registry
|
||||
class Dataspace_registry : public Object_pool<Dataspace_info>
|
||||
{
|
||||
private:
|
||||
|
||||
Object_pool<Dataspace_info> _pool;
|
||||
|
||||
public:
|
||||
|
||||
~Dataspace_registry()
|
||||
@ -136,25 +132,8 @@ namespace Noux {
|
||||
* created via 'Rm_dataspace_info::fork', are not handled by
|
||||
* those destructors. So we have to clean them up here.
|
||||
*/
|
||||
while(Dataspace_info *info = _pool.first()) {
|
||||
_pool.remove_locked(info);
|
||||
destroy(env()->heap(), info);
|
||||
}
|
||||
}
|
||||
|
||||
void insert(Dataspace_info *info)
|
||||
{
|
||||
_pool.insert(info);
|
||||
}
|
||||
|
||||
void remove(Dataspace_info *info)
|
||||
{
|
||||
_pool.remove_locked(info);
|
||||
}
|
||||
|
||||
Dataspace_info *lookup_info(Dataspace_capability ds_cap)
|
||||
{
|
||||
return _pool.lookup_and_lock(ds_cap);
|
||||
remove_all([&] (Dataspace_info *info) {
|
||||
destroy(env()->heap(), info); });
|
||||
}
|
||||
};
|
||||
|
||||
@ -172,9 +151,7 @@ namespace Noux {
|
||||
|
||||
~Static_dataspace_info()
|
||||
{
|
||||
Static_dataspace_info *info =
|
||||
dynamic_cast<Static_dataspace_info *>(_ds_registry.lookup_info(ds_cap()));
|
||||
|
||||
auto lambda = [this] (Static_dataspace_info *info) {
|
||||
if (!info) {
|
||||
PERR("lookup of binary ds info failed");
|
||||
return;
|
||||
@ -183,7 +160,8 @@ namespace Noux {
|
||||
_ds_registry.remove(info);
|
||||
|
||||
info->dissolve_users();
|
||||
|
||||
};
|
||||
_ds_registry.apply(ds_cap(), lambda);
|
||||
}
|
||||
|
||||
Dataspace_capability fork(Ram_session_capability,
|
||||
|
@ -126,8 +126,9 @@ namespace Noux {
|
||||
|
||||
void close(Genode::Session_capability session)
|
||||
{
|
||||
Rm_session_component * rm_session =
|
||||
dynamic_cast<Rm_session_component *>(_ep.lookup_and_lock(session));
|
||||
Dataspace_info *info;
|
||||
|
||||
auto lambda = [&] (Rm_session_component *rm_session) {
|
||||
if (!rm_session) {
|
||||
PWRN("Unexpected call of close with non-RM-session argument");
|
||||
return;
|
||||
@ -137,7 +138,8 @@ namespace Noux {
|
||||
Dataspace_capability ds_cap = rm_session->dataspace();
|
||||
|
||||
/* release dataspace info */
|
||||
Dataspace_info *info = _ds_registry.lookup_info(ds_cap);
|
||||
_ds_registry.apply(ds_cap, [&] (Dataspace_info *di) {
|
||||
info = di;
|
||||
if (!info) {
|
||||
PWRN("Could not lookup dataspace info for local RM session");
|
||||
return;
|
||||
@ -146,6 +148,9 @@ namespace Noux {
|
||||
_ds_registry.remove(info);
|
||||
|
||||
info->dissolve_users();
|
||||
});
|
||||
};
|
||||
_ep.apply(session, lambda);
|
||||
|
||||
/* 'rm_session' is deleted by deleting Rm_dataspace_info 'info' */
|
||||
destroy(env()->heap(), info);
|
||||
|
@ -59,8 +59,10 @@ namespace Noux {
|
||||
void close(Genode::Session_capability session)
|
||||
{
|
||||
/* acquire locked session object */
|
||||
Rom_session_component *rom_session =
|
||||
dynamic_cast<Rom_session_component *>(_ep.lookup_and_lock(session));
|
||||
Rom_session_component *rom_session;
|
||||
|
||||
_ep.apply(session, [&] (Rom_session_component *rsc) {
|
||||
rom_session = rsc;
|
||||
|
||||
if (!rom_session) {
|
||||
PWRN("Unexpected call of close with non-ROM-session argument");
|
||||
@ -68,9 +70,9 @@ namespace Noux {
|
||||
}
|
||||
|
||||
_ep.dissolve(rom_session);
|
||||
});
|
||||
|
||||
destroy(env()->heap(), rom_session);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -153,8 +153,10 @@ namespace Noux {
|
||||
|
||||
void free(Ram_dataspace_capability ds_cap)
|
||||
{
|
||||
Ram_dataspace_info *ds_info =
|
||||
dynamic_cast<Ram_dataspace_info *>(_registry.lookup_info(ds_cap));
|
||||
Ram_dataspace_info *ds_info;
|
||||
|
||||
auto lambda = [&] (Ram_dataspace_info *rdi) {
|
||||
ds_info = rdi;
|
||||
|
||||
if (!ds_info) {
|
||||
PERR("RAM free: dataspace lookup failed");
|
||||
@ -169,6 +171,8 @@ namespace Noux {
|
||||
_used_quota -= ds_info->size();
|
||||
|
||||
env()->ram_session()->free(ds_cap);
|
||||
};
|
||||
_registry.apply(ds_cap, lambda);
|
||||
destroy(env()->heap(), ds_info);
|
||||
}
|
||||
|
||||
|
@ -124,10 +124,9 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
Region * const region = _lookup_region_by_addr(addr);
|
||||
if (!region) { return cap(); }
|
||||
|
||||
auto lambda = [&] (Dataspace_info *info)
|
||||
{
|
||||
/* if there is no info for the region it can't be a sub RM */
|
||||
Dataspace_capability ds_cap = region->ds;
|
||||
typedef Object_pool<Dataspace_info>::Guard Info_guard;
|
||||
Info_guard info(_ds_registry.lookup_info(ds_cap));
|
||||
if (!info) { return cap(); }
|
||||
|
||||
/* ask the dataspace info for an appropriate sub RM */
|
||||
@ -139,6 +138,8 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
/* if the result is invalid the dataspace is no sub RM */
|
||||
if (!sub_rm.valid()) { return cap(); }
|
||||
return sub_rm;
|
||||
};
|
||||
return _ds_registry.apply(region->ds, lambda);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,11 +159,9 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
{
|
||||
Lock::Guard guard(_region_lock);
|
||||
for (Region *curr = _regions.first(); curr; curr = curr->next_region()) {
|
||||
|
||||
auto lambda = [&] (Dataspace_info *info)
|
||||
{
|
||||
Dataspace_capability ds;
|
||||
|
||||
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(curr->ds));
|
||||
|
||||
if (info) {
|
||||
|
||||
ds = info->fork(dst_ram, ds_registry, ep);
|
||||
@ -193,14 +192,16 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
|
||||
if (!ds.valid()) {
|
||||
PERR("replay: Error while forking dataspace");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
Rm_session_client(dst_rm).attach(ds, curr->size,
|
||||
curr->offset,
|
||||
true,
|
||||
curr->local_addr);
|
||||
}
|
||||
};
|
||||
_ds_registry.apply(curr->ds, lambda);
|
||||
};
|
||||
}
|
||||
|
||||
void poke(addr_t dst_addr, void const *src, size_t len)
|
||||
@ -235,14 +236,13 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
local_addr = region->local_addr;
|
||||
}
|
||||
|
||||
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(ds_cap));
|
||||
_ds_registry.apply(ds_cap, [&] (Dataspace_info *info) {
|
||||
if (!info) {
|
||||
PERR("attempt to write to unknown dataspace type");
|
||||
for (;;);
|
||||
return;
|
||||
}
|
||||
|
||||
info->poke(dst_addr - local_addr, src, len);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -275,20 +275,21 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
Region(*this, ds, size, offset, local_addr);
|
||||
|
||||
/* register region as user of RAM dataspaces */
|
||||
auto lambda = [&] (Dataspace_info *info)
|
||||
{
|
||||
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(ds));
|
||||
|
||||
if (info) {
|
||||
info->register_user(*region);
|
||||
} else {
|
||||
if (verbose_attach) {
|
||||
PWRN("Trying to attach unknown dataspace type");
|
||||
PWRN(" ds_info@%p at 0x%lx size=%zd offset=0x%lx",
|
||||
info.object(), (long)local_addr,
|
||||
info, (long)local_addr,
|
||||
Dataspace_client(ds).size(), (long)offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_ds_registry.apply(ds, lambda);
|
||||
|
||||
|
||||
/*
|
||||
* Record attachment for later replay (needed during
|
||||
@ -315,10 +316,8 @@ class Noux::Rm_session_component : public Rpc_object<Rm_session>
|
||||
_regions.remove(region);
|
||||
}
|
||||
|
||||
{
|
||||
Object_pool<Dataspace_info>::Guard info(_ds_registry.lookup_info(region->ds));
|
||||
if (info) info->unregister_user(*region);
|
||||
}
|
||||
_ds_registry.apply(region->ds, [&] (Dataspace_info *info) {
|
||||
if (info) info->unregister_user(*region); });
|
||||
|
||||
destroy(env()->heap(), region);
|
||||
|
||||
|
@ -69,9 +69,7 @@ namespace Noux {
|
||||
* Lookup and lock ds info instead of directly accessing
|
||||
* the '_ds_info' member.
|
||||
*/
|
||||
Object_pool<Dataspace_info>::Guard
|
||||
info(_ds_registry.lookup_info(_ds_info.ds_cap()));
|
||||
|
||||
_ds_registry.apply(_ds_info.ds_cap(), [this] (Dataspace_info *info) {
|
||||
if (!info) {
|
||||
PERR("~Rom_session_component: unexpected !info");
|
||||
return;
|
||||
@ -80,6 +78,7 @@ namespace Noux {
|
||||
_ds_registry.remove(&_ds_info);
|
||||
|
||||
info->dissolve_users();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user