Changeset 76071 in vbox for trunk/src/VBox/Main/src-server/win
- Timestamp:
- Dec 8, 2018 7:11:20 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 127312
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r76067 r76071 20 20 * Header Files * 21 21 *********************************************************************************************************************************/ 22 # include <iprt/win/windows.h>23 #i nclude <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 26 26 27 27 #include "VBox/com/defs.h" … … 39 39 #include <iprt/initterm.h> 40 40 #include <iprt/string.h> 41 #include <iprt/uni.h>42 41 #include <iprt/path.h> 43 42 #include <iprt/getopt.h> … … 45 44 #include <iprt/asm.h> 46 45 47 #include <TlHelp32.h> 46 //#ifdef VBOX_WITH_SDS 47 //# include <TlHelp32.h> 48 //#endif 48 49 49 50 … … 220 221 221 222 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. */ 224 static DWORD WINAPI MonitorProc(void *pv) 225 { 226 CExeModule *p = (CExeModule *)pv; 226 227 p->MonitorShutdown(); 227 228 return 0; … … 461 462 HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox) 462 463 { 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 463 472 /* 464 473 * Connect to VBoxSDS. … … 505 514 HRESULT VirtualBoxClassFactory::i_getVirtualBox(IUnknown **ppResult) 506 515 { 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 507 523 IUnknown *pObj = m_pObj; 508 524 if (pObj) … … 537 553 } 538 554 555 #ifdef DEBUG_bird 556 # include <psapi.h> /* for GetProcessImageFileNameW */ 557 558 /** Logs the RPC caller info to the release log. */ 559 static 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 */ 592 template <class Base> class DebugWatcher : public Base 593 { 594 public: 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 */ 539 650 540 651 /** … … 553 664 STDMETHODIMP VirtualBoxClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvObj) 554 665 { 666 # ifdef DEBUG_bird 667 logCaller("VirtualBoxClassFactory::CreateInstance: %RTuuid", riid); 668 # endif 555 669 HRESULT hrc = E_POINTER; 556 670 if (ppvObj != NULL) … … 589 703 { 590 704 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 591 709 ATL::CComObjectCached<VirtualBox> *p; 592 710 m_hrcCreate = hrc = ATL::CComObjectCached<VirtualBox>::CreateInstance(&p); 711 #endif 593 712 if (SUCCEEDED(hrc)) 594 713 { … … 935 1054 case 'h': 936 1055 { 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"; 943 1062 fRun = false; 944 MessageBox (NULL, txt, title, MB_OK);1063 MessageBoxW(NULL, s_wszText, s_wszTitle, MB_OK); 945 1064 return 0; 946 1065 } … … 948 1067 case 'V': 949 1068 { 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); 955 1077 fRun = false; 956 MessageBox(NULL, txt, title, MB_OK);957 RTStrFree(psz);958 RTUtf16Free(txt);959 1078 return 0; 960 1079 }
Note:
See TracChangeset
for help on using the changeset viewer.