base/core: use references instead of pointers

This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:

* The contract between caller and callee becomes more obvious. When
  passing a reference, the contract says that the argument cannot be
  a null pointer. The caller is responsible to ensure that. Therefore,
  the use of reference eliminates the need to add defensive null-pointer
  checks at the callee site, which sometimes merely exist to be on the
  safe side. The bottom line is that the code becomes easier to follow.

* Reference members must be initialized via an object initializer,
  which promotes a programming style that avoids intermediate object-
  construction states. Within core, there are still a few pointers
  as member variables left though. E.g., caused by the late association
  of 'Platform_thread' objects with their 'Platform_pd' objects.

* If no pointers are present as member variables, we don't need to
  manually provide declarations of a private copy constructor and
  an assignment operator to avoid -Weffc++ errors "class ... has
  pointer data members [-Werror=effc++]".

This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.

Fixes #3135
This commit is contained in:
Norman Feske 2019-01-24 22:00:01 +01:00
parent f9373b4430
commit 6b289a1423
242 changed files with 2390 additions and 2434 deletions

View File

@ -40,7 +40,7 @@ namespace Genode {
*/ */
inline bool map_local(addr_t from_addr, addr_t to_addr, size_t num_pages) inline bool map_local(addr_t from_addr, addr_t to_addr, size_t num_pages)
{ {
Fiasco::l4_threadid_t core_pager = platform_specific()->core_pager()->native_thread_id(); Fiasco::l4_threadid_t core_pager = platform_specific().core_pager().native_thread_id();
addr_t offset = 0; addr_t offset = 0;
size_t page_size = get_page_size(); size_t page_size = get_page_size();

View File

@ -18,11 +18,12 @@
#include <base/allocator_avl.h> #include <base/allocator_avl.h>
#include <base/internal/capability_space.h> #include <base/internal/capability_space.h>
#include "synced_range_allocator.h" #include <synced_range_allocator.h>
#include "platform_generic.h" #include <platform_generic.h>
#include "platform_thread.h" #include <platform_thread.h>
#include "platform_pd.h" #include <platform_pd.h>
#include "boot_modules.h" #include <boot_modules.h>
#include <assertion.h>
namespace Genode { namespace Genode {
@ -113,7 +114,7 @@ namespace Genode {
/** /**
* Return singleton instance of Sigma0 pager object * Return singleton instance of Sigma0 pager object
*/ */
static Sigma0 *sigma0(); static Sigma0 &sigma0();
/** /**
* Core pager thread that handles core-internal page-faults * Core pager thread that handles core-internal page-faults
@ -123,7 +124,7 @@ namespace Genode {
/** /**
* Constructor * Constructor
*/ */
Core_pager(Platform_pd *core_pd); Core_pager(Platform_pd &core_pd);
int pager(Ipc_pager &) { /* never called */ return -1; } int pager(Ipc_pager &) { /* never called */ return -1; }
}; };
@ -131,7 +132,7 @@ namespace Genode {
/** /**
* Return singleton instance of core pager object * Return singleton instance of core pager object
*/ */
Core_pager *core_pager(); Core_pager &core_pager();
/** /**
* Constructor * Constructor
@ -141,22 +142,28 @@ namespace Genode {
/** /**
* Accessor for core pd object * Accessor for core pd object
*/ */
Platform_pd *core_pd() { return _core_pd; } Platform_pd &core_pd()
{
if (_core_pd)
return *_core_pd;
ASSERT_NEVER_CALLED;
}
/******************************** /********************************
** Generic platform interface ** ** Generic platform interface **
********************************/ ********************************/
Range_allocator *core_mem_alloc() override { return &_ram_alloc; } Range_allocator &core_mem_alloc() override { return _ram_alloc; }
Range_allocator *ram_alloc() override { return &_ram_alloc; } Range_allocator &ram_alloc() override { return _ram_alloc; }
Range_allocator *io_mem_alloc() override { return &_io_mem_alloc; } Range_allocator &io_mem_alloc() override { return _io_mem_alloc; }
Range_allocator *io_port_alloc() override { return &_io_port_alloc; } Range_allocator &io_port_alloc() override { return _io_port_alloc; }
Range_allocator *irq_alloc() override { return &_irq_alloc; } Range_allocator &irq_alloc() override { return _irq_alloc; }
Range_allocator *region_alloc() override { return &_region_alloc; } Range_allocator &region_alloc() override { return _region_alloc; }
addr_t vm_start() const override { return _vm_start; } addr_t vm_start() const override { return _vm_start; }
size_t vm_size() const override { return _vm_size; } size_t vm_size() const override { return _vm_size; }
Rom_fs *rom_fs() override { return &_rom_fs; } Rom_fs &rom_fs() override { return _rom_fs; }
size_t max_caps() const { return Capability_space::max_caps(); } size_t max_caps() const { return Capability_space::max_caps(); }

View File

@ -74,7 +74,7 @@ namespace Genode {
* *
* Again a special case for Core thread0. * Again a special case for Core thread0.
*/ */
int _alloc_thread(int thread_id, Platform_thread *thread); int _alloc_thread(int thread_id, Platform_thread &thread);
/** /**
* Thread deallocation * Thread deallocation
@ -149,8 +149,12 @@ namespace Genode {
/** /**
* Constructor * Constructor
*/ */
Platform_pd(Allocator * md_alloc, char const *, Platform_pd(Allocator &md_alloc, char const *name);
signed pd_id = PD_INVALID, bool create = true);
/**
* Constructor used for core's PD
*/
Platform_pd(char const *name, signed pd_id);
/** /**
* Destructor * Destructor
@ -172,14 +176,14 @@ namespace Genode {
* *
* \return true on success * \return true on success
*/ */
bool bind_thread(Platform_thread *thread); bool bind_thread(Platform_thread &thread);
/** /**
* Unbind thread from protection domain * Unbind thread from protection domain
* *
* Free the thread's slot and update thread object. * Free the thread's slot and update thread object.
*/ */
void unbind_thread(Platform_thread *thread); void unbind_thread(Platform_thread &thread);
/** /**
* Assign parent interface to protection domain * Assign parent interface to protection domain

View File

@ -21,6 +21,7 @@
/* core includes */ /* core includes */
#include <pager.h> #include <pager.h>
#include <platform_pd.h> #include <platform_pd.h>
#include <assertion.h>
/* Fiasco includes */ /* Fiasco includes */
namespace Fiasco { namespace Fiasco {
@ -40,14 +41,17 @@ namespace Genode {
Platform_thread(Platform_thread const &); Platform_thread(Platform_thread const &);
Platform_thread &operator = (Platform_thread const &); Platform_thread &operator = (Platform_thread const &);
int _thread_id; /* plain thread number */ int _thread_id = THREAD_INVALID; /* plain thread number */
Fiasco::l4_threadid_t _l4_thread_id; /* L4 thread ID */
char _name[32]; /* thread name that will be Fiasco::l4_threadid_t _l4_thread_id;
typedef String<32> Name;
Name const _name; /* thread name that will be
registered at the kernel registered at the kernel
debugger */ debugger */
Platform_pd *_platform_pd = nullptr; /* protection domain thread Platform_pd *_platform_pd = nullptr; /* protection domain thread
is bound to */ is bound to */
Pager_object *_pager; Pager_object *_pager = nullptr;
public: public:
@ -58,9 +62,13 @@ namespace Genode {
/** /**
* Constructor * Constructor
*/ */
Platform_thread(size_t, const char *name = 0, unsigned priority = 0, Platform_thread(size_t, const char *name, unsigned priority,
Affinity::Location = Affinity::Location(), Affinity::Location, addr_t utcb);
addr_t utcb = 0, int thread_id = THREAD_INVALID);
/**
* Constructor used for core-internal threads
*/
Platform_thread(const char *name);
/** /**
* Destructor * Destructor
@ -106,7 +114,7 @@ namespace Genode {
* \param pd platform pd, thread is bound to * \param pd platform pd, thread is bound to
*/ */
void bind(int thread_id, Fiasco::l4_threadid_t l4_thread_id, void bind(int thread_id, Fiasco::l4_threadid_t l4_thread_id,
Platform_pd *pd); Platform_pd &pd);
/** /**
* Unbind this thread * Unbind this thread
@ -146,8 +154,15 @@ namespace Genode {
/** /**
* Return/set pager * Return/set pager
*/ */
Pager_object *pager() const { return _pager; } Pager_object &pager() const
void pager(Pager_object *pager) { _pager = pager; } {
if (_pager)
return *_pager;
ASSERT_NEVER_CALLED;
}
void pager(Pager_object &pager) { _pager = &pager; }
/** /**
* Return identification of thread when faulting * Return identification of thread when faulting
@ -172,7 +187,7 @@ namespace Genode {
int thread_id() const { return _thread_id; } int thread_id() const { return _thread_id; }
Fiasco::l4_threadid_t native_thread_id() const { return _l4_thread_id; } Fiasco::l4_threadid_t native_thread_id() const { return _l4_thread_id; }
const char *name() const { return _name; } Name name() const { return _name; }
}; };
} }

View File

@ -24,7 +24,7 @@ class Genode::Rpc_cap_factory
{ {
private: private:
static Native_capability _alloc(Rpc_cap_factory *owner, static Native_capability _alloc(Rpc_cap_factory &owner,
Native_capability ep); Native_capability ep);
public: public:

View File

@ -27,7 +27,7 @@ using namespace Genode;
void Io_mem_session_component::_unmap_local(addr_t base, size_t) void Io_mem_session_component::_unmap_local(addr_t base, size_t)
{ {
platform()->region_alloc()->free(reinterpret_cast<void *>(base)); platform().region_alloc().free(reinterpret_cast<void *>(base));
} }
@ -51,7 +51,7 @@ addr_t Io_mem_session_component::_map_local(addr_t base, size_t size)
/* find appropriate region for mapping */ /* find appropriate region for mapping */
void *local_base = 0; void *local_base = 0;
if (platform()->region_alloc()->alloc_aligned(size, &local_base, alignment).error()) if (platform().region_alloc().alloc_aligned(size, &local_base, alignment).error())
return 0; return 0;
/* call sigma0 for I/O region */ /* call sigma0 for I/O region */

View File

@ -121,7 +121,7 @@ Irq_object::Irq_object(unsigned irq)
{ } { }
Irq_session_component::Irq_session_component(Range_allocator *irq_alloc, Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
const char *args) const char *args)
: :
_irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)), _irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)),
@ -132,7 +132,7 @@ Irq_session_component::Irq_session_component(Range_allocator *irq_alloc,
if (msi) if (msi)
throw Service_denied(); throw Service_denied();
if (!irq_alloc || irq_alloc->alloc_addr(1, _irq_number).error()) { if (irq_alloc.alloc_addr(1, _irq_number).error()) {
error("unavailable IRQ ", _irq_number, " requested"); error("unavailable IRQ ", _irq_number, " requested");
throw Service_denied(); throw Service_denied();
} }

View File

@ -140,27 +140,27 @@ Platform::Sigma0::Sigma0()
} }
Platform::Sigma0 *Platform::sigma0() Platform::Sigma0 &Platform::sigma0()
{ {
static Sigma0 _sigma0; static Sigma0 _sigma0;
return &_sigma0; return _sigma0;
} }
Platform::Core_pager::Core_pager(Platform_pd *core_pd) Platform::Core_pager::Core_pager(Platform_pd &core_pd)
: :
Platform_thread(0, "core.pager"), Platform_thread("core.pager"),
Pager_object(Cpu_session_capability(), Thread_capability(), Pager_object(Cpu_session_capability(), Thread_capability(),
0, Affinity::Location(), Session_label(), 0, Affinity::Location(), Session_label(),
Cpu_session::Name(name())) Cpu_session::Name(name()))
{ {
Platform_thread::pager(sigma0()); Platform_thread::pager(sigma0());
core_pd->bind_thread(this); core_pd.bind_thread(*this);
cap(Capability_space::import(native_thread_id(), Rpc_obj_key())); cap(Capability_space::import(native_thread_id(), Rpc_obj_key()));
/* pager needs to know core's pd ID */ /* pager needs to know core's pd ID */
_core_pager_arg = core_pd->pd_id(); _core_pager_arg = core_pd.pd_id();
/* stack begins at the top end of the '_core_pager_stack' array */ /* stack begins at the top end of the '_core_pager_stack' array */
void *sp = (void *)&_core_pager_stack[PAGER_STACK_ELEMENTS - 1]; void *sp = (void *)&_core_pager_stack[PAGER_STACK_ELEMENTS - 1];
@ -176,10 +176,10 @@ Platform::Core_pager::Core_pager(Platform_pd *core_pd)
} }
Platform::Core_pager *Platform::core_pager() Platform::Core_pager &Platform::core_pager()
{ {
static Core_pager _core_pager(core_pd()); static Core_pager _core_pager(core_pd());
return &_core_pager; return _core_pager;
} }
@ -412,9 +412,9 @@ void Platform::_setup_basics()
Platform::Platform() : Platform::Platform() :
_ram_alloc(nullptr), _io_mem_alloc(core_mem_alloc()), _ram_alloc(nullptr), _io_mem_alloc(&core_mem_alloc()),
_io_port_alloc(core_mem_alloc()), _irq_alloc(core_mem_alloc()), _io_port_alloc(&core_mem_alloc()), _irq_alloc(&core_mem_alloc()),
_region_alloc(core_mem_alloc()), _region_alloc(&core_mem_alloc()),
_kip_rom((addr_t)get_kip(), L4_PAGESIZE, "l4v2_kip") _kip_rom((addr_t)get_kip(), L4_PAGESIZE, "l4v2_kip")
{ {
/* /*
@ -438,20 +438,21 @@ Platform::Platform() :
/* setup pd object for core pd */ /* setup pd object for core pd */
_core_label[0] = 0; _core_label[0] = 0;
_core_pd = new(core_mem_alloc()) Platform_pd(nullptr, _core_label, _core_pd = new (core_mem_alloc()) Platform_pd(_core_label, myself.id.task);
myself.id.task, false);
/* /*
* We setup the thread object for thread0 in core pd using a special * We setup the thread object for thread0 in core pd using a special
* interface that allows us to specify the lthread number. * interface that allows us to specify the lthread number.
*/ */
Platform_thread *core_thread = new(core_mem_alloc()) Platform_thread &core_thread = *new (core_mem_alloc())
Platform_thread(0, "core.main", myself.id.lthread); Platform_thread("core.main");
core_thread->pager(sigma0());
core_thread.pager(sigma0());
_core_pd->bind_thread(core_thread); _core_pd->bind_thread(core_thread);
/* we never call _core_thread.start(), so set name directly */ /* we never call _core_thread.start(), so set name directly */
Fiasco::fiasco_register_thread_name(core_thread->native_thread_id(), core_thread->name()); Fiasco::fiasco_register_thread_name(core_thread.native_thread_id(),
core_thread.name().string());
/* core log as ROM module */ /* core log as ROM module */
{ {
@ -459,14 +460,14 @@ Platform::Platform() :
unsigned const pages = 1; unsigned const pages = 1;
size_t const log_size = pages << get_page_size_log2(); size_t const log_size = pages << get_page_size_log2();
ram_alloc()->alloc_aligned(log_size, &phys_ptr, get_page_size_log2()); ram_alloc().alloc_aligned(log_size, &phys_ptr, get_page_size_log2());
addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr); addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr);
void * const core_local_ptr = phys_ptr; void * const core_local_ptr = phys_ptr;
addr_t const core_local_addr = phys_addr; addr_t const core_local_addr = phys_addr;
/* let one page free after the log buffer */ /* let one page free after the log buffer */
region_alloc()->remove_range(core_local_addr, log_size + get_page_size()); region_alloc().remove_range(core_local_addr, log_size + get_page_size());
memset(core_local_ptr, 0, log_size); memset(core_local_ptr, 0, log_size);

View File

@ -162,7 +162,7 @@ Platform_thread* Platform_pd::_next_thread()
} }
int Platform_pd::_alloc_thread(int thread_id, Platform_thread *thread) int Platform_pd::_alloc_thread(int thread_id, Platform_thread &thread)
{ {
int i = thread_id; int i = thread_id;
@ -177,7 +177,7 @@ int Platform_pd::_alloc_thread(int thread_id, Platform_thread *thread)
if (_threads[i]) return -2; if (_threads[i]) return -2;
} }
_threads[i] = thread; _threads[i] = &thread;
return i; return i;
} }
@ -196,10 +196,10 @@ void Platform_pd::_free_thread(int thread_id)
** Public object members ** ** Public object members **
***************************/ ***************************/
bool Platform_pd::bind_thread(Platform_thread *thread) bool Platform_pd::bind_thread(Platform_thread &thread)
{ {
/* thread_id is THREAD_INVALID by default - only core is the special case */ /* thread_id is THREAD_INVALID by default - only core is the special case */
int thread_id = thread->thread_id(); int thread_id = thread.thread_id();
l4_threadid_t l4_thread_id; l4_threadid_t l4_thread_id;
int t = _alloc_thread(thread_id, thread); int t = _alloc_thread(thread_id, thread);
@ -213,18 +213,18 @@ bool Platform_pd::bind_thread(Platform_thread *thread)
l4_thread_id.id.lthread = thread_id; l4_thread_id.id.lthread = thread_id;
/* finally inform thread about binding */ /* finally inform thread about binding */
thread->bind(thread_id, l4_thread_id, this); thread.bind(thread_id, l4_thread_id, *this);
return true; return true;
} }
void Platform_pd::unbind_thread(Platform_thread *thread) void Platform_pd::unbind_thread(Platform_thread &thread)
{ {
int thread_id = thread->thread_id(); int thread_id = thread.thread_id();
/* unbind thread before proceeding */ /* unbind thread before proceeding */
thread->unbind(); thread.unbind();
_free_thread(thread_id); _free_thread(thread_id);
} }
@ -246,7 +246,25 @@ void Platform_pd::flush(addr_t, size_t size, Core_local_addr core_local_base)
L4_FP_FLUSH_PAGE); L4_FP_FLUSH_PAGE);
} }
Platform_pd::Platform_pd(Allocator *, char const *, signed pd_id, bool create) Platform_pd::Platform_pd(Allocator &, char const *)
{
/* check correct init */
if (!_init)
panic("init pd facility via Platform_pd::init() before using it!");
/* init threads */
_init_threads();
int ret = _alloc_pd(PD_INVALID);
if (ret < 0) {
panic("pd alloc failed");
}
_create_pd(true);
}
Platform_pd::Platform_pd(char const *, signed pd_id)
{ {
/* check correct init */ /* check correct init */
if (!_init) if (!_init)
@ -260,14 +278,14 @@ Platform_pd::Platform_pd(Allocator *, char const *, signed pd_id, bool create)
panic("pd alloc failed"); panic("pd alloc failed");
} }
_create_pd(create); _create_pd(false);
} }
Platform_pd::~Platform_pd() Platform_pd::~Platform_pd()
{ {
/* unbind all threads */ /* unbind all threads */
while (Platform_thread *t = _next_thread()) unbind_thread(t); while (Platform_thread *t = _next_thread()) unbind_thread(*t);
_destroy_pd(); _destroy_pd();
_free_pd(); _free_pd();

View File

@ -55,7 +55,7 @@ int Platform_thread::start(void *ip, void *sp)
warning("old eflags == ~0 on ex_regs ", warning("old eflags == ~0 on ex_regs ",
Hex(thread.id.task), ".", Hex(thread.id.lthread)); Hex(thread.id.task), ".", Hex(thread.id.lthread));
fiasco_register_thread_name(thread, _name); fiasco_register_thread_name(thread, _name.string());
return 0; return 0;
} }
@ -72,11 +72,11 @@ void Platform_thread::resume()
} }
void Platform_thread::bind(int thread_id, l4_threadid_t l4_thread_id, Platform_pd *pd) void Platform_thread::bind(int thread_id, l4_threadid_t l4_thread_id, Platform_pd &pd)
{ {
_thread_id = thread_id; _thread_id = thread_id;
_l4_thread_id = l4_thread_id; _l4_thread_id = l4_thread_id;
_platform_pd = pd; _platform_pd = &pd;
} }
@ -154,12 +154,12 @@ void Platform_thread::cancel_blocking()
Platform_thread::Platform_thread(size_t, const char *name, unsigned, Platform_thread::Platform_thread(size_t, const char *name, unsigned,
Affinity::Location, addr_t, Affinity::Location, addr_t)
int thread_id) : _l4_thread_id(L4_INVALID_ID), _name(name) { }
: _thread_id(thread_id), _l4_thread_id(L4_INVALID_ID), _pager(0)
{
strncpy(_name, name, sizeof(_name)); Platform_thread::Platform_thread(const char *name)
} : _l4_thread_id(L4_INVALID_ID), _name(name) { }
Platform_thread::~Platform_thread() Platform_thread::~Platform_thread()
@ -169,5 +169,5 @@ Platform_thread::~Platform_thread()
* Thread::unbind() * Thread::unbind()
*/ */
if (_platform_pd) if (_platform_pd)
_platform_pd->unbind_thread(this); _platform_pd->unbind_thread(*this);
} }

View File

@ -18,10 +18,10 @@
using namespace Genode; using namespace Genode;
void Ram_dataspace_factory::_export_ram_ds(Dataspace_component *) { } void Ram_dataspace_factory::_export_ram_ds(Dataspace_component &) { }
void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component *) { } void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component &) { }
void Ram_dataspace_factory::_clear_ds(Dataspace_component *ds) void Ram_dataspace_factory::_clear_ds(Dataspace_component &ds)
{ {
memset((void *)ds->phys_addr(), 0, ds->size()); memset((void *)ds.phys_addr(), 0, ds.size());
} }

View File

