Growing with the Web

Working with 32-bit processes on 64-bit Windows

Published
Tags:

I hit a bug in VS Code recently related to running a 32-bit process on a 64-bit machine that was interesting. Here’s what I learned.

The System32 directory

On 64-bit Windows %windir%\System32 holds the 64-bit binaries. Accesses to this directory on 32-bit processes are automatically redirected to SysWoW64, in order to be backwards compatible.

The SysWoW64 directory

On 64-bit Windows %windir%\SysWoW64 holds the 32-bit binaries. This confused me initially until I learned that WoW64 stands for Windows 32-bit on Windows 64-bit.

The Sysnative directory

%windir%\Sysnative only exists on 32-bit processes running on 64-bit Windows and it redirects to the actual System32, allowing access to the 64-bit binaries on 32-bit processes. Initially I mistakenly assumed that Sysnative was a standard symlink that always points at the 64-bit binaries if they’re available, but this is not the case.

Directory overview

  32-bit process 64-bit process
System32 -> SysWoW64 (32-bit binaries) 64-bit binaries
SysWoW64 32-bit binaries 32-bit binaries
Sysnative -> System32 (64-bit binaries) N/A

Detecting WoW64 processes

That’s all very well and good, but how do you detect that you’re a 32-bit process running on 64-bit Windows? There are a couple of environment variables that come in handy here.

PROCESSOR_ARCHITECTURE will give you the actual processor architecture; "x86", "AMD64" or "IA64".

PROCESSOR_ARCHITEW6432 will give the same value as PROCESSOR_ARCHITECTURE, but it’s only set on 32-bit processes. To detect whether you’re in a WoW64 environment, just check whether the PROCESSOR_ARCHITEW6432 exists in the environment.

References

Like this article?
Subscribe for more!