Here's a patch that adds an extension pack helper callback that can be
used to load an HGCM service. The patch is against the 4.2.16 OSE source
download. With this patch I was able to load an HGCM service from an
extension pack module and communicate with it from a guest.

Jeff Westfahl
diff --git a/include/VBox/ExtPack/ExtPack.h b/include/VBox/ExtPack/ExtPack.h
index 4e03b38..4f84256 100755
--- a/include/VBox/ExtPack/ExtPack.h
+++ b/include/VBox/ExtPack/ExtPack.h
@@ -149,6 +149,9 @@ typedef struct VBOXEXTPACKHLP
      */
     DECLR3CALLBACKMEMBER(VBOXEXTPACKCTX, pfnGetContext,(PCVBOXEXTPACKHLP pHlp));
 
+    DECLR3CALLBACKMEMBER(int, pfnLoadHGCMService,(PCVBOXEXTPACKHLP pHlp, VBOXEXTPACK_IF_CS(IConsole) *pConsole,
+                                                  const char *pszServiceLibrary, const char *pszServiceName));
+
     DECLR3CALLBACKMEMBER(int, pfnReserved1,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
     DECLR3CALLBACKMEMBER(int, pfnReserved2,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
     DECLR3CALLBACKMEMBER(int, pfnReserved3,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
@@ -157,13 +160,12 @@ typedef struct VBOXEXTPACKHLP
     DECLR3CALLBACKMEMBER(int, pfnReserved6,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
     DECLR3CALLBACKMEMBER(int, pfnReserved7,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
     DECLR3CALLBACKMEMBER(int, pfnReserved8,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
-    DECLR3CALLBACKMEMBER(int, pfnReserved9,(PCVBOXEXTPACKHLP pHlp)); /**< Reserved for minor structure revisions. */
 
     /** End of structure marker (VBOXEXTPACKHLP_VERSION). */
     uint32_t                    u32EndMarker;
 } VBOXEXTPACKHLP;
 /** Current version of the VBOXEXTPACKHLP structure.  */
-#define VBOXEXTPACKHLP_VERSION          RT_MAKE_U32(0, 1)
+#define VBOXEXTPACKHLP_VERSION          RT_MAKE_U32(1, 1)
 
 
 /** Pointer to the extension pack callback table. */
diff --git a/src/VBox/Main/include/ExtPackManagerImpl.h b/src/VBox/Main/include/ExtPackManagerImpl.h
index 6d8a798..4106986 100755
--- a/src/VBox/Main/include/ExtPackManagerImpl.h
+++ b/src/VBox/Main/include/ExtPackManagerImpl.h
@@ -165,6 +165,8 @@ protected:
                                               VBOXEXTPACKMODKIND enmKind, char *pszFound, size_t cbFound, bool *pfNative);
     static DECLCALLBACK(int)    hlpGetFilePath(PCVBOXEXTPACKHLP pHlp, const char *pszFilename, char *pszPath, size_t cbPath);
     static DECLCALLBACK(VBOXEXTPACKCTX) hlpGetContext(PCVBOXEXTPACKHLP pHlp);
+    static DECLCALLBACK(int)    hlpLoadHGCMService(PCVBOXEXTPACKHLP pHlp, IConsole *a_pConsole,
+                                                   const char *pszServiceLibrary, const char *pszServiceName);
     static DECLCALLBACK(int)    hlpReservedN(PCVBOXEXTPACKHLP pHlp);
     /** @}  */
 
diff --git a/src/VBox/Main/src-all/ExtPackManagerImpl.cpp b/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
index 68e56b6..1197439 100755
--- a/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
+++ b/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
@@ -42,10 +42,12 @@
 #include <VBox/sup.h>
 #include <VBox/version.h>
 #include "AutoCaller.h"
+#include "ConsoleImpl.h"
 #include "Global.h"
 #include "ProgressImpl.h"
 #include "SystemPropertiesImpl.h"
 #include "VirtualBoxImpl.h"
+#include "VMMDev.h"
 
 
 /*******************************************************************************
@@ -749,6 +751,7 @@ HRESULT ExtPack::initWithDir(VBOXEXTPACKCTX a_enmContext, const char *a_pszName,
         /* pfnFindModule        = */ ExtPack::hlpFindModule,
         /* pfnGetFilePath       = */ ExtPack::hlpGetFilePath,
         /* pfnGetContext        = */ ExtPack::hlpGetContext,
+        /* pfnLoadHGCMService   = */ ExtPack::hlpLoadHGCMService,
         /* pfnReserved1         = */ ExtPack::hlpReservedN,
         /* pfnReserved2         = */ ExtPack::hlpReservedN,
         /* pfnReserved3         = */ ExtPack::hlpReservedN,
@@ -757,7 +760,6 @@ HRESULT ExtPack::initWithDir(VBOXEXTPACKCTX a_enmContext, const char *a_pszName,
         /* pfnReserved6         = */ ExtPack::hlpReservedN,
         /* pfnReserved7         = */ ExtPack::hlpReservedN,
         /* pfnReserved8         = */ ExtPack::hlpReservedN,
-        /* pfnReserved9         = */ ExtPack::hlpReservedN,
         /* u32EndMarker         = */ VBOXEXTPACKHLP_VERSION
     };
 
@@ -1572,6 +1574,41 @@ ExtPack::hlpGetContext(PCVBOXEXTPACKHLP pHlp)
 }
 
 /*static*/ DECLCALLBACK(int)
+ExtPack::hlpLoadHGCMService(PCVBOXEXTPACKHLP pHlp, IConsole *a_pConsole,
+                            const char *pszServiceLibrary, const char *pszServiceName)
+{
+/* JMW: Not sure if using this macro here is correct or appropriate. It gets
+   the job done, allowing both VBoxC and VBoxSVC to build. */
+#ifdef VBOX_COM_INPROC
+    /*
+     * Validate the input and get our bearings.
+     */
+    AssertPtrReturn(pszServiceLibrary, VERR_INVALID_POINTER);
+    AssertPtrReturn(pszServiceName, VERR_INVALID_POINTER);
+
+    AssertPtrReturn(pHlp, VERR_INVALID_POINTER);
+    AssertReturn(pHlp->u32Version == VBOXEXTPACKHLP_VERSION, VERR_INVALID_POINTER);
+    ExtPack::Data *m = RT_FROM_CPP_MEMBER(pHlp, Data, Hlp);
+    AssertPtrReturn(m, VERR_INVALID_POINTER);
+    ExtPack *pThis = m->pThis;
+    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
+
+    /* JMW: Maybe there's a different recommended way to do this cast? I
+       couldn't find any examples. static_cast also works, of course. */
+    Console *pConsole = dynamic_cast <Console *>(a_pConsole);
+    if (pConsole)
+    {
+        VMMDev *pVMMDev = pConsole->getVMMDev();
+        if (pVMMDev)
+        {
+            return pVMMDev->hgcmLoadService(pszServiceLibrary, pszServiceName);
+        }
+    }
+#endif
+    return VERR_INVALID_STATE;
+}
+
+/*static*/ DECLCALLBACK(int)
 ExtPack::hlpReservedN(PCVBOXEXTPACKHLP pHlp)
 {
     /*
diff --git a/src/VBox/Main/src-client/HGCM.cpp b/src/VBox/Main/src-client/HGCM.cpp
index 5decb29..83c14e1 100755
--- a/src/VBox/Main/src-client/HGCM.cpp
+++ b/src/VBox/Main/src-client/HGCM.cpp
@@ -18,6 +18,7 @@
 #define LOG_GROUP_MAIN_OVERRIDE LOG_GROUP_HGCM
 #include "Logging.h"
 
+#include "ExtPackUtil.h"
 #include "HGCM.h"
 #include "HGCMThread.h"
 
@@ -266,7 +267,33 @@ int HGCMService::loadServiceDLL (void)
     RTERRINFOSTATIC ErrInfo;
     RTErrInfoInitStatic (&ErrInfo);
 
-    int rc = SUPR3HardenedLdrLoadAppPriv (m_pszSvcLibrary, &m_hLdrMod, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
+    int rc;
+
+    /* JMW: Not sure if this is the best way to allow something other than a
+       core component. Not sure what is being hardened here, and if this change
+       might break it somehow. */
+    if (!RTPathHasPath(m_pszSvcLibrary))
+    {
+        rc = SUPR3HardenedLdrLoadAppPriv (m_pszSvcLibrary, &m_hLdrMod, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
+    }
+    else
+    {
+        /* Allow an extension pack to load an HGCM service. */
+        char szBaseDir[RTPATH_MAX];
+        rc = RTPathAppPrivateArchTop(szBaseDir, sizeof(szBaseDir));
+        AssertLogRelRCReturn(rc, rc);
+        rc = RTPathAppend(szBaseDir, sizeof(szBaseDir), VBOX_EXTPACK_INSTALL_DIR);
+        AssertLogRelRCReturn(rc, rc);
+
+        if (RTPathStartsWith(m_pszSvcLibrary, szBaseDir))
+        {
+            rc = SUPR3HardenedLdrLoad (m_pszSvcLibrary, &m_hLdrMod, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
+        }
+        else
+        {
+            rc = VERR_INVALID_PARAMETER;
+        }
+    }
 
     if (RT_SUCCESS(rc))
     {
_______________________________________________
vbox-dev mailing list
[email protected]
https://www.virtualbox.org/mailman/listinfo/vbox-dev

Reply via email to