I'm just curious if there is an idiomatic way to allocate a know only at runtime amount of space on the stack that is stack frame safe?
Posted on 2004-04-19 10:59:35 by ThoughtCriminal
"sub esp, eax"? :) No problem with this if you use a EBP stack frame (and no problems without it either, if you don't need proc arguments after you allocate the space).

Just remember to do page pretouching if you allocate large amounts, or you risk GPFs if you access the data in a random order (because of the use of guard pages and all that).
Posted on 2004-04-19 11:22:55 by f0dder
Page guard issue is relating to fs:[4] and fs:[8] IIRC
Posted on 2004-04-19 11:27:09 by roticv
If you want to allocate space on the stack for parameters, local variables, and register saves, then look at the ziped example given in the last part of the thread http://www.masmforum.com/viewtopic.php?t=2449&start=15 . Ratch
Posted on 2004-04-19 12:34:37 by Ratch
roticv, those fields are the min+max allowable ESP limits, stack guarding is the process of automatically committing reserved memory through the use of the page guard mechanism (phew :p).
Posted on 2004-04-19 13:30:19 by f0dder
Posted on 2004-04-19 15:05:33 by Thomas
Posted on 2004-04-19 17:53:41 by f0dder

I was only thinking of small allocations. But more info the better :)
Posted on 2004-04-20 09:48:45 by ThoughtCriminal
Another roundabout way of doing this would be using CreateThread and setting the dwStackSize paramter. I'm sure this is much less efficient than the stack probing. The only benefit I see for using CreateThread is that when the thread terminates, the committed stack space for the thread gets freed.
Posted on 2004-04-20 22:23:03 by Mecurius