Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ brk(2) — UTek 3.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

execve(2)

getrlimit(2)

end(3c)

malloc(3c)



BRK(2)                  COMMAND REFERENCE                  BRK(2)



NAME
     brk, sbrk - change data segment size

SYNOPSIS
     #include <sys/types.h>

     caddrt brk(addr)
     caddrt addr;

     newaddr = sbrk(incr)
     caddrt newaddr;
     int incr;

DESCRIPTION
     Brk and sbrk are used to change dynamically the amount of
     space allocated for the calling process's contiguous heap.
     The change is made by resetting the process's break value.
     The break value is the address of the first location beyond
     the end of the contiguous heap.  The amount of allocated
     space increases as the break value increases.  Brk sets the
     break value to addr (rounded up to the next multiple of the
     system's page size) and changes the allocated space
     accordingly.  Locations greater than addr and below the
     stack pointer are not in the address space and will thus
     cause a memory violation if accessed.

     Sbrk adds incr more bytes to the break value and changes the
     allocated space accordingly.  A pointer to the start of the
     new area is returned in newaddr.

     When a program begins execution via 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 sbrk.

     The getrlimit(2) system call may be used to determine the
     maximum permissible size of the data segment; it will not be
     possible to set the break beyond the rlim_max value returned
     from a call to getrlimit, e.g. "etext + rlp->rlim_max." (See
     end(3c) for the definition of etext.)

DIAGNOSTICS
     Sbrk and brk will fail and no additional memory will be
     allocated if one of the following are true:

     [ENOMEM]     The limit, as set by setrlimit(2), would be
                  exceeded.

     [ENOMEM]     The maximum possible size of a data segment,
                  text segment or stack would be exceeded.  These
                  limits are MAXTSIZ, MAXDSIZ and MAXSSIZ,
                  defined in <machine/vmparam.h>.



Printed 5/12/88                                                 1





BRK(2)                  COMMAND REFERENCE                  BRK(2)



     [ENOMEM]     Insufficient space exists in the swap area to
                  support the expansion.

RETURN VALUE
     Brk returns 0 if the break could be set, otherwise it
     returns -1.  Sbrk returns a pointer to the new data area in
     newaddr if the break could be set, otherwise it returns -1.
     Both brk and sbrk set errno if there is an error.

CAVEATS
     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 getrlimit.

SEE ALSO
     execve(2), getrlimit(2), end(3c), and malloc(3c).






































Printed 5/12/88                                                 2





































































%%index%%
na:216,88;
sy:304,1125;
de:1429,1805;
di:3234,650;4172,106;
rv:4278,532;
ca:4810,325;
se:5135,229;
%%index%%000000000132

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026