madExcept crashes when run inside IIS Express.

delphi package - automated exception handling
Post Reply
wpostma
Posts: 23
Joined: Fri Oct 12, 2012 4:09 pm

madExcept crashes when run inside IIS Express.

Post by wpostma »

I am trying to debug a Delphi ISAPI DLL which in production has been working fine with full IIS (w3wp.exe).

However if I run from IIS Express (32 bit) with a 32 bit ISAPI DLL, and madexcept is enabled in my dll, I get an access violation/crash at startup with this callstack, in the context of

Code: Select all

function InterceptServerSupportFunction(hConn, request: dword; buf, size, dataType: PAnsiChar) : bool; stdcall;   // intercept the ISAPI function "ServerSupportFunction"

First chance exception at $77EBF2A3. Exception class $C0000005 with message 'access violation at 0x77ebf2a3: write of address 0x00000004'. Process iisexpress.exe (14680)

    ecb2^.ServerSupportFunction := InterceptServerSupportFunction;
    >EnterCriticalSection(IRSection^);


:77ebf2a3 ntdll.RtlEnterCriticalSection + 0x13
madExcept.InterceptHttpExtensionProc($CC2904)
:5020a842 ; C:\Program Files (x86)\IIS Express\isapi.dll
:50211707 ; C:\Program Files (x86)\IIS Express\isapi.dll
:50209659 ; C:\Program Files (x86)\IIS Express\isapi.dll
:502099e7 ; C:\Program Files (x86)\IIS Express\isapi.dll
:50786ee4 ; C:\Program Files (x86)\IIS Express\iiscore.dll
:50786133 ; C:\Program Files (x86)\IIS Express\iiscore.dll
:50774f54 ; C:\Program Files (x86)\IIS Express\iiscore.dll
:50787b5e ; C:\Program Files (x86)\IIS Express\iiscore.dll
:50787526 ; C:\Program Files (x86)\IIS Express\iiscore.dll
:5077979d ; C:\Program Files (x86)\IIS Express\iiscore.dll
:50779d6f ; C:\Program Files (x86)\IIS Express\iiscore.dll
:5d376c11 ; C:\Program Files (x86)\IIS Express\w3dt.dll
:5d377a9b ; C:\Program Files (x86)\IIS Express\w3dt.dll
:5d37614a ; C:\Program Files (x86)\IIS Express\w3dt.dll
:5d0d30be ; C:\Program Files (x86)\IIS Express\W3TP.dll
:5d0d2fcb W3TP.?PostCompletion@THREAD_POOL@@QAEHKP6GXKKPAU_OVERLAPPED@@@Z0@Z + 0x5b
:5d0d1ed7 ; C:\Program Files (x86)\IIS Express\W3TP.dll
:767338f4 KERNEL32.BaseThreadInitThunk + 0x24
:77ee5663 ;

I can work around this for now, because I only need IIS Express in development and I can turn MadExcept off. If this is unexpected, and this SHOULD WORK with IIS Express, I will try to create a self-contained project giving an example of this behaviour if desired.

Warren
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: madExcept crashes when run inside IIS Express.

Post by madshi »

Ugh, I absolutely hate ISAPI stuff, it's so hard for me to reproduce and debug.

So the crash occurs when calling EnterCriticalSection? Can you check if IRSection is maybe "nil" or something? There's some code in madExcept like "InitializeCriticalSection(IRSection^)". Can you check whether that gets executed?
wpostma
Posts: 23
Joined: Fri Oct 12, 2012 4:09 pm

Re: madExcept crashes when run inside IIS Express.

Post by wpostma »

Yes, IRSection is nil, and so the EnterCriticalSection fails.

Okay it seems that I had a case where mySettings.Enabled = False. In such a case, this crash occurs.

May I suggest that you either simply EXIT if mySettings.Enabled=false from InterceptHttpExtensionProc, or avoid hooking it at all, in that case?

W
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: madExcept crashes when run inside IIS Express.

Post by madshi »

Hmmmm... Does the problem go away if you add this code at the very start of InterceptHttpExtensionProc?

Code: Select all

if not MESettings.Enabled then
begin
  result := HttpExtensionProcNext(ecb);
  exit;
end;
Post Reply