-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect: Support run-time detection on aarch64 Fuchsia
- Loading branch information
Showing
11 changed files
with
189 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Run-time feature detection on aarch64 Fuchsia by using zx_system_get_features. | ||
// | ||
// As of nightly-2023-01-23, is_aarch64_feature_detected doesn't support run-time detection on Fuchsia. | ||
// https://github.com/rust-lang/stdarch/blob/a0c30f3e3c75adcd6ee7efc94014ebcead61c507/crates/std_detect/src/detect/mod.rs | ||
// | ||
// Refs: | ||
// - https://fuchsia.dev/fuchsia-src/reference/syscalls/system_get_features | ||
// - https://github.com/llvm/llvm-project/commit/4e731abc55681751b5d736b613f7720e50eb1ad4 | ||
|
||
#![cfg_attr( | ||
any( | ||
portable_atomic_no_aarch64_target_feature, | ||
any(target_feature = "lse", portable_atomic_target_feature = "lse") | ||
), | ||
allow(dead_code) | ||
)] | ||
|
||
include!("common.rs"); | ||
|
||
#[allow(non_camel_case_types, clippy::upper_case_acronyms)] | ||
mod ffi { | ||
// https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/zircon/system/public/zircon/types.h | ||
pub(crate) type zx_status_t = i32; | ||
|
||
// https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/zircon/system/public/zircon/errors.h | ||
pub(crate) const ZX_OK: zx_status_t = 0; | ||
// https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/zircon/system/public/zircon/features.h | ||
pub(crate) const ZX_FEATURE_KIND_CPU: u32 = 0; | ||
pub(crate) const ZX_ARM64_FEATURE_ISA_ATOMICS: u32 = 1 << 8; | ||
|
||
#[link(name = "zircon")] | ||
extern "C" { | ||
// https://fuchsia.dev/fuchsia-src/reference/syscalls/system_get_features | ||
pub(crate) fn zx_system_get_features(kind: u32, features: *mut u32) -> zx_status_t; | ||
} | ||
} | ||
|
||
#[inline] | ||
fn _detect(info: &mut CpuInfo) { | ||
let mut features: u32 = 0; | ||
// SAFETY: we've passed a valid pointer. | ||
let res = unsafe { ffi::zx_system_get_features(ffi::ZX_FEATURE_KIND_CPU, &mut features) }; | ||
if res != ffi::ZX_OK { | ||
return; | ||
} | ||
if (features & ffi::ZX_ARM64_FEATURE_ISA_ATOMICS) != 0 { | ||
info.set(CpuInfo::HAS_LSE); | ||
} | ||
} | ||
|
||
#[allow( | ||
clippy::alloc_instead_of_core, | ||
clippy::std_instead_of_alloc, | ||
clippy::std_instead_of_core, | ||
clippy::undocumented_unsafe_blocks, | ||
clippy::wildcard_imports | ||
)] | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
// Static assertions for FFI bindings. | ||
// This checks that FFI bindings defined in this crate and FFI bindings | ||
// generated for the platform's latest header file using bindgen have | ||
// compatible signatures (or the same values if constants). | ||
// Since this is static assertion, we can detect problems with | ||
// `cargo check --tests --target <target>` run in CI (via TESTS=1 build.sh) | ||
// without actually running tests on these platforms. | ||
// See also tools/codegen/src/ffi.rs. | ||
// TODO: auto-generate this test | ||
#[allow( | ||
clippy::cast_possible_wrap, | ||
clippy::cast_sign_loss, | ||
clippy::cast_possible_truncation, | ||
clippy::no_effect_underscore_binding | ||
)] | ||
const _: fn() = || { | ||
use crate::tests::sys::*; | ||
// TODO: zx_status_t, zx_system_get_features | ||
let [] = [(); (ffi::ZX_OK - zircon_system_public_zircon_errors::ZX_OK as ffi::zx_status_t) | ||
as usize]; | ||
let [] = [(); (ffi::ZX_FEATURE_KIND_CPU | ||
- zircon_system_public_zircon_features::ZX_FEATURE_KIND_CPU) | ||
as usize]; | ||
let [] = [(); (ffi::ZX_ARM64_FEATURE_ISA_ATOMICS | ||
- zircon_system_public_zircon_features::ZX_ARM64_FEATURE_ISA_ATOMICS) | ||
as usize]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/tests/gen/sys/aarch64_fuchsia/zircon_system_public_zircon_errors.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/tests/gen/sys/aarch64_fuchsia/zircon_system_public_zircon_features.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
diff --git a/zircon/system/public/zircon/features.h b/zircon/system/public/zircon/features.h | ||
--- a/zircon/system/public/zircon/features.h | ||
+++ b/zircon/system/public/zircon/features.h | ||
@@ -8,7 +8,7 @@ | ||
// clang-format off | ||
|
||
// types of features that can be retrieved via |zx_system_get_features| | ||
-#define ZX_FEATURE_KIND_CPU ((uint32_t)0) | ||
+#define ZX_FEATURE_KIND_CPU 0 | ||
#define ZX_FEATURE_KIND_HW_BREAKPOINT_COUNT ((uint32_t)1) | ||
#define ZX_FEATURE_KIND_HW_WATCHPOINT_COUNT ((uint32_t)2) | ||
#define ZX_FEATURE_KIND_ADDRESS_TAGGING ((uint32_t)3) | ||
@@ -35,7 +35,7 @@ | ||
#define ZX_ARM64_FEATURE_ISA_SHA1 ((uint32_t)(1u << 5)) | ||
#define ZX_ARM64_FEATURE_ISA_SHA256 ((uint32_t)(1u << 6)) | ||
#define ZX_ARM64_FEATURE_ISA_CRC32 ((uint32_t)(1u << 7)) | ||
-#define ZX_ARM64_FEATURE_ISA_ATOMICS ((uint32_t)(1u << 8)) | ||
+#define ZX_ARM64_FEATURE_ISA_ATOMICS (1u << 8) | ||
#define ZX_ARM64_FEATURE_ISA_RDM ((uint32_t)(1u << 9)) | ||
#define ZX_ARM64_FEATURE_ISA_SHA3 ((uint32_t)(1u << 10)) | ||
#define ZX_ARM64_FEATURE_ISA_SM3 ((uint32_t)(1u << 11)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters