Exemplo n.º 1
0
/*---------------------------------------------------------
函数名称:	Antinvader_Unload
函数描述:	卸载驱动程序,关闭通信端口
输入参数:
			Flags	卸载标志
输出参数:
返回值:
			STATUS_SUCCESS 成功
其他:
更新维护:	2011.3.20    最初版本
---------------------------------------------------------*/
NTSTATUS
Antinvader_Unload (
    __in FLT_FILTER_UNLOAD_FLAGS Flags
)
{
    UNREFERENCED_PARAMETER( Flags );

    PAGED_CODE();

    DebugTrace(DEBUG_TRACE_LOAD_UNLOAD,"Unload",
               ("Entered."));

    //
    //关闭通信端口
    //

    if(pfpGlobalServerPort) {
        DebugTrace(DEBUG_TRACE_LOAD_UNLOAD,"Unload",
                   ("Closing communication port....0x%X",pfpGlobalServerPort));
        FltCloseCommunicationPort( pfpGlobalServerPort );
    }

    //
    //卸载过滤
    //

    if(pfltGlobalFilterHandle) {
        DebugTrace(DEBUG_TRACE_LOAD_UNLOAD,"Unload",
                   ("Unregistering filter....0x%X",pfltGlobalFilterHandle));
        FltUnregisterFilter( pfltGlobalFilterHandle );
    }

    //
    //销毁释放所有表格 资源 旁视链表等
    //
    PctFreeTable();

//	ExDeleteNPagedLookasideList(&nliCallbackContextLookasideList);
//	ExDeleteNPagedLookasideList(&nliFileStreamContextLookasideList);

    ExDeleteNPagedLookasideList(&nliNewFileHeaderLookasideList);

    DebugTrace(DEBUG_TRACE_LOAD_UNLOAD,"Unload",
               ("All succeed.Leave now."));

    return STATUS_SUCCESS;
}
Exemplo n.º 2
0
VOID DokanUnload(__in PDRIVER_OBJECT DriverObject)
/*++

Routine Description:

        This routine gets called to remove the driver from the system.

Arguments:

        DriverObject	- the system supplied driver object.

Return Value:

        NTSTATUS

--*/

