PROCESSOR_ARCHITECTURE returns AMD64 in some 32-bit processes

I came across a bizarre scenario where a 32-bit process claims that its PROCESSOR_ARCHITECTURE is AMD64, which leads to the failure of components making decisions based on this flag.

I highlighted it in the following steps:

  • In VS2010, create a library project
  • On the tab "Project Properties / Debugging" set "Run external program" in VS exe (for example, C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ devenv.exe)
  • Run Ctrl-F5, which launched another instance of VS
  • In this second example, create a console application and paste the following code

In the main:

Console.WriteLine(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")); Console.ReadLine(); 
  • Now run the console application

And it displays AMD64, although this is a 32-bit process (by default for console applications, for build settings).

Question : can others also reproduce this, and if so, can you explain it?

Note: if you are interested, the reason I run VS is because I use an experimental bush for the second instance

UPDATE: note that in my real scenario, I am not looking for this environment variable myself. Instead, I use a component (SQLCE) that looks for it and relies on its correctness.

+4
source share
3 answers

Based on my findings, I think I can come up with a reasonable explanation for this.

By setting the target project for “Any processor” (by default for class libraries), the PROCESSOR_ARCHITECTURE environment PROCESSOR_ARCHITECTURE will be set to what is most accessible when starting the external process “AMD64” for a 64-bit OS, however, since the Visual Studio IDE is actually is a 32-bit process launched from WOW, this can confuse processes launched from the second instance.

Forced library formatting for a 32-bit platform will be set correctly. Perhaps you should do this.

+1
source

This does not answer your question directly, but why are you not just checking the value of IntPtr.Size ? If it is 4, then you are 32-bit, if it is 8, then you are 64-bit.

The .NET framework 4 also has Is64BitProcess and Is64BitOperatingSystem , which will certainly be a way forward ...

+2
source

From what I know, PROCESSOR_ARHITECTURE is not a hardware processor; it refers to the processor for which the OS software was created.

Since AMD was the first to create a 64-bit architecture (x86-64), Microsoft provided OS support for this and left the title that AMD gave it. AMD64 and Intel64 actually refer to the same x86-64 architecture, so they are compatible.

You can try, for example, getting PROCESSOR_IDENTIFIER and find out the type of processor from the information inside it.

Someone can fix me if I'm wrong.

0
source

All Articles