VirtualBox

source: vbox/trunk/src/VBox/Main/include/VirtualBoxSDSImpl.h@ 93954

Last change on this file since 93954 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* $Id: VirtualBoxSDSImpl.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VBox Global COM Class definition
4 */
5
6/*
7 * Copyright (C) 2017-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_VirtualBoxSDSImpl_h
19#define MAIN_INCLUDED_VirtualBoxSDSImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "VirtualBoxBase.h"
25
26/* Enable the watcher code in debug builds. */
27#ifdef DEBUG
28# define WITH_WATCHER
29#endif
30
31
32class VBoxSDSPerUserData; /* See VirtualBoxSDSImpl.cpp. */
33struct VBoxSDSWatcher; /* See VirtualBoxSDSImpl.cpp. */
34
35/**
36 * The IVirtualBoxSDS implementation.
37 *
38 * This class helps different VBoxSVC processes make sure a user only have a
39 * single VirtualBox instance.
40 *
41 * @note This is a simple internal class living in a privileged process. So, we
42 * do not use the API wrappers as they add complexity. In particular,
43 * they add the auto caller logic, which is an excellent tool to create
44 * unkillable processes. If an API method during development or product
45 * for instance triggers an NT exception like STATUS_ACCESS_VIOLATION, the
46 * caller will be unwound without releasing the caller. When uninit is
47 * called during COM shutdown/whatever, the thread gets stuck waiting for
48 * the long gone caller and cannot be killed (Windows 10, build 16299),
49 * requiring a reboot to continue.
50 *
51 * @todo Would be very nice to get rid of the ATL cruft too here.
52 */
53class VirtualBoxSDS
54 : public IVirtualBoxSDS
55 , public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>
56 , public ATL::CComCoClass<VirtualBoxSDS, &CLSID_VirtualBoxSDS>
57{
58private:
59 typedef std::map<com::Utf8Str, VBoxSDSPerUserData *> UserDataMap_T;
60 /** Per user data map (key is SID string).
61 * This is an insert-only map! */
62 UserDataMap_T m_UserDataMap;
63 /** Number of registered+watched VBoxSVC processes. */
64 uint32_t m_cVBoxSvcProcesses;
65#ifdef WITH_WATCHER
66 /** Number of watcher threads. */
67 uint32_t m_cWatchers;
68 /** Pointer to an array of watcher pointers. */
69 VBoxSDSWatcher **m_papWatchers;
70 /** Lock protecting m_papWatchers and associated structures. */
71 RTCRITSECT m_WatcherCritSect;
72#endif
73 /** Lock protecting m_UserDataMap . */
74 RTCRITSECTRW m_MapCritSect;
75
76public:
77 DECLARE_CLASSFACTORY_SINGLETON(VirtualBoxSDS)
78 DECLARE_NOT_AGGREGATABLE(VirtualBoxSDS)
79 DECLARE_PROTECT_FINAL_CONSTRUCT()
80
81 BEGIN_COM_MAP(VirtualBoxSDS)
82 COM_INTERFACE_ENTRY(IVirtualBoxSDS)
83 END_COM_MAP()
84
85 DECLARE_COMMON_CLASS_METHODS(VirtualBoxSDS)
86
87 HRESULT FinalConstruct();
88 void FinalRelease();
89
90private:
91
92 /** @name IVirtualBoxSDS methods
93 * @{ */
94 STDMETHOD(RegisterVBoxSVC)(IVBoxSVCRegistration *aVBoxSVC, LONG aPid, IUnknown **aExistingVirtualBox);
95 STDMETHOD(DeregisterVBoxSVC)(IVBoxSVCRegistration *aVBoxSVC, LONG aPid);
96 STDMETHOD(LaunchVMProcess)(IN_BSTR aMachine, IN_BSTR aComment, IN_BSTR aFrontend,
97 ComSafeArrayIn(IN_BSTR, aEnvironmentChanges), IN_BSTR aCmdOptions,
98 ULONG aSessionId, ULONG *aPid);
99 /** @} */
100
101
102 /** @name Private methods
103 * @{ */
104 /**
105 * Gets the client user SID of the
106 */
107 static bool i_getClientUserSid(com::Utf8Str *a_pStrSid, com::Utf8Str *a_pStrUsername);
108
109 /**
110 * Looks up the given user.
111 *
112 * @returns Pointer to the LOCKED per user data. NULL if not found.
113 * @param a_rStrUserSid The user SID.
114 */
115 VBoxSDSPerUserData *i_lookupPerUserData(com::Utf8Str const &a_rStrUserSid);
116
117 /**
118 * Looks up the given user, creating it if not found
119 *
120 * @returns Pointer to the LOCKED per user data. NULL on allocation error.
121 * @param a_rStrUserSid The user SID.
122 * @param a_rStrUsername The user name if available.
123 */
124 VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername);
125
126#ifdef WITH_WATCHER
127 static DECLCALLBACK(int) i_watcherThreadProc(RTTHREAD hSelf, void *pvUser);
128 bool i_watchIt(VBoxSDSPerUserData *pProcess, HANDLE hProcess, RTPROCESS pid);
129 void i_stopWatching(VBoxSDSPerUserData *pProcess, RTPROCESS pid);
130 void i_shutdownAllWatchers(void);
131
132 void i_decrementClientCount();
133 void i_incrementClientCount();
134#endif
135 /** @} */
136};
137
138#ifdef WITH_WATCHER
139void VBoxSDSNotifyClientCount(uint32_t cClients);
140#endif
141
142#endif /* !MAIN_INCLUDED_VirtualBoxSDSImpl_h */
143/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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