📄 unload.c
字号:
// File Name:
// unload.c
//
// Contents:
// Routines that perform driver cleanup
//
#include "Ave2k.h"
//
// Forward declarations of local routines
//
// (None)
//
// If the compiler can handle it, make the cleanup
// pageable so it won't be hanging around all the
// time
//
#ifdef ALLOC_PRAGMA
#pragma alloc_text( page, Ave2kDriverUnload )
#pragma alloc_text( page, Ave2kReleaseHardware )
#endif // ALLOC_PRAGMA
//++
// Function:
// Ave2kDriverUnload
//
// Description:
// This function releases any resources
// allocated during driver initialization.
//
// Arguments:
// A pointer to the Driver object
//
// Return Value:
// (None)
//--
VOID
Ave2kDriverUnload(
IN PDRIVER_OBJECT DriverObject
)
{
#if _WIN32_WINNT==0x0400
//
// Stop interrupt processing and release hardware
//
Ave2kReleaseHardware( DriverObject );
#else
DebugPrintMsg("Unload and release hardware!");
DebugPrintClose();
#endif
}
//++
// Function:
// Ave2kReleaseHardware
//
// Description:
// This function releases any resources
// allocated during driver initialization.
//
// Arguments:
// A pointer to the Driver object
//
// Return Value:
// (None)
//--
VOID
Ave2kReleaseHardware(
IN PDRIVER_OBJECT DriverObject
)
{
PDEVICE_OBJECT pDevObj;
PDEVICE_EXTENSION pDevExt;
UNICODE_STRING linkName;
WCHAR linkNameBuffer[ AVE2K_MAX_NAME_LENGTH ];
UNICODE_STRING number;
WCHAR numberBuffer[10];
CM_RESOURCE_LIST ResList;
BOOLEAN bConflict;
linkName.Buffer = linkNameBuffer;
linkName.MaximumLength = AVE2K_MAX_NAME_LENGTH;
number.Buffer = numberBuffer;
number.MaximumLength = 10;
pDevObj = DriverObject->DeviceObject;
//
// Traverse the list of Device objects
// and clean up each one in turn...
//
while( pDevObj != NULL ) {
pDevExt = pDevObj->DeviceExtension;
//
// Add code here to save the state of
// the hardware in the Registry and/or
// to set the hardware into a known condition.
//
//
// Stop handling interrupts from device
//
Ave2kDisableInterrupts( pDevExt );
IoDisconnectInterrupt( pDevExt->pInterrupt );
MmUnmapIoSpace(pDevExt->PortBase, pDevExt->PortSpan);
//
// Deallocate hardware resources belonging
// only to this Device object...
//
ResList.Count = 0; // Build an empty list
IoReportResourceUsage(
NULL, // Default class name
DriverObject, // Ptr to Driver object
NULL, // No driver resources
0,
pDevObj, // Ptr to Device object
&ResList, // Device resources
sizeof( ResList ),
FALSE,
&bConflict ); // Junk, but required
//
// Form the Win32 symbolic link name.
//
linkName.Length = 0;
RtlAppendUnicodeToString(
&linkName,
AVE2K_WIN32_DEVICE_NAME );
//
// Attach Win32 device number to the
// end of the name; DOS device numbers
// are one greater than NT numbers...
//
number.Length = 0;
RtlIntegerToUnicodeString(
pDevExt->NtDeviceNumber + 1,
10,
&number );
RtlAppendUnicodeStringToString(
&linkName,
&number );
//
// Remove symbolic link from Object
// namespace...
//
IoDeleteSymbolicLink( &linkName );
//Free allocated buffer address
if(NULL != pDevExt->DataCommonBuffer1.BaseAddress)
HalFreeCommonBuffer(
#if _WIN32_WINNT==0x0500
(PADAPTER_OBJECT)
#endif
pDevExt->pAdapter,
pDevExt->DataCommonBuffer1.Length,
pDevExt->DataCommonBuffer1.LogicalAddress,
(PVOID)pDevExt->DataCommonBuffer1.BaseAddress,
FALSE);
if(NULL != pDevExt->DataCommonBuffer2.BaseAddress)
HalFreeCommonBuffer(
#if _WIN32_WINNT==0x0500
(PADAPTER_OBJECT)
#endif
pDevExt->pAdapter,
pDevExt->DataCommonBuffer2.Length,
pDevExt->DataCommonBuffer2.LogicalAddress,
(PVOID)pDevExt->DataCommonBuffer2.BaseAddress,
FALSE);
if(NULL != pDevExt->BitmapCommonBuffer.BaseAddress)
HalFreeCommonBuffer(
#if _WIN32_WINNT==0x0500
(PADAPTER_OBJECT)
#endif
pDevExt->pAdapter,
pDevExt->BitmapCommonBuffer.Length,
pDevExt->BitmapCommonBuffer.LogicalAddress,
(PVOID)pDevExt->BitmapCommonBuffer.BaseAddress,
FALSE);
//
// Get address of next Device object
// and get rid of the current one...
//
pDevObj = pDevObj->NextDevice;
IoDeleteDevice( pDevExt->DeviceObject );
}
//
// Deallocate hardware resources owned
// by the Driver object...
//
ResList.Count = 0; // Build an empty list
IoReportResourceUsage(
NULL, // Default class name
DriverObject, // Pointer to Driver object
&ResList, // Driver resources
sizeof( ResList ),
pDevObj, // Pointer to Device object
NULL, // Device resources
0,
FALSE, // Don't override conflicts
&bConflict ); // Junk, but required
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -