2011-12-22 16:19:25 +01:00
|
|
|
/*
|
2015-07-29 10:58:17 +02:00
|
|
|
* \brief Pager support for OKL4
|
2011-12-22 16:19:25 +01:00
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2009-03-31
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2009-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/* Genode includes */
|
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-07-13 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2015-07-29 10:58:17 +02:00
|
|
|
|
2016-03-08 17:44:54 +01:00
|
|
|
/* core includes */
|
2015-07-29 10:58:17 +02:00
|
|
|
#include <ipc_pager.h>
|
2015-06-19 14:58:18 +02:00
|
|
|
#include <pager.h>
|
2016-03-08 17:44:54 +01:00
|
|
|
#include <platform_thread.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-03-11 17:32:43 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/native_thread.h>
|
2016-06-13 13:53:58 +02:00
|
|
|
#include <base/internal/native_utcb.h>
|
2016-06-15 15:04:54 +02:00
|
|
|
#include <base/internal/capability_space_tpl.h>
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
#include <base/internal/okl4.h>
|
2015-07-29 10:58:17 +02:00
|
|
|
|
|
|
|
static const bool verbose_page_fault = false;
|
|
|
|
static const bool verbose_exception = false;
|
|
|
|
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
using namespace Genode;
|
2015-07-29 10:58:17 +02:00
|
|
|
using namespace Okl4;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/**
|
|
|
|
* Print page-fault information in a human-readable form
|
|
|
|
*/
|
|
|
|
static inline void print_page_fault(L4_Word_t type, L4_Word_t addr, L4_Word_t ip,
|
|
|
|
unsigned long badge)
|
|
|
|
{
|
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-07-13 19:07:09 +02:00
|
|
|
log("page (",
|
|
|
|
type & L4_Readable ? "r" : "-",
|
|
|
|
type & L4_Writable ? "w" : "-",
|
|
|
|
type & L4_eXecutable ? "x" : "-",
|
|
|
|
") fault at fault_addr=, ", Hex(addr), ", ip=", Hex(ip), ", from=", badge);
|
2015-07-29 10:58:17 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/**
|
|
|
|
* Return the global thread ID of the calling thread
|
|
|
|
*
|
|
|
|
* On OKL4 we cannot use 'L4_Myself()' to determine our own thread's
|
|
|
|
* identity. By convention, each thread stores its global ID in a
|
|
|
|
* defined entry of its UTCB.
|
|
|
|
*/
|
|
|
|
static inline Okl4::L4_ThreadId_t thread_get_my_global_id()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-07-29 10:58:17 +02:00
|
|
|
Okl4::L4_ThreadId_t myself;
|
|
|
|
myself.raw = Okl4::__L4_TCR_ThreadWord(UTCB_TCR_THREAD_WORD_MYSELF);
|
|
|
|
return myself;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/*************
|
|
|
|
** Mapping **
|
|
|
|
*************/
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Mapping::Mapping(addr_t dst_addr, addr_t src_addr, Cache_attribute, bool,
|
|
|
|
unsigned l2size, bool rw, bool)
|
2015-07-29 10:58:17 +02:00
|
|
|
:
|
|
|
|
_fpage(L4_FpageLog2(dst_addr, l2size)),
|
|
|
|
/*
|
|
|
|
* OKL4 does not support write-combining as mapping attribute.
|
|
|
|
*/
|
|
|
|
_phys_desc(L4_PhysDesc(src_addr, 0))
|
|
|
|
{
|
|
|
|
L4_Set_Rights(&_fpage, rw ? L4_ReadWriteOnly : L4_ReadeXecOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Mapping::Mapping() { }
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/***************
|
|
|
|
** IPC pager **
|
|
|
|
***************/
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
void Ipc_pager::wait_for_fault()
|
|
|
|
{
|
|
|
|
/* wait for fault */
|
|
|
|
_faulter_tag = L4_Wait(&_last);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read fault information
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* exception */
|
2016-05-11 18:21:47 +02:00
|
|
|
if (exception()) {
|
2015-07-29 10:58:17 +02:00
|
|
|
L4_StoreMR(1, &_fault_ip);
|
|
|
|
|
|
|
|
if (verbose_exception)
|
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-07-13 19:07:09 +02:00
|
|
|
error("exception (label ", Hex(L4_Label(_faulter_tag)), ") occured, "
|
|
|
|
"space=", Hex(L4_SenderSpace().raw), ", "
|
|
|
|
"ip=", Hex(_fault_ip));
|
2015-07-29 10:58:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* page fault */
|
|
|
|
else {
|
|
|
|
L4_StoreMR(1, &_fault_addr);
|
|
|
|
L4_StoreMR(2, &_fault_ip);
|
|
|
|
|
|
|
|
if (verbose_page_fault)
|
|
|
|
print_page_fault(L4_Label(_faulter_tag), _fault_addr, _fault_ip, _last.raw);
|
|
|
|
}
|
|
|
|
_last_space = L4_SenderSpace().raw;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
|
|
|
|
void Ipc_pager::reply_and_wait_for_fault()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-07-29 10:58:17 +02:00
|
|
|
L4_SpaceId_t to_space;
|
|
|
|
to_space.raw = L4_ThreadNo(_last) >> Thread_id_bits::THREAD;
|
|
|
|
|
|
|
|
/* map page to faulting space */
|
|
|
|
int ret = L4_MapFpage(to_space, _reply_mapping.fpage(),
|
|
|
|
_reply_mapping.phys_desc());
|
|
|
|
|
|
|
|
if (ret != 1)
|
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-07-13 19:07:09 +02:00
|
|
|
error("L4_MapFpage returned ", ret, ", error=", L4_ErrorCode());
|
2015-07-29 10:58:17 +02:00
|
|
|
|
|
|
|
/* reply to page-fault message to resume the faulting thread */
|
|
|
|
acknowledge_wakeup();
|
|
|
|
|
|
|
|
wait_for_fault();
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
void Ipc_pager::acknowledge_wakeup()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-07-29 10:58:17 +02:00
|
|
|
/* answer wakeup call from one of core's region-manager sessions */
|
|
|
|
L4_LoadMR(0, 0);
|
|
|
|
L4_Send(_last);
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/**********************
|
|
|
|
** Pager entrypoint **
|
|
|
|
**********************/
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
Untyped_capability Pager_entrypoint::_pager_object_cap(unsigned long badge)
|
2015-07-29 10:58:17 +02:00
|
|
|
{
|
2016-06-15 15:04:54 +02:00
|
|
|
return Capability_space::import(native_thread().l4id, Rpc_obj_key(badge));
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|