Imported Genode release 11.11

This commit is contained in:
Genode Labs
2011-12-22 16:19:25 +01:00
committed by Christian Helmuth
parent 6bcc9aef0e
commit da4e1feaa5
2462 changed files with 320115 additions and 3 deletions

View File

@ -0,0 +1,64 @@
/*
* \brief Linux-specific layout of IPC message buffer
* \author Norman Feske
* \date 2006-06-14
*/
/*
* Copyright (C) 2006-2011 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__BASE__IPC_MSGBUF_H_
#define _INCLUDE__BASE__IPC_MSGBUF_H_
namespace Genode {
/**
* IPC message buffer layout
*/
class Msgbuf_base
{
protected:
Genode::size_t _size;
char _msg_start[]; /* symbol marks start of message buffer data */
/*
* No member variables are allowed beyond this point!
*/
public:
char buf[];
/**
* Return size of message buffer
*/
inline Genode::size_t size() const { return _size; };
/**
* Return address of message buffer
*/
inline void *addr() { return &_msg_start[0]; };
};
/**
* Pump up IPC message buffer to specified buffer size
*/
template <unsigned BUF_SIZE>
class Msgbuf : public Msgbuf_base
{
public:
char buf[BUF_SIZE];
Msgbuf() { _size = BUF_SIZE; }
};
}
#endif /* _INCLUDE__BASE__IPC_MSGBUF_H_ */

View File

@ -0,0 +1,89 @@
/*
* \brief Support for process-local pseudo capabilities
* \author Norman Feske
* \date 2011-11-21
*
* Pseudo capabilities have a zero 'tid' and a non-zero 'local_name'. The local
* name is a pointer to the local object implementing the interface. Pseudo
* capabilties are valid only as arguments for local services that are prepared
* for it. I.e., the locally implemented RM service accepts pseudo dataspace
* capabilities that refer to managed dataspaces. Or the Linux-specific
* 'Rm_session_client' takes a pseudo capability to target RM-session
* invokations to the local implementation.
*
* Please note that this header file is not part of the official Genode API.
* It exists on no other platform than Linux and is meant for Genode-internal
* use only.
*/
/*
* Copyright (C) 2011 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__BASE__LOCAL_INTERFACE_H_
#define _INCLUDE__BASE__LOCAL_INTERFACE_H_
#include <base/capability.h>
#include <base/printf.h>
namespace Genode {
/**
* Common base class of local interface implementations
*/
struct Local_interface
{
virtual ~Local_interface() { }
/**
* Exception type
*/
class Non_local_capability { };
/**
* Convert pseudo capability to pointer to locally implemented session
*
* \param IF interface type
* \param cap pseudo capability
*
* \throw Non_local_capability if the argument does not refer to a
* locally implemented interface
*/
template <typename IF>
static IF *deref(Capability<IF> cap)
{
/* check if this is a pseudo capability */
if (cap.tid() != 0 || !cap.local_name())
throw Non_local_capability();
/*
* For a pseudo capability, the 'local_name' points to the local
* session object of the correct type.
*/
IF *interface = dynamic_cast<IF *>((Local_interface *)cap.local_name());
if (!interface)
throw Non_local_capability();
return interface;
}
/**
* Construct pseudo capability to process-local interface implementation
*
* \param IF interface type
* \param interface pointer to local interface implementation
* \return pseudo capability
*
*/
template <typename IF>
static Capability<IF> capability(IF *interface)
{
return reinterpret_cap_cast<IF>(Native_capability(0, (long)interface));
};
};
}
#endif /* _INCLUDE__BASE__LOCAL_INTERFACE_H_ */

View File

