1 | /* $Id: GuestSessionImpl.h 99120 2023-03-22 17:30:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - Guest session handling.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_GuestSessionImpl_h
|
---|
29 | #define MAIN_INCLUDED_GuestSessionImpl_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "GuestSessionWrap.h"
|
---|
35 | #include "EventImpl.h"
|
---|
36 |
|
---|
37 | #include "GuestCtrlImplPrivate.h"
|
---|
38 | #include "GuestProcessImpl.h"
|
---|
39 | #include "GuestDirectoryImpl.h"
|
---|
40 | #include "GuestFileImpl.h"
|
---|
41 | #include "GuestFsObjInfoImpl.h"
|
---|
42 | #include "GuestSessionImplTasks.h"
|
---|
43 |
|
---|
44 | #include <iprt/asm.h> /** @todo r=bird: Needed for ASMBitSet() in GuestSession::Data constructor. Removed when
|
---|
45 | * that is moved into the class implementation file as it should be. */
|
---|
46 | #include <deque>
|
---|
47 |
|
---|
48 | class GuestSessionTaskInternalStart; /* Needed for i_startSessionThreadTask(). */
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Guest session implementation.
|
---|
52 | */
|
---|
53 | class ATL_NO_VTABLE GuestSession
|
---|
54 | : public GuestSessionWrap
|
---|
55 | , public GuestBase
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | /** @name COM and internal init/term/mapping cruft.
|
---|
59 | * @{ */
|
---|
60 | DECLARE_COMMON_CLASS_METHODS(GuestSession)
|
---|
61 |
|
---|
62 | int init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo, const GuestCredentials &guestCreds);
|
---|
63 | void uninit(void);
|
---|
64 | HRESULT FinalConstruct(void);
|
---|
65 | void FinalRelease(void);
|
---|
66 | /** @} */
|
---|
67 |
|
---|
68 | private:
|
---|
69 |
|
---|
70 | /** Wrapped @name IGuestSession properties.
|
---|
71 | * @{ */
|
---|
72 | HRESULT getUser(com::Utf8Str &aUser);
|
---|
73 | HRESULT getDomain(com::Utf8Str &aDomain);
|
---|
74 | HRESULT getName(com::Utf8Str &aName);
|
---|
75 | HRESULT getId(ULONG *aId);
|
---|
76 | HRESULT getTimeout(ULONG *aTimeout);
|
---|
77 | HRESULT setTimeout(ULONG aTimeout);
|
---|
78 | HRESULT getProtocolVersion(ULONG *aProtocolVersion);
|
---|
79 | HRESULT getStatus(GuestSessionStatus_T *aStatus);
|
---|
80 | HRESULT getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
81 | HRESULT setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges);
|
---|
82 | HRESULT getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase);
|
---|
83 | HRESULT getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses);
|
---|
84 | HRESULT getPathStyle(PathStyle_T *aPathStyle);
|
---|
85 | HRESULT getCurrentDirectory(com::Utf8Str &aCurrentDirectory);
|
---|
86 | HRESULT setCurrentDirectory(const com::Utf8Str &aCurrentDirectory);
|
---|
87 | HRESULT getUserDocuments(com::Utf8Str &aUserDocuments);
|
---|
88 | HRESULT getUserHome(com::Utf8Str &aUserHome);
|
---|
89 | HRESULT getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories);
|
---|
90 | HRESULT getFiles(std::vector<ComPtr<IGuestFile> > &aFiles);
|
---|
91 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 | /** Wrapped @name IGuestSession methods.
|
---|
95 | * @{ */
|
---|
96 | HRESULT close();
|
---|
97 |
|
---|
98 | HRESULT copyFromGuest(const std::vector<com::Utf8Str> &aSources,
|
---|
99 | const std::vector<com::Utf8Str> &aFilters,
|
---|
100 | const std::vector<com::Utf8Str> &aFlags,
|
---|
101 | const com::Utf8Str &aDestination,
|
---|
102 | ComPtr<IProgress> &aProgress);
|
---|
103 | HRESULT copyToGuest(const std::vector<com::Utf8Str> &aSources,
|
---|
104 | const std::vector<com::Utf8Str> &aFilters,
|
---|
105 | const std::vector<com::Utf8Str> &aFlags,
|
---|
106 | const com::Utf8Str &aDestination,
|
---|
107 | ComPtr<IProgress> &aProgress);
|
---|
108 |
|
---|
109 | HRESULT directoryCopy(const com::Utf8Str &aSource,
|
---|
110 | const com::Utf8Str &aDestination,
|
---|
111 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
112 | ComPtr<IProgress> &aProgress);
|
---|
113 | HRESULT directoryCopyFromGuest(const com::Utf8Str &aSource,
|
---|
114 | const com::Utf8Str &aDestination,
|
---|
115 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
116 | ComPtr<IProgress> &aProgress);
|
---|
117 | HRESULT directoryCopyToGuest(const com::Utf8Str &aSource,
|
---|
118 | const com::Utf8Str &aDestination,
|
---|
119 | const std::vector<DirectoryCopyFlag_T> &aFlags,
|
---|
120 | ComPtr<IProgress> &aProgress);
|
---|
121 | HRESULT directoryCreate(const com::Utf8Str &aPath,
|
---|
122 | ULONG aMode,
|
---|
123 | const std::vector<DirectoryCreateFlag_T> &aFlags);
|
---|
124 | HRESULT directoryCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
125 | ULONG aMode,
|
---|
126 | const com::Utf8Str &aPath,
|
---|
127 | BOOL aSecure,
|
---|
128 | com::Utf8Str &aDirectory);
|
---|
129 | HRESULT directoryExists(const com::Utf8Str &aPath,
|
---|
130 | BOOL aFollowSymlinks,
|
---|
131 | BOOL *aExists);
|
---|
132 | HRESULT directoryOpen(const com::Utf8Str &aPath,
|
---|
133 | const com::Utf8Str &aFilter,
|
---|
134 | const std::vector<DirectoryOpenFlag_T> &aFlags,
|
---|
135 | ComPtr<IGuestDirectory> &aDirectory);
|
---|
136 | HRESULT directoryRemove(const com::Utf8Str &aPath);
|
---|
137 | HRESULT directoryRemoveRecursive(const com::Utf8Str &aPath,
|
---|
138 | const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
|
---|
139 | ComPtr<IProgress> &aProgress);
|
---|
140 | HRESULT environmentScheduleSet(const com::Utf8Str &aName,
|
---|
141 | const com::Utf8Str &aValue);
|
---|
142 | HRESULT environmentScheduleUnset(const com::Utf8Str &aName);
|
---|
143 | HRESULT environmentGetBaseVariable(const com::Utf8Str &aName,
|
---|
144 | com::Utf8Str &aValue);
|
---|
145 | HRESULT environmentDoesBaseVariableExist(const com::Utf8Str &aName,
|
---|
146 | BOOL *aExists);
|
---|
147 |
|
---|
148 | HRESULT fileCopy(const com::Utf8Str &aSource,
|
---|
149 | const com::Utf8Str &aDestination,
|
---|
150 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
151 | ComPtr<IProgress> &aProgress);
|
---|
152 | HRESULT fileCopyToGuest(const com::Utf8Str &aSource,
|
---|
153 | const com::Utf8Str &aDestination,
|
---|
154 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
155 | ComPtr<IProgress> &aProgress);
|
---|
156 | HRESULT fileCopyFromGuest(const com::Utf8Str &aSource,
|
---|
157 | const com::Utf8Str &aDestination,
|
---|
158 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
159 | ComPtr<IProgress> &aProgress);
|
---|
160 | HRESULT fileCreateTemp(const com::Utf8Str &aTemplateName,
|
---|
161 | ULONG aMode,
|
---|
162 | const com::Utf8Str &aPath,
|
---|
163 | BOOL aSecure,
|
---|
164 | ComPtr<IGuestFile> &aFile);
|
---|
165 | HRESULT fileExists(const com::Utf8Str &aPath,
|
---|
166 | BOOL aFollowSymlinks,
|
---|
167 | BOOL *aExists);
|
---|
168 | HRESULT fileOpen(const com::Utf8Str &aPath,
|
---|
169 | FileAccessMode_T aAccessMode,
|
---|
170 | FileOpenAction_T aOpenAction,
|
---|
171 | ULONG aCreationMode,
|
---|
172 | ComPtr<IGuestFile> &aFile);
|
---|
173 | HRESULT fileOpenEx(const com::Utf8Str &aPath,
|
---|
174 | FileAccessMode_T aAccessMode,
|
---|
175 | FileOpenAction_T aOpenAction,
|
---|
176 | FileSharingMode_T aSharingMode,
|
---|
177 | ULONG aCreationMode,
|
---|
178 | const std::vector<FileOpenExFlag_T> &aFlags,
|
---|
179 | ComPtr<IGuestFile> &aFile);
|
---|
180 | HRESULT fileQuerySize(const com::Utf8Str &aPath,
|
---|
181 | BOOL aFollowSymlinks,
|
---|
182 | LONG64 *aSize);
|
---|
183 | HRESULT fsQueryFreeSpace(const com::Utf8Str &aPath, LONG64 *aFreeSpace);
|
---|
184 | HRESULT fsQueryInfo(const com::Utf8Str &aPath, ComPtr<IGuestFsInfo> &aInfo);
|
---|
185 | HRESULT fsObjExists(const com::Utf8Str &aPath,
|
---|
186 | BOOL aFollowSymlinks,
|
---|
187 | BOOL *pfExists);
|
---|
188 | HRESULT fsObjQueryInfo(const com::Utf8Str &aPath,
|
---|
189 | BOOL aFollowSymlinks,
|
---|
190 | ComPtr<IGuestFsObjInfo> &aInfo);
|
---|
191 | HRESULT fsObjRemove(const com::Utf8Str &aPath);
|
---|
192 | HRESULT fsObjRemoveArray(const std::vector<com::Utf8Str> &aPaths,
|
---|
193 | ComPtr<IProgress> &aProgress);
|
---|
194 | HRESULT fsObjRename(const com::Utf8Str &aOldPath,
|
---|
195 | const com::Utf8Str &aNewPath,
|
---|
196 | const std::vector<FsObjRenameFlag_T> &aFlags);
|
---|
197 | HRESULT fsObjMove(const com::Utf8Str &aSource,
|
---|
198 | const com::Utf8Str &aDestination,
|
---|
199 | const std::vector<FsObjMoveFlag_T> &aFlags,
|
---|
200 | ComPtr<IProgress> &aProgress);
|
---|
201 | HRESULT fsObjMoveArray(const std::vector<com::Utf8Str> &aSource,
|
---|
202 | const com::Utf8Str &aDestination,
|
---|
203 | const std::vector<FsObjMoveFlag_T> &aFlags,
|
---|
204 | ComPtr<IProgress> &aProgress);
|
---|
205 | HRESULT fsObjCopyArray(const std::vector<com::Utf8Str> &aSource,
|
---|
206 | const com::Utf8Str &aDestination,
|
---|
207 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
208 | ComPtr<IProgress> &aProgress);
|
---|
209 | HRESULT fsObjSetACL(const com::Utf8Str &aPath,
|
---|
210 | BOOL aFollowSymlinks,
|
---|
211 | const com::Utf8Str &aAcl,
|
---|
212 | ULONG aMode);
|
---|
213 | HRESULT processCreate(const com::Utf8Str &aCommand,
|
---|
214 | const com::Utf8Str &aCwd,
|
---|
215 | const std::vector<com::Utf8Str> &aArguments,
|
---|
216 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
217 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
218 | ULONG aTimeoutMS,
|
---|
219 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
220 | HRESULT processCreateEx(const com::Utf8Str &aCommand,
|
---|
221 | const com::Utf8Str &aCwd,
|
---|
222 | const std::vector<com::Utf8Str> &aArguments,
|
---|
223 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
224 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
225 | ULONG aTimeoutMS,
|
---|
226 | ProcessPriority_T aPriority,
|
---|
227 | const std::vector<LONG> &aAffinity,
|
---|
228 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
229 | HRESULT processGet(ULONG aPid,
|
---|
230 | ComPtr<IGuestProcess> &aGuestProcess);
|
---|
231 | HRESULT symlinkCreate(const com::Utf8Str &aSource,
|
---|
232 | const com::Utf8Str &aTarget,
|
---|
233 | SymlinkType_T aType);
|
---|
234 | HRESULT symlinkExists(const com::Utf8Str &aSymlink,
|
---|
235 | BOOL *aExists);
|
---|
236 | HRESULT symlinkRead(const com::Utf8Str &aSymlink,
|
---|
237 | const std::vector<SymlinkReadFlag_T> &aFlags,
|
---|
238 | com::Utf8Str &aTarget);
|
---|
239 | HRESULT waitFor(ULONG aWaitFor,
|
---|
240 | ULONG aTimeoutMS,
|
---|
241 | GuestSessionWaitResult_T *aReason);
|
---|
242 | HRESULT waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor,
|
---|
243 | ULONG aTimeoutMS,
|
---|
244 | GuestSessionWaitResult_T *aReason);
|
---|
245 | /** @} */
|
---|
246 |
|
---|
247 | /** Map of guest directories. The key specifies the internal directory ID. */
|
---|
248 | typedef std::map <uint32_t, ComObjPtr<GuestDirectory> > SessionDirectories;
|
---|
249 | /** Map of guest files. The key specifies the internal file ID. */
|
---|
250 | typedef std::map <uint32_t, ComObjPtr<GuestFile> > SessionFiles;
|
---|
251 | /** Map of guest processes. The key specifies the internal process number.
|
---|
252 | * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
|
---|
253 | typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
|
---|
254 |
|
---|
255 | /** Guest session object type enumeration. */
|
---|
256 | enum SESSIONOBJECTTYPE
|
---|
257 | {
|
---|
258 | /** Invalid session object type. */
|
---|
259 | SESSIONOBJECTTYPE_INVALID = 0,
|
---|
260 | /** Session object. */
|
---|
261 | SESSIONOBJECTTYPE_SESSION = 1,
|
---|
262 | /** Directory object. */
|
---|
263 | SESSIONOBJECTTYPE_DIRECTORY = 2,
|
---|
264 | /** File object. */
|
---|
265 | SESSIONOBJECTTYPE_FILE = 3,
|
---|
266 | /** Process object. */
|
---|
267 | SESSIONOBJECTTYPE_PROCESS = 4
|
---|
268 | };
|
---|
269 |
|
---|
270 | struct SessionObject
|
---|
271 | {
|
---|
272 | /** Creation timestamp (in ms).
|
---|
273 | * @note not used by anyone at the moment. */
|
---|
274 | uint64_t msBirth;
|
---|
275 | /** The object type. */
|
---|
276 | SESSIONOBJECTTYPE enmType;
|
---|
277 | /** Weak pointer to the object itself.
|
---|
278 | * Is NULL for SESSIONOBJECTTYPE_SESSION because GuestSession doesn't
|
---|
279 | * inherit from GuestObject. */
|
---|
280 | GuestObject *pObject;
|
---|
281 | };
|
---|
282 |
|
---|
283 | /** Map containing all objects bound to a guest session.
|
---|
284 | * The key specifies the (global) context ID. */
|
---|
285 | typedef std::map<uint32_t, SessionObject> SessionObjects;
|
---|
286 |
|
---|
287 | public:
|
---|
288 | /** @name Public internal methods.
|
---|
289 | * @todo r=bird: Most of these are public for no real reason...
|
---|
290 | * @{ */
|
---|
291 | HRESULT i_copyFromGuest(const GuestSessionFsSourceSet &SourceSet, const com::Utf8Str &strDestination,
|
---|
292 | ComPtr<IProgress> &pProgress);
|
---|
293 | HRESULT i_copyToGuest(const GuestSessionFsSourceSet &SourceSet, const com::Utf8Str &strDestination,
|
---|
294 | ComPtr<IProgress> &pProgress);
|
---|
295 | int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pvrcGuest);
|
---|
296 | HRESULT i_directoryCopyFlagFromStr(const com::Utf8Str &strFlags, bool fStrict, DirectoryCopyFlag_T *pfFlags);
|
---|
297 | bool i_directoryExists(const Utf8Str &strPath);
|
---|
298 | inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir);
|
---|
299 | int i_directoryUnregister(GuestDirectory *pDirectory);
|
---|
300 | int i_directoryRemove(const Utf8Str &strPath, uint32_t fFlags, int *pvrcGuest);
|
---|
301 | int i_directoryCreate(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pvrcGuest);
|
---|
302 | int i_directoryOpen(const GuestDirectoryOpenInfo &openInfo,
|
---|
303 | ComObjPtr<GuestDirectory> &pDirectory, int *pvrcGuest);
|
---|
304 | int i_directoryQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pvrcGuest);
|
---|
305 | int i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
306 | int i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
307 | HRESULT i_fileCopyFlagFromStr(const com::Utf8Str &strFlags, bool fStrict, FileCopyFlag_T *pfFlags);
|
---|
308 | inline bool i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile);
|
---|
309 | int i_fileUnregister(GuestFile *pFile);
|
---|
310 | int i_fileRemove(const Utf8Str &strPath, int *pvrcGuest);
|
---|
311 | int i_fileOpenEx(const com::Utf8Str &aPath, FileAccessMode_T aAccessMode, FileOpenAction_T aOpenAction,
|
---|
312 | FileSharingMode_T aSharingMode, ULONG aCreationMode,
|
---|
313 | const std::vector<FileOpenExFlag_T> &aFlags,
|
---|
314 | ComObjPtr<GuestFile> &pFile, int *pvrcGuest);
|
---|
315 | int i_fileOpen(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pvrcGuest);
|
---|
316 | int i_fileQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pvrcGuest);
|
---|
317 | int i_fileQuerySize(const Utf8Str &strPath, bool fFollowSymlinks, int64_t *pllSize, int *pvrcGuest);
|
---|
318 | int i_fsCreateTemp(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory,
|
---|
319 | Utf8Str &strName, uint32_t fMode, bool fSecure, int *pvrcGuest);
|
---|
320 | int i_fsQueryInfo(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pvrcGuest);
|
---|
321 | const GuestCredentials &i_getCredentials(void);
|
---|
322 | EventSource *i_getEventSource(void) { return mEventSource; }
|
---|
323 | Utf8Str i_getName(void);
|
---|
324 | ULONG i_getId(void) { return mData.mSession.mID; }
|
---|
325 | bool i_isStarted(void) const;
|
---|
326 | HRESULT i_isStartedExternal(void);
|
---|
327 | bool i_isTerminated(void) const;
|
---|
328 | int i_onRemove(void);
|
---|
329 | #ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
|
---|
330 | int i_onFsNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
331 | #endif
|
---|
332 | int i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
333 | PathStyle_T i_getGuestPathStyle(void);
|
---|
334 | static PathStyle_T i_getHostPathStyle(void);
|
---|
335 | int i_startSession(int *pvrcGuest);
|
---|
336 | int i_startSessionAsync(void);
|
---|
337 | Guest *i_getParent(void) { return mParent; }
|
---|
338 | uint32_t i_getProtocolVersion(void) { return mData.mProtocolVersion; }
|
---|
339 | int i_objectRegister(GuestObject *pObject, SESSIONOBJECTTYPE enmType, uint32_t *pidObject);
|
---|
340 | int i_objectUnregister(uint32_t uObjectID);
|
---|
341 | int i_objectsUnregister(void);
|
---|
342 | int i_objectsNotifyAboutStatusChange(GuestSessionStatus_T enmSessionStatus);
|
---|
343 | int i_pathRename(const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags, int *pvrcGuest);
|
---|
344 | int i_pathUserDocuments(Utf8Str &strPath, int *pvrcGuest);
|
---|
345 | int i_pathUserHome(Utf8Str &strPath, int *pvrcGuest);
|
---|
346 | int i_processUnregister(GuestProcess *pProcess);
|
---|
347 | int i_processCreateEx(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
|
---|
348 | inline bool i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
|
---|
349 | inline int i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
|
---|
350 | int i_sendMessage(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms,
|
---|
351 | uint64_t fDst = VBOX_GUESTCTRL_DST_SESSION);
|
---|
352 | int i_setSessionStatus(GuestSessionStatus_T sessionStatus, int vrcSession);
|
---|
353 | int i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int vrc /*= VINF_SUCCESS */);
|
---|
354 | int i_shutdown(uint32_t fFlags, int *pvrcGuest);
|
---|
355 | int i_determineProtocolVersion(void);
|
---|
356 | int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pvrcGuest);
|
---|
357 | int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
358 | GuestSessionStatus_T *pSessionStatus, int *pvrcGuest);
|
---|
359 | /** @} */
|
---|
360 |
|
---|
361 | /** @name Public internal methods for supporting older Guest Additions via
|
---|
362 | VBoxService' built-in toolbox (< 7.1). */
|
---|
363 | int i_directoryCreateViaToolbox(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pvrcGuest);
|
---|
364 | int i_fileRemoveViaToolbox(const Utf8Str &strPath, int *pvrcGuest);
|
---|
365 | int i_fsCreateTempViaToolbox(const Utf8Str &strTemplate, const Utf8Str &strPath, bool fDirectory, Utf8Str &strName,
|
---|
366 | uint32_t fMode, bool fSecure, int *pvrcGuest);
|
---|
367 | int i_fsQueryInfoViaToolbox(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pvrcGuest);
|
---|
368 | /** @} */
|
---|
369 |
|
---|
370 | public:
|
---|
371 |
|
---|
372 | /** @name Static helper methods.
|
---|
373 | * @{ */
|
---|
374 | static Utf8Str i_guestErrorToString(int guestRc);
|
---|
375 | static bool i_isTerminated(GuestSessionStatus_T enmStatus);
|
---|
376 | static int i_startSessionThreadTask(GuestSessionTaskInternalStart *pTask);
|
---|
377 | /** @} */
|
---|
378 |
|
---|
379 | private:
|
---|
380 |
|
---|
381 | /** Pointer to the parent (Guest). */
|
---|
382 | Guest *mParent;
|
---|
383 | /**
|
---|
384 | * The session's event source. This source is used for
|
---|
385 | * serving the internal listener as well as all other
|
---|
386 | * external listeners that may register to it.
|
---|
387 | *
|
---|
388 | * Note: This can safely be used without holding any locks.
|
---|
389 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
390 | * internally there is a lock providing the necessary serialization.
|
---|
391 | */
|
---|
392 | const ComObjPtr<EventSource> mEventSource;
|
---|
393 |
|
---|
394 | /** @todo r=bird: One of the core points of the DATA sub-structures in Main is
|
---|
395 | * hinding implementation details and stuff that requires including iprt/asm.h.
|
---|
396 | * The way it's used here totally defeats that purpose. You need to make it
|
---|
397 | * a pointer to a anynmous Data struct and define that structure in
|
---|
398 | * GuestSessionImpl.cpp and allocate it in the Init() function.
|
---|
399 | */
|
---|
400 | struct Data
|
---|
401 | {
|
---|
402 | /** The session credentials. */
|
---|
403 | GuestCredentials mCredentials;
|
---|
404 | /** The session's startup info. */
|
---|
405 | GuestSessionStartupInfo mSession;
|
---|
406 | /** The session's object ID.
|
---|
407 | * Needed for registering wait events which are bound directly to this session. */
|
---|
408 | uint32_t mObjectID;
|
---|
409 | /** The session's current status. */
|
---|
410 | GuestSessionStatus_T mStatus;
|
---|
411 | /** The set of environment changes for the session for use when
|
---|
412 | * creating new guest processes. */
|
---|
413 | GuestEnvironmentChanges mEnvironmentChanges;
|
---|
414 | /** Pointer to the immutable base environment for the session.
|
---|
415 | * @note This is not allocated until the guest reports it to the host. It is
|
---|
416 | * also shared with child processes.
|
---|
417 | * @todo This is actually not yet implemented, see
|
---|
418 | * GuestSession::i_onSessionStatusChange. */
|
---|
419 | GuestEnvironment const *mpBaseEnvironment;
|
---|
420 | /** Directory objects bound to this session. */
|
---|
421 | SessionDirectories mDirectories;
|
---|
422 | /** File objects bound to this session. */
|
---|
423 | SessionFiles mFiles;
|
---|
424 | /** Process objects bound to this session. */
|
---|
425 | SessionProcesses mProcesses;
|
---|
426 | /** Map of registered session objects (files, directories, ...). */
|
---|
427 | SessionObjects mObjects;
|
---|
428 | /** Guest control protocol version to be used.
|
---|
429 | * Guest Additions < VBox 4.3 have version 1,
|
---|
430 | * any newer version will have version 2. */
|
---|
431 | uint32_t mProtocolVersion;
|
---|
432 | /** Session timeout (in ms). */
|
---|
433 | uint32_t mTimeout;
|
---|
434 | /** The last returned session VBox status status returned from the guest side. */
|
---|
435 | int mVrc;
|
---|
436 | /** Object ID allocation bitmap; clear bits are free, set bits are busy. */
|
---|
437 | uint64_t bmObjectIds[VBOX_GUESTCTRL_MAX_OBJECTS / sizeof(uint64_t) / 8];
|
---|
438 |
|
---|
439 | Data(void)
|
---|
440 | : mpBaseEnvironment(NULL)
|
---|
441 | {
|
---|
442 | RT_ZERO(bmObjectIds);
|
---|
443 | ASMBitSet(&bmObjectIds, VBOX_GUESTCTRL_MAX_OBJECTS - 1); /* Reserved for the session itself? */
|
---|
444 | ASMBitSet(&bmObjectIds, 0); /* Let's reserve this too. */
|
---|
445 | }
|
---|
446 | Data(const Data &rThat)
|
---|
447 | : mCredentials(rThat.mCredentials)
|
---|
448 | , mSession(rThat.mSession)
|
---|
449 | , mStatus(rThat.mStatus)
|
---|
450 | , mEnvironmentChanges(rThat.mEnvironmentChanges)
|
---|
451 | , mpBaseEnvironment(NULL)
|
---|
452 | , mDirectories(rThat.mDirectories)
|
---|
453 | , mFiles(rThat.mFiles)
|
---|
454 | , mProcesses(rThat.mProcesses)
|
---|
455 | , mObjects(rThat.mObjects)
|
---|
456 | , mProtocolVersion(rThat.mProtocolVersion)
|
---|
457 | , mTimeout(rThat.mTimeout)
|
---|
458 | , mVrc(rThat.mVrc)
|
---|
459 | {
|
---|
460 | memcpy(&bmObjectIds, &rThat.bmObjectIds, sizeof(bmObjectIds));
|
---|
461 | }
|
---|
462 | ~Data(void)
|
---|
463 | {
|
---|
464 | if (mpBaseEnvironment)
|
---|
465 | {
|
---|
466 | mpBaseEnvironment->releaseConst();
|
---|
467 | mpBaseEnvironment = NULL;
|
---|
468 | }
|
---|
469 | }
|
---|
470 | } mData;
|
---|
471 | };
|
---|
472 |
|
---|
473 | #endif /* !MAIN_INCLUDED_GuestSessionImpl_h */
|
---|
474 |
|
---|