genode/repos/base-nova/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

147 lines
3.0 KiB
C++

/*
* \brief Low-level page-fault handling
* \author Norman Feske
* \date 2009-10-02
*/
/*
* 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_
/* Genode includes */
#include <base/cache.h>
#include <base/ipc.h>
#include <base/stdint.h>
/* NOVA includes */
#include <nova/syscalls.h>
namespace Genode {
class Mapping;
class Ipc_pager;
}
class Genode::Mapping
{
private:
addr_t const _dst_addr;
Cache_attribute const _attr;
Nova::Mem_crd const _mem_crd;
enum { PAGE_SIZE_LOG2 = 12 };
public:
/**
* Constructor
*/
Mapping(addr_t dst_addr, addr_t source_addr,
Cache_attribute c, bool /* io_mem */,
unsigned size_log2,
bool writeable, bool executable)
:
_dst_addr(dst_addr),
_attr(c),
_mem_crd(source_addr >> PAGE_SIZE_LOG2,
size_log2 - PAGE_SIZE_LOG2,
Nova::Rights(true, writeable, executable))
{ }
void prepare_map_operation() { }
Nova::Mem_crd mem_crd() const { return _mem_crd; }
bool dma() { return _attr != CACHED; };
bool write_combined() { return _attr == WRITE_COMBINED; };
addr_t dst_addr() { return _dst_addr; }
};
class Genode::Ipc_pager
{
private:
addr_t _pd_dst;
addr_t _pd_core;
addr_t _fault_ip;
addr_t _fault_addr;
addr_t _sp;
uint8_t _fault_type;
uint8_t _syscall_res;
uint8_t _normal_ipc;
public:
Ipc_pager (Nova::Utcb *, addr_t pd_dst, addr_t pd_core);
/*
* Intel manual: 6.15 EXCEPTION AND INTERRUPT REFERENCE
* Interrupt 14—Page-Fault Exception (#PF)
*/
enum {
ERR_I = 1 << 4,
ERR_R = 1 << 3,
ERR_U = 1 << 2,
ERR_W = 1 << 1,
ERR_P = 1 << 0,
};
/**
* Answer current page fault
*/
void reply_and_wait_for_fault(addr_t sm = 0UL);
/**
* Request instruction pointer of current fault
*/
addr_t fault_ip() { return _fault_ip; }
/**
* Request page-fault address of current fault
*/
addr_t fault_addr() { return _fault_addr; }
/**
* Set page-fault reply parameters
*/
void set_reply_mapping(Mapping m);
/**
* Return true if fault was a write fault
*/
bool write_fault() const { return _fault_type & ERR_W; }
/**
* Return true if fault was a non-executable fault
*/
bool exec_fault() const {
return _fault_type & ERR_P && _fault_type & ERR_I; }
/**
* Return result of delegate syscall
*/
uint8_t syscall_result() const { return _syscall_res; }
/**
* Return low level fault type info
* Intel manual: 6.15 EXCEPTION AND INTERRUPT REFERENCE
* Interrupt 14—Page-Fault Exception (#PF)
*/
addr_t fault_type() { return _fault_type; }
/**
* Return stack pointer address valid during page-fault
*/
addr_t sp() { return _sp; }
};
#endif /* _CORE__INCLUDE__IPC_PAGER_H_ */