The Pedigree Project 0.1
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PageFaultHandler Class Reference

#include <PageFaultHandler.h>

+ Inheritance diagram for PageFaultHandler:
+ Collaboration diagram for PageFaultHandler:

Classes

struct  ActiveDispatch
 
struct  DispatchCleanup
 
struct  HandlerSlot
 

Public Member Functions

bool initialise ()
 
EXPORTED_PUBLIC bool registerHandler (MemoryTrapHandler *pHandler)
 
EXPORTED_PUBLIC bool unregisterHandler (MemoryTrapHandler *pHandler)
 
virtual void interrupt (size_t interruptNumber, InterruptState &state)
 

Static Public Member Functions

static PageFaultHandler & instance ()
 

Private Types

enum class  SlotMode : size_t {
  Empty = 0 , Enabled , Draining , Deferred ,
  Retiring
}
 

Private Member Functions

 PageFaultHandler () INITIALISATION_ONLY
 
 PageFaultHandler (const PageFaultHandler &)
 
bool dispatchHandlers (InterruptState &state, uintptr_t address, bool bIsWrite, bool bWasPresent, MemoryTrapHandler *pOnlyHandler=nullptr)
 
bool retireSlot (HandlerSlot &slot, size_t expectedPublication, MemoryTrapHandler *expectedHandler)
 
bool publishDispatch (HandlerSlot &slot, void *owner, DispatchCleanup &cleanup)
 
void unpublishDispatch (DispatchCleanup &cleanup)
 
bool hasActiveDispatch (HandlerSlot &slot) const
 
bool findCurrentDispatch (void *owner, HandlerSlot *target, bool &callbackContext) const
 
virtual ~InterruptHandler ()
 

Static Private Member Functions

static size_t makePublication (size_t generation, SlotMode mode)
 
static size_t generationOf (size_t publication)
 
static SlotMode modeOf (size_t publication)
 
static void abandonedHandlerCleanup (void *context)
 
static void * currentDispatchOwner ()
 

Private Attributes

HandlerSlot m_Handlers [MaxMemoryTrapHandlers]
 
ActiveDispatch m_ActiveDispatches [MaxActiveDispatches]
 
WaitQueue m_DispatchWaiters
 
Spinlock m_HandlerLock
 

Static Private Attributes

static const size_t MaxMemoryTrapHandlers = 16
 
static const size_t MaxActiveDispatches = 64
 
static const size_t ModeBits = 3
 
static const size_t ModeMask = (1 << ModeBits) - 1
 
static const size_t GenerationShift = ModeBits
 
static EXPORTED_PUBLIC PageFaultHandler m_Instance
 

Detailed Description

The x86 Page Fault Exception handler.

Definition at line 53 of file PageFaultHandler.h.

Member Enumeration Documentation

◆ SlotMode

enum class PageFaultHandler::SlotMode : size_t
strongprivate

Definition at line 128 of file PageFaultHandler.h.

Constructor & Destructor Documentation

◆ PageFaultHandler() [1/2]

PageFaultHandler::PageFaultHandler ( )
private

The default constructor.

Definition at line 37 of file PageFaultHandler.cc.

◆ PageFaultHandler() [2/2]

PageFaultHandler::PageFaultHandler ( const PageFaultHandler &  )
private

The copy constructor. Note not implemented.

Member Function Documentation

◆ abandonedHandlerCleanup()

void PageFaultHandler::abandonedHandlerCleanup ( void *  context)
staticprivate

Definition at line 140 of file PageFaultHandler.cc.

◆ currentDispatchOwner()

void * PageFaultHandler::currentDispatchOwner ( )
staticprivate

Definition at line 192 of file PageFaultHandler.cc.

◆ dispatchHandlers()

bool PageFaultHandler::dispatchHandlers ( InterruptState &  state,
uintptr_t  address,
bool  bIsWrite,
bool  bWasPresent,
MemoryTrapHandler *  pOnlyHandler = nullptr 
)
private

Definition at line 381 of file PageFaultHandler.cc.

◆ findCurrentDispatch()

bool PageFaultHandler::findCurrentDispatch ( void *  owner,
HandlerSlot *  target,
bool &  callbackContext 
) const
private

Definition at line 165 of file PageFaultHandler.cc.

◆ generationOf()

size_t PageFaultHandler::generationOf ( size_t  publication)
staticprivate

Definition at line 44 of file PageFaultHandler.cc.

◆ hasActiveDispatch()

bool PageFaultHandler::hasActiveDispatch ( HandlerSlot &  slot) const
private

Definition at line 147 of file PageFaultHandler.cc.

◆ initialise()

bool PageFaultHandler::initialise ( )

Register the PageFaultHandler with the InterruptManager.

Returns
true if sucessful, false otherwise.

Definition at line 15 of file arm64/PageFaultHandler.cc.

References InterruptManager::instance(), and InterruptManager::registerInterruptHandler().

Referenced by ProcessorBase::initialise1().

+ Here is the caller graph for this function:

◆ instance()

static PageFaultHandler & PageFaultHandler::instance ( )
inlinestatic

Get the PageFaultHandler instance

