KiConnectInterrupt

NTSTATUS __stdcall KiConnectInterrupt(_KINTERRUPT *Interrupt){
  __int64 Vector; 
  char v2; 
  int Irql; 
  char v4; 
  unsigned int Number; 
  unsigned __int8 SynchronizeIrql; 
  _KIDTENTRY64 *v8; 
  char *v9; 
  char *v10; 
  NTSTATUS(__stdcall *v12)(); 
  void(__fastcall *v13)(); 
  __int64 v14; 
  char OldIrql[8]; 
  char *v16; 
  _GROUP_AFFINITY PreviousAffinity; 

  Vector = Interrupt->Vector;
  v2 = 0;
  Irql = Interrupt->Irql;
  v4 = 0;
  Number = Interrupt->Number;
  OldIrql[0] = 0;
  PreviousAffinity = 0i64;
  if( (unsigned int)Vector > 0xFF || (unsigned __int8)Irql > 0xFu || Irql != (unsigned int)Vector >> 4 && (_BYTE)Irql )
    return -1073741585;
  if( Number >= (unsigned int)KeNumberProcessors_0 )
    return -1073741585;
  SynchronizeIrql = Interrupt->SynchronizeIrql;
  if( SynchronizeIrql < (unsigned __int8)Irql )
  {
    if( SynchronizeIrql )
      return -1073741585;
  }
  KiAcquireInterruptConnectLock(Number, (UINT8 *)OldIrql, &PreviousAffinity);
  v8 = &KeGetPcr()->IdtBase[Vector];
  LOWORD(v16) = v8->OffsetLow;
  WORD1(v16) = v8->OffsetMiddle;
  HIDWORD(v16) = v8->OffsetHigh;
  if( !Interrupt->Connected )
  {
    v9 = (char *)KiIsrThunkShadow;
    if( !KiKvaShadow )
      v9 = (char *)KxUnexpectedInterrupt0;
    if( v16 == &v9[8 * Vector] )
    {
      v10 = (char *)KeGetCurrentPrcb()->InterruptObject[Vector];
      if( !v10 )
      {
        if( !Interrupt->SynchronizeIrql )
        {
          Interrupt->InterruptListEntry.Blink = &Interrupt->InterruptListEntry;
          Interrupt->InterruptListEntry.Flink = &Interrupt->InterruptListEntry;
          Interrupt->DispatchAddress = (void(__fastcall *)())KiChainedDispatch;
        }
        v4 = 1;
        Interrupt->Connected = 1;
        goto LABEL_14;
      }
      if( (unsigned int)Vector >= 0x30 )
      {
        v2 = 1;
        if( Interrupt->Mode == *((_DWORD *)v10 + 27) )
        {
          if( Interrupt->ShareVector )
          {
            if( v10[100] )
            {
              if( (NTSTATUS(__stdcall *)())Interrupt->DispatchAddress == KiInterruptDispatch )
              {
                v12 = (NTSTATUS(__stdcall *)())*((_QWORD *)v10 + 10);
                if( v12 == KiInterruptDispatch || v12 == KiChainedDispatch )
                {
                  Interrupt->Connected = 1;
                  v4 = 1;
                  if( *((NTSTATUS(__stdcall **)())v10 + 10) != KiChainedDispatch )
                  {
                    *((_QWORD *)v10 + 10) = KiChainedDispatch;
                    *((_QWORD *)v10 + 2) = v10 + 8;
                    *((_QWORD *)v10 + 1) = v10 + 8;
                  }
                  KiInsertInterruptObjectOrdered((PROCESSOR_NUMBER *)v10, (INT64)Interrupt);
                  if( !*(_BYTE *)(v14 + 93) )
                  {
                    if( Interrupt->SynchronizeIrql )
                    {
                      Interrupt->DispatchAddress = v13;
LABEL_14:
                      KeGetCurrentPrcb()->InterruptObject[Vector] = Interrupt;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  __writecr8((unsigned __int8)OldIrql[0]);
  KeRevertToUserGroupAffinityThread(&PreviousAffinity);
  if( v4 )
    return v2 != 0 ? 0x127 : 0;
  return -1073741585;
}

Referenced by:

KeConnectInterrupt