MUNMAP(3P)
π MUNMAP(3P) β POSIX Programmer's Manual π
okay bestie, welcome to the POSIX Programmer's Manual page for munmap. quick vibe check first tho β¨
πΈ PROLOG πΈ
so like, this manual page is part of the POSIX Programmer's Manual, okay? and the tea is: the Linux implementation of this interface may differ (so if you're on Linux, go consult the corresponding Linux manual page for the actual details of Linux behavior), or honestly the interface may not even be implemented on Linux at all. no cap. π
β¨ NAME β¨
munmap β unmap pages of memory πΊοΈπ
π SYNOPSIS π
#include <sys/mman.h>
int munmap(void *addr, size_t len);
π¦ DESCRIPTION π¦
so 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. and then? further references to these pages shall result in the generation of a SIGSEGV signal to the process. π yes really, that's the consequence, it's giving "you asked for it."
if there are no mappings in the specified address range, then munmap() has no effect. it's just out here doing nothing, minding its business. π
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. bye bye edits π
any memory locks (see mlock() and mlockall()) associated with this address range shall be removed, as if by an appropriate call to munlock().
now this next part is the typed memory object lore π§: 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.
but 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. periodt. β
β οΈ and here's the warning bestie: the behavior of this function is unspecified if the mapping was not established by a call to mmap(). like, don't do that. that's not your moment. π
π RETURN VALUE π
upon successful completion, munmap() shall return 0 π; otherwise, it shall return -1 and set errno to indicate the error.
π₯ 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β thelenargument is0.
the munmap() function may fail if:
EINVALβ theaddrargument is not a multiple of the page size as returned bysysconf().
and just so you know, the following sections are informative. π
π EXAMPLES π
None. (literally nothing here, bestie, move along π)
β APPLICATION USAGE β
None. (again, empty, it's giving minimal effort but we respect it π«Ά)
π RATIONALE π
the munmap() function corresponds to SVR4, just as the mmap() function does. iconic lineage honestly.
so it's 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.
most implementations require that addr is a multiple of the page size as returned by sysconf().
π FUTURE DIRECTIONS π
None. (nothing coming, the future is quiet π)
π§ SEE ALSO π§
mlock(), mlockall(), mmap(), posix_typed_mem_open(), sysconf()
the Base Definitions volume of POSIX.1β2017, <sys_mman.h>
π 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. 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's brought to you by IEEE/The Open Group, dated 2017, and honestly? they ate. go unmap responsibly, munmap(3P) out. π
π¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms