Fix: stale dnode caching instance cause locked-up upon accessing (#52)
[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/mm/page.h>
6 #include <lunaix/mm/procvm.h>
7 #include <lunaix/hart_state.h>
8
9 #define RESOLVE_OK      ( 0b000001 )
10 #define NO_PREALLOC     ( 0b000010 )
11
12 struct fault_context
13 {
14     struct hart_state* hstate;
15
16     struct 
17     {
18         pte_t* fault_ptep;
19         ptr_t fault_va;
20         ptr_t fault_data;
21         ptr_t fault_instn;
22     };                      // arch-dependent fault state
23
24     pte_t fault_pte;        // the fault-causing pte
25     ptr_t fault_refva;      // referneced va, for ptep fault, equals to fault_va otherwise
26     pte_t resolving;        // the pte that will resolve the fault
27
28     struct leaflet* prealloc;      // preallocated physical page in-case of empty fault-pte
29     
30     struct 
31     {
32         bool kernel_vmfault:1;  // faulting address that is kernel
33         bool ptep_fault:1;      // faulting address is a ptep
34         bool remote_fault:1;    // referenced faulting address is remote vms
35         bool kernel_access:1;   // kernel mem access causing the fault
36     };
37
38     struct proc_mm* mm;     // process memory space associated with fault, might be remote
39     struct mm_region* vmr;
40
41     int resolve_type;
42 };
43
44 static inline void
45 fault_resolved(struct fault_context* fault, int flags)
46 {
47     fault->resolve_type |= (flags | RESOLVE_OK);
48 }
49
50 bool
51 handle_page_fault(struct fault_context* fault);
52
53 void noret
54 fault_resolving_failed(struct fault_context* fault);
55
56 #endif /* __LUNAIX_FAULT_H */