VirtualBox

source: vbox/trunk/src/VBox/HostServices/GuestProperties/VBoxGuestPropSvc.cpp@ 94069

Last change on this file since 94069 was 93891, checked in by vboxsync, 3 years ago

Main: Guest Properties: improved property name and value validation, bugref:10185.

This commit also prevents guest properties loss if they were set while VM was running.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 62.3 KB
Line 
1/* $Id: VBoxGuestPropSvc.cpp 93891 2022-02-22 18:08:39Z vboxsync $ */
2/** @file
3 * Guest Property Service: Host service entry points.
4 */
5
6/*
7 * Copyright (C) 2008-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/** @page pg_svc_guest_properties Guest Property HGCM Service
19 *
20 * This HGCM service allows the guest to set and query values in a property
21 * store on the host. The service proxies the guest requests to the service
22 * owner on the host using a request callback provided by the owner, and is
23 * notified of changes to properties made by the host. It forwards these
24 * notifications to clients in the guest which have expressed interest and
25 * are waiting for notification.
26 *
27 * The service currently consists of two threads. One of these is the main
28 * HGCM service thread which deals with requests from the guest and from the
29 * host. The second thread sends the host asynchronous notifications of
30 * changes made by the guest and deals with notification timeouts.
31 *
32 * Guest requests to wait for notification are added to a list of open
33 * notification requests and completed when a corresponding guest property
34 * is changed or when the request times out.
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define LOG_GROUP LOG_GROUP_HGCM
42#include <VBox/HostServices/GuestPropertySvc.h>
43
44#include <VBox/log.h>
45#include <iprt/asm.h>
46#include <iprt/assert.h>
47#include <iprt/buildconfig.h>
48#include <iprt/cpp/autores.h>
49#include <iprt/cpp/utils.h>
50#include <iprt/cpp/ministring.h>
51#include <VBox/err.h>
52#include <VBox/hgcmsvc.h>
53#include <iprt/mem.h>
54#include <iprt/req.h>
55#include <iprt/string.h>
56#include <iprt/thread.h>
57#include <iprt/time.h>
58#include <VBox/vmm/dbgf.h>
59#include <VBox/version.h>
60
61#include <list>
62
63
64namespace guestProp {
65
66/**
67 * Structure for holding a property
68 */
69struct Property
70{
71 /** The string space core record. */
72 RTSTRSPACECORE mStrCore;
73 /** The name of the property */
74 RTCString mName;
75 /** The property value */
76 RTCString mValue;
77 /** The timestamp of the property */
78 uint64_t mTimestamp;
79 /** The property flags */
80 uint32_t mFlags;
81
82 /** Default constructor */
83 Property() : mTimestamp(0), mFlags(GUEST_PROP_F_NILFLAG)
84 {
85 RT_ZERO(mStrCore);
86 }
87 /** Constructor with const char * */
88 Property(const char *pcszName, const char *pcszValue, uint64_t nsTimestamp, uint32_t u32Flags)
89 : mName(pcszName)
90 , mValue(pcszValue)
91 , mTimestamp(nsTimestamp)
92 , mFlags(u32Flags)
93 {
94 RT_ZERO(mStrCore);
95 mStrCore.pszString = mName.c_str();
96 }
97 /** Constructor with std::string */
98 Property(RTCString const &rName, RTCString const &rValue, uint64_t nsTimestamp, uint32_t fFlags)
99 : mName(rName)
100 , mValue(rValue)
101 , mTimestamp(nsTimestamp)
102 , mFlags(fFlags)
103 {}
104
105 /** Does the property name match one of a set of patterns? */
106 bool Matches(const char *pszPatterns) const
107 {
108 return ( pszPatterns[0] == '\0' /* match all */
109 || RTStrSimplePatternMultiMatch(pszPatterns, RTSTR_MAX,
110 mName.c_str(), RTSTR_MAX,
111 NULL)
112 );
113 }
114
115 /** Are two properties equal? */
116 bool operator==(const Property &prop)
117 {
118 if (mTimestamp != prop.mTimestamp)
119 return false;
120 if (mFlags != prop.mFlags)
121 return false;
122 if (mName != prop.mName)
123 return false;
124 if (mValue != prop.mValue)
125 return false;
126 return true;
127 }
128
129 /* Is the property nil? */
130 bool isNull()
131 {
132 return mName.isEmpty();
133 }
134};
135/** The properties list type */
136typedef std::list <Property> PropertyList;
137
138/**
139 * Structure for holding an uncompleted guest call
140 */
141struct GuestCall
142{
143 uint32_t u32ClientId;
144 /** The call handle */
145 VBOXHGCMCALLHANDLE mHandle;
146 /** The function that was requested */
147 uint32_t mFunction;
148 /** Number of call parameters. */
149 uint32_t mParmsCnt;
150 /** The call parameters */
151 VBOXHGCMSVCPARM *mParms;
152 /** The default return value, used for passing warnings */
153 int mRc;
154
155 /** The standard constructor */
156 GuestCall(void) : u32ClientId(0), mFunction(0), mParmsCnt(0) {}
157 /** The normal constructor */
158 GuestCall(uint32_t aClientId, VBOXHGCMCALLHANDLE aHandle, uint32_t aFunction,
159 uint32_t aParmsCnt, VBOXHGCMSVCPARM aParms[], int aRc)
160 : u32ClientId(aClientId), mHandle(aHandle), mFunction(aFunction),
161 mParmsCnt(aParmsCnt), mParms(aParms), mRc(aRc) {}
162};
163/** The guest call list type */
164typedef std::list <GuestCall> CallList;
165
166/**
167 * Class containing the shared information service functionality.
168 */
169class Service : public RTCNonCopyable
170{
171private:
172 /** Type definition for use in callback functions */
173 typedef Service SELF;
174 /** HGCM helper functions. */
175 PVBOXHGCMSVCHELPERS mpHelpers;
176 /** Global flags for the service */
177 uint32_t mfGlobalFlags;
178 /** The property string space handle. */
179 RTSTRSPACE mhProperties;
180 /** The number of properties. */
181 unsigned mcProperties;
182 /** The list of property changes for guest notifications;
183 * only used for timestamp tracking in notifications at the moment */
184 PropertyList mGuestNotifications;
185 /** The list of outstanding guest notification calls */
186 CallList mGuestWaiters;
187 /** @todo we should have classes for thread and request handler thread */
188 /** Callback function supplied by the host for notification of updates
189 * to properties */
190 PFNHGCMSVCEXT mpfnHostCallback;
191 /** User data pointer to be supplied to the host callback function */
192 void *mpvHostData;
193 /** The previous timestamp.
194 * This is used by getCurrentTimestamp() to decrease the chance of
195 * generating duplicate timestamps. */
196 uint64_t mPrevTimestamp;
197 /** The number of consecutive timestamp adjustments that we've made.
198 * Together with mPrevTimestamp, this defines a set of obsolete timestamp
199 * values: {(mPrevTimestamp - mcTimestampAdjustments), ..., mPrevTimestamp} */
200 uint64_t mcTimestampAdjustments;
201 /** For helping setting host version properties _after_ restoring VMs. */
202 bool m_fSetHostVersionProps;
203
204 /**
205 * Get the next property change notification from the queue of saved
206 * notification based on the timestamp of the last notification seen.
207 * Notifications will only be reported if the property name matches the
208 * pattern given.
209 *
210 * @returns iprt status value
211 * @returns VWRN_NOT_FOUND if the last notification was not found in the queue
212 * @param pszPatterns the patterns to match the property name against
213 * @param nsTimestamp the timestamp of the last notification
214 * @param pProp where to return the property found. If none is
215 * found this will be set to nil.
216 * @throws nothing
217 * @thread HGCM
218 */
219 int getOldNotification(const char *pszPatterns, uint64_t nsTimestamp, Property *pProp)
220 {
221 AssertPtrReturn(pszPatterns, VERR_INVALID_POINTER);
222 /* Zero means wait for a new notification. */
223 AssertReturn(nsTimestamp != 0, VERR_INVALID_PARAMETER);
224 AssertPtrReturn(pProp, VERR_INVALID_POINTER);
225 int rc = getOldNotificationInternal(pszPatterns, nsTimestamp, pProp);
226#ifdef VBOX_STRICT
227 /*
228 * ENSURE that pProp is the first event in the notification queue that:
229 * - Appears later than nsTimestamp
230 * - Matches the pszPatterns
231 */
232 /** @todo r=bird: This incorrectly ASSUMES that mTimestamp is unique.
233 * The timestamp resolution can be very coarse on windows for instance. */
234 PropertyList::const_iterator it = mGuestNotifications.begin();
235 for (; it != mGuestNotifications.end()
236 && it->mTimestamp != nsTimestamp; ++it)
237 { /*nothing*/ }
238 if (it == mGuestNotifications.end()) /* Not found */
239 it = mGuestNotifications.begin();
240 else
241 ++it; /* Next event */
242 for (; it != mGuestNotifications.end()
243 && it->mTimestamp != pProp->mTimestamp; ++it)
244 Assert(!it->Matches(pszPatterns));
245 if (pProp->mTimestamp != 0)
246 {
247 Assert(*pProp == *it);
248 Assert(pProp->Matches(pszPatterns));
249 }
250#endif /* VBOX_STRICT */
251 return rc;
252 }
253
254 /**
255 * Check whether we have permission to change a property.
256 *
257 * @returns Strict VBox status code.
258 * @retval VINF_SUCCESS if we do.
259 * @retval VERR_PERMISSION_DENIED if the value is read-only for the requesting
260 * side.
261 * @retval VINF_PERMISSION_DENIED if the side is globally marked read-only.
262 *
263 * @param fFlags the flags on the property in question
264 * @param isGuest is the guest or the host trying to make the change?
265 */
266 int checkPermission(uint32_t fFlags, bool isGuest)
267 {
268 if (fFlags & (isGuest ? GUEST_PROP_F_RDONLYGUEST : GUEST_PROP_F_RDONLYHOST))
269 return VERR_PERMISSION_DENIED;
270 if (isGuest && (mfGlobalFlags & GUEST_PROP_F_RDONLYGUEST))
271 return VINF_PERMISSION_DENIED;
272 return VINF_SUCCESS;
273 }
274
275 /**
276 * Check whether the property name is reserved for host changes only.
277 *
278 * @returns Boolean true (host reserved) or false (available to guest).
279 *
280 * @param pszName The property name to check.
281 */
282 bool checkHostReserved(const char *pszName)
283 {
284 if (RTStrStartsWith(pszName, "/VirtualBox/GuestAdd/VBoxService/"))
285 return true;
286 if (RTStrStartsWith(pszName, "/VirtualBox/GuestAdd/PAM/"))
287 return true;
288 if (RTStrStartsWith(pszName, "/VirtualBox/GuestAdd/Greeter/"))
289 return true;
290 if (RTStrStartsWith(pszName, "/VirtualBox/GuestAdd/SharedFolders/"))
291 return true;
292 if (RTStrStartsWith(pszName, "/VirtualBox/HostInfo/"))
293 return true;
294 if (RTStrStartsWith(pszName, "/VirtualBox/VMInfo/"))
295 return true;
296 return false;
297 }
298
299 /**
300 * Gets a property.
301 *
302 * @returns Pointer to the property if found, NULL if not.
303 *
304 * @param pszName The name of the property to get.
305 */
306 Property *getPropertyInternal(const char *pszName)
307 {
308 return (Property *)RTStrSpaceGet(&mhProperties, pszName);
309 }
310
311public:
312 explicit Service(PVBOXHGCMSVCHELPERS pHelpers)
313 : mpHelpers(pHelpers)
314 , mfGlobalFlags(GUEST_PROP_F_NILFLAG)
315 , mhProperties(NULL)
316 , mcProperties(0)
317 , mpfnHostCallback(NULL)
318 , mpvHostData(NULL)
319 , mPrevTimestamp(0)
320 , mcTimestampAdjustments(0)
321 , m_fSetHostVersionProps(false)
322 , mhThreadNotifyHost(NIL_RTTHREAD)
323 , mhReqQNotifyHost(NIL_RTREQQUEUE)
324 { }
325
326 /**
327 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnUnload}
328 * Simply deletes the service object
329 */
330 static DECLCALLBACK(int) svcUnload(void *pvService)
331 {
332 AssertLogRelReturn(RT_VALID_PTR(pvService), VERR_INVALID_PARAMETER);
333 SELF *pSelf = reinterpret_cast<SELF *>(pvService);
334 int rc = pSelf->uninit();
335 AssertRC(rc);
336 if (RT_SUCCESS(rc))
337 delete pSelf;
338 return rc;
339 }
340
341 /**
342 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnConnect}
343 * Stub implementation of pfnConnect.
344 */
345 static DECLCALLBACK(int) svcConnect(void * /* pvService */,
346 uint32_t /* u32ClientID */,
347 void * /* pvClient */,
348 uint32_t /*fRequestor*/,
349 bool /*fRestoring*/)
350 {
351 return VINF_SUCCESS;
352 }
353
354 static DECLCALLBACK(int) svcDisconnect(void *pvService, uint32_t idClient, void *pvClient);
355
356 /**
357 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnCall}
358 * Wraps to the call member function
359 */
360 static DECLCALLBACK(void) svcCall(void * pvService,
361 VBOXHGCMCALLHANDLE callHandle,
362 uint32_t u32ClientID,
363 void *pvClient,
364 uint32_t u32Function,
365 uint32_t cParms,
366 VBOXHGCMSVCPARM paParms[],
367 uint64_t tsArrival)
368 {
369 AssertLogRelReturnVoid(RT_VALID_PTR(pvService));
370 LogFlowFunc(("pvService=%p, callHandle=%p, u32ClientID=%u, pvClient=%p, u32Function=%u, cParms=%u, paParms=%p\n", pvService, callHandle, u32ClientID, pvClient, u32Function, cParms, paParms));
371 SELF *pSelf = reinterpret_cast<SELF *>(pvService);
372 pSelf->call(callHandle, u32ClientID, pvClient, u32Function, cParms, paParms);
373 LogFlowFunc(("returning\n"));
374 RT_NOREF_PV(tsArrival);
375 }
376
377 /**
378 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnHostCall}
379 * Wraps to the hostCall member function
380 */
381 static DECLCALLBACK(int) svcHostCall(void *pvService,
382 uint32_t u32Function,
383 uint32_t cParms,
384 VBOXHGCMSVCPARM paParms[])
385 {
386 AssertLogRelReturn(RT_VALID_PTR(pvService), VERR_INVALID_PARAMETER);
387 LogFlowFunc(("pvService=%p, u32Function=%u, cParms=%u, paParms=%p\n", pvService, u32Function, cParms, paParms));
388 SELF *pSelf = reinterpret_cast<SELF *>(pvService);
389 int rc = pSelf->hostCall(u32Function, cParms, paParms);
390 LogFlowFunc(("rc=%Rrc\n", rc));
391 return rc;
392 }
393
394 /**
395 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnRegisterExtension}
396 * Installs a host callback for notifications of property changes.
397 */
398 static DECLCALLBACK(int) svcRegisterExtension(void *pvService,
399 PFNHGCMSVCEXT pfnExtension,
400 void *pvExtension)
401 {
402 AssertLogRelReturn(RT_VALID_PTR(pvService), VERR_INVALID_PARAMETER);
403 SELF *pSelf = reinterpret_cast<SELF *>(pvService);
404 pSelf->mpfnHostCallback = pfnExtension;
405 pSelf->mpvHostData = pvExtension;
406 return VINF_SUCCESS;
407 }
408
409 int setHostVersionProps();
410 void incrementCounterProp(const char *pszName);
411 static DECLCALLBACK(void) svcNotify(void *pvService, HGCMNOTIFYEVENT enmEvent);
412
413 int initialize();
414
415private:
416 static DECLCALLBACK(int) reqThreadFn(RTTHREAD ThreadSelf, void *pvUser);
417 uint64_t getCurrentTimestamp(void);
418 int setPropertyBlock(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
419 int getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
420 int setProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest);
421 int setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp,
422 bool fIsGuest = false);
423 int delProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest);
424 int enumProps(uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
425 int getNotification(uint32_t u32ClientId, VBOXHGCMCALLHANDLE callHandle, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
426 int getOldNotificationInternal(const char *pszPattern, uint64_t nsTimestamp, Property *pProp);
427 int getNotificationWriteOut(uint32_t cParms, VBOXHGCMSVCPARM paParms[], Property const &prop);
428 int doNotifications(const char *pszProperty, uint64_t nsTimestamp);
429 int notifyHost(const char *pszName, const char *pszValue, uint64_t nsTimestamp, const char *pszFlags);
430
431 void call(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID,
432 void *pvClient, uint32_t eFunction, uint32_t cParms,
433 VBOXHGCMSVCPARM paParms[]);
434 int hostCall(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
435 int uninit();
436 static DECLCALLBACK(void) dbgInfo(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs);
437
438 /* Thread for handling host notifications. */
439 RTTHREAD mhThreadNotifyHost;
440 /* Queue for handling requests for notifications. */
441 RTREQQUEUE mhReqQNotifyHost;
442 static DECLCALLBACK(int) threadNotifyHost(RTTHREAD self, void *pvUser);
443
444 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Service);
445};
446
447
448/**
449 * Gets the current timestamp.
450 *
451 * Since the RTTimeNow resolution can be very coarse, this method takes some
452 * simple steps to try avoid returning the same timestamp for two consecutive
453 * calls. Code like getOldNotification() more or less assumes unique
454 * timestamps.
455 *
456 * @returns Nanosecond timestamp.
457 */
458uint64_t Service::getCurrentTimestamp(void)
459{
460 RTTIMESPEC time;
461 uint64_t u64NanoTS = RTTimeSpecGetNano(RTTimeNow(&time));
462 if (mPrevTimestamp - u64NanoTS > mcTimestampAdjustments)
463 mcTimestampAdjustments = 0;
464 else
465 {
466 mcTimestampAdjustments++;
467 u64NanoTS = mPrevTimestamp + 1;
468 }
469 this->mPrevTimestamp = u64NanoTS;
470 return u64NanoTS;
471}
472
473/**
474 * Set a block of properties in the property registry, checking the validity
475 * of the arguments passed.
476 *
477 * @returns iprt status value
478 * @param cParms the number of HGCM parameters supplied
479 * @param paParms the array of HGCM parameters
480 * @thread HGCM
481 */
482int Service::setPropertyBlock(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
483{
484 const char **papszNames;
485 const char **papszValues;
486 const char **papszFlags;
487 uint64_t *paNsTimestamps;
488 uint32_t cbDummy;
489 int rc = VINF_SUCCESS;
490
491 /*
492 * Get and validate the parameters
493 */
494 if ( cParms != 4
495 || RT_FAILURE(HGCMSvcGetPv(&paParms[0], (void **)&papszNames, &cbDummy))
496 || RT_FAILURE(HGCMSvcGetPv(&paParms[1], (void **)&papszValues, &cbDummy))
497 || RT_FAILURE(HGCMSvcGetPv(&paParms[2], (void **)&paNsTimestamps, &cbDummy))
498 || RT_FAILURE(HGCMSvcGetPv(&paParms[3], (void **)&papszFlags, &cbDummy))
499 )
500 rc = VERR_INVALID_PARAMETER;
501 /** @todo validate the array sizes... */
502 else
503 {
504 for (unsigned i = 0; RT_SUCCESS(rc) && papszNames[i] != NULL; ++i)
505 {
506 if ( !RT_VALID_PTR(papszNames[i])
507 || !RT_VALID_PTR(papszValues[i])
508 || !RT_VALID_PTR(papszFlags[i])
509 )
510 rc = VERR_INVALID_POINTER;
511 else
512 {
513 uint32_t fFlagsIgn;
514 rc = GuestPropValidateFlags(papszFlags[i], &fFlagsIgn);
515 }
516 }
517 if (RT_SUCCESS(rc))
518 {
519 /*
520 * Add the properties. No way to roll back here.
521 */
522 for (unsigned i = 0; papszNames[i] != NULL; ++i)
523 {
524 uint32_t fFlags;
525 rc = GuestPropValidateFlags(papszFlags[i], &fFlags);
526 AssertRCBreak(rc);
527 /*
528 * Handle names which are read-only for the guest.
529 */
530 if (checkHostReserved(papszNames[i]))
531 fFlags |= GUEST_PROP_F_RDONLYGUEST;
532
533 Property *pProp = getPropertyInternal(papszNames[i]);
534 if (pProp)
535 {
536 /* Update existing property. */
537 rc = pProp->mValue.assignNoThrow(papszValues[i]);
538 AssertRCBreak(rc);
539 pProp->mTimestamp = paNsTimestamps[i];
540 pProp->mFlags = fFlags;
541 }
542 else
543 {
544 /* Create a new property */
545 try
546 {
547 pProp = new Property(papszNames[i], papszValues[i], paNsTimestamps[i], fFlags);
548 }
549 catch (std::bad_alloc &)
550 {
551 return VERR_NO_MEMORY;
552 }
553 if (RTStrSpaceInsert(&mhProperties, &pProp->mStrCore))
554 mcProperties++;
555 else
556 {
557 delete pProp;
558 rc = VERR_INTERNAL_ERROR_3;
559 AssertFailedBreak();
560 }
561 }
562 }
563 }
564 }
565
566 return rc;
567}
568
569/**
570 * Retrieve a value from the property registry by name, checking the validity
571 * of the arguments passed. If the guest has not allocated enough buffer
572 * space for the value then we return VERR_OVERFLOW and set the size of the
573 * buffer needed in the "size" HGCM parameter. If the name was not found at
574 * all, we return VERR_NOT_FOUND.
575 *
576 * @returns iprt status value
577 * @param cParms the number of HGCM parameters supplied
578 * @param paParms the array of HGCM parameters
579 * @thread HGCM
580 */
581int Service::getProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
582{
583 int rc;
584 const char *pcszName = NULL; /* shut up gcc */
585 char *pchBuf = NULL; /* shut up MSC */
586 uint32_t cbName;
587 uint32_t cbBuf = 0; /* shut up MSC */
588
589 /*
590 * Get and validate the parameters
591 */
592 LogFlowThisFunc(("\n"));
593 if ( cParms != 4 /* Hardcoded value as the next lines depend on it. */
594 || RT_FAILURE(HGCMSvcGetCStr(&paParms[0], &pcszName, &cbName)) /* name */
595 || RT_FAILURE(HGCMSvcGetBuf(&paParms[1], (void **)&pchBuf, &cbBuf)) /* buffer */
596 )
597 rc = VERR_INVALID_PARAMETER;
598 else
599 rc = GuestPropValidateName(pcszName, cbName);
600 if (RT_FAILURE(rc))
601 {
602 LogFlowThisFunc(("rc = %Rrc\n", rc));
603 return rc;
604 }
605
606 /*
607 * Read and set the values we will return
608 */
609
610 /* Get the property. */
611 Property *pProp = getPropertyInternal(pcszName);
612 if (pProp)
613 {
614 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
615 rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
616 if (RT_SUCCESS(rc))
617 {
618 /* Check that the buffer is big enough */
619 size_t const cbFlags = strlen(szFlags) + 1;
620 size_t const cbValue = pProp->mValue.length() + 1;
621 size_t const cbNeeded = cbValue + cbFlags;
622 HGCMSvcSetU32(&paParms[3], (uint32_t)cbNeeded);
623 if (cbBuf >= cbNeeded)
624 {
625 /* Write the value, flags and timestamp */
626 memcpy(pchBuf, pProp->mValue.c_str(), cbValue);
627 memcpy(pchBuf + cbValue, szFlags, cbFlags);
628
629 HGCMSvcSetU64(&paParms[2], pProp->mTimestamp);
630
631 /*
632 * Done! Do exit logging and return.
633 */
634 Log2(("Queried string %s, value=%s, timestamp=%lld, flags=%s\n",
635 pcszName, pProp->mValue.c_str(), pProp->mTimestamp, szFlags));
636 }
637 else
638 rc = VERR_BUFFER_OVERFLOW;
639 }
640 }
641 else
642 rc = VERR_NOT_FOUND;
643
644 LogFlowThisFunc(("rc = %Rrc (%s)\n", rc, pcszName));
645 return rc;
646}
647
648/**
649 * Set a value in the property registry by name, checking the validity
650 * of the arguments passed.
651 *
652 * @returns iprt status value
653 * @param cParms the number of HGCM parameters supplied
654 * @param paParms the array of HGCM parameters
655 * @param isGuest is this call coming from the guest (or the host)?
656 * @throws std::bad_alloc if an out of memory condition occurs
657 * @thread HGCM
658 */
659int Service::setProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest)
660{
661 int rc = VINF_SUCCESS;
662 const char *pcszName = NULL; /* shut up gcc */
663 const char *pcszValue = NULL; /* ditto */
664 const char *pcszFlags = NULL;
665 uint32_t cchName = 0; /* ditto */
666 uint32_t cchValue = 0; /* ditto */
667 uint32_t cchFlags = 0;
668 uint32_t fFlags = GUEST_PROP_F_NILFLAG;
669 uint64_t u64TimeNano = getCurrentTimestamp();
670
671 LogFlowThisFunc(("\n"));
672
673 /*
674 * General parameter correctness checking.
675 */
676 if ( RT_SUCCESS(rc)
677 && ( (cParms < 2) || (cParms > 3) /* Hardcoded value as the next lines depend on it. */
678 || RT_FAILURE(HGCMSvcGetCStr(&paParms[0], &pcszName, &cchName)) /* name */
679 || RT_FAILURE(HGCMSvcGetCStr(&paParms[1], &pcszValue, &cchValue)) /* value */
680 || ( (3 == cParms)
681 && RT_FAILURE(HGCMSvcGetCStr(&paParms[2], &pcszFlags, &cchFlags)) /* flags */
682 )
683 )
684 )
685 rc = VERR_INVALID_PARAMETER;
686
687 /*
688 * Check the values passed in the parameters for correctness.
689 */
690 if (RT_SUCCESS(rc))
691 rc = GuestPropValidateName(pcszName, cchName);
692 if (RT_SUCCESS(rc))
693 rc = GuestPropValidateValue(pcszValue, cchValue);
694 if ((3 == cParms) && RT_SUCCESS(rc))
695 rc = RTStrValidateEncodingEx(pcszFlags, cchFlags,
696 RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
697 if ((3 == cParms) && RT_SUCCESS(rc))
698 rc = GuestPropValidateFlags(pcszFlags, &fFlags);
699 if (RT_FAILURE(rc))
700 {
701 LogFlowThisFunc(("rc = %Rrc\n", rc));
702 return rc;
703 }
704
705 /*
706 * Hand it over to the internal setter method.
707 */
708 rc = setPropertyInternal(pcszName, pcszValue, fFlags, u64TimeNano, isGuest);
709
710 LogFlowThisFunc(("%s=%s, rc=%Rrc\n", pcszName, pcszValue, rc));
711 return rc;
712}
713
714/**
715 * Internal property setter.
716 *
717 * @returns VBox status code.
718 * @param pcszName The property name.
719 * @param pcszValue The new value.
720 * @param fFlags The flags.
721 * @param nsTimestamp The timestamp.
722 * @param fIsGuest Is it the guest calling.
723 * @throws std::bad_alloc if an out of memory condition occurs
724 * @thread HGCM
725 */
726int Service::setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp,
727 bool fIsGuest /*= false*/)
728{
729 /*
730 * If the property already exists, check its flags to see if we are allowed
731 * to change it.
732 */
733 Property *pProp = getPropertyInternal(pcszName);
734 int rc = checkPermission(pProp ? pProp->mFlags : GUEST_PROP_F_NILFLAG, fIsGuest);
735 /*
736 * Handle names which are read-only for the guest.
737 */
738 if (rc == VINF_SUCCESS && checkHostReserved(pcszName))
739 {
740 if (fIsGuest)
741 rc = VERR_PERMISSION_DENIED;
742 else
743 fFlags |= GUEST_PROP_F_RDONLYGUEST;
744 }
745 if (rc == VINF_SUCCESS)
746 {
747 /*
748 * Set the actual value
749 */
750 if (pProp)
751 {
752 rc = pProp->mValue.assignNoThrow(pcszValue);
753 if (RT_SUCCESS(rc))
754 {
755 pProp->mTimestamp = nsTimestamp;
756 pProp->mFlags = fFlags;
757 }
758 }
759 else if (mcProperties < GUEST_PROP_MAX_PROPS)
760 {
761 try
762 {
763 /* Create a new string space record. */
764 pProp = new Property(pcszName, pcszValue, nsTimestamp, fFlags);
765 AssertPtr(pProp);
766
767 if (RTStrSpaceInsert(&mhProperties, &pProp->mStrCore))
768 mcProperties++;
769 else
770 {
771 AssertFailed();
772 delete pProp;
773
774 rc = VERR_ALREADY_EXISTS;
775 }
776 }
777 catch (std::bad_alloc &)
778 {
779 rc = VERR_NO_MEMORY;
780 }
781 }
782 else
783 rc = VERR_TOO_MUCH_DATA;
784
785 /*
786 * Send a notification to the guest and host and return.
787 */
788 // if (fIsGuest) /* Notify the host even for properties that the host
789 // * changed. Less efficient, but ensures consistency. */
790 int rc2 = doNotifications(pcszName, nsTimestamp);
791 if (RT_SUCCESS(rc))
792 rc = rc2;
793 }
794
795 LogFlowThisFunc(("%s=%s, rc=%Rrc\n", pcszName, pcszValue, rc));
796 return rc;
797}
798
799
800/**
801 * Remove a value in the property registry by name, checking the validity
802 * of the arguments passed.
803 *
804 * @returns iprt status value
805 * @param cParms the number of HGCM parameters supplied
806 * @param paParms the array of HGCM parameters
807 * @param isGuest is this call coming from the guest (or the host)?
808 * @thread HGCM
809 */
810int Service::delProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest)
811{
812 int rc;
813 const char *pcszName = NULL; /* shut up gcc */
814 uint32_t cbName;
815
816 LogFlowThisFunc(("\n"));
817
818 /*
819 * Check the user-supplied parameters.
820 */
821 if ( (cParms == 1) /* Hardcoded value as the next lines depend on it. */
822 && RT_SUCCESS(HGCMSvcGetCStr(&paParms[0], &pcszName, &cbName)) /* name */
823 )
824 rc = GuestPropValidateName(pcszName, cbName);
825 else
826 rc = VERR_INVALID_PARAMETER;
827 if (RT_FAILURE(rc))
828 {
829 LogFlowThisFunc(("rc=%Rrc\n", rc));
830 return rc;
831 }
832
833 /*
834 * If the property exists, check its flags to see if we are allowed
835 * to change it.
836 */
837 Property *pProp = getPropertyInternal(pcszName);
838 if (pProp)
839 rc = checkPermission(pProp->mFlags, isGuest);
840
841 /*
842 * And delete the property if all is well.
843 */
844 if (rc == VINF_SUCCESS && pProp)
845 {
846 uint64_t nsTimestamp = getCurrentTimestamp();
847 PRTSTRSPACECORE pStrCore = RTStrSpaceRemove(&mhProperties, pProp->mStrCore.pszString);
848 AssertPtr(pStrCore); NOREF(pStrCore);
849 mcProperties--;
850 delete pProp;
851 // if (isGuest) /* Notify the host even for properties that the host
852 // * changed. Less efficient, but ensures consistency. */
853 int rc2 = doNotifications(pcszName, nsTimestamp);
854 if (RT_SUCCESS(rc))
855 rc = rc2;
856 }
857
858 LogFlowThisFunc(("%s: rc=%Rrc\n", pcszName, rc));
859 return rc;
860}
861
862/**
863 * Enumeration data shared between enumPropsCallback and Service::enumProps.
864 */
865typedef struct ENUMDATA
866{
867 const char *pszPattern; /**< The pattern to match properties against. */
868 char *pchCur; /**< The current buffer postion. */
869 size_t cbLeft; /**< The amount of available buffer space. */
870 size_t cbNeeded; /**< The amount of needed buffer space. */
871} ENUMDATA;
872
873/**
874 * @callback_method_impl{FNRTSTRSPACECALLBACK}
875 */
876static DECLCALLBACK(int) enumPropsCallback(PRTSTRSPACECORE pStr, void *pvUser)
877{
878 Property *pProp = (Property *)pStr;
879 ENUMDATA *pEnum = (ENUMDATA *)pvUser;
880
881 /* Included in the enumeration? */
882 if (!pProp->Matches(pEnum->pszPattern))
883 return 0;
884
885 /* Convert the non-string members into strings. */
886 char szTimestamp[256];
887 size_t const cbTimestamp = RTStrFormatNumber(szTimestamp, pProp->mTimestamp, 10, 0, 0, 0) + 1;
888
889 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
890 int rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
891 if (RT_FAILURE(rc))
892 return rc;
893 size_t const cbFlags = strlen(szFlags) + 1;
894
895 /* Calculate the buffer space requirements. */
896 size_t const cbName = pProp->mName.length() + 1;
897 size_t const cbValue = pProp->mValue.length() + 1;
898 size_t const cbRequired = cbName + cbValue + cbTimestamp + cbFlags;
899 pEnum->cbNeeded += cbRequired;
900
901 /* Sufficient buffer space? */
902 if (cbRequired > pEnum->cbLeft)
903 {
904 pEnum->cbLeft = 0;
905 return 0; /* don't quit */
906 }
907 pEnum->cbLeft -= cbRequired;
908
909 /* Append the property to the buffer. */
910 char *pchCur = pEnum->pchCur;
911 pEnum->pchCur += cbRequired;
912
913 memcpy(pchCur, pProp->mName.c_str(), cbName);
914 pchCur += cbName;
915
916 memcpy(pchCur, pProp->mValue.c_str(), cbValue);
917 pchCur += cbValue;
918
919 memcpy(pchCur, szTimestamp, cbTimestamp);
920 pchCur += cbTimestamp;
921
922 memcpy(pchCur, szFlags, cbFlags);
923 pchCur += cbFlags;
924
925 Assert(pchCur == pEnum->pchCur);
926 return 0;
927}
928
929/**
930 * Enumerate guest properties by mask, checking the validity
931 * of the arguments passed.
932 *
933 * @returns iprt status value
934 * @param cParms the number of HGCM parameters supplied
935 * @param paParms the array of HGCM parameters
936 * @thread HGCM
937 */
938int Service::enumProps(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
939{
940 int rc = VINF_SUCCESS;
941
942 /*
943 * Get the HGCM function arguments.
944 */
945 char const *pchPatterns = NULL;
946 char *pchBuf = NULL;
947 uint32_t cbPatterns = 0;
948 uint32_t cbBuf = 0;
949 LogFlowThisFunc(("\n"));
950 if ( (cParms != 3) /* Hardcoded value as the next lines depend on it. */
951 || RT_FAILURE(HGCMSvcGetCStr(&paParms[0], &pchPatterns, &cbPatterns)) /* patterns */
952 || RT_FAILURE(HGCMSvcGetBuf(&paParms[1], (void **)&pchBuf, &cbBuf)) /* return buffer */
953 )
954 rc = VERR_INVALID_PARAMETER;
955 if (RT_SUCCESS(rc) && cbPatterns > GUEST_PROP_MAX_PATTERN_LEN)
956 rc = VERR_TOO_MUCH_DATA;
957
958 /*
959 * First repack the patterns into the format expected by RTStrSimplePatternMatch()
960 */
961 char szPatterns[GUEST_PROP_MAX_PATTERN_LEN];
962 if (RT_SUCCESS(rc))
963 {
964 for (unsigned i = 0; i < cbPatterns - 1; ++i)
965 if (pchPatterns[i] != '\0')
966 szPatterns[i] = pchPatterns[i];
967 else
968 szPatterns[i] = '|';
969 szPatterns[cbPatterns - 1] = '\0';
970 }
971
972 /*
973 * Next enumerate into the buffer.
974 */
975 if (RT_SUCCESS(rc))
976 {
977 ENUMDATA EnumData;
978 EnumData.pszPattern = szPatterns;
979 EnumData.pchCur = pchBuf;
980 EnumData.cbLeft = cbBuf;
981 EnumData.cbNeeded = 0;
982 rc = RTStrSpaceEnumerate(&mhProperties, enumPropsCallback, &EnumData);
983 AssertRCSuccess(rc);
984 if (RT_SUCCESS(rc))
985 {
986 HGCMSvcSetU32(&paParms[2], (uint32_t)(EnumData.cbNeeded + 4));
987 if (EnumData.cbLeft >= 4)
988 {
989 /* The final terminators. */
990 EnumData.pchCur[0] = '\0';
991 EnumData.pchCur[1] = '\0';
992 EnumData.pchCur[2] = '\0';
993 EnumData.pchCur[3] = '\0';
994 }
995 else
996 rc = VERR_BUFFER_OVERFLOW;
997 }
998 }
999
1000 return rc;
1001}
1002
1003
1004/** Helper query used by getOldNotification
1005 * @throws nothing
1006 */
1007int Service::getOldNotificationInternal(const char *pszPatterns, uint64_t nsTimestamp, Property *pProp)
1008{
1009 /* We count backwards, as the guest should normally be querying the
1010 * most recent events. */
1011 int rc = VWRN_NOT_FOUND;
1012 PropertyList::reverse_iterator it = mGuestNotifications.rbegin();
1013 for (; it != mGuestNotifications.rend(); ++it)
1014 if (it->mTimestamp == nsTimestamp)
1015 {
1016 rc = VINF_SUCCESS;
1017 break;
1018 }
1019
1020 /* Now look for an event matching the patterns supplied. The base()
1021 * member conveniently points to the following element. */
1022 PropertyList::iterator base = it.base();
1023 for (; base != mGuestNotifications.end(); ++base)
1024 if (base->Matches(pszPatterns))
1025 {
1026 try
1027 {
1028 *pProp = *base;
1029 }
1030 catch (std::bad_alloc &)
1031 {
1032 rc = VERR_NO_MEMORY;
1033 }
1034 return rc;
1035 }
1036 *pProp = Property();
1037 return rc;
1038}
1039
1040
1041/** Helper query used by getNotification */
1042int Service::getNotificationWriteOut(uint32_t cParms, VBOXHGCMSVCPARM paParms[], Property const &rProp)
1043{
1044 AssertReturn(cParms == 4, VERR_INVALID_PARAMETER); /* Basic sanity checking. */
1045
1046 /* Format the data to write to the buffer. */
1047 char *pchBuf;
1048 uint32_t cbBuf;
1049 int rc = HGCMSvcGetBuf(&paParms[2], (void **)&pchBuf, &cbBuf);
1050 if (RT_SUCCESS(rc))
1051 {
1052 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
1053 rc = GuestPropWriteFlags(rProp.mFlags, szFlags);
1054 if (RT_SUCCESS(rc))
1055 {
1056 HGCMSvcSetU64(&paParms[1], rProp.mTimestamp);
1057
1058 size_t const cbFlags = strlen(szFlags) + 1;
1059 size_t const cbName = rProp.mName.length() + 1;
1060 size_t const cbValue = rProp.mValue.length() + 1;
1061 size_t const cbNeeded = cbName + cbValue + cbFlags;
1062 HGCMSvcSetU32(&paParms[3], (uint32_t)cbNeeded);
1063 if (cbNeeded <= cbBuf)
1064 {
1065 memcpy(pchBuf, rProp.mName.c_str(), cbName);
1066 pchBuf += cbName;
1067 memcpy(pchBuf, rProp.mValue.c_str(), cbValue);
1068 pchBuf += cbValue;
1069 memcpy(pchBuf, szFlags, cbFlags);
1070 }
1071 else
1072 rc = VERR_BUFFER_OVERFLOW;
1073 }
1074 }
1075 return rc;
1076}
1077
1078
1079/**
1080 * Get the next guest notification.
1081 *
1082 * @returns iprt status value
1083 * @param u32ClientId the client ID
1084 * @param callHandle handle
1085 * @param cParms the number of HGCM parameters supplied
1086 * @param paParms the array of HGCM parameters
1087 * @thread HGCM
1088 * @throws nothing
1089 */
1090int Service::getNotification(uint32_t u32ClientId, VBOXHGCMCALLHANDLE callHandle,
1091 uint32_t cParms, VBOXHGCMSVCPARM paParms[])
1092{
1093 int rc = VINF_SUCCESS;
1094 char *pszPatterns = NULL; /* shut up gcc */
1095 char *pchBuf;
1096 uint32_t cchPatterns = 0;
1097 uint32_t cbBuf = 0;
1098 uint64_t nsTimestamp;
1099
1100 /*
1101 * Get the HGCM function arguments and perform basic verification.
1102 */
1103 LogFlowThisFunc(("\n"));
1104 if ( cParms != 4 /* Hardcoded value as the next lines depend on it. */
1105 || RT_FAILURE(HGCMSvcGetStr(&paParms[0], &pszPatterns, &cchPatterns)) /* patterns */
1106 || RT_FAILURE(HGCMSvcGetU64(&paParms[1], &nsTimestamp)) /* timestamp */
1107 || RT_FAILURE(HGCMSvcGetBuf(&paParms[2], (void **)&pchBuf, &cbBuf)) /* return buffer */
1108 )
1109 rc = VERR_INVALID_PARAMETER;
1110 else
1111 {
1112 LogFlow(("pszPatterns=%s, nsTimestamp=%llu\n", pszPatterns, nsTimestamp));
1113
1114 /*
1115 * If no timestamp was supplied or no notification was found in the queue
1116 * of old notifications, enqueue the request in the waiting queue.
1117 */
1118 Property prop;
1119 if (RT_SUCCESS(rc) && nsTimestamp != 0)
1120 rc = getOldNotification(pszPatterns, nsTimestamp, &prop);
1121 if (RT_SUCCESS(rc))
1122 {
1123 if (prop.isNull())
1124 {
1125 /*
1126 * Check if the client already had the same request.
1127 * Complete the old request with an error in this case.
1128 * Protection against clients, which cancel and resubmits requests.
1129 */
1130 uint32_t cPendingWaits = 0;
1131 CallList::iterator it = mGuestWaiters.begin();
1132 while (it != mGuestWaiters.end())
1133 {
1134 if (u32ClientId == it->u32ClientId)
1135 {
1136 const char *pszPatternsExisting;
1137 uint32_t cchPatternsExisting;
1138 int rc3 = HGCMSvcGetCStr(&it->mParms[0], &pszPatternsExisting, &cchPatternsExisting);
1139 if ( RT_SUCCESS(rc3)
1140 && RTStrCmp(pszPatterns, pszPatternsExisting) == 0)
1141 {
1142 /* Complete the old request. */
1143 mpHelpers->pfnCallComplete(it->mHandle, VERR_INTERRUPTED);
1144 it = mGuestWaiters.erase(it);
1145 }
1146 else if (mpHelpers->pfnIsCallCancelled(it->mHandle))
1147 {
1148 /* Cleanup cancelled request. */
1149 mpHelpers->pfnCallComplete(it->mHandle, VERR_INTERRUPTED);
1150 it = mGuestWaiters.erase(it);
1151 }
1152 else
1153 {
1154 /** @todo check if cancelled. */
1155 cPendingWaits++;
1156 ++it;
1157 }
1158 }
1159 else
1160 ++it;
1161 }
1162
1163 if (cPendingWaits < GUEST_PROP_MAX_GUEST_CONCURRENT_WAITS)
1164 {
1165 try
1166 {
1167 mGuestWaiters.push_back(GuestCall(u32ClientId, callHandle, GUEST_PROP_FN_GET_NOTIFICATION,
1168 cParms, paParms, rc));
1169 rc = VINF_HGCM_ASYNC_EXECUTE;
1170 }
1171 catch (std::bad_alloc &)
1172 {
1173 rc = VERR_NO_MEMORY;
1174 }
1175 }
1176 else
1177 {
1178 LogFunc(("Too many pending waits already!\n"));
1179 rc = VERR_OUT_OF_RESOURCES;
1180 }
1181 }
1182 /*
1183 * Otherwise reply at once with the enqueued notification we found.
1184 */
1185 else
1186 {
1187 int rc2 = getNotificationWriteOut(cParms, paParms, prop);
1188 if (RT_FAILURE(rc2))
1189 rc = rc2;
1190 }
1191 }
1192 }
1193
1194 LogFlowThisFunc(("returning rc=%Rrc\n", rc));
1195 return rc;
1196}
1197
1198
1199/**
1200 * Notify the service owner and the guest that a property has been
1201 * added/deleted/changed
1202 *
1203 * @param pszProperty The name of the property which has changed.
1204 * @param nsTimestamp The time at which the change took place.
1205 * @throws nothing.
1206 * @thread HGCM service
1207 */
1208int Service::doNotifications(const char *pszProperty, uint64_t nsTimestamp)
1209{
1210 AssertPtrReturn(pszProperty, VERR_INVALID_POINTER);
1211 LogFlowThisFunc(("pszProperty=%s, nsTimestamp=%llu\n", pszProperty, nsTimestamp));
1212 /* Ensure that our timestamp is different to the last one. */
1213 if ( !mGuestNotifications.empty()
1214 && nsTimestamp == mGuestNotifications.back().mTimestamp)
1215 ++nsTimestamp;
1216
1217 /*
1218 * Don't keep too many changes around.
1219 */
1220 if (mGuestNotifications.size() >= GUEST_PROP_MAX_GUEST_NOTIFICATIONS)
1221 mGuestNotifications.pop_front();
1222
1223 /*
1224 * Try to find the property. Create a change event if we find it and a
1225 * delete event if we do not.
1226 */
1227 Property prop;
1228 int rc = prop.mName.assignNoThrow(pszProperty);
1229 AssertRCReturn(rc, rc);
1230 prop.mTimestamp = nsTimestamp;
1231 /* prop is currently a delete event for pszProperty */
1232 Property const * const pProp = getPropertyInternal(pszProperty);
1233 if (pProp)
1234 {
1235 /* Make prop into a change event. */
1236 rc = prop.mValue.assignNoThrow(pProp->mValue);
1237 AssertRCReturn(rc, rc);
1238 prop.mFlags = pProp->mFlags;
1239 }
1240
1241 /* Release guest waiters if applicable and add the event
1242 * to the queue for guest notifications */
1243 CallList::iterator it = mGuestWaiters.begin();
1244 if (it != mGuestWaiters.end())
1245 {
1246 const char *pszPatterns = NULL;
1247 uint32_t cchPatterns;
1248 HGCMSvcGetCStr(&it->mParms[0], &pszPatterns, &cchPatterns);
1249
1250 while (it != mGuestWaiters.end())
1251 {
1252 if (prop.Matches(pszPatterns))
1253 {
1254 int rc2 = getNotificationWriteOut(it->mParmsCnt, it->mParms, prop);
1255 if (RT_SUCCESS(rc2))
1256 rc2 = it->mRc;
1257 mpHelpers->pfnCallComplete(it->mHandle, rc2);
1258 it = mGuestWaiters.erase(it);
1259 }
1260 else
1261 ++it;
1262 }
1263 }
1264
1265 try
1266 {
1267 mGuestNotifications.push_back(prop);
1268 }
1269 catch (std::bad_alloc &)
1270 {
1271 rc = VERR_NO_MEMORY;
1272 }
1273
1274 if ( RT_SUCCESS(rc)
1275 && mpfnHostCallback)
1276 {
1277 /*
1278 * Host notifications - first case: if the property exists then send its
1279 * current value
1280 */
1281 if (pProp)
1282 {
1283 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
1284 /* Send out a host notification */
1285 const char *pszValue = prop.mValue.c_str();
1286 rc = GuestPropWriteFlags(prop.mFlags, szFlags);
1287 if (RT_SUCCESS(rc))
1288 rc = notifyHost(pszProperty, pszValue, nsTimestamp, szFlags);
1289 }
1290 /*
1291 * Host notifications - second case: if the property does not exist then
1292 * send the host an empty value
1293 */
1294 else
1295 {
1296 /* Send out a host notification */
1297 rc = notifyHost(pszProperty, NULL, nsTimestamp, "");
1298 }
1299 }
1300
1301 LogFlowThisFunc(("returning rc=%Rrc\n", rc));
1302 return rc;
1303}
1304
1305static DECLCALLBACK(void)
1306notifyHostAsyncWorker(PFNHGCMSVCEXT pfnHostCallback, void *pvHostData, PGUESTPROPHOSTCALLBACKDATA pHostCallbackData)
1307{
1308 pfnHostCallback(pvHostData, 0 /*u32Function*/, (void *)pHostCallbackData, sizeof(GUESTPROPHOSTCALLBACKDATA));
1309 RTMemFree(pHostCallbackData);
1310}
1311
1312/**
1313 * Notify the service owner that a property has been added/deleted/changed.
1314 * @returns IPRT status value
1315 * @param pszName the property name
1316 * @param pszValue the new value, or NULL if the property was deleted
1317 * @param nsTimestamp the time of the change
1318 * @param pszFlags the new flags string
1319 */
1320int Service::notifyHost(const char *pszName, const char *pszValue, uint64_t nsTimestamp, const char *pszFlags)
1321{
1322 LogFlowFunc(("pszName=%s, pszValue=%s, nsTimestamp=%llu, pszFlags=%s\n", pszName, pszValue, nsTimestamp, pszFlags));
1323 int rc;
1324
1325 /* Allocate buffer for the callback data and strings. */
1326 size_t cbName = pszName? strlen(pszName): 0;
1327 size_t cbValue = pszValue? strlen(pszValue): 0;
1328 size_t cbFlags = pszFlags? strlen(pszFlags): 0;
1329 size_t cbAlloc = sizeof(GUESTPROPHOSTCALLBACKDATA) + cbName + cbValue + cbFlags + 3;
1330 PGUESTPROPHOSTCALLBACKDATA pHostCallbackData = (PGUESTPROPHOSTCALLBACKDATA)RTMemAlloc(cbAlloc);
1331 if (pHostCallbackData)
1332 {
1333 uint8_t *pu8 = (uint8_t *)pHostCallbackData;
1334 pu8 += sizeof(GUESTPROPHOSTCALLBACKDATA);
1335
1336 pHostCallbackData->u32Magic = GUESTPROPHOSTCALLBACKDATA_MAGIC;
1337
1338 pHostCallbackData->pcszName = (const char *)pu8;
1339 memcpy(pu8, pszName, cbName);
1340 pu8 += cbName;
1341 *pu8++ = 0;
1342
1343 /* NULL value means property was deleted. */
1344 pHostCallbackData->pcszValue = pszValue ? (const char *)pu8 : NULL;
1345 memcpy(pu8, pszValue, cbValue);
1346 pu8 += cbValue;
1347 *pu8++ = 0;
1348
1349 pHostCallbackData->u64Timestamp = nsTimestamp;
1350
1351 pHostCallbackData->pcszFlags = (const char *)pu8;
1352 memcpy(pu8, pszFlags, cbFlags);
1353 pu8 += cbFlags;
1354 *pu8++ = 0;
1355
1356 rc = RTReqQueueCallEx(mhReqQNotifyHost, NULL, 0, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
1357 (PFNRT)notifyHostAsyncWorker, 3,
1358 mpfnHostCallback, mpvHostData, pHostCallbackData);
1359 if (RT_FAILURE(rc))
1360 {
1361 RTMemFree(pHostCallbackData);
1362 }
1363 }
1364 else
1365 {
1366 rc = VERR_NO_MEMORY;
1367 }
1368 LogFlowFunc(("returning rc=%Rrc\n", rc));
1369 return rc;
1370}
1371
1372
1373/**
1374 * Handle an HGCM service call.
1375 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnCall}
1376 * @note All functions which do not involve an unreasonable delay will be
1377 * handled synchronously. If needed, we will add a request handler
1378 * thread in future for those which do.
1379 *
1380 * @thread HGCM
1381 */
1382void Service::call (VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID,
1383 void * /* pvClient */, uint32_t eFunction, uint32_t cParms,
1384 VBOXHGCMSVCPARM paParms[])
1385{
1386 int rc;
1387 LogFlowFunc(("u32ClientID = %d, fn = %d, cParms = %d, pparms = %p\n",
1388 u32ClientID, eFunction, cParms, paParms));
1389
1390 switch (eFunction)
1391 {
1392 /* The guest wishes to read a property */
1393 case GUEST_PROP_FN_GET_PROP:
1394 LogFlowFunc(("GET_PROP\n"));
1395 rc = getProperty(cParms, paParms);
1396 break;
1397
1398 /* The guest wishes to set a property */
1399 case GUEST_PROP_FN_SET_PROP:
1400 LogFlowFunc(("SET_PROP\n"));
1401 rc = setProperty(cParms, paParms, true);
1402 break;
1403
1404 /* The guest wishes to set a property value */
1405 case GUEST_PROP_FN_SET_PROP_VALUE:
1406 LogFlowFunc(("SET_PROP_VALUE\n"));
1407 rc = setProperty(cParms, paParms, true);
1408 break;
1409
1410 /* The guest wishes to remove a configuration value */
1411 case GUEST_PROP_FN_DEL_PROP:
1412 LogFlowFunc(("DEL_PROP\n"));
1413 rc = delProperty(cParms, paParms, true);
1414 break;
1415
1416 /* The guest wishes to enumerate all properties */
1417 case GUEST_PROP_FN_ENUM_PROPS:
1418 LogFlowFunc(("ENUM_PROPS\n"));
1419 rc = enumProps(cParms, paParms);
1420 break;
1421
1422 /* The guest wishes to get the next property notification */
1423 case GUEST_PROP_FN_GET_NOTIFICATION:
1424 LogFlowFunc(("GET_NOTIFICATION\n"));
1425 rc = getNotification(u32ClientID, callHandle, cParms, paParms);
1426 break;
1427
1428 default:
1429 rc = VERR_NOT_IMPLEMENTED;
1430 }
1431 LogFlowFunc(("rc = %Rrc\n", rc));
1432 if (rc != VINF_HGCM_ASYNC_EXECUTE)
1433 mpHelpers->pfnCallComplete(callHandle, rc);
1434}
1435
1436/**
1437 * Enumeration data shared between dbgInfoCallback and Service::dbgInfoShow.
1438 */
1439typedef struct ENUMDBGINFO
1440{
1441 PCDBGFINFOHLP pHlp;
1442} ENUMDBGINFO;
1443
1444static DECLCALLBACK(int) dbgInfoCallback(PRTSTRSPACECORE pStr, void *pvUser)
1445{
1446 Property *pProp = (Property *)pStr;
1447 PCDBGFINFOHLP pHlp = ((ENUMDBGINFO *)pvUser)->pHlp;
1448
1449 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
1450 int rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
1451 if (RT_FAILURE(rc))
1452 RTStrPrintf(szFlags, sizeof(szFlags), "???");
1453
1454 pHlp->pfnPrintf(pHlp, "%s: '%s', %RU64", pProp->mName.c_str(), pProp->mValue.c_str(), pProp->mTimestamp);
1455 if (strlen(szFlags))
1456 pHlp->pfnPrintf(pHlp, " (%s)", szFlags);
1457 pHlp->pfnPrintf(pHlp, "\n");
1458 return 0;
1459}
1460
1461
1462/**
1463 * Handler for debug info.
1464 *
1465 * @param pvUser user pointer.
1466 * @param pHlp The info helper functions.
1467 * @param pszArgs Arguments, ignored.
1468 */
1469DECLCALLBACK(void) Service::dbgInfo(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs)
1470{
1471 RT_NOREF1(pszArgs);
1472 SELF *pSelf = reinterpret_cast<SELF *>(pvUser);
1473
1474 ENUMDBGINFO EnumData = { pHlp };
1475 RTStrSpaceEnumerate(&pSelf->mhProperties, dbgInfoCallback, &EnumData);
1476}
1477
1478
1479/**
1480 * Service call handler for the host.
1481 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnHostCall}
1482 * @thread hgcm
1483 */
1484int Service::hostCall (uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
1485{
1486 int rc;
1487 LogFlowFunc(("fn = %d, cParms = %d, pparms = %p\n", eFunction, cParms, paParms));
1488
1489 switch (eFunction)
1490 {
1491 /* The host wishes to set a block of properties */
1492 case GUEST_PROP_FN_HOST_SET_PROPS:
1493 LogFlowFunc(("SET_PROPS_HOST\n"));
1494 rc = setPropertyBlock(cParms, paParms);
1495 break;
1496
1497 /* The host wishes to read a configuration value */
1498 case GUEST_PROP_FN_HOST_GET_PROP:
1499 LogFlowFunc(("GET_PROP_HOST\n"));
1500 rc = getProperty(cParms, paParms);
1501 break;
1502
1503 /* The host wishes to set a configuration value */
1504 case GUEST_PROP_FN_HOST_SET_PROP:
1505 LogFlowFunc(("SET_PROP_HOST\n"));
1506 rc = setProperty(cParms, paParms, false);
1507 break;
1508
1509 /* The host wishes to set a configuration value */
1510 case GUEST_PROP_FN_HOST_SET_PROP_VALUE:
1511 LogFlowFunc(("SET_PROP_VALUE_HOST\n"));
1512 rc = setProperty(cParms, paParms, false);
1513 break;
1514
1515 /* The host wishes to remove a configuration value */
1516 case GUEST_PROP_FN_HOST_DEL_PROP:
1517 LogFlowFunc(("DEL_PROP_HOST\n"));
1518 rc = delProperty(cParms, paParms, false);
1519 break;
1520
1521 /* The host wishes to enumerate all properties */
1522 case GUEST_PROP_FN_HOST_ENUM_PROPS:
1523 LogFlowFunc(("ENUM_PROPS\n"));
1524 rc = enumProps(cParms, paParms);
1525 break;
1526
1527 /* The host wishes to set global flags for the service */
1528 case GUEST_PROP_FN_HOST_SET_GLOBAL_FLAGS:
1529 LogFlowFunc(("SET_GLOBAL_FLAGS_HOST\n"));
1530 if (cParms == 1)
1531 {
1532 uint32_t fFlags;
1533 rc = HGCMSvcGetU32(&paParms[0], &fFlags);
1534 if (RT_SUCCESS(rc))
1535 mfGlobalFlags = fFlags;
1536 }
1537 else
1538 rc = VERR_INVALID_PARAMETER;
1539 break;
1540
1541 default:
1542 rc = VERR_NOT_SUPPORTED;
1543 break;
1544 }
1545
1546 LogFlowFunc(("rc = %Rrc\n", rc));
1547 return rc;
1548}
1549
1550/**
1551 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnDisconnect}
1552 */
1553/*static*/ DECLCALLBACK(int) Service::svcDisconnect(void *pvService, uint32_t idClient, void *pvClient)
1554{
1555 RT_NOREF(pvClient);
1556 LogFlowFunc(("idClient=%u\n", idClient));
1557 SELF *pThis = reinterpret_cast<SELF *>(pvService);
1558 AssertLogRelReturn(pThis, VERR_INVALID_POINTER);
1559
1560 /*
1561 * Complete all pending requests for this client.
1562 */
1563 for (CallList::iterator It = pThis->mGuestWaiters.begin(); It != pThis->mGuestWaiters.end();)
1564 {
1565 GuestCall &rCurCall = *It;
1566 if (rCurCall.u32ClientId != idClient)
1567 ++It;
1568 else
1569 {
1570 LogFlowFunc(("Completing call %u (%p)...\n", rCurCall.mFunction, rCurCall.mHandle));
1571 pThis->mpHelpers->pfnCallComplete(rCurCall.mHandle, VERR_INTERRUPTED);
1572 It = pThis->mGuestWaiters.erase(It);
1573 }
1574 }
1575
1576 return VINF_SUCCESS;
1577}
1578
1579/**
1580 * Increments a counter property.
1581 *
1582 * It is assumed that this a transient property that is read-only to the guest.
1583 *
1584 * @param pszName The property name.
1585 * @throws std::bad_alloc if an out of memory condition occurs
1586 */
1587void Service::incrementCounterProp(const char *pszName)
1588{
1589 /* Format the incremented value. */
1590 char szValue[64];
1591 Property *pProp = getPropertyInternal(pszName);
1592 if (pProp)
1593 {
1594 uint64_t uValue = RTStrToUInt64(pProp->mValue.c_str());
1595 RTStrFormatU64(szValue, sizeof(szValue), uValue + 1, 10, 0, 0, 0);
1596 }
1597 else
1598 {
1599 szValue[0] = '1';
1600 szValue[1] = '\0';
1601 }
1602
1603 /* Set it. */
1604 setPropertyInternal(pszName, szValue, GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, getCurrentTimestamp());
1605}
1606
1607/**
1608 * Sets the VBoxVer, VBoxVerExt and VBoxRev properties.
1609 */
1610int Service::setHostVersionProps()
1611{
1612 uint64_t nsTimestamp = getCurrentTimestamp();
1613
1614 /* Set the raw VBox version string as a guest property. Used for host/guest
1615 * version comparison. */
1616 int rc = setPropertyInternal("/VirtualBox/HostInfo/VBoxVer", VBOX_VERSION_STRING_RAW,
1617 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp);
1618 AssertRCReturn(rc, rc);
1619
1620 /* Set the full VBox version string as a guest property. Can contain vendor-specific
1621 * information/branding and/or pre-release tags. */
1622 rc = setPropertyInternal("/VirtualBox/HostInfo/VBoxVerExt", VBOX_VERSION_STRING,
1623 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp + 1);
1624 AssertRCReturn(rc, rc);
1625
1626 /* Set the VBox SVN revision as a guest property */
1627 rc = setPropertyInternal("/VirtualBox/HostInfo/VBoxRev", RTBldCfgRevisionStr(),
1628 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp + 2);
1629 AssertRCReturn(rc, rc);
1630 return VINF_SUCCESS;
1631}
1632
1633
1634/**
1635 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnNotify}
1636 */
1637/*static*/ DECLCALLBACK(void) Service::svcNotify(void *pvService, HGCMNOTIFYEVENT enmEvent)
1638{
1639 SELF *pThis = reinterpret_cast<SELF *>(pvService);
1640 AssertPtrReturnVoid(pThis);
1641
1642 /* Make sure the host version properties have been touched and are
1643 up-to-date after a restore: */
1644 if ( !pThis->m_fSetHostVersionProps
1645 && (enmEvent == HGCMNOTIFYEVENT_RESUME || enmEvent == HGCMNOTIFYEVENT_POWER_ON))
1646 {
1647 pThis->setHostVersionProps();
1648 pThis->m_fSetHostVersionProps = true;
1649 }
1650
1651 if (enmEvent == HGCMNOTIFYEVENT_RESUME)
1652 pThis->incrementCounterProp("/VirtualBox/VMInfo/ResumeCounter");
1653
1654 if (enmEvent == HGCMNOTIFYEVENT_RESET)
1655 pThis->incrementCounterProp("/VirtualBox/VMInfo/ResetCounter");
1656}
1657
1658
1659/* static */
1660DECLCALLBACK(int) Service::threadNotifyHost(RTTHREAD hThreadSelf, void *pvUser)
1661{
1662 RT_NOREF1(hThreadSelf);
1663 Service *pThis = (Service *)pvUser;
1664 int rc = VINF_SUCCESS;
1665
1666 LogFlowFunc(("ENTER: %p\n", pThis));
1667
1668 for (;;)
1669 {
1670 rc = RTReqQueueProcess(pThis->mhReqQNotifyHost, RT_INDEFINITE_WAIT);
1671
1672 AssertMsg(rc == VWRN_STATE_CHANGED,
1673 ("Left RTReqProcess and error code is not VWRN_STATE_CHANGED rc=%Rrc\n",
1674 rc));
1675 if (rc == VWRN_STATE_CHANGED)
1676 {
1677 break;
1678 }
1679 }
1680
1681 LogFlowFunc(("LEAVE: %Rrc\n", rc));
1682 return rc;
1683}
1684
1685static DECLCALLBACK(int) wakeupNotifyHost(void)
1686{
1687 /* Returning a VWRN_* will cause RTReqQueueProcess return. */
1688 return VWRN_STATE_CHANGED;
1689}
1690
1691
1692int Service::initialize()
1693{
1694 /*
1695 * Insert standard host properties.
1696 */
1697 /* The host version will but updated again on power on or resume
1698 (after restore), however we need the properties now for restored
1699 guest notification/wait calls. */
1700 int rc = setHostVersionProps();
1701 AssertRCReturn(rc, rc);
1702
1703 /* Sysprep execution by VBoxService (host is allowed to change these). */
1704 uint64_t nsNow = getCurrentTimestamp();
1705 rc = setPropertyInternal("/VirtualBox/HostGuest/SysprepExec", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1706 AssertRCReturn(rc, rc);
1707 rc = setPropertyInternal("/VirtualBox/HostGuest/SysprepArgs", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1708 AssertRCReturn(rc, rc);
1709
1710 /* Resume and reset counters. */
1711 rc = setPropertyInternal("/VirtualBox/VMInfo/ResumeCounter", "0", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1712 AssertRCReturn(rc, rc);
1713 rc = setPropertyInternal("/VirtualBox/VMInfo/ResetCounter", "0", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1714 AssertRCReturn(rc, rc);
1715
1716 /* The host notification thread and queue. */
1717 rc = RTReqQueueCreate(&mhReqQNotifyHost);
1718 if (RT_SUCCESS(rc))
1719 {
1720 rc = RTThreadCreate(&mhThreadNotifyHost,
1721 threadNotifyHost,
1722 this,
1723 0 /* default stack size */,
1724 RTTHREADTYPE_DEFAULT,
1725 RTTHREADFLAGS_WAITABLE,
1726 "GstPropNtfy");
1727 if (RT_SUCCESS(rc))
1728 {
1729 /* Finally debug stuff (ignore failures): */
1730 HGCMSvcHlpInfoRegister(mpHelpers, "guestprops", "Display the guest properties", Service::dbgInfo, this);
1731 return rc;
1732 }
1733
1734 RTReqQueueDestroy(mhReqQNotifyHost);
1735 mhReqQNotifyHost = NIL_RTREQQUEUE;
1736 }
1737 return rc;
1738}
1739
1740/**
1741 * @callback_method_impl{FNRTSTRSPACECALLBACK, Destroys Property.}
1742 */
1743static DECLCALLBACK(int) destroyProperty(PRTSTRSPACECORE pStr, void *pvUser)
1744{
1745 RT_NOREF(pvUser);
1746 Property *pProp = RT_FROM_CPP_MEMBER(pStr, struct Property, mStrCore); /* clang objects to offsetof on non-POD.*/
1747 delete pProp;
1748 return 0;
1749}
1750
1751
1752int Service::uninit()
1753{
1754 if (mpHelpers)
1755 HGCMSvcHlpInfoDeregister(mpHelpers, "guestprops");
1756
1757 if (mhReqQNotifyHost != NIL_RTREQQUEUE)
1758 {
1759 /* Stop the thread */
1760 PRTREQ pReq;
1761 int rc = RTReqQueueCall(mhReqQNotifyHost, &pReq, 10000, (PFNRT)wakeupNotifyHost, 0);
1762 if (RT_SUCCESS(rc))
1763 RTReqRelease(pReq);
1764 rc = RTThreadWait(mhThreadNotifyHost, 10000, NULL);
1765 AssertRC(rc);
1766 rc = RTReqQueueDestroy(mhReqQNotifyHost);
1767 AssertRC(rc);
1768 mhReqQNotifyHost = NIL_RTREQQUEUE;
1769 mhThreadNotifyHost = NIL_RTTHREAD;
1770 RTStrSpaceDestroy(&mhProperties, destroyProperty, NULL);
1771 mhProperties = NULL;
1772 }
1773 return VINF_SUCCESS;
1774}
1775
1776} /* namespace guestProp */
1777
1778using guestProp::Service;
1779
1780/**
1781 * @copydoc FNVBOXHGCMSVCLOAD
1782 */
1783extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad(VBOXHGCMSVCFNTABLE *ptable)
1784{
1785 int rc = VERR_IPE_UNINITIALIZED_STATUS;
1786
1787 LogFlowFunc(("ptable = %p\n", ptable));
1788
1789 if (!RT_VALID_PTR(ptable))
1790 rc = VERR_INVALID_PARAMETER;
1791 else
1792 {
1793 LogFlowFunc(("ptable->cbSize = %d, ptable->u32Version = 0x%08X\n", ptable->cbSize, ptable->u32Version));
1794
1795 if ( ptable->cbSize != sizeof(VBOXHGCMSVCFNTABLE)
1796 || ptable->u32Version != VBOX_HGCM_SVC_VERSION)
1797 rc = VERR_VERSION_MISMATCH;
1798 else
1799 {
1800 Service *pService = NULL;
1801 /* No exceptions may propagate outside. */
1802 try
1803 {
1804 pService = new Service(ptable->pHelpers);
1805 rc = VINF_SUCCESS;
1806 }
1807 catch (int rcThrown)
1808 {
1809 rc = rcThrown;
1810 }
1811 catch (...)
1812 {
1813 rc = VERR_UNEXPECTED_EXCEPTION;
1814 }
1815
1816 if (RT_SUCCESS(rc))
1817 {
1818 /* We do not maintain connections, so no client data is needed. */
1819 ptable->cbClient = 0;
1820
1821 /* Legacy clients map to the kernel category. */
1822 ptable->idxLegacyClientCategory = HGCM_CLIENT_CATEGORY_KERNEL;
1823
1824 /* Go with default client limits, but we won't ever need more than
1825 16 pending calls per client I would think (1 should be enough). */
1826 for (uintptr_t i = 0; i < RT_ELEMENTS(ptable->acMaxClients); i++)
1827 ptable->acMaxCallsPerClient[i] = 16;
1828
1829 ptable->pfnUnload = Service::svcUnload;
1830 ptable->pfnConnect = Service::svcConnect;
1831 ptable->pfnDisconnect = Service::svcDisconnect;
1832 ptable->pfnCall = Service::svcCall;
1833 ptable->pfnHostCall = Service::svcHostCall;
1834 ptable->pfnSaveState = NULL; /* The service is stateless, so the normal */
1835 ptable->pfnLoadState = NULL; /* construction done before restoring suffices */
1836 ptable->pfnRegisterExtension = Service::svcRegisterExtension;
1837 ptable->pfnNotify = Service::svcNotify;
1838 ptable->pvService = pService;
1839
1840 /* Service specific initialization. */
1841 rc = pService->initialize();
1842 if (RT_FAILURE(rc))
1843 {
1844 delete pService;
1845 pService = NULL;
1846 }
1847 }
1848 else
1849 Assert(!pService);
1850 }
1851 }
1852
1853 LogFlowFunc(("returning %Rrc\n", rc));
1854 return rc;
1855}
1856
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