aboutsummaryrefslogtreecommitdiff
path: root/alloc.inc
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2024-07-13 21:31:54 -0700
committerChristian Cunningham <cc@localhost>2024-07-13 21:31:54 -0700
commit537b6c834b541b1f8f15f2ad31dcdc7f9d9a71a5 (patch)
tree11fead33d115c910fbeb1b5663cbeb2359ee4b19 /alloc.inc
parenta33f52d00496a7bed8e5b9bac533853a8733e209 (diff)
Basic Allocator
Diffstat (limited to 'alloc.inc')
-rw-r--r--alloc.inc25
1 files changed, 25 insertions, 0 deletions
diff --git a/alloc.inc b/alloc.inc
new file mode 100644
index 0000000..da27e1e
--- /dev/null
+++ b/alloc.inc
@@ -0,0 +1,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