MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / page_fault_handler

Function page_fault_handler

kernel/src/interrupts.rs:249–274  ·  view source on GitHub ↗
(
    stack_frame: InterruptStackFrame,
    error_code: PageFaultErrorCode,
)

Source from the content-addressed store, hash-verified

247use crate::hlt_loop;
248
249extern "x86-interrupt" fn page_fault_handler(
250 stack_frame: InterruptStackFrame,
251 error_code: PageFaultErrorCode,
252) {
253 use x86_64::registers::control::Cr2;
254 let accessed_virtaddr = Cr2::read();
255
256 if error_code == (PageFaultErrorCode::PROTECTION_VIOLATION |
257 PageFaultErrorCode::CAUSED_BY_WRITE |
258 PageFaultErrorCode::USER_MODE) {
259 // User code tried to access a read-only page
260 // Missing stack or heap frame
261
262 if let Err(msg) = memory::allocate_missing_ondemand_frame(accessed_virtaddr) {
263 println!("Page fault error: {}", msg);
264 hlt_loop();
265 }
266 } else {
267 println!("EXCEPTION: PAGE FAULT");
268 println!("Accessed Address: {:?}", accessed_virtaddr);
269 println!("Error Code: {:?}", error_code);
270 println!("{:#?}", stack_frame);
271
272 hlt_loop();
273 }
274}
275
276extern "x86-interrupt" fn general_protection_fault_handler(
277 stack_frame: InterruptStackFrame,

Callers

nothing calls this directly

Calls 2

hlt_loopFunction · 0.85

Tested by

no test coverage detected