Skip to content
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

Provide null segment selector as associated constant on SegmentSelector #373

Merged
merged 3 commits into from
Apr 12, 2022

Conversation

prinzdezibel
Copy link

@prinzdezibel prinzdezibel commented Apr 8, 2022

This may be useful when used as a segment selector to load a non-existent segment into the data register.
e.g.

DS::set_reg(gdt.null_segment_selector())

This may be useful when used to load into a data register in ring 0.
e.g.
```
DS::set_reg(gdt.null_segment_descriptor())
```
@prinzdezibel prinzdezibel changed the title Provide a method to retrieve the null segment descriptor. Provide a method to retrieve the null segment descriptor of the GDT Apr 8, 2022
@prinzdezibel prinzdezibel changed the title Provide a method to retrieve the null segment descriptor of the GDT Provide a method to retrieve the null segment descriptor of the GDT as SegmentSelector Apr 8, 2022
@josephlr
Copy link
Contributor

josephlr commented Apr 9, 2022

I think this method might be useful, but it doesn't seem like it needs to be a method on our GDT. It doesn't read any data from the GDT after all.

I think an associated constant like:

pub struct SegmentSelector(pub u16);

impl SegmentSelector {
    /// Some comment explaining why we want this
    pub const NULL: Self = Self::new(0, PrivilegeLevel::Ring0);

    ...
}

would be a better idea.

@prinzdezibel
Copy link
Author

prinzdezibel commented Apr 9, 2022

@josephlr

It doesn't read any data from the GDT after all.

Correct, I was thinking the same. The reason I initially thought it may make sense nonetheless was the fact that the GDT already has a null descriptor inside (which is not read - as you've noticed correctly - because it's easier to construct it as SegmentSelector directly instead of building it from the bytes of the null descriptor)
Also the concept that the SegmentSelector knows about the index of the descriptor in the GDT led me to think that this might be a good idea.

But I agree that a dedicated SegmentSelector might even be a better idea. I'm going to adapt my MR. Thanks.

@Freax13 Freax13 changed the title Provide a method to retrieve the null segment descriptor of the GDT as SegmentSelector Provide null segment selector as associated constant on SegmentSelector Apr 12, 2022
Copy link
Member

@Freax13 Freax13 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@Freax13 Freax13 merged commit 3cae23e into rust-osdev:master Apr 12, 2022
@phil-opp phil-opp mentioned this pull request Jul 10, 2022
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