开发者

Getting the start address of the current process's heap?

I am exploring the lower level workings of th开发者_Go百科e system, and was wondering how malloc determines the start address of the heap. Is the heap at a constant offset or is there a call of some sort to get the start address? Does the stack affect the start address of the heap?


sbrk returns the start address of the bytes it adds (or removes). In a fresh process with no heap allocated yet, the first call to sbrk should then return the start address of the "break" section of the heap. If I had to bet, that's what malloc implementations which use brk/sbrk probably do on their first run.


Traditionally, the heap started just above the text section and grew up; stack frames didn't affect start address at all as they grow down towards the unmapped 0 page. However, it's more common these days for

  1. The first address to be randomized, to make it harder for exploits to hit the right address in memory
  2. The heap to be non-contiguous, as malloc() usually just calls mmap() to get an address anywhere in the virtual address space
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