-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
74 lines (58 loc) · 2.04 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sched.h>
#include <getopt.h>
#include <assert.h>
#define ASSERT(x) assert(x != -1)
#include "../utils/configuration.h"
#include "../utils/memory_utils.h"
#include "settings.h"
#include "../utils/misc_utils.h"
////////////////////////////////////////////////////////////////////////////////
// Memory Allocations
uint64_t *shared_mem;
uint64_t *evict_mem;
uint64_t evset[EV_LLC]; // To easily share the EV set with the helper
volatile uint64_t *synchronization;
volatile uint64_t *synchronization_params;
////////////////////////////////////////////////////////////////////////////////
// Function declarations
void attacker();
void attacker_helper();
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
//////////////////////////////////////////////////////////////////////////////
// Memory allocations
// `shared_mem` is for addresses that the attacker and victim will share.
// `synchronization*` are variables for communication between threads.
ASSERT(mem_map_shared(&shared_mem, SHARED_MEM_SIZE, HUGE_PAGES_AVAILABLE));
ASSERT(mem_map_shared(&evict_mem, EVICT_LLC_SIZE, HUGE_PAGES_AVAILABLE));
ASSERT(var_map_shared(&synchronization));
ASSERT(var_map_shared(&synchronization_params));
*shared_mem = 1;
*synchronization = 0;
//////////////////////////////////////////////////////////////////////////////
// Start the threads
//if (fork() == 0) {
//set_core(HELPER_CORE, "Helper ");
//attacker_helper();
//return 0;
//}
set_core(ATTACKER_CORE, "Attacker");
attacker();
//////////////////////////////////////////////////////////////////////////////
// Memory de-allocations
ASSERT(munmap(shared_mem, SHARED_MEM_SIZE));
ASSERT(munmap(evict_mem, EVICT_LLC_SIZE));
ASSERT(var_unmap(synchronization));
ASSERT(var_unmap(synchronization_params));
return 0;
}