Johnny Pauling
Johnny Pauling

Reputation: 13437

Clarification on stack memory - where is it?

As far as I know, stack isn't a PE section mapped memory (i.e. it's not mapped into a PE win32 section).

My question is: where does the stack memory reside? Where does the operating system put it?

Does the operating system allocate a page of memory for the stack when a process is started and change the ESP register value to that page before jumping to the process' code? I'm kind of confused..

Upvotes: 1

Views: 74

Answers (1)

David Heffernan
David Heffernan

Reputation: 613491

The operating system puts it wherever it can find some free space in the virtual address space. It is not part of the PE file.

There is a single virtual address space for each process. The modules are loaded into that address space. The heap is created in that address space. And so is the stack.

For an unmanaged process, the OS reserves the entire stack allocation for a new thread, and then commits the memory on demand. Managed .net processes have a different policy. They commit and reserve the entire stack allocation when each thread is created.

Upvotes: 2

Related Questions