/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Kernel { class RangeAllocator { public: RangeAllocator(); ~RangeAllocator(); void initialize_with_range(VirtualAddress, size_t); void initialize_from_parent(const RangeAllocator&); Optional allocate_anywhere(size_t, size_t alignment = PAGE_SIZE); Optional allocate_specific(VirtualAddress, size_t); Optional allocate_randomized(size_t, size_t alignment); void deallocate(const Range&); void dump() const; bool contains(const Range& range) const { ScopedSpinLock lock(m_lock); return m_total_range.contains(range); } private: void carve_at_index(int, const Range&); Vector m_available_ranges; Range m_total_range; mutable SpinLock m_lock; }; } namespace AK { template<> struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } }; }