BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libc / sys / brk.2
index 5ca0fee..79cf8cd 100644 (file)
-.\" Copyright (c) 1980 Regents of the University of California.
-.\" All rights reserved.  The Berkeley software License Agreement
-.\" specifies the terms and conditions for redistribution.
+.\" Copyright (c) 1980, 1991 Regents of the University of California.
+.\" All rights reserved.
 .\"
 .\"
-.\"    @(#)brk.2       6.4 (Berkeley) 6/17/86
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
 .\"
 .\"
-.TH BRK 2 "June 17, 1986"
-.UC 4
-.SH NAME
-brk, sbrk \- change data segment size
-.SH SYNOPSIS
-.nf
-#include <sys/types.h>
-.PP
-.ft B
-char *brk(addr)
-char *addr;
-.PP
-.ft B
-char *sbrk(incr)
-int incr;
-.fi
-.SH DESCRIPTION
-.I Brk
-sets the system's idea of the lowest data segment 
-location not used by the program (called the break)
-to
-.I addr
-(rounded up to the next multiple of the system's page size).
-Locations greater than
-.I addr
-and below the stack pointer
-are not in the address space and will thus
-cause a memory violation if accessed.
-.PP
-In the alternate function
-.IR sbrk ,
-.I incr
-more bytes are added to the
-program's data space and a pointer to the
-start of the new area is returned.
-.PP
-When a program begins execution via
-.I execve
-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
-.IR sbrk .
-.PP
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)brk.2      6.5 (Berkeley) 3/10/91
+.\"
+.Dd March 10, 1991
+.Dt BRK 2
+.Os BSD 4
+.Sh NAME
+.Nm brk ,
+.Nm sbrk
+.Nd change data segment size
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Ft char
+.Fn *brk "const char *addr"
+.Ft char *
+.Fn *sbrk "int incr"
+.Sh DESCRIPTION
+.Bf -symbolic
+The brk and sbrk functions are historical curiosities
+left over from earlier days before the advent of virtual memory management.
+.Ef
+The
+.Fn brk
+function
+sets the break or lowest address
+of a process's data segment (unilitialized data) to
+.Fa addr
+(immediately above bss).
+Data addressing is restricted between
+.Fa addr
+and the lowest stack pointer to the stack segment.
+Memory is allocated by
+.Fa brk
+in page size pieces;
+if
+.Fa addr
+is not evenly divisible by the system page size, it is
+increased to the next page boundary.
+.Pp
+.\" The
+.\" .Nm sbrk
+.\" function
+.\" allocates chunks of
+.\" .Fa incr
+.\" bytes
+.\" to the process's data space
+.\" and returns an address pointer.
+.\" The
+.\" .Xr malloc 3
+.\" function utilizes
+.\" .Nm sbrk .
+.\" .Pp
 The current value of the program break is reliably returned by
 The current value of the program break is reliably returned by
-``sbrk(0)'' (see also 
-.IR end (3)).
+.Dq Li sbrk(0)
+(see also 
+.Xr end 3 ) .
 The
 The
-.IR getrlimit (2)
+.Xr getrlimit 2
 system call may be used to determine
 the maximum permissible size of the
 system call may be used to determine
 the maximum permissible size of the
-.I data
+.Em data
 segment;
 it will not be possible to set the break
 beyond the
 segment;
 it will not be possible to set the break
 beyond the
-.I rlim_max
+.Em rlim_max
 value returned from a call to
 value returned from a call to
-.IR getrlimit ,
-e.g. \*(lqetext + rlp\(->rlim_max.\*(rq
+.Xr getrlimit ,
+e.g.
+.Dq qetext + rlp\(->rlim_max.
 (see
 (see
-.IR end (3)
+.Xr end 3
 for the definition of
 for the definition of
-.IR etext ).
-.SH "RETURN VALUE
-Zero is returned if the 
-.I brk
-could be set;
-\-1 if the program requests more
-memory than the system limit.
-.I Sbrk
-returns \-1 if the break could not be set.
-.SH ERRORS
-.I Sbrk
-will fail and no additional memory will be allocated if
-one of the following are true:
-.TP 15
-[ENOMEM]
-The limit, as set by
-.IR setrlimit (2),
-was exceeded.
-.TP 15
-[ENOMEM]
-The maximum possible size of a data segment (compiled into the
-system) was exceeded.
-.TP 15
-[ENOMEM]
-Insufficient space existed in the swap area
-to support the expansion.
-.SH "SEE ALSO"
-execve(2), getrlimit(2), malloc(3), end(3)
-.SH BUGS
+.Em etext ) .
+.Sh RETURN VALUES
+.Nm Brk
+returns 0 if successful; -1 if the process requests more memory than
+than allowed by the system limit.
+The
+.Nm sbrk
+function returns 0 if successful, otherwise the error
+.Er EOPNOTSUPP
+is returned.
+.\" .Sh ERRORS
+.\" .Xr Sbrk
+.\" returns -1 if the break could not be set.
+.\" will fail and no additional memory will be allocated if
+.\" one of the following are true:
+.\" .Bl -tag -width [ENOMEM]
+.\" .It Bq Er ENOMEM
+.\" The limit, as set by
+.\" .Xr setrlimit 2 ,
+.\" was exceeded.
+.\" .It Bq Er ENOMEM
+.\" The maximum possible size of a data segment (compiled into the
+.\" system) was exceeded.
+.\" .It Bq Er ENOMEM
+.\" Insufficient space existed in the swap area
+.\" to support the expansion.
+.\" .El
+.Sh SEE ALSO
+.Xr execve 2 ,
+.Xr getrlimit 2 ,
+.Xr malloc 3 ,
+.Xr end 3
+.Sh BUGS
 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 
 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 
-.IR getrlimit .
+.Xr getrlimit .
+.Sh HISTORY
+A
+.Nm
+function call appeared in Version 7 AT&T UNIX.