aboutsummaryrefslogtreecommitdiff
path: root/alloc.inc
blob: d99dff739c3b974c10f667f393aea32abdd631a6 (plain)
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
%ifndef ALLOC_INC
%define ALLOC_INC
%ifndef SYS_INC
%include "sys.inc"
%endif

_alloc:
	xor	rdi,	rdi	; Let Kernel give Address
	mov	rdx,	3	; PROT_READ | PROT_WRITE
	mov	r10,	0x1002	; MAP_PRIVATE | MAP_ANONYMOUS
	xor	r8,	r8	; fd = -1, Not backed by a file
	xor	r9,	r9	; offset = 0
	mov	rax,	SYS_MMAP
	syscall
	ret

%macro	alloc	0-1	rax
	%if "%1" != "%rsi"
	mov	rsi,	%1	; Size to allocate
	%endif
	call	_alloc
%endm

_free:
	mov	rax,	SYS_MUNMAP
	syscall
	ret

%macro	free	1-2	rax
	%if "%1" != "%rdi"
	mov	rdi,	%1	; Address to free
	%endif
	%if "%1" != "%rsi"
	mov	rsi,	%2	; Size allocated
	%endif
	call _free
%endm

%endif