Commit d0f51525 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Remove util.c

parent 752826ee
Showing with 19 additions and 7 deletions
+19 -7
......@@ -3,10 +3,7 @@ CFLAGS = -Iinclude -Wall -Wextra -O3 -g
all: bin/cache_timing bin/index_guesser bin/recover_local_secret bin/recover_protected_local_secret bin/exploit
bin/%.o: lib/%.c
$(CC) $(CFLAGS) -c $^ -o $@
bin/%: src/%.c bin/util.o include/%.h
bin/%: src/%.c include/%.h
$(CC) $(CFLAGS) $(filter-out %.h,$^) -o $@
clean:
......
......@@ -2,6 +2,7 @@
#define _UTIL_H
#include <inttypes.h>
#include <x86intrin.h>
#define PAGE_SIZE 4096
......@@ -19,13 +20,28 @@ inline void force_read(const void *address) {
* Evicts any cache line currently storing the given address.
* This ensures that the byte at the address is no longer in the cache.
*/
void flush_cache_line(const void *address);
void flush_cache_line(const void *address) {
_mm_clflush(address);
_mm_mfence();
for (volatile int i = 0; i < 10000; i++) {
}
}
/**
* Counts the number of processor clocks elapsed when reading a byte at the given address.
* Note that the number of clocks can be quite large
* if the process happens to be interrupted in this function.
*/
uint64_t time_read(const void *address);
uint64_t time_read(const void *address) {
uint64_t start = __rdtsc();
_mm_lfence();
force_read(address);
_mm_mfence();
_mm_lfence();
uint64_t result = __rdtsc() - start;
_mm_mfence();
_mm_lfence();
return result;
}
#endif /* _UTIL_H */
......@@ -15,5 +15,4 @@
*/
int main() {
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment