RtlpHpGetOwnerHeap

__int64 __fastcall RtlpHpGetOwnerHeap(__int64 a1, __int128 *a2){
  int v4; 
  union _RTL_RUN_ONCE *HeapManager; 
  INT64 v7; 
  __int128 v8; 
  __int128 a2a; 
  int a4; 
  int v11; 
  __int64 *a3; 
  if( (_WORD)a1 )
  {
    v4 = 0;
  }
  else
  {
    a2a = *a2;
    HeapManager = RtlpHpEnvGetHeapManager(&a2a);
    v7 = RtlCSparseBitmapBitmaskRead((INT64)&HeapManager[2], 2 * ((a1 - HeapManager[1].Value) >> 20));
    if( !v7 )
      goto LABEL_7;
    v4 = v7 - 1;
  }
  if( v4 != 2 )
  {
    a4 = 0x100000;
    v11 = 0x1000000;
    return(a1 & -(__int64)(unsigned int)*(&a4 + v4) ^ RtlpHpHeapGlobals ^ *(_QWORD *)((a1 & -(__int64)(unsigned int)*(&a4 + v4))
                                                                                     + 0x10) ^ 0xA2E64EADA2E64EADui64)
         - 192i64 * v4
         - 256;
  }
LABEL_7:
  v8 = *a2;
  a3 = 0i64;
  a2a = v8;
  RtlpHpQueryVA(a1, &a2a, &a3, &a4);
  return *a3;
}

Referenced by:

ExGetHeapFromVA