mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <Kernel/LinearAddress.h>
|
|
#include <AK/Vector.h>
|
|
|
|
class Range {
|
|
friend class RangeAllocator;
|
|
public:
|
|
Range() { }
|
|
Range(LinearAddress base, size_t size)
|
|
: m_base(base)
|
|
, m_size(size)
|
|
{
|
|
}
|
|
|
|
LinearAddress base() const { return m_base; }
|
|
size_t size() const { return m_size; }
|
|
bool is_valid() const { return !m_base.is_null(); }
|
|
|
|
bool contains(LinearAddress laddr) const { return laddr >= base() && laddr < end(); }
|
|
|
|
LinearAddress end() const { return m_base.offset(m_size); }
|
|
|
|
bool operator==(const Range& other) const
|
|
{
|
|
return m_base == other.m_base && m_size == other.m_size;
|
|
}
|
|
|
|
bool contains(LinearAddress base, size_t size) const
|
|
{
|
|
return base >= m_base && base.offset(size) <= end();
|
|
}
|
|
|
|
bool contains(const Range& other) const
|
|
{
|
|
return contains(other.base(), other.size());
|
|
}
|
|
|
|
Vector<Range, 2> carve(const Range&);
|
|
|
|
private:
|
|
LinearAddress m_base;
|
|
size_t m_size { 0 };
|
|
};
|
|
|
|
class RangeAllocator {
|
|
public:
|
|
RangeAllocator(LinearAddress, size_t);
|
|
~RangeAllocator();
|
|
|
|
Range allocate_anywhere(size_t);
|
|
Range allocate_specific(LinearAddress, size_t);
|
|
void deallocate(Range);
|
|
|
|
void dump() const;
|
|
|
|
private:
|
|
void carve_at_index(int, const Range&);
|
|
|
|
Vector<Range> m_available_ranges;
|
|
};
|