100% found this document useful (1 vote)
66 views55 pages

Windows10systemprogramming Sample

Uploaded by

Slippery Stairs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
66 views55 pages

Windows10systemprogramming Sample

Uploaded by

Slippery Stairs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 55

Windows 10 System Programming, Part 1

Pavel Yosifovich
This book is for sale at http://leanpub.com/windows10systemprogramming

This version was published on 2021-01-17

This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools
and many iterations to get reader feedback, pivot until you have the right book and build
traction once you do.

© 2019 - 2021 Pavel Yosifovich


Contents

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What You Should Know to Use This Book . . . . . . . . . . . . . . . . . . . . . . . . . 1
Sample Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Chapter 1: Foundations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Windows Architecture Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Dynamic Link Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Virtual Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
General System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Windows Application Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Your First Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Working with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Strings in the C/C++ Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
String Output Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Safe String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
32-bit vs. 64-bit Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Coding Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
C++ Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Handling API Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Defining Custom Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
The Windows Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Getting the Windows Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Chapter 2: Objects and Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6


Kernel Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Running a Single Instance Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
CONTENTS

Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Pseudo Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
RAII for Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Using WIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Creating Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Object Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Sharing Kernel Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Sharing by Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Sharing by Handle Duplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Private Object Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Bonus: WIL Wrappers for Private Namespaces . . . . . . . . . . . . . . . . . . . . 13
Other Objects and Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
User Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
GDI Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Chapter 3: Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Process Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Processes in Process Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Process Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
The main Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Process Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Creating Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Handle Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Process Drive Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Process (and Thread) Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Protected and PPL Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
UWP Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Minimal and Pico Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Process Termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Enumerating Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Using EnumProcesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using the Toolhelp Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using the WTS Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using the Native API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Chapter 4: Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Introduction to Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Creating Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CONTENTS

Nested Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Querying Job Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Job Accounting Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Querying for Job Process List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Setting Job Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CPU Rate Limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
User Interface Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Job Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Silos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Chapter 5: Threads Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21


Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Sockets, Cores, and Logical Processors . . . . . . . . . . . . . . . . . . . . . . . . . 21
Creating and Managing Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
The Primes Counter Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Running Primes Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Terminating Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
A Thread’s Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
A Thread’s Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
What About the C++ Standard Library? . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 6: Thread Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23


Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Scheduling Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Single CPU Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
The Quantum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Processor Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Multiprocessor Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Affinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CPU Sets vs. Hard Affinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
System CPU Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Revised Scheduling Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Observing Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
General Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Hard Affinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CPU Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Background Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CONTENTS

Priority Boosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Completing I/O Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Foreground Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
GUI Thread Wakeup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Starvation Avoidance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Other Aspects of Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Suspend and Resume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Suspending and Resuming a Process . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Sleeping and Yielding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Chapter 7: Thread Synchronization (Intra-Process) . . . . . . . . . . . . . . . . . . . . . 27


Synchronization Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Atomic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The Simple Increment Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The Interlocked Family of Functions . . . . . . . . . . . . . . . . . . . . . . . . . 27
Critical Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Locks and RAII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Deadlocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The MD5 Calculator Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Calculating MD5 Hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The Hash Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Image Loads Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Event Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Putting it All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Reader Writer Locks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
RAII Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
MD5 Calculator 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Condition Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Queue Demo Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Waiting on Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Synchronization Barriers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
What About the C++ Standard Library? . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

Chapter 8: Thread Synchronization (Inter-Process) . . . . . . . . . . . . . . . . . . . . . 31


Dispatcher Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Succeeding a Wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Mutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Mutex Demo Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
CONTENTS

Abandoned Mutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Semaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Queue Demo Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Working with Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Waitable Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Other Wait Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Waiting in Alertable State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Waiting on GUI Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Waiting for an Idle GUI Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Signaling and Waiting Atomically . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Chapter 9: Thread Pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34


Why Use a Thread Pool? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Thread Pool Work Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
The Simple Work Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Controlling a Work Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
The MD5 Calculator Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Thread Pool Wait Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Thread Pool Timer Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The Simple Timer Sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Thread Pool I/O Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Thread Pool Instance Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The Callback Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Private Thread Pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Cleanup Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

Chapter 10: Advanced Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37


Thread Local Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Dynamic TLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Static TLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Remote Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Breakin Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Thread Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The thlist Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Caches and Cache Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Wait Chain Traversal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
CONTENTS

The Deadlock Detector Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 38


