2 .\" Copyright 1989 AT&T Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH BRK 2 "Jan 14, 1997"
8 brk, sbrk \- change the amount of space allocated for the calling process's
15 \fBint\fR \fBbrk\fR(\fBvoid *\fR\fIendds\fR);
20 \fBvoid *\fR\fBsbrk\fR(\fBintptr_t\fR \fIincr\fR);
26 The \fBbrk()\fR and \fBsbrk()\fR functions are used to change dynamically the
27 amount of space allocated for the calling process's data segment (see
28 \fBexec\fR(2)). The change is made by resetting the process's break value and
29 allocating the appropriate amount of space. The break value is the address of
30 the first location beyond the end of the data segment. The amount of allocated
31 space increases as the break value increases. Newly allocated space is set to
32 zero. If, however, the same memory space is reallocated to the same process
33 its contents are undefined.
36 When a program begins execution using \fBexecve()\fR the break is set at the
37 highest location defined by the program and data storage areas.
40 The \fBgetrlimit\fR(2) function may be used to determine the maximum
41 permissible size of the \fIdata\fR segment; it is not possible to set the break
42 beyond the \fBrlim_max\fR value returned from a call to \fBgetrlimit()\fR, that
43 is to say, "\fBend + rlim.rlim_max\fR." See \fBend\fR(3C).
46 The \fBbrk()\fR function sets the break value to \fIendds\fR and changes the
47 allocated space accordingly.
50 The \fBsbrk()\fR function adds \fIincr\fR function bytes to the break value
51 and changes the allocated space accordingly. The \fIincr\fR function can be
52 negative, in which case the amount of allocated space is decreased.
56 Upon successful completion, \fBbrk()\fR returns \fB0\fR. Otherwise, it returns
57 \fB\(mi1\fR and sets \fBerrno\fR to indicate the error.
60 Upon successful completion, \fBsbrk()\fR returns the prior break value.
61 Otherwise, it returns \fB(void *)\(mi1\fR and sets \fBerrno\fR to indicate the
66 The \fBbrk()\fR and \fBsbrk()\fR functions will fail and no additional memory
74 The data segment size limit as set by \fBsetrlimit()\fR (see
75 \fBgetrlimit\fR(2)) would be exceeded; the maximum possible size of a data
76 segment (compiled into the system) would be exceeded; insufficient space exists
77 in the swap area to support the expansion; or the new break value would extend
78 into an area of the address space defined by some previously established
79 mapping (see \fBmmap\fR(2)).
88 Total amount of system memory available for private pages is temporarily
89 insufficient. This may occur even though the space requested was less than the
90 maximum data segment size (see \fBulimit\fR(2)).
96 The behavior of \fBbrk()\fR and \fBsbrk()\fR is unspecified if an application
97 also uses any other memory functions (such as \fBmalloc\fR(3C), \fBmmap\fR(2),
98 \fBfree\fR(3C)). The \fBbrk()\fR and \fBsbrk()\fR functions have been used in
99 specialized cases where no other memory allocation function provided the same
100 capability. The use of \fBmmap\fR(2) is now preferred because it can be used
101 portably with all other memory allocation functions and with any function that
102 uses other allocation functions.
105 It is unspecified whether the pointer returned by \fBsbrk()\fR is aligned
106 suitably for any purpose.
110 See \fBattributes\fR(5) for descriptions of the following attributes:
118 ATTRIBUTE TYPE ATTRIBUTE VALUE
126 \fBexec\fR(2), \fBgetrlimit\fR(2), \fBmmap\fR(2), \fBshmop\fR(2),
127 \fBulimit\fR(2), \fBend\fR(3C), \fBfree\fR(3C), \fBmalloc\fR(3C)
131 The value of \fIincr\fR may be adjusted by the system before setting the new
132 break value. Upon successful completion, the implementation guarantees a
133 minimum of \fIincr\fR bytes will be added to the data segment if \fIincr\fR is
134 a positive value. If \fIincr\fR is a negative value, a maximum of \fIincr\fR
135 bytes will be removed from the data segment. This adjustment may not be
136 necessary for all machine architectures.
139 The value of the arguments to both \fBbrk()\fR and \fBsbrk()\fR are rounded up
140 for alignment with eight-byte boundaries.
144 Setting the break may fail due to a temporary lack of swap space. It is not
145 possible to distinguish this from a failure caused by exceeding the maximum
146 size of the data segment without consulting \fBgetrlimit()\fR.