IBNOS
|
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__ |
struct pagingEntry __attribute__ | ( | (packed) | ) |
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().
p | Pointer to a process object or NULL for the kernel |
length | Number of consecutive pages which have to be unused |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address where the memory should be mapped |
length | Number of consecutive pages which have to be unused |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address where the memory should be mapped |
length | Number of consecutive pages which have to be unused |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object or NULL for the kernel |
length | Number of consecutive pages which have to be unused |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object |
void pagingDumpBootMap | ( | ) |
void pagingDumpPageTable | ( | struct process * | p | ) |
void pagingFillProcessInfo | ( | struct process * | p, |
struct processInfo * | info | ||
) |
Fills out all memory related fields in the processInfo structure.
p | Pointer to the process object |
info | Pointer to the processInfo structure |
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.
destination | Pointer to the destination process object (child) |
source | Pointer to the source process object (parent) |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address pointing to some allocated blocks of memory |
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.
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.
startIndex | Start index of the memory region |
stopIndex | Stop index of the memory region (not included in mapping) |
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.
dst_p | Pointer to the destination process object or NULL |
src_p | Pointer to the source process object or NULL |
dst_addr | Address where the memory should be mapped or NULL |
src_addr | Virtual address of the source memory block |
length | Number of consecutive pages to map into the destination process |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address pointing to some allocated blocks of memory |
old_length | Old length of the memory block in pages |
new_length | Number of requested pages |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address pointing to some allocated blocks of memory |
length | Number of consecutive pages to release |
void pagingReleaseProcessPageTable | ( | struct process * | p | ) |
void pagingReserveArea | ( | struct process * | p, |
void * | addr, | ||
uint32_t | length, | ||
bool | user | ||
) |
Marks the memory in a specific memory area as reserved.
p | Pointer to a process object or NULL for the kernel |
addr | Address where the memory should be mapped |
length | Number of consecutive pages which have to be unused |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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().
p | Pointer to a process object or NULL for the kernel |
length | Number of consecutive pages which have to be unused |
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.
p | Pointer to a process object or NULL for the kernel |
length | Number of consecutive pages which have to be unused |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address where the memory should be mapped |
length | Number of consecutive pages which have to be unused |
rw | If true then the page has write permission, otherwise it is a read-only page |
user | If true then the user (ring3) also has access to the page, otherwise only the kernel |
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.
src_p | Pointer to the process object |
src_addr | Virtual address of the source memory block |
length | Number of consecutive pages to map into the kernel |
rw | If true then the page has write permission, otherwise it is a read-only page |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address pointing to some allocated blocks of memory |
length | Number of consecutive pages to release |
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.
p | Pointer to a process object or NULL for the kernel |
addr | Address pointing to some allocated blocks of memory |
length | Number of consecutive pages to release |
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.
p | Pointer to a process object or NULL for the kernel |
length | Number of consecutive pages which have to be unused |
void __attribute__ |