Skip to content

Allow the GDT to be of any length - #360

Merged
josephlr merged 2 commits into
nextfrom
dyn_gdt
Mar 27, 2022
Merged

josephlr merged 2 commits into
nextfrom
dyn_gdt

Conversation

@josephlr

@josephlr josephlr commented Mar 27, 2022 •

Copy link
Copy Markdown
Contributor

This uses a const generic MAX parameter to specify the length. This is arguably a breaking change as it bumps the MSRV to 1.59 though its use of default const generics. It also can make some function call require additional type annotations:

// Before
let gdt = GlobalDescriptorTable::from_raw_slice(slice);
// After
let gdt = GlobalDescriptorTable::<8>::from_raw_slice(slice);

Fixes #333

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

@josephlr
josephlr requested review from Freax13 and phil-opp March 27, 2022 06:57
@josephlr josephlr mentioned this pull request Mar 27, 2022
11 of 13 tasks

@Freax13 Freax13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me, only two minor things that need to be improved.

Comment thread src/structures/gdt.rs Resolved
Comment thread src/structures/gdt.rs Resolved
Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
@josephlr
josephlr requested a review from Freax13 March 27, 2022 22:38
@josephlr

Copy link
Copy Markdown
Contributor Author

@Freax13 I updated the comments and messages. I think even with @phil-opp's approval I also need yours to merge this.

@josephlr
josephlr enabled auto-merge March 27, 2022 22:40

@Freax13 Freax13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread src/structures/gdt.rs
Comment on lines +51 to 54
pub struct GlobalDescriptorTable<const MAX: usize = 8> {
table: [u64; MAX],
next_free: usize,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit too late, but I just noticed that this design allows creating GDT's without any entries, but a GDT must always have at least a null entry, doesn't it?

josephlr added a commit that referenced this pull request Mar 29, 2022
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
#360 (comment)

Signed-off-by: Joe Richey <joerichey@google.com>
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

Successfully merging this pull request may close these issues.

3 participants