Fix a bunch of errors and warnings after moving to the 2024 edition

This commit is contained in:
bjorn3
2025-09-10 16:26:32 +02:00
parent cea93f7647
commit fe1c2f460e
6 changed files with 68 additions and 67 deletions
+38 -30
View File
@@ -9,7 +9,7 @@ use crate::{
interrupt_stack!(divide_by_zero, |stack| {
println!("Divide by zero");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 0,
..Default::default()
@@ -81,7 +81,7 @@ interrupt_stack!(breakpoint, |stack| {
interrupt_stack!(overflow, |stack| {
println!("Overflow trap");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 4,
..Default::default()
@@ -91,7 +91,7 @@ interrupt_stack!(overflow, |stack| {
interrupt_stack!(bound_range, |stack| {
println!("Bound range exceeded fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 5,
..Default::default()
@@ -101,7 +101,7 @@ interrupt_stack!(bound_range, |stack| {
interrupt_stack!(invalid_opcode, |stack| {
println!("Invalid opcode fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 6,
..Default::default()
@@ -111,7 +111,7 @@ interrupt_stack!(invalid_opcode, |stack| {
interrupt_stack!(device_not_available, |stack| {
println!("Device not available fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 7,
..Default::default()
@@ -121,17 +121,19 @@ interrupt_stack!(device_not_available, |stack| {
interrupt_error!(double_fault, |stack, _code| {
println!("Double fault");
stack.dump();
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
unsafe {
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
}
}
});
interrupt_error!(invalid_tss, |stack, code| {
println!("Invalid TSS fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 10,
code,
@@ -142,7 +144,7 @@ interrupt_error!(invalid_tss, |stack, code| {
interrupt_error!(segment_not_present, |stack, code| {
println!("Segment not present fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 11,
code,
@@ -153,7 +155,7 @@ interrupt_error!(segment_not_present, |stack, code| {
interrupt_error!(stack_segment, |stack, code| {
println!("Stack segment fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 12,
code,
@@ -164,7 +166,7 @@ interrupt_error!(stack_segment, |stack, code| {
interrupt_error!(protection, |stack, code| {
println!("Protection fault code={:#0x}", code);
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 13,
code,
@@ -201,7 +203,7 @@ interrupt_error!(page, |stack, code| {
if crate::memory::page_fault_handler(stack, generic_flags, cr2).is_err() {
println!("Page fault: {:>016X} {:#?}", cr2.data(), arch_flags);
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 14,
code,
@@ -213,7 +215,7 @@ interrupt_error!(page, |stack, code| {
interrupt_stack!(fpu_fault, |stack| {
println!("FPU floating point fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 16,
..Default::default()
@@ -223,7 +225,7 @@ interrupt_stack!(fpu_fault, |stack| {
interrupt_error!(alignment_check, |stack, code| {
println!("Alignment check fault");
stack.dump();
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 17,
code,
@@ -234,10 +236,12 @@ interrupt_error!(alignment_check, |stack, code| {
interrupt_stack!(machine_check, @paranoid, |stack| {
println!("Machine check fault");
stack.dump();
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
unsafe {
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
}
}
});
@@ -245,9 +249,9 @@ interrupt_stack!(simd, |stack| {
println!("SIMD floating point fault");
stack.dump();
let mut mxcsr = 0_usize;
core::arch::asm!("stmxcsr [{}]", in(reg) core::ptr::addr_of_mut!(mxcsr));
unsafe { core::arch::asm!("stmxcsr [{}]", in(reg) core::ptr::addr_of_mut!(mxcsr)) };
println!("MXCSR {:#0x}", mxcsr);
stack_trace();
unsafe { stack_trace() };
excp_handler(Exception {
kind: 19,
..Default::default()
@@ -257,19 +261,23 @@ interrupt_stack!(simd, |stack| {
interrupt_stack!(virtualization, |stack| {
println!("Virtualization fault");
stack.dump();
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
unsafe {
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
}
}
});
interrupt_error!(security, |stack, _code| {
println!("Security exception");
stack.dump();
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
unsafe {
stack_trace();
loop {
interrupt::disable();
interrupt::halt();
}
}
});
+4 -4
View File
@@ -363,9 +363,9 @@ macro_rules! interrupt_stack {
($name:ident, $save1:ident!, $save2:ident!, $rstor2:ident!, $rstor1:ident!, is_paranoid: $is_paranoid:expr_2021, |$stack:ident| $code:block) => {
#[naked]
pub unsafe extern "C" fn $name() { unsafe {
unsafe extern "C" fn inner($stack: &mut $crate::arch::x86_64::interrupt::InterruptStack) { unsafe {
unsafe extern "C" fn inner($stack: &mut $crate::arch::x86_64::interrupt::InterruptStack) {
$code
}}
}
core::arch::naked_asm!(concat!(
// Clear direction flag, required by ABI when running any Rust code in the kernel.
"cld;",
@@ -456,9 +456,9 @@ macro_rules! interrupt_error {
($name:ident, |$stack:ident, $error_code:ident| $code:block) => {
#[naked]
pub unsafe extern "C" fn $name() { unsafe {
unsafe extern "C" fn inner($stack: &mut $crate::arch::x86_64::interrupt::handler::InterruptStack, $error_code: usize) { unsafe {
unsafe extern "C" fn inner($stack: &mut $crate::arch::x86_64::interrupt::handler::InterruptStack, $error_code: usize) {
$code
}}
}
core::arch::naked_asm!(concat!(
// Clear direction flag, required by ABI when running any Rust code in the kernel.
+2 -2
View File
@@ -174,7 +174,7 @@ interrupt_stack!(pit_stack, |_stack| {
*time::OFFSET.lock() += pit::RATE;
}
eoi(0);
unsafe { eoi(0) };
// Wake up other CPUs
ipi(IpiKind::Pit, IpiTarget::Other);
@@ -309,7 +309,7 @@ interrupt_error!(generic_irq, |_stack, code| {
// (containing lots of useless NOPs).
irq_trigger((code as i32).wrapping_add(128) as u8);
lapic_eoi();
unsafe { lapic_eoi() };
});
core::arch::global_asm!("
+12 -18
View File
@@ -55,15 +55,12 @@ pub fn is_reserved(cpu_id: LogicalCpuId, index: u8) -> bool {
let byte_index = index / 32;
let bit = index % 32;
{
&IDTS
.read()
.as_ref()
.unwrap()
.get(&cpu_id)
.unwrap()
.reservations[usize::from(byte_index)]
}
IDTS.read()
.as_ref()
.unwrap()
.get(&cpu_id)
.unwrap()
.reservations[usize::from(byte_index)]
.load(Ordering::Acquire)
& (1 << bit)
!= 0
@@ -74,15 +71,12 @@ pub fn set_reserved(cpu_id: LogicalCpuId, index: u8, reserved: bool) {
let byte_index = index / 32;
let bit = index % 32;
{
&IDTS
.read()
.as_ref()
.unwrap()
.get(&cpu_id)
.unwrap()
.reservations[usize::from(byte_index)]
}
IDTS.read()
.as_ref()
.unwrap()
.get(&cpu_id)
.unwrap()
.reservations[usize::from(byte_index)]
.fetch_or(u32::from(reserved) << bit, Ordering::AcqRel);
}
+1
View File
@@ -39,6 +39,7 @@
#![deny(unreachable_patterns)]
// Ensure that all must_use results are used
#![deny(unused_must_use)]
#![warn(static_mut_refs)] // FIXME deny once all occurences are fixed
#![feature(allocator_api)]
#![feature(int_roundings)]
#![feature(iter_next_chunk)]
+11 -13
View File
@@ -108,21 +108,19 @@ impl<const WRITE: bool> UserSlice<true, WRITE> {
}
}
pub unsafe fn read_exact<T>(self) -> Result<T> {
unsafe {
let mut t: T = core::mem::zeroed();
let slice = unsafe {
core::slice::from_raw_parts_mut(
(&mut t as *mut T).cast::<u8>(),
core::mem::size_of::<T>(),
)
};
let mut t: T = unsafe { core::mem::zeroed() };
let slice = unsafe {
core::slice::from_raw_parts_mut(
(&mut t as *mut T).cast::<u8>(),
core::mem::size_of::<T>(),
)
};
self.limit(core::mem::size_of::<T>())
.ok_or(Error::new(EINVAL))?
.copy_to_slice(slice)?;
self.limit(core::mem::size_of::<T>())
.ok_or(Error::new(EINVAL))?
.copy_to_slice(slice)?;
Ok(t)
}
Ok(t)
}
pub fn copy_common_bytes_to_slice(self, slice: &mut [u8]) -> Result<usize> {
let min = core::cmp::min(self.len(), slice.len());