aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp49
-rw-r--r--arch/x86_64/include/arch/memory/heap/heap_allocator.hpp22
-rw-r--r--arch/x86_64/include/arch/memory/heap/memory_block.hpp1
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_entry.hpp3
4 files changed, 68 insertions, 7 deletions
diff --git a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp
index 1b1d964..6719bec 100644
--- a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp
@@ -5,24 +5,65 @@
namespace teachos::arch::memory::heap
{
+ /**
+ * @brief Possible types that should be constructed by the register_heap_allocator factory method.
+ * Creates the underlying heap allocator instance that is then used by all global allocations using new and delete
+ */
enum class heap_allocator_type : uint8_t
{
- NONE,
- BUMP,
- LINKED_LIST
+ NONE, ///< Don't use any heap allocation implementation, this will result in all calls of new and delte halting
+ ///< further execution of the kernel
+ BUMP, ///< Use the bump allocator as the heap allocation implementation, be aware that using this allocator leaks
+ ///< memory, because there is no delete implementation
+ LINKED_LIST ///< Use the linked list allocator as the heap implementation, recommended because it does not leak
+ ///< memory and
};
+ /**
+ * @brief Global instance of a heap allocator implementation created by the factory method pattern @see
+ * https://refactoring.guru/design-patterns/factory-method for more information.
+ *
+ * @note Can only be registered once and only once the kernel and the heap part of the kernel has been remapped
+ * successfully. If the instance is created before than the device will abort, because it acceses unmapped memory
+ * areas.
+ */
struct global_heap_allocator
{
+ /**
+ * @brief Registers the heap allocation implementation that should be used by the global heap allocator.
+ * Meaning all future calls to the global new or delete will be forwarded to the allocate and deallocate calls of
+ * the underlying heap allocation implementation
+ *
+ * @param new_type Type of the heap allocation implementation we want to instantiate
+ */
static auto register_heap_allocator(heap_allocator_type new_type) -> void;
+ /**
+ * @brief Allocates the given amount of memory and returns the pointer to the start of the allocatable memory area.
+ * Simply forwards the call to the allocate method of the registered heap_allocation implementation
+ *
+ * @param size Amount of bytes that should be allocated
+ * @return void* Pointer to the start of the allocatable memory area
+ */
static auto allocate(std::size_t size) -> void *;
+ /**
+ * @brief Deallocated the given amount of memory starting from the given pointer address.
+ * Simply forwards the call to the deallocate method of the registered heap_allocation implementation
+ *
+ * @param pointer Previously allocated memory area, that should now be freed
+ * @param size Size of the memory area we want to free
+ */
static auto deallocate(void * pointer, std::size_t size) -> void;
private:
- static heap_allocator * allocator_instance;
+ static heap_allocator * allocator_instance; ///< Instance used to actually allocate and deallocate
+ /**
+ * @brief Either returns the previously registered heap allocated or halts furthere execution
+ *
+ * @return Reference to the registered heap allocation
+ */
static auto get() -> heap_allocator &;
};
} // namespace teachos::arch::memory::heap
diff --git a/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp
index 62ba963..1519155 100644
--- a/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp
+++ b/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp
@@ -8,12 +8,34 @@ namespace teachos::arch::memory::heap
std::size_t constexpr HEAP_START = 0x100000000;
std::size_t constexpr HEAP_SIZE = 100 * 1024;
+ /**
+ * @brief Heap allocator interface containing methods required to allocate and deallocate heap memory areas
+ */
struct heap_allocator
{
+ /**
+ * @brief Virtual default destructor, created to ensure that if a pointer to this class is used and deleted, we will
+ * also call the derived base class destructor. Deleting a base class destructor that does not have a virtual
+ * destructor is undefined behaviour, because the derived class destructor originally instantiated with new is never
+ * called. This can cause potential memory leaks, because derived classes can not clean up their internal members as
+ * expected and instead simply leak them
+ */
virtual ~heap_allocator() {}
+ /**
+ * @brief Allocates the given amount of memory and returns the pointer to the start of the allocatable memory area
+ *
+ * @param size Amount of bytes that should be allocated
+ * @return void* Pointer to the start of the allocatable memory area
+ */
virtual auto allocate(std::size_t size) -> void * = 0;
+ /**
+ * @brief Deallocated the given amount of memory starting from the given pointer address
+ *
+ * @param pointer Previously allocated memory area, that should now be freed
+ * @param size Size of the memory area we want to free
+ */
virtual auto deallocate(void * pointer, std::size_t size) -> void = 0;
};
} // namespace teachos::arch::memory::heap
diff --git a/arch/x86_64/include/arch/memory/heap/memory_block.hpp b/arch/x86_64/include/arch/memory/heap/memory_block.hpp
index b9a2254..e1cd288 100644
--- a/arch/x86_64/include/arch/memory/heap/memory_block.hpp
+++ b/arch/x86_64/include/arch/memory/heap/memory_block.hpp
@@ -32,7 +32,6 @@ namespace teachos::arch::memory::heap
///< size variable and the pointer to the next hole.
memory_block * next; ///< Optional pointer to the next free memory, holds nullptr if there is none.
};
-
} // namespace teachos::arch::memory::heap
#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_MEMORY_BLOCK_HPP
diff --git a/arch/x86_64/include/arch/memory/paging/page_entry.hpp b/arch/x86_64/include/arch/memory/paging/page_entry.hpp
index 876ea3c..1de31b5 100644
--- a/arch/x86_64/include/arch/memory/paging/page_entry.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_entry.hpp
@@ -49,14 +49,13 @@ namespace teachos::arch::memory::paging
explicit entry(uint64_t flags);
/**
- * @brief Converts the given elf section flags into the corresponding correct entry flags.
+ * @brief Creates a new entry converting the given elf section flags into the corresponding correct entry flags.
*
* @note Enables us to set the correct flags on a entry depending on which elf section it is contained in. For
* example entries of .text sections should be executable and read only or entries of .data sections should be
* writable but not executable.
*
* @param elf_flags Elf section flags we want to convert into entry flags.
- * @return Entry that has the corresponding bit flags set.
*/
explicit entry(multiboot::elf_section_flags elf_flags);