20#ifndef KERNEL_PROCESSOR_HOSTED_VIRTUALADDRESSSPACE_H
21#define KERNEL_PROCESSOR_HOSTED_VIRTUALADDRESSSPACE_H
22#include "pedigree/kernel/Spinlock.h"
23#include "pedigree/kernel/processor/VirtualAddressSpace.h"
24#include "pedigree/kernel/processor/types.h"
25#include "pedigree/kernel/utilities/Vector.h"
29#include "MappingIndex.h"
34#define KERNEL_SPACE_START reinterpret_cast<void*>(0x0000700000000000)
36#define USERSPACE_DYNAMIC_LINKER_LOCATION reinterpret_cast<void*>(0x4FA00000)
38#define USERSPACE_VIRTUAL_START reinterpret_cast<void*>(0x20000000)
39#define USERSPACE_VIRTUAL_HEAP reinterpret_cast<void*>(0x50000000)
40#define USERSPACE_RESERVED_START USERSPACE_DYNAMIC_LINKER_LOCATION
41#define USERSPACE_VIRTUAL_STACK_SIZE 0x100000
42#define USERSPACE_VIRTUAL_MAX_STACK_SIZE 0x100000
43#define USERSPACE_DYNAMIC_START reinterpret_cast<void*>(0x0000400000000000)
44#define USERSPACE_DYNAMIC_END reinterpret_cast<void*>(0x0000500000000000)
45#define USERSPACE_VIRTUAL_LOWEST_STACK \
46 reinterpret_cast<void*>(USERSPACE_DYNAMIC_END + USERSPACE_VIRTUAL_MAX_STACK_SIZE)
47#define USERSPACE_VIRTUAL_STACK \
48 reinterpret_cast<void*>(0x0000700000000000ULL - PEDIGREE_TARGET_PAGE_SIZE)
49#define KERNEL_VIRTUAL_MODULE_BASE reinterpret_cast<void*>(0x70000000)
50#define KERNEL_VIRTUAL_MODULE_SIZE 0x10000000
51#define KERNEL_VIRTUAL_EVENT_BASE reinterpret_cast<void*>(0x300000000000)
52#define KERNEL_VIRTUAL_HEAP reinterpret_cast<void*>(0x0000700000000000)
53#define KERNEL_VIRTUAL_HEAP_SIZE 0x40000000
54#define KERNEL_VIRTUAL_ADDRESS reinterpret_cast<void*>(0x400000)
55#define KERNEL_VIRTUAL_CACHE reinterpret_cast<void*>(0x200000000000)
56#define KERNEL_VIRTUAL_CACHE_SIZE 0x10000000
57#define KERNEL_VIRTUAL_MEMORYREGION_ADDRESS reinterpret_cast<void*>(0x0000700040000000)
58#define KERNEL_VIRTUAL_MEMORYREGION_SIZE 0x40000000
59#define KERNEL_VIRTUAL_PAGESTACK_4GB reinterpret_cast<void*>(0x0000700080000000)
60#define KERNEL_VIRTUAL_STACK \
61 reinterpret_cast<void*>(0x0000701000000000ULL - PEDIGREE_TARGET_PAGE_SIZE)
62#define KERNEL_STACK_SIZE 0x10000
87 virtual bool isMapped(
void* virtualAddress);
89 virtual bool map(physical_uintptr_t physAddress,
void* virtualAddress,
size_t flags);
90 bool tryMapUserPage(physical_uintptr_t physical,
void* address,
size_t flags,
91 size_t* committedTablePages =
nullptr)
override;
92 bool tryDetachUserPage(
void* address, physical_uintptr_t expected)
override;
93 virtual bool getMapping(
void* virtualAddress, physical_uintptr_t& physAddress,
size_t& flags);
96 virtual bool tryReadUser32(uintptr_t address, uint32_t& value);
97 virtual bool tryReadUserPointer(uintptr_t address, uintptr_t& value);
100 virtual void setFlags(
void* virtualAddress,
size_t newFlags);
102 virtual void unmap(
void* virtualAddress);
103 virtual bool detachMapping(
void* virtualAddress, physical_uintptr_t& physical,
size_t& flags,
104 size_t requiredFlags = 0);
122 return reinterpret_cast<uintptr_t
>(KERNEL_SPACE_START);
127 return reinterpret_cast<uintptr_t
>(USERSPACE_VIRTUAL_START);
132 return reinterpret_cast<uintptr_t
>(USERSPACE_RESERVED_START);
137 return reinterpret_cast<uintptr_t
>(USERSPACE_DYNAMIC_LINKER_LOCATION);
142 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_HEAP);
147 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_HEAP) + KERNEL_VIRTUAL_HEAP_SIZE;
152 return reinterpret_cast<uintptr_t
>(USERSPACE_DYNAMIC_START);
157 return reinterpret_cast<uintptr_t
>(USERSPACE_DYNAMIC_END);
162 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_CACHE);
167 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_CACHE) + KERNEL_VIRTUAL_CACHE_SIZE;
172 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_EVENT_BASE);
177 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_MODULE_BASE);
182 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_MODULE_BASE) + KERNEL_VIRTUAL_MODULE_SIZE;
187 return reinterpret_cast<uintptr_t
>(KERNEL_VIRTUAL_PAGESTACK_4GB);
191 bool tryAccessUserWord(uintptr_t address,
size_t width, uintptr_t& value,
192 const uintptr_t* replacement);
218 uint64_t
toFlags(
size_t flags,
bool bFinal =
false);
224 size_t fromFlags(uint64_t Flags,
bool bFinal =
false);
232 physical_uintptr_t paddr;
Vector< Stack * > m_freeStacks
Stack * doAllocateStack(size_t sSize)
HostedVirtualAddressSpace(const HostedVirtualAddressSpace &)
virtual uintptr_t getDynamicLinkerAddress() const
virtual bool map(physical_uintptr_t physAddress, void *virtualAddress, size_t flags)
MUST_USE_RESULT bool trySetFlags(void *virtualAddress, size_t newFlags) override
virtual uintptr_t getDynamicEnd() const
virtual void setFlags(void *virtualAddress, size_t newFlags)
virtual bool detachMapping(void *virtualAddress, physical_uintptr_t &physical, size_t &flags, size_t requiredFlags=0)
virtual void * getEndOfHeap()
virtual void revertToKernelAddressSpace()
virtual uintptr_t getKernelEventBlockStart() const
virtual ~HostedVirtualAddressSpace()
virtual Stack * allocateStack()
virtual uintptr_t getDynamicStart() const
static void switchAddressSpace(VirtualAddressSpace &oldSpace, VirtualAddressSpace &newSpace)
virtual uintptr_t getKernelHeapEnd() const
virtual uintptr_t getKernelModulesEnd() const
virtual bool tryReadUser32(uintptr_t address, uint32_t &value)
virtual uintptr_t getKernelHeapStart() const
virtual bool tryWriteUser32(uintptr_t address, uint32_t value)
virtual bool isMapped(void *virtualAddress)
uint64_t toFlags(size_t flags, bool bFinal=false)
HostedVirtualAddressSpace & operator=(const HostedVirtualAddressSpace &)
virtual uintptr_t getUserReservedStart() const
virtual uintptr_t getKernelCacheStart() const
virtual bool memIsInHeap(void *pMem)
size_t fromFlags(uint64_t Flags, bool bFinal=false)
virtual uintptr_t getUserStart() const
HostedVirtualAddressSpace()
virtual bool isAddressValid(void *virtualAddress)
virtual VirtualAddressSpace * clone(bool copyOnWrite=true)
virtual bool memIsInKernelHeap(void *pMem)
virtual bool tryCompareExchangeUser32(uintptr_t address, uint32_t &expected, uint32_t desired, bool &exchanged)
virtual void freeStack(Stack *pStack)
virtual bool getMapping(void *virtualAddress, physical_uintptr_t &physAddress, size_t &flags)
virtual uintptr_t getKernelCacheEnd() const
virtual uintptr_t getKernelVirtualPagestack() const
virtual void unmap(void *virtualAddress)
virtual uintptr_t getKernelModulesStart() const
virtual uintptr_t getKernelStart() const
virtual bool handleCopyOnWriteFault(void *virtualAddress, bool userMode)
A vector / dynamic array.
static VirtualAddressSpace * create()
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()