Memory mapping type with move-only ownership semantics.
More...
#include <Mapping.hxx>
|
| Mapping ()=default |
| Creates an invalid memory mapping.
|
|
| Mapping (const size_t size, const mem::MapSettings &settings) |
| Create a new memory mapping based on the given settings.
|
|
| Mapping (const Mapping &)=delete |
|
Mapping & | operator= (const Mapping &)=delete |
|
| Mapping (Mapping &&other) noexcept |
|
Mapping & | operator= (Mapping &&other) noexcept |
|
bool | valid () const |
|
void | unmap () |
|
void | remap (const size_t new_size, const mem::RemapFlags &flags={}, std::optional< void * > new_addr={}) |
| Adjust the memory mappings using new settings.
|
|
void * | addr () |
| Returns the base address of the mapped memory.
|
|
const void * | addr () const |
|
size_t | size () const |
| Returns the size of the mapped memory in bytes.
|
|
void | sync (const mem::SyncFlags flags) |
| Synchronize changes in the mapping with the file backing it.
|
|
void | lock (const mem::LockFlags flags={}) |
| Lock pages in memory, preventing memory from being paged to the swap area.
|
|
void | unlock () |
| Unlock previously locked pages.
|
|
void | setProtection (const mem::AccessFlags flags) |
| Change memory protection settings.
|
|
Memory mapping type with move-only ownership semantics.
Instances of this type can be obtained via cosmos::mem::map() found in proc/mman.hxx.
Definition at line 13 of file Mapping.hxx.
◆ Mapping() [1/2]
cosmos::Mapping::Mapping |
( |
const size_t | size, |
|
|
const mem::MapSettings & | settings ) |
|
inline |
Create a new memory mapping based on the given settings.
For error conditions refer to cosmos::proc::map().
Definition at line 23 of file Mapping.hxx.
23 {
24 m_addr = mem::map(
size, settings);
26 }
size_t size() const
Returns the size of the mapped memory in bytes.
◆ ~Mapping()
cosmos::Mapping::~Mapping |
( |
| ) |
|
|
inline |
◆ Mapping() [2/2]
cosmos::Mapping::Mapping |
( |
Mapping && | other | ) |
|
|
inlinenoexcept |
Definition at line 38 of file Mapping.hxx.
38 {
39 *this = std::move(other);
40 }
◆ addr() [1/2]
void * cosmos::Mapping::addr |
( |
| ) |
|
|
inline |
Returns the base address of the mapped memory.
Definition at line 77 of file Mapping.hxx.
77 {
78 return m_addr;
79 }
◆ addr() [2/2]
const void * cosmos::Mapping::addr |
( |
| ) |
const |
|
inline |
Definition at line 81 of file Mapping.hxx.
81 {
82 return m_addr;
83 }
◆ invalidate()
void cosmos::Mapping::invalidate |
( |
| ) |
|
|
inlineprotected |
Definition at line 124 of file Mapping.hxx.
124 {
125 m_addr = nullptr;
126 m_size = 0;
127 }
◆ lock()
Lock pages in memory, preventing memory from being paged to the swap area.
- See also
- cosmos::mem::lock().
Definition at line 102 of file Mapping.hxx.
102 {}) {
103 mem::lock(m_addr, m_size, flags);
104 }
◆ operator=()
Definition at line 42 of file Mapping.hxx.
42 {
43 m_addr = other.m_addr;
44 m_size = other.m_size;
45 other.invalidate();
46 return *this;
47 }
◆ remap()
void cosmos::Mapping::remap |
( |
const size_t | new_size, |
|
|
const mem::RemapFlags & | flags = {}, |
|
|
std::optional< void * > | new_addr = {} ) |
|
inline |
Adjust the memory mappings using new settings.
For error conditions refer to cosmos::proc::remap().
Definition at line 71 of file Mapping.hxx.
71 {}, std::optional<void*> new_addr = {}) {
72 m_addr = mem::remap(m_addr, m_size, new_size, flags, new_addr);
73 m_size = new_size;
74 }
◆ setProtection()
Change memory protection settings.
- See also
- cosmos::mem::protect().
Definition at line 118 of file Mapping.hxx.
118 {
119 mem::protect(m_addr, m_size, flags);
120 }
◆ size()
size_t cosmos::Mapping::size |
( |
| ) |
const |
|
inline |
Returns the size of the mapped memory in bytes.
Definition at line 86 of file Mapping.hxx.
86 {
87 return m_size;
88 }
◆ sync()
Synchronize changes in the mapping with the file backing it.
- See also
- cosmos::mem::sync().
Definition at line 94 of file Mapping.hxx.
94 {
95 mem::sync(m_addr, m_size, flags);
96 }
◆ unlock()
void cosmos::Mapping::unlock |
( |
| ) |
|
|
inline |
Unlock previously locked pages.
- See also
- cosmos::mem::unlock().
Definition at line 110 of file Mapping.hxx.
110 {
111 mem::unlock(m_addr, m_size);
112 }
◆ unmap()
void cosmos::Mapping::unmap |
( |
| ) |
|
|
inline |
Definition at line 53 of file Mapping.hxx.
53 {
54 if (!valid())
55 return;
56
57 try {
58 mem::unmap(m_addr, m_size);
59 invalidate();
60 } catch (...) {
61
62 invalidate();
63 throw;
64 }
65 }
◆ valid()
bool cosmos::Mapping::valid |
( |
| ) |
const |
|
inline |
Definition at line 49 of file Mapping.hxx.
49 {
50 return m_addr != nullptr;
51 }
◆ m_addr
void* cosmos::Mapping::m_addr = nullptr |
|
protected |
◆ m_size
size_t cosmos::Mapping::m_size = 0 |
|
protected |
The documentation for this class was generated from the following file: