VslpEnterIumSecureMode

NTSTATUS __fastcall VslpEnterIumSecureMode(UINT8 a1, INT16 a2, INT64 a3, INT64 a4){
  __int16 v4; 
  bool v5; 
  unsigned __int8 CurrentIrql; 
  _BYTE *v8; 
  int v9; 
  __int64 v10; 
  NTSTATUS result; 
  char v12; 
  _ETHREAD *CurrentThread; 
  unsigned __int8 v14; 
  int v15; 
  int v16; 
  UINT64 v17; 
  char v18; 
  INT64 v19; 
  char v20; 
  int v21; 
  _ETHREAD *v22; 
  unsigned int v23; 
  PLARGE_INTEGER Timeout; 
  char v25; 
  char v26; 
  char v27; 
  int v29; 
  __int16 v30[2]; 
  __int16 v31[2]; 
  __int16 v32[2]; 
  __int16 v33[2]; 
  int v34; 
  INT64 v35; 
  EVENT_DATA_DESCRIPTOR EventData; 
  EVENT_DATA_DESCRIPTOR v37; 
  EVENT_DATA_DESCRIPTOR v38; 
  EVENT_DATA_DESCRIPTOR v39; 
  v4 = a1;
  v5 = 0;
  v27 = 0;
  v29 = a3;
  CurrentIrql = 15;
  if( !HvlQueryVsmConnection(0i64) )
    return -1073741667;
  *(_BYTE *)v10 = v4;
  *(_WORD *)(v10 + 2) = (_WORD)v8;
  v35 = *((_QWORD *)KeGetCurrentThread() + 144);
  if( (unsigned __int8)v4 > 2u )
  {
    if( (*((_BYTE *)&PerfGlobalGroupMask + 20) & 8) != 0 )
    {
      EventData.Reserved &= v9;
      v30[1] = (__int16)v8;
      EventData.Ptr = (unsigned __int64)v30;
      v30[0] = v4;
      EventData.Size = 4;
      v20 = 1;
      LODWORD(Timeout) = 4200706;
      EtwTraceKernelEvent(&EventData, 1ui64, 0xA0000008ui64, 0x549u, (UINT64)Timeout);
    }
    else
    {
      v20 = 0;
    }
    HvlSwitchToVsmVtl1(0i64, (INT64 *)a4, (unsigned int)v35);
    if( v20 )
    {
      v37.Reserved = 0;
      v31[1] = a2;
      v31[0] = v4;
      v37.Ptr = (unsigned __int64)v31;
      v37.Size = 4;
      LODWORD(Timeout) = 4200706;
      EtwTraceKernelEvent(&v37, 1ui64, 0xA0000008ui64, 0x54Au, (UINT64)Timeout);
    }
    if( *(char *)(a4 + 1) < 0 )
    {
      __debugbreak();
      *(_BYTE *)(a4 + 1) &= ~0x80u;
    }
    return 0;
  }
  KeAreInterruptsEnabled(v9, v8);
  if( !v12 && VslVsmEnabled )
  {
    CurrentIrql = KeGetCurrentIrql();
    __writecr8(0xFui64);
  }
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v14 = KeGetCurrentIrql();
  v15 = v29;
  if( (_BYTE)v4 == 1 )
  {
    *(_DWORD *)(a4 + 4) = v29;
    goto LABEL_14;
  }
  if( v29 )
  {
LABEL_59:
    *(_DWORD *)(a4 + 4) = v15;
    goto LABEL_13;
  }
  if( v14 < 2u )
  {
    v15 = *((_DWORD *)CurrentThread + 199);
    if( !v15 )
    {
      *(_DWORD *)(a4 + 4) = 0;
      if( VslVsmEnabled )
      {
        result = KeWaitForSingleObject(&VslpIumThreadSemaphore, Executive, 0, 0, 0i64);
        if( result < 0 )
          return result;
        v27 = 1;
      }
      goto LABEL_13;
    }
    v29 = *((_DWORD *)CurrentThread + 199);
    goto LABEL_59;
  }
  *(_DWORD *)(a4 + 4) = 0;
  v29 = 1;
LABEL_13:
  v5 = *((_DWORD *)CurrentThread + 199) == 0;
LABEL_14:
  if( v14 == 1 )
  {
    LOBYTE(v34) = 1;
LABEL_18:
    --*((_WORD *)CurrentThread + 242);
    goto LABEL_19;
  }
  v16 = 0;
  if( !v14 )
    v16 = v5;
  v34 = v16;
  if( (_BYTE)v16 )
    goto LABEL_18;
  while( 1 )
  {
LABEL_19:
    if( (*((_BYTE *)&PerfGlobalGroupMask + 20) & 8) != 0 )
    {
      v32[1] = a2;
      v25 = 1;
      v38.Ptr = (unsigned __int64)v32;
      v32[0] = v4;
      *(_QWORD *)&v38.Size = 4i64;
      LODWORD(Timeout) = 4200706;
      EtwTraceKernelEvent(&v38, 1ui64, 0xA0000008ui64, 0x549u, (UINT64)Timeout);
    }
    else
    {
      v25 = 0;
    }
    HvlSwitchToVsmVtl1(0i64, (INT64 *)a4, (unsigned int)v35);
    if( v25 )
    {
      v33[1] = a2;
      v33[0] = v4;
      v39.Ptr = (unsigned __int64)v33;
      *(_QWORD *)&v39.Size = 4i64;
      LODWORD(Timeout) = 4200706;
      EtwTraceKernelEvent(&v39, 1ui64, 0xA0000008ui64, 0x54Au, (UINT64)Timeout);
    }
    v18 = *(_BYTE *)(a4 + 1);
    if( v18 < 0 )
    {
      __debugbreak();
      *(_BYTE *)(a4 + 1) &= ~0x80u;
      v18 = *(_BYTE *)(a4 + 1);
    }
    if( v18 == 6 )
      break;
    if( v18 == 1 )
      goto LABEL_27;
    if( (_BYTE)v4 == 1 )
    {
      v21 = *(_DWORD *)(a4 + 4);
      v22 = CurrentThread;
      if( !v21 )
        v22 = CurrentThread;
      *((_DWORD *)v22 + 199) = v21;
    }
    else if( !v29 )
    {
      *((_DWORD *)CurrentThread + 199) = *(_DWORD *)(a4 + 4);
    }
    v19 = *(unsigned __int8 *)(a4 + 1);
    switch( *(_BYTE *)(a4 + 1) )
    {
      case 0:
LABEL_46:
        PsDispatchIumService(a4, v19, 0i64, v17);
        break;
      case 2:
        if( !*((_BYTE *)CurrentThread + 562) )
        {
          *(_QWORD *)(a4 + 8) = -1073741776i64;
          break;
        }
LABEL_67:
        v23 = *(unsigned __int16 *)(a4 + 2);
        if( v23 < (unsigned int)xmmword_140E018D0 )
        {
          v26 = *((_BYTE *)CurrentThread + 562);
          if( (_BYTE)v19 == 3 )
          {
            *((_BYTE *)CurrentThread + 562) = 0;
            LOWORD(v23) = *(_WORD *)(a4 + 2);
          }
          *(_QWORD *)(a4 + 8) = (int)VslpDispatchIumSyscall(
                                       (__int64(__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))(KeServiceDescriptorTable
                                                                                              + (*(int *)(KeServiceDescriptorTable + 4i64 * (unsigned __int16)v23) >> 4)),
                                       (_QWORD *)(a4 + 8),
                                       *(_BYTE *)(KeServiceDescriptorTable + 4i64 * (unsigned __int16)v23) & 0xF);
          *((_BYTE *)CurrentThread + 562) = v26;
        }
        else
        {
          *(_QWORD *)(a4 + 8) = -1073741796i64;
        }
        break;
      case 3:
        goto LABEL_67;
      case 5:
        goto LABEL_46;
    }
    if( !v29 && (_BYTE)v4 != 1 )
      *((_DWORD *)CurrentThread + 199) = 0;
    *(_BYTE *)a4 = 0;
    *(_WORD *)(a4 + 2) = 0;
  }
  __writecr8(0i64);
LABEL_27:
  if( v27 )
    KeReleaseSemaphoreEx(&VslpIumThreadSemaphore, 0i64, 1i64, v17);
  if( (_BYTE)v34 )
    KeLeaveCriticalRegionThread((__int64)CurrentThread);
  if( CurrentIrql != 15 )
    __writecr8(CurrentIrql);
  return *(_DWORD *)(a4 + 8);
}

