-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.inc
53 lines (49 loc) · 1.16 KB
/
memory.inc
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
;s=`...`.split("\n")
;{const m=[],r=s=>m.splice(m.indexOf(s),1),f={"-":r,"*":r,"+":s=>m.push(s)};for(const l of s)f[l[0]]&&f[l[0]](l.substr(1));m}
macro malloc size* {
if DEBUGMEM
if size eqtype rax
save_inline size
cinvoke fprintf, [stdout], s_malloc, qword[rsp+20h+8]
cinvoke flushall
rest
else
cinvoke fprintf, [stdout], s_malloc, size
cinvoke flushall
end if
;int3
end if
cinvoke HeapAlloc,[_heap],HEAP_GENERATE_EXCEPTIONS,size
if DEBUGMEM
debx rax
end if
}
macro realloc ptr*, size* {
if DEBUGMEM
if size eqtype rax
save_inline size,ptr
cinvoke fprintf, [stdout], s_realloc, qword[rsp+20h] ;size left out
cinvoke flushall
rest
else
save_inline ptr
cinvoke fprintf, [stdout], s_realloc, qword[rsp+20h+8] ;size left out
cinvoke flushall
rest
end if
;int3
end if
cinvoke HeapReAlloc,[_heap],HEAP_GENERATE_EXCEPTIONS,ptr,size
if DEBUGMEM
debx rax
end if
}
macro mfree ptr {
if DEBUGMEM
save_inline ptr
cinvoke fprintf, [stdout], s_free, qword[rsp+20h+8]
cinvoke flushall
rest
end if
cinvoke HeapFree,[_heap],HEAP_GENERATE_EXCEPTIONS,ptr
}