Skip to content

Commit

Permalink
static_assertions remove labels
Browse files Browse the repository at this point in the history
Fixes #85
  • Loading branch information
Orycterope committed Mar 14, 2019
1 parent 4ce9daf commit 5b71120
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 41 deletions.
5 changes: 4 additions & 1 deletion ahci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ kfs-libutils = { path = "../libutils" }
spin = "0.4"
log = "0.4.6"
bitfield = "0.13.1"
static_assertions = "0.3.1"

[dependencies.lazy_static]
features = ["spin_no_std"]
version = "1.3.0"

[dependencies.static_assertions]
version = "0.3.1"
features = ["nightly"]
8 changes: 4 additions & 4 deletions ahci/src/hba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ pub struct CmdHeaderArray {
pub slots: [CmdHeader; 32]
}

assert_eq_size!(size_CmdHeaderArray; CmdHeaderArray, [u8; 1024]);
assert_eq_size!(CmdHeaderArray, [u8; 1024]);

unsafe impl ZeroInitialized for CmdHeaderArray {}

Expand Down Expand Up @@ -1068,7 +1068,7 @@ pub struct CmdTable {
// 248 entries fills the rest of the page.
}

assert_eq_size!(size_CmdTable; CmdTable, [u8; 4096]);
assert_eq_size!(CmdTable, [u8; 4096]);

unsafe impl ZeroInitialized for CmdTable {}

Expand All @@ -1084,7 +1084,7 @@ union Cfis {
// ...
}

assert_eq_size!(size_Cfis; Cfis, [u8; 64]);
assert_eq_size!(Cfis, [u8; 64]);

/// Physical Region Descriptor Table entry.
///
Expand Down Expand Up @@ -1189,7 +1189,7 @@ pub struct ReceivedFis {
_rsv3: [u8; 0x60],
}

assert_eq_size!(size_ReceivedFis; ReceivedFis, [u8; 0x100]);
assert_eq_size!(ReceivedFis, [u8; 0x100]);

unsafe impl ZeroInitialized for ReceivedFis {}

Expand Down
2 changes: 1 addition & 1 deletion ahci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! simultaneously. Unfortunately we can't take advantage of that until we manage to
//! make command-completion interrupts work.
#![feature(alloc, maybe_uninit, box_syntax, untagged_unions, const_vec_new)]
#![feature(alloc, maybe_uninit, box_syntax, untagged_unions, const_vec_new, underscore_const_names)]
#![no_std]

// rustc warnings
Expand Down
5 changes: 4 additions & 1 deletion bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bit_field = "0.9.0"
bitflags = "1.0"
multiboot2 = { git = "https://github.com/roblabla/multiboot2-elf64" }
spin = "0.5.0"
static_assertions = "*"
xmas-elf = "0.6.2"

[dependencies.smallvec]
Expand All @@ -29,3 +28,7 @@ version = "0.4.10"
[dependencies.lazy_static]
features = ["spin_no_std"]
version = "1.3.0"

[dependencies.static_assertions]
version = "0.3.1"
features = ["nightly"]
2 changes: 1 addition & 1 deletion bootstrap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! fancy logging interfaces that the kernel has.
//!
#![feature(lang_items, start, asm, global_asm, compiler_builtins_lib, naked_functions, core_intrinsics, const_fn, abi_x86_interrupt)]
#![feature(lang_items, start, asm, global_asm, compiler_builtins_lib, naked_functions, core_intrinsics, const_fn, abi_x86_interrupt, underscore_const_names)]
#![no_std]
#![cfg_attr(target_os = "none", no_main)]

