I have a cmd file that runs on 32 bit Vista system.
I notice that the code has references to the system32 driver folder.
I'm wondering whether the code could potentially run on a 64 bit Windows 7 system. So I guess my question is
Does a 64 bit system contain a system32 folder?
Be very grateful for any replies.
The System32 folder in 64-bit Windows actually contains the 64-bit files, and 32-bit programs running under WOW64 would generally go looking in System32 for the 32-bit DLLs etc. that they can call - but they'll find the 64-bit ones instead. Therefore the OS redirects all 32-bit applications' requests for the System32 folder to the SysWOW64 folder, which contains 32-bit system files.
Windows has a technology called WoW 64 (Windows-on-Windows 64-bit) that allows 32-bit applications (even compiled ones written in C/C++, etc.) to run on 64-bit Windows.
In addition to the System32 folder, a 64-bit Windows installation has a SysWow64 folder that has 32-bit versions of the files that you'll find in System32.
To be clear, references to System32 get redirected when running from a 32-bit process (unless the process disables this redirection, which is possible). As a result, if you have a .CMD file that references System32, it's actually going to read from the SysWow64 directory.
System32 is the name of the folder that contains important operating system files.
Early versions of 64-bit Windows XP only ran 64-bit applications. This made sense:
you run 16-bit applications on 16-bit Windows
you run 32-bit applications on 32-bit Windows
you run 64-bit applications on 64-bit Windows
And early versions of 64-bit Windows XP were 64-bit, and only supported running 64-bit applications.
And since all the folders names stay the same, you can simply recompile your application as 64-bit (and not have to change anything else - including your accidentally hard-coded paths), and it will just work.
Emulate 32-bit OS on 64-bit Windows
Very quickly it became obvious that only being able to run 64-bit applications on 64-bit Windows, would prevent some people from upgrading to 64-bit Windows. So an emulation layer was created to allow you to run 32-bit applications on a 64-bit operating system.
It was called WOW64: Windows on Windows64:
This emulation layer simulates the x86 architecture, virtualizing the CPU, the file system, the registry, the environment variables, the system information functions, all that stuff.
If a 32-bit program tries to look at the system, it will see a 32-bit system.
For example, if the program calls the GetSystemInfo function to see what processor is running, it will be told that it's running on a 32-bit processor, with a 32-bit address space, in a world with a 32-bit sky and 32-bit birds in the 32-bit trees.
And that's the point of the emulation: To keep the 32-bit program happy by simulating a 32-bit execution environment.
The problem is where should these 32-bit applications store all their 32-bit files, and configure the locations of their 32-bit DLLs, and load 32-bit operating system support files?
We already know where native applications store their stuff.
| Native Application |
|---------------------|
| C:\Windows\System32 |
| C:\Program Files |
| HKCU\Software |
This is all correct and right; if you simply recompile your 32-bit application as 64-bit: everything works. All these locations are still correct.
32-bit in a 64-bit world
But now since we're going to bend-over backwards in order to accomdoate non-64 bit applications, we have to find someplace for them to have their old 32-bit OS files, and store their 32-bit data, and have their 32-bit programs, with 32-bit shared components:
| Native Application | Emulated 32-bit |
|---------------------|---------------------------|
| C:\Windows\System32 | C:\Windows\SysWOW64 |
| C:\Program Files | C:\Program Files (x86) |
| HKCU\Software | HKCU\Software\Wow6432Node |
A problem is that:
if a 64-bit program asks for C:\Windows\System32, it damn well better get 64-bit files
if a 32-bit program asks for C:\Windows\System32, it damn well better get 32-bit files
This means that if a 32-bit process ask for some of these file locations, Windows has to transparently redirect the call to the 32-bit folders and registry keys.
If a 32-bit program, that thinks it's running on an old 32-bit operating system, asks for a 32-bit location, it needs to be given the "real" location:
| Native Application | Emulated 32-bit asks for | Is actually given |
|---------------------|---------------------------|---------------------------|
| C:\Windows\System32 | C:\Windows\System32 | C:\Windows\SysWOW64 |
| C:\Program Files | C:\Program Files | C:\Program Files (x86) |
| HKCU\Software | HKCU\Software | HKCU\Software\Wow6432Node |
If you don't want your 32-bit application to be subject to all this emulation and thunking, then the solution is obvious:
create a 64-bit application for a 64-bit operating system
Stop creating a 32-bit application, and then complaining when the emulation layer causes you to go through emulation. Your application is the misbehaving oddball; fix it.
Windows 7 64 bit has a System32 folder.
Whether your file will still run, however, is a more complex problem. It might, and depends entirely on what it relies on; if it's relying on drivers in the wrong way, it will fail as 32 bit drivers just don't work on 64 bit systems.
Related
Investigating the bit width of DLLs on my Windows 10/64 bit box with Visual Studiop 2013 installed.
dumpbin /headers C:\windows\system32\msvcp120.dll | findstr machine
reports: 8664 machine (x64)
but
cd C:\windows\system32\
dumpbin /headers .\msvcp120.dll | findstr machine
reports:
14C machine (x86) 32 bit word machine
I've tried it on several machines with the same result. What's going on ?
This is the file system redirector at work, always active on a 64-bit OS when you look at the c:\windows\system32 directory. You are actually looking at c:\windows\syswow64\msvcp120.dll, thus the machine type is x86. Caused primarily by running the 32-bit version of dumpbin.exe, like most users would. Only the 64-bit version (vc/bin/amd64 directory) does not get redirected.
I was puzzled a bit and discovered one aspect of the redirector I did not know before. It redirects only relative paths. So .\msvcp120.dll or ..\system32\msvcp120.dll. But not a full path, like c:\windows\system32\msvcp120.dll. Drive letter is not actually important.
I wrote an application in C++ for linux (X11, GLX) and it is working alright on my development computer (32-bit linux on 64-bit capable hardware). However, when I ran it on a 64-bit linux downstairs, I received an error telling me the linker failed to link stdlibc++.so.6, but I thought 32-bit compiled application could run on 64-bit kernels and Oses as well? At least that is the case in Windows... Do I have to separately compile 32 and 64 bit with different libs?
And how do I properly distribute my application? It's a game, and currently you have to run a makefile to let it move its dependencies to the /usr/lib/ directory (a kind of amateur installer). Will this work on all mainstream linux distro's? And are there better, neater ways to release your application?
I am writing a launcher in C++ to launch my java based GUI application on Windows. I am using CreateProcess to launch "javaw.exe". Everything works except for the fact that 32-bit version of "javaw.exe" is always launched.
When java is installed, it puts the executables "java.exe" and "javaw.exe" in %windir%\System32 on 32-bit windows. On 64-bit windows, it puts the same executables in %windir%\SysWow64.
There are 3 possibilities:
32-bit launcher executed on 32-bit windows: %windir%\System32 is in search path, and 32-bit javaw.exe is found. The GUI launches. Everything works.
32-bit launcher executed on 64-bit windows: %windir%\System32 is in search path. %windir%\System32 is redirected to %windir%\SysWow64 (since my launcher is 32 bit in this case). 32-bit javaw.exe is found. The GUI launches. Everything works.
64-bit launcher executed on 64-bit windows: %windir%\System32 is in search path. No redirection happens. It does not contain the executable javaw.exe. The launcher fails.
How do I launch 64-bit javaw.exe in the third case?
I finally found a solution (by digging through various posts on stackoverflow).
Recent versions of JRE when installed do put a copy of "javaw.exe" in System32. The previous versions of 64 bit JRE probably didn't (not sure).
In any case, the registry key HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java Runtime Environment has a property CurrentVersion which points to the key for the default JRE for the system. The sub-key corresponding to the version number has a property JavaHome which points to the location of JRE installation.
If JRE/JDK is not installed, then the Java Runtime Environment key won't be found.
When compiling code with VC++, MSDN gives you the option between using the x86_amd64 toolset or the amd64 toolset (when calling vcvarsall.bat).
How do I choose between those two when compile x64 code? Will the amd64 option churn out more efficient x64 machine code than the cross compiler?
It has nothing to do with efficiency. The native and cross-compiler will both generate the same machine code. You will however gain some benefits by running a native 64-bit compiler process on a 64-bit workstation (larger registers, larger memory space, etc...).
The native compiler will only run on an 64-bit copy of Windows, so if your workstation is 32-bit this compiler won't even run.
The cross-compiler is meant to run on x86 machines even though it will run on a 64-bit copy of Windows via WoW; however, there is no reason to do this.
The page you link says it quite well:
x64 on x86 (x64 cross-compiler)
Allows
you to create output files for x64.
This version of cl.exe runs as a
32-bit process, native on an x86
machine and under WOW64 on a 64-bit
Widows operating system.
x64 on x64
Allows you to create output
files for x64. This version of cl.exe
runs as a native process on an x64
machine.
Thanks to Brian R. Bondy for the quote formatting
From what you linked:
x64 on x86 (x64 cross-compiler)
Allows
you to create output files for x64.
This version of cl.exe runs as a
32-bit process, native on an x86
machine and under WOW64 on a 64-bit
Widows operating system.
x64 on x64
Allows you to create output
files for x64. This version of cl.exe
runs as a native process on an x64
machine.
Paraphrased:
If you use x86_amd64, then you are typically developing on an x86 machine and you want to create x64 files that run natively on x64. You could also use this option on an x64 machine but your compiler will be running under WOW64 emulation.
If you use AMD64, then you are developing on an x64 machine and you want to create x64 files that run natively on x64. The compiler is running natively in x64. This option is more efficient to build x64 programs.
You may wonder why you would ever develop an x64 program on an x86 computer, since you can't run it you can't debug it. Well it's still useful for example if you have a build server which is x86 and that build server needs to generate both x86 and x64 outputs.
How is it possible for a compiler to run under x64 if it is an x86 based program (x86_amd64)? That is the same reason you can run any x86 program on your x64 machine... Thanks to WOW64 emulation.
What is WOW64 emulation:
WOW64 emulation happens when you run an x86 program on an x64 computer (or IA64). WOW64 stands for Windows 32 on Windows 64. It is an emulation layer on top of x64 machines which allow you to execute x86 programs.
Your file system operations will be redirected to WOW64 folders and your registry will be redirected to a subnode as well. For example when you try to obtain the folder for program files it will return c:\program files (x86)\ if you are using WOW64 but it will return c:\program files\ if you are using x64.
Another example, for the registry if you try to write to HKLM\Software\Something it will really redirect you to HKLM\SOFTWARE\Wow6432Node\Something without your x86 program's knowledge.
Running a native x64 build will be more efficient than running through WOW64 emulation Why? Because you don't have that extra emulation layer of transforming your 32bit calls into 64bit ones.
By the way if you are running the x64 version of Windows you can see which processes are running through WOW64 because they will have a *32 appended to the process name in the process list.
How is Linux simultaneously 32bit and 64bit? Or is that something handled in glibc?
I run CentOS 5.3 and it is a "64 bit" version; although I build things for 64 bit and 32 bit. From what I think I know, Windows supposedly has a 32bit emulator. Does Linux do the same thing? Is it in userspace or kernel space?
If libc handles it, is it kind of like a emulator that says, I'll link with 32 bit apps, but speak 64 bit to the kernel?
The cpu can execute both 64 and 32bit instructions and the kernel can switch between modes. The only limitation is that you cannot link 32bit programs against 64bit libraries so you must have both 32 and 64bit versions of libc, etc. installed.
Nothing is stopping the cpu from switching from 64bit to 32bit. It just switches.
You can have a 64 bit kernel, and run 32bit apps. You can even have a 32bit kernel and run 64bit apps(Mac os x).
However you need the libaries they use to also be 32bit or or 64bit, which is why you might see files called lib64 or lib32 on linux for the 64bit or 32bit libaries.
Because x86_64 processors are designed over x86 technology, they are still able to support 32-bit programs without any hardware emulation, like what you would need to run x86 programs in a PowerPC or Sparc environment. In Linux, all you need to do is install the necessary software libraries to run the 32-bit software.