F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MmapAllocator.cpp
Go to the documentation of this file.
1
14#include <cstdlib>
15#include <sys/mman.h>
16#include <Fw/Types/Assert.hpp>
17
18namespace Fw {
19
21 }
22
25
26 void *MmapAllocator::allocate(const NATIVE_UINT_TYPE identifier, NATIVE_UINT_TYPE &size, bool& recoverable) {
27 void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE,
28 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
29 if (addr == MAP_FAILED) {
30 size = 0;
31 return nullptr;
32 }
33 this->m_length = size;
34
35 // mmap memory is never recoverable
36 recoverable = false;
37
38 return addr;
39 }
40
41 void MmapAllocator::deallocate(const NATIVE_UINT_TYPE identifier, void* ptr) {
42 if (this->m_length) {
43 int stat = munmap(ptr, this->m_length);
44 FW_ASSERT(stat == 0, stat);
45 }
46 }
47
48} /* namespace Fw */
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
A MemAllocator implementation class that uses mmap.
void deallocate(const NATIVE_UINT_TYPE identifier, void *ptr)
virtual ~MmapAllocator()
Destructor with no arguments.
void * allocate(const NATIVE_UINT_TYPE identifier, NATIVE_UINT_TYPE &size, bool &recoverable)