{

  PDEVICE_OBJECT deviceObject = DriverObject->DeviceObject;
  WCHAR symbolicLinkBuf[] = DOKAN_GLOBAL_SYMBOLIC_LINK_NAME;
  UNICODE_STRING symbolicLinkName;
  PDOKAN_GLOBAL dokanGlobal;

  // PAGED_CODE();
  DDbgPrint("==> DokanUnload\n");

  dokanGlobal = deviceObject->DeviceExtension;
  if (GetIdentifierType(dokanGlobal) == DGL) {
    DDbgPrint("  Delete Global DeviceObject\n");

    RtlInitUnicodeString(&symbolicLinkName, symbolicLinkBuf);
    IoDeleteSymbolicLink(&symbolicLinkName);

    IoUnregisterFileSystem(dokanGlobal->FsDiskDeviceObject);
    IoUnregisterFileSystem(dokanGlobal->FsCdDeviceObject);

    IoDeleteDevice(dokanGlobal->FsDiskDeviceObject);
    IoDeleteDevice(dokanGlobal->FsCdDeviceObject);
    IoDeleteDevice(deviceObject);
  }

  ExDeleteNPagedLookasideList(&DokanIrpEntryLookasideList);

  DDbgPrint("<== DokanUnload\n");
  return;
}
VOID
OcObDeleteObjectType(
    IN POC_OBJECT_TYPE    PtrObjectType
    )
    /*
    The function checks the object type's reference count
    and deletes the object type if the reference count is zero,
    else the object type is marked and will be deleted when
    the refrence count drops to zero
    */
{

    OcObDeleteObjectTypeMethod    DeleteObjectTypeMethod;

    ASSERT( OcTypeObjectType == PtrObjectType->CommonHeader.Type );

    if( 0x0 != InterlockedCompareExchange( &PtrObjectType->RefCount, 0x0, 0x0 ) ){

        OcSetFlag( PtrObjectType->Flags, OcObjectTypeMarkedForDeletion );
        return;
    }

    if( !OcIsFlagOn( PtrObjectType->Flags, OcObjectTypeUseStdPoolAllocator ) )
        ExDeleteNPagedLookasideList( &PtrObjectType->LookasideList );

    //
    // get the pointer to the notify routine
    //
    DeleteObjectTypeMethod = PtrObjectType->Methods.DeleteObjectType;

#if DBG
    RtlFillMemory( PtrObjectType, sizeof( *PtrObjectType ), 0x0C );
#endif//DBG

    //
    // notify about the object type uninitialization
    //
    if( NULL != DeleteObjectTypeMethod ){

        DeleteObjectTypeMethod( PtrObjectType );
        OC_DEBUG_SET_POINTER_TO_INVALID_VALUE( PtrObjectType );
    }
}
Exemplo n.º 4
0
void DestroyNotificationQueue(NOTIFICATION_QUEUE *queue) {
	while(!IsListEmpty(&queue->notification_list)) {
		PGNOTIFYNODE *notifynode = (PGNOTIFYNODE*)RemoveHeadList(&queue->notification_list);
		ExFreeToNPagedLookasideList(&queue->lookaside, notifynode);
	}

	while(!IsListEmpty(&queue->irp_list)) {
		PGIRPNODE *irpnode = (PGIRPNODE*)RemoveHeadList(&queue->irp_list);
		
		irpnode->irp->IoStatus.Status = STATUS_CANCELLED;
		irpnode->irp->IoStatus.Information = 0;

		IoCompleteRequest(irpnode->irp, IO_NO_INCREMENT);

		ExFreeToNPagedLookasideList(&queue->lookaside, irpnode);
	}

	ExDeleteNPagedLookasideList(&queue->lookaside);
}
VOID
BalloonEvtDeviceContextCleanup(
    IN WDFOBJECT  Device
    )
{
    PDEVICE_CONTEXT     devCtx = GetDeviceContext((WDFDEVICE)Device);

    PAGED_CODE();

    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "--> %s\n", __FUNCTION__);

    if(devCtx->bListInitialized)
    {
        ExDeleteNPagedLookasideList(&devCtx->LookAsideList);
        devCtx->bListInitialized = FALSE;
    }
    if(devCtx->pfns_table)
    {
        ExFreePoolWithTag(
                   devCtx->pfns_table,
                   BALLOON_MGMT_POOL_TAG
                   );
        devCtx->pfns_table = NULL;
    }

    RtlFillMemory(devCtx->MemStats,
        sizeof(BALLOON_STAT) * VIRTIO_BALLOON_S_NR, -1);
    if (devCtx->StatVirtQueue)
    {
        BalloonMemStats(Device);
    }

    if(devCtx->MemStats)
    {
        ExFreePoolWithTag(
                   devCtx->MemStats,
                   BALLOON_MGMT_POOL_TAG
                   );
        devCtx->MemStats = NULL;
    }
    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "<-- %s\n", __FUNCTION__);
}
Exemplo n.º 6
0
VOID DokanUnload(__in PDRIVER_OBJECT DriverObject)
/*++

Routine Description:

        This routine gets called to remove the driver from the system.

Arguments:

        DriverObject    - the system supplied driver object.

Return Value:

        NTSTATUS

--*/

{

  PDEVICE_OBJECT deviceObject = DriverObject->DeviceObject;
  PDOKAN_GLOBAL dokanGlobal;

  DDbgPrint("==> DokanUnload\n");

  PAGED_CODE();

  dokanGlobal = deviceObject->DeviceExtension;
  if (GetIdentifierType(dokanGlobal) == DGL) {
    DDbgPrint("  Delete Global DeviceObject\n");
    CleanupGlobalDiskDevice(dokanGlobal);
    ExFreePool(DriverObject->FastIoDispatch);
  }

  ExDeleteNPagedLookasideList(&DokanIrpEntryLookasideList);

  ExDeleteLookasideListEx(&g_DokanCCBLookasideList);
  ExDeleteLookasideListEx(&g_DokanFCBLookasideList);
  ExDeleteLookasideListEx(&g_DokanEResourceLookasideList);

  DDbgPrint("<== DokanUnload\n");
}
Exemplo n.º 7
0
void cp_free_fast_crypt()
{
	int i;

	/* disable thread pool */
	if (lock_xchg(&pool_enabled, 0) == 0) {
		return;
	}
	/* stop all threads */
	for (i = 0; i < MAX_CPU_COUNT; i++)
	{
		if (pool_threads[i] != NULL) {
			KeSetEvent(&pool_signal_event, IO_NO_INCREMENT, FALSE);
			ZwWaitForSingleObject(pool_threads[i], FALSE, NULL);
			ZwClose(pool_threads[i]);
		}
	}
	/* free memory */
	memset(&pool_threads, 0, sizeof(pool_threads));
	ExDeleteNPagedLookasideList(&pool_req_mem);
}
Exemplo n.º 8
0
/* KphProtectDeinit
 * 
 * Removes process protection and frees associated structures.
 * 
 * IRQL: <= APC_LEVEL
 */
