IBNOS
Classes | Macros | Functions | Variables
Paging

Classes

struct  pagingEntry
 
struct  userMemory
 

Macros

#define PAGETABLE_SIZE   0x1000
 
#define PAGETABLE_MASK   0x3FF
 
#define PAGETABLE_BITS   10
 
#define PAGETABLE_COUNT   0x400
 

Functions

struct pagingEntry __attribute__ ((packed))
 
void pagingInsertBootMap (uint32_t startIndex, uint32_t stopIndex)
 Appends a specific range of physical pages to the bootmap. More...
 
void pagingDumpBootMap ()
 Dumps a list of all entries in the boot map. More...
 
void pagingInit ()
 Initializes paging. More...
 
void pagingDumpPageTable (struct process *p)
 Dumps information about the page table of a specific process. More...
 
void pagingReserveArea (struct process *p, void *addr, uint32_t length, bool user)
 Marks the memory in a specific memory area as reserved. More...
 
void * pagingSearchArea (struct process *p, uint32_t length)
 Searches for a consecutive area of length free pages in a process. More...
 
void * pagingTrySearchArea (struct process *p, uint32_t length)
 Searches for a consecutive area of length free pages in a process. More...
 
void * pagingAllocatePhysMem (struct process *p, uint32_t length, bool rw, bool user)
 Allocates several pages of physical memory in a process. More...
 
void * pagingAllocatePhysMemUnpageable (struct process *p, uint32_t length, bool rw, bool user)
 Allocates several pages of unpageable physical memory in a process. More...
 
void * pagingTryAllocatePhysMem (struct process *p, uint32_t length, bool rw, bool user)
 Tries to allocates several pages of physical memory in a process. More...
 
void * pagingAllocatePhysMemFixed (struct process *p, void *addr, uint32_t length, bool rw, bool user)
 Allocates several pages of physical memory at a fixed virtual address in a process. More...
 
void * pagingAllocatePhysMemFixedUnpageable (struct process *p, void *addr, uint32_t length, bool rw, bool user)
 Allocates several pages of unpageable physical memory at a fixed virtual address in a process. More...
 
void * pagingTryAllocatePhysMemFixed (struct process *p, void *addr, uint32_t length, bool rw, bool user)
 Allocates several pages of unpageable physical memory at a fixed virtual address in a process. More...
 
void * pagingReAllocatePhysMem (struct process *p, void *addr, uint32_t old_length, uint32_t new_length, bool rw, bool user)
 Reallocates a specific range of virtual memory in a process. More...
 
void pagingReleasePhysMem (struct process *p, void *addr, uint32_t length)
 Releases several pages of physical memory in a process. More...
 
bool pagingTryReleasePhysMem (struct process *p, void *addr, uint32_t length)
 Releases several pages of physical memory of a process. More...
 
bool pagingTryReleaseUserMem (struct process *p, void *addr, uint32_t length)
 Releases several pages of physical memory of a process. More...
 
uint32_t pagingGetPhysMem (struct process *p, void *addr)
 Returns the physical page index for a virtual address. More...
 
void * pagingMapRemoteMemory (struct process *dst_p, struct process *src_p, void *dst_addr, void *src_addr, uint32_t length, bool rw, bool user)
 Maps some virtual memory from one process to another one. More...
 
void * pagingTryMapUserMem (struct process *src_p, void *src_addr, uint32_t length, bool rw)
 Maps some virtual memory of a usermode process into the kernel. More...
 
void pagingAllocProcessPageTable (struct process *p)
 Allocates the page directory and page table for a specific process. More...
 
void pagingForkProcessPageTable (struct process *destination, struct process *source)
 Duplicate a page table and assigns it to a destination process. More...
 
void pagingReleaseProcessPageTable (struct process *p)
 Releases the page directory and page table of a specific process. More...
 
void pagingFillProcessInfo (struct process *p, struct processInfo *info)
 Fills out all memory related fields in the processInfo structure. More...
 

Variables

struct userMemory __attribute__
 

Detailed Description

Macro Definition Documentation

◆ PAGETABLE_BITS

#define PAGETABLE_BITS   10

Definition at line 37 of file paging.h.

◆ PAGETABLE_COUNT