Expand Down
18 changes: 8 additions & 10 deletions bootstrap/src/paging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,14 @@ impl VirtualSpaceLand for UserLand {

// Assertions to check that Kernel/User pages falls on distinct page tables
// and also that they do not overlap
fn __land_assertions() {
const_assert!(KernelLand::start_addr().0 < KernelLand::end_addr().0);
const_assert!(UserLand::start_addr().0 < UserLand::end_addr().0);
// TODO: Const FN sucks! Check that the kernelland and userland don't overlap.
//const_assert!(::core::cmp::max(KernelLand::start_addr(), UserLand::start_addr()) >=
// ::core::cmp::min(KernelLand::end_addr(), UserLand::end_addr()));

const_assert!(KernelLand::start_addr().0 % (ENTRY_COUNT * PAGE_SIZE) == 0);
const_assert!(UserLand::start_addr().0 % (ENTRY_COUNT * PAGE_SIZE) == 0);
}
const_assert!(KernelLand::start_addr().0 < KernelLand::end_addr().0);
const_assert!(UserLand::start_addr().0 < UserLand::end_addr().0);
// TODO: Const FN sucks! Check that the kernelland and userland don't overlap.
//const_assert!(::core::cmp::max(KernelLand::start_addr(), UserLand::start_addr()) >=
// ::core::cmp::min(KernelLand::end_addr(), UserLand::end_addr()));

const_assert!(KernelLand::start_addr().0 % (ENTRY_COUNT * PAGE_SIZE) == 0);
const_assert!(UserLand::start_addr().0 % (ENTRY_COUNT * PAGE_SIZE) == 0);

/// Creates a mapping in the page tables with the given flags.
/// Allocates the pointed page and chooses the virtual address.
Expand Down
9 changes: 3 additions & 6 deletions bootstrap/src/paging/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ pub struct PageTable {
/// A page directory
pub struct PageDirectory(PageTable);

// Assertions
fn __assertions() {
const_assert!(::core::mem::size_of::<PageDirectory>() >= MEMORY_FRAME_SIZE);
const_assert!(::core::mem::size_of::<PageTable>() >= MEMORY_FRAME_SIZE);
const_assert!(::core::mem::size_of::<PageTable>() == ::core::mem::size_of::<PageDirectory>());
}
const_assert!(::core::mem::size_of::<PageDirectory>() >= MEMORY_FRAME_SIZE);
const_assert!(::core::mem::size_of::<PageTable>() >= MEMORY_FRAME_SIZE);
const_assert!(::core::mem::size_of::<PageTable>() == ::core::mem::size_of::<PageDirectory>());

/// When paging is on, accessing this address loops back to the directory itself thanks to
/// recursive mapping on directory's last entry
Expand Down
5 changes: 4 additions & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ bit_field = "0.9.0"
bitflags = "1.0"
multiboot2 = { git = "https://github.com/roblabla/multiboot2-elf64" }
spin = "0.5"
static_assertions = "0.3.1"
linked_list_allocator = "0.6.2"
log = "0.4.6"
xmas-elf = "0.6.2"
Expand All @@ -48,3 +47,7 @@ version = "0.1.8"
[dependencies.lazy_static]
features = ["spin_no_std"]
version = "1.3.0"

[dependencies.static_assertions]
version = "0.3.1"
features = ["nightly"]
2 changes: 1 addition & 1 deletion kernel/src/i386/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl Default for TssStruct {
}
}

const_assert_eq!(tss_struct_size; ::core::mem::size_of::<TssStruct>(), 0x68);
const_assert_eq!(::core::mem::size_of::<TssStruct>(), 0x68);

impl TssStruct {
/// Creates a new TssStruct.
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/i386/structures/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl fmt::Debug for Idt {
}
}

const_assert_eq!(const_assert_idt; mem::size_of::<Idt>(), 256 * 8);
const_assert_eq!(mem::size_of::<Idt>(), 256 * 8);


impl Idt {
Expand Down Expand Up @@ -544,7 +544,7 @@ impl<F> fmt::Debug for IdtEntry<F> {
}
}

const_assert_eq!(const_assert_idtentry; mem::size_of::<IdtEntry<()>>(), 8);
const_assert_eq!(mem::size_of::<IdtEntry<()>>(), 8);

/// A handler function for an interrupt or an exception without error code.
pub type HandlerFunc = extern "x86-interrupt" fn(&mut ExceptionStackFrame);
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! Currently doesn't do much, besides booting and printing Hello World on the
//! screen. But hey, that's a start.
#![feature(lang_items, start, asm, global_asm, compiler_builtins_lib, naked_functions, core_intrinsics, const_fn, abi_x86_interrupt, allocator_api, alloc, box_syntax, no_more_cas, const_vec_new, range_contains, step_trait, thread_local, nll)]
#![feature(lang_items, start, asm, global_asm, compiler_builtins_lib, naked_functions, core_intrinsics, const_fn, abi_x86_interrupt, allocator_api, alloc, box_syntax, no_more_cas, const_vec_new, range_contains, step_trait, thread_local, nll, underscore_const_names)]
#![no_std]
#![cfg_attr(target_os = "none", no_main)]
#![recursion_limit = "1024"]
Expand Down
21 changes: 9 additions & 12 deletions kernel/src/paging/lands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ impl VirtualSpaceLand for RecursiveTablesLand {

/// Assertions to check that Kernel/User pages falls on distinct page tables
/// and also that they do not overlap.
fn __land_assertions() {
const_assert!(KernelLand::START.0 < KernelLand::END.0);
const_assert!(UserLand::START.0 < UserLand::END.0);
const_assert!(RecursiveTablesLand::START.0 < RecursiveTablesLand::END.0);
// TODO: Const FN sucks! Check that the kernelland and userland don't overlap.
//const_assert!(::core::cmp::max(KernelLand::start_addr(), UserLand::start_addr()) >=
// ::core::cmp::min(KernelLand::end_addr(), UserLand::end_addr()));

const_assert!(KernelLand::START.0 % (ENTRY_COUNT * PAGE_SIZE) == 0);
const_assert!(UserLand::START.0 % (ENTRY_COUNT * PAGE_SIZE) == 0);
}

const_assert!(KernelLand::START.0 < KernelLand::END.0);
const_assert!(UserLand::START.0 < UserLand::END.0);
const_assert!(RecursiveTablesLand::START.0 < RecursiveTablesLand::END.0);
// TODO: Const FN sucks! Check that the kernelland and userland don't overlap.
//const_assert!(::core::cmp::max(KernelLand::start_addr(), UserLand::start_addr()) >=
// ::core::cmp::min(KernelLand::end_addr(), UserLand::end_addr()));

const_assert!(KernelLand::START.0 % (ENTRY_COUNT * PAGE_SIZE) == 0);
const_assert!(UserLand::START.0 % (ENTRY_COUNT * PAGE_SIZE) == 0);

0 comments on commit 5b71120

Please sign in to comment.