-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMM.ASM
More file actions
56 lines (46 loc) · 1.14 KB
/
MM.ASM
File metadata and controls
56 lines (46 loc) · 1.14 KB
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
IDEAL
P386
MODEL FLAT, C
ASSUME cs:_TEXT,ds:FLAT,es:FLAT,fs:FLAT,gs:FLAT
include "mm.inc"
CODESEG
proc mm_init
mov [mm_start_addr], 0400000h ;; load the memory manager at 4mb
ret
endp mm_init
ifdef NASM
extern malloc
endif
proc alloc
arg @@size:dword
uses ebx
ifndef NASM
mov eax, [mm_start_addr]
mov ebx, [@@size]
add [mm_start_addr], ebx
else
;; Allocate a little more memory
;; I wanted to use the linux brk syscall but it is giving me a hard time
;; so i'm going to be lazy and link in malloc. This is safer anyway.
;; linux uses a different calling convention so we need to save ALL the
;; registers we are using. And since this includes all the registers
;; functions in our backtrace are using as well, we will simply
;; push and pop all regs (except eax and ebx since we are already
;; returning/saving them)
push ecx
push edx
push edi
push esi
call malloc, [@@size]
pop esi
pop edi
pop edx
pop ecx
endif
ret
endp alloc
;; Since we use a single allocation memory manager. A free function is not yet
;; necessary.
DATASEG
mm_start_addr dd 0
END