2016-07-08 16:38:48 +02:00
|
|
|
/*
|
|
|
|
* \brief Paging-server framework
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2006-04-28
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2016-07-08 16:38:48 +02: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.
|
2016-07-08 16:38:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__PAGER_H_
|
|
|
|
#define _CORE__INCLUDE__PAGER_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.h>
|
|
|
|
#include <base/object_pool.h>
|
2016-09-05 11:24:51 +02:00
|
|
|
#include <base/session_label.h>
|
2016-07-08 16:38:48 +02:00
|
|
|
#include <pager/capability.h>
|
|
|
|
#include <ipc_pager.h>
|
|
|
|
|
|
|
|
/* core-local includes */
|
|
|
|
#include <rpc_cap_factory.h>
|
|
|
|
#include <base/internal/capability_space_sel4.h>
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Special server object for paging
|
|
|
|
*
|
|
|
|
* A 'Pager_object' is very similar to a 'Rpc_object'. It is just a
|
|
|
|
* special implementation for page-fault handling, which does not allow to
|
|
|
|
* define a "badge" for pager capabilities.
|
|
|
|
*/
|
|
|
|
class Pager_object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paging entry point
|
|
|
|
*/
|
|
|
|
class Pager_entrypoint;
|
|
|
|
|
|
|
|
enum { PAGER_EP_STACK_SIZE = sizeof(addr_t) * 2048 };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Genode::Pager_object : public Object_pool<Pager_object>::Entry
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Local name for this pager object
|
|
|
|
*/
|
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
|
|
|
unsigned long _badge = 0;
|
2016-07-08 16:38:48 +02:00
|
|
|
|
|
|
|
Cpu_session_capability _cpu_session_cap;
|
|
|
|
Thread_capability _thread_cap;
|
|
|
|
Genode::Cap_sel _reply_cap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User-level signal handler registered for this pager object via
|
|
|
|
* 'Cpu_session::exception_handler()'.
|
|
|
|
*/
|
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
|
|
|
Signal_context_capability _exception_sigh { };
|
2016-07-08 16:38:48 +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
|
|
|
Session_label _pd_label;
|
|
|
|
Cpu_session::Name _name;
|
2016-09-05 11:24:51 +02:00
|
|
|
|
2016-07-08 16:38:48 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains information about exception state of corresponding thread.
|
|
|
|
*/
|
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
|
|
|
Thread_state state { };
|
2016-07-08 16:38:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param location affinity of paged thread to physical CPU
|
|
|
|
*/
|
2016-09-05 11:24:51 +02:00
|
|
|
Pager_object(Cpu_session_capability cpu_session, Thread_capability thread,
|
|
|
|
unsigned long badge, Affinity::Location location,
|
|
|
|
Session_label const &pd_label,
|
|
|
|
Cpu_session::Name const &name);
|
2016-07-08 16:38:48 +02:00
|
|
|
|
|
|
|
~Pager_object();
|
|
|
|
|
|
|
|
unsigned long badge() const { return _badge; }
|
|
|
|
|
|
|
|
unsigned long reply_cap_sel() const { return _reply_cap.value(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface to be implemented by a derived class
|
|
|
|
*
|
|
|
|
* \param ps 'Ipc_pager' stream
|
|
|
|
*
|
|
|
|
* Returns !0 on error and pagefault will not be answered.
|
|
|
|
*/
|
|
|
|
virtual int pager(Ipc_pager &ps) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wake up the faulter
|
|
|
|
*/
|
|
|
|
void wake_up();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign user-level exception handler for the pager object
|
|
|
|
*/
|
|
|
|
void exception_handler(Signal_context_capability sigh)
|
|
|
|
{
|
|
|
|
_exception_sigh = sigh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify exception handler about the occurrence of an exception
|
|
|
|
*/
|
|
|
|
void submit_exception_signal()
|
|
|
|
{
|
|
|
|
if (!_exception_sigh.valid()) return;
|
|
|
|
|
|
|
|
Signal_transmitter transmitter(_exception_sigh);
|
|
|
|
transmitter.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return CPU session that was used to created the thread
|
|
|
|
*/
|
|
|
|
Cpu_session_capability cpu_session_cap() const { return _cpu_session_cap; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return thread capability
|
|
|
|
*
|
|
|
|
* This function enables the destructor of the thread's
|
|
|
|
* address-space region map to kill the thread.
|
|
|
|
*/
|
|
|
|
Thread_capability thread_cap() const { return _thread_cap; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note in the thread state that an unresolved page
|
|
|
|
* fault occurred.
|
|
|
|
*/
|
|
|
|
void unresolved_page_fault_occurred();
|
2016-09-05 11:24:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print pager object belonging
|
|
|
|
*/
|
|
|
|
void print(Output &out) const
|
|
|
|
{
|
|
|
|
Genode::print(out, "pager_object: pd='", _pd_label,
|
|
|
|
"' thread='", _name, "'");
|
|
|
|
}
|
2016-07-08 16:38:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Genode::Pager_entrypoint : public Object_pool<Pager_object>,
|
|
|
|
public Thread_deprecated<PAGER_EP_STACK_SIZE>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
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
|
|
|
Ipc_pager _pager { };
|
2016-07-08 16:38:48 +02:00
|
|
|
Rpc_cap_factory _cap_factory;
|
|
|
|
|
|
|
|
Untyped_capability _pager_object_cap(unsigned long badge);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param cap_factory factory for creating capabilities
|
|
|
|
* for the pager objects managed by this
|
|
|
|
* entry point
|
|
|
|
*/
|
|
|
|
Pager_entrypoint(Rpc_cap_factory &cap_factory)
|
|
|
|
:
|
|
|
|
Thread_deprecated<PAGER_EP_STACK_SIZE>("pager_ep"),
|
|
|
|
_cap_factory(cap_factory)
|
|
|
|
{ start(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Associate Pager_object with the 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 &);
|
2016-07-08 16:38:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dissolve Pager_object 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 &);
|
2016-07-08 16:38:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
** Thread interface **
|
|
|
|
**********************/
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override;
|
2016-07-08 16:38:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__PAGER_H_ */
|