Skip to content

Conversation

@mikewyxtt
Copy link

I've rewritten the Iterator impl to be a bit easier on the eyes and also prevent out of bounds access panics whilst iterating.

I do suspect there is a way to implement this without using unsafe code, but I haven't gotten to it yet.

Also:

  • Created a proper BootInfoHeader struct, with a payload_len() method for convenience when constructing the chunk slice in the iterator
  • Declares BootInfoExtraId enum as non_exhaustive
  • Adds additional enum fields to match the C enum in bootinfo_types.h

- Create BootInfoHeader struct.
- Refactor BootInfoExtra struct to use the header instead of an id and 'content_with_header'. This allows the chunk to be referenced individually.
- BootInfoHeader.id() returns type BootInfoExtraId
- BootInfoHeader.id_raw() returns type sys::seL4_BootInfoID::Type
@mikewyxtt mikewyxtt requested a review from nspin as a code owner August 25, 2025 04:23
@nspin
Copy link
Member

nspin commented Aug 31, 2025

Thanks for identifying this bug.

I'd like to avoid unsafe except where absolutely necessary. The reason for not using the sys::seL4_BootInfoHeader directly for reading the header is because casting arbitrary data to Rust structs is unsound. You can read more about why in the docs of the zerocopy crate which provides a safe way to do this. However, I'd like to avoid unnecessary dependencies too, hence the manual way of doing it implemented in bootinfo.rs.

But I'm all for making the BootInfoExtraIter implementation more readable! Provided that we don't introduce unnecessary usage of unsafe (or unnecessary dependencies like zerocopy).

In the meantime, do you have a fix for the bug without using unsafe?

Also, thanks for adding more enum variants to BootInfoExtraId. For those new variants, can we stick to the Rust convention of UpperCamelCase?

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