Skip to content

Commit 1cc82d5

Browse files
authored
Add workaround for CPUID bug in std (#800)
1 parent b858f0c commit 1cc82d5

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpufeatures/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.2.5 (2022-09-04)
9+
### Fixed
10+
- Add workaround for [CPUID bug] in `std` ([#800])
11+
12+
[CPUID bug]: https://github.com/rust-lang/rust/issues/101346
13+
[#800]: https://github.com/RustCrypto/utils/pull/800
14+
815
## 0.2.4 (2022-08-22)
916
- Re-release v0.2.3 without any changes to fix [#795] ([#796])
1017

cpufeatures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cpufeatures"
3-
version = "0.2.4"
3+
version = "0.2.5"
44
description = """
55
Lightweight runtime CPU feature detection for x86/x86_64 and aarch64 with
66
no_std support and support for mobile targets including Android and iOS

cpufeatures/src/x86.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,27 @@ macro_rules! __unless_target_features {
3333
macro_rules! __detect_target_features {
3434
($($tf:tt),+) => {{
3535
#[cfg(target_arch = "x86")]
36-
use core::arch::x86::{__cpuid, __cpuid_count};
36+
use core::arch::x86::{__cpuid, __cpuid_count, CpuidResult};
3737
#[cfg(target_arch = "x86_64")]
38-
use core::arch::x86_64::{__cpuid, __cpuid_count};
38+
use core::arch::x86_64::{__cpuid, __cpuid_count, CpuidResult};
39+
40+
// These wrappers are workarounds around
41+
// https://github.com/rust-lang/rust/issues/101346
42+
//
43+
// DO NOT remove it until MSRV is bumped to a version
44+
// with the issue fix (at least 1.64).
45+
#[inline(never)]
46+
unsafe fn cpuid(leaf: u32) -> CpuidResult {
47+
__cpuid(leaf)
48+
}
49+
50+
#[inline(never)]
51+
unsafe fn cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
52+
__cpuid_count(leaf, sub_leaf)
53+
}
3954

4055
let cr = unsafe {
41-
[__cpuid(1), __cpuid_count(7, 0)]
56+
[cpuid(1), cpuid_count(7, 0)]
4257
};
4358

4459
$($crate::check!(cr, $tf) & )+ true

0 commit comments

Comments
 (0)