#define PAGETABLE_COUNT   0x400

Definition at line 38 of file paging.h.

◆ PAGETABLE_MASK

#define PAGETABLE_MASK   0x3FF

Definition at line 36 of file paging.h.

◆ PAGETABLE_SIZE

#define PAGETABLE_SIZE   0x1000

Definition at line 35 of file paging.h.

Function Documentation

◆ __attribute__()

struct pagingEntry __attribute__ ( (packed)  )

◆ pagingAllocatePhysMem()

void* pagingAllocatePhysMem ( struct process p,
uint32_t  length,
bool  rw,
bool  user 
)

Allocates several pages of physical memory in a process.

This function first searches for a free range of consecutive virtual memory pages. Afterwards it maps these entries to physical memory and sets the access permissions based on the provided arguments. If the virtual address space is exhausted an exception is thrown, so only use this command if its very critical. For non-critical purposes use pagingTryAllocatePhysMem().

Parameters
pPointer to a process object or NULL for the kernel
lengthNumber of consecutive pages which have to be unused
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the allocated memory block (inside of the process)

Definition at line 659 of file paging.c.

◆ pagingAllocatePhysMemFixed()

void* pagingAllocatePhysMemFixed ( struct process p,
void *  addr,
uint32_t  length,
bool  rw,
bool  user 
)

Allocates several pages of physical memory at a fixed virtual address in a process.

Similar to pagingAllocatePhysMem(), but uses the provided address instead of searching through the virtual address space.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress where the memory should be mapped
lengthNumber of consecutive pages which have to be unused
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the allocated memory block (inside of the process)

Definition at line 778 of file paging.c.

◆ pagingAllocatePhysMemFixedUnpageable()

void* pagingAllocatePhysMemFixedUnpageable ( struct process p,
void *  addr,
uint32_t  length,
bool  rw,
bool  user 
)

Allocates several pages of unpageable physical memory at a fixed virtual address in a process.

Similar to pagingAllocatePhysMemFixed(), but makes the pages unpageable before returning from the function.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress where the memory should be mapped
lengthNumber of consecutive pages which have to be unused
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the allocated memory block (inside of the process)

Definition at line 804 of file paging.c.

◆ pagingAllocatePhysMemUnpageable()

void* pagingAllocatePhysMemUnpageable ( struct process p,
uint32_t  length,
bool  rw,
bool  user 
)

Allocates several pages of unpageable physical memory in a process.

Similar to pagingAllocatePhysMem(), but makes the physical memory unpageable before returning from the function. This is especially useful for memory which has to stay valid during the execution of exception handlers.

Parameters
pPointer to a process object or NULL for the kernel
lengthNumber of consecutive pages which have to be unused
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the allocated memory block (inside of the process)

Definition at line 686 of file paging.c.

◆ pagingAllocProcessPageTable()

void pagingAllocProcessPageTable ( struct process p)

Allocates the page directory and page table for a specific process.

Each process needs its own page directory and page table such that they have no influence on each other. This command allocates a minimal page table which can then be used to map the rest of the memory into a new usermode process.

Parameters
pPointer to a process object

Definition at line 1236 of file paging.c.

◆ pagingDumpBootMap()

void pagingDumpBootMap ( )

Dumps a list of all entries in the boot map.

Definition at line 444 of file paging.c.

◆ pagingDumpPageTable()

void pagingDumpPageTable ( struct process p)

Dumps information about the page table of a specific process.

Parameters
pPointer to a process object or NULL for the kernel

Definition at line 514 of file paging.c.

◆ pagingFillProcessInfo()

void pagingFillProcessInfo ( struct process p,
struct processInfo info 
)

Fills out all memory related fields in the processInfo structure.

Parameters
pPointer to the process object
infoPointer to the processInfo structure

Definition at line 1436 of file paging.c.

◆ pagingForkProcessPageTable()

void pagingForkProcessPageTable ( struct process destination,
struct process source 
)

Duplicate a page table and assigns it to a destination process.

During the fork syscall it is necessary initialize the child process with exactly the same memory layout as the parent process. To make this possible we copy the page directory and page table. All other pages are marked as read-only, so they will be copied later when it is necessary.

Parameters
destinationPointer to the destination process object (child)
sourcePointer to the source process object (parent)

