20 #include "pedigree/kernel/process/Ipc.h" 21 #include "pedigree/kernel/LockGuard.h" 22 #include "pedigree/kernel/processor/MemoryRegion.h" 23 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 24 #include "pedigree/kernel/processor/Processor.h" 25 #include "pedigree/kernel/processor/ProcessorInformation.h" 26 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 27 #include "pedigree/kernel/utilities/MemoryPool.h" 29 #include "pedigree/kernel/utilities/Result.h" 33 #define MEMPOOL_BUFF_SIZE 4096 34 #define MEMPOOL_BASE_SIZE 1024 36 static MemoryPool __ipc_mempool(
"IPC Message Pool");
43 return result.hasValue() ? result.value() :
nullptr;
46 void Ipc::createEndpoint(
String &name)
48 if (__endpoints.
lookup(name).hasValue())
53 void Ipc::removeEndpoint(
String &name)
55 if (!__endpoints.
lookup(name).hasValue())
62 if (!(pEndpoint && pMessage))
65 Mutex *pMutex = pEndpoint->pushMessage(pMessage, bAsync);
81 if (!(pEndpoint && pMessage))
84 IpcMessage *pMsg = pEndpoint->getMessage(!bAsync);
102 QueuedMessage *p =
new QueuedMessage;
103 p->pMessage = pMessage;
104 p->pMutex =
new Mutex(
true);
113 IpcMessage *IpcEndpoint::getMessage(
bool bBlock)
117 QueuedMessage *p = 0;
132 p = m_Queue.popFront();
138 p->pMutex->release();
148 Ipc::IpcMessage::IpcMessage() : nPages(1), m_vAddr(0), m_pMemRegion(0)
152 if (!__ipc_mempool.
initialise(MEMPOOL_BASE_SIZE, MEMPOOL_BUFF_SIZE))
154 ERROR(
"IpcMessage: memory pool could not be initialised.");
160 uintptr_t msg = __ipc_mempool.
allocate();
171 ERROR(
"IpcMessage: no memory available.");
176 Ipc::IpcMessage::IpcMessage(
size_t nBytes, uintptr_t regionHandle)
177 : nPages(0), m_vAddr(0), m_pMemRegion(0)
179 nPages = (nBytes / 4096) + 1;
198 ERROR(
"IpcMessage: region allocation failed.");
213 physical_uintptr_t map_phys = 0;
220 if (phys == map_phys)
236 ERROR(
"IpcMessage: region allocation (via handle) failed.");
259 return reinterpret_cast<void *
>(
m_vAddr);
uintptr_t m_vAddr
Virtual address of a message when m_pMemRegion is invalid.
A key/value dictionary for string keys.
static PhysicalMemoryManager & instance()
bool acquire(size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0)
static const size_t continuous
virtual void getMapping(void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)=0
virtual bool isMapped(void *virtualAddress)=0
MemoryRegion * m_pMemRegion
void insert(const String &key, const T &value)
static ProcessorInformation & information()
bool initialised()
Call if you aren't certain that the object has been initialised yet.
static const size_t Write
Result< T, bool > lookup(const String &key) const
Special memory entity in the kernel's virtual address space.
physical_uintptr_t physicalAddress() const
bool initialise(size_t poolSize, size_t bufferSize=1024)
void free(uintptr_t buffer)
Frees an allocated buffer, allowing it to be used elsewhere.
void * virtualAddress() const
bool tryAcquire(size_t n=1)
void remove(const String &key)
Implements a Radix Tree, a kind of Trie with compressed keys.