20#define SizeOfHandle(x) (sizeof(HANDLE) * (x))
21#define INDEX_TO_HANDLE_VALUE(x) ((x) << HANDLE_TAG_BITS)
26#define strtoulptr strtoull
28#define strtoulptr strtoul
64 TableLevel = (
ULONG)(TableBase & 3);
67 PointerArray = (
PVOID*)TableBase;
76 PointerArray = PointerArray[
Handle.HighIndex];
83 HandleArray = PointerArray[
Handle.MidIndex];
216 Level1 = (
PVOID)TableBase;
219 else if (TableLevel == 1)
222 Level2 = (
PVOID)TableBase;
228 if (!Level2[
i])
break;
240 Level3 = (
PVOID)TableBase;
246 if (!Level3[
i])
break;
252 if (!Level3[
i][
j])
break;
301 LockIndex =
Handle.Index % 4;
318 HandleTableEntry->NextFreeTableEntry = OldValue;
363 if (!HandleTableTable)
381 HandleEntry = &HandleTableTable[0];
383 HandleEntry->
Value = 0;
395 HandleEntry->
Value = 0;
403 HandleEntry->
Value = 0;
417 for (
i = 0;
i < 4;
i++)
442 HandleEntry = &
Low[0];
444 HandleEntry->
Value = 0;
460 HandleEntry->
Value = 0;
466 HandleEntry->
Value = 0;
483 if (!Mid)
return NULL;
496 *LowTableEntry =
Low;
507 ULONG NewFree, FirstFree;
519 if (!Mid)
return FALSE;
523 Mid[0] = (
PVOID)TableBase;
529 else if (TableLevel == 1)
532 SecondLevel = (
PVOID)TableBase;
575 else if (TableLevel == 2)
578 ThirdLevel = (
PVOID)TableBase;
589 if (!Mid)
return FALSE;
638 if (NewFree == FirstFree)
break;
656 if (!LastFree)
return LastFree;
659 for (
i = 1;
i < 4;
i++)
686 ULONG OldValue, NewValue, NewValue1;
738 NewHandle->GenericHandleOverlay =
NULL;
751 OldHandle.
Value = OldValue;
766 NewValue = *(
volatile ULONG*)&
Entry->NextFreeTableEntry;
776 if (NewValue1 == OldValue)
845 *NewEntry = *HandleTableEntry;
853 return Handle.GenericHandleOverlay;
868 OldValue = HandleTableEntry->Value;
897 OldValue = *(
volatile LONG_PTR *)&HandleTableEntry->Object;
901 NewValue = OldValue & ~EXHANDLE_TABLE_ENTRY_LOCK_BIT;
913 if (!OldValue)
return FALSE;
972 if (DestroyHandleProcedure)
997 if (!HandleTableEntry)
1003 if (!(HandleTableEntry) ||
1004 !(HandleTableEntry->Object) ||
1005 (HandleTableEntry->NextFreeTableEntry == -2))
1061 if (!HandleTableEntry)
return NULL;
1067 return HandleTableEntry;
1085 if (!NewTable)
return NULL;
1103 NewTable->FirstFree = 0;
1135 *NewEntry = *HandleTableEntry;
1138 if (DupHandleProcedure(
Process,
1206 if (!(HandleTableEntry) ||
1207 !(HandleTableEntry->
Object) ||
1251 EnumHandleProcedure(HandleTableEntry,
1252 Handle.GenericHandleOverlay,
1289 if ((HandleTableEntry->
Object) &&
1296 Result = EnumHandleProcedure(HandleTableEntry,
1297 Handle.GenericHandleOverlay,
1307 if (EnumHandle) *EnumHandle =
Handle.GenericHandleOverlay;
1322#if DBG && defined(KDBG)
1339 ULONG NeededLength = 0;
1363 KdbpPrint(
"Invalid parameter: %s\n", Argv[1]);
1373 if (*endptr !=
'\0')
1375 KdbpPrint(
"Invalid parameter: %s\n", Argv[1]);
1412 KdbpPrint(
"\tObjectHeader: %p\n", ObjectHeader);
1448 while (CurrentKcb !=
NULL)
1460 if (NeededLength <
sizeof(KeyPath))
1464 while (CurrentKcb !=
NULL)
1482 NeededLength -= NameLength;
#define ObpDirectoryObjectType
#define OBJ_NAME_PATH_SEPARATOR
#define InterlockedIncrement
#define InterlockedExchange
#define InterlockedDecrement
struct _CM_KEY_BODY * PCM_KEY_BODY
VOID NTAPI CmpCopyCompressedName(OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
USHORT NTAPI CmpCompressedNameSize(IN PWCHAR Name, IN ULONG Length)
#define NT_SUCCESS(StatCode)
#define InterlockedExchangePointer(Target, Value)
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define KeGetCurrentIrql()
#define InitializeListHead(ListHead)
#define ExInitializePushLock
BOOLEAN(NTAPI * PEX_SWEEP_HANDLE_CALLBACK)(PHANDLE_TABLE_ENTRY HandleTableEntry, HANDLE Handle, PVOID Context)
BOOLEAN(NTAPI * PEX_CHANGE_HANDLE_CALLBACK)(PHANDLE_TABLE_ENTRY HandleTableEntry, ULONG_PTR Context)
#define EXHANDLE_TABLE_ENTRY_LOCK_BIT
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
#define MID_LEVEL_ENTRIES
#define HIGH_LEVEL_ENTRIES
FORCEINLINE VOID ExAcquirePushLockShared(PEX_PUSH_LOCK PushLock)
FORCEINLINE VOID ExReleasePushLockShared(PEX_PUSH_LOCK PushLock)
#define LOW_LEVEL_ENTRIES
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
BOOLEAN(NTAPI * PEX_DUPLICATE_HANDLE_CALLBACK)(IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN PHANDLE_TABLE_ENTRY NewEntry)
FORCEINLINE VOID ExWaitOnPushLock(PEX_PUSH_LOCK PushLock)
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
#define KeGetCurrentThread
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
#define InterlockedExchangeAdd
#define InterlockedCompareExchangePointer
#define InterlockedCompareExchange
POBJECT_TYPE IoFileObjectType
VOID KdbpPrint(_In_ PSTR Format, _In_ ...)
Prints the given string with printf-like formatting.
BOOLEAN NTAPI KdbpGetHexNumber(IN PCHAR pszNum, OUT ULONG_PTR *pulValue)
BOOLEAN ExpKdbgExtHandle(ULONG Argc, PCHAR Argv[])
#define KeLeaveCriticalRegion()
#define KeEnterCriticalRegion()
#define ExFreePoolWithTag(_P, _T)
BOOLEAN(NTAPI * PEX_ENUM_HANDLE_CALLBACK)(_In_ struct _HANDLE_TABLE_ENTRY *HandleTableEntry, _In_ HANDLE Handle, _In_ PVOID Context)
struct _HANDLE_TABLE_ENTRY * PHANDLE_TABLE_ENTRY
#define OBJECT_HEADER_TO_NAME_INFO(h)
VOID NTAPI ExpFreeLowLevelTable(IN PEPROCESS Process, IN PHANDLE_TABLE_ENTRY TableEntry)
PVOID NTAPI ExpAllocateTablePagedPoolNoZero(IN PEPROCESS Process OPTIONAL, IN SIZE_T Size)
PHANDLE_TABLE NTAPI ExpAllocateHandleTable(IN PEPROCESS Process OPTIONAL, IN BOOLEAN NewTable)
ULONG NTAPI ExpMoveFreeHandles(IN PHANDLE_TABLE HandleTable)
VOID NTAPI ExSweepHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_SWEEP_HANDLE_CALLBACK EnumHandleProcedure, IN PVOID Context)
BOOLEAN NTAPI ExChangeHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PEX_CHANGE_HANDLE_CALLBACK ChangeRoutine, IN ULONG_PTR Context)
BOOLEAN NTAPI ExEnumHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure, IN OUT PVOID Context, OUT PHANDLE EnumHandle OPTIONAL)
PVOID NTAPI ExpAllocateTablePagedPool(IN PEPROCESS Process OPTIONAL, IN SIZE_T Size)
VOID NTAPI ExpInitializeHandleTables(VOID)
PHANDLE_TABLE_ENTRY NTAPI ExpLookupHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN EXHANDLE Handle)
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
PHANDLE_TABLE_ENTRY NTAPI ExpAllocateHandleTableEntry(IN PHANDLE_TABLE HandleTable, OUT PEXHANDLE NewHandle)
VOID NTAPI ExRemoveHandleTable(IN PHANDLE_TABLE HandleTable)
VOID NTAPI ExpFreeTablePagedPool(IN PEPROCESS Process OPTIONAL, IN PVOID Buffer, IN SIZE_T Size)
VOID NTAPI ExpFreeHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN EXHANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
PHANDLE_TABLE NTAPI ExCreateHandleTable(IN PEPROCESS Process OPTIONAL)
PHANDLE_TABLE_ENTRY NTAPI ExpAllocateLowLevelTable(IN PHANDLE_TABLE HandleTable, IN BOOLEAN DoInit)
EX_PUSH_LOCK HandleTableListLock
LIST_ENTRY HandleTableListHead
BOOLEAN NTAPI ExpAllocateHandleTableEntrySlow(IN PHANDLE_TABLE HandleTable, IN BOOLEAN DoInit)
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
BOOLEAN NTAPI ExpLockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
#define INDEX_TO_HANDLE_VALUE(x)
VOID NTAPI ExDestroyHandleTable(IN PHANDLE_TABLE HandleTable, IN PVOID DestroyHandleProcedure OPTIONAL)
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
VOID NTAPI ExpBlockOnLockedHandleEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
VOID NTAPI ExpFreeHandleTable(IN PHANDLE_TABLE HandleTable)
PHANDLE_TABLE_ENTRY *NTAPI ExpAllocateMidLevelTable(IN PHANDLE_TABLE HandleTable, IN BOOLEAN DoInit, OUT PHANDLE_TABLE_ENTRY *LowTableEntry)
PHANDLE_TABLE NTAPI ExDupHandleTable(IN PEPROCESS Process, IN PHANDLE_TABLE HandleTable, IN PEX_DUPLICATE_HANDLE_CALLBACK DupHandleProcedure, IN ULONG_PTR Mask)
HANDLE NTAPI PsGetCurrentProcessId(VOID)
HANDLE NTAPI PsGetProcessId(PEPROCESS Process)
#define ObpGetHandleObject(x)
VOID FASTCALL ExWaitForUnblockPushLock(IN PEX_PUSH_LOCK PushLock, IN PVOID WaitBlock)
VOID FASTCALL ExfUnblockPushLock(PEX_PUSH_LOCK PushLock, PVOID CurrentWaitBlock)
VOID FASTCALL ExBlockPushLock(PEX_PUSH_LOCK PushLock, PVOID pWaitBlock)
VOID NTAPI PsReturnProcessPagedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Returns the paged pool quota that the process was taking up.
NTSTATUS NTAPI PsChargeProcessPagedPoolQuota(_In_ PEPROCESS Process, _In_ SIZE_T Amount)
Charges the paged pool quota of a given process.
POBJECT_TYPE MmSectionObjectType
PULONG MinorVersion OPTIONAL
base of all file and directory entries
PCM_NAME_CONTROL_BLOCK NameBlock
struct _CM_KEY_CONTROL_BLOCK * ParentKcb
WCHAR Name[ANYSIZE_ARRAY]
ULONG NextHandleNeedingPool
LIST_ENTRY HandleTableList
struct _LIST_ENTRY * Flink
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
HANDLE GenericHandleOverlay
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
POBJECT_TYPE ExDesktopObjectType
POBJECT_TYPE ExWindowStationObjectType
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION Free
_Must_inspect_result_ typedef _In_ ULONG TableEntry
#define PsGetCurrentProcess