PatchworkOS
Loading...
Searching...
No Matches
space.h
Go to the documentation of this file.
1#pragma once
2
4#include <kernel/fs/path.h>
6#include <kernel/sched/wait.h>
7#include <kernel/sync/lock.h>
8
9#include <boot/boot_info.h>
10
11#include <sys/bitmap.h>
12#include <sys/list.h>
13#include <sys/proc.h>
14
39
43typedef void (*space_callback_func_t)(void* private);
44
55
67
102
106#define SPACE_TLB_SHOOTDOWN_TIMEOUT (CLOCKS_PER_SEC)
107
117uint64_t space_init(space_t* space, uintptr_t startAddress, uintptr_t endAddress, space_flags_t flags);
118
124void space_deinit(space_t* space);
125
135void space_load(space_t* space);
136
166uint64_t space_pin(space_t* space, const void* address, uint64_t length, stack_pointer_t* userStack);
167
184uint64_t space_pin_terminated(space_t* space, const void* address, const void* terminator, uint8_t objectSize,
185 uint64_t maxCount, stack_pointer_t* userStack);
186
196void space_unpin(space_t* space, const void* address, uint64_t length);
197
210uint64_t space_check_access(space_t* space, const void* addr, uint64_t length);
211
223
240uint64_t space_mapping_start(space_t* space, space_mapping_t* mapping, void* virtAddr, void* physAddr, uint64_t length,
241 pml_flags_t flags);
242
258
269void space_free_callback(space_t* space, pml_callback_id_t callbackId);
270
287void space_tlb_shootdown(space_t* space, void* virtAddr, uint64_t pageAmount);
288
299void* space_mapping_end(space_t* space, space_mapping_t* mapping, errno_t err);
300
309bool space_is_mapped(space_t* space, const void* virtAddr, uint64_t length);
310
int errno_t
Definition errno_t.h:4
uint8_t pml_callback_id_t
Callback ID type.
#define PML_MAX_CALLBACK
Maximum number of callbacks that can be registered for a page table.
void space_unpin(space_t *space, const void *address, uint64_t length)
Unpins pages in a region previously pinned with space_pin() or space_pin_string().
Definition space.c:448
bool space_is_mapped(space_t *space, const void *virtAddr, uint64_t length)
Checks if a virtual memory region is fully mapped.
Definition space.c:750
void * space_mapping_end(space_t *space, space_mapping_t *mapping, errno_t err)
Performs cleanup after changes to the address space mappings.
Definition space.c:730
pml_callback_id_t space_alloc_callback(space_t *space, uint64_t pageAmount, space_callback_func_t func, void *private)
Allocate a callback.
Definition space.c:592
uint64_t space_check_access(space_t *space, const void *addr, uint64_t length)
Checks if a virtual memory region is within the allowed address range of the space.
Definition space.c:474
void space_free_callback(space_t *space, pml_callback_id_t callbackId)
Free a callback.
Definition space.c:633
space_flags_t
Flags for space initialization.
Definition space.h:28
uint64_t space_pin_terminated(space_t *space, const void *address, const void *terminator, uint8_t objectSize, uint64_t maxCount, stack_pointer_t *userStack)
Pins a region of memory terminated by a terminator value.
Definition space.c:382
void(* space_callback_func_t)(void *private)
Space callback function.
Definition space.h:43
uint64_t space_pin(space_t *space, const void *address, uint64_t length, stack_pointer_t *userStack)
Pins pages within a region of the address space.
Definition space.c:334
void space_load(space_t *space)
Loads a virtual address space.
Definition space.c:161
void space_tlb_shootdown(space_t *space, void *virtAddr, uint64_t pageAmount)
Performs a TLB shootdown for a region of the address space, and wait for acknowledgements.
Definition space.c:638
void space_deinit(space_t *space)
Deinitializes a virtual address space.
Definition space.c:124
uint64_t space_init(space_t *space, uintptr_t startAddress, uintptr_t endAddress, space_flags_t flags)
Initializes a virtual address space.
Definition space.c:62
uint64_t space_mapping_start(space_t *space, space_mapping_t *mapping, void *virtAddr, void *physAddr, uint64_t length, pml_flags_t flags)
Prepare for changes to the address space mappings.
Definition space.c:524
@ SPACE_NONE
Definition space.h:29
@ SPACE_MAP_KERNEL_HEAP
Map the kernel heap into the address space.
Definition space.h:36
@ SPACE_USE_PMM_BITMAP
Definition space.h:34
@ SPACE_MAP_IDENTITY
Map the identity mapped physical memory into the address space.
Definition space.h:37
@ SPACE_MAP_KERNEL_BINARY
Map the kernel binary into the address space.
Definition space.h:35
#define BITMAP_BITS_TO_QWORDS(bits)
Convert number of bits to number of qwords.
Definition bitmap.h:34
static uintptr_t address
Definition hpet.c:12
static uint64_t pageAmount
Definition pmm.c:42
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
Bitmap structure.
Definition bitmap.h:22
A doubly linked list.
Definition list.h:51
A simple ticket lock implementation.
Definition lock.h:43
Map entry structure.
Definition map.h:57
Hash map structure.
Definition map.h:76
A page table structure.
A entry in a page table without a specified address or callback ID.
uint64_t pageAmount
Definition space.h:53
space_callback_func_t func
Definition space.h:51
Helper structure for managing address space mappings.
Definition space.h:217
void * physAddr
Definition space.h:219
pml_flags_t flags
Definition space.h:221
uint64_t pageAmount
Definition space.h:220
void * virtAddr
Definition space.h:218
Pinned page structure.
Definition space.h:63
uint64_t pinCount
The number of times this page is pinned, will be unpinned when it reaches 0.
Definition space.h:65
map_entry_t mapEntry
Definition space.h:64
Virtual address space structure.
Definition space.h:79
lock_t lock
Definition space.h:100
map_t pinnedPages
Map of pages with a pin depth greater than 1.
Definition space.h:80
uintptr_t startAddress
The start address for allocations in this address space.
Definition space.h:82
uint64_t callbacksLength
Length of the callbacks array.
Definition space.h:92
uintptr_t endAddress
The end address for allocations in this address space.
Definition space.h:83
page_table_t pageTable
The page table associated with the address space.
Definition space.h:81
bitmap_t callbackBitmap
Bitmap to track available callback IDs.
Definition space.h:93
space_flags_t flags
Definition space.h:85
list_t cpus
List of CPUs using this address space.
Definition space.h:98
uintptr_t freeAddress
The next available free virtual address in this address space.
Definition space.h:84
atomic_uint16_t shootdownAcks
Definition space.h:99
space_callback_t * callbacks
Definition space.h:91
Structure to define a stack in memory.