diff --git a/Cargo.lock b/Cargo.lock index 23c3f36..7b26ac6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -218,9 +218,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.171" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "log" @@ -245,9 +245,9 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -419,7 +419,7 @@ dependencies = [ [[package]] name = "xmodem" version = "0.4.0" -source = "git+https://github.com/oxidecomputer/xmodem.rs#b066322e83df764e12e668ec2c1ff6b67cb752f6" +source = "git+https://github.com/oxidecomputer/xmodem.rs#e0e71d32dcfd92076f913fe3267e70067ee57d2d" dependencies = [ "crc16", "log", diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0418098..87858dd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -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" ] diff --git a/src/idt.rs b/src/idt.rs index a048fa8..da512d1 100644 --- a/src/idt.rs +++ b/src/idt.rs @@ -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)) } }; } @@ -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. diff --git a/src/main.rs b/src/main.rs index 2cee462..a3fa496 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)] diff --git a/src/mmu.rs b/src/mmu.rs index 1a740d4..0bca8b3 100644 --- a/src/mmu.rs +++ b/src/mmu.rs @@ -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::()), - ); + assert!(!p.is_null() && p.cast::().is_aligned()); unsafe { &*TableAlloc::try_with_addr(p.addr()).unwrap() } }) } @@ -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::()) - ); + assert!(!p.is_null() && p.cast::().is_aligned()); unsafe { &mut *TableAlloc::try_with_addr(p.addr()).unwrap() } }) } @@ -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::()), - ); + assert!(!p.is_null() && p.cast::().is_aligned()); unsafe { &*TableAlloc::try_with_addr(p.addr()).unwrap() } }) } @@ -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::()) - ); + assert!(!p.is_null() && p.cast::().is_aligned()); unsafe { &mut *TableAlloc::try_with_addr(p.addr()).unwrap() } }) } @@ -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::()), - ); + assert!(!p.is_null() && p.cast::().is_aligned()); unsafe { &*TableAlloc::try_with_addr(p.addr()).unwrap() } }) } @@ -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::()) - ); + assert!(!p.is_null() && p.cast::().is_aligned()); unsafe { &mut *TableAlloc::try_with_addr(p.addr()).unwrap() } }) } @@ -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::()) { + if !ptr.cast::().is_aligned() { return Err(Error::PtrAlign); } Ok(ptr as *mut T) @@ -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::()) { + if !ptr.cast::().is_aligned() { return Err(Error::PtrAlign); } Ok(ptr as *mut T)