Lesson 2. Support of 32-bit applications in the 64-bit Windows environment

Embed Size (px)

Citation preview

  • 8/6/2019 Lesson 2. Support of 32-bit applications in the 64-bit Windows environment

    1/3

    Lesson 2. Support of 32-bitapplications in the 64-bit WindowsenvironmentBefore we start discussing the topic of developing 64-bit program code, let us speakabout backward compatibility of 64-bit Windows versions with 32-bit applications.Backward compatibility is arranged through the mechanisms implemented inWoW64 .

    WoW64 (Windows-on-Windows 64-bit) is a subsystem of Windows operating systemthat allows you to execute 32-bit applications on all the 64-bit versions of Windows.

    The WoW64 subsystem does not support the following programs:

    programs compiled for 16-bit operating systems; kernel-mode programs compiled for 32-bit operating systems.

    Indirect expensesDifferent processor architectures have a bit different WoW64. For example, the 64-bit Windows version developed for Intel Itanium 2 processor employs WoW64 toemulate x86 instructions. This emulation is rather resource-intensive in comparisonto WoW64 for Intel 64 architecture because the system has to switch from the 64-bit mode to compatibility mode when executing 32-bit programs.

    WoW64 on Intel 64 (AMD64 / x64) does not require instruction emulation. In thiscase the WoW64 subsystem emulates only the 32-bit environment through anadditional layer between a 32-bit application and the 64-bit Windows API. In someplaces this layer is thin, in others a bit thicker. For an average program, you mayexpect 2% performance penalty because of this layer. For some programs, it can belarger. Two per cent is not very much but keep in mind that 32-bit applications worka bit slower under the 64-bit Windows than in the 32-bit environment.

    Compilation of 64-bit code does not only allow you to avoid using WoW64 but also

    gives you an additional performance gain. This is explained by architecturalmodifications in the microprocessor such as an increased number of general-purpose registers. For an average program, you may expect a 5-15% performancegain after mere recompilation.

    Benefits of the 64-bit environment for 32-bit programsBecause of the WoW64 layer, 32-bit programs are less efficient in the 64-bitenvironment than in their native 32-bit one. But still simple 32-bit applications canget one benefit of being executed in the 64-bit environment. Maybe you know thata program built with the switch "/LARGEADDRESSAWARE:YES" can allocate up to 3Gbytes of memory if a 32-bit Windows is launched with the switch "/3gb". Well, the

    http://www.viva64.com/terminology/WoW64.htmlhttp://www.viva64.com/terminology/x86.htmlhttp://www.viva64.com/terminology/Intel_64.htmlhttp://www.viva64.com/terminology/x86.htmlhttp://www.viva64.com/terminology/Intel_64.htmlhttp://www.viva64.com/terminology/WoW64.html
  • 8/6/2019 Lesson 2. Support of 32-bit applications in the 64-bit Windows environment

    2/3

    same 32-bit program built on a 64-bit system can allocate almost 4 Gbytes of memory (in practice it is usually about 3.5 Gbytes).

    Redirections The WoW64 subsystem isolates 32-bit programs from 64-bit ones by redirecting

    calls to files and the register. It helps to keep 32-bit programs from accidentallyaccessing the data of 64-bit ones. For example, a 32-bit application that launches aDLL file from the catalogue "%systemroot%\System32" can accidentally address a64-bit DLL which is incompatible with the 32-bit program. To avoid this, the WoW64subsystem redirects the access from the folder "%systemroot%\System32" into thefolder "%systemroot%\SysWOW64". This redirection helps you avoid compatibilityerrors because the 32-bit application will need a special DLL file created to workwith 32-bit applications.

    To learn more about the mechanisms of file system and register redirection see

    MSDN section " Running 32-bit Applications ".

    Why cannot 32-bit DLL's be used in a 64-bit program? Isthere a way to evade this limitation?It is impossible to load a 32-bit DLL from a 64-bit process and execute its code. It isimpossible due to the design of 64-bit systems. It is impossible fundamentally. Andno tricks and undocumented means will help you. To do this you will have to loadand initialize WoW64, not to speak of the kernel structures. Actually, it means that a64-bit process must be made 32-bit "on the fly". This topic is described more

    thoroughly in the post " Why can't you thunk between 32-bit and 64-bit Windows?". The only thing we can recommend is to create a surrogate process and work with itthrough the COM technology. You may read about it in the article " Accessing 32-bitDLLs from 64-bit code ".

    But it is quite easy to load resources from a 32-bit DLL into a 64-bit process. Youmay do it specifying the flag LOAD_LIBRARY_AS_DATAFILE when callingLoadLibraryEx.

    Gradual renunciation of 32-bit software supportIt will be quite natural if Microsoft company will stimulate the move to 64-bitsystems by gradually canceling the support of 32-bit programs in some versions of Windows operating system. Of course it will be a very slow process but the firststeps in this direction have been already made.

    Many administrators know about a relatively new installation and operation mode of the server version of the operating system called Server Core. It is that very modethe participants of "Windows vs Linux" wars have been speaking of for a long time.One of the reasons that adherents of using Linux on servers referred to was thecapability to install the server operating system without graphical interface (GUI).

    But here is such a capability in Windows Server too. Now, if you install the system inthis mode, you will get only the command line without user interface.

    http://www.viva64.com/go.php?url=265http://www.viva64.com/go.php?url=294http://www.viva64.com/go.php?url=209http://www.viva64.com/go.php?url=209http://www.viva64.com/go.php?url=265http://www.viva64.com/go.php?url=294http://www.viva64.com/go.php?url=209http://www.viva64.com/go.php?url=209
  • 8/6/2019 Lesson 2. Support of 32-bit applications in the 64-bit Windows environment

    3/3