Archives
- October 2025
- September 2025
- August 2025
- July 2025
- June 2025
- May 2025
- April 2025
- March 2025
- February 2025
- January 2025
- December 2024
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- March 2021
- February 2021
- January 2021
- December 2020
- November 2020
- October 2020
- September 2020
- August 2020
- July 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- January 2011
- November 2010
- October 2010
- August 2010
- July 2010
AVX support disrupts WoW64 debugging
Sometimes, the old and the new intersect in unexpected ways. After upgrading to a Sandy Bridge based system (Core i7) and Windows 7 SP1 64-bit some time ago, I noticed that debugging exceptions in 32-bit user programs didn’t quite work right. Recently the issue has been brought to my attention again and I had to do some digging.
The symptom of the problem is that when a debugger stops on a second chance exception, the context of the (32-bit) process being debugged is damaged and the debugger stops in a bogus location, namely ZwRaiseException or NtRaiseException (same thing with two different names). That is a huge problem when the debugged process handles certain exceptions. The debugger can’t stop on every first chance exception, because those occur in the normal flow of execution. Yet if a real bug pops up and causes an unhandled exception, the debugger will not show where the problem is!
The issue is 100% reproducible… but only on some systems. The ingredients are: 64-bit Windows 7 SP1, a 32-bit process being debugged, and a recent CPU. The process doesn’t matter, the type of exception doesn’t matter, the debugger doesn’t matter (both 64-bit and 32-bit debuggers are affected). Software installed on the system doesn’t matter beyond the base OS.
Problem
A log of a short debugging session with WinDbg/NTSD illustrates the problem:
(7b8.4d4): WOW64 breakpoint - code 4000001f (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. ntdll32!LdrpDoDebuggerBreak+0x2c: 77000fab cc int 3 0:000:x86> g (7b8.4d4): Integer divide-by-zero - code c0000094 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. *** WARNING: Unable to verify checksum for crashm.exe crashm!main+0x10: 00401020 f7f9 idiv eax,ecx <----- correct 0:000:x86> k ChildEBP RetAddr 0018ff48 004010e5 crashm!main+0x10 [crash.c @ 7] 0018ff88 75dd339a crashm!mainCRTStartup+0xb4 0018ff94 76f99ef2 kernel32!BaseThreadInitThunk+0xe 0018ffd4 76f99ec5 ntdll32!__RtlUserThreadStart+0x70 0018ffec 00000000 ntdll32!_RtlUserThreadStart+0x1b 0:000:x86> g (7b8.4d4): Integer divide-by-zero - code c0000094 (!!! second chance !!!) ntdll32!ZwRaiseException+0x12: 76f815de 83c404 add esp,4 <----- wrong 0:000:x86> k ChildEBP RetAddr 0018fa7c 76f7014d ntdll32!ZwRaiseException+0x12 0018fa8c c0000094 ntdll32!KiUserExceptionDispatcher+0x29 WARNING: Frame IP not in any known module. Following frames may be wrong. 0018ff48 004010e5 0xc0000094 0018ff88 75dd339a crashm!mainCRTStartup+0xb4 0018ff94 76f99ef2 kernel32!BaseThreadInitThunk+0xe 0018ffd4 76f99ec5 ntdll32!__RtlUserThreadStart+0x70 0018ffec 00000000 ntdll32!_RtlUserThreadStart+0x1b 0:000:x86> g (7b8.4d4): Unknown exception - code 00000000 (first chance) (7b8.4d4): Unknown exception - code 00000000 (!!! second chance !!!) ntdll32!ZwRaiseException+0x12: 76f815de 83c404 add esp,4 0:000:x86> g WARNING: Continuing a non-continuable exception (7b8.4d4): Unknown exception - code 00000000 (first chance) (7b8.4d4): Unknown exception - code 00000000 (!!! second chance !!!) ntdll32!ZwRaiseException+0x12: 76f815de 83c404 add esp,4
The first chance exception is reported correctly, but as mentioned earlier, stopping on first chance exceptions may not be feasible. The second chance exception is erroneously reported in ZwRaiseException, which is completely bogus. The stack is damaged enough that execution cannot be continued at all, which compounds the problem.
It’s worth pointing out that on the damaged stack, the first bogus frame (going from bottom to top as printed) shows the location as 0xC0000094. That certainly does not look like a valid address, but it looks exactly like the exception code of a division by zero. If ever something looked like a coincidence… this is not it.
Yet that only shows Windows is doing something wrong, not what or why.
For reference, this was the test program:
#include <stdio.h>
int main( int argc, char **argv )
{
int i;
i = 33 / (argc - 1);
return( i );
}
The testcase was written in a slightly convoluted way to defeat compiler optimizations and ensure a division error will happen at run-time.
The compiler and linker used doesn’t matter, and the bug can be reproduced with a tiny assembler program as well.
Clues
While investigating the problem, I naturally tried to reproduce it in a VM, as it would have been easier to analyze the issue in a virtual environment. But… the problem didn’t happen in a VM. The Windows 7 version was exactly the same, the host CPU was the same, the software used was the same. But what failed on the host stubbornly worked in a VM, no matter how the host and guest were configured (memory size, number of CPUs, etc.).
I knew that was a clue, but couldn’t interpret it. One possibility was that virtualization masked some new-fangled CPU feature and that hid the problem. That could explain why the bug showed up on Intel Core i7 and i5 systems, but not Intel Core 2 or AMD Phenom machines.
A few days later, a coworker mentioned in passing that the AVX instruction set requires a larger memory area to save the state. That got me wondering, because in earlier investigation I noticed that on the broken systems, there seemed to be more data on the exception stack.
Microsoft documents that AVX is indeed supported and enabled by default on Windows 7 SP1. AVX state is indeed saved when exceptions are dispatched. Hmm, could that be it?
To confirm or disprove the theory, I’d need a way to disable AVX. That cannot be done in the system’s BIOS. But hey… Microsoft documents how to disable AVX in Windows as a workaround for a completely unrelated problem. The xsavedisable switch is not properly documented, but maybe it works…
Solution
I executed
bcdedit /set xsavedisable 1
from an elevated command prompt and rebooted the system. Re-ran the debugger testcase and lo and behold, now exception handling works properly!
The problem is definitely a bug in Windows 7 SP1 on AVX-enabled systems; however, it seems to be specific to the debug support in the WoW64 component. A 32-bit version of Windows 7 SP1 behaves correctly, and so does debugging of 64-bit processes. A 32-bit process can handle its own exceptions correctly when running under WoW64, it’s only when a 32-bit process is run under a debugger within WoW64 that trouble strikes.
I can only guess that with AVX on, the kernel saves AVX context on the exception stack in the user process (after continuing a first chance exception), but WoW64 does not expect the additional data when a debugger is attached and messes up the stack. That of course does no good and the user process is toast.
For now, disabling AVX is an acceptable workaround for me. Hopefully the bug will be eventually fixed and it will be possible to both use AVX and debug 32-bit processes properly.
18 Responses to AVX support disrupts WoW64 debugging
Hi,
Not related to this post, but when do you continue DOS history?
When I’m happy with what I’ve researched and written π
Thank you so much, you’ve just saved my work a lot (more) trouble trying to figure out why we can’t debug crashes on our new PC’s.
Have you submitted this as a bug report to Microsoft?
I submitted an informal report which did get to the right people, but I don’t know if and when a fix might be forthcoming.
Thank you for this timely information! It has saved me a lot of frustration.
I have a similar setup to you (Win7 SP1 64-bit on Core i7) but I’m not able to reproduce this issue. I do, however often get minidumps from clients in which the excepting thread’s callstack unwinds to ZwRaiseException. Any word on if MS has patched in a fix for this (just wondering since you said you submitted an informal report). Working on the assumption that perhaps I have the patch but some users do not…
I don’t think there’s a patch available and I haven’t heard from Microsoft. Maybe I need to retry and see if the problem is still there…
I believe the problem should be reproducible on any AVX system, assuming AVX is enabled. And of course only for 32-bit processes.
From what I can tell, there are many other reasons for getting a crash in ZwRaiseException though.
I wonder if that’s the same thing as described here: GetThreadContext() may return stale contents
No, definitely a different problem. What the link describes has nothing to do with AVX, while what I ran into is specific to systems with AVX support.
Pingback: When Even Crashing Doesn’t Work | Random ASCII
Pingback: Are you still there? | Windows Live space
michaln you are cool Cool COOL!
This issue has been driving me insane on my new FX machine…
This post should sort to the top on Google for “zwraiseexception” but it doesn’t and a month ago I ignored it anyway due to the “OS/2 Museum”.
Confoundingly VS2010 & 12 didn’t exhibit this sitting on the zwraiseexception, which hastened my port from Open watcom to VC++ but it kept bugging me!
I believe the Visual Studio debuggers tend to intercept first chance exceptions or don’t intercept the exception at all. In fact this is probably the #1 reason why the bug even crept in. I didn’t analyze Visual Studio (since I don’t use it), but WinDbg is definitely affected.
Do you have done any explicit tests wrt. to the behaviour of the MiniDumpWriteDump function? Does it work properly? You seem to imply so: “… A 32-bit process can handle its own exceptions correctly when running under WoW64, itβs only when a 32-bit process is run under a debugger within WoW64 that trouble strikes …”
I have found the following, but am unsure whether that holds always:
* MiniDumpWriteDump works from within the global UHEF (installed by SetUnhandledExceptionFilter) in the same process
* MiniDumpWriteDump works from another process also (say when I spawn another process from my UHEF and invoke it on the crashed process)
* I tried with SysInternals’ procdump.exe tool and the -e switch – and the dump generated this way has a messed-up stack — I guess this would be due to the fact that procdump.exe attaches as a debugger to the [-e]-monitored process.
Sorry, I didn’t do any experiments with MiniDumpWriteDump. But what you said would be consistent with my observations.
Pingback: Should This Windows 7 Bug be Fixed? | Random ASCII
See https://connect.microsoft.com/VisualStudio/feedback/details/782228/debugger-shows-zwraiseexception-in-callstack-on-exception#tabs for a bug report. Feel free to upvote the issue if it concerns you.
Looks like a hotfix has been issued:
http://support.microsoft.com/kb/2864432
This site uses Akismet to reduce spam. Learn how your comment data is processed.