Virtual Memory
[Kernel]
|
Data Structures |
| struct | vm_desc_t |
| | Represents an area of memory, possibly shared between more than one process. More...
|
| struct | vm_node_t |
| | Represents an area of memory in one process. More...
|
Defines |
|
#define | VM_AREA_NORMAL 1 |
|
#define | VM_AREA_MAP 2 |
|
#define | VM_AREA_FILE 3 |
|
#define | VM_AREA_IMAGE 4 |
|
#define | VM_AREA_CALLBACK 5 |
|
#define | VM_MEM_KERNEL 0x00000000 |
| | Allow access only from kernel mode.
|
|
#define | VM_MEM_USER 0x00000003 |
| | Allow access from user mode and kernel mode.
|
|
#define | VM_MEM_PL_MASK 0x00000003 |
| | Mask for privilege level bits.
|
|
#define | VM_MEM_READ 0x00000004 |
| | Allow memory to be read.
|
|
#define | VM_MEM_WRITE 0x00000008 |
| | Allow memory to be written.
|
|
#define | VM_MEM_ZERO 0x00000010 |
| | Zero memory before it is used.
|
|
#define | VM_MEM_CACHE_WT 0x00000020 |
| | Disable write caching on memory.
|
|
#define | VM_MEM_CACHE_NONE 0x00000040 |
| | Disable all caching on memory.
|
|
#define | VM_MEM_LITERAL 0x00000080 |
| | Allow mapping of VM_AREA_MAP areas to address 0.
|
|
#define | VM_MEM_RESERVED 0x00000100 |
| | Reserve a region of address space (nodes only).
|
| #define | VM_MEM_NODE_MASK |
| | Flags that are valid for nodes (as opposed to areas).
|
|
#define | VMM_NODE_IS_EMPTY(n) ((n)->flags == 0) |
|
#define | PAGE_SIZE 4096 |
| | Size of one page on the target architecture.
|
|
#define | PAGE_ALIGN(addr) ((addr) & -PAGE_SIZE) |
| | Rounds an address down to a page boundary.
|
|
#define | PAGE_ALIGN_UP(addr) (((addr) + PAGE_SIZE - 1) & -PAGE_SIZE) |
| | Rounds an address up to a page boundary.
|
Typedefs |
|
typedef vm_node_t | vm_node_t |
|
typedef bool(* | VMM_CALLBACK )(void *cookie, vm_node_t *node, addr_t start, bool is_writing) |
|
typedef vm_desc_t | vm_desc_t |
Functions |
| void * | VmmMap (size_t pages, addr_t start, void *dest1, void *dest2, unsigned type, uint32_t flags) |
| | Creates any type of memory area in the current process.
|
| void * | VmmAllocCallback (size_t pages, addr_t start, uint32_t flags, VMM_CALLBACK handler, void *cookie) |
| | Allocates an area of memory whose mapping is controlled by a callback function.
|
|
void | VmmFreeNode (vm_node_t *node) |
| bool | VmmPageFault (process_t *proc, addr_t start, bool is_writing) |
| | Handles a page fault in VMM-managed memory in the current process.
|
|
vm_node_t * | VmmLookupNode (int level, vm_node_t *parent, const void *ptr) |
| void * | VmmAlloc (size_t pages, addr_t base, uint32_t flags) |
| | Allocates an area of memory.
|
| bool | VmmFree (void *base) |
| | Frees an area of memory allocated by the VmmAlloc() function.
|
|
void * | VmmMapSharedArea (vm_desc_t *desc, addr_t base, uint32_t flags) |
| void * | VmmMapFile (file_handle_t *fh, addr_t base, size_t pages, uint32_t flags) |
| | Allocates an area of memory backed by a file.
|
|
void * | VmmReserveArea (size_t pages, addr_t base) |
| vm_desc_t * | VmmShare (void *base, const wchar_t *name) |
| | Makes an area of memory available for sharing through VmmOpenSharedArea and VmmMapSharedArea.
|
|
void * | VmmAlloc () |
|
uint32_t bool | VmmFree () |
|
void *void * | VmmMapSharedArea () |
|
uint32_t void * | VmmMapFile () |
|
uint32_t void * | VmmReserveArea () |
|
addr_t handle_t | VmmShare () |
Variables |
|
| size_t |
|
| addr_t |
|
| handle_t |
|
void * | base |
Detailed Description
Define Documentation
|
|
Value: Flags that are valid for nodes (as opposed to areas).
|
Function Documentation
| void* VmmAlloc |
( |
size_t |
pages, |
|
|
addr_t |
start, |
|
|
uint32_t |
flags |
|
) |
|
|
|
|
Allocates an area of memory.
- Parameters:
-
| pages | Number of 4KB pages to allocate |
| start | Virtual address at which the area will start. If this is NULL an address will be chosen (unless flags includes the VM_MEM_LITERAL flag). |
| flags | VM_MEM_xxx flags controlling the allocation of and access to the allocated area |
- Returns:
- A pointer to the start of the area, or
NULL if the area could not be allocated.
|
| void* VmmAllocCallback |
( |
size_t |
pages, |
|
|
addr_t |
start, |
|
|
uint32_t |
flags, |
|
|
VMM_CALLBACK |
handler, |
|
|
void * |
cookie |
|
) |
|
|
|
|
Allocates an area of memory whose mapping is controlled by a callback function.
- Parameters:
-
| pages | Number of 4KB pages to allocate |
| start | Virtual address at which the area will start. If this if NULL an address will be chosen (unless flags includes the VM_MEM_LITERAL flag). |
| flags | VM_MEM_xxx flags controlling the allocation of and access to the allocated area |
| handler | Function called by the kernel when a page fault occurs in the allocated area |
| cookie | Opaque pointer passed to handler |
- Returns:
- A pointer to the start of the area, or
NULL if the area could not be allocated.
|
| bool VmmFree |
( |
void * |
ptr |
) |
|
|
|
|
Frees an area of memory allocated by the VmmAlloc() function.
- Parameters:
-
| ptr | Pointer with the area to be freed |
|
| void* VmmMap |
( |
size_t |
pages, |
|
|
addr_t |
start, |
|
|
void * |
dest1, |
|
|
void * |
dest2, |
|
|
unsigned |
type, |
|
|
uint32_t |
flags |
|
) |
|
|
|
|
Creates any type of memory area in the current process.
Called by VmmAlloc and VmmAllocCallback and VmmMapFile. This function creates the vm_desc_t structure backing the memory area, and calls VmmAllocNode to allocate space in the current process's address space. Other functions (VmmMapSharedArea) can attach additional vm_node_t structures to the same vm_desc_t.
- Parameters:
-
| pages | Size of the area to allocate, in pages |
| start | Start address of the area in the current process, or use NULL to get VmmAllocNode to choose a suitable address. The address chosen when NULL is passed will be below 2GB for user-mode allocations ((flags & 3) != 0) and above 2GB for kernel-mode allocations ((flags & 3) == 0). |
| dest1 | Parameter for the area; this pointer is interpreted differently according to the value passed for type. |
| dest2 | Additional parameter for the area |
| type | Type of mapping to create. Can be one of the following values:
VM_AREA_NORMAL: dest1 and dest2 are ignored.VM_AREA_MAP: dest1 specifies the physical address of a virtual-to- physical mapping; dest2 is ignored.VM_AREA_FILE: dest1 specifies a file handle in the current process; dest2 is ignored.VM_AREA_IMAGE: dest1 specifies a pointer to a module_t structure; dest2 is ignored.VM_AREA_CALLBACK: dest1 specifies a handler function whose signature matches that of the typedef VMM_CALLBACK; dest2 specifies the cookie to be passed to the handler function.
|
| flags | Flags to apply to the allocation and mapping of the area. Can be a bitwise-OR combination of the any of the following values:
VM_MEM_READ: Permits read access to the area. Note: current x86 processors always allow read access to memory.VM_MEM_WRITE: Permits write access to the area. Note: on the x86, user- mode pages area always writable from kernel mode, regardless of whether write protection has been applied.VM_MEM_ZERO: Causes each page in the area to be zeroed as it is allocated.
|
- Returns:
- A pointer to the start of the newly-allocated area, or
NULL is allocation failed.
|
| void* VmmMapFile |
( |
file_handle_t * |
file, |
|
|
addr_t |
start, |
|
|
size_t |
pages, |
|
|
uint32_t |
flags |
|
) |
|
|
|
|
Allocates an area of memory backed by a file.
- Parameters:
-
| file | Handle to the file to be mapped |
| start | Virtual address at which the area will start. If this if NULL an address will be chosen (unless flags includes the VM_MEM_LITERAL flag). |
| pages | Number of 4KB pages to map |
| flags | VM_MEM_xxx flags controlling the allocation of and access to the allocated area |
- Returns:
- A pointer to the start of the area, or
NULL if the area could not be mapped.
|
| bool VmmPageFault |
( |
process_t * |
proc, |
|
|
addr_t |
page, |
|
|
bool |
is_writing |
|
) |
|
|
|
|
Handles a page fault in VMM-managed memory in the current process.
Attempts to look up the fault address in the current process's VMM nodes and, if found, calls the appropriate handler function to bring the page into physical memory.
- Parameters:
-
| proc | Process whose nodes are to be checked. This can be either current()->process or proc_idle. |
| page | Virtual address which caused the page fault |
| is_writing | Set to true if the access to address page was a write, of false for a read |
- Returns:
true if the function could handle the page fault, false otherwise
|
| vm_desc_t* VmmShare |
( |
void * |
base, |
|
|
const wchar_t * |
name |
|
) |
|
|
|
|
Makes an area of memory available for sharing through VmmOpenSharedArea and VmmMapSharedArea.
- Parameters:
-
| base | Pointer to the start of the area to be shared |
| name | Name under which the area will be made available |
- Returns:
true if the area could be shared, false otherwise
|
|