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

#include <VirtualAddressSpace.h>

+ Inheritance diagram for X86VirtualAddressSpace:
+ Collaboration diagram for X86VirtualAddressSpace:

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 VirtualAddressSpaceclone ()
 
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 VirtualAddressSpaceclone (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 VirtualAddressSpacegetKernelAddressSpace ()
 
static VirtualAddressSpacecreate ()
 

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 &)
 
X86VirtualAddressSpaceoperator= (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
 
VirtualAddressSpaceVirtualAddressSpace::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
 

Detailed Description

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.

Constructor & Destructor Documentation

X86VirtualAddressSpace::~X86VirtualAddressSpace ( )
virtual
X86VirtualAddressSpace::X86VirtualAddressSpace ( void *  Heap,
physical_uintptr_t  PhysicalPageDirectory,
void *  VirtualPageDirectory,
void *  VirtualPageTables,
void *  VirtualStack 
)
protected

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]VirtualPageDirectoryvirtual address of the page directory
[in]VirtualPageTablesvirtual address of the page tables
[in]VirtualStackvirtual address of the next stacks
Note
This constructor is only used to construct the kernel VirtualAddressSpace

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.

X86VirtualAddressSpace::X86VirtualAddressSpace ( )
private
X86VirtualAddressSpace::X86VirtualAddressSpace ( const X86VirtualAddressSpace )
private

The copy-constructor

Note
NOT implemented

Member Function Documentation

void * X86VirtualAddressSpace::allocateStack ( )
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.

void * X86VirtualAddressSpace::allocateStack ( size_t  stackSz)
virtual

Allocates a single stack of the given size for a thread.

Reimplemented from VirtualAddressSpace.

Definition at line 165 of file x86/VirtualAddressSpace.cc.

uintptr_t X86VirtualAddressSpace::beginCrossSpace ( X86VirtualAddressSpace pOther)
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".

Returns
A value to pass to mapCrossSpace. This value contains the current page table mapped into 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().

+ Here is the caller graph for this function:

void X86VirtualAddressSpace::endCrossSpace ( )
private

Called to end a cross-space transaction.

Definition at line 878 of file x86/VirtualAddressSpace.cc.

References unmap().

Referenced by fromFlags(), and getKernelHeapEnd().

+ Here is the caller graph for this function:

size_t X86VirtualAddressSpace::fromFlags ( uint32_t  Flags,
bool  bFinal = false 
)
private
virtual uintptr_t X86VirtualAddressSpace::getDynamicLinkerAddress ( ) const
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.

void * X86VirtualAddressSpace::getEndOfHeap ( )
virtual

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

Implements VirtualAddressSpace.

Definition at line 98 of file x86/VirtualAddressSpace.cc.

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

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

void X86VirtualAddressSpace::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.

Reimplemented in X86KernelVirtualAddressSpace.

Definition at line 129 of file x86/VirtualAddressSpace.cc.

References panic().

bool X86VirtualAddressSpace::getPageTableEntry ( void *  virtualAddress,
uint32_t *&  pageTableEntry 
)
private

Get the page table entry, if it exists and check whether a page is mapped or marked as swapped out.

Parameters
[in]virtualAddressthe virtual address
[out]pageTableEntrypointer to the page table entry
Returns
true, if the page table is present and the page mapped or marked swapped out, false otherwise

Definition at line 541 of file x86/VirtualAddressSpace.cc.

References m_VirtualPageDirectory, and m_VirtualPageTables.

Referenced by getKernelHeapEnd(), and X86VirtualAddressSpace().

+ Here is the caller graph for this function:

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

virtual uintptr_t X86VirtualAddressSpace::getUserStart ( ) const
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 void X86VirtualAddressSpace::initialise ( )
static

Initialise the static members of VirtualAddressSpace

bool X86VirtualAddressSpace::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 105 of file x86/VirtualAddressSpace.cc.

bool X86VirtualAddressSpace::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.

Reimplemented in X86KernelVirtualAddressSpace.

Definition at line 109 of file x86/VirtualAddressSpace.cc.

References panic().

bool X86VirtualAddressSpace::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.

Reimplemented in X86KernelVirtualAddressSpace.

Definition at line 119 of file x86/VirtualAddressSpace.cc.

References panic().

Referenced by beginCrossSpace(), mapCrossSpace(), and X86VirtualAddressSpace().

+ Here is the caller graph for this function:

bool X86VirtualAddressSpace::mapCrossSpace ( uintptr_t &  v,
physical_uintptr_t  physicalAddress,
void *  virtualAddress,
size_t  flags 
)
private

The mapping function for cross-space mappings. beginCrossSpace must be called first.

Parameters
vValue 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().

+ Here is the caller graph for this function:

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

Note
This should only be used from the PhysicalMemoryManager and you have to switch to the VirtualAddressSpace you want to change first.
Parameters
[in]physicalAddressthe physical page that should be used as page table or page frame
[in]virtualAddressthe virtual address that should be checked for the existance of a page table and page frame
[in]flagsthe flags used for the mapping
Returns
true, if a page table/frame is already mapped for that address, false if the physicalAddress has been used as a page table or as a page frame.

Definition at line 179 of file x86/VirtualAddressSpace.cc.

References PhysicalMemoryManager::getPageSize().

bool X86VirtualAddressSpace::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 89 of file x86/VirtualAddressSpace.cc.

References VirtualAddressSpace::getEndOfHeap().

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

The copy-constructor

Note
Not implemented

Referenced by getKernelHeapEnd().

+ Here is the caller graph for this function:

void X86VirtualAddressSpace::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'.

Todo:
When swap system comes along, we want to remove this page from swap!

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().

void X86VirtualAddressSpace::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.

Reimplemented in X86KernelVirtualAddressSpace.

Definition at line 140 of file x86/VirtualAddressSpace.cc.

References panic().

uint32_t X86VirtualAddressSpace::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 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().

+ Here is the caller graph for this function:

void X86VirtualAddressSpace::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.

Reimplemented in X86KernelVirtualAddressSpace.

Definition at line 150 of file x86/VirtualAddressSpace.cc.

References panic().

Referenced by endCrossSpace(), mapCrossSpace(), and revertToKernelAddressSpace().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class Multiprocessor
friend

Multiprocessor::initialise() needs access to m_PhysicalPageDirectory

Definition at line 67 of file kernel/core/processor/x86/VirtualAddressSpace.h.

friend class Processor
friend

Processor::switchAddressSpace() needs access to m_PhysicalPageDirectory

Definition at line 65 of file kernel/core/processor/x86/VirtualAddressSpace.h.

VirtualAddressSpace::create needs access to the constructor

Member Data Documentation

Vector<void *> X86VirtualAddressSpace::m_freeStacks
private

List of free stacks

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

Referenced by fromFlags(), and X86VirtualAddressSpace().

Spinlock X86VirtualAddressSpace::m_Lock
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().

physical_uintptr_t X86VirtualAddressSpace::m_PhysicalPageDirectory
private

Physical address of the page directory

Definition at line 226 of file kernel/core/processor/x86/VirtualAddressSpace.h.

Referenced by beginCrossSpace(), and X86VirtualAddressSpace().

void* X86VirtualAddressSpace::m_pStackTop
private

Current top of the stacks

Definition at line 232 of file kernel/core/processor/x86/VirtualAddressSpace.h.

Referenced by fromFlags(), and X86VirtualAddressSpace().

void* X86VirtualAddressSpace::m_VirtualPageDirectory
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().

void* X86VirtualAddressSpace::m_VirtualPageTables
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().


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