BSD 4_3_Tahoe development
[unix-history] / usr / man / cat2 / sbrk.0
BRK(2) UNIX Programmer's Manual BRK(2)
N\bNA\bAM\bME\bE
brk, sbrk - change data segment size
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#include <sys/types.h>
c\bch\bha\bar\br *\b*b\bbr\brk\bk(\b(a\bad\bdd\bdr\br)\b)
c\bch\bha\bar\br *\b*a\bad\bdd\bdr\br;\b;
c\bch\bha\bar\br *\b*s\bsb\bbr\brk\bk(\b(i\bin\bnc\bcr\br)\b)
i\bin\bnt\bt i\bin\bnc\bcr\br;\b;
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
_\bB_\br_\bk sets the system's idea of the lowest data segment loca-
tion not used by the program (called the break) to _\ba_\bd_\bd_\br
(rounded up to the next multiple of the system's page size).
Locations greater than _\ba_\bd_\bd_\br and below the stack pointer are
not in the address space and will thus cause a memory viola-
tion if accessed.
In the alternate function _\bs_\bb_\br_\bk, _\bi_\bn_\bc_\br more bytes are added to
the program's data space and a pointer to the start of the
new area is returned.
When a program begins execution via _\be_\bx_\be_\bc_\bv_\be the break is set
at the highest location defined by the program and data
storage areas. Ordinarily, therefore, only programs with
growing data areas need to use _\bs_\bb_\br_\bk.
The current value of the program break is reliably returned
by ``sbrk(0)'' (see also _\be_\bn_\bd(3)). The _\bg_\be_\bt_\br_\bl_\bi_\bm_\bi_\bt(2) system
call may be used to determine the maximum permissible size
of the _\bd_\ba_\bt_\ba segment; it will not be possible to set the
break beyond the _\br_\bl_\bi_\bm__\bm_\ba_\bx value returned from a call to
_\bg_\be_\bt_\br_\bl_\bi_\bm_\bi_\bt, e.g. "etext + rlp->rlim_max." (see _\be_\bn_\bd(3) for the
definition of _\be_\bt_\be_\bx_\bt).
R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bE
Zero is returned if the _\bb_\br_\bk could be set; -1 if the program
requests more memory than the system limit. _\bS_\bb_\br_\bk returns -1
if the break could not be set.
E\bER\bRR\bRO\bOR\bRS\bS
_\bS_\bb_\br_\bk will fail and no additional memory will be allocated if
one of the following are true:
[ENOMEM] The limit, as set by _\bs_\be_\bt_\br_\bl_\bi_\bm_\bi_\bt(2), was
exceeded.
[ENOMEM] The maximum possible size of a data segment
(compiled into the system) was exceeded.
Printed 7/9/88 June 17, 1986 1
BRK(2) UNIX Programmer's Manual BRK(2)
[ENOMEM] Insufficient space existed in the swap area
to support the expansion.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
execve(2), getrlimit(2), malloc(3), end(3)
B\bBU\bUG\bGS\bS
Setting the break may fail due to a temporary lack of swap
space. It is not possible to distinguish this from a
failure caused by exceeding the maximum size of the data
segment without consulting _\bg_\be_\bt_\br_\bl_\bi_\bm_\bi_\bt.
Printed 7/9/88 June 17, 1986 2