1/* @title: Page Fault */
2#pragma once
3#include <irq/irq.h>
4#include <types/types.h>
5
6struct page;
7
8enum page_fault_access { PAGE_FAULT_READ, PAGE_FAULT_WRITE, PAGE_FAULT_EXEC };
9
10enum page_fault_error_code : uint64_t {
11 PAGE_FAULT_EC_PRESENT = 1ULL << 0, /* P: protection violation, not
12 a not-present page */
13 PAGE_FAULT_EC_WRITE = 1ULL << 1, /* W/R: access was a write */
14 PAGE_FAULT_EC_USER = 1ULL << 2, /* U/S: fault taken in user mode */
15 PAGE_FAULT_EC_RESERVED = 1ULL << 3, /* RSVD: reserved bit set in a
16 paging-structure entry */
17 PAGE_FAULT_EC_INSTRUCTION = 1ULL << 4, /* I/D: instruction fetch */
18 PAGE_FAULT_EC_PROTECTION_KEY = 1ULL << 5, /* PK: protection-key block */
19 PAGE_FAULT_EC_SHADOW_STACK = 1ULL << 6, /* SS: shadow-stack access */
20 PAGE_FAULT_EC_SGX = 1ULL << 15, /* SGX: enclave violation */
21};
22
23struct page_fault_info {
24 vaddr_t addr;
25 enum page_fault_access access;
26 bool was_present;
27 bool user;
28};
29
30struct page_fault_handler_ops {
31 bool (*is_valid_fault)(struct page_fault_info *pfi);
32 bool (*update_after_map)(vaddr_t vaddr, struct page *page);
33 paddr_t (*alloc_pages)(vaddr_t vaddr, uint8_t order);
34};
35
36struct page_fault_handler {
37 struct page_fault_handler_ops *ops;
38};
39
40struct page_fault_scratch_buffer {
41 vaddr_t virt;
42 uint64_t error_code;
43};
44
45enum irq_result page_fault_isr(void *context, uint8_t vector,
46 struct irq_context *rsp);
47