Skip to content

Commit 57e4e4b

Browse files
author
Requiem
committed
directive redefinition
1 parent 89c68bf commit 57e4e4b

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/vmaware.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8026,7 +8026,7 @@ struct VM {
80268026
constexpr u64 tscSyncDiffThreshold = 1000000000LL; // TSC difference threshold
80278027

80288028
// to minimize context switching/scheduling
8029-
#if defined(WINDOWS)
8029+
#if (WINDOWS)
80308030
HANDLE hThread = GetCurrentThread();
80318031
int oldPriority = GetThreadPriority(hThread);
80328032
SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
@@ -8040,7 +8040,7 @@ struct VM {
80408040
#endif
80418041

80428042
auto restoreThreadPriority = [&]() {
8043-
#if defined(WINDOWS)
8043+
#if (WINDOWS)
80448044
SetThreadPriority(hThread, oldPriority);
80458045
#else
80468046
sched_setscheduler(0, oldPolicy, &oldParam);
@@ -8052,11 +8052,11 @@ struct VM {
80528052
int spikeCount = 0;
80538053
for (int i = 0; i < classicIterations; i++) {
80548054
u64 start = __rdtsc();
8055-
#if defined(WINDOWS)
8055+
#if (WINDOWS)
80568056
int cpu_info[4];
80578057
__cpuid(cpu_info, 0); // CPUID serializes pipeline and is frequently intercepted by hypervisors
80588058
UNUSED(cpu_info);
8059-
#elif defined(LINUX) || defined(APPLE)
8059+
#elif (LINUX || APPLE)
80608060
u32 eax = 0, ebx = 0, ecx = 0, edx = 0;
80618061
__cpuid(0, eax, ebx, ecx, edx);
80628062
UNUSED(eax); UNUSED(ebx); UNUSED(ecx); UNUSED(edx);
@@ -8088,35 +8088,35 @@ struct VM {
80888088
// rdtsc+cpuid+rdtsc on CPU1 while CPU2 spams cpuid. This detection tries to detect invariant TSC to flag hypervisors that share the same timer across multiple vCPUs
80898089
std::atomic<bool> stopSpammer{ false };
80908090
std::thread spammer([&stopSpammer] {
8091-
#if defined(WINDOWS)
8091+
#if (WINDOWS)
80928092
SetThreadAffinityMask(GetCurrentThread(), 2);
8093-
#elif defined(LINUX)
8093+
#elif (LINUX)
80948094
cpu_set_t cpuset;
80958095
CPU_ZERO(&cpuset);
80968096
CPU_SET(1, &cpuset); // core 1 (0-indexed)
80978097
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
8098-
#elif defined(APPLE)
8098+
#elif (APPLE)
80998099
thread_affinity_policy_data_t policy = { 1 };
81008100
thread_policy_set(pthread_mach_thread_np(pthread_self()),
81018101
THREAD_AFFINITY_POLICY,
81028102
(thread_policy_t)&policy, 1);
81038103
#endif
81048104
// hypervisor trap pressure
81058105
while (!stopSpammer.load()) {
8106-
#if defined(WINDOWS)
8106+
#if (WINDOWS)
81078107
int cpu_info[4];
81088108
__cpuid(cpu_info, 0);
8109-
#elif defined(LINUX) || defined(APPLE)
8109+
#elif (LINUX || APPLE)
81108110
u32 eax = 0, ebx = 0, ecx = 0, edx = 0;
81118111
__cpuid(0, eax, ebx, ecx, edx);
81128112
#endif
81138113
}
81148114
});
81158115

81168116
// --- 3a. Pin Measurement Thread for Consistent Timing ---
8117-
#if defined(WINDOWS)
8117+
#if (WINDOWS)
81188118
DWORD_PTR oldAffinityMask = SetThreadAffinityMask(GetCurrentThread(), 1);
8119-
#elif defined(LINUX)
8119+
#elif (LINUX)
81208120
cpu_set_t oldCpuSet;
81218121
CPU_ZERO(&oldCpuSet);
81228122
pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &oldCpuSet);
@@ -8125,7 +8125,7 @@ struct VM {
81258125
CPU_ZERO(&newCpuSet);
81268126
CPU_SET(0, &newCpuSet); // core 0 for consistent timing
81278127
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &newCpuSet);
8128-
#elif defined(APPLE)
8128+
#elif (APPLE)
81298129
// restoration is not supported on Apple
81308130
thread_affinity_policy_data_t policy = { 1 };
81318131
thread_policy_set(pthread_mach_thread_np(pthread_self()),
@@ -8137,10 +8137,10 @@ struct VM {
81378137
u64 measurement = 0;
81388138
for (int i = 0; i < spammerIterations; i++) {
81398139
u64 start = __rdtsc();
8140-
#if defined(WINDOWS)
8140+
#if (WINDOWS)
81418141
int cpu_info[4];
81428142
__cpuid(cpu_info, 0);
8143-
#elif defined(LINUX) || defined(APPLE)
8143+
#elif (LINUX || APPLE)
81448144
u32 eax = 0, ebx = 0, ecx = 0, edx = 0;
81458145
__cpuid(0, eax, ebx, ecx, edx);
81468146
#endif
@@ -8150,9 +8150,9 @@ struct VM {
81508150
stopSpammer.store(true);
81518151
spammer.join();
81528152

8153-
#if defined(WINDOWS)
8153+
#if (WINDOWS)
81548154
SetThreadAffinityMask(GetCurrentThread(), oldAffinityMask);
8155-
#elif defined(LINUX)
8155+
#elif (LINUX)
81568156
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &oldCpuSet);
81578157
#endif
81588158

@@ -8167,7 +8167,7 @@ struct VM {
81678167
return true;
81688168
}
81698169

8170-
#if defined(WINDOWS)
8170+
#if (WINDOWS)
81718171
// --- 4. QPC Check ---
81728172
// Compare trapping vs non-trapping instruction timing
81738173
LARGE_INTEGER startQPC, endQPC;

src/vmaware_MIT.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,7 +7831,7 @@ struct VM {
78317831
constexpr u64 tscSyncDiffThreshold = 1000000000LL; // TSC difference threshold
78327832

78337833
// to minimize context switching/scheduling
7834-
#if defined(WINDOWS)
7834+
#if (WINDOWS)
78357835
HANDLE hThread = GetCurrentThread();
78367836
int oldPriority = GetThreadPriority(hThread);
78377837
SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
@@ -7845,7 +7845,7 @@ struct VM {
78457845
#endif
78467846

78477847
auto restoreThreadPriority = [&]() {
7848-
#if defined(WINDOWS)
7848+
#if (WINDOWS)
78497849
SetThreadPriority(hThread, oldPriority);
78507850
#else
78517851
sched_setscheduler(0, oldPolicy, &oldParam);
@@ -7857,11 +7857,11 @@ struct VM {
78577857
int spikeCount = 0;
78587858
for (int i = 0; i < classicIterations; i++) {
78597859
u64 start = __rdtsc();
7860-
#if defined(WINDOWS)
7860+
#if (WINDOWS)
78617861
int cpu_info[4];
78627862
__cpuid(cpu_info, 0); // CPUID serializes pipeline and is frequently intercepted by hypervisors
78637863
UNUSED(cpu_info);
7864-
#elif defined(LINUX) || defined(APPLE)
7864+
#elif (LINUX || APPLE)
78657865
u32 eax = 0, ebx = 0, ecx = 0, edx = 0;
78667866
__cpuid(0, eax, ebx, ecx, edx);
78677867
UNUSED(eax); UNUSED(ebx); UNUSED(ecx); UNUSED(edx);
@@ -7893,35 +7893,35 @@ struct VM {
78937893
// rdtsc+cpuid+rdtsc on CPU1 while CPU2 spams cpuid. This detection tries to detect invariant TSC to flag hypervisors that share the same timer across multiple vCPUs
78947894
std::atomic<bool> stopSpammer{ false };
78957895
std::thread spammer([&stopSpammer] {
7896-
#if defined(WINDOWS)
7896+
#if (WINDOWS)
78977897
SetThreadAffinityMask(GetCurrentThread(), 2);
7898-
#elif defined(LINUX)
7898+
#elif (LINUX)
78997899
cpu_set_t cpuset;
79007900
CPU_ZERO(&cpuset);
79017901
CPU_SET(1, &cpuset); // core 1 (0-indexed)
79027902
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
7903-
#elif defined(APPLE)
7903+
#elif (APPLE)
79047904
thread_affinity_policy_data_t policy = { 1 };
79057905
thread_policy_set(pthread_mach_thread_np(pthread_self()),
79067906
THREAD_AFFINITY_POLICY,
79077907
(thread_policy_t)&policy, 1);
79087908
#endif
79097909
// hypervisor trap pressure
79107910
while (!stopSpammer.load()) {
7911-
#if defined(WINDOWS)
7911+
#if (WINDOWS)
79127912
int cpu_info[4];
79137913
__cpuid(cpu_info, 0);
7914-
#elif defined(LINUX) || defined(APPLE)
7914+
#elif (LINUX || APPLE)
79157915
u32 eax = 0, ebx = 0, ecx = 0, edx = 0;
79167916
__cpuid(0, eax, ebx, ecx, edx);
79177917
#endif
79187918
}
79197919
});
79207920

79217921
// --- 3a. Pin Measurement Thread for Consistent Timing ---
7922-
#if defined(WINDOWS)
7922+
#if (WINDOWS)
79237923
DWORD_PTR oldAffinityMask = SetThreadAffinityMask(GetCurrentThread(), 1);
7924-
#elif defined(LINUX)
7924+
#elif (LINUX)
79257925
cpu_set_t oldCpuSet;
79267926
CPU_ZERO(&oldCpuSet);
79277927
pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &oldCpuSet);
@@ -7930,7 +7930,7 @@ struct VM {
79307930
CPU_ZERO(&newCpuSet);
79317931
CPU_SET(0, &newCpuSet); // core 0 for consistent timing
79327932
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &newCpuSet);
7933-
#elif defined(APPLE)
7933+
#elif (APPLE)
79347934
// restoration is not supported on Apple
79357935
thread_affinity_policy_data_t policy = { 1 };
79367936
thread_policy_set(pthread_mach_thread_np(pthread_self()),
@@ -7942,10 +7942,10 @@ struct VM {
79427942
u64 measurement = 0;
79437943
for (int i = 0; i < spammerIterations; i++) {
79447944
u64 start = __rdtsc();
7945-
#if defined(WINDOWS)
7945+
#if (WINDOWS)
79467946
int cpu_info[4];
79477947
__cpuid(cpu_info, 0);
7948-
#elif defined(LINUX) || defined(APPLE)
7948+
#elif (LINUX || APPLE)
79497949
u32 eax = 0, ebx = 0, ecx = 0, edx = 0;
79507950
__cpuid(0, eax, ebx, ecx, edx);
79517951
#endif
@@ -7955,9 +7955,9 @@ struct VM {
79557955
stopSpammer.store(true);
79567956
spammer.join();
79577957

7958-
#if defined(WINDOWS)
7958+
#if (WINDOWS)
79597959
SetThreadAffinityMask(GetCurrentThread(), oldAffinityMask);
7960-
#elif defined(LINUX)
7960+
#elif (LINUX)
79617961
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &oldCpuSet);
79627962
#endif
79637963

@@ -7972,7 +7972,7 @@ struct VM {
79727972
return true;
79737973
}
79747974

7975-
#if defined(WINDOWS)
7975+
#if (WINDOWS)
79767976
// --- 4. QPC Check ---
79777977
// Compare trapping vs non-trapping instruction timing
79787978
LARGE_INTEGER startQPC, endQPC;

0 commit comments

Comments
 (0)