VirtualBox

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

Last change on this file since 77863 was 76562, checked in by vboxsync, 6 years ago

Main: Use MAIN_INCLUDED_ and MAIN_INCLUDED_SRC_ as header guard prefixes with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: VirtualBoxSDSImpl.h 76562 2019-01-01 03:22:50Z 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 /** @} */
97
98
99 /** @name Private methods
100 * @{ */
101 /**
102 * Gets the client user SID of the
103 */
104 static bool i_getClientUserSid(com::Utf8Str *a_pStrSid, com::Utf8Str *a_pStrUsername);
105
106 /**
107 * Looks up the given user.
108 *
109 * @returns Pointer to the LOCKED per user data. NULL if not found.
110 * @param a_rStrUserSid The user SID.
111 */
112 VBoxSDSPerUserData *i_lookupPerUserData(com::Utf8Str const &a_rStrUserSid);
113
114 /**
115 * Looks up the given user, creating it if not found
116 *
117 * @returns Pointer to the LOCKED per user data. NULL on allocation error.
118 * @param a_rStrUserSid The user SID.
119 * @param a_rStrUsername The user name if available.
120 */
121 VBoxSDSPerUserData *i_lookupOrCreatePerUserData(com::Utf8Str const &a_rStrUserSid, com::Utf8Str const &a_rStrUsername);
122
123#ifdef WITH_WATCHER
124 static DECLCALLBACK(int) i_watcherThreadProc(RTTHREAD hSelf, void *pvUser);
125 bool i_watchIt(VBoxSDSPerUserData *pProcess, HANDLE hProcess, RTPROCESS pid);
126 void i_stopWatching(VBoxSDSPerUserData *pProcess, RTPROCESS pid);
127 void i_shutdownAllWatchers(void);
128
129 void i_decrementClientCount();
130 void i_incrementClientCount();
131#endif
132 /** @} */
133};
134
135#ifdef WITH_WATCHER
136void VBoxSDSNotifyClientCount(uint32_t cClients);
137#endif
138
139#endif /* !MAIN_INCLUDED_VirtualBoxSDSImpl_h */
140/* 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