/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Kernel::Memory { class VirtualRangeAllocator { public: VirtualRangeAllocator(); ~VirtualRangeAllocator() = default; ErrorOr initialize_with_range(VirtualAddress, size_t); ErrorOr initialize_from_parent(VirtualRangeAllocator const&); ErrorOr try_allocate_anywhere(size_t, size_t alignment = PAGE_SIZE); ErrorOr try_allocate_specific(VirtualAddress, size_t); ErrorOr try_allocate_randomized(size_t, size_t alignment); void deallocate(VirtualRange const&); void dump() const; bool contains(VirtualRange const& range) const { return m_total_range.contains(range); } private: void carve_from_region(VirtualRange const& from, VirtualRange const&); RedBlackTree m_available_ranges; VirtualRange m_total_range; mutable Spinlock m_lock; }; } namespace AK { template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } }; }