-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_traverser.c
73 lines (60 loc) · 1.88 KB
/
stack_traverser.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
#include "stack_traverser.h"
#include <string.h>
#define Dump_registers() \
jmp_buf env; \
if (setjmp(env)) abort(); \
extern void **environ;
void *get_stack_top() {
int top_of_stack;
return &top_of_stack;
}
ll_head get_alive_stack_pointers(heap_t *h) {
return get_alive_stack_pointers_in_range(h, get_stack_top(), environ);
}
ll_head get_alive_stack_address_pointers(heap_t *h) {
return get_alive_stack_address_pointers_in_range(h, get_stack_top(), environ);
}
ll_head get_alive_stack_pointers_in_range(heap_t *h, void *top, void *bottom) {
Dump_registers();
ll_node **root = LL_initRoot();
if (top > bottom) {
while (top > bottom) {
void **content = top;
if (validate_object(*content, h)) { // checks the pointers metadata to check whether it's pointing at an object or not
LL_createAndInsertSequentially(root, *content);
}
--top;
}
} else {
while (top < bottom) {
void **content = top;
if (validate_object(*content, h)) { // checks the pointers metadata to check whether it's pointing at an object or not
LL_createAndInsertSequentially(root, *content);
}
++top;
}
}
return root;
}
ll_head get_alive_stack_address_pointers_in_range(heap_t *h, void *top, void *bottom) {
Dump_registers();
ll_node **root = LL_initRoot();
if (top > bottom) {
while (top > bottom) {
void **content = top;
if (validate_object(*content, h)) { // checks the pointers metadata to check whether it's pointing at an object or not
LL_createAndInsertSequentially(root, content);
}
--top;
}
} else {
while (top < bottom) {
void **content = top;
if (validate_object(*content, h)) { // checks the pointers metadata to check whether it's pointing at an object or not
LL_createAndInsertSequentially(root, content);
}
++top;
}
}
return root;
}