sys_mman.h(7POSIX)
๐ฆ sys_mman.h โ the memory management header, bestie edition
okay so real talk, this is the POSIX Programmer's Manual page for sys_mman.h, and it's giving โจ "all the memory vibes in one header" โจ. Manual name is sys_mman.h(7POSIX) if you were wondering, and yes I will be saying "shall define" a lot because that's just how POSIX talks, periodt.
๐ PROLOG ๐
heads up bestie ๐ซถ this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ โ so go check the corresponding Linux manual page for the deets on Linux behavior โ or honestly the interface might not even be implemented on Linux at all. ๐
๐ธ NAME ๐ธ
sys/mman.h โ memory management declarations. that's it, that's the whole name section, iconic.
โจ SYNOPSIS โจ
#include <sys/mman.h>
one include, no notes, we love a low-maintenance header. ๐
๐ DESCRIPTION ๐
The <sys/mman.h> header shall define the following symbolic constants for use as protection options:
PROT_EXECโ Page can be executed. ๐โ๏ธPROT_NONEโ Page cannot be accessed. nope, not even a peek, absolutely not. ๐ซPROT_READโ Page can be read. ๐PROT_WRITEโ Page can be written. โ๏ธ
The <sys/mman.h> header shall define the following symbolic constants for use as flag options:
MAP_FIXEDโ Interpret addr exactly. no wiggle room, it means EXACTLY. ๐MAP_PRIVATEโ Changes are private. ๐คซMAP_SHAREDโ Share changes. ๐ค
The <sys/mman.h> header shall define the following symbolic constants for the msync() function:
MS_ASYNCโ Perform asynchronous writes. ๐ฆMS_INVALIDATEโ Invalidate mappings. ๐MS_SYNCโ Perform synchronous writes. โณ
The <sys/mman.h> header shall define the following symbolic constants for the mlockall() function:
MCL_CURRENTโ Lock currently mapped pages. ๐MCL_FUTUREโ Lock pages that become mapped. ๐ฎ
The <sys/mman.h> header shall define the symbolic constant MAP_FAILED which shall have type void * and shall be used to indicate a failure from the mmap() function.
not me making you memorizeMAP_FAILEDโ it's the "this went wrong" flag and it's avoid *, okurrr? ๐ญ
If the Advisory Information option is supported, the <sys/mman.h> header shall define symbolic constants for the advice argument to the posix_madvise() function as follows:
POSIX_MADV_DONTNEEDโ The application expects that it will not access the specified range in the near future. bye bye, don't need it. ๐POSIX_MADV_NORMALโ The application has no advice to give on its behavior with respect to the specified range. It is the default characteristic if no advice is given for a range of memory. the "no thoughts, head empty" option ๐ซงPOSIX_MADV_RANDOMโ The application expects to access the specified range in a random order. chaos mode, we love her ๐ฒPOSIX_MADV_SEQUENTIALโ The application expects to access the specified range sequentially from lower addresses to higher addresses. one direction only, like a good playlist ๐งPOSIX_MADV_WILLNEEDโ The application expects to access the specified range in the near future. manifesting it, bestie โจ
The <sys/mman.h> header shall define the following symbolic constants for use as flags for the posix_typed_mem_open() function:
POSIX_TYPED_MEM_ALLOCATEโ Allocate onmmap(). ๐ฑPOSIX_TYPED_MEM_ALLOCATE_CONTIGโ Allocate contiguously onmmap(). ๐POSIX_TYPED_MEM_MAP_ALLOCATABLEโ Map onmmap(), without affecting allocatability. ๐ง
The <sys/mman.h> header shall define the mode_t, off_t, and size_t types as described in <sys_types.h>.
The <sys/mman.h> header shall define the posix_typed_mem_info structure, which shall include at least the following member:
size_t posix_tmi_length Maximum length which may be allocated
from a typed memory object.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
int mlock(const void *, size_t);
int mlockall(int);
void *mmap(void *, size_t, int, int, int, off_t);
int mprotect(void *, size_t, int);
int msync(void *, size_t, int);
int munlock(const void *, size_t);
int munlockall(void);
int munmap(void *, size_t);
int posix_madvise(void *, size_t, int);
int posix_mem_offset(const void *restrict, size_t, off_t *restrict,
size_t *restrict, int *restrict);
int posix_typed_mem_get_info(int, struct posix_typed_mem_info *);
int posix_typed_mem_open(const char *, int, int);
int shm_open(const char *, int, mode_t);
int shm_unlink(const char *);
look at all thoserestrictqualifiers inposix_mem_offset()โ highkey a serve, they're telling the compiler "nobody's aliasing, trust me". ๐
The following sections are informative. (yes, informative โ meaning they're not the normative tea, they're the commentary track. ๐๏ธ)
๐ APPLICATION USAGE ๐
None. literally nothing. it's giving minimalism. ๐
๐ง RATIONALE ๐ง
None. no rationale, no explanation, just vibes and standards documents. ๐
โญ FUTURE DIRECTIONS โญ
None. the future is unwritten bestie. ๐ฎ
๐ฅ SEE ALSO ๐ฅ
<sys_types.h>
The System Interfaces volume of POSIX.1โ2017, plus:
mlock(), mlockall(), mmap(), mprotect(), msync(), munmap(), posix_madvise(), posix_mem_offset(), posix_typed_mem_get_info(), posix_typed_mem_open(), shm_open(), shm_unlink()
go read those too, they're all bangers, iykyk. ๐
๐ COPYRIGHT ๐
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (translation: if they disagree, the real standard wins, no cap. ๐) The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie, mwah ๐ this one came from IEEE/The Open Group, 2017 โ sys_mman.h(7POSIX), memory management declarations, ate and left no crumbs. ๐โจ๐ฆ
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms