genode/repos/base-okl4/src/core/include/ipc_pager.h
Norman Feske eba9c15746 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
2018-01-17 12:14:35 +01:00

184 lines
4.3 KiB
C++

/*
* \brief OKL4 pager support for Genode
* \author Norman Feske
* \date 2009-03-31
*/
/*
* Copyright (C) 2009-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _CORE__INCLUDE__IPC_PAGER_H_
#define _CORE__INCLUDE__IPC_PAGER_H_
#include <base/cache.h>
#include <base/ipc.h>
#include <base/stdint.h>
/* base-internal includes */
#include <base/internal/okl4.h>
namespace Genode {
class Mapping
{
private:
addr_t _phys_addr { 0 };
Okl4::L4_Fpage_t _fpage { };
Okl4::L4_PhysDesc_t _phys_desc { };
public:
/**
* Constructor
*/
Mapping(addr_t dst_addr, addr_t src_addr,
Cache_attribute cacheability, bool io_mem,
unsigned l2size, bool rw, bool executable);
/**
* Construct invalid mapping
*/
Mapping();
/**
* Return flexpage describing the virtual destination address
*/
Okl4::L4_Fpage_t fpage() const { return _fpage; }
/**
* Return physical-memory descriptor describing the source location
*/
Okl4::L4_PhysDesc_t phys_desc() const { return _phys_desc; }
/**
* Prepare map operation
*
* On OKL4, we do not need to map a page core-locally to be able to
* map it into another address space. Therefore, we can leave this
* function blank.
*/
void prepare_map_operation() { }
};
/**
* Special paging server class
*/
class Ipc_pager
{
private:
Okl4::L4_MsgTag_t _faulter_tag { 0 }; /* fault flags */
Okl4::L4_ThreadId_t _last { 0 }; /* faulted thread */
Okl4::L4_Word_t _last_space { 0 }; /* space of faulted thread */
Okl4::L4_Word_t _fault_addr { 0 }; /* page-fault address */
Okl4::L4_Word_t _fault_ip { 0 }; /* instruction pointer of faulter */
Mapping _reply_mapping { }; /* page-fault answer */
protected:
/**
* Wait for short-message (register) IPC -- fault
*/
void _wait();
/**
* Send short flex page and
* wait for next short-message (register) IPC -- fault
*/
void _reply_and_wait();
public:
/**
* Wait for a new fault received as short message IPC
*/
void wait_for_fault();
/**
* Reply current fault and wait for a new one
*
* Send short flex page and wait for next short-message (register)
* IPC -- pagefault
*/
void reply_and_wait_for_fault();
/**
* Request instruction pointer of current fault
*/
addr_t fault_ip() { return _fault_ip; }
/**
* Request fault address of current fault
*/
addr_t fault_addr() { return _fault_addr & ~3; }
/**
* Set parameters for next reply
*/
void set_reply_mapping(Mapping m) { _reply_mapping = m; }
/**
* Set destination for next reply
*/
void set_reply_dst(Native_capability pager_object) {
_last.raw = pager_object.local_name(); }
/**
* Answer call without sending a flex-page mapping
*
* This function is used to acknowledge local calls from one of
* core's region-manager sessions.
*/
void acknowledge_wakeup();
/**
* Returns true if the last request was send from a core thread
*/
bool request_from_core() const
{
enum { CORE_SPACE = 0 };
return _last_space == CORE_SPACE;
}
/**
* Return badge for faulting thread
*
* Because OKL4 has no server-defined badges for fault messages, we
* interpret the sender ID as badge.
*/
unsigned long badge() const { return _last.raw; }
/**
* Return true if last fault was a write fault
*/
bool write_fault() const { return L4_Label(_faulter_tag) & 2; }
/**
* Return true if last fault was a executable fault
*/
bool exec_fault() const { return false; }
/**
* Return true if last fault was an exception
*/
bool exception() const
{
/*
* A page-fault message has one of the op bits (lower 3 bits of the
* label) set. If those bits are zero, we got an exception message.
* If the label is zero, we got an IPC wakeup message from within
* core.
*/
return L4_Label(_faulter_tag) && (L4_Label(_faulter_tag) & 0xf) == 0;
}
};
}
#endif /* _CORE__INCLUDE__IPC_PAGER_H_ */