Reputation:
Every process running on a machine is given the illusion that it is the only process running on it. And every process has a text, data and a stack section.
However, I fail to understand why the stack address of every process starts off at the same address(assuming that no kernel patches are installed and Address randomization is disabled).
Could someone point me towards a few reading resources or explain why this happens?
Upvotes: 1
Views: 650
Reputation: 58762
This is not really an asm question, it depends on the operating system. For linux (which is open source, you know) look in fs/exec.c:
/*
* Place the stack at the largest stack address the architecture
* supports. Later, we'll move this to an appropriate place. We don't
* use STACK_TOP because that can depend on attributes which aren't
* configured yet.
*/
vma->vm_end = STACK_TOP_MAX;
And later:
stack_top = arch_align_stack(stack_top);
stack_top = PAGE_ALIGN(stack_top);
Randomization is done in arch_align_stack
.
Upvotes: 1
Reputation: 709
Because there's an actual address and its, I'm going to use "virtual," address. Like you said it's an illusion. The starting address isn't actually the same.
Upvotes: 1
Reputation: 93760
The heap grows up and the stack grows down, so on most operating systems the virtual space looks like:
Program text
Program data/bss
Heap
(dynamically grows up)
...
...
(dynamically growing down)
stack
Thus the location of the heap moves depending on the program size but the stack's starting space is not dependent on anything about the program.
Upvotes: 2