Changeset 70274 in vbox for trunk/src/VBox
- Timestamp:
- Dec 21, 2017 1:39:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp
r70270 r70274 196 196 static NTSTATUS vgdrvNtShutdown(PDEVICE_OBJECT pDevObj, PIRP pIrp); 197 197 static NTSTATUS vgdrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp); 198 static VOID NTAPI vgdrvNtBugCheckCallback(PVOID pvBuffer, ULONG cbBuffer); 198 199 #ifdef VBOX_STRICT 199 200 static void vgdrvNtDoTests(void); … … 228 229 *********************************************************************************************************************************/ 229 230 /** The detected NT (windows) version. */ 230 static VGDRVNTVER g_enmVGDrvNtVer = VGDRVNTVER_INVALID;231 static VGDRVNTVER g_enmVGDrvNtVer = VGDRVNTVER_INVALID; 231 232 /** Pointer to the PoStartNextPowerIrp routine (in the NT kernel). 232 233 * Introduced in Windows 2000. */ 233 static decltype(PoStartNextPowerIrp) *g_pfnPoStartNextPowerIrp = NULL;234 static decltype(PoStartNextPowerIrp) *g_pfnPoStartNextPowerIrp = NULL; 234 235 /** Pointer to the PoCallDriver routine (in the NT kernel). 235 236 * Introduced in Windows 2000. */ 236 static decltype(PoCallDriver) *g_pfnPoCallDriver = NULL; 237 238 237 static decltype(PoCallDriver) *g_pfnPoCallDriver = NULL; 238 /** Pointer to the KeRegisterBugCheckCallback routine (in the NT kernel). 239 * Introduced in Windows 3.50. */ 240 static decltype(KeRegisterBugCheckCallback) *g_pfnKeRegisterBugCheckCallback = NULL; 241 /** Pointer to the KeRegisterBugCheckCallback routine (in the NT kernel). 242 * Introduced in Windows 3.50. */ 243 static decltype(KeDeregisterBugCheckCallback) *g_pfnKeDeregisterBugCheckCallback = NULL; 244 /** Pointer to the KiBugCheckData array (in the NT kernel). 245 * Introduced in Windows 4. */ 246 static uintptr_t const *g_pauKiBugCheckData = NULL; 247 /** Set if the callback was successfully registered and needs deregistering. */ 248 static bool g_fBugCheckCallbackRegistered = false; 249 /** The bugcheck callback record. */ 250 static KBUGCHECK_CALLBACK_RECORD g_BugCheckCallbackRec; 239 251 240 252 /** … … 347 359 * Dynamically resolve symbols not present in NT4. 348 360 */ 349 int rc; 361 RTDBGKRNLINFO hKrnlInfo; 362 int rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/); 363 if (RT_SUCCESS(rc)) 364 { 365 g_pfnKeRegisterBugCheckCallback = (decltype(KeRegisterBugCheckCallback) *) RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "KeRegisterBugCheckCallback"); 366 g_pfnKeDeregisterBugCheckCallback = (decltype(KeDeregisterBugCheckCallback) *)RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "KeDeregisterBugCheckCallback"); 367 g_pauKiBugCheckData = (uintptr_t const *) RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "KiBugCheckData"); 368 g_pfnPoCallDriver = (decltype(PoCallDriver) *) RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "PoCallDriver"); 369 g_pfnPoStartNextPowerIrp = (decltype(PoStartNextPowerIrp) *) RTR0DbgKrnlInfoGetSymbol(hKrnlInfo, NULL, "PoStartNextPowerIrp"); 350 370 #ifdef TARGET_NT4 351 if (g_enmVGDrvNtVer <= VGDRVNTVER_WINNT4) 352 rc = VINF_SUCCESS; 353 else 371 if (g_enmVGDrvNtVer > VGDRVNTVER_WINNT4) 354 372 #endif 355 { 356 RTDBGKRNLINFO hKrnlInfo; 357 rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/); 358 if (RT_SUCCESS(rc)) 359 { 360 int rc1 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "PoCallDriver", (void **)&g_pfnPoCallDriver); 361 int rc2 = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "PoStartNextPowerIrp", (void **)&g_pfnPoStartNextPowerIrp); 362 if (g_enmVGDrvNtVer > VGDRVNTVER_WINNT4 && RT_FAILURE(rc1)) 363 rc = rc1; 364 if (g_enmVGDrvNtVer > VGDRVNTVER_WINNT4 && RT_FAILURE(rc2)) 365 rc = rc2; 366 RTR0DbgKrnlInfoRelease(hKrnlInfo); 367 } 373 { 374 if (!g_pfnPoCallDriver) { LogRelFunc(("Missing PoCallDriver!\n")); rc = VERR_SYMBOL_NOT_FOUND; } 375 if (!g_pfnPoStartNextPowerIrp) { LogRelFunc(("Missing PoStartNextPowerIrp!\n")); rc = VERR_SYMBOL_NOT_FOUND; } 376 } 377 378 RTR0DbgKrnlInfoRelease(hKrnlInfo); 368 379 } 369 380 if (RT_SUCCESS(rc)) … … 393 404 if (NT_SUCCESS(rcNt)) 394 405 { 406 /* 407 * Try register the bugcheck callback (non-fatal). 408 */ 409 if ( g_pfnKeRegisterBugCheckCallback 410 && g_pfnKeDeregisterBugCheckCallback) 411 { 412 AssertCompile(BufferEmpty == 0); 413 KeInitializeCallbackRecord(&g_BugCheckCallbackRec); 414 if (g_pfnKeRegisterBugCheckCallback(&g_BugCheckCallbackRec, vgdrvNtBugCheckCallback, 415 NULL, 0, (PUCHAR)"VBoxGuest")) 416 g_fBugCheckCallbackRegistered = true; 417 else 418 g_fBugCheckCallbackRegistered = false; 419 } 420 else 421 Assert(g_pfnKeRegisterBugCheckCallback == NULL && g_pfnKeDeregisterBugCheckCallback); 422 395 423 LogFlowFunc(("Returning %#x\n", rcNt)); 396 424 return rcNt; 397 425 } 398 426 } 427 else 428 rcNt = STATUS_PROCEDURE_NOT_FOUND; 399 429 } 400 430 … … 816 846 { 817 847 Log(("vgdrvNt4CreateDevice: Device extension created\n")); 818 # ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION 819 rc = hlpRegisterBugCheckCallback(pDevExt);820 # endif 848 849 /* Do the actual VBox init ... */ 850 rc = vgdrvNtSetupDevice(pDevExt, pDeviceObject, NULL /*pIrp*/, pDrvObj, pRegPath); 821 851 if (NT_SUCCESS(rc)) 822 852 { 823 /* Do the actual VBox init ... */ 824 rc = vgdrvNtSetupDevice(pDevExt, pDeviceObject, NULL /*pIrp*/, pDrvObj, pRegPath); 825 if (NT_SUCCESS(rc)) 826 { 827 Log(("vgdrvNt4CreateDevice: Returning rc = 0x%x (succcess)\n", rc)); 828 return rc; 829 } 830 831 /* bail out */ 853 Log(("vgdrvNt4CreateDevice: Returning rc = 0x%x (succcess)\n", rc)); 854 return rc; 832 855 } 856 857 /* bail out */ 833 858 VGDrvCommonDeleteDevExtFundament(&pDevExt->Core); 834 859 } … … 894 919 if (pDevExt->pNextLowerDriver != NULL) 895 920 { 896 /* 897 * If we reached this point we're fine with the basic driver setup, 898 * so continue to init our own things. 899 */ 900 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION 901 vgdrvNtBugCheckCallback(pDevExt); /* Ignore failure! */ 902 #endif 903 if (NT_SUCCESS(rcNt)) 904 { 905 /* Ensure we are not called at elevated IRQL, even if our code isn't pagable any more. */ 906 pDeviceObject->Flags |= DO_POWER_PAGABLE; 907 908 /* Driver is ready now. */ 909 pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; 910 LogFlowFunc(("Returning with rcNt=%#x (success)\n", rcNt)); 911 return rcNt; 912 } 913 914 IoDetachDevice(pDevExt->pNextLowerDriver); 921 /* Ensure we are not called at elevated IRQL, even if our code isn't pagable any more. */ 922 pDeviceObject->Flags |= DO_POWER_PAGABLE; 923 924 /* Driver is ready now. */ 925 pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; 926 LogFlowFunc(("Returning with rcNt=%#x (success)\n", rcNt)); 927 return rcNt; 915 928 } 916 else 917 { 918 LogFunc(("IoAttachDeviceToDeviceStack did not give a nextLowerDriver!\n")); 919 rcNt = STATUS_DEVICE_NOT_CONNECTED; 920 } 929 930 LogFunc(("IoAttachDeviceToDeviceStack did not give a nextLowerDriver!\n")); 931 rcNt = STATUS_DEVICE_NOT_CONNECTED; 921 932 VGDrvCommonDeleteDevExtFundament(&pDevExt->Core); 922 933 } … … 1026 1037 pDevExt->pPowerStateRequest = NULL; /* Will be deleted by the following call. */ 1027 1038 VGDrvCommonDeleteDevExtFundament(&pDevExt->Core); 1028 1029 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION1030 hlpDeregisterBugCheckCallback(pDevExt);1031 #endif1032 1039 1033 1040 /* … … 1620 1627 VGDrvCommonDestroyLoggers(); 1621 1628 RTR0Term(); 1622 LogFlowFunc(("Returning\n")); 1629 1630 /* 1631 * Finally deregister the bugcheck callback. Do it late to catch trouble in RTR0Term. 1632 */ 1633 if (g_fBugCheckCallbackRegistered) 1634 { 1635 g_pfnKeDeregisterBugCheckCallback(&g_BugCheckCallbackRec); 1636 g_fBugCheckCallbackRegistered = false; 1637 } 1623 1638 } 1624 1639 … … 1939 1954 1940 1955 return STATUS_NOT_SUPPORTED; 1956 } 1957 1958 1959 /** 1960 * Bug check callback (KBUGCHECK_CALLBACK_ROUTINE). 1961 * 1962 * This adds a log entry on the host, in case Hyper-V isn't active or the guest 1963 * is too old for reporting it itself via the crash MSRs. 1964 * 1965 * @param pvBuffer Not used. 1966 * @param cbBuffer Not used. 1967 */ 1968 static VOID NTAPI vgdrvNtBugCheckCallback(PVOID pvBuffer, ULONG cbBuffer) 1969 { 1970 if (g_pauKiBugCheckData) 1971 RTLogBackdoorPrintf("VBoxGuest: BugCheck! P0=%#zx P1=%#zx P2=%#zx P3=%#zx P4=%#zx\n", g_pauKiBugCheckData[0], 1972 g_pauKiBugCheckData[1], g_pauKiBugCheckData[2], g_pauKiBugCheckData[3], g_pauKiBugCheckData[4]); 1973 else 1974 RTLogBackdoorPrintf("VBoxGuest: BugCheck!\n"); 1975 1976 RT_NOREF(pvBuffer, cbBuffer); 1941 1977 } 1942 1978
Note:
See TracChangeset
for help on using the changeset viewer.