]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/mprotect.2
zfs: merge openzfs/zfs@a03ebd9be
[FreeBSD/FreeBSD.git] / lib / libc / sys / mprotect.2
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .Dd September 7, 2021
29 .Dt MPROTECT 2
30 .Os
31 .Sh NAME
32 .Nm mprotect
33 .Nd control the protection of pages
34 .Sh LIBRARY
35 .Lb libc
36 .Sh SYNOPSIS
37 .In sys/mman.h
38 .Ft int
39 .Fn mprotect "void *addr" "size_t len" "int prot"
40 .Sh DESCRIPTION
41 The
42 .Fn mprotect
43 system call
44 changes the specified pages to have protection
45 .Fa prot .
46 .Pp
47 The
48 .Fa prot
49 argument shall be
50 .Dv PROT_NONE
51 (no permissions at all)
52 or the bitwise
53 .Em or
54 of one or more of the following values:
55 .Pp
56 .Bl -tag -width ".Dv PROT_WRITE" -compact
57 .It Dv PROT_READ
58 The pages can be read.
59 .It Dv PROT_WRITE
60 The pages can be written.
61 .It Dv PROT_EXEC
62 The pages can be executed.
63 .El
64 .Pp
65 In addition to these standard protection flags,
66 the
67 .Fx
68 implementation of
69 .Fn mprotect
70 provides the ability to set the maximum protection of a region
71 (which prevents
72 .Nm
73 from adding to the permissions later).
74 This is accomplished by bitwise
75 .Em or Ns 'ing
76 one or more
77 .Dv PROT_
78 values wrapped in the
79 .Dv PROT_MAX()
80 macro into the
81 .Fa prot
82 argument.
83 .Sh RETURN VALUES
84 .Rv -std mprotect
85 .Sh ERRORS
86 The
87 .Fn mprotect
88 system call will fail if:
89 .Bl -tag -width Er
90 .It Bq Er EACCES
91 The calling process was not allowed to change
92 the protection to the value specified by
93 the
94 .Fa prot
95 argument.
96 .It Bq Er EINVAL
97 The virtual address range specified by the
98 .Fa addr
99 and
100 .Fa len
101 arguments is not valid.
102 .It Bq Er EINVAL
103 The
104 .Fa prot
105 argument contains unhandled bits.
106 .It Bq Er ENOTSUP
107 The
108 .Fa prot
109 argument contains permissions which are not a subset of the specified
110 maximum permissions.
111 .El
112 .Sh SEE ALSO
113 .Xr madvise 2 ,
114 .Xr mincore 2 ,
115 .Xr msync 2 ,
116 .Xr munmap 2
117 .Sh HISTORY
118 The
119 .Fn mprotect
120 system call was first documented in
121 .Bx 4.2
122 and first appeared in
123 .Bx 4.4 .
124 .Pp
125 The
126 .Dv PROT_MAX
127 functionality was introduced in
128 .Fx 13 .