NTSTATUS KphProtectDeinit()
{
    NTSTATUS status = STATUS_SUCCESS;
    KIRQL oldIrql;
    LARGE_INTEGER waitLi;
    
    /* Unhook. */
    status = KphObOpenUnhook(&ProcessOpenHook);
    status = KphObOpenUnhook(&ThreadOpenHook);
    
    /* Wait for all activity to finish. */
    ExWaitForRundownProtectionRelease(&ProtectedProcessRundownProtect);
    /* Wait for a bit (some regions of hook target functions 
       are NOT guarded by rundown protection, e.g. 
       prologues and epilogues). */
    waitLi.QuadPart = KPH_REL_TIMEOUT_IN_SEC(1);
    KeDelayExecutionThread(KernelMode, FALSE, &waitLi);
    
    /* Free all process protection entries. */
    ExDeleteNPagedLookasideList(&ProtectedProcessLookasideList);
    
    return status;
}
Exemplo n.º 9
0
NTSTATUS TCPShutdown(VOID)
/*
 * FUNCTION: Shuts down the TCP subsystem
 * RETURNS:
 *     Status of operation
 */
{
    if (!TCPInitialized)
        return STATUS_SUCCESS;

    ExDeleteNPagedLookasideList(&TdiBucketLookasideList);
    
    LibIPShutdown();

    /* Deregister this protocol with IP layer */
    IPRegisterProtocol(IPPROTO_TCP, NULL);

    TCPInitialized = FALSE;

    PortsShutdown( &TCPPorts );

    return STATUS_SUCCESS;
}
Exemplo n.º 10
0
void DestroyTable(PHASHTABLE pHashTable)
{
	PTWOWAY pNode = NULL; 
	PTWOWAY pTmpNode = NULL;
	PLIST_ENTRY pListHead = NULL;
	PLIST_ENTRY pListLink = NULL;
    unsigned int i;

	for (i = 0; i < pHashTable->tableSize; i++)
	{
		pListHead = pListLink = pHashTable->pListHeads[i];
		if (pListHead == NULL)
		{
			DbgPrint("pListHead is NULL!\n");
			continue;
		}
		if (!IsListEmpty(pListHead))
		{
			do
			{
				pNode = CONTAINING_RECORD(pListLink, TWOWAY, linkfield);
				pListLink = pListLink->Flink;
				ExFreeToNPagedLookasideList(pLookasideList_TWOWAY, pNode);
			} while (pListLink != pListHead);
		}
		else
		{
			pNode = CONTAINING_RECORD(pListHead, TWOWAY, linkfield);
			ExFreeToNPagedLookasideList(pLookasideList_TWOWAY, pNode);
		}
	}

	ExDeleteNPagedLookasideList(pLookasideList_TWOWAY);
	ExFreePoolWithTag(pLookasideList_TWOWAY, DRIVERTAG1);
	ExFreePoolWithTag(pHashTable->pListHeads, DRIVERTAG1);
	ExFreePoolWithTag(pHashTable, DRIVERTAG1);
}
Exemplo n.º 11
0
VOID
DriverUnload (IN PDRIVER_OBJECT DriverObject)
{

    UNICODE_STRING              DosDeviceName;

    DEBUG(DL_FUN, ( "Ext2Fsd: Unloading routine.\n"));

    /*
     *  stop reaper thread ...
     */


    /*
     *  removing memory allocations and  objects
     */

    RtlInitUnicodeString(&DosDeviceName, DOS_DEVICE_NAME);
    IoDeleteSymbolicLink(&DosDeviceName);

    Ext2UnloadAllNls();

    ExDeleteResourceLite(&Ext2Global->Resource);

    ExDeleteNPagedLookasideList(&(Ext2Global->Ext2DentryLookasideList));
    ExDeleteNPagedLookasideList(&(Ext2Global->Ext2ExtLookasideList));
    ExDeleteNPagedLookasideList(&(Ext2Global->Ext2McbLookasideList));
    ExDeleteNPagedLookasideList(&(Ext2Global->Ext2CcbLookasideList));
    ExDeleteNPagedLookasideList(&(Ext2Global->Ext2FcbLookasideList));
    ExDeleteNPagedLookasideList(&(Ext2Global->Ext2IrpContextLookasideList));

    ObDereferenceObject(Ext2Global->DiskdevObject);
    ObDereferenceObject(Ext2Global->CdromdevObject);

    /* cleanup journal related caches */
    UNLOAD_MODULE(journal_exit);

    /* cleanup linux lib */
    ext2_destroy_linux();

    Ext2FreePool(Ext2Global, 'LG2E');
    Ext2Global = NULL;
}
Exemplo n.º 12
0
VOID
FatUnload(
    IN PDRIVER_OBJECT DriverObject
    )

