mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
Kernel/Memory: Move some VirtualRange functions inline
This will allow turning this class into a templated base class. Don't move expand_to_page_boundaries() inline since it will only be implemented by one subclass. Additionally, this function uses page_round_up() from MemoryManager.h. Including this header in VirtualRange.h would result in a circular include.
This commit is contained in:
1 parent
3c4fe04b2b
commit
25538bf0f0
2 files changed
+35
-40
No files matched your search
@@ -5,48 +5,11 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/Memory/MemoryManager.h>
|
||||
#include <Kernel/Memory/VirtualRange.h>
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
Vector<VirtualRange, 2> VirtualRange::carve(VirtualRange const& taken) const
|
||||
{
|
||||
VERIFY((taken.size() % PAGE_SIZE) == 0);
|
||||
|
||||
Vector<VirtualRange, 2> parts;
|
||||
if (taken == *this)
|
||||
return {};
|
||||
if (taken.base() > base())
|
||||
parts.unchecked_append({ base(), taken.base().get() - base().get() });
|
||||
if (taken.end() < end())
|
||||
parts.unchecked_append({ taken.end(), end().get() - taken.end().get() });
|
||||
return parts;
|
||||
}
|
||||
|
||||
bool VirtualRange::intersects(VirtualRange const& other) const
|
||||
{
|
||||
auto a = *this;
|
||||
auto b = other;
|
||||
|
||||
if (a.base() > b.base())
|
||||
swap(a, b);
|
||||
|
||||
return a.base() < b.end() && b.base() < a.end();
|
||||
}
|
||||
|
||||
VirtualRange VirtualRange::intersect(VirtualRange const& other) const
|
||||
{
|
||||
if (*this == other) {
|
||||
return *this;
|
||||
}
|
||||
auto new_base = max(base(), other.base());
|
||||
auto new_end = min(end(), other.end());
|
||||
VERIFY(new_base < new_end);
|
||||
return VirtualRange(new_base, (new_end - new_base).get());
|
||||
}
|
||||
|
||||
ErrorOr<VirtualRange> VirtualRange::expand_to_page_boundaries(FlatPtr address, size_t size)
|
||||
{
|
||||
if ((address + size) < address)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/Memory/VirtualAddress.h>
|
||||
|
||||
namespace Kernel::Memory {
|
||||
@@ -46,10 +47,41 @@ public:
|
||||
return contains(other.base(), other.size());
|
||||
}
|
||||
|
||||
Vector<VirtualRange, 2> carve(VirtualRange const&) const;
|
||||
VirtualRange intersect(VirtualRange const&) const;
|
||||
Vector<VirtualRange, 2> carve(VirtualRange const& taken) const
|
||||
{
|
||||
VERIFY((taken.size() % PAGE_SIZE) == 0);
|
||||
|
||||
bool intersects(VirtualRange const&) const;
|
||||
Vector<VirtualRange, 2> parts;
|
||||
if (taken == *this)
|
||||
return {};
|
||||
if (taken.base() > base())
|
||||
parts.unchecked_append({ base(), taken.base().get() - base().get() });
|
||||
if (taken.end() < end())
|
||||
parts.unchecked_append({ taken.end(), end().get() - taken.end().get() });
|
||||
return parts;
|
||||
}
|
||||
|
||||
VirtualRange intersect(VirtualRange const& other) const
|
||||
{
|
||||
if (*this == other) {
|
||||
return *this;
|
||||
}
|
||||
auto new_base = max(base(), other.base());
|
||||
auto new_end = min(end(), other.end());
|
||||
VERIFY(new_base < new_end);
|
||||
return VirtualRange(new_base, (new_end - new_base).get());
|
||||
}
|
||||
|
||||
bool intersects(VirtualRange const& other) const
|
||||
{
|
||||
auto a = *this;
|
||||
auto b = other;
|
||||
|
||||
if (a.base() > b.base())
|
||||
swap(a, b);
|
||||
|
||||
return a.base() < b.end() && b.base() < a.end();
|
||||
}
|
||||
|
||||
static ErrorOr<VirtualRange> expand_to_page_boundaries(FlatPtr address, size_t size);
|
||||
|
||||
|
||||
Reference in new issue
Block a user