Asynchronous WCT Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
User Mode Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Init Once Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Debugging Multithreaded Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Parallel Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Parallel Watch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Thread Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Chapter 11: File and Device I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40


The I/O System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
The CreateFile Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Working with Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Path Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Setting File Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Synchronous I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Asynchronous I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ReadFileEx and WriteFileEx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Manually Queued APC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
I/O Completion Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
The Bulk Copy Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Using the Thread Pool for I/O Completion . . . . . . . . . . . . . . . . . . . . . . . 42
The Bulk Copy 2 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
I/O Cancellation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Pipes and Mailslots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Transactional NTFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
File Search and Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
NTFS Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Chapter 12: Memory Management Fundamentals . . . . . . . . . . . . . . . . . . . . . . 44


Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Process Address Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Page States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
CONTENTS

Address Space Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44


32-bit Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
64-bit Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Address Space Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Memory Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Process Memory Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Process Memory Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Page Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Enumerating Address Space Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
The Simple VMMap Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
More Address Space Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Sharing Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Page Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
WOW64 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
WOW64 Redirections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Virtual Address Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Introduction
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Who Should Read This Book


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

What You Should Know to Use This Book


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sample Code
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 1: Foundations
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Windows Architecture Overview


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Processes

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Dynamic Link Libraries

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Virtual Memory

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Threads

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

General System Architecture

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 1: Foundations 3

Windows Application Development


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Your First Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Working with Strings


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Strings in the C/C++ Runtime

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

String Output Parameters

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Safe String Functions

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

32-bit vs. 64-bit Development


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 1: Foundations 4

Coding Conventions
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

C++ Usage

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Handling API Errors


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Defining Custom Error Codes

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Windows Version


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Getting the Windows Version

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 1: Foundations 5

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 2: Objects and Handles
Windows is an object-based operating system, exposing various types of objects (usually referred
to as kernel Objects), that provide the bulk of the functionality in Windows. Example object types
are processes, threads and files. In this chapter we’ll discuss the general theory related to kernel
objects without too much details of any specific object type. The following chapters will go into
details of many of these types.

In this chapter:

• Kernel Objects
• Handles
• Creating Objects
• Object Names
• Sharing Kernel Objects
• Private Object Namespaces

Kernel Objects
The Windows kernel exposes various types of objects for use by user-mode processes, the kernel
itself and kernel-mode drivers. Instances of these types are data structures in system (kernel)
space, created and managed by the Object Manager (part of the Executive) when requested to do
so by user or kernel code. kernel objects are reference counted, so only when the last reference
to the object is released will the object be destroyed and freed from memory.
There are quite a few object types supported by the Windows kernel. To get a peek, run the
WinObj tool from Sysinternals (elevated) and locate the ObjectTypes directory. Figure 2-1 shows
what this looks like. These types can be cataloged based on their visibility and usage:

• Types that are exported to user-mode via the Windows API. Examples: mutex, semaphore,
file, process, thread, timer. This book discusses many of these object types.
Chapter 2: Objects and Handles 7

• Types that are not exported to user mode, but are documented in the Windows Driver Kit
(WDK) for use by device driver writers. Examples: device, driver, callback.
• Types that are not documented even in the WDK (at least at the time of writing). These
object types are for use by the kernel itself only. Examples: partition, keyed event, core
messaging.

Figure 2-1: Object types

The main attributes of a kernel object are depicted in figure 2-2.


Chapter 2: Objects and Handles 8

Figure 2-2: Kernel Object Attributes

Since kernel objects reside in system space, they cannot be accessed directly from user mode.
Applications must use an indirect mechanism to access kernel objects, known as handles. Handles
provide at least the following benefits:

• Any change in the object type’s data structure in a future Windows release will not affect
any client.
• Access to the object can be controlled through security access checks.
• Handles are private to a process, so having a handle to a particular object in one process
means nothing in another process context.

