1BRK(2) System Calls Manual BRK(2)
2
3
4
6 brk, sbrk - change data segment size
7
9 #include <sys/types.h>
10
11 char *brk(addr)
12 char *addr;
13
14 char *sbrk(incr)
15 int incr;
16
18 Brk sets the system's idea of the lowest data segment location not used
19 by the program (called the break) to addr (rounded up to the next mul‐
20 tiple of the system's page size). Locations greater than addr and
21 below the stack pointer are not in the address space and will thus
22 cause a memory violation if accessed.
23
24 In the alternate function sbrk, incr more bytes are added to the pro‐
25 gram's data space and a pointer to the start of the new area is
26 returned.
27
28 When a program begins execution via execve the break is set at the
29 highest location defined by the program and data storage areas. Ordi‐
30 narily, therefore, only programs with growing data areas need to use
31 sbrk.
32
33 The getrlimit(2) system call may be used to determine the maximum per‐
34 missible size of the data segment; it will not be possible to set the
35 break beyond the rlim_max value returned from a call to getrlimit, e.g.
36 “etext + rlp→rlim_max.” (see end(3) for the definition of etext).
37
39 Zero is returned if the brk could be set; -1 if the program requests
40 more memory than the system limit. Sbrk returns -1 if the break could
41 not be set.
42
44 Sbrk will fail and no additional memory will be allocated if one of the
45 following are true:
46
47 [ENOMEM] The limit, as set by setrlimit(2), was exceeded.
48
49 [ENOMEM] The maximum possible size of a data segment (compiled
50 into the system) was exceeded.
51
52 [ENOMEM] Insufficient space existed in the swap area to support
53 the expansion.
54
56 execve(2), getrlimit(2), malloc(3), end(3)
57
59 Setting the break may fail due to a temporary lack of swap space. It
60 is not possible to distinguish this from a failure caused by exceeding
61 the maximum size of the data segment without consulting getrlimit.
62
63
64
654th Berkeley Distribution May 22, 1986 BRK(2)