9#ifndef MAXOS_SYSTEM_MEMORYMANAGEMENT_H
10#define MAXOS_SYSTEM_MEMORYMANAGEMENT_H
14#include <system/multiboot.h>
18namespace MaxOS::memory {
58 static void*
malloc(
size_t size);
59 static void free(
void* pointer);
62 static void*
kmalloc(
size_t size);
63 static void kfree(
void* pointer);
72 static size_t align(
size_t size);
78void*
operator new(
size_t size)
throw();
79void*
operator new[](
size_t size)
throw();
82void*
operator new(
size_t size,
void* pointer);
83void*
operator new[](
size_t size,
void* pointer);
85void operator delete(
void* pointer);
86void operator delete[](
void* pointer);
88void operator delete(
void* pointer,
size_t size);
89void operator delete[](
void* pointer,
size_t size);
Handles memory allocation and deallocation.
void * handle_malloc(size_t size)
Allocates a block of memory.
static MemoryManager * s_current_memory_manager
The memory manager for the current process.
static size_t align(size_t size)
Aligns the size to the chunk alignment.
void handle_free(void *pointer)
Frees a block of memory.
static void free(void *pointer)
Frees a block of memory using the current memory manager.
static MemoryManager * s_kernel_memory_manager
The memory manager for any kernel processes and all kernel allocations.
static void * malloc(size_t size)
Allocates a block of memory in the current USERSPACE heap.
static void * kmalloc(size_t size)
Allocates a block of memory in the KERNEL space.
size_t memory_used()
Returns the amount of memory used.
static void kfree(void *pointer)
Frees a block of memory using the kernel memory manager.
~MemoryManager()
Destroy the Memory Manager object, frees the VMM if not the kernel memory manager.
static void switch_active_memory_manager(MemoryManager *manager)
Switches the active memory manager.
VirtualMemoryManager * vmm()
Manages the virtual memory of the system and provides functions to allocate and free memory in the vi...
constexpr size_t CHUNK_ALIGNMENT
How many bytes the chunks should be a multiple of (round up to this)
A span of memory in the heap, can be allocated or free. Used as a node in a doubly linked list.
MemoryChunk * prev
Pointer to the chunk before this one in the list.
MemoryChunk * next
Pointer to the chunk after this one in the list.
size_t size
The size of this span of memory (not including the MemoryChunk struct itself)
bool allocated
Whether this chunk is in use or can be allocated.
Defines a VirtualMemoryManager class for managing virtual memory allocation and mapping to physical m...