1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1993 Michael Haardt
4 .\" (michael@moria.de),
5 .\" Fri Apr 2 11:32:09 MET DST 1993
7 .\" This is free documentation; you can redistribute it and/or
8 .\" modify it under the terms of the GNU General Public License as
9 .\" published by the Free Software Foundation; either version 2 of
10 .\" the License, or (at your option) any later version.
12 .\" The GNU General Public License's references to "object code"
13 .\" and "executables" are to be interpreted as the output of any
14 .\" document formatting or typesetting system, including
15 .\" intermediate and printed output.
17 .\" This manual is distributed in the hope that it will be useful,
18 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 .\" GNU General Public License for more details.
22 .\" You should have received a copy of the GNU General Public
23 .\" License along with this manual; if not, write to the Free
24 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
27 .\" Modified Wed Jul 21 19:52:58 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sun Aug 21 17:40:38 1994 by Rik Faith <faith@cs.unc.edu>
30 .\" Japanese Version Copyright (c) 1996 TABATA Tomohira
31 .\" all rights reserved.
32 .\" Translated Wed Jun 26 19:12:54 JST 1996
33 .\" by TABATA Tomohira <loba@k2.t.u-tokyo.ac.jp>
34 .\" Modified Sat Dec 13 23:43:56 JST 1997
35 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
36 .\" Updated & Modified Wed May 19 01:55:29 JST 2004
37 .\" by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v1.66
38 .\" Updated & Modified Tue Jan 2 09:09:47 JST 2007 by Yuichi SATO, LDP v2.43
39 .\" Updated 2008-08-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
41 .TH BRK 2 2008-06-18 "Linux" "Linux Programmer's Manual"
44 .\"O brk, sbrk \- change data segment size
45 brk, sbrk \- ¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È¤Î¥µ¥¤¥º¤ÎÊѹ¹¤¹¤ë
48 .B #include <unistd.h>
50 .BI "int brk(void *" addr );
52 .BI "void *sbrk(intptr_t " increment );
55 .\"O Feature Test Macro Requirements for glibc (see
56 .\"O .BR feature_test_macros (7)):
57 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
58 .RB ( feature_test_macros (7)
65 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
72 .\"O change the location of the
73 .\"O .IR "program break" ,
74 .\"O which defines the end of the process's data segment
75 .\"O (i.e., the program break is the first location after the end of the
76 .\"O uninitialized data segment).
77 .\"O Increasing the program break has the effect of
78 .\"O allocating memory to the process;
79 .\"O decreasing the break deallocates memory.
84 .I "¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯ (program break)"
86 ¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤Ï¥×¥í¥»¥¹¤Î¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È (data segment) ¤Î
87 ËöÈø¤ò¼¨¤¹ (¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤Ï¡¢½é´ü²½¤µ¤ì¤Æ¤¤¤Ê¤¤
88 ¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È¤ÎËöÈø¤Îľ¸å¤Î¾ì½ê¤È¤Ê¤ë)¡£
89 ¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤òÁý¤ä¤¹¤È¤¤¤¦¤³¤È¤Ï¡¢¤½¤Î¥×¥í¥»¥¹¤Ø¤Î
90 ¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë¸ú²Ì¤¬¤¢¤ê¡¢
91 ¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤ò¸º¤é¤¹¤È¤¤¤¦¤³¤È¤Ï¡¢¥á¥â¥ê¤ò²òÊü¤¹¤ë
95 .\"O sets the end of the data segment to the value specified by
97 .\"O when that value is reasonable, the system has enough memory,
98 .\"O and the process does not exceed its maximum data size (see
99 .\"O .BR setrlimit (2)).
101 ¤Ï¡¢¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È¤ÎËöÈø¤ò
103 ¤Ç»ØÄꤷ¤¿ÃͤËÀßÄꤹ¤ë¡£
104 ÀßÄ꤬¹Ô¤ï¤ì¤ë¤Î¤Ï¡¢»ØÄꤷ¤¿Ãͤ¬Í¸ú¤Ç¡¢
105 ¥·¥¹¥Æ¥à¤Ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤¢¤ê¡¢
106 ¥×¥í¥»¥¹¤Î¥Ç¡¼¥¿¥µ¥¤¥º¤ÎºÇÂçÃͤòĶ¤¨¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ç¤¢¤ë
111 .\"O increments the program's data space by
115 ¤Ï¡¢¥×¥í¥°¥é¥à¤Î¥Ç¡¼¥¿¶õ´Ö¤ò
122 .\"O of 0 can be used to find the current location of the program break.
126 ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Ç¡¢¥×¥í¥°¥é¥à¤Î¸½ºß¤Î¥Ö¥ì¡¼¥¯ (break) ¾ì½ê¤òÃΤ뤳¤È¤¬¤Ç¤¤ë¡£
127 .\"O .SH "RETURN VALUE"
135 .\"O On error, \-1 is returned, and
139 .\"O (But see \fILINUX NOTES\fP below.)
140 ¥¨¥é¡¼¤Î¾ì¹ç¤Ë¤Ï¡¢\-1 ¤òÊÖ¤·¡¢
145 (¤¿¤À¤·¡ÖLINUX ¤Ç¤ÎÃí°Õ¡×¤ò»²¾È¤¹¤ë¤³¤È)¡£
149 .\"O returns the previous program break.
150 .\"O (If the break was increased,
151 .\"O then this value is a pointer to the start of the newly allocated memory).
153 .\"O .I "(void\ *)\ \-1"
154 .\"O is returned, and
160 ¤ÏÊѹ¹Á°¤Î¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤òÊÖ¤¹
161 (¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤¬Áý¤ä¤µ¤ì¤¿¾ì¹ç¡¢¤³¤ÎÃͤÏ
162 ¿·¤·¤¯³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ÎÀèƬ¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤È¤Ê¤ë)¡£
170 .\"O .SH "CONFORMING TO"
172 .\"O 4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001.
174 SUSv2 ¤Ç¤Ï¡Ö²áµî¤Î̾»Ä (LEGACY)¡×¤È°ÌÃÖÉÕ¤±¤é¤ì¤Æ¤ª¤ê¡¢
175 POSIX.1-2001 ¤Çºï½ü¤µ¤ì¤¿¡£
180 .\"O .\" are not defined in the C Standard and are deliberately excluded from the
181 .\"O .\" POSIX.1-1990 standard (see paragraphs B.1.1.1.3 and B.8.3.3).
185 .\" ¤Ï C µ¬³Ê (C Standard) ¤Ë¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
186 .\" ¤Þ¤¿ POSIX.1 µ¬³Ê¤«¤é¤Ï°Õ¿ÞŪ¤Ë½ü³°¤µ¤ì¤Æ¤¤¤ë (ÃÊÍî B.1.1.1.3, B.8.3.3 »²¾È)¡£
195 .\"O memory allocation package is the
196 .\"O portable and comfortable way of allocating memory.
200 ¤ò»ÈÍѤ¹¤ë¤Î¤ÏÈò¤±¤ë¤³¤È¡£
202 ¥á¥â¥ê³ä¤êÅö¤Æ¥Ñ¥Ã¥±¡¼¥¸¤ÎÊý¤¬¡¢°Ü¿¢À¤¬¹â¤¯¡¢
203 »È¤¤¤ä¤¹¤¤¥á¥â¥ê³ä¤êÅö¤ÆÊýË¡¤òÄ󶡤·¤Æ¤¤¤ë¡£
205 .\"O Various systems use various types for the argument of
207 ¤¤¤í¤¤¤í¤Ê¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ¡¢
209 ¤Î°ú¤¿ô¤ËÍÍ¡¹¤Ê·¿¤¬»È¤ï¤ì¤Æ¤¤¤ë¡£
210 .\"O Common are \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP.
211 °ìÈÌŪ¤Ê¤Î¤Ï \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP ¤Ç¤¢¤ë¡£
213 .\"O .\" \fIint\fP (e.g., XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
214 .\"O .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
215 .\"O .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
216 .\"O .\" \fIintptr_t\fP (e.g., XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7, NetBSD 1.6,
217 .\"O .\" Tru64 5.1, glibc2.2).
218 .\" \fIint\fP (¤¿¤È¤¨¤Ð XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
219 .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
220 .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
221 .\" \fIintptr_t\fP (¤¿¤È¤¨¤Ð XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7,
222 .\" NetBSD 1.6, Tru64 5.1, glibc2.2).
223 .\" ¤È¤¤¤¦¤Î¤¬Ê¬¤«¤ë¤À¤í¤¦¡£
226 .\"O The return value described above for
228 .\"O is the behavior provided by the glibc wrapper function for the Linux
233 ¤ÎÊÖ¤êÃͤˤĤ¤¤Æ¤ÎÆ°ºî¤Ï¡¢
236 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥é¥Ã¥×¤¹¤ë glibc ¤Î´Ø¿ô¤Ë¤è¤ë¤â¤Î¤Ç¤¢¤ë¡£
237 .\"O (On most other implementations, the return value from
239 .\"O is the same; this return value was also specified in SUSv2.)
240 (¤½¤Î¾¤Î¿¤¯¤Î¼ÂÁõ¤Ç¤â¡¢
242 ¤ÎÊÖ¤êÃͤϤ³¤ì¤ÈƱ¤¸¤Ç¤¢¤ë¡£
243 ¤³¤ÎÊÖ¤êÃÍ¤Ï SUSv2 ¤Ç¤âµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£)
245 .\"O the actual Linux system call returns the new program break on success.
246 ¤·¤«¤·¡¢¼ÂºÝ¤Î Linux ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç¡¢
247 ¥×¥í¥°¥é¥à¤Î¿·¤·¤¤¥Ö¥ì¡¼¥¯¤òÊÖ¤¹¡£
248 .\"O On failure, the system call returns the current break.
249 ¼ºÇÔ¤·¤¿¾ì¹ç¡¢¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¸½ºß¤Î¥Ö¥ì¡¼¥¯¤òÊÖ¤¹¡£
250 .\"O The glibc wrapper function does some work
251 .\"O (i.e., checks whether the new break is less than
253 .\"O to provide the 0 and \-1 return values described above.
254 glibc ¥é¥Ã¥Ñ¡¼´Ø¿ô¤ÏƱÍͤÎƯ¤¤ò¤·
255 (¤¹¤Ê¤ï¤Á¡¢¿·¤·¤¤¥Ö¥ì¡¼¥¯¤¬
257 ¤è¤ê¾®¤µ¤¤¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤·)¡¢
258 ¾å¤ÇÀâÌÀ¤·¤¿ 0 ¤È \-1 ¤È¤¤¤¦ÊÖ¤êÃͤòÊÖ¤¹¡£
262 .\"O is implemented as a library function that uses the
264 .\"O system call, and does some internal bookkeeping so that it can
265 .\"O return the old break value.
270 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»È¤¦¥é¥¤¥Ö¥é¥ê´Ø¿ô¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤Æ¤ª¤ê¡¢
271 °ÊÁ°¤Î¥Ö¥ì¡¼¥¯¤ÎÃͤòÊÖ¤¹¤³¤È¤¬¤Ç¤¤ë¤è¤¦¤ËÆâÉô¤ÇÄ´À°¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë¡£