File tree 1 file changed +5
-0
lines changed
1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ impl<const MAX: usize> GlobalDescriptorTable<MAX> {
64
64
/// Creates an empty GDT which can hold `MAX` number of [`Descriptor`]s.
65
65
#[ inline]
66
66
pub const fn empty ( ) -> Self {
67
+ // TODO: Replace with compiler error when feature(generic_const_exprs) is stable.
68
+ assert ! ( MAX > 0 , "A GDT cannot have 0 entries" ) ;
69
+ assert ! ( MAX <= ( 1 << 13 ) , "A GDT can only have at most 2^13 entries" ) ;
67
70
Self {
68
71
table : [ 0 ; MAX ] ,
69
72
next_free : 1 ,
@@ -184,6 +187,8 @@ impl<const MAX: usize> GlobalDescriptorTable<MAX> {
184
187
use core:: mem:: size_of;
185
188
super :: DescriptorTablePointer {
186
189
base : crate :: VirtAddr :: new ( self . table . as_ptr ( ) as u64 ) ,
190
+ // 0 < self.next_free <= MAX <= 2^13, so the limit calculation
191
+ // will not underflow or overflow.
187
192
limit : ( self . next_free * size_of :: < u64 > ( ) - 1 ) as u16 ,
188
193
}
189
194
}
You can’t perform that action at this time.
0 commit comments