2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Paging-server framework
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Christian Helmuth
|
2015-07-29 10:58:17 +02:00
|
|
|
* \author Stefan Kalkowski
|
2011-12-22 16:19:25 +01:00
|
|
|
* \date 2006-04-28
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-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-06-19 14:58:18 +02:00
|
|
|
#ifndef _CORE__INCLUDE__PAGER_H_
|
|
|
|
#define _CORE__INCLUDE__PAGER_H_
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-19 20:24:22 +01:00
|
|
|
/* Genode includes */
|
2016-09-05 11:24:51 +02:00
|
|
|
#include <base/session_label.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <base/thread.h>
|
|
|
|
#include <base/object_pool.h>
|
|
|
|
#include <pager/capability.h>
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
#include <cpu_session/cpu_session.h>
|
2015-07-29 10:58:17 +02:00
|
|
|
#include <ipc_pager.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-19 20:24:22 +01:00
|
|
|
/* core-local includes */
|
|
|
|
#include <rpc_cap_factory.h>
|
2016-12-13 19:19:44 +01:00
|
|
|
#include <pager_object_exception_state.h>
|
2016-01-19 20:24:22 +01:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
typedef Cpu_session::Thread_creation_failed Invalid_thread;
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-03-04 21:12:14 +01:00
|
|
|
class Pager_object;
|
2015-07-29 10:58:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Paging entry point
|
|
|
|
*/
|
2011-12-22 16:19:25 +01:00
|
|
|
class Pager_entrypoint;
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
enum { PAGER_EP_STACK_SIZE = sizeof(addr_t) * 2048 };
|
|
|
|
}
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Genode::Pager_object : public Object_pool<Pager_object>::Entry
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Local name for this pager object
|
|
|
|
*/
|
|
|
|
unsigned long _badge;
|
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
Cpu_session_capability _cpu_session_cap;
|
|
|
|
Thread_capability _thread_cap;
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User-level signal handler registered for this pager object via
|
|
|
|
* 'Cpu_session::exception_handler()'.
|
|
|
|
*/
|
|
|
|
Signal_context_capability _exception_sigh;
|
|
|
|
|
2016-09-05 11:24:51 +02:00
|
|
|
Session_label _pd_label;
|
|
|
|
Cpu_session::Name _name;
|
|
|
|
|
2015-03-04 21:12:14 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains information about exception state of corresponding thread.
|
|
|
|
*/
|
2016-12-13 19:19:44 +01:00
|
|
|
Pager_object_exception_state state;
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param location affinity of paged thread to physical CPU
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
*
|
|
|
|
* \throw Invalid_thread
|
2015-03-04 21:12:14 +01:00
|
|
|
*/
|
2016-09-05 11:24:51 +02:00
|
|
|
Pager_object(Cpu_session_capability cpu_sesion,
|
|
|
|
Thread_capability thread,
|
|
|
|
unsigned long badge, Affinity::Location location,
|
|
|
|
Session_label const &pd_label,
|
|
|
|
Cpu_session::Name const &name)
|
2016-04-20 21:12:57 +02:00
|
|
|
:
|
2016-09-05 11:24:51 +02:00
|
|
|
_badge(badge), _cpu_session_cap(cpu_sesion), _thread_cap(thread),
|
|
|
|
_pd_label(pd_label), _name(name)
|
2016-04-20 21:12:57 +02:00
|
|
|
{ }
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
virtual ~Pager_object() { }
|
|
|
|
|
|
|
|
unsigned long badge() const { return _badge; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-20 21:12:57 +02:00
|
|
|
* Return CPU session that was used to created the thread
|
2015-03-04 21:12:14 +01:00
|
|
|
*/
|
2016-04-20 21:12:57 +02:00
|
|
|
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; }
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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, "'");
|
|
|
|
}
|
2015-03-04 21:12:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
class Genode::Pager_entrypoint : public Object_pool<Pager_object>,
|
2016-05-04 12:27:17 +02:00
|
|
|
public Thread_deprecated<PAGER_EP_STACK_SIZE>
|
2015-03-04 21:12:14 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-01-19 20:24:22 +01:00
|
|
|
Ipc_pager _pager;
|
|
|
|
Rpc_cap_factory _cap_factory;
|
2015-03-27 14:05:55 +01:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
Untyped_capability _pager_object_cap(unsigned long badge);
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2016-01-19 20:24:22 +01:00
|
|
|
* \param cap_factory factory for creating capabilities
|
2015-03-04 21:12:14 +01:00
|
|
|
* for the pager objects managed by this
|
|
|
|
* entry point
|
|
|
|
*/
|
2016-01-19 20:24:22 +01:00
|
|
|
Pager_entrypoint(Rpc_cap_factory &cap_factory)
|
|
|
|
:
|
2016-05-04 12:27:17 +02:00
|
|
|
Thread_deprecated<PAGER_EP_STACK_SIZE>("pager_ep"),
|
2016-01-19 20:24:22 +01:00
|
|
|
_cap_factory(cap_factory)
|
|
|
|
{ start(); }
|
2015-03-04 21:12:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Associate Pager_object with the entry point
|
|
|
|
*/
|
|
|
|
Pager_capability manage(Pager_object *obj);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dissolve Pager_object from entry point
|
|
|
|
*/
|
|
|
|
void dissolve(Pager_object *obj);
|
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
/**********************
|
|
|
|
** Thread interface **
|
|
|
|
**********************/
|
2015-03-04 21:12:14 +01:00
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
void entry();
|
2015-03-04 21:12:14 +01:00
|
|
|
};
|
|
|
|
|
2015-06-19 14:58:18 +02:00
|
|
|
#endif /* _CORE__INCLUDE__PAGER_H_ */
|