/*++

Routine Description:

    This is the unload routine for the filesystem

Arguments:

    DriverObject - Pointer to driver object created by the system.

Return Value:

    None

--*/

{
#if __NDAS_FAT__
	UNICODE_STRING linkString;
#endif

#if DBG
	DbgPrint( "FastFat FatUnload %s %s\n", __DATE__, __TIME__ );
#endif

    ExDeleteNPagedLookasideList (&FatEResourceLookasideList);
    ExDeleteNPagedLookasideList (&FatNonPagedFcbLookasideList);
    ExDeleteNPagedLookasideList (&FatIrpContextLookasideList);
    ExDeleteResourceLite( &FatData.Resource );
    IoFreeWorkItem (FatData.FatCloseItem);
    ObDereferenceObject( FatDiskFileSystemDeviceObject);
#if __NDAS_FAT__
	if (FatCdromFileSystemDeviceObject)
#endif
    ObDereferenceObject( FatCdromFileSystemDeviceObject);

#if __NDAS_FAT__

    RtlInitUnicodeString( &linkString, NDAS_FAT_CONTROL_LINK_NAME );
    IoDeleteSymbolicLink( &linkString );

	DebugTrace2( 0, Dbg2, ("NdasFatUnload occured NdasFatControlDeviceObject->ReferenceCount = %x\n", 
							FatControlDeviceObject->ReferenceCount) );

	IoDeleteDevice( FatControlDeviceObject );

	DebugTrace2( 0, Dbg2, ("NdasFatUnload occured NdasFatFileSystemDeviceObject->ReferenceCount = %x\n", 
							FatDiskFileSystemDeviceObject->ReferenceCount) );

	IoDeleteDevice( FatDiskFileSystemDeviceObject );
	if (FatCdromFileSystemDeviceObject)
		IoDeleteDevice( FatCdromFileSystemDeviceObject );

#endif

}
Exemplo n.º 13
0
NTSTATUS
DriverEntry (
    _In_ PDRIVER_OBJECT DriverObject,
    _In_ PUNICODE_STRING RegistryPath
    )