Definition at line 1261 of file paging.c.

◆ pagingGetPhysMem()

uint32_t pagingGetPhysMem ( struct process p,
void *  addr 
)

Returns the physical page index for a virtual address.

Looks up the virtual address in the page table of the corresponding process and returns the physical page index. If the page is paged out to the hard drive, then it is paged in again in this process. If the page is not mapped at all an internal assertion is triggered.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress pointing to some allocated blocks of memory
Returns
Physical page index

Definition at line 1111 of file paging.c.

◆ pagingInit()

void pagingInit ( )

Initializes paging.

This function is called as part of the startup routine to initialize all the processor features. It internally allocates a page directory for the kernel and afterwards prepares everything with the entries from the boot map. Then paging is finally enabled. It is currently not possible to turn it off again.

Definition at line 467 of file paging.c.

◆ pagingInsertBootMap()

void pagingInsertBootMap ( uint32_t  startIndex,
uint32_t  stopIndex 
)

Appends a specific range of physical pages to the bootmap.

The bootmap is an internal array of physical page regions, which is mapped at exactly the same location in virtual address space after paging has been enabled. This allows to continue the execution of the kernel without having to relocate it to a different address. It is only possible to add entries until paging was activated, afterwards all these steps (requesting physical memory and mapping it to the corresponding virtual address) have to be done manually.

Parameters
startIndexStart index of the memory region
stopIndexStop index of the memory region (not included in mapping)

Definition at line 391 of file paging.c.

◆ pagingMapRemoteMemory()

void* pagingMapRemoteMemory ( struct process dst_p,
struct process src_p,
void *  dst_addr,
void *  src_addr,
uint32_t  length,
bool  rw,
bool  user 
)

Maps some virtual memory from one process to another one.

Parameters
dst_pPointer to the destination process object or NULL
src_pPointer to the source process object or NULL
dst_addrAddress where the memory should be mapped or NULL
src_addrVirtual address of the source memory block
lengthNumber of consecutive pages to map into the destination process
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the mapped memory block (inside of the destination process)

Definition at line 1150 of file paging.c.

◆ pagingReAllocatePhysMem()

void* pagingReAllocatePhysMem ( struct process p,
void *  addr,
uint32_t  old_length,
uint32_t  new_length,
bool  rw,
bool  user 
)

Reallocates a specific range of virtual memory in a process.

Changes the size of a block of virtual memory. If the new size is smaller than the old size all unused pages will be released. If the new size is greather than the old size some additional pages will be allocated with the provided permission attributes. If the reallocation fails a system failure will be triggered. This functions returns a pointer to the new location in the virtual address space of the given process.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress pointing to some allocated blocks of memory
old_lengthOld length of the memory block in pages
new_lengthNumber of requested pages
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the reallocated memory block (inside of the process)

Definition at line 937 of file paging.c.

◆ pagingReleasePhysMem()

void pagingReleasePhysMem ( struct process p,
void *  addr,
uint32_t  length 
)

Releases several pages of physical memory in a process.

This functions iterates through length pages starting from the base address and releases all associated physical memory. If the area contains pages which are not reserved an assertion is triggered, because this typically means that there is a programming error somewhere.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress pointing to some allocated blocks of memory
lengthNumber of consecutive pages to release

Definition at line 1034 of file paging.c.

◆ pagingReleaseProcessPageTable()

void pagingReleaseProcessPageTable ( struct process p)

Releases the page directory and page table of a specific process.

Deallocates the memory used for the page directory and page able.

Parameters
pPointer to the process object

Definition at line 1344 of file paging.c.

◆ pagingReserveArea()

void pagingReserveArea ( struct process p,
void *  addr,
uint32_t  length,
bool  user 
)

Marks the memory in a specific memory area as reserved.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress where the memory should be mapped
lengthNumber of consecutive pages which have to be unused
userIf true then the user (ring3) also has access to the page, otherwise only the kernel

Definition at line 550 of file paging.c.

◆ pagingSearchArea()

void* pagingSearchArea ( struct process p,
uint32_t  length 
)

Searches for a consecutive area of length free pages in a process.

