'\"macro stdmacro
.if n .pH g2.mprotect @(#)mprotect	40.12 of 10/10/89
.\" Copyright 1989 AT&T
'\" ident	"@(#)svid_rt:rt_os/mprotect	1.2"
.\" @(#)mprotect 1.4 88/09/26 SMI;
'\" macro stdmacro
.\" Sun's mprotect.2
.nr X
.if \nX=0 .ds x} mprotect 2 "" "\&"
.if \nX=1 .ds x} mprotect 2 ""
.if \nX=2 .ds x} mprotect 2 "" "\&"
.if \nX=3 .ds x} mprotect "" "" "\&"
.TH \*(x}
.SH NAME
\f4mprotect\f1 \- set protection of memory mapping
.SH SYNOPSIS
.ft 4
.nf
#include <sys/types.h>
#include <sys/mman.h>
.sp0.5
int mprotect(caddr_t addr, size_t len, int prot);
.ft 1
.fi
.SH DESCRIPTION
The function \f4mprotect\f1
changes the access protections on the mappings specified
by the range
[\f2addr, addr + len\f1\^)
to be that specified by
.IR prot .
Legitimate values for
\f2prot\f1
are the same as those permitted for
\f4mmap\f1 and are defined in
\f4<sys/mman.h>\f1 as:
.sp .5
.RS
.ta 25n 30n
.nf
.ft 4
PROT_READ	/* page can be read */
PROT_WRITE	/* page can be written */
PROT_EXEC	/* page can be executed */
PROT_NONE	/* page can not be accessed */
.ft 1
.fi
.RE
.SH RETURN VALUE
Upon successful completion, the function \f4mprotect\f1 returns a 
value of \f40\f1; otherwise, it returns a value of \f4\-1\f1 
and sets \f4errno\f1 to indicate an error.
.SH ERRORS
Under the following conditions, the function \f4mprotect\f1
fails and sets \f4errno\f1 to:
.TP .75i
\f4EACCES\f1
if \f2prot\f1
specifies a protection that violates the access permission
the process has to the underlying memory object.
.TP
\f4EAGAIN\f1
if \f2prot\f1
specifies
\f4PROT_WRITE\f1
over a
\f4MAP_PRIVATE\f1
mapping and there are insufficient
memory resources to reserve for locking the private page.
.TP
\f4EINVAL\f1
if \f2addr\f1
is not a multiple of the page size as returned by
\f4\%sysconf\f1.
.TP
\f4EINVAL\f1
The argument
\f2len\f1
has a value less than or equal to \f40\f1.
.TP
\f4ENOMEM\f1
if addresses in the range
[\f2addr, addr + len\f1)
are invalid for the address space of a process,
or specify one or more pages which are not mapped.
.P
When
\f4mprotect\f1
fails for reasons other than
\f4EINVAL\f1,
the protections on some of the pages in the range
[\f2addr, addr + len\f1)
may have been changed.
If the error occurs
on some page at \f2addr2\f1,
then the protections of
all whole pages in the range
[\f2addr, addr2\f1\^]
will have been modified.
.SH SEE ALSO
.na
\f4memcntl\fP(2),
\f4mmap\fP(2),
\f4plock\fP(2),
\f4mlock\fP(3C),
\f4mlockall\fP(3C),
\f4sysconf\fP(3C).
.ad
