VirtualBox

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

Last change on this file since 80612 was 80569, checked in by vboxsync, 5 years ago

Main: bugref:9341: Added VM autostart during boot support for windows host

  • 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 80569 2019-09-03 14:34:21Z vboxsync $ */
2/** @file
3 * VBox Global COM Class definition
4 */
5
6/*
7 * Copyright (C) 2017-2019 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_EMPTY_CTOR_DTOR(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, IN_BSTR aEnvironmentChanges,
97 IN_BSTR aCmdOptions, ULONG aSessionId, ULONG *aPid);
98 /** @} */
99
100
101 /** @name Private methods
102 * @{ */
103 /**
104 * Gets the client user SID of the
105 */
106 static bool i_getClientUserSid(com::Utf8Str *a_pStrSid, com::Utf8Str *a_pStrUsername);
107
108 /**
109 * Looks up the given user.
110 *
111 * @returns Pointer to the LOCKED per user data. NULL if not found.
112 * @param a_rStrUserSid The user SID.
113 */
114 VBoxSDSPerUserData *i_lookupPerUserData(com::Utf8Str const &a_rStrUserSid);
115
116 /**
117 * Looks up the given user, creating it if not found
118 *
119 * @returns Pointer to the LOCKED per user data. NULL on allocation error.
120 * @param a_rStrUserSid The user SID.
121 * @param a_rStrUsername The user name if available.
122 */
123 VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername);
124
125#ifdef WITH_WATCHER
126 static DECLCALLBACK(int) i_watcherThreadProc(RTTHREAD hSelf, void *pvUser);
127 bool i_watchIt(VBoxSDSPerUserData *pProcess, HANDLE hProcess, RTPROCESS pid);
128 void i_stopWatching(VBoxSDSPerUserData *pProcess, RTPROCESS pid);
129 void i_shutdownAllWatchers(void);
130
131 void i_decrementClientCount();
132 void i_incrementClientCount();
133#endif
134 /** @} */
135};
136
137#ifdef WITH_WATCHER
138void VBoxSDSNotifyClientCount(uint32_t cClients);
139#endif
140
141#endif /* !MAIN_INCLUDED_VirtualBoxSDSImpl_h */
142/* 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