Subject: Re: sbrk() semantics ....
To: Andrew Cagney <cagney@highland.com.au>
From: Chris G Demetriou <Chris_G_Demetriou@LAGAVULIN.PDL.CS.CMU.EDU>
List: tech-kern
Date: 03/09/1995 19:52:36
> Below is what I understand to be the semantics of sbrk.  Firstly is this
> correct and secondly should the manual page reflect this (the copy I had
> didn't :-).
> 
> 	sbrk(invalid-arg)	return -1
> 	sbrk(0)		return `curbrk'  -- current break
> 	sbrk(N)		tmp = `curbrk', `curbrk' = tmp + N, return tmp

to quote the current manual page:

DESCRIPTION
     The brk and sbrk functions are historical curiosities left over from ear-
     lier days before the advent of virtual memory management.   The brk()
     function sets the break or lowest address of a process's data segment
     (uninitialized data) to addr (immediately above bss).  Data addressing is
     restricted between addr and the lowest stack pointer to the stack seg-
     ment.  Memory is allocated by brk in page size pieces; if addr is not
     evenly divisible by the system page size, it is increased to the next
     page boundary.

     The current value of the program break is reliably returned by
     ``sbrk(0)'' (see also end(3)).  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.  ``qetext + rlp->rlim_max.'' (see end(3) for
     the definition of etext).

RETURN VALUES
     Brk returns a pointer to the new end of memory if successful; otherwise
     -1 with errno set to indicate why the allocation failed.  The sbrk func-
     tion returns a pointer to the base of the new storage if successful; oth-
     erwise -1 with errno set to indicate why the allocation failed.


unless i'm mistaken (or just blind 8-), that documents it correctly...



chris