Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)brk.2 6.5 (Berkeley) 3/10/91 | |
33 | .\" | |
34 | .Dd March 10, 1991 | |
35 | .Dt BRK 2 | |
36 | .Os BSD 4 | |
37 | .Sh NAME | |
38 | .Nm brk , | |
39 | .Nm sbrk | |
40 | .Nd change data segment size | |
41 | .Sh SYNOPSIS | |
42 | .Fd #include <sys/types.h> | |
c3e2d0fd RG |
43 | .Ft int |
44 | .Fn brk "const char *addr" | |
15637ed4 | 45 | .Ft char * |
c3e2d0fd | 46 | .Fn sbrk "int incr" |
15637ed4 RG |
47 | .Sh DESCRIPTION |
48 | .Bf -symbolic | |
49 | The brk and sbrk functions are historical curiosities | |
50 | left over from earlier days before the advent of virtual memory management. | |
51 | .Ef | |
52 | The | |
53 | .Fn brk | |
54 | function | |
55 | sets the break or lowest address | |
56 | of a process's data segment (unilitialized data) to | |
57 | .Fa addr | |
58 | (immediately above bss). | |
59 | Data addressing is restricted between | |
60 | .Fa addr | |
61 | and the lowest stack pointer to the stack segment. | |
62 | Memory is allocated by | |
63 | .Fa brk | |
64 | in page size pieces; | |
65 | if | |
66 | .Fa addr | |
67 | is not evenly divisible by the system page size, it is | |
68 | increased to the next page boundary. | |
69 | .Pp | |
70 | .\" The | |
71 | .\" .Nm sbrk | |
72 | .\" function | |
73 | .\" allocates chunks of | |
74 | .\" .Fa incr | |
75 | .\" bytes | |
76 | .\" to the process's data space | |
77 | .\" and returns an address pointer. | |
78 | .\" The | |
79 | .\" .Xr malloc 3 | |
80 | .\" function utilizes | |
81 | .\" .Nm sbrk . | |
82 | .\" .Pp | |
83 | The current value of the program break is reliably returned by | |
84 | .Dq Li sbrk(0) | |
85 | (see also | |
86 | .Xr end 3 ) . | |
87 | The | |
88 | .Xr getrlimit 2 | |
89 | system call may be used to determine | |
90 | the maximum permissible size of the | |
91 | .Em data | |
92 | segment; | |
93 | it will not be possible to set the break | |
94 | beyond the | |
95 | .Em rlim_max | |
96 | value returned from a call to | |
97 | .Xr getrlimit , | |
98 | e.g. | |
99 | .Dq qetext + rlp\(->rlim_max. | |
100 | (see | |
101 | .Xr end 3 | |
102 | for the definition of | |
103 | .Em etext ) . | |
104 | .Sh RETURN VALUES | |
105 | .Nm Brk | |
106 | returns 0 if successful; -1 if the process requests more memory than | |
107 | than allowed by the system limit. | |
108 | The | |
109 | .Nm sbrk | |
c3e2d0fd | 110 | function returns the old break value if successful, otherwise a -1 |
15637ed4 RG |
111 | is returned. |
112 | .\" .Sh ERRORS | |
113 | .\" .Xr Sbrk | |
114 | .\" returns -1 if the break could not be set. | |
115 | .\" will fail and no additional memory will be allocated if | |
116 | .\" one of the following are true: | |
117 | .\" .Bl -tag -width [ENOMEM] | |
118 | .\" .It Bq Er ENOMEM | |
119 | .\" The limit, as set by | |
120 | .\" .Xr setrlimit 2 , | |
121 | .\" was exceeded. | |
122 | .\" .It Bq Er ENOMEM | |
123 | .\" The maximum possible size of a data segment (compiled into the | |
124 | .\" system) was exceeded. | |
125 | .\" .It Bq Er ENOMEM | |
126 | .\" Insufficient space existed in the swap area | |
127 | .\" to support the expansion. | |
128 | .\" .El | |
129 | .Sh SEE ALSO | |
130 | .Xr execve 2 , | |
131 | .Xr getrlimit 2 , | |
132 | .Xr malloc 3 , | |
133 | .Xr end 3 | |
134 | .Sh BUGS | |
135 | Setting the break may fail due to a temporary lack of | |
136 | swap space. It is not possible to distinguish this | |
137 | from a failure caused by exceeding the maximum size of | |
138 | the data segment without consulting | |
139 | .Xr getrlimit . | |
140 | .Sh HISTORY | |
141 | A | |
142 | .Nm | |
326e0c26 GW |
143 | function call appeared in |
144 | .At v7 . |