64-bit Insider
Volume I, Issue 5
The 64-bit Advantage
The computer industry is chang-
The WOW64:
ing, and 64-bit technology is the
next, inevitable step. The 64-bit
File System Redirection, Part 1
Insider newsletter will help you
adopt this technology by provid- Before you embrace 64-bit technology, you must consider what
ing tips and tricks for a successful you will do with existing 32-bit applications. It’s highly unlikely
port. that any company will migrate all of its server applications at
Development and migration of 64-
once. In addition, consumers gradually will adopt 64-bit tech-
bit technology is not as compli- nology; hence, 32-bit applications will continue to be available
cated as the 16-bit to 32-bit transi- in the future.
tion. However, as with any new
technology, several areas do re-
Therefore, as companies adopt 64-bit technology, they must
quire close examination and con- still have the ability to run 32-bit applications. One of the
sideration. The goal of the 64-bit major functionalities that allows 32- and 64-bit application
Insider newsletter is to identify to coexist is file system redirection.
potential migration issues and
provide viable, effective solutions In this article, we will examine how the file system redirec-
to these issues. With a plethora of tor transparently handles 32-bit applications.
Web sites already focused on 64-
bit technology, the intention of
this newsletter is not to repeat
previously published information.
Instead, it will focus on 64-bit
issues that are somewhat isolated
yet extremely important to under-
stand. It will also connect you to
reports and findings from 64-bit
experts.
64-bit Insider Newsletter
Volume 1, Issue 3
Page 1/6
File System Redirection
On 64-bit Windows, there are a number of dynami-
cally linked libraries (DLLs) that are available for
both 32-bit and 64-bit applications. Most of these
libraries have the same name. Consequently, to
coexist, these DLLs need to be located in different
directories. Today, there are two system folders on
Microsoft Windows that are used for most system
DLL’s:
• %windir%\system32, which stores 64-bit application components.
• %windir%\SysWOW64, which stores 32-bit application components
and libraries.
By default, file system redirection for the WOW64
folder is enabled. This means that any 32-bit
“... it is possible to disable
application will be transparently redirected to the
file system redirection for a
SysWOW64 directory any time that it tries to access
specific thread when and if
the system32 directory. It is possible to disable file
you must access the native
system redirection for a specific thread when you must
64-bit system directory...”
access the native 64-bit system directory (system32)
from a 32-bit processor. However, it is extremely im-
portant to turn file system redirection back on once the
direct access is no longer required.
While the need to turn off file system redirection is not common, there are some cases
when it is necessary. For example, if you use a file system indexer or a 32-bit installer
that requires you to install libraries in the 64-bit System32 folder.
There are two APIs that enable and disable file system redirection:
• Wow64DisableWow64FsRedirection disables file system redirection for the
calling thread. File system redirection is enabled by default.
• Wow64RevertWow64FsRedirection restores file system redirection for the call-
ing thread.
The following code demonstrates how these functions can be used:
64-bit Insider Newsletter
Volume 1, Issue 3
Page 2/6
#define _WIN32_WINNT 0x0501
#include <windows.h>
PVOID OldValue;
HANDLE hFile;
BOOL bRet = Wow64DisableWow64FsRedirection (&OldValue);
if (bRet == TRUE)
{
// Open a file
hFile = CreateFile(...);
// Restore previous WOW64 file system redirection value.
Wow64RevertWow64FsRedirection (OldValue);
}
if( INVALID_HANDLE_VALUE != hFile )
{
// Use the file handle
}
In order to use these functions, it is necessary to define the _WIN32_WINNT macro as
0x0501 or later. Also, OldValue is used to store the previous WOW64 system redirection
value. You need to obtain this value when you disable file system redirection, and then
store it and pass it back when you turn file system redirection back on.
Please remember that disabling file system redirection works only for the current thread.
There is no global way to turn off file system redirection.
Redirecting the System32 Folder
When a 32-bit application executes inside When a 32-bit application
WOW64, it executes the same as it would if executes inside WOW64, it
running on a 32-bit processor. Any access from a executes the same as it would
32-bit application to System32 will be redirected if running on a 32-bit proces-
silently to SysWOW64. Therefore, the WOW64 sor.
makes it transparent for 32-bit applications to run
on 64-bit Windows.
The following example uses notepad.exe to demonstrate a very simple test that shows
how the WOW64’s file system redirection works.
Most 32-bit libraries and applications have been ported to a 64-bit platform. Even though
these binaries are 64-bit, they are still being stored in the System32 folder. Notepad is one
of them.
For our test, we will open the 64-bit version of notepad.exe using the Run window. We
will also open, by using the same method, the 32-bit Notepad version located in the
SysWOW64 folder. Please observe the difference in folder name where Notepad is lo-
cated.
64-bit Insider Newsletter
Volume 1, Issue 3
Page 3/6
Figure 1 Launch of 32-bit Notepad (left) and 64-bit (right)
To differentiate the contents of each file, we type a different message on each window.
Figure 2 Text to be saved with 64-bit Notepad
Figure 3 Text to be saved with 32-bit Notepad
Next, we save the file. In both windows, we type C:\Windows\system32 as the save lo-
cation. The only difference is the filename given to the file. We will use myfile32 for the
32-bit file and myfile64 for the 64-bit one.
Figure 4 Path to save with 64-bit Notepad
64-bit Insider Newsletter
Volume 1, Issue 3
Page 4/6
Figure 5 Path to save with 32-bit Notepad
On the 32-bit version of Notepad, as soon as the Save button is clicked, file system redi-
rection comes into play. Both applications will try and write the file to the System32
folder. After both files have been saved, open an Explorer window and try to find them.
You will notice that, even though the 32-bit version of Notepad tried to save the file to
the hard-coded path of c:\WINDOWS\System32, the file is nowhere to be found in this
directory. The 32-bit application was silently redirected and saved in SysWOW64.
Figure 6 Contents of the 64-bit system folder
Figure 7 Contents of the 32-bit system folder
With a simple test, it is easy to observe how 32-bit applications are redirected to the
SysWOW64 folder.
64-bit Insider Newsletter
Volume 1, Issue 3
Page 5/6
Remember that the System32 folder is the only folder that is actually being redirected.
Besides System32, the entire file system on a Windows 64-bit operating system can be
accessed directly by both 32- and 64-bit applications.
In the upcoming newsletter, we’ll find out if the Program Files directory is redirected as
well. Topics such as DLL load order will also come into place when finding out exactly
how is it that the WOW64 loads a 32-bit or 64-bit DLL when invoked by a process.
Recommended Reading
WOW64 Implementation Details
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/win64/win64/wow64_implementation_details.asp
Wowing Your 32-bit Applications with 64-bit Windows, Parts 1 & 2
http://www.devx.com/amd/article/20342
Windows Data Alignment on IPF, x86, and x86-64
http://www.devx.com/amd/Article/20367
64-bit Insider Newsletter
Volume 1, Issue 3
Page 6/6