/*++

Routine Description:

    This routine is called when a driver first loads.  Its purpose is to
    initialize global state and then register with FltMgr to start filtering.

Arguments:

    DriverObject - Pointer to driver object created by the system to
        represent this driver.
    RegistryPath - Unicode string identifying where the parameters for this
        driver are located in the registry.

Return Value:

    Status of the operation.

--*/
{
    PSECURITY_DESCRIPTOR sd;
    OBJECT_ATTRIBUTES oa;
    UNICODE_STRING uniString;
    NTSTATUS status = STATUS_SUCCESS;

    try {

        //
        // Initialize global data structures.
        //

        MiniSpyData.LogSequenceNumber = 0;
        MiniSpyData.MaxRecordsToAllocate = DEFAULT_MAX_RECORDS_TO_ALLOCATE;
        MiniSpyData.RecordsAllocated = 0;
        MiniSpyData.NameQueryMethod = DEFAULT_NAME_QUERY_METHOD;

        MiniSpyData.DriverObject = DriverObject;

        InitializeListHead( &MiniSpyData.OutputBufferList );
        KeInitializeSpinLock( &MiniSpyData.OutputBufferLock );

        ExInitializeNPagedLookasideList( &MiniSpyData.FreeBufferList,
                                         NULL,
                                         NULL,
                                         0,
                                         RECORD_SIZE,
                                         SPY_TAG,
                                         0 );

#if MINISPY_VISTA

        //
        //  Dynamically import FilterMgr APIs for transaction support
        //

#pragma warning(push)
#pragma warning(disable:4055) // type cast from data pointer to function pointer
        MiniSpyData.PFltSetTransactionContext = (PFLT_SET_TRANSACTION_CONTEXT) FltGetRoutineAddress( "FltSetTransactionContext" );
        MiniSpyData.PFltGetTransactionContext = (PFLT_GET_TRANSACTION_CONTEXT) FltGetRoutineAddress( "FltGetTransactionContext" );
        MiniSpyData.PFltEnlistInTransaction = (PFLT_ENLIST_IN_TRANSACTION) FltGetRoutineAddress( "FltEnlistInTransaction" );
#pragma warning(pop)

#endif

        //
        // Read the custom parameters for MiniSpy from the registry
        //

        SpyReadDriverParameters(RegistryPath);

        //
        //  Now that our global configuration is complete, register with FltMgr.
        //

        status = FltRegisterFilter( DriverObject,
                                    &FilterRegistration,
                                    &MiniSpyData.Filter );

        if (!NT_SUCCESS( status )) {

           leave;
        }


        status  = FltBuildDefaultSecurityDescriptor( &sd,
                                                     FLT_PORT_ALL_ACCESS );

        if (!NT_SUCCESS( status )) {
            leave;
        }

        RtlInitUnicodeString( &uniString, MINISPY_PORT_NAME );

        InitializeObjectAttributes( &oa,
                                    &uniString,
                                    OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
                                    NULL,
                                    sd );

        status = FltCreateCommunicationPort( MiniSpyData.Filter,
                                             &MiniSpyData.ServerPort,
                                             &oa,
                                             NULL,
                                             SpyConnect,
                                             SpyDisconnect,
                                             SpyMessage,
                                             1 );

        FltFreeSecurityDescriptor( sd );

        if (!NT_SUCCESS( status )) {
            leave;
        }

        //
        //  We are now ready to start filtering
        //

        status = FltStartFiltering( MiniSpyData.Filter );


		//If all went ok, register a process creation notification cb.
		if (NT_SUCCESS(status))
		{
			status = PsSetCreateProcessNotifyRoutine(ProcessCreationCB, FALSE);
		}

		//If all went ok, register also a register filter.
		if (NT_SUCCESS(status))
		{
			status = CmRegisterCallback(RegistryCallback, NULL, &g_CmCookie);
		}

    } finally {

        if (!NT_SUCCESS( status ) ) {

             if (NULL != MiniSpyData.ServerPort) {
                 FltCloseCommunicationPort( MiniSpyData.ServerPort );
             }

             if (NULL != MiniSpyData.Filter) {
                 FltUnregisterFilter( MiniSpyData.Filter );
             }

             ExDeleteNPagedLookasideList( &MiniSpyData.FreeBufferList );
        }
    }

    return status;
}
Exemplo n.º 14
0
VOID
ReleasePacketLookaside()
{
    ExDeleteNPagedLookasideList(&g_PktLookaside);
    ExDeleteNPagedLookasideList(&g_DataLookaside);
}
Exemplo n.º 15
0
VOID
AfdUnload (
    IN PDRIVER_OBJECT DriverObject
    )
{

    PLIST_ENTRY listEntry;
    PAFD_TRANSPORT_INFO transportInfo;

    UNREFERENCED_PARAMETER( DriverObject );

    PAGED_CODE( );

    KdPrint(( "AfdUnload called.\n" ));

    //
    // Kill the transport info list.
    //

    while( !IsListEmpty( &AfdTransportInfoListHead ) ) {

        listEntry = RemoveHeadList( &AfdTransportInfoListHead );

        transportInfo = CONTAINING_RECORD(
                            listEntry,
                            AFD_TRANSPORT_INFO,
                            TransportInfoListEntry
                            );

        AFD_FREE_POOL(
            transportInfo,
            AFD_TRANSPORT_INFO_POOL_TAG
            );

    }

    //
    // Kill the resource that protects the executive worker thread queue.
    //

    if( AfdResource != NULL ) {

        ExDeleteResource( AfdResource );

        AFD_FREE_POOL(
            AfdResource,
            AFD_RESOURCE_POOL_TAG
            );

    }

    //
    // Destroy the lookaside lists.
    //

    if( AfdLookasideLists != NULL ) {

        ExDeleteNPagedLookasideList( &AfdLookasideLists->WorkQueueList );
        ExDeleteNPagedLookasideList( &AfdLookasideLists->LargeBufferList );
        ExDeleteNPagedLookasideList( &AfdLookasideLists->MediumBufferList );
        ExDeleteNPagedLookasideList( &AfdLookasideLists->SmallBufferList );

        AFD_FREE_POOL(
            AfdLookasideLists,
            AFD_LOOKASIDE_LISTS_POOL_TAG
            );

    }

    //
    // Terminate the group ID manager.
    //

    AfdTerminateGroup();

    //
    // Delete our device object.
    //

    IoDeleteDevice( AfdDeviceObject );

} // AfdUnload
Exemplo n.º 16
0
VOID
SpReleaseAdapterResources(
    IN PADAPTER_EXTENSION Adapter,
    IN BOOLEAN Surprise
    )

/*++

Routine Description:

    This function deletes all of the storage associated with a device
    extension, disconnects from the timers and interrupts and then deletes the
    object.   This function can be called at any time during the initialization.

Arguments:

    Adapter - Supplies a pointer to the device extesnion to be deleted.

Return Value:

    None.

--*/

