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