Before mapping some memory to a process or into the kernel virtual address space we have to find a proper location. This function searches through the corresponding page table and afterwards returns a base address which can be used for later mapping. If the virtual address space is exhausted an exception is thrown, so only use this command if its very critical. For non-critical purposes use pagingTrySearchArea().

Parameters
pPointer to a process object or NULL for the kernel
lengthNumber of consecutive pages which have to be unused
Returns
Virtual base address to the memory block (inside of the process)

Definition at line 588 of file paging.c.

◆ pagingTryAllocatePhysMem()

void* pagingTryAllocatePhysMem ( struct process p,
uint32_t  length,
bool  rw,
bool  user 
)

Tries to allocates several pages of physical memory in a process.

Similar to pagingAllocatePhysMem(), but doesn't fail if the algorithm cannot find any spot in the corresponding page table. In such a case NULL will be returned.

Parameters
pPointer to a process object or NULL for the kernel
lengthNumber of consecutive pages which have to be unused
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the allocated memory block (inside of the process) or NULL

Definition at line 736 of file paging.c.

◆ pagingTryAllocatePhysMemFixed()

void* pagingTryAllocatePhysMemFixed ( struct process p,
void *  addr,
uint32_t  length,
bool  rw,
bool  user 
)

Allocates several pages of unpageable physical memory at a fixed virtual address in a process.

Similar to pagingAllocatePhysMemFixed(), but doesn't fail if the algorithm cannot find any spot in the corresponding page table. In such a case NULL will be returned.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress where the memory should be mapped
lengthNumber of consecutive pages which have to be unused
rwIf true then the page has write permission, otherwise it is a read-only page
userIf true then the user (ring3) also has access to the page, otherwise only the kernel
Returns
Virtual base address to the allocated memory block (inside of the process) or NULL

Definition at line 851 of file paging.c.

◆ pagingTryMapUserMem()

void* pagingTryMapUserMem ( struct process src_p,
void *  src_addr,
uint32_t  length,
bool  rw 
)

Maps some virtual memory of a usermode process into the kernel.

This function is similar to pagingMapRemoteMemory(), but will never trigger a system failure, even if the provided arguments are invalid (page not mapped or wrong permissions). If it is not possible to map the whole area of length pages, then the whole area will be unmapped again.

Parameters
src_pPointer to the process object
src_addrVirtual address of the source memory block
lengthNumber of consecutive pages to map into the kernel
rwIf true then the page has write permission, otherwise it is a read-only page
Returns
Virtual base address to the mapped memory block (inside of the kernel)

Definition at line 1520 of file paging.c.

◆ pagingTryReleasePhysMem()

bool pagingTryReleasePhysMem ( struct process p,
void *  addr,
uint32_t  length 
)

Releases several pages of physical memory of a process.

This functions iterates through length pages starting from the base address and releases all associated physical memory. If the area contains pages which are not present the return value is false.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress pointing to some allocated blocks of memory
lengthNumber of consecutive pages to release
Returns
True if all pages were successfully unmapped, otherwise false

Definition at line 1051 of file paging.c.

◆ pagingTryReleaseUserMem()

bool pagingTryReleaseUserMem ( struct process p,
void *  addr,
uint32_t  length 
)

Releases several pages of physical memory of a process.

This function is similar to pagingTryReleasePhysMem() and iterates through length pages starting from the base address. It releases all associated physical memory, but only if the pages are accessible for the usermode process.

Parameters
pPointer to a process object or NULL for the kernel
addrAddress pointing to some allocated blocks of memory
lengthNumber of consecutive pages to release
Returns
True on success (all pages were valid and owned by the user), otherwise false

Definition at line 1615 of file paging.c.

◆ pagingTrySearchArea()

void* pagingTrySearchArea ( struct process p,
uint32_t  length 
)

Searches for a consecutive area of length free pages in a process.

Similar to pagingSearchArea(), but doesn't fail if the algorithm cannot find any spot in the corresponding page table. In such a case NULL will be returned.

Parameters
pPointer to a process object or NULL for the kernel
lengthNumber of consecutive pages which have to be unused
Returns
Virtual base address to the memory block (inside of the process) or NULL

Definition at line 612 of file paging.c.

Variable Documentation

◆ __attribute__

void __attribute__