VirtualBox

Changeset 70274 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 21, 2017 1:39:30 PM (7 years ago)
Author:
vboxsync
Message:

VBoxGuest-win.cpp: Reintroduced the bugcheck callback and backdoor logging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp

    r70270 r70274  
    196196static NTSTATUS vgdrvNtShutdown(PDEVICE_OBJECT pDevObj, PIRP pIrp);
    197197static NTSTATUS vgdrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);
     198static VOID NTAPI vgdrvNtBugCheckCallback(PVOID pvBuffer, ULONG cbBuffer);
    198199#ifdef VBOX_STRICT
    199200static void     vgdrvNtDoTests(void);
     
    228229*********************************************************************************************************************************/
    229230/** The detected NT (windows) version. */
    230 static VGDRVNTVER                       g_enmVGDrvNtVer = VGDRVNTVER_INVALID;
     231static VGDRVNTVER                               g_enmVGDrvNtVer = VGDRVNTVER_INVALID;
    231232/** Pointer to the PoStartNextPowerIrp routine (in the NT kernel).
    232233 * Introduced in Windows 2000. */
    233 static decltype(PoStartNextPowerIrp)   *g_pfnPoStartNextPowerIrp = NULL;
     234static decltype(PoStartNextPowerIrp)           *g_pfnPoStartNextPowerIrp = NULL;
    234235/** Pointer to the PoCallDriver routine (in the NT kernel).
    235236 * Introduced in Windows 2000. */
    236 static decltype(PoCallDriver)          *g_pfnPoCallDriver = NULL;
    237 
    238 
     237static decltype(PoCallDriver)                  *g_pfnPoCallDriver = NULL;
     238/** Pointer to the KeRegisterBugCheckCallback routine (in the NT kernel).
     239 * Introduced in Windows 3.50. */
     240static decltype(KeRegisterBugCheckCallback)    *g_pfnKeRegisterBugCheckCallback = NULL;
     241/** Pointer to the KeRegisterBugCheckCallback routine (in the NT kernel).
     242 * Introduced in Windows 3.50. */
     243static decltype(KeDeregisterBugCheckCallback)  *g_pfnKeDeregisterBugCheckCallback = NULL;
     244/** Pointer to the KiBugCheckData array (in the NT kernel).
     245 * Introduced in Windows 4. */
     246static uintptr_t const                         *g_pauKiBugCheckData = NULL;
     247/** Set if the callback was successfully registered and needs deregistering.  */
     248static bool                                     g_fBugCheckCallbackRegistered = false;
     249/** The bugcheck callback record. */
     250static KBUGCHECK_CALLBACK_RECORD                g_BugCheckCallbackRec;
    239251
    240252/**
     
    347359         * Dynamically resolve symbols not present in NT4.
    348360         */
    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");
    350370#ifdef TARGET_NT4
    351         if (g_enmVGDrvNtVer <= VGDRVNTVER_WINNT4)
    352             rc = VINF_SUCCESS;
    353         else
     371            if (g_enmVGDrvNtVer > VGDRVNTVER_WINNT4)
    354372#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);
    368379        }
    369380        if (RT_SUCCESS(rc))
     
    393404            if (NT_SUCCESS(rcNt))
    394405            {
     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
    395423                LogFlowFunc(("Returning %#x\n", rcNt));
    396424                return rcNt;
    397425            }
    398426        }
     427        else
     428            rcNt = STATUS_PROCEDURE_NOT_FOUND;
    399429    }
    400430
     
    816846            {
    817847                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);
    821851                if (NT_SUCCESS(rc))
    822852                {
    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;
    832855                }
     856
     857                /* bail out */
    833858                VGDrvCommonDeleteDevExtFundament(&pDevExt->Core);
    834859            }
     
    894919                if (pDevExt->pNextLowerDriver != NULL)
    895920                {
    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;
    915928                }
    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;
    921932                VGDrvCommonDeleteDevExtFundament(&pDevExt->Core);
    922933            }
     
    10261037    pDevExt->pPowerStateRequest = NULL; /* Will be deleted by the following call. */
    10271038    VGDrvCommonDeleteDevExtFundament(&pDevExt->Core);
    1028 
    1029 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
    1030     hlpDeregisterBugCheckCallback(pDevExt);
    1031 #endif
    10321039
    10331040    /*
     
    16201627    VGDrvCommonDestroyLoggers();
    16211628    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    }
    16231638}
    16241639
     
    19391954
    19401955    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 */
     1968static 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);
    19411977}
    19421978
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette