![]() __________Chapter 3: Win32 Implementations: A Comparative Look____ 29
for Microsoft was to ensure that the 16-bit code is not entered from multiple tasks. To
achieve this, Microsoft came up with the Winl6Mutex solution.
Before entering the 16-bit code, the operating system acquires the Winl6Mutex,
and it leaves the Winl6Mutex while returning from 16-bit code. The Winl6Mutex
is always acquired when a 16-bit application is running, which results in reduced
multitasking. Windows NT does not have this problem because the entire code is
32-bit and is well suited for time slice-based preemptive multitasking. Also, the 16-
bit code thunks up to 32-bit code in the case of Windows NT.
Thunking
Thunking enables 16-bit applications to run in a 3 2-bit environment and vice
versa. It is a way of calling a function written in one bitness from the code running
at a different bitness. Bitness is a property of the processor, and you can program
the processor to adjust the bitness. Bitness decides the way instructions are decoded
by the processor. There are two different types of thunking available:
+ Universal thunking
+ Generic thunking
Universal thunking enables you to call a 32-bit function from 16-bit code,
whereas generic thunking enables you to call a 16-bit function from 32-bit code.
Windows 95/98 supports both generic and universal thunking, but Windows NT
supports only universal thunking. As you saw earlier in this chapter, generic thunk-
ing is used extensively in WIN32 API implementation of Windows 95/98. For ex-
ample, a 32-bit USER32.DLL calls functions from a 16-bit USER.EXE, and a 32-bit
GDI32.DLL calls functions from a 16-bit GDI.EXE. Various issues are involved in
thunking, such as converting 16:16 far pointers in 16-bit code to flat 32-bit address
and manipulating a stack for making a proper call from code running at one bitness
to code running at a different bitness. Microsoft provides tools such as thunk com-
pilers to automate most of these tasks.
Many vendors who write code for Windows 95/98 use generic thunking to avoid
a major redesign of their applications. For example, say a particular vendor has a
product for Windows 3.1 and would like to port it to Windows 95. Instead of
rewriting the code for Windows 95, an easier solution is to use the majority of the
existing 16-bit code and use generic thunking as a way of calling this code from
32-bit applications. However, these applications need to be rewritten for Windows
NT as Windows NT does not support generic thunking.
Device Drivers
Device drivers are trusted components of the operating system that have full access
to the entire hardware. There are no restrictions on what device drivers can do.
Each operating system provides some way of adding new device drivers to the sys-
|
|