@ -37,12 +37,12 @@ void Thread::_thread_start()
void Thread::start() void Thread::start()
{ {
/* create and start platform thread */ /* create and start platform thread */
native_thread().pt = new(platform()->core_mem_alloc()) native_thread().pt = new (platform().core_mem_alloc())
Platform_thread(0, _stack->name().string()); Platform_thread(_stack->name().string());
platform_specific()->core_pd()->bind_thread(native_thread().pt); platform_specific().core_pd().bind_thread(*native_thread().pt);
native_thread().pt->pager(platform_specific()->core_pager()); native_thread().pt->pager(platform_specific().core_pager());
native_thread().l4id = native_thread().pt->native_thread_id(); native_thread().l4id = native_thread().pt->native_thread_id();
native_thread().pt->start((void *)_thread_start, stack_top()); native_thread().pt->start((void *)_thread_start, stack_top());
@ -60,5 +60,5 @@ void Thread::cancel_blocking()
void Thread::_deinit_platform_thread() void Thread::_deinit_platform_thread()
{ {
/* destruct platform thread */ /* destruct platform thread */
destroy(platform()->core_mem_alloc(), native_thread().pt); destroy(platform().core_mem_alloc(), native_thread().pt);
} }

View File

@ -42,7 +42,7 @@ namespace Genode {
class Out_of_ids : Exception {}; class Out_of_ids : Exception {};
Cap_id_allocator(Allocator*); Cap_id_allocator(Allocator &);
unsigned long alloc(); unsigned long alloc();
void free(unsigned long id); void free(unsigned long id);

View File

@ -36,7 +36,7 @@ namespace Genode {
* *
* \return pointer to newly constructed Core_cap_index object * \return pointer to newly constructed Core_cap_index object
*/ */
inline Core_cap_index* _get_cap(); inline Core_cap_index *_get_cap();
public: public:

View File

@ -1,72 +0,0 @@
/*
* \brief Fiasco.OC-specific implementation of core's CPU service
* \author Christian Helmuth
* \author Norman Feske
* \author Stefan Kalkowski
* \date 2006-07-17
*/
/*
* Copyright (C) 2006-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__CPU_SESSION_IRQS_H_
#define _CORE__INCLUDE__CPU_SESSION_IRQS_H_
/* Genode includes */
#include <util/avl_tree.h>
/* core includes */
#include <cpu_session_component.h>
namespace Genode { class Cpu_session_irqs; }
class Genode::Cpu_session_irqs : public Avl_node<Cpu_session_irqs>
{
private:
/*
* Noncopyable
*/
Cpu_session_irqs(Cpu_session_irqs const &);
Cpu_session_irqs &operator = (Cpu_session_irqs const &);
enum { IRQ_MAX = 20 };
Cpu_session_component* _owner;
Native_capability _irqs[IRQ_MAX];
unsigned _cnt;
public:
Cpu_session_irqs(Cpu_session_component *owner)
: _owner(owner), _cnt(0) {}
bool add(Native_capability irq)
{
if (_cnt >= (IRQ_MAX - 1))
return false;
_irqs[_cnt++] = irq;
return true;
}
/************************
** Avl node interface **
************************/
bool higher(Cpu_session_irqs *c) { return (c->_owner > _owner); }
Cpu_session_irqs *find_by_session(Cpu_session_component *o)
{
if (o == _owner) return this;
Cpu_session_irqs *c = Avl_node<Cpu_session_irqs>::child(o > _owner);
return c ? c->find_by_session(o) : 0;
}
};
#endif /* _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ */

View File

@ -202,13 +202,13 @@ class Genode::Ipc_pager : public Native_capability
* Copy the exception registers from the last exception * Copy the exception registers from the last exception
* to the given Thread_state object. * to the given Thread_state object.
*/ */
void get_regs(Foc_thread_state *state); void get_regs(Foc_thread_state &state) const;
/* /*
* Copy the exception reply registers from the given * Copy the exception reply registers from the given
* Thread_state object * Thread_state object
*/ */
void set_regs(Foc_thread_state state); void set_regs(Foc_thread_state const &state);
}; };
#endif /* _CORE__INCLUDE__IPC_PAGER_H_ */ #endif /* _CORE__INCLUDE__IPC_PAGER_H_ */

View File

@ -26,6 +26,7 @@
#include <platform_generic.h> #include <platform_generic.h>
#include <platform_thread.h> #include <platform_thread.h>
#include <platform_pd.h> #include <platform_pd.h>
#include <assertion.h>
namespace Genode { namespace Genode {
@ -123,7 +124,7 @@ namespace Genode {
/** /**
* Constructor * Constructor
*/ */
Core_pager(Platform_pd *core_pd, Sigma0*); Core_pager(Platform_pd &core_pd, Sigma0 &);
int pager(Ipc_pager &) { /* never called */ return -1; } int pager(Ipc_pager &) { /* never called */ return -1; }
}; };
@ -131,7 +132,7 @@ namespace Genode {
/** /**
* Return singleton instance of core pager object * Return singleton instance of core pager object
*/ */
Core_pager *core_pager(); Core_pager &core_pager();
/** /**
* Set interrupt trigger/polarity (e.g., level or edge, high or low) * Set interrupt trigger/polarity (e.g., level or edge, high or low)
@ -147,26 +148,33 @@ namespace Genode {
/** /**
* Accessor for core pd object * Accessor for core pd object
*/ */
Platform_pd *core_pd() { return _core_pd; } Platform_pd &core_pd()
{
if (_core_pd)
return *_core_pd;
ASSERT_NEVER_CALLED;
}
/******************************** /********************************
** Generic platform interface ** ** Generic platform interface **
********************************/ ********************************/
Range_allocator *core_mem_alloc() { return &_ram_alloc; } Range_allocator &core_mem_alloc() override { return _ram_alloc; }
Range_allocator *ram_alloc() { return &_ram_alloc; } Range_allocator &ram_alloc() override { return _ram_alloc; }
Range_allocator *io_mem_alloc() { return &_io_mem_alloc; } Range_allocator &io_mem_alloc() override { return _io_mem_alloc; }
Range_allocator *io_port_alloc() { return &_io_port_alloc; } Range_allocator &io_port_alloc() override { return _io_port_alloc; }
Range_allocator *irq_alloc() { return &_irq_alloc; } Range_allocator &irq_alloc() override { return _irq_alloc; }
Range_allocator *region_alloc() { return &_region_alloc; } Range_allocator &region_alloc() override { return _region_alloc; }
Cap_id_allocator *cap_id_alloc() { return &_cap_id_alloc; } addr_t vm_start() const override { return _vm_start; }
addr_t vm_start() const { return _vm_start; } size_t vm_size() const override { return _vm_size; }
size_t vm_size() const { return _vm_size; } Rom_fs &rom_fs() override { return _rom_fs; }
Rom_fs *rom_fs() { return &_rom_fs; } Affinity::Space affinity_space() const override;
Affinity::Space affinity_space() const;
size_t max_caps() const override { return cap_idx_alloc()->max_caps(); } size_t max_caps() const override { return cap_idx_alloc().max_caps(); }
Cap_id_allocator &cap_id_alloc() { return _cap_id_alloc; }
void wait_for_exit(); void wait_for_exit();
}; };

View File

@ -65,7 +65,7 @@ namespace Genode {
Cap_mapping _task; Cap_mapping _task;
Cap_mapping _parent { }; Cap_mapping _parent { };
Cap_mapping _debug { }; Cap_mapping _debug { };
Platform_thread *_threads[THREAD_MAX]; Platform_thread *_threads[THREAD_MAX] { };
public: public:
@ -73,14 +73,14 @@ namespace Genode {
/** /**
* Constructor for core. * Constructor for core
*/ */
Platform_pd(Core_cap_index*); Platform_pd(Core_cap_index &);
/** /**
* Constructor for all tasks except core. * Constructor for all tasks except core.
*/ */
Platform_pd(Allocator *, char const *label); Platform_pd(Allocator &, char const *label);
/** /**
* Destructor * Destructor
@ -90,14 +90,14 @@ namespace Genode {
/** /**
* Bind thread to protection domain * Bind thread to protection domain
*/ */
bool bind_thread(Platform_thread *thread); bool bind_thread(Platform_thread &);
/** /**
* Unbind thread from protection domain * Unbind thread from protection domain
* *
* Free the thread's slot and update thread object. * Free the thread's slot and update thread object.
*/ */
void unbind_thread(Platform_thread *thread); void unbind_thread(Platform_thread &);
/** /**
* Assign parent interface to protection domain * Assign parent interface to protection domain

View File

@ -23,6 +23,7 @@
#include <pager.h> #include <pager.h>
#include <platform_pd.h> #include <platform_pd.h>
#include <cap_mapping.h> #include <cap_mapping.h>
#include <assertion.h>
namespace Genode { namespace Genode {
@ -39,8 +40,11 @@ namespace Genode {
enum State { DEAD, RUNNING }; enum State { DEAD, RUNNING };
typedef String<32> Name;
friend class Platform_pd; friend class Platform_pd;
Name const _name; /* name at kernel debugger */
State _state; State _state;
bool _core_thread; bool _core_thread;
Cap_mapping _thread; Cap_mapping _thread;
@ -48,9 +52,6 @@ namespace Genode {
Cap_mapping _pager { }; Cap_mapping _pager { };
Cap_mapping _irq; Cap_mapping _irq;
addr_t _utcb; addr_t _utcb;
char _name[32]; /* thread name that will be
registered at the kernel
debugger */
Platform_pd *_platform_pd; /* protection domain thread Platform_pd *_platform_pd; /* protection domain thread
is bound to */ is bound to */
Pager_object *_pager_obj; Pager_object *_pager_obj;
@ -59,7 +60,7 @@ namespace Genode {
Affinity::Location _location { }; Affinity::Location _location { };
void _create_thread(void); void _create_thread(void);
void _finalize_construction(const char *name); void _finalize_construction();
bool _in_syscall(Fiasco::l4_umword_t flags); bool _in_syscall(Fiasco::l4_umword_t flags);
public: public:
@ -75,8 +76,8 @@ namespace Genode {
/** /**
* Constructor for core main-thread * Constructor for core main-thread
*/ */
Platform_thread(Core_cap_index* thread, Platform_thread(Core_cap_index& thread,
Core_cap_index* irq, const char *name); Core_cap_index& irq, const char *name);
/** /**
* Constructor for core threads * Constructor for core threads
@ -124,7 +125,7 @@ namespace Genode {
* *
* \param pd platform pd, thread is bound to * \param pd platform pd, thread is bound to
*/ */
void bind(Platform_pd *pd); void bind(Platform_pd &pd);
/** /**
* Unbind this thread * Unbind this thread
@ -162,8 +163,15 @@ namespace Genode {
/** /**
* Return/set pager * Return/set pager
*/ */
Pager_object *pager() const { return _pager_obj; } Pager_object &pager() const
void pager(Pager_object *pager); {
if (_pager_obj)
return *_pager_obj;
ASSERT_NEVER_CALLED;
}
void pager(Pager_object &pager);
/** /**
* Return identification of thread when faulting * Return identification of thread when faulting
@ -188,7 +196,7 @@ namespace Genode {
Cap_mapping const & thread() const { return _thread; } Cap_mapping const & thread() const { return _thread; }
Cap_mapping & gate() { return _gate; } Cap_mapping & gate() { return _gate; }
const char *name() const { return _name; } Name name() const { return _name; }
bool core_thread() const { return _core_thread; } bool core_thread() const { return _core_thread; }
addr_t utcb() const { return _utcb; } addr_t utcb() const { return _utcb; }
}; };

View File

@ -23,7 +23,7 @@ using namespace Genode;
void Io_mem_session_component::_unmap_local(addr_t base, size_t) void Io_mem_session_component::_unmap_local(addr_t base, size_t)
{ {
platform()->region_alloc()->free(reinterpret_cast<void *>(base)); platform().region_alloc().free(reinterpret_cast<void *>(base));
} }
@ -35,7 +35,7 @@ addr_t Io_mem_session_component::_map_local(addr_t base, size_t size)
/* find appropriate region for mapping */ /* find appropriate region for mapping */
void *local_base = 0; void *local_base = 0;
if (platform()->region_alloc()->alloc_aligned(size, &local_base, alignment).error()) if (platform().region_alloc().alloc_aligned(size, &local_base, alignment).error())
return 0; return 0;
if (!map_local_io(base, (addr_t)local_base, size >> get_page_size_log2())) { if (!map_local_io(base, (addr_t)local_base, size >> get_page_size_log2())) {

View File

@ -147,7 +147,7 @@ void Genode::Irq_object::ack_irq()
Genode::Irq_object::Irq_object() Genode::Irq_object::Irq_object()
: :
_cap(cap_map()->insert(platform_specific()->cap_id_alloc()->alloc())), _cap(cap_map().insert(platform_specific().cap_id_alloc().alloc())),
_trigger(Irq_session::TRIGGER_UNCHANGED), _trigger(Irq_session::TRIGGER_UNCHANGED),
_polarity(Irq_session::POLARITY_UNCHANGED), _polarity(Irq_session::POLARITY_UNCHANGED),
_irq(~0U), _msi_addr(0), _msi_data(0) _irq(~0U), _msi_addr(0), _msi_data(0)
@ -170,7 +170,7 @@ Genode::Irq_object::~Irq_object()
if (l4_error(l4_icu_unbind(L4_BASE_ICU_CAP, irq, _capability()))) if (l4_error(l4_icu_unbind(L4_BASE_ICU_CAP, irq, _capability())))
error("cannot unbind IRQ"); error("cannot unbind IRQ");
cap_map()->remove(_cap); cap_map().remove(_cap);
} }
@ -179,7 +179,7 @@ Genode::Irq_object::~Irq_object()
***************************/ ***************************/
Irq_session_component::Irq_session_component(Range_allocator *irq_alloc, Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
const char *args) const char *args)
: _irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)), : _irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)),
_irq_alloc(irq_alloc), _irq_object() _irq_alloc(irq_alloc), _irq_object()
@ -192,7 +192,7 @@ Irq_session_component::Irq_session_component(Range_allocator *irq_alloc,
} }
msi_alloc.set(_irq_number, 1); msi_alloc.set(_irq_number, 1);
} else { } else {
if (!irq_alloc || irq_alloc->alloc_addr(1, _irq_number).error()) { if (irq_alloc.alloc_addr(1, _irq_number).error()) {
error("unavailable IRQ ", _irq_number, " requested"); error("unavailable IRQ ", _irq_number, " requested");
throw Service_denied(); throw Service_denied();
} }
@ -208,7 +208,7 @@ Irq_session_component::Irq_session_component(Range_allocator *irq_alloc,
msi_alloc.clear(_irq_number, 1); msi_alloc.clear(_irq_number, 1);
else { else {
addr_t const free_irq = _irq_number; addr_t const free_irq = _irq_number;
_irq_alloc->free((void *)free_irq); _irq_alloc.free((void *)free_irq);
} }
throw Service_denied(); throw Service_denied();
} }
@ -223,7 +223,7 @@ Irq_session_component::~Irq_session_component()
msi_alloc.clear(_irq_number, 1); msi_alloc.clear(_irq_number, 1);
} else { } else {
Genode::addr_t free_irq = _irq_number; Genode::addr_t free_irq = _irq_number;
_irq_alloc->free((void *)free_irq); _irq_alloc.free((void *)free_irq);
} }
} }

View File

@ -16,7 +16,7 @@
/* core includes */ /* core includes */
#include <native_cpu_component.h> #include <native_cpu_component.h>
#include <cpu_session_irqs.h> #include <cpu_session_component.h>
#include <platform.h> #include <platform.h>
/* Fiasco.OC includes */ /* Fiasco.OC includes */
@ -54,7 +54,7 @@ Genode::Native_cpu_component::thread_state(Genode::Thread_capability cap)
Genode::Native_cpu_component::Native_cpu_component(Cpu_session_component &cpu_session, char const *) Genode::Native_cpu_component::Native_cpu_component(Cpu_session_component &cpu_session, char const *)
: :
_cpu_session(cpu_session), _thread_ep(*_cpu_session._thread_ep) _cpu_session(cpu_session), _thread_ep(_cpu_session._thread_ep)
{ {
_thread_ep.manage(this); _thread_ep.manage(this);
} }

View File

@ -59,7 +59,7 @@ void Pager_entrypoint::entry()
{ {
if (_pager.exception()) { if (_pager.exception()) {
Lock::Guard guard(obj->state.lock); Lock::Guard guard(obj->state.lock);
_pager.get_regs(&obj->state); _pager.get_regs(obj->state);
obj->state.exceptions++; obj->state.exceptions++;
obj->state.in_exception = true; obj->state.in_exception = true;
obj->submit_exception_signal(); obj->submit_exception_signal();
@ -115,7 +115,7 @@ void Pager_entrypoint::entry()
case Ipc_pager::PAUSE: case Ipc_pager::PAUSE:
{ {
Lock::Guard guard(obj->state.lock); Lock::Guard guard(obj->state.lock);
_pager.get_regs(&obj->state); _pager.get_regs(obj->state);
obj->state.exceptions++; obj->state.exceptions++;
obj->state.in_exception = true; obj->state.in_exception = true;
@ -139,24 +139,24 @@ void Pager_entrypoint::entry()
} }
void Pager_entrypoint::dissolve(Pager_object *obj) void Pager_entrypoint::dissolve(Pager_object &obj)
{ {
/* cleanup at cap session */ /* cleanup at cap session */
_cap_factory.free(obj->Object_pool<Pager_object>::Entry::cap()); _cap_factory.free(obj.Object_pool<Pager_object>::Entry::cap());
remove(obj); remove(&obj);
} }
Pager_capability Pager_entrypoint::manage(Pager_object *obj) Pager_capability Pager_entrypoint::manage(Pager_object &obj)
{ {
using namespace Fiasco; using namespace Fiasco;
Native_capability cap(_cap_factory.alloc(Thread::_thread_cap)); Native_capability cap(_cap_factory.alloc(Thread::_thread_cap));
/* add server object to object pool */ /* add server object to object pool */
obj->cap(cap); obj.cap(cap);
insert(obj); insert(&obj);
/* return capability that uses the object id as badge */ /* return capability that uses the object id as badge */
return reinterpret_cap_cast<Pager_object>(cap); return reinterpret_cap_cast<Pager_object>(cap);

View File

@ -137,7 +137,7 @@ Platform::Sigma0::Sigma0(Cap_index* i)
} }
Platform::Core_pager::Core_pager(Platform_pd *core_pd, Sigma0 *sigma0) Platform::Core_pager::Core_pager(Platform_pd &core_pd, Sigma0 &sigma0)
: :
Platform_thread("core.pager"), Platform_thread("core.pager"),
Pager_object(Cpu_session_capability(), Thread_capability(), Pager_object(Cpu_session_capability(), Thread_capability(),
@ -146,7 +146,7 @@ Platform::Core_pager::Core_pager(Platform_pd *core_pd, Sigma0 *sigma0)
{ {
Platform_thread::pager(sigma0); Platform_thread::pager(sigma0);
core_pd->bind_thread(this); core_pd.bind_thread(*this);
cap(thread().local); cap(thread().local);
/* stack begins at the top end of the '_core_pager_stack' array */ /* stack begins at the top end of the '_core_pager_stack' array */
@ -164,10 +164,10 @@ Platform::Core_pager::Core_pager(Platform_pd *core_pd, Sigma0 *sigma0)
} }
Platform::Core_pager *Platform::core_pager() Platform::Core_pager &Platform::core_pager()
{ {
static Core_pager _core_pager(core_pd(), &_sigma0); static Core_pager _core_pager(core_pd(), _sigma0);
return &_core_pager; return _core_pager;
} }
@ -248,13 +248,13 @@ static inline int sigma0_req_region(addr_t *addr, unsigned log2size)
} }
static Fiasco::l4_kernel_info_t *sigma0_map_kip() static Fiasco::l4_kernel_info_t &sigma0_map_kip()
{ {
using namespace Fiasco; using namespace Fiasco;
static l4_kernel_info_t *kip = nullptr; static l4_kernel_info_t *kip_ptr = nullptr;
if (kip) return kip; if (kip_ptr) return *kip_ptr;
/* signal we want to map the KIP */ /* signal we want to map the KIP */
l4_utcb_mr()->mr[0] = SIGMA0_REQ_KIP; l4_utcb_mr()->mr[0] = SIGMA0_REQ_KIP;
@ -270,15 +270,15 @@ static Fiasco::l4_kernel_info_t *sigma0_map_kip()
l4_msgtag(L4_PROTO_SIGMA0, 1, 0, 0), l4_msgtag(L4_PROTO_SIGMA0, 1, 0, 0),
L4_IPC_NEVER); L4_IPC_NEVER);
if (l4_ipc_error(tag, l4_utcb())) if (l4_ipc_error(tag, l4_utcb()))
return 0; panic("kip request to sigma0 failed");
l4_addr_t ret = l4_trunc_page(l4_utcb_mr()->mr[0]); l4_addr_t ret = l4_trunc_page(l4_utcb_mr()->mr[0]);
if (!ret) if (!ret)
panic("kip mapping failed"); panic("kip mapping failed");
else
kip = (l4_kernel_info_t*) ret; kip_ptr = (l4_kernel_info_t*)ret;
return kip;
return *kip_ptr;
} }
@ -347,21 +347,21 @@ void Platform::_setup_basics()
{ {
using namespace Fiasco; using namespace Fiasco;
l4_kernel_info_t * kip = sigma0_map_kip(); l4_kernel_info_t const &kip = sigma0_map_kip();
if (kip->magic != L4_KERNEL_INFO_MAGIC) if (kip.magic != L4_KERNEL_INFO_MAGIC)
panic("Sigma0 mapped something but not the KIP"); panic("Sigma0 mapped something but not the KIP");
log(""); log("");
log("KIP @ ", kip); log("KIP @ ", &kip);
log(" magic: ", Hex(kip->magic)); log(" magic: ", Hex(kip.magic));
log(" version: ", Hex(kip->version)); log(" version: ", Hex(kip.version));
/* add KIP as ROM module */ /* add KIP as ROM module */
_rom_fs.insert(&_kip_rom); _rom_fs.insert(&_kip_rom);
/* update multi-boot info pointer from KIP */ /* update multi-boot info pointer from KIP */
addr_t mb_info_addr = kip->user_ptr; addr_t mb_info_addr = kip.user_ptr;
log("MBI @ ", Hex(mb_info_addr)); log("MBI @ ", Hex(mb_info_addr));
/* parse memory descriptors - look for virtual memory configuration */ /* parse memory descriptors - look for virtual memory configuration */
@ -369,9 +369,9 @@ void Platform::_setup_basics()
using Fiasco::L4::Kip::Mem_desc; using Fiasco::L4::Kip::Mem_desc;
_vm_start = 0; _vm_size = 0; _vm_start = 0; _vm_size = 0;
Mem_desc *desc = Mem_desc::first(kip); Mem_desc const * const desc = Mem_desc::first(&kip);
for (unsigned i = 0; i < Mem_desc::count(kip); ++i) for (unsigned i = 0; i < Mem_desc::count(&kip); ++i)
if (desc[i].is_virtual()) { if (desc[i].is_virtual()) {
_vm_start = round_page(desc[i].start()); _vm_start = round_page(desc[i].start());
_vm_size = trunc_page(desc[i].end() - _vm_start + 1); _vm_size = trunc_page(desc[i].end() - _vm_start + 1);
@ -398,8 +398,8 @@ void Platform::_setup_basics()
_io_mem_alloc.add_range(0, ~0); _io_mem_alloc.add_range(0, ~0);
/* remove KIP and MBI area from region and IO_MEM allocator */ /* remove KIP and MBI area from region and IO_MEM allocator */
remove_region(Region((addr_t)kip, (addr_t)kip + L4_PAGESIZE), _region_alloc); remove_region(Region((addr_t)&kip, (addr_t)&kip + L4_PAGESIZE), _region_alloc);
remove_region(Region((addr_t)kip, (addr_t)kip + L4_PAGESIZE), _io_mem_alloc); remove_region(Region((addr_t)&kip, (addr_t)&kip + L4_PAGESIZE), _io_mem_alloc);
/* remove core program image memory from region and IO_MEM allocator */ /* remove core program image memory from region and IO_MEM allocator */
addr_t img_start = (addr_t) &_prog_img_beg; addr_t img_start = (addr_t) &_prog_img_beg;
@ -413,11 +413,11 @@ void Platform::_setup_basics()
Platform::Platform() : Platform::Platform() :
_ram_alloc(nullptr), _io_mem_alloc(core_mem_alloc()), _ram_alloc(nullptr), _io_mem_alloc(&core_mem_alloc()),
_io_port_alloc(core_mem_alloc()), _irq_alloc(core_mem_alloc()), _io_port_alloc(&core_mem_alloc()), _irq_alloc(&core_mem_alloc()),
_region_alloc(core_mem_alloc()), _cap_id_alloc(core_mem_alloc()), _region_alloc(&core_mem_alloc()), _cap_id_alloc(core_mem_alloc()),
_kip_rom((addr_t)sigma0_map_kip(), L4_PAGESIZE, "l4v2_kip"), _kip_rom((addr_t)&sigma0_map_kip(), L4_PAGESIZE, "l4v2_kip"),
_sigma0(cap_map()->insert(_cap_id_alloc.alloc(), Fiasco::L4_BASE_PAGER_CAP)) _sigma0(cap_map().insert(_cap_id_alloc.alloc(), Fiasco::L4_BASE_PAGER_CAP))
{ {
/* /*
* We must be single-threaded at this stage and so this is safe. * We must be single-threaded at this stage and so this is safe.
@ -434,31 +434,33 @@ Platform::Platform() :
log(_rom_fs); log(_rom_fs);
Core_cap_index* pdi = Core_cap_index &pdi =
reinterpret_cast<Core_cap_index*>(cap_map()->insert(_cap_id_alloc.alloc(), Fiasco::L4_BASE_TASK_CAP)); *reinterpret_cast<Core_cap_index*>(cap_map().insert(_cap_id_alloc.alloc(),
Core_cap_index* thi = Fiasco::L4_BASE_TASK_CAP));
reinterpret_cast<Core_cap_index*>(cap_map()->insert(_cap_id_alloc.alloc(), Fiasco::L4_BASE_THREAD_CAP)); Core_cap_index &thi =
Core_cap_index* irqi = *reinterpret_cast<Core_cap_index*>(cap_map().insert(_cap_id_alloc.alloc(),
reinterpret_cast<Core_cap_index*>(cap_map()->insert(_cap_id_alloc.alloc())); Fiasco::L4_BASE_THREAD_CAP));
Core_cap_index &irqi =
*reinterpret_cast<Core_cap_index*>(cap_map().insert(_cap_id_alloc.alloc()));
/* setup pd object for core pd */ /* setup pd object for core pd */
_core_pd = new(core_mem_alloc()) Platform_pd(pdi); _core_pd = new (core_mem_alloc()) Platform_pd(pdi);
/* /*
* We setup the thread object for thread0 in core pd using a special * We setup the thread object for thread0 in core pd using a special
* interface that allows us to specify the capability slot. * interface that allows us to specify the capability slot.
*/ */
Platform_thread *core_thread = new(core_mem_alloc()) Platform_thread &core_thread = *new (core_mem_alloc())
Platform_thread(thi, irqi, "core.main"); Platform_thread(thi, irqi, "core.main");
core_thread->pager(&_sigma0); core_thread.pager(_sigma0);
_core_pd->bind_thread(core_thread); _core_pd->bind_thread(core_thread);
{ {
/* export x86 platform specific infos */ /* export x86 platform specific infos */
void * phys_ptr = nullptr; void * phys_ptr = nullptr;
if (ram_alloc()->alloc_aligned(get_page_size(), &phys_ptr, if (ram_alloc().alloc_aligned(get_page_size(), &phys_ptr,
get_page_size_log2()).ok()) { get_page_size_log2()).ok()) {
addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr); addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr);
/* empty for now */ /* empty for now */
_rom_fs.insert(new (core_mem_alloc()) Rom_module(phys_addr, _rom_fs.insert(new (core_mem_alloc()) Rom_module(phys_addr,
@ -474,11 +476,11 @@ Platform::Platform() :
unsigned const pages = 1; unsigned const pages = 1;
size_t const log_size = pages << get_page_size_log2(); size_t const log_size = pages << get_page_size_log2();
ram_alloc()->alloc_aligned(log_size, &phys_ptr, get_page_size_log2()); ram_alloc().alloc_aligned(log_size, &phys_ptr, get_page_size_log2());
addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr); addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr);
/* let one page free after the log buffer */ /* let one page free after the log buffer */
region_alloc()->alloc_aligned(log_size, &core_local_ptr, get_page_size_log2()); region_alloc().alloc_aligned(log_size, &core_local_ptr, get_page_size_log2());
addr_t const core_local_addr = reinterpret_cast<addr_t>(core_local_ptr); addr_t const core_local_addr = reinterpret_cast<addr_t>(core_local_ptr);
map_local(phys_addr, core_local_addr, pages); map_local(phys_addr, core_local_addr, pages);

View File

@ -42,42 +42,42 @@ static addr_t core_utcb_base() {
** Public object members ** ** Public object members **
***************************/ ***************************/
bool Platform_pd::bind_thread(Platform_thread *thread) bool Platform_pd::bind_thread(Platform_thread &thread)
{ {
/* /*
* Fiasco.OC limits the UTCB area for roottask to 16K. Therefore, the * Fiasco.OC limits the UTCB area for roottask to 16K. Therefore, the
* number of threads is limited to 16K / L4_UTCB_OFFSET. * number of threads is limited to 16K / L4_UTCB_OFFSET.
* (see kernel/fiasco/src/kern/kernel_thread-std.cpp:94) * (see kernel/fiasco/src/kern/kernel_thread-std.cpp:94)
*/ */
unsigned const thread_max = thread->core_thread() ? 16*1024/L4_UTCB_OFFSET : THREAD_MAX; unsigned const thread_max = thread.core_thread() ? 16*1024/L4_UTCB_OFFSET : THREAD_MAX;
for (unsigned i = 0; i < thread_max; i++) { for (unsigned i = 0; i < thread_max; i++) {
if (_threads[i]) if (_threads[i])
continue; continue;
_threads[i] = thread; _threads[i] = &thread;
if (thread->core_thread()) if (thread.core_thread())
thread->_utcb = (addr_t) (core_utcb_base() + i * L4_UTCB_OFFSET); thread._utcb = (addr_t) (core_utcb_base() + i * L4_UTCB_OFFSET);
else else
thread->_utcb = thread._utcb =
reinterpret_cast<addr_t>(utcb_area_start() + i * L4_UTCB_OFFSET); reinterpret_cast<addr_t>(utcb_area_start() + i * L4_UTCB_OFFSET);
Fiasco::l4_cap_idx_t cap_offset = THREAD_AREA_BASE + i * THREAD_AREA_SLOT; Fiasco::l4_cap_idx_t cap_offset = THREAD_AREA_BASE + i * THREAD_AREA_SLOT;
thread->_gate.remote = cap_offset + THREAD_GATE_CAP; thread._gate.remote = cap_offset + THREAD_GATE_CAP;
thread->_pager.remote = cap_offset + THREAD_PAGER_CAP; thread._pager.remote = cap_offset + THREAD_PAGER_CAP;
thread->_irq.remote = cap_offset + THREAD_IRQ_CAP; thread._irq.remote = cap_offset + THREAD_IRQ_CAP;
/* if it's no core-thread we have to map parent and pager gate cap */ /* if it's no core-thread we have to map parent and pager gate cap */
if (!thread->core_thread()) { if (!thread.core_thread()) {
_task.map(_task.local.data()->kcap()); _task.map(_task.local.data()->kcap());
// FIXME: there is no debug cap anymore // FIXME: there is no debug cap anymore
// _debug.map(_task.local.data()->kcap()); // _debug.map(_task.local.data()->kcap());
} }
/* inform thread about binding */ /* inform thread about binding */
thread->bind(this); thread.bind(*this);
return true; return true;
} }
@ -86,14 +86,14 @@ bool Platform_pd::bind_thread(Platform_thread *thread)
} }
void Platform_pd::unbind_thread(Platform_thread *thread) void Platform_pd::unbind_thread(Platform_thread &thread)
{ {
/* inform thread about unbinding */ /* inform thread about unbinding */
thread->unbind(); thread.unbind();
for (unsigned i = 0; i < THREAD_MAX; i++) for (unsigned i = 0; i < THREAD_MAX; i++)
if (_threads[i] == thread) { if (_threads[i] == &thread) {
_threads[i] = (Platform_thread*) 0; _threads[i] = (Platform_thread*)nullptr;
return; return;
} }
} }
@ -117,25 +117,19 @@ void Platform_pd::flush(addr_t, size_t size, Core_local_addr core_local)
static Core_cap_index * debug_cap() static Core_cap_index * debug_cap()
{ {
unsigned long id = platform_specific()->cap_id_alloc()->alloc(); unsigned long const id = platform_specific().cap_id_alloc().alloc();
static Cap_index * idx = cap_map()->insert(id, DEBUG_CAP); static Cap_index * idx = cap_map().insert(id, DEBUG_CAP);
return reinterpret_cast<Core_cap_index*>(idx); return reinterpret_cast<Core_cap_index*>(idx);
} }
Platform_pd::Platform_pd(Core_cap_index* i) Platform_pd::Platform_pd(Core_cap_index &ci)
: _task(Native_capability(i), TASK_CAP) : _task(Native_capability(&ci), TASK_CAP)
{ { }
for (unsigned i = 0; i < THREAD_MAX; i++)
_threads[i] = (Platform_thread*) 0;
}
Platform_pd::Platform_pd(Allocator *, char const *) Platform_pd::Platform_pd(Allocator &, char const *)
: _task(true, TASK_CAP), _debug(debug_cap(), DEBUG_CAP) : _task(true, TASK_CAP), _debug(debug_cap(), DEBUG_CAP)
{ {
for (unsigned i = 0; i < THREAD_MAX; i++)
_threads[i] = (Platform_thread*) 0;
l4_fpage_t utcb_area = l4_fpage(utcb_area_start(), l4_fpage_t utcb_area = l4_fpage(utcb_area_start(),
log2<unsigned>(UTCB_AREA_SIZE), 0); log2<unsigned>(UTCB_AREA_SIZE), 0);
l4_msgtag_t tag = l4_factory_create_task(L4_BASE_FACTORY_CAP, l4_msgtag_t tag = l4_factory_create_task(L4_BASE_FACTORY_CAP,

View File

@ -153,11 +153,11 @@ void Platform_thread::resume()
} }
void Platform_thread::bind(Platform_pd *pd) void Platform_thread::bind(Platform_pd &pd)
{ {
_platform_pd = pd; _platform_pd = &pd;
_gate.map(pd->native_task().data()->kcap()); _gate.map(pd.native_task().data()->kcap());
_irq.map(pd->native_task().data()->kcap()); _irq.map(pd.native_task().data()->kcap());
} }
@ -180,11 +180,11 @@ void Platform_thread::unbind()
} }
void Platform_thread::pager(Pager_object *pager_obj) void Platform_thread::pager(Pager_object &pager_obj)
{ {
_pager_obj = pager_obj; _pager_obj = &pager_obj;
if (_pager_obj) if (_pager_obj)
_pager.local = pager_obj->cap(); _pager.local = pager_obj.cap();
else else
_pager.local = Native_capability(); _pager.local = Native_capability();
} }
@ -240,7 +240,7 @@ Affinity::Location Platform_thread::affinity() const
static Rpc_cap_factory &thread_cap_factory() static Rpc_cap_factory &thread_cap_factory()
{ {
static Rpc_cap_factory inst(*platform()->core_mem_alloc()); static Rpc_cap_factory inst(platform().core_mem_alloc());
return inst; return inst;
} }
@ -257,7 +257,7 @@ void Platform_thread::_create_thread()
} }
void Platform_thread::_finalize_construction(const char *name) void Platform_thread::_finalize_construction()
{ {
/* create irq for new thread */ /* create irq for new thread */
l4_msgtag_t tag = l4_factory_create_irq(L4_BASE_FACTORY_CAP, l4_msgtag_t tag = l4_factory_create_irq(L4_BASE_FACTORY_CAP,
@ -271,8 +271,7 @@ void Platform_thread::_finalize_construction(const char *name)
warning("attaching thread's irq failed"); warning("attaching thread's irq failed");
/* set human readable name in kernel debugger */ /* set human readable name in kernel debugger */
strncpy(_name, name, sizeof(_name)); Fiasco::l4_debugger_set_object_name(_thread.local.data()->kcap(), _name.string());
Fiasco::l4_debugger_set_object_name(_thread.local.data()->kcap(), name);
/* set priority of thread */ /* set priority of thread */
l4_sched_param_t params = l4_sched_param(_prio); l4_sched_param_t params = l4_sched_param(_prio);
@ -283,7 +282,8 @@ void Platform_thread::_finalize_construction(const char *name)
Platform_thread::Platform_thread(size_t, const char *name, unsigned prio, Platform_thread::Platform_thread(size_t, const char *name, unsigned prio,
Affinity::Location location, addr_t) Affinity::Location location, addr_t)
: _state(DEAD), : _name(name),
_state(DEAD),
_core_thread(false), _core_thread(false),
_thread(true), _thread(true),
_irq(true), _irq(true),
@ -295,17 +295,18 @@ Platform_thread::Platform_thread(size_t, const char *name, unsigned prio,
/* XXX remove const cast */ /* XXX remove const cast */
((Core_cap_index *)_thread.local.data())->pt(this); ((Core_cap_index *)_thread.local.data())->pt(this);
_create_thread(); _create_thread();
_finalize_construction(name); _finalize_construction();
affinity(location); affinity(location);
} }
Platform_thread::Platform_thread(Core_cap_index* thread, Platform_thread::Platform_thread(Core_cap_index &thread,
Core_cap_index* irq, const char *name) Core_cap_index &irq, const char *name)
: _state(RUNNING), : _name(name),
_state(RUNNING),
_core_thread(true), _core_thread(true),
_thread(Native_capability(thread), L4_BASE_THREAD_CAP), _thread(Native_capability(&thread), L4_BASE_THREAD_CAP),
_irq(Native_capability(irq)), _irq(Native_capability(&irq)),
_utcb(0), _utcb(0),
_platform_pd(0), _platform_pd(0),
_pager_obj(0), _pager_obj(0),
@ -313,12 +314,13 @@ Platform_thread::Platform_thread(Core_cap_index* thread,
{ {
/* XXX remove const cast */ /* XXX remove const cast */
((Core_cap_index *)_thread.local.data())->pt(this); ((Core_cap_index *)_thread.local.data())->pt(this);
_finalize_construction(name); _finalize_construction();
} }
Platform_thread::Platform_thread(const char *name) Platform_thread::Platform_thread(const char *name)
: _state(DEAD), : _name(name),
_state(DEAD),
_core_thread(true), _core_thread(true),
_thread(true), _thread(true),
_irq(true), _irq(true),
@ -330,7 +332,7 @@ Platform_thread::Platform_thread(const char *name)
/* XXX remove const cast */ /* XXX remove const cast */
((Core_cap_index *)_thread.local.data())->pt(this); ((Core_cap_index *)_thread.local.data())->pt(this);
_create_thread(); _create_thread();
_finalize_construction(name); _finalize_construction();
} }
@ -343,5 +345,5 @@ Platform_thread::~Platform_thread()
* Thread::unbind() * Thread::unbind()
*/ */
if (_platform_pd) if (_platform_pd)
_platform_pd->unbind_thread(this); _platform_pd->unbind_thread(*this);
} }

View File

@ -21,15 +21,15 @@ namespace Fiasco {
using namespace Genode; using namespace Genode;
void Ram_dataspace_factory::_export_ram_ds(Dataspace_component *) { } void Ram_dataspace_factory::_export_ram_ds(Dataspace_component &) { }
void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component *) { } void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component &) { }
void Ram_dataspace_factory::_clear_ds(Dataspace_component *ds) void Ram_dataspace_factory::_clear_ds(Dataspace_component &ds)
{ {
memset((void *)ds->phys_addr(), 0, ds->size()); memset((void *)ds.phys_addr(), 0, ds.size());
if (ds->cacheability() != CACHED) if (ds.cacheability() != CACHED)
Fiasco::l4_cache_dma_coherent(ds->phys_addr(), ds->phys_addr() + ds->size()); Fiasco::l4_cache_dma_coherent(ds.phys_addr(), ds.phys_addr() + ds.size());
} }

View File

@ -43,10 +43,10 @@ using namespace Genode;
** Cap_index_allocator ** ** Cap_index_allocator **
***************************/ ***************************/
Genode::Cap_index_allocator* Genode::cap_idx_alloc() Genode::Cap_index_allocator &Genode::cap_idx_alloc()
{ {
static Genode::Cap_index_allocator_tpl<Core_cap_index,10*1024> alloc; static Genode::Cap_index_allocator_tpl<Core_cap_index,10*1024> alloc;
return &alloc; return alloc;
} }
@ -54,10 +54,10 @@ Genode::Cap_index_allocator* Genode::cap_idx_alloc()
** Cap_mapping ** ** Cap_mapping **
*******************/ *******************/
Core_cap_index* Cap_mapping::_get_cap() Core_cap_index *Cap_mapping::_get_cap()
{ {
int id = platform_specific()->cap_id_alloc()->alloc(); int const id = platform_specific().cap_id_alloc().alloc();
return static_cast<Core_cap_index*>(cap_map()->insert(id)); return static_cast<Core_cap_index*>(cap_map().insert(id));
} }
@ -107,12 +107,12 @@ Native_capability Rpc_cap_factory::alloc(Native_capability ep)
/* /*
* Allocate new id, and ipc-gate and set id as gate-label * Allocate new id, and ipc-gate and set id as gate-label
*/ */
unsigned long id = platform_specific()->cap_id_alloc()->alloc(); unsigned long const id = platform_specific().cap_id_alloc().alloc();
Core_cap_index* idx = static_cast<Core_cap_index*>(cap_map()->insert(id)); Core_cap_index *idx = static_cast<Core_cap_index*>(cap_map().insert(id));
if (!idx) { if (!idx) {
warning("Out of capability indices!"); warning("Out of capability indices!");
platform_specific()->cap_id_alloc()->free(id); platform_specific().cap_id_alloc().free(id);
return cap; return cap;
} }
@ -121,12 +121,12 @@ Native_capability Rpc_cap_factory::alloc(Native_capability ep)
ref->pt()->thread().local.data()->kcap(), id); ref->pt()->thread().local.data()->kcap(), id);
if (l4_msgtag_has_error(tag)) { if (l4_msgtag_has_error(tag)) {
error("l4_factory_create_gate failed!"); error("l4_factory_create_gate failed!");
cap_map()->remove(idx); cap_map().remove(idx);
platform_specific()->cap_id_alloc()->free(id); platform_specific().cap_id_alloc().free(id);
return cap; return cap;
} else } else
/* set debugger-name of ipc-gate to thread's name */ /* set debugger-name of ipc-gate to thread's name */
Fiasco::l4_debugger_set_object_name(idx->kcap(), ref->pt()->name()); Fiasco::l4_debugger_set_object_name(idx->kcap(), ref->pt()->name().string());
// XXX remove cast // XXX remove cast
idx->session((Pd_session_component *)this); idx->session((Pd_session_component *)this);
@ -159,7 +159,7 @@ void Rpc_cap_factory::free(Native_capability cap)
if (static_cast<Core_cap_index const *>(cap.data())->session() != (Pd_session_component *)this) if (static_cast<Core_cap_index const *>(cap.data())->session() != (Pd_session_component *)this)
return; return;
Entry * entry; Entry * entry = nullptr;
_pool.apply(cap, [&] (Entry *e) { _pool.apply(cap, [&] (Entry *e) {
entry = e; entry = e;
if (e) { if (e) {
@ -184,8 +184,8 @@ Rpc_cap_factory::~Rpc_cap_factory()
** Capability ID Allocator ** ** Capability ID Allocator **
*******************************/ *******************************/
Cap_id_allocator::Cap_id_allocator(Allocator* alloc) Cap_id_allocator::Cap_id_allocator(Allocator &alloc)
: _id_alloc(alloc) : _id_alloc(&alloc)
{ {
_id_alloc.add_range(CAP_ID_OFFSET, CAP_ID_RANGE); _id_alloc.add_range(CAP_ID_OFFSET, CAP_ID_RANGE);
} }
@ -195,7 +195,7 @@ unsigned long Cap_id_allocator::alloc()
{ {
Lock::Guard lock_guard(_lock); Lock::Guard lock_guard(_lock);
void *id; void *id = nullptr;
if (_id_alloc.alloc(CAP_ID_OFFSET, &id)) if (_id_alloc.alloc(CAP_ID_OFFSET, &id))
return (unsigned long) id; return (unsigned long) id;
throw Out_of_ids(); throw Out_of_ids();
@ -211,7 +211,7 @@ void Cap_id_allocator::free(unsigned long id)
} }
void Genode::Capability_map::remove(Genode::Cap_index* i) void Genode::Capability_map::remove(Genode::Cap_index *i)
{ {
using namespace Genode; using namespace Genode;
using namespace Fiasco; using namespace Fiasco;
@ -228,9 +228,9 @@ void Genode::Capability_map::remove(Genode::Cap_index* i)
error("destruction of ipc-gate ", i->kcap(), " failed!"); error("destruction of ipc-gate ", i->kcap(), " failed!");
platform_specific()->cap_id_alloc()->free(i->id()); platform_specific().cap_id_alloc().free(i->id());
_tree.remove(i); _tree.remove(i);
} }
cap_idx_alloc()->free(i, 1); cap_idx_alloc().free(i, 1);
} }
} }

View File

@ -32,20 +32,20 @@ using namespace Genode;
** Signal-source component ** ** Signal-source component **
*****************************/ *****************************/
void Signal_source_component::release(Signal_context_component *context) void Signal_source_component::release(Signal_context_component &context)
{ {
if (context && context->enqueued()) if (context.enqueued())
_signal_queue.remove(context); _signal_queue.remove(&context);
} }
void Signal_source_component::submit(Signal_context_component *context, void Signal_source_component::submit(Signal_context_component &context,
unsigned long cnt) unsigned long cnt)
{ {
/* enqueue signal to context */ /* enqueue signal to context */
context->increment_signal_cnt(cnt); context.increment_signal_cnt(cnt);
if (!context->enqueued()) { if (!context.enqueued()) {
_signal_queue.enqueue(context); _signal_queue.enqueue(&context);
/* wake up client */ /* wake up client */
Fiasco::l4_irq_trigger(_blocking_semaphore.data()->kcap()); Fiasco::l4_irq_trigger(_blocking_semaphore.data()->kcap());
@ -61,16 +61,16 @@ Signal_source::Signal Signal_source_component::wait_for_signal()
} }
/* dequeue and return pending signal */ /* dequeue and return pending signal */
Signal_context_component *context = _signal_queue.dequeue(); Signal_context_component &context = *_signal_queue.dequeue();
Signal result(context->imprint(), context->cnt()); Signal result(context.imprint(), context.cnt());
context->reset_signal_cnt(); context.reset_signal_cnt();
return result; return result;
} }
Signal_source_component::Signal_source_component(Rpc_entrypoint *ep) Signal_source_component::Signal_source_component(Rpc_entrypoint &ep)
: :
Signal_source_rpc_object(cap_map()->insert(platform_specific()->cap_id_alloc()->alloc())), Signal_source_rpc_object(cap_map().insert(platform_specific().cap_id_alloc().alloc())),
_entrypoint(ep) _entrypoint(ep)
{ {
using namespace Fiasco; using namespace Fiasco;

View File

@ -32,29 +32,29 @@ void Genode::Ipc_pager::_parse_exception()
} }
void Genode::Ipc_pager::get_regs(Foc_thread_state *state) void Genode::Ipc_pager::get_regs(Foc_thread_state &state) const
{ {
state->ip = _regs.pc; state.ip = _regs.pc;
state->sp = _regs.sp; state.sp = _regs.sp;
state->r0 = _regs.r[0]; state.r0 = _regs.r[0];
state->r1 = _regs.r[1]; state.r1 = _regs.r[1];
state->r2 = _regs.r[2]; state.r2 = _regs.r[2];
state->r3 = _regs.r[3]; state.r3 = _regs.r[3];
state->r4 = _regs.r[4]; state.r4 = _regs.r[4];
state->r5 = _regs.r[5]; state.r5 = _regs.r[5];
state->r6 = _regs.r[6]; state.r6 = _regs.r[6];
state->r7 = _regs.r[7]; state.r7 = _regs.r[7];
state->r8 = _regs.r[8]; state.r8 = _regs.r[8];
state->r9 = _regs.r[9]; state.r9 = _regs.r[9];
state->r10 = _regs.r[10]; state.r10 = _regs.r[10];
state->r11 = _regs.r[11]; state.r11 = _regs.r[11];
state->r12 = _regs.r[12]; state.r12 = _regs.r[12];
state->lr = _regs.ulr; state.lr = _regs.ulr;
state->cpsr = _regs.cpsr; state.cpsr = _regs.cpsr;
} }
void Genode::Ipc_pager::set_regs(Foc_thread_state state) void Genode::Ipc_pager::set_regs(Foc_thread_state const &state)
{ {
_regs.pc = state.ip; _regs.pc = state.ip;
_regs.sp = state.sp; _regs.sp = state.sp;

View File

@ -17,25 +17,25 @@
#include <ipc_pager.h> #include <ipc_pager.h>
void Genode::Ipc_pager::get_regs(Foc_thread_state *state) void Genode::Ipc_pager::get_regs(Foc_thread_state &state) const
{ {
state->ip = _regs.ip; state.ip = _regs.ip;
state->sp = _regs.sp; state.sp = _regs.sp;
state->edi = _regs.edi; state.edi = _regs.edi;
state->esi = _regs.esi; state.esi = _regs.esi;
state->ebp = _regs.ebp; state.ebp = _regs.ebp;
state->ebx = _regs.ebx; state.ebx = _regs.ebx;
state->edx = _regs.edx; state.edx = _regs.edx;
state->ecx = _regs.ecx; state.ecx = _regs.ecx;
state->eax = _regs.eax; state.eax = _regs.eax;
state->gs = _regs.gs; state.gs = _regs.gs;
state->fs = _regs.fs; state.fs = _regs.fs;
state->eflags = _regs.flags; state.eflags = _regs.flags;
state->trapno = _regs.trapno; state.trapno = _regs.trapno;
} }
void Genode::Ipc_pager::set_regs(Foc_thread_state state) void Genode::Ipc_pager::set_regs(Foc_thread_state const &state)
{ {
_regs.ip = state.ip; _regs.ip = state.ip;
_regs.sp = state.sp; _regs.sp = state.sp;

View File

@ -17,32 +17,32 @@
#include <ipc_pager.h> #include <ipc_pager.h>
void Genode::Ipc_pager::get_regs(Foc_thread_state *state) void Genode::Ipc_pager::get_regs(Foc_thread_state &state) const
{ {
state->ip = _regs.ip; state.ip = _regs.ip;
state->sp = _regs.sp; state.sp = _regs.sp;
state->r8 = _regs.r8; state.r8 = _regs.r8;
state->r9 = _regs.r9; state.r9 = _regs.r9;
state->r10 = _regs.r10; state.r10 = _regs.r10;
state->r11 = _regs.r11; state.r11 = _regs.r11;
state->r12 = _regs.r12; state.r12 = _regs.r12;
state->r13 = _regs.r13; state.r13 = _regs.r13;
state->r14 = _regs.r14; state.r14 = _regs.r14;
state->r15 = _regs.r15; state.r15 = _regs.r15;
state->rax = _regs.rax; state.rax = _regs.rax;
state->rbx = _regs.rbx; state.rbx = _regs.rbx;
state->rcx = _regs.rcx; state.rcx = _regs.rcx;
state->rdx = _regs.rdx; state.rdx = _regs.rdx;
state->rdi = _regs.rdi; state.rdi = _regs.rdi;
state->rsi = _regs.rsi; state.rsi = _regs.rsi;
state->rbp = _regs.rbp; state.rbp = _regs.rbp;
state->ss = _regs.ss; state.ss = _regs.ss;
state->eflags = _regs.flags; state.eflags = _regs.flags;
state->trapno = _regs.trapno; state.trapno = _regs.trapno;
} }
void Genode::Ipc_pager::set_regs(Foc_thread_state state) void Genode::Ipc_pager::set_regs(Foc_thread_state const &state)
{ {
_regs.ip = state.ip; _regs.ip = state.ip;
_regs.sp = state.sp; _regs.sp = state.sp;

View File

@ -45,26 +45,26 @@ void Thread::start()
using namespace Fiasco; using namespace Fiasco;
/* create and start platform thread */ /* create and start platform thread */
Platform_thread *pt = Platform_thread &pt = *new (platform().core_mem_alloc())
new(platform()->core_mem_alloc()) Platform_thread(_stack->name().string()); Platform_thread(_stack->name().string());
platform_specific()->core_pd()->bind_thread(pt); platform_specific().core_pd().bind_thread(pt);
l4_utcb_t *foc_utcb = (l4_utcb_t *)(pt->utcb()); l4_utcb_t *foc_utcb = (l4_utcb_t *)(pt.utcb());
native_thread() = Native_thread(pt->gate().remote); native_thread() = Native_thread(pt.gate().remote);
utcb()->foc_utcb = foc_utcb; utcb()->foc_utcb = foc_utcb;
_thread_cap = _thread_cap =
reinterpret_cap_cast<Cpu_thread>(Native_capability(pt->thread().local)); reinterpret_cap_cast<Cpu_thread>(Native_capability(pt.thread().local));
pt->pager(platform_specific()->core_pager()); pt.pager(platform_specific().core_pager());
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_BADGE] = (unsigned long) pt->gate().local.data(); l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_BADGE] = (unsigned long) pt.gate().local.data();
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this; l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this;
pt->start((void *)_thread_start, stack_top()); pt.start((void *)_thread_start, stack_top());
} }

View File

@ -124,7 +124,7 @@ namespace Genode {
/** /**
* Get the global Cap_index_allocator of the process. * Get the global Cap_index_allocator of the process.
*/ */
Cap_index_allocator *cap_idx_alloc(); Cap_index_allocator &cap_idx_alloc();
/** /**
@ -245,7 +245,7 @@ namespace Genode {
/** /**
* Get the global Capability_map of the process. * Get the global Capability_map of the process.
*/ */
Capability_map *cap_map(); Capability_map &cap_map();
} }
#endif /* _INCLUDE__BASE__CAP_MAP_H_ */ #endif /* _INCLUDE__BASE__CAP_MAP_H_ */

View File

@ -33,15 +33,14 @@ namespace Genode {
{ {
unsigned long const local_name = _parent_cap; unsigned long const local_name = _parent_cap;
static Cap_index *i = cap_map()->insert(local_name, static Cap_index *i = cap_map().insert(local_name, Fiasco::PARENT_CAP);
Fiasco::PARENT_CAP);
/* /*
* Update local name after a parent capability got reloaded via * Update local name after a parent capability got reloaded via
* 'Platform_env::reload_parent_cap()'. * 'Platform_env::reload_parent_cap()'.
*/ */
if (i->id() != local_name) { if (i->id() != local_name) {
cap_map()->remove(i); cap_map().remove(i);
i = cap_map()->insert(local_name, Fiasco::PARENT_CAP); i = cap_map().insert(local_name, Fiasco::PARENT_CAP);
} }
return reinterpret_cap_cast<Parent>(Native_capability(i)); return reinterpret_cap_cast<Parent>(Native_capability(i));

View File

@ -13,8 +13,8 @@
#include <base/internal/cap_alloc.h> #include <base/internal/cap_alloc.h>
Genode::Cap_index_allocator* Genode::cap_idx_alloc() Genode::Cap_index_allocator &Genode::cap_idx_alloc()
{ {
static Genode::Cap_index_allocator_tpl<Cap_index,4096> alloc; static Genode::Cap_index_allocator_tpl<Cap_index,4096> alloc;
return &alloc; return alloc;
} }

View File

@ -71,13 +71,13 @@ Genode::Cap_index* Genode::Cap_index::find_by_id(Genode::uint16_t id)
Genode::addr_t Genode::Cap_index::kcap() const { Genode::addr_t Genode::Cap_index::kcap() const {
return cap_idx_alloc()->idx_to_kcap(this); } return cap_idx_alloc().idx_to_kcap(this); }
Genode::uint8_t Genode::Cap_index::inc() Genode::uint8_t Genode::Cap_index::inc()
{ {
/* con't ref-count index that are controlled by core */ /* con't ref-count index that are controlled by core */
if (cap_idx_alloc()->static_idx(this)) if (cap_idx_alloc().static_idx(this))
return 1; return 1;
spinlock_lock(&_cap_index_spinlock); spinlock_lock(&_cap_index_spinlock);
@ -90,7 +90,7 @@ Genode::uint8_t Genode::Cap_index::inc()
Genode::uint8_t Genode::Cap_index::dec() Genode::uint8_t Genode::Cap_index::dec()
{ {
/* con't ref-count index that are controlled by core */ /* con't ref-count index that are controlled by core */
if (cap_idx_alloc()->static_idx(this)) if (cap_idx_alloc().static_idx(this))
return 1; return 1;
spinlock_lock(&_cap_index_spinlock); spinlock_lock(&_cap_index_spinlock);
@ -121,7 +121,7 @@ Genode::Cap_index* Genode::Capability_map::insert(int id)
ASSERT(!_tree.first() || !_tree.first()->find_by_id(id), ASSERT(!_tree.first() || !_tree.first()->find_by_id(id),
"Double insertion in cap_map()!"); "Double insertion in cap_map()!");
Cap_index *i = cap_idx_alloc()->alloc_range(1); Cap_index * const i = cap_idx_alloc().alloc_range(1);
if (i) { if (i) {
i->id(id); i->id(id);
_tree.insert(i); _tree.insert(i);
@ -141,7 +141,7 @@ Genode::Cap_index* Genode::Capability_map::insert(int id, addr_t kcap)
if (i) if (i)
_tree.remove(i); _tree.remove(i);
i = cap_idx_alloc()->alloc(kcap); i = cap_idx_alloc().alloc(kcap);
if (i) { if (i) {
i->id(id); i->id(id);
_tree.insert(i); _tree.insert(i);
@ -180,7 +180,7 @@ Genode::Cap_index* Genode::Capability_map::insert_map(int id, addr_t kcap)
} }
/* the capability doesn't exists in the map so allocate a new one */ /* the capability doesn't exists in the map so allocate a new one */
i = cap_idx_alloc()->alloc_range(1); i = cap_idx_alloc().alloc_range(1);
if (!i) if (!i)
return 0; return 0;
@ -196,10 +196,10 @@ Genode::Cap_index* Genode::Capability_map::insert_map(int id, addr_t kcap)
} }
Genode::Capability_map* Genode::cap_map() Genode::Capability_map &Genode::cap_map()
{ {
static Genode::Capability_map map; static Genode::Capability_map map;
return &map; return map;
} }
@ -209,14 +209,14 @@ Genode::Capability_map* Genode::cap_map()
Fiasco::l4_cap_idx_t Genode::Capability_space::alloc_kcap() Fiasco::l4_cap_idx_t Genode::Capability_space::alloc_kcap()
{ {
return cap_idx_alloc()->alloc_range(1)->kcap(); return cap_idx_alloc().alloc_range(1)->kcap();
} }
void Genode::Capability_space::free_kcap(Fiasco::l4_cap_idx_t kcap) void Genode::Capability_space::free_kcap(Fiasco::l4_cap_idx_t kcap)
{ {
Genode::Cap_index* idx = Genode::cap_idx_alloc()->kcap_to_idx(kcap); Genode::Cap_index *idx = Genode::cap_idx_alloc().kcap_to_idx(kcap);
Genode::cap_idx_alloc()->free(idx, 1); Genode::cap_idx_alloc().free(idx, 1);
} }

View File

@ -22,9 +22,9 @@ void Genode::Capability_map::remove(Genode::Cap_index* i)
Lock_guard<Spin_lock> guard(_lock); Lock_guard<Spin_lock> guard(_lock);
if (i) { if (i) {
Cap_index* e = _tree.first() ? _tree.first()->find_by_id(i->id()) : 0; Cap_index *e = _tree.first() ? _tree.first()->find_by_id(i->id()) : 0;
if (e == i) if (e == i)
_tree.remove(i); _tree.remove(i);
cap_idx_alloc()->free(i, 1); cap_idx_alloc().free(i, 1);
} }
} }

View File

@ -36,7 +36,7 @@ void Native_capability::_inc()
void Native_capability::_dec() void Native_capability::_dec()
{ {
if (_data && !_data->dec()) if (_data && !_data->dec())
cap_map()->remove(_data); cap_map().remove(_data);
} }

View File

@ -159,8 +159,8 @@ static unsigned long extract_msg_from_utcb(l4_msgtag_t tag,
*/ */
for (unsigned i = 0; i < num_caps; i++) { for (unsigned i = 0; i < num_caps; i++) {
if (caps[i].valid) { if (caps[i].valid) {
rcv_msg.insert(Native_capability(cap_map()->insert_map(caps[i].badge, rcv_msg.insert(Native_capability(cap_map().insert_map(caps[i].badge,
caps[i].sel))); caps[i].sel)));
} else { } else {
rcv_msg.insert(Native_capability()); rcv_msg.insert(Native_capability());
} }
@ -383,13 +383,13 @@ Ipc_server::~Ipc_server() { }
Receive_window::~Receive_window() Receive_window::~Receive_window()
{ {
if (_rcv_idx_base) if (_rcv_idx_base)
cap_idx_alloc()->free(_rcv_idx_base, MAX_CAPS_PER_MSG); cap_idx_alloc().free(_rcv_idx_base, MAX_CAPS_PER_MSG);
} }
void Receive_window::init() void Receive_window::init()
{ {
_rcv_idx_base = cap_idx_alloc()->alloc_range(MAX_CAPS_PER_MSG); _rcv_idx_base = cap_idx_alloc().alloc_range(MAX_CAPS_PER_MSG);
} }

View File

@ -31,7 +31,7 @@ void prepare_init_main_thread()
{ {
using namespace Genode; using namespace Genode;
enum { THREAD_CAP_ID = 1 }; enum { THREAD_CAP_ID = 1 };
Cap_index * ci(cap_map()->insert(THREAD_CAP_ID, Fiasco::MAIN_THREAD_CAP)); Cap_index * ci(cap_map().insert(THREAD_CAP_ID, Fiasco::MAIN_THREAD_CAP));
Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_BADGE] = (unsigned long)ci; Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_BADGE] = (unsigned long)ci;
Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_THREAD_OBJ] = 0; Fiasco::l4_utcb_tcr()->user[Fiasco::UTCB_TCR_THREAD_OBJ] = 0;
} }
@ -40,8 +40,8 @@ void prepare_init_main_thread()
void prepare_reinit_main_thread() void prepare_reinit_main_thread()
{ {
using namespace Genode; using namespace Genode;
construct_at<Capability_map>(cap_map()); construct_at<Capability_map>(&cap_map());
cap_idx_alloc()->reinit(); cap_idx_alloc().reinit();
prepare_init_main_thread(); prepare_init_main_thread();
} }

View File

@ -40,7 +40,7 @@ void Thread::_deinit_platform_thread()
if (native_thread().kcap && _thread_cap.valid()) { if (native_thread().kcap && _thread_cap.valid()) {
Cap_index *i = (Cap_index*)l4_utcb_tcr_u(utcb()->foc_utcb)->user[UTCB_TCR_BADGE]; Cap_index *i = (Cap_index*)l4_utcb_tcr_u(utcb()->foc_utcb)->user[UTCB_TCR_BADGE];
cap_map()->remove(i); cap_map().remove(i);
_cpu_session->kill_thread(_thread_cap); _cpu_session->kill_thread(_thread_cap);
} }
} }
@ -93,7 +93,7 @@ void Thread::start()
native_thread() = Native_thread(state.kcap); native_thread() = Native_thread(state.kcap);
Cap_index *i = cap_map()->insert(state.id, state.kcap); Cap_index *i = cap_map().insert(state.id, state.kcap);
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_BADGE] = (unsigned long) i; l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_BADGE] = (unsigned long) i;
l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this; l4_utcb_tcr_u(foc_utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this;

View File

@ -34,7 +34,7 @@ Main::Main(Env &env)
enum { COUNT = 1000 }; enum { COUNT = 1000 };
Cap_index* idx = cap_idx_alloc()->alloc_range(COUNT); Cap_index* idx = cap_idx_alloc().alloc_range(COUNT);
Fiasco::l4_cap_idx_t tid = Capability_space::kcap(env.ram_session_cap()); Fiasco::l4_cap_idx_t tid = Capability_space::kcap(env.ram_session_cap());
/* try the first 1000 local name IDs */ /* try the first 1000 local name IDs */

View File

@ -49,9 +49,8 @@ Core_region_map::attach(Dataspace_capability ds_cap, size_t size,
/* allocate range in core's virtual address space */ /* allocate range in core's virtual address space */
void *virt_addr; void *virt_addr;
if (!platform()->region_alloc()->alloc_aligned(page_rounded_size, if (!platform().region_alloc().alloc_aligned(page_rounded_size, &virt_addr,
&virt_addr, get_page_size_log2()).ok()) {
get_page_size_log2()).ok()) {
error("could not allocate virtual address range in core of size ", error("could not allocate virtual address range in core of size ",
page_rounded_size); page_rounded_size);
return nullptr; return nullptr;

View File

@ -14,9 +14,13 @@
#ifndef _CORE__CPU_THREAD_ALLOCATOR_H_ #ifndef _CORE__CPU_THREAD_ALLOCATOR_H_
#define _CORE__CPU_THREAD_ALLOCATOR_H_ #define _CORE__CPU_THREAD_ALLOCATOR_H_
/* Genode includes */
#include <base/log.h> #include <base/log.h>
#include <base/allocator.h> #include <base/allocator.h>
/* core includes */
#include <assertion.h>
namespace Genode namespace Genode
{ {
/** /**
@ -36,7 +40,7 @@ namespace Genode
Cpu_thread_allocator(Cpu_thread_allocator const &); Cpu_thread_allocator(Cpu_thread_allocator const &);
Cpu_thread_allocator &operator = (Cpu_thread_allocator const &); Cpu_thread_allocator &operator = (Cpu_thread_allocator const &);
Allocator * const _alloc; Allocator &_alloc;
public: public:
@ -45,34 +49,25 @@ namespace Genode
* *
* \param alloc allocator backend * \param alloc allocator backend
*/ */
Cpu_thread_allocator(Allocator * alloc) : _alloc(alloc) { } Cpu_thread_allocator(Allocator &alloc) : _alloc(alloc) { }
/************************* /*************************
** Allocator interface ** ** Allocator interface **
*************************/ *************************/
bool alloc(size_t size, void **out_addr) override { bool alloc(size_t size, void **out_addr) override {
return _alloc->alloc(size, out_addr); } return _alloc.alloc(size, out_addr); }
void free(void *addr, size_t size) override { void free(void *addr, size_t size) override {
_alloc->free(addr, size); } _alloc.free(addr, size); }
size_t consumed() const override size_t consumed() const override { ASSERT_NEVER_CALLED; }
{
warning(__func__, "unexpectedly called");
while (1) ;
return 0;
}
size_t overhead(size_t) const override size_t overhead(size_t) const override { ASSERT_NEVER_CALLED; }
{
warning(__func__, "unexpectedly called");
while (1) ;
return 0;
}
bool need_size_for_free() const override { bool need_size_for_free() const override {
return _alloc->need_size_for_free(); } return _alloc.need_size_for_free(); }
}; };
} }

View File

@ -62,14 +62,14 @@ Irq_session_component::~Irq_session_component()
using namespace Kernel; using namespace Kernel;
User_irq * kirq = reinterpret_cast<User_irq*>(&_kernel_object); User_irq * kirq = reinterpret_cast<User_irq*>(&_kernel_object);
_irq_alloc->free((void *)(addr_t)_irq_number); _irq_alloc.free((void *)(addr_t)_irq_number);
if (_sig_cap.valid()) if (_sig_cap.valid())
Kernel::delete_irq(kirq); Kernel::delete_irq(kirq);
} }
Irq_session_component::Irq_session_component(Range_allocator * const irq_alloc, Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
const char * const args) const char * const args)
: :
_irq_number(Platform::irq(_find_irq_number(args))), _irq_alloc(irq_alloc), _irq_number(Platform::irq(_find_irq_number(args))), _irq_alloc(irq_alloc),
_is_msi(false), _address(0), _value(0) _is_msi(false), _address(0), _value(0)
@ -85,7 +85,7 @@ Irq_session_component::Irq_session_component(Range_allocator * const irq_alloc,
} }
/* allocate interrupt */ /* allocate interrupt */
if (_irq_alloc->alloc_addr(1, _irq_number).error()) { if (_irq_alloc.alloc_addr(1, _irq_number).error()) {
error("unavailable interrupt ", _irq_number, " requested"); error("unavailable interrupt ", _irq_number, " requested");
throw Service_denied(); throw Service_denied();
} }

View File

@ -31,14 +31,8 @@ class Genode::Irq_session_component : public Rpc_object<Irq_session>,
friend class List<Irq_session_component>; friend class List<Irq_session_component>;
/*
* Noncopyable
*/
Irq_session_component(Irq_session_component const &);
Irq_session_component &operator = (Irq_session_component const &);
unsigned _irq_number; unsigned _irq_number;
Range_allocator *_irq_alloc; Range_allocator &_irq_alloc;
Genode::uint8_t _kernel_object[sizeof(Kernel::User_irq)]; Genode::uint8_t _kernel_object[sizeof(Kernel::User_irq)];
bool _is_msi; bool _is_msi;
addr_t _address, _value; addr_t _address, _value;
@ -55,7 +49,7 @@ class Genode::Irq_session_component : public Rpc_object<Irq_session>,
* \param irq_alloc platform-dependent IRQ allocator * \param irq_alloc platform-dependent IRQ allocator
* \param args session construction arguments * \param args session construction arguments
*/ */
Irq_session_component(Range_allocator *irq_alloc, Irq_session_component(Range_allocator &irq_alloc,
const char *args); const char *args);
/** /**

View File

@ -27,10 +27,7 @@
using namespace Kernel; using namespace Kernel;
namespace Kernel Kernel::Cpu_pool &Kernel::cpu_pool() { return *unmanaged_singleton<Cpu_pool>(); }
{
Cpu_pool * cpu_pool() { return unmanaged_singleton<Cpu_pool>(); }
}
/************* /*************
@ -64,14 +61,14 @@ void Cpu_job::_activate_own_share() { _cpu->schedule(this); }
void Cpu_job::_deactivate_own_share() void Cpu_job::_deactivate_own_share()
{ {
assert(_cpu->id() == Cpu::executing_id()); assert(_cpu->id() == Cpu::executing_id());
_cpu->scheduler()->unready(this); _cpu->scheduler().unready(this);
} }
void Cpu_job::_yield() void Cpu_job::_yield()
{ {
assert(_cpu->id() == Cpu::executing_id()); assert(_cpu->id() == Cpu::executing_id());
_cpu->scheduler()->yield(); _cpu->scheduler().yield();
} }
@ -79,7 +76,7 @@ void Cpu_job::_interrupt(unsigned const /* cpu_id */)
{ {
/* determine handling for specific interrupt */ /* determine handling for specific interrupt */
unsigned irq_id; unsigned irq_id;
if (pic()->take_request(irq_id)) if (pic().take_request(irq_id))
/* is the interrupt a cpu-local one */ /* is the interrupt a cpu-local one */
if (!_cpu->interrupt(irq_id)) { if (!_cpu->interrupt(irq_id)) {
@ -91,20 +88,20 @@ void Cpu_job::_interrupt(unsigned const /* cpu_id */)
} }
/* end interrupt request at controller */ /* end interrupt request at controller */
pic()->finish_request(); pic().finish_request();
} }
void Cpu_job::affinity(Cpu * const cpu) void Cpu_job::affinity(Cpu &cpu)
{ {
_cpu = cpu; _cpu = &cpu;
_cpu->scheduler()->insert(this); _cpu->scheduler().insert(this);
} }
void Cpu_job::quota(unsigned const q) void Cpu_job::quota(unsigned const q)
{ {
if (_cpu) { _cpu->scheduler()->quota(this, q); } if (_cpu) { _cpu->scheduler().quota(this, q); }
else { Cpu_share::quota(q); } else { Cpu_share::quota(q); }
} }
@ -117,7 +114,7 @@ Cpu_job::Cpu_job(Cpu_priority const p, unsigned const q)
Cpu_job::~Cpu_job() Cpu_job::~Cpu_job()
{ {
if (!_cpu) { return; } if (!_cpu) { return; }
_cpu->scheduler()->remove(this); _cpu->scheduler().remove(this);
} }
@ -127,13 +124,13 @@ Cpu_job::~Cpu_job()
extern "C" void idle_thread_main(void); extern "C" void idle_thread_main(void);
Cpu::Idle_thread::Idle_thread(Cpu * const cpu) Cpu::Idle_thread::Idle_thread(Cpu &cpu)
: Thread("idle") : Thread("idle")
{ {
regs->ip = (addr_t)&idle_thread_main; regs->ip = (addr_t)&idle_thread_main;
affinity(cpu); affinity(cpu);
Thread::_pd = core_pd(); Thread::_pd = &core_pd();
} }
@ -199,7 +196,7 @@ Cpu::Cpu(unsigned const id, Pic & pic,
Inter_processor_work_list & global_work_list) Inter_processor_work_list & global_work_list)
: :
_id(id), _pic(pic), _timer(_id), _id(id), _pic(pic), _timer(_id),
_scheduler(&_idle, _quota(), _fill()), _idle(this), _scheduler(&_idle, _quota(), _fill()), _idle(*this),
_ipi_irq(*this), _timer_irq(_timer.interrupt_id(), *this), _ipi_irq(*this), _timer_irq(_timer.interrupt_id(), *this),
_global_work_list(global_work_list) _global_work_list(global_work_list)
{ _arch_init(); } { _arch_init(); }

View File

@ -38,7 +38,7 @@ namespace Kernel
/** /**
* Return singleton of CPU pool * Return singleton of CPU pool
*/ */
Cpu_pool * cpu_pool(); Cpu_pool &cpu_pool();
} }
@ -106,7 +106,7 @@ class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout
/** /**
* Construct idle context for CPU 'cpu' * Construct idle context for CPU 'cpu'
*/ */
Idle_thread(Cpu * const cpu); Idle_thread(Cpu &cpu);
}; };
@ -175,7 +175,7 @@ class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout
return *static_cast<Job *>(_scheduler.head())->helping_sink(); } return *static_cast<Job *>(_scheduler.head())->helping_sink(); }
unsigned id() const { return _id; } unsigned id() const { return _id; }
Cpu_scheduler * scheduler() { return &_scheduler; } Cpu_scheduler &scheduler() { return _scheduler; }
time_t us_to_ticks(time_t const us) const { return _timer.us_to_ticks(us); }; time_t us_to_ticks(time_t const us) const { return _timer.us_to_ticks(us); };

View File

@ -68,7 +68,7 @@ class Kernel::Cpu_job : private Cpu_share
/** /**
* Return wether we are allowed to help job 'j' with our CPU-share * Return wether we are allowed to help job 'j' with our CPU-share
*/ */
bool _helping_possible(Cpu_job * const j) { return j->_cpu == _cpu; } bool _helping_possible(Cpu_job const &j) const { return j._cpu == _cpu; }
public: public:
@ -100,7 +100,7 @@ class Kernel::Cpu_job : private Cpu_share
/** /**
* Link job to CPU 'cpu' * Link job to CPU 'cpu'
*/ */
void affinity(Cpu * const cpu); void affinity(Cpu &cpu);
/** /**
* Set CPU quota of the job to 'q' * Set CPU quota of the job to 'q'
@ -124,7 +124,7 @@ class Kernel::Cpu_job : private Cpu_share
** Accessors ** ** Accessors **
***************/ ***************/
void cpu(Cpu * const cpu) { _cpu = cpu; } void cpu(Cpu &cpu) { _cpu = &cpu; }
Cpu_share &share() { return *this; } Cpu_share &share() { return *this; }
}; };

