Re: Stack corruption and memory leak problems in c++/Fortran application



"Louis Krupp" <lkrupp@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:13iguknhfk3p80a@xxxxxxxxxxxxxxxxxxxxx

Fortran could be expecting a 4-byte string length as the last argument. On
a little-endian system like a PC, the string length is in the first four
bytes, so the subroutine sees the right value. However, when the
subroutine exits, it cuts back the stack as if the string length had used
only four bytes, and the high order four bytes of the string length are
being left on the stack. This could be why you're seeing increments of
four bytes of memory usage and an eventual stack overflow.

Whoah there, this is a case of the blind leading the blind. In 64-bit
Windows, the callee does not cut back the stack on exit. There is only
one convention, search for the file SWConventions.doc that got installed
on your hard disk, or http://www.agner.org/optimize/calling_conventions.pdf
or see if it's in the Programming with Mixed Languages chapter of Intel's
documentation set. The first four arguments are passed in registers,
and further arguments are passed on the stack. There is a 32-byte gap
on the stack between the return address and the first stack argument, and
the stack is aligned 8 mod 16 on procedure entry. All stack arguments take
up 8 bytes on the stack, otherwise the next argument would be misaligned.

If in doubt, disassemble caller and callee either via the debugger or
DUMPBIN /DISASM (equivalently LINK /DUMP /DISASM) and look at what the
two sides are actually doing.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


.



Relevant Pages

  • Re: Does MSIL Qualify?
    ... The term stack is not entirely to confuse with the x86 CPU stack. ... this is enough to determine it isnt asm. ... The way a string is stored could have a very significant impact on speed, ... If wolfgangs code on avarage is 16 times faster than other code then this means that his code can run on far slower software, and he will allways have years ahead of HLL developers because of this. ...
    (alt.lang.asm)
  • Problems with Search
    ... % then the matching string ... /MLinfo exch def % set to original ... string, still on the stack. ... prematch strcat ...
    (comp.lang.postscript)
  • Re: Problems with Search
    ... The ifelse removes the boolean and the two procedures from the stack ... % then the matching string ... /MLinfo exch def % set to original ... prematch strcat ...
    (comp.lang.postscript)
  • Re: HOWTO Implement LoadLibrary, GetProcAdress, and FreeLibrary.
    ... public static string Invoke(IntPtr IntPtr_Function, string csParam1, ... AssemblyName AssemblyName_This = new AssemblyName; ... // We must now push each paramter onto the stack. ... // We must now push the function pointer onto the stack. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Postscript problems
    ... dup 1 string readstring pop ... There are multiple references on stack to one and the same ... you were getting at 12 string cvs, but converted the integer 12 to a ... before re-using the conversion string. ...
    (comp.lang.postscript)