#include <sys/mman.h>

sys/mman.h

58 macros · 14 functions

macroPROT_NONE

Protections are chosen from these bits, or-ed together
#define PROT_NONE 0x00
[MC2] no permissions

macroPROT_READ

#define PROT_READ 0x01
[MC2] pages can be read

macroPROT_WRITE

#define PROT_WRITE 0x02
[MC2] pages can be written

macroPROT_EXEC

#define PROT_EXEC 0x04
[MC2] pages can be executed

macroMAP_SHARED

Flags contain sharing type and options. Sharing types; choose one.
#define MAP_SHARED 0x0001
[MF|SHM] share changes

macroMAP_PRIVATE

#define MAP_PRIVATE 0x0002
[MF|SHM] changes are private

macroMAP_COPY

#define MAP_COPY MAP_PRIVATE
Obsolete

macroMAP_FIXED

Other flags
#define MAP_FIXED 0x0010
[MF|SHM] interpret addr exactly

macroMAP_RENAME

#define MAP_RENAME 0x0020
Sun: rename private pages to file

macroMAP_NORESERVE

#define MAP_NORESERVE 0x0040
Sun: don't reserve needed swap area

macroMAP_RESERVED0080

#define MAP_RESERVED0080 0x0080
previously unimplemented MAP_INHERIT

macroMAP_NOEXTEND

#define MAP_NOEXTEND 0x0100
for MAP_FILE, don't change file size

macroMAP_HASSEMAPHORE

#define MAP_HASSEMAPHORE 0x0200
region may contain semaphores

macroMAP_NOCACHE

#define MAP_NOCACHE 0x0400
don't cache pages for this mapping

macroMAP_JIT

#define MAP_JIT 0x0800
Allocate a region that will be used for JIT purposes

macroMAP_FILE

Mapping type
#define MAP_FILE 0x0000
map from file (default)

macroMAP_ANON

#define MAP_ANON 0x1000
allocated from memory, swap space

macroMAP_ANONYMOUS

#define MAP_ANONYMOUS MAP_ANON

macroMAP_RESILIENT_CODESIGN

The MAP_RESILIENT_* flags can be used when the caller wants to map some possibly unreliable memory and be able to access it safely, possibly getting the wrong contents rather than raising any exception. For safety reasons, such mappings have to be read-only (PROT_READ access only). MAP_RESILIENT_CODESIGN: accessing this mapping will not generate code-signing violations, even if the contents are tainted. MAP_RESILIENT_MEDIA: accessing this mapping will not generate an exception if the contents are not available (unreachable removable or remote media, access beyond end-of-file, ...). Missing contents will be replaced with zeroes.
#define MAP_RESILIENT_CODESIGN 0x2000
no code-signing failures

macroMAP_RESILIENT_MEDIA

#define MAP_RESILIENT_MEDIA 0x4000
no backing-store failures

macroMAP_32BIT

#define MAP_32BIT 0x8000
Return virtual addresses <4G only

macroMAP_TRANSLATED_ALLOW_EXECUTE

Flags used to support translated processes.
#define MAP_TRANSLATED_ALLOW_EXECUTE 0x20000
allow execute in translated processes

macroMAP_UNIX03

#define MAP_UNIX03 0x40000
UNIX03 compliance

macroMAP_TPRO

#define MAP_TPRO 0x80000
Allocate a region that will be protected by TPRO

macroMCL_CURRENT

Process memory locking
#define MCL_CURRENT 0x0001
[ML] Lock only current memory

macroMCL_FUTURE

#define MCL_FUTURE 0x0002
[ML] Lock all future memory as well

macroMAP_FAILED

Error return from mmap()
#define MAP_FAILED ((void *)-1)
[MF|SHM] mmap failed

macroMS_ASYNC

msync() flags When making a new MS_*, update tests vm_parameter_validation_[user|kern] and their expected results; they deliberately call VM functions with invalid msync values and you may be turning one of those invalid msyncs valid.
#define MS_ASYNC 0x0001
[MF|SIO] return immediately

macroMS_INVALIDATE

#define MS_INVALIDATE 0x0002
[MF|SIO] invalidate all cached data

macroMS_SYNC

#define MS_SYNC 0x0010
[MF|SIO] msync synchronously

macroMS_KILLPAGES

#define MS_KILLPAGES 0x0004
invalidate pages, leave mapped

macroMS_DEACTIVATE

#define MS_DEACTIVATE 0x0008
deactivate pages, leave mapped

macroPOSIX_MADV_NORMAL

Advice to madvise When making a new MADV_*, update tests vm_parameter_validation_[user|kern] and their expected results; they deliberately call VM functions with invalid madvise values and you may be turning one of those invalid madvises valid.
#define POSIX_MADV_NORMAL 0
[MC1] no further special treatment

