views:

74

answers:

4

Are return address and data mixed/stored in the same stack, or in 2 different stacks, which is the case?

+2  A: 

They are mixed. However, it depends on the actual programming language / compiler. I can image a compiler allocating space for local variable on the heap and keeping a pointer to the storage on the stack.

There is one stack per thread in each process. Hence, for example, a process with 20 threads has 20 independent stacks.

Ondrej Tucny
A: 

It depends on the compiler, but the x86 architecture is geared towards a single stack, due to the way push and pop instructions work with a single stack pointer. The compiler would have to do more work maintaining more than one stack.

Mike Houston
+2  A: 

As others have already pointed out, it's mostly a single, mixed stack. I'll just add one minor detail: reasonably recent processors also have a small cache of return addresses that's stored in the processor itself, and this stores only return addresses, not other data. It's mostly invisible outside of faster execution though...

Jerry Coffin
A: 

On more note: every thread in Win32 has its own stack. So, when you tell "windows program" - it depends on how many threads it has. (Of course threads are created/exited during the runtime).

valdo