]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/mprotect.2
libarchive: merge from vendor branch
[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 .\"     @(#)mprotect.2  8.1 (Berkeley) 6/9/93
29 .\" $FreeBSD$
30 .\"
31 .Dd September 7, 2021
32 .Dt MPROTECT 2
33 .Os
34 .Sh NAME
35 .Nm mprotect
36 .Nd control the protection of pages
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/mman.h
41 .Ft int
42 .Fn mprotect "void *addr" "size_t len" "int prot"
43 .Sh DESCRIPTION
44 The
45 .Fn mprotect
46 system call
47 changes the specified pages to have protection
48 .Fa prot .
49 .Pp
50 The
51 .Fa prot
52 argument shall be
53 .Dv PROT_NONE
54 (no permissions at all)
55 or the bitwise
56 .Em or
57 of one or more of the following values:
58 .Pp
59 .Bl -tag -width ".Dv PROT_WRITE" -compact
60 .It Dv PROT_READ
61 The pages can be read.
62 .It Dv PROT_WRITE
63 The pages can be written.
64 .It Dv PROT_EXEC
65 The pages can be executed.
66 .El
67 .Pp
68 In addition to these standard protection flags,
69 the
70 .Fx
71 implementation of
72 .Fn mprotect
73 provides the ability to set the maximum protection of a region
74 (which prevents
75 .Nm
76 from adding to the permissions later).
77 This is accomplished by bitwise
78 .Em or Ns 'ing
79 one or more
80 .Dv PROT_
81 values wrapped in the
82 .Dv PROT_MAX()
83 macro into the
84 .Fa prot
85 argument.
86 .Sh RETURN VALUES
87 .Rv -std mprotect
88 .Sh ERRORS
89 The
90 .Fn mprotect
91 system call will fail if:
92 .Bl -tag -width Er
93 .It Bq Er EACCES
94 The calling process was not allowed to change
95 the protection to the value specified by
96 the
97 .Fa prot
98 argument.
99 .It Bq Er EINVAL
100 The virtual address range specified by the
101 .Fa addr
102 and
103 .Fa len
104 arguments is not valid.
105 .It Bq Er EINVAL
106 The
107 .Fa prot
108 argument contains unhandled bits.
109 .It Bq Er ENOTSUP
110 The
111 .Fa prot
112 argument contains permissions which are not a subset of the specified
113 maximum permissions.
114 .El
115 .Sh SEE ALSO
116 .Xr madvise 2 ,
117 .Xr mincore 2 ,
118 .Xr msync 2 ,
119 .Xr munmap 2
120 .Sh HISTORY
121 The
122 .Fn mprotect
123 system call was first documented in
124 .Bx 4.2
125 and first appeared in
126 .Bx 4.4 .
127 .Pp
128 The
129 .Dv PROT_MAX
130 functionality was introduced in
131 .Fx 13 .