![]() |
Max OS 0.3
|
Handles memory allocation and deallocation. More...
#include <memorymanagement.h>
Public Member Functions | |
| MemoryManager (VirtualMemoryManager *virtual_memory_manager=nullptr) | |
| Construct a new Memory Manager object. Will switch the pml4 to use the calling process's page tables. | |
| ~MemoryManager () | |
| Destroy the Memory Manager object, frees the VMM if not the kernel memory manager. | |
| void * | handle_malloc (size_t size) |
| Allocates a block of memory. | |
| void | handle_free (void *pointer) |
| Frees a block of memory. | |
| VirtualMemoryManager * | vmm () |
| size_t | memory_used () |
| Returns the amount of memory used. | |
Static Public Member Functions | |
| static void * | malloc (size_t size) |
| Allocates a block of memory in the current USERSPACE heap. | |
| static void | free (void *pointer) |
| Frees a block of memory using the current memory manager. | |
| static void * | kmalloc (size_t size) |
| Allocates a block of memory in the KERNEL space. | |
| static void | kfree (void *pointer) |
| Frees a block of memory using the kernel memory manager. | |
| static size_t | align (size_t size) |
| Aligns the size to the chunk alignment. | |
| static void | switch_active_memory_manager (MemoryManager *manager) |
| Switches the active memory manager. | |
Static Public Attributes | |
| static MemoryManager * | s_current_memory_manager = nullptr |
| The memory manager for the current process. | |
| static MemoryManager * | s_kernel_memory_manager = nullptr |
| The memory manager for any kernel processes and all kernel allocations. | |
Handles memory allocation and deallocation.
Definition at line 40 of file memorymanagement.h.
|
explicit |
Construct a new Memory Manager object. Will switch the pml4 to use the calling process's page tables.
| vmm | The virtual memory manager to use, if nullptr a new one will be created |
Definition at line 22 of file memorymanagement.cpp.
References MaxOS::memory::VirtualMemoryManager::allocate(), MaxOS::memory::MemoryChunk::allocated, MaxOS::memory::MemoryChunk::next, MaxOS::memory::PAGE_SIZE, MaxOS::memory::MemoryChunk::prev, s_kernel_memory_manager, MaxOS::memory::MemoryChunk::size, and switch_active_memory_manager().
| MemoryManager::~MemoryManager | ( | ) |
Destroy the Memory Manager object, frees the VMM if not the kernel memory manager.
Definition at line 49 of file memorymanagement.cpp.
References s_current_memory_manager, and s_kernel_memory_manager.
Aligns the size to the chunk alignment.
| size | The size to align |
Definition at line 288 of file memorymanagement.cpp.
References MaxOS::memory::CHUNK_ALIGNMENT.
Referenced by handle_malloc().
Frees a block of memory using the current memory manager.
| pointer | The pointer to the block |
Definition at line 158 of file memorymanagement.cpp.
References s_current_memory_manager.
Referenced by MaxOS::system::SyscallManager::syscall_free_memory().
Frees a block of memory.
| pointer | A pointer to the block |
Definition at line 186 of file memorymanagement.cpp.
Allocates a block of memory.
| size | The size of the block to allocate |
Definition at line 100 of file memorymanagement.cpp.
References align().
Frees a block of memory using the kernel memory manager.
| pointer | The pointer to the block |
Definition at line 172 of file memorymanagement.cpp.
References s_kernel_memory_manager.
Referenced by MaxOS::net::TCPSocket::connected(), MaxOS::net::UserDatagramProtocolHandler::disconnect(), MaxOS::net::TCPSocket::disconnected(), MaxOS::net::TCPSocket::handle_transmission_control_protocol_payload(), MaxOS::net::UDPSocket::handle_user_datagram_protocol_payload(), operator delete(), operator delete(), operator delete[](), operator delete[](), MaxOS::net::UserDatagramProtocolHandler::send(), MaxOS::net::EthernetFrameHandler::send_ethernet_frame(), MaxOS::net::InternetProtocolHandler::send_internet_protocol_packet(), and MaxOS::net::TransmissionControlProtocolHandler::send_transmission_control_protocol_packet().
Allocates a block of memory in the KERNEL space.
| size | The size of the block |
Definition at line 85 of file memorymanagement.cpp.
References s_kernel_memory_manager.
Referenced by MaxOS::drivers::ethernet::AMD_AM79C973::AMD_AM79C973(), MaxOS::net::TransmissionControlProtocolHandler::connect(), MaxOS::net::UserDatagramProtocolHandler::connect(), MaxOS::net::TransmissionControlProtocolHandler::listen(), MaxOS::net::UserDatagramProtocolHandler::listen(), operator new(), operator new[](), MaxOS::net::UserDatagramProtocolHandler::send(), MaxOS::net::EthernetFrameHandler::send_ethernet_frame(), MaxOS::net::InternetProtocolHandler::send_internet_protocol_packet(), MaxOS::net::TransmissionControlProtocolHandler::send_transmission_control_protocol_packet(), MaxOS::processes::Thread::Thread(), MaxOS::drivers::console::VESABootConsole::VESABootConsole(), and MaxOS::system::Core::wake_up().
Allocates a block of memory in the current USERSPACE heap.
| size | size of the block |
Definition at line 70 of file memorymanagement.cpp.
References s_current_memory_manager.
Referenced by MaxOS::system::SyscallManager::syscall_allocate_memory(), and MaxOS::processes::Thread::Thread().
| size_t MemoryManager::memory_used | ( | ) |
Returns the amount of memory used.
Definition at line 270 of file memorymanagement.cpp.
|
static |
Switches the active memory manager.
| manager | The new memory manager |
Definition at line 299 of file memorymanagement.cpp.
References s_current_memory_manager.
Referenced by MemoryManager().
| VirtualMemoryManager * MemoryManager::vmm | ( | ) |
Gets the active virtual memory manager
Definition at line 317 of file memorymanagement.cpp.
|
inlinestatic |
The memory manager for the current process.
Definition at line 51 of file memorymanagement.h.
Referenced by free(), malloc(), switch_active_memory_manager(), and ~MemoryManager().
|
inlinestatic |
The memory manager for any kernel processes and all kernel allocations.
Definition at line 52 of file memorymanagement.h.
Referenced by kfree(), kmalloc(), MemoryManager(), MaxOS::processes::Process::Process(), MaxOS::processes::Scheduler::Scheduler(), MaxOS::memory::VirtualMemoryManager::VirtualMemoryManager(), and ~MemoryManager().