Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::hardwarecommunication::PageFaultHandler Class Reference

Handles a page fault exception. More...

#include <interrupts.h>

Inheritance diagram for MaxOS::hardwarecommunication::PageFaultHandler:
MaxOS::hardwarecommunication::ExceptionHandler MaxOS::hardwarecommunication::InterruptHandler

Public Member Functions

 PageFaultHandler ()
 Create a new PageFaultHandler.
 
string get_message (system::cpu_status_t *status) final
 Get an human readable error message explaining this exception.
 
- Public Member Functions inherited from MaxOS::hardwarecommunication::ExceptionHandler
 ExceptionHandler (uint8_t interrupt_number)
 Create a new base exception handler for an interrupt.
 
 ~ExceptionHandler ()
 
virtual system::cpu_status_t * handle_interrupt (system::cpu_status_t *status)
 Handle the interrupt relating to this exception.
 
- Public Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
virtual void handle_interrupt ()
 Handles an interrupt.
 

Additional Inherited Members

- Protected Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
 InterruptHandler (uint8_t interrupt_number, int64_t redirect=-1, uint64_t redirect_index=0)
 Creates a new interrupt handler and registers it with the interrupt manager.
 
virtual ~InterruptHandler ()
 Destroys the interrupt handler and unregisters it from the interrupt manager.
 
- Protected Attributes inherited from MaxOS::hardwarecommunication::InterruptHandler
uint8_t m_interrupt_number
 The interrupt number this handler handles.
 

Detailed Description

Handles a page fault exception.

Definition at line 115 of file interrupts.h.

Constructor & Destructor Documentation

◆ PageFaultHandler()

MaxOS::hardwarecommunication::PageFaultHandler::PageFaultHandler ( )
inline

Create a new PageFaultHandler.

Definition at line 119 of file interrupts.h.

119: ExceptionHandler(0x0E) { }
ExceptionHandler(uint8_t interrupt_number)
Create a new base exception handler for an interrupt.

Member Function Documentation

◆ get_message()

string PageFaultHandler::get_message ( system::cpu_status_t *  status)
finalvirtual

Get an human readable error message explaining this exception.

Parameters
statusThe CPU state at time of exception
Returns
The error message

Reimplemented from MaxOS::hardwarecommunication::ExceptionHandler.

Definition at line 176 of file interrupts.cpp.

176 {
177
178 // Extract the information about the fault
179 bool present = (status->error_code & 0x1) != 0;
180 bool write = (status->error_code & 0x2) != 0;
181 bool user_mode = (status->error_code & 0x4) != 0;
182 bool reserved_write = (status->error_code & 0x8) != 0;
183 bool instruction_fetch = (status->error_code & 0x10) != 0;
184 uint64_t faulting_address;
185 asm volatile("movq %%cr2, %0" : "=r" (faulting_address));
186
187 return StringBuilder() << "Page Fault: " << (user_mode ? "user" : "kernel") << " code at 0x" << status->rip << " tried to " << (write ? "write" : "read") << " address 0x" << faulting_address << " which is " << (present ? "" : "not") << " mapped and " << (reserved_write ? "" : "not") << " reserved. " << " (instruction fetch: " << (instruction_fetch ? "Yes" : "No") << ")\n";
188}

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