View File

@ -41,7 +41,7 @@ void Cpu::trigger_ip_interrupt()
/* check whether there is still an IPI send */ /* check whether there is still an IPI send */
if (_ipi_irq.pending) return; if (_ipi_irq.pending) return;
pic()->send_ipi(_id); pic().send_ipi(_id);
_ipi_irq.pending = true; _ipi_irq.pending = true;
} }

View File

@ -30,11 +30,11 @@ using namespace Kernel;
static_assert(sizeof(Genode::sizet_arithm_t) >= 2 * sizeof(size_t), static_assert(sizeof(Genode::sizet_arithm_t) >= 2 * sizeof(size_t),
"Bad result type for size_t arithmetics."); "Bad result type for size_t arithmetics.");
Pd * Kernel::core_pd() { Pd &Kernel::core_pd() {
return &unmanaged_singleton<Genode::Core_platform_pd>()->kernel_pd(); } return unmanaged_singleton<Genode::Core_platform_pd>()->kernel_pd(); }
Pic * Kernel::pic() { return unmanaged_singleton<Pic>(); } Pic &Kernel::pic() { return *unmanaged_singleton<Pic>(); }
extern "C" void kernel_init(); extern "C" void kernel_init();
@ -50,7 +50,7 @@ extern "C" void kernel_init()
Lock::Guard guard(data_lock()); Lock::Guard guard(data_lock());
/* initialize current cpu */ /* initialize current cpu */
pool_ready = cpu_pool()->initialize(*pic()); pool_ready = cpu_pool().initialize(pic());
}; };
/* wait until all cpus have initialized their corresponding cpu object */ /* wait until all cpus have initialized their corresponding cpu object */

