aboutsummaryrefslogtreecommitdiff
path: root/alloc.inc
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2024-11-02 16:42:47 -0700
committerChristian Cunningham <cc@localhost>2024-11-02 16:42:47 -0700
commit39709266fcba445e267bdecf5f1c1a8f2112880a (patch)
treee1186d4e5a9743618df84b42a9e7005346500ffe /alloc.inc
parenta69a84ee6ef6d4a93167d5d096f28b8b40ed1b86 (diff)
Allocation functionalized
Diffstat (limited to 'alloc.inc')
-rw-r--r--alloc.inc22
1 files changed, 18 insertions, 4 deletions
diff --git a/alloc.inc b/alloc.inc
index 2412d08..d99dff7 100644
--- a/alloc.inc
+++ b/alloc.inc
@@ -4,22 +4,36 @@
%include "sys.inc"
%endif
-%macro alloc 0-1 rax
+_alloc:
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
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
- mov rax, SYS_MUNMAP
- syscall
+ %endif
+ call _free
%endm
%endif