2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Core-specific environment
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2006-07-28
|
|
|
|
*
|
|
|
|
* The Core-specific environment ensures that all sessions of Core's
|
|
|
|
* environment a local (_component) not remote (_client).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__CORE_ENV_H_
|
|
|
|
#define _CORE__INCLUDE__CORE_ENV_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/env.h>
|
|
|
|
#include <base/heap.h>
|
|
|
|
#include <ram_session/client.h>
|
2016-01-14 13:22:00 +01:00
|
|
|
#include <pd_session/client.h>
|
2014-01-28 14:30:36 +01:00
|
|
|
#include <rm_session/capability.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* core includes */
|
2012-05-28 16:57:09 +02:00
|
|
|
#include <platform.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <core_parent.h>
|
|
|
|
#include <core_rm_session.h>
|
2016-01-14 13:22:00 +01:00
|
|
|
#include <core_pd_session.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <cap_session_component.h>
|
|
|
|
#include <ram_session_component.h>
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock-guarded version of a RAM-session implementation
|
|
|
|
*
|
|
|
|
* \param RAM_SESSION_IMPL non-thread-safe RAM-session class
|
|
|
|
*
|
|
|
|
* In contrast to normal processes, core's 'env()->ram_session()' is not
|
|
|
|
* synchronized by an RPC interface. However, it is accessed by different
|
|
|
|
* threads using the 'env()->heap()' and the sliced heap used for
|
|
|
|
* allocating sessions to core's services.
|
|
|
|
*/
|
|
|
|
template <typename RAM_SESSION_IMPL>
|
|
|
|
class Synchronized_ram_session : public RAM_SESSION_IMPL
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Lock _lock;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Synchronized_ram_session(Rpc_entrypoint *ds_ep,
|
|
|
|
Rpc_entrypoint *ram_session_ep,
|
|
|
|
Range_allocator *ram_alloc,
|
|
|
|
Allocator *md_alloc,
|
|
|
|
const char *args,
|
|
|
|
size_t quota_limit = 0)
|
|
|
|
:
|
|
|
|
RAM_SESSION_IMPL(ds_ep, ram_session_ep, ram_alloc, md_alloc, args, quota_limit)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
** RAM-session interface **
|
|
|
|
***************************/
|
|
|
|
|
2014-06-19 16:37:31 +02:00
|
|
|
Ram_dataspace_capability alloc(size_t size, Cache_attribute cached)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
Lock::Guard lock_guard(_lock);
|
2012-06-18 15:20:31 +02:00
|
|
|
return RAM_SESSION_IMPL::alloc(size, cached);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void free(Ram_dataspace_capability ds)
|
|
|
|
{
|
|
|
|
RAM_SESSION_IMPL::free(ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ref_account(Ram_session_capability session)
|
|
|
|
{
|
|
|
|
Lock::Guard lock_guard(_lock);
|
|
|
|
return RAM_SESSION_IMPL::ref_account(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
int transfer_quota(Ram_session_capability session, size_t size)
|
|
|
|
{
|
|
|
|
Lock::Guard lock_guard(_lock);
|
|
|
|
return RAM_SESSION_IMPL::transfer_quota(session, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t quota()
|
|
|
|
{
|
|
|
|
Lock::Guard lock_guard(_lock);
|
|
|
|
return RAM_SESSION_IMPL::quota();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t used()
|
|
|
|
{
|
|
|
|
Lock::Guard lock_guard(_lock);
|
|
|
|
return RAM_SESSION_IMPL::used();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Core_env : public Env
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
typedef Synchronized_ram_session<Ram_session_component> Core_ram_session;
|
|
|
|
|
2016-01-14 13:22:00 +01:00
|
|
|
Core_parent _core_parent;
|
|
|
|
Cap_session_component _cap_session;
|
|
|
|
|
2012-11-14 16:34:45 +01:00
|
|
|
enum { ENTRYPOINT_STACK_SIZE = 2048 * sizeof(Genode::addr_t) };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
Rpc_entrypoint _entrypoint;
|
|
|
|
Core_rm_session _rm_session;
|
|
|
|
Core_ram_session _ram_session;
|
|
|
|
Ram_session_capability const _ram_session_cap;
|
|
|
|
|
2016-01-14 13:22:00 +01:00
|
|
|
/*
|
|
|
|
* The core-local PD session is provided by a real RPC object
|
|
|
|
* dispatched by the same entrypoint as the signal-source RPC
|
|
|
|
* objects. This is needed to allow the 'Pd_session::submit'
|
|
|
|
* method to issue out-of-order replies to
|
|
|
|
* 'Signal_source::wait_for_signal' calls.
|
|
|
|
*/
|
|
|
|
Core_pd_session_component _pd_session_component;
|
|
|
|
Pd_session_client _pd_session_client;
|
|
|
|
|
|
|
|
Heap _heap;
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2016-01-14 13:22:00 +01:00
|
|
|
Core_env()
|
|
|
|
:
|
2012-11-28 12:13:11 +01:00
|
|
|
_cap_session(platform()->core_mem_alloc(), "ram_quota=4K"),
|
2011-12-22 16:19:25 +01:00
|
|
|
_entrypoint(&_cap_session, ENTRYPOINT_STACK_SIZE, "entrypoint"),
|
|
|
|
_rm_session(&_entrypoint),
|
|
|
|
_ram_session(&_entrypoint, &_entrypoint,
|
|
|
|
platform()->ram_alloc(), platform()->core_mem_alloc(),
|
|
|
|
"ram_quota=4M", platform()->ram_alloc()->avail()),
|
2016-01-14 13:22:00 +01:00
|
|
|
_ram_session_cap(_entrypoint.manage(&_ram_session)),
|
|
|
|
_pd_session_component(_entrypoint /* XXX use a different entrypoint */),
|
|
|
|
_pd_session_client(_entrypoint.manage(&_pd_session_component)),
|
|
|
|
_heap(&_ram_session, &_rm_session)
|
2011-12-22 16:19:25 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Core_env() { parent()->exit(0); }
|
|
|
|
|
|
|
|
Rpc_entrypoint *entrypoint() { return &_entrypoint; }
|
2016-01-14 13:22:00 +01:00
|
|
|
Cap_session *cap_session() { return &_cap_session; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*******************
|
|
|
|
** Env interface **
|
|
|
|
*******************/
|
|
|
|
|
2016-01-14 13:22:00 +01:00
|
|
|
Parent *parent() override { return &_core_parent; }
|
|
|
|
Ram_session *ram_session() override { return &_ram_session; }
|
|
|
|
Ram_session_capability ram_session_cap() override { return _ram_session_cap; }
|
|
|
|
Rm_session *rm_session() override { return &_rm_session; }
|
|
|
|
Pd_session *pd_session() override { return &_pd_session_client; }
|
|
|
|
Allocator *heap() override { return &_heap; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
Cpu_session *cpu_session()
|
|
|
|
{
|
2012-10-10 13:59:32 +02:00
|
|
|
PWRN("%s:%u not implemented", __FILE__, __LINE__);
|
2011-12-22 16:19:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-10 13:05:54 +02:00
|
|
|
Cpu_session_capability cpu_session_cap() {
|
2012-10-10 13:59:32 +02:00
|
|
|
PWRN("%s:%u not implemented", __FILE__, __LINE__);
|
2012-10-10 13:05:54 +02:00
|
|
|
return Cpu_session_capability();
|
|
|
|
}
|
|
|
|
|
2016-01-14 13:22:00 +01:00
|
|
|
Pd_session_capability pd_session_cap() override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2012-10-10 13:59:32 +02:00
|
|
|
PWRN("%s:%u not implemented", __FILE__, __LINE__);
|
2016-01-14 13:22:00 +01:00
|
|
|
return Pd_session_capability();
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2013-02-13 21:46:19 +01:00
|
|
|
|
2014-01-28 14:30:36 +01:00
|
|
|
void reinit(Capability<Parent>::Dst, long) { }
|
|
|
|
|
|
|
|
void reinit_main_thread(Rm_session_capability &) { }
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request pointer to static environment of Core
|
|
|
|
*/
|
|
|
|
extern Core_env *core_env();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__CORE_ENV_H_ */
|