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 2005-09-13 "Linux" "Linux Programmer's Manual"
55 .\"O mremap \- remap a virtual memory address
57 mremap \- ²¾ÁÛ¥á¥â¥ê¡¦¥¢¥É¥ì¥¹¤òºÆ¥Þ¥Ã¥Ô¥ó¥°¤¹¤ë
61 .B #define _GNU_SOURCE
63 .B #include <sys/mman.h>
65 .BI "void *mremap(void *" old_address ", size_t " old_size ,
66 .BI " size_t " new_size ", int " flags );
71 .\"O expands (or shrinks) an existing memory mapping, potentially
72 .\"O moving it at the same time (controlled by the \fIflags\fP argument and
73 .\"O the available virtual address space).
75 ¤Ï´û¸¤Î¥á¥â¥ê¡¦¥Þ¥Ã¥Ô¥ó¥°¤Î³ÈÄ¥ (¤Þ¤¿¤Ï½Ì¾®) ¤ò¹Ô¤¦¡£
76 Ʊ»þ¤Ë°ÜÆ°¤µ¤ì¤ë¤³¤È¤â¤¢¤ë
77 (\fIflags\fP °ú¤¿ô¤ÈÍøÍѲÄǽ¤Ê²¾ÁÛ¥¢¥É¥ì¥¹¶õ´Ö¤Ë¤è¤Ã¤Æ·è¤Þ¤ë)¡£
79 .\"O \fIold_address\fP is the old address of the virtual memory block that you
80 .\"O want to expand (or shrink).
81 .\"O Note that \fIold_address\fP has to be page
83 .\"O \fIold_size\fP is the old size of the
84 .\"O virtual memory block.
85 .\"O \fInew_size\fP is the requested size of the
86 .\"O virtual memory block after the resize.
87 \fIold_address\fP ¤Ï³ÈÄ¥ (¤Þ¤¿¤Ï½Ì¾®) ¤·¤è¤¦¤È¤¹¤ë²¾ÁÛ¥á¥â¥ê¡¦¥Ö¥í¥Ã¥¯
88 ¤Î¸µ¤Î¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£\fIold_address\fP ¤Ï¥Ú¡¼¥¸¶³¦¤Ë¹ç¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð
89 ¤Ê¤é¤Ê¤¤ÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£\fIold_size\fP ¤Ï¸µ¤Î²¾ÁÛ¥á¥â¥ê¡¦¥Ö¥í¥Ã¥¯¤Î
91 \fInew_size\fP ¤ÏÍ׵᤹¤ëÊѹ¹¸å¤Î²¾ÁÛ¥á¥â¥ê¡¦¥Ö¥í¥Ã¥¯¤Î¥µ¥¤¥º¤Ç¤¢¤ë¡£
93 .\"O In Linux the memory is divided into pages.
94 .\"O A user process has (one or)
95 .\"O several linear virtual memory segments.
96 .\"O Each virtual memory segment has one
97 .\"O or more mappings to real memory pages (in the page table).
98 .\"O Each virtual memory segment has its own
99 .\"O protection (access rights), which may cause
100 .\"O a segmentation violation if the memory is accessed incorrectly (e.g.,
101 .\"O writing to a read-only segment).
102 .\"O Accessing virtual memory outside of the
103 .\"O segments will also cause a segmentation violation.
104 Linux ¤Ç¤Ï¥á¥â¥ê¤Ï¥Ú¡¼¥¸¤Ëʬ³ä¤µ¤ì¤ë¡£¥æ¡¼¥¶¡¼¡¦¥×¥í¥»¥¹¤Ï (°ì¤Ä¤Þ¤¿¤Ï)
105 Ê£¿ô¤Î¥ê¥Ë¥¢¤Ê²¾ÁÛ¥á¥â¥ê¥»¥°¥á¥ó¥È¤ò»ý¤Ä¡£
106 ¤½¤ì¤¾¤ì¤Î²¾ÁÛ¥á¥â¥ê¥»¥°¥á¥ó¥È¤Ï°ì¤Ä°Ê¾å¤Î¼Â¥á¥â¥ê¡¦¥Ú¡¼¥¸
107 ¤Ë¥Þ¥Ã¥Ô¥ó¥°¤µ¤ì¤Æ¤¤¤ë (¥Þ¥Ã¥Ô¥ó¥°¾ðÊó¤Ï¥Ú¡¼¥¸¡¦¥Æ¡¼¥Ö¥ë¤Ç´ÉÍý¤µ¤ì¤ë)¡£
108 ²¾ÁÛ¥á¥â¥ê¥»¥°¥á¥ó¥È¤Ë¤Ï¥»¥°¥á¥ó¥ÈËè¤ÎÊݸî (¥¢¥¯¥»¥¹¸¢) ¤¬ÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢
109 ¥á¥â¥ê¤¬ÉÔÀµ¤Ë¥¢¥¯¥»¥¹¤µ¤ì¤¿¾ì¹ç (Î㤨¤ÐÆɤ߹þ¤ßÀìÍѤΥ»¥°¥á¥ó¥È¤Ë
110 ½ñ¤¹þ¤ó¤À¾ì¹ç)¡¢¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¿¯³² (segmentation violation) ¤ò
111 °ú¤µ¯¤³¤¹¡£¤Þ¤¿¡¢¥»¥°¥á¥ó¥È³°¤Î²¾ÁÛ¥á¥â¥ê¤Ë¥¢¥¯¥»¥¹¤·¤¿¾ì¹ç¤Ë¤â
112 ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¿¯³²¤¬È¯À¸¤¹¤ë¡£
115 .\"O uses the Linux page table scheme.
118 .\"O mapping between virtual addresses and memory pages.
119 .\"O This can be used to implement a very efficient
120 .\"O .BR realloc (3).
122 ¤Ï Linux ¤Î¥Ú¡¼¥¸¡¦¥Æ¡¼¥Ö¥ëÊý¼°¤ò»ÈÍѤ¹¤ë¡£
124 ¤Ï²¾ÁÛ¥¢¥É¥ì¥¹¤È¥á¥â¥ê¡¦¥Ú¡¼¥¸¤Î¥Þ¥Ã¥Ô¥ó¥°¤òÊѹ¹¤¹¤ë¡£¤³¤ì¤ÏÈó¾ï¤Ë¸úΨŪ¤Ê
126 ¤ò¼ÂÁõ¤¹¤ë¤Î¤Ë»ÈÍѤµ¤ì¤Æ¤¤¤ë¡£
128 .\"O The \fIflags\fP bit-mask argument may be 0, or include the following flag:
129 \fIflags\fP ¥Ó¥Ã¥È¥Þ¥¹¥¯°ú¿ô¤Ï 0 ¤Þ¤¿¤Ï°Ê²¼¤Î¥Õ¥é¥°¤ò´Þ¤à:
132 .\"O By default, if there is not sufficient space to expand a mapping
133 .\"O at its current location, then
136 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¸½ºß¤Î°ÌÃ֤˥ޥåԥ󥰤ò³ÈÄ¥¤¹¤ë¤¿¤á¤Î
140 .\"O If this flag is specified, then the kernel is permitted to
141 .\"O relocate the mapping to a new virtual address, if necessary.
142 ¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¤È¡¢¥«¡¼¥Í¥ë¤ÏɬÍפ¬¤¢¤ì¤Ð¥Þ¥Ã¥Ô¥ó¥°¤ò
143 ¿·¤·¤¤²¾ÁÛ¥¢¥É¥ì¥¹¤ËºÆÇÛÃÖ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë
144 .\"O If the mapping is relocated,
145 .\"O then absolute pointers into the old mapping location
146 .\"O become invalid (offsets relative to the starting address of
147 .\"O the mapping should be employed).
148 ¥Þ¥Ã¥Ô¥ó¥°¤¬ºÆÇÛÃÖ¤µ¤ì¤ë¤È¡¢¸Å¤¤¥Þ¥Ã¥Ô¥ó¥°°ÌÃ֤ؤÎÀäÂХݥ¤¥ó¥¿¤Ï
149 ̵¸ú¤Ë¤Ê¤ë (¥Þ¥Ã¥Ô¥ó¥°¤Î³«»Ï¥¢¥É¥ì¥¹¤«¤é¤ÎÁêÂÐ¥ª¥Õ¥»¥Ã¥È¤Ï͸ú¤Î¤Þ¤Þ¤Ç¤¢¤ë)¡£
151 .\"O .BR MREMAP_FIXED " (since Linux 2.3.31)"
152 .BR MREMAP_FIXED " (Linux 2.3.31 °Ê¹ß)"
153 .\"O This flag serves a similar purpose to the
161 ¥Õ¥é¥°¤È»÷¤¿¤è¤¦¤ÊÌÜŪ¤ÇÍѤ¤¤é¤ì¤ë¡£
162 .\"O If this flag is specified, then
164 .\"O accepts a fifth argument,
165 .\"O .IR "void *new_address" ,
166 .\"O which specifies a page-aligned address to which the mapping must
168 ¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤ë¤È¡¢
171 .I "void *new_address"
172 ¤ò¼õ¤±¼è¤ê¡¢¤³¤Î°ú¿ô¤Ï¥Þ¥Ã¥Ô¥ó¥°¤¬°ÜÆ°¤µ¤ì¤ë¤Ù¤¥¢¥É¥ì¥¹¤ò»ØÄꤹ¤ë¡£
173 ¤³¤Î¥¢¥É¥ì¥¹¤Ï¥Ú¡¼¥¸¶³¦¤Ë¹ç¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
174 .\"O Any previous mapping at the address range specified by
182 ¤Ç»ØÄꤵ¤ì¤ë¥¢¥É¥ì¥¹ÈϰϤ˲áµî¤Î¥Þ¥Ã¥Ô¥ó¥°¤¬¤¢¤Ã¤¿¾ì¹ç¡¢
183 ¤½¤Î¥Þ¥Ã¥Ô¥ó¥°¤Ï¥¢¥ó¥Þ¥Ã¥×¤µ¤ì¤ë (unmapped)¡£
186 .\"O is specified, then
187 .\"O .B MREMAP_MAYMOVE
188 .\"O must also be specified.
192 ¤â»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
194 .\"O If the memory segment specified by
198 .\"O is locked (using
200 .\"O or similar), then this lock is maintained when the segment is
201 .\"O resized and/or relocated.
202 .\"O As a consequence, the amount of memory locked by the process may change.
206 ¤Ç»ØÄꤵ¤ì¤ë¥á¥â¥ê¥»¥°¥á¥ó¥È¤¬
208 ¤äƱÍͤΤâ¤Î¤Ç) ¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¥»¥°¥á¥ó¥È¤Î¥µ¥¤¥º¤¬ÊѤï¤Ã¤¿¤ê
209 ºÆÇÛÃÖ¤µ¤ì¤¿¤ê¤·¤¿»þ¤Ë¥í¥Ã¥¯¤â°Ý»ý¤µ¤ì¤ë¡£
210 ¤½¤Î·ë²Ì¡¢¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æ¥í¥Ã¥¯¤µ¤ì¤ë¥á¥â¥ê¤ÎÎ̤ÏÊѲ½¤¹¤ë¡£
211 .\"O .SH "RETURN VALUE"
215 .\"O returns a pointer to the new virtual memory area.
216 .\"O On error, the value
218 .\"O (that is, \fI(void\ *)\ \-1\fP) is returned,
219 .\"O and \fIerrno\fP is set appropriately.
222 ¤Ï¿·¤·¤¤²¾ÁÛ¥á¥â¥êÎΰè¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
225 (¤¹¤Ê¤ï¤Á \fI(void\ *)\ \-1\fP) ¤¬ÊÖ¤µ¤ì¡¢
226 \fIerrno\fP ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
231 .\"O The caller tried to expand a memory segment that is locked,
232 .\"O but this was not possible without exceeding the
233 .\"O .B RLIMIT_MEMLOCK
235 ¸Æ¤Ó½Ð¤·¸µ¤¬¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë¥á¥â¥ê¥»¥°¥á¥ó¥È¤ò³ÈÄ¥¤·¤è¤¦¤È¤·¤¿¤¬¡¢
237 ¥ê¥½¡¼¥¹À©¸Â¤ò±Û¤¨¤º¤Ë¤³¤ì¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤¤Ê¤¤¡£
240 .\"O "Segmentation fault." Some address in the range
241 .\"O \fIold_address\fP to \fIold_address\fP+\fIold_size\fP is an invalid
242 .\"O virtual memory address for this process.
243 .\"O You can also get
245 .\"O even if there exist mappings that cover the
246 .\"O whole address space requested, but those mappings are of different types.
247 ¡Ö¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó°ãÈ¿(segmentation fault)¡×
248 \fIold_address\fP ¤«¤é \fIold_address\fP+\fIold_size\fP ¤Î
249 ÈϰϤΥ¢¥É¥ì¥¹¤Î¤É¤ì¤«¤¬¤³¤Î¥×¥í¥»¥¹¤Ë¤ª¤¤¤ÆÉÔÀµ¤Ê²¾ÁÛ¥á¥â¥ê¡¦¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£
250 ¤¿¤È¤¨Í׵ᤷ¤¿¥¢¥É¥ì¥¹¶õ´ÖÁ´ÂΤò´Þ¤à¤è¤¦¤Ê¥Þ¥Ã¥Ô¥ó¥°¤¬¤¢¤Ã¤¿¤È¤·¤Æ¤â¡¢
251 ¤½¤ì¤é¤Î¥Þ¥Ã¥Ô¥ó¥°¤¬°Û¤Ê¤Ã¤¿·¿¤Ê¤é¤Ð
256 .\"O An invalid argument was given.
257 ÉÔÀµ¤Ê°ú¤¿ô¤¬Í¿¤¨¤é¤ì¤¿¡£
258 .\"O Possible causes are: \fIold_address\fP was not
259 .\"O page aligned; a value other than
260 .\"O .B MREMAP_MAYMOVE
263 .\"O was specified in
271 .\"O or the new address range specified by
275 .\"O overlapped the old address range specified by
281 .\"O was specified without also specifying
282 .\"O .BR MREMAP_MAYMOVE .
283 ²ÄǽÀ¤Î¤¢¤ë¸¶°ø¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¢¤ë:
284 ¤¿¤¤¤Æ¤¤¤Ï \fIold_address\fP ¤¬¥Ú¡¼¥¸¶³¦¤Ë
291 °Ê³°¤ÎÃͤ¬»ØÄꤵ¤ì¤Æ¤¤¤ë;
301 ¤Ç»ØÄꤵ¤ì¤ë¿·¤·¤¤¥¢¥É¥ì¥¹ÈϰϤ¬
305 ¤Ç»ØÄꤵ¤ì¤ë¸Å¤¤¥¢¥É¥ì¥¹ÈϰϤȽŤʤäƤ¤¤ë;
312 .\"O The memory area cannot be expanded at the current virtual address, and the
313 .\"O .B MREMAP_MAYMOVE
314 .\"O flag is not set in \fIflags\fP.
315 .\"O Or, there is not enough (virtual) memory available.
316 ¸½ºß¤Î²¾ÁÛ¥¢¥É¥ì¥¹¤Ç¤Ï¥á¥â¥êÎΰ褬³ÈÄ¥¤Ç¤¤º¡¢
318 ¥Õ¥é¥°¤¬ \fIflags\fP ¤ËÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
319 ¤Þ¤¿¤Ï½½Ê¬¤Ê (²¾ÁÛ) ¥á¥â¥ê¤¬Â¸ºß¤·¤Ê¤¤¡£
320 .\"O .SH "CONFORMING TO"
322 .\"O This call is Linux-specific, and should not be used in programs
323 .\"O intended to be portable.
324 .\"O .\" 4.2BSD had a (never actually implemented)
325 .\"O .\" .BR mremap (2)
326 .\"O .\" call with completely different semantics.
327 ¤³¤Î¥³¡¼¥ë¤Ï Linux ÆÃͤǤ¢¤ê¡¢°Ü¿¢¤ò°Õ¿Þ¤·¤¿¥×¥í¥°¥é¥à¤Ç
329 .\" 4.2BSD ¤Ë¤Ï (¼ÂºÝ¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤¿¤ï¤±¤Ç¤Ï¤Ê¤¤¤¬)
330 .\" Á´¤¯°Û¤Ã¤¿Êý¼° (semantics) ¤Ë¤è¤ë
333 .\" FIXME perhaps remove above statement about 4.2BSD.
336 .\"O Prior to version 2.4, glibc did not expose the definition of
337 .\"O .BR MREMAP_FIXED ,
338 .\"O and the prototype for
340 .\"O did not allow for the
343 ¥Ð¡¼¥¸¥ç¥ó 2.4 ¤è¤êÁ°¤Î glibc ¤Ç¤Ï¡¢
345 ¤ÎÄêµÁ¤Ï¸ø³«¤µ¤ì¤Æ¤ª¤é¤º¡¢
349 °ú¤¿ô¤ò¼è¤é¤Ê¤«¤Ã¤¿¡£
360 .BR feature_test_macros (7)
362 .\"O Your favorite OS text book for more information on paged memory.
363 .\"O (\fIModern Operating Systems\fP by Andrew S. Tannenbaum,
364 .\"O \fIInside Linux\fP by Randolf Bentson,
365 .\"O \fIThe Design of the UNIX Operating System\fP by Maurice J. Bach.)
366 ¥Ú¡¼¥¸Ê¬³ä¤µ¤ì¤¿¥á¥â¥ê¤Ë¤Ä¤¤¤Æ¤â¤Ã¤È¾Ü¤·¤¯ÃΤꤿ¤¤¤Ê¤é¤Ð
367 ¤¢¤Ê¤¿¤Î¹¥¤ß¤Î OS ¤Î¶µ²Ê½ñ¤ò»²¾È¤¹¤ë¤³¤È¡£
368 (\fIModern Operating Systems\fP by Andrew S. Tannenbaum,
369 \fIInside Linux\fP by Randolf Bentson,
370 \fIThe Design of the UNIX Operating System\fP by Maurice J. Bach.)