diff --git a/src/imp/atomic128/detect/x86_64.rs b/src/imp/atomic128/detect/x86_64.rs index defd0179..939bbea9 100644 --- a/src/imp/atomic128/detect/x86_64.rs +++ b/src/imp/atomic128/detect/x86_64.rs @@ -2,8 +2,8 @@ #![cfg_attr( any( - portable_atomic_no_outline_atomics, not(target_feature = "sse"), + portable_atomic_no_outline_atomics, target_env = "sgx", miri, portable_atomic_sanitize_thread, @@ -69,7 +69,7 @@ fn _detect(info: &mut CpuInfo) { { info.set(CpuInfo::HAS_CMPXCHG16B); } - // sgx doesn't support `cpuid`: https://github.com/rust-lang/stdarch/blob/a0c30f3e3c75adcd6ee7efc94014ebcead61c507/crates/core_arch/src/x86/cpuid.rs#L102-L105 + // SGX doesn't support CPUID: https://github.com/rust-lang/stdarch/blob/a0c30f3e3c75adcd6ee7efc94014ebcead61c507/crates/core_arch/src/x86/cpuid.rs#L102-L105 #[cfg(not(any(target_env = "sgx", miri)))] { use core::arch::x86_64::_xgetbv; @@ -137,8 +137,8 @@ mod tests { } #[test] - // Miri doesn't support inline assembly - // sgx doesn't support `cpuid` + // SGX doesn't support CPUID. + // Miri doesn't support inline assembly. #[cfg_attr(any(target_env = "sgx", miri), ignore)] fn test_cpuid() { assert_eq!(std::is_x86_feature_detected!("cmpxchg16b"), has_cmpxchg16b()); diff --git a/src/imp/atomic128/x86_64.rs b/src/imp/atomic128/x86_64.rs index 12c61579..e332937a 100644 --- a/src/imp/atomic128/x86_64.rs +++ b/src/imp/atomic128/x86_64.rs @@ -273,10 +273,12 @@ unsafe fn atomic_load(src: *mut u128, order: Ordering) -> u128 { // Do not use vector registers on targets such as x86_64-unknown-none unless SSE is explicitly enabled. // https://doc.rust-lang.org/nightly/rustc/platform-support/x86_64-unknown-none.html + // SGX doesn't support CPUID. // Miri and Sanitizer do not support inline assembly. #[cfg(any( - portable_atomic_no_outline_atomics, not(target_feature = "sse"), + portable_atomic_no_outline_atomics, + target_env = "sgx", miri, portable_atomic_sanitize_thread, ))] @@ -285,8 +287,9 @@ unsafe fn atomic_load(src: *mut u128, order: Ordering) -> u128 { _atomic_load_cmpxchg16b(src, order) } #[cfg(not(any( - portable_atomic_no_outline_atomics, not(target_feature = "sse"), + portable_atomic_no_outline_atomics, + target_env = "sgx", miri, portable_atomic_sanitize_thread, )))] @@ -316,10 +319,12 @@ unsafe fn atomic_store(dst: *mut u128, val: u128, order: Ordering) { // Do not use vector registers on targets such as x86_64-unknown-none unless SSE is explicitly enabled. // https://doc.rust-lang.org/nightly/rustc/platform-support/x86_64-unknown-none.html + // SGX doesn't support CPUID. // Miri and Sanitizer do not support inline assembly. #[cfg(any( - portable_atomic_no_outline_atomics, not(target_feature = "sse"), + portable_atomic_no_outline_atomics, + target_env = "sgx", miri, portable_atomic_sanitize_thread, ))] @@ -328,8 +333,9 @@ unsafe fn atomic_store(dst: *mut u128, val: u128, order: Ordering) { _atomic_store_cmpxchg16b(dst, val, order); } #[cfg(not(any( - portable_atomic_no_outline_atomics, not(target_feature = "sse"), + portable_atomic_no_outline_atomics, + target_env = "sgx", miri, portable_atomic_sanitize_thread, )))] diff --git a/src/imp/fallback/imp.rs b/src/imp/fallback/imp.rs index 14d8b449..d216b0b4 100644 --- a/src/imp/fallback/imp.rs +++ b/src/imp/fallback/imp.rs @@ -3,6 +3,7 @@ target_arch = "x86_64", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), allow(dead_code) )] diff --git a/src/imp/fallback/mod.rs b/src/imp/fallback/mod.rs index 71af7235..28cc14da 100644 --- a/src/imp/fallback/mod.rs +++ b/src/imp/fallback/mod.rs @@ -86,6 +86,7 @@ pub(crate) use seq_lock::imp::{AtomicI64, AtomicU64}; target_arch = "x86_64", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), ), allow(unused_imports) diff --git a/src/imp/mod.rs b/src/imp/mod.rs index 6d66121f..8eb690a0 100644 --- a/src/imp/mod.rs +++ b/src/imp/mod.rs @@ -43,6 +43,7 @@ mod aarch64; feature = "fallback", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), ))] #[cfg(target_arch = "x86_64")] @@ -323,6 +324,7 @@ pub(crate) use self::aarch64::{AtomicI128, AtomicU128}; feature = "fallback", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), ), target_arch = "x86_64", @@ -353,6 +355,7 @@ pub(crate) use self::s390x::{AtomicI128, AtomicU128}; feature = "fallback", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), ), target_arch = "x86_64", diff --git a/src/lib.rs b/src/lib.rs index 35f82c6c..1fb9a41d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,6 +233,7 @@ See also [the `atomic128` module's readme](https://github.com/taiki-e/portable-a target_arch = "x86_64", portable_atomic_unstable_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), feature = "fallback", ), feature(cmpxchg16b_target_feature) @@ -4597,6 +4598,7 @@ atomic_int!(AtomicU64, u64, 8); feature = "fallback", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), ), target_arch = "x86_64", @@ -4649,6 +4651,7 @@ atomic_int!(AtomicI128, i128, 16); feature = "fallback", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), ), ), target_arch = "x86_64", diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 24c35c79..ad26cfa5 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -167,6 +167,7 @@ fn test_is_lock_free() { feature = "fallback", portable_atomic_cmpxchg16b_target_feature, not(portable_atomic_no_outline_atomics), + not(target_env = "sgx"), )) && std::is_x86_feature_detected!("cmpxchg16b"); assert_eq!(AtomicI128::is_lock_free(), has_cmpxchg16b); assert_eq!(AtomicU128::is_lock_free(), has_cmpxchg16b); diff --git a/src/utils.rs b/src/utils.rs index 4c2e15f0..d5c172d8 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -141,6 +141,7 @@ macro_rules! serde_impls { // Adapted from https://github.com/BurntSushi/memchr/blob/2.4.1/src/memchr/x86/mod.rs#L9-L71. #[allow(unused_macros)] #[cfg(not(portable_atomic_no_outline_atomics))] +#[cfg(any(target_arch = "aarch64", all(target_arch = "x86_64", not(target_env = "sgx"))))] macro_rules! ifunc { // if the functions are unsafe, this macro is also unsafe. (unsafe fn($($arg_pat:ident: $arg_ty:ty),*) $(-> $ret_ty:ty)? { $($if_block:tt)* }) => {{