diff --git a/Cargo.lock b/Cargo.lock index dbf71bf0..ab94c9cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,6 @@ dependencies = [ name = "abi-lib" version = "0.1.0" dependencies = [ - "compiler_builtins", "rustc-std-workspace-core", ] @@ -33,7 +32,6 @@ dependencies = [ name = "abi-serde" version = "0.1.0" dependencies = [ - "compiler_builtins", "rustc-std-workspace-alloc", "rustc-std-workspace-core", ] @@ -407,15 +405,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" -[[package]] -name = "compiler_builtins" -version = "0.1.146" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97117b1434b79833f39a5fabdf82f890bd98c1988334dea1cb67f7e627fa311" -dependencies = [ - "rustc-std-workspace-core", -] - [[package]] name = "console" version = "0.15.10" @@ -1291,9 +1280,8 @@ dependencies = [ [[package]] name = "libm" version = "0.2.8" -source = "git+https://git.alnyan.me/yggdrasil/libm.git#ace5825d9683d2bf4a71c8f18f2c854660c297b2" +source = "git+https://git.alnyan.me/yggdrasil/libm.git#78b62c33fc6a56b6c063c19bbffc5224616b7028" dependencies = [ - "compiler_builtins", "rustc-std-workspace-core", ] @@ -1330,7 +1318,6 @@ version = "0.1.0" name = "libyalloc" version = "0.1.0" dependencies = [ - "compiler_builtins", "libc", "rustc-std-workspace-core", "yggdrasil-rt", @@ -3023,7 +3010,6 @@ dependencies = [ "abi-lib", "abi-serde", "bytemuck", - "compiler_builtins", "prettyplease", "rustc-std-workspace-alloc", "rustc-std-workspace-core", @@ -3101,7 +3087,6 @@ dependencies = [ "abi-lib", "abi-serde", "cc", - "compiler_builtins", "libm", "prettyplease", "rustc-std-workspace-alloc", diff --git a/Cargo.toml b/Cargo.toml index bd991cbc..79cc2428 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,7 @@ features = ["no_std_stream"] [workspace.lints.rust] unexpected_cfgs = { level = "allow", check-cfg = ['cfg(rust_analyzer)'] } +unsafe_op_in_unsafe_fn.level = "deny" [workspace.lints.clippy] derivable_impls = { level = "allow" } diff --git a/etc/aarch64-unknown-none.json b/etc/aarch64-unknown-none.json index aa49667f..4ec2e62c 100644 --- a/etc/aarch64-unknown-none.json +++ b/etc/aarch64-unknown-none.json @@ -2,6 +2,7 @@ "arch": "aarch64", "os": "none", "abi": "softfloat", + "rustc-abi": "softfloat", "llvm-target": "aarch64-unknown-none", "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", "max-atomic-width": 128, diff --git a/etc/riscv64-unknown-none.json b/etc/riscv64-unknown-none.json index 0f5bde53..b7fec2bc 100644 --- a/etc/riscv64-unknown-none.json +++ b/etc/riscv64-unknown-none.json @@ -1,8 +1,8 @@ { "arch": "riscv64", "os": "none", - "abi": "softfloat", "cpu": "generic-rv64", + "llvm-abiname": "lp64", "llvm-target": "riscv64", "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", "max-atomic-width": 64, @@ -20,7 +20,6 @@ "crt-objects-fallback": "false", "emit-debug-gdb-scripts": false, - "llvm-abiname": "lp64", "linker": "rust-lld", "linker-flavor": "ld.lld" diff --git a/kernel/arch/aarch64/src/lib.rs b/kernel/arch/aarch64/src/lib.rs index 9adf4263..397696fb 100644 --- a/kernel/arch/aarch64/src/lib.rs +++ b/kernel/arch/aarch64/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(decl_macro)] #![allow(clippy::new_without_default)] extern crate alloc; diff --git a/kernel/arch/hosted/Cargo.toml b/kernel/arch/hosted/Cargo.toml index 3a0e172a..5c31442c 100644 --- a/kernel/arch/hosted/Cargo.toml +++ b/kernel/arch/hosted/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-arch-hosted" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] kernel-arch-interface.workspace = true diff --git a/kernel/arch/interface/Cargo.toml b/kernel/arch/interface/Cargo.toml index f61e176e..f09d6231 100644 --- a/kernel/arch/interface/Cargo.toml +++ b/kernel/arch/interface/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-arch-interface" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/arch/interface/src/cpu.rs b/kernel/arch/interface/src/cpu.rs index 65b20ead..f410dcce 100644 --- a/kernel/arch/interface/src/cpu.rs +++ b/kernel/arch/interface/src/cpu.rs @@ -94,7 +94,7 @@ impl CpuImpl { /// /// See [Architecture::set_local_cpu]. pub unsafe fn set_local(&'static mut self) { - A::set_local_cpu(self as *mut _ as *mut _) + unsafe { A::set_local_cpu(self as *mut _ as *mut _) } } pub fn try_local<'a>() -> Option> { diff --git a/kernel/arch/interface/src/lib.rs b/kernel/arch/interface/src/lib.rs index 665b648b..f59b6126 100644 --- a/kernel/arch/interface/src/lib.rs +++ b/kernel/arch/interface/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(step_trait, const_trait_impl, never_type, decl_macro)] +#![feature(never_type)] #![allow(clippy::new_without_default)] use core::ops::Range; diff --git a/kernel/arch/interface/src/mem/mod.rs b/kernel/arch/interface/src/mem/mod.rs index c31a529e..a19e6d29 100644 --- a/kernel/arch/interface/src/mem/mod.rs +++ b/kernel/arch/interface/src/mem/mod.rs @@ -86,7 +86,7 @@ impl RawDeviceMemoryMapping { size: usize, attrs: DeviceMemoryAttributes, ) -> Result { - A::map_device_pages(base, size, attrs) + unsafe { A::map_device_pages(base, size, attrs) } } /// Consumes the device mapping, leaking its address without deallocating the translation diff --git a/kernel/arch/x86/Cargo.toml b/kernel/arch/x86/Cargo.toml index 3ffd8e6e..8fec0e25 100644 --- a/kernel/arch/x86/Cargo.toml +++ b/kernel/arch/x86/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-arch-x86" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] kernel-arch-interface.workspace = true diff --git a/kernel/arch/x86/src/cpuid.rs b/kernel/arch/x86/src/cpuid.rs index 56f497d5..a4e279f0 100644 --- a/kernel/arch/x86/src/cpuid.rs +++ b/kernel/arch/x86/src/cpuid.rs @@ -170,36 +170,40 @@ impl CpuFeatureSet for CpuFeatures { #[cfg(any(target_arch = "x86_64", rust_analyzer))] unsafe fn raw_cpuid(eax: u32, result: &mut [u32]) { - core::arch::asm!( - r#" + unsafe { + core::arch::asm!( + r#" push %rbx cpuid mov %ebx, {0:e} pop %rbx "#, - out(reg) result[0], - out("edx") result[1], - out("ecx") result[2], - in("eax") eax, - options(att_syntax) - ); + out(reg) result[0], + out("edx") result[1], + out("ecx") result[2], + in("eax") eax, + options(att_syntax) + ); + } } #[cfg(any(target_arch = "x86", rust_analyzer))] unsafe fn raw_cpuid(eax: u32, result: &mut [u32]) { - core::arch::asm!( - r#" + unsafe { + core::arch::asm!( + r#" push %ebx cpuid mov %ebx, {0:e} pop %ebx "#, - out(reg) result[0], - out("edx") result[1], - out("ecx") result[2], - in("eax") eax, - options(att_syntax) - ); + out(reg) result[0], + out("edx") result[1], + out("ecx") result[2], + in("eax") eax, + options(att_syntax) + ); + } } fn cpuid_features() -> (EcxFeatures, EdxFeatures, ExtEdxFeatures) { diff --git a/kernel/arch/x86/src/gdt.rs b/kernel/arch/x86/src/gdt.rs index bb9a8054..51ed3d41 100644 --- a/kernel/arch/x86/src/gdt.rs +++ b/kernel/arch/x86/src/gdt.rs @@ -225,42 +225,44 @@ mod imp { offset: gdt_addr, }; - core::arch::asm!( - r#" - wbinvd - lgdt ({0}) + unsafe { + core::arch::asm!( + r#" + wbinvd + lgdt ({0}) - // Have to use iretq here - mov %rsp, %rcx - leaq 1f(%rip), %rax + // Have to use iretq here + mov %rsp, %rcx + leaq 1f(%rip), %rax - // SS:RSP - pushq $0x10 - pushq %rcx + // SS:RSP + pushq $0x10 + pushq %rcx - // RFLAGS - pushfq + // RFLAGS + pushfq - // CS:RIP - pushq $0x08 - pushq %rax - iretq - 1: - mov $0x10, %ax - mov %ax, %ds - mov %ax, %es - mov %ax, %fs - mov %ax, %gs - mov %ax, %ss + // CS:RIP + pushq $0x08 + pushq %rax + iretq + 1: + mov $0x10, %ax + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs + mov %ax, %ss - mov $0x28, %ax - ltr %ax - "#, - in(reg) &gdtr, - out("rax") _, - out("rcx") _, - options(att_syntax) - ); + mov $0x28, %ax + ltr %ax + "#, + in(reg) &gdtr, + out("rax") _, + out("rcx") _, + options(att_syntax) + ); + } } /// Initializes and loads the GDT data structure for the current CPU. @@ -270,7 +272,7 @@ mod imp { /// Intended to be called once per each CPU during their early initialization. pub unsafe fn init() -> usize { let (gdt, tss) = create_gdt(); - load_gdt(gdt); + unsafe { load_gdt(gdt) }; (tss as *const Tss).addr() } } diff --git a/kernel/arch/x86/src/intrinsics.rs b/kernel/arch/x86/src/intrinsics.rs index a9ed001b..d45b66d8 100644 --- a/kernel/arch/x86/src/intrinsics.rs +++ b/kernel/arch/x86/src/intrinsics.rs @@ -76,7 +76,9 @@ impl IoPortAccess for IoPort { #[inline] pub unsafe fn inb(port: u16) -> u8 { let value: u8; - core::arch::asm!("inb %dx, %al", in("dx") port, out("al") value, options(att_syntax)); + unsafe { + core::arch::asm!("inb %dx, %al", in("dx") port, out("al") value, options(att_syntax)) + }; value } @@ -88,7 +90,9 @@ pub unsafe fn inb(port: u16) -> u8 { #[inline] pub unsafe fn inw(port: u16) -> u16 { let value: u16; - core::arch::asm!("inw %dx, %ax", in("dx") port, out("ax") value, options(att_syntax)); + unsafe { + core::arch::asm!("inw %dx, %ax", in("dx") port, out("ax") value, options(att_syntax)) + }; value } @@ -100,7 +104,9 @@ pub unsafe fn inw(port: u16) -> u16 { #[inline] pub unsafe fn inl(port: u16) -> u32 { let value: u32; - core::arch::asm!("inl %dx, %eax", in("dx") port, out("eax") value, options(att_syntax)); + unsafe { + core::arch::asm!("inl %dx, %eax", in("dx") port, out("eax") value, options(att_syntax)) + }; value } @@ -111,7 +117,9 @@ pub unsafe fn inl(port: u16) -> u32 { /// Provides direct access to port I/O, unsafe. #[inline] pub unsafe fn outb(port: u16, value: u8) { - core::arch::asm!("outb %al, %dx", in("dx") port, in("al") value, options(att_syntax)); + unsafe { + core::arch::asm!("outb %al, %dx", in("dx") port, in("al") value, options(att_syntax)) + }; } /// Writes a 16-bit value to the I/O port. @@ -121,7 +129,9 @@ pub unsafe fn outb(port: u16, value: u8) { /// Provides direct access to port I/O, unsafe. #[inline] pub unsafe fn outw(port: u16, value: u16) { - core::arch::asm!("outw %ax, %dx", in("dx") port, in("ax") value, options(att_syntax)); + unsafe { + core::arch::asm!("outw %ax, %dx", in("dx") port, in("ax") value, options(att_syntax)) + }; } /// Writes a 32-bit value to the I/O port. @@ -131,7 +141,9 @@ pub unsafe fn outw(port: u16, value: u16) { /// Provides direct access to port I/O, unsafe. #[inline] pub unsafe fn outl(port: u16, value: u32) { - core::arch::asm!("outl %eax, %dx", in("dx") port, in("eax") value, options(att_syntax)); + unsafe { + core::arch::asm!("outl %eax, %dx", in("dx") port, in("eax") value, options(att_syntax)) + }; } #[inline] diff --git a/kernel/arch/x86_64/Cargo.toml b/kernel/arch/x86_64/Cargo.toml index a2441555..e723d589 100644 --- a/kernel/arch/x86_64/Cargo.toml +++ b/kernel/arch/x86_64/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-arch-x86_64" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/arch/x86_64/src/context.rs b/kernel/arch/x86_64/src/context.rs index 8010455c..8115445f 100644 --- a/kernel/arch/x86_64/src/context.rs +++ b/kernel/arch/x86_64/src/context.rs @@ -255,7 +255,7 @@ impl; unsafe fn fork(&self, address_space: u64) -> Result, Error> { - TaskContextImpl::from_syscall_frame(self, address_space) + unsafe { TaskContextImpl::from_syscall_frame(self, address_space) } } fn set_return_value(&mut self, value: u64) { @@ -405,18 +405,20 @@ impl ! { - self.load_state(); - __x86_64_enter_task(self.inner.get()) + unsafe { + self.load_state(); + __x86_64_enter_task(self.inner.get()) + } } unsafe fn switch(&self, from: &Self) { @@ -515,14 +519,18 @@ impl *mut () { @@ -127,7 +127,7 @@ impl Architecture for ArchitectureImpl { ))); cpu.this = cpu.deref_mut(); - cpu.set_local(); + unsafe { cpu.set_local() }; } fn idle_task() -> extern "C" fn(usize) -> ! { @@ -153,10 +153,12 @@ impl Architecture for ArchitectureImpl { unsafe fn set_interrupt_mask(mask: bool) -> bool { let old = Self::interrupt_mask(); - if mask { - core::arch::asm!("cli"); - } else { - core::arch::asm!("sti"); + unsafe { + if mask { + core::arch::asm!("cli"); + } else { + core::arch::asm!("sti"); + } } old } diff --git a/kernel/arch/x86_64/src/mem/fixed.rs b/kernel/arch/x86_64/src/mem/fixed.rs index adc5ae91..962ccf93 100644 --- a/kernel/arch/x86_64/src/mem/fixed.rs +++ b/kernel/arch/x86_64/src/mem/fixed.rs @@ -101,29 +101,33 @@ impl DevicePageTableLevel for L3DeviceMemory { } pub(super) unsafe fn setup(have_1gib_pages: bool) { - let phys = PhysicalAddress::from_usize(auto_lower_address(&raw const KERNEL_PDPT)); - KERNEL_PML4[KERNEL_L0I] = PageEntry::table(phys, PageAttributes::WRITABLE); + unsafe { + let phys = PhysicalAddress::from_usize(auto_lower_address(&raw const KERNEL_PDPT)); + KERNEL_PML4[KERNEL_L0I] = PageEntry::table(phys, PageAttributes::WRITABLE); - if have_1gib_pages { - for i in 0..IDENTITY_SIZE_L1 { - let phys = PhysicalAddress::from_usize(i * L1::SIZE); - KERNEL_PDPT[i] = PageEntry::::block(phys, PageAttributes::WRITABLE); + if have_1gib_pages { + for i in 0..IDENTITY_SIZE_L1 { + let phys = PhysicalAddress::from_usize(i * L1::SIZE); + KERNEL_PDPT[i] = PageEntry::::block(phys, PageAttributes::WRITABLE); + } + } else { + // TODO + ArchitectureImpl::halt(); } - } else { - // TODO - ArchitectureImpl::halt(); - } - // DEVICE_L1 -> Device L2 table - // 0..DEVICE_MAPPING_L3_COUNT -> Device L3 tables -> Device L3 pages - // ..512 -> Device L2 pages - for i in 0..DEVICE_MAPPING_L3_COUNT { + // DEVICE_L1 -> Device L2 table + // 0..DEVICE_MAPPING_L3_COUNT -> Device L3 tables -> Device L3 pages + // ..512 -> Device L2 pages + for i in 0..DEVICE_MAPPING_L3_COUNT { + let phys = PhysicalAddress::from_usize(auto_lower_address( + &raw const DEVICE_MEMORY.normal.0[i], + )); + DEVICE_MEMORY.large.0[i] = PageEntry::table(phys, PageAttributes::WRITABLE); + } let phys = - PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.normal.0[i])); - DEVICE_MEMORY.large.0[i] = PageEntry::table(phys, PageAttributes::WRITABLE); + PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.large.0)); + KERNEL_PDPT[DEVICE_L1] = PageEntry::table(phys, PageAttributes::WRITABLE); } - let phys = PhysicalAddress::from_usize(auto_lower_address(&raw const DEVICE_MEMORY.large.0)); - KERNEL_PDPT[DEVICE_L1] = PageEntry::table(phys, PageAttributes::WRITABLE); } pub(super) unsafe fn load() { diff --git a/kernel/arch/x86_64/src/mem/mod.rs b/kernel/arch/x86_64/src/mem/mod.rs index 6648bc89..664c139a 100644 --- a/kernel/arch/x86_64/src/mem/mod.rs +++ b/kernel/arch/x86_64/src/mem/mod.rs @@ -41,13 +41,17 @@ impl KernelTableManager for KernelTableManagerImpl { ) -> Result, Error> { let _lock = fixed::LOCK.lock(); #[allow(static_mut_refs)] - fixed::DEVICE_MEMORY.map_device_pages(PhysicalAddress::from_u64(base), count, attrs) + unsafe { + fixed::DEVICE_MEMORY.map_device_pages(PhysicalAddress::from_u64(base), count, attrs) + } } unsafe fn unmap_device_pages(mapping: &RawDeviceMemoryMapping) { let _lock = fixed::LOCK.lock(); #[allow(static_mut_refs)] - fixed::DEVICE_MEMORY.unmap_device_pages(mapping); + unsafe { + fixed::DEVICE_MEMORY.unmap_device_pages(mapping) + }; } } @@ -84,9 +88,11 @@ pub fn auto_lower_address(pointer: *const T) -> usize { /// Unsafe, must only be called by BSP during its early init, must already be in "higher-half" #[inline(never)] pub unsafe fn init_fixed_tables(have_1gib_pages: bool, bsp: bool) { - fixed::setup(have_1gib_pages); - if bsp { - fixed::load(); + unsafe { + fixed::setup(have_1gib_pages); + if bsp { + fixed::load(); + } } } @@ -95,5 +101,5 @@ pub unsafe fn init_fixed_tables(have_1gib_pages: bool, bsp: bool) { /// `address` must be page-aligned. #[inline] pub unsafe fn flush_tlb_entry(address: usize) { - core::arch::asm!("invlpg ({0})", in(reg) address, options(att_syntax)); + unsafe { core::arch::asm!("invlpg ({0})", in(reg) address, options(att_syntax)) }; } diff --git a/kernel/arch/x86_64/src/mem/process.rs b/kernel/arch/x86_64/src/mem/process.rs index ca38b90a..8303cabd 100644 --- a/kernel/arch/x86_64/src/mem/process.rs +++ b/kernel/arch/x86_64/src/mem/process.rs @@ -85,8 +85,10 @@ impl ProcessAddressSpaceManager for ProcessAddressSpaceI } unsafe fn clear(&mut self) { - self.l0 - .drop_range::(0..((Self::UPPER_LIMIT_PFN * L3::SIZE).page_index::())); + unsafe { + self.l0 + .drop_range::(0..((Self::UPPER_LIMIT_PFN * L3::SIZE).page_index::())); + } } } diff --git a/kernel/arch/x86_64/src/mem/table.rs b/kernel/arch/x86_64/src/mem/table.rs index 759a70a7..f51bd242 100644 --- a/kernel/arch/x86_64/src/mem/table.rs +++ b/kernel/arch/x86_64/src/mem/table.rs @@ -220,7 +220,7 @@ impl PageTable { /// Unsafe: the caller must ensure the provided reference is properly aligned and contains sane /// data. pub unsafe fn from_raw_slice_mut(data: &mut [PageEntry; 512]) -> &mut Self { - core::mem::transmute(data) + unsafe { core::mem::transmute(data) } } /// Allocates a new page table, filling it with non-preset entries @@ -243,8 +243,10 @@ impl PageTable { /// /// The caller must ensure the table is no longer in use and is not referenced anymore. pub unsafe fn free(this: PhysicalRefMut) { - let physical = this.as_physical_address(); - TA::free_page_table(physical); + unsafe { + let physical = this.as_physical_address(); + TA::free_page_table(physical); + } } // /// Returns the physical address of this table @@ -303,25 +305,29 @@ where const FULL_RANGE: Range = 0..512; unsafe fn drop_range(&mut self, range: Range) { - for index in range { - let entry = self[index]; + unsafe { + for index in range { + let entry = self[index]; - if let Some(table) = entry.as_table() { - let mut table_ref: PhysicalRefMut, KernelTableManagerImpl> = - PhysicalRefMut::map(table); + if let Some(table) = entry.as_table() { + let mut table_ref: PhysicalRefMut< + PageTable, + KernelTableManagerImpl, + > = PhysicalRefMut::map(table); - table_ref.drop_all::(); + table_ref.drop_all::(); - TA::free_page_table(table); - } else if entry.is_present() { - // Memory must've been cleared beforehand, so no non-table entries must be present - panic!( - "Expected a table containing only tables, got table[{}] = {:#x?}", - index, entry.0 - ); + TA::free_page_table(table); + } else if entry.is_present() { + // Memory must've been cleared beforehand, so no non-table entries must be present + panic!( + "Expected a table containing only tables, got table[{}] = {:#x?}", + index, entry.0 + ); + } + + self[index] = PageEntry::INVALID; } - - self[index] = PageEntry::INVALID; } } } diff --git a/kernel/driver/block/ahci/Cargo.toml b/kernel/driver/block/ahci/Cargo.toml index 457c3178..6e9e5752 100644 --- a/kernel/driver/block/ahci/Cargo.toml +++ b/kernel/driver/block/ahci/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_ahci" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/block/ahci/src/command.rs b/kernel/driver/block/ahci/src/command.rs index 094a22c1..0f915eaa 100644 --- a/kernel/driver/block/ahci/src/command.rs +++ b/kernel/driver/block/ahci/src/command.rs @@ -115,7 +115,7 @@ impl AtaCommand for AtaIdentify { } unsafe fn into_response(self) -> Self::Response { - DmaBuffer::assume_init(self.buffer) + unsafe { DmaBuffer::assume_init(self.buffer) } } } diff --git a/kernel/driver/bsp/riscv/src/lib.rs b/kernel/driver/bsp/riscv/src/lib.rs index d2fdadb6..10e0ea71 100644 --- a/kernel/driver/bsp/riscv/src/lib.rs +++ b/kernel/driver/bsp/riscv/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] #![no_std] extern crate alloc; diff --git a/kernel/driver/bus/usb/Cargo.toml b/kernel/driver/bus/usb/Cargo.toml index 14ad15ab..8933006e 100644 --- a/kernel/driver/bus/usb/Cargo.toml +++ b/kernel/driver/bus/usb/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_usb" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/bus/usb/src/lib.rs b/kernel/driver/bus/usb/src/lib.rs index eda8b1c8..1ae2c100 100644 --- a/kernel/driver/bus/usb/src/lib.rs +++ b/kernel/driver/bus/usb/src/lib.rs @@ -4,7 +4,6 @@ generic_const_exprs, iter_array_chunks, maybe_uninit_as_bytes, - maybe_uninit_fill, maybe_uninit_array_assume_init )] diff --git a/kernel/driver/fs/ext2/Cargo.toml b/kernel/driver/fs/ext2/Cargo.toml index 5f7a5aad..abf2fe67 100644 --- a/kernel/driver/fs/ext2/Cargo.toml +++ b/kernel/driver/fs/ext2/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ext2" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/fs/ext2/src/lib.rs b/kernel/driver/fs/ext2/src/lib.rs index 53a03800..250176ae 100644 --- a/kernel/driver/fs/ext2/src/lib.rs +++ b/kernel/driver/fs/ext2/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(impl_trait_in_assoc_type)] #![cfg_attr(not(test), no_std)] #![allow(clippy::new_ret_no_self)] diff --git a/kernel/driver/fs/kernel-fs/Cargo.toml b/kernel/driver/fs/kernel-fs/Cargo.toml index 10863d31..f96ec7eb 100644 --- a/kernel/driver/fs/kernel-fs/Cargo.toml +++ b/kernel/driver/fs/kernel-fs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kernel-fs" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/fs/memfs/Cargo.toml b/kernel/driver/fs/memfs/Cargo.toml index 628d811e..c03c9bb3 100644 --- a/kernel/driver/fs/memfs/Cargo.toml +++ b/kernel/driver/fs/memfs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "memfs" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/fs/memfs/src/block.rs b/kernel/driver/fs/memfs/src/block.rs index 9c0bd9d1..6861a30f 100644 --- a/kernel/driver/fs/memfs/src/block.rs +++ b/kernel/driver/fs/memfs/src/block.rs @@ -159,7 +159,7 @@ impl<'a, A: BlockAllocator> BlockRaw<'a, A> { panic!("Null block dereference"); } - &mut *(self.inner.ptr as *mut _) + unsafe { &mut *(self.inner.ptr as *mut _) } } #[inline] @@ -197,7 +197,7 @@ impl BlockData<'_, A> { pub unsafe fn copy_on_write(address: usize) -> Self { Self { inner: BlockRaw { - inner: BlockRef::copy_on_write(address), + inner: unsafe { BlockRef::copy_on_write(address) }, }, } } diff --git a/kernel/driver/input/Cargo.toml b/kernel/driver/input/Cargo.toml index a1be2a09..cba63fe9 100644 --- a/kernel/driver/input/Cargo.toml +++ b/kernel/driver/input/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_input" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/driver/net/core/src/lib.rs b/kernel/driver/net/core/src/lib.rs index 55d588d9..f3140df4 100644 --- a/kernel/driver/net/core/src/lib.rs +++ b/kernel/driver/net/core/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(map_try_insert)] #![allow(clippy::type_complexity, clippy::new_without_default)] #![no_std] diff --git a/kernel/driver/net/loopback/Cargo.toml b/kernel/driver/net/loopback/Cargo.toml index 6f7dc4bc..26595cf2 100644 --- a/kernel/driver/net/loopback/Cargo.toml +++ b/kernel/driver/net/loopback/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_net_loopback" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/driver/usb/xhci/Cargo.toml b/kernel/driver/usb/xhci/Cargo.toml index fe688727..3675f32a 100644 --- a/kernel/driver/usb/xhci/Cargo.toml +++ b/kernel/driver/usb/xhci/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_usb_xhci" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/kernel/driver/usb/xhci/src/lib.rs b/kernel/driver/usb/xhci/src/lib.rs index 0615b543..3f9b220b 100644 --- a/kernel/driver/usb/xhci/src/lib.rs +++ b/kernel/driver/usb/xhci/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![allow(clippy::new_without_default)] -#![feature(iter_array_chunks)] extern crate alloc; diff --git a/kernel/driver/virtio/core/Cargo.toml b/kernel/driver/virtio/core/Cargo.toml index 5eafe1ee..58b6bef4 100644 --- a/kernel/driver/virtio/core/Cargo.toml +++ b/kernel/driver/virtio/core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_virtio_core" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/driver/virtio/core/src/queue.rs b/kernel/driver/virtio/core/src/queue.rs index 45ea0f25..a09acfc2 100644 --- a/kernel/driver/virtio/core/src/queue.rs +++ b/kernel/driver/virtio/core/src/queue.rs @@ -272,7 +272,7 @@ impl DescriptorTable { visitor: F, ) -> u16 { debug_assert_ne!(count, 0); - let mut current = self.first_free.unwrap_unchecked(); + let mut current = unsafe { self.first_free.unwrap_unchecked() }; let head = current; for i in 0..count { let descriptor = &mut self.descriptors[current as usize]; diff --git a/kernel/driver/virtio/gpu/Cargo.toml b/kernel/driver/virtio/gpu/Cargo.toml index 35615a47..4ade6648 100644 --- a/kernel/driver/virtio/gpu/Cargo.toml +++ b/kernel/driver/virtio/gpu/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_virtio_gpu" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/driver/virtio/net/Cargo.toml b/kernel/driver/virtio/net/Cargo.toml index 7cd051f1..0ce50499 100644 --- a/kernel/driver/virtio/net/Cargo.toml +++ b/kernel/driver/virtio/net/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygg_driver_virtio_net" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/driver/virtio/net/src/lib.rs b/kernel/driver/virtio/net/src/lib.rs index 4b06a222..d9986c0b 100644 --- a/kernel/driver/virtio/net/src/lib.rs +++ b/kernel/driver/virtio/net/src/lib.rs @@ -263,7 +263,7 @@ impl Device for VirtioNet { unsafe fn init(self: Arc, _cx: DeviceInitContext) -> Result<(), Error> { let status = self.begin_init()?; - self.setup_queues()?; + unsafe { self.setup_queues() }?; self.finish_init(status); diff --git a/kernel/lib/device-api/Cargo.toml b/kernel/lib/device-api/Cargo.toml index a18e4b90..02f2bbef 100644 --- a/kernel/lib/device-api/Cargo.toml +++ b/kernel/lib/device-api/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "device-api" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/kernel/lib/device-api/macros/Cargo.toml b/kernel/lib/device-api/macros/Cargo.toml index 6d7dd27f..82081747 100644 --- a/kernel/lib/device-api/macros/Cargo.toml +++ b/kernel/lib/device-api/macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "device-api-macros" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/kernel/lib/device-api/src/i2c.rs b/kernel/lib/device-api/src/i2c.rs index b5f0364c..9b3e9b15 100644 --- a/kernel/lib/device-api/src/i2c.rs +++ b/kernel/lib/device-api/src/i2c.rs @@ -151,11 +151,11 @@ impl I2CDevice { impl Device for I2CDevice { unsafe fn init(self: Arc, cx: DeviceInitContext) -> Result<(), Error> { - self.device.clone().init(cx) + unsafe { self.device.clone().init(cx) } } unsafe fn init_irq(self: Arc) -> Result<(), Error> { - self.device.clone().init_irq() + unsafe { self.device.clone().init_irq() } } fn display_name(&self) -> &str { diff --git a/kernel/lib/device-api/src/lib.rs b/kernel/lib/device-api/src/lib.rs index 3ddd1984..f5d5614c 100644 --- a/kernel/lib/device-api/src/lib.rs +++ b/kernel/lib/device-api/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(trait_alias)] #![no_std] #![allow(clippy::new_without_default)] diff --git a/kernel/lib/device-tree/src/lib.rs b/kernel/lib/device-tree/src/lib.rs index c1d60c2d..2d75914b 100644 --- a/kernel/lib/device-tree/src/lib.rs +++ b/kernel/lib/device-tree/src/lib.rs @@ -10,7 +10,7 @@ //! * `pl011` - basic peripheral usage with `reg` and `interrupts` //! * `gic` in aarch64 - interrupt controller/mapper implementation #![cfg_attr(any(not(test), rust_analyzer), no_std)] -#![feature(trait_alias, decl_macro)] +#![feature(decl_macro)] #![allow(clippy::type_complexity)] #![warn(missing_docs)] diff --git a/kernel/lib/module-build/Cargo.toml b/kernel/lib/module-build/Cargo.toml index 43b4e220..db4a60ab 100644 --- a/kernel/lib/module-build/Cargo.toml +++ b/kernel/lib/module-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "module-build" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] diff --git a/kernel/lib/vmalloc/Cargo.toml b/kernel/lib/vmalloc/Cargo.toml index 7897d7ed..ce81ac49 100644 --- a/kernel/lib/vmalloc/Cargo.toml +++ b/kernel/lib/vmalloc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "vmalloc" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/kernel/lib/vmalloc/src/lib.rs b/kernel/lib/vmalloc/src/lib.rs index a1cbcbd2..b263572e 100644 --- a/kernel/lib/vmalloc/src/lib.rs +++ b/kernel/lib/vmalloc/src/lib.rs @@ -6,7 +6,6 @@ #![deny(missing_docs)] #![no_std] -#![feature(linked_list_cursors)] extern crate alloc; diff --git a/kernel/libk/libk-mm/Cargo.toml b/kernel/libk/libk-mm/Cargo.toml index ec9a0e04..74f88629 100644 --- a/kernel/libk/libk-mm/Cargo.toml +++ b/kernel/libk/libk-mm/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libk-mm" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/kernel/libk/libk-mm/interface/Cargo.toml b/kernel/libk/libk-mm/interface/Cargo.toml index 9afa7604..f7f708e6 100644 --- a/kernel/libk/libk-mm/interface/Cargo.toml +++ b/kernel/libk/libk-mm/interface/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libk-mm-interface" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/kernel/libk/libk-mm/interface/src/device.rs b/kernel/libk/libk-mm/interface/src/device.rs index 11403a29..10a9726f 100644 --- a/kernel/libk/libk-mm/interface/src/device.rs +++ b/kernel/libk/libk-mm/interface/src/device.rs @@ -93,13 +93,15 @@ impl DevicePageManager { .ok_or(Error::OutOfMemory)?; let mapped_address = mapped_base + large_offset; - Ok(RawDeviceMemoryMapping::from_raw_parts( - large_aligned_base.into_u64(), - mapped_address, - mapped_base, - large_page_count, - L::Level::SIZE, - )) + Ok(unsafe { + RawDeviceMemoryMapping::from_raw_parts( + large_aligned_base.into_u64(), + mapped_address, + mapped_base, + large_page_count, + L::Level::SIZE, + ) + }) } else { // Allocate from small page pool let mapped_base = self @@ -108,13 +110,15 @@ impl DevicePageManager { .ok_or(Error::OutOfMemory)?; let mapped_address = mapped_base + small_offset; - Ok(RawDeviceMemoryMapping::from_raw_parts( - small_aligned_base.into_u64(), - mapped_address, - mapped_base, - small_page_count, - N::Level::SIZE, - )) + Ok(unsafe { + RawDeviceMemoryMapping::from_raw_parts( + small_aligned_base.into_u64(), + mapped_address, + mapped_base, + small_page_count, + N::Level::SIZE, + ) + }) } } @@ -125,17 +129,19 @@ impl DevicePageManager { &mut self, mapping: &RawDeviceMemoryMapping, ) { - if mapping.page_size == N::Level::SIZE { - self.normal - .remove_mapping(mapping.base_address, mapping.page_count); - } else if mapping.page_size == L::Level::SIZE { - self.large - .remove_mapping(mapping.base_address, mapping.page_count); - } else { - unreachable!( - "Invalid device memory mapping with page size {:#x}", - mapping.page_size - ) + unsafe { + if mapping.page_size == N::Level::SIZE { + self.normal + .remove_mapping(mapping.base_address, mapping.page_count); + } else if mapping.page_size == L::Level::SIZE { + self.large + .remove_mapping(mapping.base_address, mapping.page_count); + } else { + unreachable!( + "Invalid device memory mapping with page size {:#x}", + mapping.page_size + ) + } } } } diff --git a/kernel/libk/libk-mm/interface/src/lib.rs b/kernel/libk/libk-mm/interface/src/lib.rs index 06ce3d10..112c399d 100644 --- a/kernel/libk/libk-mm/interface/src/lib.rs +++ b/kernel/libk/libk-mm/interface/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(step_trait, const_trait_impl)] +#![feature(step_trait)] use core::ops::{Deref, DerefMut}; diff --git a/kernel/libk/libk-mm/interface/src/pointer.rs b/kernel/libk/libk-mm/interface/src/pointer.rs index 67bcbfee..e28ceb33 100644 --- a/kernel/libk/libk-mm/interface/src/pointer.rs +++ b/kernel/libk/libk-mm/interface/src/pointer.rs @@ -33,7 +33,7 @@ impl<'a, T: Sized, K: KernelTableManager> PhysicalRefMut<'a, T, K> { /// contains T. The caller must also take care of access synchronization and make sure no /// aliasing occurs. pub unsafe fn map(physical: PhysicalAddress) -> PhysicalRefMut<'a, T, K> { - let value = virtualize_raw::<_, K>(physical); + let value = unsafe { virtualize_raw::<_, K>(physical) }; PhysicalRefMut { value, _pd: PhantomData, @@ -48,7 +48,7 @@ impl<'a, T: Sized, K: KernelTableManager> PhysicalRefMut<'a, T, K> { /// contains [T; len]. The caller must also take care of access synchronization and make /// sure no aliasing occurs. pub unsafe fn map_slice(physical: PhysicalAddress, len: usize) -> PhysicalRefMut<'a, [T], K> { - let value = virtualize_slice_raw::<_, K>(physical, len); + let value = unsafe { virtualize_slice_raw::<_, K>(physical, len) }; PhysicalRefMut { value, _pd: PhantomData, @@ -66,7 +66,9 @@ impl PhysicalRefMut<'_, T, K> { impl AsPhysicalAddress for PhysicalRefMut<'_, T, K> { unsafe fn as_physical_address(&self) -> PhysicalAddress { - PhysicalAddress::raw_from_virtualized::(PhysicalRefMut::::as_address(self)) + unsafe { + PhysicalAddress::raw_from_virtualized::(PhysicalRefMut::::as_address(self)) + } } } @@ -106,7 +108,7 @@ impl<'a, T: Sized, K: KernelTableManager> PhysicalRef<'a, T, K> { /// The caller must ensure the correct origin of the physical address as well that it actually /// contains T. pub unsafe fn map(physical: PhysicalAddress) -> PhysicalRef<'a, T, K> { - let value = virtualize_raw::<_, K>(physical); + let value = unsafe { virtualize_raw::<_, K>(physical) }; PhysicalRef { value, _pd: PhantomData, @@ -121,7 +123,7 @@ impl<'a, T: Sized, K: KernelTableManager> PhysicalRef<'a, T, K> { /// The caller must ensure the correct origin of the physical address as well that it actually /// contains [T; len]. pub unsafe fn map_slice(physical: PhysicalAddress, len: usize) -> PhysicalRef<'a, [T], K> { - let value = virtualize_slice_raw::<_, K>(physical, len); + let value = unsafe { virtualize_slice_raw::<_, K>(physical, len) }; PhysicalRef { value, _pd: PhantomData, @@ -139,7 +141,7 @@ impl PhysicalRef<'_, T, K> { impl AsPhysicalAddress for PhysicalRef<'_, T, K> { unsafe fn as_physical_address(&self) -> PhysicalAddress { - PhysicalAddress::raw_from_virtualized::(PhysicalRef::::as_address(self)) + unsafe { PhysicalAddress::raw_from_virtualized::(PhysicalRef::::as_address(self)) } } } @@ -162,7 +164,7 @@ unsafe fn virtualize_raw<'a, T: Sized, K: KernelTableManager>( ) -> &'a mut T { // TODO check align let address = physical.raw_virtualize::(); - &mut *(address as *mut T) + unsafe { &mut *(address as *mut T) } } unsafe fn virtualize_slice_raw<'a, T: Sized, K: KernelTableManager>( @@ -171,5 +173,5 @@ unsafe fn virtualize_slice_raw<'a, T: Sized, K: KernelTableManager>( ) -> &'a mut [T] { // TODO check align let address = physical.raw_virtualize::(); - core::slice::from_raw_parts_mut(address as *mut T, len) + unsafe { core::slice::from_raw_parts_mut(address as *mut T, len) } } diff --git a/kernel/libk/libk-mm/interface/src/table.rs b/kernel/libk/libk-mm/interface/src/table.rs index e2c29f20..6194887d 100644 --- a/kernel/libk/libk-mm/interface/src/table.rs +++ b/kernel/libk/libk-mm/interface/src/table.rs @@ -100,7 +100,7 @@ pub trait EntryLevelDrop { /// Caller must ensure the unmapped range is not in use by some other thread and will not be /// referred to from this point. unsafe fn drop_all(&mut self) { - self.drop_range::(Self::FULL_RANGE) + unsafe { self.drop_range::(Self::FULL_RANGE) } } } diff --git a/kernel/libk/libk-mm/src/device.rs b/kernel/libk/libk-mm/src/device.rs index 0ca571a6..cdf33705 100644 --- a/kernel/libk/libk-mm/src/device.rs +++ b/kernel/libk/libk-mm/src/device.rs @@ -50,7 +50,7 @@ impl DeviceMemoryMapping { size: usize, attrs: DeviceMemoryAttributes, ) -> Result { - let inner = RawDeviceMemoryMapping::map(base.into_u64(), size, attrs)?; + let inner = unsafe { RawDeviceMemoryMapping::map(base.into_u64(), size, attrs)? }; let address = inner.address; Ok(Self { inner: Arc::new(inner), @@ -78,7 +78,7 @@ impl<'a, T: Sized> DeviceMemoryIo<'a, T> { todo!(); } // TODO check align - let value = &*(inner.address as *const T); + let value = unsafe { &*(inner.address as *const T) }; Ok(DeviceMemoryIo { inner, value }) } @@ -94,8 +94,8 @@ impl<'a, T: Sized> DeviceMemoryIo<'a, T> { attrs: DeviceMemoryAttributes, ) -> Result, Error> { let layout = Layout::array::(count).unwrap(); - let inner = RawDeviceMemoryMapping::map(base.into_u64(), layout.size(), attrs)?; - let value = core::slice::from_raw_parts(inner.address as *mut T, count); + let inner = unsafe { RawDeviceMemoryMapping::map(base.into_u64(), layout.size(), attrs)? }; + let value = unsafe { core::slice::from_raw_parts(inner.address as *mut T, count) }; Ok(DeviceMemoryIo { inner: Arc::new(inner), @@ -113,8 +113,8 @@ impl<'a, T: Sized> DeviceMemoryIo<'a, T> { base: PhysicalAddress, attrs: DeviceMemoryAttributes, ) -> Result, Error> { - let inner = RawDeviceMemoryMapping::map(base.into_u64(), size_of::(), attrs)?; - let value = &*(inner.address as *const T); + let inner = unsafe { RawDeviceMemoryMapping::map(base.into_u64(), size_of::(), attrs)? }; + let value = unsafe { &*(inner.address as *const T) }; Ok(DeviceMemoryIo { inner: Arc::new(inner), @@ -139,7 +139,7 @@ impl<'a, T: ?Sized> DeviceMemoryIo<'a, T> { DeviceMemoryIo { inner: self.inner.clone(), - value: &*value, + value: unsafe { &*value }, } } } @@ -175,8 +175,8 @@ impl<'a, T: Sized> DeviceMemoryIoMut<'a, T> { attrs: DeviceMemoryAttributes, ) -> Result, Error> { let layout = Layout::array::(len).unwrap(); - let inner = RawDeviceMemoryMapping::map(base.into_u64(), layout.size(), attrs)?; - let value = core::slice::from_raw_parts_mut(inner.address as *mut T, len); + let inner = unsafe { RawDeviceMemoryMapping::map(base.into_u64(), layout.size(), attrs)? }; + let value = unsafe { core::slice::from_raw_parts_mut(inner.address as *mut T, len) }; Ok(DeviceMemoryIoMut { inner, value }) } diff --git a/kernel/libk/libk-mm/src/heap.rs b/kernel/libk/libk-mm/src/heap.rs index a0ade8b4..dadc1a52 100644 --- a/kernel/libk/libk-mm/src/heap.rs +++ b/kernel/libk/libk-mm/src/heap.rs @@ -59,7 +59,7 @@ unsafe impl GlobalAlloc for KernelAllocator { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { let ptr = NonNull::new(ptr).unwrap(); - self.inner.lock().free(ptr, layout); + unsafe { self.inner.lock().free(ptr, layout) }; } } diff --git a/kernel/libk/libk-mm/src/lib.rs b/kernel/libk/libk-mm/src/lib.rs index 155a53f6..77b73ca0 100644 --- a/kernel/libk/libk-mm/src/lib.rs +++ b/kernel/libk/libk-mm/src/lib.rs @@ -1,10 +1,4 @@ -#![feature( - slice_ptr_get, - step_trait, - const_trait_impl, - maybe_uninit_as_bytes, - negative_impls -)] +#![feature(slice_ptr_get, maybe_uninit_as_bytes, negative_impls)] #![no_std] extern crate alloc; @@ -46,7 +40,7 @@ impl TableAllocator for TableAllocatorImpl { } unsafe fn free_page_table(address: PhysicalAddress) { - phys::free_page(address) + unsafe { phys::free_page(address) } } } @@ -138,7 +132,7 @@ impl PageBox { /// Unsafe: converts a raw physical address back into a [PageBox]. Only intended to be used /// for allocations previously converted to [PhysicalAddress] via [PageBox::into_physical_raw]. pub unsafe fn from_physical_raw(address: PhysicalAddress) -> PageBox { - PageBox::from_physical_raw_in(address) + unsafe { PageBox::from_physical_raw_in(address) } } pub fn from_slice(slice: &[T]) -> Result, Error> @@ -335,7 +329,7 @@ impl> PageBox is transparent // 2. self.value still points to the same memory and is not deallocated let page_count = self.page_count; - let value = MaybeUninit::assume_init_mut(&mut *self.value); + let value = unsafe { MaybeUninit::assume_init_mut(&mut *self.value) }; // Prevent deallocation of the PageBox with MaybeUninit core::mem::forget(self); @@ -363,7 +357,7 @@ impl> PageBox<[MaybeUni // 1. MaybeUninit is transparent // 2. self.value still points to the same memory and is not deallocated let page_count = self.page_count; - let value = (&mut *self.value).assume_init_mut(); + let value = unsafe { (&mut *self.value).assume_init_mut() }; core::mem::forget(self); @@ -380,7 +374,7 @@ impl> PageBox<[MaybeUni /// /// See [MaybeUninit::slice_assume_init_ref] pub unsafe fn assume_init_slice_ref(&self) -> &[T] { - (&*self.value).assume_init_ref() + unsafe { (&*self.value).assume_init_ref() } } /// Returns a mutable reference to the slice data with [MaybeUninit] removed. @@ -389,7 +383,7 @@ impl> PageBox<[MaybeUni /// /// See [MaybeUninit::slice_assume_init_mut] pub unsafe fn assume_init_slice_mut(&mut self) -> &mut [T] { - (&mut *self.value).assume_init_mut() + unsafe { (&mut *self.value).assume_init_mut() } } /// Fills a slice of MaybeUninit with zeroes. @@ -400,7 +394,7 @@ impl> PageBox<[MaybeUni /// trivial types. pub unsafe fn zero(p: &mut Self) { let ptr = p.as_mut_ptr() as *mut u8; - let slice = core::slice::from_raw_parts_mut(ptr, p.page_count * L3_PAGE_SIZE); + let slice = unsafe { core::slice::from_raw_parts_mut(ptr, p.page_count * L3_PAGE_SIZE) }; slice.fill(0); } } diff --git a/kernel/libk/libk-mm/src/phys/manager.rs b/kernel/libk/libk-mm/src/phys/manager.rs index 0cca9ead..d4e8974b 100644 --- a/kernel/libk/libk-mm/src/phys/manager.rs +++ b/kernel/libk/libk-mm/src/phys/manager.rs @@ -49,10 +49,12 @@ impl PhysicalMemoryManager { page_count: usize, ) -> PhysicalMemoryManager { let bitmap_len = page_count.div_ceil(BITMAP_WORD_SIZE); - let mut bitmap = PhysicalRefMut::<'static, _, KernelTableManagerImpl>::map_slice( - bitmap_phys_base, - bitmap_len, - ); + let mut bitmap = unsafe { + PhysicalRefMut::<'static, _, KernelTableManagerImpl>::map_slice( + bitmap_phys_base, + bitmap_len, + ) + }; bitmap.fill(BitmapWord::MAX); diff --git a/kernel/libk/libk-mm/src/phys/mod.rs b/kernel/libk/libk-mm/src/phys/mod.rs index ab74ad9e..7bd1cb77 100644 --- a/kernel/libk/libk-mm/src/phys/mod.rs +++ b/kernel/libk/libk-mm/src/phys/mod.rs @@ -78,7 +78,7 @@ impl PhysicalMemoryAllocator for GlobalPhysicalAllocator { } unsafe fn free_page(page: Self::Address) { - free_page(page) + unsafe { free_page(page) } } } @@ -111,7 +111,7 @@ pub fn stats() -> SystemMemoryStats { /// /// `addr` must be a page-aligned physical address previously allocated by this implementation. pub unsafe fn free_page(addr: PhysicalAddress) { - PHYSICAL_MEMORY.get().lock().free_page(addr) + unsafe { PHYSICAL_MEMORY.get().lock().free_page(addr) } } fn physical_memory_range>( @@ -208,13 +208,15 @@ pub unsafe fn init_from_iter + Clone>( 000000:?:libk_mm::phys:207: page_bitmap_phys_base=0x80060000 000000:?:libk_mm::phys:208: total_count=32768 */ - let mut manager = PhysicalMemoryManager::new( - page_bitmap_phys_base, - phys_start - .try_into_usize() - .expect("Memory start didn't fit in usize"), - total_count, - ); + let mut manager = unsafe { + PhysicalMemoryManager::new( + page_bitmap_phys_base, + phys_start + .try_into_usize() + .expect("Memory start didn't fit in usize"), + total_count, + ) + }; let mut collected = 0; const MAX_MEMORY: usize = 256 * 1024; @@ -245,7 +247,7 @@ pub unsafe fn init_from_iter + Clone>( fn kernel_physical_memory_region() -> PhysicalMemoryRegion { use core::ptr::addr_of; - extern "C" { + unsafe extern "C" { static __kernel_start: u8; static __kernel_end: u8; } @@ -259,17 +261,17 @@ fn kernel_physical_memory_region() -> PhysicalMemoryRegion { PhysicalMemoryRegion { base, size } } -#[no_mangle] +#[unsafe(no_mangle)] fn __allocate_page() -> Result { alloc_page() } -#[no_mangle] +#[unsafe(no_mangle)] fn __allocate_contiguous_pages(count: usize) -> Result { alloc_pages_contiguous(count) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe fn __free_page(page: PhysicalAddress) { - free_page(page) + unsafe { free_page(page) } } diff --git a/kernel/libk/libk-mm/src/process.rs b/kernel/libk/libk-mm/src/process.rs index 34a19157..eea5360d 100644 --- a/kernel/libk/libk-mm/src/process.rs +++ b/kernel/libk/libk-mm/src/process.rs @@ -185,7 +185,7 @@ impl Inner { let offset = (pfn - origin_pfn) * L3_PAGE_SIZE; let virt = pfn * L3_PAGE_SIZE; - if let Ok((phys, dirty)) = self.table.unmap_page(virt) { + if let Ok((phys, dirty)) = unsafe { self.table.unmap_page(virt) } { backing.release_page(offset as u64, phys, dirty)?; } } @@ -284,7 +284,7 @@ impl Inner { let offset = ((pfn - origin_pfn) * L3_PAGE_SIZE) as u64; let virt = pfn * L3_PAGE_SIZE; - let (phys, dirty) = match self.table.unmap_page(virt) { + let (phys, dirty) = match unsafe { self.table.unmap_page(virt) } { Ok(res) => res, Err(Error::DoesNotExist) => continue, Err(error) => return Err(error), @@ -319,7 +319,7 @@ impl Inner { })?; // Drop the tables - self.table.clear(); + unsafe { self.table.clear() }; Ok(()) } @@ -546,7 +546,7 @@ impl ProcessAddressSpace { let mut lock = self.inner.lock(); - lock.unmap_range(address, size / L3_PAGE_SIZE) + unsafe { lock.unmap_range(address, size / L3_PAGE_SIZE) } } /// Returns the physical address of the translation table along with its ASID diff --git a/kernel/libk/libk-util/src/lib.rs b/kernel/libk/libk-util/src/lib.rs index 54c58ac7..57e1870c 100644 --- a/kernel/libk/libk-util/src/lib.rs +++ b/kernel/libk/libk-util/src/lib.rs @@ -1,11 +1,5 @@ #![no_std] -#![feature( - linked_list_cursors, - async_fn_traits, - allocator_api, - const_trait_impl, - str_from_utf16_endian -)] +#![feature(linked_list_cursors, async_fn_traits, allocator_api)] #![allow(clippy::new_without_default)] extern crate alloc; diff --git a/kernel/libk/src/lib.rs b/kernel/libk/src/lib.rs index 39bc5936..37d22142 100644 --- a/kernel/libk/src/lib.rs +++ b/kernel/libk/src/lib.rs @@ -4,13 +4,8 @@ #![feature( option_get_or_try_insert_with, async_fn_traits, - new_range_api, associated_type_defaults, - step_trait, - const_trait_impl, - slice_ptr_get, never_type, - allocator_api, trait_alias, arbitrary_self_types, slice_split_once, diff --git a/kernel/modules/test_mod/Cargo.toml b/kernel/modules/test_mod/Cargo.toml index 27fd8445..1cc68e9a 100644 --- a/kernel/modules/test_mod/Cargo.toml +++ b/kernel/modules/test_mod/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "test_mod" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] crate-type = ["dylib"] diff --git a/kernel/src/arch/aarch64/boot/mod.rs b/kernel/src/arch/aarch64/boot/mod.rs index 7b292f7c..fcc3d9e7 100644 --- a/kernel/src/arch/aarch64/boot/mod.rs +++ b/kernel/src/arch/aarch64/boot/mod.rs @@ -45,7 +45,7 @@ static mut DTB_PHYSICAL_ADDRESS: PhysicalAddress = PhysicalAddress::ZERO; unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_end: usize) { let rela_count = (rela_end - rela_start) / size_of::(); let rela_ptr: *const Elf64_Rela = core::ptr::with_exposed_provenance(rela_start); - let rela_table = core::slice::from_raw_parts(rela_ptr, rela_count); + let rela_table = unsafe { core::slice::from_raw_parts(rela_ptr, rela_count) }; for rela in rela_table { let slot: *mut i64 = @@ -56,7 +56,7 @@ unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_en _ => ArchitectureImpl::halt(), }; - slot.write_volatile(value); + unsafe { slot.write_volatile(value) }; } } @@ -82,12 +82,14 @@ unsafe fn leave_el2(pc: usize, sp: usize, x0: usize) -> ! { ELR_EL2.set(pc as u64); SP_EL1.set(sp as u64); - core::arch::asm!("eret", in("x0") x0, options(noreturn)); + unsafe { core::arch::asm!("eret", in("x0") x0, options(noreturn)) }; } #[inline] unsafe fn long_jump(pc: usize, sp: usize) -> ! { - core::arch::asm!("mov sp, {sp}; br {pc}", sp = in(reg) sp, pc = in(reg) pc, options(noreturn)); + unsafe { + core::arch::asm!("mov sp, {sp}; br {pc}", sp = in(reg) sp, pc = in(reg) pc, options(noreturn)) + }; } unsafe extern "C" fn bsp_entry_upper() -> ! { @@ -100,12 +102,12 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { atomic::fence(Ordering::SeqCst); let rela_start = (&raw const __rela_start).addr(); let rela_end = (&raw const __rela_end).addr(); - let image_base = (KERNEL_VIRT_OFFSET as u64 + KERNEL_LOAD_BASE) as i64; - relocate_kernel(image_base, rela_start, rela_end); + let image_base = unsafe { (KERNEL_VIRT_OFFSET as u64 + KERNEL_LOAD_BASE) as i64 }; + unsafe { relocate_kernel(image_base, rela_start, rela_end) }; atomic::fence(Ordering::SeqCst); // Setup memory management (using DTB from lower half) - if let Err(error) = PLATFORM.init_memory_management(DTB_PHYSICAL_ADDRESS) { + if let Err(error) = unsafe { PLATFORM.init_memory_management(DTB_PHYSICAL_ADDRESS) } { let _ = error; ArchitectureImpl::halt(); } @@ -126,7 +128,7 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { runtime::init_task_queue(); // Initialize the BSP CPU + the devices - if PLATFORM.init_platform(true).is_err() { + if unsafe { PLATFORM.init_platform(true).is_err() } { ArchitectureImpl::halt(); } @@ -159,15 +161,17 @@ unsafe extern "C" fn ap_entry_upper() -> ! { } unsafe extern "C" fn bsp_entry_el1() -> ! { - setup_cpu_common(); - mem::init_lower(true); - let pc = (bsp_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; - let sp = BSP_STACK.top_addr() + KERNEL_VIRT_OFFSET; - long_jump(pc, sp) + unsafe { + setup_cpu_common(); + mem::init_lower(true); + let pc = (bsp_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; + let sp = BSP_STACK.top_addr() + KERNEL_VIRT_OFFSET; + long_jump(pc, sp) + } } unsafe extern "C" fn bsp_entry_el2() -> ! { - leave_el2((bsp_entry_el1 as *const ()).addr(), BSP_STACK.top_addr(), 0) + unsafe { leave_el2((bsp_entry_el1 as *const ()).addr(), BSP_STACK.top_addr(), 0) } } unsafe extern "C" fn ap_entry_el1(sp: usize) -> ! { @@ -175,18 +179,18 @@ unsafe extern "C" fn ap_entry_el1(sp: usize) -> ! { const AP_STACK_PAGES: usize = 8; setup_cpu_common(); - mem::init_lower(false); + unsafe { mem::init_lower(false) }; let stack_pages = phys::alloc_pages_contiguous(AP_STACK_PAGES).unwrap(); let stack_base = stack_pages.virtualize(); let sp = stack_base + L3::SIZE * AP_STACK_PAGES; let pc = (ap_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; - long_jump(pc, sp) + unsafe { long_jump(pc, sp) } } unsafe extern "C" fn ap_entry_el2(sp: usize) -> ! { - leave_el2((ap_entry_el1 as *const ()).addr(), sp, sp) + unsafe { leave_el2((ap_entry_el1 as *const ()).addr(), sp, sp) } } global_asm!( diff --git a/kernel/src/arch/aarch64/exception.rs b/kernel/src/arch/aarch64/exception.rs index 875dcc9b..9bd036a1 100644 --- a/kernel/src/arch/aarch64/exception.rs +++ b/kernel/src/arch/aarch64/exception.rs @@ -51,7 +51,7 @@ unsafe fn perform_ptw(virt: usize, handler: F) { // Strip ASID let ttbr_phys = PhysicalAddress::from_u64(ttbr_phys & !(0xFFFF << 48)); - let Some(l1) = PageTable::::from_physical(ttbr_phys) else { + let Some(l1) = (unsafe { PageTable::::from_physical(ttbr_phys) }) else { handler(0, EntryType::Invalid); return; }; @@ -60,14 +60,14 @@ unsafe fn perform_ptw(virt: usize, handler: F) { let l2 = l1.walk(l1i); handler(1, l2); let l2 = match l2 { - EntryType::Table(_, l2) => PageTable::::from_physical(l2).unwrap(), + EntryType::Table(_, l2) => unsafe { PageTable::::from_physical(l2).unwrap() }, _ => return, }; let l3 = l2.walk(l2i); handler(2, l3); let l3 = match l3 { - EntryType::Table(_, l3) => PageTable::::from_physical(l3).unwrap(), + EntryType::Table(_, l3) => unsafe { PageTable::::from_physical(l3).unwrap() }, _ => return, }; diff --git a/kernel/src/arch/aarch64/gic/mod.rs b/kernel/src/arch/aarch64/gic/mod.rs index ffa02dbf..ba99ed5e 100644 --- a/kernel/src/arch/aarch64/gic/mod.rs +++ b/kernel/src/arch/aarch64/gic/mod.rs @@ -164,7 +164,7 @@ impl LocalInterruptController for Gic { } unsafe fn init_ap(&self) -> Result<(), Error> { - self.gicc.init(); + unsafe { self.gicc.init() }; Ok(()) } } @@ -223,30 +223,32 @@ impl Gic { gicc_base: PhysicalAddress, ) -> Result { log::debug!("Init GIC: gicd={:#x}, gicc={:#x}", gicd_base, gicc_base); - let gicd_mmio = Arc::new(RawDeviceMemoryMapping::map( - gicd_base.into_u64(), - 0x1000, - Default::default(), - )?); - let gicd_mmio_shared = DeviceMemoryIo::from_raw(gicd_mmio.clone())?; - let gicd_mmio_banked = DeviceMemoryIo::from_raw(gicd_mmio)?; - let gicc_mmio = DeviceMemoryIo::map(gicc_base, Default::default())?; + unsafe { + let gicd_mmio = Arc::new(RawDeviceMemoryMapping::map( + gicd_base.into_u64(), + 0x1000, + Default::default(), + )?); + let gicd_mmio_shared = DeviceMemoryIo::from_raw(gicd_mmio.clone())?; + let gicd_mmio_banked = DeviceMemoryIo::from_raw(gicd_mmio)?; + let gicc_mmio = DeviceMemoryIo::map(gicc_base, Default::default())?; - let gicd = Gicd::new(gicd_mmio_shared, gicd_mmio_banked); - let gicc = Gicc::new(gicc_mmio); + let gicd = Gicd::new(gicd_mmio_shared, gicd_mmio_banked); + let gicc = Gicc::new(gicc_mmio); - gicd.init(); - gicc.init(); + gicd.init(); + gicc.init(); - // self.gicd.init(gicd); - // self.gicc.init(gicc); - let table = FixedInterruptTable::new(MAX_IRQ); + // self.gicd.init(gicd); + // self.gicc.init(gicc); + let table = FixedInterruptTable::new(MAX_IRQ); - Ok(Self { - gicd, - gicc, - table, // table: IrqSafeRwLock::new(FixedInterruptTable::new()), - }) + Ok(Self { + gicd, + gicc, + table, // table: IrqSafeRwLock::new(FixedInterruptTable::new()), + }) + } } } diff --git a/kernel/src/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs index 4e117bb0..a70a55da 100644 --- a/kernel/src/arch/aarch64/mod.rs +++ b/kernel/src/arch/aarch64/mod.rs @@ -82,7 +82,7 @@ impl Platform for AArch64 { } let dt = self.dt.get(); - if let Err(error) = smp::start_ap_cores(dt) { + if let Err(error) = unsafe { smp::start_ap_cores(dt) } { log::error!("Could not initialize AP CPUs: {:?}", error); } } @@ -93,20 +93,22 @@ impl Platform for AArch64 { // } // unsafe fn reset(&self) -> ! { - if let Some(reset) = self.reset.try_get() { - reset.reset() - } else { - let psci = self.psci.get(); - psci.reset() + unsafe { + if let Some(reset) = self.reset.try_get() { + reset.reset() + } else { + let psci = self.psci.get(); + psci.reset() + } } } unsafe fn power_off(&self) -> Result { - Self::halt_aps()?; + unsafe { Self::halt_aps() }?; if let Some(psci) = self.psci.try_get() { log::info!("Powering off"); - psci.power_off() + unsafe { psci.power_off() } } else { log::warn!("No power off method, halting"); ArchitectureImpl::halt(); @@ -160,8 +162,9 @@ impl AArch64 { dtb_address: PhysicalAddress, ) -> Result<(), Error> { let dtb: PhysicalRef<[u8]> = - PhysicalRef::map_slice(dtb_address, DeviceTree::MIN_HEADER_SIZE); - let dtb_size = DeviceTree::read_totalsize(&dtb[..]).map_err(|_| Error::InvalidArgument)?; + unsafe { PhysicalRef::map_slice(dtb_address, DeviceTree::MIN_HEADER_SIZE) }; + let dtb_size = + unsafe { DeviceTree::read_totalsize(&dtb[..]).map_err(|_| Error::InvalidArgument) }?; reserve_region( "dtb", @@ -171,8 +174,8 @@ impl AArch64 { }, ); - let dtb: PhysicalRef<[u8]> = PhysicalRef::map_slice(dtb_address, dtb_size); - let dt = DeviceTree::from_raw(dtb.as_ptr().addr())?; + let dtb: PhysicalRef<[u8]> = unsafe { PhysicalRef::map_slice(dtb_address, dtb_size) }; + let dt = unsafe { DeviceTree::from_raw(dtb.as_ptr().addr()) }?; // Setup initrd from the dt let initrd = dt.chosen_initrd(); @@ -194,7 +197,7 @@ impl AArch64 { let dt = self.dt.init(dt); // Initialize the physical memory - phys::init_from_iter(dt.memory_regions())?; + unsafe { phys::init_from_iter(dt.memory_regions()) }?; // Setup initrd if let Some((initrd_start, initrd_end)) = initrd { @@ -254,7 +257,7 @@ impl AArch64 { let per_cpu = PerCpuData { gic: OneTimeInit::new(), }; - Cpu::init_local(None, per_cpu); + unsafe { Cpu::init_local(None, per_cpu) }; if is_bsp { atomic::compiler_fence(Ordering::SeqCst); @@ -266,7 +269,7 @@ impl AArch64 { config::parse_boot_arguments(bootargs); // Will register drivers - call_init_array(); + unsafe { call_init_array() }; // Create device tree sysfs nodes device_tree::util::create_sysfs_nodes(dt); @@ -280,7 +283,7 @@ impl AArch64 { unflatten_device_tree(dt); - Self::setup_chosen_stdout(dt).ok(); + unsafe { Self::setup_chosen_stdout(dt).ok() }; if let Some(machine) = machine_name { log::info!("Running on {machine:?}"); diff --git a/kernel/src/arch/aarch64/smp.rs b/kernel/src/arch/aarch64/smp.rs index 099cd706..b2a0d598 100644 --- a/kernel/src/arch/aarch64/smp.rs +++ b/kernel/src/arch/aarch64/smp.rs @@ -78,7 +78,7 @@ impl CpuEnableMethod { Error::DoesNotExist })?; - psci.start_cpu(id, ip, sp) + unsafe { psci.start_cpu(id, ip, sp) } } &Self::SpinTable(cpu_release_addr) => { // Store a stack for the CPU @@ -91,7 +91,7 @@ impl CpuEnableMethod { // Make the CPU jump to __aarch64_ap_spin_table_entry first let release_ptr = ptr::with_exposed_provenance_mut::(cpu_release_addr.virtualize()); - let release_atomic = AtomicU64::from_ptr(release_ptr); + let release_atomic = unsafe { AtomicU64::from_ptr(release_ptr) }; let spin_entry_addr = (__aarch64_ap_spin_table_entry as *const ()).addr() - KERNEL_VIRT_OFFSET; @@ -146,7 +146,7 @@ pub unsafe fn start_ap_cores(dt: &DeviceTree) -> Result<(), Error> { barrier::dsb(barrier::ISH); barrier::isb(barrier::SY); - if let Err(error) = cpu.enable_method.start_cpu(cpu.id as usize, ip, sp) { + if let Err(error) = unsafe { cpu.enable_method.start_cpu(cpu.id as usize, ip, sp) } { log::error!("Couldn't start cpu{} up: {:?}", cpu.id, error); continue; } diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs index a655a1ed..58c4916c 100644 --- a/kernel/src/arch/mod.rs +++ b/kernel/src/arch/mod.rs @@ -46,7 +46,7 @@ pub trait Platform { /// The caller must ensure it is actually safe to reset, i.e. no critical processes will be /// aborted and no data will be lost. unsafe fn reset(&self) -> ! { - ArchitectureImpl::set_interrupt_mask(true); + unsafe { ArchitectureImpl::set_interrupt_mask(true) }; loop { ArchitectureImpl::wait_for_interrupt(); } @@ -59,7 +59,7 @@ pub trait Platform { /// The caller must ensure it is actually safe to power down, i.e. no critical processes will be /// aborted and no data will be lost. unsafe fn power_off(&self) -> Result { - ArchitectureImpl::set_interrupt_mask(true); + unsafe { ArchitectureImpl::set_interrupt_mask(true) }; loop { ArchitectureImpl::wait_for_interrupt(); } diff --git a/kernel/src/arch/riscv64/boot/mod.rs b/kernel/src/arch/riscv64/boot/mod.rs index da88140f..5cd4808f 100644 --- a/kernel/src/arch/riscv64/boot/mod.rs +++ b/kernel/src/arch/riscv64/boot/mod.rs @@ -42,7 +42,7 @@ impl BootStack { unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_end: usize) { let rela_count = (rela_end - rela_start) / size_of::(); let rela_ptr: *const Elf64_Rela = core::ptr::with_exposed_provenance(rela_start); - let rela_table = core::slice::from_raw_parts(rela_ptr, rela_count); + let rela_table = unsafe { core::slice::from_raw_parts(rela_ptr, rela_count) }; for rela in rela_table { let slot: *mut i64 = @@ -53,12 +53,20 @@ unsafe extern "C" fn relocate_kernel(image_base: i64, rela_start: usize, rela_en _ => ArchitectureImpl::halt(), }; - slot.write_volatile(value); + unsafe { slot.write_volatile(value) }; } } unsafe fn long_jump(pc: usize, sp: usize, a0: usize) -> ! { - core::arch::asm!("mv sp, {sp}; jr {pc}", in("a0") a0, sp = in(reg) sp, pc = in(reg) pc, options(noreturn)) + unsafe { + core::arch::asm!( + "mv sp, {sp}; jr {pc}", + in("a0") a0, + sp = in(reg) sp, + pc = in(reg) pc, + options(noreturn) + ) + } } unsafe extern "C" fn bsp_entry_upper() -> ! { @@ -71,8 +79,8 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { atomic::fence(Ordering::SeqCst); let rela_start = (&raw const __rela_start).addr(); let rela_end = (&raw const __rela_end).addr(); - let image_base = (KERNEL_VIRT_OFFSET as u64 + KERNEL_LOAD_BASE) as i64; - relocate_kernel(image_base, rela_start, rela_end); + let image_base = unsafe { (KERNEL_VIRT_OFFSET as u64 + KERNEL_LOAD_BASE) as i64 }; + unsafe { relocate_kernel(image_base, rela_start, rela_end) }; atomic::fence(Ordering::SeqCst); debug::init_logger(); @@ -80,13 +88,13 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { log::info!("Starting riscv64 upper half"); - if DTB_ADDRESS.is_zero() { + if unsafe { DTB_ADDRESS.is_zero() } { log::error!("No device tree provided"); // No DTB provided ArchitectureImpl::halt(); } - if let Err(error) = PLATFORM.init_memory_management(DTB_ADDRESS) { + if let Err(error) = unsafe { PLATFORM.init_memory_management(DTB_ADDRESS) } { log::error!("Failed to initialize memory management: {error:?}"); ArchitectureImpl::halt(); } @@ -96,7 +104,7 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { runtime::init_task_queue(); - if let Err(error) = PLATFORM.init_platform(BOOT_HART_ID as u32, 0, true) { + if let Err(error) = unsafe { PLATFORM.init_platform(BOOT_HART_ID as u32, 0, true) } { log::error!("Failed to initialize the platform: {error:?}"); ArchitectureImpl::halt(); } @@ -105,20 +113,22 @@ unsafe extern "C" fn bsp_entry_upper() -> ! { } unsafe extern "C" fn bsp_smode_entry() -> ! { - mem::enable_mmu(); - let pc = (bsp_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; - let sp = (&raw const BOOT_STACK).addr() + BOOT_STACK_SIZE + KERNEL_VIRT_OFFSET; - long_jump(pc, sp, 0) + unsafe { + mem::enable_mmu(); + let pc = (bsp_entry_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; + let sp = (&raw const BOOT_STACK).addr() + BOOT_STACK_SIZE + KERNEL_VIRT_OFFSET; + long_jump(pc, sp, 0) + } } unsafe extern "C" fn ap_smode_upper(context: PhysicalAddress) -> ! { let hart_id = { - let context = PageBox::::from_physical_raw(context); + let context = unsafe { PageBox::::from_physical_raw(context) }; context.hart_id }; let queue_index = CPU_COUNT.fetch_add(1, Ordering::Acquire); - if let Err(error) = PLATFORM.init_platform(hart_id as u32, queue_index, false) { + if let Err(error) = unsafe { PLATFORM.init_platform(hart_id as u32, queue_index, false) } { log::error!("Secondary hart init error: {error:?}"); ArchitectureImpl::halt(); } @@ -128,11 +138,13 @@ unsafe extern "C" fn ap_smode_upper(context: PhysicalAddress) -> ! { unsafe extern "C" fn ap_smode_entry(context: PhysicalAddress, sp: PhysicalAddress) -> ! { compiler_fence(Ordering::SeqCst); - mem::enable_mmu(); - compiler_fence(Ordering::SeqCst); - let pc = (ap_smode_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; - let sp = sp.virtualize(); - long_jump(pc, sp, context.into_usize()) + unsafe { + mem::enable_mmu(); + compiler_fence(Ordering::SeqCst); + let pc = (ap_smode_upper as *const ()).addr() + KERNEL_VIRT_OFFSET; + let sp = sp.virtualize(); + long_jump(pc, sp, context.into_usize()) + } } global_asm!( diff --git a/kernel/src/arch/riscv64/exception.rs b/kernel/src/arch/riscv64/exception.rs index 8c71fe5c..c19ba8c1 100644 --- a/kernel/src/arch/riscv64/exception.rs +++ b/kernel/src/arch/riscv64/exception.rs @@ -186,7 +186,7 @@ unsafe fn smode_exception_handler(frame: &mut TrapFrame) { } unsafe extern "C" fn smode_interrupt_handler(frame: *mut TrapFrame) { - let frame = &mut *frame; + let frame = unsafe { &mut *frame }; let smode = frame.sstatus & (1 << 8) != 0; match frame.scause & !(1 << 63) { @@ -204,24 +204,26 @@ unsafe extern "C" fn smode_interrupt_handler(frame: *mut TrapFrame) { } if !smode && let Some(thread) = Thread::get_current() { - thread.handle_pending_signals(frame); + unsafe { thread.handle_pending_signals(frame) }; } } unsafe extern "C" fn smode_general_trap_handler(frame: *mut TrapFrame) { - let frame = &mut *frame; + let frame = unsafe { &mut *frame }; let interrupt = frame.scause & (1 << 63) != 0; let smode = frame.sstatus & (1 << 8) != 0; - match (interrupt, smode) { - (true, _) => smode_interrupt_handler(frame), - (false, true) => smode_exception_handler(frame), - (false, false) => umode_exception_handler(frame), + unsafe { + match (interrupt, smode) { + (true, _) => smode_interrupt_handler(frame), + (false, true) => smode_exception_handler(frame), + (false, false) => umode_exception_handler(frame), + } } if !smode && let Some(thread) = Thread::get_current() { - thread.handle_pending_signals(frame); + unsafe { thread.handle_pending_signals(frame) }; } mem::tlb_flush_full(); } diff --git a/kernel/src/arch/riscv64/mod.rs b/kernel/src/arch/riscv64/mod.rs index b09a17a3..914b327d 100644 --- a/kernel/src/arch/riscv64/mod.rs +++ b/kernel/src/arch/riscv64/mod.rs @@ -77,8 +77,9 @@ impl Riscv64 { &'static self, dtb_address: PhysicalAddress, ) -> Result<(), Error> { - let dtb = PhysicalRef::::map_slice(dtb_address, DeviceTree::MIN_HEADER_SIZE); - let dtb_size = DeviceTree::read_totalsize(&dtb[..]).map_err(|_| Error::InvalidArgument)?; + let dtb = unsafe { PhysicalRef::::map_slice(dtb_address, DeviceTree::MIN_HEADER_SIZE) }; + let dtb_size = + unsafe { DeviceTree::read_totalsize(&dtb[..]).map_err(|_| Error::InvalidArgument) }?; // // Unmap the lower half // mem::setup_fixed_tables(); @@ -93,8 +94,8 @@ impl Riscv64 { }, ); - let dtb = PhysicalRef::::map_slice(dtb_address, dtb_size); - let dt = DeviceTree::from_raw(dtb.as_ptr().addr())?; + let dtb = unsafe { PhysicalRef::::map_slice(dtb_address, dtb_size) }; + let dt = unsafe { DeviceTree::from_raw(dtb.as_ptr().addr()) }?; // Reserve memory regions specified in the DTB log::info!("Reserved memory:"); @@ -122,7 +123,7 @@ impl Riscv64 { } // Initialize the physical memory - phys::init_from_iter(dt.memory_regions())?; + unsafe { phys::init_from_iter(dt.memory_regions()) }?; self.dt.init(dt); @@ -160,14 +161,14 @@ impl Riscv64 { bootstrap: is_bsp, queue_index, }; - Cpu::init_local(Some(hart_id), per_cpu); + unsafe { Cpu::init_local(Some(hart_id), per_cpu) }; assert_eq!(Cpu::local().id(), hart_id); exception::init_smode_exceptions(); if is_bsp { - call_init_array(); + unsafe { call_init_array() }; unsafe extern "C" { static __kernel_start: u8; @@ -196,7 +197,7 @@ impl Riscv64 { if let Err(error) = Self::setup_clock_timebase(dt) { log::error!("Could not setup clock timebase from device tree: {error:?}"); } - if let Err(error) = Self::setup_chosen_stdout(dt) { + if let Err(error) = unsafe { Self::setup_chosen_stdout(dt) } { log::error!("chosen-stdout setup error: {error:?}"); } else { libk::debug::disable_early_sinks(); diff --git a/kernel/src/arch/x86_64/apic/local.rs b/kernel/src/arch/x86_64/apic/local.rs index d04b7196..8dbe0a59 100644 --- a/kernel/src/arch/x86_64/apic/local.rs +++ b/kernel/src/arch/x86_64/apic/local.rs @@ -347,7 +347,8 @@ impl LocalApic { /// /// Only meant to be called once per processor during their init. pub unsafe fn new() -> Self { - let regs = DeviceMemoryIo::::map(Self::base(), Default::default()).unwrap(); + let regs = + unsafe { DeviceMemoryIo::::map(Self::base(), Default::default()).unwrap() }; let id = regs.Id.read(Id::ApicId); diff --git a/kernel/src/arch/x86_64/apic/mod.rs b/kernel/src/arch/x86_64/apic/mod.rs index 9768bdee..f1247a2d 100644 --- a/kernel/src/arch/x86_64/apic/mod.rs +++ b/kernel/src/arch/x86_64/apic/mod.rs @@ -65,16 +65,18 @@ unsafe extern "C" fn irq_handler(vector: usize, frame: *mut IrqFrame) { unreachable!("Got a weird IRQ with vector {}", vector); } - let cpu = Cpu::local(); - let frame = &mut *frame; + unsafe { + let cpu = Cpu::local(); + let frame = &mut *frame; - if let Ok(intc) = external_interrupt_controller() { - intc.handle_specific_irq(vector); - } - cpu.local_apic().clear_interrupt(); + if let Ok(intc) = external_interrupt_controller() { + intc.handle_specific_irq(vector); + } + cpu.local_apic().clear_interrupt(); - if let Some(thread) = Thread::get_current() { - thread.handle_pending_signals(frame); + if let Some(thread) = Thread::get_current() { + thread.handle_pending_signals(frame); + } } } @@ -83,32 +85,36 @@ unsafe extern "C" fn msi_handler(vector: usize, frame: *mut IrqFrame) { unreachable!("Got a weird MSI with vector {}", vector); } - let cpu = Cpu::local(); - let frame = &mut *frame; + unsafe { + let cpu = Cpu::local(); + let frame = &mut *frame; - cpu.local_apic().handle_msi(vector); - cpu.local_apic().clear_interrupt(); + cpu.local_apic().handle_msi(vector); + cpu.local_apic().clear_interrupt(); - if let Some(thread) = Thread::get_current() { - thread.handle_pending_signals(frame); + if let Some(thread) = Thread::get_current() { + thread.handle_pending_signals(frame); + } } } unsafe extern "C" fn local_timer_irq_handler(frame: *mut IrqFrame) { - let frame = &mut *frame; + unsafe { + let frame = &mut *frame; - runtime::tick(); + runtime::tick(); - let cpu = Cpu::local(); - // Clear interrupt before switching, because otherwise we won't receive the next one - cpu.local_apic().clear_interrupt(); + let cpu = Cpu::local(); + // Clear interrupt before switching, because otherwise we won't receive the next one + cpu.local_apic().clear_interrupt(); - if let Some(queue) = cpu.try_get_scheduler() { - queue.yield_cpu(); - } + if let Some(queue) = cpu.try_get_scheduler() { + queue.yield_cpu(); + } - if let Some(thread) = Thread::get_current() { - thread.handle_pending_signals(frame); + if let Some(thread) = Thread::get_current() { + thread.handle_pending_signals(frame); + } } } diff --git a/kernel/src/arch/x86_64/boot/mod.rs b/kernel/src/arch/x86_64/boot/mod.rs index 8e8c70cf..aefec1d0 100644 --- a/kernel/src/arch/x86_64/boot/mod.rs +++ b/kernel/src/arch/x86_64/boot/mod.rs @@ -99,15 +99,17 @@ static YBOOT_DATA: LoadProtocolV1 = LoadProtocolV1 { }; unsafe fn init_dummy_cpu() { - static UNINIT_CPU_INNER: usize = 0; - static UNINIT_CPU_PTR: &usize = &UNINIT_CPU_INNER; + unsafe { + static UNINIT_CPU_INNER: usize = 0; + static UNINIT_CPU_PTR: &usize = &UNINIT_CPU_INNER; - // Point %gs to a dummy structure so that Cpu::get_local() works properly even before the CPU - // data structure is initialized - MSR_IA32_KERNEL_GS_BASE.set(&UNINIT_CPU_PTR as *const _ as u64); - core::arch::asm!("swapgs"); - MSR_IA32_KERNEL_GS_BASE.set(&UNINIT_CPU_PTR as *const _ as u64); - core::arch::asm!("swapgs"); + // Point %gs to a dummy structure so that Cpu::get_local() works properly even before the CPU + // data structure is initialized + MSR_IA32_KERNEL_GS_BASE.set(&UNINIT_CPU_PTR as *const _ as u64); + core::arch::asm!("swapgs"); + MSR_IA32_KERNEL_GS_BASE.set(&UNINIT_CPU_PTR as *const _ as u64); + core::arch::asm!("swapgs"); + } } /// Application processor entry point diff --git a/kernel/src/arch/x86_64/exception.rs b/kernel/src/arch/x86_64/exception.rs index 36b90b53..9dfcb2dc 100644 --- a/kernel/src/arch/x86_64/exception.rs +++ b/kernel/src/arch/x86_64/exception.rs @@ -252,7 +252,7 @@ pub unsafe fn init_exceptions(cpu_index: usize) { static __x86_64_exception_vectors: [usize; 32]; } - for (i, &entry) in __x86_64_exception_vectors.iter().enumerate() { + for (i, &entry) in unsafe { __x86_64_exception_vectors.iter().enumerate() } { idt[i] = Entry::new(entry, 0x08, Entry::PRESENT | Entry::INT32); } @@ -265,7 +265,9 @@ pub unsafe fn init_exceptions(cpu_index: usize) { offset: idt.as_ptr().addr(), }; - core::arch::asm!("wbinvd; lidt ({0})", in(reg) &idtr, options(att_syntax)); + unsafe { + core::arch::asm!("wbinvd; lidt ({0})", in(reg) &idtr, options(att_syntax)); + } } global_asm!( diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index ee12bcef..a14986fc 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -94,7 +94,7 @@ impl Platform for X86_64 { return; }; - smp::start_ap_cores(&pinfo); + unsafe { smp::start_ap_cores(&pinfo) }; } } @@ -165,15 +165,17 @@ impl X86_64 { } unsafe fn init_physical_memory_from_yboot(data: &LoadProtocolV1) -> Result<(), Error> { - let mmap = PhysicalRef::::map_slice( - PhysicalAddress::from_u64(data.memory_map.address), - data.memory_map.len as usize, - ); + unsafe { + let mmap = PhysicalRef::::map_slice( + PhysicalAddress::from_u64(data.memory_map.address), + data.memory_map.len as usize, + ); - phys::init_from_iter(mmap.as_ref().iter().map(|reg| PhysicalMemoryRegion { - base: PhysicalAddress::from_u64(reg.start_address), - size: reg.page_count as usize * L3::SIZE, - })) + phys::init_from_iter(mmap.as_ref().iter().map(|reg| PhysicalMemoryRegion { + base: PhysicalAddress::from_u64(reg.start_address), + size: reg.page_count as usize * L3::SIZE, + })) + } } unsafe fn init_memory_management( @@ -183,7 +185,9 @@ impl X86_64 { ) -> Result<(), Error> { let have_1gib_pages = enabled_features.ext_edx.contains(ExtEdxFeatures::PDPE1GB); - mem::init_fixed_tables(have_1gib_pages, is_bsp); + unsafe { + mem::init_fixed_tables(have_1gib_pages, is_bsp); + } if !is_bsp { return Ok(()); @@ -198,36 +202,41 @@ impl X86_64 { }, ); - match self.boot_data.get() { - &BootData::YBoot(data) => Self::init_physical_memory_from_yboot(data)?, + unsafe { + match self.boot_data.get() { + &BootData::YBoot(data) => Self::init_physical_memory_from_yboot(data)?, + } } Ok(()) } unsafe fn init_platform(&'static self, cpu_id: usize) -> Result<(), Error> { - let (available_features, enabled_features) = self.init_cpu_features(); + let (available_features, enabled_features) = unsafe { self.init_cpu_features() }; - PLATFORM - .init_memory_management(&enabled_features, cpu_id == 0) - .expect("Could not initialize memory management"); - let local_apic = self.init_local_cpu(cpu_id, available_features, enabled_features); + unsafe { + PLATFORM + .init_memory_management(&enabled_features, cpu_id == 0) + .expect("Could not initialize memory management"); + } + let local_apic = + unsafe { self.init_local_cpu(cpu_id, available_features, enabled_features) }; if cpu_id == 0 { - self.setup_from_boot_data()?; + unsafe { self.setup_from_boot_data()? }; // TODO yboot doesn't yet pass any command line options let cmdline = self.boot_data.get().cmdline(); let mut early = x86::init_platform_early(cmdline)?; if !config::get().x86.disable_boot_fb - && let Err(error) = self.init_framebuffer() + && let Err(error) = unsafe { self.init_framebuffer() } { log::error!("Could not initialize boot framebuffer: {error:?}"); } if let Some(acpi) = self.acpi.try_get() { - self.init_platform_from_acpi(acpi, local_apic)?; + unsafe { self.init_platform_from_acpi(acpi, local_apic)? }; } if !config::get().x86_64.disable_hpet { @@ -236,7 +245,7 @@ impl X86_64 { log::info!("HPET disabled by config"); } - call_init_array(); + unsafe { call_init_array() }; x86::init_platform_devices(early); @@ -289,24 +298,26 @@ impl X86_64 { available_features: CpuFeatures, enabled_features: CpuFeatures, ) -> Arc { - let local_apic = Arc::new(LocalApic::new()); - let tss_address = gdt::init(); - exception::init_exceptions(cpu_id); + unsafe { + let local_apic = Arc::new(LocalApic::new()); + let tss_address = gdt::init(); + exception::init_exceptions(cpu_id); - let cpu_data = PerCpuData { - this: null_mut(), - tss_address, - tmp_address: 0, - local_apic: local_apic.clone(), - available_features, - enabled_features, - }; + let cpu_data = PerCpuData { + this: null_mut(), + tss_address, + tmp_address: 0, + local_apic: local_apic.clone(), + available_features, + enabled_features, + }; - Cpu::init_local(Some(cpu_id as _), cpu_data); + Cpu::init_local(Some(cpu_id as _), cpu_data); - syscall::init_syscall(); + syscall::init_syscall(); - local_apic + local_apic + } } unsafe fn setup_from_boot_data(&self) -> Result<(), Error> { @@ -315,16 +326,17 @@ impl X86_64 { // Already reserved in set_boot_data() x86::set_initrd(data, false); - self.init_acpi_from_rsdp(data.rsdp_address as usize) + unsafe { self.init_acpi_from_rsdp(data.rsdp_address as usize) } } } } unsafe fn init_acpi_from_rsdp(&self, rsdp: usize) -> Result<(), Error> { - let acpi_tables = AcpiTables::from_rsdp(AcpiHandlerImpl, rsdp).map_err(|err| { - log::error!("Could not initialize ACPI tables: {:?}", err); - Error::InvalidArgument - })?; + let acpi_tables = + unsafe { AcpiTables::from_rsdp(AcpiHandlerImpl, rsdp) }.map_err(|err| { + log::error!("Could not initialize ACPI tables: {:?}", err); + Error::InvalidArgument + })?; self.acpi.init(acpi_tables); Ok(()) } @@ -405,14 +417,16 @@ impl X86_64 { _ => PixelFormat::R8G8B8A8, }; - let framebuffer = LinearFramebuffer::from_physical_bits( - PhysicalAddress::from_u64(info.res_address), - info.res_size as usize, - info.res_stride as usize, - info.res_width, - info.res_height, - format, - )?; + let framebuffer = unsafe { + LinearFramebuffer::from_physical_bits( + PhysicalAddress::from_u64(info.res_address), + info.res_size as usize, + info.res_stride as usize, + info.res_width, + info.res_height, + format, + )? + }; Some(Arc::new(framebuffer)) } diff --git a/kernel/src/arch/x86_64/smp.rs b/kernel/src/arch/x86_64/smp.rs index f417ff8f..1d5fa7ad 100644 --- a/kernel/src/arch/x86_64/smp.rs +++ b/kernel/src/arch/x86_64/smp.rs @@ -55,14 +55,16 @@ unsafe fn start_ap_core(apic_id: u32) { entry: (ap_entry as *const ()).addr(), }; - let mut data_ref = PhysicalRefMut::::map(AP_BOOTSTRAP_DATA); + let mut data_ref = unsafe { PhysicalRefMut::::map(AP_BOOTSTRAP_DATA) }; *data_ref = data; let cpu_count = CPU_COUNT.load(Ordering::Acquire); // Send an IPI to wake up the AP - core::arch::asm!("wbinvd"); - bsp_apic.wakeup_cpu(apic_id, AP_BOOTSTRAP_CODE); + unsafe { + core::arch::asm!("wbinvd"); + bsp_apic.wakeup_cpu(apic_id, AP_BOOTSTRAP_CODE); + } while cpu_count == CPU_COUNT.load(Ordering::Acquire) { core::hint::spin_loop(); @@ -87,27 +89,29 @@ pub unsafe fn start_ap_cores(info: &ProcessorInfo) { let mut identity_l1 = PageTable::::new_zeroed::().unwrap(); let mut identity_l2 = PageTable::::new_zeroed::().unwrap(); - identity_l1[0] = - PageEntry::::table(identity_l2.as_physical_address(), PageAttributes::WRITABLE); - identity_l2[0] = PageEntry::::block(PhysicalAddress::ZERO, PageAttributes::WRITABLE); + unsafe { + identity_l1[0] = + PageEntry::::table(identity_l2.as_physical_address(), PageAttributes::WRITABLE); + identity_l2[0] = PageEntry::::block(PhysicalAddress::ZERO, PageAttributes::WRITABLE); - fixed::KERNEL_PML4[0] = - PageEntry::table(identity_l1.as_physical_address(), PageAttributes::WRITABLE); + fixed::KERNEL_PML4[0] = + PageEntry::table(identity_l1.as_physical_address(), PageAttributes::WRITABLE); - // Load AP_BOOTSTRAP_CODE - let mut code_ref = PhysicalRefMut::map_slice(AP_BOOTSTRAP_CODE, AP_BOOTSTRAP_BIN.len()); - code_ref.copy_from_slice(AP_BOOTSTRAP_BIN); + // Load AP_BOOTSTRAP_CODE + let mut code_ref = PhysicalRefMut::map_slice(AP_BOOTSTRAP_CODE, AP_BOOTSTRAP_BIN.len()); + code_ref.copy_from_slice(AP_BOOTSTRAP_BIN); - for ap in aps.iter() { - if ap.is_ap && ap.state == ProcessorState::WaitingForSipi { - start_ap_core(ap.local_apic_id); + for ap in aps.iter() { + if ap.is_ap && ap.state == ProcessorState::WaitingForSipi { + start_ap_core(ap.local_apic_id); + } } + + // Remove the identity-map + identity_l2[0] = PageEntry::INVALID; + flush_tlb_entry(0); + + PageTable::free::(identity_l1); + PageTable::free::(identity_l2); } - - // Remove the identity-map - identity_l2[0] = PageEntry::INVALID; - flush_tlb_entry(0); - - PageTable::free::(identity_l1); - PageTable::free::(identity_l2); } diff --git a/kernel/src/device/power/arm_psci.rs b/kernel/src/device/power/arm_psci.rs index bf4c3eca..5c28f38b 100644 --- a/kernel/src/device/power/arm_psci.rs +++ b/kernel/src/device/power/arm_psci.rs @@ -42,16 +42,18 @@ impl Device for Psci { impl CpuBringupDevice for Psci { unsafe fn start_cpu(&self, id: usize, ip: usize, arg0: usize) -> Result<(), Error> { - self.call(self.cpu_on as _, id as _, ip as _, arg0 as _); + unsafe { self.call(self.cpu_on as _, id as _, ip as _, arg0 as _) }; Ok(()) } } impl ResetDevice for Psci { unsafe fn reset(&self) -> ! { - ArchitectureImpl::set_interrupt_mask(true); + unsafe { + ArchitectureImpl::set_interrupt_mask(true); - self.call(Self::SYSTEM_RESET as _, 0, 0, 0); + self.call(Self::SYSTEM_RESET as _, 0, 0, 0); + } loop { ArchitectureImpl::wait_for_interrupt(); @@ -65,12 +67,14 @@ impl Psci { #[inline] unsafe fn call(&self, mut x0: u64, x1: u64, x2: u64, x3: u64) -> u64 { - match self.method { - CallMethod::Hvc => { - core::arch::asm!("hvc #0", inlateout("x0") x0, in("x1") x1, in("x2") x2, in("x3") x3) - } - CallMethod::Smc => { - core::arch::asm!("smc #0", inlateout("x0") x0, in("x1") x1, in("x2") x2, in("x3") x3) + unsafe { + match self.method { + CallMethod::Hvc => { + core::arch::asm!("hvc #0", inlateout("x0") x0, in("x1") x1, in("x2") x2, in("x3") x3) + } + CallMethod::Smc => { + core::arch::asm!("smc #0", inlateout("x0") x0, in("x1") x1, in("x2") x2, in("x3") x3) + } } } x0 @@ -82,7 +86,7 @@ impl Psci { /// /// Unsafe: requires caller to perform all the necessary shutdown preparations. pub unsafe fn power_off(&self) -> Result { - self.call(Self::SYSTEM_OFF as _, 0, 0, 0); + unsafe { self.call(Self::SYSTEM_OFF as _, 0, 0, 0) }; unreachable!() } } diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index 325ccc80..21d4d2d7 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -53,7 +53,7 @@ unsafe impl BlockAllocator for FileBlockAllocator { unsafe fn dealloc(block: NonNull) { let page = block.as_ptr() as usize; let physical = PhysicalAddress::from_virtualized(page); - phys::free_page(physical); + unsafe { phys::free_page(physical) }; } } diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 97a7c573..11f7a20d 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -1,23 +1,5 @@ //! osdev-x kernel crate -#![feature( - step_trait, - decl_macro, - optimize_attribute, - const_trait_impl, - arbitrary_self_types, - linked_list_cursors, - rustc_private, - allocator_api, - trait_alias, - slice_ptr_get, - slice_split_once, - iter_collect_into, - iter_next_chunk, - exact_size_is_empty, - never_type, - format_args_nl, - associated_type_defaults -)] +#![feature(arbitrary_self_types, rustc_private, never_type)] #![allow( clippy::new_without_default, clippy::fn_to_numeric_cast, @@ -25,8 +7,7 @@ clippy::match_single_binding, clippy::missing_transmute_annotations, clippy::modulo_one, - async_fn_in_trait, - unsafe_op_in_unsafe_fn + async_fn_in_trait )] #![deny(missing_docs)] #![no_std] diff --git a/kernel/src/mem/mod.rs b/kernel/src/mem/mod.rs index 18c7d828..8a7191c5 100644 --- a/kernel/src/mem/mod.rs +++ b/kernel/src/mem/mod.rs @@ -17,13 +17,14 @@ pub const KERNEL_VIRT_OFFSET: usize = kernel_arch::KERNEL_VIRT_OFFSET; /// The caller must ensure the correct origin of the address, its alignment and that the access is /// properly synchronized. pub unsafe fn read_memory(address: PhysicalAddress) -> T { - let io = DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap(); + let io = + unsafe { DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap() }; let address = io.address(); if address.is_multiple_of(align_of::()) { - (address as *const T).read_volatile() + unsafe { (address as *const T).read_volatile() } } else { - (address as *const T).read_unaligned() + unsafe { (address as *const T).read_unaligned() } } } @@ -34,32 +35,33 @@ pub unsafe fn read_memory(address: PhysicalAddress) -> T { /// The caller must ensure the correct origin of the address, its alignment and that the access is /// properly synchronized. pub unsafe fn write_memory(address: PhysicalAddress, value: T) { - let io = DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap(); + let io = + unsafe { DeviceMemoryMapping::map(address, size_of::(), Default::default()).unwrap() }; let address = io.address(); if address.is_multiple_of(align_of::()) { - (address as *mut T).write_volatile(value) + unsafe { (address as *mut T).write_volatile(value) } } else { - (address as *mut T).write_unaligned(value) + unsafe { (address as *mut T).write_unaligned(value) } } } #[unsafe(no_mangle)] unsafe extern "C" fn memcpy(p0: *mut c_void, p1: *const c_void, len: usize) -> *mut c_void { - compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _ + unsafe { compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _ } } #[unsafe(no_mangle)] unsafe extern "C" fn memcmp(p0: *const c_void, p1: *const c_void, len: usize) -> i32 { - compiler_builtins::mem::memcmp(p0 as _, p1 as _, len) + unsafe { compiler_builtins::mem::memcmp(p0 as _, p1 as _, len) } } #[unsafe(no_mangle)] unsafe extern "C" fn memmove(dst: *mut c_void, src: *const c_void, len: usize) -> *mut c_void { - compiler_builtins::mem::memmove(dst as _, src as _, len) as _ + unsafe { compiler_builtins::mem::memmove(dst as _, src as _, len) as _ } } #[unsafe(no_mangle)] unsafe extern "C" fn memset(dst: *mut c_void, val: i32, len: usize) -> *mut c_void { - compiler_builtins::mem::memset(dst as _, val, len) as _ + unsafe { compiler_builtins::mem::memset(dst as _, val, len) as _ } } diff --git a/kernel/src/task/mod.rs b/kernel/src/task/mod.rs index bf0b55c7..0303ad1f 100644 --- a/kernel/src/task/mod.rs +++ b/kernel/src/task/mod.rs @@ -75,5 +75,5 @@ pub unsafe fn enter() -> ! { let queue = CpuQueue::for_cpu(cpu.queue_index()); cpu.set_scheduler(queue); - queue.enter() + unsafe { queue.enter() } } diff --git a/kernel/src/util/mod.rs b/kernel/src/util/mod.rs index 431fc3f4..a029da06 100644 --- a/kernel/src/util/mod.rs +++ b/kernel/src/util/mod.rs @@ -90,7 +90,7 @@ pub unsafe fn call_init_array() { } let size = (end - base.addr()) / size_of::(); - let init_array: &[InitFn] = core::slice::from_raw_parts(base.cast(), size); + let init_array: &[InitFn] = unsafe { core::slice::from_raw_parts(base.cast(), size) }; for function in init_array { function(); diff --git a/lib/abi-lib/Cargo.toml b/lib/abi-lib/Cargo.toml index 0eb3c554..b3f13800 100644 --- a/lib/abi-lib/Cargo.toml +++ b/lib/abi-lib/Cargo.toml @@ -1,18 +1,14 @@ [package] name = "abi-lib" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } -compiler_builtins = { version = "0.1", optional = true } [features] default = [] -rustc-dep-of-std = [ - "core", - "compiler_builtins/rustc-dep-of-std", -] +rustc-dep-of-std = ["core"] [lints.rust] unexpected_cfgs = { level = "allow", check-cfg = ['cfg(rust_analyzer)'] } diff --git a/lib/abi-serde/Cargo.toml b/lib/abi-serde/Cargo.toml index 4ef6a9db..1ffea837 100644 --- a/lib/abi-serde/Cargo.toml +++ b/lib/abi-serde/Cargo.toml @@ -1,10 +1,9 @@ [package] name = "abi-serde" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] -compiler_builtins = { version = "0.1", optional = true } core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } rustc_std_alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } @@ -13,7 +12,6 @@ default = [] rustc-dep-of-std = [ "core", "rustc_std_alloc", - "compiler_builtins/rustc-dep-of-std", ] [lints] diff --git a/lib/abi/Cargo.toml b/lib/abi/Cargo.toml index 2fa3131a..d08a8ebf 100644 --- a/lib/abi/Cargo.toml +++ b/lib/abi/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yggdrasil-abi" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -9,7 +9,6 @@ authors = ["Mark Poliakov "] [dependencies] core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } rustc_std_alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } -compiler_builtins = { version = "0.1", optional = true } abi-serde = { path = "../abi-serde" } @@ -33,7 +32,6 @@ serde_kernel = ["serde", "serde/alloc"] rustc-dep-of-std = [ "core", "rustc_std_alloc", - "compiler_builtins/rustc-dep-of-std", "abi-lib/rustc-dep-of-std", "abi-serde/rustc-dep-of-std" ] diff --git a/lib/abi/src/lib.rs b/lib/abi/src/lib.rs index d9abe9ed..8920ed3a 100644 --- a/lib/abi/src/lib.rs +++ b/lib/abi/src/lib.rs @@ -8,7 +8,7 @@ incomplete_features, stable_features )] -#![feature(trace_macros, const_trait_impl, ip_in_core)] +#![feature(ip_in_core)] #![warn(missing_docs)] #[cfg(all(any(feature = "alloc", test), not(feature = "rustc-dep-of-std")))] diff --git a/lib/abi/src/time.rs b/lib/abi/src/time.rs index ba2a9ac2..334f7522 100644 --- a/lib/abi/src/time.rs +++ b/lib/abi/src/time.rs @@ -54,6 +54,14 @@ impl SystemTime { nanoseconds: 0, }; + /// Minimum representable system time + pub const MIN: Self = Self::ZERO; + /// Maximum representable system time + pub const MAX: Self = Self { + seconds: u64::MAX, + nanoseconds: 999999999, + }; + /// Constructs a new [SystemTime] from seconds and nanoseconds, without performing /// any adjustments. /// diff --git a/lib/libutil/Cargo.toml b/lib/libutil/Cargo.toml index f7b6bb06..079e8349 100644 --- a/lib/libutil/Cargo.toml +++ b/lib/libutil/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libutil" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] diff --git a/lib/libyalloc/Cargo.toml b/lib/libyalloc/Cargo.toml index 0b22088a..81cf5df1 100644 --- a/lib/libyalloc/Cargo.toml +++ b/lib/libyalloc/Cargo.toml @@ -1,15 +1,13 @@ [package] name = "libyalloc" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } -compiler_builtins = { version = "0.1", optional = true } - [target.'cfg(unix)'.dependencies] libc = { version = "0.2.140", default-features = false } @@ -22,8 +20,6 @@ global = [] dep-of-kernel = [] rustc-dep-of-std = [ "core", - "compiler_builtins", - "compiler_builtins/rustc-dep-of-std", "libc/rustc-dep-of-std", "yggdrasil-rt/rustc-dep-of-std" ] diff --git a/lib/libyalloc/src/allocator.rs b/lib/libyalloc/src/allocator.rs index 6c59dee8..c0fa3066 100644 --- a/lib/libyalloc/src/allocator.rs +++ b/lib/libyalloc/src/allocator.rs @@ -62,7 +62,7 @@ where unsafe fn free(&mut self, ptr: NonNull) { let mut node = self.head; while let Some(mut bucket) = node { - let bucket = bucket.as_mut(); + let bucket = unsafe { bucket.as_mut() }; if let (true, _last) = bucket.free(ptr) { // TODO free the node if last? @@ -137,16 +137,18 @@ impl BucketAllocator

{ pub unsafe fn free(&mut self, ptr: NonNull, layout: Layout) { let aligned = layout.pad_to_align(); - match aligned.size() { - size if size <= 32 => self.buckets_32.free(ptr), - size if size <= 64 => self.buckets_64.free(ptr), - size if size <= 128 => self.buckets_128.free(ptr), - size if size <= 256 => self.buckets_256.free(ptr), - size if size <= 512 => self.buckets_512.free(ptr), - size if size <= 1024 => self.buckets_1024.free(ptr), - size => { - assert_eq!(usize::from(ptr.addr()) % sys::PAGE_SIZE, 0); - P::unmap_pages(ptr, size.div_ceil(sys::PAGE_SIZE)); + unsafe { + match aligned.size() { + size if size <= 32 => self.buckets_32.free(ptr), + size if size <= 64 => self.buckets_64.free(ptr), + size if size <= 128 => self.buckets_128.free(ptr), + size if size <= 256 => self.buckets_256.free(ptr), + size if size <= 512 => self.buckets_512.free(ptr), + size if size <= 1024 => self.buckets_1024.free(ptr), + size => { + assert_eq!(usize::from(ptr.addr()) % sys::PAGE_SIZE, 0); + P::unmap_pages(ptr, size.div_ceil(sys::PAGE_SIZE)); + } } } } diff --git a/lib/libyalloc/src/global.rs b/lib/libyalloc/src/global.rs index 411de36d..30fe7192 100644 --- a/lib/libyalloc/src/global.rs +++ b/lib/libyalloc/src/global.rs @@ -22,7 +22,7 @@ unsafe impl GlobalAlloc for GlobalAllocator { #[inline] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { let ptr = NonNull::new(ptr).expect("Invalid pointer"); - GLOBAL_ALLOCATOR.lock().free(ptr, layout); + unsafe { GLOBAL_ALLOCATOR.lock().free(ptr, layout) }; } } @@ -33,7 +33,7 @@ unsafe impl Allocator for GlobalAllocator { } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { - GLOBAL_ALLOCATOR.lock().free(ptr, layout); + unsafe { GLOBAL_ALLOCATOR.lock().free(ptr, layout) }; } } diff --git a/lib/libyalloc/src/lib.rs b/lib/libyalloc/src/lib.rs index fcb3f0e0..74c5acb3 100644 --- a/lib/libyalloc/src/lib.rs +++ b/lib/libyalloc/src/lib.rs @@ -2,8 +2,6 @@ generic_const_exprs, arbitrary_self_types, let_chains, - test, - allocator_api, unsigned_is_multiple_of )] #![cfg_attr(not(test), no_std)] @@ -13,6 +11,8 @@ clippy::new_without_default, stable_features )] +#![cfg_attr(test, feature(test))] +#![cfg_attr(feature = "global", feature(allocator_api))] #[cfg(test)] extern crate test; diff --git a/lib/libyalloc/src/util.rs b/lib/libyalloc/src/util.rs index 19fcadb5..83adcd34 100644 --- a/lib/libyalloc/src/util.rs +++ b/lib/libyalloc/src/util.rs @@ -17,7 +17,7 @@ pub trait NonNullExt { impl NonNullExt for NonNull { unsafe fn add_ext(self, offset: usize) -> Self { - NonNull::new_unchecked(self.as_ptr().add(offset)) + unsafe { NonNull::new_unchecked(self.as_ptr().add(offset)) } } } diff --git a/lib/qemu/Cargo.toml b/lib/qemu/Cargo.toml index 8399fe3e..ad143fd1 100644 --- a/lib/qemu/Cargo.toml +++ b/lib/qemu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qemu" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 9666a177..3914e490 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yggdrasil-rt" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] build = "build.rs" @@ -10,7 +10,6 @@ yggdrasil-abi = { path = "../abi", features = ["alloc"] } core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } -compiler_builtins = { version = "0.1", optional = true } libm = { git = "https://git.alnyan.me/yggdrasil/libm.git", optional = true } abi-lib = { path = "../abi-lib" } @@ -27,7 +26,7 @@ __tls_get_addr = [] rustc-dep-of-std = [ "core", "alloc", - "compiler_builtins/rustc-dep-of-std", + "__tls_get_addr", "yggdrasil-abi/rustc-dep-of-std", "abi-lib/rustc-dep-of-std", "abi-serde/rustc-dep-of-std", diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs index 06ff24bc..c41eeb6a 100644 --- a/lib/runtime/build.rs +++ b/lib/runtime/build.rs @@ -28,11 +28,25 @@ fn build_libm() { let mut build = cc::Build::new(); + let rust_target = env::var("TARGET").unwrap(); + let cc_target = match rust_target.as_ref() { + "x86_64-unknown-none" | "x86_64-unknown-yggdrasil" => "x86_64-unknown-none", + "aarch64-unknown-none" | "aarch64-unknown-yggdrasil" => "aarch64-unknown-none", + "riscv64-unknown-yggdrasil" | "riscv64-unknown-none" => "riscv64-unknown-none", + _ => todo!("{rust_target:?}"), + }; + build .compiler("clang") .flag("-ffreestanding") .flag("-nostdlib"); + if cc_target == "riscv64-unknown-none" { + build.flag("--target=riscv64-unknown-none"); + } else { + build.target(cc_target); + } + add_file(&mut build, "libm/e_fmodf.c"); add_file(&mut build, "libm/e_hypotf.c"); add_file(&mut build, "libm/e_log.c"); diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 0306ff9b..60864589 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -8,13 +8,14 @@ generic_const_exprs, maybe_uninit_array_assume_init )] +#![allow(unused_features)] #![no_std] #![warn(missing_docs)] #![allow(nonstandard_style, clippy::new_without_default, incomplete_features)] -#[cfg(not(rust_analyzer))] -#[allow(unused_extern_crates)] -extern crate compiler_builtins; +// #[cfg(not(any(rust_analyzer, test)))] +// #[allow(unused_extern_crates)] +// extern crate compiler_builtins; #[allow(unused_extern_crates)] extern crate alloc; diff --git a/lib/runtime/src/mem.rs b/lib/runtime/src/mem.rs index 0c2c0a32..4fe942a3 100644 --- a/lib/runtime/src/mem.rs +++ b/lib/runtime/src/mem.rs @@ -6,12 +6,12 @@ pub use abi::mem::{MappingFlags, MappingSource}; mod intrinsics { use core::ffi::{c_char, c_void}; - #[no_mangle] + #[unsafe(no_mangle)] unsafe extern "C" fn bcmp(p0: *const c_void, p1: *const c_void, len: usize) -> i32 { - memcmp(p0, p1, len) + unsafe { memcmp(p0, p1, len) } } - #[no_mangle] + #[unsafe(no_mangle)] unsafe extern "C" fn memcmp(p0: *const c_void, p1: *const c_void, len: usize) -> i32 { let mut offset = 0; @@ -20,8 +20,8 @@ mod intrinsics { } while offset < len { - let c0 = (p0 as *const u8).add(offset).read_volatile(); - let c1 = (p1 as *const u8).add(offset).read_volatile(); + let c0 = unsafe { (p0 as *const u8).add(offset).read_volatile() }; + let c1 = unsafe { (p1 as *const u8).add(offset).read_volatile() }; if c0 > c1 { return (c0 - c1) as i32; @@ -35,35 +35,71 @@ mod intrinsics { 0 } - #[no_mangle] + #[unsafe(no_mangle)] pub unsafe extern "C" fn memcpy(p0: *mut c_void, p1: *const c_void, len: usize) -> *mut c_void { - compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _ + let p0 = p0.cast::(); + let p1 = p1.cast::(); + let mut offset = 0; + while offset < len { + unsafe { + p0.add(offset) + .write_volatile(p1.add(offset).read_volatile()); + } + offset += 1; + } + p0.cast() + // compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _ } - #[no_mangle] + #[unsafe(no_mangle)] unsafe extern "C" fn memmove(dst: *mut c_void, src: *const c_void, n: usize) -> *mut c_void { - compiler_builtins::mem::memmove(dst as _, src as _, n) as _ + let dst = dst.cast::(); + let src = src.cast::(); + + if dst.addr() == src.addr() || n == 0 { + return dst.cast(); + } + + if (dst as usize) < (src as usize) { + // Copy forward + let mut i = 0; + while i < n { + unsafe { *dst.add(i) = *src.add(i) }; + i += 1; + } + } else { + // Copy backward (handles overlap) + let mut i = n; + while i != 0 { + i -= 1; + unsafe { *dst.add(i) = *src.add(i) }; + } + } + + dst.cast() } - #[no_mangle] + #[unsafe(no_mangle)] unsafe extern "C" fn memset(dst: *mut c_void, val: i32, len: usize) -> *mut c_void { let mut offset = 0; while offset < len { - (dst as *mut u8).add(offset).write_volatile(val as u8); + unsafe { (dst as *mut u8).add(offset).write_volatile(val as u8) }; offset += 1; } dst } - #[no_mangle] + #[unsafe(no_mangle)] unsafe extern "C" fn strlen(mut s: *mut c_char) -> usize { if s.is_null() { return 0; } let mut len = 0; - while s.read() != 0 { - len += 1; - s = s.add(1); + unsafe { + while s.read() != 0 { + len += 1; + s = s.add(1); + } } len } diff --git a/lib/runtime/src/process/signal.rs b/lib/runtime/src/process/signal.rs index b5f10349..6851e62d 100644 --- a/lib/runtime/src/process/signal.rs +++ b/lib/runtime/src/process/signal.rs @@ -42,13 +42,13 @@ unsafe extern "C" fn common_signal_entry(data: &SignalEntryData) -> ! { SignalHandler::Rust(function) => function(data.signal), SignalHandler::C(function) => { let signum = data.signal.into_raw() as i32; - function(signum); + unsafe { function(signum) }; } SignalHandler::Terminate => terminate_by_signal(data.signal), SignalHandler::Ignore => (), } - crate::sys::exit_signal(data) + unsafe { crate::sys::exit_signal(data) } } // TODO add signal print hook function to dump signal info here diff --git a/lib/runtime/src/process/thread.rs b/lib/runtime/src/process/thread.rs index 9e3842aa..fac467eb 100644 --- a/lib/runtime/src/process/thread.rs +++ b/lib/runtime/src/process/thread.rs @@ -149,13 +149,15 @@ impl Thread { /// /// This function has to be called with the same `Self` type as the thread it was created with. pub unsafe fn current() -> Arc { - let raw: *const Self = ptr::with_exposed_provenance(SELF); - if raw.is_null() { - panic!("Thread::SELF == NULL, was spawn() called with runtime=false?"); + unsafe { + let raw: *const Self = ptr::with_exposed_provenance(SELF); + if raw.is_null() { + panic!("Thread::SELF == NULL, was spawn() called with runtime=false?"); + } + // This will "move" the pointer, so an extra strong count increment is required. + Arc::increment_strong_count(raw); + Arc::from_raw(raw) } - // This will "move" the pointer, so an extra strong count increment is required. - Arc::increment_strong_count(raw); - Arc::from_raw(raw) } extern "C" fn thread_entry(raw: usize) -> ! { @@ -301,5 +303,5 @@ pub unsafe fn track_main() { id: AtomicU32::new(0), result: RwLock::new(None), }); - SELF = Arc::into_raw(main).addr(); + unsafe { SELF = Arc::into_raw(main).addr() }; } diff --git a/lib/runtime/src/process/thread_local/mod.rs b/lib/runtime/src/process/thread_local/mod.rs index c362ccc5..d530c50d 100644 --- a/lib/runtime/src/process/thread_local/mod.rs +++ b/lib/runtime/src/process/thread_local/mod.rs @@ -332,9 +332,11 @@ pub fn get_dtv() -> &'static mut Dtv { any(target_arch = "x86", target_arch = "x86_64", target_arch = "riscv64"), any(feature = "__tls_get_addr", rust_analyzer) ))] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __tls_get_addr(index: *mut usize) -> *mut c_void { - let module_id = index.read(); - let offset = index.add(1).read(); - get_dtv().get(module_id).add(offset) + unsafe { + let module_id = index.read(); + let offset = index.add(1).read() as isize; + get_dtv().get(module_id).offset(offset) + } } diff --git a/lib/runtime/src/process/thread_local/riscv64.rs b/lib/runtime/src/process/thread_local/riscv64.rs index 53188a80..de0dcf6a 100644 --- a/lib/runtime/src/process/thread_local/riscv64.rs +++ b/lib/runtime/src/process/thread_local/riscv64.rs @@ -14,6 +14,6 @@ pub fn get_thread_pointer() -> usize { /// /// Usual pointer rules apply. pub unsafe fn set_thread_pointer(value: usize) -> Result<(), Error> { - core::arch::asm!("mv tp, {0}", in(reg) value); + unsafe { core::arch::asm!("mv tp, {0}", in(reg) value) }; Ok(()) } diff --git a/lib/runtime/src/sys/aarch64.rs b/lib/runtime/src/sys/aarch64.rs index e7194416..fe1d6163 100644 --- a/lib/runtime/src/sys/aarch64.rs +++ b/lib/runtime/src/sys/aarch64.rs @@ -3,42 +3,52 @@ macro_rules! syscall { ($num:expr $(,)?) => {{ let mut res: usize; - core::arch::asm!("svc #0", lateout("x0") res, in("x8") usize::from($num)); + unsafe { core::arch::asm!("svc #0", lateout("x0") res, in("x8") usize::from($num)) }; res }}; ($num:expr, $a0:expr $(,)?) => {{ let mut res: usize = $a0; - core::arch::asm!("svc #0", - inlateout("x0") res, - in("x8") usize::from($num)); + unsafe { + core::arch::asm!("svc #0", + inlateout("x0") res, + in("x8") usize::from($num)) + }; res }}; ($num:expr, $a0:expr, $a1:expr $(,)?) => {{ let mut res: usize = $a0; - core::arch::asm!("svc #0", - inlateout("x0") res, in("x1") $a1, - in("x8") usize::from($num)); + unsafe { + core::arch::asm!("svc #0", + inlateout("x0") res, in("x1") $a1, + in("x8") usize::from($num)); + } res }}; ($num:expr, $a0:expr, $a1:expr, $a2:expr $(,)?) => {{ let mut res: usize = $a0; - core::arch::asm!("svc #0", - inlateout("x0") res, in("x1") $a1, in("x2") $a2, - in("x8") usize::from($num)); + unsafe { + core::arch::asm!("svc #0", + inlateout("x0") res, in("x1") $a1, in("x2") $a2, + in("x8") usize::from($num)); + } res }}; ($num:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr $(,)?) => {{ let mut res: usize = $a0; - core::arch::asm!("svc #0", - inlateout("x0") res, in("x1") $a1, in("x2") $a2, - in("x3") $a3, in("x8") usize::from($num)); + unsafe { + core::arch::asm!("svc #0", + inlateout("x0") res, in("x1") $a1, in("x2") $a2, + in("x3") $a3, in("x8") usize::from($num)); + } res }}; ($num:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr $(,)?) => {{ let mut res: usize = $a0; - core::arch::asm!("svc #0", - inlateout("x0") res, in("x1") $a1, in("x2") $a2, - in("x3") $a3, in("x4") $a4, in("x8") usize::from($num)); + unsafe { + core::arch::asm!("svc #0", + inlateout("x0") res, in("x1") $a1, in("x2") $a2, + in("x3") $a3, in("x4") $a4, in("x8") usize::from($num)); + } res }}; } diff --git a/lib/runtime/src/sys/riscv64.rs b/lib/runtime/src/sys/riscv64.rs index 2eed7ac4..ad76dbca 100644 --- a/lib/runtime/src/sys/riscv64.rs +++ b/lib/runtime/src/sys/riscv64.rs @@ -3,49 +3,55 @@ macro_rules! syscall { ($num:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!("ecall", inlateout("a0") a0); + unsafe { core::arch::asm!("ecall", inlateout("a0") a0) }; a0 }}; ($num:expr, $a1:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!("ecall", inlateout("a0") a0, in("a1") $a1); + unsafe { core::arch::asm!("ecall", inlateout("a0") a0, in("a1") $a1) }; a0 }}; ($num:expr, $a1:expr, $a2:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!("ecall", inlateout("a0") a0, in("a1") $a1, in("a2") $a2); + unsafe { core::arch::asm!("ecall", inlateout("a0") a0, in("a1") $a1, in("a2") $a2) }; a0 }}; ($num:expr, $a1:expr, $a2:expr, $a3:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!("ecall", inlateout("a0") a0, in("a1") $a1, in("a2") $a2, in("a3") $a3); + unsafe { core::arch::asm!("ecall", inlateout("a0") a0, in("a1") $a1, in("a2") $a2, in("a3") $a3) }; a0 }}; ($num:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!( - "ecall", - inlateout("a0") a0, - in("a1") $a1, in("a2") $a2, in("a3") $a3, in("a4") $a4 - ); + unsafe { + core::arch::asm!( + "ecall", + inlateout("a0") a0, + in("a1") $a1, in("a2") $a2, in("a3") $a3, in("a4") $a4 + ); + } a0 }}; ($num:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!( - "ecall", - inlateout("a0") a0, - in("a1") $a1, in("a2") $a2, in("a3") $a3, in("a4") $a4, in("a5") $a5 - ); + unsafe { + core::arch::asm!( + "ecall", + inlateout("a0") a0, + in("a1") $a1, in("a2") $a2, in("a3") $a3, in("a4") $a4, in("a5") $a5 + ); + } a0 }}; ($num:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr $(,)?) => {{ let mut a0 = usize::from($num); - core::arch::asm!( - "ecall", - inlateout("a0") a0, - in("a1") $a1, in("a2") $a2, in("a3") $a3, in("a4") $a4, in("a5") $a5, in("a6") $a6 - ); + unsafe { + core::arch::asm!( + "ecall", + inlateout("a0") a0, + in("a1") $a1, in("a2") $a2, in("a3") $a3, in("a4") $a4, in("a5") $a5, in("a6") $a6 + ); + } a0 }}; } diff --git a/lib/runtime/src/sys/x86_64.rs b/lib/runtime/src/sys/x86_64.rs index 94bf1367..1e473393 100644 --- a/lib/runtime/src/sys/x86_64.rs +++ b/lib/runtime/src/sys/x86_64.rs @@ -3,104 +3,116 @@ macro_rules! syscall { ($num:expr $(,)?) => {{ let mut res = usize::from($num); - core::arch::asm!( - "syscall", - inlateout("rax") res, - out("rdi") _, - out("rsi") _, - out("rdx") _, - out("r10") _, - out("r8") _, - out("r9") _, - // Clobbered by syscall - out("rcx") _, - out("r11") _, - ); + unsafe { + core::arch::asm!( + "syscall", + inlateout("rax") res, + out("rdi") _, + out("rsi") _, + out("rdx") _, + out("r10") _, + out("r8") _, + out("r9") _, + // Clobbered by syscall + out("rcx") _, + out("r11") _, + ); + } res }}; ($num:expr, $a0:expr $(,)?) => {{ let mut res = usize::from($num); - core::arch::asm!( - "syscall", - inlateout("rax") res, - in("rdi") $a0, - out("rsi") _, - out("rdx") _, - out("r10") _, - out("r8") _, - out("r9") _, - // Clobbered by syscall - out("rcx") _, - out("r11") _, - ); + unsafe { + core::arch::asm!( + "syscall", + inlateout("rax") res, + in("rdi") $a0, + out("rsi") _, + out("rdx") _, + out("r10") _, + out("r8") _, + out("r9") _, + // Clobbered by syscall + out("rcx") _, + out("r11") _, + ); + } res }}; ($num:expr, $a0:expr, $a1:expr $(,)?) => {{ let mut res = usize::from($num); - core::arch::asm!( - "syscall", - inlateout("rax") res, - in("rdi") $a0, - in("rsi") $a1, - out("rdx") _, - out("r10") _, - out("r8") _, - out("r9") _, - // Clobbered by syscall - out("rcx") _, - out("r11") _, - ); + unsafe { + core::arch::asm!( + "syscall", + inlateout("rax") res, + in("rdi") $a0, + in("rsi") $a1, + out("rdx") _, + out("r10") _, + out("r8") _, + out("r9") _, + // Clobbered by syscall + out("rcx") _, + out("r11") _, + ); + } res }}; ($num:expr, $a0:expr, $a1:expr, $a2:expr $(,)?) => {{ let mut res = usize::from($num); - core::arch::asm!( - "syscall", - inlateout("rax") res, - in("rdi") $a0, - in("rsi") $a1, - in("rdx") $a2, - out("r10") _, - out("r8") _, - out("r9") _, - // Clobbered by syscall - out("rcx") _, - out("r11") _, - ); + unsafe { + core::arch::asm!( + "syscall", + inlateout("rax") res, + in("rdi") $a0, + in("rsi") $a1, + in("rdx") $a2, + out("r10") _, + out("r8") _, + out("r9") _, + // Clobbered by syscall + out("rcx") _, + out("r11") _, + ); + } res }}; ($num:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr $(,)?) => {{ let mut res = usize::from($num); - core::arch::asm!( - "syscall", - inlateout("rax") res, - in("rdi") $a0, - in("rsi") $a1, - in("rdx") $a2, - in("r10") $a3, - out("r8") _, - out("r9") _, - // Clobbered by syscall - out("rcx") _, - out("r11") _, - ); + unsafe { + core::arch::asm!( + "syscall", + inlateout("rax") res, + in("rdi") $a0, + in("rsi") $a1, + in("rdx") $a2, + in("r10") $a3, + out("r8") _, + out("r9") _, + // Clobbered by syscall + out("rcx") _, + out("r11") _, + ); + } res }}; ($num:expr, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr $(,)?) => {{ let mut res = usize::from($num); - core::arch::asm!( - "syscall", - inlateout("rax") res, - in("rdi") $a0, - in("rsi") $a1, - in("rdx") $a2, - in("r10") $a3, - in("r8") $a4, - out("r9") _, - // Clobbered by syscall - out("rcx") _, - out("r11") _, - ); + unsafe { + core::arch::asm!( + "syscall", + inlateout("rax") res, + in("rdi") $a0, + in("rsi") $a1, + in("rdx") $a2, + in("r10") $a3, + in("r8") $a4, + out("r9") _, + // Clobbered by syscall + out("rcx") _, + out("r11") _, + ); + } res }}; } diff --git a/tool/abi-generator/Cargo.toml b/tool/abi-generator/Cargo.toml index 5400f584..23e4dbeb 100644 --- a/tool/abi-generator/Cargo.toml +++ b/tool/abi-generator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "abi-generator" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] proc-macro2 = { version = "^1.0.63", features = ["span-locations"] } diff --git a/tool/abi-generator/src/abi/mod.rs b/tool/abi-generator/src/abi/mod.rs index da37594e..0adc3e92 100644 --- a/tool/abi-generator/src/abi/mod.rs +++ b/tool/abi-generator/src/abi/mod.rs @@ -1,23 +1,23 @@ use std::{collections::HashMap, path::Path, rc::Rc}; use proc_macro2::{Span, TokenStream}; -use quote::{quote, TokenStreamExt}; -use syn::{punctuated::Punctuated, spanned::Spanned, token, Token}; +use quote::{TokenStreamExt, quote}; +use syn::{Token, punctuated::Punctuated, spanned::Spanned, token}; pub mod ty; use crate::{ + TargetEnv, abi::ty::{AbiPrimitive, ComplexType, SimpleType}, error::Error, syntax::{ - parse_abi, Attributes, BitfieldDefaultValue, BitfieldRange, BitfieldType, - BitfieldTypeField, DocumentTypeDefinition, EnumType, EnumTypeVariant, NewType, ParseError, - StructType, TypeRepr, + Attributes, BitfieldDefaultValue, BitfieldRange, BitfieldType, BitfieldTypeField, + DocumentTypeDefinition, EnumType, EnumTypeVariant, NewType, ParseError, StructType, + TypeRepr, parse_abi, }, - TargetEnv, }; -use self::ty::{complex::ExternKind, Type}; +use self::ty::{Type, complex::ExternKind}; mod syscall; @@ -27,6 +27,7 @@ pub trait GenerateTypeDefinition { fn generate_type_definition(&self, abi_type: &ComplexType, env: &TargetEnv) -> TokenStream; } +#[derive(Default)] pub struct TypeEnv { pub locals: HashMap, DocumentTypeDefinition)>, pub externs: HashMap, @@ -316,7 +317,7 @@ impl GenerateTypeDefinition for EnumType { #[allow(clippy::missing_safety_doc)] pub const unsafe fn from_raw(value: #repr) -> Self { - core::mem::transmute(value) + unsafe { core::mem::transmute(value) } } } diff --git a/tool/abi-generator/src/abi/syscall.rs b/tool/abi-generator/src/abi/syscall.rs index d746c41b..a1ed1128 100644 --- a/tool/abi-generator/src/abi/syscall.rs +++ b/tool/abi-generator/src/abi/syscall.rs @@ -5,8 +5,8 @@ use proc_macro2::TokenStream; use quote::quote; use crate::{ - abi::ty::{AbiPrimitive, SimpleType, Type}, TargetEnv, + abi::ty::{AbiPrimitive, SimpleType, Type}, }; use super::ty::ComplexType; diff --git a/tool/abi-generator/src/abi/ty/complex.rs b/tool/abi-generator/src/abi/ty/complex.rs index 8e62cf5c..456396c5 100644 --- a/tool/abi-generator/src/abi/ty/complex.rs +++ b/tool/abi-generator/src/abi/ty/complex.rs @@ -2,7 +2,7 @@ use std::{fmt, rc::Rc}; use proc_macro2::TokenStream; use quote::quote; -use syn::{punctuated::Punctuated, Ident, Token}; +use syn::{Ident, Token, punctuated::Punctuated}; use crate::TargetEnv; diff --git a/tool/abi-generator/src/lib.rs b/tool/abi-generator/src/lib.rs index bc49ae63..feefad76 100644 --- a/tool/abi-generator/src/lib.rs +++ b/tool/abi-generator/src/lib.rs @@ -1,4 +1,5 @@ -#![feature(if_let_guard, extend_one, proc_macro_span)] +#![feature(extend_one, if_let_guard)] +#![allow(stable_features)] use crate::abi::ty::TypeWidth; diff --git a/tool/abi-generator/src/syntax/bitfield_type.rs b/tool/abi-generator/src/syntax/bitfield_type.rs index e09cbd2d..06980261 100644 --- a/tool/abi-generator/src/syntax/bitfield_type.rs +++ b/tool/abi-generator/src/syntax/bitfield_type.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; -use syn::{braced, punctuated::Punctuated, Token}; +use quote::{ToTokens, quote}; +use syn::{Token, braced, punctuated::Punctuated}; use super::{ common::{Attributes, TypeRepr}, diff --git a/tool/abi-generator/src/syntax/common.rs b/tool/abi-generator/src/syntax/common.rs index 420b2e6b..8062d053 100644 --- a/tool/abi-generator/src/syntax/common.rs +++ b/tool/abi-generator/src/syntax/common.rs @@ -1,8 +1,8 @@ use std::ops::{Deref, DerefMut}; use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; -use syn::{parenthesized, Token}; +use quote::{ToTokens, quote}; +use syn::{Token, parenthesized}; #[derive(Clone)] pub struct TypeRepr(pub syn::Ident); diff --git a/tool/abi-generator/src/syntax/document.rs b/tool/abi-generator/src/syntax/document.rs index 40b9b5c5..59d06777 100644 --- a/tool/abi-generator/src/syntax/document.rs +++ b/tool/abi-generator/src/syntax/document.rs @@ -1,5 +1,5 @@ use quote::ToTokens; -use syn::{parse::ParseStream, Token}; +use syn::{Token, parse::ParseStream}; use super::{ bitfield_type::BitfieldType, diff --git a/tool/abi-generator/src/syntax/enum_type.rs b/tool/abi-generator/src/syntax/enum_type.rs index 21657c5b..76a42d88 100644 --- a/tool/abi-generator/src/syntax/enum_type.rs +++ b/tool/abi-generator/src/syntax/enum_type.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; -use syn::{braced, punctuated::Punctuated, Token}; +use quote::{ToTokens, quote}; +use syn::{Token, braced, punctuated::Punctuated}; use super::{ common::{Attributes, TypeRepr}, diff --git a/tool/abi-generator/src/syntax/extern_block.rs b/tool/abi-generator/src/syntax/extern_block.rs index 6c204572..1b5c68d8 100644 --- a/tool/abi-generator/src/syntax/extern_block.rs +++ b/tool/abi-generator/src/syntax/extern_block.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; -use syn::{braced, punctuated::Punctuated, Token}; +use quote::{ToTokens, quote}; +use syn::{Token, braced, punctuated::Punctuated}; use super::Attributes; diff --git a/tool/abi-generator/src/syntax/mod.rs b/tool/abi-generator/src/syntax/mod.rs index bfbd7f44..f5629d5b 100644 --- a/tool/abi-generator/src/syntax/mod.rs +++ b/tool/abi-generator/src/syntax/mod.rs @@ -1,11 +1,10 @@ use std::{rc::Rc, str::FromStr}; -use syn::{punctuated::Punctuated, Expr, ExprLit, Lit, PathSegment}; +use syn::{Expr, ExprLit, Lit, PathSegment, punctuated::Punctuated}; use crate::abi::{ - syscall_enum_variant_identifier, - ty::{complex::ExternKind, AbiPrimitive, ComplexType, SimpleType}, - Abi, Syscall, TypeEnv, + Abi, Syscall, TypeEnv, syscall_enum_variant_identifier, + ty::{AbiPrimitive, ComplexType, SimpleType, complex::ExternKind}, }; mod common; diff --git a/tool/abi-generator/src/syntax/newtype.rs b/tool/abi-generator/src/syntax/newtype.rs index 40242182..0959dfed 100644 --- a/tool/abi-generator/src/syntax/newtype.rs +++ b/tool/abi-generator/src/syntax/newtype.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; +use quote::{ToTokens, quote}; use syn::Token; use super::{ diff --git a/tool/abi-generator/src/syntax/struct_type.rs b/tool/abi-generator/src/syntax/struct_type.rs index a1423cb0..8583511b 100644 --- a/tool/abi-generator/src/syntax/struct_type.rs +++ b/tool/abi-generator/src/syntax/struct_type.rs @@ -1,4 +1,4 @@ -use quote::{quote, ToTokens}; +use quote::{ToTokens, quote}; use super::document::DocumentItemAttributes; diff --git a/tool/abi-generator/src/syntax/syscall.rs b/tool/abi-generator/src/syntax/syscall.rs index 5c6caf56..b3885b7e 100644 --- a/tool/abi-generator/src/syntax/syscall.rs +++ b/tool/abi-generator/src/syntax/syscall.rs @@ -1,5 +1,5 @@ -use quote::{quote, ToTokens}; -use syn::{parenthesized, parse::ParseStream, punctuated::Punctuated, Ident, Token}; +use quote::{ToTokens, quote}; +use syn::{Ident, Token, parenthesized, parse::ParseStream, punctuated::Punctuated}; use super::{common::Attributes, document::DocumentItemAttributes}; diff --git a/userspace/dyn-loader/Cargo.toml b/userspace/dyn-loader/Cargo.toml index 5038573a..6193e317 100644 --- a/userspace/dyn-loader/Cargo.toml +++ b/userspace/dyn-loader/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dyn-loader" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-rt.workspace = true diff --git a/userspace/dyn-loader/src/builtins.rs b/userspace/dyn-loader/src/builtins.rs index 8fdb1f86..727495cf 100644 --- a/userspace/dyn-loader/src/builtins.rs +++ b/userspace/dyn-loader/src/builtins.rs @@ -22,7 +22,7 @@ pub struct Dl_info { // Has to be naked: need to prevent the function from clobbering any registers besides x0 #[cfg(any(target_arch = "aarch64", rust_analyzer))] -#[naked] +#[unsafe(naked)] pub(crate) unsafe extern "C" fn tlsdesc_resolve_static(argument: *const usize) -> usize { // x0 -- pointer to tlsdesc struct: // [0]: this function pointer @@ -53,13 +53,13 @@ pub(crate) unsafe extern "C" fn dlerror(_object: *mut c_void) -> c_int { pub(crate) unsafe extern "C" fn dladdr(addr: *mut c_void, info: *mut Dl_info) -> c_int { #[allow(static_mut_refs)] - let objects = OBJECTS.assume_init_ref(); + let objects = unsafe { OBJECTS.assume_init_ref() }; let Some(symbol) = objects.lookup_address(addr.addr()) else { log::warn!("dladdr({addr:p}) -> NULL"); return 0; }; - if let Some(info) = info.as_mut() { + if let Some(info) = unsafe { info.as_mut() } { info.dli_sname = symbol.symbol_name.as_ptr(); info.dli_saddr = ptr::with_exposed_provenance_mut(symbol.symbol_base); info.dli_fname = symbol.object_name.as_ptr(); diff --git a/userspace/dyn-loader/src/env.rs b/userspace/dyn-loader/src/env.rs index 2fd2bdbe..18055b73 100644 --- a/userspace/dyn-loader/src/env.rs +++ b/userspace/dyn-loader/src/env.rs @@ -1,7 +1,7 @@ use bytemuck::Pod; use yggdrasil_rt::{ mem::MappingFlags, - process::{auxv, AuxValue}, + process::{AuxValue, auxv}, }; use crate::{error::Error, mapping::Mapping}; diff --git a/userspace/dyn-loader/src/main.rs b/userspace/dyn-loader/src/main.rs index 83637582..06777e91 100644 --- a/userspace/dyn-loader/src/main.rs +++ b/userspace/dyn-loader/src/main.rs @@ -1,12 +1,4 @@ -#![feature( - yggdrasil_os, - never_type, - map_try_insert, - slice_ptr_get, - iter_chain, - naked_functions, - let_chains -)] +#![feature(yggdrasil_os, never_type, map_try_insert, slice_ptr_get)] #![allow( clippy::new_without_default, clippy::missing_transmute_annotations, @@ -19,7 +11,7 @@ use config::Config; use error::Error; use object::Object; use state::ObjectSet; -use yggdrasil_rt::process::{auxv, AuxValue}; +use yggdrasil_rt::process::{AuxValue, auxv}; pub mod builtins; pub mod config; diff --git a/userspace/dyn-loader/src/object.rs b/userspace/dyn-loader/src/object.rs index 1d7be1e2..aef5b75d 100644 --- a/userspace/dyn-loader/src/object.rs +++ b/userspace/dyn-loader/src/object.rs @@ -11,6 +11,7 @@ use std::{ }; use elf::{ + ElfStream, abi::{ DF_1_PIE, DT_FINI, DT_FINI_ARRAY, DT_FINI_ARRAYSZ, DT_FLAGS_1, DT_INIT, DT_INIT_ARRAY, DT_INIT_ARRAYSZ, DT_NEEDED, DT_PREINIT_ARRAY, DT_PREINIT_ARRAYSZ, ET_DYN, ET_EXEC, @@ -22,7 +23,6 @@ use elf::{ parse::ParsingIterator, segment::ProgramHeader, symbol::Symbol, - ElfStream, }; use yggdrasil_rt::mem::MappingFlags; @@ -364,13 +364,13 @@ impl Object { type Constructor = extern "C" fn(); for slot in range.step_by(size_of::()) { - let func = ptr::with_exposed_provenance::(slot).read_unaligned(); + let func = unsafe { ptr::with_exposed_provenance::(slot).read_unaligned() }; if func == 0 || func == usize::MAX { continue; } - let func = mem::transmute::<_, Constructor>(func); + let func = unsafe { mem::transmute::<_, Constructor>(func) }; log::debug!("ld: call constructor {func:p}"); func(); @@ -383,7 +383,7 @@ impl Object { /// this function. pub unsafe fn call_early_constructors(&mut self) { if let Some(pre_init_array) = self.pre_init_array.as_ref() { - Self::call_constructor_list(pre_init_array.clone()); + unsafe { Self::call_constructor_list(pre_init_array.clone()) }; } } @@ -393,7 +393,7 @@ impl Object { /// this function. pub unsafe fn call_constructors(&mut self) { if let Some(init_array) = self.init_array.as_ref() { - Self::call_constructor_list(init_array.clone()); + unsafe { Self::call_constructor_list(init_array.clone()) }; } } diff --git a/userspace/dyn-loader/src/relocation/aarch64.rs b/userspace/dyn-loader/src/relocation/aarch64.rs index 0d18813e..20444e48 100644 --- a/userspace/dyn-loader/src/relocation/aarch64.rs +++ b/userspace/dyn-loader/src/relocation/aarch64.rs @@ -1,7 +1,7 @@ use elf::{ abi::{ R_AARCH64_ABS64, R_AARCH64_GLOB_DAT, R_AARCH64_JUMP_SLOT, R_AARCH64_RELATIVE, - R_AARCH64_TLSDESC, R_AARCH64_TLS_TPREL, + R_AARCH64_TLS_TPREL, R_AARCH64_TLSDESC, }, relocation::{Rel, Rela}, }; @@ -32,7 +32,7 @@ fn make_tlsdesc_relocation( panic!("TLSDESC relocation against unknown module_id={module_id}, offset={symbol_offset}"); }; - let resolver = builtins::tlsdesc_resolve_static as usize; + let resolver = (builtins::tlsdesc_resolve_static as *const ()).addr(); RelaValue::DQWord(resolver as i64, offset as i64) } diff --git a/userspace/dyn-loader/src/state.rs b/userspace/dyn-loader/src/state.rs index 3ca191a1..ddd57dba 100644 --- a/userspace/dyn-loader/src/state.rs +++ b/userspace/dyn-loader/src/state.rs @@ -173,7 +173,7 @@ impl State { } } - pub fn lookup(&self, sym: &DynamicSymbol) -> Option { + pub fn lookup(&self, sym: &DynamicSymbol) -> Option> { match sym.raw.st_symtype() { STT_FUNC | STT_OBJECT | STT_NOTYPE => { self.symbol_table.get(&sym.name).map(ExportedSymbol::Normal) @@ -222,12 +222,12 @@ impl State { } pub fn add_magic_symbols(&mut self) { - self.export_magic_symbol("dlopen", crate::builtins::dlopen as usize); - self.export_magic_symbol("dlclose", crate::builtins::dlclose as usize); - self.export_magic_symbol("dlsym", crate::builtins::dlsym as usize); - self.export_magic_symbol("dlerror", crate::builtins::dlerror as usize); - self.export_magic_symbol("dladdr", crate::builtins::dladdr as usize); - self.export_magic_symbol("dladdr1", crate::builtins::dladdr1 as usize); + self.export_magic_symbol("dlopen", (crate::builtins::dlopen as *const ()).addr()); + self.export_magic_symbol("dlclose", (crate::builtins::dlclose as *const ()).addr()); + self.export_magic_symbol("dlsym", (crate::builtins::dlsym as *const ()).addr()); + self.export_magic_symbol("dlerror", (crate::builtins::dlerror as *const ()).addr()); + self.export_magic_symbol("dladdr", (crate::builtins::dladdr as *const ()).addr()); + self.export_magic_symbol("dladdr1", (crate::builtins::dladdr1 as *const ()).addr()); } } @@ -347,7 +347,7 @@ impl ObjectSet { } } - pub fn lookup_address(&self, address: usize) -> Option { + pub fn lookup_address(&self, address: usize) -> Option> { // Lookup in stuff exported from .dynsym for (_, symbol) in self.state.symbol_table.iter() { if address >= symbol.value && address - symbol.value < symbol.size { diff --git a/userspace/dynload-program/Cargo.toml b/userspace/dynload-program/Cargo.toml index 8e3f2c25..d21b7780 100644 --- a/userspace/dynload-program/Cargo.toml +++ b/userspace/dynload-program/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "dynload-program" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-rt.path = "../../lib/runtime" diff --git a/userspace/graphics/colors/Cargo.toml b/userspace/graphics/colors/Cargo.toml index daac6efb..f34249fd 100644 --- a/userspace/graphics/colors/Cargo.toml +++ b/userspace/graphics/colors/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "colors" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [[bin]] diff --git a/userspace/graphics/colors/src/main.rs b/userspace/graphics/colors/src/main.rs index f3a42b02..cb348fbb 100644 --- a/userspace/graphics/colors/src/main.rs +++ b/userspace/graphics/colors/src/main.rs @@ -1,6 +1,5 @@ #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os, rustc_private))] #![allow(clippy::single_match, clippy::collapsible_else_if)] -#![feature(if_let_guard, iter_chain, map_many_mut, let_chains)] use std::{ collections::{BTreeMap, HashMap, HashSet}, diff --git a/userspace/graphics/colors/src/wm/workspace.rs b/userspace/graphics/colors/src/wm/workspace.rs index c6f4f09a..443caa22 100644 --- a/userspace/graphics/colors/src/wm/workspace.rs +++ b/userspace/graphics/colors/src/wm/workspace.rs @@ -308,7 +308,7 @@ impl Workspace { if let Some(parent_nid) = node.parent { let child_nid = container.children.remove(0); let [Some(child), Some(parent)] = - self.nodes.get_many_mut([&child_nid, &parent_nid]) + self.nodes.get_disjoint_mut([&child_nid, &parent_nid]) else { return; }; @@ -585,7 +585,7 @@ impl Workspace { fn add_child_to(&mut self, container_nid: NodeId, child_nid: NodeId) -> bool { let [Some(container_node), Some(child_node)] = - self.nodes.get_many_mut([&container_nid, &child_nid]) + self.nodes.get_disjoint_mut([&container_nid, &child_nid]) else { return false; }; diff --git a/userspace/graphics/iv/Cargo.toml b/userspace/graphics/iv/Cargo.toml index 5d64908a..edcc5929 100644 --- a/userspace/graphics/iv/Cargo.toml +++ b/userspace/graphics/iv/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "iv" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] libcolors = { workspace = true, features = ["client"] } diff --git a/userspace/graphics/term/Cargo.toml b/userspace/graphics/term/Cargo.toml index 07ed849f..6eb96bc5 100644 --- a/userspace/graphics/term/Cargo.toml +++ b/userspace/graphics/term/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "term" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [dependencies] diff --git a/userspace/lib/cross/Cargo.toml b/userspace/lib/cross/Cargo.toml index 2382844d..d8a701e0 100644 --- a/userspace/lib/cross/Cargo.toml +++ b/userspace/lib/cross/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cross" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] bitflags.workspace = true diff --git a/userspace/lib/cryptic/Cargo.toml b/userspace/lib/cryptic/Cargo.toml index 251c3bc9..b4a5a794 100644 --- a/userspace/lib/cryptic/Cargo.toml +++ b/userspace/lib/cryptic/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cryptic" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] cross.workspace = true diff --git a/userspace/lib/hclient/Cargo.toml b/userspace/lib/hclient/Cargo.toml index bc9e68ce..244ec2aa 100644 --- a/userspace/lib/hclient/Cargo.toml +++ b/userspace/lib/hclient/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hclient" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] cryptic = { workspace = true, optional = true } diff --git a/userspace/lib/hclient/src/client.rs b/userspace/lib/hclient/src/client.rs index aa2f747e..3088e7e0 100644 --- a/userspace/lib/hclient/src/client.rs +++ b/userspace/lib/hclient/src/client.rs @@ -1,6 +1,6 @@ use std::{net::ToSocketAddrs, time::Duration}; -use http::{header, response, HeaderName, HeaderValue, StatusCode, Uri}; +use http::{HeaderName, HeaderValue, StatusCode, Uri, header, response}; use crate::{ body::HttpBody, @@ -41,7 +41,7 @@ impl HttpClient { &mut self, method: http::Method, url: U, - ) -> HttpRequestBuilder { + ) -> HttpRequestBuilder<'_, C, U> { HttpRequestBuilder { client: self, url, diff --git a/userspace/lib/libcolors/Cargo.toml b/userspace/lib/libcolors/Cargo.toml index f5d70ddf..a65da1b9 100644 --- a/userspace/lib/libcolors/Cargo.toml +++ b/userspace/lib/libcolors/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libcolors" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] [[example]] diff --git a/userspace/lib/libcolors/src/application/mod.rs b/userspace/lib/libcolors/src/application/mod.rs index 67146fa1..a7534793 100644 --- a/userspace/lib/libcolors/src/application/mod.rs +++ b/userspace/lib/libcolors/src/application/mod.rs @@ -2,8 +2,8 @@ use std::{ collections::BTreeMap, process::ExitCode, sync::{ - atomic::{AtomicBool, Ordering}, Arc, Mutex, + atomic::{AtomicBool, Ordering}, }, }; diff --git a/userspace/lib/libcolors/src/application/window.rs b/userspace/lib/libcolors/src/application/window.rs index 539ca15b..96fadff6 100644 --- a/userspace/lib/libcolors/src/application/window.rs +++ b/userspace/lib/libcolors/src/application/window.rs @@ -7,7 +7,7 @@ use crate::{ surface::{MappedSurface, Surface}, }; -use super::{connection::Connection, Application}; +use super::{Application, connection::Connection}; pub trait OnCloseRequested = Fn() -> EventOutcome; pub trait OnKeyInput = Fn(KeyInput) -> EventOutcome; diff --git a/userspace/lib/libcolors/src/lib.rs b/userspace/lib/libcolors/src/lib.rs index ed0f34d1..c499d17a 100644 --- a/userspace/lib/libcolors/src/lib.rs +++ b/userspace/lib/libcolors/src/lib.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os, rustc_private))] #![cfg_attr(feature = "client", feature(trait_alias))] -#![feature(array_chunks, portable_simd)] +#![feature(portable_simd)] #[cfg(any(rust_analyzer, target_os = "yggdrasil"))] pub const CHANNEL_NAME: &str = "/colors.sock"; diff --git a/userspace/lib/libpsf/Cargo.toml b/userspace/lib/libpsf/Cargo.toml index f00312fb..996fdb88 100644 --- a/userspace/lib/libpsf/Cargo.toml +++ b/userspace/lib/libpsf/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libpsf" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] bytemuck.workspace = true diff --git a/userspace/lib/libterm/Cargo.toml b/userspace/lib/libterm/Cargo.toml index 3c6dd4a7..404dc7fb 100644 --- a/userspace/lib/libterm/Cargo.toml +++ b/userspace/lib/libterm/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libterm" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/userspace/lib/libterm/src/yggdrasil.rs b/userspace/lib/libterm/src/yggdrasil.rs index 299fb82e..6d401203 100644 --- a/userspace/lib/libterm/src/yggdrasil.rs +++ b/userspace/lib/libterm/src/yggdrasil.rs @@ -3,7 +3,7 @@ use std::{ os::{ fd::AsRawFd, yggdrasil::io::terminal::{ - get_terminal_size, set_terminal_options, update_terminal_options, TerminalOptions, + TerminalOptions, get_terminal_size, set_terminal_options, update_terminal_options, }, }, }; @@ -15,14 +15,14 @@ impl RawMode { /// /// May leave the terminal in broken state, unsafe. pub unsafe fn enter(stdin: &F) -> io::Result { - update_terminal_options(stdin, |_| TerminalOptions::raw_input()).map(Self) + unsafe { update_terminal_options(stdin, |_| TerminalOptions::raw_input()).map(Self) } } /// # Safety /// /// May leave the terminal in broken state, unsafe. pub unsafe fn leave(&self, stdin: &F) { - set_terminal_options(stdin, &self.0).ok(); + unsafe { set_terminal_options(stdin, &self.0).ok() }; } } diff --git a/userspace/lib/logsink/Cargo.toml b/userspace/lib/logsink/Cargo.toml index 776bba74..8f14b64b 100644 --- a/userspace/lib/logsink/Cargo.toml +++ b/userspace/lib/logsink/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "logsink" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] log.workspace = true diff --git a/userspace/lib/pixie/Cargo.toml b/userspace/lib/pixie/Cargo.toml index 303f1b0d..31b7986b 100644 --- a/userspace/lib/pixie/Cargo.toml +++ b/userspace/lib/pixie/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pixie" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] bytemuck.workspace = true diff --git a/userspace/lib/pixie/src/jpeg/huffman.rs b/userspace/lib/pixie/src/jpeg/huffman.rs index 00611997..6a3a5343 100644 --- a/userspace/lib/pixie/src/jpeg/huffman.rs +++ b/userspace/lib/pixie/src/jpeg/huffman.rs @@ -101,8 +101,7 @@ impl HuffmanTable { } } - offset[17] = 0; - offset[17] = 0x000F_FFFF; + // offset[17] = 0x000F_FFFF; Ok(Self { lut, diff --git a/userspace/lib/runtime/Cargo.toml b/userspace/lib/runtime/Cargo.toml index b2afb957..b246b969 100644 --- a/userspace/lib/runtime/Cargo.toml +++ b/userspace/lib/runtime/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] diff --git a/userspace/lib/runtime/src/lib.rs b/userspace/lib/runtime/src/lib.rs index 8a123bbb..8278dd6d 100644 --- a/userspace/lib/runtime/src/lib.rs +++ b/userspace/lib/runtime/src/lib.rs @@ -2,6 +2,7 @@ any(rust_analyzer, target_os = "yggdrasil"), feature(yggdrasil_os, rustc_private) )] +#![allow(exported_private_dependencies)] #[cfg(rust_analyzer)] pub use abi_lib; diff --git a/userspace/lib/stuff/Cargo.toml b/userspace/lib/stuff/Cargo.toml index fb1e124f..3429e200 100644 --- a/userspace/lib/stuff/Cargo.toml +++ b/userspace/lib/stuff/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "stuff" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] cross.workspace = true diff --git a/userspace/lib/uipc/Cargo.toml b/userspace/lib/uipc/Cargo.toml index f1825bcd..60569be4 100644 --- a/userspace/lib/uipc/Cargo.toml +++ b/userspace/lib/uipc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "uipc" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] cross.workspace = true diff --git a/userspace/lib/yasync/Cargo.toml b/userspace/lib/yasync/Cargo.toml index 5fdbdea0..ef8df1d2 100644 --- a/userspace/lib/yasync/Cargo.toml +++ b/userspace/lib/yasync/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yasync" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] cross.workspace = true diff --git a/userspace/lib/ygglibc/Cargo.toml b/userspace/lib/ygglibc/Cargo.toml index 87c7c991..1af057d0 100644 --- a/userspace/lib/ygglibc/Cargo.toml +++ b/userspace/lib/ygglibc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ygglibc" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] crate-type = ["cdylib", "staticlib"] diff --git a/userspace/netutils/Cargo.toml b/userspace/netutils/Cargo.toml index a42676e3..882a493c 100644 --- a/userspace/netutils/Cargo.toml +++ b/userspace/netutils/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "netutils" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] yggdrasil-abi.workspace = true diff --git a/userspace/netutils/src/lib.rs b/userspace/netutils/src/lib.rs index 6e2cec41..f32e8cc6 100644 --- a/userspace/netutils/src/lib.rs +++ b/userspace/netutils/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(yggdrasil_os, rustc_private, let_chains)] +#![feature(yggdrasil_os, rustc_private)] use std::io::{self}; @@ -24,4 +24,3 @@ pub enum Error { #[error("Cannot resolve network address: {0:?}")] UnresolvedAddress(String), } - diff --git a/userspace/netutils/src/netconfig.rs b/userspace/netutils/src/netconfig.rs index 9eb54126..f6e48808 100644 --- a/userspace/netutils/src/netconfig.rs +++ b/userspace/netutils/src/netconfig.rs @@ -7,7 +7,7 @@ use std::{ use runtime::{ abi::net::{self, netconfig}, - abi_serde::{wire, Deserialize}, + abi_serde::{Deserialize, wire}, rt, }; diff --git a/userspace/sysutils/Cargo.toml b/userspace/sysutils/Cargo.toml index 8f3d9e80..114762b0 100644 --- a/userspace/sysutils/Cargo.toml +++ b/userspace/sysutils/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sysutils" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/userspace/sysutils/src/chmod.rs b/userspace/sysutils/src/chmod.rs index 9b79d271..215b28e3 100644 --- a/userspace/sysutils/src/chmod.rs +++ b/userspace/sysutils/src/chmod.rs @@ -1,7 +1,6 @@ -#![feature(iter_chain)] use std::{env, iter, process::ExitCode}; -use cross::fs::{update_file_mode, FileMode, FileModeUpdate}; +use cross::fs::{FileMode, FileModeUpdate, update_file_mode}; fn parse_delta_bit( bit: &str, diff --git a/userspace/sysutils/src/ls.rs b/userspace/sysutils/src/ls.rs index f2731fa3..25125810 100644 --- a/userspace/sysutils/src/ls.rs +++ b/userspace/sysutils/src/ls.rs @@ -1,12 +1,12 @@ #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os, rustc_private))] -#![feature(let_chains, decl_macro)] +#![feature(decl_macro)] use std::{ cmp::Ordering, ffi::OsString, fmt, - fs::{read_dir, FileType, Metadata}, - io::{self, stdout, IsTerminal}, + fs::{FileType, Metadata, read_dir}, + io::{self, IsTerminal, stdout}, path::{Path, PathBuf}, process::ExitCode, time::SystemTime, diff --git a/userspace/tools/crypt/Cargo.toml b/userspace/tools/crypt/Cargo.toml index 3df1dde6..00953f9b 100644 --- a/userspace/tools/crypt/Cargo.toml +++ b/userspace/tools/crypt/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "crypt" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] rsa.workspace = true diff --git a/userspace/tools/init/Cargo.toml b/userspace/tools/init/Cargo.toml index 84dcd0d4..1b81415c 100644 --- a/userspace/tools/init/Cargo.toml +++ b/userspace/tools/init/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "init" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/userspace/tools/md2txt/Cargo.toml b/userspace/tools/md2txt/Cargo.toml index 5af52277..345b885b 100644 --- a/userspace/tools/md2txt/Cargo.toml +++ b/userspace/tools/md2txt/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "md2txt" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] libterm.workspace = true diff --git a/userspace/tools/md2txt/src/main.rs b/userspace/tools/md2txt/src/main.rs index 42ed2acf..c82fc978 100644 --- a/userspace/tools/md2txt/src/main.rs +++ b/userspace/tools/md2txt/src/main.rs @@ -1,5 +1,3 @@ -#![feature(iter_intersperse, let_chains, vec_pop_if)] - use std::{ fs, io::{self, IsTerminal, stdout}, diff --git a/userspace/tools/ntpc/Cargo.toml b/userspace/tools/ntpc/Cargo.toml index c8ff7ed6..3c307e95 100644 --- a/userspace/tools/ntpc/Cargo.toml +++ b/userspace/tools/ntpc/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ntpc" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] logsink.workspace = true diff --git a/userspace/tools/rdb/Cargo.toml b/userspace/tools/rdb/Cargo.toml index b76ca4e1..e563a939 100644 --- a/userspace/tools/rdb/Cargo.toml +++ b/userspace/tools/rdb/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rdb" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] serde_json.workspace = true diff --git a/userspace/tools/red/Cargo.toml b/userspace/tools/red/Cargo.toml index af7568d3..1cb86f35 100644 --- a/userspace/tools/red/Cargo.toml +++ b/userspace/tools/red/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "red" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Mark Poliakov "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/userspace/tools/red/src/line.rs b/userspace/tools/red/src/line.rs index 1481e927..8a23885e 100644 --- a/userspace/tools/red/src/line.rs +++ b/userspace/tools/red/src/line.rs @@ -39,7 +39,7 @@ impl Line { } } - pub fn as_span(&self) -> Span { + pub fn as_span(&self) -> Span<'_> { Span(self.data.as_ref()) } diff --git a/userspace/tools/red/src/main.rs b/userspace/tools/red/src/main.rs index d11df773..06c8867b 100644 --- a/userspace/tools/red/src/main.rs +++ b/userspace/tools/red/src/main.rs @@ -1,4 +1,4 @@ -#![feature(let_chains, rustc_private)] +#![feature(rustc_private)] #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os))] #![allow(clippy::new_without_default)] diff --git a/userspace/tools/rsh/Cargo.toml b/userspace/tools/rsh/Cargo.toml index cd36dff4..0d4fae7f 100644 --- a/userspace/tools/rsh/Cargo.toml +++ b/userspace/tools/rsh/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rsh" version = "0.1.0" -edition = "2021" +edition = "2024" [[bin]] name = "rshd" diff --git a/userspace/tools/rsh/src/crypt/server.rs b/userspace/tools/rsh/src/crypt/server.rs index 15c0147f..b36f6a5b 100644 --- a/userspace/tools/rsh/src/crypt/server.rs +++ b/userspace/tools/rsh/src/crypt/server.rs @@ -269,7 +269,7 @@ impl PendingClient { } } - fn recv(&mut self) -> Result { + fn recv(&mut self) -> Result, Error> { self.stream .read_exact(&mut self.buffer[..size_of::()])?; let len = u16::from_le_bytes([self.buffer[0], self.buffer[1]]) as usize; diff --git a/userspace/tools/rsh/src/crypt/signature.rs b/userspace/tools/rsh/src/crypt/signature.rs index 0c09d753..3bc64cae 100644 --- a/userspace/tools/rsh/src/crypt/signature.rs +++ b/userspace/tools/rsh/src/crypt/signature.rs @@ -112,7 +112,7 @@ impl SignEd25519 { Ok(ed25519_dalek::SIGNATURE_LENGTH) } - pub fn verifying_key_bytes(&self) -> Cow<[u8]> { + pub fn verifying_key_bytes(&self) -> Cow<'_, [u8]> { Cow::Borrowed(self.verifying_key.as_bytes()) } @@ -156,7 +156,7 @@ impl SignatureMethod { } } - pub fn verifying_key_bytes(&self) -> Cow<[u8]> { + pub fn verifying_key_bytes(&self) -> Cow<'_, [u8]> { match self { Self::Ed25519(ed25519) => ed25519.verifying_key_bytes(), } diff --git a/userspace/tools/rsh/src/lib.rs b/userspace/tools/rsh/src/lib.rs index 6fc3617f..7f1607e8 100644 --- a/userspace/tools/rsh/src/lib.rs +++ b/userspace/tools/rsh/src/lib.rs @@ -1,11 +1,5 @@ #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os))] -#![feature( - generic_const_exprs, - portable_simd, - if_let_guard, - let_chains, - path_add_extension -)] +#![feature(generic_const_exprs, portable_simd, if_let_guard)] #![allow(incomplete_features)] pub mod crypt; diff --git a/userspace/tools/rsh/src/main.rs b/userspace/tools/rsh/src/main.rs index e850004b..ebb80d5b 100644 --- a/userspace/tools/rsh/src/main.rs +++ b/userspace/tools/rsh/src/main.rs @@ -1,5 +1,4 @@ #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os))] -#![feature(let_chains)] use std::{ io::{IsTerminal, Read, Stderr, Write, stderr, stdout}, diff --git a/userspace/tools/rsh/src/rcp.rs b/userspace/tools/rsh/src/rcp.rs index 4188dacd..2cb37f4a 100644 --- a/userspace/tools/rsh/src/rcp.rs +++ b/userspace/tools/rsh/src/rcp.rs @@ -1,5 +1,3 @@ -#![feature(path_add_extension)] - use std::{ ffi::OsStr, fs::File, diff --git a/userspace/tools/shell/Cargo.toml b/userspace/tools/shell/Cargo.toml index 1faf941f..8c52c7a3 100644 --- a/userspace/tools/shell/Cargo.toml +++ b/userspace/tools/shell/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "shell" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] cross.workspace = true diff --git a/userspace/tools/shell/src/builtin.rs b/userspace/tools/shell/src/builtin.rs index ab0b992a..a991f862 100644 --- a/userspace/tools/shell/src/builtin.rs +++ b/userspace/tools/shell/src/builtin.rs @@ -148,7 +148,7 @@ fn b_exit(mut io: Args, args: Vec, _env: Envs) -> Outcome { fn b_export(_io: Args, _args: Vec, env: Envs) -> Outcome { for (key, value) in env.0 { - env::set_var(key, value); + unsafe { env::set_var(key, value) }; } Outcome::ok() } diff --git a/userspace/tools/shell/src/command/env.rs b/userspace/tools/shell/src/command/env.rs index b15e3848..73cd1169 100644 --- a/userspace/tools/shell/src/command/env.rs +++ b/userspace/tools/shell/src/command/env.rs @@ -69,7 +69,7 @@ impl Environment { if let Some(current) = self.current_mut() { current.insert_literal(name, value); } else { - std::env::set_var(name.into(), value.into()); + unsafe { std::env::set_var(name.into(), value.into()) }; } } diff --git a/userspace/tools/shell/src/command/eval.rs b/userspace/tools/shell/src/command/eval.rs index 94e3b408..8fa1141d 100644 --- a/userspace/tools/shell/src/command/eval.rs +++ b/userspace/tools/shell/src/command/eval.rs @@ -51,7 +51,7 @@ pub fn evaluate_pipeline( stdins.push(pipeline_stdin); for _ in 1..pipeline.elements.len() { - let (read, write) = std::pipe::pipe().unwrap(); + let (read, write) = std::io::pipe().unwrap(); // std::pipe::pipe().unwrap(); stdins.push(Input::Pipe(BufReader::new(read))); stdouts.push(Output::Pipe(write)); } diff --git a/userspace/tools/shell/src/exec.rs b/userspace/tools/shell/src/exec.rs index 937fa10e..92bb7f98 100644 --- a/userspace/tools/shell/src/exec.rs +++ b/userspace/tools/shell/src/exec.rs @@ -1,10 +1,9 @@ use std::{ fmt, fs::File, - io::{self, BufRead, BufReader, Stderr, Stdout, Write}, + io::{self, BufRead, BufReader, PipeReader, PipeWriter, Stderr, Stdout, Write}, marker::PhantomData, os::fd::{FromRawFd, IntoRawFd}, - pipe::{PipeReader, PipeWriter}, process::{self, Child, ExitCode, ExitStatus, Stdio}, thread::{self, JoinHandle}, }; diff --git a/userspace/tools/shell/src/main.rs b/userspace/tools/shell/src/main.rs index 190425a6..be6daefd 100644 --- a/userspace/tools/shell/src/main.rs +++ b/userspace/tools/shell/src/main.rs @@ -1,11 +1,4 @@ -#![feature( - if_let_guard, - iter_chain, - anonymous_pipe, - trait_alias, - exitcode_exit_method, - let_chains -)] +#![feature(exitcode_exit_method, if_let_guard)] #![cfg_attr(target_os = "yggdrasil", feature(yggdrasil_os, rustc_private))] #![allow(clippy::new_without_default, clippy::should_implement_trait)] diff --git a/userspace/tools/shell/src/syntax/lex.rs b/userspace/tools/shell/src/syntax/lex.rs index 8d69a906..15232699 100644 --- a/userspace/tools/shell/src/syntax/lex.rs +++ b/userspace/tools/shell/src/syntax/lex.rs @@ -115,7 +115,7 @@ pub enum Redirect<'a> { Output(OutputRedirect<'a>), } -fn lex_escape(i: &str) -> IResult<&str, Escape> { +fn lex_escape(i: &str) -> IResult<&str, Escape<'_>> { preceded( tag("\\"), alt(( @@ -157,7 +157,7 @@ fn lex_double_quoted_literal_segment(i: &str) -> IResult<&str, &str> { recognize(streaming::is_not(EXCLUDE))(i) } -fn lex_double_quoted_segment(i: &str) -> IResult<&str, DoubleQuotedSegment> { +fn lex_double_quoted_segment(i: &str) -> IResult<&str, DoubleQuotedSegment<'_>> { alt(( map(lex_escape, DoubleQuotedSegment::Escape), map(lex_var_segment, DoubleQuotedSegment::Var), @@ -168,11 +168,11 @@ fn lex_double_quoted_segment(i: &str) -> IResult<&str, DoubleQuotedSegment> { ))(i) } -fn lex_double_quote_word_segment(i: &str) -> IResult<&str, Vec> { +fn lex_double_quote_word_segment(i: &str) -> IResult<&str, Vec>> { delimited(tag("\""), many0(lex_double_quoted_segment), tag("\""))(i) } -fn lex_word_segment(i: &str) -> IResult<&str, WordSegment> { +fn lex_word_segment(i: &str) -> IResult<&str, WordSegment<'_>> { alt(( map(lex_escape, WordSegment::Escape), map(lex_var_segment, WordSegment::Var), @@ -182,11 +182,11 @@ fn lex_word_segment(i: &str) -> IResult<&str, WordSegment> { ))(i) } -fn lex_word(i: &str) -> IResult<&str, WordToken> { +fn lex_word(i: &str) -> IResult<&str, WordToken<'_>> { map(terminated(many1(lex_word_segment), whitespace0), WordToken)(i) } -fn lex_word_or_keyword(i: &str) -> IResult<&str, Token> { +fn lex_word_or_keyword(i: &str) -> IResult<&str, Token<'_>> { map(lex_word, |word| { if let Some(kw) = word.as_keyword() { Token::Keyword(kw) @@ -221,21 +221,21 @@ fn lex_punct(i: &str) -> IResult<&str, Punct> { ))(i) } -fn lex_input_redirect(i: &str) -> IResult<&str, InputRedirect> { +fn lex_input_redirect(i: &str) -> IResult<&str, InputRedirect<'_>> { alt(( map(preceded(tag("<<"), lex_identifier), InputRedirect::Heredoc), map(preceded(tag("<"), lex_word), InputRedirect::Filename), ))(i) } -fn lex_output_redirect_target(i: &str) -> IResult<&str, OutputRedirectTarget> { +fn lex_output_redirect_target(i: &str) -> IResult<&str, OutputRedirectTarget<'_>> { alt(( map(preceded(tag("&"), digit1), OutputRedirectTarget::Descriptor), map(lex_word, OutputRedirectTarget::Filename), ))(i) } -fn lex_output_redirect(i: &str) -> IResult<&str, OutputRedirect> { +fn lex_output_redirect(i: &str) -> IResult<&str, OutputRedirect<'_>> { map( tuple(( digit0, @@ -254,7 +254,7 @@ fn lex_output_redirect(i: &str) -> IResult<&str, OutputRedirect> { )(i) } -fn lex_redirect(i: &str) -> IResult<&str, Redirect> { +fn lex_redirect(i: &str) -> IResult<&str, Redirect<'_>> { alt(( map(lex_output_redirect, Redirect::Output), map(lex_input_redirect, Redirect::Input), @@ -265,7 +265,7 @@ fn whitespace0(i: &str) -> IResult<&str, &str> { recognize(many0(complete::is_a(" \t")))(i) } -pub fn lex_token(i: &str) -> IResult<&str, Token> { +pub fn lex_token(i: &str) -> IResult<&str, Token<'_>> { preceded( whitespace0, alt(( @@ -276,7 +276,7 @@ pub fn lex_token(i: &str) -> IResult<&str, Token> { )(i) } -pub fn lex_tokens(mut i: &str) -> IResult<&str, Vec> { +pub fn lex_tokens(mut i: &str) -> IResult<&str, Vec>> { let mut tokens = vec![]; while !i.is_empty() { let (rest, token) = lex_token(i)?; diff --git a/userspace/tools/shell/src/syntax/parse.rs b/userspace/tools/shell/src/syntax/parse.rs index 7f464343..3d3a6215 100644 --- a/userspace/tools/shell/src/syntax/parse.rs +++ b/userspace/tools/shell/src/syntax/parse.rs @@ -102,7 +102,7 @@ impl From>> for Error<'_> { } } -fn parse_pipeline_element(mut input: &str) -> Result<(&str, PipelineElement), Error> { +fn parse_pipeline_element(mut input: &str) -> Result<(&str, PipelineElement<'_>), Error<'_>> { let mut words = vec![]; let mut redirects = vec![]; loop { @@ -128,7 +128,7 @@ fn parse_pipeline_element(mut input: &str) -> Result<(&str, PipelineElement), Er Ok((input, PipelineElement { words, redirects })) } -fn parse_pipeline(mut input: &str) -> Result<(&str, PipelineExpression), Error> { +fn parse_pipeline(mut input: &str) -> Result<(&str, PipelineExpression<'_>), Error<'_>> { let mut elements = vec![]; let mut redirects = vec![]; @@ -200,7 +200,7 @@ fn parse_until<'i, T, P: Fn(&'i str) -> Result<(&'i str, T), Error<'i>>, Q: Fn(& Ok((input, elements)) } -fn parse_if(input: &str) -> Result<(&str, Expression), Error> { +fn parse_if(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (mut input, condition) = parse_expression(input)?; loop { input = skip_newline(input)?; @@ -252,7 +252,7 @@ fn parse_if(input: &str) -> Result<(&str, Expression), Error> { )) } -fn parse_while(input: &str) -> Result<(&str, Expression), Error> { +fn parse_while(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (mut input, condition) = parse_expression(input)?; loop { input = skip_newline(input)?; @@ -290,7 +290,7 @@ fn parse_while(input: &str) -> Result<(&str, Expression), Error> { )) } -fn parse_for(input: &str) -> Result<(&str, Expression), Error> { +fn parse_for(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { // xxx in ...; do ... done let (input, variable) = lex::lex_token(input)?; let Token::Word(variable_word) = &variable else { @@ -341,7 +341,7 @@ fn parse_for(input: &str) -> Result<(&str, Expression), Error> { )) } -fn parse_conditional(input: &str) -> Result<(&str, Expression), Error> { +fn parse_conditional(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (input, body) = parse_expression(input)?; let (input, rbracket) = lex::lex_token(input)?; if rbracket != Token::Punct(Punct::RBracket) { @@ -359,7 +359,7 @@ fn parse_conditional(input: &str) -> Result<(&str, Expression), Error> { )) } -fn parse_redirects(mut input: &str) -> Result<(&str, Vec), Error> { +fn parse_redirects(mut input: &str) -> Result<(&str, Vec>), Error<'_>> { let mut redirects = vec![]; loop { if input.is_empty() { @@ -376,7 +376,7 @@ fn parse_redirects(mut input: &str) -> Result<(&str, Vec), Error> { Ok((input, redirects)) } -fn parse_group(input: &str) -> Result<(&str, Expression), Error> { +fn parse_group(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (input, body) = parse_until(input, parse_expression, |t| { *t == Token::Punct(Punct::RBrace) })?; @@ -395,7 +395,7 @@ fn parse_group(input: &str) -> Result<(&str, Expression), Error> { )) } -fn skip_newline(mut input: &str) -> Result<&str, Error> { +fn skip_newline(mut input: &str) -> Result<&str, Error<'_>> { loop { let (rest, token) = lex::lex_token(input)?; if token == Token::Punct(Punct::Newline) { @@ -407,7 +407,7 @@ fn skip_newline(mut input: &str) -> Result<&str, Error> { Ok(input) } -fn parse_case_branch(input: &str) -> Result<(&str, CaseBranch), Error> { +fn parse_case_branch(input: &str) -> Result<(&str, CaseBranch<'_>), Error<'_>> { let (input, pattern) = lex::lex_token(input)?; let Token::Word(pattern) = pattern else { return Err(Error::Expected { @@ -427,7 +427,7 @@ fn parse_case_branch(input: &str) -> Result<(&str, CaseBranch), Error> { Ok((input, CaseBranch { pattern, body })) } -fn parse_case(input: &str) -> Result<(&str, Expression), Error> { +fn parse_case(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (input, expression) = lex::lex_token(input)?; let Token::Word(expression) = expression else { return Err(Error::Expected { @@ -458,7 +458,7 @@ fn parse_case(input: &str) -> Result<(&str, Expression), Error> { )) } -fn parse_atom(mut input: &str) -> Result<(&str, Expression), Error> { +fn parse_atom(mut input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { loop { let (rest, token) = lex::lex_token(input)?; // TODO (...) @@ -522,12 +522,12 @@ fn maybe_binary<'i>( Ok((input, expr)) } -pub fn parse_expression(input: &str) -> Result<(&str, Expression), Error> { +pub fn parse_expression(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (input, atom) = parse_atom(input)?; maybe_binary(atom, input) } -pub fn parse_toplevel(input: &str) -> Result<(&str, Expression), Error> { +pub fn parse_toplevel(input: &str) -> Result<(&str, Expression<'_>), Error<'_>> { let (rest, atom) = parse_atom(input)?; // If atom is `xxx()`, try to parse a function declaration if let Some(identifier) = atom @@ -560,7 +560,7 @@ impl PipelineElement<'_> { } } - fn as_word(&self) -> Option<&WordToken> { + fn as_word(&self) -> Option<&WordToken<'_>> { if !self.redirects.is_empty() || self.words.len() != 1 { return None; } @@ -576,11 +576,11 @@ impl PipelineExpression<'_> { self.elements[0].as_function_decl() } - pub fn as_word(&self) -> Option<&WordToken> { + pub fn as_word(&self) -> Option<&WordToken<'_>> { self.as_single_command()?.as_word() } - pub fn as_single_command(&self) -> Option<&PipelineElement> { + pub fn as_single_command(&self) -> Option<&PipelineElement<'_>> { if self.elements.len() != 1 { return None; } @@ -589,14 +589,14 @@ impl PipelineExpression<'_> { } impl Expression<'_> { - pub fn as_pipeline(&self) -> Option<&PipelineExpression> { + pub fn as_pipeline(&self) -> Option<&PipelineExpression<'_>> { match self { Self::Pipeline(pipeline) => Some(pipeline), _ => None, } } - pub fn as_word(&self) -> Option<&WordToken> { + pub fn as_word(&self) -> Option<&WordToken<'_>> { self.as_pipeline()?.as_word() } } diff --git a/userspace/tools/strace/Cargo.toml b/userspace/tools/strace/Cargo.toml index 431169d3..ac0bcde5 100644 --- a/userspace/tools/strace/Cargo.toml +++ b/userspace/tools/strace/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "strace" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] runtime.workspace = true diff --git a/userspace/tools/strace/src/main.rs b/userspace/tools/strace/src/main.rs index c87e1b35..01f2ea90 100644 --- a/userspace/tools/strace/src/main.rs +++ b/userspace/tools/strace/src/main.rs @@ -1,4 +1,5 @@ -#![feature(rustc_private, yggdrasil_os, let_chains)] +#![feature(rustc_private, yggdrasil_os)] +#![allow(exported_private_dependencies)] use std::{ io, diff --git a/xtask/src/build/toolchain.rs b/xtask/src/build/toolchain.rs index ac31d5ec..b3649dec 100644 --- a/xtask/src/build/toolchain.rs +++ b/xtask/src/build/toolchain.rs @@ -23,10 +23,12 @@ struct RustBuildConfig { struct RustTargetConfig { cc: Option, cxx: Option, + rustflags: Option>, } #[derive(Debug, serde::Serialize)] struct RustRustConfig { + channel: String, incremental: bool, } @@ -42,7 +44,7 @@ struct RustToolchainConfig { fn configure>(env: &BuildEnv, config_toml_path: P) -> Result<(), Error> { let config = RustToolchainConfig { - profile: "user".into(), + profile: "compiler".into(), build: RustBuildConfig { host: vec![env.host_triple.clone()], @@ -59,6 +61,7 @@ fn configure>(env: &BuildEnv, config_toml_path: P) -> Result<(), RustTargetConfig { cc: Some("aarch64-linux-gnu-gcc".into()), cxx: Some("aarch64-linux-gnu-g++".into()), + rustflags: None, }, ), ( @@ -66,10 +69,19 @@ fn configure>(env: &BuildEnv, config_toml_path: P) -> Result<(), RustTargetConfig { cc: Some("clang".into()), cxx: Some("clang++".into()), + rustflags: Some(vec![ + "-Clinker=clang".into(), + "-Clink-arg=-fuse-ld=lld".into(), + "-Clink-arg=--target=riscv64".into(), + "-Clink-arg=-nostdlib".into(), + ]), }, ), ]), - rust: RustRustConfig { incremental: true }, + rust: RustRustConfig { + incremental: true, + channel: "nightly".into(), + }, }; let toml = toml::to_string_pretty(&config)?; diff --git a/xtask/src/build/userspace.rs b/xtask/src/build/userspace.rs index 75360ccf..428840c5 100644 --- a/xtask/src/build/userspace.rs +++ b/xtask/src/build/userspace.rs @@ -96,7 +96,8 @@ const PROGRAMS: &[(&str, &str)] = &[ fn build_userspace(env: &BuildEnv, _: AllOk) -> Result<(), Error> { log::info!("Building userspace"); CargoBuilder::Userspace(env).build(env.workspace_root.join("userspace"))?; - CargoBuilder::Userspace(env).build(env.workspace_root.join("userspace/dynload-program"))?; + // TODO rust-lld incorrectly links riscv64 binaries + // CargoBuilder::Userspace(env).build(env.workspace_root.join("userspace/dynload-program"))?; Ok(()) } @@ -161,15 +162,15 @@ fn build_rootfs, D: AsRef>( } } - // TODO other architectures - util::copy_file( - env.workspace_root.join(format!( - "userspace/dynload-program/target/{}-unknown-yggdrasil/{}/dynload-program", - env.arch.name(), - env.profile.name() - )), - rootfs_dir.join("dynload-program"), - )?; + // // TODO other architectures + // util::copy_file( + // env.workspace_root.join(format!( + // "userspace/dynload-program/target/{}-unknown-yggdrasil/{}/dynload-program", + // env.arch.name(), + // env.profile.name() + // )), + // rootfs_dir.join("dynload-program"), + // )?; // Copy /etc util::copy_dir_recursive(user_dir.join("etc"), rootfs_dir.join("etc"))?; diff --git a/xtask/src/env.rs b/xtask/src/env.rs index 66a8c081..3cd62a48 100644 --- a/xtask/src/env.rs +++ b/xtask/src/env.rs @@ -105,7 +105,7 @@ pub struct BuildEnv { impl Default for ToolchainConfig { fn default() -> Self { Self { - branch: "alnyan/yggdrasil-1.84.0".into(), + branch: "alnyan/yggdrasil-1.94.0".into(), } } }