BSD 4_3_Reno release
[unix-history] / usr / src / lib / libc / sys / brk.2
CommitLineData
1423f0e0
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
ca67e7b4 5.\" @(#)brk.2 6.4 (Berkeley) 6/17/86
1423f0e0 6.\"
ca67e7b4 7.TH BRK 2 "June 17, 1986"
1423f0e0
KM
8.UC 4
9.SH NAME
1fa16506 10brk, sbrk \- change data segment size
1423f0e0 11.SH SYNOPSIS
1fa16506 12.nf
fbce8e35
KM
13#include <sys/types.h>
14.PP
1fa16506 15.ft B
96a9406d
DS
16char *brk(addr)
17char *addr;
1423f0e0 18.PP
1fa16506 19.ft B
96a9406d 20char *sbrk(incr)
1fa16506
KM
21int incr;
22.fi
1423f0e0
KM
23.SH DESCRIPTION
24.I Brk
1fa16506
KM
25sets the system's idea of the lowest data segment
26location not used by the program (called the break)
1423f0e0
KM
27to
28.I addr
1fa16506
KM
29(rounded up to the next multiple of the system's page size).
30Locations greater than
1423f0e0
KM
31.I addr
32and below the stack pointer
33are not in the address space and will thus
34cause a memory violation if accessed.
35.PP
36In the alternate function
1fa16506 37.IR sbrk ,
1423f0e0
KM
38.I incr
39more bytes are added to the
40program's data space and a pointer to the
41start of the new area is returned.
42.PP
43When a program begins execution via
1fa16506 44.I execve
1423f0e0
KM
45the break is set at the
46highest location defined by the program
47and data storage areas.
48Ordinarily, therefore, only programs with growing
49data areas need to use
1fa16506 50.IR sbrk .
1423f0e0 51.PP
53d740be
KM
52The current value of the program break is reliably returned by
53``sbrk(0)'' (see also
54.IR end (3)).
1423f0e0 55The
1fa16506 56.IR getrlimit (2)
1423f0e0
KM
57system call may be used to determine
58the maximum permissible size of the
59.I data
1fa16506 60segment;
1423f0e0 61it will not be possible to set the break
1fa16506
KM
62beyond the
63.I rlim_max
64value returned from a call to
65.IR getrlimit ,
66e.g. \*(lqetext + rlp\(->rlim_max.\*(rq
90f5cfd5 67(see
1423f0e0
KM
68.IR end (3)
69for the definition of
90f5cfd5 70.IR etext ).
1fa16506 71.SH "RETURN VALUE
1423f0e0
KM
72Zero is returned if the
73.I brk
74could be set;
75\-1 if the program requests more
1fa16506 76memory than the system limit.
1423f0e0
KM
77.I Sbrk
78returns \-1 if the break could not be set.
1fa16506
KM
79.SH ERRORS
80.I Sbrk
81will fail and no additional memory will be allocated if
82one of the following are true:
83.TP 15
84[ENOMEM]
85The limit, as set by
86.IR setrlimit (2),
87was exceeded.
88.TP 15
89[ENOMEM]
90The maximum possible size of a data segment (compiled into the
91system) was exceeded.
92.TP 15
93[ENOMEM]
94Insufficient space existed in the swap area
95to support the expansion.
96.SH "SEE ALSO"
97execve(2), getrlimit(2), malloc(3), end(3)
1423f0e0 98.SH BUGS
1fa16506
KM
99Setting the break may fail due to a temporary lack of
100swap space. It is not possible to distinguish this
101from a failure caused by exceeding the maximum size of
102the data segment without consulting
103.IR getrlimit .