The Pedigree Project  0.1
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
HostedVirtualAddressSpace Class Reference

#include <VirtualAddressSpace.h>

+ Inheritance diagram for HostedVirtualAddressSpace:
+ Collaboration diagram for HostedVirtualAddressSpace:

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 StackallocateStack ()
 
virtual StackallocateStack (size_t stackSz)
 
virtual void freeStack (Stack *pStack)
 
virtual bool memIsInHeap (void *pMem)
 
virtual void * getEndOfHeap ()
 
virtual VirtualAddressSpaceclone (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 &)
 
HostedVirtualAddressSpaceoperator= (const HostedVirtualAddressSpace &)
 
uint64_t toFlags (size_t flags, bool bFinal=false)
 
size_t fromFlags (uint64_t Flags, bool bFinal=false)
 
StackdoAllocateStack (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_tm_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
 
VirtualAddressSpaceVirtualAddressSpace::getKernelAddressSpace ()
 
VirtualAddressSpaceVirtualAddressSpace::create ()
 

Additional Inherited Members

- Static Public Member Functions inherited from VirtualAddressSpace
static EXPORTED_PUBLIC VirtualAddressSpacegetKernelAddressSpace ()
 
static VirtualAddressSpacecreate ()
 
- 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)
 

Detailed Description

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.

Constructor & Destructor Documentation

HostedVirtualAddressSpace::~HostedVirtualAddressSpace ( )
virtual

The destructor cleans up the address space

Definition at line 528 of file hosted/VirtualAddressSpace.cc.

HostedVirtualAddressSpace::HostedVirtualAddressSpace ( )
private

The default constructor

Definition at line 534 of file hosted/VirtualAddressSpace.cc.

Referenced by getKernelModulesEnd().

+ Here is the caller graph for this function:

HostedVirtualAddressSpace::HostedVirtualAddressSpace ( void *  Heap,
void *  VirtualStack 
)
private

The constructor for already present paging structures

Parameters
[in]Heapvirtual address of the beginning of the heap
[in]PhysicalPageDirectoryphysical address of the page directory
[in]VirtualStackvirtual address of the top of the next kernel stack
Note
This constructor is only used to construct the kernel VirtualAddressSpace

Definition at line 542 of file hosted/VirtualAddressSpace.cc.

HostedVirtualAddressSpace::HostedVirtualAddressSpace ( const HostedVirtualAddressSpace )
private

The copy-constructor

Note
NOT implemented

Member Function Documentation

VirtualAddressSpace::Stack * HostedVirtualAddressSpace::allocateStack ( )
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().

VirtualAddressSpace::Stack * HostedVirtualAddressSpace::allocateStack ( size_t  stackSz)
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().

VirtualAddressSpace * HostedVirtualAddressSpace::clone ( bool  copyOnWrite = true)
virtual

Clone this VirtualAddressSpace. That means that we copy-on-write-map the application * image. *

Parameters
[in]copyOnWritewhether the new address space copies pages on write, or shares them with the parent address space.
Returns
pointer to the new VirtualAddressSpace

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.

VirtualAddressSpace::Stack * HostedVirtualAddressSpace::doAllocateStack ( size_t  sSize)
private
void HostedVirtualAddressSpace::freeStack ( Stack pStack)
virtual
size_t HostedVirtualAddressSpace::fromFlags ( uint64_t  Flags,
bool  bFinal = false 
)
private

Convert processor's representation of the flags to the processor independant representation

Parameters
[in]Flagsthe processor specific flag representation
[in]bFinalwhether this is for the actual page or just an intermediate PTE/PDE
Returns
the proessor independant flag representation

Definition at line 564 of file hosted/VirtualAddressSpace.cc.

Referenced by getKernelModulesEnd().

+ Here is the caller graph for this function:

virtual uintptr_t HostedVirtualAddressSpace::getDynamicEnd ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getDynamicLinkerAddress ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getDynamicStart ( ) const
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.

void * HostedVirtualAddressSpace::getEndOfHeap ( )
virtual

Gets a pointer to the byte after the end of the heap.

Implements VirtualAddressSpace.

Definition at line 83 of file hosted/VirtualAddressSpace.cc.

virtual uintptr_t HostedVirtualAddressSpace::getKernelCacheEnd ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getKernelCacheStart ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getKernelEventBlockStart ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getKernelHeapEnd ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getKernelHeapStart ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getKernelModulesEnd ( ) const
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().

virtual uintptr_t HostedVirtualAddressSpace::getKernelModulesStart ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getKernelStart ( ) const
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.

void HostedVirtualAddressSpace::getMapping ( void *  virtualAddress,
physical_uintptr_t &  physicalAddress,
size_t &  flags 
)
virtual

Get the physical address and the flags associated with the specific virtual address.

Note
This function is only valid on memory that was mapped with VirtualAddressSpace::map() and that is still mapped or marked as swapped out.
Parameters
[in]virtualAddressthe address in the virtual address space
[out]flagsthe flags
[out]physicalAddressthe 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().

virtual uintptr_t HostedVirtualAddressSpace::getUserReservedStart ( ) const
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.

