aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-11-13 11:40:07 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-11-22 14:20:35 +0100
commit60ba364ec3c458b6bcf3d048781c8dd88937cd0e (patch)
treee1496703981b5f64d396e2b11c5c914c3124ff62 /kapi
parent32a0bc18a741f5599e6447add4cd69a6e25a31be (diff)
downloadkernel-60ba364ec3c458b6bcf3d048781c8dd88937cd0e.tar.xz
kernel-60ba364ec3c458b6bcf3d048781c8dd88937cd0e.zip
kapi/memory: fix page unmap logic
Previously, the page mapper was expected to automatically free all frames that had become unused. However, this only works if all mappings refer to plain memory frames. In the case of MMIO frames, the mapper would still try to release the frame via the global frame allocator, which is incorrect, leading to undefined behavior in the worst case. This problem was discovered during work the PCI/PCIe subsystem, since we want to unmap any unused buses during enumeration.
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/memory.hpp3
-rw-r--r--kapi/kapi/memory/page_mapper.hpp8
2 files changed, 7 insertions, 4 deletions
diff --git a/kapi/kapi/memory.hpp b/kapi/kapi/memory.hpp
index 4b14b553..2ae8b91b 100644
--- a/kapi/kapi/memory.hpp
+++ b/kapi/kapi/memory.hpp
@@ -82,7 +82,8 @@ namespace kapi::memory
//! @warning This function will panic if no page mapper has been registered, or the page is not mapped.
//!
//! @param page The page to unmap
- auto unmap(page page) -> void;
+ //! @return The frame the page was previously mapped to.
+ [[nodiscard]] auto unmap(page page) -> frame;
//! Initialize the Memory-mapped I/O region system.
//!
diff --git a/kapi/kapi/memory/page_mapper.hpp b/kapi/kapi/memory/page_mapper.hpp
index 5ac0210f..4a4827b6 100644
--- a/kapi/kapi/memory/page_mapper.hpp
+++ b/kapi/kapi/memory/page_mapper.hpp
@@ -11,6 +11,7 @@
#include <cstddef>
#include <cstdint>
+#include <optional>
#include <type_traits>
namespace kapi::memory
@@ -54,13 +55,14 @@ namespace kapi::memory
//! terminate execution via a kernel panic.
//!
//! @param page The page to unmap.
- virtual auto unmap(page page) -> void = 0;
+ //! @return The frame the page was previously mapped to.
+ virtual auto unmap(page page) -> frame = 0;
//! Try to unmap the given page.
//!
//! @param page The page to unmap
- //! @return true iff. the page was successfully unmapped, false otherwise.
- virtual auto try_unmap(page page) noexcept -> bool = 0;
+ //! @return The frame that was previously mapped to the page, if any.
+ virtual auto try_unmap(page page) noexcept -> std::optional<frame> = 0;
//! @qualifier kernel-defined
//! Map a page into a given frame, applyint the given flags.