genode/repos/base-fiasco/src/core/include/platform_pd.h
Norman Feske 17c79a9e23 base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.

While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).

To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.

Issue #1987
2016-08-29 17:27:10 +02:00

199 lines
4.1 KiB
C++

/*
* \brief L4/Fiasco protection domain facility
* \author Christian Helmuth
* \date 2006-04-11
*
* Protection domains are L4 tasks under Fiasco and serve as base
* container for the platform.
*/
/*
* 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 _CORE__INCLUDE__PLATFORM_PD_H_
#define _CORE__INCLUDE__PLATFORM_PD_H_
#include <base/allocator.h>
#include <platform_thread.h>
#include <address_space.h>
namespace Fiasco {
#include <l4/sys/types.h>
}
namespace Genode {
class Platform_thread;
class Platform_pd : public Address_space
{
private:
enum {
VERSION_BITS = 10,
PD_FIRST = 0x10,
PD_MAX = (1 << 11) - 1, /* leave 0x7ff free for L4_INVALID_ID */
PD_VERSION_MAX = (1 << 10) - 1,
PD_INVALID = -1,
THREAD_MAX = (1 << 7),
};
unsigned _pd_id; /* plain pd number */
unsigned _version; /* version number */
Fiasco::l4_taskid_t _l4_task_id; /* L4 task ID */
/**********************************************
** Threads of this protection domain object **
**********************************************/
Platform_thread *_threads[THREAD_MAX];
/**
* Initialize thread allocator
*/
void _init_threads();
/**
* Thread iteration for one task
*/
Platform_thread *_next_thread();
/**
* Thread allocation
*
* Again a special case for Core thread0.
*/
int _alloc_thread(int thread_id, Platform_thread *thread);
/**
* Thread deallocation
*
* No special case for Core thread0 here - we just never call it.
*/
void _free_thread(int thread_id);
/******************
** PD allocator **
******************/
struct Pd_alloc
{
unsigned reserved : 1;
unsigned free : 1;
unsigned version : VERSION_BITS;
Pd_alloc(bool r, bool f, unsigned v)
: reserved(r), free(f), version(v) { }
Pd_alloc() : reserved(0), free(0), version(0) { }
};
static Pd_alloc *_pds()
{
static Pd_alloc static_pds[PD_MAX];
return static_pds;
}
/**
* Protection-domain creation
*
* The syscall parameter propagates if any L4 kernel function
* should be used. We need the special case for the Core startup.
*/
void _create_pd(bool syscall);
/**
* Protection domain destruction
*
* No special case for Core here - we just never call it.
*/
void _destroy_pd();
/**
* Protection domain allocation
*
* Find free L4 task and use it. We need the special case for Core
* startup.
*/
int _alloc_pd(signed pd_id);
/**
* Protection domain deallocation
*
* No special case for Core here - we just never call it.
*/
void _free_pd();
/***************
** Debugging **
***************/
void _debug_log_pds(void);
void _debug_log_threads(void);
public:
/**
* Constructor
*/
Platform_pd(Allocator * md_alloc, char const *,
signed pd_id = PD_INVALID, bool create = true);
/**
* Destructor
*/
~Platform_pd();
/**
* Register quota donation at allocator guard
*/
void upgrade_ram_quota(size_t ram_quota) { }
/**
* Initialize L4 task facility
*/
static void init();
/**
* Bind thread to protection domain
*
* \return true on success
*/
bool bind_thread(Platform_thread *thread);
/**
* Unbind thread from protection domain
*
* Free the thread's slot and update thread object.
*/
void unbind_thread(Platform_thread *thread);
/**
* Assign parent interface to protection domain
*/
void assign_parent(Native_capability parent) { }
int pd_id() const { return _pd_id; }
/*****************************
** Address-space interface **
*****************************/
/*
* On L4/Fiasco, we don't use directed unmap but rely on the
* in-kernel mapping database. See 'region_map_support.cc'.
*/
void flush(addr_t, size_t) { warning(__func__, " not implemented"); }
};
}
#endif /* _CORE__INCLUDE__PLATFORM_PD_H_ */