VirtualBox

Ignore:
Timestamp:
Dec 8, 2018 7:11:20 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127312
Message:

VBoxSDS,VBoxSVC: Some DEBUG_bird experiments for identifying the caller. bugref:3300

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/win/svcmain.cpp

    r76067 r76071  
    2020*   Header Files                                                                                                                 *
    2121*********************************************************************************************************************************/
    22 #include <iprt/win/windows.h>
    23 #include <stdio.h>
    24 #include <stdlib.h>
    25 #include <tchar.h>
     22# include <iprt/win/windows.h>
     23#ifdef DEBUG_bird
     24# include <RpcAsync.h>
     25#endif
    2626
    2727#include "VBox/com/defs.h"
     
    3939#include <iprt/initterm.h>
    4040#include <iprt/string.h>
    41 #include <iprt/uni.h>
    4241#include <iprt/path.h>
    4342#include <iprt/getopt.h>
     
    4544#include <iprt/asm.h>
    4645
    47 #include <TlHelp32.h>
     46//#ifdef VBOX_WITH_SDS
     47//# include <TlHelp32.h>
     48//#endif
    4849
    4950
     
    220221
    221222
    222 /* Passed to CreateThread to monitor the shutdown event */
    223 static DWORD WINAPI MonitorProc(void* pv)
    224 {
    225     CExeModule* p = (CExeModule*)pv;
     223/** Passed to CreateThread to monitor the shutdown event. */
     224static DWORD WINAPI MonitorProc(void *pv)
     225{
     226    CExeModule *p = (CExeModule *)pv;
    226227    p->MonitorShutdown();
    227228    return 0;
     
    461462HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox)
    462463{
     464# ifdef DEBUG_bird
     465    RPC_CALL_ATTRIBUTES_V2_W CallAttribs = { RPC_CALL_ATTRIBUTES_VERSION, RPC_QUERY_CLIENT_PID | RPC_QUERY_IS_CLIENT_LOCAL };
     466    RPC_STATUS rcRpc = RpcServerInqCallAttributesW(NULL, &CallAttribs);
     467    LogRel(("i_registerWithSds: RpcServerInqCallAttributesW -> %#x ClientPID=%#x IsClientLocal=%d ProtocolSequence=%#x CallStatus=%#x CallType=%#x OpNum=%#x InterfaceUuid=%RTuuid\n",
     468            rcRpc, CallAttribs.ClientPID, CallAttribs.IsClientLocal, CallAttribs.ProtocolSequence, CallAttribs.CallStatus,
     469            CallAttribs.CallType, CallAttribs.OpNum, &CallAttribs.InterfaceUuid));
     470# endif
     471
    463472    /*
    464473     * Connect to VBoxSDS.
     
    505514HRESULT VirtualBoxClassFactory::i_getVirtualBox(IUnknown **ppResult)
    506515{
     516# ifdef DEBUG_bird
     517    RPC_CALL_ATTRIBUTES_V2_W CallAttribs = { RPC_CALL_ATTRIBUTES_VERSION, RPC_QUERY_CLIENT_PID | RPC_QUERY_IS_CLIENT_LOCAL };
     518    RPC_STATUS rcRpc = RpcServerInqCallAttributesW(NULL, &CallAttribs);
     519    LogRel(("i_getVirtualBox: RpcServerInqCallAttributesW -> %#x ClientPID=%#x IsClientLocal=%d ProtocolSequence=%#x CallStatus=%#x CallType=%#x OpNum=%#x InterfaceUuid=%RTuuid\n",
     520            rcRpc, CallAttribs.ClientPID, CallAttribs.IsClientLocal, CallAttribs.ProtocolSequence, CallAttribs.CallStatus,
     521            CallAttribs.CallType, CallAttribs.OpNum, &CallAttribs.InterfaceUuid));
     522# endif
    507523    IUnknown *pObj = m_pObj;
    508524    if (pObj)
     
    537553}
    538554
     555#ifdef DEBUG_bird
     556# include <psapi.h> /* for GetProcessImageFileNameW */
     557
     558/** Logs the RPC caller info to the release log. */
     559static void logCaller(const char *pszFormat, ...)
     560{
     561    char szTmp[80];
     562    va_list va;
     563    va_start(va, pszFormat);
     564    RTStrPrintfV(szTmp, sizeof(szTmp), pszFormat, va);
     565    va_end(va);
     566
     567    RPC_CALL_ATTRIBUTES_V2_W CallAttribs = { RPC_CALL_ATTRIBUTES_VERSION, RPC_QUERY_CLIENT_PID | RPC_QUERY_IS_CLIENT_LOCAL };
     568    RPC_STATUS rcRpc = RpcServerInqCallAttributesW(NULL, &CallAttribs);
     569
     570    RTUTF16 wszProcName[256];
     571    wszProcName[0] = '\0';
     572    if (rcRpc == 0 && CallAttribs.ClientPID != 0)
     573    {
     574        HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)(uintptr_t)CallAttribs.ClientPID);
     575        if (hProcess)
     576        {
     577            RT_ZERO(wszProcName);
     578            GetProcessImageFileNameW(hProcess, wszProcName, RT_ELEMENTS(wszProcName) - 1);
     579            CloseHandle(hProcess);
     580        }
     581    }
     582    LogRel(("%s [rcRpc=%#x ClientPID=%#zx/%zu (%ls) IsClientLocal=%d ProtocolSequence=%#x CallStatus=%#x CallType=%#x OpNum=%#x InterfaceUuid=%RTuuid]\n",
     583            szTmp, rcRpc, CallAttribs.ClientPID, CallAttribs.ClientPID, wszProcName, CallAttribs.IsClientLocal,
     584            CallAttribs.ProtocolSequence, CallAttribs.CallStatus, CallAttribs.CallType, CallAttribs.OpNum,
     585            &CallAttribs.InterfaceUuid));
     586}
     587
     588/**
     589 * Caller watcher wrapper exploration wrapping CComObjectCached.
     590 * @sa @bugref{3300}
     591 */
     592template <class Base> class DebugWatcher : public Base
     593{
     594public:
     595    DebugWatcher(void *a_pWhatever = NULL) : Base(a_pWhatever)
     596    {
     597    }
     598
     599    virtual ~DebugWatcher()
     600    {
     601    }
     602
     603    STDMETHOD_(ULONG, AddRef)() throw()
     604    {
     605        ULONG cRefs = Base::AddRef();
     606        logCaller("AddRef -> %u", cRefs);
     607        return cRefs;
     608    }
     609
     610    STDMETHOD_(ULONG, Release)() throw()
     611    {
     612        ULONG cRefs = Base::Release();
     613        logCaller("Release -> %u", cRefs);
     614        return cRefs;
     615    }
     616
     617    STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj) throw()
     618    {
     619        HRESULT hrc = Base::QueryInterface(iid, ppvObj);
     620        logCaller("QueryInterface %RTuuid -> %Rhrc %p", iid, hrc, *ppvObj);
     621        return hrc;
     622    }
     623
     624    static HRESULT WINAPI CreateInstance(DebugWatcher<Base> **pp) throw()
     625    {
     626        AssertReturn(pp, E_POINTER);
     627        *pp = NULL;
     628
     629        HRESULT hrc = E_OUTOFMEMORY;
     630        DebugWatcher<Base> *p = new (std::nothrow) DebugWatcher<Base>();
     631        if (p)
     632        {
     633            p->SetVoid(NULL);
     634            p->InternalFinalConstructAddRef();
     635            hrc = p->_AtlInitialConstruct();
     636            if (SUCCEEDED(hrc))
     637                hrc = p->FinalConstruct();
     638            p->InternalFinalConstructRelease();
     639            if (FAILED(hrc))
     640                delete p;
     641            else
     642                *pp = p;
     643        }
     644        return hrc;
     645    }
     646
     647};
     648
     649#endif /* DEBUG_bird */
    539650
    540651/**
     
    553664STDMETHODIMP VirtualBoxClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvObj)
    554665{
     666# ifdef DEBUG_bird
     667    logCaller("VirtualBoxClassFactory::CreateInstance: %RTuuid", riid);
     668# endif
    555669    HRESULT hrc = E_POINTER;
    556670    if (ppvObj != NULL)
     
    589703                        {
    590704                            ATL::_pAtlModule->Lock();
     705#ifdef DEBUG_bird
     706                            DebugWatcher<ATL::CComObjectCached<VirtualBox>> *p;
     707                            m_hrcCreate = hrc = DebugWatcher<ATL::CComObjectCached<VirtualBox>>::CreateInstance(&p);
     708#else
    591709                            ATL::CComObjectCached<VirtualBox> *p;
    592710                            m_hrcCreate = hrc = ATL::CComObjectCached<VirtualBox>::CreateInstance(&p);
     711#endif
    593712                            if (SUCCEEDED(hrc))
    594713                            {
     
    9351054            case 'h':
    9361055            {
    937                 TCHAR txt[]= L"Options:\n\n"
    938                              L"/RegServer:\tregister COM out-of-proc server\n"
    939                              L"/UnregServer:\tunregister COM out-of-proc server\n"
    940                              L"/ReregServer:\tunregister and register COM server\n"
    941                              L"no options:\trun the server";
    942                 TCHAR title[]=_T("Usage");
     1056                static const WCHAR s_wszText[]  = L"Options:\n\n"
     1057                                                  L"/RegServer:\tregister COM out-of-proc server\n"
     1058                                                  L"/UnregServer:\tunregister COM out-of-proc server\n"
     1059                                                  L"/ReregServer:\tunregister and register COM server\n"
     1060                                                  L"no options:\trun the server";
     1061                static const WCHAR s_wszTitle[] = L"Usage";
    9431062                fRun = false;
    944                 MessageBox(NULL, txt, title, MB_OK);
     1063                MessageBoxW(NULL, s_wszText, s_wszTitle, MB_OK);
    9451064                return 0;
    9461065            }
     
    9481067            case 'V':
    9491068            {
    950                 char *psz = NULL;
    951                 RTStrAPrintf(&psz, "%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
    952                 PRTUTF16 txt = NULL;
    953                 RTStrToUtf16(psz, &txt);
    954                 TCHAR title[]=_T("Version");
     1069                static const WCHAR s_wszTitle[] = L"Version";
     1070                char         *pszText = NULL;
     1071                RTStrAPrintf(&pszText, "%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
     1072                PRTUTF16     pwszText = NULL;
     1073                RTStrToUtf16(pszText, &pwszText);
     1074                RTStrFree(pszText);
     1075                MessageBoxW(NULL, pwszText, s_wszTitle, MB_OK);
     1076                RTUtf16Free(pwszText);
    9551077                fRun = false;
    956                 MessageBox(NULL, txt, title, MB_OK);
    957                 RTStrFree(psz);
    958                 RTUtf16Free(txt);
    9591078                return 0;
    9601079            }
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