* same with xv6
[mascara-docs.git] / i386 / MIT / course / src / git.lab / lib / pgfault.c
bloba975518f0d95f643fb11bf52b797c8924c9be6a9
1 // User-level page fault handler support.
2 // Rather than register the C page fault handler directly with the
3 // kernel as the page fault handler, we register the assembly language
4 // wrapper in pfentry.S, which in turns calls the registered C
5 // function.
7 #include <inc/lib.h>
10 // Assembly language pgfault entrypoint defined in lib/pfentry.S.
11 extern void _pgfault_upcall(void);
13 // Pointer to currently installed C-language pgfault handler.
14 void (*_pgfault_handler)(struct UTrapframe *utf);
17 // Set the page fault handler function.
18 // If there isn't one yet, _pgfault_handler will be 0.
19 // The first time we register a handler, we need to
20 // allocate an exception stack (one page of memory with its top
21 // at UXSTACKTOP), and tell the kernel to call the assembly-language
22 // _pgfault_upcall routine when a page fault occurs.
24 void
25 set_pgfault_handler(void (*handler)(struct UTrapframe *utf))
27 int r;
29 if (_pgfault_handler == 0) {
30 // First time through!
31 // LAB 4: Your code here.
32 panic("set_pgfault_handler not implemented");
35 // Save handler pointer for assembly to call.
36 _pgfault_handler = handler;