Kernel/Memory: Split the MemoryManager.h file from user address checks

This commit is contained in:
Liav A 2023-08-08 22:26:35 +03:00 committed by Andrew Kaster
parent 7550b4175e
commit 3b09560251
Notes: sideshowbarker 2024-07-18 03:20:18 +09:00
2 changed files with 37 additions and 21 deletions

View File

@ -13,6 +13,7 @@
#include <Kernel/Forward.h>
#include <Kernel/Locking/Spinlock.h>
#include <Kernel/Memory/AllocationStrategy.h>
#include <Kernel/Memory/MemorySections.h>
#include <Kernel/Memory/PhysicalPage.h>
#include <Kernel/Memory/PhysicalRegion.h>
#include <Kernel/Memory/Region.h>
@ -299,27 +300,6 @@ private:
SpinlockProtected<GlobalData, LockRank::None> m_global_data;
};
inline bool is_user_address(VirtualAddress vaddr)
{
return vaddr.get() < USER_RANGE_CEILING;
}
inline bool is_user_range(VirtualAddress vaddr, size_t size)
{
if (vaddr.offset(size) < vaddr)
return false;
if (!is_user_address(vaddr))
return false;
if (size <= 1)
return true;
return is_user_address(vaddr.offset(size - 1));
}
inline bool is_user_range(VirtualRange const& range)
{
return is_user_range(range.base(), range.size());
}
inline bool PhysicalPage::is_shared_zero_page() const
{
return this == &MM.shared_zero_page();

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/Memory/VirtualAddress.h>
#include <Kernel/Memory/VirtualRange.h>
#include <Kernel/Sections.h>
namespace Kernel::Memory {
inline bool is_user_address(VirtualAddress vaddr)
{
return vaddr.get() < USER_RANGE_CEILING;
}
inline bool is_user_range(VirtualAddress vaddr, size_t size)
{
if (vaddr.offset(size) < vaddr)
return false;
if (!is_user_address(vaddr))
return false;
if (size <= 1)
return true;
return is_user_address(vaddr.offset(size - 1));
}
inline bool is_user_range(VirtualRange const& range)
{
return is_user_range(range.base(), range.size());
}
}