diff --git a/src/structures/gdt.rs b/src/structures/gdt.rs index c30c52adc..8c4ddf7e1 100644 --- a/src/structures/gdt.rs +++ b/src/structures/gdt.rs @@ -64,6 +64,9 @@ impl GlobalDescriptorTable { /// Creates an empty GDT which can hold `MAX` number of [`Descriptor`]s. #[inline] pub const fn empty() -> Self { + // TODO: Replace with compiler error when feature(generic_const_exprs) is stable. + assert!(MAX > 0, "A GDT cannot have 0 entries"); + assert!(MAX <= (1 << 13), "A GDT can only have at most 2^13 entries"); Self { table: [0; MAX], next_free: 1, @@ -184,6 +187,8 @@ impl GlobalDescriptorTable { use core::mem::size_of; super::DescriptorTablePointer { base: crate::VirtAddr::new(self.table.as_ptr() as u64), + // 0 < self.next_free <= MAX <= 2^13, so the limit calculation + // will not underflow or overflow. limit: (self.next_free * size_of::() - 1) as u16, } }