macroPOSIX_MADV_RANDOM

#define POSIX_MADV_RANDOM 1
[MC1] expect random page refs

macroPOSIX_MADV_SEQUENTIAL

#define POSIX_MADV_SEQUENTIAL 2
[MC1] expect sequential page refs

macroPOSIX_MADV_WILLNEED

#define POSIX_MADV_WILLNEED 3
[MC1] will need these pages

macroPOSIX_MADV_DONTNEED

#define POSIX_MADV_DONTNEED 4
[MC1] dont need these pages

macroMADV_NORMAL

#define MADV_NORMAL POSIX_MADV_NORMAL

macroMADV_RANDOM

#define MADV_RANDOM POSIX_MADV_RANDOM

macroMADV_SEQUENTIAL

#define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL

macroMADV_WILLNEED

#define MADV_WILLNEED POSIX_MADV_WILLNEED

macroMADV_DONTNEED

#define MADV_DONTNEED POSIX_MADV_DONTNEED

macroMADV_FREE

#define MADV_FREE 5
pages unneeded, discard contents

macroMADV_ZERO_WIRED_PAGES

#define MADV_ZERO_WIRED_PAGES 6
zero the wired pages that have not been unwired before the entry is deleted

macroMADV_FREE_REUSABLE

#define MADV_FREE_REUSABLE 7
pages can be reused (by anyone)

macroMADV_FREE_REUSE

#define MADV_FREE_REUSE 8
caller wants to reuse those pages

macroMADV_CAN_REUSE

#define MADV_CAN_REUSE 9

macroMADV_PAGEOUT

#define MADV_PAGEOUT 10
page out now (internal only)

macroMADV_ZERO

#define MADV_ZERO 11
zero pages without faulting in additional pages

macroMINCORE_INCORE

Return bits from mincore
#define MINCORE_INCORE 0x1
Page is incore

macroMINCORE_REFERENCED

#define MINCORE_REFERENCED 0x2
Page has been referenced by us

macroMINCORE_MODIFIED

#define MINCORE_MODIFIED 0x4
Page has been modified by us

macroMINCORE_REFERENCED_OTHER

#define MINCORE_REFERENCED_OTHER 0x8
Page has been referenced

macroMINCORE_MODIFIED_OTHER

#define MINCORE_MODIFIED_OTHER 0x10
Page has been modified

macroMINCORE_PAGED_OUT

#define MINCORE_PAGED_OUT 0x20
Page has been paged out

macroMINCORE_COPIED

#define MINCORE_COPIED 0x40
Page has been copied

macroMINCORE_ANONYMOUS

#define MINCORE_ANONYMOUS 0x80
Page belongs to an anonymous object

functionmlockall

int mlockall(int)
[ML]

functionmunlockall

int munlockall(void)

functionmlock

int mlock(const void *, size_t)
[MR]
man page · June 2, 1993
mlock(2) — lock (unlock) physical pages in memory

macro_MMAP

#define _MMAP 

functionmmap

__DARWIN_ALIAS(mmap)
void * mmap(void *, size_t, int, int, int, off_t)
[MC3]
man page · February 14, 2020
mmap(2) — allocate memory, or map files or devices into memory

functionmprotect

__DARWIN_ALIAS(mprotect)
int mprotect(void *, size_t, int)
[MPR]
man page · October 16, 2008
mprotect(2) — control the protection of pages

functionmsync

__DARWIN_ALIAS_C(msync)
int msync(void *, size_t, int)
[MF|SIO]
man page · June 21, 1994
msync(2) — synchronize a mapped region

functionmunlock

int munlock(const void *, size_t)
[MR]
man page · June 2, 1993
munlock(2) — lock (unlock) physical pages in memory

functionmunmap

__DARWIN_ALIAS(munmap)
int munmap(void *, size_t)
[MC3]
man page · October 16, 2008
munmap(2) — remove a mapping

functionshm_open

int shm_open(const char *, int, ...)
[SHM]
man page · August 29, 2008
shm_open(2) — open a shared memory object

functionposix_madvise

int posix_madvise(void *, size_t, int)
[ADV]
man page · June 9, 1993
posix_madvise(2) — give advice about use of memory

functionmadvise

int madvise(void *, size_t, int)
man page · June 9, 1993
madvise(2) — give advice about use of memory

functionmincore

int mincore(const void *, size_t, char *)
man page · June 9, 1993
mincore(2) — determine residency of memory pages
⚠ the man page prototype differs from the current header — man: int mincore(char*, size_t, char*) · header: int mincore(void*, size_t, char*)

functionminherit

int minherit(void *, size_t, int)
man page · June 9, 1993
minherit(2) — control the inheritance of pages
⚠ the man page prototype differs from the current header — man: int minherit(char*, size_t, int) · header: int minherit(void*, size_t, int)