From 5049415db63478eb0182a50a920df9c2668681c7 Mon Sep 17 00:00:00 2001 From: Jason White Date: Fri, 21 Oct 2022 12:09:36 -0700 Subject: [PATCH] Get main `reverie` crate compiling on aarch64 Reviewed By: wangbj Differential Revision: D40577288 fbshipit-source-id: 0cf76ef1fdae1a5bcd0aaf046ec59ed7b7478d91 --- reverie/src/lib.rs | 2 ++ reverie/src/rdtsc.rs | 3 ++- reverie/src/tool.rs | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/reverie/src/lib.rs b/reverie/src/lib.rs index db1da4b..564ecdd 100644 --- a/reverie/src/lib.rs +++ b/reverie/src/lib.rs @@ -21,6 +21,7 @@ mod auxv; mod backtrace; mod error; mod guest; +#[cfg(target_arch = "x86_64")] mod rdtsc; mod stack; mod subscription; @@ -33,6 +34,7 @@ pub use error::*; pub use guest::*; pub use process::ExitStatus; pub use process::Pid; +#[cfg(target_arch = "x86_64")] pub use rdtsc::*; pub use reverie_process as process; pub use stack::*; diff --git a/reverie/src/rdtsc.rs b/reverie/src/rdtsc.rs index cf69bba..85d992d 100644 --- a/reverie/src/rdtsc.rs +++ b/reverie/src/rdtsc.rs @@ -7,7 +7,8 @@ * LICENSE file in the root directory of this source tree. */ -//! rdtsc/rdtscp helpers +//! rdtsc/rdtscp helpers. This only makes sense on x86_64 as it is the only +//! architecture where we can intercept these instructions. use core::arch::x86_64::__rdtscp; use core::arch::x86_64::_rdtsc; diff --git a/reverie/src/tool.rs b/reverie/src/tool.rs index 37e7b59..d492b3d 100644 --- a/reverie/src/tool.rs +++ b/reverie/src/tool.rs @@ -14,8 +14,6 @@ //! same process. use async_trait::async_trait; -use raw_cpuid::cpuid; -use raw_cpuid::CpuIdResult; use reverie_syscalls::Syscall; use serde::de::DeserializeOwned; use serde::Serialize; @@ -23,7 +21,9 @@ use serde::Serialize; use crate::error::Errno; use crate::error::Error; use crate::guest::Guest; +#[cfg(target_arch = "x86_64")] use crate::rdtsc::Rdtsc; +#[cfg(target_arch = "x86_64")] use crate::rdtsc::RdtscResult; use crate::ExitStatus; use crate::Pid; @@ -238,25 +238,31 @@ pub trait Tool: Serialize + DeserializeOwned + Send + Sync + Default { guest.tail_inject(c).await } - /// CPUID is trapped, the tool should implement this function to return [eax, - /// ebx, ecx, edx] + /// CPUID is trapped, the tool should implement this function to return + /// `[eax, ebx, ecx, edx]`. /// - /// NOTE: This is never called by default unless cpuid events are subscribed - /// to. + /// NOTE: + /// * This is never called by default unless cpuid events are subscribed + /// to. + /// * This is only available on x86_64. + #[cfg(target_arch = "x86_64")] async fn handle_cpuid_event>( &self, _guest: &mut T, eax: u32, ecx: u32, - ) -> Result { - Ok(cpuid!(eax, ecx)) + ) -> Result { + Ok(raw_cpuid::cpuid!(eax, ecx)) } /// rdtsc/rdtscp is trapped, the tool should implement this function to /// return the counter. /// - /// NOTE: This is never called by default unless rdtsc events are subscribed - /// to. + /// NOTE: + /// * This is never called by default unless rdtsc events are subscribed + /// to. + /// * This is only available on x86_64. + #[cfg(target_arch = "x86_64")] async fn handle_rdtsc_event>( &self, _guest: &mut T,