From 95ef6d0421f6eb4e884ce9616e551dda9f34dae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:37:24 +0100 Subject: [PATCH 1/8] fix(common-os): `clippy::unreadable-literal` --- src/arch/x86_64/kernel/mod.rs | 2 +- src/mm/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 9144a5a9ee..3ca66a6b13 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -282,7 +282,7 @@ unsafe extern "C" fn pre_init(boot_info: Option<&'static RawBootInfo>, cpu_id: u } #[cfg(feature = "common-os")] -const LOADER_START: usize = 0x10000000000; +const LOADER_START: usize = 0x0100_0000_0000; #[cfg(feature = "common-os")] const LOADER_STACK_SIZE: usize = 0x8000; diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 6f3be4e103..ad3eb89f76 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -98,7 +98,7 @@ pub(crate) fn init() { // we reserve at least 75% of the memory for the user space let reserve: usize = (avail_mem * 75) / 100; // 64 MB is enough as kernel heap - let reserve = core::cmp::min(reserve, 0x4000000); + let reserve = core::cmp::min(reserve, 0x0400_0000); let virt_size: usize = reserve.align_down(LargePageSize::SIZE as usize); let virt_addr = From 437dddabadf744767062aa8f3b6cb95b4d75b6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:38:51 +0100 Subject: [PATCH 2/8] fix(common-os): `clippy::fn_to_numeric_cast` --- src/arch/x86_64/kernel/processor.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index cbdcf7bf8a..0ddfdbf1d8 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -894,7 +894,9 @@ pub fn configure() { wrmsr(IA32_STAR, (0x1bu64 << 48) | (0x08u64 << 32)); wrmsr( IA32_LSTAR, - crate::arch::x86_64::kernel::syscall::syscall_handler as u64, + (crate::arch::x86_64::kernel::syscall::syscall_handler as usize) + .try_into() + .unwrap(), ); wrmsr(IA32_FMASK, 1 << 9); // clear IF flag during system call } From 0a0565aa18a9534f86401706cfe478c842a60e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:40:14 +0100 Subject: [PATCH 3/8] fix(common-os): `clippy::unnecessary_cast` --- src/arch/x86_64/kernel/mod.rs | 8 +++----- src/arch/x86_64/mm/mod.rs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 3ca66a6b13..1ef6bf2c31 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -300,8 +300,7 @@ where use crate::arch::x86_64::mm::physicalmem; let code_size = (code_size as usize + LOADER_STACK_SIZE).align_up(BasePageSize::SIZE as usize); - let physaddr = - physicalmem::allocate_aligned(code_size as usize, BasePageSize::SIZE as usize).unwrap(); + let physaddr = physicalmem::allocate_aligned(code_size, BasePageSize::SIZE as usize).unwrap(); let mut flags = PageTableEntryFlags::empty(); flags.normal().writable().user().execute_enable(); @@ -335,9 +334,8 @@ where tls_memsz / BasePageSize::SIZE as usize, flags, ); - let block = unsafe { - &mut *slice_from_raw_parts_mut(tls_virt.as_mut_ptr() as *mut u8, tls_offset + tcb_size) - }; + let block = + unsafe { &mut *slice_from_raw_parts_mut(tls_virt.as_mut_ptr(), tls_offset + tcb_size) }; for elem in block.iter_mut() { *elem = 0; } diff --git a/src/arch/x86_64/mm/mod.rs b/src/arch/x86_64/mm/mod.rs index de09018087..234765cfdd 100644 --- a/src/arch/x86_64/mm/mod.rs +++ b/src/arch/x86_64/mm/mod.rs @@ -63,7 +63,7 @@ pub fn create_new_root_page_table() -> usize { paging::map::(slice_addr, physaddr, 1, flags); unsafe { - let pml4 = core::slice::from_raw_parts_mut(slice_addr.as_mut_ptr() as *mut u64, 512); + let pml4 = core::slice::from_raw_parts_mut(slice_addr.as_mut_ptr(), 512); // clear PML4 for elem in pml4.iter_mut() { From 6578826ab1c5132f515b9d08c21f0d78d28aaee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:44:34 +0100 Subject: [PATCH 4/8] fix(common-os): `clippy::result_unit_err` --- src/arch/x86_64/kernel/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arch/x86_64/kernel/mod.rs b/src/arch/x86_64/kernel/mod.rs index 1ef6bf2c31..53c93eb907 100644 --- a/src/arch/x86_64/kernel/mod.rs +++ b/src/arch/x86_64/kernel/mod.rs @@ -287,9 +287,9 @@ const LOADER_START: usize = 0x0100_0000_0000; const LOADER_STACK_SIZE: usize = 0x8000; #[cfg(feature = "common-os")] -pub fn load_application(code_size: u64, tls_size: u64, func: F) -> Result<(), ()> +pub fn load_application(code_size: u64, tls_size: u64, func: F) -> T where - F: FnOnce(&'static mut [u8], Option<&'static mut [u8]>) -> Result<(), ()>, + F: FnOnce(&'static mut [u8], Option<&'static mut [u8]>) -> T, { use core::ptr::slice_from_raw_parts_mut; From b6a7325d69635a034966c71b1abf50cec2339fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:45:51 +0100 Subject: [PATCH 5/8] fix(common-os): expect `dead_code` --- src/arch/x86_64/mm/paging.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index fda118bd24..61f98b4938 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -38,6 +38,7 @@ pub trait PageTableEntryFlagsExt { #[cfg(feature = "common-os")] fn user(&mut self) -> &mut Self; + #[expect(dead_code)] #[cfg(feature = "common-os")] fn kernel(&mut self) -> &mut Self; } From c07093c3362b7424994154adc2159a265fa4cab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:52:23 +0100 Subject: [PATCH 6/8] fix(aarch64): fix compilation with `feature = "common-os"` --- src/arch/aarch64/kernel/scheduler.rs | 16 ++++++++++++++-- src/arch/mod.rs | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/arch/aarch64/kernel/scheduler.rs b/src/arch/aarch64/kernel/scheduler.rs index e752d44d56..73937a4757 100644 --- a/src/arch/aarch64/kernel/scheduler.rs +++ b/src/arch/aarch64/kernel/scheduler.rs @@ -1,10 +1,14 @@ //! Architecture dependent interface to initialize a task +#[cfg(not(feature = "common-os"))] use alloc::alloc::{alloc_zeroed, Layout}; +#[cfg(not(feature = "common-os"))] use alloc::boxed::Box; use core::arch::naked_asm; +#[cfg(not(feature = "common-os"))] +use core::slice; use core::sync::atomic::Ordering; -use core::{mem, ptr, slice}; +use core::{mem, ptr}; use align_address::Align; use memory_addresses::arch::aarch64::{PhysAddr, VirtAddr}; @@ -12,10 +16,12 @@ use memory_addresses::arch::aarch64::{PhysAddr, VirtAddr}; use crate::arch::aarch64::kernel::core_local::core_scheduler; use crate::arch::aarch64::kernel::CURRENT_STACK_ADDRESS; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; +#[cfg(not(feature = "common-os"))] +use crate::env; use crate::scheduler::task::{Task, TaskFrame}; #[cfg(target_os = "none")] use crate::scheduler::PerCoreSchedulerExt; -use crate::{env, DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; +use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; #[derive(Debug)] #[repr(C, packed)] @@ -243,6 +249,7 @@ impl Drop for TaskStacks { * of the TLS implementations. */ +#[cfg(not(feature = "common-os"))] #[derive(Copy, Clone)] #[repr(C)] struct DtvPointer { @@ -250,12 +257,14 @@ struct DtvPointer { to_free: *const (), } +#[cfg(not(feature = "common-os"))] #[repr(C)] union Dtv { counter: usize, pointer: DtvPointer, } +#[cfg(not(feature = "common-os"))] #[repr(C)] pub struct TaskTLS { dtv: mem::MaybeUninit>, @@ -263,6 +272,7 @@ pub struct TaskTLS { block: [u8], } +#[cfg(not(feature = "common-os"))] impl TaskTLS { fn from_environment() -> Option> { let tls_info = env::boot_info().load_info.tls_info?; @@ -346,6 +356,7 @@ extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize) -> ! { impl TaskFrame for Task { fn create_stack_frame(&mut self, func: unsafe extern "C" fn(usize), arg: usize) { // Check if TLS is allocated already and if the task uses thread-local storage. + #[cfg(not(feature = "common-os"))] if self.tls.is_none() { self.tls = TaskTLS::from_environment(); } @@ -360,6 +371,7 @@ impl TaskFrame for Task { stack -= mem::size_of::(); let state = stack.as_mut_ptr::(); + #[cfg(not(feature = "common-os"))] if let Some(tls) = &self.tls { (*state).tpidr_el0 = tls.thread_ptr() as u64; } diff --git a/src/arch/mod.rs b/src/arch/mod.rs index d2106bd5e6..f03998a248 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -15,6 +15,7 @@ cfg_if::cfg_if! { pub(crate) use self::aarch64::kernel::processor; pub(crate) use self::aarch64::kernel::processor::set_oneshot_timer; pub(crate) use self::aarch64::kernel::scheduler; + #[cfg(not(feature = "common-os"))] pub(crate) use self::aarch64::kernel::switch; #[cfg(feature = "smp")] pub(crate) use self::aarch64::kernel::application_processor_init; From 54222943fd5af6a406a7f7f72d18a87633a2b049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 14:54:29 +0100 Subject: [PATCH 7/8] fix(riscv64): fix compilation with `feature = "common-os"` --- src/arch/riscv64/kernel/scheduler.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/arch/riscv64/kernel/scheduler.rs b/src/arch/riscv64/kernel/scheduler.rs index b7a483cb00..bf2bbb2e20 100644 --- a/src/arch/riscv64/kernel/scheduler.rs +++ b/src/arch/riscv64/kernel/scheduler.rs @@ -1,5 +1,8 @@ +#[cfg(not(feature = "common-os"))] use alloc::alloc::{alloc, dealloc, Layout}; +#[cfg(not(feature = "common-os"))] use alloc::boxed::Box; +#[cfg(not(feature = "common-os"))] use core::convert::TryInto; use core::{mem, ptr}; @@ -9,8 +12,10 @@ use memory_addresses::{PhysAddr, VirtAddr}; use crate::arch::riscv64::kernel::core_local::core_scheduler; use crate::arch::riscv64::kernel::processor::set_oneshot_timer; use crate::arch::riscv64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; +#[cfg(not(feature = "common-os"))] +use crate::env; use crate::scheduler::task::{Task, TaskFrame}; -use crate::{env, DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; +use crate::{DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; #[repr(C, packed)] #[derive(Clone, Copy, Debug)] @@ -257,12 +262,14 @@ impl Drop for TaskStacks { } } +#[cfg(not(feature = "common-os"))] pub struct TaskTLS { address: VirtAddr, tp: VirtAddr, layout: Layout, } +#[cfg(not(feature = "common-os"))] impl TaskTLS { pub fn from_environment() -> Option> { let tls_info = env::boot_info().load_info.tls_info?; @@ -320,6 +327,7 @@ impl TaskTLS { } } +#[cfg(not(feature = "common-os"))] impl Drop for TaskTLS { fn drop(&mut self) { debug!( @@ -377,6 +385,7 @@ impl TaskFrame for Task { fn create_stack_frame(&mut self, func: unsafe extern "C" fn(usize), arg: usize) { // Check if the task (process or thread) uses Thread-Local-Storage. // check is TLS is already allocated + #[cfg(not(feature = "common-os"))] if self.tls.is_none() { self.tls = TaskTLS::from_environment(); } @@ -391,6 +400,7 @@ impl TaskFrame for Task { stack -= mem::size_of::(); let state = stack.as_mut_ptr::(); + #[cfg(not(feature = "common-os"))] if let Some(tls) = &self.tls { (*state).tp = tls.tp().as_usize(); } From f4d810c4b15266f0cb8974c00057ef7edba0442e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 13:49:49 +0100 Subject: [PATCH 8/8] fix(xtask): run clippy on `feature = "common-os"` --- xtask/src/clippy.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/xtask/src/clippy.rs b/xtask/src/clippy.rs index b5957a2720..72f37e5b4f 100644 --- a/xtask/src/clippy.rs +++ b/xtask/src/clippy.rs @@ -17,6 +17,7 @@ impl Clippy { let triple = arch.triple(); cmd!(sh, "cargo clippy --target={triple}").run()?; + cmd!(sh, "cargo clippy --target={triple} --features common-os").run()?; cmd!(sh, "cargo clippy --target={triple}") .arg("--features=acpi,dns,fsgsbase,pci,smp,vga") .run()?;