Page 347 - DCAP103_Principle of operating system
P. 347
Principles of Operating Systems
Notes
In computing, a device driver or software driver is a computer program
allowing higher-level computer programs to interact with a hardware device.
11.1.7 Environment Subsystems
Going back to Figure 11.1, we see that Windows 2000 consists of components in kernel
mode and in user mode. We have now completed our examination of the kernel mode
components; now it is time to look at the user mode components of which there are three
kinds: DLLs, environment subsystems, and service processes. These components work
together to provide each user process with an interface that is distinct from the Windows
2000 system call interface.
Windows 2000 supports three different documented APIs—Win32, POSIX, and OS/2. Each of
these interfaces has a published list of library calls that programmers can use. The job of the DLLs
(Dynamic Link Libraries) and environment subsystems is to implement the functionality of the
published interface, thereby hiding the true system call interface from application programs. In
particular, the Win32 interface is the official interface for Windows 2000, Windows NT, Windows
95/98/Me, and to a limited extent, Windows CE. By using the DLLs and Win32 environment
subsystem, a program can be written to the Win32 specification and run unmodified on all these
versions of Windows, even though the system calls are not the same on the various systems.
To see how these interfaces are implemented, let us look at Win32. A Win32 program normally
contains many calls to Win32 API functions, for example, CreateWindow, DrawMenuBar, and
OpenSemaphore. There are thousands of such calls, and most programs use a substantial number
of them. One possible implementation would be to statically link every Win32 program with all
the library procedures that it uses. If this were done, each binary program would contain one
copy of each procedure that used in its executable binary.
The trouble with this approach is that it wastes memory if the user has multiple programs
open at once and they use many of the same library procedures. For example, Word, Excel, and
Powerpoint all use exactly the same procedures for opening dialog boxes, drawing windows,
displaying menus, managing the clipboard, etc., so if a user had all of them to open and active
at once, there would be three (identical) copies of each of the libraries in memory. To avoid
this problem, all versions of Windows support shared libraries, called DLLs (Dynamic Link
Libraries). Each DLL collects together a set of closely related library procedures and their data
structures into a single file, usually (but not always) with extension .DLL. When an application
is linked, the linker sees that some of the library procedures belong to DLLs and records this
information in the executable’s header. Calls to procedures in DLLs are made indirectly through
a transfer vector in the caller’s address space. Initially this vector is filled with 0s, since the
addresses of the procedures to be called are not yet known.
When the application process is started, the DLLs that are needed are located (on disk or in
memory) and mapped into the process’ virtual address space. The transfer vector is then filled
in with the correct addresses so that the procedures can then be called via the transfer vector
with only a negligible loss of efficiency. The win here is that even though multiple application
programs have the same DLL mapped in, only one copy of the DLL text is needed in physical
memory (but each process gets its own copy of the private static data in the DLL). Windows
2000 uses DLLs extremely heavily for all aspects of the system.
Now we have enough background to see how the Win32 and other process interfaces are
implemented. Each user process generally links with a number of DLLs that together implement
the Win32 interface. To make an API call, one of the procedures in a DLL is called, shown as
step 1 in Figure 11.7. What happens next depends on the Win32 API call? Different ones are
implemented in different ways.
340 LOVELY PROFESSIONAL UNIVERSITY