-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathneschecklib.c
70 lines (62 loc) · 1.9 KB
/
neschecklib.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
#include <stdio.h>
#include <stdlib.h>
extern unsigned int TOS_NODE_ID;
unsigned long checksexecuted = 0;
// #define IS_DEBUGGING 1
struct metadata_table_entry {
long ptr;
long size;
};
long metadatatablecount = 0;
struct metadata_table_entry** metadatatable = NULL;
// TODO: replace with the other BST efficient implementation.
struct metadata_table_entry* findMetadataTableEntry(long p) {
struct metadata_table_entry* entry = NULL;
int i;
for (i = 0; i < metadatatablecount; i++) {
if (metadatatable[i]->ptr == p) {
entry = metadatatable[i];
break;
}
}
return entry;
}
void setMetadataTableEntry(long p, long size, long addr) {
struct metadata_table_entry* entry = findMetadataTableEntry(p);
if (entry == NULL) { // not found, create it
#ifdef IS_DEBUGGING
printf("[%p] Creating entry for %p, size = %ld\n", (void*)addr, (void*)p, size);
#endif
entry = malloc(sizeof(struct metadata_table_entry));
entry->ptr = p;
entry->size = size;
metadatatablecount++;
metadatatable = realloc(metadatatable, metadatatablecount * sizeof(struct metadata_table_entry *));
metadatatable[metadatatablecount - 1] = entry;
}
entry->size = size;
}
long lookupMetadataTableEntry(long p) {
struct metadata_table_entry* entry = findMetadataTableEntry(p);
if (entry == NULL) {
#ifdef IS_DEBUGGING
printf("\tNot found %p\n", (void*)p);
#endif
return 0;
} else {
#ifdef IS_DEBUGGING
printf("\tFound %p, size = %ld\n", (void*)p, entry->size);
#endif
return entry->size;
}
}
void printErrorLine(long l) {
printf("Memory error near line %ld.\n", l);
}
void printCheck(/*long l, long r*/) {
#ifdef IS_DEBUGGING
// disable this or the output will be GigaBytes big for real programs!
// if (l < r) printf("%ld <= %ld ?\n", r, l);
printf("?");
#endif
}