x86_64 icon indicating copy to clipboard operation
x86_64 copied to clipboard

Add function for making a GlobalDescriptorTable in a const environmen…

Open tepperson2 opened this issue 2 years ago • 4 comments

…t on stable rust.

tepperson2 avatar Mar 03 '23 17:03 tepperson2

We probably don't want to have two identical ways of creating a GDT table. We should either:

  • Get rid of the existing &mut self method
  • Just wait for the const_mut_refs feature to be stabilized

My preference would be for the second option.

josephlr avatar Mar 03 '23 18:03 josephlr

Unfortunately it is not clear when the const_mut_refs feature will be stable, so maybe we need to wait for quite some time. So I would be fine with merging this PR to unlock GDT creation on stable Rust right now. Perhaps we should put it behind a new stable_workaround cargo feature and clearly state in the docs that the function is just a temporary workaround. (It's true that const GDT creation on stable is already possible today using from_raw_slice, but this function is unsafe and very low-level.)

  • Get rid of the existing &mut self method

This would be a breaking change, so it's not something that we can do immediately either.

phil-opp avatar Mar 04 '23 10:03 phil-opp

I think there's a way to unblock safer compile-time GDT creation without adding methods we will just end up removing later. I think we could have a method like:

impl GlobalDescriptorTable {
    pub const fn from_descriptors<const N: usize>(
        descriptors: [Descriptor; N],
    ) -> (Self, [SegmentSelector; N]) {
        ...
    }
}

which takes an array of descriptors and returns:

  • The GDT
  • The corresponding segments

See example implementation here.

josephlr avatar Mar 07 '23 00:03 josephlr

Nice, this looks very promising!

phil-opp avatar Mar 07 '23 08:03 phil-opp

Closing as this is partially addressed by #413

josephlr avatar Mar 26 '24 22:03 josephlr