ExHandleLogBadReference

VOID __stdcall ExHandleLogBadReference(_HANDLE_TABLE *HandleTable, VOID *Handle, INT8 PreviousMode){
  if( (HandleTable->Flags & 2) != 0 )
  {
    if( HandleTable->DebugInfo )
      ExpUpdateDebugInfo(HandleTable, (_ETHREAD *)KeGetCurrentThread(), Handle, 3ui64);
    if( PreviousMode == 1 )
    {
      if( KeGetCurrentThread()->ApcStateIndex != 1
        && HandleTable == KeGetCurrentThread()->ApcState.Process->ObjectTable )
      {
        if( (NtGlobalFlag & 0x100) != 0 )
          DbgPrintEx(
            0x5Du,
            0,
            "AVRF: Invalid handle %p in process %p \n",
            Handle,
            KeGetCurrentThread()->ApcState.Process);
        KeRaiseUserException(3221225480i64);
      }
    }
    else if( (NtGlobalFlag & 0x40000000) != 0 )
    {
      KeBugCheckEx(0x93u, Handle, HandleTable, 0i64, (PVOID)1);
    }
  }
}

Referenced by:

AlpcpLookupMessage
NtClose
ObReferenceFileObjectForWrite
ObWaitForMultipleObjects
ObpCloseHandle
ObpReferenceObjectByHandleWithTag