VirtualBox

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

最後變更 在這個檔案從95331是 95324,由 vboxsync 提交於 3 年 前

GuestProperties: No need to validate flag encoding twice in Service::setProperty, as HGCMSvcGetCStr always does it. Also, use 'cb' rather than 'cch' when the string terminator is included in the count.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 62.5 KB
 
1/* $Id: VBoxGuestPropSvc.cpp 95324 2022-06-21 14:09:10Z 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.alldomusa.eu.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, bool fWasDeleted);
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 const char *pcszName = NULL; /* shut up gcc */
662 const char *pcszValue = NULL; /* ditto */
663 const char *pcszFlags = NULL;
664 uint32_t cbName = 0; /* ditto */
665 uint32_t cbValue = 0; /* ditto */
666 uint32_t cbFlags = 0;
667 uint32_t fFlags = GUEST_PROP_F_NILFLAG;
668 uint64_t u64TimeNano = getCurrentTimestamp();
669
670 LogFlowThisFunc(("\n"));
671
672 /*
673 * General parameter correctness checking.
674 */
675 int rc = VINF_SUCCESS;
676 if ( cParms < 2 /* Hardcoded value as the next lines depend on it these range checks. */
677 || cParms > 3
678 || RT_FAILURE(HGCMSvcGetCStr(&paParms[0], &pcszName, &cbName)) /* name */
679 || RT_FAILURE(HGCMSvcGetCStr(&paParms[1], &pcszValue, &cbValue)) /* value */
680 || ( cParms == 3
681 && RT_FAILURE(HGCMSvcGetCStr(&paParms[2], &pcszFlags, &cbFlags)) /* flags */
682 )
683 )
684 rc = VERR_INVALID_PARAMETER;
685
686 /*
687 * Check the values passed in the parameters for correctness.
688 */
689 if (RT_SUCCESS(rc))
690 rc = GuestPropValidateName(pcszName, cbName);
691 if (RT_SUCCESS(rc))
692 rc = GuestPropValidateValue(pcszValue, cbValue);
693 if (cParms == 3 && RT_SUCCESS(rc))
694 rc = GuestPropValidateFlags(pcszFlags, &fFlags);
695 if (RT_FAILURE(rc))
696 {
697 LogFlowThisFunc(("rc = %Rrc\n", rc));
698 return rc;
699 }
700
701 /*
702 * Hand it over to the internal setter method.
703 */
704 rc = setPropertyInternal(pcszName, pcszValue, fFlags, u64TimeNano, isGuest);
705
706 LogFlowThisFunc(("%s=%s, rc=%Rrc\n", pcszName, pcszValue, rc));
707 return rc;
708}
709
710/**
711 * Internal property setter.
712 *
713 * @returns VBox status code.
714 * @param pcszName The property name.
715 * @param pcszValue The new value.
716 * @param fFlags The flags.
717 * @param nsTimestamp The timestamp.
718 * @param fIsGuest Is it the guest calling.
719 * @throws std::bad_alloc if an out of memory condition occurs
720 * @thread HGCM
721 */
722int Service::setPropertyInternal(const char *pcszName, const char *pcszValue, uint32_t fFlags, uint64_t nsTimestamp,
723 bool fIsGuest /*= false*/)
724{
725 /*
726 * If the property already exists, check its flags to see if we are allowed
727 * to change it.
728 */
729 Property *pProp = getPropertyInternal(pcszName);
730 int rc = checkPermission(pProp ? pProp->mFlags : GUEST_PROP_F_NILFLAG, fIsGuest);
731 /*
732 * Handle names which are read-only for the guest.
733 */
734 if (rc == VINF_SUCCESS && checkHostReserved(pcszName))
735 {
736 if (fIsGuest)
737 rc = VERR_PERMISSION_DENIED;
738 else
739 fFlags |= GUEST_PROP_F_RDONLYGUEST;
740 }
741 if (rc == VINF_SUCCESS)
742 {
743 /*
744 * Set the actual value
745 */
746 if (pProp)
747 {
748 rc = pProp->mValue.assignNoThrow(pcszValue);
749 if (RT_SUCCESS(rc))
750 {
751 pProp->mTimestamp = nsTimestamp;
752 pProp->mFlags = fFlags;
753 }
754 }
755 else if (mcProperties < GUEST_PROP_MAX_PROPS)
756 {
757 try
758 {
759 /* Create a new string space record. */
760 pProp = new Property(pcszName, pcszValue, nsTimestamp, fFlags);
761 AssertPtr(pProp);
762
763 if (RTStrSpaceInsert(&mhProperties, &pProp->mStrCore))
764 mcProperties++;
765 else
766 {
767 AssertFailed();
768 delete pProp;
769
770 rc = VERR_ALREADY_EXISTS;
771 }
772 }
773 catch (std::bad_alloc &)
774 {
775 rc = VERR_NO_MEMORY;
776 }
777 }
778 else
779 rc = VERR_TOO_MUCH_DATA;
780
781 /*
782 * Send a notification to the guest and host and return.
783 */
784 // if (fIsGuest) /* Notify the host even for properties that the host
785 // * changed. Less efficient, but ensures consistency. */
786 int rc2 = doNotifications(pcszName, nsTimestamp);
787 if (RT_SUCCESS(rc))
788 rc = rc2;
789 }
790
791 LogFlowThisFunc(("%s=%s, rc=%Rrc\n", pcszName, pcszValue, rc));
792 return rc;
793}
794
795
796/**
797 * Remove a value in the property registry by name, checking the validity
798 * of the arguments passed.
799 *
800 * @returns iprt status value
801 * @param cParms the number of HGCM parameters supplied
802 * @param paParms the array of HGCM parameters
803 * @param isGuest is this call coming from the guest (or the host)?
804 * @thread HGCM
805 */
806int Service::delProperty(uint32_t cParms, VBOXHGCMSVCPARM paParms[], bool isGuest)
807{
808 int rc;
809 const char *pcszName = NULL; /* shut up gcc */
810 uint32_t cbName;
811
812 LogFlowThisFunc(("\n"));
813
814 /*
815 * Check the user-supplied parameters.
816 */
817 if ( (cParms == 1) /* Hardcoded value as the next lines depend on it. */
818 && RT_SUCCESS(HGCMSvcGetCStr(&paParms[0], &pcszName, &cbName)) /* name */
819 )
820 rc = GuestPropValidateName(pcszName, cbName);
821 else
822 rc = VERR_INVALID_PARAMETER;
823 if (RT_FAILURE(rc))
824 {
825 LogFlowThisFunc(("rc=%Rrc\n", rc));
826 return rc;
827 }
828
829 /*
830 * If the property exists, check its flags to see if we are allowed
831 * to change it.
832 */
833 Property *pProp = getPropertyInternal(pcszName);
834 if (pProp)
835 rc = checkPermission(pProp->mFlags, isGuest);
836
837 /*
838 * And delete the property if all is well.
839 */
840 if (rc == VINF_SUCCESS && pProp)
841 {
842 uint64_t nsTimestamp = getCurrentTimestamp();
843 PRTSTRSPACECORE pStrCore = RTStrSpaceRemove(&mhProperties, pProp->mStrCore.pszString);
844 AssertPtr(pStrCore); NOREF(pStrCore);
845 mcProperties--;
846 delete pProp;
847 // if (isGuest) /* Notify the host even for properties that the host
848 // * changed. Less efficient, but ensures consistency. */
849 int rc2 = doNotifications(pcszName, nsTimestamp);
850 if (RT_SUCCESS(rc))
851 rc = rc2;
852 }
853
854 LogFlowThisFunc(("%s: rc=%Rrc\n", pcszName, rc));
855 return rc;
856}
857
858/**
859 * Enumeration data shared between enumPropsCallback and Service::enumProps.
860 */
861typedef struct ENUMDATA
862{
863 const char *pszPattern; /**< The pattern to match properties against. */
864 char *pchCur; /**< The current buffer postion. */
865 size_t cbLeft; /**< The amount of available buffer space. */
866 size_t cbNeeded; /**< The amount of needed buffer space. */
867} ENUMDATA;
868
869/**
870 * @callback_method_impl{FNRTSTRSPACECALLBACK}
871 */
872static DECLCALLBACK(int) enumPropsCallback(PRTSTRSPACECORE pStr, void *pvUser)
873{
874 Property *pProp = (Property *)pStr;
875 ENUMDATA *pEnum = (ENUMDATA *)pvUser;
876
877 /* Included in the enumeration? */
878 if (!pProp->Matches(pEnum->pszPattern))
879 return 0;
880
881 /* Convert the non-string members into strings. */
882 char szTimestamp[256];
883 size_t const cbTimestamp = RTStrFormatNumber(szTimestamp, pProp->mTimestamp, 10, 0, 0, 0) + 1;
884
885 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
886 int rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
887 if (RT_FAILURE(rc))
888 return rc;
889 size_t const cbFlags = strlen(szFlags) + 1;
890
891 /* Calculate the buffer space requirements. */
892 size_t const cbName = pProp->mName.length() + 1;
893 size_t const cbValue = pProp->mValue.length() + 1;
894 size_t const cbRequired = cbName + cbValue + cbTimestamp + cbFlags;
895 pEnum->cbNeeded += cbRequired;
896
897 /* Sufficient buffer space? */
898 if (cbRequired > pEnum->cbLeft)
899 {
900 pEnum->cbLeft = 0;
901 return 0; /* don't quit */
902 }
903 pEnum->cbLeft -= cbRequired;
904
905 /* Append the property to the buffer. */
906 char *pchCur = pEnum->pchCur;
907 pEnum->pchCur += cbRequired;
908
909 memcpy(pchCur, pProp->mName.c_str(), cbName);
910 pchCur += cbName;
911
912 memcpy(pchCur, pProp->mValue.c_str(), cbValue);
913 pchCur += cbValue;
914
915 memcpy(pchCur, szTimestamp, cbTimestamp);
916 pchCur += cbTimestamp;
917
918 memcpy(pchCur, szFlags, cbFlags);
919 pchCur += cbFlags;
920
921 Assert(pchCur == pEnum->pchCur);
922 return 0;
923}
924
925/**
926 * Enumerate guest properties by mask, checking the validity
927 * of the arguments passed.
928 *
929 * @returns iprt status value
930 * @param cParms the number of HGCM parameters supplied
931 * @param paParms the array of HGCM parameters
932 * @thread HGCM
933 */
934int Service::enumProps(uint32_t cParms, VBOXHGCMSVCPARM paParms[])
935{
936 int rc = VINF_SUCCESS;
937
938 /*
939 * Get the HGCM function arguments.
940 */
941 char const *pchPatterns = NULL;
942 char *pchBuf = NULL;
943 uint32_t cbPatterns = 0;
944 uint32_t cbBuf = 0;
945 LogFlowThisFunc(("\n"));
946 if ( (cParms != 3) /* Hardcoded value as the next lines depend on it. */
947 || RT_FAILURE(HGCMSvcGetCStr(&paParms[0], &pchPatterns, &cbPatterns)) /* patterns */
948 || RT_FAILURE(HGCMSvcGetBuf(&paParms[1], (void **)&pchBuf, &cbBuf)) /* return buffer */
949 )
950 rc = VERR_INVALID_PARAMETER;
951 if (RT_SUCCESS(rc) && cbPatterns > GUEST_PROP_MAX_PATTERN_LEN)
952 rc = VERR_TOO_MUCH_DATA;
953
954 /*
955 * First repack the patterns into the format expected by RTStrSimplePatternMatch()
956 */
957 char szPatterns[GUEST_PROP_MAX_PATTERN_LEN];
958 if (RT_SUCCESS(rc))
959 {
960 for (unsigned i = 0; i < cbPatterns - 1; ++i)
961 if (pchPatterns[i] != '\0')
962 szPatterns[i] = pchPatterns[i];
963 else
964 szPatterns[i] = '|';
965 szPatterns[cbPatterns - 1] = '\0';
966 }
967
968 /*
969 * Next enumerate into the buffer.
970 */
971 if (RT_SUCCESS(rc))
972 {
973 ENUMDATA EnumData;
974 EnumData.pszPattern = szPatterns;
975 EnumData.pchCur = pchBuf;
976 EnumData.cbLeft = cbBuf;
977 EnumData.cbNeeded = 0;
978 rc = RTStrSpaceEnumerate(&mhProperties, enumPropsCallback, &EnumData);
979 AssertRCSuccess(rc);
980 if (RT_SUCCESS(rc))
981 {
982 HGCMSvcSetU32(&paParms[2], (uint32_t)(EnumData.cbNeeded + 4));
983 if (EnumData.cbLeft >= 4)
984 {
985 /* The final terminators. */
986 EnumData.pchCur[0] = '\0';
987 EnumData.pchCur[1] = '\0';
988 EnumData.pchCur[2] = '\0';
989 EnumData.pchCur[3] = '\0';
990 }
991 else
992 rc = VERR_BUFFER_OVERFLOW;
993 }
994 }
995
996 return rc;
997}
998
999
1000/** Helper query used by getOldNotification
1001 * @throws nothing
1002 */
1003int Service::getOldNotificationInternal(const char *pszPatterns, uint64_t nsTimestamp, Property *pProp)
1004{
1005 /* We count backwards, as the guest should normally be querying the
1006 * most recent events. */
1007 int rc = VWRN_NOT_FOUND;
1008 PropertyList::reverse_iterator it = mGuestNotifications.rbegin();
1009 for (; it != mGuestNotifications.rend(); ++it)
1010 if (it->mTimestamp == nsTimestamp)
1011 {
1012 rc = VINF_SUCCESS;
1013 break;
1014 }
1015
1016 /* Now look for an event matching the patterns supplied. The base()
1017 * member conveniently points to the following element. */
1018 PropertyList::iterator base = it.base();
1019 for (; base != mGuestNotifications.end(); ++base)
1020 if (base->Matches(pszPatterns))
1021 {
1022 try
1023 {
1024 *pProp = *base;
1025 }
1026 catch (std::bad_alloc &)
1027 {
1028 rc = VERR_NO_MEMORY;
1029 }
1030 return rc;
1031 }
1032 *pProp = Property();
1033 return rc;
1034}
1035
1036
1037/** Helper query used by getNotification */
1038int Service::getNotificationWriteOut(uint32_t cParms, VBOXHGCMSVCPARM paParms[], Property const &rProp, bool fWasDeleted)
1039{
1040 AssertReturn(cParms == 4, VERR_INVALID_PARAMETER); /* Basic sanity checking. */
1041
1042 /* Format the data to write to the buffer. */
1043 char *pchBuf;
1044 uint32_t cbBuf;
1045 int rc = HGCMSvcGetBuf(&paParms[2], (void **)&pchBuf, &cbBuf);
1046 if (RT_SUCCESS(rc))
1047 {
1048 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
1049 char szWasDeleted[2] = { fWasDeleted ? '1' : '0', '\0' };
1050
1051 rc = GuestPropWriteFlags(rProp.mFlags, szFlags);
1052 if (RT_SUCCESS(rc))
1053 {
1054 HGCMSvcSetU64(&paParms[1], rProp.mTimestamp);
1055
1056 size_t const cbFlags = strlen(szFlags) + 1;
1057 size_t const cbName = rProp.mName.length() + 1;
1058 size_t const cbValue = rProp.mValue.length() + 1;
1059 size_t const cbWasDeleted = strlen(szWasDeleted) + 1;
1060 size_t const cbNeeded = cbName + cbValue + cbFlags + cbWasDeleted;
1061 HGCMSvcSetU32(&paParms[3], (uint32_t)cbNeeded);
1062 if (cbNeeded <= cbBuf)
1063 {
1064 /* Buffer layout: Name\0Value\0Flags\0fWasDeleted\0. */
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 pchBuf += cbFlags;
1071 memcpy(pchBuf, szWasDeleted, cbWasDeleted);
1072 }
1073 else
1074 rc = VERR_BUFFER_OVERFLOW;
1075 }
1076 }
1077 return rc;
1078}
1079
1080
1081/**
1082 * Get the next guest notification.
1083 *
1084 * @returns iprt status value
1085 * @param u32ClientId the client ID
1086 * @param callHandle handle
1087 * @param cParms the number of HGCM parameters supplied
1088 * @param paParms the array of HGCM parameters
1089 * @thread HGCM
1090 * @throws nothing
1091 */
1092int Service::getNotification(uint32_t u32ClientId, VBOXHGCMCALLHANDLE callHandle,
1093 uint32_t cParms, VBOXHGCMSVCPARM paParms[])
1094{
1095 int rc = VINF_SUCCESS;
1096 char *pszPatterns = NULL; /* shut up gcc */
1097 char *pchBuf;
1098 uint32_t cchPatterns = 0;
1099 uint32_t cbBuf = 0;
1100 uint64_t nsTimestamp;
1101
1102 /*
1103 * Get the HGCM function arguments and perform basic verification.
1104 */
1105 LogFlowThisFunc(("\n"));
1106 if ( cParms != 4 /* Hardcoded value as the next lines depend on it. */
1107 || RT_FAILURE(HGCMSvcGetStr(&paParms[0], &pszPatterns, &cchPatterns)) /* patterns */
1108 || RT_FAILURE(HGCMSvcGetU64(&paParms[1], &nsTimestamp)) /* timestamp */
1109 || RT_FAILURE(HGCMSvcGetBuf(&paParms[2], (void **)&pchBuf, &cbBuf)) /* return buffer */
1110 )
1111 rc = VERR_INVALID_PARAMETER;
1112 else
1113 {
1114 LogFlow(("pszPatterns=%s, nsTimestamp=%llu\n", pszPatterns, nsTimestamp));
1115
1116 /*
1117 * If no timestamp was supplied or no notification was found in the queue
1118 * of old notifications, enqueue the request in the waiting queue.
1119 */
1120 Property prop;
1121 if (RT_SUCCESS(rc) && nsTimestamp != 0)
1122 rc = getOldNotification(pszPatterns, nsTimestamp, &prop);
1123 if (RT_SUCCESS(rc))
1124 {
1125 if (prop.isNull())
1126 {
1127 /*
1128 * Check if the client already had the same request.
1129 * Complete the old request with an error in this case.
1130 * Protection against clients, which cancel and resubmits requests.
1131 */
1132 uint32_t cPendingWaits = 0;
1133 CallList::iterator it = mGuestWaiters.begin();
1134 while (it != mGuestWaiters.end())
1135 {
1136 if (u32ClientId == it->u32ClientId)
1137 {
1138 const char *pszPatternsExisting;
1139 uint32_t cchPatternsExisting;
1140 int rc3 = HGCMSvcGetCStr(&it->mParms[0], &pszPatternsExisting, &cchPatternsExisting);
1141 if ( RT_SUCCESS(rc3)
1142 && RTStrCmp(pszPatterns, pszPatternsExisting) == 0)
1143 {
1144 /* Complete the old request. */
1145 mpHelpers->pfnCallComplete(it->mHandle, VERR_INTERRUPTED);
1146 it = mGuestWaiters.erase(it);
1147 }
1148 else if (mpHelpers->pfnIsCallCancelled(it->mHandle))
1149 {
1150 /* Cleanup cancelled request. */
1151 mpHelpers->pfnCallComplete(it->mHandle, VERR_INTERRUPTED);
1152 it = mGuestWaiters.erase(it);
1153 }
1154 else
1155 {
1156 /** @todo check if cancelled. */
1157 cPendingWaits++;
1158 ++it;
1159 }
1160 }
1161 else
1162 ++it;
1163 }
1164
1165 if (cPendingWaits < GUEST_PROP_MAX_GUEST_CONCURRENT_WAITS)
1166 {
1167 try
1168 {
1169 mGuestWaiters.push_back(GuestCall(u32ClientId, callHandle, GUEST_PROP_FN_GET_NOTIFICATION,
1170 cParms, paParms, rc));
1171 rc = VINF_HGCM_ASYNC_EXECUTE;
1172 }
1173 catch (std::bad_alloc &)
1174 {
1175 rc = VERR_NO_MEMORY;
1176 }
1177 }
1178 else
1179 {
1180 LogFunc(("Too many pending waits already!\n"));
1181 rc = VERR_OUT_OF_RESOURCES;
1182 }
1183 }
1184 /*
1185 * Otherwise reply at once with the enqueued notification we found.
1186 */
1187 else
1188 {
1189 int rc2 = getNotificationWriteOut(cParms, paParms, prop, !getPropertyInternal(prop.mName.c_str()));
1190 if (RT_FAILURE(rc2))
1191 rc = rc2;
1192 }
1193 }
1194 }
1195
1196 LogFlowThisFunc(("returning rc=%Rrc\n", rc));
1197 return rc;
1198}
1199
1200
1201/**
1202 * Notify the service owner and the guest that a property has been
1203 * added/deleted/changed
1204 *
1205 * @param pszProperty The name of the property which has changed.
1206 * @param nsTimestamp The time at which the change took place.
1207 * @throws nothing.
1208 * @thread HGCM service
1209 */
1210int Service::doNotifications(const char *pszProperty, uint64_t nsTimestamp)
1211{
1212 AssertPtrReturn(pszProperty, VERR_INVALID_POINTER);
1213 LogFlowThisFunc(("pszProperty=%s, nsTimestamp=%llu\n", pszProperty, nsTimestamp));
1214 /* Ensure that our timestamp is different to the last one. */
1215 if ( !mGuestNotifications.empty()
1216 && nsTimestamp == mGuestNotifications.back().mTimestamp)
1217 ++nsTimestamp;
1218
1219 /*
1220 * Don't keep too many changes around.
1221 */
1222 if (mGuestNotifications.size() >= GUEST_PROP_MAX_GUEST_NOTIFICATIONS)
1223 mGuestNotifications.pop_front();
1224
1225 /*
1226 * Try to find the property. Create a change event if we find it and a
1227 * delete event if we do not.
1228 */
1229 Property prop;
1230 int rc = prop.mName.assignNoThrow(pszProperty);
1231 AssertRCReturn(rc, rc);
1232 prop.mTimestamp = nsTimestamp;
1233 /* prop is currently a delete event for pszProperty */
1234 Property const * const pProp = getPropertyInternal(pszProperty);
1235 if (pProp)
1236 {
1237 /* Make prop into a change event. */
1238 rc = prop.mValue.assignNoThrow(pProp->mValue);
1239 AssertRCReturn(rc, rc);
1240 prop.mFlags = pProp->mFlags;
1241 }
1242
1243 /* Release guest waiters if applicable and add the event
1244 * to the queue for guest notifications */
1245 CallList::iterator it = mGuestWaiters.begin();
1246 if (it != mGuestWaiters.end())
1247 {
1248 const char *pszPatterns = NULL;
1249 uint32_t cchPatterns;
1250 HGCMSvcGetCStr(&it->mParms[0], &pszPatterns, &cchPatterns);
1251
1252 while (it != mGuestWaiters.end())
1253 {
1254 if (prop.Matches(pszPatterns))
1255 {
1256 int rc2 = getNotificationWriteOut(it->mParmsCnt, it->mParms, prop, !pProp);
1257 if (RT_SUCCESS(rc2))
1258 rc2 = it->mRc;
1259 mpHelpers->pfnCallComplete(it->mHandle, rc2);
1260 it = mGuestWaiters.erase(it);
1261 }
1262 else
1263 ++it;
1264 }
1265 }
1266
1267 try
1268 {
1269 mGuestNotifications.push_back(prop);
1270 }
1271 catch (std::bad_alloc &)
1272 {
1273 rc = VERR_NO_MEMORY;
1274 }
1275
1276 if ( RT_SUCCESS(rc)
1277 && mpfnHostCallback)
1278 {
1279 /*
1280 * Host notifications - first case: if the property exists then send its
1281 * current value
1282 */
1283 if (pProp)
1284 {
1285 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
1286 /* Send out a host notification */
1287 const char *pszValue = prop.mValue.c_str();
1288 rc = GuestPropWriteFlags(prop.mFlags, szFlags);
1289 if (RT_SUCCESS(rc))
1290 rc = notifyHost(pszProperty, pszValue, nsTimestamp, szFlags);
1291 }
1292 /*
1293 * Host notifications - second case: if the property does not exist then
1294 * send the host an empty value
1295 */
1296 else
1297 {
1298 /* Send out a host notification */
1299 rc = notifyHost(pszProperty, NULL, nsTimestamp, "");
1300 }
1301 }
1302
1303 LogFlowThisFunc(("returning rc=%Rrc\n", rc));
1304 return rc;
1305}
1306
1307static DECLCALLBACK(void)
1308notifyHostAsyncWorker(PFNHGCMSVCEXT pfnHostCallback, void *pvHostData, PGUESTPROPHOSTCALLBACKDATA pHostCallbackData)
1309{
1310 pfnHostCallback(pvHostData, 0 /*u32Function*/, (void *)pHostCallbackData, sizeof(GUESTPROPHOSTCALLBACKDATA));
1311 RTMemFree(pHostCallbackData);
1312}
1313
1314/**
1315 * Notify the service owner that a property has been added/deleted/changed.
1316 * @returns IPRT status value
1317 * @param pszName the property name
1318 * @param pszValue the new value, or NULL if the property was deleted
1319 * @param nsTimestamp the time of the change
1320 * @param pszFlags the new flags string
1321 */
1322int Service::notifyHost(const char *pszName, const char *pszValue, uint64_t nsTimestamp, const char *pszFlags)
1323{
1324 LogFlowFunc(("pszName=%s, pszValue=%s, nsTimestamp=%llu, pszFlags=%s\n", pszName, pszValue, nsTimestamp, pszFlags));
1325 int rc;
1326
1327 /* Allocate buffer for the callback data and strings. */
1328 size_t cbName = pszName? strlen(pszName): 0;
1329 size_t cbValue = pszValue? strlen(pszValue): 0;
1330 size_t cbFlags = pszFlags? strlen(pszFlags): 0;
1331 size_t cbAlloc = sizeof(GUESTPROPHOSTCALLBACKDATA) + cbName + cbValue + cbFlags + 3;
1332 PGUESTPROPHOSTCALLBACKDATA pHostCallbackData = (PGUESTPROPHOSTCALLBACKDATA)RTMemAlloc(cbAlloc);
1333 if (pHostCallbackData)
1334 {
1335 uint8_t *pu8 = (uint8_t *)pHostCallbackData;
1336 pu8 += sizeof(GUESTPROPHOSTCALLBACKDATA);
1337
1338 pHostCallbackData->u32Magic = GUESTPROPHOSTCALLBACKDATA_MAGIC;
1339
1340 pHostCallbackData->pcszName = (const char *)pu8;
1341 memcpy(pu8, pszName, cbName);
1342 pu8 += cbName;
1343 *pu8++ = 0;
1344
1345 /* NULL value means property was deleted. */
1346 pHostCallbackData->pcszValue = pszValue ? (const char *)pu8 : NULL;
1347 memcpy(pu8, pszValue, cbValue);
1348 pu8 += cbValue;
1349 *pu8++ = 0;
1350
1351 pHostCallbackData->u64Timestamp = nsTimestamp;
1352
1353 pHostCallbackData->pcszFlags = (const char *)pu8;
1354 memcpy(pu8, pszFlags, cbFlags);
1355 pu8 += cbFlags;
1356 *pu8++ = 0;
1357
1358 rc = RTReqQueueCallEx(mhReqQNotifyHost, NULL, 0, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
1359 (PFNRT)notifyHostAsyncWorker, 3,
1360 mpfnHostCallback, mpvHostData, pHostCallbackData);
1361 if (RT_FAILURE(rc))
1362 {
1363 RTMemFree(pHostCallbackData);
1364 }
1365 }
1366 else
1367 {
1368 rc = VERR_NO_MEMORY;
1369 }
1370 LogFlowFunc(("returning rc=%Rrc\n", rc));
1371 return rc;
1372}
1373
1374
1375/**
1376 * Handle an HGCM service call.
1377 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnCall}
1378 * @note All functions which do not involve an unreasonable delay will be
1379 * handled synchronously. If needed, we will add a request handler
1380 * thread in future for those which do.
1381 *
1382 * @thread HGCM
1383 */
1384void Service::call (VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID,
1385 void * /* pvClient */, uint32_t eFunction, uint32_t cParms,
1386 VBOXHGCMSVCPARM paParms[])
1387{
1388 int rc;
1389 LogFlowFunc(("u32ClientID = %d, fn = %d, cParms = %d, pparms = %p\n",
1390 u32ClientID, eFunction, cParms, paParms));
1391
1392 switch (eFunction)
1393 {
1394 /* The guest wishes to read a property */
1395 case GUEST_PROP_FN_GET_PROP:
1396 LogFlowFunc(("GET_PROP\n"));
1397 rc = getProperty(cParms, paParms);
1398 break;
1399
1400 /* The guest wishes to set a property */
1401 case GUEST_PROP_FN_SET_PROP:
1402 LogFlowFunc(("SET_PROP\n"));
1403 rc = setProperty(cParms, paParms, true);
1404 break;
1405
1406 /* The guest wishes to set a property value */
1407 case GUEST_PROP_FN_SET_PROP_VALUE:
1408 LogFlowFunc(("SET_PROP_VALUE\n"));
1409 rc = setProperty(cParms, paParms, true);
1410 break;
1411
1412 /* The guest wishes to remove a configuration value */
1413 case GUEST_PROP_FN_DEL_PROP:
1414 LogFlowFunc(("DEL_PROP\n"));
1415 rc = delProperty(cParms, paParms, true);
1416 break;
1417
1418 /* The guest wishes to enumerate all properties */
1419 case GUEST_PROP_FN_ENUM_PROPS:
1420 LogFlowFunc(("ENUM_PROPS\n"));
1421 rc = enumProps(cParms, paParms);
1422 break;
1423
1424 /* The guest wishes to get the next property notification */
1425 case GUEST_PROP_FN_GET_NOTIFICATION:
1426 LogFlowFunc(("GET_NOTIFICATION\n"));
1427 rc = getNotification(u32ClientID, callHandle, cParms, paParms);
1428 break;
1429
1430 default:
1431 rc = VERR_NOT_IMPLEMENTED;
1432 }
1433 LogFlowFunc(("rc = %Rrc\n", rc));
1434 if (rc != VINF_HGCM_ASYNC_EXECUTE)
1435 mpHelpers->pfnCallComplete(callHandle, rc);
1436}
1437
1438/**
1439 * Enumeration data shared between dbgInfoCallback and Service::dbgInfoShow.
1440 */
1441typedef struct ENUMDBGINFO
1442{
1443 PCDBGFINFOHLP pHlp;
1444} ENUMDBGINFO;
1445
1446static DECLCALLBACK(int) dbgInfoCallback(PRTSTRSPACECORE pStr, void *pvUser)
1447{
1448 Property *pProp = (Property *)pStr;
1449 PCDBGFINFOHLP pHlp = ((ENUMDBGINFO *)pvUser)->pHlp;
1450
1451 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
1452 int rc = GuestPropWriteFlags(pProp->mFlags, szFlags);
1453 if (RT_FAILURE(rc))
1454 RTStrPrintf(szFlags, sizeof(szFlags), "???");
1455
1456 pHlp->pfnPrintf(pHlp, "%s: '%s', %RU64", pProp->mName.c_str(), pProp->mValue.c_str(), pProp->mTimestamp);
1457 if (strlen(szFlags))
1458 pHlp->pfnPrintf(pHlp, " (%s)", szFlags);
1459 pHlp->pfnPrintf(pHlp, "\n");
1460 return 0;
1461}
1462
1463
1464/**
1465 * Handler for debug info.
1466 *
1467 * @param pvUser user pointer.
1468 * @param pHlp The info helper functions.
1469 * @param pszArgs Arguments, ignored.
1470 */
1471DECLCALLBACK(void) Service::dbgInfo(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs)
1472{
1473 RT_NOREF1(pszArgs);
1474 SELF *pSelf = reinterpret_cast<SELF *>(pvUser);
1475
1476 ENUMDBGINFO EnumData = { pHlp };
1477 RTStrSpaceEnumerate(&pSelf->mhProperties, dbgInfoCallback, &EnumData);
1478}
1479
1480
1481/**
1482 * Service call handler for the host.
1483 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnHostCall}
1484 * @thread hgcm
1485 */
1486int Service::hostCall (uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
1487{
1488 int rc;
1489 LogFlowFunc(("fn = %d, cParms = %d, pparms = %p\n", eFunction, cParms, paParms));
1490
1491 switch (eFunction)
1492 {
1493 /* The host wishes to set a block of properties */
1494 case GUEST_PROP_FN_HOST_SET_PROPS:
1495 LogFlowFunc(("SET_PROPS_HOST\n"));
1496 rc = setPropertyBlock(cParms, paParms);
1497 break;
1498
1499 /* The host wishes to read a configuration value */
1500 case GUEST_PROP_FN_HOST_GET_PROP:
1501 LogFlowFunc(("GET_PROP_HOST\n"));
1502 rc = getProperty(cParms, paParms);
1503 break;
1504
1505 /* The host wishes to set a configuration value */
1506 case GUEST_PROP_FN_HOST_SET_PROP:
1507 LogFlowFunc(("SET_PROP_HOST\n"));
1508 rc = setProperty(cParms, paParms, false);
1509 break;
1510
1511 /* The host wishes to set a configuration value */
1512 case GUEST_PROP_FN_HOST_SET_PROP_VALUE:
1513 LogFlowFunc(("SET_PROP_VALUE_HOST\n"));
1514 rc = setProperty(cParms, paParms, false);
1515 break;
1516
1517 /* The host wishes to remove a configuration value */
1518 case GUEST_PROP_FN_HOST_DEL_PROP:
1519 LogFlowFunc(("DEL_PROP_HOST\n"));
1520 rc = delProperty(cParms, paParms, false);
1521 break;
1522
1523 /* The host wishes to enumerate all properties */
1524 case GUEST_PROP_FN_HOST_ENUM_PROPS:
1525 LogFlowFunc(("ENUM_PROPS\n"));
1526 rc = enumProps(cParms, paParms);
1527 break;
1528
1529 /* The host wishes to set global flags for the service */
1530 case GUEST_PROP_FN_HOST_SET_GLOBAL_FLAGS:
1531 LogFlowFunc(("SET_GLOBAL_FLAGS_HOST\n"));
1532 if (cParms == 1)
1533 {
1534 uint32_t fFlags;
1535 rc = HGCMSvcGetU32(&paParms[0], &fFlags);
1536 if (RT_SUCCESS(rc))
1537 mfGlobalFlags = fFlags;
1538 }
1539 else
1540 rc = VERR_INVALID_PARAMETER;
1541 break;
1542
1543 default:
1544 rc = VERR_NOT_SUPPORTED;
1545 break;
1546 }
1547
1548 LogFlowFunc(("rc = %Rrc\n", rc));
1549 return rc;
1550}
1551
1552/**
1553 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnDisconnect}
1554 */
1555/*static*/ DECLCALLBACK(int) Service::svcDisconnect(void *pvService, uint32_t idClient, void *pvClient)
1556{
1557 RT_NOREF(pvClient);
1558 LogFlowFunc(("idClient=%u\n", idClient));
1559 SELF *pThis = reinterpret_cast<SELF *>(pvService);
1560 AssertLogRelReturn(pThis, VERR_INVALID_POINTER);
1561
1562 /*
1563 * Complete all pending requests for this client.
1564 */
1565 for (CallList::iterator It = pThis->mGuestWaiters.begin(); It != pThis->mGuestWaiters.end();)
1566 {
1567 GuestCall &rCurCall = *It;
1568 if (rCurCall.u32ClientId != idClient)
1569 ++It;
1570 else
1571 {
1572 LogFlowFunc(("Completing call %u (%p)...\n", rCurCall.mFunction, rCurCall.mHandle));
1573 pThis->mpHelpers->pfnCallComplete(rCurCall.mHandle, VERR_INTERRUPTED);
1574 It = pThis->mGuestWaiters.erase(It);
1575 }
1576 }
1577
1578 return VINF_SUCCESS;
1579}
1580
1581/**
1582 * Increments a counter property.
1583 *
1584 * It is assumed that this a transient property that is read-only to the guest.
1585 *
1586 * @param pszName The property name.
1587 * @throws std::bad_alloc if an out of memory condition occurs
1588 */
1589void Service::incrementCounterProp(const char *pszName)
1590{
1591 /* Format the incremented value. */
1592 char szValue[64];
1593 Property *pProp = getPropertyInternal(pszName);
1594 if (pProp)
1595 {
1596 uint64_t uValue = RTStrToUInt64(pProp->mValue.c_str());
1597 RTStrFormatU64(szValue, sizeof(szValue), uValue + 1, 10, 0, 0, 0);
1598 }
1599 else
1600 {
1601 szValue[0] = '1';
1602 szValue[1] = '\0';
1603 }
1604
1605 /* Set it. */
1606 setPropertyInternal(pszName, szValue, GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, getCurrentTimestamp());
1607}
1608
1609/**
1610 * Sets the VBoxVer, VBoxVerExt and VBoxRev properties.
1611 */
1612int Service::setHostVersionProps()
1613{
1614 uint64_t nsTimestamp = getCurrentTimestamp();
1615
1616 /* Set the raw VBox version string as a guest property. Used for host/guest
1617 * version comparison. */
1618 int rc = setPropertyInternal("/VirtualBox/HostInfo/VBoxVer", VBOX_VERSION_STRING_RAW,
1619 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp);
1620 AssertRCReturn(rc, rc);
1621
1622 /* Set the full VBox version string as a guest property. Can contain vendor-specific
1623 * information/branding and/or pre-release tags. */
1624 rc = setPropertyInternal("/VirtualBox/HostInfo/VBoxVerExt", VBOX_VERSION_STRING,
1625 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp + 1);
1626 AssertRCReturn(rc, rc);
1627
1628 /* Set the VBox SVN revision as a guest property */
1629 rc = setPropertyInternal("/VirtualBox/HostInfo/VBoxRev", RTBldCfgRevisionStr(),
1630 GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsTimestamp + 2);
1631 AssertRCReturn(rc, rc);
1632 return VINF_SUCCESS;
1633}
1634
1635
1636/**
1637 * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnNotify}
1638 */
1639/*static*/ DECLCALLBACK(void) Service::svcNotify(void *pvService, HGCMNOTIFYEVENT enmEvent)
1640{
1641 SELF *pThis = reinterpret_cast<SELF *>(pvService);
1642 AssertPtrReturnVoid(pThis);
1643
1644 /* Make sure the host version properties have been touched and are
1645 up-to-date after a restore: */
1646 if ( !pThis->m_fSetHostVersionProps
1647 && (enmEvent == HGCMNOTIFYEVENT_RESUME || enmEvent == HGCMNOTIFYEVENT_POWER_ON))
1648 {
1649 pThis->setHostVersionProps();
1650 pThis->m_fSetHostVersionProps = true;
1651 }
1652
1653 if (enmEvent == HGCMNOTIFYEVENT_RESUME)
1654 pThis->incrementCounterProp("/VirtualBox/VMInfo/ResumeCounter");
1655
1656 if (enmEvent == HGCMNOTIFYEVENT_RESET)
1657 pThis->incrementCounterProp("/VirtualBox/VMInfo/ResetCounter");
1658}
1659
1660
1661/* static */
1662DECLCALLBACK(int) Service::threadNotifyHost(RTTHREAD hThreadSelf, void *pvUser)
1663{
1664 RT_NOREF1(hThreadSelf);
1665 Service *pThis = (Service *)pvUser;
1666 int rc = VINF_SUCCESS;
1667
1668 LogFlowFunc(("ENTER: %p\n", pThis));
1669
1670 for (;;)
1671 {
1672 rc = RTReqQueueProcess(pThis->mhReqQNotifyHost, RT_INDEFINITE_WAIT);
1673
1674 AssertMsg(rc == VWRN_STATE_CHANGED,
1675 ("Left RTReqProcess and error code is not VWRN_STATE_CHANGED rc=%Rrc\n",
1676 rc));
1677 if (rc == VWRN_STATE_CHANGED)
1678 {
1679 break;
1680 }
1681 }
1682
1683 LogFlowFunc(("LEAVE: %Rrc\n", rc));
1684 return rc;
1685}
1686
1687static DECLCALLBACK(int) wakeupNotifyHost(void)
1688{
1689 /* Returning a VWRN_* will cause RTReqQueueProcess return. */
1690 return VWRN_STATE_CHANGED;
1691}
1692
1693
1694int Service::initialize()
1695{
1696 /*
1697 * Insert standard host properties.
1698 */
1699 /* The host version will but updated again on power on or resume
1700 (after restore), however we need the properties now for restored
1701 guest notification/wait calls. */
1702 int rc = setHostVersionProps();
1703 AssertRCReturn(rc, rc);
1704
1705 /* Sysprep execution by VBoxService (host is allowed to change these). */
1706 uint64_t nsNow = getCurrentTimestamp();
1707 rc = setPropertyInternal("/VirtualBox/HostGuest/SysprepExec", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1708 AssertRCReturn(rc, rc);
1709 rc = setPropertyInternal("/VirtualBox/HostGuest/SysprepArgs", "", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1710 AssertRCReturn(rc, rc);
1711
1712 /* Resume and reset counters. */
1713 rc = setPropertyInternal("/VirtualBox/VMInfo/ResumeCounter", "0", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1714 AssertRCReturn(rc, rc);
1715 rc = setPropertyInternal("/VirtualBox/VMInfo/ResetCounter", "0", GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_RDONLYGUEST, nsNow);
1716 AssertRCReturn(rc, rc);
1717
1718 /* The host notification thread and queue. */
1719 rc = RTReqQueueCreate(&mhReqQNotifyHost);
1720 if (RT_SUCCESS(rc))
1721 {
1722 rc = RTThreadCreate(&mhThreadNotifyHost,
1723 threadNotifyHost,
1724 this,
1725 0 /* default stack size */,
1726 RTTHREADTYPE_DEFAULT,
1727 RTTHREADFLAGS_WAITABLE,
1728 "GstPropNtfy");
1729 if (RT_SUCCESS(rc))
1730 {
1731 /* Finally debug stuff (ignore failures): */
1732 HGCMSvcHlpInfoRegister(mpHelpers, "guestprops", "Display the guest properties", Service::dbgInfo, this);
1733 return rc;
1734 }
1735
1736 RTReqQueueDestroy(mhReqQNotifyHost);
1737 mhReqQNotifyHost = NIL_RTREQQUEUE;
1738 }
1739 return rc;
1740}
1741
1742/**
1743 * @callback_method_impl{FNRTSTRSPACECALLBACK, Destroys Property.}
1744 */
1745static DECLCALLBACK(int) destroyProperty(PRTSTRSPACECORE pStr, void *pvUser)
1746{
1747 RT_NOREF(pvUser);
1748 Property *pProp = RT_FROM_CPP_MEMBER(pStr, struct Property, mStrCore); /* clang objects to offsetof on non-POD.*/
1749 delete pProp;
1750 return 0;
1751}
1752
1753
1754int Service::uninit()
1755{
1756 if (mpHelpers)
1757 HGCMSvcHlpInfoDeregister(mpHelpers, "guestprops");
1758
1759 if (mhReqQNotifyHost != NIL_RTREQQUEUE)
1760 {
1761 /* Stop the thread */
1762 PRTREQ pReq;
1763 int rc = RTReqQueueCall(mhReqQNotifyHost, &pReq, 10000, (PFNRT)wakeupNotifyHost, 0);
1764 if (RT_SUCCESS(rc))
1765 RTReqRelease(pReq);
1766 rc = RTThreadWait(mhThreadNotifyHost, 10000, NULL);
1767 AssertRC(rc);
1768 rc = RTReqQueueDestroy(mhReqQNotifyHost);
1769 AssertRC(rc);
1770 mhReqQNotifyHost = NIL_RTREQQUEUE;
1771 mhThreadNotifyHost = NIL_RTTHREAD;
1772 RTStrSpaceDestroy(&mhProperties, destroyProperty, NULL);
1773 mhProperties = NULL;
1774 }
1775 return VINF_SUCCESS;
1776}
1777
1778} /* namespace guestProp */
1779
1780using guestProp::Service;
1781
1782/**
1783 * @copydoc FNVBOXHGCMSVCLOAD
1784 */
1785extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad(VBOXHGCMSVCFNTABLE *ptable)
1786{
1787 int rc = VERR_IPE_UNINITIALIZED_STATUS;
1788
1789 LogFlowFunc(("ptable = %p\n", ptable));
1790
1791 if (!RT_VALID_PTR(ptable))
1792 rc = VERR_INVALID_PARAMETER;
1793 else
1794 {
1795 LogFlowFunc(("ptable->cbSize = %d, ptable->u32Version = 0x%08X\n", ptable->cbSize, ptable->u32Version));
1796
1797 if ( ptable->cbSize != sizeof(VBOXHGCMSVCFNTABLE)
1798 || ptable->u32Version != VBOX_HGCM_SVC_VERSION)
1799 rc = VERR_VERSION_MISMATCH;
1800 else
1801 {
1802 Service *pService = NULL;
1803 /* No exceptions may propagate outside. */
1804 try
1805 {
1806 pService = new Service(ptable->pHelpers);
1807 rc = VINF_SUCCESS;
1808 }
1809 catch (int rcThrown)
1810 {
1811 rc = rcThrown;
1812 }
1813 catch (...)
1814 {
1815 rc = VERR_UNEXPECTED_EXCEPTION;
1816 }
1817
1818 if (RT_SUCCESS(rc))
1819 {
1820 /* We do not maintain connections, so no client data is needed. */
1821 ptable->cbClient = 0;
1822
1823 /* Legacy clients map to the kernel category. */
1824 ptable->idxLegacyClientCategory = HGCM_CLIENT_CATEGORY_KERNEL;
1825
1826 /* Go with default client limits, but we won't ever need more than
1827 16 pending calls per client I would think (1 should be enough). */
1828 for (uintptr_t i = 0; i < RT_ELEMENTS(ptable->acMaxClients); i++)
1829 ptable->acMaxCallsPerClient[i] = 16;
1830
1831 ptable->pfnUnload = Service::svcUnload;
1832 ptable->pfnConnect = Service::svcConnect;
1833 ptable->pfnDisconnect = Service::svcDisconnect;
1834 ptable->pfnCall = Service::svcCall;
1835 ptable->pfnHostCall = Service::svcHostCall;
1836 ptable->pfnSaveState = NULL; /* The service is stateless, so the normal */
1837 ptable->pfnLoadState = NULL; /* construction done before restoring suffices */
1838 ptable->pfnRegisterExtension = Service::svcRegisterExtension;
1839 ptable->pfnNotify = Service::svcNotify;
1840 ptable->pvService = pService;
1841
1842 /* Service specific initialization. */
1843 rc = pService->initialize();
1844 if (RT_FAILURE(rc))
1845 {
1846 delete pService;
1847 pService = NULL;
1848 }
1849 }
1850 else
1851 Assert(!pService);
1852 }
1853 }
1854
1855 LogFlowFunc(("returning %Rrc\n", rc));
1856 return rc;
1857}
1858
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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