From 1071297ee44d5102feb92b7a5d5ceb44e90622b7 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 14 Nov 2026 17:20:53 +0100 Subject: memory: improve MMIO allocation/mapping robustness --- kapi/kapi/memory.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'kapi') diff --git a/kapi/kapi/memory.hpp b/kapi/kapi/memory.hpp index 2ae8b91b..4cdd6ac1 100644 --- a/kapi/kapi/memory.hpp +++ b/kapi/kapi/memory.hpp @@ -10,6 +10,7 @@ #include // IWYU pragma: export #include +#include #include #include @@ -94,8 +95,10 @@ namespace kapi::memory //! Allocate a Memory-mapped I/O region of the given size. //! //! @warning This function will panic if the MMIO system has not been initialized! + //! //! @param page_count The number of pages to allocate. - auto allocate_mmio_region(std::size_t page_count) -> mmio_region; + //! @return The newly allocated MMIO region on success, an error otherwise. + auto allocate_mmio_region(std::size_t page_count) -> kstd::result; //! Map a region of Memory-mapped I/O address space to a given hardware address using the given flags. //! @@ -107,10 +110,15 @@ namespace kapi::memory //! @param region The region to map. //! @param hw_base The base of the hardware region. //! @param flags The flags to apply. + //! @return A result containing a pointer to the first byte of the mapped region on success, an error otherwise, in + //! which case any partial mappings have been rolled back. auto map_mmio_region(mmio_region region, physical_address hw_base, page_mapper::flags flags = {}) - -> kstd::observer_ptr; + -> kstd::result>; - //! Release a Memory-mapped I/O region. + //! Release (unmap and free) a Memory-mapped I/O region. + //! + //! This function is tolerant of partially mapped regions and will unmap any mapped pages within the region before + //! releasing the MMIO region. //! //! @warning This function will panic if the MMIO system has not been initialized! //! @param region The region to release. -- cgit v1.2.3