The Pedigree Project
0.1
|
#include <VirtualAddressSpace.h>
Public Member Functions | |
virtual bool | isAddressValid (void *virtualAddress) |
virtual bool | isMapped (void *virtualAddress) |
virtual bool | map (physical_uintptr_t physAddress, void *virtualAddress, size_t flags) |
virtual bool | mapHuge (physical_uintptr_t physAddress, void *virtualAddress, size_t count, size_t flags) |
virtual void | getMapping (void *virtualAddress, physical_uintptr_t &physAddress, size_t &flags) |
virtual void | setFlags (void *virtualAddress, size_t newFlags) |
virtual void | unmap (void *virtualAddress) |
virtual Stack * | allocateStack () |
virtual Stack * | allocateStack (size_t stackSz) |
virtual void | freeStack (Stack *pStack) |
virtual bool | memIsInKernelHeap (void *pMem) |
virtual bool | memIsInHeap (void *pMem) |
virtual void * | getEndOfHeap () |
virtual VirtualAddressSpace * | clone (bool copyOnWrite=true) |
virtual void | revertToKernelAddressSpace () |
bool | mapPageStructures (physical_uintptr_t physAddress, void *virtualAddress, size_t flags) |
bool | mapPageStructuresAbove4GB (physical_uintptr_t physAddress, void *virtualAddress, size_t flags) |
virtual | ~X64VirtualAddressSpace () |
virtual uintptr_t | getKernelStart () const |
virtual uintptr_t | getUserStart () const |
virtual uintptr_t | getUserReservedStart () const |
virtual uintptr_t | getDynamicLinkerAddress () const |
virtual uintptr_t | getKernelHeapStart () const |
virtual uintptr_t | getKernelHeapEnd () const |
virtual uintptr_t | getDynamicStart () const |
virtual uintptr_t | getDynamicEnd () const |
virtual uintptr_t | getGlobalInfoBlock () const |
virtual uintptr_t | getKernelCacheStart () const |
virtual uintptr_t | getKernelCacheEnd () const |
virtual uintptr_t | getKernelEventBlockStart () const |
virtual uintptr_t | getKernelModulesStart () const |
virtual uintptr_t | getKernelModulesEnd () const |
Public Member Functions inherited from VirtualAddressSpace | |
virtual void * | expandHeap (ssize_t incr, size_t flags) |
virtual | ~VirtualAddressSpace () |
void | setHeap (void *heap, void *heapEnd) |
Private Member Functions | |
X64VirtualAddressSpace () | |
X64VirtualAddressSpace (void *Heap, physical_uintptr_t PhysicalPML4, void *VirtualStack) | |
X64VirtualAddressSpace (const X64VirtualAddressSpace &) | |
X64VirtualAddressSpace & | operator= (const X64VirtualAddressSpace &) |
bool | getPageTableEntry (void *virtualAddress, uint64_t *&pageTableEntry) const |
void | maybeFreeTables (void *virtualAddress) |
Possibly cleans up tables for the given address. More... | |
uint64_t | toFlags (size_t flags, bool bFinal=false) const PURE |
size_t | fromFlags (uint64_t Flags, bool bFinal=false) const PURE |
bool | conditionalTableEntryAllocation (uint64_t *tableEntry, uint64_t flags) |
bool | conditionalTableEntryMapping (uint64_t *tableEntry, uint64_t physAddress, uint64_t flags) |
bool | mapUnlocked (physical_uintptr_t physAddress, void *virtualAddress, size_t flags, bool locked=false) |
void | unmapUnlocked (void *virtualAddress, bool requireMapped=true) |
Stack * | doAllocateStack (size_t sSize) |
Private Attributes | |
physical_uintptr_t | m_PhysicalPML4 |
void * | m_pStackTop |
Vector< Stack * > | m_freeStacks |
bool | m_bKernelSpace |
Spinlock | m_Lock |
Spinlock | m_StacksLock |
Static Private Attributes | |
static X64VirtualAddressSpace | m_KernelSpace |
Friends | |
class | Processor |
class | Multiprocessor |
VirtualAddressSpace & | VirtualAddressSpace::getKernelAddressSpace () |
VirtualAddressSpace * | VirtualAddressSpace::create () |
Additional Inherited Members | |
Static Public Member Functions inherited from VirtualAddressSpace | |
static EXPORTED_PUBLIC VirtualAddressSpace & | getKernelAddressSpace () |
static VirtualAddressSpace * | create () |
Public Attributes inherited from VirtualAddressSpace | |
void * | m_Heap |
void * | m_HeapEnd |
Static Public Attributes inherited from VirtualAddressSpace | |
static const size_t | KernelMode = 0x01 |
static const size_t | Write = 0x02 |
static const size_t | Execute = 0x04 |
static const size_t | WriteThrough = 0x08 |
static const size_t | CacheDisable = 0x10 |
static const size_t | CopyOnWrite = 0x20 |
static const size_t | Swapped = 0x40 |
static const size_t | MemoryCoherent = 0x80 |
static const size_t | Guarded = 0x100 |
static const size_t | Shared = 0x200 |
static const size_t | WriteCombine = 0x400 |
static const size_t | Accessed = 0x800 |
static const size_t | Dirty = 0x1000 |
static const size_t | ClearDirty = 0x2000 |
static physical_uintptr_t | m_ZeroPage = 0 |
Protected Member Functions inherited from VirtualAddressSpace | |
VirtualAddressSpace (void *Heap) | |
The X64VirtualAddressSpace implements the VirtualAddressSpace class for the x64 processor architecture, that means it wraps around the processor's paging functionality.
Definition at line 90 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
virtual |
The destructor cleans up the address space
Definition at line 933 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), PhysicalMemoryManager::instance(), and VirtualAddressSpace::revertToKernelAddressSpace().
|
private |
The default constructor
Definition at line 949 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::allocatePage(), PhysicalMemoryManager::instance(), m_KernelSpace, m_PhysicalPML4, and physicalAddress().
Referenced by getKernelModulesEnd().
|
private |
The constructor for already present paging structures
[in] | Heap | virtual address of the beginning of the heap |
[in] | PhysicalPageDirectory | physical address of the page directory |
[in] | VirtualStack | virtual address of the top of the next kernel stack |
Definition at line 971 of file x64/VirtualAddressSpace.cc.
|
private |
The copy-constructor
|
virtual |
Allocates a single stack for a thread. Will use the default kernel thread size.
Implements VirtualAddressSpace.
Definition at line 809 of file x64/VirtualAddressSpace.cc.
|
virtual |
Allocates a single stack of the given size for a thread.
Reimplemented from VirtualAddressSpace.
Definition at line 818 of file x64/VirtualAddressSpace.cc.
References VirtualAddressSpace::allocateStack().
|
virtual |
Clone this VirtualAddressSpace. That means that we copy-on-write-map the application * image. *
[in] | copyOnWrite | whether the new address space copies pages on write, or shares them with the parent address space. |
Implements VirtualAddressSpace.
Definition at line 474 of file x64/VirtualAddressSpace.cc.
References Vector< T >::begin(), VirtualAddressSpace::create(), PhysicalMemoryManager::instance(), Processor::invalidate(), m_freeStacks, VirtualAddressSpace::m_Heap, VirtualAddressSpace::m_HeapEnd, m_Lock, m_pStackTop, m_StacksLock, mapUnlocked(), physicalAddress(), PhysicalMemoryManager::pin(), Vector< T >::pushBack(), and WARNING.
|
private |
Allocate and map the table entry if none is present
[in] | tableEntry | pointer to the current table entry |
[in] | flags | flags that are used for the mapping |
Definition at line 1192 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::allocatePage(), ERROR, PhysicalMemoryManager::getPageSize(), PhysicalMemoryManager::instance(), physicalAddress(), and toFlags().
Referenced by getKernelModulesEnd().
|
private |
map the table entry if none is present
[in] | tableEntry | pointer to the current table entry |
[in] | physAddress | physical address of the page used as the table |
[in] | flags | flags that are used for the mapping |
Definition at line 1233 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::getPageSize(), physicalAddress(), and toFlags().
Referenced by getKernelModulesEnd().
|
private |
Allocates a stack with a given size.
Definition at line 826 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::allocatePage(), VirtualAddressSpace::CopyOnWrite, PhysicalMemoryManager::getPageSize(), PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, VirtualAddressSpace::map(), PhysicalMemoryManager::pin(), WARNING, and VirtualAddressSpace::Write.
Referenced by getKernelModulesEnd().
|
virtual |
Frees a stack allocated with allocateStack.
Implements VirtualAddressSpace.
Definition at line 903 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), and VirtualAddressSpace::unmap().
|
private |
Convert processor's representation of the flags to the processor independant representation
[in] | Flags | the processor specific flag representation |
[in] | bFinal | whether this is for the actual page or just an intermediate PTE/PDE |
Definition at line 1161 of file x64/VirtualAddressSpace.cc.
References VirtualAddressSpace::Accessed, VirtualAddressSpace::CacheDisable, VirtualAddressSpace::CopyOnWrite, VirtualAddressSpace::Dirty, VirtualAddressSpace::Execute, VirtualAddressSpace::KernelMode, VirtualAddressSpace::Shared, VirtualAddressSpace::Swapped, VirtualAddressSpace::Write, VirtualAddressSpace::WriteCombine, and VirtualAddressSpace::WriteThrough.
Referenced by getKernelModulesEnd().
|
inlinevirtual |
Gets address of the end of dynamic memory mapping area.
Reimplemented from VirtualAddressSpace.
Definition at line 194 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the dynamic linker in the address space.
Implements VirtualAddressSpace.
Definition at line 169 of file kernel/core/processor/x64/VirtualAddressSpace.h.
References USERSPACE_DYNAMIC_LINKER_LOCATION.
|
inlinevirtual |
Gets address of the start of dynamic memory mapping area.
Reimplemented from VirtualAddressSpace.
Definition at line 188 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
virtual |
Gets a pointer to the byte after the end of the heap.
Implements VirtualAddressSpace.
Definition at line 133 of file x64/VirtualAddressSpace.cc.
References VirtualAddressSpace::m_Heap, and VirtualAddressSpace::m_HeapEnd.
|
inlinevirtual |
Gets address of the global info block location.
Reimplemented from VirtualAddressSpace.
Definition at line 200 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the end of the kernel's cache region.
Implements VirtualAddressSpace.
Definition at line 212 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the start of the kernel's cache region.
Implements VirtualAddressSpace.
Definition at line 206 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the start of the kernel's event handling block.
Implements VirtualAddressSpace.
Definition at line 219 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the end of the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 181 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the start of the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 175 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the end of the kernel's module region.
Implements VirtualAddressSpace.
Definition at line 231 of file kernel/core/processor/x64/VirtualAddressSpace.h.
References conditionalTableEntryAllocation(), conditionalTableEntryMapping(), doAllocateStack(), fromFlags(), getPageTableEntry(), mapUnlocked(), maybeFreeTables(), operator=(), PURE, toFlags(), unmapUnlocked(), and X64VirtualAddressSpace().
|
inlinevirtual |
Gets address of the start of the kernel's module region.
Implements VirtualAddressSpace.
Definition at line 225 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets start address of the kernel in the address space.
Implements VirtualAddressSpace.
Definition at line 151 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
virtual |
Get the physical address and the flags associated with the specific virtual address.
[in] | virtualAddress | the address in the virtual address space |
[out] | flags | the flags |
[out] | physicalAddress | the physical address |
Implements VirtualAddressSpace.
Definition at line 398 of file x64/VirtualAddressSpace.cc.
References panic().
|
private |
Get the page table entry, if it exists and check whether a page is mapped or marked as swapped out.
[in] | virtualAddress | the virtual address |
[out] | pageTableEntry | pointer to the page table entry |
Definition at line 979 of file x64/VirtualAddressSpace.cc.
References m_PhysicalPML4.
Referenced by getKernelModulesEnd().
|
inlinevirtual |
Gets start address of reserved areas of the userpace address space.
Implements VirtualAddressSpace.
Definition at line 163 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
inlinevirtual |
Gets start address of the region usable and cloneable for userspace.
Implements VirtualAddressSpace.
Definition at line 157 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
virtual |
Is a particular virtual address valid?
[in] | virtualAddress | the virtual address to check |
Implements VirtualAddressSpace.
Definition at line 147 of file x64/VirtualAddressSpace.cc.
|
virtual |
Checks whether a mapping the the specific virtual address exists. Pages marked as swapped out are not considered mapped.
[in] | virtualAddress | the virtual address |
Implements VirtualAddressSpace.
Definition at line 156 of file x64/VirtualAddressSpace.cc.
Referenced by X86CommonPhysicalMemoryManager::PageStack::maybeMap().
|
virtual |
Map a specific physical page (of size PhysicalMemoryManager::getPageSize()) at a specific location into the virtual address space.
[in] | physicalAddress | the address of the physical page that should be mapped into the virtual address space. |
[in] | virtualAddress | the virtual address at which the page apears within the virtual address space. |
[in] | flags | flags that describe which accesses should be allowed on the page. |
Implements VirtualAddressSpace.
Definition at line 197 of file x64/VirtualAddressSpace.cc.
|
virtual |
Map a region of memory using the largest possible frame size. Where possible the largest page size should be used, degrading into smaller page sizes as needed (e.g. 1 GB, 2 MB, 4K) to reduce the overhead of the mapping on the system. Default implementation calls map() in a loop.
Reimplemented from VirtualAddressSpace.
Definition at line 205 of file x64/VirtualAddressSpace.cc.
References Processor::cpuid(), PhysicalMemoryManager::getPageSize(), and VirtualAddressSpace::mapHuge().
bool X64VirtualAddressSpace::mapPageStructures | ( | physical_uintptr_t | physAddress, |
void * | virtualAddress, | ||
size_t | flags | ||
) |
Map the page directory pointer table, the page directory, the page table or the page frame if none is currently present
[in] | physAddress | the physical page that should be used as page table or page frame |
[in] | virtualAddress | the virtual address that should be checked for the existance of a page directory pointer table, page directory, page table or page frame |
[in] | flags | the flags used for the mapping |
Definition at line 718 of file x64/VirtualAddressSpace.cc.
Referenced by X86CommonPhysicalMemoryManager::PageStack::maybeMap().
|
private |
Perform a mapping proper, without taking the lock.
[in] | locked | whether the lock was taken before calling or not. |
Definition at line 302 of file x64/VirtualAddressSpace.cc.
References Process::getAddressSpace(), Scheduler::getNumProcesses(), Scheduler::getProcess(), Scheduler::instance(), Processor::invalidate(), Processor::m_Initialised, and m_PhysicalPML4.
Referenced by clone(), and getKernelModulesEnd().
|
private |
Possibly cleans up tables for the given address.
This is used when unmapping pages to opportunistically unmap paging structures that are no longer necessary.
[in] | virtualAddress | the virtual address |
[out] | pageTableEntry | pointer to the page table entry |
Definition at line 1021 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), PhysicalMemoryManager::instance(), and m_PhysicalPML4.
Referenced by getKernelModulesEnd().
|
virtual |
Determines if a given point is within the virtual address space region dedicated to the kernel heap.
Implements VirtualAddressSpace.
Definition at line 116 of file x64/VirtualAddressSpace.cc.
References VirtualAddressSpace::getEndOfHeap(), VirtualAddressSpace::m_Heap, and WARNING.
|
virtual |
Determines whether a given address is within the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 101 of file x64/VirtualAddressSpace.cc.
|
private |
The copy-constructor
Referenced by getKernelModulesEnd().
|
virtual |
Undo a clone() - this happens when an application is Exec()'d - we destroy all mappings not in the kernel address space so the space is 'clean'.
Implements VirtualAddressSpace.
Definition at line 625 of file x64/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), PhysicalMemoryManager::instance(), Processor::invalidate(), VirtualAddressSpace::m_Heap, VirtualAddressSpace::m_HeapEnd, and physicalAddress().
|
virtual |
Set the flags of the page at a specific virtual address.
[in] | virtualAddress | the virtual address |
[in] | newFlags | the flags |
Implements VirtualAddressSpace.
Definition at line 414 of file x64/VirtualAddressSpace.cc.
References Processor::invalidate(), and panic().
|
private |
Convert the processor independant flags to the processor's representation of the flags
[in] | flags | the processor independant flag representation |
[in] | bFinal | whether this is for the actual page or just an intermediate PTE/PDE |
Definition at line 1124 of file x64/VirtualAddressSpace.cc.
References VirtualAddressSpace::Accessed, VirtualAddressSpace::CacheDisable, VirtualAddressSpace::ClearDirty, VirtualAddressSpace::CopyOnWrite, VirtualAddressSpace::Dirty, VirtualAddressSpace::Execute, VirtualAddressSpace::KernelMode, VirtualAddressSpace::Shared, VirtualAddressSpace::Swapped, VirtualAddressSpace::Write, VirtualAddressSpace::WriteCombine, and VirtualAddressSpace::WriteThrough.
Referenced by conditionalTableEntryAllocation(), conditionalTableEntryMapping(), and getKernelModulesEnd().
|
virtual |
Remove the page at the specific virtual address from the virtual address space.
[in] | virtualAddress | the virtual address |
Implements VirtualAddressSpace.
Definition at line 433 of file x64/VirtualAddressSpace.cc.
|
private |
Perform an unmap without taking the lock.
Definition at line 440 of file x64/VirtualAddressSpace.cc.
References Processor::invalidate(), and panic().
Referenced by getKernelModulesEnd().
|
friend |
Multiprocessor::initialise() needs access to m_PhysicalPML4
Definition at line 95 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
friend |
Processor::switchAddressSpace() needs access to m_PhysicalPML4
Definition at line 93 of file kernel/core/processor/x64/VirtualAddressSpace.h.
|
friend |
VirtualAddressSpace::create needs access to the constructor
VirtualAddressSpace::getKernelAddressSpace() needs access to m_KernelSpace
|
private |
Is this the kernel space?
Definition at line 320 of file kernel/core/processor/x64/VirtualAddressSpace.h.
List of free stacks
Definition at line 318 of file kernel/core/processor/x64/VirtualAddressSpace.h.
Referenced by clone().
|
staticprivate |
The kernel virtual address space
Definition at line 327 of file kernel/core/processor/x64/VirtualAddressSpace.h.
Referenced by X64VirtualAddressSpace().
|
private |
Lock to guard against multiprocessor reentrancy.
Definition at line 322 of file kernel/core/processor/x64/VirtualAddressSpace.h.
Referenced by clone().
|
private |
Physical address of the Page Map Level 4
Definition at line 314 of file kernel/core/processor/x64/VirtualAddressSpace.h.
Referenced by getPageTableEntry(), mapUnlocked(), maybeFreeTables(), and X64VirtualAddressSpace().
|
private |
Current top of the stacks
Definition at line 316 of file kernel/core/processor/x64/VirtualAddressSpace.h.
Referenced by clone().
|
private |
Lock to guard against multiprocessor reentrancy for stack reuse.
Definition at line 324 of file kernel/core/processor/x64/VirtualAddressSpace.h.
Referenced by clone().