brk__sbrk

brk__sbrk

NAME
       brk, sbrk - change data segment size

SYNOPSIS
       #include <unistd.h>

       int brk(void *end_data_segment);

       void *sbrk(intptr_t increment);

DESCRIPTION
       brk()  sets the end of the data segment to the value specified by end_data_segment,
       when that value is reasonable, the system does have enough memory and  the  process
       does not exceed its max data size (see setrlimit(2)).

       sbrk() increments the program's data space by increment bytes.  sbrk() isn't a sys-
       tem call, it is just a C library wrapper.  Calling sbrk() with an  increment  of  0
       can be used to find the current location of the program break.

RETURN VALUE
       On  success,  brk()  returns zero, and sbrk() returns a pointer to the start of the
       new area.  On error, -1 is returned, and errno is set to ENOMEM.

CONFORMING TO
       4.3BSD

       brk() and sbrk() are not defined in the C Standard and  are  deliberately  excluded
       from the POSIX.1 standard (see paragraphs B.1.1.1.3 and B.8.3.3).

NOTES
       Various  systems  use  various  types for the parameter of sbrk().  Common are int,
       ssize_t, ptrdiff_t, intptr_t.  XPGv6 obsoletes this function.

SEE ALSO
       execve(2), getrlimit(2), malloc(3)

    The brk() and sbrk() functions are used to change the amount of memory
    allocated in a process's data segment. They do this by moving the loca-
    tion of the ``break''. The break is the first address after the end of  
    the process's uninitialized data segment (also known as the ``BSS'').


brk and sbrk设置的是BSS里的边界,具体什么是BSS呢
bss = "Block Started by Symbol" (由符号启始的区块)

Dennis Ritchie 曾说过:
这个缩写也许有其它说法,但事实上我们采用这个缩写的本意是
"Block Started by Symbol"。它是 FAP 上的伪指令,FAP
(Fortran Assembly [-er?] Program) 是指 IBM 704-709-7090-7094
这种机型的组译器。这个指令可定义自己的标号,并且预留一定数目
的字组空间。还有另一个伪指令 BES,是 "Block Ended by
Symbol",跟 BSS 指令几乎一样,不同点在于标号是定义在预留字组
空间尾端的地址 + 1 的地方。在这些机器上,Fortran 的数组是以反
方向储存,而且数组的索引是从 1 算起。

这种用法是合理的,因为这跟 UNIX 上标准的程序加载器一样,程序
码当中并非真的放入这一整块预留空间,而是先用一个数目表示,在
加载时才真的把所需的预留空间定出来。
from:
Linux man page and
http://www.linuxforum.net/forum/gshowflat.php?Cat=&Board=linuxK&Number=300677&page=16&view=collapsed&sb=5&o=all&fpart=

你可能感兴趣的:(brk__sbrk)