2013-11-14 13:29:47 +01:00
|
|
|
/*
|
|
|
|
* \brief Paging framework
|
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2013-11-07
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-11-14 13:29:47 +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.
|
2013-11-14 13:29:47 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#ifndef _CORE__PAGER_H_
|
|
|
|
#define _CORE__PAGER_H_
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
/* Genode includes */
|
2016-09-05 11:24:51 +02:00
|
|
|
#include <base/session_label.h>
|
2013-11-14 13:29:47 +01:00
|
|
|
#include <base/thread.h>
|
|
|
|
#include <base/object_pool.h>
|
|
|
|
#include <base/signal.h>
|
|
|
|
#include <pager/capability.h>
|
2016-01-20 18:27:18 +01:00
|
|
|
|
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/unmanaged_singleton.h>
|
2016-01-19 20:24:22 +01:00
|
|
|
|
|
|
|
/* core-local includes */
|
2015-06-22 14:44:28 +02:00
|
|
|
#include <kernel/signal_receiver.h>
|
2017-02-21 13:46:59 +01:00
|
|
|
#include <hw/mapping.h>
|
2015-06-22 14:44:28 +02:00
|
|
|
#include <object.h>
|
2016-01-19 20:24:22 +01:00
|
|
|
#include <rpc_cap_factory.h>
|
2013-12-06 19:06:32 +01:00
|
|
|
|
2013-11-14 13:29:47 +01:00
|
|
|
namespace Genode
|
|
|
|
{
|
2017-02-21 13:46:59 +01:00
|
|
|
/**
|
|
|
|
* Interface used by generic region_map code
|
|
|
|
*/
|
|
|
|
struct Mapping;
|
|
|
|
|
2013-11-14 13:29:47 +01:00
|
|
|
/**
|
|
|
|
* Interface between the generic paging system and the base-hw backend
|
|
|
|
*/
|
|
|
|
class Ipc_pager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a faulter and its paging context
|
|
|
|
*/
|
|
|
|
class Pager_object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paging entry point that manages a pool of pager objects
|
|
|
|
*/
|
|
|
|
class Pager_entrypoint;
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
enum { PAGER_EP_STACK_SIZE = sizeof(addr_t) * 2048 };
|
2013-11-14 13:29:47 +01:00
|
|
|
}
|
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
|
|
|
|
struct Genode::Mapping : Hw::Mapping
|
|
|
|
{
|
|
|
|
Mapping() {}
|
|
|
|
|
|
|
|
Mapping(addr_t virt,
|
|
|
|
addr_t phys,
|
|
|
|
Cache_attribute cacheable,
|
|
|
|
bool io,
|
|
|
|
unsigned size_log2,
|
2017-10-13 15:26:33 +02:00
|
|
|
bool writeable,
|
|
|
|
bool executable)
|
2017-02-21 13:46:59 +01:00
|
|
|
: Hw::Mapping(phys, virt, 1 << size_log2,
|
2017-10-13 16:23:10 +02:00
|
|
|
{ writeable ? Hw::RW : Hw::RO,
|
|
|
|
executable ? Hw::EXEC : Hw::NO_EXEC, Hw::USER,
|
2017-02-21 13:46:59 +01:00
|
|
|
Hw::NO_GLOBAL, io ? Hw::DEVICE : Hw::RAM, cacheable }) {}
|
|
|
|
|
|
|
|
void prepare_map_operation() const {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-11-14 13:29:47 +01:00
|
|
|
class Genode::Ipc_pager
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
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
|
|
|
Kernel::Thread_fault _fault { };
|
|
|
|
|
|
|
|
Mapping _mapping { };
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instruction pointer of current page fault
|
|
|
|
*/
|
|
|
|
addr_t fault_ip() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Faulter-local fault address of current page fault
|
|
|
|
*/
|
|
|
|
addr_t fault_addr() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access direction of current page fault
|
|
|
|
*/
|
2016-05-11 18:21:47 +02:00
|
|
|
bool write_fault() const;
|
2013-11-14 13:29:47 +01:00
|
|
|
|
2017-10-13 15:26:33 +02:00
|
|
|
/**
|
|
|
|
* Executable permission fault
|
|
|
|
*/
|
2017-10-13 16:23:10 +02:00
|
|
|
bool exec_fault() const;
|
2017-10-13 15:26:33 +02:00
|
|
|
|
2013-11-14 13:29:47 +01:00
|
|
|
/**
|
|
|
|
* Input mapping data as reply to current page fault
|
|
|
|
*/
|
|
|
|
void set_reply_mapping(Mapping m);
|
|
|
|
};
|
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
|
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
|
|
|
class Genode::Pager_object : private Object_pool<Pager_object>::Entry,
|
|
|
|
private Genode::Kernel_object<Kernel::Signal_context>
|
2013-11-14 13:29:47 +01:00
|
|
|
{
|
|
|
|
friend class Pager_entrypoint;
|
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
|
|
|
friend class Object_pool<Pager_object>;
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
unsigned long const _badge;
|
|
|
|
Cpu_session_capability _cpu_session_cap;
|
|
|
|
Thread_capability _thread_cap;
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2013-11-15 13:47:55 +01:00
|
|
|
* \param badge user identifaction of pager object
|
2013-11-14 13:29:47 +01:00
|
|
|
*/
|
2016-04-20 21:12:57 +02:00
|
|
|
Pager_object(Cpu_session_capability cpu_session_cap,
|
2017-08-21 15:34:27 +02:00
|
|
|
Thread_capability thread_cap, addr_t const badge,
|
2016-09-05 11:24:51 +02:00
|
|
|
Affinity::Location, Session_label const&,
|
|
|
|
Cpu_session::Name const&);
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User identification of pager object
|
|
|
|
*/
|
2015-02-06 17:23:41 +01:00
|
|
|
unsigned long badge() const { return _badge; }
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume faulter
|
|
|
|
*/
|
|
|
|
void wake_up();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unnecessary as base-hw doesn't use exception handlers
|
|
|
|
*/
|
|
|
|
void exception_handler(Signal_context_capability);
|
|
|
|
|
2013-12-06 19:06:32 +01:00
|
|
|
/**
|
|
|
|
* Install information that is necessary to handle page faults
|
|
|
|
*
|
2015-06-22 14:44:28 +02:00
|
|
|
* \param receiver signal receiver that receives the page faults
|
2013-12-06 19:06:32 +01:00
|
|
|
*/
|
2015-06-22 14:44:28 +02:00
|
|
|
void start_paging(Kernel::Signal_receiver * receiver);
|
2013-12-06 19:06:32 +01:00
|
|
|
|
2015-03-10 12:06:55 +01:00
|
|
|
/**
|
|
|
|
* Called when a page-fault finally could not be resolved
|
|
|
|
*/
|
|
|
|
void unresolved_page_fault_occurred();
|
|
|
|
|
2016-09-05 11:24:51 +02:00
|
|
|
void print(Output &out) const;
|
|
|
|
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
/******************
|
|
|
|
** Pure virtual **
|
|
|
|
******************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a mapping that resolves a fault directly
|
|
|
|
*
|
|
|
|
* \param p offers the fault data and receives mapping data
|
|
|
|
*
|
|
|
|
* \retval 0 succeeded
|
|
|
|
* \retval !=0 fault can't be received directly
|
|
|
|
*/
|
|
|
|
virtual int pager(Ipc_pager & p) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
Cpu_session_capability cpu_session_cap() const { return _cpu_session_cap; }
|
|
|
|
Thread_capability thread_cap() const { return _thread_cap; }
|
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
|
|
|
|
|
|
|
using Object_pool<Pager_object>::Entry::cap;
|
2013-11-14 13:29:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
class Genode::Pager_entrypoint : public Object_pool<Pager_object>,
|
|
|
|
public Thread_deprecated<PAGER_EP_STACK_SIZE>,
|
|
|
|
private Kernel_object<Kernel::Signal_receiver>,
|
|
|
|
private Ipc_pager
|
2013-11-14 13:29:47 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2016-01-19 20:24:22 +01:00
|
|
|
Pager_entrypoint(Rpc_cap_factory &);
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Associate pager object 'obj' with entry point
|
|
|
|
*/
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Pager_capability manage(Pager_object &obj);
|
2013-11-14 13:29:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dissolve pager object 'obj' from entry point
|
|
|
|
*/
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
void dissolve(Pager_object &obj);
|
2013-11-14 13:29:47 +01:00
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
** Thread interface **
|
|
|
|
**********************/
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override;
|
2013-11-14 13:29:47 +01:00
|
|
|
};
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#endif /* _CORE__PAGER_H_ */
|