aboutsummaryrefslogtreecommitdiff
path: root/src/lib/include/user_region.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/include/user_region.h')
-rw-r--r--src/lib/include/user_region.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/include/user_region.h b/src/lib/include/user_region.h
new file mode 100644
index 0000000..8a4c490
--- /dev/null
+++ b/src/lib/include/user_region.h
@@ -0,0 +1,34 @@
+#pragma once
+
+// User virtual memory region allocator
+
+// This is entirely thread-safe
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#include <syscall.h>
+
+#define PAGE_SIZE 0x1000
+#define PAGE_MASK 0xFFFFF000
+#define PAGE_ALIGN_DOWN(x) (((size_t)x) & PAGE_MASK)
+#define PAGE_ALIGN_UP(x) ((((size_t)x)&(~PAGE_MASK)) == 0 ? ((size_t)x) : (((size_t)x) & PAGE_MASK) + PAGE_SIZE)
+
+struct region_info;
+
+typedef struct region_info {
+ void* addr;
+ size_t size;
+ char* type;
+} region_info_t;
+
+void region_allocator_init(void* begin, void* end);
+
+void* region_alloc(size_t size, char* type); // returns 0 on error
+region_info_t *find_region(void* addr);
+void region_free(void* addr);
+
+void dbg_print_region_info();
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/