1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

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.
This commit is contained in:
Liav A 2022-09-23 14:47:16 +03:00 committed by Linus Groh
parent fe2bd8e3dd
commit 6bafbd64e2

View file

@ -6,7 +6,9 @@
#pragma once
#include <AK/NonnullOwnPtr.h>
#include <AK/StringView.h>
#include <AK/Try.h>
#include <Kernel/Memory/MemoryManager.h>
namespace Kernel::Memory {
@ -24,6 +26,17 @@ struct TypedMapping {
size_t offset { 0 };
};
template<typename T>
static ErrorOr<NonnullOwnPtr<TypedMapping<T>>> 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<T>()));
table->region = move(region);
table->offset = paddr.offset_in_page();
return table;
}
template<typename T>
static ErrorOr<TypedMapping<T>> map_typed(PhysicalAddress paddr, size_t length, Region::Access access = Region::Access::Read)
{