FxRequestMemory::~FxRequestMemory( VOID ) /*++ Routine Description: Destructor for this object. Does nothing with the client memory since the client owns it. Arguments: None Return Value: None --*/ { // // Non-embedded case releases resources in the destructor // rather than Dispose to ensure all outstanding device driver // references are gone. // #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE) if( m_Mdl != NULL ) { Mx::MxUnlockPages(m_Mdl); FxMdlFree(GetDriverGlobals(), m_Mdl); m_Mdl = NULL; } #endif if( m_Request != NULL ) { m_Request->ReleaseIrpReference(); m_Request = NULL; } }
FORCEINLINE FxIoContext::~FxIoContext( VOID ) { // // Free the buffer allocated for the request, reset m_CopyBackToBuffer // to FALSE. // NOTE: We delay the freeing of the buffer on purpose. // ClearBuffer(); // // Free the MDL allocated for the request // if (m_MdlToFree != NULL) { // // Being defensive here, MmUnlockPages should have been done in // ReleaseAndRestore. // if (m_UnlockPages) { MmUnlockPages(m_MdlToFree); m_UnlockPages = FALSE; } FxMdlFree(m_DriverGlobals, m_MdlToFree); m_MdlToFree = NULL; } }
FORCEINLINE NTSTATUS FxRequestBuffer::GetOrAllocateMdlWorker( __in PFX_DRIVER_GLOBALS FxDriverGlobals, __deref_out PMDL* Mdl, __in BOOLEAN * ReuseMdl, __in LONG Length, __in PVOID Buffer, __inout size_t* SizeOfMdl, __in BOOLEAN UnlockWhenFreed, __deref_out_opt PMDL* MdlToFree ) { size_t sizeofCurrentMdl; sizeofCurrentMdl = MmSizeOfMdl(Buffer, Length); // // Caller of this function (GetOrAllocateMdl) verifies that pages // are already unlocked. Asserting here, in case we start using this // function elsewhere. // // This is why we don't unlock pages either in reuse or non-reuse case. // ASSERT(UnlockWhenFreed == FALSE); UNREFERENCED_PARAMETER(UnlockWhenFreed); //for fre build // // If ReuseMdl is TRUE then the Mdl to be reused is passed in. // if (*ReuseMdl && sizeofCurrentMdl <= *SizeOfMdl) { MmPrepareMdlForReuse(*MdlToFree); *Mdl = *MdlToFree; } else { *ReuseMdl = FALSE; // // Since *Mdl may have the original IRP Mdl // free *MdlToFree and not *Mdl // if (*MdlToFree != NULL) { FxMdlFree(FxDriverGlobals, *MdlToFree); *MdlToFree = NULL; if (SizeOfMdl != NULL) { *SizeOfMdl = 0; } } *Mdl = FxMdlAllocate(FxDriverGlobals, NULL, // owning FxObject Buffer, Length, FALSE, FALSE); if (*Mdl == NULL) { ASSERT(SizeOfMdl ? (*SizeOfMdl == 0) : TRUE); return STATUS_INSUFFICIENT_RESOURCES; } if (SizeOfMdl != NULL) { *SizeOfMdl = sizeofCurrentMdl; } } return STATUS_SUCCESS; }