1
0

brk 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. .TH BRK 2
  2. .SH NAME
  3. brk, sbrk \- change memory allocation
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .ta \w'\fLvoid* 'u
  10. .B
  11. int brk(void *addr)
  12. .PP
  13. .B
  14. void* sbrk(ulong incr)
  15. .SH DESCRIPTION
  16. .I Brk
  17. sets the system's idea of the lowest bss location not used by the program
  18. (called the break)
  19. to
  20. .I addr
  21. rounded up to the next multiple of 8 bytes.
  22. Locations not less than
  23. .I addr
  24. and below the stack pointer
  25. may cause a memory violation if accessed.
  26. .PP
  27. In the alternate function
  28. .IR sbrk ,
  29. .I incr
  30. more bytes are added to the
  31. program's data space and a pointer to the
  32. start of the new area is returned.
  33. Rounding occurs as with
  34. .IR brk .
  35. .PP
  36. When a program begins execution via
  37. .I exec
  38. the break is set at the
  39. highest location defined by the program
  40. and data storage areas.
  41. Ordinarily, therefore, only programs with growing
  42. data areas need to use
  43. .IR brk .
  44. A call to
  45. .I sbrk
  46. with a zero argument returns the lowest address
  47. in the dynamic segment.
  48. .SH SOURCE
  49. .B /sys/src/libc/9sys/sbrk.c
  50. .SH SEE ALSO
  51. .IR intro (2),
  52. .IR malloc (2),
  53. .IR segattach (2),
  54. .IR segbrk (2)
  55. .SH DIAGNOSTICS
  56. These functions set
  57. .IR errstr .
  58. .PP
  59. The error return from
  60. .I sbrk
  61. is
  62. .BR (void*)-1 .