diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-24 13:51:12 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-24 13:51:12 +0000 |
| commit | c291e1ed629489c418049f6c4116433636717636 (patch) | |
| tree | aee0889f0d52ee51ada62ee992ee0b9682f78774 /arch/x86_64/include | |
| parent | 47732f54474a083e9f98e52714c12c0ca1181174 (diff) | |
| download | teachos-c291e1ed629489c418049f6c4116433636717636.tar.xz teachos-c291e1ed629489c418049f6c4116433636717636.zip | |
Add comments and rename file
Diffstat (limited to 'arch/x86_64/include')
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/allocator.hpp | 46 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/bump_allocator.hpp | 53 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/concept.hpp | 7 |
3 files changed, 58 insertions, 48 deletions
diff --git a/arch/x86_64/include/arch/memory/heap/allocator.hpp b/arch/x86_64/include/arch/memory/heap/allocator.hpp deleted file mode 100644 index 6f7535e..0000000 --- a/arch/x86_64/include/arch/memory/heap/allocator.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_ALLOCATOR_HPP -#define TEACHOS_ARCH_X86_64_MEMORY_HEAP_ALLOCATOR_HPP - -#include <cstdint> - -namespace teachos::arch::memory::heap -{ - std::size_t constexpr HEAP_START = 0x4000'0000; - std::size_t constexpr HEAP_SIZE = 100 * 1024; - - /** - * @brief Simple heap allocator - */ - struct bump_allocator - { - bump_allocator(std::size_t heap_start, std::size_t heap_end) - : heap_start{heap_start} - , heap_end{heap_end} - , next{heap_start} - { - } - - /** - * @brief Allocates the specified amount of memory in the heap - * - * @param size Amount of memory to allocate - * @return Address of the allocated memory - */ - auto allocate(std::size_t size) -> void *; - - /** - * @brief Deallocates heap memory at the specified location - * - * @param pointer Pointer to the location which should be deallocated - */ - auto deallocate(uint8_t * pointer) -> void; - - private: - std::size_t heap_start; - std::size_t heap_end; - std::size_t next; - }; - -} // namespace teachos::arch::memory::heap - -#endif
\ No newline at end of file diff --git a/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp b/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp new file mode 100644 index 0000000..5b581ba --- /dev/null +++ b/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp @@ -0,0 +1,53 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_BUMP_ALLOCATOR_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_HEAP_BUMP_ALLOCATOR_HPP + +#include <cstdint> + +namespace teachos::arch::memory::heap +{ + /** + * @brief Simple heap allocator, which leaks all allocated memory, because it does not really deallocate anything. + */ + struct bump_allocator + { + /** + * @brief Constructor. + * + * @param heap_start Start of the allocatable heap area + * @param heap_end End of the allocatable heap area (Start + Size) + */ + bump_allocator(std::size_t heap_start, std::size_t heap_end) + : heap_start{heap_start} + , heap_end{heap_end} + , next{heap_start} + { + // Nothing to do + } + + /** + * @brief Allocates the specified amount of memory in the heap. + * + * @param size Amount of memory to allocate. + * @return Address of the first byte to the allocated area + */ + auto allocate(std::size_t size) -> void *; + + /** + * @brief Deallocates heap memory at the specified location. + * + * @note Simply does nothing, because this allocator leaks all memory. + * + * @param pointer Pointer to the location which should be deallocated. + * @param size Size of the underlying memory area we want to deallocate. + */ + auto deallocate(uint8_t * pointer, std::size_t size) -> void; + + private: + std::size_t heap_start; ///< Start of the allocatable heap area + std::size_t heap_end; ///< End of the allocatable heap area + std::size_t next; ///< Current address, which is the start of still unused allocatable heap area + }; + +} // namespace teachos::arch::memory::heap + +#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_BUMP_ALLOCATOR_HPP diff --git a/arch/x86_64/include/arch/memory/heap/concept.hpp b/arch/x86_64/include/arch/memory/heap/concept.hpp index a525b0b..8c8c887 100644 --- a/arch/x86_64/include/arch/memory/heap/concept.hpp +++ b/arch/x86_64/include/arch/memory/heap/concept.hpp @@ -1,10 +1,13 @@ #ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP #define TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP -#include <cstdint> +#include <concepts> namespace teachos::arch::memory::heap { + std::size_t constexpr HEAP_START = 0x4000'0000; + std::size_t constexpr HEAP_SIZE = 100 * 1024; + template<typename T> concept HeapAllocator = requires(T t, uint8_t * pointer, std::size_t size) { { t.allocate(size) } -> std::same_as<uint8_t *>; @@ -12,4 +15,4 @@ namespace teachos::arch::memory::heap }; } // namespace teachos::arch::memory::heap -#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP
\ No newline at end of file +#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP |
