From 6bafbd64e23c51933a37c170dcba649df3fa3760 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 23 Sep 2022 14:47:16 +0300 Subject: [PATCH] Kernel/Memory: Introduce a method to allocate TypedMapping on the heap This will be used later on to allocate such structure on the heap when it is necessary to do so. --- Kernel/Memory/TypedMapping.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Kernel/Memory/TypedMapping.h b/Kernel/Memory/TypedMapping.h index f1dd584aef..033d346473 100644 --- a/Kernel/Memory/TypedMapping.h +++ b/Kernel/Memory/TypedMapping.h @@ -6,7 +6,9 @@ #pragma once +#include #include +#include #include namespace Kernel::Memory { @@ -24,6 +26,17 @@ struct TypedMapping { size_t offset { 0 }; }; +template +static ErrorOr>> adopt_new_nonnull_own_typed_mapping(PhysicalAddress paddr, size_t length, Region::Access access = Region::Access::Read) +{ + auto mapping_length = TRY(page_round_up(paddr.offset_in_page() + length)); + auto region = TRY(MM.allocate_kernel_region(paddr.page_base(), mapping_length, {}, access)); + auto table = TRY(adopt_nonnull_own_or_enomem(new (nothrow) Memory::TypedMapping())); + table->region = move(region); + table->offset = paddr.offset_in_page(); + return table; +} + template static ErrorOr> map_typed(PhysicalAddress paddr, size_t length, Region::Access access = Region::Access::Read) {