OSDN Git Service

(split) LDP: Update original to LDP v3.63
[linuxjm/LDP_man-pages.git] / original / man2 / mprotect.2
index d7b9712..f8f8fba 100644 (file)
@@ -1,7 +1,7 @@
-.\" -*- nroff -*-
 .\" Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
 .\" and Copyright (C) 1995 Michael Shields <shields@tembel.org>.
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" manual provided the copyright notice and this permission notice are
 .\" preserved on all copies.
@@ -21,6 +21,7 @@
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and author of this work.
+.\" %%%LICENSE_END
 .\"
 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
 .\" Modified 1997-05-31 by Andries Brouwer <aeb@cwi.nl>
 .\" Modified 2004-08-16 by Andi Kleen <ak@muc.de>
 .\" 2007-06-02, mtk: Fairly substantial rewrites and additions, and
 .\" a much improved example program.
+.\" FIXME The following protection flags need documenting:
+.\"         PROT_SEM
+.\"         PROT_GROWSDOWN
+.\"         PROT_GROWSUP
+.\"         PROT_SAO (PowerPC)
 .\"
-.TH MPROTECT 2 2008-08-06 "Linux" "Linux Programmer's Manual"
+.TH MPROTECT 2 2014-01-05 "Linux" "Linux Programmer's Manual"
 .SH NAME
 mprotect \- set protection on a region of memory
 .SH SYNOPSIS
 .nf
 .B #include <sys/mman.h>
 .sp
-.BI "int mprotect(const void *" addr ", size_t " len ", int " prot );
+.BI "int mprotect(void *" addr ", size_t " len ", int " prot );
 .fi
 .SH DESCRIPTION
 .BR mprotect ()
@@ -69,7 +75,7 @@ The memory can be modified.
 The memory can be executed.
 .\" FIXME
 .\" Document PROT_GROWSUP and PROT_GROWSDOWN
-.SH "RETURN VALUE"
+.SH RETURN VALUE
 On success,
 .BR mprotect ()
 returns zero.
@@ -98,13 +104,13 @@ Internal kernel structures could not be allocated.
 .B ENOMEM
 Addresses in the range
 .RI [ addr ,
-.IR addr + len ]
+.IR addr + len \-1]
 are invalid for the address space of the process,
 or specify one or more pages that are not mapped.
 (Before kernel 2.4.19, the error
 .BR EFAULT
 was incorrectly produced for these cases.)
-.SH "CONFORMING TO"
+.SH CONFORMING TO
 SVr4, POSIX.1-2001.
 .\" SVr4 defines an additional error
 .\" code EAGAIN. The SVr4 error conditions don't map neatly onto Linux's.
@@ -134,7 +140,7 @@ implies
 POSIX.1-2001 says that an implementation may permit access
 other than that specified in
 .IR prot ,
-but at a minimum can only allow write access if
+but at a minimum can allow write access only if
 .B PROT_WRITE
 has been set, and must not allow any access if
 .B PROT_NONE
@@ -143,7 +149,7 @@ has been set.
 .\" sigaction.2 refers to this example
 .PP
 The program below allocates four pages of memory, makes the third
-of these pages read-only, and then executes a loop that walks upwards
+of these pages read-only, and then executes a loop that walks upward
 through the allocated region modifying bytes.
 
 An example of what we might see when running the program is the
@@ -170,7 +176,7 @@ Got SIGSEGV at address: 0x804e000
 #define handle_error(msg) \\
     do { perror(msg); exit(EXIT_FAILURE); } while (0)
 
-char *buffer;
+static char *buffer;
 
 static void
 handler(int sig, siginfo_t *si, void *unused)
@@ -207,7 +213,7 @@ main(int argc, char *argv[])
     printf("Start of region:        0x%lx\\n", (long) buffer);
 
     if (mprotect(buffer + pagesize * 2, pagesize,
-                PROT_NONE) == \-1)
+                PROT_READ) == \-1)
         handle_error("mprotect");
 
     for (p = buffer ; ; )
@@ -217,6 +223,6 @@ main(int argc, char *argv[])
     exit(EXIT_SUCCESS);
 }
 .fi
-.SH "SEE ALSO"
+.SH SEE ALSO
 .BR mmap (2),
 .BR sysconf (3)