-
Notifications
You must be signed in to change notification settings - Fork 159
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
uefi-raw: unified boolean type #1307
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,9 @@ bitflags.workspace = true | |
ptr_meta.workspace = true | ||
uguid.workspace = true | ||
|
||
[features] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no error type in uefi-raw now, so I think the |
||
default = [] | ||
unstable = [] | ||
|
||
[package.metadata.docs.rs] | ||
rustdoc-args = ["--cfg", "docsrs"] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,11 +31,12 @@ pub mod time; | |||||
|
||||||
mod status; | ||||||
|
||||||
use core::ffi::c_void; | ||||||
use core::fmt::{self, Debug, Formatter}; | ||||||
pub use status::Status; | ||||||
pub use uguid::{guid, Guid}; | ||||||
|
||||||
use core::ffi::c_void; | ||||||
use core::fmt::{self, Debug, Formatter}; | ||||||
|
||||||
/// Handle to an event structure. | ||||||
pub type Event = *mut c_void; | ||||||
|
||||||
|
@@ -65,6 +66,43 @@ pub type PhysicalAddress = u64; | |||||
/// of target platform. | ||||||
pub type VirtualAddress = u64; | ||||||
|
||||||
/// ABI-compatible UEFI boolean. | ||||||
/// | ||||||
/// Opaque 1-byte value holding either `0` for FALSE or a `1` for TRUE. This | ||||||
/// type can be converted from and to `bool` via corresponding [`From`] | ||||||
/// implementations. | ||||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Ord, PartialOrd, Eq, Hash)] | ||||||
#[repr(transparent)] | ||||||
pub struct Boolean(pub u8); | ||||||
|
||||||
impl Boolean { | ||||||
/// [`Boolean`] representing `true`. | ||||||
pub const TRUE: Self = Self(1); | ||||||
|
||||||
/// [`Boolean`] representing `false`. | ||||||
pub const FALSE: Self = Self(0); | ||||||
} | ||||||
|
||||||
impl From<bool> for Boolean { | ||||||
fn from(value: bool) -> Self { | ||||||
match value { | ||||||
true => Self(1), | ||||||
false => Self(0), | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
impl From<Boolean> for bool { | ||||||
#[allow(clippy::match_like_matches_macro)] | ||||||
fn from(value: Boolean) -> Self { | ||||||
// We handle it as in C: Any bit-pattern != 0 equals true | ||||||
match value.0 { | ||||||
0 => false, | ||||||
_ => true, | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// An IPv4 internet protocol address. | ||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||||||
#[repr(transparent)] | ||||||
|
@@ -133,3 +171,26 @@ impl Default for IpAddress { | |||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||||||
#[repr(transparent)] | ||||||
pub struct MacAddress(pub [u8; 32]); | ||||||
|
||||||
#[cfg(test)] | ||||||
mod tests { | ||||||
use super::*; | ||||||
|
||||||
#[test] | ||||||
/// Test the properties promised in [0]. This also applies for the other | ||||||
/// architectures. | ||||||
/// | ||||||
/// [0] https://github.com/tianocore/edk2/blob/b0f43dd3fdec2363e3548ec31eb455dc1c4ac761/MdePkg/Include/X64/ProcessorBind.h#L192 | ||||||
fn test_boolean_abi() { | ||||||
assert_eq!(size_of::<Boolean>(), 1); | ||||||
assert_eq!(Boolean::from(true).0, 1); | ||||||
assert_eq!(Boolean::from(false).0, 0); | ||||||
assert_eq!(Boolean::TRUE.0, 1); | ||||||
assert_eq!(Boolean::FALSE.0, 0); | ||||||
assert_eq!(bool::from(Boolean(0b0)), false); | ||||||
assert_eq!(bool::from(Boolean(0b1)), true); | ||||||
// We do it a C: Every bit pattern not 0 is equal to true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
assert_eq!(bool::from(Boolean(0b11111110)), true); | ||||||
assert_eq!(bool::from(Boolean(0b11111111)), true); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,9 +15,9 @@ details of the deprecated items that were removed in this release. | |||||
- **Breaking:** `FileSystem` no longer has a lifetime parameter, and the | ||||||
deprecated conversion from `uefi::table::boot::ScopedProtocol` has been | ||||||
removed. | ||||||
- **Breaking:** Removed `BootPolicyError` as `BootPolicy` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- Fixed `boot::open_protocol` to properly handle a null interface pointer. | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tiny nit: per your changes in 4d1906e, two blank lines between each version entry |
||||||
# uefi - 0.32.0 (2024-09-09) | ||||||
|
||||||
See [Deprecating SystemTable/BootServices/RuntimeServices][funcmigrate] for | ||||||
|
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.
No longer needed