Returns
the PageFaultHandler instance.

Definition at line 57 of file PageFaultHandler.h.

References m_Instance.

Referenced by DLTrapHandler::DLTrapHandler(), ProcessorBase::initialise1(), MemoryMapManager::MemoryMapManager(), and DLTrapHandler::~DLTrapHandler().

+ Here is the caller graph for this function:

◆ interrupt()

void PageFaultHandler::interrupt ( size_t  nInterruptNumber,
InterruptState &  state 
)
virtual

Called when the handler is registered with the interrupt manager and the interrupt occurred

Parameters
[in]nInterruptNumberthe interrupt number
[in]statereference to the state before the interrupt
Todo:
probably can just skip checking for traps across the entire kernel address space?

Implements InterruptHandler.

Definition at line 19 of file arm64/PageFaultHandler.cc.

References Thread::deferSubsystemException(), Thread::getParent(), VirtualAddressSpace::handleCopyOnWriteFault(), Hex, ProcessorBase::information(), ProcessorBase::m_Initialised, and panic().

◆ makePublication()

size_t PageFaultHandler::makePublication ( size_t  generation,
SlotMode  mode 
)
staticprivate

Definition at line 40 of file PageFaultHandler.cc.

◆ modeOf()

PageFaultHandler::SlotMode PageFaultHandler::modeOf ( size_t  publication)
staticprivate

Definition at line 48 of file PageFaultHandler.cc.

◆ publishDispatch()

bool PageFaultHandler::publishDispatch ( HandlerSlot &  slot,
void *  owner,
DispatchCleanup &  cleanup 
)
private

Definition at line 76 of file PageFaultHandler.cc.

◆ registerHandler()

bool PageFaultHandler::registerHandler ( MemoryTrapHandler *  pHandler)

Registers a trap handler.

Duplicate handlers and registrations beyond the fixed registry capacity are rejected.

Definition at line 198 of file PageFaultHandler.cc.

References m_Handlers.

Referenced by DLTrapHandler::DLTrapHandler(), and MemoryMapManager::MemoryMapManager().

+ Here is the caller graph for this function:

◆ retireSlot()

bool PageFaultHandler::retireSlot ( HandlerSlot &  slot,
size_t  expectedPublication,
MemoryTrapHandler *  expectedHandler 
)
private

Definition at line 52 of file PageFaultHandler.cc.

◆ unpublishDispatch()

void PageFaultHandler::unpublishDispatch ( DispatchCleanup &  cleanup)
private

Definition at line 98 of file PageFaultHandler.cc.

◆ unregisterHandler()

bool PageFaultHandler::unregisterHandler ( MemoryTrapHandler *  pHandler)

Stops new callbacks and waits for callbacks which already pinned the handler to return.

A handler cannot synchronously drain its own active callback. Such a request returns false and retires the handler when that callback returns. A synchronous caller must not retain a resource which the active handler needs to finish.

Definition at line 238 of file PageFaultHandler.cc.

References Spinlock::acquire(), ProcessorBase::getInterrupts(), ProcessorBase::information(), m_Handlers, and Spinlock::release().

Referenced by DLTrapHandler::~DLTrapHandler().

+ Here is the caller graph for this function:

Member Data Documentation

◆ GenerationShift

const size_t PageFaultHandler::GenerationShift = ModeBits
staticprivate

Definition at line 138 of file PageFaultHandler.h.

◆ m_ActiveDispatches

ActiveDispatch PageFaultHandler::m_ActiveDispatches[MaxActiveDispatches]
private

Definition at line 182 of file PageFaultHandler.h.

◆ m_DispatchWaiters

WaitQueue PageFaultHandler::m_DispatchWaiters
private

Definition at line 183 of file PageFaultHandler.h.

◆ m_HandlerLock

Spinlock PageFaultHandler::m_HandlerLock
private

Definition at line 184 of file PageFaultHandler.h.

◆ m_Handlers

HandlerSlot PageFaultHandler::m_Handlers[MaxMemoryTrapHandlers]
private

Fixed storage keeps the fault path allocation-free.

Definition at line 181 of file PageFaultHandler.h.

Referenced by registerHandler(), and unregisterHandler().

◆ m_Instance

PageFaultHandler PageFaultHandler::m_Instance
staticprivate

The PageFaultHandler instance

Definition at line 193 of file PageFaultHandler.h.

Referenced by instance().

◆ MaxActiveDispatches

const size_t PageFaultHandler::MaxActiveDispatches = 64
staticprivate

Definition at line 126 of file PageFaultHandler.h.

◆ MaxMemoryTrapHandlers

const size_t PageFaultHandler::MaxMemoryTrapHandlers = 16
staticprivate

Definition at line 125 of file PageFaultHandler.h.

◆ ModeBits

const size_t PageFaultHandler::ModeBits = 3
staticprivate

Definition at line 136 of file PageFaultHandler.h.

◆ ModeMask

const size_t PageFaultHandler::ModeMask = (1 << ModeBits) - 1
staticprivate

Definition at line 137 of file PageFaultHandler.h.


The documentation for this class was generated from the following files: