From ac8a870408cd1ddc449c8e6a5699954803df5c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Sun, 4 Sep 2022 18:01:48 +0300 Subject: [PATCH 1/3] Add workaround for CPUID bug in std --- Cargo.lock | 2 +- cpufeatures/Cargo.toml | 2 +- cpufeatures/src/x86.rs | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0684895e..3b2b2842 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,7 @@ version = "0.0.2" [[package]] name = "cpufeatures" -version = "0.2.4" +version = "0.2.5" dependencies = [ "libc", ] diff --git a/cpufeatures/Cargo.toml b/cpufeatures/Cargo.toml index b5a72330..d42f9dca 100644 --- a/cpufeatures/Cargo.toml +++ b/cpufeatures/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cpufeatures" -version = "0.2.4" +version = "0.2.5" description = """ Lightweight runtime CPU feature detection for x86/x86_64 and aarch64 with no_std support and support for mobile targets including Android and iOS diff --git a/cpufeatures/src/x86.rs b/cpufeatures/src/x86.rs index e21131bf..c973b744 100644 --- a/cpufeatures/src/x86.rs +++ b/cpufeatures/src/x86.rs @@ -33,12 +33,27 @@ macro_rules! __unless_target_features { macro_rules! __detect_target_features { ($($tf:tt),+) => {{ #[cfg(target_arch = "x86")] - use core::arch::x86::{__cpuid, __cpuid_count}; + use core::arch::x86::{__cpuid, __cpuid_count, CpuidResult}; #[cfg(target_arch = "x86_64")] - use core::arch::x86_64::{__cpuid, __cpuid_count}; + use core::arch::x86_64::{__cpuid, __cpuid_count, CpuidResult}; + + // These wrappers are workarounds around + // https://github.com/rust-lang/rust/issues/101346 + // + // DO NOT remove it until MSRV is bumped to a version + // with the issue fix (at least 1.64). + #[inline(never)] + unsafe fn cpuid(leaf: u32) -> CpuidResult { + __cpuid(leaf) + } + + #[inline(never)] + unsafe fn cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult { + __cpuid_count(leaf, sub_leaf) + } let cr = unsafe { - [__cpuid(1), __cpuid_count(7, 0)] + [cpuid(1), cpuid_count(7, 0)] }; $($crate::check!(cr, $tf) & )+ true From 5429d41a7b1592ef9a2e35b2573def75df55402c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Sun, 4 Sep 2022 18:10:11 +0300 Subject: [PATCH 2/3] Update changelog --- cpufeatures/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpufeatures/CHANGELOG.md b/cpufeatures/CHANGELOG.md index 53aca1db..9f5f01be 100644 --- a/cpufeatures/CHANGELOG.md +++ b/cpufeatures/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.2.5 (2022-09-05) +### Fixed +- Add workaround for [CPUID bug] in `std` ([#800]) + +[CPUID bug]: https://github.com/rust-lang/rust/issues/101346 +[#800]: https://github.com/RustCrypto/utils/pull/800 + ## 0.2.4 (2022-08-22) - Re-release v0.2.3 without any changes to fix [#795] ([#796]) From 757e8b04e8993c228d78994a9eaa523b16a596c5 Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Sun, 4 Sep 2022 20:39:41 +0000 Subject: [PATCH 3/3] Update release date --- cpufeatures/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpufeatures/CHANGELOG.md b/cpufeatures/CHANGELOG.md index 9f5f01be..dae3dd11 100644 --- a/cpufeatures/CHANGELOG.md +++ b/cpufeatures/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 0.2.5 (2022-09-05) +## 0.2.5 (2022-09-04) ### Fixed - Add workaround for [CPUID bug] in `std` ([#800])