VirtualBox

Changeset 69872 in vbox


Ignore:
Timestamp:
Nov 29, 2017 8:09:05 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119328
Message:

WDDM: display driver: debugging helper.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp

    r69500 r69872  
    1717
    1818#include "VBoxDispD3DCmn.h"
     19
     20#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
     21#include <Psapi.h>
     22#endif
    1923
    2024#include <stdio.h>
     
    688692#ifdef VBOXWDDMDISP_DEBUG_VEHANDLER
    689693
     694typedef BOOL WINAPI FNGetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb);
     695typedef FNGetModuleInformation *PFNGetModuleInformation;
     696
     697static PFNGetModuleInformation g_pfnGetModuleInformation = NULL;
     698static HMODULE g_hModPsapi = NULL;
    690699static PVOID g_VBoxWDbgVEHandler = NULL;
     700
     701static bool vboxVDbgIsAddressInModule(PVOID pv, const char *pszModuleName)
     702{
     703    HMODULE hMod = GetModuleHandleA(pszModuleName);
     704    if (!hMod)
     705        return false;
     706
     707    HANDLE hProcess = GetCurrentProcess();
     708
     709    if (!g_pfnGetModuleInformation)
     710        return false;
     711
     712    MODULEINFO ModuleInfo = {0};
     713    if (!g_pfnGetModuleInformation(hProcess, hMod, &ModuleInfo, sizeof(ModuleInfo)))
     714        return false;
     715
     716    return    (uintptr_t)ModuleInfo.lpBaseOfDll <= (uintptr_t)pv
     717           && (uintptr_t)pv < (uintptr_t)ModuleInfo.lpBaseOfDll + ModuleInfo.SizeOfImage;
     718}
     719
     720static bool vboxVDbgIsExceptionIgnored(PEXCEPTION_RECORD pExceptionRecord)
     721{
     722    /* Module (dll) names for GetModuleHandle.
     723     * Exceptions originated from these modules will be ignored.
     724     */
     725    static const char *apszIgnoredModuleNames[] =
     726    {
     727        NULL
     728    };
     729
     730    int i = 0;
     731    while (apszIgnoredModuleNames[i])
     732    {
     733        if (vboxVDbgIsAddressInModule(pExceptionRecord->ExceptionAddress, apszIgnoredModuleNames[i]))
     734            return true;
     735
     736        ++i;
     737    }
     738
     739    return false;
     740}
     741
    691742LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
    692743{
     744    static volatile bool g_fAllowIgnore = true; /* Might be changed in kernel debugger. */
     745
    693746    PEXCEPTION_RECORD pExceptionRecord = pExceptionInfo->ExceptionRecord;
    694     PCONTEXT pContextRecord = pExceptionInfo->ContextRecord;
     747    /* PCONTEXT pContextRecord = pExceptionInfo->ContextRecord; */
     748
    695749    switch (pExceptionRecord->ExceptionCode)
    696750    {
     751        default:
     752            break;
    697753        case EXCEPTION_BREAKPOINT:
    698754        case EXCEPTION_ACCESS_VIOLATION:
     
    703759        case EXCEPTION_INT_DIVIDE_BY_ZERO:
    704760        case EXCEPTION_ILLEGAL_INSTRUCTION:
    705             AssertRelease(0);
     761            if (g_fAllowIgnore && vboxVDbgIsExceptionIgnored(pExceptionRecord))
     762                break;
     763            ASMBreakpoint();
    706764            break;
    707         default:
     765        case 0x40010006: /* OutputDebugStringA? */
     766        case 0x4001000a: /* OutputDebugStringW? */
    708767            break;
    709768    }
     
    716775    g_VBoxWDbgVEHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
    717776    Assert(g_VBoxWDbgVEHandler);
     777
     778    g_hModPsapi = GetModuleHandleA("Psapi.dll"); /* Usually already loaded. */
     779    if (g_hModPsapi)
     780        g_pfnGetModuleInformation = (PFNGetModuleInformation)GetProcAddress(g_hModPsapi, "GetModuleInformation");
    718781}
    719782
     
    722785    Assert(g_VBoxWDbgVEHandler);
    723786    ULONG uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler);
    724     Assert(uResult);
     787    Assert(uResult); RT_NOREF(uResult);
    725788    g_VBoxWDbgVEHandler = NULL;
    726 }
    727 
    728 #endif
     789
     790    g_hModPsapi = NULL;
     791    g_pfnGetModuleInformation = NULL;
     792}
     793
     794#endif /* VBOXWDDMDISP_DEBUG_VEHANDLER */
    729795
    730796#if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV)
Note: See TracChangeset for help on using the changeset viewer.

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