23 #define _PH_REF_PRIVATE
36 static ULONG PhpAutoPoolTlsIndex;
39 LIST_ENTRY PhDbgObjectListHead;
41 PPH_CREATE_OBJECT_HOOK PhDbgCreateObjectHook = NULL;
44 #define REF_STAT_UP(Name) PHLIB_INC_STATISTIC(Name)
61 &PhObjectSmallFreeList,
69 PhObjectTypeObject = &dummyObjectType;
70 PhObjectTypeTable[0] = &dummyObjectType;
81 PhpAutoPoolTlsIndex = TlsAlloc();
83 if (PhpAutoPoolTlsIndex == TLS_OUT_OF_INDEXES)
84 return STATUS_INSUFFICIENT_RESOURCES;
86 return STATUS_SUCCESS;
98 _In_ SIZE_T ObjectSize,
102 NTSTATUS status = STATUS_SUCCESS;
109 _InterlockedIncrement((PLONG)&ObjectType->NumberOfObjects);
113 objectHeader->
TypeIndex = ObjectType->TypeIndex;
120 USHORT capturedFrames;
122 capturedFrames = RtlCaptureStackBackTrace(1, 16, objectHeader->StackBackTrace, NULL);
124 &objectHeader->StackBackTrace[capturedFrames],
126 sizeof(objectHeader->StackBackTrace) - capturedFrames *
sizeof(PVOID)
131 InsertTailList(&PhDbgObjectListHead, &objectHeader->ObjectListEntry);
135 PPH_CREATE_OBJECT_HOOK dbgCreateObjectHook;
137 dbgCreateObjectHook = PhDbgCreateObjectHook;
139 if (dbgCreateObjectHook)
169 _InterlockedIncrement(&objectHeader->
RefCount);
190 assert(!(RefCount < 0));
194 oldRefCount = _InterlockedExchangeAdd(&objectHeader->
RefCount, RefCount);
196 return oldRefCount + RefCount;
246 newRefCount = _InterlockedDecrement(&objectHeader->
RefCount);
250 if (newRefCount == 0)
285 _In_ BOOLEAN DeferDelete
292 assert(!(RefCount < 0));
297 oldRefCount = _InterlockedExchangeAdd(&objectHeader->
RefCount, -RefCount);
298 newRefCount = oldRefCount - RefCount;
301 if (newRefCount == 0)
313 else if (newRefCount < 0)
388 NTSTATUS status = STATUS_SUCCESS;
401 objectType->
Flags = (USHORT)Flags;
405 objectType->
Name = Name;
408 PhObjectTypeTable[objectType->
TypeIndex] = objectType;
414 if (Flags & PH_OBJECT_TYPE_USE_FREE_LIST)
419 Parameters->FreeListCount
438 Information->Name = ObjectType->Name;
439 Information->NumberOfObjects = ObjectType->NumberOfObjects;
440 Information->Flags = ObjectType->Flags;
441 Information->TypeIndex = ObjectType->TypeIndex;
452 _In_ SIZE_T ObjectSize
474 objectHeader->
Flags = 0;
493 objectType = PhObjectTypeTable[ObjectHeader->TypeIndex];
539 PSLIST_ENTRY oldFirstEntry;
559 PSLIST_ENTRY listEntry;
567 objectHeader = CONTAINING_RECORD(listEntry,
PH_OBJECT_HEADER, DeferDeleteListEntry);
568 listEntry = listEntry->Next;
573 return STATUS_SUCCESS;
607 if (!TlsSetValue(PhpAutoPoolTlsIndex, AutoPool))
612 PPHP_BASE_THREAD_DBG dbg;
614 dbg = (PPHP_BASE_THREAD_DBG)TlsGetValue(PhDbgThreadDbgTlsIndex);
618 dbg->CurrentAutoPool = AutoPool;
636 AutoPool->StaticCount = 0;
637 AutoPool->DynamicCount = 0;
638 AutoPool->DynamicAllocated = 0;
639 AutoPool->DynamicObjects = NULL;
669 if (AutoPool->DynamicObjects)
670 PhFree(AutoPool->DynamicObjects);
686 for (i = 0; i < AutoPool->StaticCount; i++)
689 AutoPool->StaticCount = 0;
691 if (AutoPool->DynamicObjects)
693 for (i = 0; i < AutoPool->DynamicCount; i++)
698 AutoPool->DynamicCount = 0;
702 AutoPool->DynamicAllocated = 0;
703 PhFree(AutoPool->DynamicObjects);
704 AutoPool->DynamicObjects = NULL;
718 _In_opt_ PVOID Object