virtualMemory.h File Reference

Architecture dependent routines for virtual memory. More...

+ Include dependency graph for virtualMemory.h:

Go to the source code of this file.

Enumerations

enum  ArchMemoryProtection { ArchProtectNoAccess, ArchProtectReadOnly, ArchProtectReadWrite, ArchProtectReadWriteCopy }
 Memory protection options, see ArchSetMemoryProtection(). More...
 

Functions

ARCH_API void * ArchReserveVirtualMemory (size_t numBytes)
 Reserve numBytes bytes of virtual memory. More...
 
ARCH_API bool ArchCommitVirtualMemoryRange (void *start, size_t numBytes)
 Make the range of numBytes bytes starting at start available for reading and writing. More...
 
ARCH_API bool ArchFreeVirtualMemory (void *start, size_t numBytes)
 Return memory obtained with ArchReserveVirtualMemory() to the system. More...
 
ARCH_API bool ArchSetMemoryProtection (void const *start, size_t numBytes, ArchMemoryProtection protection)
 Change the memory protection on the pages containing start and start + numBytes to protection. More...
 

Detailed Description

Architecture dependent routines for virtual memory.

Definition in file virtualMemory.h.

Enumeration Type Documentation

◆ ArchMemoryProtection

Memory protection options, see ArchSetMemoryProtection().

Definition at line 61 of file virtualMemory.h.

Function Documentation

◆ ArchCommitVirtualMemoryRange()

ARCH_API bool ArchCommitVirtualMemoryRange ( void *  start,
size_t  numBytes 
)

Make the range of numBytes bytes starting at start available for reading and writing.

The range must be within one previously reserved by ArchReserveVirtualMemory(). It is not an error to commit a range that was previously partly or fully committed. Return false in case of an error; check errno.

◆ ArchFreeVirtualMemory()

ARCH_API bool ArchFreeVirtualMemory ( void *  start,
size_t  numBytes 
)

Return memory obtained with ArchReserveVirtualMemory() to the system.

The start argument must be the value returned from a previous call to ArchReserveVirtualMemory, and numBytes must match the argument from that call. Memory within the range may not be accessed after this call. Return false in case of an error; check errno.

◆ ArchReserveVirtualMemory()

ARCH_API void* ArchReserveVirtualMemory ( size_t  numBytes)

Reserve numBytes bytes of virtual memory.

Call ArchCommitVirtualMemory() on subranges to write to and read from the memory. Return nullptr in case of an error; check errno.

◆ ArchSetMemoryProtection()

ARCH_API bool ArchSetMemoryProtection ( void const *  start,
size_t  numBytes,
ArchMemoryProtection  protection 
)

Change the memory protection on the pages containing start and start + numBytes to protection.

Return true if the protection is changed successfully. Return false in case of an error; check errno. This function rounds start to the nearest lower page boundary. On POSIX systems, ArchProtectReadWrite and ArchProtectReadWriteCopy are the same, on Windows they differ but the Windows API documentation does not make it clear what using ReadWrite means for a private file-backed mapping.