mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Use references for the ExceptionStackFrame argument
We require/assume that these pointers are correct. Using references is cleaner than blindly dereferencing raw pointers.
Important: The Rust book guarantees that: “At runtime, a raw pointer * and a reference pointing to the same piece of data have an identical representation.”
(cherry picked from commit 15feb9a120)
This commit is contained in:
@@ -18,7 +18,7 @@ macro_rules! handler {
|
|||||||
sub rsp, 8 // align the stack pointer
|
sub rsp, 8 // align the stack pointer
|
||||||
call $0"
|
call $0"
|
||||||
:: "i"($name as extern "C" fn(
|
:: "i"($name as extern "C" fn(
|
||||||
*const ExceptionStackFrame) -> !)
|
&ExceptionStackFrame) -> !)
|
||||||
: "rdi" : "intel");
|
: "rdi" : "intel");
|
||||||
::core::intrinsics::unreachable();
|
::core::intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ macro_rules! handler_with_error_code {
|
|||||||
sub rsp, 8 // align the stack pointer
|
sub rsp, 8 // align the stack pointer
|
||||||
call $0"
|
call $0"
|
||||||
:: "i"($name as extern "C" fn(
|
:: "i"($name as extern "C" fn(
|
||||||
*const ExceptionStackFrame, u64) -> !)
|
&ExceptionStackFrame, u64) -> !)
|
||||||
: "rdi","rsi" : "intel");
|
: "rdi","rsi" : "intel");
|
||||||
::core::intrinsics::unreachable();
|
::core::intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
@@ -72,14 +72,12 @@ struct ExceptionStackFrame {
|
|||||||
stack_segment: u64,
|
stack_segment: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn divide_by_zero_handler(stack_frame: *const ExceptionStackFrame) -> ! {
|
extern "C" fn divide_by_zero_handler(stack_frame: &ExceptionStackFrame) -> ! {
|
||||||
let stack_frame = unsafe { &*stack_frame };
|
|
||||||
println!("\nEXCEPTION: DIVIDE BY ZERO\n{:#?}", stack_frame);
|
println!("\nEXCEPTION: DIVIDE BY ZERO\n{:#?}", stack_frame);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn invalid_opcode_handler(stack_frame: *const ExceptionStackFrame) -> ! {
|
extern "C" fn invalid_opcode_handler(stack_frame: &ExceptionStackFrame) -> ! {
|
||||||
let stack_frame = unsafe { &*stack_frame };
|
|
||||||
println!("\nEXCEPTION: INVALID OPCODE at {:#x}\n{:#?}",
|
println!("\nEXCEPTION: INVALID OPCODE at {:#x}\n{:#?}",
|
||||||
stack_frame.instruction_pointer,
|
stack_frame.instruction_pointer,
|
||||||
stack_frame);
|
stack_frame);
|
||||||
@@ -96,8 +94,7 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn page_fault_handler(stack_frame: *const ExceptionStackFrame, error_code: u64) -> ! {
|
extern "C" fn page_fault_handler(stack_frame: &ExceptionStackFrame, error_code: u64) -> ! {
|
||||||
let stack_frame = unsafe { &*stack_frame };
|
|
||||||
use x86::controlregs;
|
use x86::controlregs;
|
||||||
println!("\nEXCEPTION: PAGE FAULT while accessing {:#x}\nerror code: \
|
println!("\nEXCEPTION: PAGE FAULT while accessing {:#x}\nerror code: \
|
||||||
{:?}\n{:#?}",
|
{:?}\n{:#?}",
|
||||||
|
|||||||
Reference in New Issue
Block a user