From b3443bcbb9d3148941da8ea591f8f753e698d0f4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 6 Oct 2008 18:56:44 +0000 Subject: [PATCH] - Call the MiniportShutdown handler at the right time - Now we call it upon system shutdown and if a bug check occurred svn path=/branches/aicom-network-fixes/; revision=36667 --- drivers/network/ndis/ndis/miniport.c | 40 ++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/network/ndis/ndis/miniport.c b/drivers/network/ndis/ndis/miniport.c index 550d184e1ea..3238fcfc959 100644 --- a/drivers/network/ndis/ndis/miniport.c +++ b/drivers/network/ndis/ndis/miniport.c @@ -1137,8 +1137,10 @@ NdisMDeregisterAdapterShutdownHandler( NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n")); - if(Adapter->BugcheckContext->ShutdownHandler) + if(Adapter->BugcheckContext->ShutdownHandler) { KeDeregisterBugCheckCallback(Adapter->BugcheckContext->CallbackRecord); + IoUnregisterShutdownNotification(Adapter->NdisMiniportBlock.DeviceObject); + } } @@ -1306,13 +1308,10 @@ NdisMRegisterAdapterShutdownHandler( */ { PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportHandle; - PMINIPORT_BUGCHECK_CONTEXT BugcheckContext = Adapter->BugcheckContext; + PMINIPORT_BUGCHECK_CONTEXT BugcheckContext; NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n")); - if(BugcheckContext) - return; - BugcheckContext = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_BUGCHECK_CONTEXT)); if(!BugcheckContext) { @@ -1324,11 +1323,19 @@ NdisMRegisterAdapterShutdownHandler( BugcheckContext->DriverContext = ShutdownContext; BugcheckContext->CallbackRecord = ExAllocatePool(NonPagedPool, sizeof(KBUGCHECK_CALLBACK_RECORD)); + if (!BugcheckContext->CallbackRecord) { + ExFreePool(BugcheckContext); + return; + } + + Adapter->BugcheckContext = BugcheckContext; KeInitializeCallbackRecord(BugcheckContext->CallbackRecord); KeRegisterBugCheckCallback(BugcheckContext->CallbackRecord, NdisIBugcheckCallback, BugcheckContext, sizeof(BugcheckContext), (PUCHAR)"Ndis Miniport"); + + IoRegisterShutdownNotification(Adapter->NdisMiniportBlock.DeviceObject); } @@ -1781,6 +1788,28 @@ NdisIPnPStopDevice( return STATUS_SUCCESS; } +NTSTATUS +NTAPI +NdisIShutdown( + IN PDEVICE_OBJECT DeviceObject, + PIRP Irp) +{ + PLOGICAL_ADAPTER Adapter = DeviceObject->DeviceExtension; + PMINIPORT_BUGCHECK_CONTEXT Context = Adapter->BugcheckContext; + ADAPTER_SHUTDOWN_HANDLER ShutdownHandler = Context->ShutdownHandler; + + ASSERT(ShutdownHandler); + + ShutdownHandler(Context->DriverContext); + + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = 0; + + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return STATUS_SUCCESS; +} + NTSTATUS NTAPI @@ -2075,6 +2104,7 @@ NdisMRegisterMiniport( *MiniportPtr = Miniport; Miniport->DriverObject->MajorFunction[IRP_MJ_PNP] = NdisIDispatchPnp; + Miniport->DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = NdisIShutdown; Miniport->DriverObject->DriverExtension->AddDevice = NdisIAddDevice; return NDIS_STATUS_SUCCESS;