Object Management
Because USER and GDI are both old components that were ported from
ancient versions of Windows, they don’t use the kernel object manager dis-
cussed earlier. Instead they each use their own little object manager mecha-
nism. Both USER and GDI maintain object tables that are quite similar in
layout. Handles to Win32 objects such as windows and device contexts are
essentially indexes into these object tables. The tables are stored and managed
in kernel memory, but are also mapped into each process’s address space for
read-only access from user mode.
Because the USER and GDI handle tables are global, and because handles
are just indexes into those tables, it is obvious that unlike kernel object han-
dles, both USER and GDI handles are global—if more than one process needs
to access the same objects, they all share the same handles. In reality, the Win32
subsystem doesn’t always allow more than one process to access the same
objects; the specific behavior object type.
Structured Exception Handling
An exception is a special condition in a program that makes it immediately
jump to a special function called an exception handler. The exception handler
then decides how to deal with the exception and can either correct the problem
and make the program continue from the same code position or resume exe-
cution from another position. An exception handler can also decide to termi-
nate the program if the exception cannot be resolved.
There are two basic types of exceptions: hardware exceptionsand software
exceptions. Hardware exceptions are exceptions generated by the processor, for
example when a program accesses an invalid memory page (a page fault) or
when a division by zero occurs. A software exception is generated when a pro-
gram explicitly generates an exception in order to report an error. In C++ for
example, an exception can be raised using the throwkeyword, which is a
commonly used technique for propagating error conditions (as an alternative
to returning error codes in function return values). In Windows, the throw
keyword is implemented using the RaiseExceptionWin32 API, which goes
down into the kernel and follows a similar code path as a hardware exception,
eventually returning to user mode to notify the program of the exception.
Structured exception handling means that the operating system provides
mechanisms for “distributing” exceptions to applications in an organized
manner. Each thread is assigned an exception-handler list, which is a list of rou-
tines that can deal with exceptions when they occur. When an exception
occurs, the operating system calls each of the registered handlers and the han-
dlers can decide whether they would like to handle the exception or whether
the system should keep on looking.
Windows Fundamentals 105