@ -0,0 +1,135 @@
/*
* \brief Native types
* \author Norman Feske
* \date 2007-10-15
*/
/*
* Copyright (C) 2007-2011 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__BASE__NATIVE_TYPES_H_
#define _INCLUDE__BASE__NATIVE_TYPES_H_
/*
* We cannot just include <semaphore.h> and <pthread.h> here
* because this would impy the nested inclusion of a myriad
* of Linux types and would pollute the namespace for everyone
* who includes this header file. We want to cleanly separate
* Genode from POSIX.
*/
namespace Genode {
/**
* Native lock type
*
* We are using a sleeping spinlock as lock implementation on Linux. This
* is a temporary solution until we have implemented futex-based locking.
* In a previous version, we have relied on POSIX semaphores as provided by
* the glibc. However, relying on the glibc badly interferes with a custom
* libc implementation. The glibc semaphore implementation expects to find
* a valid pthread structure via the TLS pointer. We do not have such a
* structure because we create threads via the 'clone' system call rather
* than 'pthread_create'. Hence we have to keep the base framework clean
* from glibc usage altogether.
*/
typedef volatile int Native_lock;
/**
* Thread ID used in lock implementation
*
* Unfortunately, both - PID and TID - are needed for lx_tgkill() in
* thread_check_stopped_and_restart().
*/
struct Native_thread_id
{
unsigned int tid; /* Native thread ID type as returned by the
'clone' system call */
unsigned int pid; /* process ID (resp. thread-group ID) */
Native_thread_id() : tid(0), pid(0) { }
Native_thread_id(unsigned int tid, unsigned int pid)
: tid(tid), pid(pid) { }
};
/**
* Native thread contains more thread-local data than just the ID
*
* A thread needs two sockets as it may be a server that depends on another
* service during request processing. If the server socket would be used for
* the client call, the server thread may be unblocked by further requests
* from its clients. In other words, the additional client socket provides
* closed-receive semantics in calls. An even better solution is to use
* SCM_RIGHTS messages to send a client socket descriptor with the request.
*/
struct Native_thread : Native_thread_id
{
int client; /* socket used as IPC client */
int server; /* socket used as IPC server */
Native_thread() : client(-1), server(-1) { }
};
inline bool operator == (Native_thread_id t1, Native_thread_id t2) {
return (t1.tid == t2.tid) && (t1.pid == t2.pid); }
inline bool operator != (Native_thread_id t1, Native_thread_id t2) {
return (t1.tid != t2.tid) || (t1.pid != t2.pid); }
/**
* Empty UTCB type expected by the thread library, unused on Linux
*/
typedef struct { } Native_utcb;
/*
* On Linux, the local_name member of a capability is global
* to the whole system. Therefore, capabilities are to be
* created at a central place that prevents id clashes.
*/
class Native_capability
{
protected:
long _tid; /* target thread */
long _local_name;
public:
/**
* Default constructor
*/
Native_capability() : _tid(0), _local_name(0) { }
long local_name() const { return _local_name; }
bool valid() const { return _tid != 0; }
/****************************************************
** Functions to be used by the Linux backend only **
****************************************************/
/**
* Constructor
*
* This constructor can be called to create a Linux
* capability by hand. It must never be used from
* generic code!
*/
Native_capability(long tid, long local_name)
: _tid(tid), _local_name(local_name) { }
/**
* Access raw capability data
*/
long tid() const { return _tid; }
};
typedef int Native_connection_state; /* socket descriptor */
}
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */

View File

@ -0,0 +1,43 @@
/*
* \brief Paging-server framework
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-04-28
*
* Linux dummies
*/
/*
* Copyright (C) 2006-2011 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__BASE__PAGER_H_
#define _INCLUDE__BASE__PAGER_H_
#include <base/signal.h>
#include <pager/capability.h>
#include <cap_session/cap_session.h>
namespace Genode {
struct Pager_object
{
virtual ~Pager_object() { }
void exception_handler(Signal_context_capability) { }
};
class Pager_activation_base { };
struct Pager_entrypoint
{
Pager_entrypoint(Cap_session *, Pager_activation_base *) { }
Pager_object *obj_by_cap(Pager_capability) { return 0; }
};
template <int FOO> class Pager_activation : public Pager_activation_base { };
}
#endif /* _INCLUDE__BASE__PAGER_H_ */

View File

