From 8b4e129fc167f2a666ecd73b2bea3374ece2f849 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 4 Nov 2023 18:13:16 +0200 Subject: [PATCH] Kernel: Add better APIs for fast page --- kernel/include/kernel/Memory/PageTable.h | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/kernel/include/kernel/Memory/PageTable.h b/kernel/include/kernel/Memory/PageTable.h index 705853bac1..96c527a927 100644 --- a/kernel/include/kernel/Memory/PageTable.h +++ b/kernel/include/kernel/Memory/PageTable.h @@ -1,12 +1,20 @@ #pragma once #include +#include +#include #include #include namespace Kernel { + template + concept with_fast_page_callback = requires(F func) + { + requires BAN::is_same_v; + }; + class PageTable { public: @@ -33,6 +41,15 @@ namespace Kernel static void unmap_fast_page(); static constexpr vaddr_t fast_page() { return KERNEL_OFFSET; } + template + static void with_fast_page(paddr_t paddr, F callback) + { + CriticalScope _; + map_fast_page(paddr); + callback(); + unmap_fast_page(); + } + // FIXME: implement sized checks, return span, etc static void* fast_page_as_ptr(size_t offset = 0) { @@ -47,6 +64,14 @@ namespace Kernel return *reinterpret_cast(fast_page() + offset); } + // Retrieves index'th element from fast_page + template + static T& fast_page_as_sized(size_t index) + { + ASSERT((index + 1) * sizeof(T) <= PAGE_SIZE); + return *reinterpret_cast(fast_page() + index * sizeof(T)); + } + static bool is_valid_pointer(uintptr_t); static BAN::ErrorOr create_userspace();