{

    PCOMMON_EXTENSION commonExtension = &(Adapter->CommonExtension);
    ULONG j;
    PVOID tempPointer;

    PAGED_CODE();

#if DBG

    if(!Surprise) {

        //
        // Free the Remove tracking lookaside list.
        //

        ExDeleteNPagedLookasideList(&(commonExtension->RemoveTrackingLookasideList));
    }
#endif

    //
    // Stop the time and disconnect the interrupt if they have been
    // initialized.  The interrupt object is connected after
    // timer has been initialized, and the interrupt object is connected, but
    // before the timer is started.
    //

    if(Adapter->DeviceObject->Timer != NULL) {
        IoStopTimer(Adapter->DeviceObject);
        KeCancelTimer(&(Adapter->MiniPortTimer));
    }

    if(Adapter->SynchronizeExecution != SpSynchronizeExecution) {

        if (Adapter->InterruptObject) {
            IoDisconnectInterrupt(Adapter->InterruptObject);
        }

        if (Adapter->InterruptObject2) {
            IoDisconnectInterrupt(Adapter->InterruptObject2);
            Adapter->InterruptObject2 = NULL;
        }

        //
        // SpSynchronizeExecution expects to get a pointer to the 
        // adapter extension as the "interrupt" parameter.
        //

        Adapter->InterruptObject = (PVOID) Adapter;
        Adapter->SynchronizeExecution = SpSynchronizeExecution;
    }

    //
    // Delete the miniport's device extension
    //

    if (Adapter->HwDeviceExtension != NULL) {

        PHW_DEVICE_EXTENSION devExt =
            CONTAINING_RECORD(Adapter->HwDeviceExtension,
                              HW_DEVICE_EXTENSION,
                              HwDeviceExtension);

        ExFreePool(devExt);
        Adapter->HwDeviceExtension = NULL;
    }

    //
    // Free the configuration information structure.
    //

    if (Adapter->PortConfig) {
        ExFreePool(Adapter->PortConfig);
        Adapter->PortConfig = NULL;
    }

    //
    // Deallocate SCSIPORT WMI REGINFO information, if any.
    //

    SpWmiDestroySpRegInfo(Adapter->DeviceObject);

    //
    // Free the common buffer.
    //

    if (Adapter->SrbExtensionBuffer != NULL &&
        Adapter->CommonBufferSize != 0) {

        if (Adapter->DmaAdapterObject == NULL) {

            //
            // Since there is no adapter just free the non-paged pool.
            //

            ExFreePool(Adapter->SrbExtensionBuffer);

        } else {

#if defined(_X86_)
            if(Adapter->UncachedExtensionIsCommonBuffer == FALSE) {
                MmFreeContiguousMemorySpecifyCache(Adapter->SrbExtensionBuffer,
                                                   Adapter->CommonBufferSize,
                                                   MmNonCached);
            } else 
#endif
            {

                HalFreeCommonBuffer(
                    Adapter->DmaAdapterObject,
                    Adapter->CommonBufferSize,
                    Adapter->PhysicalCommonBuffer,
                    Adapter->SrbExtensionBuffer,
                    FALSE);
            }

        }
        Adapter->SrbExtensionBuffer = NULL;
    }

    //
    // Free the SRB data array.
    //

    if (Adapter->SrbDataListInitialized) {

        if(Adapter->EmergencySrbData != NULL) {

            ExFreeToNPagedLookasideList(
                &Adapter->SrbDataLookasideList,
                Adapter->EmergencySrbData);
            Adapter->EmergencySrbData = NULL;
        }

        ExDeleteNPagedLookasideList(&Adapter->SrbDataLookasideList);

        Adapter->SrbDataListInitialized = FALSE;
    }

    if (Adapter->InquiryBuffer != NULL) {
        ExFreePool(Adapter->InquiryBuffer);
        Adapter->InquiryBuffer = NULL;
    }

    if (Adapter->InquirySenseBuffer != NULL) {
        ExFreePool(Adapter->InquirySenseBuffer);
        Adapter->InquirySenseBuffer = NULL;
    }

    if (Adapter->InquiryIrp != NULL) {
        IoFreeIrp(Adapter->InquiryIrp);
        Adapter->InquiryIrp = NULL;
    }

    if (Adapter->InquiryMdl != NULL) {
        IoFreeMdl(Adapter->InquiryMdl);
        Adapter->InquiryMdl = NULL;
    }

    //
    // Free the Scatter Gather lookaside list.
    //

    if (Adapter->MediumScatterGatherListInitialized) {

        ExDeleteNPagedLookasideList(
            &Adapter->MediumScatterGatherLookasideList);

        Adapter->MediumScatterGatherListInitialized = FALSE;
    }

    //
    // Unmap any mapped areas.
    //

    SpReleaseMappedAddresses(Adapter);

    //
    // If we've got any resource lists allocated still we should free them
    // now.
    //

    if(Adapter->AllocatedResources != NULL) {
        ExFreePool(Adapter->AllocatedResources);
        Adapter->AllocatedResources = NULL;
    }

    if(Adapter->TranslatedResources != NULL) {
        ExFreePool(Adapter->TranslatedResources);
        Adapter->TranslatedResources = NULL;
    }

    Adapter->CommonExtension.IsInitialized = FALSE;

    return;
}
Exemplo n.º 17
0
VOID
SpDeleteLogicalUnit(
    IN PDEVICE_OBJECT LogicalUnit
    )

