ViAllocateMapRegisterFile
CHAR *__fastcall ViAllocateMapRegisterFile(INT64 a1, UINT64 a2){
unsigned int v3;
char *PoolWithTag;
char *v5;
PMDL Mdl;
VOID *v7;
struct _MDL *v8;
VOID **v9;
INT64 v10;
__int64 v11;
VOID *v12;
PHYSICAL_ADDRESS PhysicalAddress;
PVOID v14;
int v16;
PVOID *v17;
void *v18;
v3 = a2;
if( (unsigned int)(a2 + *(_DWORD *)(a1 + 160)) <= 0x20 )
{
if( (_DWORD)a2 )
{
PoolWithTag = (char *)ExAllocatePoolWithTag(NonPagedPoolNx, (unsigned int)(32 * (a2 - 1) + 120), 0x566C6148ui64);
v5 = PoolWithTag;
if( PoolWithTag )
{
memset((INT64)PoolWithTag, 0i64);
*((_DWORD *)v5 + 7) = v3;
Mdl = IoAllocateMdl(0i64, v3 << 12, 0, 0, 0i64);
if( Mdl )
{
v7 = ExAllocatePoolWithTag(NonPagedPoolNx, (unsigned __int64)v3 << 12, 0x566C6148ui64);
*((_QWORD *)v5 + 9) = v7;
if( v7 )
{
v8 = Mdl + 1;
v9 = (VOID **)(v5 + 104);
do
{
v10 = ViAllocateFromContiguousMemory(a1, *((_DWORD *)v5 + 7) - v3);
*v9 = (VOID *)v10;
if( v10 )
{
v11 = 312i64;
}
else
{
v12 = ExAllocatePoolWithTag(NonPagedPoolNxCacheAligned, 0x3000ui64, 0x566C6148ui64);
*v9 = v12;
if( !v12 )
goto LABEL_14;
v11 = 316i64;
}
_InterlockedIncrement((volatile signed __int32 *)(v11 + a1));
ViInitializePadding(*v9, 0x3000ui64, 0i64, 0i64);
PhysicalAddress = MmGetPhysicalAddress((char *)*v9 + 4096);
v9 += 4;
v8->Next = (_MDL *)((unsigned __int64)PhysicalAddress.QuadPart >> 12);
v8 = (struct _MDL *)((char *)v8 + 8);
--v3;
}
while( v3 );
Mdl->MdlFlags |= 2u;
v14 = MmMapLockedPagesSpecifyCache(Mdl, 0, MmCached, 0i64, 0, 0x40000010u);
*((_QWORD *)v5 + 8) = v14;
if( v14 )
{
*((_QWORD *)v5 + 10) = 0i64;
*((_QWORD *)v5 + 7) = Mdl;
*(_DWORD *)v5 = -1393569779;
ExInterlockedInsertHeadList((PLIST_ENTRY)(a1 + 104), (PLIST_ENTRY)(v5 + 8), (PKSPIN_LOCK)(a1 + 120));
return v5;
}
}
}
LABEL_14:
v16 = *((_DWORD *)v5 + 7);
if( v16 )
{
v17 = (PVOID *)(v5 + 104);
do
{
if( !*v17 )
break;
if( !(unsigned int)ViFreeToContiguousMemory(a1, (__int64)*v17, *((_DWORD *)v5 + 7) - v16) )
ExFreePoolWithTag(*v17, 0);
v17 += 4;
--v16;
}
while( v16 );
}
if( Mdl )
IoFreeMdl(Mdl);
v18 = (void *)*((_QWORD *)v5 + 9);
if( v18 )
ExFreePoolWithTag(v18, 0);
ExFreePoolWithTag(v5, 0);
}
}
}
return 0i64;
}Referenced by:
VfAllocateAdapterChannel
VfBuildScatterGatherList
VfGetScatterGatherList
VfHalAllocateMapRegisters