NetBSD/lib/libc/sys/brk.2

152 lines
4.3 KiB
Groff
Raw Normal View History

1998-04-29 02:28:30 +04:00
.\" $NetBSD: brk.2,v 1.11 1998/04/28 22:28:30 fair Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
.\"
.\" 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.
.\"
.\" 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.
.\"
1998-02-02 08:20:24 +03:00
.\" @(#)brk.2 8.4 (Berkeley) 5/1/95
1993-03-21 12:45:37 +03:00
.\"
1998-02-02 08:20:24 +03:00
.Dd May 1, 1995
1993-03-21 12:45:37 +03:00
.Dt BRK 2
.Os BSD 4
.Sh NAME
.Nm brk ,
.Nm sbrk
.Nd change data segment size
.Sh SYNOPSIS
.Fd #include <unistd.h>
.Ft char *
1993-11-25 05:48:32 +03:00
.Fn brk "const char *addr"
1993-03-21 12:45:37 +03:00
.Ft char *
1993-11-25 05:48:32 +03:00
.Fn sbrk "int incr"
1993-03-21 12:45:37 +03:00
.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
.Pp
1993-03-21 12:45:37 +03:00
The
.Fn brk
1998-04-29 02:28:30 +04:00
function sets the break or lowest address of a process's data
segment (uninitialized data) to
1993-03-21 12:45:37 +03:00
.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
1998-04-29 02:28:30 +04:00
is not evenly divisible by the system page size, it is increased
to the next page boundary.
1993-03-21 12:45:37 +03:00
.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
.Dq Li sbrk(0)
1998-04-29 02:28:30 +04:00
(see also
1993-03-21 12:45:37 +03:00
.Xr end 3 ) .
The
.Xr getrlimit 2
system call may be used to determine
the maximum permissible size of the
.Em data
segment;
it will not be possible to set the break
beyond the
.Em rlim_max
value returned from a call to
1998-04-29 02:28:30 +04:00
.Xr getrlimit 2 ,
1993-03-21 12:45:37 +03:00
e.g.
.Dq etext + rlp\(->rlim_max.
1993-03-21 12:45:37 +03:00
(see
.Xr end 3
for the definition of
.Em etext ) .
.Sh RETURN VALUES
1998-02-02 08:20:24 +03:00
.Nm brk
returns 0 if successful;
otherwise -1 with
.Va errno
set to indicate why the allocation failed.
1993-03-21 12:45:37 +03:00
The
.Nm sbrk
function returns a pointer to the base of the new storage if successful;
otherwise -1 with
.Va errno
set to indicate why the allocation failed.
.Sh ERRORS
1998-02-02 08:20:24 +03:00
.Xr brk
or
.Xr sbrk
will fail and no additional memory will be allocated if
one of the following are true:
.Bl -tag -width Er
.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
1993-03-21 12:45:37 +03:00
.Sh SEE ALSO
.Xr execve 2 ,
.Xr getrlimit 2 ,
.Xr mmap 2 ,
1993-03-21 12:45:37 +03:00
.Xr malloc 3 ,
.Xr end 3
.Sh BUGS
1998-04-29 02:28:30 +04:00
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
.Xr getrlimit 2 .
1993-03-21 12:45:37 +03:00
.Sh HISTORY
A
.Fn brk
1998-04-29 02:28:30 +04:00
function call appeared in
.At v7 .