Skip to content

[Question] Why at most 8 entries for the GDT? #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TornaxO7 opened this issue Nov 11, 2022 · 3 comments
Closed

[Question] Why at most 8 entries for the GDT? #395

TornaxO7 opened this issue Nov 11, 2022 · 3 comments

Comments

@TornaxO7
Copy link
Contributor

May I ask why there can be only at most 8 entries in the GDT? According to the intel manual the GDT should be able to have at most 8.192 entries:
image

@josephlr
Copy link
Contributor

The basic answer is we had to pick a size, and 8 was a reasonable value that worked for most use-cases.

In theory, with const-generics now stable, we could add a parameter to make the maximum size user-configurable. Something like:

#[derive(Debug, Clone)]
pub struct GlobalDescriptorTable<const MAX: usize = 8> {
    table: [u64; MAX],
    len: usize,
}

impl<const MAX: usize> GlobalDescriptorTable<MAX> {
   #[inline]
    pub const fn new() -> Self {
        assert!(MAX >= 1);
        Self {
            table: [0; MAX],
            len: 1,
        }
    }
    ...
}

The main downside is that while this looks like it would be a non-breaking change, it is actually a very subtle breaking change:

pub fn this_still_works() -> GlobalDescriptorTable {
    let x = GlobalDescriptorTable::new();
    x
}
pub fn this_stops_working() {
    let x = GlobalDescriptorTable::new();
    ...
}

@TornaxO7
Copy link
Contributor Author

Hm... ok. Thank you for your response!

@phil-opp
Copy link
Member

Update: We merged a PR to use const generics for the GDT in #360, apparently even before this issue was opened. The reason that this was not available on crates.io yet is that the PR targeted the v0.15 release, which is almost ready now (see #446).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants