VirtualBox

Ignore:
Timestamp:
Dec 9, 2018 11:19:16 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127333
Message:

Main: Kicked out RpcChannelHook and IVirtualBoxclientList hacks (basically rolling back r12027) as these won't be used. See bugref:3300 for details.

File:
1 edited

Legend:

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

    r76091 r76092  
    2828#include "VBox/com/com.h"
    2929#include "VBox/com/VirtualBox.h"
    30 #include "VBox/com/array.h"
    3130
    3231#include "VirtualBoxImpl.h"
     
    4342#include <iprt/message.h>
    4443#include <iprt/asm.h>
    45 
    46 //#ifdef VBOX_WITH_SDS
    47 //# include <TlHelp32.h>
    48 //#endif
    4944
    5045
     
    9893volatile uint32_t dwTimeOut = dwNormalTimeout; /* time for EXE to be idle before shutting down. Can be decreased at system shutdown phase. */
    9994
    100 
    101 #if 0 //def VBOX_WITH_SDS
    102 
    103 BOOL CALLBACK CloseWindowProc(_In_ HWND   hWnd, _In_ LPARAM /* lParam */)
    104 {
    105     _ASSERTE(hWnd);
    106     DWORD_PTR dwResult;
    107     // Close topmost windows in the thread
    108     LRESULT lResult = SendMessageTimeout(hWnd, WM_CLOSE, NULL, NULL,
    109         SMTO_ABORTIFHUNG | SMTO_BLOCK, 0, &dwResult);
    110     if (lResult != 0)
    111     {
    112         LogRel(("EnumThreadWndProc: Close message sent to window %x successfully \n", hWnd));
    113     }
    114     else
    115     {
    116         LogRel(("EnumThreadWndProc: Cannot send event to window %x. result: %d, last error: %x\n",
    117             hWnd, dwResult, GetLastError()));
    118     }
    119     return TRUE;
    120 }
    121 
    122 void SendCloseToAllThreads(DWORD dwTargetPid)
    123 {
    124     HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    125     if (hSnapshot == NULL)
    126     {
    127         LogRel(("SendCloseToAllThreads: cannot get threads snapshot. error: 0x%x \n",
    128             GetLastError()));
    129         return;
    130     }
    131 
    132     THREADENTRY32 threadEntry;
    133     ZeroMemory(&threadEntry, sizeof(threadEntry));
    134     threadEntry.dwSize = sizeof(threadEntry);
    135 
    136     if (Thread32First(hSnapshot, &threadEntry))
    137     {
    138         do
    139         {
    140             LogRel(("SendCloseToAllThreads: process: %d thread: %x \n",
    141                 threadEntry.th32OwnerProcessID, threadEntry.th32ThreadID));
    142             if (threadEntry.th32OwnerProcessID == dwTargetPid)
    143             {
    144                 BOOL bRes = EnumThreadWindows(threadEntry.th32ThreadID, CloseWindowProc, NULL);
    145                 if (!bRes)
    146                 {
    147                     LogRel(("SendCloseToAllThreads: EnumThreadWindows() failed to enumerate threads. error: %x \n",
    148                         GetLastError()));
    149                 }
    150                 else
    151                 {
    152                     LogRel(("SendCloseToAllThreads: about to close window in thread %x of process d\n",
    153                         threadEntry.th32ThreadID, dwTargetPid));
    154                 }
    155             }
    156         } while (Thread32Next(hSnapshot, &threadEntry));
    157     }
    158     CloseHandle(hSnapshot);
    159 }
    160 
    161 static int CloseActiveClients()
    162 {
    163     ComPtr<IVirtualBoxClientList> ptrClientList;
    164     /**
    165     * Connect to VBoxSDS.
    166     * here we close all API client processes: our own and customers
    167     */
    168     LogRelFunc(("Forcibly close API clients during system shutdown on Windows 7:\n"));
    169     HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxClientList, NULL, CLSCTX_LOCAL_SERVER, IID_IVirtualBoxClientList,
    170         (void **)ptrClientList.asOutParam());
    171     if (SUCCEEDED(hrc))
    172     {
    173         com::SafeArray<LONG> aCllients;
    174         hrc = ptrClientList->get_Clients(aCllients.__asOutParam());
    175         RTCList<LONG> clientsList = aCllients.toList();
    176         LogRel(("==========Client list begin ========\n"));
    177         for (size_t i = 0; i < clientsList.size(); i++)
    178         {
    179             LogRel(("About to close client pid: %d\n", clientsList[i]));
    180             SendCloseToAllThreads(clientsList[i]);
    181         }
    182         LogRel(("==========Client list end ========\n"));
    183     }
    184     else
    185     {
    186         LogFunc(("Error to connect to VBoxSDS: hr=%Rhrf\n", hrc));
    187     }
    188     return 0;
    189 }
    190 
    191 // These are copies of functions defined in VersionHelpers.h
    192 bool IsWindowsVersionOrGreaterWrap(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
    193 {
    194     OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };
    195     DWORDLONG        const dwlConditionMask = VerSetConditionMask(
    196         VerSetConditionMask(
    197             VerSetConditionMask(
    198                 0, VER_MAJORVERSION, VER_GREATER_EQUAL),
    199             VER_MINORVERSION, VER_GREATER_EQUAL),
    200         VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
    201 
    202     osvi.dwMajorVersion = wMajorVersion;
    203     osvi.dwMinorVersion = wMinorVersion;
    204     osvi.wServicePackMajor = wServicePackMajor;
    205 
    206     return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
    207 }
    208 
    209 #if !defined _WIN32_WINNT_WIN8
    210 
    211 #define _WIN32_WINNT_WIN8                   0x0602
    212 
    213 #endif  // #if !defined _WIN32_WINNT_WIN8
    214 
    215 bool IsWindows8OrGreaterWrap()
    216 {
    217     return IsWindowsVersionOrGreaterWrap(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 0);
    218 }
    219 
    220 #endif // !VBOX_WITH_SDS
    22195
    22296
     
    367241    HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox);
    368242    void    VirtualBoxClassFactory::i_deregisterWithSds(void);
    369     void    VirtualBoxClassFactory::i_finishVBoxSvc();
    370243
    371244    friend VBoxSVCRegistration;
     
    438311            return m_pFactory->i_getVirtualBox(ppResult);
    439312        return E_FAIL;
    440     }
    441 
    442     // IVBoxSVCRegistration: called from
    443     STDMETHOD(NotifyClientsFinished)()
    444     {
    445         LogRelFunc(("All clients gone - shutdown sequence initiated\n"));
    446         if (m_pFactory)
    447             m_pFactory->i_finishVBoxSvc();
    448 
    449         // This is not enough to finish VBoxSvc such as reference to crashed client still is in action
    450         // So I forcebly shutdown VBoxSvc
    451         LONG cLocks = g_pModule->Unlock();
    452         LogRelFunc(("Unlock -> %d\n", cLocks));
    453         while (cLocks > 0)
    454             cLocks = g_pModule->Unlock();
    455 
    456         LogRelFunc(("returns\n"));
    457         return S_OK;
    458313    }
    459314};
     
    507362            NOREF(hrc);
    508363        }
    509     }
    510     i_finishVBoxSvc();
     364        m_ptrVirtualBoxSDS.setNull();
     365        g_fRegisteredWithVBoxSDS = false;
     366    }
     367    if (m_pVBoxSVC)
     368    {
     369        m_pVBoxSVC->m_pFactory = NULL;
     370        m_pVBoxSVC->Release();
     371        m_pVBoxSVC = NULL;
     372    }
    511373}
    512374
     
    534396    Log(("VirtualBoxClassFactory::GetVirtualBox: E_FAIL\n"));
    535397    return E_FAIL;
    536 }
    537 
    538 
    539 void    VirtualBoxClassFactory::i_finishVBoxSvc()
    540 {
    541     LogRelFunc(("Finish work of VBoxSVC and VBoxSDS\n"));
    542     if (m_ptrVirtualBoxSDS.isNotNull())
    543     {
    544         m_ptrVirtualBoxSDS.setNull();
    545         g_fRegisteredWithVBoxSDS = false;
    546     }
    547     if (m_pVBoxSVC)
    548     {
    549         m_pVBoxSVC->m_pFactory = NULL;
    550         m_pVBoxSVC->Release();
    551         m_pVBoxSVC = NULL;
    552     }
    553398}
    554399
     
    794639                    Log(("VBoxSVCWinMain: WM_QUERYENDSESSION: VBoxSvc has active connections. bActivity = %d. Loc count = %d\n",
    795640                         g_pModule->bActivity, g_pModule->GetLockCount()));
    796 
    797 #if 0 //def VBOX_WITH_SDS
    798                     // On Windows 7 our clients doesn't receive right sequence of Session End events
    799                     // So we send them all WM_QUIT to forcible close them.
    800                     // Windows 10 sends end session events correctly
    801                     // Note: the IsWindows8Point1() and IsWindows10OrGreater() doesnt work in
    802                     // application without manifest so I use old compatible functions for detection of Win 7
    803                     if(!IsWindows8OrGreaterWrap())
    804                         CloseActiveClients();
    805 #endif
    806641                }
    807642                rc = !fActiveConnection;
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