2 .\" Copyright 1989 AT&T Copyright (c) 1996, Sun Microsystems, Inc. All Rights Reserved Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions 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.
6 .\" This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH MPROTECT 2 "Jan 12, 1998"
12 mprotect \- set protection of memory mapping
18 \fBint\fR \fBmprotect\fR(\fBvoid *\fR\fIaddr\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIprot\fR);
24 The \fBmprotect()\fR function changes the access protections on the mappings
25 specified by the range [\fIaddr, addr + len\fR\|), rounding \fIlen\fR up to the
26 next multiple of the page size as returned by \fBsysconf\fR(3C), to be that
27 specified by \fIprot\fR. Legitimate values for \fIprot\fR are the same as those
28 permitted for \fBmmap\fR(2) and are defined in <\fBsys/mman.h\fR> as:
35 \fB/* page can be read */\fR
41 \fB\fBPROT_WRITE\fR\fR
44 \fB/* page can be written */\fR
53 \fB/* page can be executed */\fR
62 \fB/* page can not be accessed */\fR
67 When \fBmprotect()\fR fails for reasons other than \fBEINVAL\fR, the
68 protections on some of the pages in the range [\fIaddr, addr + len\fR) may have
69 been changed. If the error occurs on some page at \fIaddr2\fR, then the
70 protections of all whole pages in the range [\fIaddr, addr2\fR] will have been
75 Upon successful completion, \fBmprotect()\fR returns \fB0\fR. Otherwise, it
76 returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error.
80 The \fBmprotect()\fR function will fail if:
87 The \fIprot\fR argument specifies a protection that violates the access
88 permission the process has to the underlying memory object.
97 The \fIlen\fR argument has a value equal to 0, or \fIaddr\fR is not a multiple
98 of the page size as returned by \fBsysconf\fR(3C).
107 Addresses in the range [\fIaddr, addr + len\fR) are invalid for the address
108 space of a process, or specify one or more pages which are not mapped.
113 The \fBmprotect()\fR function may fail if:
120 The address range [\fIaddr, addr + len\fR) includes one or more pages that have
121 been locked in memory and that were mapped \fB\fR\fBMAP_PRIVATE\fR\fB;\fR
122 \fIprot\fR includes \fB\fR\fBPROT_WRITE\fR\fB;\fR and the system has
123 insufficient resources to reserve memory for the private pages that may be
124 created. These private pages may be created by store operations in the
125 now-writable address range.
131 See \fBattributes\fR(5) for descriptions of the following attributes:
139 ATTRIBUTE TYPE ATTRIBUTE VALUE
141 Interface Stability Standard
147 \fBmmap\fR(2), \fBplock\fR(3C), \fBmlock\fR(3C), \fBmlockall\fR(3C),
148 \fBsysconf\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)