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

Basic doubly linked list bump memory manager. More...

#include <memorymanagement.h>

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

Public Member Functions

 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 switch_active_memory_manager (BumpMemoryManager *manager)
 Switches the active memory manager.
 

Detailed Description

Basic doubly linked list bump memory manager.

Definition at line 29 of file memorymanagement.h.

Constructor & Destructor Documentation

◆ BumpMemoryManager()

BumpMemoryManager::BumpMemoryManager ( VirtualMemoryManager *  virtual_memory_manager = nullptr)

Constructs a new BumpMemoryManager.

Parameters
virtual_memory_managerThe virtual memory region this allocator manages

Definition at line 25 of file memorymanagement.cpp.

26 : m_virtual_memory_manager(virtual_memory_manager)
27{
28
29 // Create the VMM if not provided
30 if(m_virtual_memory_manager == nullptr)
31 m_virtual_memory_manager = new VirtualMemoryManager();
32
33 // Set up the first chunk of memory
34 auto address = (uintptr_t)m_virtual_memory_manager->allocate(PAGE_SIZE, 0);
35 setup_region(address, PAGE_SIZE);
36
37}
Manages the virtual memory of the system and provides functions to allocate and free memory in the vi...
Definition virtual.h:104
void * allocate(size_t size, size_t flags)
Allocate a new chunk of virtual memory.
Definition virtual.cpp:113
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.
Definition bump.cpp:122

References MaxOS::memory::VirtualMemoryManager::allocate(), MaxOS::memory::PAGE_SIZE, and MaxOS::memory::allocator::BumpAllocator::setup_region().

◆ ~BumpMemoryManager()

BumpMemoryManager::~BumpMemoryManager ( )

Destructs the BumpMemoryManager, freeing the VMM it manages

Definition at line 42 of file memorymanagement.cpp.

42 {
43
44 // Free the VMM (if this is not the kernel memory manager)
45 if(m_virtual_memory_manager != nullptr)
46 delete m_virtual_memory_manager;
47
48}

Member Function Documentation

◆ switch_active_memory_manager()

void BumpMemoryManager::switch_active_memory_manager ( BumpMemoryManager *  manager)
static

Switches the active memory manager.

Parameters
managerThe new memory manager

Definition at line 83 of file memorymanagement.cpp.

83 {
84
85 // Make sure there is a manager
86 if(manager == nullptr)
87 return;
88
89 // Switch the address space
90 asm volatile("mov %0, %%cr3"::"r"((uint64_t) manager->m_virtual_memory_manager->pml4_root_address_physical()) : "memory");
91
92}
uint64_t * pml4_root_address_physical()
Get the physical address of the PML4 root.
Definition virtual.cpp:476

References MaxOS::memory::VirtualMemoryManager::pml4_root_address_physical().

◆ vmm()

VirtualMemoryManager * BumpMemoryManager::vmm ( )

Gets the active virtual memory manager

Returns
The active virtual memory manager

Definition at line 72 of file memorymanagement.cpp.

72 {
73
74 return m_virtual_memory_manager;
75}

Referenced by MaxOS::processes::resources::BridgeHandler::BridgeHandler(), MaxOS::processes::SharedMemory::open(), MaxOS::processes::GlobalScheduler::prepare_initrd(), MaxOS::processes::Process::Process(), and MaxOS::processes::resources::BridgeHandler::send_to_bridge().


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