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