mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
![Andreas Kling](/assets/img/avatar_default.png)
This patch ports MemoryManager to RegionTree as well. The biggest difference between this and the userspace code is that kernel regions are owned by extant OwnPtr<Region> objects spread around the kernel, while userspace regions are owned by the AddressSpace itself. For kernelspace, there are a couple of situations where we need to make large VM reservations that never get backed by regular VMObjects (for example the kernel image reservation, or the big kmalloc range.) Since we can't make a VM reservation without a Region object anymore, this patch adds a way to create unbacked Region objects that can be used for this exact purpose. They have no internal VMObject.)
51 lines
1.3 KiB
C++
51 lines
1.3 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<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;
|
|
};
|
|
|
|
}
|