diff --git a/content/projects/noxos/docs/codebase/mm/heap.h.md b/content/projects/noxos/docs/codebase/mm/heap.h.md new file mode 100644 index 0000000..234f2d2 --- /dev/null +++ b/content/projects/noxos/docs/codebase/mm/heap.h.md @@ -0,0 +1,45 @@ +--- +title: "heap.h" +summary: "dynamic memory allocator" +--- + +#### `heap_segment_T` - struct +This header lies in memory, directly before the accessible buffer of the related segment. + +| Name | Type | Description | +|-------|---------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------| +| magic | uint32_t | An out of bounds memory write would override this, what would indicate a heap corruption | +| size | uint64_t | The size of the segment | +| free | bool | If this is set, the segment is reclaimable | +| next | [heap_segment_T](https://nerdcult.net/projects/noxos/docs/codebase/mm/heap.h/#heap_segment_t---struct)* | The next segment in the heap | +| prev | [heap_segment_T](https://nerdcult.net/projects/noxos/docs/codebase/mm/heap.h/#heap_segment_t---struct)* | The previous segment in the heap | + + +#### `heap_T` - struct + +| Name | Type | Description | +|--------------|---------------------------------------------------------------------------------------------------------|-------------------------------------------------------------| +| start | void* | The start of the heaps segment pool | +| end | void* | The current end of the heaps segment pool (growing upwards) | +| last_segment | [heap_segment_T](https://nerdcult.net/projects/noxos/docs/codebase/mm/heap.h/#heap_segment_t---struct)* | The current last segment in the heaps segment pool | + +#### `heap_init(heap*, base)` - function (void) +Initializes **_heap_** at **_base_** (virtual address). +It will automatically map some page frames to that address. + +#### `heap_memory_allocate(heap*, size)` - function (void) +Returns a pointer to a free usable memory location, that has at least the given **_size_**. +It will return `NULL` and log an error, if the heap is corrupted. +Because this function iterates over the entire heap to find a free segment, it is kinda slow. + +#### `heap_memory_free(heap*, address)` - function (void) +Frees a with [heap_memory_allocate](https://nerdcult.net/projects/noxos/docs/codebase/mm/heap.h/#heap_memory_allocateheap-size---function-void)* created heap segment, and makes it usable again. +Does nothing, if the address doesn't point to a valid heap segment. + +#### `heap_dump_segments(heap*)` - function (void) +Logs a complete list, of all heap segments. +Useful, when debugging / testing the heap. + +#### `heap_destruct(heap*)` - function (void) +Invalidates all segments of a heap, frees all used page frames and unmaps them. + diff --git a/content/projects/noxos/docs/codebase/mm/region.h.md b/content/projects/noxos/docs/codebase/mm/region.h.md new file mode 100644 index 0000000..b1f8d02 --- /dev/null +++ b/content/projects/noxos/docs/codebase/mm/region.h.md @@ -0,0 +1,36 @@ +--- +title: "region.h" +summary: "virtual memory space layout" +--- + +The first 4 digits of an address can be ignored, they are also ignored by the MMU, +but for clarity / readability reasons they are `FFFF` in the kernel space. +See _General Concepts / Memory Layout_(todo: add reference) and _General Concepts / Process Memory Isolation_(todo: add reference) for more details. + +| Name | Start | Description | +|----------------------------------|--------------------|---------------------------------------------------| +| `MEM_REGION_PROCESS` | 0x0000000000000000 | This is the start of the process space | +| `MEM_REGION_PROCESS_EXEC` | 0x0000010000000000 | Every processes' executable will be mapped here | +| `MEM_REGION_PROCESS_THREAD_BASE` | 0x0000010100000000 | The start of the _Thread Data_ regions | +| `MEM_REGION_KERNEL` | 0xFFFF800000000000 | This is the start of the kernel space | +| `MEM_REGION_KERNEL_STACK_DUMMY` | 0xFFFFF00000000000 | This area is used when preparing a threads' stack | +| `MEM_REGION_KERNEL_HEAP` | 0xFFFFF80000000000 | The kernels' heap begins here | +| `MEM_REGION_KERNEL_THREAD_BASE` | 0xFFFFFF0000000000 | The kernel processes' _Thread Data_ regions | +| `MEM_REGION_KERNELEXEC` | 0xFFFFFFFF80000000 | The kernel executable is mapped here | + +#### `MEM_REGION_THREAD_OFFSET` - macro +This time the threads id specifies its offset in its processes' _Thread Data_ region. + +#### `KERNEL_START_ADDRESS` - macro +Returns the address of [_kernel_start](https://nerdcult.net/projects/noxos/docs/codebase/mm/region.h/#_kernel_start---global-variable). + +#### `KERNEL_END_ADDRESS` - macro +Returns the address of [_kernel_end](https://nerdcult.net/projects/noxos/docs/codebase/mm/region.h/#_kernel_end---global-variable). + +#### `_kernel_start` - global variable +This symbol is inserted by the linker at the beginning of the kernel. +To access its value use [KERNEL_START_ADDRESS](https://nerdcult.net/projects/noxos/docs/codebase/mm/region.h/#kernel_start_address---macro). + +#### `_kernel_end` - global variable +This symbol is inserted by the linker at the end of the kernel. +To access its value use [KERNEL_END_ADDRESS](https://nerdcult.net/projects/noxos/docs/codebase/mm/region.h/#kernel_end_address---macro).