Hi,
I have lived with with assumption that failed asserts in the kernel
mode cause BSODs when a checked version of a driver is running on a
system which is NOT running in DEBUG mode. Threads
http://www.osronline.com/showThread.cfm?link=169579 and
http://www.osronline.com/showThread.cfm?link=153733 made my assumption
even stronger.
However a recent bug has shaken this assumption. It seemed that failed
ASSERTs were NOT causing BSODs on my test Win 7 RTM (x86) machine.
I have checked WDK docs and have googled a fair bit but didn’t find
any strong statement that ASSERTs should cause BSODs, so I have
resorted to a debugger. As you probably know ASSERT calls RtlAssert()
when the condition is false, so I disassembled the latter. To my
surprise it seems that after printing assertion message (using
DbgPrint) RtlAssert checks fixed place in memory (FFDF02D4h) to see
whether it contains 3, and quits if it doesn’t:
82b0bb42 a0d402dfff mov al,byte ptr ds:[FFDF02D4h]
82b0bb47 2403 and al,3
82b0bb49 83c41c add esp,1Ch
82b0bb4c 3c03 cmp al,3
82b0bb4e 0f858d000000 jne nt!RtlAssert+0xf9 (82b0bbe1)
…
nt!RtlAssert+0xf9:
156 82b0bbe1 8b4dfc mov ecx,dword ptr [ebp-4]
156 82b0bbe4 5f pop edi
156 82b0bbe5 5e pop esi
156 82b0bbe6 33cd xor ecx,ebp
156 82b0bbe8 5b pop ebx
156 82b0bbe9 e8da28f7ff call nt!__security_check_cookie (82a7e4c8)
156 82b0bbee c9 leave
156 82b0bbef c21000 ret 10h
So if FFDF02D4h contains something else than 3 no ‘BSOD making’ call
is made. With some experimenting it seems that FFDF02D4 is set to 1
when the system is running in DEBUG mode and to 3 if it is running in
DEBUG mode and a debugger is attached to it.
When I replace a failing ASSERT with a failing NT_ASSERT then I get a
nice BSOD exactly as I would expect.
I was wondering whether one of you might know an answer to some/all of
the following questions:
- What am I missing?
- Has implementation of RtlAssert been changed between XP and Vista
(RtlAssert on Vista looks very like the RtlAssert on Win7 shown
above)? - Is there any way to tell the OS that I want ASSERTs to result in
BSODs? I.e. how can I influence FFDF02D4h without a debugger. I would
like to have our system test run with version of drivers which BSOD
when a false assertion is hit. (I know I can write my own assert
macros, but I wonder whether there is any out-of-the-box way). - NT_ASSERT is not documented. Is that an omission or does MS wants
people to use only ASSERTs?
Thanks a lot for your help.
Take care,
Rafal