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

%macro	alloc	1
	mov	rax,	SYS_MMAP
	xor	rdi,	rdi	; Let Kernel give Address
	mov	rsi,	%1	; Size to allocate
	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
	syscall
%endm

%macro	free	2
	mov	rax,	SYS_MUNMAP
	mov	rdi,	%1	; Address to free
	mov	rsi,	%2	; Size allocated
	syscall
%endm

%endif