2

I just read that windows programs call _alloca on function entry to grow the stack if they need more than 4k on the stack. I guss that every time the guard page is hit windows allocates a new page for the stack, therefore _alloca accesses the stack in 4k steps to allocate the space.

I also read that this only applies to windows. How does linux (or other oses) solve this problem if they don't need _alloca?

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Jochen_0x90h
  • 311
  • 3
  • 5

1 Answers1

1

Linux relies on a heavily optimized page fault handling, so what happens is that the program just pushes things on the stack and the page fault handler will extend the stack on the fly.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • so are holes in the stack allowed? seems logical to do it this way. what are the reasons for windows to use _alloca? – Jochen_0x90h Jul 21 '11 at 14:55
  • No, the virtual stack is without holes. The real pages in RAM are scattered, of course. `_alloca` is probably a bit faster when its needed but it's wasted when the stack is big enough. – Aaron Digulla Jul 21 '11 at 15:39
  • That's not what is meant by holes in the stack -- it means unmapped pages between two mapped pages. – Jimmy Hartzell May 18 '16 at 19:58