Post · 1 min read· pp. 916–917

KAFFINITY_EX

The KAFFINITY_EX structure is used by the kernel to represent an arbitrary boolean property per processor. It is essentially a dressing-up of a bitmap that allows one bit per processor. Outside the kernel, the structure is opaque. The kernel exports functions that support a range of operations such as setting, clearing and counting bits. All date from version 6.1 unless otherwise noted:

  • KeAddGroupAffinityEx
  • KeAddProcessorAffinityEx
  • KeAndAffinityEx
  • KeAndGroupAffinityEx
  • KeCheckProcessorAffinityEx
  • KeComplementAffinityEx
  • KeCopyAffinityEx
  • KeCountSetBitsAffinityEx
  • KeFindFirstSetLeftAffinityEx
  • KeFindFirstSetRightAffinityEx (6.3 and higher)
  • KeFirstGroupAffinityEx
  • KeInitializeAffinityEx
  • KeInterlockedClearProcessorAffinityEx
  • KeInterlockedSetProcessorAffinityEx
  • KeIsEmptyAffinityEx
  • KeIsEqualAffinityEx
  • KeIsSingleGroupAffinityEx
  • KeIsSubsetAffinityEx
  • KeOrAffinityEx
  • KeQueryGroupAffinityEx
  • KeRemoveGroupAffinityEx
  • KeRemoveProcessorAffinityEx
  • KeSubtractAffinityEx

Documentation Status

The KAFFINITY_EX structure is not documented. Neither are the functions, though they are declared in the NTOSP.H from the Enterprise edition of the Windows Driver Kit (WDK) for Windows 10 Version 1511.

Layout

The KAFFINITY_EX expands as successive Windows versions allow more processor groups:

VersionSize (x86)Size (x64)
6.10x0C0x28
6.2 to 10.00x0C0xA8

Sizes, offsets, types and names in the table that follows are from Microsoft’s symbol files for the kernel.

OffsetDefinition
0x00USHORT Count;
0x02USHORT Size;
0x04ULONG Reserved;
0x08KAFFINITY Bitmap [MAX_PROC_GROUPS];

Here, a macro, MAX_PROC_GROUPS, is presumed for the maximum number of processor groups:

  • 1 for 32-bit Windows;
  • 4 for 64-bit Windows in version 6.1;
  • 20 for 64-bit Windows in version 6.2 and higher.

The Count and Size count processor groups. They are initially 1 and MAX_PROC_GROUPS. The Count grows, up to the Size, as bits get set further into the bitmap.