mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 18:56:29 +00:00
core: equip signal-context slab with initial block
By supplying a statically allocated initial block to the slab allocator for signal contexts, we become able to construct a 'Signal_broker' (the back end for the PD's signalling API) without any dynamic memory allocation. This is a precondition for using the PD as meta-data allocator for its contained signal broker (meta data allocations must not happen before the PD construction is complete). Issue #2407
This commit is contained in:
parent
a96919632e
commit
963a6c37a0
@ -24,6 +24,7 @@
|
||||
#include <platform.h>
|
||||
#include <signal_source_component.h>
|
||||
#include <signal_source/capability.h>
|
||||
#include <signal_context_slab.h>
|
||||
|
||||
namespace Genode { class Signal_broker; }
|
||||
|
||||
@ -38,8 +39,7 @@ class Genode::Signal_broker
|
||||
Rpc_entrypoint &_context_ep;
|
||||
Signal_source_component _source;
|
||||
Signal_source_capability _source_cap;
|
||||
Tslab<Signal_context_component,
|
||||
960*sizeof(long)> _contexts_slab { &_md_alloc };
|
||||
Signal_context_slab _context_slab { _md_alloc };
|
||||
|
||||
public:
|
||||
|
||||
@ -62,7 +62,7 @@ class Genode::Signal_broker
|
||||
_source_ep.dissolve(&_source);
|
||||
|
||||
/* free all signal contexts */
|
||||
while (Signal_context_component *r = _contexts_slab.first_object())
|
||||
while (Signal_context_component *r = _context_slab.any_signal_context())
|
||||
free_context(reinterpret_cap_cast<Signal_context>(r->cap()));
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ class Genode::Signal_broker
|
||||
}
|
||||
|
||||
/* the _contexts_slab may throw Allocator::Out_of_memory */
|
||||
_obj_pool.insert(new (&_contexts_slab) Signal_context_component(cap));
|
||||
_obj_pool.insert(new (&_context_slab) Signal_context_component(cap));
|
||||
|
||||
/* return unique capability for the signal context */
|
||||
return cap;
|
||||
@ -121,7 +121,7 @@ class Genode::Signal_broker
|
||||
Hex(context_cap.local_name()));
|
||||
return;
|
||||
}
|
||||
destroy(&_contexts_slab, context);
|
||||
destroy(&_context_slab, context);
|
||||
|
||||
Nova::revoke(Nova::Obj_crd(context_cap.local_name(), 0));
|
||||
cap_map()->remove(context_cap.local_name(), 0);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <signal_source_component.h>
|
||||
#include <signal_source/capability.h>
|
||||
#include <signal_context_slab.h>
|
||||
|
||||
namespace Genode { class Signal_broker; }
|
||||
|
||||
@ -23,13 +24,12 @@ class Genode::Signal_broker
|
||||
{
|
||||
private:
|
||||
|
||||
Allocator &_md_alloc;
|
||||
Rpc_entrypoint &_source_ep;
|
||||
Rpc_entrypoint &_context_ep;
|
||||
Signal_source_component _source;
|
||||
Signal_source_capability _source_cap;
|
||||
Tslab<Signal_context_component,
|
||||
960*sizeof(long)> _contexts_slab { &_md_alloc };
|
||||
Allocator &_md_alloc;
|
||||
Rpc_entrypoint &_source_ep;
|
||||
Rpc_entrypoint &_context_ep;
|
||||
Signal_source_component _source;
|
||||
Signal_source_capability _source_cap;
|
||||
Signal_context_slab _contexts_slab { _md_alloc };
|
||||
|
||||
public:
|
||||
|
||||
@ -52,7 +52,7 @@ class Genode::Signal_broker
|
||||
_source_ep.dissolve(&_source);
|
||||
|
||||
/* free all signal contexts */
|
||||
while (Signal_context_component *r = _contexts_slab.first_object())
|
||||
while (Signal_context_component *r = _contexts_slab.any_signal_context())
|
||||
free_context(r->cap());
|
||||
}
|
||||
|
||||
|
49
repos/base/src/core/include/signal_context_slab.h
Normal file
49
repos/base/src/core/include/signal_context_slab.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* \brief Slab allocator for signal contexts
|
||||
* \author Norman Feske
|
||||
* \date 2017-05-10
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _CORE__INCLUDE__SIGNAL_CONTEXT_SLAB_H_
|
||||
#define _CORE__INCLUDE__SIGNAL_CONTEXT_SLAB_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/slab.h>
|
||||
|
||||
/* core-local includes */
|
||||
#include <signal_source_component.h>
|
||||
|
||||
namespace Genode { struct Signal_context_slab; }
|
||||
|
||||
|
||||
/**
|
||||
* Slab allocator for signal contexts
|
||||
*
|
||||
* We define an initial slab block to prevent a dynamic slab-block allocation
|
||||
* via '_md_alloc' at the slab's construction time. This would be a problem
|
||||
* because the '_md_alloc' supplied by the 'Pd_session_component' constructor
|
||||
* uses the PD session itself as backing store (which would be in the middle of
|
||||
* construction).
|
||||
*/
|
||||
struct Genode::Signal_context_slab : Slab
|
||||
{
|
||||
static constexpr size_t SBS = 960*sizeof(long);
|
||||
uint8_t _initial_sb[SBS];
|
||||
|
||||
Signal_context_slab(Allocator &md_alloc)
|
||||
: Slab(sizeof(Signal_context_component), SBS, _initial_sb, &md_alloc) { }
|
||||
|
||||
Signal_context_component *any_signal_context()
|
||||
{
|
||||
return (Signal_context_component *)Slab::any_used_elem();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _CORE__INCLUDE__SIGNAL_CONTEXT_SLAB_H_ */
|
@ -29,6 +29,8 @@ namespace Genode {
|
||||
class Signal_source_component;
|
||||
|
||||
typedef Fifo<Signal_context_component> Signal_queue;
|
||||
|
||||
struct Signal_context_slab;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user