[Gc] Re: WOW64 bug: GetThreadContext() may return stale contents

Johannes Totz jtotz at imperial.ac.uk
Tue Dec 28 11:22:09 PST 2010


Maybe a warning for the developer is appropriate?

-------------- next part --------------
# HG changeset patch
# User jtotz at ic.ac.uk
# Date 1292903539 0
# Node ID 51f8c8179ecfb377f9f4612523964e075fecf88b
# Parent  eeae26f5449fed2805489da4c08e26ff412121cc
warning message when running under wow64
wow64 has a design flaw that make thread contexts invalid thus breaking the gc

diff -r eeae26f5449f -r 51f8c8179ecf win32_threads.c
--- a/win32_threads.c	Fri Oct 22 14:58:44 2010 +0100
+++ b/win32_threads.c	Tue Dec 21 03:52:19 2010 +0000
@@ -2571,6 +2571,33 @@
 #     endif
       static int entry_count = 0;
 
+#ifdef GC_DEBUG
+#ifndef _WIN64
+	  if (reason == DLL_PROCESS_ATTACH)
+	  {
+			// wow64: running 32-bit-gc on 64-bit-sys is broken!
+			// code copied from msdn docs example
+			typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
+			LPFN_ISWOW64PROCESS fnIsWow64Process = 0;
+			fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandleA("kernel32"), "IsWow64Process");
+			if (NULL != fnIsWow64Process)
+			{
+				BOOL bIsWow64 = FALSE;
+				if (fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
+				{
+					if (bIsWow64)
+						MessageBoxA(NULL, 
+							"This program uses the BDWGC garbage collector compiled for 32-bit "
+							"but running on a 64-bit version of Windows.\n"
+							"This is known to be broken due to a design flaw in Windows itself! Expect erratic behaviour...", 
+							"32-bit program running on 64-bit system", 
+							MB_ICONWARNING | MB_OK);
+				}
+			}
+	  }
+#endif
+#endif
+
 	  // despite the comment above
 	  //  this seems to work fine...
 	  GC_use_DllMain();


More information about the Gc mailing list