.\" 2007-06-02, mtk: Fairly substantial rewrites and additions, and
.\" a much improved example program.
.\"
-.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
-.\" all rights reserved.
-.\" Translated 1997-06-01, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
-.\" Updated and revised 2003-10-24, Suzuki Takashi.
-.\" Updated & Modified 2005-02-08, Yuichi SATO <ysato444@yahoo.co.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 読み取り専用
+.\" This file was generated with po4a. Translate the source file.
.\"
-.TH MPROTECT 2 2011-09-08 "Linux" "Linux Programmer's Manual"
-.\"O .SH NAME
+.\"*******************************************************************
+.TH MPROTECT 2 2011\-09\-08 Linux "Linux Programmer's Manual"
.SH 名前
-.\"O mprotect \- set protection on a region of memory
mprotect \- メモリ領域の保護を設定する
-.\"O .SH SYNOPSIS
.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(const 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
-はページ境界に一致していなければならない。
+\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.
+\fIprot\fP には、 \fBPROT_NONE\fP か、以下のリストの \fBPROT_NONE\fP 以外の値をビット毎の論理和 (bitwize\-or)
+で指定する:
+.TP 1.1i
+\fBPROT_NONE\fP
そのメモリには全くアクセスできない。
-.TP
-.B PROT_READ
-.\"O The memory can be read.
+.TP
+\fBPROT_READ\fP
そのメモリを読み取ることができる。
-.TP
-.B PROT_WRITE
-.\"O The memory can be modified.
+.TP
+\fBPROT_WRITE\fP
そのメモリを変更できる。
-.TP
-.B PROT_EXEC
-.\"O The memory can be executed.
-そのメモリは実行可能である。
+.TP
+\fBPROT_EXEC\fP
.\" 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
+成功した場合、 \fBmprotect\fP() は 0 を返す。エラーの場合は \-1 が返り、 \fIerrno\fP が適切に設定される。
.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 が有効なポインタでないか、
-システムのページサイズの倍数でない。
+.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.
+\fIaddr\fP が有効なポインタでないか、 システムのページサイズの倍数でない。
+.TP
+\fBENOMEM\fP
カーネル内部の構造体を割り当てることができなかった。
-.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
+.TP
+\fBENOMEM\fP
+[\fIaddr\fP, \fIaddr\fP+\fIlen\fP\-1] という範囲のアドレスがプロセスのアドレス空間として不正であるか、
+その範囲のアドレスがマップされていない 1 つ以上のページを指している (カーネル 2.4.19 より前では、この状況でエラー \fBEFAULT\fP
が間違って生成されていた)。
-.\"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
+.\" 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 注意
-.\"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 ()
-を呼び出すことが、常に許されている。
-これは特に既存のコードマッピングを書き込み可能にするために使われる。
+Linux では、(カーネル vsyscall 領域以外の) 任意のプロセスアドレス空間に対して \fBmprotect\fP()
+を呼び出すことが、常に許されている。 これは特に既存のコードマッピングを書き込み可能にするために使われる。
-.\"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
-がセットされる。
+\fBPROT_EXEC\fP が \fBPROT_READ\fP と異なる影響を持つか否かは、アーキテクチャとカーネルのバージョンに依存する。 (i386
+などの) いくつかのアーキテクチャでは、 \fBPROT_WRITE\fP をセットすると、暗黙のうちに \fBPROT_READ\fP がセットされる。
-.\"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
-がセットされている場合にはアクセスは許可されない点だけは
+POSIX.1\-2001 では、 \fIprot\fP で指定されていないアクセスを許可する実装を認めている。 ただし、最低限、 \fBPROT_WRITE\fP
+がセットされている場合にのみ書き込みアクセスが許可され、 \fBPROT_NONE\fP がセットされている場合にはアクセスは許可されない点だけは
満たす必要がある。
-.\"O .SH EXAMPLE
.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
+.in
.SS プログラムのソース
\&
-.in
.nf
#include <unistd.h>
#include <signal.h>
#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 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);
}
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)
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)
+\fBmmap\fP(2), \fBsysconf\fP(3)