Skip to content

Conversation

AtsukiTak
Copy link
Contributor

@AtsukiTak AtsukiTak commented Feb 27, 2022

The old implementation contains a protocols slice with a lifetime a.

pub struct ProtocolsPerHandle<'a> {
    boot_services: &'a BootServices,
    protocols: &'a mut [&'a Guid],
}

But protocols slice does not live long enough for 'a. It will be freed when the ProtocolsPerHandle struct is dropped.

From std doc, ( https://doc.rust-lang.org/nightly/core/slice/fn.from_raw_parts.html )

pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]

The memory referenced by the returned slice must not be mutated for the duration of lifetime 'a.

The current codebase does not use this internal property except the protocols getter method. So having an invalid lifetime does not immediately cause undefined behavior but it is safer to fix.

Since I'm not a native English speaker, it is very appreciated to fix my English document :)

Thanks!

Old implementation contains a slice with invalid lifetime.
@nicholasbishop
Copy link
Member

Looks good, thanks for the fix!

@nicholasbishop nicholasbishop merged commit 10e6aeb into rust-osdev:main Feb 27, 2022
@AtsukiTak AtsukiTak deleted the fix-protocols-per-handle-struct branch February 27, 2022 17:04
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