The Pedigree Project
0.1
|
#include <VirtualAddressSpace.h>
Classes | |
struct | mapping_t |
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 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 | memIsInHeap (void *pMem) |
virtual void * | getEndOfHeap () |
virtual VirtualAddressSpace * | clone (bool copyOnWrite=true) |
virtual void | revertToKernelAddressSpace () |
virtual | ~HostedVirtualAddressSpace () |
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 | 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 bool | mapHuge (physical_uintptr_t physAddress, void *virtualAddress, size_t count, size_t flags) |
virtual | ~VirtualAddressSpace () |
void | setHeap (void *heap, void *heapEnd) |
virtual bool | memIsInKernelHeap (void *pMem)=0 |
virtual uintptr_t | getGlobalInfoBlock () const |
Private Member Functions | |
HostedVirtualAddressSpace () | |
HostedVirtualAddressSpace (void *Heap, void *VirtualStack) | |
HostedVirtualAddressSpace (const HostedVirtualAddressSpace &) | |
HostedVirtualAddressSpace & | operator= (const HostedVirtualAddressSpace &) |
uint64_t | toFlags (size_t flags, bool bFinal=false) |
size_t | fromFlags (uint64_t Flags, bool bFinal=false) |
Stack * | doAllocateStack (size_t sSize) |
Static Private Member Functions | |
static void | switchAddressSpace (VirtualAddressSpace &oldSpace, VirtualAddressSpace &newSpace) |
Private Attributes | |
void * | m_pStackTop |
Vector< Stack * > | m_freeStacks |
bool | m_bKernelSpace |
Spinlock | m_Lock |
mapping_t * | m_pKnownMaps |
size_t | m_KnownMapsSize |
size_t | m_numKnownMaps |
size_t | m_nLastUnmap |
Static Private Attributes | |
static HostedVirtualAddressSpace | 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 HostedVirtualAddressSpace implements the VirtualAddressSpace class for the x64 processor architecture, that means it wraps around the processor's paging functionality.
Definition at line 68 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
virtual |
The destructor cleans up the address space
Definition at line 528 of file hosted/VirtualAddressSpace.cc.
|
private |
The default constructor
Definition at line 534 of file hosted/VirtualAddressSpace.cc.
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 542 of file hosted/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 409 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getKernelAddressSpace().
|
virtual |
Allocates a single stack of the given size for a thread.
Reimplemented from VirtualAddressSpace.
Definition at line 418 of file hosted/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 316 of file hosted/VirtualAddressSpace.cc.
References Vector< T >::begin(), VirtualAddressSpace::CopyOnWrite, VirtualAddressSpace::create(), PhysicalMemoryManager::instance(), m_freeStacks, VirtualAddressSpace::m_Heap, VirtualAddressSpace::m_HeapEnd, m_KnownMapsSize, m_nLastUnmap, m_numKnownMaps, m_pKnownMaps, m_pStackTop, NOTICE, PhysicalMemoryManager::pin(), Vector< T >::pushBack(), VirtualAddressSpace::Shared, and VirtualAddressSpace::Write.
|
private |
Allocates a stack with a given size.
Definition at line 426 of file hosted/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 501 of file hosted/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 564 of file hosted/VirtualAddressSpace.cc.
Referenced by getKernelModulesEnd().
|
inlinevirtual |
Gets address of the end of dynamic memory mapping area.
Reimplemented from VirtualAddressSpace.
Definition at line 150 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the dynamic linker in the address space.
Implements VirtualAddressSpace.
Definition at line 125 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
References USERSPACE_DYNAMIC_LINKER_LOCATION.
|
inlinevirtual |
Gets address of the start of dynamic memory mapping area.
Reimplemented from VirtualAddressSpace.
Definition at line 144 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
virtual |
Gets a pointer to the byte after the end of the heap.
Implements VirtualAddressSpace.
Definition at line 83 of file hosted/VirtualAddressSpace.cc.
|
inlinevirtual |
Gets address of the end of the kernel's cache region.
Implements VirtualAddressSpace.
Definition at line 162 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the start of the kernel's cache region.
Implements VirtualAddressSpace.
Definition at line 156 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the start of the kernel's event handling block.
Implements VirtualAddressSpace.
Definition at line 169 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the end of the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 137 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the start of the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 131 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets address of the end of the kernel's module region.
Implements VirtualAddressSpace.
Definition at line 181 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
References doAllocateStack(), fromFlags(), HostedVirtualAddressSpace(), operator=(), switchAddressSpace(), and toFlags().
|
inlinevirtual |
Gets address of the start of the kernel's module region.
Implements VirtualAddressSpace.
Definition at line 175 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets start address of the kernel in the address space.
Implements VirtualAddressSpace.
Definition at line 107 of file kernel/core/processor/hosted/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 218 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getKernelAddressSpace(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), VirtualAddressSpace::isMapped(), page_align(), and panic().
|
inlinevirtual |
Gets start address of reserved areas of the userpace address space.
Implements VirtualAddressSpace.
Definition at line 119 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
inlinevirtual |
Gets start address of the region usable and cloneable for userspace.
Implements VirtualAddressSpace.
Definition at line 113 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
virtual |
Is a particular virtual address valid?
[in] | virtualAddress | the virtual address to check |
Implements VirtualAddressSpace.
Definition at line 88 of file hosted/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 96 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), VirtualAddressSpace::isMapped(), and page_align().
Referenced by switchAddressSpace().
|
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 129 of file hosted/VirtualAddressSpace.cc.
References assert, VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), HostedPhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::KernelMode, VirtualAddressSpace::map(), page_align(), panic(), and UNLIKELY.
|
virtual |
Determines if a given point is within the virtual address space region dedicated to the kernel heap.
Implements VirtualAddressSpace.
Definition at line 73 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getEndOfHeap().
|
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 380 of file hosted/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::Shared, and VirtualAddressSpace::Swapped.
|
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 255 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::KernelMode, page_align(), VirtualAddressSpace::setFlags(), and WARNING.
|
staticprivate |
Switch address spaces.
Definition at line 569 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), HostedPhysicalMemoryManager::instance(), isMapped(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::KernelMode, m_KnownMapsSize, m_pKnownMaps, and toFlags().
Referenced by getKernelModulesEnd(), and Processor::jumpUser().
|
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 550 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::Execute, VirtualAddressSpace::Swapped, and VirtualAddressSpace::Write.
Referenced by getKernelModulesEnd(), and switchAddressSpace().
|
virtual |
Remove the page at the specific virtual address from the virtual address space.
[in] | virtualAddress | the virtual address |
Implements VirtualAddressSpace.
Definition at line 287 of file hosted/VirtualAddressSpace.cc.
References VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), VirtualAddressSpace::isMapped(), page_align(), and VirtualAddressSpace::unmap().
|
friend |
Multiprocessor::initialise() needs access to m_PhysicalPML4
Definition at line 73 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
friend |
Processor::switchAddressSpace() needs access to m_PhysicalPML4
Definition at line 71 of file kernel/core/processor/hosted/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 238 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
List of free stacks
Definition at line 236 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
Referenced by clone().
|
private |
Tracks the size of the known mappings list.
Definition at line 244 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
Referenced by clone(), and switchAddressSpace().
|
private |
Lock to guard against multiprocessor reentrancy.
Definition at line 240 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
|
private |
Last unmap for easier finding of places to fit entries.
Definition at line 248 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
Referenced by clone().
|
private |
Tracks the number of known mappings we have.
Definition at line 246 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
Referenced by clone().
|
private |
Tracks the current mappings made in this address space.
Definition at line 242 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
Referenced by clone(), and switchAddressSpace().
|
private |
Current top of the stacks
Definition at line 234 of file kernel/core/processor/hosted/VirtualAddressSpace.h.
Referenced by clone().