@ -0,0 +1,379 @@
/*
* \brief Linux-specific environment
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-28
*/
/*
* Copyright (C) 2006-2011 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__BASE__PLATFORM_ENV_H_
#define _INCLUDE__BASE__PLATFORM_ENV_H_
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <base/env.h>
#include <base/printf.h>
#include <util/misc_math.h>
#include <base/local_interface.h>
#include <base/heap.h>
#include <parent/client.h>
#include <ram_session/client.h>
#include <cpu_session/client.h>
namespace Genode {
class Platform_env : public Env
{
private:
/**************************
** Local region manager **
**************************/
class Region
{
private:
addr_t _start;
off_t _offset;
Dataspace_capability _ds;
size_t _size;
/**
* Return offset of first byte after the region
*/
addr_t _end() const { return _start + _size; }
public:
Region() : _start(0), _offset(0), _size(0) { }
Region(addr_t start, off_t offset, Dataspace_capability ds, size_t size)
: _start(start), _offset(offset), _ds(ds), _size(size) { }
bool used() const { return _size > 0; }
addr_t start() const { return _start; }
off_t offset() const { return _offset; }
size_t size() const { return _size; }
Dataspace_capability dataspace() const { return _ds; }
bool intersects(Region const &r) const
{
return (r.start() < _end()) && (_start < r._end());
}
};
/**
* Meta data about dataspaces attached to an RM session
*/
class Region_map
{
public:
enum { MAX_REGIONS = 4096 };
private:
Region _map[MAX_REGIONS];
bool _id_valid(int id) const {
return (id >= 0 && id < MAX_REGIONS); }
public:
/**
* Add region to region map
*
* \return region ID, or
* -1 if out of metadata, or
* -2 if region conflicts existing region
*/
int add_region(Region const &region)
{
/*
* Check for region conflicts
*/
for (int i = 0; i < MAX_REGIONS; i++) {
if (_map[i].intersects(region))
return -2;
}
/*
* Allocate new region metadata
*/
int i;
for (i = 0; i < MAX_REGIONS; i++)
if (!_map[i].used()) break;
if (i == MAX_REGIONS) {
PERR("maximum number of %d regions reached",
MAX_REGIONS);
return -1;
}
_map[i] = region;
return i;
}
Region region(int id) const
{
return _id_valid(id) ? _map[id] : Region();
}
Region lookup(addr_t start)
{
for (int i = 0; i < MAX_REGIONS; i++)
if (_map[i].start() == start)
return _map[i];
return Region();
}
void remove_region(addr_t start)
{
for (int i = 0; i < MAX_REGIONS; i++)
if (_map[i].start() == start)
_map[i] = Region();
}
};
/*
* On Linux, we use a local region manager session
* that attaches dataspaces via mmap to the local
* address space.
*/
class Rm_session_mmap : public Local_interface,
public Rm_session,
public Dataspace
{
private:
Lock _lock; /* protect '_rmap' */
Region_map _rmap;
bool const _sub_rm; /* false if RM session is root */
size_t const _size;
/**
* Base offset of the RM session
*
* For a normal RM session (the one that comes with the
* 'env()', this value is zero. If the RM session is
* used as nested dataspace, '_base' contains the address
* where the managed dataspace is attached in the root RM
* session.
*
* Note that a managed dataspace cannot be attached more
* than once. Furthermore, managed dataspace cannot be
* attached to another managed dataspace. The nested
* dataspace emulation is solely implemented to support
* the common use case of managed dataspaces as mechanism
* to reserve parts of the local address space from being
* populated by the 'env()->rm_session()'. (i.e., for the
* context area, or for the placement of consecutive
* shared-library segments)
*/
addr_t _base;
bool _is_attached() const { return _base > 0; }
void _add_to_rmap(Region const &);
public:
Rm_session_mmap(bool sub_rm, size_t size = ~0)
: _sub_rm(sub_rm), _size(size), _base(0) { }
~Rm_session_mmap()
{
/* detach sub RM session when destructed */
if (_sub_rm && _is_attached())
env()->rm_session()->detach((void *)_base);
}
/**************************************
** Region manager session interface **
**************************************/
Local_addr attach(Dataspace_capability ds, size_t size,
off_t, bool, Local_addr);
void detach(Local_addr local_addr);
Pager_capability add_client(Thread_capability thread) {
return Pager_capability(); }
void fault_handler(Signal_context_capability handler) { }
State state() { return State(); }
/*************************
** Dataspace interface **
*************************/
size_t size() { return _size; }
addr_t phys_addr() { return 0; }
bool writable() { return true; }
/**
* Return pseudo dataspace capability of the RM session
*
* The capability returned by this function is only usable
* as argument to 'Rm_session_mmap::attach'. It is not a
* real capability.
*/
Dataspace_capability dataspace()
{
return Local_interface::capability(this);
}
};
class Expanding_ram_session_client : public Ram_session_client
{
Ram_session_capability _cap;
public:
Expanding_ram_session_client(Ram_session_capability cap)
: Ram_session_client(cap), _cap(cap) { }
Ram_dataspace_capability alloc(size_t size) {
bool try_again;
do {
try_again = false;
try {
return Ram_session_client::alloc(size);
} catch (Ram_session::Out_of_metadata) {
/* give up if the error occurred a second time */
if (try_again)
break;
PINF("upgrade quota donation for Env::RAM session");
env()->parent()->upgrade(_cap, "ram_quota=8K");
try_again = true;
}
} while (try_again);
return Ram_dataspace_capability();
}
};
/**
* Local interceptor of parent requests
*
* On Linux, we need to intercept calls to the parent interface to
* implement the RM service locally. This particular service is
* used for creating managed dataspaces, which allow the
* reservation of parts of the local address space from being
* automatically managed by the 'env()->rm_session()'.
*
* All requests that do not refer to the RM service are passed
* through the real parent interface.
*/
class Local_parent : public Parent_client
{
public:
/**********************
** Parent interface **
**********************/
Session_capability session(Service_name const &,
Session_args const &);
void close(Session_capability);
/**
* Constructor
*
* \param parent_cap real parent capability used to
* promote requests to non-local
* services
*/
Local_parent(Parent_capability parent_cap);
};
/*************************************
** Linux-specific helper functions **
*************************************/
/**
* Read Unix environment variable as long value
*/
static unsigned long _get_env_ulong(const char *key);
Parent_capability _parent_cap()
{
long tid = _get_env_ulong("parent_tid");
long local_name = _get_env_ulong("parent_local_name");
/* produce typed capability manually */
return reinterpret_cap_cast<Parent>(Native_capability(tid, local_name));
}
/*******************************
** Platform-specific members **
*******************************/
Local_parent _parent;
Ram_session_capability _ram_session_cap;
Expanding_ram_session_client _ram_session_client;
Cpu_session_client _cpu_session_client;
Rm_session_mmap _rm_session_mmap;
Heap _heap;
public:
/**
* Standard constructor
*/
Platform_env()
:
_parent(_parent_cap()),
_ram_session_cap(static_cap_cast<Ram_session>(parent()->session("Env::ram_session", ""))),
_ram_session_client(_ram_session_cap),
_cpu_session_client(static_cap_cast<Cpu_session>(parent()->session("Env::cpu_session", ""))),
_rm_session_mmap(false),
_heap(&_ram_session_client, &_rm_session_mmap)
{ }
/**
* Destructor
*/
~Platform_env() { parent()->exit(0); }
/*******************
** Env interface **
*******************/
Parent *parent() { return &_parent; }
Ram_session *ram_session() { return &_ram_session_client; }
Ram_session_capability ram_session_cap() { return _ram_session_cap; }
Rm_session *rm_session() { return &_rm_session_mmap; }
Heap *heap() { return &_heap; }
Cpu_session *cpu_session() { return &_cpu_session_client; }
Pd_session *pd_session() { return 0; }
};
}
#endif /* _INCLUDE__BASE__PLATFORM_ENV_H_ */