View File

@ -28,35 +28,35 @@
using namespace Kernel; using namespace Kernel;
static inline void free_obj_id_ref(Pd *pd, void *ptr) static inline void free_obj_id_ref(Pd &pd, void *ptr)
{ {
pd->platform_pd()->capability_slab().free(ptr, sizeof(Object_identity_reference)); pd.platform_pd().capability_slab().free(ptr, sizeof(Object_identity_reference));
} }
void Ipc_node::copy_msg(Ipc_node * const sender) void Ipc_node::copy_msg(Ipc_node &sender)
{ {
using namespace Genode; using namespace Genode;
using Reference = Object_identity_reference; using Reference = Object_identity_reference;
/* copy payload and set destination capability id */ /* copy payload and set destination capability id */
*_utcb = *sender->_utcb; *_utcb = *sender._utcb;
_utcb->destination(sender->_capid); _utcb->destination(sender._capid);
/* translate capabilities */ /* translate capabilities */
for (unsigned i = 0; i < _rcv_caps; i++) { for (unsigned i = 0; i < _rcv_caps; i++) {
capid_t id = sender->_utcb->cap_get(i); capid_t id = sender._utcb->cap_get(i);
/* if there is no capability to send, just free the pre-allocation */ /* if there is no capability to send, just free the pre-allocation */
if (i >= sender->_utcb->cap_cnt()) { if (i >= sender._utcb->cap_cnt()) {
free_obj_id_ref(pd(), _obj_id_ref_ptr[i]); free_obj_id_ref(pd(), _obj_id_ref_ptr[i]);
continue; continue;
} }
/* lookup the capability id within the caller's cap space */ /* lookup the capability id within the caller's cap space */
Reference *oir = (id == cap_id_invalid()) Reference *oir = (id == cap_id_invalid())
? nullptr : sender->pd()->cap_tree().find(id); ? nullptr : sender.pd().cap_tree().find(id);
/* if the caller's capability is invalid, free the pre-allocation */ /* if the caller's capability is invalid, free the pre-allocation */
if (!oir) { if (!oir) {
@ -69,8 +69,8 @@ void Ipc_node::copy_msg(Ipc_node * const sender)
Reference *dst_oir = oir->find(pd()); Reference *dst_oir = oir->find(pd());
/* if it is not found, and the target is not core, create a reference */ /* if it is not found, and the target is not core, create a reference */
if (!dst_oir && (pd() != core_pd())) { if (!dst_oir && (&pd() != &core_pd())) {
dst_oir = oir->factory(_obj_id_ref_ptr[i], *pd()); dst_oir = oir->factory(_obj_id_ref_ptr[i], pd());
if (!dst_oir) if (!dst_oir)
free_obj_id_ref(pd(), _obj_id_ref_ptr[i]); free_obj_id_ref(pd(), _obj_id_ref_ptr[i]);
} else /* otherwise free the pre-allocation */ } else /* otherwise free the pre-allocation */
@ -84,15 +84,15 @@ void Ipc_node::copy_msg(Ipc_node * const sender)
} }
void Ipc_node::_receive_request(Ipc_node * const caller) void Ipc_node::_receive_request(Ipc_node &caller)
{ {
copy_msg(caller); copy_msg(caller);
_caller = caller; _caller = &caller;
_state = INACTIVE; _state = INACTIVE;
} }
void Ipc_node::_receive_reply(Ipc_node * callee) void Ipc_node::_receive_reply(Ipc_node &callee)
{ {
copy_msg(callee); copy_msg(callee);
_state = INACTIVE; _state = INACTIVE;
@ -100,7 +100,7 @@ void Ipc_node::_receive_reply(Ipc_node * callee)
} }
void Ipc_node::_announce_request(Ipc_node * const node) void Ipc_node::_announce_request(Ipc_node &node)
{ {
/* directly receive request if we've awaited it */ /* directly receive request if we've awaited it */
if (_state == AWAIT_REQUEST) { if (_state == AWAIT_REQUEST) {
@ -110,7 +110,7 @@ void Ipc_node::_announce_request(Ipc_node * const node)
} }
/* cannot receive yet, so queue request */ /* cannot receive yet, so queue request */
_request_queue.enqueue(node); _request_queue.enqueue(&node);
} }
@ -125,7 +125,7 @@ void Ipc_node::_cancel_request_queue()
void Ipc_node::_cancel_outbuf_request() void Ipc_node::_cancel_outbuf_request()
{ {
if (_callee) { if (_callee) {
_callee->_announced_request_cancelled(this); _callee->_announced_request_cancelled(*this);
_callee = nullptr; _callee = nullptr;
} }
} }
@ -140,10 +140,10 @@ void Ipc_node::_cancel_inbuf_request()
} }
void Ipc_node::_announced_request_cancelled(Ipc_node * const node) void Ipc_node::_announced_request_cancelled(Ipc_node &node)
{ {
if (_caller == node) _caller = nullptr; if (_caller == &node) _caller = nullptr;
else _request_queue.remove(node); else _request_queue.remove(&node);
} }
@ -160,36 +160,36 @@ void Ipc_node::_outbuf_request_cancelled()
bool Ipc_node::_helps_outbuf_dst() { return (_state == AWAIT_REPLY) && _help; } bool Ipc_node::_helps_outbuf_dst() { return (_state == AWAIT_REPLY) && _help; }
void Ipc_node::_init(Genode::Native_utcb * utcb, Ipc_node * starter) void Ipc_node::_init(Genode::Native_utcb &utcb, Ipc_node &starter)
{ {
_utcb = utcb; _utcb = &utcb;
_rcv_caps = starter->_utcb->cap_cnt(); _rcv_caps = starter._utcb->cap_cnt();
Genode::Allocator &slab = pd()->platform_pd()->capability_slab(); Genode::Allocator &slab = pd().platform_pd().capability_slab();
for (unsigned i = 0; i < _rcv_caps; i++) for (unsigned i = 0; i < _rcv_caps; i++)
_obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference)); _obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference));
copy_msg(starter); copy_msg(starter);
} }
void Ipc_node::send_request(Ipc_node * const callee, capid_t capid, bool help, void Ipc_node::send_request(Ipc_node &callee, capid_t capid, bool help,
unsigned rcv_caps) unsigned rcv_caps)
{ {
if (_state != INACTIVE) { if (_state != INACTIVE) {
Genode::error("IPC send request: bad state"); Genode::error("IPC send request: bad state");
return; return;
} }
Genode::Allocator &slab = pd()->platform_pd()->capability_slab(); Genode::Allocator &slab = pd().platform_pd().capability_slab();
for (unsigned i = 0; i < rcv_caps; i++) for (unsigned i = 0; i < rcv_caps; i++)
_obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference)); _obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference));
_state = AWAIT_REPLY; _state = AWAIT_REPLY;
_callee = callee; _callee = &callee;
_capid = capid; _capid = capid;
_help = false; _help = false;
_rcv_caps = rcv_caps; _rcv_caps = rcv_caps;
/* announce request */ /* announce request */
_callee->_announce_request(this); _callee->_announce_request(*this);
_help = help; _help = help;
} }
@ -205,7 +205,7 @@ bool Ipc_node::await_request(unsigned rcv_caps)
Genode::error("IPC await request: bad state"); Genode::error("IPC await request: bad state");
return true; return true;
} }
Genode::Allocator &slab = pd()->platform_pd()->capability_slab(); Genode::Allocator &slab = pd().platform_pd().capability_slab();
for (unsigned i = 0; i < rcv_caps; i++) for (unsigned i = 0; i < rcv_caps; i++)
_obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference)); _obj_id_ref_ptr[i] = slab.alloc(sizeof(Object_identity_reference));
@ -213,7 +213,7 @@ bool Ipc_node::await_request(unsigned rcv_caps)
/* if anybody already announced a request receive it */ /* if anybody already announced a request receive it */
if (!_request_queue.empty()) { if (!_request_queue.empty()) {
_receive_request(_request_queue.dequeue()); _receive_request(*_request_queue.dequeue());
return true; return true;
} }
@ -227,7 +227,7 @@ void Ipc_node::send_reply()
{ {
/* reply to the last request if we have to */ /* reply to the last request if we have to */
if (_state == INACTIVE && _caller) { if (_state == INACTIVE && _caller) {
_caller->_receive_reply(this); _caller->_receive_reply(*this);
_caller = nullptr; _caller = nullptr;
} }
} }

View File

@ -24,6 +24,7 @@
/* core includes */ /* core includes */
#include <kernel/fifo.h> #include <kernel/fifo.h>
#include <kernel/interface.h> #include <kernel/interface.h>
#include <assertion.h>
namespace Genode { class Msgbuf_base; }; namespace Genode { class Msgbuf_base; };
@ -50,7 +51,7 @@ class Kernel::Ipc_node : private Ipc_node_queue::Element
AWAIT_REQUEST = 3, AWAIT_REQUEST = 3,
}; };
void _init(Genode::Native_utcb * utcb, Ipc_node * callee); void _init(Genode::Native_utcb &utcb, Ipc_node &callee);
private: private:
@ -70,22 +71,22 @@ class Kernel::Ipc_node : private Ipc_node_queue::Element
/* pre-allocation array for obkject identity references */ /* pre-allocation array for obkject identity references */
void * _obj_id_ref_ptr[Genode::Msgbuf_base::MAX_CAPS_PER_MSG]; void * _obj_id_ref_ptr[Genode::Msgbuf_base::MAX_CAPS_PER_MSG];
inline void copy_msg(Ipc_node * const sender); inline void copy_msg(Ipc_node &sender);
/** /**
* Buffer next request from request queue in 'r' to handle it * Buffer next request from request queue in 'r' to handle it
*/ */
void _receive_request(Ipc_node * const caller); void _receive_request(Ipc_node &caller);
/** /**
* Receive a given reply if one is expected * Receive a given reply if one is expected
*/ */
void _receive_reply(Ipc_node * callee); void _receive_reply(Ipc_node &callee);
/** /**
* Insert 'r' into request queue, buffer it if we were waiting for it * Insert 'r' into request queue, buffer it if we were waiting for it
*/ */
void _announce_request(Ipc_node * const node); void _announce_request(Ipc_node &node);
/** /**
* Cancel all requests in request queue * Cancel all requests in request queue
@ -105,7 +106,7 @@ class Kernel::Ipc_node : private Ipc_node_queue::Element
/** /**
* A request 'r' in inbuf or request queue was cancelled by sender * A request 'r' in inbuf or request queue was cancelled by sender
*/ */
void _announced_request_cancelled(Ipc_node * const node); void _announced_request_cancelled(Ipc_node &node);
/** /**
* The request in the outbuf was cancelled by receiver * The request in the outbuf was cancelled by receiver
@ -159,7 +160,7 @@ class Kernel::Ipc_node : private Ipc_node_queue::Element
* \param callee targeted IPC node * \param callee targeted IPC node
* \param help wether the request implies a helping relationship * \param help wether the request implies a helping relationship
*/ */
void send_request(Ipc_node * const callee, capid_t capid, bool help, void send_request(Ipc_node &callee, capid_t capid, bool help,
unsigned rcv_caps); unsigned rcv_caps);
/** /**
@ -202,8 +203,15 @@ class Kernel::Ipc_node : private Ipc_node_queue::Element
** Accessors ** ** Accessors **
***************/ ***************/
Pd *pd() const { return _pd; } Pd &pd() const
Genode::Native_utcb *utcb() { return _utcb; } {
if (_pd)
return *_pd;
ASSERT_NEVER_CALLED;
}
Genode::Native_utcb *utcb() { return _utcb; }
}; };
#endif /* _CORE__KERNEL__IPC_NODE_H_ */ #endif /* _CORE__KERNEL__IPC_NODE_H_ */

View File

@ -18,14 +18,14 @@
#include <pic.h> #include <pic.h>
void Kernel::Irq::disable() const { pic()->mask(_irq_nr); } void Kernel::Irq::disable() const { pic().mask(_irq_nr); }
void Kernel::Irq::enable() const { pic()->unmask(_irq_nr, Cpu::executing_id()); } void Kernel::Irq::enable() const { pic().unmask(_irq_nr, Cpu::executing_id()); }
Kernel::Irq::Pool * Kernel::User_irq::_pool() Kernel::Irq::Pool &Kernel::User_irq::_pool()
{ {
static Irq::Pool p; static Irq::Pool p;
return &p; return p;
} }

View File

@ -128,7 +128,7 @@ class Kernel::User_irq : public Kernel::Irq, public Kernel::Object
/** /**
* Get map that provides all user interrupts by their kernel names * Get map that provides all user interrupts by their kernel names
*/ */
static Irq::Pool * _pool(); static Irq::Pool &_pool();
public: public:
@ -136,7 +136,7 @@ class Kernel::User_irq : public Kernel::Irq, public Kernel::Object
* Construct object that signals interrupt 'irq' via signal 'context' * Construct object that signals interrupt 'irq' via signal 'context'
*/ */
User_irq(unsigned const irq, Signal_context &context) User_irq(unsigned const irq, Signal_context &context)
: Irq(irq, *_pool()), _context(context) { disable(); } : Irq(irq, _pool()), _context(context) { disable(); }
/** /**
* Destructor * Destructor
@ -156,7 +156,7 @@ class Kernel::User_irq : public Kernel::Irq, public Kernel::Object
* Handle occurence of interrupt 'irq' * Handle occurence of interrupt 'irq'
*/ */
static User_irq * object(unsigned const irq) { static User_irq * object(unsigned const irq) {
return dynamic_cast<User_irq*>(_pool()->object(irq)); } return dynamic_cast<User_irq*>(_pool().object(irq)); }
}; };
#endif /* _CORE__KERNEL__IRQ_H_ */ #endif /* _CORE__KERNEL__IRQ_H_ */

View File

@ -22,7 +22,7 @@ extern "C" void kernel()
{ {
using namespace Kernel; using namespace Kernel;
Cpu & cpu = cpu_pool()->cpu(Cpu::executing_id()); Cpu &cpu = cpu_pool().cpu(Cpu::executing_id());
Cpu_job * new_job; Cpu_job * new_job;
{ {

View File

@ -27,8 +27,8 @@ namespace Kernel {
class Pd; class Pd;
Pd * core_pd(); Pd &core_pd();
Pic * pic(); Pic &pic();
} }
#endif /* _CORE__KERNEL__KERNEL_H_ */ #endif /* _CORE__KERNEL__KERNEL_H_ */

View File

@ -46,13 +46,13 @@ Object_identity::~Object_identity() { invalidate(); }
*******************************/ *******************************/
Object_identity_reference * Object_identity_reference *
Object_identity_reference::find(Pd * pd) Object_identity_reference::find(Pd &pd)
{ {
if (!_identity) return nullptr; if (!_identity) return nullptr;
for (Object_identity_reference * oir = _identity->first(); for (Object_identity_reference * oir = _identity->first();
oir; oir = oir->next()) oir; oir = oir->next())
if (pd == &(oir->_pd)) return oir; if (&pd == &(oir->_pd)) return oir;
return nullptr; return nullptr;
} }

View File

@ -160,7 +160,7 @@ class Kernel::Object_identity_reference
** Lookup functions ** ** Lookup functions **
**********************/ **********************/
Object_identity_reference * find(Pd * pd); Object_identity_reference * find(Pd &pd);
Object_identity_reference * find(capid_t capid); Object_identity_reference * find(capid_t capid);
}; };
@ -189,7 +189,7 @@ class Kernel::Core_object_identity : public Object_identity,
Core_object_identity(T & object) Core_object_identity(T & object)
: Object_identity(object), : Object_identity(object),
Object_identity_reference(this, *core_pd()) { } Object_identity_reference(this, core_pd()) { }
capid_t core_capid() { return capid(); } capid_t core_capid() { return capid(); }
}; };

View File

@ -47,14 +47,8 @@ class Kernel::Pd : public Kernel::Object
private: private:
/* Hw::Page_table &_table;
* Noncopyable Genode::Platform_pd &_platform_pd;
*/
Pd(Pd const &);
Pd &operator = (Pd const &);
Hw::Page_table * const _table;
Genode::Platform_pd * const _platform_pd;
Capid_allocator _capid_alloc { }; Capid_allocator _capid_alloc { };
Object_identity_reference_tree _cap_tree { }; Object_identity_reference_tree _cap_tree { };
@ -68,10 +62,10 @@ class Kernel::Pd : public Kernel::Object
* \param table translation table of the PD * \param table translation table of the PD
* \param platform_pd core object of the PD * \param platform_pd core object of the PD
*/ */
Pd(Hw::Page_table * const table, Pd(Hw::Page_table &table,
Genode::Platform_pd * const platform_pd) Genode::Platform_pd &platform_pd)
: _table(table), _platform_pd(platform_pd), : _table(table), _platform_pd(platform_pd),
mmu_regs((addr_t)table) mmu_regs((addr_t)&table)
{ {
capid_t invalid = _capid_alloc.alloc(); capid_t invalid = _capid_alloc.alloc();
assert(invalid == cap_id_invalid()); assert(invalid == cap_id_invalid());
@ -84,11 +78,11 @@ class Kernel::Pd : public Kernel::Object
} }
static capid_t syscall_create(void * const dst, static capid_t syscall_create(void * const dst,
Hw::Page_table * tt, Hw::Page_table &tt,
Genode::Platform_pd * const pd) Genode::Platform_pd &pd)
{ {
return call(call_id_new_pd(), (Call_arg)dst, return call(call_id_new_pd(), (Call_arg)dst,
(Call_arg)tt, (Call_arg)pd); (Call_arg)&tt, (Call_arg)&pd);
} }
static void syscall_destroy(Pd * const pd) { static void syscall_destroy(Pd * const pd) {
@ -105,10 +99,10 @@ class Kernel::Pd : public Kernel::Object
** Accessors ** ** Accessors **
***************/ ***************/
Genode::Platform_pd * platform_pd() const { return _platform_pd; } Genode::Platform_pd &platform_pd() { return _platform_pd; }
Hw::Page_table * translation_table() const { return _table; } Hw::Page_table &translation_table() { return _table; }
Capid_allocator & capid_alloc() { return _capid_alloc; } Capid_allocator &capid_alloc() { return _capid_alloc; }
Object_identity_reference_tree & cap_tree() { return _cap_tree; } Object_identity_reference_tree &cap_tree() { return _cap_tree; }
}; };
#endif /* _CORE__KERNEL__PD_H_ */ #endif /* _CORE__KERNEL__PD_H_ */

View File

