34 &PhHandleTableLevel0FreeList,
39 &PhHandleTableLevel1FreeList,
52 #ifdef PH_HANDLE_TABLE_SAFE
66 handleTable->
Count = 0;
69 #ifdef PH_HANDLE_TABLE_SAFE
88 handleTable->
Flags = 0;
100 ULONG_PTR tableValue;
108 tableValue = HandleTable->TableValue;
110 tableValue -= tableLevel;
176 value = HandleTableEntry->Value;
201 value = HandleTableEntry->Value;
209 (PVOID *)&HandleTableEntry->Value,
210 (PVOID)(value - PH_HANDLE_TABLE_ENTRY_LOCKED),
227 _interlockedbittestandset(
228 (PLONG)&HandleTableEntry->Value,
253 entry->
TypeAndValue.Value = HandleTableEntry->TypeAndValue.Value;
254 entry->
Value2 = HandleTableEntry->Value2;
273 if (!HandleTableEntry)
277 if (!HandleTableEntry)
285 (PVOID *)&HandleTableEntry->Value,
320 _In_opt_ PVOID Context
352 _In_opt_ PVOID Context
383 _Out_writes_bytes_opt_(BufferLength) PVOID Buffer,
384 _In_ ULONG BufferLength,
385 _Out_opt_ PULONG ReturnLength
388 NTSTATUS status = STATUS_SUCCESS;
391 switch (InformationClass)
399 basicInfo->
Count = HandleTable->Count;
400 basicInfo->
Flags = HandleTable->Flags;
405 status = STATUS_INFO_LENGTH_MISMATCH;
417 flagsInfo->
Flags = HandleTable->Flags;
421 status = STATUS_INFO_LENGTH_MISMATCH;
428 status = STATUS_INVALID_INFO_CLASS;
434 *ReturnLength = returnLength;
442 _In_reads_bytes_(BufferLength) PVOID Buffer,
443 _In_ ULONG BufferLength
446 NTSTATUS status = STATUS_SUCCESS;
448 switch (InformationClass)
457 flags = flagsInfo->
Flags;
460 HandleTable->Flags = flags;
462 status = STATUS_INVALID_PARAMETER;
466 status = STATUS_INFO_LENGTH_MISMATCH;
471 status = STATUS_INVALID_INFO_CLASS;
479 _Out_ PULONG HandleValue
491 freeValue = HandleTable->FreeValue;
499 freeValue = HandleTable->FreeValue;
522 freeValue = HandleTable->FreeValue;
555 if (HandleTable->FreeValue != freeValue)
577 oldFreeValue = _InterlockedCompareExchange(
578 &HandleTable->FreeValue,
585 if (oldFreeValue == freeValue)
589 _InterlockedIncrement((PLONG)&HandleTable->Count);
591 *HandleValue = freeValue;
598 _In_ ULONG HandleValue,
606 _InterlockedDecrement((PLONG)&HandleTable->Count);
608 flags = HandleTable->Flags;
618 freeList = &HandleTable->FreeValue;
622 freeList = &HandleTable->FreeValueAlt;
627 oldValue = *freeList;
628 HandleTableEntry->NextFreeValue = oldValue;
630 if (_InterlockedCompareExchange(
643 _In_ BOOLEAN Initialize
646 ULONG_PTR tableValue;
658 tableValue = HandleTable->TableValue;
660 tableValue -= tableLevel;
670 #ifdef PH_HANDLE_TABLE_SAFE
680 #ifdef PH_HANDLE_TABLE_SAFE
691 tableValue = (ULONG_PTR)table1 | 1;
693 HandleTable->TableValue = tableValue;
709 #ifdef PH_HANDLE_TABLE_SAFE
723 #ifdef PH_HANDLE_TABLE_SAFE
733 #ifdef PH_HANDLE_TABLE_SAFE
743 #ifdef PH_HANDLE_TABLE_SAFE
757 tableValue = (ULONG_PTR)table2 | 2;
759 HandleTable->TableValue = tableValue;
767 i = HandleTable->NextValue /
783 #ifdef PH_HANDLE_TABLE_SAFE
790 j = HandleTable->NextValue - i *
797 table2[i][j] = table0;
803 #ifdef PH_HANDLE_TABLE_SAFE
810 #ifdef PH_HANDLE_TABLE_SAFE
830 oldNextValue = _InterlockedExchangeAdd(
831 (PLONG)&HandleTable->NextValue,
841 freeValue = HandleTable->FreeValue;
844 if (_InterlockedCompareExchange(
845 &HandleTable->FreeValue,
860 _In_ ULONG HandleValue
863 ULONG_PTR tableValue;
870 if (HandleValue >= HandleTable->NextValue)
875 tableValue = HandleTable->TableValue;
877 tableValue -= tableLevel;
887 entry = &table0[HandleValue];
943 flags = HandleTable->Flags;
949 if (_InterlockedCompareExchange(
950 &HandleTable->FreeValue,
961 index = freeValueAlt;
991 freeValue = HandleTable->FreeValue;
994 if (_InterlockedCompareExchange(
995 &HandleTable->FreeValue,
1004 (flags & PH_HANDLE_TABLE_STRICT_FIFO) &&
1016 _In_ BOOLEAN Initialize
1024 #ifdef PH_HANDLE_TABLE_SAFE
1040 baseValue = HandleTable->NextValue;
1069 #ifdef PH_HANDLE_TABLE_SAFE
1100 #ifdef PH_HANDLE_TABLE_SAFE