From 7bb8a99b56465952f48bfe9d887c3d815686c31f Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Thu, 20 Feb 2025 17:04:23 -0600 Subject: [PATCH] Messed with some stuff --- kernel/config.aphro.example | 2 +- kernel/src/kernel/arch/example_impl/mod.rs | 3 +++ kernel/src/kernel/arch/x86/paging.rs | 4 ++-- kernel/src/kernel/indep_boot_entry.rs | 3 ++- kernel/src/kernel/mem.rs | 20 ++++++++++++++++---- kernel/src/kernel/mod.rs | 3 +++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/kernel/config.aphro.example b/kernel/config.aphro.example index ecf90c7..4571dd7 100644 --- a/kernel/config.aphro.example +++ b/kernel/config.aphro.example @@ -4,7 +4,7 @@ CONT_WITH_DIFFERENT_VERSION=true # Begin metadata -# Set VERSION=generate to attempt to autogenerate a version based on git information +# Set VERSION=generate(or unset) to attempt to autogenerate a version based on git information VERSION=generate # SUFFIX is unset diff --git a/kernel/src/kernel/arch/example_impl/mod.rs b/kernel/src/kernel/arch/example_impl/mod.rs index 262d2d1..4d5650c 100644 --- a/kernel/src/kernel/arch/example_impl/mod.rs +++ b/kernel/src/kernel/arch/example_impl/mod.rs @@ -7,6 +7,9 @@ //! actual architecture, of course): //! #![cfg(any(target_arch = "arch"))] +// DO NOT have this in your actual code: +#![allow(dead_code)] + /// Returns the most specific architecture available. pub const fn get_arch() -> super::Architecture { super::Architecture::ExampleDummy diff --git a/kernel/src/kernel/arch/x86/paging.rs b/kernel/src/kernel/arch/x86/paging.rs index a38022c..e52361f 100644 --- a/kernel/src/kernel/arch/x86/paging.rs +++ b/kernel/src/kernel/arch/x86/paging.rs @@ -13,7 +13,7 @@ pub enum PageDirectoryEntry { } impl PageDirectoryEntry { - const fn create_fourmb( + pub const fn create_fourmb( mut bits32to22: u16, bits39to32: u8, pat: bool, @@ -64,7 +64,7 @@ impl PageDirectoryEntry { Self::FourMb(out) } - const fn create_other( + pub const fn create_other( mut bits31to12: u32, pat: bool, mut available: u8, diff --git a/kernel/src/kernel/indep_boot_entry.rs b/kernel/src/kernel/indep_boot_entry.rs index faa6e50..ec457bd 100644 --- a/kernel/src/kernel/indep_boot_entry.rs +++ b/kernel/src/kernel/indep_boot_entry.rs @@ -22,7 +22,8 @@ fn indep_boot_entry( ) -> ! { assert_ne!( crate::arch::get_arch(), - crate::arch::Architecture::ExampleDummy + crate::arch::Architecture::ExampleDummy, + "Somehow the kernel successfully booted into IndepBootEntry with a dummy architecture" ); crate::arch::output::sdebugsln("IndepBootEntry called"); diff --git a/kernel/src/kernel/mem.rs b/kernel/src/kernel/mem.rs index 4ea881c..ce696fd 100644 --- a/kernel/src/kernel/mem.rs +++ b/kernel/src/kernel/mem.rs @@ -76,6 +76,18 @@ fn get_allocator() -> Option<&'static MemoryMapAlloc<'static>> { } } +/// The unsafe counterpart of [MemMapAlloc()]. Doesn't check if the allocator is initalized. +/// Internally, uses [MaybeUninit::assume_init_ref]. +/// +/// # Safety +/// +/// Calling this instead of [MemMapAlloc] or when the allocator is uninitalized causes +/// undefined behavior; check [MaybeUninit::assume_init_ref] for safety guarantees. +pub unsafe fn get_allocator_unchecked() -> &'static MemoryMapAlloc<'static> { + #[allow(static_mut_refs)] + unsafe { ALLOCATOR.assume_init_ref() } +} + #[kernel_item(MemMapAllocInit)] fn memory_map_alloc_init(memmap: crate::boot::MemoryMap) -> Result<(), crate::Error<'static>> { #[allow(static_mut_refs)] @@ -107,19 +119,19 @@ pub struct MemoryMapAlloc<'a> { } /// Too many allocations have been created, pushing the size of [MemoryMapAlloc::allocations] over [MemoryMapAlloc::max_allocations_size]. -const TOO_MANY_ALLOCATIONS: i16 = -2; +pub const TOO_MANY_ALLOCATIONS: i16 = -2; /// There isn't enough space for 32 allocations(the minimum available). pub const ALLOCATIONS_NOT_ENOUGH_SPACE: i16 = -3; /// The index provided to [MemoryMapAlloc::extend_allocation] is too big. -const EXTEND_ALLOCATION_INVALID_INDEX: i16 = -4; +pub const EXTEND_ALLOCATION_INVALID_INDEX: i16 = -4; /// The allocation provided to [MemoryMapAlloc::extend_allocation] is unused. -const EXTEND_ALLOCATION_ALLOCATION_UNUSED: i16 = -5; +pub const EXTEND_ALLOCATION_ALLOCATION_UNUSED: i16 = -5; /// The allocation provided to [MemoryMapAlloc::extend_allocation], if extended, would extend into another allocation. -const EXTEND_ALLOCATION_OTHER_ALLOCATION: i16 = -6; +pub const EXTEND_ALLOCATION_OTHER_ALLOCATION: i16 = -6; impl<'a> Debug for MemoryMapAlloc<'a> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { diff --git a/kernel/src/kernel/mod.rs b/kernel/src/kernel/mod.rs index 9b1839d..ef47a04 100644 --- a/kernel/src/kernel/mod.rs +++ b/kernel/src/kernel/mod.rs @@ -4,6 +4,7 @@ #![warn(rustdoc::missing_crate_level_docs)] #![deny(rustdoc::invalid_html_tags)] #![deny(rustdoc::invalid_rust_codeblocks)] +#![deny(unsafe_op_in_unsafe_fn)] // tidy-alphabetical-start #![feature(ptr_metadata)] #![feature(const_trait_impl)] @@ -48,10 +49,12 @@ pub use util::*; #[allow(unused_imports)] // if there are no traits, then it gives a warning pub use traits::*; +/// Returns the version of aphrodite. pub const fn version() -> &'static str { env!("VERSION") } +/// Returns the version of the config for aphrodite. pub const fn cfg_version() -> &'static str { env!("CFG_VERSION") }