@@ -4947,7 +4947,13 @@ struct VM {
49474947 for (unsigned i = 0 ; i < CPUID_ITER; ++i) {
49484948 // read rdtsc and accumulate delta
49494949 const u64 now = rdtsc ();
4950- acc += (now >= last) ? (now - last) : (u64 )((u64 )0 - last + now);
4950+
4951+ // If now < last, the hypervisor rewound the TSC or it's a very rare 64-bit overflow
4952+ // we do not increment acc to ensure ratio t2_delta / t1_delta drops below 0.95
4953+ if (now >= last) {
4954+ acc += (now - last);
4955+ }
4956+
49514957 last = now;
49524958
49534959 // store latency if buffer has space
@@ -4964,7 +4970,11 @@ struct VM {
49644970
49654971 // final rdtsc after detecting finish
49664972 const u64 final_now = rdtsc ();
4967- acc += (final_now >= last) ? (final_now - last) : (u64 )((u64 )0 - last + final_now);
4973+
4974+ if (final_now >= last) {
4975+ acc += (final_now - last);
4976+ }
4977+
49684978 last = final_now;
49694979
49704980 // publish results
@@ -5011,7 +5021,7 @@ struct VM {
50115021
50125022 if (cpuid_latency >= cycle_threshold) {
50135023 debug (" TIMER: Detected a vmexit on CPUID" );
5014- return true ;
5024+ return core::add (brands::NULL_BRAND, 100 ); // to prevent FPs due to kernel noise
50155025 }
50165026 else if (cpuid_latency <= 25 ) {
50175027 debug (" TIMER: Detected a hypervisor downscaling CPUID latency" );
@@ -6573,16 +6583,6 @@ struct VM {
65736583 debug (" FIRMWARE: C2 and C3 latencies indicate VM" );
65746584 return true ;
65756585 }
6576-
6577- if (buffer_len >= 276 ) {
6578- u64 hypervisor_vid = 0 ;
6579- memcpy (&hypervisor_vid, buffer + 268 , 8 );
6580-
6581- if (hypervisor_vid != 0 ) {
6582- debug (" FIRMWARE: FACP 'Hypervisor Vendor Identity' field is occupied" );
6583- return true ;
6584- }
6585- }
65866586 }
65876587
65886588 return false ;
@@ -7513,6 +7513,10 @@ struct VM {
75137513 }
75147514 #endif
75157515
7516+ // ARM CPUs trigger this check
7517+ if (util::is_running_under_translator ())
7518+ return false ;
7519+
75167520 const HMODULE kernel32 = GetModuleHandleA (" kernel32.dll" );
75177521 const HMODULE ntdll = util::get_ntdll ();
75187522 if (!kernel32 || !ntdll) {
@@ -11217,8 +11221,6 @@ struct VM {
1121711221 const unsigned char * n =
1121811222 reinterpret_cast <const unsigned char *>(needle);
1121911223
11220- const size_t nlen = strlen (needle);
11221-
1122211224 for (; *h; ++h) {
1122311225 size_t i = 0 ;
1122411226 for (;; ++i) {
@@ -11361,8 +11363,6 @@ struct VM {
1136111363 { 0x4B564D00u , 0x4B564DFFu }
1136211364 };
1136311365
11364- static thread_local bool g_msr_faulted = false ;
11365-
1136611366 auto try_read = [](u32 msr_index) -> bool {
1136711367 #if (MSVC)
1136811368 unsigned __int64 value = 0 ;
@@ -11375,7 +11375,7 @@ struct VM {
1137511375 return false ;
1137611376 }
1137711377 #elif (GCC || CLANG)
11378- g_msr_faulted = false ;
11378+ static thread_local bool g_msr_faulted = false ;
1137911379
1138011380 auto veh_handler = [](PEXCEPTION_POINTERS info) -> LONG {
1138111381 if (info->ExceptionRecord ->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION) {
0 commit comments