File tree Expand file tree Collapse file tree 2 files changed +32
-9
lines changed Expand file tree Collapse file tree 2 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -3,17 +3,20 @@ include "core/stack.corth"
3
3
4
4
macro malloc:ARRAY-SIZE 0x4000 endmacro
5
5
macro malloc:AVAIL-STACK-SIZE 0x100 endmacro
6
- include "dynamic/malloc.corth"
7
6
include "dynamic/debug_malloc.corth"
8
7
8
+ memory index sizeof(int) end
9
+
9
10
proc allocate-space
10
11
int -> ptr
11
12
in let size in
12
- size malloc let object in
13
+ size index @64 malloc let object in
13
14
object mlength size != if
14
15
"[INFO] Size does not match.\n" puts
16
+ 1 exit drop
15
17
else
16
- "[INFO] Successfully allocated object.\n" puts
18
+ "[INFO] Successfully allocated object with index " puts index @64 puti ".\n" puts
19
+ index @inc64
17
20
end
18
21
19
22
STDOUT debug-dynamic-memory
@@ -24,10 +27,13 @@ end end
24
27
proc deallocate-space
25
28
ptr ->
26
29
in let container in
27
- container mfree if
28
- "[INFO] Successfully deallocated object.\n" puts
29
- else
30
- "[INFO] Could not deallocate object.\n" puts
30
+ container debug-malloc:get-tag let tag in
31
+ container mfree if
32
+ "[INFO] Successfully deallocated object with index " puts tag puti ".\n" puts
33
+ else
34
+ "[INFO] Could not deallocate object.\n" puts
35
+ 1 exit drop
36
+ end
31
37
end
32
38
33
39
STDOUT debug-dynamic-memory
@@ -37,6 +43,7 @@ proc main
37
43
int int -> int
38
44
in let argc argv in
39
45
malloc:init
46
+ 0 index !64
40
47
41
48
STDOUT debug-dynamic-memory
42
49
Original file line number Diff line number Diff line change 1
1
include "linux_x86/sys.corth"
2
2
include "linux_x86/io/output.corth"
3
- include "dynamic/malloc .corth"
3
+ include "dynamic/_malloc .corth"
4
4
5
5
6
6
// Can be used to debug malloc segments.
54
54
true end
55
55
56
56
57
- // Can bu used to see how much space is available and to check memory leaks.
57
+ // Can be used to check the space available and to check memory leaks.
58
58
proc get-available-dynamic-memory
59
59
-> int
60
60
in
68
68
sum @64
69
69
end
70
70
end
71
+
72
+ macro malloc:init malloc:_init endmacro
73
+
74
+ // This returns a shifted pointer.
75
+ // The created dynamicly-placed object contains debug tag information which is hidden from the user.
76
+ macro malloc let _size_ _debug_ in
77
+ size 8 + _malloc peek _obj_ in _obj_ isn-null if
78
+ _debug_ _obj_ !64
79
+ end end 8 +
80
+ end endmacro
81
+ macro mfree 8 - _mfree endmacro
82
+ macro mfree-deep _mfree-deep endmacro
83
+ macro mlength 8 - _mlength 8 - endmacro
84
+
85
+ macro debug-malloc:get-tag 8 - @64 endmacro
86
+ macro debug-malloc:set-tag 8 - !64 endmacro
You can’t perform that action at this time.
0 commit comments