HalpAllocateDmaResourcesInternal
NTSTATUS __stdcall HalpAllocateDmaResourcesInternal(PDMA_ADAPTER DmaAdapter){
void(__fastcall *FreeCommonBuffer)(_DMA_ADAPTER *, unsigned int, _LARGE_INTEGER, void *, unsigned __int8);
char v2;
__int64 v3;
__int64 DmaOperations_low;
_DMA_OPERATIONS *DmaOperations;
_DWORD *v7;
char v8;
unsigned int v9;
_DMA_OPERATIONS *MapRegisters;
_DMA_OPERATIONS *v11;
unsigned int i;
_DMA_OPERATIONS *v13;
int v14;
DmaOperations_low = LODWORD(DmaAdapter[38].DmaOperations);
DmaOperations = DmaAdapter[21].DmaOperations;
v7 = (_DWORD *)v3;
v8 = v2;
switch( (_DWORD)DmaOperations_low )
{
case 0:
LODWORD(DmaAdapter[38].DmaOperations) = 1;
LABEL_8:
if( !HIBYTE(DmaAdapter[27].Version) && !HalpAllocateDmaChannels((__int64)DmaAdapter) )
goto LABEL_25;
DmaOperations_low = (unsigned int)++LODWORD(DmaAdapter[38].DmaOperations);
goto LABEL_11;
case 1:
goto LABEL_8;
case 2:
LABEL_11:
v9 = *(_DWORD *)&DmaAdapter[15].Version;
if( v9 && LOBYTE(DmaAdapter[27].Version) )
{
MapRegisters = (_DMA_OPERATIONS *)HalpDmaAllocateMapRegisters((__int64)DmaAdapter, v9, v3, DmaOperations_low);
DmaAdapter[14].DmaOperations = MapRegisters;
v11 = MapRegisters;
if( !MapRegisters )
{
HalpQueueMapBufferWorker((__int64)DmaAdapter, v9);
if( (HIDWORD(DmaOperations->AllocateCommonBuffer) & 1) == 0 )
HalpDmaQueueAdapter((__int64)DmaAdapter);
goto LABEL_25;
}
MapRegisters->FreeCommonBuffer = (void(__fastcall *)(_DMA_ADAPTER *, unsigned int, _LARGE_INTEGER, void *, unsigned __int8))-1i64;
MapRegisters->AllocateAdapterChannel = 0i64;
if( (HIDWORD(DmaOperations->AllocateCommonBuffer) & 4) != 0 )
{
for( i = 0; i < v9; ++i )
{
if( !v11 )
break;
v11->FreeAdapterChannel = (void(__fastcall *)(_DMA_ADAPTER *))((unsigned __int64)v11->FreeAdapterChannel | 0x20);
v11 = (_DMA_OPERATIONS *)v11->PutDmaAdapter;
}
}
LODWORD(DmaOperations_low) = DmaAdapter[38].DmaOperations;
}
else
{
DmaAdapter[14].DmaOperations = 0i64;
*(_DWORD *)&DmaAdapter[15].Version = 0;
}
LODWORD(DmaAdapter[38].DmaOperations) = DmaOperations_low + 1;
goto LABEL_23;
case 3:
LABEL_23:
if( *(_DWORD *)&DmaAdapter[32].Version != 2
|| (v13 = DmaAdapter[14].DmaOperations,
LOBYTE(v3) = (HIDWORD(DmaOperations->AllocateCommonBuffer) & 1) == 0,
v14 = HalpDmaAllocateAndPremapLa(
(INT64)DmaAdapter,
HIDWORD(DmaOperations->AllocateCommonBuffer) & 0xFFFFF000,
v3,
(UINT64 *)&v13->FreeCommonBuffer),
v13->FlushAdapterBuffers = (unsigned __int8(__fastcall *)(_DMA_ADAPTER *, _MDL *, void *, void *, unsigned int, unsigned __int8))v13->FreeCommonBuffer,
v14 >= 0) )
{
LODWORD(DmaOperations_low) = ++LODWORD(DmaAdapter[38].DmaOperations);
goto LABEL_34;
}
LABEL_25:
LODWORD(FreeCommonBuffer) = HIDWORD(DmaOperations->AllocateCommonBuffer);
if( ((unsigned __int8)FreeCommonBuffer & 1) != 0
|| ((unsigned __int8)FreeCommonBuffer & 2) != 0
&& (LODWORD(FreeCommonBuffer) = DmaOperations[-1].FreeCommonBufferVector,
((unsigned __int8)FreeCommonBuffer & 2) != 0)
&& (HalpDmaRemoveFromEmergencyLogicalAddressQueue((INT64)DmaAdapter, &DmaAdapter[37].Version)
|| HalpDmaRemoveAdapterFromMasterQueue((__int64)DmaAdapter)
|| HalpDmaRemoveAdapterFromChannelQueue((__int64)DmaAdapter)) )
{
*(_DWORD *)&DmaAdapter[15].Version = 0;
IoFreeAdapterChannel(DmaAdapter);
}
goto LABEL_6;
}
if( (_DWORD)DmaOperations_low != 4 )
{
LABEL_6:
LOBYTE(FreeCommonBuffer) = 0;
return(int)FreeCommonBuffer;
}
LABEL_34:
if( (HIDWORD(DmaOperations->AllocateCommonBuffer) & 2) != 0 )
{
_InterlockedOr((volatile signed __int32 *)&DmaOperations[-1].FreeCommonBufferVector, 1u);
LODWORD(DmaOperations_low) = DmaAdapter[38].DmaOperations;
}
LODWORD(DmaAdapter[38].DmaOperations) = DmaOperations_low + 1;
if( (HIDWORD(DmaOperations->AllocateCommonBuffer) & 2) != 0 )
*(_QWORD *)&DmaAdapter[22].Version = (char *)DmaOperations - 16;
FreeCommonBuffer = DmaOperations->FreeCommonBuffer;
if( FreeCommonBuffer )
{
LODWORD(FreeCommonBuffer) = ((__int64(__fastcall *)(void(__fastcall *)(_DMA_ADAPTER *), void(__fastcall *)(_DMA_ADAPTER *, void *, unsigned int), _DMA_OPERATIONS *, int(__fastcall *)(_DMA_ADAPTER *, _DEVICE_OBJECT *, unsigned int, _IO_ALLOCATION_ACTION(__fastcall *)(_DEVICE_OBJECT *, _IRP *, void *, void *), void *)))FreeCommonBuffer)(
DmaOperations->FreeAdapterChannel,
DmaOperations->FreeMapRegisters,
DmaAdapter[14].DmaOperations,
DmaOperations->AllocateAdapterChannel);
if( v7 )
*v7 = (_DWORD)FreeCommonBuffer;
if( v8 )
HalFreeAdapterObject((__int64)DmaAdapter, (int)FreeCommonBuffer);
}
LOBYTE(FreeCommonBuffer) = 1;
return(int)FreeCommonBuffer;
}Referenced by:
HalpAllocateAdapterChannel
HalpAllocateDmaResources
HalpDmaProcessMapRegisterQueueV3
HalpDmaReturnEmergencyLogicalAddressResources
IoFreeAdapterChannelV3