MUNMAP(3POSIX)

πŸ’– MUNMAP(3POSIX) β€” the POSIX Programmer's Manual, bestie edition πŸ’–

okay so real talk, this page lives in the POSIX Programmer's Manual (yes, the whole POSIX Programmer's Manual, we love her). ✨


🌸 PROLOG 🌸

This manual page is part of the POSIX Programmer's Manual. Heads up though: the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or the interface might not even be implemented on Linux at all. πŸ™ˆ It's giving "results may vary", fr fr.


✨ NAME ✨

munmap β€” unmap pages of memory. she's literally the undo button for mmap, no cap. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/mman.h>

int munmap(void *addr, size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe. The munmap() function shall remove any mappings for those entire pages containing any part of the address space of the process starting at addr and continuing for len bytes. (entire pages, bestie β€” she's not doing partial pages, that's not her thing.)

Further references to these pages shall result in the generation of a SIGSEGV signal to the process. 😭 so like, don't touch. it's gone. periodt.

If there are no mappings in the specified address range, then munmap() has no effect. (chill, nothing bad happens, she just vibes.)

The implementation may require that addr be a multiple of the page size as returned by sysconf().

If a mapping to be removed was private, any modifications made in this address range shall be discarded. πŸ’€ gone gone, no takebacks.

Any memory locks (see mlock() and mlockall()) associated with this address range shall be removed, as if by an appropriate call to munlock().

If a mapping removed from a typed memory object causes the corresponding address range of the memory pool to be inaccessible by any process in the system except through allocatable mappings (that is, mappings of typed memory objects opened with the POSIX_TYPED_MEM_MAP_ALLOCATABLE flag), then that range of the memory pool shall become deallocated and may become available to satisfy future typed memory allocation requests.

A mapping removed from a typed memory object opened with the POSIX_TYPED_MEM_MAP_ALLOCATABLE flag shall not affect in any way the availability of that typed memory for allocation.

⚠️ big warning energy: the behavior of this function is unspecified if the mapping was not established by a call to mmap(). like, she didn't make that mess, she's not cleaning it up. don't do that.

πŸ’« RETURN VALUE πŸ’«

Upon successful completion, munmap() shall return 0. πŸŽ‰ otherwise, it shall return -1 and set errno to indicate the error. sad girl hours.


πŸ”₯ ERRORS πŸ”₯

The munmap() function shall fail if:

  • EINVAL β€” Addresses in the range [addr,addr+len) are outside the valid range for the address space of a process.
  • EINVAL β€” The len argument is 0. (zero? no. she said no. πŸ’€)

The munmap() function may fail if:

  • EINVAL β€” The addr argument is not a multiple of the page size as returned by sysconf().

The following sections are informative. (translation: the vibes section, not the rules section ✨)


🌈 EXAMPLES 🌈

None. she said no examples today bestie, we're keeping it mysterious. 🧚


πŸ’œ APPLICATION USAGE πŸ’œ

None. nothing to add, she's confident. πŸ‘‘


⭐ RATIONALE ⭐

The munmap() function corresponds to SVR4, just as the mmap() function does. (they're a matching set, it's giving iconic duo.)

It is possible that an application has applied process memory locking to a region that contains shared memory. If this has occurred, the munmap() call ignores those locks and, if necessary, causes those locks to be removed. 😀 she does not ask permission.

Most implementations require that addr is a multiple of the page size as returned by sysconf(). (so like, lowkey assume it, k?)


πŸ“ FUTURE DIRECTIONS πŸ“

None. the future is unwritten and she's not spoiling it. πŸ’…


🌸 SEE ALSO 🌸

  • mlock()
  • mlockall()
  • mmap()
  • posix_typed_mem_open()
  • sysconf()

The Base Definitions volume of POSIX.1‐2017, <sys_mman.h>


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. 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!! 🫢 this one came from IEEE/The Open Group, 2017, and the manual name is MUNMAP(3POSIX) β€” mwah, go unmap responsibly, ily, bye!! πŸ’–βœ¨πŸŽ€