forked from MaximeCheramy/MICA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mica_utils.cpp
72 lines (61 loc) · 1.45 KB
/
mica_utils.cpp
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
/*
* This file is part of MICA, a Pin tool to collect
* microarchitecture-independent program characteristics using the Pin
* instrumentation framework.
*
* Please see the README.txt file distributed with the MICA release for more
* information.
*/
/* MICA includes */
#include "mica_utils.h"
/* lookup memNode for key in table
* returns NULL is no such memNode is found
*/
memNode* lookup(nlist** table, ADDRINT key){
nlist* np;
for (np = table[key % MAX_MEM_TABLE_ENTRIES]; np != (nlist*)NULL; np = np->next){
if(np-> id == key)
return np->mem;
}
return (memNode*)NULL;
}
/* install new memNode in table */
memNode* install(nlist** table, ADDRINT key){
nlist* np;
ADDRINT index;
index = key % MAX_MEM_TABLE_ENTRIES;
np = table[index];
if(np == (nlist*)NULL) {
np = (nlist*)checked_malloc(sizeof(nlist));
table[index] = np;
}
else{
while(np->next != (nlist*)NULL){
np = np->next;
}
np->next = (nlist*)checked_malloc(sizeof(nlist));
np = np->next;
}
np->next = (nlist*)NULL;
np->id = key;
np->mem = (memNode*)checked_malloc(sizeof(memNode));
for(ADDRINT i = 0; i < MAX_MEM_ENTRIES; i++){
(np->mem)->timeAvailable[i] = 0;
}
for(ADDRINT i = 0; i < MAX_MEM_BLOCK; i++){
(np->mem)->numReferenced[i] = false;
}
return (np->mem);
}
/**
* Free a nlist and set the pointer to NULL.
*/
void free_nlist(nlist*& np) {
nlist* np_rm;
while(np != (nlist*)NULL){
np_rm = np;
np = np->next;
free(np_rm->mem);
free(np_rm);
}
}