2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2018-10-18 00:13:55 +03:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-16 12:36:52 +03:00
|
|
|
#include <AK/Concepts.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <AK/HashTable.h>
|
2021-07-12 23:52:17 +03:00
|
|
|
#include <AK/NonnullOwnPtrVector.h>
|
2019-06-27 14:34:28 +03:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
2020-02-16 03:50:16 +03:00
|
|
|
#include <Kernel/Forward.h>
|
2021-08-22 02:37:17 +03:00
|
|
|
#include <Kernel/Locking/Spinlock.h>
|
2021-08-06 11:45:34 +03:00
|
|
|
#include <Kernel/Memory/AllocationStrategy.h>
|
|
|
|
#include <Kernel/Memory/PhysicalPage.h>
|
|
|
|
#include <Kernel/Memory/PhysicalRegion.h>
|
|
|
|
#include <Kernel/Memory/Region.h>
|
|
|
|
#include <Kernel/Memory/VMObject.h>
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2021-12-01 20:14:03 +03:00
|
|
|
namespace Kernel {
|
|
|
|
class PageDirectoryEntry;
|
|
|
|
}
|
|
|
|
|
2021-12-25 19:23:18 +03:00
|
|
|
struct KmallocGlobalData;
|
|
|
|
|
2021-08-06 14:49:36 +03:00
|
|
|
namespace Kernel::Memory {
|
2020-02-16 03:27:42 +03:00
|
|
|
|
2021-12-24 17:22:11 +03:00
|
|
|
ErrorOr<FlatPtr> page_round_up(FlatPtr x);
|
2021-02-14 11:57:19 +03:00
|
|
|
|
|
|
|
constexpr FlatPtr page_round_down(FlatPtr x)
|
|
|
|
{
|
|
|
|
return ((FlatPtr)(x)) & ~(PAGE_SIZE - 1);
|
|
|
|
}
|
2019-01-13 02:27:25 +03:00
|
|
|
|
2021-06-17 14:05:37 +03:00
|
|
|
inline FlatPtr virtual_to_low_physical(FlatPtr virtual_)
|
2020-01-17 21:59:20 +03:00
|
|
|
{
|
2021-07-22 14:05:04 +03:00
|
|
|
return virtual_ - physical_to_virtual_offset;
|
2020-01-17 21:59:20 +03:00
|
|
|
}
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
enum class UsedMemoryRangeType {
|
2021-01-19 21:13:03 +03:00
|
|
|
LowMemory = 0,
|
|
|
|
Kernel,
|
|
|
|
BootModule,
|
2021-07-08 04:50:05 +03:00
|
|
|
PhysicalPages,
|
2021-12-19 03:15:12 +03:00
|
|
|
__Count
|
2021-01-19 21:13:03 +03:00
|
|
|
};
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
static constexpr StringView UserMemoryRangeTypeNames[] {
|
2021-01-19 21:13:03 +03:00
|
|
|
"Low memory",
|
|
|
|
"Kernel",
|
|
|
|
"Boot module",
|
2021-07-08 04:50:05 +03:00
|
|
|
"Physical Pages"
|
2021-01-19 21:13:03 +03:00
|
|
|
};
|
2021-12-19 03:15:12 +03:00
|
|
|
static_assert(array_size(UserMemoryRangeTypeNames) == to_underlying(UsedMemoryRangeType::__Count));
|
2021-01-19 21:13:03 +03:00
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
struct UsedMemoryRange {
|
|
|
|
UsedMemoryRangeType type {};
|
2021-01-19 21:13:03 +03:00
|
|
|
PhysicalAddress start;
|
|
|
|
PhysicalAddress end;
|
|
|
|
};
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
struct ContiguousReservedMemoryRange {
|
2021-01-29 15:03:25 +03:00
|
|
|
PhysicalAddress start;
|
2021-07-07 06:35:15 +03:00
|
|
|
PhysicalSize length {};
|
2021-01-29 15:03:25 +03:00
|
|
|
};
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
enum class PhysicalMemoryRangeType {
|
2021-01-29 15:03:25 +03:00
|
|
|
Usable = 0,
|
|
|
|
Reserved,
|
|
|
|
ACPI_Reclaimable,
|
|
|
|
ACPI_NVS,
|
|
|
|
BadMemory,
|
2021-02-12 00:02:39 +03:00
|
|
|
Unknown,
|
2021-01-29 15:03:25 +03:00
|
|
|
};
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
struct PhysicalMemoryRange {
|
|
|
|
PhysicalMemoryRangeType type { PhysicalMemoryRangeType::Unknown };
|
2021-01-29 15:03:25 +03:00
|
|
|
PhysicalAddress start;
|
2021-07-07 06:35:15 +03:00
|
|
|
PhysicalSize length {};
|
2021-01-29 15:03:25 +03:00
|
|
|
};
|
|
|
|
|
2021-08-06 14:49:36 +03:00
|
|
|
#define MM Kernel::Memory::MemoryManager::the()
|
2018-10-27 15:56:52 +03:00
|
|
|
|
2020-06-29 01:04:35 +03:00
|
|
|
struct MemoryManagerData {
|
2021-07-27 15:30:26 +03:00
|
|
|
static ProcessorSpecificDataID processor_specific_data_id() { return ProcessorSpecificDataID::MemoryManager; }
|
|
|
|
|
2021-09-05 20:02:03 +03:00
|
|
|
Spinlock m_quickmap_in_use;
|
2020-07-03 14:19:50 +03:00
|
|
|
u32 m_quickmap_prev_flags;
|
2020-11-01 02:19:50 +03:00
|
|
|
|
|
|
|
PhysicalAddress m_last_quickmap_pd;
|
|
|
|
PhysicalAddress m_last_quickmap_pt;
|
2020-06-29 01:04:35 +03:00
|
|
|
};
|
|
|
|
|
2021-11-01 01:43:03 +03:00
|
|
|
// NOLINTNEXTLINE(readability-redundant-declaration) FIXME: Why do we declare this here *and* in Thread.h?
|
2021-08-22 02:37:17 +03:00
|
|
|
extern RecursiveSpinlock s_mm_lock;
|
2020-07-06 16:27:22 +03:00
|
|
|
|
2021-08-04 23:49:13 +03:00
|
|
|
// This class represents a set of committed physical pages.
|
|
|
|
// When you ask MemoryManager to commit pages for you, you get one of these in return.
|
|
|
|
// You can allocate pages from it via `take_one()`
|
|
|
|
// It will uncommit any (unallocated) remaining pages when destroyed.
|
|
|
|
class CommittedPhysicalPageSet {
|
|
|
|
AK_MAKE_NONCOPYABLE(CommittedPhysicalPageSet);
|
|
|
|
|
|
|
|
public:
|
|
|
|
CommittedPhysicalPageSet(Badge<MemoryManager>, size_t page_count)
|
|
|
|
: m_page_count(page_count)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommittedPhysicalPageSet(CommittedPhysicalPageSet&& other)
|
|
|
|
: m_page_count(exchange(other.m_page_count, 0))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~CommittedPhysicalPageSet();
|
|
|
|
|
|
|
|
bool is_empty() const { return m_page_count == 0; }
|
|
|
|
size_t page_count() const { return m_page_count; }
|
|
|
|
|
|
|
|
[[nodiscard]] NonnullRefPtr<PhysicalPage> take_one();
|
2021-08-05 18:14:13 +03:00
|
|
|
void uncommit_one();
|
2021-08-04 23:49:13 +03:00
|
|
|
|
|
|
|
void operator=(CommittedPhysicalPageSet&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t m_page_count { 0 };
|
|
|
|
};
|
|
|
|
|
2018-10-18 00:13:55 +03:00
|
|
|
class MemoryManager {
|
2021-07-14 00:21:22 +03:00
|
|
|
friend class PageDirectory;
|
2020-09-06 00:52:14 +03:00
|
|
|
friend class AnonymousVMObject;
|
2018-11-08 16:35:30 +03:00
|
|
|
friend class Region;
|
2018-11-08 23:20:09 +03:00
|
|
|
friend class VMObject;
|
2021-12-25 19:23:18 +03:00
|
|
|
friend struct ::KmallocGlobalData;
|
2019-05-28 12:53:16 +03:00
|
|
|
|
2018-10-18 00:13:55 +03:00
|
|
|
public:
|
2019-07-16 14:44:41 +03:00
|
|
|
static MemoryManager& the();
|
2020-08-30 01:41:30 +03:00
|
|
|
static bool is_initialized();
|
2018-10-18 00:13:55 +03:00
|
|
|
|
2020-06-29 01:04:35 +03:00
|
|
|
static void initialize(u32 cpu);
|
2020-09-18 10:49:51 +03:00
|
|
|
|
2020-06-29 01:04:35 +03:00
|
|
|
static inline MemoryManagerData& get_data()
|
|
|
|
{
|
2021-07-27 15:30:26 +03:00
|
|
|
return ProcessorSpecific<MemoryManagerData>::get();
|
2020-06-29 01:04:35 +03:00
|
|
|
}
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2021-07-14 14:31:21 +03:00
|
|
|
PageFaultResponse handle_page_fault(PageFault const&);
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2021-03-11 15:03:40 +03:00
|
|
|
void set_page_writable_direct(VirtualAddress, bool);
|
|
|
|
|
2021-02-14 19:35:07 +03:00
|
|
|
void protect_readonly_after_init_memory();
|
2021-12-19 03:15:12 +03:00
|
|
|
void unmap_prekernel();
|
2021-07-16 10:50:34 +03:00
|
|
|
void unmap_text_after_init();
|
2021-12-17 11:52:06 +03:00
|
|
|
void protect_ksyms_after_init();
|
2021-02-14 19:35:07 +03:00
|
|
|
|
2021-09-06 18:11:33 +03:00
|
|
|
static void enter_process_address_space(Process&);
|
|
|
|
static void enter_address_space(AddressSpace&);
|
2018-11-01 11:01:51 +03:00
|
|
|
|
2021-08-06 14:57:39 +03:00
|
|
|
bool validate_user_stack_no_lock(AddressSpace&, VirtualAddress) const;
|
|
|
|
bool validate_user_stack(AddressSpace&, VirtualAddress) const;
|
2020-02-21 15:05:39 +03:00
|
|
|
|
2019-06-07 18:13:23 +03:00
|
|
|
enum class ShouldZeroFill {
|
2019-05-28 12:53:16 +03:00
|
|
|
No,
|
|
|
|
Yes
|
|
|
|
};
|
2019-01-31 05:57:06 +03:00
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<CommittedPhysicalPageSet> commit_user_physical_pages(size_t page_count);
|
2021-08-04 23:49:13 +03:00
|
|
|
void uncommit_user_physical_pages(Badge<CommittedPhysicalPageSet>, size_t page_count);
|
|
|
|
|
2021-08-05 20:58:09 +03:00
|
|
|
NonnullRefPtr<PhysicalPage> allocate_committed_user_physical_page(Badge<CommittedPhysicalPageSet>, ShouldZeroFill = ShouldZeroFill::Yes);
|
2020-09-01 22:40:34 +03:00
|
|
|
RefPtr<PhysicalPage> allocate_user_physical_page(ShouldZeroFill = ShouldZeroFill::Yes, bool* did_purge = nullptr);
|
2019-06-21 19:37:47 +03:00
|
|
|
RefPtr<PhysicalPage> allocate_supervisor_physical_page();
|
2021-07-13 17:10:48 +03:00
|
|
|
NonnullRefPtrVector<PhysicalPage> allocate_contiguous_supervisor_physical_pages(size_t size);
|
2021-07-12 00:12:32 +03:00
|
|
|
void deallocate_physical_page(PhysicalAddress);
|
2018-11-05 12:23:00 +03:00
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<NonnullOwnPtr<Region>> allocate_contiguous_kernel_region(size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes);
|
2021-12-16 18:05:51 +03:00
|
|
|
ErrorOr<NonnullOwnPtr<Memory::Region>> allocate_dma_buffer_page(StringView name, Memory::Region::Access access, RefPtr<Memory::PhysicalPage>& dma_buffer_page);
|
2022-01-08 19:34:09 +03:00
|
|
|
ErrorOr<NonnullOwnPtr<Memory::Region>> allocate_dma_buffer_page(StringView name, Memory::Region::Access access);
|
2021-12-16 18:05:51 +03:00
|
|
|
ErrorOr<NonnullOwnPtr<Memory::Region>> allocate_dma_buffer_pages(size_t size, StringView name, Memory::Region::Access access, NonnullRefPtrVector<Memory::PhysicalPage>& dma_buffer_pages);
|
2022-01-08 19:34:09 +03:00
|
|
|
ErrorOr<NonnullOwnPtr<Memory::Region>> allocate_dma_buffer_pages(size_t size, StringView name, Memory::Region::Access access);
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<NonnullOwnPtr<Region>> allocate_kernel_region(size_t, StringView name, Region::Access access, AllocationStrategy strategy = AllocationStrategy::Reserve, Region::Cacheable = Region::Cacheable::Yes);
|
|
|
|
ErrorOr<NonnullOwnPtr<Region>> allocate_kernel_region(PhysicalAddress, size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes);
|
|
|
|
ErrorOr<NonnullOwnPtr<Region>> allocate_kernel_region_with_vmobject(VMObject&, size_t, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes);
|
|
|
|
ErrorOr<NonnullOwnPtr<Region>> allocate_kernel_region_with_vmobject(VirtualRange const&, VMObject&, StringView name, Region::Access access, Region::Cacheable = Region::Cacheable::Yes);
|
2019-05-14 12:51:00 +03:00
|
|
|
|
2021-07-07 06:35:15 +03:00
|
|
|
struct SystemMemoryInfo {
|
|
|
|
PhysicalSize user_physical_pages { 0 };
|
|
|
|
PhysicalSize user_physical_pages_used { 0 };
|
|
|
|
PhysicalSize user_physical_pages_committed { 0 };
|
|
|
|
PhysicalSize user_physical_pages_uncommitted { 0 };
|
|
|
|
PhysicalSize super_physical_pages { 0 };
|
|
|
|
PhysicalSize super_physical_pages_used { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
SystemMemoryInfo get_system_memory_info()
|
|
|
|
{
|
2021-08-22 02:49:22 +03:00
|
|
|
SpinlockLocker lock(s_mm_lock);
|
2021-07-07 06:35:15 +03:00
|
|
|
return m_system_memory_info;
|
|
|
|
}
|
2019-06-11 14:13:02 +03:00
|
|
|
|
2021-05-16 12:36:52 +03:00
|
|
|
template<IteratorFunction<VMObject&> Callback>
|
2019-08-08 11:43:44 +03:00
|
|
|
static void for_each_vmobject(Callback callback)
|
|
|
|
{
|
2021-08-16 23:54:25 +03:00
|
|
|
VMObject::all_instances().with([&](auto& list) {
|
|
|
|
for (auto& vmobject : list) {
|
|
|
|
if (callback(vmobject) == IterationDecision::Break)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2019-08-08 11:43:44 +03:00
|
|
|
}
|
|
|
|
|
2021-05-16 12:36:52 +03:00
|
|
|
template<VoidFunction<VMObject&> Callback>
|
|
|
|
static void for_each_vmobject(Callback callback)
|
|
|
|
{
|
2021-08-16 23:54:25 +03:00
|
|
|
VMObject::all_instances().with([&](auto& list) {
|
|
|
|
for (auto& vmobject : list) {
|
|
|
|
callback(vmobject);
|
|
|
|
}
|
|
|
|
});
|
2021-05-16 12:36:52 +03:00
|
|
|
}
|
|
|
|
|
2021-08-06 14:57:39 +03:00
|
|
|
static Region* find_user_region_from_vaddr(AddressSpace&, VirtualAddress);
|
|
|
|
static Region* find_user_region_from_vaddr_no_lock(AddressSpace&, VirtualAddress);
|
|
|
|
static void validate_syscall_preconditions(AddressSpace&, RegisterState const&);
|
2019-11-29 18:15:30 +03:00
|
|
|
|
2020-01-18 10:34:28 +03:00
|
|
|
void dump_kernel_regions();
|
|
|
|
|
2020-02-15 15:12:02 +03:00
|
|
|
PhysicalPage& shared_zero_page() { return *m_shared_zero_page; }
|
2020-09-05 06:12:25 +03:00
|
|
|
PhysicalPage& lazy_committed_page() { return *m_lazy_committed_page; }
|
2020-02-15 15:12:02 +03:00
|
|
|
|
2020-06-02 07:55:09 +03:00
|
|
|
PageDirectory& kernel_page_directory() { return *m_kernel_page_directory; }
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
Vector<UsedMemoryRange> const& used_memory_ranges() { return m_used_memory_ranges; }
|
2021-12-23 22:49:31 +03:00
|
|
|
bool is_allowed_to_read_physical_memory_for_userspace(PhysicalAddress, size_t read_length) const;
|
2021-01-19 21:13:03 +03:00
|
|
|
|
2021-07-08 04:50:05 +03:00
|
|
|
PhysicalPageEntry& get_physical_page_entry(PhysicalAddress);
|
|
|
|
PhysicalAddress get_physical_address(PhysicalPage const&);
|
|
|
|
|
2021-11-17 21:31:30 +03:00
|
|
|
void copy_physical_page(PhysicalPage&, u8 page_buffer[PAGE_SIZE]);
|
|
|
|
|
2022-01-03 02:27:21 +03:00
|
|
|
IterationDecision for_each_physical_memory_range(Function<IterationDecision(PhysicalMemoryRange const&)>);
|
|
|
|
|
2018-10-18 00:13:55 +03:00
|
|
|
private:
|
2020-08-22 18:53:34 +03:00
|
|
|
MemoryManager();
|
2018-10-18 00:13:55 +03:00
|
|
|
~MemoryManager();
|
|
|
|
|
2021-07-08 04:50:05 +03:00
|
|
|
void initialize_physical_pages();
|
2021-01-29 15:03:25 +03:00
|
|
|
void register_reserved_ranges();
|
|
|
|
|
2018-11-09 00:24:02 +03:00
|
|
|
void register_region(Region&);
|
|
|
|
void unregister_region(Region&);
|
2018-11-08 23:20:09 +03:00
|
|
|
|
2020-01-18 00:07:20 +03:00
|
|
|
void protect_kernel_image();
|
2020-01-17 23:03:52 +03:00
|
|
|
void parse_memory_map();
|
2020-07-06 16:27:22 +03:00
|
|
|
static void flush_tlb_local(VirtualAddress, size_t page_count = 1);
|
2021-07-14 14:31:21 +03:00
|
|
|
static void flush_tlb(PageDirectory const*, VirtualAddress, size_t page_count = 1);
|
2018-10-18 00:13:55 +03:00
|
|
|
|
2019-08-06 11:31:20 +03:00
|
|
|
static Region* kernel_region_from_vaddr(VirtualAddress);
|
|
|
|
|
2020-07-31 00:52:28 +03:00
|
|
|
static Region* find_region_from_vaddr(VirtualAddress);
|
2019-08-06 12:19:16 +03:00
|
|
|
|
2020-09-05 06:12:25 +03:00
|
|
|
RefPtr<PhysicalPage> find_free_user_physical_page(bool);
|
2021-07-08 04:50:05 +03:00
|
|
|
|
|
|
|
ALWAYS_INLINE u8* quickmap_page(PhysicalPage& page)
|
|
|
|
{
|
|
|
|
return quickmap_page(page.paddr());
|
|
|
|
}
|
|
|
|
u8* quickmap_page(PhysicalAddress const&);
|
2018-11-05 15:48:07 +03:00
|
|
|
void unquickmap_page();
|
|
|
|
|
2020-01-17 21:59:20 +03:00
|
|
|
PageDirectoryEntry* quickmap_pd(PageDirectory&, size_t pdpt_index);
|
|
|
|
PageTableEntry* quickmap_pt(PhysicalAddress);
|
|
|
|
|
2020-11-01 02:19:18 +03:00
|
|
|
PageTableEntry* pte(PageDirectory&, VirtualAddress);
|
2020-09-02 01:10:54 +03:00
|
|
|
PageTableEntry* ensure_pte(PageDirectory&, VirtualAddress);
|
2021-12-19 03:15:12 +03:00
|
|
|
enum class IsLastPTERelease {
|
|
|
|
Yes,
|
|
|
|
No
|
|
|
|
};
|
|
|
|
enum class UnsafeIgnoreMissingPageTable {
|
|
|
|
Yes,
|
|
|
|
No
|
|
|
|
};
|
|
|
|
void release_pte(PageDirectory&, VirtualAddress, IsLastPTERelease, UnsafeIgnoreMissingPageTable = UnsafeIgnoreMissingPageTable::No);
|
2018-10-18 00:13:55 +03:00
|
|
|
|
2019-06-21 19:37:47 +03:00
|
|
|
RefPtr<PageDirectory> m_kernel_page_directory;
|
2018-10-18 14:05:00 +03:00
|
|
|
|
2020-02-15 15:12:02 +03:00
|
|
|
RefPtr<PhysicalPage> m_shared_zero_page;
|
2020-09-05 06:12:25 +03:00
|
|
|
RefPtr<PhysicalPage> m_lazy_committed_page;
|
2020-02-15 15:12:02 +03:00
|
|
|
|
2021-07-07 06:35:15 +03:00
|
|
|
SystemMemoryInfo m_system_memory_info;
|
2019-06-11 14:13:02 +03:00
|
|
|
|
2021-07-12 23:52:17 +03:00
|
|
|
NonnullOwnPtrVector<PhysicalRegion> m_user_physical_regions;
|
2021-08-04 20:29:02 +03:00
|
|
|
OwnPtr<PhysicalRegion> m_super_physical_region;
|
2021-07-12 23:52:17 +03:00
|
|
|
OwnPtr<PhysicalRegion> m_physical_pages_region;
|
2021-07-08 04:50:05 +03:00
|
|
|
PhysicalPageEntry* m_physical_page_entries { nullptr };
|
|
|
|
size_t m_physical_page_entries_count { 0 };
|
2018-11-08 23:20:09 +03:00
|
|
|
|
2021-12-11 20:31:56 +03:00
|
|
|
RedBlackTree<FlatPtr, Region*> m_kernel_regions;
|
|
|
|
|
2021-08-07 00:42:53 +03:00
|
|
|
Vector<UsedMemoryRange> m_used_memory_ranges;
|
|
|
|
Vector<PhysicalMemoryRange> m_physical_memory_ranges;
|
|
|
|
Vector<ContiguousReservedMemoryRange> m_reserved_memory_ranges;
|
2018-10-18 00:13:55 +03:00
|
|
|
};
|
2018-11-01 13:44:21 +03:00
|
|
|
|
2020-01-02 22:49:21 +03:00
|
|
|
inline bool is_user_address(VirtualAddress vaddr)
|
|
|
|
{
|
2021-07-07 05:25:22 +03:00
|
|
|
return vaddr.get() < USER_RANGE_CEILING;
|
2020-01-02 22:49:21 +03:00
|
|
|
}
|
2020-01-19 11:14:14 +03:00
|
|
|
|
|
|
|
inline bool is_user_range(VirtualAddress vaddr, size_t size)
|
|
|
|
{
|
|
|
|
if (vaddr.offset(size) < vaddr)
|
|
|
|
return false;
|
2021-09-11 03:34:55 +03:00
|
|
|
if (!is_user_address(vaddr))
|
|
|
|
return false;
|
|
|
|
if (size <= 1)
|
|
|
|
return true;
|
|
|
|
return is_user_address(vaddr.offset(size - 1));
|
2020-01-19 11:14:14 +03:00
|
|
|
}
|
2020-02-15 15:12:02 +03:00
|
|
|
|
2021-08-06 14:54:48 +03:00
|
|
|
inline bool is_user_range(VirtualRange const& range)
|
2021-02-13 02:47:47 +03:00
|
|
|
{
|
|
|
|
return is_user_range(range.base(), range.size());
|
|
|
|
}
|
|
|
|
|
2020-02-15 15:12:02 +03:00
|
|
|
inline bool PhysicalPage::is_shared_zero_page() const
|
|
|
|
{
|
|
|
|
return this == &MM.shared_zero_page();
|
|
|
|
}
|
2020-02-16 03:27:42 +03:00
|
|
|
|
2020-09-05 06:12:25 +03:00
|
|
|
inline bool PhysicalPage::is_lazy_committed_page() const
|
|
|
|
{
|
|
|
|
return this == &MM.lazy_committed_page();
|
|
|
|
}
|
|
|
|
|
2021-11-29 22:19:58 +03:00
|
|
|
inline ErrorOr<Memory::VirtualRange> expand_range_to_page_boundaries(FlatPtr address, size_t size)
|
|
|
|
{
|
|
|
|
if ((address + size) < address)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
auto base = VirtualAddress { address }.page_base();
|
2021-12-24 17:22:11 +03:00
|
|
|
auto end = TRY(Memory::page_round_up(address + size));
|
2021-11-29 22:19:58 +03:00
|
|
|
|
|
|
|
return Memory::VirtualRange { base, end - base.get() };
|
|
|
|
}
|
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
}
|