Stack overflow exception in Windows Mobile 6 Professional emulator

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




I am running into a stack overflow exception while testing a .NET
application that talks to unmanaged C code via a P/Invoke layer (it
runs on Windows Mobile 6.0 professional **emulator**). I have reached
a point where my skillsets aren't deep enough to look at CPU registers/
assembly and see if the stack or frame pointers are looking funny.

The stack overflow occurs when the unmanaged code tries to spawn a
worker thread from inside another worker thread (using the
CreateThread Win32 API). So:

void SomeThread(void* threadArg)
{
// lot of blah
// CreateThread(AnotherThread, .......);
WaitForAnotherThreadToInitialize(5000); // 5 seconds
}

void AnotherThread(void* threadArg)
{
// declare local variables
// KABOOM here...
}

Before the CreateThread API is called, the registers look like this
inside SomeThread:

R0 = 0x00000001 R1 = 0x00000002 R2 = 0x00000010 R3 = 0x00000001
R4 = 0x0122bd10 R5 = 0x1e06f560 R6 = 0x88044520 R7 = 0x88046d24
R8 = 0x00000000 R9 = 0x80000004 R10 = 0x00000001 R11 = 0x00499930
R12 = 0x03f65770 Sp = 0x1e5cfc8c Lr = 0x01221900 Pc = 0x012219e0
Psr = 0x20000010

When, the stack overflow occurs in AnotherThread and debugger breaks
into it, here is what the registers look like:

R0 = 0x01482130 R1 = 0x00000000 R2 = 0x1627a107 R3 = 0x00000000
R4 = 0x012259a8 R5 = 0x01482130 R6 = 0x88044520 R7 = 0x88046d24
R8 = 0x00000000 R9 = 0x80000004 R10 = 0x00000001 R11 = 0x16153a9e
R12 = 0x1e5eeed0 Sp = 0x1e5e0ed0 Lr = 0x03f6b334 Pc = 0x01225ed4
Psr = 0x80000010

In addition the output window logs this:

[Stack fault]: Thread=96edd000 Proc=80096f40 'TestMobile.exe'
AKY=00004001 PC=01225ed4(unmanagedCode.dll+0x00005ed4) RA=03f6b334
(coredll.dll+0x0001d334) BVA=1e5e0ea4 FSR=00000407
First-chance exception at 0x01225ed4 in TestMobile.exe: 0xC00000FD:
Stack overflow.

I have been banging my head on this for a week and not making any
progress.

Can anyone see anything funny in the above data? Is there any other
approach I can take?


.



Relevant Pages

  • [Full-Disclosure] To anybody whos offended by my disclosure policy
    ... MSIE IFRAME bufferoverflow: ... MSIE nested array sortloop Stack overflow exception: ... My disclosure policy: ... PS. Recursive function call will cause stack overflow causing write exception in guard page on a push, no control over registers: ...
    (Full-Disclosure)
  • Re: Stack Overflow
    ... EW> The code almost completes when it throws a stack overflow exception. ... If I understand correctly data is stored in the buffer. ... Then data is piling up in the heap not in the stack... ...
    (microsoft.public.dotnet.general)
  • Re: WindowsError: stack overflow
    ... > I can get through about 1750 pages of 5000 before I get a WindowsError: ... > stack overflow exception. ... A typical source of stack overflow is recursion. ...
    (comp.lang.python)
  • Re: how to find what kills D2007
    ... the stack overflow exception EStackOverflow is caught by the debugger. ... Running the executable directly from the explorer I get the Stack Overflow dialog I described previously. ...
    (borland.public.delphi.non-technical)