mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +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:
parent
fe2bd8e3dd
commit
6bafbd64e2
Notes:
sideshowbarker
2024-07-17 06:41:51 +09:00
Author: https://github.com/supercomputer7
Commit: 6bafbd64e2
Pull-request: https://github.com/SerenityOS/serenity/pull/15107
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/FireFox317
Reviewed-by: https://github.com/kleinesfilmroellchen
Reviewed-by: https://github.com/linusg
1 changed files with 13 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue