Add function for making a GlobalDescriptorTable in a const environmen…
…t on stable rust.
We probably don't want to have two identical ways of creating a GDT table. We should either:
- Get rid of the existing
&mut selfmethod - Just wait for the
const_mut_refsfeature to be stabilized
My preference would be for the second option.
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 selfmethod
This would be a breaking change, so it's not something that we can do immediately either.
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.
Nice, this looks very promising!
Closing as this is partially addressed by #413