mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00

Instead of first allocating the VM range, and then inserting a region with that range into the MM region tree, we now do both things in a single atomic operation: - RegionTree::place_anywhere(Region&, size, alignment) - RegionTree::place_specifically(Region&, address, size) To reduce the number of things we do while locking the region tree, we also require callers to provide a constructed Region object.
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/IntrusiveRedBlackTree.h>
|
|
#include <Kernel/Locking/Spinlock.h>
|
|
#include <Kernel/Memory/Region.h>
|
|
#include <Kernel/Memory/VirtualRange.h>
|
|
#include <Kernel/VirtualAddress.h>
|
|
|
|
namespace Kernel::Memory {
|
|
|
|
class RegionTree {
|
|
AK_MAKE_NONCOPYABLE(RegionTree);
|
|
AK_MAKE_NONMOVABLE(RegionTree);
|
|
|
|
public:
|
|
explicit RegionTree(VirtualRange total_range)
|
|
: m_total_range(total_range)
|
|
{
|
|
}
|
|
|
|
~RegionTree();
|
|
|
|
auto& regions() { return m_regions; }
|
|
auto const& regions() const { return m_regions; }
|
|
|
|
VirtualRange total_range() const { return m_total_range; }
|
|
|
|
ErrorOr<NonnullOwnPtr<Region>> allocate_unbacked_anywhere(size_t size, size_t alignment = PAGE_SIZE);
|
|
|
|
ErrorOr<void> place_anywhere(Region&, size_t size, size_t alignment = PAGE_SIZE);
|
|
ErrorOr<void> place_specifically(Region&, VirtualRange const&);
|
|
|
|
ErrorOr<VirtualRange> try_allocate_anywhere(size_t size, size_t alignment = PAGE_SIZE);
|
|
ErrorOr<VirtualRange> try_allocate_specific(VirtualAddress base, size_t size);
|
|
ErrorOr<VirtualRange> try_allocate_randomized(size_t size, size_t alignment = PAGE_SIZE);
|
|
|
|
void delete_all_regions_assuming_they_are_unmapped();
|
|
|
|
private:
|
|
Spinlock m_lock;
|
|
|
|
IntrusiveRedBlackTree<&Region::m_tree_node> m_regions;
|
|
VirtualRange const m_total_range;
|
|
};
|
|
|
|
}
|