A Total Overhaul on the Lunaix's Virtual Memory Model (#26)
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / fault.h
1 #ifndef __LUNAIX_FAULT_H
2 #define __LUNAIX_FAULT_H
3
4 #include <lunaix/mm/mm.h>
5 #include <lunaix/pcontext.h>
6 #include <lunaix/mm/procvm.h>
7
8 #define RESOLVE_OK      ( 0b000001 )
9 #define NO_PREALLOC     ( 0b000010 )
10
11 struct fault_context
12 {
13     isr_param* ictx;
14
15     struct 
16     {
17         pte_t* fault_ptep;
18         ptr_t fault_va;
19         ptr_t fault_data;
20         ptr_t fault_instn;
21     };                      // arch-dependent fault state
22
23     pte_t fault_pte;        // the fault-causing pte
24     ptr_t fault_refva;      // referneced va, for ptep fault, equals to fault_va otherwise
25     pte_t resolving;        // the pte that will resolve the fault
26
27     ptr_t prealloc_pa;      // preallocated physical page in-case of empty fault-pte
28     
29     bool kernel_vmfault:1;  // faulting address that is kernel
30     bool ptep_fault:1;      // faulting address is a ptep
31     bool remote_fault:1;    // referenced faulting address is remote vms
32     bool kernel_access:1;   // kernel mem access causing the fault
33
34     struct proc_mm* mm;     // process memory space associated with fault, might be remote
35     struct mm_region* vmr;
36
37     int resolve_type;
38 };
39
40 bool
41 __arch_prepare_fault_context(struct fault_context* context);
42
43 static inline void
44 fault_resolved(struct fault_context* fault, pte_t resolved, int flags)
45 {
46     fault->resolving = resolved;
47     fault->resolve_type |= (flags | RESOLVE_OK);
48 }
49 #endif /* __LUNAIX_FAULT_H */