//
// Remove handle table entry from head of free list.
//
p = HandleTable->FreeHandles;
HandleTable->FreeHandles = p->NextFree;
//
// Clear free list link field, which also leaves the handle allocated bit
// clear. This allows the caller to mark it is allocated after they are
// done filling in their portion.
//
p->NextFree = NULL;
//
// If requested, return the index of this handle table entry
//
if (ARGUMENT_PRESENT( HandleIndex )) {
*HandleIndex = (ULONG) (((PCHAR)p - (PCHAR)HandleTable->CommittedHandles) /
HandleTable->SizeOfHandleTableEntry);
}
//
// Return a pointer to the handle table entry.
//
return p;
}
BOOLEAN
RtlFreeHandle(
IN PRTL_HANDLE_TABLE HandleTable,
IN PRTL_HANDLE_TABLE_ENTRY Handle
)
{
#if DBG
if (!RtlIsValidHandle( HandleTable, Handle )) {
DbgPrint( "RTL: RtlFreeHandle( %lx ) - invalid handle\n", Handle );
if (NtCurrentPeb()->BeingDebugged) {
DbgBreakPoint();
}
return FALSE;
}
#endif
BOOLEAN
RtlIsValidIndexHandle(
IN PRTL_HANDLE_TABLE HandleTable,
IN ULONG HandleIndex,
OUT PRTL_HANDLE_TABLE_ENTRY *Handle
)
{
PRTL_HANDLE_TABLE_ENTRY p;
p = (PRTL_HANDLE_TABLE_ENTRY)
((PCHAR)HandleTable->CommittedHandles + (HandleIndex * HandleTable->SizeOfHandleTableEntry));
if (RtlIsValidHandle( HandleTable, p )) {
*Handle = p;
return TRUE;
}
else {
return FALSE;
}
}