genode/repos/base-foc/src/core/platform_pd.cc
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

141 lines
3.3 KiB
C++

/*
* \brief Fiasco protection domain facility
* \author Christian Helmuth
* \author Stefan Kalkowski
* \date 2006-04-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.
*/
/* Genode includes */
#include <base/native_capability.h>
#include <util/misc_math.h>
/* core includes */
#include <util.h>
#include <platform.h>
#include <platform_pd.h>
/* Fiasco includes */
namespace Fiasco {
#include <l4/sys/utcb.h>
#include <l4/sys/factory.h>
}
using namespace Fiasco;
using namespace Genode;
static addr_t core_utcb_base() {
static addr_t base = (addr_t) l4_utcb();
return base;
}
/***************************
** Public object members **
***************************/
bool Platform_pd::bind_thread(Platform_thread *thread)
{
/*
* Fiasco.OC limits the UTCB area for roottask to 16K. Therefore, the
* number of threads is limited to 16K / L4_UTCB_OFFSET.
* (see kernel/fiasco/src/kern/kernel_thread-std.cpp:94)
*/
unsigned const thread_max = thread->core_thread() ? 16*1024/L4_UTCB_OFFSET : THREAD_MAX;
for (unsigned i = 0; i < thread_max; i++) {
if (_threads[i])
continue;
_threads[i] = thread;
if (thread->core_thread())
thread->_utcb = (addr_t) (core_utcb_base() + i * L4_UTCB_OFFSET);
else
thread->_utcb =
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;
thread->_gate.remote = cap_offset + THREAD_GATE_CAP;
thread->_pager.remote = cap_offset + THREAD_PAGER_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 (!thread->core_thread())
_task.map(_task.local.data()->kcap());
/* inform thread about binding */
thread->bind(this);
return true;
}
error("thread alloc failed");
return false;
}
void Platform_pd::unbind_thread(Platform_thread *thread)
{
/* inform thread about unbinding */
thread->unbind();
for (unsigned i = 0; i < THREAD_MAX; i++)
if (_threads[i] == thread) {
_threads[i] = (Platform_thread*) 0;
return;
}
}
void Platform_pd::assign_parent(Native_capability parent)
{
if (_parent.remote == Fiasco::L4_INVALID_CAP && parent.valid()) {
_parent.local = parent;
_parent.remote = PARENT_CAP;
_parent.map(_task.local.data()->kcap());
}
}
Platform_pd::Platform_pd(Core_cap_index* i)
: _task(Native_capability(*i), TASK_CAP)
{
for (unsigned i = 0; i < THREAD_MAX; i++)
_threads[i] = (Platform_thread*) 0;
}
Platform_pd::Platform_pd(Allocator *, char const *)
: _task(true, TASK_CAP)
{
for (unsigned i = 0; i < THREAD_MAX; i++)
_threads[i] = (Platform_thread*) 0;
l4_fpage_t utcb_area = l4_fpage(utcb_area_start(),
log2<unsigned>(UTCB_AREA_SIZE), 0);
l4_msgtag_t tag = l4_factory_create_task(L4_BASE_FACTORY_CAP,
_task.local.data()->kcap(), utcb_area);
if (l4_msgtag_has_error(tag))
error("pd creation failed");
}
Platform_pd::~Platform_pd()
{
/* invalidate weak pointers to this object */
Address_space::lock_for_destruction();
for (unsigned i = 0; i < THREAD_MAX; i++) {
if (_threads[i])
_threads[i]->unbind();
}
}