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 physicalAddress, void *virtualAddress, size_t flags) |
virtual void | getMapping (void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags) |
virtual void | setFlags (void *virtualAddress, size_t newFlags) |
virtual void | unmap (void *virtualAddress) |
virtual void * | allocateStack () |
virtual void * | allocateStack (size_t stackSz) |
virtual void | freeStack (void *pStack) |
virtual bool | memIsInHeap (void *pMem) |
virtual void * | getEndOfHeap () |
virtual VirtualAddressSpace * | clone () |
virtual void | revertToKernelAddressSpace () |
bool | mapPageStructures (physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags) |
virtual | ~X86VirtualAddressSpace () |
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 |
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 void | freeStack (Stack *pStack)=0 |
virtual VirtualAddressSpace * | clone (bool copyOnWrite=true)=0 |
virtual | ~VirtualAddressSpace () |
void | setHeap (void *heap, void *heapEnd) |
virtual bool | memIsInKernelHeap (void *pMem)=0 |
virtual uintptr_t | getKernelCacheStart () const =0 |
virtual uintptr_t | getKernelCacheEnd () const =0 |
virtual uintptr_t | getKernelEventBlockStart () const =0 |
virtual uintptr_t | getKernelModulesStart () const =0 |
virtual uintptr_t | getKernelModulesEnd () const =0 |
virtual uintptr_t | getDynamicStart () const |
virtual uintptr_t | getDynamicEnd () const |
virtual uintptr_t | getGlobalInfoBlock () const |
Static Public Member Functions | |
static void | initialise () INITIALISATION_ONLY |
Static Public Member Functions inherited from VirtualAddressSpace | |
static EXPORTED_PUBLIC VirtualAddressSpace & | getKernelAddressSpace () |
static VirtualAddressSpace * | create () |
Protected Member Functions | |
X86VirtualAddressSpace (void *Heap, physical_uintptr_t PhysicalPageDirectory, void *VirtualPageDirectory, void *VirtualPageTables, void *VirtualStack) INITIALISATION_ONLY | |
bool | doIsMapped (void *virtualAddress) |
bool | doMap (physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags) |
void | doGetMapping (void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags) |
void | doSetFlags (void *virtualAddress, size_t newFlags) |
void | doUnmap (void *virtualAddress) |
void * | doAllocateStack (size_t sSize) |
Protected Member Functions inherited from VirtualAddressSpace | |
VirtualAddressSpace (void *Heap) | |
Private Member Functions | |
X86VirtualAddressSpace () | |
X86VirtualAddressSpace (const X86VirtualAddressSpace &) | |
X86VirtualAddressSpace & | operator= (const X86VirtualAddressSpace &) |
bool | getPageTableEntry (void *virtualAddress, uint32_t *&pageTableEntry) |
uint32_t | toFlags (size_t flags, bool bFinal=false) |
size_t | fromFlags (uint32_t Flags, bool bFinal=false) |
uintptr_t | beginCrossSpace (X86VirtualAddressSpace *pOther) |
bool | mapCrossSpace (uintptr_t &v, physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags) |
void | endCrossSpace () |
Private Attributes | |
physical_uintptr_t | m_PhysicalPageDirectory |
void * | m_VirtualPageDirectory |
void * | m_VirtualPageTables |
void * | m_pStackTop |
Vector< void * > | m_freeStacks |
Spinlock | m_Lock |
Friends | |
class | Processor |
class | Multiprocessor |
VirtualAddressSpace * | VirtualAddressSpace::create () |
Additional Inherited Members | |
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 |
The X86VirtualAddressSpace implements the VirtualAddressSpace class for the x86 processor architecture, that means it wraps around the processor's paging functionality.
Definition at line 61 of file kernel/core/processor/x86/VirtualAddressSpace.h.
|
virtual |
The destructor cleans up the address space
Definition at line 217 of file x86/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), Processor::information(), PhysicalMemoryManager::instance(), and Processor::switchAddressSpace().
|
protected |
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] | VirtualPageDirectory | virtual address of the page directory |
[in] | VirtualPageTables | virtual address of the page tables |
[in] | VirtualStack | virtual address of the next stacks |
Definition at line 298 of file x86/VirtualAddressSpace.cc.
References PhysicalMemoryManager::allocatePage(), Vector< T >::count(), FATAL, fromFlags(), Process::getAddressSpace(), VirtualAddressSpace::getKernelAddressSpace(), Scheduler::getNumProcesses(), PhysicalMemoryManager::getPageSize(), getPageTableEntry(), Scheduler::getProcess(), Processor::id(), Processor::information(), Scheduler::instance(), PhysicalMemoryManager::instance(), Processor::invalidate(), m_freeStacks, Processor::m_Initialised, m_Lock, m_pStackTop, m_VirtualPageDirectory, m_VirtualPageTables, map(), panic(), physicalAddress(), Vector< T >::popBack(), Processor::switchAddressSpace(), toFlags(), WARNING, and VirtualAddressSpace::Write.
|
private |
The default constructor
Definition at line 243 of file x86/VirtualAddressSpace.cc.
References PhysicalMemoryManager::allocatePage(), Processor::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, m_PhysicalPageDirectory, m_VirtualPageDirectory, VirtualAddressSpace::map(), VirtualAddressSpace::unmap(), and VirtualAddressSpace::Write.
Referenced by getKernelHeapEnd().
|
private |
The copy-constructor
|
virtual |
Allocates a single stack for a thread. Will use the default kernel thread size.
Implements VirtualAddressSpace.
Reimplemented in X86KernelVirtualAddressSpace.
Definition at line 159 of file x86/VirtualAddressSpace.cc.
|
virtual |
Allocates a single stack of the given size for a thread.
Reimplemented from VirtualAddressSpace.
Definition at line 165 of file x86/VirtualAddressSpace.cc.
|
private |
Begins a "cross-address-space" transaction; maps this address space's page directory and a page table in temporarily to the current address space, to be used with mapCrossSpace.
This uses the pages "KERNEL_VIRTUAL_TEMP2" and "KERNEL_VIRTUAL_TEMP3".
Definition at line 806 of file x86/VirtualAddressSpace.cc.
References VirtualAddressSpace::KernelMode, m_PhysicalPageDirectory, map(), and VirtualAddressSpace::Write.
Referenced by fromFlags(), and getKernelHeapEnd().
|
private |
Called to end a cross-space transaction.
Definition at line 878 of file x86/VirtualAddressSpace.cc.
References unmap().
Referenced by fromFlags(), and getKernelHeapEnd().
|
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 602 of file x86/VirtualAddressSpace.cc.
References VirtualAddressSpace::Accessed, Vector< T >::begin(), beginCrossSpace(), VirtualAddressSpace::CacheDisable, VirtualAddressSpace::CopyOnWrite, VirtualAddressSpace::create(), VirtualAddressSpace::Dirty, Vector< T >::end(), endCrossSpace(), VirtualAddressSpace::Execute, Processor::information(), PhysicalMemoryManager::instance(), Processor::invalidate(), VirtualAddressSpace::KernelMode, m_freeStacks, VirtualAddressSpace::m_Heap, VirtualAddressSpace::m_HeapEnd, m_Lock, m_pStackTop, m_VirtualPageDirectory, m_VirtualPageTables, mapCrossSpace(), physicalAddress(), PhysicalMemoryManager::pin(), Vector< T >::pushBack(), VirtualAddressSpace::Shared, VirtualAddressSpace::Swapped, WARNING, VirtualAddressSpace::Write, VirtualAddressSpace::WriteCombine, and VirtualAddressSpace::WriteThrough.
Referenced by getKernelHeapEnd(), and X86VirtualAddressSpace().
|
inlinevirtual |
Gets address of the dynamic linker in the address space.
Implements VirtualAddressSpace.
Definition at line 134 of file kernel/core/processor/x86/VirtualAddressSpace.h.
References USERSPACE_DYNAMIC_LINKER_LOCATION.
|
virtual |
Gets a pointer to the byte after the end of the heap.
Implements VirtualAddressSpace.
Definition at line 98 of file x86/VirtualAddressSpace.cc.
|
inlinevirtual |
Gets address of the end of the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 146 of file kernel/core/processor/x86/VirtualAddressSpace.h.
References beginCrossSpace(), endCrossSpace(), fromFlags(), getPageTableEntry(), INITIALISATION_ONLY, mapCrossSpace(), operator=(), physicalAddress(), toFlags(), and X86VirtualAddressSpace().
|
inlinevirtual |
Gets address of the start of the kernel's heap region.
Implements VirtualAddressSpace.
Definition at line 140 of file kernel/core/processor/x86/VirtualAddressSpace.h.
|
inlinevirtual |
Gets start address of the kernel in the address space.
Implements VirtualAddressSpace.
Definition at line 116 of file kernel/core/processor/x86/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.
Reimplemented in X86KernelVirtualAddressSpace.
Definition at line 129 of file x86/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 541 of file x86/VirtualAddressSpace.cc.
References m_VirtualPageDirectory, and m_VirtualPageTables.
Referenced by getKernelHeapEnd(), and X86VirtualAddressSpace().
|
inlinevirtual |
Gets start address of reserved areas of the userpace address space.
Implements VirtualAddressSpace.
Definition at line 128 of file kernel/core/processor/x86/VirtualAddressSpace.h.
|
inlinevirtual |
Gets start address of the region usable and cloneable for userspace.
Implements VirtualAddressSpace.
Definition at line 122 of file kernel/core/processor/x86/VirtualAddressSpace.h.
|
static |
Initialise the static members of VirtualAddressSpace
|
virtual |
Is a particular virtual address valid?
[in] | virtualAddress | the virtual address to check |
Implements VirtualAddressSpace.
Definition at line 105 of file x86/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.
Reimplemented in X86KernelVirtualAddressSpace.
Definition at line 109 of file x86/VirtualAddressSpace.cc.
References panic().
|
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.
Reimplemented in X86KernelVirtualAddressSpace.
Definition at line 119 of file x86/VirtualAddressSpace.cc.
References panic().
Referenced by beginCrossSpace(), mapCrossSpace(), and X86VirtualAddressSpace().
|
private |
The mapping function for cross-space mappings. beginCrossSpace must be called first.
v | Value given by "beginCrossSpace". |
Definition at line 818 of file x86/VirtualAddressSpace.cc.
References PhysicalMemoryManager::allocatePage(), PhysicalMemoryManager::getPageSize(), PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, map(), toFlags(), unmap(), and VirtualAddressSpace::Write.
Referenced by fromFlags(), and getKernelHeapEnd().
bool X86VirtualAddressSpace::mapPageStructures | ( | physical_uintptr_t | physicalAddress, |
void * | virtualAddress, | ||
size_t | flags | ||
) |
Map the page table or the page frame if none is currently present
[in] | physicalAddress | 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 table and page frame |
[in] | flags | the flags used for the mapping |
Definition at line 179 of file x86/VirtualAddressSpace.cc.
References PhysicalMemoryManager::getPageSize().
|
virtual |
Determines if a given point is within the virtual address space region dedicated to the kernel heap.
Implements VirtualAddressSpace.
Definition at line 89 of file x86/VirtualAddressSpace.cc.
References VirtualAddressSpace::getEndOfHeap().
|
private |
The copy-constructor
Referenced by getKernelHeapEnd().
|
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 745 of file x86/VirtualAddressSpace.cc.
References PhysicalMemoryManager::freePage(), PhysicalMemoryManager::instance(), Processor::invalidate(), m_Lock, m_VirtualPageDirectory, m_VirtualPageTables, physicalAddress(), and unmap().
|
virtual |
Set the flags of the page at a specific virtual address.
[in] | virtualAddress | the virtual address |
[in] | newFlags | the flags |
Implements VirtualAddressSpace.
Reimplemented in X86KernelVirtualAddressSpace.
Definition at line 140 of file x86/VirtualAddressSpace.cc.
References 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 568 of file x86/VirtualAddressSpace.cc.
References VirtualAddressSpace::Accessed, VirtualAddressSpace::CacheDisable, VirtualAddressSpace::ClearDirty, VirtualAddressSpace::CopyOnWrite, VirtualAddressSpace::Dirty, VirtualAddressSpace::KernelMode, VirtualAddressSpace::Shared, VirtualAddressSpace::Swapped, VirtualAddressSpace::Write, VirtualAddressSpace::WriteCombine, and VirtualAddressSpace::WriteThrough.
Referenced by getKernelHeapEnd(), mapCrossSpace(), and X86VirtualAddressSpace().
|
virtual |
Remove the page at the specific virtual address from the virtual address space.
[in] | virtualAddress | the virtual address |
Implements VirtualAddressSpace.
Reimplemented in X86KernelVirtualAddressSpace.
Definition at line 150 of file x86/VirtualAddressSpace.cc.
References panic().
Referenced by endCrossSpace(), mapCrossSpace(), and revertToKernelAddressSpace().
|
friend |
Multiprocessor::initialise() needs access to m_PhysicalPageDirectory
Definition at line 67 of file kernel/core/processor/x86/VirtualAddressSpace.h.
|
friend |
Processor::switchAddressSpace() needs access to m_PhysicalPageDirectory
Definition at line 65 of file kernel/core/processor/x86/VirtualAddressSpace.h.
|
friend |
VirtualAddressSpace::create needs access to the constructor
|
private |
List of free stacks
Definition at line 234 of file kernel/core/processor/x86/VirtualAddressSpace.h.
Referenced by fromFlags(), and X86VirtualAddressSpace().
|
private |
Lock to guard against multiprocessor reentrancy.
Definition at line 236 of file kernel/core/processor/x86/VirtualAddressSpace.h.
Referenced by fromFlags(), revertToKernelAddressSpace(), and X86VirtualAddressSpace().
|
private |
Physical address of the page directory
Definition at line 226 of file kernel/core/processor/x86/VirtualAddressSpace.h.
Referenced by beginCrossSpace(), and X86VirtualAddressSpace().
|
private |
Current top of the stacks
Definition at line 232 of file kernel/core/processor/x86/VirtualAddressSpace.h.
Referenced by fromFlags(), and X86VirtualAddressSpace().
|
private |
Virtual address of the page directory
Definition at line 228 of file kernel/core/processor/x86/VirtualAddressSpace.h.
Referenced by fromFlags(), getPageTableEntry(), revertToKernelAddressSpace(), and X86VirtualAddressSpace().
|
private |
Virtual address of the page tables
Definition at line 230 of file kernel/core/processor/x86/VirtualAddressSpace.h.
Referenced by fromFlags(), getPageTableEntry(), revertToKernelAddressSpace(), and X86VirtualAddressSpace().