HalpInitializeGenericErrorSource

NTSTATUS __stdcall HalpInitializeGenericErrorSource(UINT64 Phase, _WHEA_ERROR_SOURCE_DESCRIPTOR *ErrorSource){
  int v4; 
  int v5; 
  _QWORD *v6; 
  _QWORD *v7; 
  int v8; 
  _QWORD *v9; 
  _QWORD *v10; 
  int v11; 
  _QWORD *v12; 
  _QWORD *v13; 
  int v14; 
  _QWORD *v15; 
  _LARGE_INTEGER *v16; 
  VOID *v17; 
  _QWORD *v18; 
  int inited; 
  _QWORD *v20; 
  _QWORD *v21; 
  bool v22; 
  VOID *ServiceContext; 

  ServiceContext = 0i64;
  if( !(_DWORD)Phase )
    return 0;
  if( !HalpGenericInitDone )
  {
    *(&CmpDummyThreadEvent + 1001) = (char *)&CmpDummyThreadEvent + 8000;
    *(&CmpDummyThreadEvent + 1000) = (char *)&CmpDummyThreadEvent + 8000;
    qword_140C49AF8 = (__int64)&qword_140C49AF0;
    qword_140C49AF0 = &qword_140C49AF0;
    qword_140C49AD8 = (__int64)&qword_140C49AD0;
    qword_140C49AD0 = &qword_140C49AD0;
    HalpGenericInitDone = 1;
    qword_140C49AC8 = &qword_140C49AC0;
    qword_140C49AC0 = (INT64)&qword_140C49AC0;
    qword_140C49AE8 = &qword_140C49AE0;
    qword_140C49AE0 = (INT64)&qword_140C49AE0;
    *(&CmpDummyThreadEvent + 1005) = (char *)&CmpDummyThreadEvent + 8032;
    *(&CmpDummyThreadEvent + 1004) = (char *)&CmpDummyThreadEvent + 8032;
    *(&CmpDummyThreadEvent + 1003) = (char *)&CmpDummyThreadEvent + 8016;
    *(&CmpDummyThreadEvent + 1002) = (char *)&CmpDummyThreadEvent + 8016;
  }
  switch( ErrorSource->Info.XpfMceDescriptor.Banks[0].BankNumber )
  {
    case 0u:
      if( ErrorSource->Type == WheaErrSrcTypeGenericV2 )
        inited = HalpInitGenericErrorSourceEntryV2((__int64)ErrorSource, &ServiceContext);
      else
        inited = HalpInitGenericErrorSourceEntry((__int64)ErrorSource, &ServiceContext);
      v4 = inited;
      v20 = ServiceContext;
      *((_QWORD *)ServiceContext + 2) = KUSER_SHARED_DATA.TickCountQuad;
      if( inited < 0 )
        return v4;
      v21 = qword_140C49AC8;
      if( (INT64 *)*qword_140C49AC8 == &qword_140C49AC0 )
      {
        v22 = HalpGenericPollingInitDone == 0;
        *v20 = &qword_140C49AC0;
        v20[1] = v21;
        *v21 = v20;
        qword_140C49AC8 = v20;
        if( v22 )
        {
          HalpGenericPollingInitDone = 1;
          HalpInitGenericErrorSourcePollingRoutine();
        }
        goto LABEL_55;
      }
      goto LABEL_52;
    case 4u:
      if( ErrorSource->Type == WheaErrSrcTypeGenericV2 )
        v14 = HalpInitGenericErrorSourceEntryV2((__int64)ErrorSource, &ServiceContext);
      else
        v14 = HalpInitGenericErrorSourceEntry((__int64)ErrorSource, &ServiceContext);
      v4 = v14;
      if( v14 >= 0 )
      {
        v15 = ServiceContext;
        v16 = (_LARGE_INTEGER *)*((_QWORD *)ServiceContext + 5);
        if( v16->QuadPart == -1
          || (v17 = MmMapIoSpaceEx(*v16, *((unsigned int *)ServiceContext + 12), 0x204ui64), (v15[7] = v17) == 0i64) )
        {
          ExFreePoolWithTag(v15, 0x206C6148u);
          return -1073741823;
        }
        v18 = qword_140C49AE8;
        if( (INT64 *)*qword_140C49AE8 != &qword_140C49AE0 )
          goto LABEL_52;
        *v15 = &qword_140C49AE0;
        v15[1] = v18;
        *v18 = v15;
        qword_140C49AE8 = v15;
      }
      if( !HalpGenericNmiInitDone )
        HalpGenericNmiInitDone = 1;
      goto LABEL_55;
    case 8u:
      if( ErrorSource->Type == WheaErrSrcTypeGenericV2 )
        v11 = HalpInitGenericErrorSourceEntryV2((__int64)ErrorSource, &ServiceContext);
      else
        v11 = HalpInitGenericErrorSourceEntry((__int64)ErrorSource, &ServiceContext);
      v4 = v11;
      if( v11 >= 0 )
      {
        v12 = (_QWORD *)*(&CmpDummyThreadEvent + 1005);
        if( (_UNKNOWN *)**(&CmpDummyThreadEvent + 1005) != (_UNKNOWN *)((char *)&CmpDummyThreadEvent + 8032) )
          goto LABEL_52;
        v13 = ServiceContext;
        *(_QWORD *)ServiceContext = (char *)&CmpDummyThreadEvent + 8032;
        v13[1] = v12;
        *v12 = v13;
        *(&CmpDummyThreadEvent + 1005) = v13;
      }
      if( !HalpGenericSeaInitDone )
        HalpGenericSeaInitDone = 1;
      goto LABEL_55;
    case 9u:
      if( ErrorSource->Type == WheaErrSrcTypeGenericV2 )
        v8 = HalpInitGenericErrorSourceEntryV2((__int64)ErrorSource, &ServiceContext);
      else
        v8 = HalpInitGenericErrorSourceEntry((__int64)ErrorSource, &ServiceContext);
      v4 = v8;
      if( v8 >= 0 )
      {
        v9 = (_QWORD *)*(&CmpDummyThreadEvent + 1003);
        if( (_UNKNOWN *)**(&CmpDummyThreadEvent + 1003) != (_UNKNOWN *)((char *)&CmpDummyThreadEvent + 8016) )
          goto LABEL_52;
        v10 = ServiceContext;
        *(_QWORD *)ServiceContext = (char *)&CmpDummyThreadEvent + 8016;
        v10[1] = v9;
        *v9 = v10;
        *(&CmpDummyThreadEvent + 1003) = v10;
      }
      if( !HalpGenericSeiInitDone )
        HalpGenericSeiInitDone = 1;
      goto LABEL_55;
    case 0xAu:
      if( ErrorSource->Type == WheaErrSrcTypeGenericV2 )
        v5 = HalpInitGenericErrorSourceEntryV2((__int64)ErrorSource, &ServiceContext);
      else
        v5 = HalpInitGenericErrorSourceEntry((__int64)ErrorSource, &ServiceContext);
      v4 = v5;
      if( !HalpGenericPeiInitDone )
        HalpGenericPeiInitDone = 1;
      if( v5 < 0 )
        return v4;
      v6 = ServiceContext;
      v4 = HalpRegisterPeiErrorSource(ServiceContext);
      if( v4 < 0 )
        return v4;
      v7 = (_QWORD *)*(&CmpDummyThreadEvent + 1001);
      if( (_UNKNOWN *)**(&CmpDummyThreadEvent + 1001) == (_UNKNOWN *)((char *)&CmpDummyThreadEvent + 8000) )
      {
        *v6 = (char *)&CmpDummyThreadEvent + 8000;
        v6[1] = v7;
        *v7 = v6;
        *(&CmpDummyThreadEvent + 1001) = v6;
LABEL_55:
        if( v4 >= 0 )
          HalpGenInitialRead((INT64)ErrorSource);
        return v4;
      }
LABEL_52:
      __fastfail(3u);
  }
  return -1073741637;
}

Referenced by:

HalpInitializeErrSrc