MINHERIT(2)
π¦ MINHERIT(2) β the inheritance-vibes system call π
okay so this is a page from the System Calls Manual, section 2, and the star of the show is minherit. Yes bestie, we're doing memory inheritance today. Buckle up π
β¨ NAME β¨
minherit β control the inheritance of pages
π LIBRARY π
Standard C Library (libc, -lc) β she's built in, no extra shopping required π«Ά
π§ SYNOPSIS π§
#include <sys/mman.h>
int
minherit(void *addr, size_t len, int inherit);
πΈ DESCRIPTION πΈ
So minherit() is a system call that changes the specified pages so they have the inheritance characteristic inherit. Iconic. But hear me out: not all implementations will guarantee that the inheritance characteristic can be set on a page basis β the granularity of changes may be as large as an entire region π. FreeBSD is capable of adjusting inheritance characteristics on a page basis though, so slay for FreeBSD β¨.
Inheritance only effects children created by fork(). It has no effect on exec() β exec'd processes replace their address space entirely, like a full glow-up, nothing carried over. This system call also has no effect on the parent's address space (other than to potentially share the address space with its children).
Ngl, inheritance is a rather esoteric feature, largely superseded by the MAP_SHARED feature of mmap(). But π‘ it is possible to use minherit() to share a block of memory between parent and child that has been mapped MAP_PRIVATE. That is, modifications made by parent or child are shared but the original underlying file is left untouched. Obsessed, honestly.
INHERIT_SHAREβ this option causes the address space in question to be shared between parent and child. It has no effect on how the original underlying backing store was mapped.INHERIT_NONEβ this option prevents the address space in question from being inherited at all. The address space will be unmapped in the child. Gone. Blocked. Uninvited from the group chat πINHERIT_COPYβ this option causes the child to inherit the address space as copy-on-write. But β οΈ this option also has an unfortunate side effect of causing the parent address space to become copy-on-write when the parent forks. If the original mapping wasMAP_SHARED, it will no longer be shared in the parent after the parent forks, and there is no way to get the previous shared-backing-store mapping without unmapping and remapping the address space in the parent. Not the vibe, but facts are facts π«INHERIT_ZEROβ this option causes the address space in question to be mapped as new anonymous pages, which would be initialized to all zero bytes, in the child process. Fresh start energy, main character reborn with a blank slate π§Όβ¨
π RETURN VALUES π
The minherit() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. Classic. 0 = good, -1 = check errno bestie π
π₯ ERRORS π₯
The minherit() system call will fail if:
[EINVAL]β the virtual address range specified by theaddrandlenarguments is not valid. Ma'am that range does not exist π[EACCES]β the flags specified by theinheritargument were not valid for the pages specified by theaddrandlenarguments. Permission said no π
π SEE ALSO π
fork(2), madvise(2), mincore(2), mprotect(2), msync(2), munmap(2), rfork(2) β go read those next, iykyk ππ
π HISTORY π
The minherit() system call first appeared in OpenBSD and then in FreeBSD 2.2. A legend was born β¨
The INHERIT_ZERO support first appeared in OpenBSD 5.6 and then in FreeBSD 12.0. She arrived late but she arrived π
π BUGS π
Once you set inheritance to MAP_PRIVATE or MAP_SHARED, there is no way to recover the original copy-on-write semantics short of unmapping and remapping the area. So like... choose wisely bestie, there's no undo button π no cap.
that's the whole page! shipped to you from Debian, dated March 15, 2017, MINHERIT(2) and all π«Άπ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms