aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/include/kapi/memory.hpp9
-rw-r--r--kapi/include/kapi/memory/frame_allocator.hpp24
2 files changed, 31 insertions, 2 deletions
diff --git a/kapi/include/kapi/memory.hpp b/kapi/include/kapi/memory.hpp
index da666da..c2e9df8 100644
--- a/kapi/include/kapi/memory.hpp
+++ b/kapi/include/kapi/memory.hpp
@@ -10,6 +10,7 @@
#include <cstddef>
#include <optional>
+#include <utility>
namespace teachos::memory
{
@@ -46,6 +47,14 @@ namespace teachos::memory
auto allocate_frame() -> std::optional<frame>;
//! @qualifier kernel-defined
+ //! Allocate multiple new frames of physical memory
+ //!
+ //! @warning This function will panic if no frame allocator has been registered.
+ //!
+ //! @return An engaged std::optional iff. @p count frames could be allocated, std::nullopt otherwise.
+ auto allocate_many_frames(std::size_t count) -> std::optional<std::pair<frame, std::size_t>>;
+
+ //! @qualifier kernel-defined
//! Map a page onto a frame.
//!
//! @warning This function will panic if no page mapper has been registered, or the page has already been mapped.
diff --git a/kapi/include/kapi/memory/frame_allocator.hpp b/kapi/include/kapi/memory/frame_allocator.hpp
index fb6bc0d..8532a45 100644
--- a/kapi/include/kapi/memory/frame_allocator.hpp
+++ b/kapi/include/kapi/memory/frame_allocator.hpp
@@ -5,7 +5,9 @@
#include "kapi/memory/frame.hpp"
+#include <cstddef>
#include <optional>
+#include <utility>
namespace teachos::memory
{
@@ -27,12 +29,30 @@ namespace teachos::memory
//! Allocate a frame of physical memory.
//!
//! @return An engaged std::optional iff. a new frame could be allocated, std::nullopt otherwise.
- virtual auto allocate() noexcept -> std::optional<frame> = 0;
+ virtual auto allocate() noexcept -> std::optional<frame>
+ {
+ return allocate_many(1).transform([](auto result) { return result.first; });
+ }
+
+ //! Allocate multiple consecutive frames of physical memory.
+ //!
+ //! @param count The number of frames to allocate
+ //! @return an engaged optional iff. a block of consecutive frames could be allocated, std::nullopt otherwise.
+ virtual auto allocate_many(std::size_t count) noexcept -> std::optional<std::pair<frame, std::size_t>> = 0;
//! Release a frame of physical memory.
//!
//! @param frame A frame of physical memory, previously acquired by a call to the #allocate function.
- virtual auto release(frame frame) -> void = 0;
+ virtual auto release(frame frame) -> void
+ {
+ return release_many({frame, 1});
+ }
+
+ //! Release a frame of physical memory.
+ //!
+ //! @param frame_set A set of frames of physical memory, previously acquired by a call to the #allocate_many
+ //! function.
+ virtual auto release_many(std::pair<frame, std::size_t> frame_set) -> void = 0;
protected:
frame_allocator() = default;