rust-osdev / x86_64

Library to program x86_64 hardware.
https://docs.rs/x86_64
Apache License 2.0
797 stars 132 forks source link

gdt: Check that MAX is in range #365

Closed josephlr closed 2 years ago

josephlr commented 2 years ago

The GDT can have a maxium length of 2^16 bytes, and must contain at least one null descriptor. As MAX counts the number of u64 entries, we must have 0 < MAX <= 2^13.

Unfortunely, we cannot do this check with a where clause, as feature(generic_const_expers) is not yet stable. However, we can do this check with an assert! in GlobalDescriptorTable::empty(), which is a const fn.

Pointed out by @Freax13 in https://github.com/rust-osdev/x86_64/pull/360#discussion_r836788703

Signed-off-by: Joe Richey joerichey@google.com