Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::memory::MemoryManager Class Reference

Handles memory allocation and deallocation. More...

#include <memorymanagement.h>

Inheritance diagram for MaxOS::memory::MemoryManager:
MaxOS::memory::BumpMemoryManager MaxOS::memory::allocator::BumpAllocator MaxOS::memory::allocator::MemoryAllocator

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.
 
- Public Member Functions inherited from MaxOS::memory::BumpMemoryManager
 BumpMemoryManager (VirtualMemoryManager *virtual_memory_manager=nullptr)
 Constructs a new BumpMemoryManager.
 
 ~BumpMemoryManager ()
 
VirtualMemoryManager * vmm ()
 
- Public Member Functions inherited from MaxOS::memory::allocator::BumpAllocator
 BumpAllocator ()
 Creates a new bump memory allocator.
 
virtual ~BumpAllocator ()
 Destructs a Bump memory allocator.
 
void setup_region (uintptr_t address, size_t length) final
 Setup a region to be bump memory managed, creates a free chunk represent the whole region.
 
void * allocate (size_t size) final
 Allocates a block of memory.
 
void unallocate (void *pointer) final
 Frees a block of memory.
 
size_t amount_used () final
 Returns the amount of memory used.
 
size_t align (size_t size) final
 Aligns the size to the chunk alignment.
 
- Public Member Functions inherited from MaxOS::memory::allocator::MemoryAllocator
 MemoryAllocator ()
 
virtual ~MemoryAllocator ()
 

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 Public Member Functions inherited from MaxOS::memory::BumpMemoryManager
static void switch_active_memory_manager (BumpMemoryManager *manager)
 Switches the active memory manager.
 

Static Public Attributes

static MemoryManager * s_kernel_memory_manager = nullptr
 The memory manager for any kernel processes and all kernel allocations.
 

Detailed Description

Handles memory allocation and deallocation.

Definition at line 51 of file memorymanagement.h.

Constructor & Destructor Documentation

◆ MemoryManager()

MemoryManager::MemoryManager ( VirtualMemoryManager *  vmm = nullptr)
explicit

Construct a new Memory Manager object. Will switch the pml4 to use the calling process's page tables.

Parameters
vmmThe virtual memory manager to use, if nullptr a new one will be created

Definition at line 99 of file memorymanagement.cpp.

101{
102
103 // First memory manager is the kernel memory manager
104 if(s_kernel_memory_manager == nullptr)
106
107}
Basic doubly linked list bump memory manager.
static MemoryManager * s_kernel_memory_manager
The memory manager for any kernel processes and all kernel allocations.

References s_kernel_memory_manager.

◆ ~MemoryManager()

MemoryManager::~MemoryManager ( )

Destroy the Memory Manager object, frees the VMM if not the kernel memory manager.

Definition at line 112 of file memorymanagement.cpp.

112 {
113
114 // Remove the kernel reference to this
115 if(s_kernel_memory_manager == this)
116 s_kernel_memory_manager = nullptr;
117}

References s_kernel_memory_manager.

Member Function Documentation

◆ free()

void MemoryManager::free ( void *  pointer)
static

Frees a block of memory using the current memory manager.

Parameters
pointerThe pointer to the block

Definition at line 150 of file memorymanagement.cpp.

150 {
151
153}
void unallocate(void *pointer) final
Frees a block of memory.
Definition bump.cpp:212
static Process * current_process()
Gets the process on the currently executing core.
memory::MemoryManager * memory_manager
The manager for memory used by this process.
Definition process.h:121

References MaxOS::processes::GlobalScheduler::current_process(), MaxOS::processes::Process::memory_manager, and MaxOS::memory::allocator::BumpAllocator::unallocate().

Referenced by MaxOS::system::SyscallManager::syscall_free_memory().

◆ kfree()

void MemoryManager::kfree ( void *  pointer)
static

Frees a block of memory using the kernel memory manager.

Parameters
pointerThe pointer to the block

Definition at line 160 of file memorymanagement.cpp.

160 {
161
162 // Make sure there is a kernel memory manager
163 if(s_kernel_memory_manager == nullptr)
164 return;
165
167}

References s_kernel_memory_manager, and MaxOS::memory::allocator::BumpAllocator::unallocate().

◆ kmalloc()

void * MemoryManager::kmalloc ( size_t  size)
static

Allocates a block of memory in the KERNEL space.

Parameters
sizeThe size of the block
Returns
The pointer to the block, or nullptr if no block is available

Definition at line 136 of file memorymanagement.cpp.

136 {
137
138 // Make sure there is a kernel memory manager
139 if(s_kernel_memory_manager == nullptr)
140 return nullptr;
141
142 return s_kernel_memory_manager->allocate(size);
143}
void * allocate(size_t size) final
Allocates a block of memory.
Definition bump.cpp:144

References MaxOS::memory::allocator::BumpAllocator::allocate(), and s_kernel_memory_manager.

Referenced by MaxOS::system::Core::Core(), MaxOS::processes::resources::ProcessResourceRegistry::create_resource(), MaxOS::console::FramebufferConsole::FramebufferConsole(), and MaxOS::processes::Thread::Thread().

◆ malloc()

void * MemoryManager::malloc ( size_t  size)
static

Allocates a block of memory in the current USERSPACE heap.

Parameters
sizesize of the block
Returns
a pointer to the block, 0 if no block is available or no memory manager is set

Definition at line 125 of file memorymanagement.cpp.

125 {
126
128}

References MaxOS::memory::allocator::BumpAllocator::allocate(), MaxOS::processes::GlobalScheduler::current_process(), and MaxOS::processes::Process::memory_manager.

Referenced by MaxOS::processes::resources::ProcessResource::read(), and MaxOS::system::SyscallManager::syscall_allocate_memory().

Member Data Documentation

◆ s_kernel_memory_manager

MemoryManager* MaxOS::memory::MemoryManager::s_kernel_memory_manager = nullptr
inlinestatic

The documentation for this class was generated from the following files: