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) {