xref: /freebsd/lib/libsys/minherit.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"
2*8269e767SBrooks Davis.\" Copyright (c) 1991, 1993
3*8269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
4*8269e767SBrooks Davis.\"
5*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
6*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
7*8269e767SBrooks Davis.\" are met:
8*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
9*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
10*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
11*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
12*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
13*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
14*8269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
15*8269e767SBrooks Davis.\"    without specific prior written permission.
16*8269e767SBrooks Davis.\"
17*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*8269e767SBrooks Davis.\" SUCH DAMAGE.
28*8269e767SBrooks Davis.\"
29*8269e767SBrooks Davis.Dd March 15, 2017
30*8269e767SBrooks Davis.Dt MINHERIT 2
31*8269e767SBrooks Davis.Os
32*8269e767SBrooks Davis.Sh NAME
33*8269e767SBrooks Davis.Nm minherit
34*8269e767SBrooks Davis.Nd control the inheritance of pages
35*8269e767SBrooks Davis.Sh LIBRARY
36*8269e767SBrooks Davis.Lb libc
37*8269e767SBrooks Davis.Sh SYNOPSIS
38*8269e767SBrooks Davis.In sys/mman.h
39*8269e767SBrooks Davis.Ft int
40*8269e767SBrooks Davis.Fn minherit "void *addr" "size_t len" "int inherit"
41*8269e767SBrooks Davis.Sh DESCRIPTION
42*8269e767SBrooks DavisThe
43*8269e767SBrooks Davis.Fn minherit
44*8269e767SBrooks Davissystem call
45*8269e767SBrooks Davischanges the specified pages to have the inheritance characteristic
46*8269e767SBrooks Davis.Fa inherit .
47*8269e767SBrooks DavisNot all implementations will guarantee that the inheritance characteristic
48*8269e767SBrooks Daviscan be set on a page basis;
49*8269e767SBrooks Davisthe granularity of changes may be as large as an entire region.
50*8269e767SBrooks Davis.Fx
51*8269e767SBrooks Davisis capable of adjusting inheritance characteristics on a page basis.
52*8269e767SBrooks DavisInheritance only effects children created by
53*8269e767SBrooks Davis.Fn fork .
54*8269e767SBrooks DavisIt has no effect on
55*8269e767SBrooks Davis.Fn exec .
56*8269e767SBrooks Davisexec'd processes replace their address space entirely.
57*8269e767SBrooks DavisThis system call also
58*8269e767SBrooks Davishas no effect on the parent's address space (other than to potentially
59*8269e767SBrooks Davisshare the address space with its children).
60*8269e767SBrooks Davis.Pp
61*8269e767SBrooks DavisInheritance is a rather esoteric feature largely superseded by the
62*8269e767SBrooks Davis.Dv MAP_SHARED
63*8269e767SBrooks Davisfeature of
64*8269e767SBrooks Davis.Fn mmap .
65*8269e767SBrooks DavisHowever, it is possible to use
66*8269e767SBrooks Davis.Fn minherit
67*8269e767SBrooks Davisto share a block of memory between parent and child that has been mapped
68*8269e767SBrooks Davis.Dv MAP_PRIVATE .
69*8269e767SBrooks DavisThat is, modifications made by parent or child are shared but
70*8269e767SBrooks Davisthe original underlying file is left untouched.
71*8269e767SBrooks Davis.Bl -tag -width ".Dv INHERIT_SHARE"
72*8269e767SBrooks Davis.It Dv INHERIT_SHARE
73*8269e767SBrooks DavisThis option causes the address space in question to be shared between
74*8269e767SBrooks Davisparent and child.
75*8269e767SBrooks DavisIt has no effect on how the original underlying backing
76*8269e767SBrooks Davisstore was mapped.
77*8269e767SBrooks Davis.It Dv INHERIT_NONE
78*8269e767SBrooks DavisThis option prevents the address space in question from being inherited
79*8269e767SBrooks Davisat all.
80*8269e767SBrooks DavisThe address space will be unmapped in the child.
81*8269e767SBrooks Davis.It Dv INHERIT_COPY
82*8269e767SBrooks DavisThis option causes the child to inherit the address space as copy-on-write.
83*8269e767SBrooks DavisThis option also has an unfortunate side effect of causing the parent
84*8269e767SBrooks Davisaddress space to become copy-on-write when the parent forks.
85*8269e767SBrooks DavisIf the original mapping was
86*8269e767SBrooks Davis.Dv MAP_SHARED ,
87*8269e767SBrooks Davisit will no longer be shared in the parent
88*8269e767SBrooks Davisafter the parent forks and there is no way to get the previous
89*8269e767SBrooks Davisshared-backing-store mapping without unmapping and remapping the address
90*8269e767SBrooks Davisspace in the parent.
91*8269e767SBrooks Davis.It Dv INHERIT_ZERO
92*8269e767SBrooks DavisThis option causes the address space in question to be mapped as new
93*8269e767SBrooks Davisanonymous pages,
94*8269e767SBrooks Daviswhich would be initialized to all zero bytes,
95*8269e767SBrooks Davisin the child process.
96*8269e767SBrooks Davis.El
97*8269e767SBrooks Davis.Sh RETURN VALUES
98*8269e767SBrooks Davis.Rv -std minherit
99*8269e767SBrooks Davis.Sh ERRORS
100*8269e767SBrooks DavisThe
101*8269e767SBrooks Davis.Fn minherit
102*8269e767SBrooks Davissystem call will fail if:
103*8269e767SBrooks Davis.Bl -tag -width Er
104*8269e767SBrooks Davis.It Bq Er EINVAL
105*8269e767SBrooks DavisThe virtual address range specified by the
106*8269e767SBrooks Davis.Fa addr
107*8269e767SBrooks Davisand
108*8269e767SBrooks Davis.Fa len
109*8269e767SBrooks Davisarguments is not valid.
110*8269e767SBrooks Davis.It Bq Er EACCES
111*8269e767SBrooks DavisThe flags specified by the
112*8269e767SBrooks Davis.Fa inherit
113*8269e767SBrooks Davisargument were not valid for the pages specified
114*8269e767SBrooks Davisby the
115*8269e767SBrooks Davis.Fa addr
116*8269e767SBrooks Davisand
117*8269e767SBrooks Davis.Fa len
118*8269e767SBrooks Davisarguments.
119*8269e767SBrooks Davis.El
120*8269e767SBrooks Davis.Sh SEE ALSO
121*8269e767SBrooks Davis.Xr fork 2 ,
122*8269e767SBrooks Davis.Xr madvise 2 ,
123*8269e767SBrooks Davis.Xr mincore 2 ,
124*8269e767SBrooks Davis.Xr mprotect 2 ,
125*8269e767SBrooks Davis.Xr msync 2 ,
126*8269e767SBrooks Davis.Xr munmap 2 ,
127*8269e767SBrooks Davis.Xr rfork 2
128*8269e767SBrooks Davis.Sh HISTORY
129*8269e767SBrooks DavisThe
130*8269e767SBrooks Davis.Fn minherit
131*8269e767SBrooks Davissystem call first appeared in
132*8269e767SBrooks Davis.Ox
133*8269e767SBrooks Davisand then in
134*8269e767SBrooks Davis.Fx 2.2 .
135*8269e767SBrooks Davis.Pp
136*8269e767SBrooks DavisThe
137*8269e767SBrooks Davis.Dv INHERIT_ZERO
138*8269e767SBrooks Davissupport first appeared in
139*8269e767SBrooks Davis.Ox 5.6
140*8269e767SBrooks Davisand then in
141*8269e767SBrooks Davis.Fx 12.0 .
142*8269e767SBrooks Davis.Sh BUGS
143*8269e767SBrooks DavisOnce you set inheritance to
144*8269e767SBrooks Davis.Dv MAP_PRIVATE
145*8269e767SBrooks Davisor
146*8269e767SBrooks Davis.Dv MAP_SHARED ,
147*8269e767SBrooks Davisthere is no way to recover the original copy-on-write semantics
148*8269e767SBrooks Davisshort of unmapping and remapping the area.
149