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 memorize MAP_FAILED โ€” it's the "this went wrong" flag and it's a void *, 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 on mmap(). ๐ŸŒฑ
  • POSIX_TYPED_MEM_ALLOCATE_CONTIG โ€” Allocate contiguously on mmap(). ๐ŸŒˆ
  • POSIX_TYPED_MEM_MAP_ALLOCATABLE โ€” Map on mmap(), 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 those restrict qualifiers in posix_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. ๐Ÿ“š


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