11#include <cosmos/BitMask.hxx>
12#include <cosmos/fs/FileDescriptor.hxx>
20namespace cosmos::mem {
57 INTO_32BIT = MAP_32BIT,
117 void setTLBPageSize(
size_t page_size);
166COSMOS_API
void* map(
const size_t length,
const MapSettings &settings);
177COSMOS_API
void unmap(
void *addr,
const size_t length);
211COSMOS_API
void protect(
void *addr,
const size_t length,
const AccessFlags flags,
const ProtectFlags extra = {});
218 FIXED = MREMAP_FIXED,
271COSMOS_API
void* remap(
void *old_addr,
const size_t old_size,
const size_t new_size,
272 const RemapFlags flags = {}, std::optional<void*> new_addr = {});
307COSMOS_API
void sync(
void *addr,
const size_t length,
308 const SyncFlags flags = SyncFlags{SyncFlag::SYNC});
350COSMOS_API
void lock(
void *addr,
const size_t length,
const LockFlags flags = {});
362COSMOS_API
void unlock(
void *addr,
const size_t length);
386COSMOS_API
void lock_all(
const LockAllFlags flags);
393COSMOS_API
void unlock_all();
Thin Wrapper around OS file descriptors.
Flags used in MapSettings.
@ SYNC
Similar to DSYNC, see man page.
@ NONBLOCK
Attempt to open the file in non-blocking mode causing I/O operations not to block.
@ ASYNC
Enable signal driven I/O for certain file types.
ProtectFlag
Extra flags used with mem::protect().
@ GROWSUP
Apply protection settings up to the end of mapping that grows upwards.
LockFlag
Flags used with cosmos::mem::lock().
@ LOCK_ON_FAULT
lock all pages that are already resident, the rest will be locked after a page fault occurs.
RemapFlag
Flags used with cosmos::mem::remap().
@ MAYMOVE
allow to move the mapping to a new starting address.
@ DONTUNMAP
used only together with MAYMOVE; keep the original mapping available for special memory algorithms li...
SyncFlag
Flags used with cosmos::mem::sync().
@ INVALIDATE
invalidate other mappings of the same file, allowing them to be updated with the changed data.
LockAllFlag
Flags passed to cosmos::mem::lockall().
@ ONFAULT
lock all current/future pages, but don't pre-fault them.
@ CURRENT
lock all currently loaded pages in memory.
@ FUTURE
lock all pages loaded in the future in memory.
MapType
The basic type of a memory mapping to be created.
@ SHARED
Creates a shared memory mapping that can be shared with other processes.
@ PRIVATE
A private copy-on-write mapping that isn't shared with other processes.
@ SHARED_VALIDATE
Same as SHARED but the MapFlags will be validated for unknown flags.
MapFlag
Flags that influence properties of memory mappings.
@ FIXED_NOREPLACE
Like FIXED but don't replace existing mappings, fail with EEXISTS instead.
@ STACK
Allocate the mapping at an address suitable for a thread stack (currently has no effect on Linux).
@ NORESERVE
Do not reserve swap space for this mapping.
@ GROWSDOWN
Create a mapping suitable for stacks, including automatic growing via a guard page.
@ POPULATE
Pre-fault page tables for a mapping.
@ ANONYMOUS
Create a mapping that is not backed by a file, contents are initialized to zero.
@ LOCKED
Mark the memory to be locked similar to mem::lock(), but no major faults will be prevented.
@ FIXED
Map memory exactly at the given hint address, replacing already existing mappings at the address.
@ UNINITIALIZED
Don't clear anonymous pages.
@ HUGETLB
Allocate the mapping using hugetlb page sizes, see also MapFlags::setTLBPageSize().
AccessFlag
Different memory page access permissions.
@ SEM
the memory can be used for atomic operations (used with futexes, doesn't currently do anything on any...
@ SAO
the memory should have strong access ordering (a PowerPC architecture feature)
@ WRITE
allow write access
@ EXEC
allow execute access
Collection of settings used in cosmos::mem::map().
off_t offset
offset into the file object starting from which the mapping will be setup for.
FileDescriptor fd
the file object to be mapped, if MapFlag::ANONYMOUS is set then leave this invalid.
void * addr
a hint where to place the mapping, or the exact address if MapFlag::FIXED is given.