-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpattern_manager.c
More file actions
78 lines (67 loc) · 1.32 KB
/
Copy pathpattern_manager.c
File metadata and controls
78 lines (67 loc) · 1.32 KB
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
75
76
77
static void touch_simple(char *addr)
{
/* Notice the function reads and then writes*/
if(*addr != 0xf) {
*addr = 0xf;
}
else {
*addr = 0x00;
}
}
/*
* For FIX to work we need a static structure
* that book keeps the same element within
* the addr range.
*
* Following is a simple disjoint linear list that
* keeps track of the previous access point.
* TODO: Make it a self balancing tree eg: AVL.
*/
typedef struct __fix_bookeeper_node {
char *addr;
lt_t loc;
}fix_bk_node;
typedef struct __fix_bookeeper {
fix_bk_node node;
struct __fix_bookeeper *nxt;
}fix_bookeeper;
static fix_bookeeper *fix_head = NULL;
static fix_bk_node* fix_exists(char *const addr)
{
fix_bookeeper *iter = fix_head;
while(iter) {
if(addr == iter->node.addr)
break;
iter = iter->nxt;
}
if(iter) {
return &(iter->node);
}
return NULL;
}
static fix_bk_node* fix_alloc_node(char *addr)
{
fix_bookeeper *b = malloc(sizeof(*b));
if(b) {
b->node.addr = addr;
b->node.loc = 0;
b->nxt = fix_head;
fix_head = b;
}
return &(b->node);
}
void pattern_fix(char *addr1, lt_t len)
{
char *addr = (char*)addr1;
fix_bk_node *node;
if(!addr || !len) {
PR_ERROR("%s: addr: %p len: %lld\n", addr, len);
goto fin;
}
if(!(node = fix_exists(addr))) {
node = fix_alloc_node(addr)
}
touch_simple(node->addr);
fin:
return;
}