diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-01 07:44:28 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2024-11-01 07:44:28 +0000 |
| commit | 98edc76893b2e22ccdbd81a4a3f1e1113c712cba (patch) | |
| tree | eaba60db849293aa83fb38e0c0ec3ba885616ecf /arch/x86_64 | |
| parent | dfb0ea2fd7525dd12addf295aef4d642e93ea22a (diff) | |
| download | teachos-98edc76893b2e22ccdbd81a4a3f1e1113c712cba.tar.xz teachos-98edc76893b2e22ccdbd81a4a3f1e1113c712cba.zip | |
Extract contract into seperate file and create tinyallocator constructor
Diffstat (limited to 'arch/x86_64')
5 files changed, 26 insertions, 10 deletions
diff --git a/arch/x86_64/include/arch/memory/allocator/area_frame_allocator.hpp b/arch/x86_64/include/arch/memory/allocator/area_frame_allocator.hpp index 6135184..4b6c2d4 100644 --- a/arch/x86_64/include/arch/memory/allocator/area_frame_allocator.hpp +++ b/arch/x86_64/include/arch/memory/allocator/area_frame_allocator.hpp @@ -8,12 +8,6 @@ namespace teachos::arch::memory::allocator { - template<typename T> - concept FrameAllocator = requires(T t, physical_frame a) { - { t.allocate_frame() } -> std::same_as<std::optional<physical_frame>>; - { t.deallocate_frame(a) } -> std::same_as<void>; - }; - /** * @brief Allocates memory using memory areas read from the multiboot2 information pointer. */ diff --git a/arch/x86_64/include/arch/memory/allocator/concept.hpp b/arch/x86_64/include/arch/memory/allocator/concept.hpp new file mode 100644 index 0000000..0aa45c6 --- /dev/null +++ b/arch/x86_64/include/arch/memory/allocator/concept.hpp @@ -0,0 +1,17 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_CONCEPT_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_CONCEPT_HPP + +#include "arch/memory/allocator/physical_frame.hpp" + +#include <optional> + +namespace teachos::arch::memory::allocator +{ + template<typename T> + concept FrameAllocator = requires(T t, physical_frame a) { + { t.allocate_frame() } -> std::same_as<std::optional<physical_frame>>; + { t.deallocate_frame(a) } -> std::same_as<void>; + }; +} // namespace teachos::arch::memory::allocator + +#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_CONCEPT_HPP diff --git a/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp b/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp index 70c7de6..a028e30 100644 --- a/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp +++ b/arch/x86_64/include/arch/memory/allocator/tiny_frame_allocator.hpp @@ -1,10 +1,10 @@ #ifndef TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_TINY_FRAME_ALLOCATOR_HPP #define TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_TINY_FRAME_ALLOCATOR_HPP +#include "arch/memory/allocator/concept.hpp" #include "arch/memory/allocator/physical_frame.hpp" #include <array> -#include <optional> namespace teachos::arch::memory::allocator { @@ -16,7 +16,12 @@ namespace teachos::arch::memory::allocator /** * @brief Defaulted constructor. */ - tiny_frame_allocator() = default; + template<FrameAllocator T> + tiny_frame_allocator(T & allocator) + : frames{allocator.allocate_frame(), allocator.allocate_frame(), allocator.allocate_frame()} + { + // Nothing to do + } /** * @brief Allocate memory by finding and returning one of the three free physical frames. diff --git a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp index a9f8eb8..26b8171 100644 --- a/arch/x86_64/include/arch/memory/paging/page_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_mapper.hpp @@ -2,7 +2,7 @@ #define TEACHOS_ARCH_X86_64_MEMORY_PAGING_PAGE_MAPPER_HPP #include "arch/exception_handling/assert.hpp" -#include "arch/memory/allocator/area_frame_allocator.hpp" +#include "arch/memory/allocator/concept.hpp" #include "arch/memory/paging/virtual_page.hpp" #include <algorithm> diff --git a/arch/x86_64/include/arch/memory/paging/page_table.hpp b/arch/x86_64/include/arch/memory/paging/page_table.hpp index 31fb58c..b9ea44b 100644 --- a/arch/x86_64/include/arch/memory/paging/page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp @@ -2,7 +2,7 @@ #define TEACHOS_ARCH_X86_64_MEMORY_PAGING_PAGE_TABLE_HPP #include "arch/exception_handling/assert.hpp" -#include "arch/memory/allocator/area_frame_allocator.hpp" +#include "arch/memory/allocator/concept.hpp" #include "arch/memory/paging/page_entry.hpp" namespace teachos::arch::memory::paging |
