1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1996 Tom Bjorkholm <tomb@mydata.se>
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, write to the Free
22 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
25 .\" 1996-04-11 Tom Bjorkholm <tomb@mydata.se>
26 .\" First version written (1.3.86)
27 .\" 1996-04-12 Tom Bjorkholm <tomb@mydata.se>
28 .\" Update for Linux 1.3.87 and later
29 .\" 2005-10-11 mtk: Added NOTES for MREMAP_FIXED; revised EINVAL text.
31 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
32 .\" all rights reserved.
33 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
34 .\" Updated 2002-11-26, Kentaro Shirakata <argrath@ub32.org>
35 .\" Updated 2005-10-09, Kentaro Shirakata <argrath@ub32.org>
36 .\" Updated 2006-04-16, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.28
38 .\"WORD: virtual memory ²¾ÁÛ¥á¥â¥ê
39 .\"WORD: remap ºÆ¥Þ¥Ã¥Ô¥ó¥°
40 .\"WORD: argument °ú¤¿ô
41 .\"WORD: address space ¥¢¥É¥ì¥¹¶õ´Ö
42 .\"WORD: page align ¥Ú¡¼¥¸¶³¦
43 .\"WORD: linear ¥ê¥Ë¥¢
44 .\"WORD: process ¥×¥í¥»¥¹
45 .\"WORD: segment ¥»¥°¥á¥ó¥È
46 .\"WORD: real memory ¼Â¥á¥â¥ê
47 .\"WORD: segmentation violation ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¿¯³²
48 .\"WORD: segmentation fault ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó°ãÈ¿
50 .\"WORD: implement ¼ÂÁõ
53 .TH MREMAP 2 2010-06-10 "Linux" "Linux Programmer's Manual"
55 .\"O mremap \- remap a virtual memory address
57 mremap \- ²¾ÁÛ¥á¥â¥ê¡¦¥¢¥É¥ì¥¹¤òºÆ¥Þ¥Ã¥Ô¥ó¥°¤¹¤ë
61 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
62 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
64 .B #include <sys/mman.h>
66 .BI "void *mremap(void *" old_address ", size_t " old_size ,
67 .BI " size_t " new_size ", int " flags ", ... /* void *" new_address " */);"
72 .\"O expands (or shrinks) an existing memory mapping, potentially
73 .\"O moving it at the same time (controlled by the \fIflags\fP argument and
74 .\"O the available virtual address space).
76 ¤Ï´û¸¤Î¥á¥â¥ê¡¦¥Þ¥Ã¥Ô¥ó¥°¤Î³ÈÄ¥ (¤Þ¤¿¤Ï½Ì¾®) ¤ò¹Ô¤¦¡£
77 Ʊ»þ¤Ë°ÜÆ°¤µ¤ì¤ë¤³¤È¤â¤¢¤ë
78 (\fIflags\fP °ú¤¿ô¤ÈÍøÍѲÄǽ¤Ê²¾ÁÛ¥¢¥É¥ì¥¹¶õ´Ö¤Ë¤è¤Ã¤Æ·è¤Þ¤ë)¡£
80 .\"O \fIold_address\fP is the old address of the virtual memory block that you
81 .\"O want to expand (or shrink).
82 .\"O Note that \fIold_address\fP has to be page
84 .\"O \fIold_size\fP is the old size of the
85 .\"O virtual memory block.
86 .\"O \fInew_size\fP is the requested size of the
87 .\"O virtual memory block after the resize.
88 \fIold_address\fP ¤Ï³ÈÄ¥ (¤Þ¤¿¤Ï½Ì¾®) ¤·¤è¤¦¤È¤¹¤ë²¾ÁÛ¥á¥â¥ê¡¦¥Ö¥í¥Ã¥¯
89 ¤Î¸µ¤Î¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£\fIold_address\fP ¤Ï¥Ú¡¼¥¸¶³¦¤Ë¹ç¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð
90 ¤Ê¤é¤Ê¤¤ÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£\fIold_size\fP ¤Ï¸µ¤Î²¾ÁÛ¥á¥â¥ê¡¦¥Ö¥í¥Ã¥¯¤Î
92 \fInew_size\fP ¤ÏÍ׵᤹¤ëÊѹ¹¸å¤Î²¾ÁÛ¥á¥â¥ê¡¦¥Ö¥í¥Ã¥¯¤Î¥µ¥¤¥º¤Ç¤¢¤ë¡£
93 .\"O An optional fifth argument,
94 .\"O .IR new_address ,
95 .\"O may be provided; see the description of
100 ¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£²¼µ¤Î
104 .\"O In Linux the memory is divided into pages.
105 .\"O A user process has (one or)
106 .\"O several linear virtual memory segments.
107 .\"O Each virtual memory segment has one
108 .\"O or more mappings to real memory pages (in the page table).
109 .\"O Each virtual memory segment has its own
110 .\"O protection (access rights), which may cause
111 .\"O a segmentation violation if the memory is accessed incorrectly (e.g.,
112 .\"O writing to a read-only segment).
113 .\"O Accessing virtual memory outside of the
114 .\"O segments will also cause a segmentation violation.
115 Linux ¤Ç¤Ï¥á¥â¥ê¤Ï¥Ú¡¼¥¸¤Ëʬ³ä¤µ¤ì¤ë¡£¥æ¡¼¥¶¡¼¡¦¥×¥í¥»¥¹¤Ï (°ì¤Ä¤Þ¤¿¤Ï)
116 Ê£¿ô¤Î¥ê¥Ë¥¢¤Ê²¾ÁÛ¥á¥â¥ê¥»¥°¥á¥ó¥È¤ò»ý¤Ä¡£
117 ¤½¤ì¤¾¤ì¤Î²¾ÁÛ¥á¥â¥ê¥»¥°¥á¥ó¥È¤Ï°ì¤Ä°Ê¾å¤Î¼Â¥á¥â¥ê¡¦¥Ú¡¼¥¸
118 ¤Ë¥Þ¥Ã¥Ô¥ó¥°¤µ¤ì¤Æ¤¤¤ë (¥Þ¥Ã¥Ô¥ó¥°¾ðÊó¤Ï¥Ú¡¼¥¸¡¦¥Æ¡¼¥Ö¥ë¤Ç´ÉÍý¤µ¤ì¤ë)¡£
119 ²¾ÁÛ¥á¥â¥ê¥»¥°¥á¥ó¥È¤Ë¤Ï¥»¥°¥á¥ó¥ÈËè¤ÎÊݸî (¥¢¥¯¥»¥¹¸¢) ¤¬ÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢
120 ¥á¥â¥ê¤¬ÉÔÀµ¤Ë¥¢¥¯¥»¥¹¤µ¤ì¤¿¾ì¹ç (Î㤨¤ÐÆɤ߹þ¤ßÀìÍѤΥ»¥°¥á¥ó¥È¤Ë
121 ½ñ¤¹þ¤ó¤À¾ì¹ç)¡¢¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¿¯³² (segmentation violation) ¤ò
122 °ú¤µ¯¤³¤¹¡£¤Þ¤¿¡¢¥»¥°¥á¥ó¥È³°¤Î²¾ÁÛ¥á¥â¥ê¤Ë¥¢¥¯¥»¥¹¤·¤¿¾ì¹ç¤Ë¤â
123 ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¿¯³²¤¬È¯À¸¤¹¤ë¡£
126 .\"O uses the Linux page table scheme.
129 .\"O mapping between virtual addresses and memory pages.
130 .\"O This can be used to implement a very efficient
131 .\"O .BR realloc (3).
133 ¤Ï Linux ¤Î¥Ú¡¼¥¸¡¦¥Æ¡¼¥Ö¥ëÊý¼°¤ò»ÈÍѤ¹¤ë¡£
135 ¤Ï²¾ÁÛ¥¢¥É¥ì¥¹¤È¥á¥â¥ê¡¦¥Ú¡¼¥¸¤Î¥Þ¥Ã¥Ô¥ó¥°¤òÊѹ¹¤¹¤ë¡£¤³¤ì¤ÏÈó¾ï¤Ë¸úΨŪ¤Ê
137 ¤ò¼ÂÁõ¤¹¤ë¤Î¤Ë»ÈÍѤµ¤ì¤Æ¤¤¤ë¡£
139 .\"O The \fIflags\fP bit-mask argument may be 0, or include the following flag:
140 \fIflags\fP ¥Ó¥Ã¥È¥Þ¥¹¥¯°ú¿ô¤Ï 0 ¤Þ¤¿¤Ï°Ê²¼¤Î¥Õ¥é¥°¤ò´Þ¤à:
143 .\"O By default, if there is not sufficient space to expand a mapping
144 .\"O at its current location, then
147 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¸½ºß¤Î°ÌÃ֤˥ޥåԥ󥰤ò³ÈÄ¥¤¹¤ë¤¿¤á¤Î
151 .\"O If this flag is specified, then the kernel is permitted to
152 .\"O relocate the mapping to a new virtual address, if necessary.
153 ¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¤È¡¢¥«¡¼¥Í¥ë¤ÏɬÍפ¬¤¢¤ì¤Ð¥Þ¥Ã¥Ô¥ó¥°¤ò
154 ¿·¤·¤¤²¾ÁÛ¥¢¥É¥ì¥¹¤ËºÆÇÛÃÖ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë
155 .\"O If the mapping is relocated,
156 .\"O then absolute pointers into the old mapping location
157 .\"O become invalid (offsets relative to the starting address of
158 .\"O the mapping should be employed).
159 ¥Þ¥Ã¥Ô¥ó¥°¤¬ºÆÇÛÃÖ¤µ¤ì¤ë¤È¡¢¸Å¤¤¥Þ¥Ã¥Ô¥ó¥°°ÌÃ֤ؤÎÀäÂХݥ¤¥ó¥¿¤Ï
160 ̵¸ú¤Ë¤Ê¤ë (¥Þ¥Ã¥Ô¥ó¥°¤Î³«»Ï¥¢¥É¥ì¥¹¤«¤é¤ÎÁêÂÐ¥ª¥Õ¥»¥Ã¥È¤Ï͸ú¤Î¤Þ¤Þ¤Ç¤¢¤ë)¡£
162 .\"O .BR MREMAP_FIXED " (since Linux 2.3.31)"
163 .BR MREMAP_FIXED " (Linux 2.3.31 °Ê¹ß)"
164 .\"O This flag serves a similar purpose to the
172 ¥Õ¥é¥°¤È»÷¤¿¤è¤¦¤ÊÌÜŪ¤ÇÍѤ¤¤é¤ì¤ë¡£
173 .\"O If this flag is specified, then
175 .\"O accepts a fifth argument,
176 .\"O .IR "void *new_address" ,
177 .\"O which specifies a page-aligned address to which the mapping must
179 ¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¤È¡¢
182 .I "void *new_address"
183 ¤ò¼õ¤±¼è¤ê¡¢¤³¤Î°ú¿ô¤Ï¥Þ¥Ã¥Ô¥ó¥°¤¬°ÜÆ°¤µ¤ì¤ë¤Ù¤¥¢¥É¥ì¥¹¤ò»ØÄꤹ¤ë¡£
184 ¤³¤Î¥¢¥É¥ì¥¹¤Ï¥Ú¡¼¥¸¶³¦¤Ë¹ç¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
185 .\"O Any previous mapping at the address range specified by
193 ¤Ç»ØÄꤵ¤ì¤ë¥¢¥É¥ì¥¹ÈϰϤ˲áµî¤Î¥Þ¥Ã¥Ô¥ó¥°¤¬¤¢¤Ã¤¿¾ì¹ç¡¢
194 ¤½¤Î¥Þ¥Ã¥Ô¥ó¥°¤Ï¥¢¥ó¥Þ¥Ã¥×¤µ¤ì¤ë (unmapped)¡£
197 .\"O is specified, then
198 .\"O .B MREMAP_MAYMOVE
199 .\"O must also be specified.
203 ¤â»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
205 .\"O If the memory segment specified by
209 .\"O is locked (using
211 .\"O or similar), then this lock is maintained when the segment is
212 .\"O resized and/or relocated.
213 .\"O As a consequence, the amount of memory locked by the process may change.
217 ¤Ç»ØÄꤵ¤ì¤ë¥á¥â¥ê¥»¥°¥á¥ó¥È¤¬
219 ¤äƱÍͤΤâ¤Î¤Ç) ¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¥»¥°¥á¥ó¥È¤Î¥µ¥¤¥º¤¬ÊѤï¤Ã¤¿¤ê
220 ºÆÇÛÃÖ¤µ¤ì¤¿¤ê¤·¤¿»þ¤Ë¥í¥Ã¥¯¤â°Ý»ý¤µ¤ì¤ë¡£
221 ¤½¤Î·ë²Ì¡¢¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æ¥í¥Ã¥¯¤µ¤ì¤ë¥á¥â¥ê¤ÎÎ̤ÏÊѲ½¤¹¤ë¡£
222 .\"O .SH "RETURN VALUE"
226 .\"O returns a pointer to the new virtual memory area.
227 .\"O On error, the value
229 .\"O (that is, \fI(void\ *)\ \-1\fP) is returned,
230 .\"O and \fIerrno\fP is set appropriately.
233 ¤Ï¿·¤·¤¤²¾ÁÛ¥á¥â¥êÎΰè¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
236 (¤¹¤Ê¤ï¤Á \fI(void\ *)\ \-1\fP) ¤¬ÊÖ¤µ¤ì¡¢
237 \fIerrno\fP ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
242 .\"O The caller tried to expand a memory segment that is locked,
243 .\"O but this was not possible without exceeding the
244 .\"O .B RLIMIT_MEMLOCK
246 ¸Æ¤Ó½Ð¤·¸µ¤¬¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë¥á¥â¥ê¥»¥°¥á¥ó¥È¤ò³ÈÄ¥¤·¤è¤¦¤È¤·¤¿¤¬¡¢
248 ¥ê¥½¡¼¥¹À©¸Â¤ò±Û¤¨¤º¤Ë¤³¤ì¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤¤Ê¤¤¡£
251 .\"O "Segmentation fault." Some address in the range
252 .\"O \fIold_address\fP to \fIold_address\fP+\fIold_size\fP is an invalid
253 .\"O virtual memory address for this process.
254 .\"O You can also get
256 .\"O even if there exist mappings that cover the
257 .\"O whole address space requested, but those mappings are of different types.
258 ¡Ö¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó°ãÈ¿(segmentation fault)¡×
259 \fIold_address\fP ¤«¤é \fIold_address\fP+\fIold_size\fP ¤Î
260 ÈϰϤΥ¢¥É¥ì¥¹¤Î¤É¤ì¤«¤¬¤³¤Î¥×¥í¥»¥¹¤Ë¤ª¤¤¤ÆÉÔÀµ¤Ê²¾ÁÛ¥á¥â¥ê¡¦¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£
261 ¤¿¤È¤¨Í׵ᤷ¤¿¥¢¥É¥ì¥¹¶õ´ÖÁ´ÂΤò´Þ¤à¤è¤¦¤Ê¥Þ¥Ã¥Ô¥ó¥°¤¬¤¢¤Ã¤¿¤È¤·¤Æ¤â¡¢
262 ¤½¤ì¤é¤Î¥Þ¥Ã¥Ô¥ó¥°¤¬°Û¤Ê¤Ã¤¿·¿¤Ê¤é¤Ð
267 .\"O An invalid argument was given.
268 ÉÔÀµ¤Ê°ú¤¿ô¤¬Í¿¤¨¤é¤ì¤¿¡£
269 .\"O Possible causes are: \fIold_address\fP was not
270 .\"O page aligned; a value other than
271 .\"O .B MREMAP_MAYMOVE
274 .\"O was specified in
282 .\"O or the new address range specified by
286 .\"O overlapped the old address range specified by
292 .\"O was specified without also specifying
293 .\"O .BR MREMAP_MAYMOVE .
294 ²ÄǽÀ¤Î¤¢¤ë¸¶°ø¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë:
295 ¤¿¤¤¤Æ¤¤¤Ï \fIold_address\fP ¤¬¥Ú¡¼¥¸¶³¦¤Ë
302 °Ê³°¤ÎÃͤ¬»ØÄꤵ¤ì¤Æ¤¤¤ë;
312 ¤Ç»ØÄꤵ¤ì¤ë¿·¤·¤¤¥¢¥É¥ì¥¹ÈϰϤ¬
316 ¤Ç»ØÄꤵ¤ì¤ë¸Å¤¤¥¢¥É¥ì¥¹ÈϰϤȽŤʤäƤ¤¤ë;
323 .\"O The memory area cannot be expanded at the current virtual address, and the
324 .\"O .B MREMAP_MAYMOVE
325 .\"O flag is not set in \fIflags\fP.
326 .\"O Or, there is not enough (virtual) memory available.
327 ¸½ºß¤Î²¾ÁÛ¥¢¥É¥ì¥¹¤Ç¤Ï¥á¥â¥êÎΰ褬³ÈÄ¥¤Ç¤¤º¡¢
329 ¥Õ¥é¥°¤¬ \fIflags\fP ¤ËÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
330 ¤Þ¤¿¤Ï½½Ê¬¤Ê (²¾ÁÛ) ¥á¥â¥ê¤¬Â¸ºß¤·¤Ê¤¤¡£
331 .\"O .SH "CONFORMING TO"
333 .\"O This call is Linux-specific, and should not be used in programs
334 .\"O intended to be portable.
335 .\"O .\" 4.2BSD had a (never actually implemented)
336 .\"O .\" .BR mremap (2)
337 .\"O .\" call with completely different semantics.
338 ¤³¤Î¥³¡¼¥ë¤Ï Linux ÆÃͤǤ¢¤ê¡¢°Ü¿¢¤ò°Õ¿Þ¤·¤¿¥×¥í¥°¥é¥à¤Ç
340 .\" 4.2BSD ¤Ë¤Ï (¼ÂºÝ¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤¿¤ï¤±¤Ç¤Ï¤Ê¤¤¤¬)
341 .\" Á´¤¯°Û¤Ã¤¿Êý¼° (semantics) ¤Ë¤è¤ë
344 .\" FIXME perhaps remove above statement about 4.2BSD.
347 .\"O Prior to version 2.4, glibc did not expose the definition of
348 .\"O .BR MREMAP_FIXED ,
349 .\"O and the prototype for
351 .\"O did not allow for the
354 ¥Ð¡¼¥¸¥ç¥ó 2.4 ¤è¤êÁ°¤Î glibc ¤Ç¤Ï¡¢
356 ¤ÎÄêµÁ¤Ï¸ø³«¤µ¤ì¤Æ¤ª¤é¤º¡¢
360 °ú¤¿ô¤ò¼è¤é¤Ê¤«¤Ã¤¿¡£
372 .\"O Your favorite OS text book for more information on paged memory.
373 .\"O (\fIModern Operating Systems\fP by Andrew S. Tannenbaum,
374 .\"O \fIInside Linux\fP by Randolf Bentson,
375 .\"O \fIThe Design of the UNIX Operating System\fP by Maurice J. Bach.)
376 ¥Ú¡¼¥¸Ê¬³ä¤µ¤ì¤¿¥á¥â¥ê¤Ë¤Ä¤¤¤Æ¤â¤Ã¤È¾Ü¤·¤¯ÃΤꤿ¤¤¤Ê¤é¤Ð
377 ¤¢¤Ê¤¿¤Î¹¥¤ß¤Î OS ¤Î¶µ²Ê½ñ¤ò»²¾È¤¹¤ë¤³¤È¡£
378 (\fIModern Operating Systems\fP by Andrew S. Tannenbaum,
379 \fIInside Linux\fP by Randolf Bentson,
380 \fIThe Design of the UNIX Operating System\fP by Maurice J. Bach.)