* same with xv6
[mascara-docs.git] / i386 / MIT / course / src / git.lab / user / faultallocbad.c
blob2c0898a379c282ee2472ecf0ba9178da3e23f32d
1 // test user-level fault handler -- alloc pages to fix faults
2 // doesn't work because we sys_cputs instead of cprintf (exercise: why?)
4 #include <inc/lib.h>
6 void
7 handler(struct UTrapframe *utf)
9 int r;
10 void *addr = (void*)utf->utf_fault_va;
12 cprintf("fault %x\n", addr);
13 if ((r = sys_page_alloc(0, ROUNDDOWN(addr, PGSIZE),
14 PTE_P|PTE_U|PTE_W)) < 0)
15 panic("allocating at %x in page fault handler: %e", addr, r);
16 snprintf((char*) addr, 100, "this string was faulted in at %x", addr);
19 void
20 umain(int argc, char **argv)
22 set_pgfault_handler(handler);
23 sys_cputs((char*)0xDEADBEEF, 4);