[comp.sys.ibm.pc] Changing stack size in a .EXE file

kevin@kosman.UUCP (Kevin O'Gorman) (11/25/89)

I have a need to enlarge the stack for an existing .EXE file.  I understand
that if I had any MS language, I would have EXEMOD.EXE, which does this
sort of thing.  Unfortunately, I don't and I don't.

The need arises because I have a *lot* of SET commands in AUTOEXEC.BAT,
setting up the environment for various tools that I use, and this silly
program loads the whole environment into the stack rather than extracting
what it needs.  Thus, I need to give it a bigger stack.

I have the feeling that this is pretty easy to do, and I'm comfortable
writing a program (in Turbo C) or doing binary patches by hand.  I just
don't know what to modify.  I can't quite convince myself that I understand
all the fields in the EXE header.

Could someone who understands these things enlighten me?

toma@tekgvs.LABS.TEK.COM (Tom Almy) (11/29/89)

In article <1026@kosman.UUCP> kevin@kosman.UUCP (Kevin O'Gorman) writes:
>I have a need to enlarge the stack for an existing .EXE file.  I understand
>that if I had any MS language, I would have EXEMOD.EXE, which does this
>sort of thing.  Unfortunately, I don't and I don't.
[...]
>Could someone who understands these things enlighten me?

Life is not simple, with or without EXEMOD. If the stack is located at
the end of the load module (as is the case with most programs, including
Microsoft compiled) then the word at displacement 10H into the EXE file
contains the initial SP value, which can be made larger, and the Minimum
number of paragraphs needed (and the maximum required, which much be 
larger) at offsets 0AH and 0CH respectively need to be inlarged as well.

Unfortunately (?) a number of compilers, including Borland Turbo C,
carve out their own stack at runtime. The size of the stack is given as
a compiler option, an initialized variable (the case with Turbo C), or
can be overridden at execution time on the command line (Zortech, Lattice).
In the last case, the fix is simple since you can invoke the program
specifying the stack size. In the other cases you are out of luck --
no ammount of header twiddling will change the size of the stack.


Tom Almy
toma@tekgvs.labs.tek.com
Standard Disclaimers Apply