-
-
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 illumos
- Loading branch information
Showing
10 changed files
with
313 additions
and
0 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
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,73 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Run-time CPU feature detection on AArch64 illumos by using getisax. | ||
|
||
include!("common.rs"); | ||
|
||
// core::ffi::c_* (except c_void) requires Rust 1.64, libc will soon require Rust 1.47 | ||
#[allow(non_camel_case_types)] | ||
mod ffi { | ||
pub(crate) use super::c_types::c_uint; | ||
|
||
// Defined in sys/auxv_aarch64.h. | ||
// /~https://github.com/richlowe/illumos-gate/blob/arm64-gate/usr/src/uts/common/sys/auxv_aarch64.h | ||
pub(crate) const AV_AARCH64_LSE: u32 = 1 << 15; | ||
pub(crate) const AV_AARCH64_2_LSE2: u32 = 1 << 2; | ||
|
||
extern "C" { | ||
// Defined in sys/auxv.h. | ||
// https://illumos.org/man/2/getisax | ||
// /~https://github.com/richlowe/illumos-gate/blob/arm64-gate/usr/src/uts/common/sys/auxv.h | ||
pub(crate) fn getisax(array: *mut u32, n: c_uint) -> c_uint; | ||
} | ||
} | ||
|
||
#[cold] | ||
fn _detect(info: &mut CpuInfo) { | ||
let mut out = [0_u32; 2]; | ||
// SAFETY: the pointer is valid because we got it from a reference. | ||
unsafe { | ||
ffi::getisax(out.as_mut_ptr(), 2); | ||
} | ||
if out[0] & ffi::AV_AARCH64_LSE != 0 { | ||
info.set(CpuInfo::HAS_LSE); | ||
} | ||
if out[1] & ffi::AV_AARCH64_2_LSE2 != 0 { | ||
info.set(CpuInfo::HAS_LSE2); | ||
} | ||
} | ||
|
||
#[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(codegen): 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 test_helper::sys; | ||
let mut _getisax: unsafe extern "C" fn(*mut u32, ffi::c_uint) -> ffi::c_uint = ffi::getisax; | ||
_getisax = sys::getisax; | ||
static_assert!(ffi::AV_AARCH64_LSE == sys::AV_AARCH64_LSE); | ||
static_assert!(ffi::AV_AARCH64_2_LSE2 == sys::AV_AARCH64_2_LSE2); | ||
}; | ||
} |
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.
68 changes: 68 additions & 0 deletions
68
tests/helper/src/gen/sys/aarch64_illumos/sys_auxv_aarch64.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
Oops, something went wrong.