News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Defining a string size

Started by lonewolff, March 01, 2009, 09:13:34 AM

Previous topic - Next topic

BlackVortex

Reading through the GoLink manual I found these linker options and explanations :

Quote/stackinit xxxx
   = initial stack commitment on start-up and on new threads.
Here you can specify the size in bytes (using hex) of the amount of memory which the system should commit for the stack when the application starts or when making a new thread. If you do not use this switch a value of 10000h (64KB) is used by default. Regardless of the value specified using this switch the system always enlarges the amount of committed memory in the stack in 4K chunks as the application needs it.
This switch may be used if your application needs to create space for a large amount of local data. Without this switch an exception could occur if your local data is larger than 4K. The reason for this is that the system uses Structured Exception Handling to manage the enlargement of the stack as and when it is needed, and it does this by establishing guard pages just adjacent to and deeper into the area of stack already committed. If your application attempts to write or read from a place beyond these guard pages, a true exception will occur rather than a signal to the system to create more stack. In experiments the size of the guard pages seems to vary but it is unlikely that it could ever be below 4K which is the normal page size.

Quote/stacksize xxxx
   = stack allocation size on start-up or on new threads.
Here you can specify the size in bytes (using hex) of the area of memory which the system should allocate for potential stack use, should the application require it. If you do not use this switch a value of 100000h (1MB) is used by default. At start-up the system merely allocates space in virtual memory and only a small amount is committed at first. The system commits the remainder automatically in 4K chunks if the application needs it.
The value given with this switch applies both to the main thread of the application and also any new threads it makes.
This switch may be used if your application might need more than 1MB of stack space. Specifying more than 1MB does not use memory unnecessarily since the memory is only committed if it is actually used. Normally 1MB is more than sufficient for the stack, but you would need this switch if you were keeping large amounts of local data on the stack in procedures which were highly recursive.

MichaelW

JJ,

I was trying to show that in answer to "how much data can be defined on the stack for a proc before there is a stack overflow", 4096 is not correct, but as it turns out my memory of this was bad. The default commit size for the Microsoft linker appears to be 4096 bytes (and the reserve 1MB), and the (old) code I posted works because it is accessing in byte increments.

It looks to me like your code is trying to access beyond the end of your stack data, a somewhat different problem.

eschew obfuscation

jj2007

Quote from: MichaelW on April 01, 2009, 07:14:28 PM
JJ,

It looks to me like your code is trying to access beyond the end of your stack data, a somewhat different problem.


Michael,
Thanks. Yes, it had originally another purpose (I simply wanted to see how exactly those LOCALS work...).

Please have a look at the edits I added to my last post, and the revised code. It appears that 3*4096 is the "allowed" size. Don't ask me why :bg

farrier

You can define a "large" amount of data on the stack as locals, as long as you do not cross the "guard page" boundaries by more than one page.  See the link and the entire thread at:

http://www.masm32.com/board/index.php?topic=2011.msg17056#msg17056

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)