[9] | 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 | .\"
|
---|
| 5 | .\" @(#)brk.2 6.3 (Berkeley) 5/22/86
|
---|
| 6 | .\"
|
---|
| 7 | .TH BRK 2 "May 22, 1986"
|
---|
| 8 | .UC 4
|
---|
| 9 | .SH NAME
|
---|
| 10 | brk, sbrk \- change data segment size
|
---|
| 11 | .SH SYNOPSIS
|
---|
| 12 | .nf
|
---|
| 13 | #include <unistd.h>
|
---|
| 14 | .PP
|
---|
| 15 | .ft B
|
---|
| 16 | int brk(char *\fIaddr\fP)
|
---|
| 17 | .PP
|
---|
| 18 | .ft B
|
---|
| 19 | char *sbrk(int \fIincr\fP)
|
---|
| 20 | .fi
|
---|
| 21 | .SH DESCRIPTION
|
---|
| 22 | .B Brk
|
---|
| 23 | sets the system's idea of the lowest data segment
|
---|
| 24 | location not used by the program (called the break)
|
---|
| 25 | to
|
---|
| 26 | .IR addr .
|
---|
| 27 | Locations greater than
|
---|
| 28 | .I addr
|
---|
| 29 | and below the stack pointer
|
---|
| 30 | are not in the address space and will thus
|
---|
| 31 | cause a memory violation if accessed.
|
---|
| 32 | .PP
|
---|
| 33 | In the alternate function
|
---|
| 34 | .BR sbrk ,
|
---|
| 35 | .I incr
|
---|
| 36 | more bytes are added to the
|
---|
| 37 | program's data space and a pointer to the
|
---|
| 38 | start of the new area is returned.
|
---|
| 39 | .PP
|
---|
| 40 | When a program begins execution via
|
---|
| 41 | .B execve
|
---|
| 42 | the break is set at the
|
---|
| 43 | highest location defined by the program
|
---|
| 44 | and data storage areas.
|
---|
| 45 | Ordinarily, therefore, only programs with growing
|
---|
| 46 | data areas need to use
|
---|
| 47 | .BR sbrk .
|
---|
| 48 | .SH "RETURN VALUE
|
---|
| 49 | The address of the new break is returned if
|
---|
| 50 | .B brk
|
---|
| 51 | succeeds;
|
---|
| 52 | .B \-1
|
---|
| 53 | if the program requests more
|
---|
| 54 | memory than the system limit.
|
---|
| 55 | .B Sbrk
|
---|
| 56 | returns
|
---|
| 57 | .B \-1
|
---|
| 58 | if the break could not be set.
|
---|
| 59 | .SH ERRORS
|
---|
| 60 | .B Sbrk
|
---|
| 61 | will fail and no additional memory will be allocated if
|
---|
| 62 | one of the following are true:
|
---|
| 63 | .TP 15
|
---|
| 64 | [ENOMEM]
|
---|
| 65 | The maximum possible size of a data segment (as set by
|
---|
| 66 | .BR chmem (1))
|
---|
| 67 | was exceeded.
|
---|
| 68 | .TP 15
|
---|
| 69 | [ENOMEM]
|
---|
| 70 | Insufficient virtual memory space existed
|
---|
| 71 | to support the expansion. (Minix-vmd)
|
---|
| 72 | .SH "SEE ALSO"
|
---|
| 73 | .BR chmem (1),
|
---|
| 74 | .BR execve (2),
|
---|
| 75 | .BR malloc (3),
|
---|
| 76 | .BR end (3).
|
---|
| 77 | .SH NOTES
|
---|
| 78 | Minix-vmd rounds a small data segment limit up to 3 megabytes.
|
---|
| 79 | .SH BUGS
|
---|
| 80 | Setting the break may fail due to a temporary lack of
|
---|
| 81 | virtual memory under Minix-vmd. It is not possible to distinguish this
|
---|
| 82 | from a failure caused by exceeding the maximum size of
|
---|
| 83 | the data segment.
|
---|
| 84 |
|
---|
| 85 | .\"
|
---|
| 86 | .\" $PchId: brk.2,v 1.2 2000/08/11 20:05:51 philip Exp $
|
---|