-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMemory_Realloc.asm
83 lines (75 loc) · 1.79 KB
/
Memory_Realloc.asm
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
78
79
80
81
82
;==============================================================================
;
; UASM64 Library
;
; https://github.com/mrfearless/UASM64-Library
;
;==============================================================================
.686
.MMX
.XMM
.x64
option casemap : none
IF @Platform EQ 1
option win64 : 11
ENDIF
option frame : auto
IF @Platform EQ 1 ; Win x64
GlobalReAlloc PROTO pMem:QWORD, dwBytes:QWORD, uFlags:DWORD
IFNDEF GMEM_MOVEABLE
GMEM_MOVEABLE EQU 0002h
ENDIF
IFNDEF GMEM_FIXED
GMEM_FIXED EQU 0000h
ENDIF
IFNDEF GMEM_ZEROINIT
GMEM_ZEROINIT EQU 0040h
ENDIF
includelib kernel32.lib
ENDIF
IF @Platform EQ 3 ; Linux x64
EXTERNDEF realloc: PROTO pMemoryAddress:QWORD, qwBytes:QWORD
ENDIF
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; Memory_Realloc
;
; Re-allocates memory, by resizing and moving an existing memory block that was
; previously allocated via the Memory_Alloc function.
;
; Parameters:
;
; * pMemSource - The address of memory previously allocated by Memory_Alloc
; which is now to be resized.
;
; * qwBytes - The new number of bytes to re-allocate.
;
; Returns:
;
; A pointer to the allocated memory, or 0 if an error occured.
;
; Notes:
;
; See Also:
;
; Memory_Alloc, Memory_Free
;
;------------------------------------------------------------------------------
Memory_Realloc PROC FRAME pMemSource:QWORD, qwBytes:QWORD
.IF pMemSource == 0
mov rax, 0
ret
.ENDIF
IF @Platform EQ 1 ; Win x64
Invoke GlobalReAlloc, pMemSource, qwBytes, GMEM_MOVEABLE or GMEM_ZEROINIT
ENDIF
IF @Platform EQ 3 ; Linux x64
mov rdi, pMemSource
mov rsi, qwBytes
call realloc
ENDIF
ret
Memory_Realloc ENDP
END