aboutsummaryrefslogtreecommitdiff
path: root/src/allocator.h
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-20 16:24:14 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-20 16:24:14 +0200
commit12302df8b3f59de46f9f20ecae57ccf874d0c867 (patch)
treec89f806227442014911ddb8e424bbc6248974b11 /src/allocator.h
parentAdd quicksort implementation to stdlib (diff)
downloadkernel.cpp-12302df8b3f59de46f9f20ecae57ccf874d0c867.tar.xz
Add allocator
Diffstat (limited to 'src/allocator.h')
-rw-r--r--src/allocator.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/allocator.h b/src/allocator.h
new file mode 100644
index 0000000..8a12be8
--- /dev/null
+++ b/src/allocator.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <types.h>
+
+class MemoryAllocator {
+public:
+ MemoryAllocator(uint32_t start, size_t size);
+
+ void* malloc(size_t size);
+ void free(void* ptr);
+
+ size_t free_space() const;
+ size_t used_space() const;
+
+private:
+ struct MemoryChunk {
+ MemoryChunk* prev = nullptr;
+ MemoryChunk* next = nullptr;
+ bool allocated = false;
+ size_t size = 0;
+ };
+ MemoryChunk* begin;
+};
+
+namespace std {
+struct nothrow_t {
+ explicit nothrow_t() = default;
+};
+}; // namespace std
+
+void* operator new(unsigned, const std::nothrow_t&) noexcept;
+void* operator new[](unsigned, const std::nothrow_t&) noexcept;
+
+void operator delete(void* ptr);
+void operator delete[](void* ptr);
+
+// placement new
+void* operator new(unsigned, void*);
+void* operator new[](unsigned, void*);