OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / draft / man2 / mprotect.2
index 27291e4..9e3776b 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>
 .\" 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)
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
 .\"         all rights reserved.
 .\" Translated 1997-06-01, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
 .\" Updated & Modified 2005-10-15, Yuichi SATO
 .\" Updated 2007-06-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.54
 .\"
-.\"WORD: bitwise-or             ¥Ó¥Ã¥È¤´¤È¤ÎÏÀÍýÏÂ
-.\"WORD: protection             ¥¢¥¯¥»¥¹Êݸî
-.\"WORD: read-only              Æɤ߼è¤êÀìÍÑ
-.\"
-.TH MPROTECT 2 2011-09-08 "Linux" "Linux Programmer's Manual"
-.\"O .SH NAME
-.SH Ì¾Á°
-.\"O mprotect \- set protection on a region of memory
-mprotect \- ¥á¥â¥êÎΰè¤ÎÊݸî¤òÀßÄꤹ¤ë
-.\"O .SH SYNOPSIS
-.SH ½ñ¼°
+.TH MPROTECT 2 2014\-01\-05 Linux "Linux Programmer's Manual"
+.SH 名前
+mprotect \- メモリー領域の保護を設定する
+.SH 書式
 .nf
-.B #include <sys/mman.h>
+\fB#include <sys/mman.h>\fP
 .sp
-.BI "int mprotect(const void *" addr ", size_t " len ", int " prot );
+\fBint mprotect(void *\fP\fIaddr\fP\fB, size_t \fP\fIlen\fP\fB, int \fP\fIprot\fP\fB);\fP
 .fi
-.\"O .SH DESCRIPTION
-.SH ÀâÌÀ
-.\"O .BR mprotect ()
-.\"O changes protection for the calling process's memory page(s)
-.\"O containing any part of the address range in the
-.\"O interval [\fIaddr\fP,\ \fIaddr\fP+\fIlen\fP\-1].
-.\"O .I addr
-.\"O must be aligned to a page boundary.
-.BR mprotect ()
-¤Ï¡¢¶è´Ö [\fIaddr\fP,\ \fIaddr\fP+\fIlen\fP\-1] ¤Î¥¢¥É¥ì¥¹ÈϰϤò´Þ¤à
-¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤Î¥á¥â¥ê¥Ú¡¼¥¸¤Î¥¢¥¯¥»¥¹Êݸî¤òÊѹ¹¤¹¤ë¡£
-.I addr
-¤Ï¥Ú¡¼¥¸¶­³¦¤Ë°ìÃפ·¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
+.SH 説明
+\fBmprotect\fP()  は、区間 [\fIaddr\fP,\ \fIaddr\fP+\fIlen\fP\-1] のアドレス範囲を含む
+呼び出し元のプロセスのメモリーページのアクセス保護を変更する。 \fIaddr\fP はページ境界に一致していなければならない。
 
-.\"O If the calling process tries to access memory in a manner
-.\"O that violates the protection, then the kernel generates a
-.\"O .B SIGSEGV
-.\"O signal for the process.
-¸Æ¤Ó½Ð¤·¸µ¤Î¥×¥í¥»¥¹¤¬¥¢¥¯¥»¥¹Êݸî¤Ë°ãÈ¿¤¹¤ë¤è¤¦¤Ê¥á¥â¥ê¥¢¥¯¥»¥¹¤ò
-¹Ô¤ª¤¦¤È¤¹¤ë¤È¡¢¥«¡¼¥Í¥ë¤Ï¥·¥°¥Ê¥ë
-.B SIGSEGV
-¤ò¤½¤Î¥×¥í¥»¥¹¤ËÂФ·¤ÆÀ¸À®¤¹¤ë¡£
+呼び出し元のプロセスがアクセス保護に違反するようなメモリーアクセスを 行おうとすると、カーネルはシグナル \fBSIGSEGV\fP
+をそのプロセスに対して生成する。
 .PP
-.\"O .I prot
-.\"O is either
-.\"O .B PROT_NONE
-.\"O or a bitwise-or of the other values in the following list:
-.I prot
-¤Ë¤Ï¡¢
-.B PROT_NONE
-¤«¡¢°Ê²¼¤Î¥ê¥¹¥È¤Î
-.B PROT_NONE
-°Ê³°¤ÎÃͤò¥Ó¥Ã¥ÈËè¤ÎÏÀÍýÏ (bitwize-or) ¤Ç»ØÄꤹ¤ë:
-.TP 1.1i
-.B PROT_NONE
-.\"O The memory cannot be accessed at all.
-¤½¤Î¥á¥â¥ê¤Ë¤ÏÁ´¤¯¥¢¥¯¥»¥¹¤Ç¤­¤Ê¤¤¡£
-.TP
-.B PROT_READ
-.\"O The memory can be read.
-¤½¤Î¥á¥â¥ê¤òÆɤ߼è¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
-.TP
-.B PROT_WRITE
-.\"O The memory can be modified.
-¤½¤Î¥á¥â¥ê¤òÊѹ¹¤Ç¤­¤ë¡£
-.TP
-.B PROT_EXEC
-.\"O The memory can be executed.
-¤½¤Î¥á¥â¥ê¤Ï¼Â¹Ô²Äǽ¤Ç¤¢¤ë¡£
-.\" FIXME
-.\" Document PROT_GROWSUP and PROT_GROWSDOWN
-.\"O .SH "RETURN VALUE"
-.SH ÊÖ¤êÃÍ
-.\"O On success,
-.\"O .BR mprotect ()
-.\"O returns zero.
-.\"O On error, \-1 is returned, and
-.\"O .I errno
-.\"O is set appropriately.
-À®¸ù¤·¤¿¾ì¹ç¡¢
-.BR mprotect ()
-¤Ï 0 ¤òÊÖ¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï \-1 ¤¬Ê֤ꡢ
-.I errno
-¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
-.\"O .SH ERRORS
-.SH ¥¨¥é¡¼
-.TP
-.B EACCES
-.\"O The memory cannot be given the specified access.
-.\"O This can happen, for example, if you
-.\"O .BR mmap (2)
-.\"O a file to which you have read-only access, then ask
-.\"O .BR mprotect ()
-.\"O to mark it
-.\"O .BR PROT_WRITE .
-»ØÄꤵ¤ì¤¿¥¢¥¯¥»¥¹¤ò¥á¥â¥ê¤ËÀßÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¡£
-¤³¤ì¤Ï¡¢Î㤨¤Ð
-¥Õ¥¡¥¤¥ë¤òÆɤ߼è¤êÀìÍѤÇ
-.BR mmap (2)
-¤·¤Æ¤ª¤ê¡¢¤½¤ÎÎΰè¤ËÂФ·¤Æ
-.BR mprotect ()
-¤ò¸Æ¤Ó½Ð¤·¤Æ
-.B PROT_WRITE
-¤ËÀßÄꤷ¤è¤¦¤È¤·¤¿¾ì¹ç¤ËȯÀ¸¤¹¤ë¡£
-.TP
-.B EINVAL
-.\"O \fIaddr\fP is not a valid pointer,
-.\"O or not a multiple of the system page size.
-\fIaddr\fP ¤¬Í­¸ú¤Ê¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¤¤«¡¢
-¥·¥¹¥Æ¥à¤Î¥Ú¡¼¥¸¥µ¥¤¥º¤ÎÇÜ¿ô¤Ç¤Ê¤¤¡£
+\fIprot\fP には、 \fBPROT_NONE\fP か、以下のリストの \fBPROT_NONE\fP 以外の値をビット毎の論理和 (bitwize\-or)
+で指定する:
+.TP  1.1i
+\fBPROT_NONE\fP
+そのメモリーには全くアクセスできない。
+.TP 
+\fBPROT_READ\fP
+そのメモリーを読み取ることができる。
+.TP 
+\fBPROT_WRITE\fP
+そのメモリーを変更できる。
+.TP 
+\fBPROT_EXEC\fP
+そのメモリーは実行可能である。
+.SH 返り値
+成功した場合、 \fBmprotect\fP()  は 0 を返す。エラーの場合は \-1 が返り、 \fIerrno\fP が適切に設定される。
+.SH エラー
+.TP 
+\fBEACCES\fP
+指定されたアクセスをメモリーに設定することができない。 これは、例えば ファイルを読み取り専用で \fBmmap\fP(2)  しており、その領域に対して
+\fBmprotect\fP()  を呼び出して \fBPROT_WRITE\fP に設定しようとした場合に発生する。
+.TP 
+\fBEINVAL\fP
 .\" Or: both PROT_GROWSUP and PROT_GROWSDOWN were specified in 'prot'.
-.TP
-.B ENOMEM
-.\"O Internal kernel structures could not be allocated.
-¥«¡¼¥Í¥ëÆâÉô¤Î¹½Â¤ÂΤò³ä¤êÅö¤Æ¤ë¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¡£
-.TP
-.B ENOMEM
-.\"O Addresses in the range
-.\"O .RI [ addr ,
-.\"O .IR addr + len \-1]
-.\"O are invalid for the address space of the process,
-.\"O or specify one or more pages that are not mapped.
-.\"O (Before kernel 2.4.19, the error
-.\"O .BR EFAULT
-.\"O was incorrectly produced for these cases.)
-.RI [ addr ,
-.IR addr + len \-1]
-¤È¤¤¤¦ÈϰϤΥ¢¥É¥ì¥¹¤¬¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤È¤·¤ÆÉÔÀµ¤Ç¤¢¤ë¤«¡¢
-¤½¤ÎÈϰϤΥ¢¥É¥ì¥¹¤¬¥Þ¥Ã¥×¤µ¤ì¤Æ¤¤¤Ê¤¤ 1 ¤Ä°Ê¾å¤Î¥Ú¡¼¥¸¤ò»Ø¤·¤Æ¤¤¤ë
-(¥«¡¼¥Í¥ë 2.4.19 ¤è¤êÁ°¤Ç¤Ï¡¢¤³¤Î¾õ¶·¤Ç¥¨¥é¡¼
-.B EFAULT
-¤¬´Ö°ã¤Ã¤ÆÀ¸À®¤µ¤ì¤Æ¤¤¤¿)¡£
-.\"O .SH "CONFORMING TO"
-.SH ½àµò
-SVr4, POSIX.1-2001.
-.\"O .\" SVr4 defines an additional error
-.\"O .\" code EAGAIN. The SVr4 error conditions don't map neatly onto Linux's.
-.\"O POSIX says that the behavior of
-.\"O .BR mprotect ()
-.\"O is unspecified if it is applied to a region of memory that
-.\"O was not obtained via
-.\"O .BR mmap (2).
-.\" SVr4 ¤Ç¤Ï¾¤Ë¥¨¥é¡¼¥³¡¼¥É EAGAIN ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¡£
-.\" SVr4 ¤Î¥¨¥é¡¼¾ò·ï¤Ï Linux ¤Î¤â¤Î¤Ë¤­¤Á¤ó¤ÈÂбþ¤·¤Ê¤¤¡£
-POSIX ¤Ç¤Ï¡¢
-.BR mmap (2)
-·Ðͳ¤Ç³ÍÆÀ¤·¤Æ¤¤¤Ê¤¤¥á¥â¥êÎΰè¤ËÂФ·¤Æ
-.BR mprotect ()
-¤ò¹Ô¤Ã¤¿¾ì¹ç¤Î
-.BR mprotect ()
-¤ÎÆ°ºî¤Ï̤ÄêµÁ¤Ç¤¢¤ë¤È¤µ¤ì¤Æ¤¤¤ë¡£
-.\"O .SH NOTES
-.SH Ãí°Õ
-.\"O On Linux it is always permissible to call
-.\"O .BR mprotect ()
-.\"O on any address in a process's address space (except for the
-.\"O kernel vsyscall area).
-.\"O In particular it can be used
-.\"O to change existing code mappings to be writable.
-Linux ¤Ç¤Ï¡¢(¥«¡¼¥Í¥ë vsyscall Îΰè°Ê³°¤Î)
-Ǥ°Õ¤Î¥×¥í¥»¥¹¥¢¥É¥ì¥¹¶õ´Ö¤ËÂФ·¤Æ
-.BR mprotect ()
-¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤¬¡¢¾ï¤Ëµö¤µ¤ì¤Æ¤¤¤ë¡£
-¤³¤ì¤ÏÆä˴û¸¤Î¥³¡¼¥É¥Þ¥Ã¥Ô¥ó¥°¤ò½ñ¤­¹þ¤ß²Äǽ¤Ë¤¹¤ë¤¿¤á¤Ë»È¤ï¤ì¤ë¡£
-
-.\"O Whether
-.\"O .B PROT_EXEC
-.\"O has any effect different from
-.\"O .B PROT_READ
-.\"O is architecture- and kernel version-dependent.
-.\"O On some hardware architectures (e.g., i386),
-.\"O .B PROT_WRITE
-.\"O implies
-.\"O .BR PROT_READ .
-.B PROT_EXEC
-¤¬
-.B PROT_READ
-¤È°Û¤Ê¤ë±Æ¶Á¤ò»ý¤Ä¤«Èݤ«¤Ï¡¢¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤È¥«¡¼¥Í¥ë¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë°Í¸¤¹¤ë¡£
-(i386 ¤Ê¤É¤Î) ¤¤¤¯¤Ä¤«¤Î¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç¤Ï¡¢
-.B PROT_WRITE
-¤ò¥»¥Ã¥È¤¹¤ë¤È¡¢°ÅÌۤΤ¦¤Á¤Ë
-.B PROT_READ
-¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£
-
-.\"O POSIX.1-2001 says that an implementation may permit access
-.\"O other than that specified in
-.\"O .IR prot ,
-.\"O but at a minimum can only allow write access if
-.\"O .B PROT_WRITE
-.\"O has been set, and must not allow any access if
-.\"O .B PROT_NONE
-.\"O has been set.
-POSIX.1-2001 ¤Ç¤Ï¡¢
-.I prot
-¤Ç»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¥¢¥¯¥»¥¹¤òµö²Ä¤¹¤ë¼ÂÁõ¤òǧ¤á¤Æ¤¤¤ë¡£
-¤¿¤À¤·¡¢ºÇÄã¸Â¡¢
-.B PROT_WRITE
-¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Î¤ß½ñ¤­¹þ¤ß¥¢¥¯¥»¥¹¤¬µö²Ä¤µ¤ì¡¢
-.B PROT_NONE
-¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¥¢¥¯¥»¥¹¤Ïµö²Ä¤µ¤ì¤Ê¤¤ÅÀ¤À¤±¤Ï
-Ëþ¤¿¤¹É¬Íפ¬¤¢¤ë¡£
-.\"O .SH EXAMPLE
-.SH Îã
+\fIaddr\fP が有効なポインターでないか、 システムのページサイズの倍数でない。
+.TP 
+\fBENOMEM\fP
+カーネル内部の構造体を割り当てることができなかった。
+.TP 
+\fBENOMEM\fP
+[\fIaddr\fP, \fIaddr\fP+\fIlen\fP\-1] という範囲のアドレスがプロセスのアドレス空間として不正であるか、
+その範囲のアドレスがマップされていない 1 つ以上のページを指している (カーネル 2.4.19 より前では、この状況でエラー \fBEFAULT\fP
+が間違って生成されていた)。
+.SH 準拠
+.\" SVr4 defines an additional error
+.\" code EAGAIN. The SVr4 error conditions don't map neatly onto Linux's.
+SVr4, POSIX.1\-2001.  POSIX では、 \fBmmap\fP(2)  経由で獲得していないメモリー領域に対して
+\fBmprotect\fP()  を行った場合の \fBmprotect\fP()  の動作は未定義であるとされている。
+.SH 注意
+Linux では、(カーネル vsyscall 領域以外の)  任意のプロセスアドレス空間に対して \fBmprotect\fP()
+を呼び出すことが、常に許されている。 これは特に既存のコードマッピングを書き込み可能にするために使われる。
+
+\fBPROT_EXEC\fP が \fBPROT_READ\fP と異なる影響を持つか否かは、アーキテクチャーとカーネルのバージョンに依存する。 (i386
+などの) いくつかのアーキテクチャーでは、 \fBPROT_WRITE\fP をセットすると、暗黙のうちに \fBPROT_READ\fP がセットされる。
+
+POSIX.1\-2001 では、 \fIprot\fP で指定されていないアクセスを許可する実装を認めている。 ただし、最低限、 \fBPROT_WRITE\fP
+がセットされている場合にのみ書き込みアクセスが許可され、 \fBPROT_NONE\fP がセットされている場合にはアクセスは許可されない点だけは
+満たす必要がある。
+.SH 例
 .\" sigaction.2 refers to this example
 .PP
-.\"O The program below allocates four pages of memory, makes the third
-.\"O of these pages read-only, and then executes a loop that walks upward
-.\"O through the allocated region modifying bytes.
-°Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢¥á¥â¥ê¥Ú¡¼¥¸¤ò 4¤Ä³ÎÊݤ·¡¢¤½¤Î¤¦¤Á 3ÈÖÌܤΥڡ¼¥¸¤ò
-Æɤ߹þ¤ßÀìÍѤËÀßÄꤹ¤ë¡£¤½¤Î¸å¤Ç¡¢³ÎÊݤ·¤¿Îΰè¤Î¥¢¥É¥ì¥¹¤Î¾®¤µ¤¤Êý¤«¤é
-Â礭¤ÊÊý¤Ë¸þ¤«¤Ã¤Æ½çÈ֤˥Х¤¥ÈÃͤòÊѹ¹¤¹¤ë¥ë¡¼¥×¤ò¼Â¹Ô¤¹¤ë¡£
+以下のプログラムは、メモリーページを 4つ確保し、そのうち 3番目のページを 読み込み専用に設定する。その後で、確保した領域のアドレスの小さい方から
+大きな方に向かって順番にバイト値を変更するループを実行する。
 
-.\"O An example of what we might see when running the program is the
-.\"O following:
-¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤·¤¿¾ì¹ç¤Î°ìÎã¤ò°Ê²¼¤Ë¼¨¤¹¡£
+プログラムを実行した場合の一例を以下に示す。
 
 .in +4n
 .nf
