Changeset 37083 in vbox
- Timestamp:
- May 13, 2011 7:24:39 PM (14 years ago)
- Location:
- trunk/src/VBox/HostDrivers/VBoxUSB/win/mon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbHook.cpp
r37042 r37083 51 51 if (pfnOldVal != pHook->pfnHook) 52 52 { 53 Assert Failed();53 AssertMsgFailed(("unhook failed!!!\n")); 54 54 /* this is bad! this could happen if someone else has chained another hook, 55 * return the failure and don't do anything else */ 55 * or (which is even worse) restored the "initial" entry value it saved when doing a hooking before us 56 * return the failure and don't do anything else 57 * the best thing to do if this happens is to leave everything as is 58 * and to prevent the driver from being unloaded to ensure no one references our unloaded hook routine */ 56 59 KeReleaseSpinLock(&pHook->Lock, Irql); 57 60 return STATUS_UNSUCCESSFUL; -
trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp
r37042 r37083 54 54 { 55 55 VBOXUSBHOOK_ENTRY Hook; 56 bool fUninitFailed; 56 57 } VBOXUSBHUB_PNPHOOK, *PVBOXUSBHUB_PNPHOOK; 57 58 … … 68 69 IO_REMOVE_LOCK RmLock; 69 70 uint32_t cOpens; 71 volatile LONG ulPreventUnloadOn; 72 PFILE_OBJECT pPreventUnloadFileObj; 70 73 } VBOXUSBMONGLOBALS, *PVBOXUSBMONGLOBALS; 71 74 … … 657 660 return STATUS_SUCCESS; 658 661 #else 662 if (g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed) 663 { 664 AssertMsgFailed(("trying to hook usbhub pnp after the unhook failed, do nothing & pretend success..\n")); 665 return STATUS_SUCCESS; 666 } 659 667 return VBoxUsbHookInstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook); 660 668 #endif … … 666 674 return STATUS_SUCCESS; 667 675 #else 668 return VBoxUsbHookUninstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook); 676 NTSTATUS Status = VBoxUsbHookUninstall(&g_VBoxUsbMonGlobals.UsbHubPnPHook.Hook); 677 if (!NT_SUCCESS(Status)) 678 { 679 AssertMsgFailed(("usbhub pnp unhook failed, setting the fUninitFailed flag, the current value of fUninitFailed (%d)\n", g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed)); 680 g_VBoxUsbMonGlobals.UsbHubPnPHook.fUninitFailed = true; 681 } 682 return Status; 669 683 #endif 670 684 } … … 677 691 FALSE, /* BOOLEAN Alertable */ 678 692 NULL /* IN PLARGE_INTEGER Timeout */ 679 ); 680 Assert(Status == STATUS_SUCCESS); 681 if (Status == STATUS_SUCCESS) 682 { 683 do 684 { 685 if (--g_VBoxUsbMonGlobals.cOpens) 686 break; 687 688 Status = vboxUsbMonHookUninstall(); 689 if (NT_SUCCESS(Status)) 690 { 691 Status = VBoxUsbFltTerm(); 692 if (NT_SUCCESS(Status)) 693 { 694 Status = STATUS_SUCCESS; 695 break; 696 } 697 else 698 { 699 AssertFailed(); 700 } 701 } 702 else 703 { 704 AssertFailed(); 705 } 706 707 ++g_VBoxUsbMonGlobals.cOpens; 708 Assert(g_VBoxUsbMonGlobals.cOpens == 1); 709 } while (0); 710 711 KeSetEvent(&g_VBoxUsbMonGlobals.OpenSynchEvent, 0, FALSE); 712 } 693 ); 694 AssertRelease(Status == STATUS_SUCCESS); 695 696 do 697 { 698 if (--g_VBoxUsbMonGlobals.cOpens) 699 break; 700 701 Status = vboxUsbMonHookUninstall(); 702 703 NTSTATUS tmpStatus = VBoxUsbFltTerm(); 704 if (!NT_SUCCESS(tmpStatus)) 705 { 706 /* this means a driver state is screwed up, KeBugCheckEx here ? */ 707 AssertReleaseFailed(); 708 } 709 } while (0); 710 711 KeSetEvent(&g_VBoxUsbMonGlobals.OpenSynchEvent, 0, FALSE); 712 713 713 return Status; 714 714 } … … 818 818 NTSTATUS Status = vboxUsbMonContextClose(pCtx); 819 819 Assert(Status == STATUS_SUCCESS); 820 if (Status != STATUS_SUCCESS) 821 { 822 AssertMsgFailed(("close failed with Status 0x%x, prefent unload\n", Status)); 823 if (!InterlockedExchange(&g_VBoxUsbMonGlobals.ulPreventUnloadOn, 1)) 824 { 825 LogRel(("ulPreventUnloadOn not set, preventing unload\n")); 826 UNICODE_STRING UniName; 827 PDEVICE_OBJECT pTmpDevObj; 828 RtlInitUnicodeString(&UniName, USBMON_DEVICE_NAME_NT); 829 NTSTATUS tmpStatus = IoGetDeviceObjectPointer(&UniName, FILE_ALL_ACCESS, &g_VBoxUsbMonGlobals.pPreventUnloadFileObj, &pTmpDevObj); 830 AssertRelease(NT_SUCCESS(tmpStatus)); 831 AssertRelease(pTmpDevObj == pDevObj); 832 } 833 else 834 { 835 AssertMsgFailed(("ulPreventUnloadOn already set\n")); 836 } 837 Status = STATUS_SUCCESS; 838 } 820 839 pFileObj->FsContext = NULL; 821 840 pIrp->IoStatus.Status = Status;
Note:
See TracChangeset
for help on using the changeset viewer.