-
- Notifications
You must be signed in to change notification settings - Fork 182
PXE: Fix BaseCode::discover optional argument #630
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
Conversation
| A quick grep ( |
e1d1c7e to 240400a Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Good catch on the bad Option type there. I've left a suggestion to use a DST struct instead of generics.
uefi/src/proto/network/pxe.rs Outdated
| server_m_cast_ip: IpAddress, | ||
| ip_cnt: u16, | ||
| srv_list: T, | ||
| srv_list: [Server; N], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change this to a DST type instead? That's how we've handled similar things elsewhere in this crate, see for example PcrEvent, and how we convert from a thin pointer to the DST type in PcrEvent::from_ptr. That way we don't need to know what N is at compile time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this closer, I don't think this can be a DST - or at least I'm not sure how to go about turning it into one. Unlike PcrEvent, this type needs to be constructed from Rust and passed across the FFI boundary - I'm not aware of a way to create a new DST instance with relying on dynamic allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry I should have provided an example of that. The way to do it without allocation is to provide a byte buffer. Here's a not-yet-merged example for PcrEvent: https://github.com/rust-osdev/uefi-rs/pull/631/files#diff-3c3ebe7fc6a06f58897b24d5e0420ad545037b8cb91dae43d5551037122d19cfR136
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. I left it as a separate commit for comparison, can be squashed.
| Should I include the |
Yes, please add |
2b4535e to b725f68 Compare | Sorry - that should be all the lints fixed. For some reason I had it in my head that clippy would yell about rustfmt issues as well. |
…fo type. NOTE: This commit changes the API for `BaseCode::discover`, but should continue to be source-compatible. The `info` parameter in `BaseCode::discover` is an optional pointer argument (it may be NULL), but is incorrectly specified in the Rust exern definition as `Option<*const T>`. This type is (at least) one byte larger than a Pointer on all platforms, making it incompatible with the Optional Pointers in EFI. The `DiscoverInfo` struct had odd bounds associated with it, and being generic over `T: ?Sized` doesn't make sense when the server list has to be a fixed size. This could be removed or broken out into a separate commit if needed.
| Lgtm, thanks again for the PR :) |
NOTE: This commit changes the API for
BaseCode::discover, but should continue to be source-compatible. Edit:DiscoverInfowill break in cases where the generic can't be inferred, or where it's explicitly declared (eg,DiscoverInfo<[Server; 4]>needs to be changed toDiscoverInfo<4>).The
infoparameter inBaseCode::discoveris an optional pointer argument (it may be NULL), but is incorrectly specified in the Rust extern definition asOption<*const T>. This type is (at least) one byte larger than a Pointer on all platforms, making it incompatible with the Optional Pointers in EFI. Two possible fixes:Optionwrapper (this is what the PR contains)Option<&T>(chose not to use this since converting references requires unsafe)The
DiscoverInfostruct had odd bounds associated with it, and being generic overT: ?Sizeddoesn't make sense when the server list has to be a fixed size. This could be removed or broken out into a separate commit if needed.Checklist