mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
Move repositories to 'repos/' subdirectory
This patch changes the top-level directory layout as a preparatory step for improving the tools for managing 3rd-party source codes. The rationale is described in the issue referenced below. Issue #1082
This commit is contained in:
22
repos/base/include/root/capability.h
Normal file
22
repos/base/include/root/capability.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* \brief Root capability type
|
||||
* \author Norman Feske
|
||||
* \date 2008-08-16
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2008-2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__ROOT__CAPABILITY_H_
|
||||
#define _INCLUDE__ROOT__CAPABILITY_H_
|
||||
|
||||
#include <base/capability.h>
|
||||
#include <root/root.h>
|
||||
|
||||
namespace Genode { typedef Capability<Root> Root_capability; }
|
||||
|
||||
#endif /* _INCLUDE__ROOT__CAPABILITY_H_ */
|
||||
38
repos/base/include/root/client.h
Normal file
38
repos/base/include/root/client.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* \brief Root client interface
|
||||
* \author Norman Feske
|
||||
* \date 2006-05-11
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__ROOT__CLIENT_H_
|
||||
#define _INCLUDE__ROOT__CLIENT_H_
|
||||
|
||||
#include <root/capability.h>
|
||||
#include <base/rpc_client.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
struct Root_client : Rpc_client<Root>
|
||||
{
|
||||
explicit Root_client(Root_capability root)
|
||||
: Rpc_client<Root>(root) { }
|
||||
|
||||
Session_capability session(Session_args const &args, Affinity const &affinity) {
|
||||
return call<Rpc_session>(args, affinity); }
|
||||
|
||||
void upgrade(Session_capability session, Upgrade_args const &args) {
|
||||
call<Rpc_upgrade>(session, args); }
|
||||
|
||||
void close(Session_capability session) {
|
||||
call<Rpc_close>(session); }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__ROOT__CLIENT_H_ */
|
||||
264
repos/base/include/root/component.h
Normal file
264
repos/base/include/root/component.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* \brief Generic root component implementation
|
||||
* \author Norman Feske
|
||||
* \date 2006-05-22
|
||||
*
|
||||
* This class is there for your convenience. It performs the common actions
|
||||
* that must always be taken when creating a new session.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__ROOT__COMPONENT_H_
|
||||
#define _INCLUDE__ROOT__COMPONENT_H_
|
||||
|
||||
#include <root/root.h>
|
||||
#include <base/rpc_server.h>
|
||||
#include <base/heap.h>
|
||||
#include <ram_session/ram_session.h>
|
||||
#include <util/arg_string.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/**
|
||||
* Session creation policy for a single-client service
|
||||
*/
|
||||
class Single_client
|
||||
{
|
||||
private:
|
||||
|
||||
bool _used;
|
||||
|
||||
public:
|
||||
|
||||
Single_client() : _used(0) { }
|
||||
|
||||
void aquire(const char *)
|
||||
{
|
||||
if (_used)
|
||||
throw Root::Unavailable();
|
||||
|
||||
_used = true;
|
||||
}
|
||||
|
||||
void release() { _used = false; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Session-creation policy for a multi-client service
|
||||
*/
|
||||
struct Multiple_clients
|
||||
{
|
||||
void aquire(const char *) { }
|
||||
void release() { }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Template for implementing the root interface
|
||||
*
|
||||
* \param SESSION_TYPE session-component type to manage,
|
||||
* derived from 'Rpc_object'
|
||||
* \param POLICY session-creation policy
|
||||
*
|
||||
* The 'POLICY' template parameter allows for constraining the session
|
||||
* creation to only one instance at a time (using the 'Single_session'
|
||||
* policy) or multiple instances (using the 'Multiple_sessions' policy).
|
||||
*
|
||||
* The 'POLICY' class must provide the following two functions:
|
||||
*
|
||||
* :'aquire(const char *args)': is called with the session arguments
|
||||
* at creation time of each new session. It can therefore implement
|
||||
* a session-creation policy taking session arguments into account.
|
||||
* If the policy denies the creation of a new session, it throws
|
||||
* one of the exceptions defined in the 'Root' interface.
|
||||
*
|
||||
* :'release': is called at the destruction time of a session. It enables
|
||||
* the policy to keep track of and impose restrictions on the number
|
||||
* of existing sessions.
|
||||
*
|
||||
* The default policy 'Multiple_clients' imposes no restrictions on the
|
||||
* creation of new sessions.
|
||||
*/
|
||||
template <typename SESSION_TYPE, typename POLICY = Multiple_clients>
|
||||
class Root_component : public Rpc_object<Typed_root<SESSION_TYPE> >, private POLICY
|
||||
{
|
||||
private:
|
||||
|
||||
/*
|
||||
* Entry point that manages the session objects
|
||||
* created by this root interface
|
||||
*/
|
||||
Rpc_entrypoint *_ep;
|
||||
|
||||
/*
|
||||
* Allocator for allocating session objects.
|
||||
* This allocator must be used by the derived
|
||||
* class when calling the 'new' operator for
|
||||
* creating a new session.
|
||||
*/
|
||||
Allocator *_md_alloc;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Create new session (to be implemented by a derived class)
|
||||
*
|
||||
* Only a derived class knows the constructor arguments of
|
||||
* a specific session. Therefore, we cannot unify the call
|
||||
* of its 'new' operator and must implement the session
|
||||
* creation at a place, where the required knowledge exist.
|
||||
*
|
||||
* In the implementation of this function, the heap, provided
|
||||
* by 'Root_component' must be used for allocating the session
|
||||
* object.
|
||||
*
|
||||
* If the server implementation does not evaluate the session
|
||||
* affinity, it suffices to override the overload without the
|
||||
* affinity argument.
|
||||
*
|
||||
* \throw Allocator::Out_of_memory typically caused by the
|
||||
* meta-data allocator
|
||||
* \throw Root::Invalid_args typically caused by the
|
||||
* session-component constructor
|
||||
*/
|
||||
virtual SESSION_TYPE *_create_session(const char *args,
|
||||
Affinity const &)
|
||||
{
|
||||
return _create_session(args);
|
||||
}
|
||||
|
||||
virtual SESSION_TYPE *_create_session(const char *args)
|
||||
{
|
||||
throw Root::Invalid_args();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform session about a quota upgrade
|
||||
*
|
||||
* Once a session is created, its client can successively extend
|
||||
* its quota donation via the 'Parent::transfer_quota' function.
|
||||
* This will result in the invokation of 'Root::upgrade' at the
|
||||
* root interface the session was created with. The root interface,
|
||||
* in turn, informs the session about the new resources via the
|
||||
* '_upgrade_session' function. The default implementation is
|
||||
* suited for sessions that use a static amount of resources
|
||||
* accounted for at session-creation time. For such sessions, an
|
||||
* upgrade is not useful. However, sessions that dynamically
|
||||
* allocate resources on behalf of its client, should respond to
|
||||
* quota upgrades by implementing this function.
|
||||
*
|
||||
* \param session session to upgrade
|
||||
* \param args description of additional resources in the
|
||||
* same format as used at session creation
|
||||
*/
|
||||
virtual void _upgrade_session(SESSION_TYPE *, const char *) { }
|
||||
|
||||
virtual void _destroy_session(SESSION_TYPE *session) {
|
||||
destroy(_md_alloc, session); }
|
||||
|
||||
/**
|
||||
* Return allocator to allocate server object in '_create_session()'
|
||||
*/
|
||||
Allocator *md_alloc() { return _md_alloc; }
|
||||
Rpc_entrypoint *ep() { return _ep; }
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param ep entry point that manages the sessions of this
|
||||
* root interface.
|
||||
* \param ram_session provider of dataspaces for the backing store
|
||||
* of session objects and session data
|
||||
*/
|
||||
Root_component(Rpc_entrypoint *ep, Allocator *metadata_alloc)
|
||||
: _ep(ep), _md_alloc(metadata_alloc) { }
|
||||
|
||||
|
||||
/********************
|
||||
** Root interface **
|
||||
********************/
|
||||
|
||||
Session_capability session(Root::Session_args const &args,
|
||||
Affinity const &affinity)
|
||||
{
|
||||
if (!args.is_valid_string()) throw Root::Invalid_args();
|
||||
|
||||
POLICY::aquire(args.string());
|
||||
|
||||
/*
|
||||
* We need to decrease 'ram_quota' by
|
||||
* the size of the session object.
|
||||
*/
|
||||
size_t ram_quota = Arg_string::find_arg(args.string(), "ram_quota").long_value(0);
|
||||
size_t needed = sizeof(SESSION_TYPE) + md_alloc()->overhead(sizeof(SESSION_TYPE));
|
||||
|
||||
if (needed > ram_quota) {
|
||||
PERR("Insufficient ram quota, provided=%zu, required=%zu",
|
||||
ram_quota, needed);
|
||||
throw Root::Quota_exceeded();
|
||||
}
|
||||
|
||||
size_t const remaining_ram_quota = ram_quota - needed;
|
||||
|
||||
/*
|
||||
* Deduce ram quota needed for allocating the session object from the
|
||||
* donated ram quota.
|
||||
*
|
||||
* XXX the size of the 'adjusted_args' buffer should dependent
|
||||
* on the message-buffer size and stack size.
|
||||
*/
|
||||
enum { MAX_ARGS_LEN = 256 };
|
||||
char adjusted_args[MAX_ARGS_LEN];
|
||||
strncpy(adjusted_args, args.string(), sizeof(adjusted_args));
|
||||
char ram_quota_buf[64];
|
||||
snprintf(ram_quota_buf, sizeof(ram_quota_buf), "%zu",
|
||||
remaining_ram_quota);
|
||||
Arg_string::set_arg(adjusted_args, sizeof(adjusted_args),
|
||||
"ram_quota", ram_quota_buf);
|
||||
|
||||
SESSION_TYPE *s = 0;
|
||||
try { s = _create_session(adjusted_args, affinity); }
|
||||
catch (Allocator::Out_of_memory) { throw Root::Quota_exceeded(); }
|
||||
|
||||
return _ep->manage(s);
|
||||
}
|
||||
|
||||
void upgrade(Session_capability session, Root::Upgrade_args const &args)
|
||||
{
|
||||
if (!args.is_valid_string()) throw Root::Invalid_args();
|
||||
|
||||
typedef typename Object_pool<SESSION_TYPE>::Guard Object_guard;
|
||||
Object_guard s(_ep->lookup_and_lock(session));
|
||||
if (!s) return;
|
||||
|
||||
_upgrade_session(s, args.string());
|
||||
}
|
||||
|
||||
void close(Session_capability session)
|
||||
{
|
||||
SESSION_TYPE * s =
|
||||
dynamic_cast<SESSION_TYPE *>(_ep->lookup_and_lock(session));
|
||||
if (!s) return;
|
||||
|
||||
/* let the entry point forget the session object */
|
||||
_ep->dissolve(s);
|
||||
|
||||
_destroy_session(s);
|
||||
|
||||
POLICY::release();
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__ROOT__COMPONENT_H_ */
|
||||
95
repos/base/include/root/root.h
Normal file
95
repos/base/include/root/root.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* \brief Root interface
|
||||
* \author Norman Feske
|
||||
* \date 2006-05-11
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__ROOT__ROOT_H_
|
||||
#define _INCLUDE__ROOT__ROOT_H_
|
||||
|
||||
#include <base/exception.h>
|
||||
#include <base/rpc.h>
|
||||
#include <base/rpc_args.h>
|
||||
#include <base/affinity.h>
|
||||
#include <session/capability.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
struct Root
|
||||
{
|
||||
/*********************
|
||||
** Exception types **
|
||||
*********************/
|
||||
|
||||
class Exception : public ::Genode::Exception { };
|
||||
class Unavailable : public Exception { };
|
||||
class Quota_exceeded : public Exception { };
|
||||
class Invalid_args : public Exception { };
|
||||
|
||||
typedef Rpc_in_buffer<160> Session_args;
|
||||
typedef Rpc_in_buffer<160> Upgrade_args;
|
||||
|
||||
virtual ~Root() { }
|
||||
|
||||
/**
|
||||
* Create session
|
||||
*
|
||||
* \throw Unavailable
|
||||
* \throw Quota_exceeded
|
||||
* \throw Invalid_args
|
||||
*
|
||||
* \return capability to new session
|
||||
*/
|
||||
virtual Session_capability session(Session_args const &args,
|
||||
Affinity const &affinity) = 0;
|
||||
|
||||
/**
|
||||
* Extend resource donation to an existing session
|
||||
*/
|
||||
virtual void upgrade(Session_capability session, Upgrade_args const &args) = 0;
|
||||
|
||||
/**
|
||||
* Close session
|
||||
*/
|
||||
virtual void close(Session_capability session) = 0;
|
||||
|
||||
|
||||
/*********************
|
||||
** RPC declaration **
|
||||
*********************/
|
||||
|
||||
GENODE_RPC_THROW(Rpc_session, Session_capability, session,
|
||||
GENODE_TYPE_LIST(Unavailable, Quota_exceeded, Invalid_args),
|
||||
Session_args const &, Affinity const &);
|
||||
GENODE_RPC_THROW(Rpc_upgrade, void, upgrade,
|
||||
GENODE_TYPE_LIST(Invalid_args),
|
||||
Session_capability, Upgrade_args const &);
|
||||
GENODE_RPC(Rpc_close, void, close, Session_capability);
|
||||
|
||||
GENODE_RPC_INTERFACE(Rpc_session, Rpc_upgrade, Rpc_close);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Root interface supplemented with information about the managed
|
||||
* session type
|
||||
*
|
||||
* This class template is used to automatically propagate the
|
||||
* correct session type to 'Parent::announce()' when announcing
|
||||
* a service.
|
||||
*/
|
||||
template <typename SESSION_TYPE>
|
||||
struct Typed_root : Root
|
||||
{
|
||||
typedef SESSION_TYPE Session_type;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__ROOT__ROOT_H_ */
|
||||
Reference in New Issue
Block a user