diff options
author | Liav A <liavalb@gmail.com> | 2022-09-23 14:47:16 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-23 17:22:15 +0100 |
commit | 6bafbd64e23c51933a37c170dcba649df3fa3760 (patch) | |
tree | 0a09dea371c0f52f7fd7d2599553fa5ed262ff63 /Kernel/Memory | |
parent | fe2bd8e3ddcc833c39f0a7a8b52b6c2345a691a8 (diff) | |
download | serenity-6bafbd64e23c51933a37c170dcba649df3fa3760.zip |
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.
Diffstat (limited to 'Kernel/Memory')
-rw-r--r-- | Kernel/Memory/TypedMapping.h | 13 |
1 files changed, 13 insertions, 0 deletions
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 <AK/NonnullOwnPtr.h> #include <AK/StringView.h> +#include <AK/Try.h> #include <Kernel/Memory/MemoryManager.h> namespace Kernel::Memory { @@ -25,6 +27,17 @@ struct TypedMapping { }; 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) { TypedMapping<T> table; |