/*++

Routine Description:

    This routine will release any resources held for the logical unit, mark the
    device extension as deleted, and call the io system to actually delete
    the object.  The device object will be deleted once it's reference count
    drops to zero.

Arguments:

    LogicalUnit - the device object for the logical unit to be deleted.

Return Value:

    none

--*/

{
    PLOGICAL_UNIT_EXTENSION luExtension = LogicalUnit->DeviceExtension;
    PCOMMON_EXTENSION commonExtension = LogicalUnit->DeviceExtension;

    PAGED_CODE();

    ASSERT(luExtension->ReadyLogicalUnit == NULL);
    ASSERT(luExtension->PendingRequest == NULL);
    ASSERT(luExtension->BusyRequest == NULL);
    ASSERT(luExtension->QueueCount == 0);

    //
    // Unregister with WMI.
    //

    if(commonExtension->WmiInitialized == TRUE) {

        //
        // Destroy all our WMI resources and unregister with WMI.
        //

        IoWMIRegistrationControl(LogicalUnit,
            WMIREG_ACTION_DEREGISTER);

        // BUGBUG
        // We should be asking the WmiFreeRequestList of remove some
        // free cells.

        commonExtension->WmiInitialized = FALSE;
        SpWmiDestroySpRegInfo(LogicalUnit);
    }

    SpDeleteDeviceMapEntry(luExtension->DeviceObject);

    //
    // Yank this out of the logical unit list.
    //

    SpRemoveLogicalUnitFromBin(luExtension->AdapterExtension, luExtension);

#if DBG
    // ASSERT(commonExtension->RemoveTrackingList == NULL);
    ExDeleteNPagedLookasideList(&(commonExtension->RemoveTrackingLookasideList));
#endif

    //
    // If the request sense irp still exists, delete it.
    //

    if(luExtension->RequestSenseIrp != NULL) {
        IoFreeIrp(luExtension->RequestSenseIrp);
        luExtension->RequestSenseIrp = NULL;
    }

    IoDeleteDevice(LogicalUnit);

    return;
}
Exemplo n.º 18
0
NTSTATUS
CHardwareSimulation::
Stop (
    )

/*++

Routine Description:

    Stop the hardware simulation....  Wait until the hardware simulation
    has successfully stopped and then return.

Arguments:

    None

Return Value:

    Success / Failure

--*/

