1*61181Sbostic.\" Copyright (c) 1980, 1991, 1993 2*61181Sbostic.\" The Regents of the University of California. All rights reserved. 320011Smckusick.\" 447208Scael.\" %sccs.include.redist.man% 520011Smckusick.\" 6*61181Sbostic.\" @(#)brk.2 8.1 (Berkeley) 06/04/93 747208Scael.\" 847208Scael.Dd 947208Scael.Dt BRK 2 1047208Scael.Os BSD 4 1147208Scael.Sh NAME 1247208Scael.Nm brk , 1347208Scael.Nm sbrk 1447208Scael.Nd change data segment size 1547208Scael.Sh SYNOPSIS 1647208Scael.Fd #include <sys/types.h> 1747208Scael.Ft char 1847208Scael.Fn *brk "const char *addr" 1947208Scael.Ft char * 2047208Scael.Fn *sbrk "int incr" 2147208Scael.Sh DESCRIPTION 2247208Scael.Bf -symbolic 2347208ScaelThe brk and sbrk functions are historical curiosities 2447208Scaelleft over from earlier days before the advent of virtual memory management. 2547208Scael.Ef 2647208ScaelThe 2747208Scael.Fn brk 2847208Scaelfunction 2947208Scaelsets the break or lowest address 3047208Scaelof a process's data segment (unilitialized data) to 3147208Scael.Fa addr 3247208Scael(immediately above bss). 3347208ScaelData addressing is restricted between 3447208Scael.Fa addr 3547208Scaeland the lowest stack pointer to the stack segment. 3647208ScaelMemory is allocated by 3747208Scael.Fa brk 3847208Scaelin page size pieces; 3947208Scaelif 4047208Scael.Fa addr 4147208Scaelis not evenly divisible by the system page size, it is 4247208Scaelincreased to the next page boundary. 4347208Scael.Pp 4447208Scael.\" The 4547208Scael.\" .Nm sbrk 4647208Scael.\" function 4747208Scael.\" allocates chunks of 4847208Scael.\" .Fa incr 4947208Scael.\" bytes 5047208Scael.\" to the process's data space 5147208Scael.\" and returns an address pointer. 5247208Scael.\" The 5347208Scael.\" .Xr malloc 3 5447208Scael.\" function utilizes 5547208Scael.\" .Nm sbrk . 5647208Scael.\" .Pp 5729411SmckusickThe current value of the program break is reliably returned by 5847208Scael.Dq Li sbrk(0) 5947208Scael(see also 6047208Scael.Xr end 3 ) . 6120011SmckusickThe 6247208Scael.Xr getrlimit 2 6320011Smckusicksystem call may be used to determine 6420011Smckusickthe maximum permissible size of the 6547208Scael.Em data 6620012Smckusicksegment; 6720011Smckusickit will not be possible to set the break 6820012Smckusickbeyond the 6947208Scael.Em rlim_max 7020012Smckusickvalue returned from a call to 7147208Scael.Xr getrlimit , 7247208Scaele.g. 7347208Scael.Dq qetext + rlp\(->rlim_max. 7428360Sanne(see 7547208Scael.Xr end 3 7620011Smckusickfor the definition of 7747208Scael.Em etext ) . 7847208Scael.Sh RETURN VALUES 7947208Scael.Nm Brk 8060016Smckusickreturns a pointer to the new end of memory if successful; 8160016Smckusickotherwise -1 with 8260016Smckusick.Va errno 8360016Smckusickset to indicate why the allocation failed. 8447208ScaelThe 8547208Scael.Nm sbrk 8660016Smckusickreturns a pointer to the base of the new storage if successful; 8760016Smckusickotherwise -1 with 8860016Smckusick.Va errno 8960016Smckusickset to indicate why the allocation failed. 9060016Smckusick.Sh ERRORS 9160016Smckusick.Xr Sbrk 9260016Smckusickwill fail and no additional memory will be allocated if 9360016Smckusickone of the following are true: 9460016Smckusick.Bl -tag -width [ENOMEM] 9560016Smckusick.It Bq Er ENOMEM 9660016SmckusickThe limit, as set by 9760016Smckusick.Xr setrlimit 2 , 9860016Smckusickwas exceeded. 9960016Smckusick.It Bq Er ENOMEM 10060016SmckusickThe maximum possible size of a data segment (compiled into the 10160016Smckusicksystem) was exceeded. 10260016Smckusick.It Bq Er ENOMEM 10360016SmckusickInsufficient space existed in the swap area 10460016Smckusickto support the expansion. 10560016Smckusick.El 10647208Scael.Sh SEE ALSO 10747208Scael.Xr execve 2 , 10847208Scael.Xr getrlimit 2 , 10947208Scael.Xr malloc 3 , 11047208Scael.Xr end 3 11147208Scael.Sh BUGS 11220012SmckusickSetting the break may fail due to a temporary lack of 11320012Smckusickswap space. It is not possible to distinguish this 11420012Smckusickfrom a failure caused by exceeding the maximum size of 11520012Smckusickthe data segment without consulting 11647208Scael.Xr getrlimit . 11747208Scael.Sh HISTORY 11847208ScaelA 11947208Scael.Nm 12047208Scaelfunction call appeared in Version 7 AT&T UNIX. 121