File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -244,16 +244,21 @@ impl<const MAX: usize> GlobalDescriptorTable<MAX> {
244
244
index
245
245
}
246
246
247
+ /// Returns the value of the limit for a gdt pointer. It is one less than the number of bytes of the table.
248
+ pub const fn limit ( & self ) -> u16 {
249
+ use core:: mem:: size_of;
250
+ // 0 < self.next_free <= MAX <= 2^13, so the limit calculation
251
+ // will not underflow or overflow.
252
+ ( self . len * size_of :: < u64 > ( ) - 1 ) as u16
253
+ }
254
+
247
255
/// Creates the descriptor pointer for this table. This pointer can only be
248
256
/// safely used if the table is never modified or destroyed while in use.
249
257
#[ cfg( feature = "instructions" ) ]
250
258
fn pointer ( & self ) -> super :: DescriptorTablePointer {
251
- use core:: mem:: size_of;
252
259
super :: DescriptorTablePointer {
253
260
base : crate :: VirtAddr :: new ( self . table . as_ptr ( ) as u64 ) ,
254
- // 0 < self.next_free <= MAX <= 2^13, so the limit calculation
255
- // will not underflow or overflow.
256
- limit : ( self . len * size_of :: < u64 > ( ) - 1 ) as u16 ,
261
+ limit : self . limit ( ) ,
257
262
}
258
263
}
259
264
}
You can’t perform that action at this time.
0 commit comments