virtual uintptr_t HostedVirtualAddressSpace::getUserStart ( ) const
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.

bool HostedVirtualAddressSpace::isAddressValid ( void *  virtualAddress)
virtual

Is a particular virtual address valid?

Parameters
[in]virtualAddressthe virtual address to check
Returns
true, if the address is valid, false otherwise

Implements VirtualAddressSpace.

Definition at line 88 of file hosted/VirtualAddressSpace.cc.

bool HostedVirtualAddressSpace::isMapped ( void *  virtualAddress)
virtual

Checks whether a mapping the the specific virtual address exists. Pages marked as swapped out are not considered mapped.

Note
This function must be valid on all the valid addresses within the virtual address space.
Parameters
[in]virtualAddressthe virtual address
Returns
true, if a mapping exists, false otherwise

Implements VirtualAddressSpace.

Definition at line 96 of file hosted/VirtualAddressSpace.cc.

References VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), VirtualAddressSpace::isMapped(), and page_align().

Referenced by switchAddressSpace().

+ Here is the caller graph for this function:

bool HostedVirtualAddressSpace::map ( physical_uintptr_t  physicalAddress,
void *  virtualAddress,
size_t  flags 
)
virtual

Map a specific physical page (of size PhysicalMemoryManager::getPageSize()) at a specific location into the virtual address space.

Note
This function must also work on pages marked as swapped out.
Parameters
[in]physicalAddressthe address of the physical page that should be mapped into the virtual address space.
[in]virtualAddressthe virtual address at which the page apears within the virtual address space.
[in]flagsflags that describe which accesses should be allowed on the page.
Returns
true, if successfull, false otherwise

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.

bool HostedVirtualAddressSpace::memIsInHeap ( void *  pMem)
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().

HostedVirtualAddressSpace& HostedVirtualAddressSpace::operator= ( const HostedVirtualAddressSpace )
private

The copy-constructor

Note
Not implemented

Referenced by getKernelModulesEnd().

+ Here is the caller graph for this function:

void HostedVirtualAddressSpace::revertToKernelAddressSpace ( )
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.

void HostedVirtualAddressSpace::setFlags ( void *  virtualAddress,
size_t  newFlags 
)
virtual

Set the flags of the page at a specific virtual address.

Note
The page must have been mapped with VirtualAddressSpace::map() and the page must still be mapped or marked as swapped out.
Parameters
[in]virtualAddressthe virtual address
[in]newFlagsthe 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.

void HostedVirtualAddressSpace::switchAddressSpace ( VirtualAddressSpace oldSpace,
VirtualAddressSpace newSpace 
)
staticprivate
uint64_t HostedVirtualAddressSpace::toFlags ( size_t  flags,
bool  bFinal = false 
)
private

Convert the processor independant flags to the processor's representation of the flags

Parameters
[in]flagsthe processor independant flag representation
[in]bFinalwhether this is for the actual page or just an intermediate PTE/PDE
Returns
the proessor specific flag representation

Definition at line 550 of file hosted/VirtualAddressSpace.cc.

References VirtualAddressSpace::Execute, VirtualAddressSpace::Swapped, and VirtualAddressSpace::Write.

Referenced by getKernelModulesEnd(), and switchAddressSpace().

+ Here is the caller graph for this function:

void HostedVirtualAddressSpace::unmap ( void *  virtualAddress)
virtual

Remove the page at the specific virtual address from the virtual address space.

Note
This function is only valid on memory that was mapped with VirtualAddressSpace::map() and that is still mapped or marked as swapped out.
Parameters
[in]virtualAddressthe 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().

Friends And Related Function Documentation

friend class Multiprocessor
friend

Multiprocessor::initialise() needs access to m_PhysicalPML4

Definition at line 73 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

friend class Processor
friend

Processor::switchAddressSpace() needs access to m_PhysicalPML4

Definition at line 71 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

VirtualAddressSpace::create needs access to the constructor

VirtualAddressSpace::getKernelAddressSpace() needs access to m_KernelSpace

Member Data Documentation

bool HostedVirtualAddressSpace::m_bKernelSpace
private

Is this the kernel space?

Definition at line 238 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

Vector<Stack *> HostedVirtualAddressSpace::m_freeStacks
private

List of free stacks

Definition at line 236 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

Referenced by clone().

size_t HostedVirtualAddressSpace::m_KnownMapsSize
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().

Spinlock HostedVirtualAddressSpace::m_Lock
private

Lock to guard against multiprocessor reentrancy.

Definition at line 240 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

size_t HostedVirtualAddressSpace::m_nLastUnmap
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().

size_t HostedVirtualAddressSpace::m_numKnownMaps
private

Tracks the number of known mappings we have.

Definition at line 246 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

Referenced by clone().

mapping_t* HostedVirtualAddressSpace::m_pKnownMaps
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().

void* HostedVirtualAddressSpace::m_pStackTop
private

Current top of the stacks

Definition at line 234 of file kernel/core/processor/hosted/VirtualAddressSpace.h.

Referenced by clone().


The documentation for this class was generated from the following files: