Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2025-04-10"
channel = "nightly-2025-04-22"
components = [ "rustfmt", "rust-src", "llvm-tools", "clippy", "miri", "rust-analyzer" ]
132 changes: 63 additions & 69 deletions src/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,19 @@ struct TrapFrame {

macro_rules! gen_stub {
($name:ident, $vecnum:expr) => {
#[naked]
#[unsafe(naked)]
unsafe extern "C" fn $name() -> ! {
unsafe {
naked_asm!("pushq $0; pushq ${}; jmp {}",
const $vecnum, sym alltraps,
options(att_syntax))
}
naked_asm!("pushq $0; pushq ${}; jmp {}",
const $vecnum, sym alltraps,
options(att_syntax))
}
};
($name:ident, $vecnum:expr, err) => {
#[naked]
#[unsafe(naked)]
unsafe extern "C" fn $name() -> ! {
unsafe {
naked_asm!("pushq ${}; jmp {}",
const $vecnum, sym alltraps,
options(att_syntax))
}
naked_asm!("pushq ${}; jmp {}",
const $vecnum, sym alltraps,
options(att_syntax))
}
};
}
Expand Down Expand Up @@ -166,64 +162,62 @@ seq!(N in 0..=255 {
/// number and a padding zero for exceptions that don't push a
/// hardware error are pushed by the trap stubs before jumping
/// here.
#[naked]
#[unsafe(naked)]
unsafe extern "C" fn alltraps() -> ! {
unsafe {
naked_asm!(r#"
// Save the x86 segmentation registers.
subq $32, %rsp
movq $0, 24(%rsp);
movw %gs, 24(%rsp);
movq $0, 16(%rsp);
movw %fs, 16(%rsp);
movq $0, 8(%rsp);
movw %es, 8(%rsp);
movq $0, (%rsp);
movw %ds, (%rsp);
pushq %r15;
pushq %r14;
pushq %r13;
pushq %r12;
pushq %r11;
pushq %r10;
pushq %r9;
pushq %r8;
pushq %rbp;
pushq %rdi;
pushq %rsi;
pushq %rdx;
pushq %rcx;
pushq %rbx;
pushq %rax;
movq %rsp, %rdi;
callq {trap};
popq %rax;
popq %rbx;
popq %rcx;
popq %rdx;
popq %rsi;
popq %rdi;
popq %rbp;
popq %r8;
popq %r9;
popq %r10;
popq %r11;
popq %r12;
popq %r13;
popq %r14;
popq %r15;
movw (%rsp), %ds;
movw 8(%rsp), %es;
movw 16(%rsp), %fs;
movw 24(%rsp), %gs;
addq $32, %rsp;
// Pop vector and error word.
addq $16, %rsp;
iretq;
"#,
trap = sym trap,
options(att_syntax))
}
naked_asm!(r#"
// Save the x86 segmentation registers.
subq $32, %rsp
movq $0, 24(%rsp);
movw %gs, 24(%rsp);
movq $0, 16(%rsp);
movw %fs, 16(%rsp);
movq $0, 8(%rsp);
movw %es, 8(%rsp);
movq $0, (%rsp);
movw %ds, (%rsp);
pushq %r15;
pushq %r14;
pushq %r13;
pushq %r12;
pushq %r11;
pushq %r10;
pushq %r9;
pushq %r8;
pushq %rbp;
pushq %rdi;
pushq %rsi;
pushq %rdx;
pushq %rcx;
pushq %rbx;
pushq %rax;
movq %rsp, %rdi;
callq {trap};
popq %rax;
popq %rbx;
popq %rcx;
popq %rdx;
popq %rsi;
popq %rdi;
popq %rbp;
popq %r8;
popq %r9;
popq %r10;
popq %r11;
popq %r12;
popq %r13;
popq %r14;
popq %r15;
movw (%rsp), %ds;
movw 8(%rsp), %es;
movw 16(%rsp), %fs;
movw 24(%rsp), %gs;
addq $32, %rsp;
// Pop vector and error word.
addq $16, %rsp;
iretq;
"#,
trap = sym trap,
options(att_syntax))
}

/// The Interrupt Descriptor Table.
Expand Down
4 changes: 0 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![feature(allocator_api)]
#![feature(naked_functions)]
#![feature(pointer_is_aligned_to)]
#![feature(ptr_mask)]
#![feature(sync_unsafe_cell)]
#![feature(type_alias_impl_trait)]
#![cfg_attr(not(any(test, clippy)), no_std)]
#![cfg_attr(not(test), no_main)]
#![forbid(unsafe_op_in_unsafe_fn)]
Expand Down
28 changes: 8 additions & 20 deletions src/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,7 @@ impl InnerTable for PML4 {
let entry = self.entries[Self::index(va)];
entry.p().then(|| {
let p = unsafe { entry.virt_addr() };
assert!(
!p.is_null() && p.is_aligned_to(core::mem::align_of::<PML3>()),
);
assert!(!p.is_null() && p.cast::<PML3>().is_aligned());
unsafe { &*TableAlloc::try_with_addr(p.addr()).unwrap() }
})
}
Expand All @@ -643,9 +641,7 @@ impl InnerTable for PML4 {
let entry = self.entries[Self::index(va)];
entry.p().then(|| {
let p = unsafe { entry.virt_addr() };
assert!(
!p.is_null() && p.is_aligned_to(core::mem::align_of::<PML3>())
);
assert!(!p.is_null() && p.cast::<PML3>().is_aligned());
unsafe { &mut *TableAlloc::try_with_addr(p.addr()).unwrap() }
})
}
Expand Down Expand Up @@ -731,9 +727,7 @@ impl InnerTable for PML3 {
let entry = self.entries[Self::index(va)];
(entry.p() && !entry.h()).then(|| {
let p = unsafe { entry.virt_addr() };
assert!(
!p.is_null() && p.is_aligned_to(core::mem::align_of::<PML2>()),
);
assert!(!p.is_null() && p.cast::<PML2>().is_aligned());
unsafe { &*TableAlloc::try_with_addr(p.addr()).unwrap() }
})
}
Expand All @@ -742,9 +736,7 @@ impl InnerTable for PML3 {
let entry = self.entries[Self::index(va)];
(entry.p() && !entry.h()).then(|| {
let p = unsafe { entry.virt_addr() };
assert!(
!p.is_null() && p.is_aligned_to(core::mem::align_of::<PML2>())
);
assert!(!p.is_null() && p.cast::<PML2>().is_aligned());
unsafe { &mut *TableAlloc::try_with_addr(p.addr()).unwrap() }
})
}
Expand Down Expand Up @@ -859,9 +851,7 @@ impl InnerTable for PML2 {
let entry = self.entries[Self::index(va)];
(entry.p() && !entry.h()).then(|| {
let p = unsafe { entry.virt_addr() };
assert!(
!p.is_null() && p.is_aligned_to(core::mem::align_of::<PML1>()),
);
assert!(!p.is_null() && p.cast::<PML1>().is_aligned());
unsafe { &*TableAlloc::try_with_addr(p.addr()).unwrap() }
})
}
Expand All @@ -870,9 +860,7 @@ impl InnerTable for PML2 {
let entry = self.entries[Self::index(va)];
(entry.p() && !entry.h()).then(|| {
let p = unsafe { entry.virt_addr() };
assert!(
!p.is_null() && p.is_aligned_to(core::mem::align_of::<PML1>())
);
assert!(!p.is_null() && p.cast::<PML1>().is_aligned());
unsafe { &mut *TableAlloc::try_with_addr(p.addr()).unwrap() }
})
}
Expand Down Expand Up @@ -1240,7 +1228,7 @@ impl PageTable {
return Err(Error::Unmapped);
};
let ptr = core::ptr::with_exposed_provenance_mut::<()>(va);
if !ptr.is_aligned_to(core::mem::align_of::<T>()) {
if !ptr.cast::<T>().is_aligned() {
return Err(Error::PtrAlign);
}
Ok(ptr as *mut T)
Expand Down Expand Up @@ -1675,7 +1663,7 @@ mod arena {
}
let base = page_allocator.base();
let ptr = base.with_addr(addr);
if !ptr.is_aligned_to(core::mem::align_of::<T>()) {
if !ptr.cast::<T>().is_aligned() {
return Err(Error::PtrAlign);
}
Ok(ptr as *mut T)
Expand Down