From dd924d84b0d9faa16d33687599b21b27ae9d80ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 19:48:08 +0000 Subject: [PATCH 1/3] chore(deps): bump bitflags from 2.3.3 to 2.4.1 Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.3.3 to 2.4.1. - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](https://github.com/bitflags/bitflags/compare/2.3.3...2.4.1) --- updated-dependencies: - dependency-name: bitflags dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43e1a2cc..ec2a88ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,7 +41,7 @@ version = "0.66.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.1", "cexpr", "clang-sys", "lazy_static", @@ -66,9 +66,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" @@ -525,7 +525,7 @@ dependencies = [ name = "mc-sgx-core-types" version = "0.10.1" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.1", "displaydoc", "getrandom", "hex", @@ -1072,7 +1072,7 @@ version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", From a6e114e034a64413535c603b29ebb6510adfbeed Mon Sep 17 00:00:00 2001 From: Nick Santana Date: Tue, 2 Jan 2024 13:53:39 -0800 Subject: [PATCH 2/3] Update logic for new bitflags behavior The bitflags crate was updated to allow for unnamed flags. This change resulted in the formatting of `Attributes` to change slightly. As part of this upgrade the formatting of `Attributes` has been improved to show both the known flags as well as bitflag values that don't pertain to a known flag. --- core/types/src/attributes.rs | 53 ++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/core/types/src/attributes.rs b/core/types/src/attributes.rs index 9c937f4e..3190ddcc 100644 --- a/core/types/src/attributes.rs +++ b/core/types/src/attributes.rs @@ -3,7 +3,7 @@ //! SGX Attributes types use crate::{impl_newtype, impl_newtype_no_display}; -use bitflags::bitflags; +use bitflags::{bitflags, Flags}; use core::fmt::{Display, Formatter}; use core::ops::BitAnd; use mc_sgx_core_sys_types::{ @@ -79,31 +79,44 @@ impl Display for Attributes { impl Display for AttributeFlags { fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { - for (idx, (name, flag)) in self.iter_names().enumerate() { - if *self & flag == flag { - if idx >= 1 { - write!(f, " | ")?; - } - write!(f, "{}", name)?; - } - } - Ok(()) + format_bitflags(self, f) } } impl Display for ExtendedFeatureRequestMask { fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { - for (idx, (name, flag)) in self.iter_names().enumerate() { - if *self & flag == flag { - if idx >= 1 { - write!(f, " | ")?; - } - write!(f, "{}", name)?; - } - } + format_bitflags(self, f) + } +} - Ok(()) +/// Formats the provided bitflags as text +/// +/// Any bits taht aren't part of a contained flag will be formatted as a hex number. +/// +/// Example output with two known flags and some bits that didn't pertain to a tag +/// +/// FLAG1 | FLAG2 | 0x0000_0000_FF00_0000 +/// +fn format_bitflags(bitflags: &F, f: &mut Formatter) -> core::fmt::Result +where + F::Bits: Into, +{ + let mut separators = ::core::iter::once("").chain(::core::iter::repeat(" | ")); + let mut iter = bitflags.iter_names(); + for (name, _) in &mut iter { + let separator = separators.next().expect("Separator should exist"); + write!(f, "{}", separator)?; + write!(f, "{}", name)?; } + + let remaining = iter.remaining().bits(); + if remaining != bitflags::Bits::EMPTY { + let separator = separators.next().expect("Separator should exist"); + write!(f, "{}", separator)?; + mc_sgx_util::fmt_hex(&remaining.into().to_be_bytes(), f)?; + } + + Ok(()) } bitflags! { @@ -311,7 +324,7 @@ mod test { }); assert_eq!( attributes.to_string(), - "Flags: (none) Xfrm: 0x7FFF_FFFF_FFFF_FFFF" + "Flags: (none) Xfrm: LEGACY | AVX | AVX_512 | MPX | PKRU | AMX | 0x7FFF_FFFF_FFF9_FD00" ); } From e4f9874d7824d760f7ed46d34a84236e62b42564 Mon Sep 17 00:00:00 2001 From: Henry Holtzman Date: Tue, 2 Jan 2024 16:11:06 -0800 Subject: [PATCH 3/3] fixed typo --- core/types/src/attributes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/types/src/attributes.rs b/core/types/src/attributes.rs index 3190ddcc..57112fd2 100644 --- a/core/types/src/attributes.rs +++ b/core/types/src/attributes.rs @@ -91,7 +91,7 @@ impl Display for ExtendedFeatureRequestMask { /// Formats the provided bitflags as text /// -/// Any bits taht aren't part of a contained flag will be formatted as a hex number. +/// Any bits that aren't part of a contained flag will be formatted as a hex number. /// /// Example output with two known flags and some bits that didn't pertain to a tag ///