@ -41,7 +41,7 @@ using namespace Kernel;
Thread::Pd_update::Pd_update(Thread & caller, Pd & pd, unsigned cnt) Thread::Pd_update::Pd_update(Thread & caller, Pd & pd, unsigned cnt)
: caller(caller), pd(pd), cnt(cnt) : caller(caller), pd(pd), cnt(cnt)
{ {
cpu_pool()->work_list().insert(&_le); cpu_pool().work_list().insert(&_le);
caller._become_inactive(AWAITS_RESTART); caller._become_inactive(AWAITS_RESTART);
} }
@ -57,7 +57,7 @@ Thread::Destroy::Destroy(Thread & caller, Thread & to_delete)
void Thread::Destroy::execute() void Thread::Destroy::execute()
{ {
thread_to_destroy.~Thread(); thread_to_destroy.~Thread();
cpu_pool()->executing_cpu().work_list().remove(&_le); cpu_pool().executing_cpu().work_list().remove(&_le);
caller._restart(); caller._restart();
} }
@ -224,18 +224,18 @@ void Thread::_call_thread_quota()
void Thread::_call_start_thread() void Thread::_call_start_thread()
{ {
/* lookup CPU */ /* lookup CPU */
Cpu & cpu = cpu_pool()->cpu(user_arg_2()); Cpu & cpu = cpu_pool().cpu(user_arg_2());
user_arg_0(0); user_arg_0(0);
Thread * const thread = (Thread*) user_arg_1(); Thread &thread = *(Thread *)user_arg_1();
assert(thread->_state == AWAITS_START); assert(thread._state == AWAITS_START);
thread->affinity(&cpu); thread.affinity(cpu);
/* join protection domain */ /* join protection domain */
thread->_pd = (Pd *) user_arg_3(); thread._pd = (Pd *) user_arg_3();
thread->Ipc_node::_init((Native_utcb *)user_arg_4(), this); thread.Ipc_node::_init(*(Native_utcb *)user_arg_4(), *this);
thread->_become_active(); thread._become_active();
} }
@ -268,17 +268,20 @@ void Thread::_call_stop_thread()
void Thread::_call_restart_thread() void Thread::_call_restart_thread()
{ {
if (!pd()) { Thread *thread_ptr = pd().cap_tree().find<Thread>(user_arg_1());
return; }
Thread * const thread = pd()->cap_tree().find<Thread>(user_arg_1()); if (!thread_ptr)
if (!thread || (!_core && (pd() != thread->pd()))) { return;
Thread &thread = *thread_ptr;
if (!_core && (&pd() != &thread.pd())) {
warning(*this, ": failed to lookup thread ", (unsigned)user_arg_1(), warning(*this, ": failed to lookup thread ", (unsigned)user_arg_1(),
" to restart it"); " to restart it");
_die(); _die();
return; return;
} }
user_arg_0(thread->_restart()); user_arg_0(thread._restart());
} }
@ -386,7 +389,7 @@ void Thread::_call_timeout_max_us()
void Thread::timeout_triggered() void Thread::timeout_triggered()
{ {
Signal_context * const c = Signal_context * const c =
pd()->cap_tree().find<Signal_context>(_timeout_sigid); pd().cap_tree().find<Signal_context>(_timeout_sigid);
if (!c || c->submit(1)) if (!c || c->submit(1))
Genode::warning(*this, ": failed to submit timeout signal"); Genode::warning(*this, ": failed to submit timeout signal");
} }
@ -394,7 +397,7 @@ void Thread::timeout_triggered()
void Thread::_call_send_request_msg() void Thread::_call_send_request_msg()
{ {
Object_identity_reference * oir = pd()->cap_tree().find(user_arg_1()); Object_identity_reference * oir = pd().cap_tree().find(user_arg_1());
Thread * const dst = (oir) ? oir->object<Thread>() : nullptr; Thread * const dst = (oir) ? oir->object<Thread>() : nullptr;
if (!dst) { if (!dst) {
Genode::warning(*this, ": cannot send to unknown recipient ", Genode::warning(*this, ": cannot send to unknown recipient ",
@ -402,10 +405,10 @@ void Thread::_call_send_request_msg()
_become_inactive(AWAITS_IPC); _become_inactive(AWAITS_IPC);
return; return;
} }
bool const help = Cpu_job::_helping_possible(dst); bool const help = Cpu_job::_helping_possible(*dst);
oir = oir->find(dst->pd()); oir = oir->find(dst->pd());
Ipc_node::send_request(dst, oir ? oir->capid() : cap_id_invalid(), Ipc_node::send_request(*dst, oir ? oir->capid() : cap_id_invalid(),
help, user_arg_2()); help, user_arg_2());
_state = AWAITS_IPC; _state = AWAITS_IPC;
if (!help || !dst->own_share_active()) { _deactivate_used_shares(); } if (!help || !dst->own_share_active()) { _deactivate_used_shares(); }
@ -424,8 +427,8 @@ void Thread::_call_send_reply_msg()
void Thread::_call_pager() void Thread::_call_pager()
{ {
/* override event route */ /* override event route */
Thread * const t = (Thread*) user_arg_1(); Thread &thread = *(Thread *)user_arg_1();
t->_pager = pd()->cap_tree().find<Signal_context>(user_arg_2()); thread._pager = pd().cap_tree().find<Signal_context>(user_arg_2());
} }
@ -441,7 +444,7 @@ void Thread::_call_await_signal()
return; return;
} }
/* lookup receiver */ /* lookup receiver */
Signal_receiver * const r = pd()->cap_tree().find<Signal_receiver>(user_arg_1()); Signal_receiver * const r = pd().cap_tree().find<Signal_receiver>(user_arg_1());
if (!r) { if (!r) {
Genode::warning(*this, ": cannot await, unknown signal receiver ", Genode::warning(*this, ": cannot await, unknown signal receiver ",
(unsigned)user_arg_1()); (unsigned)user_arg_1());
@ -460,15 +463,9 @@ void Thread::_call_await_signal()
void Thread::_call_cancel_next_await_signal() void Thread::_call_cancel_next_await_signal()
{ {
/* kill the caller if he has no protection domain */
if (!pd()) {
error(*this, ": PD not set");
_die();
return;
}
/* kill the caller if the capability of the target thread is invalid */ /* kill the caller if the capability of the target thread is invalid */
Thread * const thread = pd()->cap_tree().find<Thread>(user_arg_1()); Thread * const thread = pd().cap_tree().find<Thread>(user_arg_1());
if (!thread || pd() != thread->pd()) { if (!thread || (&pd() != &thread->pd())) {
error(*this, ": failed to lookup thread ", (unsigned)user_arg_1()); error(*this, ": failed to lookup thread ", (unsigned)user_arg_1());
_die(); _die();
return; return;
@ -486,7 +483,7 @@ void Thread::_call_cancel_next_await_signal()
void Thread::_call_submit_signal() void Thread::_call_submit_signal()
{ {
/* lookup signal context */ /* lookup signal context */
Signal_context * const c = pd()->cap_tree().find<Signal_context>(user_arg_1()); Signal_context * const c = pd().cap_tree().find<Signal_context>(user_arg_1());
if(!c) { if(!c) {
Genode::warning(*this, ": cannot submit unknown signal context"); Genode::warning(*this, ": cannot submit unknown signal context");
user_arg_0(-1); user_arg_0(-1);
@ -506,7 +503,7 @@ void Thread::_call_submit_signal()
void Thread::_call_ack_signal() void Thread::_call_ack_signal()
{ {
/* lookup signal context */ /* lookup signal context */
Signal_context * const c = pd()->cap_tree().find<Signal_context>(user_arg_1()); Signal_context * const c = pd().cap_tree().find<Signal_context>(user_arg_1());
if (!c) { if (!c) {
Genode::warning(*this, ": cannot ack unknown signal context"); Genode::warning(*this, ": cannot ack unknown signal context");
return; return;
@ -520,7 +517,7 @@ void Thread::_call_ack_signal()
void Thread::_call_kill_signal_context() void Thread::_call_kill_signal_context()
{ {
/* lookup signal context */ /* lookup signal context */
Signal_context * const c = pd()->cap_tree().find<Signal_context>(user_arg_1()); Signal_context * const c = pd().cap_tree().find<Signal_context>(user_arg_1());
if (!c) { if (!c) {
Genode::warning(*this, ": cannot kill unknown signal context"); Genode::warning(*this, ": cannot kill unknown signal context");
user_arg_0(-1); user_arg_0(-1);
@ -538,7 +535,7 @@ void Thread::_call_kill_signal_context()
void Thread::_call_new_irq() void Thread::_call_new_irq()
{ {
Signal_context * const c = pd()->cap_tree().find<Signal_context>(user_arg_3()); Signal_context * const c = pd().cap_tree().find<Signal_context>(user_arg_3());
if (!c) { if (!c) {
Genode::warning(*this, ": invalid signal context for interrupt"); Genode::warning(*this, ": invalid signal context for interrupt");
user_arg_0(-1); user_arg_0(-1);
@ -557,7 +554,7 @@ void Thread::_call_ack_irq() {
void Thread::_call_new_obj() void Thread::_call_new_obj()
{ {
/* lookup thread */ /* lookup thread */
Object_identity_reference * ref = pd()->cap_tree().find(user_arg_2()); Object_identity_reference * ref = pd().cap_tree().find(user_arg_2());
Thread * thread = ref ? ref->object<Thread>() : nullptr; Thread * thread = ref ? ref->object<Thread>() : nullptr;
if (!thread || if (!thread ||
(static_cast<Core_object<Thread>*>(thread)->capid() != ref->capid())) { (static_cast<Core_object<Thread>*>(thread)->capid() != ref->capid())) {
@ -583,19 +580,19 @@ void Thread::_call_delete_obj()
void Thread::_call_ack_cap() void Thread::_call_ack_cap()
{ {
Object_identity_reference * oir = pd()->cap_tree().find(user_arg_1()); Object_identity_reference * oir = pd().cap_tree().find(user_arg_1());
if (oir) oir->remove_from_utcb(); if (oir) oir->remove_from_utcb();
} }
void Thread::_call_delete_cap() void Thread::_call_delete_cap()
{ {
Object_identity_reference * oir = pd()->cap_tree().find(user_arg_1()); Object_identity_reference * oir = pd().cap_tree().find(user_arg_1());
if (!oir) return; if (!oir) return;
if (oir->in_utcb()) return; if (oir->in_utcb()) return;
destroy(pd()->platform_pd()->capability_slab(), oir); destroy(pd().platform_pd().capability_slab(), oir);
} }
@ -604,7 +601,7 @@ void Kernel::Thread::_call_update_pd()
Pd * const pd = (Pd *) user_arg_1(); Pd * const pd = (Pd *) user_arg_1();
unsigned cnt = 0; unsigned cnt = 0;
cpu_pool()->for_each_cpu([&] (Cpu & cpu) { cpu_pool().for_each_cpu([&] (Cpu & cpu) {
/* if a cpu needs to update increase the counter */ /* if a cpu needs to update increase the counter */
if (pd->update(cpu)) cnt++; }); if (pd->update(cpu)) cnt++; });
@ -660,8 +657,8 @@ void Thread::_call()
case call_id_thread_pager(): _call_pager(); return; case call_id_thread_pager(): _call_pager(); return;
case call_id_update_pd(): _call_update_pd(); return; case call_id_update_pd(): _call_update_pd(); return;
case call_id_new_pd(): case call_id_new_pd():
_call_new<Pd>((Hw::Page_table *) user_arg_2(), _call_new<Pd>(*(Hw::Page_table *) user_arg_2(),
(Genode::Platform_pd *) user_arg_3()); *(Genode::Platform_pd *) user_arg_3());
return; return;
case call_id_delete_pd(): _call_delete<Pd>(); return; case call_id_delete_pd(): _call_delete<Pd>(); return;
case call_id_new_signal_receiver(): _call_new<Signal_receiver>(); return; case call_id_new_signal_receiver(): _call_new<Signal_receiver>(); return;
@ -717,7 +714,7 @@ Thread::Thread(unsigned const priority, unsigned const quota,
void Thread::print(Genode::Output &out) const void Thread::print(Genode::Output &out) const
{ {
Genode::print(out, (_pd) ? _pd->platform_pd()->label() : "?"); Genode::print(out, _pd ? _pd->platform_pd().label() : "?");
Genode::print(out, " -> "); Genode::print(out, " -> ");
Genode::print(out, label()); Genode::print(out, label());
} }
@ -751,9 +748,9 @@ Core_thread::Core_thread()
regs->sp = (addr_t)&__initial_stack_base[0] + DEFAULT_STACK_SIZE; regs->sp = (addr_t)&__initial_stack_base[0] + DEFAULT_STACK_SIZE;
regs->ip = (addr_t)&_core_start; regs->ip = (addr_t)&_core_start;
affinity(&cpu_pool()->primary_cpu()); affinity(cpu_pool().primary_cpu());
_utcb = utcb; _utcb = utcb;
Thread::_pd = core_pd(); Thread::_pd = &core_pd();
_become_active(); _become_active();
} }

View File

@ -18,7 +18,7 @@
void Kernel::Thread::_call_new_vm() void Kernel::Thread::_call_new_vm()
{ {
Signal_context * context = Signal_context * context =
pd()->cap_tree().find<Signal_context>(user_arg_4()); pd().cap_tree().find<Signal_context>(user_arg_4());
if (!context) { if (!context) {
user_arg_0(cap_id_invalid()); user_arg_0(cap_id_invalid());
return; return;

View File

@ -65,6 +65,8 @@ class Genode::Kernel_object
T * kernel_object() { return reinterpret_cast<T*>(_data); } T * kernel_object() { return reinterpret_cast<T*>(_data); }
Untyped_capability cap() { return _cap; }
/** /**
* Create the kernel object explicitely via this function * Create the kernel object explicitely via this function
*/ */

View File

@ -69,7 +69,7 @@ void Pager_object::unresolved_page_fault_occurred()
Platform_thread * const pt = (Platform_thread *)badge(); Platform_thread * const pt = (Platform_thread *)badge();
if (pt && pt->pd()) if (pt && pt->pd())
warning("page fault, pager_object: pd='", pt->pd()->label(), warning("page fault, pager_object: pd='", pt->pd()->label(),
"' thread='", pt->label(), "' ", pt->kernel_object()->fault()); "' thread='", pt->label(), "' ", pt->fault_info());
} }
void Pager_object::print(Output &out) const void Pager_object::print(Output &out) const
@ -94,12 +94,10 @@ Pager_object::Pager_object(Cpu_session_capability cpu_session_cap,
** Pager_entrypoint ** ** Pager_entrypoint **
**********************/ **********************/
void Pager_entrypoint::dissolve(Pager_object * const o) void Pager_entrypoint::dissolve(Pager_object &o)
{ {
if (o) { Kernel::kill_signal_context(Capability_space::capid(o.cap()));
Kernel::kill_signal_context(Capability_space::capid(o->cap())); remove(&o);
remove(o);
}
} }
@ -109,9 +107,9 @@ Pager_entrypoint::Pager_entrypoint(Rpc_cap_factory &)
{ start(); } { start(); }
Pager_capability Pager_entrypoint::manage(Pager_object * const o) Pager_capability Pager_entrypoint::manage(Pager_object &o)
{ {
o->start_paging(kernel_object()); o.start_paging(kernel_object());
insert(o); insert(&o);
return reinterpret_cap_cast<Pager_object>(o->cap()); return reinterpret_cap_cast<Pager_object>(o.cap());
} }

View File

@ -208,12 +208,12 @@ class Genode::Pager_entrypoint : public Object_pool<Pager_object>,
/** /**
* Associate pager object 'obj' with entry point * Associate pager object 'obj' with entry point
*/ */
Pager_capability manage(Pager_object * const obj); Pager_capability manage(Pager_object &obj);
/** /**
* Dissolve pager object 'obj' from entry point * Dissolve pager object 'obj' from entry point
*/ */
void dissolve(Pager_object * const obj); void dissolve(Pager_object &obj);
/********************** /**********************

View File

@ -97,27 +97,27 @@ addr_t Platform::_rom_module_phys(addr_t virt)
Platform::Platform() Platform::Platform()
: :
_io_mem_alloc(core_mem_alloc()), _io_mem_alloc(&core_mem_alloc()),
_io_port_alloc(core_mem_alloc()), _io_port_alloc(&core_mem_alloc()),
_irq_alloc(core_mem_alloc()) _irq_alloc(&core_mem_alloc())
{ {
struct Kernel_resource : Exception { }; struct Kernel_resource : Exception { };
_core_mem_alloc.virt_alloc()->add_range(Hw::Mm::core_heap().base, _core_mem_alloc.virt_alloc().add_range(Hw::Mm::core_heap().base,
Hw::Mm::core_heap().size); Hw::Mm::core_heap().size);
_core_virt_regions().for_each([this] (Hw::Memory_region const & r) { _core_virt_regions().for_each([this] (Hw::Memory_region const & r) {
_core_mem_alloc.virt_alloc()->remove_range(r.base, r.size); }); _core_mem_alloc.virt_alloc().remove_range(r.base, r.size); });
_boot_info().elf_mappings.for_each([this] (Hw::Mapping const & m) { _boot_info().elf_mappings.for_each([this] (Hw::Mapping const & m) {
_core_mem_alloc.virt_alloc()->remove_range(m.virt(), m.size()); }); _core_mem_alloc.virt_alloc().remove_range(m.virt(), m.size()); });
_boot_info().ram_regions.for_each([this] (Hw::Memory_region const & region) { _boot_info().ram_regions.for_each([this] (Hw::Memory_region const & region) {
_core_mem_alloc.phys_alloc()->add_range(region.base, region.size); }); _core_mem_alloc.phys_alloc().add_range(region.base, region.size); });
_init_io_port_alloc(); _init_io_port_alloc();
/* make all non-kernel interrupts available to the interrupt allocator */ /* make all non-kernel interrupts available to the interrupt allocator */
for (unsigned i = 0; i < Kernel::Pic::NR_OF_IRQ; i++) { for (unsigned i = 0; i < Kernel::Pic::NR_OF_IRQ; i++) {
bool kernel_resource = false; bool kernel_resource = false;
Kernel::cpu_pool()->for_each_cpu([&] (Kernel::Cpu const &cpu) { Kernel::cpu_pool().for_each_cpu([&] (Kernel::Cpu const &cpu) {
if (i == cpu.timer_interrupt_id()) { if (i == cpu.timer_interrupt_id()) {
kernel_resource = true; kernel_resource = true;
} }
@ -142,11 +142,11 @@ Platform::Platform()
unsigned const pages = 1; unsigned const pages = 1;
size_t const log_size = pages << get_page_size_log2(); size_t const log_size = pages << get_page_size_log2();
ram_alloc()->alloc_aligned(log_size, &phys_ptr, get_page_size_log2()); ram_alloc().alloc_aligned(log_size, &phys_ptr, get_page_size_log2());
addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr); addr_t const phys_addr = reinterpret_cast<addr_t>(phys_ptr);
/* let one page free after the log buffer */ /* let one page free after the log buffer */
region_alloc()->alloc_aligned(log_size, &core_local_ptr, get_page_size_log2()); region_alloc().alloc_aligned(log_size, &core_local_ptr, get_page_size_log2());
addr_t const core_local_addr = reinterpret_cast<addr_t>(core_local_ptr); addr_t const core_local_addr = reinterpret_cast<addr_t>(core_local_ptr);
map_local(phys_addr, core_local_addr, pages); map_local(phys_addr, core_local_addr, pages);
@ -169,16 +169,16 @@ Platform::Platform()
bool Genode::map_local(addr_t from_phys, addr_t to_virt, size_t num_pages, bool Genode::map_local(addr_t from_phys, addr_t to_virt, size_t num_pages,
Page_flags flags) Page_flags flags)
{ {
Platform_pd * pd = Kernel::core_pd()->platform_pd(); Platform_pd &pd = Kernel::core_pd().platform_pd();
return pd->insert_translation(to_virt, from_phys, return pd.insert_translation(to_virt, from_phys,
num_pages * get_page_size(), flags); num_pages * get_page_size(), flags);
} }
bool Genode::unmap_local(addr_t virt_addr, size_t num_pages) bool Genode::unmap_local(addr_t virt_addr, size_t num_pages)
{ {
Platform_pd * pd = Kernel::core_pd()->platform_pd(); Platform_pd &pd = Kernel::core_pd().platform_pd();
pd->flush(virt_addr, num_pages * get_page_size()); pd.flush(virt_addr, num_pages * get_page_size());
return true; return true;
} }

View File

@ -32,6 +32,7 @@
#include <core_region_map.h> #include <core_region_map.h>
#include <core_mem_alloc.h> #include <core_mem_alloc.h>
#include <translation_table.h> #include <translation_table.h>
#include <assertion.h>
namespace Genode { namespace Genode {
class Address_space; class Address_space;
@ -48,7 +49,7 @@ class Genode::Platform : public Genode::Platform_generic
Phys_allocator _irq_alloc; /* IRQ allocator */ Phys_allocator _irq_alloc; /* IRQ allocator */
Rom_fs _rom_fs { }; /* ROM file system */ Rom_fs _rom_fs { }; /* ROM file system */
static Hw::Boot_info const & _boot_info(); static Hw::Boot_info const &_boot_info();
static Hw::Memory_region_array const & _core_virt_regions(); static Hw::Memory_region_array const & _core_virt_regions();
/** /**
@ -120,34 +121,23 @@ class Genode::Platform : public Genode::Platform_generic
** Platform_generic interface ** ** Platform_generic interface **
********************************/ ********************************/
Range_allocator * core_mem_alloc() { Range_allocator &core_mem_alloc() override { return _core_mem_alloc; }
return &_core_mem_alloc; } Range_allocator &ram_alloc() override { return _core_mem_alloc.phys_alloc(); }
Range_allocator &region_alloc() override { return _core_mem_alloc.virt_alloc(); }
Range_allocator * ram_alloc() { Range_allocator &io_mem_alloc() override { return _io_mem_alloc; }
return _core_mem_alloc.phys_alloc(); } Range_allocator &io_port_alloc() override { return _io_port_alloc; }
Range_allocator &irq_alloc() override { return _irq_alloc; }
Range_allocator * region_alloc() { addr_t vm_start() const override { return Hw::Mm::user().base; }
return _core_mem_alloc.virt_alloc(); } size_t vm_size() const override { return Hw::Mm::user().size; }
Rom_fs &rom_fs() override { return _rom_fs; }
Range_allocator * io_mem_alloc() { return &_io_mem_alloc; }
Range_allocator * io_port_alloc() { return &_io_port_alloc; }
Range_allocator * irq_alloc() { return &_irq_alloc; }
addr_t vm_start() const { return Hw::Mm::user().base; }
size_t vm_size() const { return Hw::Mm::user().size; }
Rom_fs *rom_fs() { return &_rom_fs; }
inline void wait_for_exit() { inline void wait_for_exit() {
while (1) { Kernel::stop_thread(); } }; while (1) { Kernel::stop_thread(); } };
bool supports_direct_unmap() const { return 1; } bool supports_direct_unmap() const override { return true; }
Address_space * core_pd() { return nullptr; } Address_space &core_pd() { ASSERT_NEVER_CALLED; }
Affinity::Space affinity_space() const { Affinity::Space affinity_space() const override {
return Affinity::Space(_boot_info().cpus); } return Affinity::Space(_boot_info().cpus); }
/* /*

View File

@ -29,15 +29,15 @@ using Hw::Page_table;
** Hw::Address_space implementation ** ** Hw::Address_space implementation **
**************************************/ **************************************/
Core_mem_allocator * Hw::Address_space::_cma() { Core_mem_allocator &Hw::Address_space::_cma() {
return static_cast<Core_mem_allocator*>(platform()->core_mem_alloc()); } return static_cast<Core_mem_allocator &>(platform().core_mem_alloc()); }
void * Hw::Address_space::_table_alloc() void *Hw::Address_space::_table_alloc()
{ {
void * ret; void * ret = nullptr;
if (!_cma()->alloc_aligned(sizeof(Page_table), (void**)&ret, if (!_cma().alloc_aligned(sizeof(Page_table), (void**)&ret,
Page_table::ALIGNM_LOG2).ok()) Page_table::ALIGNM_LOG2).ok())
throw Insufficient_ram_quota(); throw Insufficient_ram_quota();
return ret; return ret;
} }
@ -53,7 +53,7 @@ bool Hw::Address_space::insert_translation(addr_t virt, addr_t phys,
_tt.insert_translation(virt, phys, size, flags, _tt_alloc); _tt.insert_translation(virt, phys, size, flags, _tt_alloc);
return true; return true;
} catch(Hw::Out_of_tables &) { } catch(Hw::Out_of_tables &) {
flush(platform()->vm_start(), platform()->vm_size()); flush(platform().vm_start(), platform().vm_size());
} }
} }
} catch(...) { } catch(...) {
@ -86,16 +86,16 @@ Hw::Address_space::Address_space(Kernel::Pd & pd, Page_table & tt,
Hw::Address_space::Address_space(Kernel::Pd & pd) Hw::Address_space::Address_space(Kernel::Pd & pd)
: _tt(*construct_at<Page_table>(_table_alloc(), *((Page_table*)Hw::Mm::core_page_tables().base))), : _tt(*construct_at<Page_table>(_table_alloc(), *((Page_table*)Hw::Mm::core_page_tables().base))),
_tt_phys((addr_t)_cma()->phys_addr(&_tt)), _tt_phys((addr_t)_cma().phys_addr(&_tt)),
_tt_array(new (_cma()) Array([this] (void * virt) { _tt_array(new (_cma()) Array([this] (void * virt) {
return (addr_t)_cma()->phys_addr(virt);})), return (addr_t)_cma().phys_addr(virt);})),
_tt_alloc(_tt_array->alloc()), _tt_alloc(_tt_array->alloc()),
_kernel_pd(pd) { } _kernel_pd(pd) { }
Hw::Address_space::~Address_space() Hw::Address_space::~Address_space()
{ {
flush(platform()->vm_start(), platform()->vm_size()); flush(platform().vm_start(), platform().vm_size());
destroy(_cma(), _tt_array); destroy(_cma(), _tt_array);
destroy(_cma(), &_tt); destroy(_cma(), &_tt);
} }
@ -121,18 +121,18 @@ void Cap_space::upgrade_slab(Allocator &alloc)
** Platform_pd implementation ** ** Platform_pd implementation **
********************************/ ********************************/
bool Platform_pd::bind_thread(Platform_thread * t) bool Platform_pd::bind_thread(Platform_thread &t)
{ {
/* is this the first and therefore main thread in this PD? */ /* is this the first and therefore main thread in this PD? */
bool main_thread = !_thread_associated; bool main_thread = !_thread_associated;
_thread_associated = true; _thread_associated = true;
t->join_pd(this, main_thread, Address_space::weak_ptr()); t.join_pd(this, main_thread, Address_space::weak_ptr());
return true; return true;
} }
void Platform_pd::unbind_thread(Platform_thread *t) { void Platform_pd::unbind_thread(Platform_thread &t) {
t->join_pd(nullptr, false, Address_space::weak_ptr()); } t.join_pd(nullptr, false, Address_space::weak_ptr()); }
void Platform_pd::assign_parent(Native_capability parent) void Platform_pd::assign_parent(Native_capability parent)
@ -144,15 +144,18 @@ void Platform_pd::assign_parent(Native_capability parent)
Platform_pd::Platform_pd(Page_table & tt, Platform_pd::Platform_pd(Page_table & tt,
Page_table::Allocator & alloc) Page_table::Allocator & alloc)
: Hw::Address_space(*kernel_object(), tt, alloc), :
Kernel_object<Kernel::Pd>(false, (Page_table*)translation_table_phys(), this), Hw::Address_space(*kernel_object(), tt, alloc),
_label("core") { } Kernel_object<Kernel::Pd>(false, *(Page_table*)translation_table_phys(), *this),
_label("core")
{ }
Platform_pd::Platform_pd(Allocator *, char const *label) Platform_pd::Platform_pd(Allocator &, char const *label)
: Hw::Address_space(*kernel_object()), :
Kernel_object<Kernel::Pd>(true, (Page_table*)translation_table_phys(), this), Hw::Address_space(*kernel_object()),
_label(label) Kernel_object<Kernel::Pd>(true, *(Page_table*)translation_table_phys(), *this),
_label(label)
{ {
if (!_cap.valid()) { if (!_cap.valid()) {
error("failed to create kernel object"); error("failed to create kernel object");

View File

@ -76,11 +76,12 @@ class Hw::Address_space : public Genode::Address_space
Table & _tt; /* table virt addr */ Table & _tt; /* table virt addr */
Genode::addr_t _tt_phys; /* table phys addr */ Genode::addr_t _tt_phys; /* table phys addr */
Array * _tt_array = nullptr; Array * _tt_array = nullptr;
Table::Allocator & _tt_alloc; /* table allocator */ Table::Allocator & _tt_alloc; /* table allocator */
Kernel::Pd & _kernel_pd; Kernel::Pd & _kernel_pd;
static inline Genode::Core_mem_allocator * _cma(); static inline Genode::Core_mem_allocator &_cma();
static inline void * _table_alloc();
static inline void *_table_alloc();
protected: protected:
@ -193,7 +194,7 @@ class Genode::Platform_pd : public Hw::Address_space,
* *
* \param label name of protection domain * \param label name of protection domain
*/ */
Platform_pd(Allocator * md_alloc, char const *label); Platform_pd(Allocator &md_alloc, char const *label);
/** /**
* Destructor * Destructor
@ -204,14 +205,14 @@ class Genode::Platform_pd : public Hw::Address_space,
using Cap_space::upgrade_slab; using Cap_space::upgrade_slab;
/** /**
* Bind thread 't' to protection domain * Bind thread to protection domain
*/ */
bool bind_thread(Platform_thread * t); bool bind_thread(Platform_thread &);
/** /**
* Unbind thread 't' from protection domain * Unbind thread from protection domain
*/ */
void unbind_thread(Platform_thread *t); void unbind_thread(Platform_thread &);
/** /**
* Assign parent interface to protection domain * Assign parent interface to protection domain

View File

@ -47,28 +47,27 @@ Platform_thread::~Platform_thread()
} }
/* free UTCB */ /* free UTCB */
core_env()->ram_session()->free(_utcb); core_env().ram_session()->free(_utcb);
} }
void Platform_thread::quota(size_t const quota) { void Platform_thread::quota(size_t const quota) {
Kernel::thread_quota(kernel_object(), quota); } Kernel::thread_quota(_kobj.kernel_object(), quota); }
Platform_thread::Platform_thread(const char * const label, Platform_thread::Platform_thread(Label const &label, Native_utcb &utcb)
Native_utcb * utcb) :
: Kernel_object<Kernel::Thread>(true, _label), _label(label),
_pd(Kernel::core_pd()->platform_pd()), _pd(&Kernel::core_pd().platform_pd()),
_pager(nullptr), _pager(nullptr),
_utcb_core_addr(utcb), _utcb_core_addr(&utcb),
_utcb_pd_addr(utcb), _utcb_pd_addr(&utcb),
_main_thread(false) _main_thread(false),
_kobj(true, _label.string())
{ {
strncpy(_label, label, LABEL_MAX_LEN);
/* create UTCB for a core thread */ /* create UTCB for a core thread */
void *utcb_phys; void *utcb_phys;
if (!platform()->ram_alloc()->alloc(sizeof(Native_utcb), &utcb_phys)) { if (!platform().ram_alloc().alloc(sizeof(Native_utcb), &utcb_phys)) {
error("failed to allocate UTCB"); error("failed to allocate UTCB");
throw Out_of_ram(); throw Out_of_ram();
} }
@ -77,27 +76,26 @@ Platform_thread::Platform_thread(const char * const label,
} }
Platform_thread::Platform_thread(size_t const quota, Platform_thread::Platform_thread(size_t const quota,
const char * const label, Label const &label,
unsigned const virt_prio, unsigned const virt_prio,
Affinity::Location location, Affinity::Location const location,
addr_t const utcb) addr_t const utcb)
: Kernel_object<Kernel::Thread>(true, _priority(virt_prio), quota, _label), :
_pd(nullptr), _label(label),
_pager(nullptr), _pd(nullptr),
_utcb_pd_addr((Native_utcb *)utcb), _pager(nullptr),
_main_thread(false) _utcb_pd_addr((Native_utcb *)utcb),
_main_thread(false),
_kobj(true, _priority(virt_prio), quota, _label.string())
{ {
strncpy(_label, label, LABEL_MAX_LEN);
try { try {
_utcb = core_env()->ram_session()->alloc(sizeof(Native_utcb), _utcb = core_env().ram_session()->alloc(sizeof(Native_utcb), CACHED);
CACHED);
} catch (...) { } catch (...) {
error("failed to allocate UTCB"); error("failed to allocate UTCB");
throw Out_of_ram(); throw Out_of_ram();
} }
_utcb_core_addr = (Native_utcb *)core_env()->rm_session()->attach(_utcb); _utcb_core_addr = (Native_utcb *)core_env().rm_session()->attach(_utcb);
affinity(location); affinity(location);
} }
@ -151,12 +149,12 @@ int Platform_thread::start(void * const ip, void * const sp)
} }
return 0; return 0;
}; };
if (core_env()->entrypoint()->apply(_utcb, lambda)) return -1; if (core_env().entrypoint().apply(_utcb, lambda)) return -1;
} }
/* initialize thread registers */ /* initialize thread registers */
kernel_object()->regs->ip = reinterpret_cast<addr_t>(ip); _kobj.kernel_object()->regs->ip = reinterpret_cast<addr_t>(ip);
kernel_object()->regs->sp = reinterpret_cast<addr_t>(sp); _kobj.kernel_object()->regs->sp = reinterpret_cast<addr_t>(sp);
/* start executing new thread */ /* start executing new thread */
if (!_pd) { if (!_pd) {
@ -167,49 +165,54 @@ int Platform_thread::start(void * const ip, void * const sp)
unsigned const cpu = unsigned const cpu =
_location.valid() ? _location.xpos() : Cpu::primary_id(); _location.valid() ? _location.xpos() : Cpu::primary_id();
Native_utcb * utcb = Thread::myself()->utcb(); Native_utcb &utcb = *Thread::myself()->utcb();
/* reset capability counter */ /* reset capability counter */
utcb->cap_cnt(0); utcb.cap_cnt(0);
utcb->cap_add(Capability_space::capid(_cap)); utcb.cap_add(Capability_space::capid(_kobj.cap()));
if (_main_thread) { if (_main_thread) {
utcb->cap_add(Capability_space::capid(_pd->parent())); utcb.cap_add(Capability_space::capid(_pd->parent()));
utcb->cap_add(Capability_space::capid(_utcb)); utcb.cap_add(Capability_space::capid(_utcb));
} }
Kernel::start_thread(kernel_object(), cpu, &_pd->kernel_pd(), Kernel::start_thread(_kobj.kernel_object(), cpu, &_pd->kernel_pd(),
_utcb_core_addr); _utcb_core_addr);
return 0; return 0;
} }
void Platform_thread::pager(Pager_object * const pager) void Platform_thread::pager(Pager_object &pager)
{ {
using namespace Kernel; using namespace Kernel;
thread_pager(kernel_object(), pager ? Capability_space::capid(pager->cap()) thread_pager(_kobj.kernel_object(), Capability_space::capid(pager.cap()));
: cap_id_invalid()); _pager = &pager;
_pager = pager;
} }
Genode::Pager_object * Platform_thread::pager() { return _pager; } Genode::Pager_object &Platform_thread::pager()
{
if (_pager)
return *_pager;
ASSERT_NEVER_CALLED;
}
Thread_state Platform_thread::state() Thread_state Platform_thread::state()
{ {
Thread_state_base bstate(*kernel_object()->regs); Thread_state_base bstate(*_kobj.kernel_object()->regs);
return Thread_state(bstate); return Thread_state(bstate);
} }
void Platform_thread::state(Thread_state thread_state) void Platform_thread::state(Thread_state thread_state)
{ {
Cpu_state * cstate = static_cast<Cpu_state *>(&*kernel_object()->regs); Cpu_state * cstate = static_cast<Cpu_state *>(&*_kobj.kernel_object()->regs);
*cstate = static_cast<Cpu_state>(thread_state); *cstate = static_cast<Cpu_state>(thread_state);
} }
void Platform_thread::restart() void Platform_thread::restart()
{ {
Kernel::restart_thread(Capability_space::capid(_cap)); Kernel::restart_thread(Capability_space::capid(_kobj.cap()));
} }

View File

@ -41,7 +41,7 @@ namespace Genode {
/** /**
* Userland interface for the management of kernel thread-objects * Userland interface for the management of kernel thread-objects
*/ */
class Platform_thread : public Kernel_object<Kernel::Thread> class Platform_thread : Noncopyable
{ {
/* /*
* Noncopyable * Noncopyable
@ -49,15 +49,15 @@ namespace Genode {
Platform_thread(Platform_thread const &); Platform_thread(Platform_thread const &);
Platform_thread &operator = (Platform_thread const &); Platform_thread &operator = (Platform_thread const &);
enum { LABEL_MAX_LEN = 32 }; typedef String<32> Label;
Label const _label;
Platform_pd * _pd; Platform_pd * _pd;
Weak_ptr<Address_space> _address_space { }; Weak_ptr<Address_space> _address_space { };
Pager_object * _pager; Pager_object * _pager;
Native_utcb * _utcb_core_addr { }; /* UTCB addr in core */ Native_utcb * _utcb_core_addr { }; /* UTCB addr in core */
Native_utcb * _utcb_pd_addr; /* UTCB addr in pd */ Native_utcb * _utcb_pd_addr; /* UTCB addr in pd */
Ram_dataspace_capability _utcb { }; /* UTCB dataspace */ Ram_dataspace_capability _utcb { }; /* UTCB dataspace */
char _label[LABEL_MAX_LEN];
/* /*
* Wether this thread is the main thread of a program. * Wether this thread is the main thread of a program.
@ -71,6 +71,8 @@ namespace Genode {
Affinity::Location _location { }; Affinity::Location _location { };
Kernel_object<Kernel::Thread> _kobj;
/** /**
* Common construction part * Common construction part
*/ */
@ -95,7 +97,7 @@ namespace Genode {
* \param label debugging label * \param label debugging label
* \param utcb virtual address of UTCB within core * \param utcb virtual address of UTCB within core
*/ */
Platform_thread(const char * const label, Native_utcb * utcb); Platform_thread(Label const &label, Native_utcb &utcb);
/** /**
* Constructor for threads outside of core * Constructor for threads outside of core
@ -105,7 +107,7 @@ namespace Genode {
* \param virt_prio unscaled processor-scheduling priority * \param virt_prio unscaled processor-scheduling priority
* \param utcb core local pointer to userland stack * \param utcb core local pointer to userland stack
*/ */
Platform_thread(size_t const quota, const char * const label, Platform_thread(size_t const quota, Label const &label,
unsigned const virt_prio, Affinity::Location, unsigned const virt_prio, Affinity::Location,
addr_t const utcb); addr_t const utcb);
@ -114,6 +116,11 @@ namespace Genode {
*/ */
~Platform_thread(); ~Platform_thread();
/**
* Return information about current fault
*/
Kernel::Thread_fault fault_info() { return _kobj.kernel_object()->fault(); }
/** /**
* Join a protection domain * Join a protection domain
* *
@ -124,7 +131,7 @@ namespace Genode {
* This function has no effect when called more twice for a * This function has no effect when called more twice for a
* given thread. * given thread.
*/ */
void join_pd(Platform_pd * const pd, bool const main_thread, void join_pd(Platform_pd *const pd, bool const main_thread,
Weak_ptr<Address_space> address_space); Weak_ptr<Address_space> address_space);
/** /**
@ -140,7 +147,7 @@ namespace Genode {
/** /**
* Pause this thread * Pause this thread
*/ */
void pause() { Kernel::pause_thread(kernel_object()); } void pause() { Kernel::pause_thread(_kobj.kernel_object()); }
/** /**
* Enable/disable single stepping * Enable/disable single stepping
@ -150,13 +157,13 @@ namespace Genode {
/** /**
* Resume this thread * Resume this thread
*/ */
void resume() { Kernel::resume_thread(kernel_object()); } void resume() { Kernel::resume_thread(_kobj.kernel_object()); }
/** /**
* Cancel currently blocking operation * Cancel currently blocking operation
*/ */
void cancel_blocking() { void cancel_blocking() {
Kernel::cancel_thread_blocking(kernel_object()); } Kernel::cancel_thread_blocking(_kobj.kernel_object()); }
/** /**
* Set CPU quota of the thread to 'quota' * Set CPU quota of the thread to 'quota'
@ -205,11 +212,11 @@ namespace Genode {
** Accessors ** ** Accessors **
***************/ ***************/
char const * label() const { return _label; }; Label label() const { return _label; };
void pager(Pager_object * const pager); void pager(Pager_object &pager);
Pager_object * pager(); Pager_object &pager();
Platform_pd * pd() const { return _pd; } Platform_pd * pd() const { return _pd; }

View File

@ -3,9 +3,6 @@
* \author Martin Stein * \author Martin Stein
* \author Stefan Kalkowski * \author Stefan Kalkowski
* \date 2012-02-12 * \date 2012-02-12
*
* TODO: this file is almost identical to
* base-okl4/src/core/ram_dataspace_support.cc, we should merge them
*/ */
/* /*
@ -25,16 +22,16 @@
using namespace Genode; using namespace Genode;
void Ram_dataspace_factory::_export_ram_ds(Dataspace_component *) { } void Ram_dataspace_factory::_export_ram_ds(Dataspace_component &) { }
void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component *) { } void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component &) { }
void Ram_dataspace_factory::_clear_ds (Dataspace_component * ds) void Ram_dataspace_factory::_clear_ds (Dataspace_component &ds)
{ {
size_t page_rounded_size = (ds->size() + get_page_size() - 1) & get_page_mask(); size_t page_rounded_size = (ds.size() + get_page_size() - 1) & get_page_mask();
/* allocate range in core's virtual address space */ /* allocate range in core's virtual address space */
void *virt_addr; void *virt_addr;
if (!platform()->region_alloc()->alloc(page_rounded_size, &virt_addr)) { if (!platform().region_alloc().alloc(page_rounded_size, &virt_addr)) {
error("could not allocate virtual address range in core of size ", error("could not allocate virtual address range in core of size ",
page_rounded_size); page_rounded_size);
return; return;
@ -42,7 +39,7 @@ void Ram_dataspace_factory::_clear_ds (Dataspace_component * ds)
/* map the dataspace's physical pages to corresponding virtual addresses */ /* map the dataspace's physical pages to corresponding virtual addresses */
size_t num_pages = page_rounded_size >> get_page_size_log2(); size_t num_pages = page_rounded_size >> get_page_size_log2();
if (!map_local(ds->phys_addr(), (addr_t)virt_addr, num_pages)) { if (!map_local(ds.phys_addr(), (addr_t)virt_addr, num_pages)) {
error("core-local memory mapping failed"); error("core-local memory mapping failed");
return; return;
} }
@ -51,7 +48,7 @@ void Ram_dataspace_factory::_clear_ds (Dataspace_component * ds)
memset(virt_addr, 0, page_rounded_size); memset(virt_addr, 0, page_rounded_size);
/* uncached dataspaces need to be flushed from the data cache */ /* uncached dataspaces need to be flushed from the data cache */
if (ds->cacheability() != CACHED) if (ds.cacheability() != CACHED)
Kernel::update_data_region((addr_t)virt_addr, page_rounded_size); Kernel::update_data_region((addr_t)virt_addr, page_rounded_size);
/* invalidate the dataspace memory from instruction cache */ /* invalidate the dataspace memory from instruction cache */
@ -62,6 +59,6 @@ void Ram_dataspace_factory::_clear_ds (Dataspace_component * ds)
error("could not unmap core-local address range at ", virt_addr); error("could not unmap core-local address range at ", virt_addr);
/* free core's virtual address space */ /* free core's virtual address space */
platform()->region_alloc()->free(virt_addr, page_rounded_size); platform().region_alloc().free(virt_addr, page_rounded_size);
} }

View File

@ -50,7 +50,7 @@ void Pager_entrypoint::entry()
continue; continue;
} }
_fault = pt->kernel_object()->fault(); _fault = pt->fault_info();
/* try to resolve fault directly via local region managers */ /* try to resolve fault directly via local region managers */
if (po->pager(*this)) continue; if (po->pager(*this)) continue;

View File

@ -54,7 +54,7 @@ void Thread::exception(Cpu & cpu)
void Kernel::Thread::_call_update_data_region() void Kernel::Thread::_call_update_data_region()
{ {
Cpu & cpu = cpu_pool()->cpu(Cpu::executing_id()); Cpu &cpu = cpu_pool().cpu(Cpu::executing_id());
/* /*
* FIXME: If the caller is not a core thread, the kernel operates in a * FIXME: If the caller is not a core thread, the kernel operates in a
@ -78,7 +78,7 @@ void Kernel::Thread::_call_update_data_region()
void Kernel::Thread::_call_update_instr_region() void Kernel::Thread::_call_update_instr_region()
{ {
Cpu & cpu = cpu_pool()->cpu(Cpu::executing_id()); Cpu &cpu = cpu_pool().cpu(Cpu::executing_id());
/* /*
* FIXME: If the caller is not a core thread, the kernel operates in a * FIXME: If the caller is not a core thread, the kernel operates in a
@ -112,7 +112,7 @@ void Kernel::Thread::Pd_update::execute() { };
void Thread::proceed(Cpu & cpu) void Thread::proceed(Cpu & cpu)
{ {
cpu.switch_to(*regs, pd()->mmu_regs); cpu.switch_to(*regs, pd().mmu_regs);
regs->cpu_exception = cpu.stack_start(); regs->cpu_exception = cpu.stack_start();
kernel_to_user_context_switch((static_cast<Cpu::Context*>(&*regs)), kernel_to_user_context_switch((static_cast<Cpu::Context*>(&*regs)),

View File

@ -22,10 +22,13 @@ using namespace Kernel;
Kernel::Vm::Vm(void * const state, Kernel::Vm::Vm(void * const state,
Kernel::Signal_context * const context, Kernel::Signal_context * const context,
void * const /* table */) void * const /* table */)
: Cpu_job(Cpu_priority::MIN, 0), :
_state((Genode::Vm_state * const)state), Cpu_job(Cpu_priority::MIN, 0),
_context(context), _table(0) { _state((Genode::Vm_state * const)state),
affinity(&cpu_pool()->primary_cpu()); } _context(context), _table(0)
{
affinity(cpu_pool().primary_cpu());
}
Kernel::Vm::~Vm() {} Kernel::Vm::~Vm() {}
@ -58,10 +61,10 @@ void Vm::proceed(Cpu & cpu)
{ {
unsigned const irq = _state->irq_injection; unsigned const irq = _state->irq_injection;
if (irq) { if (irq) {
if (pic()->secure(irq)) { if (pic().secure(irq)) {
Genode::warning("Refuse to inject secure IRQ into VM"); Genode::warning("Refuse to inject secure IRQ into VM");
} else { } else {
pic()->trigger(irq); pic().trigger(irq);
_state->irq_injection = 0; _state->irq_injection = 0;
} }
} }

View File

@ -34,7 +34,7 @@ Vm_session_component::Vm_session_component(Rpc_entrypoint *ds_ep,
: _ds_ep(ds_ep), _ds(_ds_size(), _alloc_ds(ram_quota), UNCACHED, true, 0), : _ds_ep(ds_ep), _ds(_ds_size(), _alloc_ds(ram_quota), UNCACHED, true, 0),
_ds_cap(static_cap_cast<Dataspace>(_ds_ep->manage(&_ds))) _ds_cap(static_cap_cast<Dataspace>(_ds_ep->manage(&_ds)))
{ {
_ds.assign_core_local_addr(core_env()->rm_session()->attach(_ds_cap)); _ds.assign_core_local_addr(core_env().rm_session()->attach(_ds_cap));
} }
@ -44,6 +44,6 @@ Vm_session_component::~Vm_session_component()
_ds_ep->dissolve(&_ds); _ds_ep->dissolve(&_ds);
/* free region in allocator */ /* free region in allocator */
core_env()->rm_session()->detach(_ds.core_local_addr()); core_env().rm_session()->detach(_ds.core_local_addr());
platform()->ram_alloc()->free((void*)_ds.phys_addr()); platform().ram_alloc().free((void*)_ds.phys_addr());
} }

View File

@ -58,6 +58,8 @@ class Genode::Vm_session_component : public Genode::Rpc_object<Genode::Vm_sessi
size_t ram_quota); size_t ram_quota);
~Vm_session_component(); ~Vm_session_component();
using Rpc_object<Vm_session>::cap;
/************************** /**************************
** Vm session interface ** ** Vm session interface **

View File

@ -58,7 +58,7 @@ struct Kernel::Vm_irq : Kernel::Irq
{ {
Vm_irq(unsigned const irq) Vm_irq(unsigned const irq)
: :
Kernel::Irq(irq, cpu_pool()->executing_cpu().irq_pool()) Kernel::Irq(irq, cpu_pool().executing_cpu().irq_pool())
{ } { }
/** /**
@ -66,7 +66,7 @@ struct Kernel::Vm_irq : Kernel::Irq
*/ */
void occurred() void occurred()
{ {
Cpu_job & job = cpu_pool()->executing_cpu().scheduled_job(); Cpu_job & job = cpu_pool().executing_cpu().scheduled_job();
Vm *vm = dynamic_cast<Vm*>(&job); Vm *vm = dynamic_cast<Vm*>(&job);
if (!vm) if (!vm)
Genode::error("VM timer interrupt while VM is not runnning!"); Genode::error("VM timer interrupt while VM is not runnning!");
@ -213,7 +213,7 @@ Kernel::Vm::Vm(void * const state,
_context(context), _context(context),
_table(table) _table(table)
{ {
affinity(&cpu_pool()->primary_cpu()); affinity(cpu_pool().primary_cpu());
Virtual_pic::pic().irq.enable(); Virtual_pic::pic().irq.enable();
vt_host_context.sp = _cpu->stack_start(); vt_host_context.sp = _cpu->stack_start();

View File

@ -22,14 +22,14 @@
using namespace Genode; using namespace Genode;
static Core_mem_allocator * cma() { static Core_mem_allocator & cma() {
return static_cast<Core_mem_allocator*>(platform()->core_mem_alloc()); } return static_cast<Core_mem_allocator&>(platform().core_mem_alloc()); }
void Vm_session_component::exception_handler(Signal_context_capability handler) void Vm_session_component::exception_handler(Signal_context_capability handler)
{ {
if (!create((void*)_ds.core_local_addr(), Capability_space::capid(handler), if (!create((void*)_ds.core_local_addr(), Capability_space::capid(handler),
cma()->phys_addr(&_table))) cma().phys_addr(&_table)))
Genode::warning("Cannot instantiate vm kernel object, invalid signal context?"); Genode::warning("Cannot instantiate vm kernel object, invalid signal context?");
} }
@ -84,8 +84,8 @@ void * Vm_session_component::_alloc_table()
{ {
void * table; void * table;
/* get some aligned space for the translation table */ /* get some aligned space for the translation table */
if (!cma()->alloc_aligned(sizeof(Table), (void**)&table, if (!cma().alloc_aligned(sizeof(Table), (void**)&table,
Table::ALIGNM_LOG2).ok()) { Table::ALIGNM_LOG2).ok()) {
error("failed to allocate kernel object"); error("failed to allocate kernel object");
throw Insufficient_ram_quota(); throw Insufficient_ram_quota();
} }
@ -99,9 +99,9 @@ Vm_session_component::Vm_session_component(Rpc_entrypoint *ds_ep,
_ds_cap(static_cap_cast<Dataspace>(_ds_ep->manage(&_ds))), _ds_cap(static_cap_cast<Dataspace>(_ds_ep->manage(&_ds))),
_table(*construct_at<Table>(_alloc_table())), _table(*construct_at<Table>(_alloc_table())),
_table_array(*(new (cma()) Array([this] (void * virt) { _table_array(*(new (cma()) Array([this] (void * virt) {
return (addr_t)cma()->phys_addr(virt);}))) return (addr_t)cma().phys_addr(virt);})))
{ {
_ds.assign_core_local_addr(core_env()->rm_session()->attach(_ds_cap)); _ds.assign_core_local_addr(core_env().rm_session()->attach(_ds_cap));
} }
@ -111,10 +111,10 @@ Vm_session_component::~Vm_session_component()
_ds_ep->dissolve(&_ds); _ds_ep->dissolve(&_ds);
/* free region in allocator */ /* free region in allocator */
core_env()->rm_session()->detach(_ds.core_local_addr()); core_env().rm_session()->detach(_ds.core_local_addr());
platform()->ram_alloc()->free((void*)_ds.phys_addr()); platform().ram_alloc().free((void*)_ds.phys_addr());
/* free guest-to-host page tables */ /* free guest-to-host page tables */
destroy(platform()->core_mem_alloc(), &_table); destroy(platform().core_mem_alloc(), &_table);
destroy(platform()->core_mem_alloc(), &_table_array); destroy(platform().core_mem_alloc(), &_table_array);
} }

View File

@ -67,6 +67,8 @@ class Genode::Vm_session_component : public Genode::Rpc_object<Genode::Vm_sessio
size_t ram_quota); size_t ram_quota);
~Vm_session_component(); ~Vm_session_component();
using Rpc_object<Vm_session>::cap;
/************************** /**************************
** Vm session interface ** ** Vm session interface **

View File

@ -22,8 +22,8 @@ addr_t Vm_session_component::_alloc_ds(size_t &ram_quota)
{ {
addr_t addr; addr_t addr;
if (_ds_size() > ram_quota || if (_ds_size() > ram_quota ||
platform()->ram_alloc()->alloc_aligned(_ds_size(), (void**)&addr, platform().ram_alloc().alloc_aligned(_ds_size(), (void**)&addr,
get_page_size_log2()).error()) get_page_size_log2()).error())
throw Insufficient_ram_quota(); throw Insufficient_ram_quota();
ram_quota -= _ds_size(); ram_quota -= _ds_size();
return addr; return addr;

View File

@ -28,9 +28,9 @@ extern Genode::addr_t hypervisor_exception_vector;
/* /*
* Add ARM virtualization specific vm service * Add ARM virtualization specific vm service
*/ */
void Genode::platform_add_local_services(Rpc_entrypoint *ep, void Genode::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap *sh, Sliced_heap &sh,
Registry<Service> *services) Registry<Service> &services)
{ {
using namespace Genode; using namespace Genode;
@ -39,5 +39,5 @@ void Genode::platform_add_local_services(Rpc_entrypoint *ep,
Hw::PAGE_FLAGS_KERN_TEXT); Hw::PAGE_FLAGS_KERN_TEXT);
static Vm_root vm_root(ep, sh); static Vm_root vm_root(ep, sh);
static Core_service<Vm_session_component> vm_service(*services, vm_root); static Core_service<Vm_session_component> vm_service(services, vm_root);
} }

View File

@ -27,14 +27,14 @@ extern int monitor_mode_exception_vector;
/* /*
* Add TrustZone specific vm service * Add TrustZone specific vm service
*/ */
void Genode::platform_add_local_services(Rpc_entrypoint *ep, void Genode::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap *sliced_heap, Sliced_heap &sliced_heap,
Registry<Service> *local_services) Registry<Service> &local_services)
{ {
static addr_t const phys_base = static addr_t const phys_base =
Platform::core_phys_addr((addr_t)&monitor_mode_exception_vector); Platform::core_phys_addr((addr_t)&monitor_mode_exception_vector);
map_local(phys_base, Hw::Mm::system_exception_vector().base, 1, map_local(phys_base, Hw::Mm::system_exception_vector().base, 1,
Hw::PAGE_FLAGS_KERN_TEXT); Hw::PAGE_FLAGS_KERN_TEXT);
static Vm_root vm_root(ep, sliced_heap); static Vm_root vm_root(ep, sliced_heap);
static Core_service<Vm_session_component> vm_service(*local_services, vm_root); static Core_service<Vm_session_component> vm_service(local_services, vm_root);
} }

View File

@ -25,7 +25,7 @@ void Kernel::Thread::Pd_update::execute()
/* if this is the last cpu, wake up the caller thread */ /* if this is the last cpu, wake up the caller thread */
if (--cnt == 0) { if (--cnt == 0) {
cpu_pool()->work_list().remove(&_le); cpu_pool().work_list().remove(&_le);
caller._restart(); caller._restart();
} }
}; };
@ -39,7 +39,7 @@ void Kernel::Thread::_call_update_instr_region() { }
void Kernel::Thread::proceed(Cpu & cpu) void Kernel::Thread::proceed(Cpu & cpu)
{ {
cpu.switch_to(*regs, pd()->mmu_regs); cpu.switch_to(*regs, pd().mmu_regs);
asm volatile("mov %0, %%rsp \n" asm volatile("mov %0, %%rsp \n"
"popq %%r8 \n" "popq %%r8 \n"

View File

@ -40,7 +40,7 @@ void Thread::exception(Cpu & cpu)
} }
if (regs->trapno >= Cpu::Context::INTERRUPTS_START && if (regs->trapno >= Cpu::Context::INTERRUPTS_START &&
regs->trapno <= Cpu::Context::INTERRUPTS_END) { regs->trapno <= Cpu::Context::INTERRUPTS_END) {
pic()->irq_occurred(regs->trapno); pic().irq_occurred(regs->trapno);
_interrupt(cpu.id()); _interrupt(cpu.id());
return; return;
} }

View File

@ -27,7 +27,7 @@ Kernel::Vm::Vm(void * const state, Kernel::Signal_context * const context,
_context(context), _context(context),
_table(nullptr) _table(nullptr)
{ {
affinity(&cpu_pool()->primary_cpu()); affinity(cpu_pool().primary_cpu());
} }
@ -44,7 +44,7 @@ void Kernel::Vm::exception(Cpu & cpu)
if (_state->trapno >= Genode::Cpu_state::INTERRUPTS_START && if (_state->trapno >= Genode::Cpu_state::INTERRUPTS_START &&
_state->trapno <= Genode::Cpu_state::INTERRUPTS_END) { _state->trapno <= Genode::Cpu_state::INTERRUPTS_END) {
pic()->irq_occurred(_state->trapno); pic().irq_occurred(_state->trapno);
_interrupt(cpu.id()); _interrupt(cpu.id());
_context->submit(1); _context->submit(1);
return; return;

View File

@ -24,15 +24,15 @@
/* /*
* Add I/O port service and virtualization specific vm service * Add I/O port service and virtualization specific vm service
*/ */
void Genode::platform_add_local_services(Rpc_entrypoint *ep, void Genode::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap *sh, Sliced_heap &sliced_heap,
Registry<Service> *services) Registry<Service> &services)
{ {
static Vm_root vm_root(ep, sh); static Vm_root vm_root(ep, sliced_heap);
static Core_service<Vm_session_component> vm_ls(*services, vm_root); static Core_service<Vm_session_component> vm_ls(services, vm_root);
static Io_port_root io_port_root(core_env()->pd_session(), static Io_port_root io_port_root(*core_env().pd_session(),
platform()->io_port_alloc(), sh); platform().io_port_alloc(), sliced_heap);
static Core_service<Io_port_session_component> io_port_ls(*services, static Core_service<Io_port_session_component> io_port_ls(services,
io_port_root); io_port_root);
} }

View File

@ -42,6 +42,8 @@ class Genode::Vm_session_component
Vm_session_component(Rpc_entrypoint*, size_t) : _state() { } Vm_session_component(Rpc_entrypoint*, size_t) : _state() { }
~Vm_session_component() { } ~Vm_session_component() { }
using Genode::Rpc_object<Genode::Vm_session>::cap;
/************************** /**************************
** Vm session interface ** ** Vm session interface **

View File

@ -31,14 +31,14 @@ void Platform::_init_additional()
void *virt_ptr = nullptr; void *virt_ptr = nullptr;
const char *rom_name = "platform_info"; const char *rom_name = "platform_info";
if (!ram_alloc()->alloc(get_page_size(), &phys_ptr)) { if (!ram_alloc().alloc(get_page_size(), &phys_ptr)) {
error("could not setup platform_info ROM - ram allocation error"); error("could not setup platform_info ROM - ram allocation error");
return; return;
} }
if (!region_alloc()->alloc(rom_size, &virt_ptr)) { if (!region_alloc().alloc(rom_size, &virt_ptr)) {
error("could not setup platform_info ROM - region allocation error"); error("could not setup platform_info ROM - region allocation error");
ram_alloc()->free(phys_ptr); ram_alloc().free(phys_ptr);
return; return;
} }
@ -47,8 +47,8 @@ void Platform::_init_additional()
if (!map_local(phys_addr, virt_addr, pages, Hw::PAGE_FLAGS_KERN_DATA)) { if (!map_local(phys_addr, virt_addr, pages, Hw::PAGE_FLAGS_KERN_DATA)) {
error("could not setup platform_info ROM - map error"); error("could not setup platform_info ROM - map error");
region_alloc()->free(virt_ptr); region_alloc().free(virt_ptr);
ram_alloc()->free(phys_ptr); ram_alloc().free(phys_ptr);
return; return;
} }
@ -93,7 +93,7 @@ void Platform::_init_additional()
return; return;
} }
region_alloc()->free(virt_ptr); region_alloc().free(virt_ptr);
_rom_fs.insert( _rom_fs.insert(
new (core_mem_alloc()) Rom_module(phys_addr, rom_size, rom_name)); new (core_mem_alloc()) Rom_module(phys_addr, rom_size, rom_name));
@ -102,7 +102,7 @@ void Platform::_init_additional()
void Platform::setup_irq_mode(unsigned irq_number, unsigned trigger, void Platform::setup_irq_mode(unsigned irq_number, unsigned trigger,
unsigned polarity) { unsigned polarity) {
Kernel::pic()->ioapic.setup_irq_mode(irq_number, trigger, polarity); } Kernel::pic().ioapic.setup_irq_mode(irq_number, trigger, polarity); }
bool Platform::get_msi_params(addr_t, addr_t &, addr_t &, unsigned &) { bool Platform::get_msi_params(addr_t, addr_t &, addr_t &, unsigned &) {

View File

@ -51,15 +51,15 @@ void Thread::cancel_blocking()
void Thread::_deinit_platform_thread() void Thread::_deinit_platform_thread()
{ {
/* destruct platform thread */ /* destruct platform thread */
destroy(platform()->core_mem_alloc(), native_thread().platform_thread); destroy(platform().core_mem_alloc(), native_thread().platform_thread);
} }
void Thread::_init_platform_thread(size_t, Type type) void Thread::_init_platform_thread(size_t, Type type)
{ {
if (type == NORMAL) { if (type == NORMAL) {
native_thread().platform_thread = new (platform()->core_mem_alloc()) native_thread().platform_thread = new (platform().core_mem_alloc())
Platform_thread(_stack->name().string(), &_stack->utcb()); Platform_thread(_stack->name(), _stack->utcb());
return; return;
} }

View File

@ -38,15 +38,15 @@ namespace Genode {
{ {
private: private:
Filename _fname { }; /* filename for mmap */ Filename _fname { }; /* filename for mmap */
size_t _size { 0 }; /* size of dataspace in bytes */ size_t const _size; /* size of dataspace in bytes */
addr_t _addr { 0 }; /* meaningless on linux */ addr_t const _addr; /* meaningless on linux */
int _fd { -1 }; /* file descriptor */ int _fd { -1 }; /* file descriptor */
bool _writable { false }; /* false if read-only */ bool const _writable; /* false if read-only */
/* Holds the dataspace owner if a distinction between owner and /* Holds the dataspace owner if a distinction between owner and
* others is necessary on the dataspace, otherwise it is 0 */ * others is necessary on the dataspace, otherwise it is 0 */
Dataspace_owner * _owner; Dataspace_owner const * const _owner;
static Filename _file_name(const char *args); static Filename _file_name(const char *args);
size_t _file_size(); size_t _file_size();
@ -72,7 +72,7 @@ namespace Genode {
* Default constructor returns invalid dataspace * Default constructor returns invalid dataspace
*/ */
Dataspace_component() Dataspace_component()
: _size(0), _addr(0), _fd(-1), _writable(false), _owner(0) { } : _size(0), _addr(0), _fd(-1), _writable(false), _owner(nullptr) { }
/** /**
* This constructor is only provided for compatibility * This constructor is only provided for compatibility
@ -81,7 +81,8 @@ namespace Genode {
Dataspace_component(size_t size, addr_t, addr_t phys_addr, Dataspace_component(size_t size, addr_t, addr_t phys_addr,
Cache_attribute, bool, Dataspace_owner *_owner) Cache_attribute, bool, Dataspace_owner *_owner)
: :
_size(size), _addr(phys_addr), _fd(-1), _owner(_owner) _size(size), _addr(phys_addr), _fd(-1), _writable(false),
_owner(_owner)
{ {
warning("Should only be used for IOMEM and not within Linux."); warning("Should only be used for IOMEM and not within Linux.");
_fname.buf[0] = 0; _fname.buf[0] = 0;
@ -105,20 +106,21 @@ namespace Genode {
/** /**
* Check if dataspace is owned by a specified object * Check if dataspace is owned by a specified object
*/ */
bool owner(Dataspace_owner const *o) const { return _owner == o; } bool owner(Dataspace_owner const &o) const { return _owner == &o; }
/** /**
* Detach dataspace from all rm sessions. * Detach dataspace from all rm sessions.
*/ */
void detach_from_rm_sessions() { } void detach_from_rm_sessions() { }
/************************* /*************************
** Dataspace interface ** ** Dataspace interface **
*************************/ *************************/
size_t size() { return _size; } size_t size() override { return _size; }
addr_t phys_addr() { return _addr; } addr_t phys_addr() override { return _addr; }
bool writable() { return _writable; } bool writable() override { return _writable; }
/**************************************** /****************************************

View File

@ -40,9 +40,9 @@ namespace Genode {
* particular MMIO region base, size and * particular MMIO region base, size and
* caching demands * caching demands
*/ */
Io_mem_session_component(Range_allocator *io_mem_alloc, Io_mem_session_component(Range_allocator &io_mem_alloc,
Range_allocator *ram_alloc, Range_allocator &ram_alloc,
Rpc_entrypoint *ds_ep, Rpc_entrypoint &ds_ep,
const char *args); const char *args);
/** /**

View File

@ -34,7 +34,7 @@ class Genode::Irq_session_component : public Rpc_object<Irq_session>,
/** /**
* Constructor * Constructor
*/ */
Irq_session_component(Range_allocator *, const char *) { } Irq_session_component(Range_allocator &, const char *) { }
/** /**
* Destructor * Destructor
@ -49,8 +49,9 @@ class Genode::Irq_session_component : public Rpc_object<Irq_session>,
void ack_irq() override { } void ack_irq() override { }
void sigh(Signal_context_capability) override { } void sigh(Signal_context_capability) override { }
Info info() override { Info info() override {
return { .type = Genode::Irq_session::Info::Type::INVALID, return { .type = Genode::Irq_session::Info::Type::INVALID,
.address = 0, .value = 0 }; } .address = 0,
.value = 0 }; }
}; };
#endif /* _CORE__INCLUDE__IRQ_SESSION_COMPONENT_H_ */ #endif /* _CORE__INCLUDE__IRQ_SESSION_COMPONENT_H_ */

View File

@ -52,9 +52,9 @@ namespace Genode {
auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) { auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) {
return f(nullptr); } return f(nullptr); }
Pager_capability manage(Pager_object *) { return Pager_capability(); } Pager_capability manage(Pager_object &) { return Pager_capability(); }
void dissolve(Pager_object *) { } void dissolve(Pager_object &) { }
}; };
} }

View File

@ -22,6 +22,7 @@
#include <platform_pd.h> #include <platform_pd.h>
#include <platform_thread.h> #include <platform_thread.h>
#include <synced_range_allocator.h> #include <synced_range_allocator.h>
#include <assertion.h>
namespace Genode { namespace Genode {
@ -36,6 +37,29 @@ namespace Genode {
*/ */
Synced_range_allocator<Allocator_avl> _core_mem_alloc; Synced_range_allocator<Allocator_avl> _core_mem_alloc;
Rom_fs _dummy_rom_fs { };
struct Dummy_allocator : Range_allocator
{
void free(void *, size_t) override { ASSERT_NEVER_CALLED; }
bool need_size_for_free() const override { ASSERT_NEVER_CALLED; }
size_t consumed() const override { ASSERT_NEVER_CALLED; }
size_t overhead(size_t) const override { ASSERT_NEVER_CALLED; }
int add_range (addr_t, size_t ) override { ASSERT_NEVER_CALLED; }
int remove_range(addr_t, size_t ) override { ASSERT_NEVER_CALLED; }
void free(void *) override { ASSERT_NEVER_CALLED; }
size_t avail() const override { ASSERT_NEVER_CALLED; }
bool valid_addr(addr_t ) const override { ASSERT_NEVER_CALLED; }
bool alloc(size_t, void **) override { ASSERT_NEVER_CALLED; }
Alloc_return alloc_aligned(size_t, void **, int, addr_t, addr_t) override
{ ASSERT_NEVER_CALLED; }
Alloc_return alloc_addr(size_t, addr_t) override
{ ASSERT_NEVER_CALLED; }
} _dummy_alloc { };
/** /**
* Allocator for pseudo physical memory * Allocator for pseudo physical memory
*/ */
@ -61,15 +85,14 @@ namespace Genode {
int add_range(addr_t, size_t) override { return 0; } int add_range(addr_t, size_t) override { return 0; }
int remove_range(addr_t, size_t) override { return 0; } int remove_range(addr_t, size_t) override { return 0; }
void free(void *) override { } void free(void *) override { }
void free(void *, size_t) override { } void free(void *, size_t) override { }
size_t avail() const override { return ~0; } size_t avail() const override { return ~0; }
bool valid_addr(addr_t) const override { return true; } bool valid_addr(addr_t) const override { return true; }
size_t overhead(size_t) const override { return 0; } size_t overhead(size_t) const override { return 0; }
bool need_size_for_free() const override { return true; } bool need_size_for_free() const override { return true; }
};
Pseudo_ram_allocator _ram_alloc { }; } _ram_alloc { };
public: public:
@ -83,15 +106,15 @@ namespace Genode {
** Generic platform interface ** ** Generic platform interface **
********************************/ ********************************/
Range_allocator *core_mem_alloc() override { return &_core_mem_alloc; } Range_allocator &core_mem_alloc() override { return _core_mem_alloc; }
Range_allocator *ram_alloc() override { return &_ram_alloc; } Range_allocator &ram_alloc() override { return _ram_alloc; }
Range_allocator *io_mem_alloc() override { return 0; } Range_allocator &io_mem_alloc() override { return _dummy_alloc; }
Range_allocator *io_port_alloc() override { return 0; } Range_allocator &io_port_alloc() override { return _dummy_alloc; }
Range_allocator *irq_alloc() override { return 0; } Range_allocator &irq_alloc() override { return _dummy_alloc; }
Range_allocator *region_alloc() override { return 0; } Range_allocator &region_alloc() override { return _dummy_alloc; }
addr_t vm_start() const override { return 0; } addr_t vm_start() const override { return 0; }
size_t vm_size() const override { return 0; } size_t vm_size() const override { return 0; }
Rom_fs *rom_fs() override { return 0; } Rom_fs &rom_fs() override { return _dummy_rom_fs; }
/* /*
* On Linux, the maximum number of capabilities is primarily * On Linux, the maximum number of capabilities is primarily

View File

@ -26,9 +26,9 @@ namespace Genode {
struct Genode::Platform_pd struct Genode::Platform_pd
{ {
Platform_pd(Allocator *, char const *) { } Platform_pd(Allocator &, char const *) { }
bool bind_thread(Platform_thread *) { return true; } bool bind_thread(Platform_thread &) { return true; }
void assign_parent(Capability<Parent>) { } void assign_parent(Capability<Parent>) { }
}; };

View File

@ -60,7 +60,7 @@ namespace Genode {
/** /**
* Return singleton instance of 'Platform_thread::Registry' * Return singleton instance of 'Platform_thread::Registry'
*/ */
static Registry *_registry(); static Registry &_registry();
unsigned long _tid = -1; unsigned long _tid = -1;
unsigned long _pid = -1; unsigned long _pid = -1;
@ -110,8 +110,8 @@ namespace Genode {
/** /**
* Dummy implementation of platform-thread interface * Dummy implementation of platform-thread interface
*/ */
Pager_object *pager() { return &_pager; } Pager_object &pager() { return _pager; }
void pager(Pager_object *) { } void pager(Pager_object &) { }
int start(void *, void *) { return 0; } int start(void *, void *) { return 0; }
Thread_state state() Thread_state state()
@ -164,7 +164,7 @@ namespace Genode {
*/ */
static void submit_exception(int pid) static void submit_exception(int pid)
{ {
_registry()->submit_exception(pid); _registry().submit_exception(pid);
} }
/** /**

View File

@ -65,22 +65,16 @@ class Genode::Region_map_component : public Rpc_object<Region_map>,
Dataspace_capability dataspace() { return Dataspace_capability(); } Dataspace_capability dataspace() { return Dataspace_capability(); }
Rm_dataspace_component *dataspace_component() { return 0; } Rm_dataspace_component *dataspace_component() { return nullptr; }
void address_space(Platform_pd *) { } void address_space(Platform_pd *) { }
}; };
struct Genode::Rm_member : Interface struct Genode::Rm_client : Pager_object
{ {
Region_map_component *member_rm() { return 0; } Rm_client(Cpu_session_capability, Thread_capability,
}; Region_map_component &, unsigned long,
struct Genode::Rm_client : Pager_object, Rm_member
{
Rm_client(Cpu_session_capability, Thread_capability,
Region_map_component *, unsigned long,
Affinity::Location, Cpu_session::Name const&, Affinity::Location, Cpu_session::Name const&,
Session_label const&) Session_label const&)
{ } { }

View File

@ -24,7 +24,7 @@ class Genode::Rpc_cap_factory
{ {
private: private:
static Native_capability _alloc(Rpc_cap_factory *owner, static Native_capability _alloc(Rpc_cap_factory &owner,
Native_capability ep); Native_capability ep);
public: public:

Some files were not shown because too many files have changed in this diff Show More