Skip to content

uefi-raw: improve documentation how to model UEFI types - #2091

Open
phip1611 wants to merge 1 commit into
mainfrom
uefi-raw-doc
Open

phip1611 wants to merge 1 commit into
mainfrom
uefi-raw-doc

Conversation

@phip1611

Copy link
Copy Markdown
Member

Let's document how we actually model things in uefi-raw.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@phip1611 phip1611 self-assigned this Sep 14, 2026
Comment thread uefi-raw/src/lib.rs
//!
//! ## Mapping of C Qualifiers to Rust
//!
//! The spec annotates parameters with `IN`, `OUT`, `IN OUT`, `CONST` and

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicholasbishop from everything that has happened today, I think this is the most interesting to you. My first take on a writeup and future guidance.

I know that we are not yet 100% perfect here and there are likely a few things still inconsistent or one can argue about them - I fully agree. I am nevertheless very confident that today's spec and UB fixes are a significant step forward.

Comment thread uefi-raw/src/lib.rs
//! ## Mapping of C Qualifiers to Rust
//!
//! The spec annotates parameters with `IN`, `OUT`, `IN OUT`, `CONST` and
//! `OPTIONAL`. In C these are comments; in Rust they become pointer types,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear on this part: "in Rust they become pointer types". Since our signature has to match the C code, optionals don't really affect the Rust signature except in the case of function pointers, which can't otherwise be null in Rust.

Comment thread uefi-raw/src/lib.rs
//! | `IN T *Name`, `IN CONST T *Name` | `*const T` |
//! | `OUT T *Name`, `IN OUT T *Name` | `*mut T` |
//! | `IN T *Name OPTIONAL` | `*const T` |
//! | `OUT T *Name OPTIONAL` | `Option<NonNull<T>>` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this last row accurate? NonNull isn't currently used in uefi-raw, which I think is probably a fine choice since we generally want to closely match the C API, which doesn't have this concept.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have it at a few places. Let me double check

Comment thread uefi-raw/src/lib.rs
//! - `This` is `*const Self` if the function only reads the protocol
//! instance, otherwise `*mut Self`.
//! - Firmware-owned structures that consumers only read, such as `Mode`
//! pointers, are `*const` even where C has no `CONST`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this convention. Quoting from api_guidelines.md:

Pointer fields in structs should always be *mut. Even if the pointer should
not be used for mutation by bootloaders and OSes, these types are intended to be
useful for UEFI implementations as well, which may need to mutate data.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll revisit

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