Overview
This documentation covers system-defined constants used in Windows kernel-mode driver development. These constants are essential for interacting with the Windows operating system kernel and its various components. They represent specific values, flags, or enumerations that control the behavior of drivers and system services.
Key Areas
- Memory Management Constants: Definitions related to memory allocation, protection, and caching.
- Object Management Constants: Values used for kernel objects like processes, threads, and events.
- I/O Manager Constants: Flags and codes for I/O request packets (IRPs) and I/O operations.
- Synchronization Constants: Defines for synchronization primitives like mutexes, semaphores, and spin locks.
- Power Management Constants: Values related to system power states and device power management.
- Registry Constants: Defines for interacting with the Windows Registry.
Commonly Used Constants
Memory Management
| Constant Name | Description | Value (Hex) |
|---|---|---|
PAGE_READONLY |
Specifies that memory pages can only be read. | 0x02 |
PAGE_READWRITE |
Specifies that memory pages can be read and written. | 0x04 |
MEM_COMMIT |
Commits a region of pages, making them accessible. | 0x1000 |
MEM_RESERVE |
Reserves a range of the process's virtual address space. | 0x2000 |
I/O Manager Flags
| Constant Name | Description | Value (Hex) |
|---|---|---|
IRP_MJ_CREATE |
Major function code for creating a file or object. | 0x00 |
IRP_MJ_READ |
Major function code for reading data. | 0x02 |
IRP_MJ_WRITE |
Major function code for writing data. | 0x03 |
IO_STACK_LOCATION_SIZE |
Size of an I/O stack location. | Calculated |
Object Types
Constants like IoDriverObjectType, IoFileObjectType, and IoDeviceObjectType are used when creating or referencing kernel objects.
Using Constants in Drivers
System-defined constants are typically defined in header files provided by the Windows Driver Kit (WDK). For example, memory management constants are found in wdm.h or ntddk.h.
When writing driver code, you'll often use these constants in function calls or conditional statements:
// Example: Allocating memory with specific protections
PVOID buffer = MmAllocateContiguousMemory(size, startAddress, alignment);
if (buffer) {
// Set memory protections (example)
NTSTATUS status = IoSetIoControl(DeviceObject, IOCTL_MY_DEVICE_SET_MEMORY_PROTECTION, buffer, size, PAGE_READWRITE, ...);
// ...
}
Tip
Always refer to the latest WDK documentation for the most accurate and up-to-date definitions of system constants. Some constants may be deprecated or have changed behavior across Windows versions.