Referenced by:

DbgkCopyProcessDebugPort
ExRebootSystemForRecovery
HvlCollectLivedump
HvlNotifyDebugDeviceAvailable
HvlPrepareForRootCrashdump
HvlPrepareForSecureHibernate
KeBalanceSetManager
KeCopyPrivilegedPage
KeRequestTerminationThread
KeSetPagePrivilege
KeUnsecureProcess
MiApplyImportOptimizationToBootDrivers
MiApplyRetpolineFixupsToKernelAndHal
MiCreateSlabAllocationsFromLoaderBlock
MiFlushEntireTbDueToAttributeChange
MiMarkKernelImageCfgBits
MiReloadBootLoadedDrivers
MiWaitForFreePage
MmWriteSystemImageTracepoint
NtRemoveProcessDebug
PipUnprotectDevice
PsRequestDebugSecureProcess
PsRundownVsmEnclave
PsTerminateVsmEnclave
PspInitPhase3
PspIumWorker
PspUserThreadStartup
VslAbortLiveDump
VslAccessPciDevice
VslAllocateSecureHibernateResources
VslApplyDynamicRelocations
VslApplyHotPatch
VslApplySecureImageFixups
VslBindNtIum
VslCallEnclave
VslCapturePgoData
VslCaptureSecureImageIat
VslCloseSecureHandle
VslCompleteSecureDriverLoad
VslConfigureDynamicMemory
VslConnectSwInterrupt
VslCreateEnclave
VslCreateSecureAllocation
VslCreateSecureImageSection
VslCreateSecureProcess
VslCreateSecureSection
VslCreateSecureThread
VslDebugProtectSecureProcessMemory
VslDebugReadWriteSecureProcess
VslDeleteSecureSection
VslDetermineHotPatchType
VslDetermineHotPatchUndoTableSize
VslEnableKernelCfgTarget
VslEnableOnDemandDebugWithResponse
VslEndSecurePageIteration
VslExchangeEntropy
VslFastFlushSecureRangeList
VslFillSecureAllocation
VslFinalizeLiveDumpInSk
VslFinalizeSecureImageHash
VslFinishSecureImageValidation
VslFinishStartSecureProcessor
VslFlushSecureAddressSpace
VslFreeSecureHibernateResources
VslFreeSecureImageIat
VslGetEtwDebugId
VslGetNestedPageProtectionFlags
VslGetOnDemandDebugChallenge
VslGetSecurePageList
VslGetSecurePciDeviceAlternateFunctionNumberForVtl0Dma
VslGetSecurePciEnabled
VslGetSecurePebAddress
VslGetSecureSpeculationControlInformation
VslGetSecureTebAddress
VslGetSetSecureContext
VslInitializeEnclave
VslInitializeSecureKernelCfg
VslInitializeSecurePool
VslInitializeSecureProcess
VslIsTrustletRunning
VslIumEfiRuntimeService
VslIumEtwEnableCallback
VslLiveDumpCaptureProcess
VslLiveDumpQuerySecondaryDataSize
VslLoadEnclaveData
VslLoadEnclaveModule
VslMakeCodeCatalog
VslMakeProtectedPageExecutable
VslMakeProtectedPageWritable
VslNotifyShutdown
VslObtainHotPatchUndoTable
VslPrepareDriverForPatch
VslPrepareSecureImageRelocations
VslProvisionDumpEncryption
VslQuerySecureDevice
VslQuerySecureKernelProfileInformation
VslQueryVirtualMemory
VslRegisterLogPages
VslRegisterSecureSystemProcess
VslRelaxQuotas
VslRelocateImage
VslReportBugCheckProgress
VslReserveProtectedPages
VslRetrieveMailbox
VslRevertHotPatch
VslRundownSecureProcess
VslSendDebugAttachNotifications
VslSetCodeIntegrityPolicy
VslSetPlaceholderPages
VslSetupLiveDumpBufferInSk
VslSlowFlushSecureRangeList
VslStartSecurePageIteration
VslStartSecureProcessor
VslSvcEnterIumSecureMode
VslTerminateSecureThread
VslTestRoutine
VslTransferSecureImageVersionResource
VslUpdateFreezeTimeBias
VslValidateDynamicCodePages
VslValidateSecureImagePages
VslVerifyPage
VslpAddLiveDumpBufferChunk
VslpConnectedStandbyPoCallback
VslpConnectedStandbyWnfCallback
VslpIumPhase0Initialize
VslpIumPhase4Initialize
VslpKsrEnterIumSecureMode
VslpLiveDumpStart
VslpSetupLiveDumpBuffer
VslpSkMapBuffers
VslpSkStopProfiling