Commit | Line | Data |
---|---|---|
931b8415 CL |
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
1423f0e0 | 3 | .\" |
931b8415 | 4 | .\" %sccs.include.redist.man% |
1423f0e0 | 5 | .\" |
931b8415 CL |
6 | .\" @(#)brk.2 6.5 (Berkeley) %G% |
7 | .\" | |
8 | .Dd | |
9 | .Dt BRK 2 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm brk , | |
13 | .Nm sbrk | |
14 | .Nd change data segment size | |
15 | .Sh SYNOPSIS | |
16 | .Fd #include <sys/types.h> | |
17 | .Ft char | |
18 | .Fn *brk "const char *addr" | |
19 | .Ft char * | |
20 | .Fn *sbrk "int incr" | |
21 | .Sh DESCRIPTION | |
22 | .Bf -symbolic | |
23 | The brk and sbrk functions are historical curiosities | |
24 | left over from earlier days before the advent of virtual memory management. | |
25 | .Ef | |
26 | The | |
27 | .Fn brk | |
28 | function | |
29 | sets the break or lowest address | |
30 | of a process's data segment (unilitialized data) to | |
31 | .Fa addr | |
32 | (immediately above bss). | |
33 | Data addressing is restricted between | |
34 | .Fa addr | |
35 | and the lowest stack pointer to the stack segment. | |
36 | Memory is allocated by | |
37 | .Fa brk | |
38 | in page size pieces; | |
39 | if | |
40 | .Fa addr | |
41 | is not evenly divisible by the system page size, it is | |
42 | increased to the next page boundary. | |
43 | .Pp | |
44 | .\" The | |
45 | .\" .Nm sbrk | |
46 | .\" function | |
47 | .\" allocates chunks of | |
48 | .\" .Fa incr | |
49 | .\" bytes | |
50 | .\" to the process's data space | |
51 | .\" and returns an address pointer. | |
52 | .\" The | |
53 | .\" .Xr malloc 3 | |
54 | .\" function utilizes | |
55 | .\" .Nm sbrk . | |
56 | .\" .Pp | |
53d740be | 57 | The current value of the program break is reliably returned by |
931b8415 CL |
58 | .Dq Li sbrk(0) |
59 | (see also | |
60 | .Xr end 3 ) . | |
1423f0e0 | 61 | The |
931b8415 | 62 | .Xr getrlimit 2 |
1423f0e0 KM |
63 | system call may be used to determine |
64 | the maximum permissible size of the | |
931b8415 | 65 | .Em data |
1fa16506 | 66 | segment; |
1423f0e0 | 67 | it will not be possible to set the break |
1fa16506 | 68 | beyond the |
931b8415 | 69 | .Em rlim_max |
1fa16506 | 70 | value returned from a call to |
931b8415 CL |
71 | .Xr getrlimit , |
72 | e.g. | |
73 | .Dq qetext + rlp\(->rlim_max. | |
90f5cfd5 | 74 | (see |
931b8415 | 75 | .Xr end 3 |
1423f0e0 | 76 | for the definition of |
931b8415 CL |
77 | .Em etext ) . |
78 | .Sh RETURN VALUES | |
79 | .Nm Brk | |
80 | returns 0 if successful; -1 if the process requests more memory than | |
81 | than allowed by the system limit. | |
82 | The | |
83 | .Nm sbrk | |
84 | function returns 0 if successful, otherwise the error | |
85 | .Er EOPNOTSUPP | |
86 | is returned. | |
87 | .\" .Sh ERRORS | |
88 | .\" .Xr Sbrk | |
89 | .\" returns -1 if the break could not be set. | |
90 | .\" will fail and no additional memory will be allocated if | |
91 | .\" one of the following are true: | |
92 | .\" .Bl -tag -width [ENOMEM] | |
93 | .\" .It Bq Er ENOMEM | |
94 | .\" The limit, as set by | |
95 | .\" .Xr setrlimit 2 , | |
96 | .\" was exceeded. | |
97 | .\" .It Bq Er ENOMEM | |
98 | .\" The maximum possible size of a data segment (compiled into the | |
99 | .\" system) was exceeded. | |
100 | .\" .It Bq Er ENOMEM | |
101 | .\" Insufficient space existed in the swap area | |
102 | .\" to support the expansion. | |
103 | .\" .El | |
104 | .Sh SEE ALSO | |
105 | .Xr execve 2 , | |
106 | .Xr getrlimit 2 , | |
107 | .Xr malloc 3 , | |
108 | .Xr end 3 | |
109 | .Sh BUGS | |
1fa16506 KM |
110 | Setting the break may fail due to a temporary lack of |
111 | swap space. It is not possible to distinguish this | |
112 | from a failure caused by exceeding the maximum size of | |
113 | the data segment without consulting | |
931b8415 CL |
114 | .Xr getrlimit . |
115 | .Sh HISTORY | |
116 | A | |
117 | .Nm | |
118 | function call appeared in Version 7 AT&T UNIX. |