SmKmKeyGenGenerate

__int64 __fastcall SmKmKeyGenGenerate(ULONG_PTR BugCheckParameter2, unsigned __int16 *a2, void *a3, unsigned int a4){
  UINT64 v4; 
  _ETHREAD *CurrentThread; 
  struct _PRIVILEGE_SET *v9; 
  struct _PRIVILEGE_SET *v10; 
  int v11; 
  v4 = a4;
  while( 1 )
  {
    while( 1 )
    {
      CurrentThread = (_ETHREAD *)KeGetCurrentThread();
      --*((_WORD *)CurrentThread + 242);
      ExAcquirePushLockSharedEx(BugCheckParameter2, 0i64);
      v9 = (struct _PRIVILEGE_SET *)SmKmKeyGenKeyFind(BugCheckParameter2, a2);
      v10 = v9;
      if( v9 )
        break;
      if( _InterlockedCompareExchange64((volatile signed __int64 *)BugCheckParameter2, 0i64, 17i64) != 17 )
        ExfReleasePushLockShared((INT64 *)BugCheckParameter2);
      KeAbPostRelease((PVOID)BugCheckParameter2);
      KeLeaveCriticalRegion();
      v11 = SmKmKeyGenNewKey(BugCheckParameter2, a2, v4);
      if( v11 < 0 )
        return(unsigned int)v11;
    }
    if( v9[1].Privilege[0].Luid.HighPart == (_DWORD)v4 )
      break;
    if( _InterlockedCompareExchange64((volatile signed __int64 *)BugCheckParameter2, 0i64, 17i64) != 17 )
      ExfReleasePushLockShared((INT64 *)BugCheckParameter2);
    KeAbPostRelease((PVOID)BugCheckParameter2);
    KeLeaveCriticalRegion();
    SmKmKeyGenKeyDelete((PVOID)BugCheckParameter2, v10);
  }
  memmove((UINT8 *)a3, *(UINT8 **)&v9[1].Control, v4);
  v11 = 0;
  if( _InterlockedCompareExchange64((volatile signed __int64 *)BugCheckParameter2, 0i64, 17i64) != 17 )
    ExfReleasePushLockShared((INT64 *)BugCheckParameter2);
  KeAbPostRelease((PVOID)BugCheckParameter2);
  KeLeaveCriticalRegion();
  return(unsigned int)v11;
}

Referenced by:

SmcStoreCreate