summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-03-31 08:28:21 +0000
committerguenther <guenther@openbsd.org>2013-03-31 08:28:21 +0000
commite35c6e1ab9e44c77e15be0384fd9f270112b5f90 (patch)
treea7020ab865b83709a35c9f4bc0a8aa674f8783c1 /lib/libc/sys
parentUse consistent wording for the EINVAL, EBADF, ENOTDIR, and EACCES cases (diff)
downloadwireguard-openbsd-e35c6e1ab9e44c77e15be0384fd9f270112b5f90.tar.xz
wireguard-openbsd-e35c6e1ab9e44c77e15be0384fd9f270112b5f90.zip
Add ERRORS and STANDARDS sections; reorder and reword description to
clarify PROT_NONE vs PROT_* and what protections are actually sure to be supprted. ok jmc@, deraadt@
Diffstat (limited to 'lib/libc/sys')
-rw-r--r--lib/libc/sys/mprotect.253
1 files changed, 39 insertions, 14 deletions
diff --git a/lib/libc/sys/mprotect.2 b/lib/libc/sys/mprotect.2
index 4f21b2d845c..ba41a16bd21 100644
--- a/lib/libc/sys/mprotect.2
+++ b/lib/libc/sys/mprotect.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mprotect.2,v 1.15 2010/02/12 21:49:10 jmc Exp $
+.\" $OpenBSD: mprotect.2,v 1.16 2013/03/31 08:28:21 guenther Exp $
.\" $NetBSD: mprotect.2,v 1.6 1995/10/12 15:41:08 jtc Exp $
.\"
.\" Copyright (c) 1991, 1993
@@ -30,14 +30,13 @@
.\"
.\" @(#)mprotect.2 8.1 (Berkeley) 6/9/93
.\"
-.Dd $Mdocdate: February 12 2010 $
+.Dd $Mdocdate: March 31 2013 $
.Dt MPROTECT 2
.Os
.Sh NAME
.Nm mprotect
.Nd control the protection of pages
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
.Fd #include <sys/mman.h>
.Ft int
.Fn mprotect "void *addr" "size_t len" "int prot"
@@ -58,17 +57,14 @@ If
is 0, no action is taken on the page that contains
.Fa addr .
.Pp
-Not all implementations will guarantee protection on a page basis;
-the granularity of protection changes may be as large as an entire region.
-Nor will all implementations guarantee to give exactly the requested
-permissions; more permissions may be granted than requested by
-.Fa prot .
-.Pp
The protections (region accessibility) are specified in the
.Fa prot
-argument by
-.Tn OR Ns 'ing
-the following values:
+argument.
+It should either be
+.Dv PROT_NONE
+or a bitwise-inclusive
+.Tn OR
+of one or more of the following values:
.Pp
.Bl -tag -width "PROT_WRITEXX" -offset indent -compact
.It Dv PROT_EXEC
@@ -77,20 +73,49 @@ Pages may be executed.
Pages may be read.
.It Dv PROT_WRITE
Pages may be written.
-.It Dv PROT_NONE
-No permissions.
.El
+.Pp
+Not all implementations will guarantee protection on a page basis;
+the granularity of protection changes may be as large as an entire region.
+Nor will all implementations guarantee to give exactly the requested
+permissions; more permissions may be granted than requested by
+.Fa prot .
+However, if
+.Dv PROT_WRITE
+was not specified then the page will not be writable.
.Sh RETURN VALUES
Upon successful completion,
a value of 0 is returned.
Otherwise, a value of \-1 is returned and
.Va errno
is set to indicate the error.
+.Sh ERRORS
+.Fn mprotect
+will fail if:
+.Bl -tag -width Er
+.It Bq Er EACCES
+The process does not have sufficient access to the underlying memory
+object to provide the requested protection.
+.It Bq Er ENOMEM
+The process has locked future pages with
+.Fn mlockall MCL_FUTURE ,
+a page being protected is not currently accessible,
+and making it accessible and locked would exceed process or system limits.
+.It Bq Er EINVAL
+The
+.Fa prot
+argument is invalid or the specified address range would wrap around.
+.El
.Sh SEE ALSO
.Xr madvise 2 ,
.Xr mincore 2 ,
.Xr msync 2 ,
.Xr munmap 2
+.Sh STANDARDS
+The
+.Fn mprotect
+function conforms to
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Fn mprotect