{
    KIRQL Irql;
    //
    // If the hardware is told to stop while it's running, we need to
    // halt the interrupts first.  If we're already paused, this has
    // already been done.
    //
    if (m_HardwareState == HardwareRunning) {
    
        m_StopHardware = TRUE;
    
        KeWaitForSingleObject (
            &m_HardwareEvent,
            Suspended,
            KernelMode,
            FALSE,
            NULL
            );
    
        ASSERT (m_StopHardware == FALSE);

    }

    m_HardwareState = HardwareStopped;

    //
    // The image synthesizer may still be around.  Just for safety's
    // sake, NULL out the image synthesis buffer and toast it.
    //
    m_ImageSynth -> SetBuffer (NULL);

    if (m_SynthesisBuffer) {
        ExFreePool (m_SynthesisBuffer);
        m_SynthesisBuffer = NULL;
    }

    //
    // Protect the S/G list
    //
    KeAcquireSpinLock (&m_ListLock, &Irql);
    // 
    // Free S/G buffer 
    // 
    // 
    while (m_ScatterGatherMappingsQueued > 0) {
        LIST_ENTRY *listEntry = RemoveHeadList (&m_ScatterGatherMappings);
        m_ScatterGatherMappingsQueued--;
        PSCATTER_GATHER_ENTRY SGEntry =
            reinterpret_cast <PSCATTER_GATHER_ENTRY> (
                CONTAINING_RECORD (
                    listEntry,
                    SCATTER_GATHER_ENTRY,
                    ListEntry
                    )
                );
        // 
        // Release the scatter / gather entry back to our lookaside. 
        // 
        ExFreeToNPagedLookasideList (
            &m_ScatterGatherLookaside,
            reinterpret_cast <PVOID> (SGEntry)
            );
    } 

    m_NumMappingsCompleted = 0;
    m_ScatterGatherBytesQueued = 0;
    //
    // Delete the scatter / gather lookaside for this run.
    //
    ExDeleteNPagedLookasideList (&m_ScatterGatherLookaside);

    KeReleaseSpinLock (&m_ListLock, Irql);

    return STATUS_SUCCESS;

}
Exemplo n.º 19
0
static NTSTATUS NTAPI
V4vDispatchPnP(PDEVICE_OBJECT fdo, PIRP irp)
{
    NTSTATUS           status = STATUS_SUCCESS;
    PIO_STACK_LOCATION isl = IoGetCurrentIrpStackLocation(irp);
    PXENV4V_EXTENSION  pde = V4vGetDeviceExtension(fdo);
    KEVENT             kev;

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    TraceVerbose((" =PnP= 0x%x\n", isl->MinorFunction));

    status = IoAcquireRemoveLock(&pde->removeLock, irp);
    if (!NT_SUCCESS(status)) {
        TraceError(("failed to acquire IO lock - error: 0x%x\n", status));
        return V4vSimpleCompleteIrp(irp, status);
    }

    switch (isl->MinorFunction) {
    case IRP_MN_START_DEVICE:
        KeInitializeEvent(&kev, NotificationEvent, FALSE);
        // Send the start down and wait for it to complete
        IoCopyCurrentIrpStackLocationToNext(irp);
        IoSetCompletionRoutine(irp, V4vStartDeviceIoCompletion, &kev, TRUE, TRUE, TRUE);
        status = IoCallDriver(pde->ldo, irp);
        if (status == STATUS_PENDING) {
            // Wait for everything underneath us to complete
            TraceVerbose(("Device start waiting for lower device.\n"));
            KeWaitForSingleObject(&kev, Executive, KernelMode, FALSE, NULL);
            TraceVerbose(("Device start wait finished.\n"));
        }

        status = irp->IoStatus.Status;
        if (!NT_SUCCESS(status)) {
            TraceError(("Failed to start lower drivers: %x.\n", status));
            IoCompleteRequest(irp, IO_NO_INCREMENT);
            break;
        }

        status = STATUS_SUCCESS;

        // Connect our interrupt (ec).
        status = V4vInitializeEventChannel(fdo);
        if (NT_SUCCESS(status)) {
            InterlockedExchange(&pde->state, XENV4V_DEV_STARTED);
        }
        else {
            TraceError(("failed to initialize event channel - error: 0x%x\n", status));
        }

        irp->IoStatus.Status = status;
        IoCompleteRequest(irp, IO_NO_INCREMENT);
        break;
    case IRP_MN_STOP_DEVICE:
        // Stop our device's IO processing
        V4vStopDevice(fdo, pde);

        // Pass it down
        irp->IoStatus.Status = STATUS_SUCCESS;
        IoSkipCurrentIrpStackLocation(irp);
        status = IoCallDriver(pde->ldo, irp);
        break;        
    case IRP_MN_REMOVE_DEVICE:
        // Stop our device's IO processing
        V4vStopDevice(fdo, pde);

        // Cleanup anything here that locks for IO
        IoReleaseRemoveLockAndWait(&pde->removeLock, irp);

        // Pass it down first
        IoSkipCurrentIrpStackLocation(irp);
        status = IoCallDriver(pde->ldo, irp);

        // Then detach and cleanup our device
        xenbus_change_state(XBT_NIL, pde->frontendPath, "state", XENBUS_STATE_CLOSED);
        IoDetachDevice(pde->ldo);
        ExDeleteNPagedLookasideList(&pde->destLookasideList);
        XmFreeMemory(pde->frontendPath);
        IoDeleteSymbolicLink(&pde->symbolicLink);
        IoDeleteDevice(fdo);
        InterlockedAnd(&g_deviceCreated, 0);
        return status;
    default:
        // Pass it down
        TraceVerbose(("IRP_MJ_PNP MinorFunction %d passed down\n", isl->MinorFunction));
        IoSkipCurrentIrpStackLocation(irp);
        status = IoCallDriver(pde->ldo, irp);
    };

    // Everybody but REMOVE
    IoReleaseRemoveLock(&pde->removeLock, irp); 

    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));

    return status;
}