Kernel objects are reference counted. The Object Manager maintains a handle count and a pointer
count, the sum of which is the total reference count for an object (direct pointers can be obtained
from kernel mode). Once an object used by a user mode client is no longer needed, the client
code should close the handle used to access the object by calling CloseHandle. From that point
on, the code should consider the handle to be invalid. Trying to access the object through the
closed handle will fail, with GetLastError returning ERROR_INVALID_HANDLE (6). The client
does not know, in the general case, whether the object has been destroyed or not. The Object
Manager will delete the object if its reference drops to zero.
Handle values are multiples of 4, where the first valid handle is 4; Zero is never a valid handle
value. This scheme does not change on 64 bit systems.
A handle is logically an index to an array of entries in a handle table maintained on a process by
process basis, that points logically to a kernel object residing in system space. There are various
Create* and Open* functions to create/open objects and retrieve back handles to these objects.
Chapter 2: Objects and Handles 9

If the object cannot be created or opened, the returned handle is in most cases NULL (0). One
notable exception to this rule is the CreateFile function that returns INVALID_HANDLE_VALUE
(-1) if it fails.
For example, the CreateMutex function allows creating a new mutex or opening a mutex by
name (depending whether the mutex with that name exists). If successful, the function returns a
handle to the mutex. A return value of zero means an invalid handle (and a function call failure).
The OpenMutex function, on the other hand, tries to open a handle to a named mutex. If the
mutex with that name does not exist, the function fails.
If the function succeeds and a name was provided, the returned handle can be to a new mutex
or to an existing mutex with that name. The code can check this by calling GetLastError and
comparing the result to ERROR_ALREADY_EXISTS. If it is, then it’s not a new object, but rather
another handle to an existing object. This is one of those rare cases where GetLastError can be
called even if the API in question succeeded.

Running a Single Instance Process

One fairly well-known usage for the ERROR_ALREADY_EXIST case is limiting an executable to
have a single process instance. Normally, if you double-click an executable in Explorer, a new
process is spawned based on that executable. If you repeat this operation, another process is
created based on the same executable. What if you wanted to prevent the second process from
launching, or at least have it shut down if it detects another process instance with the same
executable already running.
The trick is using some named kernel object (a mutex is usually employed, although any named
object type can be used instead), where an object with a particular name is created. If the object
already exists, there must be another instance already running, so the process can shut down
(possibly notifying its sibling of that fact).
The SingleInstance demo application demonstrates how this can be achieved. It’s a dialog-based
application built with WTL. Figure 2-3 shows what this application looks like running. If you
try launching more instances of this application, you’ll find that the first window logs messages
coming from the new process instance that then exits.
Chapter 2: Objects and Handles 10

Figure 2-3: The Single Instance application

In the WinMain function, we create the mutex first. If this fails, then something is very wrong
and we bail out.

HANDLE hMutex = ::CreateMutex(nullptr, FALSE, L"SingleInstanceMutex");


if (!hMutex) {
CString text;
text.Format(L"Failed to create mutex (Error: %d)", ::GetLastError());
::MessageBox(nullptr, text, L"Single Instance", MB_OK);
return 0;
}

Failure to create the mutex should be extremely rare. The most likely scenario for failure is that
another kernel object (which is not a mutex) with that same name already exists.
Now that we get a proper handle to the mutex, the only question is whether the mutex was
actually created or we received another handle to an existing mutex (presumably created by a
previous instance of this executable):

if (::GetLastError() == ERROR_ALREADY_EXISTS) {
NotifyOtherInstance();
return 0;
}

If the object existed prior to the CreateMutex call, then we call a helper function that sends some
message to the existing instances and exits. Here is NotifyOtherInstance:
Chapter 2: Objects and Handles 11

#define WM_NOTIFY_INSTANCE (WM_USER + 100)

void NotifyOtherInstance() {
auto hWnd = ::FindWindow(nullptr, L"Single Instance");
if (!hWnd) {
::MessageBox(nullptr, L"Failed to locate other instance window",
L"Single Instance", MB_OK);
return;
}

::PostMessage(hWnd, WM_NOTIFY_INSTANCE, ::GetCurrentProcessId(), 0);


::ShowWindow(hWnd, SW_NORMAL);
::SetForegroundWindow(hWnd);
}

The function searches for the existing window with the FindWindow function and uses the
window caption as the search criteria. This is not ideal in the general case, but it’s good enough
for this sample.
Once the window is located, we send a custom message to the window with the current process
ID as an argument. This shows up in the dialog’s list box.
The final piece of the puzzle is handling the WM_NOTIFY_INSTANCE message by the dialog. In
WTL, window messages are mapped to functions using macros. The message map of the dialog
class (CMainDlg) in MainDlg.h is repeated here:

BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_NOTIFY_INSTANCE, OnNotifyInstance)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()

The custom message is mapped to the OnNotifyInstance member function, implemented like
so:
Chapter 2: Objects and Handles 12

LRESULT CMainDlg::OnNotifyInstance(UINT, WPARAM wParam, LPARAM, BOOL &) {


CString text;
text.Format(L"Message from another instance (PID: %d)", wParam);

AddText(text);
return 0;
}

The process ID is extracted from the wParam parameter and some text is added to the list box
with the AddText helper function:

void CMainDlg::AddText(PCWSTR text) {


CTime dt = CTime::GetCurrentTime();
m_List.AddString(dt.Format(L"%T") + L": " + text);
}

m_List is of type CListBox, a WTL wrapper for a Windows list box control.

Handles
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Pseudo Handles

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

RAII for Handles

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Using WIL

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 2: Objects and Handles 13

Creating Objects
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Object Names
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sharing Kernel Objects


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sharing by Name

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sharing by Handle Duplication

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Private Object Namespaces


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Bonus: WIL Wrappers for Private Namespaces

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 2: Objects and Handles 14

Other Objects and Handles


Kernel objects are interesting in the context of system programming, and are the focus of this
book. There are other common objects used in Windows, namely user objects and GDI objects.
The following is a brief description of these objects and handles to such objects.
Task Manager can show the number of such objects for each process by adding the User Objects
and GDI Objects columns, as shown in figure 2-21.

Figure 2-21: User and GDI object count

User Objects
User objects are Windows (HWND), Menus (HMENU) and hooks (HHOOK). Handles to these objects
have the following attributes:

• No reference counting. The first caller that destroys a user object - it’s gone.
Chapter 2: Objects and Handles 15

• Handle values are scoped under a Window Station. A Window Station contains a clipboard,
desktops and atom table. This means handles to these objects can be passed freely among
all applications sharing a desktop, for instance.

The terms Window Station and desktop will be discussed later in this book. Atom tables will
not, as these are related to the UI subsystem in Windows, which is not the focus of this book.

GDI Objects

The Graphics Device Interface (GDI) is the original graphics API in Windows and is still used
today, even though there are richer and better APIs (Direct2D for example). Example GDI objects:
device context (HDC), pen (HPEN), brush (HBRUSH), bitmap (HBITMAP) and others. Here are their
attributes:

• No reference counting.
• Handles are valid only in the process in which they are created.
• Cannot be shared between processes.

Summary
In this chapter, we looked at kernel objects and the ways they can be accessed and shared by
using handles. We did not look at any specific object type too closely, as these will be discussed
in other chapters in more detail. In the next chapter, we’ll delve into the most well-known of all
kernel objects - the process.
Chapter 3: Processes
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Basics
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Processes in Process Explorer


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Creation
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The main Functions


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Environment Variables


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Creating Processes
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 3: Processes 17

Handle Inheritance
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Drive Directories


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process (and Thread) Attributes


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Protected and PPL Processes


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

UWP Processes
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Minimal and Pico Processes


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Termination
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Enumerating Processes
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 3: Processes 18

Using EnumProcesses

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Using the Toolhelp Functions

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Using the WTS Functions

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Using the Native API

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 4: Jobs
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Introduction to Jobs
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Creating Jobs
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Nested Jobs
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Querying Job Information


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Job Accounting Information


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Querying for Job Process List


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 4: Jobs 20

Setting Job Limits


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

CPU Rate Limit

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

User Interface Limits

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Job Notifications
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Silos
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 5: Threads Basics
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Introduction
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sockets, Cores, and Logical Processors


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Creating and Managing Threads


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Primes Counter Application


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Running Primes Counter


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Terminating Threads
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 5: Threads Basics 22

A Thread’s Stack
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

A Thread’s Name
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

What About the C++ Standard Library?


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 6: Thread Scheduling
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Priorities
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Scheduling Basics
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Single CPU Scheduling


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Quantum
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Processor Groups
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Multiprocessor Scheduling
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 6: Thread Scheduling 24

Affinity
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Ideal Processor

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Hard Affinity

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

CPU Sets

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

