Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::SharedMemory Class Referencefinal

A block memory that is mapped into multiple processes. More...

#include <ipc.h>

Inheritance diagram for MaxOS::processes::SharedMemory:

Public Member Functions

 SharedMemory (const string &name, size_t size, resources::resource_type_t type)
 Creates a new shared memory block.
 
void open (size_t flags) final
 Map the shared memory into the address space of the owning process.
 
void close (size_t flags) final
 Frees the page containing the shared memory.
 
int read (void *buffer, size_t size, size_t flags) final
 Get the address that the current process has this shared memory mapped to.
 
uintptr_t physical_address () const
 Gets the physical address of the shared memory block.
 
size_t size () const
 Gets the size of the shared memory block.
 

Detailed Description

A block memory that is mapped into multiple processes.

Definition at line 45 of file ipc.h.

Constructor & Destructor Documentation

◆ SharedMemory()

SharedMemory::SharedMemory ( const string &  name,
size_t  size,
resources::resource_type_t  type 
)

Creates a new shared memory block.

Parameters
nameThe name of the block
sizeThe size of the shared memory region
typeThe type of resource

Definition at line 30 of file ipc.cpp.

31: Resource(name, size, MaxOS::KPI::ResourceType::SHARED_MEMORY),
32 m_size(size)
33{
34 m_physical_address = (uintptr_t) PhysicalMemoryManager::s_current_manager->allocate_area(0, size);
35}
static PhysicalMemoryManager * s_current_manager
The current physical memory manager in use.
Definition physical.h:183
size_t size() const
Gets the size of the shared memory block.
Definition ipc.cpp:72
KPI::Resource Resource
Alias to make the libsyscore Resource accessible here.
Definition resource.h:26

References MaxOS::memory::PhysicalMemoryManager::s_current_manager, and size().

Member Function Documentation

◆ close()

void SharedMemory::close ( size_t  flags)
final

Frees the page containing the shared memory.

Parameters
flagsNot used for this resource

Definition at line 99 of file ipc.cpp.

99 {
100
101 PhysicalMemoryManager::s_current_manager->free_area(m_physical_address, m_size);
102
103}
void free_area(uint64_t start_address, size_t size)
Frees an area of physical memory.
Definition physical.cpp:341

References MaxOS::memory::PhysicalMemoryManager::free_area(), and MaxOS::memory::PhysicalMemoryManager::s_current_manager.

◆ open()

void SharedMemory::open ( size_t  flags)
final

Map the shared memory into the address space of the owning process.

Parameters
flagsNot used for this resource

Definition at line 82 of file ipc.cpp.

82 {
83
84 // Process has already opened this memory
85 auto it = m_mappings.find(GlobalScheduler::current_process()->pid());
86 if(it != m_mappings.end())
87 return;
88
89 auto virtual_address = (uintptr_t)GlobalScheduler::current_process()->memory_manager->vmm()->load_shared_memory(m_physical_address, m_size);
90 m_mappings.insert(GlobalScheduler::current_process()->pid(), virtual_address);
91
92}
void * load_shared_memory(const string &name)
Load shared memory into the VMM's address space.
Definition virtual.cpp:487
static Process * current_process()
Gets the process on the currently executing core.
uint64_t pid() const
Gets the pid of the process.
Definition process.cpp:429
memory::MemoryManager * memory_manager
The manager for memory used by this process.
Definition process.h:121

References MaxOS::processes::GlobalScheduler::current_process(), MaxOS::memory::VirtualMemoryManager::load_shared_memory(), MaxOS::processes::Process::memory_manager, MaxOS::processes::Process::pid(), and MaxOS::memory::BumpMemoryManager::vmm().

◆ physical_address()

uintptr_t SharedMemory::physical_address ( ) const

Gets the physical address of the shared memory block.

Returns
The physical address

Definition at line 62 of file ipc.cpp.

62 {
63
64 return m_physical_address;
65}

◆ read()

int SharedMemory::read ( void *  buffer,
size_t  size,
size_t  flags 
)
final

Get the address that the current process has this shared memory mapped to.

Parameters
bufferNot used
sizeNot used
flagsNot used
Returns
The virtual address in the current process's address space or 0 if not found

Definition at line 47 of file ipc.cpp.

47 {
48
49 // Process hasn't opened the resource
50 auto it = m_mappings.find(GlobalScheduler::current_process()->pid());
51 if(it == m_mappings.end())
52 return 0;
53
54 return it->second;
55}

References MaxOS::processes::GlobalScheduler::current_process().

◆ size()

size_t SharedMemory::size ( ) const

Gets the size of the shared memory block.

Returns
The size

Definition at line 72 of file ipc.cpp.

72 {
73
74 return m_size;
75}

Referenced by SharedMemory().


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