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

Add lifetimes for GDT #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add lifetimes for GDT #155

wants to merge 1 commit into from

Conversation

YtvwlD
Copy link

@YtvwlD YtvwlD commented Dec 4, 2023

I was happy to be able to use this crate for creating a GDT like this:

let gdt = DescriptorTablePointer::new_from_slice(
    &[Descriptor::NULL, code_segment, data_segment]
);
unsafe {
    x86::dtables::lgdt(&gdt)
    // inline assembly with a far-jump goes here
}

This worked in a debug build, but failed in a release build because the array containing the descriptors did not live long enough. I spent some time finding this issue, so I figured it might be nice to express these constraints via lifetimes.

I'm not sure about disallowing access to the limit and base pointer but they probably shouldn't be writable.

@gz
Copy link
Owner

gz commented Dec 29, 2023

Thanks, any reason why you'd need a non-static lifetime in the new_from_slice? e.g., would this be simpler:

pub fn new_from_slice(slice: &'static [T])

@YtvwlD
Copy link
Author

YtvwlD commented Jan 19, 2024

I'm not exactly sure. If you're writing a kernel, then you'll most likely load it with lgdt, so it would have to be 'static either way.

Not requiring it might be helpful for tests or VMs or something like that, but I don't know. I would be fine with the static lifetime just in new and new_from_slice.

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.

2 participants