CPU Sets vs. Hard Affinity


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

System CPU Sets


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Revised Scheduling Algorithm


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Observing Scheduling
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 6: Thread Scheduling 25

General Scheduling
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Hard Affinity
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

CPU Sets
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Background Mode
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Priority Boosts
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Completing I/O Operations


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Foreground Process
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

GUI Thread Wakeup


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 6: Thread Scheduling 26

Starvation Avoidance

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Other Aspects of Scheduling


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Suspend and Resume

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Suspending and Resuming a Process

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sleeping and Yielding

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 7: Thread Synchronization
(Intra-Process)
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Synchronization Basics
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Atomic Operations
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Simple Increment Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Interlocked Family of Functions

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Critical Sections
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 7: Thread Synchronization (Intra-Process) 28

Locks and RAII


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Deadlocks
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The MD5 Calculator Application


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Calculating MD5 Hash

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Hash Cache

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Image Loads Notifications

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Event Parsing

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 7: Thread Synchronization (Intra-Process) 29

Putting it All Together

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Reader Writer Locks


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

RAII Wrappers

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

MD5 Calculator 2

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Condition Variables
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Queue Demo Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Waiting on Address
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 7: Thread Synchronization (Intra-Process) 30

Synchronization Barriers
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

What About the C++ Standard Library?


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 8: Thread Synchronization
(Inter-Process)
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Dispatcher Objects
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Succeeding a Wait

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Mutex
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Mutex Demo Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Abandoned Mutex

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 8: Thread Synchronization (Inter-Process) 32

The Semaphore
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Queue Demo Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Event
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Working with Events

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Waitable Timer


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Other Wait Functions


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Waiting in Alertable State

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 8: Thread Synchronization (Inter-Process) 33

Waiting on GUI Threads

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Waiting for an Idle GUI Thread

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Signaling and Waiting Atomically

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 9: Thread Pools
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Why Use a Thread Pool?


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Pool Work Callbacks


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Simple Work Application


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Controlling a Work Item


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The MD5 Calculator Application


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Pool Wait Callbacks


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 9: Thread Pools 35

Thread Pool Timer Callbacks


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Simple Timer Sample

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Pool I/O Callbacks


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Pool Instance Operations


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Callback Environment


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Private Thread Pools


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Cleanup Groups
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 9: Thread Pools 36

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 10: Advanced Threading
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Local Storage


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Dynamic TLS
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Static TLS
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Remote Threads
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Breakin Application


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Enumeration
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 10: Advanced Threading 38

The thlist Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Caches and Cache Lines


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Wait Chain Traversal


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Deadlock Detector Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Asynchronous WCT Sessions

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

User Mode Scheduling


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Init Once Initialization


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 10: Advanced Threading 39

Debugging Multithreaded Applications


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Breakpoints

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Parallel Stacks

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Parallel Watch

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Thread Names

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Exercises
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 11: File and Device I/O
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The I/O System


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The CreateFile Function


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Working with Symbolic Links


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Path Length
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Directories
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Files
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 11: File and Device I/O 41

Setting File Information

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Synchronous I/O
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Asynchronous I/O
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

ReadFileEx and WriteFileEx

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Manually Queued APC

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

I/O Completion Ports


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Bulk Copy Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 11: File and Device I/O 42

Using the Thread Pool for I/O Completion

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Bulk Copy 2 Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

I/O Cancellation
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Devices
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Pipes and Mailslots


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Pipes

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Transactional NTFS
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 11: File and Device I/O 43

File Search and Enumeration


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

NTFS Streams
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 12: Memory Management
Fundamentals
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Basic Concepts
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Address Space


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Page States
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Address Space Layout


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

32-bit Systems
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

64-bit Systems
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 12: Memory Management Fundamentals 45

Address Space Usage

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Memory Counters
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Memory Counters

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Process Memory Map


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Page Protection
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Enumerating Address Space Regions


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

The Simple VMMap Application

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.
Chapter 12: Memory Management Fundamentals 46

More Address Space Information

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Sharing Memory
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Page Files
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

WOW64
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

WOW64 Redirections

This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Virtual Address Translation


This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

Summary
This content is not available in the sample book. The book can be purchased on Leanpub at
http://leanpub.com/windows10systemprogramming.

You might also like