-.RB "$" " ./a.out"
+$\fB ./a.out\fP
 Start of region:        0x804c000
 Got SIGSEGV at address: 0x804e000
 .fi
-.\"O .SS Program source
-.SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
-\&
 .in
+.SS プログラムのソース
+\&
 .nf
 #include <unistd.h>
 #include <signal.h>
@@ -268,15 +140,15 @@ Got SIGSEGV at address: 0x804e000
 #include <errno.h>
 #include <sys/mman.h>
 
-#define handle_error(msg) \\
+#define handle_error(msg) \e
     do { perror(msg); exit(EXIT_FAILURE); } while (0)
 
-char *buffer;
+static char *buffer;
 
 static void
 handler(int sig, siginfo_t *si, void *unused)
 {
-    printf("Got SIGSEGV at address: 0x%lx\\n",
+    printf("Got SIGSEGV at address: 0x%lx\en",
             (long) si\->si_addr);
     exit(EXIT_FAILURE);
 }
@@ -305,7 +177,7 @@ main(void)
     if (buffer == NULL)
         handle_error("memalign");
 
-    printf("Start of region:        0x%lx\\n", (long) buffer);
+    printf("Start of region:        0x%lx\en", (long) buffer);
 
     if (mprotect(buffer + pagesize * 2, pagesize,
                 PROT_READ) == \-1)
@@ -314,11 +186,13 @@ main(void)
     for (p = buffer ; ; )
         *(p++) = \(aqa\(aq;
 
-    printf("Loop completed\\n");     /* Should never happen */
+    printf("Loop completed\en");     /* Should never happen */
     exit(EXIT_SUCCESS);
 }
 .fi
-.\"O .SH "SEE ALSO"
-.SH ´ØÏ¢¹àÌÜ
-.BR mmap (2),
-.BR sysconf (3)
+.SH 関連項目
+\fBmmap\fP(2), \fBsysconf\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。