Programming the Windows 32 API and UNIX System Services with Cdrom
Authors: Donald Merusi
Venue:  (2000)

From the Book:PREFACE: PrefaceThis book attempts to illustrate what facilities exist in both the Microsoft Windows and UNIX programming worlds for performing comparable API functionality. The term UNIX in this book refers to both Sun Microsystem's Solaris V2.6 and Red Hat Linux Version 6.1. Unless a specific distinction is mentioned, the term UNIX refers to both UNIX environments. Although the concept of open systems and platform independent program environments seems to abound, to take advantage of specific system functionality requires understanding facilities particular to each operating system environment. Although the POSIX standard provides for source-level portability, specifics of it are not always guaranteed, and the full range of capability of the system API calls is generally not available from within the POSIX calls. The program examples presented in this book are rudimentary and serve only as a starting point for a more elaborate implementation.Chapter 1 discusses how to create and manage threads and processes in both the UNIX and Microsoft Windows worlds. The UNIX focus is on POSIX threads, and the user is made aware that on Solaris a separate library, the LWP or lightweight process library, is available which offers some extensions and variations to the POSIX calls. Topics discussed in this chapter under thread management include using thread priorities and controlling thread execution by suspending or resuming their execution. User mode thread scheduling under Microsoft Windows is also discussed using fibers. Along with threads, Microsoft Windows processes and UNIX fork processes are discussed.With all the asynchronous activity instigated bythefunctions described in Chapter 2, some means of controlling this activity is required. This chapter discusses various aspects of controlling concurrency by using an assortment of API calls for creating and using mutexes, semaphores, condition variables, critical sections, and many other functions. Chapter 3 discusses programming for the unexpected: what happens when an unexpected error or condition occurs. Also, how do you ensure that certain actions take place when a program exits from the system? This chapter discusses the UNIX signaling facility and shows how it can be controlled in a multithreaded environment. Microsoft Visual C/C++ offers structured exception handling, which offers a very natural way to design a program for unexpected events. The C++ catch and throw facility is also mentioned. In the UNIX POSIX world, thread cancellation can be used to gracefully terminate threads and to perform an assortment of thread cancellation handlers on the way out. Exit handlers are generally available in both UNIX and the Microsoft Windows platforms. Microsoft Windows asynchronous procedure calls (APCs) are also discussed as a means of improving program throughput.Chapter 4 discusses various aspects of file systems. Modern file system technology requires programs to be able to perform more than just basic I/O to files. Various portions of files can be locked from access by other threads. Files themselves can be used as coordination mechanisms. Files can also be memory mapped, that is, their contents can be read and even updated as if the file contents existed in a memory buffer. File mapping facilitates sharing information between different programs. File search mechanisms are also discussed for the Microsoft Windows environment.Chapter 5 discusses memory management functions. These functions are available to users who want a particular level of control in how their memory environment is managed. The virtual memory and heap management routines are discussed for the Microsoft Windows world. The basic UNIX heap management routines are also mentioned for completeness. Certain superuser-level memory management control routines are also discussed for the Solaris environment.Chapter 6 discusses various aspects of networking and communications. Facilities are categorized as being either connection-oriented or connectionless-oriented. Both UNIX and Microsoft Windows offer a common networking communications environment by allowing TCP and UDP communications to take place between these environments. Other communications facilities discussed in this chapter are mailslots, named and unnamed pipes, and message queues.Chapter 7 discusses mostly what facilities exist in the Microsoft Windows world for security control. With the advent of Windows NT and 2000, the security APIs have become extremely robust and offer a myriad of options for controlling access to system resources. The basic security components of Windows NT/2000 are discussed first, access tokens and security descriptors next, and then discussions and demonstrations of how to control them are then performed. Access control lists (ACLs) are the unit of access control on both Microsoft Windows and Solaris UNIX, and API calls are available for specifically controlling them. Finally, the UNIX setuid, setgid, chown, and chmod routines are discussed as another collection of security-related functions.The Appendix lists several programs written by students at Rensselaer at Hartford for a course based on the material presented in this book. The programs depicted represent one of the programming assignments for the course and offer an excellent exercise in understanding how to use and control a multithreaded application.