Index: /trunk/include/VBox/VBoxVideo3D.h
===================================================================
--- /trunk/include/VBox/VBoxVideo3D.h	(revision 42517)
+++ /trunk/include/VBox/VBoxVideo3D.h	(revision 42518)
@@ -111,4 +111,14 @@
 #define VBoxTlsRefGetCurrent(_t, _Tsd) ((_t*) VBoxTlsRefGetImpl((_Tsd)))
 
+#define VBoxTlsRefGetCurrentFunctional(_val, _t, _Tsd) do { \
+       _t * cur = VBoxTlsRefGetCurrent(_t, _Tsd); \
+       if (!cur || VBoxTlsRefIsFunctional(cur)) { \
+           (_val) = cur; \
+       } else { \
+           VBoxTlsRefSetCurrent(_t, _Tsd, NULL); \
+           (_val) = NULL; \
+       } \
+   } while (0)
+
 #define VBoxTlsRefSetCurrent(_t, _Tsd, _p) do { \
         _t * oldCur = VBoxTlsRefGetCurrent(_t, _Tsd); \
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 42517)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3D.cpp	(revision 42518)
@@ -6621,11 +6621,9 @@
     if (VBOXDISPMODE_IS_3D(pAdapter))
     {
-//    Assert(!pDevice->cScreens);
-        /* destroy the device first, since destroying PVBOXWDDMDISP_SWAPCHAIN would result in a device window termination */
+        vboxWddmSwapchainDestroyAll(pDevice);
+        /* ensure the device is destroyed in any way.
+         * Release may not work in case of some leaking, which will leave the crOgl context refering the destroyed VBOXUHGSMI */
         if (pDevice->pDevice9If)
-        {
-            pDevice->pDevice9If->Release();
-        }
-        vboxWddmSwapchainDestroyAll(pDevice);
+            pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9Term((IDirect3DDevice9Ex *)pDevice->pDevice9If);
     }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 42517)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.cpp	(revision 42518)
@@ -80,4 +80,11 @@
         }
 
+        pD3D->pfnVBoxWineExD3DDev9Term = (PFNVBOXWINEEXD3DDEV9_TERM)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9Term");
+        if (!pD3D->pfnVBoxWineExD3DDev9Term)
+        {
+            WARN(("no VBoxWineExD3DDev9Term"));
+            break;
+        }
+
         pD3D->pfnVBoxWineExD3DRc9SetShRcState = (PFNVBOXWINEEXD3DRC9_SETSHRCSTATE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DRc9SetShRcState");
         if (!pD3D->pfnVBoxWineExD3DRc9SetShRcState)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h	(revision 42517)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DIf.h	(revision 42518)
@@ -63,4 +63,6 @@
     PFNVBOXWINEEXD3DDEV9_UPDATE pfnVBoxWineExD3DDev9Update;
 
+    PFNVBOXWINEEXD3DDEV9_TERM pfnVBoxWineExD3DDev9Term;
+
     PFNVBOXWINEEXD3DRC9_SETSHRCSTATE pfnVBoxWineExD3DRc9SetShRcState;
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9wddm.def
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9wddm.def	(revision 42517)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9wddm.def	(revision 42518)
@@ -16,4 +16,5 @@
   VBoxWineExD3DDev9CreateCubeTexture
   VBoxWineExD3DDev9Update
+  VBoxWineExD3DDev9Term
   VBoxWineExD3DSwapchain9Present
   VBoxWineExD3DRc9SetShRcState
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 42517)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 42518)
@@ -260,4 +260,30 @@
 }
 
+static ULONG IDirect3DDevice9Impl_Term(IDirect3DDevice9Impl *This)
+{
+    ULONG wined3dDevRefs = 0;
+    unsigned i;
+    This->inDestruction = TRUE;
+
+    wined3d_mutex_lock();
+    for(i = 0; i < This->numConvertedDecls; i++) {
+        /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
+         * device
+         */
+        IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
+    }
+    HeapFree(GetProcessHeap(), 0, This->convertedDecls);
+
+    IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
+#ifndef VBOX_WITH_WDDM
+    IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
+#endif
+    wined3dDevRefs = IWineD3DDevice_Release(This->WineD3DDevice);
+    wined3d_mutex_unlock();
+
+    HeapFree(GetProcessHeap(), 0, This);
+    return wined3dDevRefs;
+}
+
 static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
@@ -270,24 +296,5 @@
 
     if (ref == 0) {
-      unsigned i;
-      This->inDestruction = TRUE;
-
-      wined3d_mutex_lock();
-      for(i = 0; i < This->numConvertedDecls; i++) {
-          /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
-           * device
-           */
-          IDirect3DVertexDeclaration9Impl_Destroy(This->convertedDecls[i]);
-      }
-      HeapFree(GetProcessHeap(), 0, This->convertedDecls);
-
-      IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
-#ifndef VBOX_WITH_WDDM
-      IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
-#endif
-      IWineD3DDevice_Release(This->WineD3DDevice);
-      wined3d_mutex_unlock();
-
-      HeapFree(GetProcessHeap(), 0, This);
+        IDirect3DDevice9Impl_Term(This);
     }
     return ref;
@@ -822,4 +829,22 @@
     IDirect3DDevice9_AddRef(iface);
     *outIface = iface;
+    return D3D_OK;
+}
+
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Term(IDirect3DDevice9Ex *iface)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IWineD3DDevice *WineD3DDevice = This->WineD3DDevice;
+    ULONG wined3dRefs;
+    if (This->ref != 1)
+    {
+        ERR("unexpected ref count %d, destroying in anyway", This->ref);
+    }
+    wined3dRefs = IDirect3DDevice9Impl_Term(This);
+    if (wined3dRefs)
+    {
+        ERR("unexpected wined3dRefs %d, destroying in anyway", wined3dRefs);
+        while (IWineD3DDevice_Release(WineD3DDevice)) {}
+    }
     return D3D_OK;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h	(revision 42517)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/vbox/VBoxWineEx.h	(revision 42518)
@@ -53,4 +53,7 @@
 typedef FNVBOXWINEEXD3DDEV9_UPDATE *PFNVBOXWINEEXD3DDEV9_UPDATE;
 
+typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DDEV9_TERM(IDirect3DDevice9Ex *iface);
+typedef FNVBOXWINEEXD3DDEV9_TERM *PFNVBOXWINEEXD3DDEV9_TERM;
+
 typedef VBOXWINEEX_DECL(HRESULT) FNVBOXWINEEXD3DRC9_SETSHRCSTATE(IDirect3DResource9 *iface, VBOXWINEEX_SHRC_STATE enmState);
 typedef FNVBOXWINEEXD3DRC9_SETSHRCSTATE *PFNVBOXWINEEXD3DRC9_SETSHRCSTATE;
@@ -80,4 +83,6 @@
                                                     IDirect3DDevice9Ex **outIface); /* update device parameters */
 
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Term(IDirect3DDevice9Ex *iface);
+
 VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DRc9SetShRcState(IDirect3DResource9 *iface, VBOXWINEEX_SHRC_STATE enmState);
 
Index: /trunk/src/VBox/Additions/common/crOpenGL/context.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/context.c	(revision 42517)
+++ /trunk/src/VBox/Additions/common/crOpenGL/context.c	(revision 42518)
@@ -88,4 +88,70 @@
 }
 
+void stubForcedFlush(GLint con)
+{
+#if 0
+    GLint buffer;
+    stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
+    stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
+    stub.spu->dispatch_table.Flush();
+    stub.spu->dispatch_table.DrawBuffer(buffer);
+#else
+    if (con)
+    {
+        stub.spu->dispatch_table.VBoxConFlush(con);
+    }
+    else
+    {
+        stub.spu->dispatch_table.Flush();
+    }
+#endif
+}
+
+static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
+{
+    ContextInfo *context = (ContextInfo *) data1;
+
+    CRASSERT(context);
+
+    if (context->currentDrawable == data2)
+        context->currentDrawable = NULL;
+}
+
+void stubDestroyWindow( GLint con, GLint window )
+{
+    WindowInfo *winInfo = (WindowInfo *)
+        crHashtableSearch(stub.windowTable, (unsigned int) window);
+    if (winInfo && winInfo->type == CHROMIUM && stub.spu)
+    {
+        crHashtableLock(stub.windowTable);
+
+        stub.spu->dispatch_table.VBoxWindowDestroy(con, winInfo->spuWindow );
+
+#ifdef WINDOWS
+        if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
+        {
+            DeleteObject(winInfo->hVisibleRegion);
+        }
+#elif defined(GLX)
+        if (winInfo->pVisibleRegions)
+        {
+            XFree(winInfo->pVisibleRegions);
+        }
+# ifdef CR_NEWWINTRACK
+        if (winInfo->syncDpy)
+        {
+            XCloseDisplay(winInfo->syncDpy);
+        }
+# endif
+#endif
+        stubForcedFlush(con);
+
+        crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
+
+        crHashtableDelete(stub.windowTable, window, crFree);
+
+        crHashtableUnlock(stub.windowTable);
+    }
+}
 
 /**
@@ -333,4 +399,11 @@
 
 static void
+stubContextFree( ContextInfo *context )
+{
+    crMemZero(context, sizeof(ContextInfo));  /* just to be safe */
+    crFree(context);
+}
+
+static void
 stubDestroyContextLocked( ContextInfo *context )
 {
@@ -367,6 +440,5 @@
 #endif
 
-    crMemZero(context, sizeof(ContextInfo));  /* just to be safe */
-    crHashtableDelete(stub.contextTable, contextId, crFree);
+    crHashtableDelete(stub.contextTable, contextId, NULL);
 }
 
@@ -374,9 +446,5 @@
 static DECLCALLBACK(void) stubContextDtor(void*pvContext)
 {
-    crHashtableLock(stub.windowTable);
-    crHashtableLock(stub.contextTable);
-    stubDestroyContextLocked((ContextInfo*)pvContext);
-    crHashtableUnlock(stub.contextTable);
-    crHashtableUnlock(stub.windowTable);
+    stubContextFree((ContextInfo*)pvContext);
 }
 #endif
@@ -1015,7 +1083,7 @@
                could be destroyed.
              */
-            crWindowDestroy((GLint)pWindow->hWnd);
+            stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
 #else
-            crWindowDestroy((GLint)pWindow->drawable);
+            stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
 #endif
     }
@@ -1167,5 +1235,5 @@
                         if (context->currentDrawable->hWnd!=WindowFromDC(context->currentDrawable->drawable))
                         {
-                            crWindowDestroy((GLint)context->currentDrawable->hWnd);
+                            stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->hWnd);
                         }
 #else
@@ -1177,5 +1245,5 @@
                         if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
                         {
-                            crWindowDestroy((GLint)context->currentDrawable->drawable);
+                            stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->drawable);
                         }
                         XUNLOCK(context->currentDrawable->dpy);
@@ -1196,7 +1264,4 @@
     window->type = context->type;
     window->pOwner = context;
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-    window->spuConnection = context->spuConnection;
-#endif
     context->currentDrawable = window;
     stubSetCurrentContext(context);
@@ -1286,4 +1351,7 @@
     CRASSERT(context);
 
+    CRASSERT(0);
+    stubDestroyContextLocked(context);
+
 #ifdef CHROMIUM_THREADSAFE
     if (stubGetCurrentContext() == context) {
@@ -1291,11 +1359,11 @@
     }
 
+    VBoxTlsRefMarkDestroy(context);
     VBoxTlsRefRelease(context);
 #else
-    stubDestroyContextLocked(context);
-
     if (stubGetCurrentContext() == context) {
         stubSetCurrentContext(NULL);
     }
+    stubContextFree(context);
 #endif
     crHashtableUnlock(stub.contextTable);
Index: /trunk/src/VBox/Additions/common/crOpenGL/load.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/load.c	(revision 42517)
+++ /trunk/src/VBox/Additions/common/crOpenGL/load.c	(revision 42518)
@@ -190,7 +190,7 @@
     {
 #ifdef WINDOWS
-        crWindowDestroy((GLint)pWindow->hWnd);
+        stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
 #else
-        crWindowDestroy((GLint)pWindow->drawable);
+        stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
 #endif
         return;
@@ -843,5 +843,5 @@
     if (!stubSystemWindowExist(pWindow))
     {
-        crWindowDestroy((GLint)pWindow->hWnd);
+        stubDestroyWindow(0, (GLint)pWindow->hWnd);
         return;
     }
@@ -991,7 +991,7 @@
     {
 #ifdef WINDOWS
-        crWindowDestroy((GLint)pWindow->hWnd);
+        stubDestroyWindow(0, (GLint)pWindow->hWnd);
 #else
-        crWindowDestroy((GLint)pWindow->drawable);
+        stubDestroyWindow(0, (GLint)pWindow->drawable);
 #endif
         /*No need to flush here as crWindowDestroy does it*/
Index: /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c	(revision 42517)
+++ /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c	(revision 42518)
@@ -160,17 +160,18 @@
     if (CRPACKSPU_IS_WDDM_CRHGSMI())
     {
-        ThreadInfo *thread;
-        CRPackContext * curPacker = crPackGetContext();
-        if (!con)
-        {
-            crError("connection expected!!");
+        GET_THREAD(thread);
+        if (con)
+        {
+            CRPackContext * curPacker = crPackGetContext();
+            CRASSERT(!thread || !thread->bInjectThread);
+            thread = GET_THREAD_VAL_ID(con);
+            crPackSetContext(thread->packer);
+            crPackWindowDestroy(window);
+            if (curPacker != thread->packer)
+                crPackSetContext(curPacker);
             return;
         }
-        thread = GET_THREAD_VAL_ID(con);
-        crPackSetContext(thread->packer);
-        crPackWindowDestroy(window);
-        if (curPacker != thread->packer)
-            crPackSetContext(curPacker);
-        return;
+        CRASSERT(thread);
+        CRASSERT(thread->bInjectThread);
     }
     crPackWindowDestroy(window);
Index: /trunk/src/VBox/Additions/common/crOpenGL/stub.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/stub.c	(revision 42517)
+++ /trunk/src/VBox/Additions/common/crOpenGL/stub.c	(revision 42518)
@@ -10,30 +10,4 @@
 #include "stub.h"
 #include <iprt/thread.h>
-
-static void crForcedFlush(
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-        GLint con
-#endif
-        )
-{
-#if 0
-    GLint buffer;
-    stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
-    stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
-    stub.spu->dispatch_table.Flush();
-    stub.spu->dispatch_table.DrawBuffer(buffer);
-#else
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-    if (con)
-    {
-        stub.spu->dispatch_table.VBoxConFlush(con);
-    }
-    else
-#endif
-    {
-        stub.spu->dispatch_table.Flush();
-    }
-#endif
-}
 
 #ifdef GLX
@@ -142,62 +116,7 @@
 }
 
-static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
-{
-    ContextInfo *context = (ContextInfo *) data1;
-
-    CRASSERT(context);
-
-    if (context->currentDrawable == data2)
-        context->currentDrawable = NULL;
-}
-
 void APIENTRY crWindowDestroy( GLint window )
 {
-    WindowInfo *winInfo = (WindowInfo *)
-        crHashtableSearch(stub.windowTable, (unsigned int) window);
-    if (winInfo && winInfo->type == CHROMIUM && stub.spu)
-    {
-        crHashtableLock(stub.windowTable);
-
-        stub.spu->dispatch_table.VBoxWindowDestroy(
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-                winInfo->spuConnection,
-#else
-                0,
-#endif
-                winInfo->spuWindow );
-
-#ifdef WINDOWS
-        if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
-        {
-            DeleteObject(winInfo->hVisibleRegion);
-        }
-#elif defined(GLX)
-        if (winInfo->pVisibleRegions)
-        {
-            XFree(winInfo->pVisibleRegions);
-        }
-# ifdef CR_NEWWINTRACK
-        if (winInfo->syncDpy)
-        {
-            XCloseDisplay(winInfo->syncDpy);
-        }
-# endif
-#endif
-        crForcedFlush(
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-                winInfo->spuConnection
-#endif
-                );
-
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-        winInfo->spuConnection = 0;
-#endif
-        crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
-
-        crHashtableDelete(stub.windowTable, window, crFree);
-
-        crHashtableUnlock(stub.windowTable);
-    }
+    stubDestroyWindow( 0, window );
 }
 
@@ -415,5 +334,5 @@
                 if (stubUpdateWindowGeometry(winInfo, GL_FALSE) || changed)
                 {
-                    crForcedFlush();
+                    stubForcedFlush(0);
                 }
                 break;
@@ -429,5 +348,5 @@
                 if (stub.trackWindowVisibleRgn && stubUpdateWindowVisibileRegions(winInfo))
                 {
-                    crForcedFlush();
+                    stubForcedFlush(0);
                 }
                 break;
@@ -439,5 +358,5 @@
                 {
                     crDebug("Visibility info updated due to unknown hooked message (%d)", pMsgInfo->message);
-                    crForcedFlush();
+                    stubForcedFlush(0);
                 }
                 break;
Index: /trunk/src/VBox/Additions/common/crOpenGL/stub.h
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/stub.h	(revision 42517)
+++ /trunk/src/VBox/Additions/common/crOpenGL/stub.h	(revision 42518)
@@ -170,7 +170,4 @@
     ContextInfo *pOwner;     /* ctx which created this window */
     GLboolean mapped;
-#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
-    GLint spuConnection;
-#endif
 #ifdef WINDOWS
     HDC      drawable;
@@ -289,5 +286,10 @@
 extern CRtsd g_stubCurrentContextTSD;
 
-# define stubGetCurrentContext() VBoxTlsRefGetCurrent(ContextInfo, &g_stubCurrentContextTSD)
+DECLINLINE(ContextInfo*) stubGetCurrentContext()
+{
+    ContextInfo* ctx;
+    VBoxTlsRefGetCurrentFunctional(ctx, ContextInfo, &g_stubCurrentContextTSD);
+    return ctx;
+}
 # define stubSetCurrentContext(_ctx) VBoxTlsRefSetCurrent(ContextInfo, &g_stubCurrentContextTSD, _ctx)
 #else
@@ -345,4 +347,5 @@
 extern GLboolean stubMakeCurrent( WindowInfo *window, ContextInfo *context );
 extern GLint stubNewWindow( const char *dpyName, GLint visBits );
+extern void stubDestroyWindow( GLint con, GLint window );
 extern void stubSwapBuffers(WindowInfo *window, GLint flags);
 extern void stubGetWindowGeometry(WindowInfo *win, int *x, int *y, unsigned int *w, unsigned int *h);
@@ -351,7 +354,14 @@
 extern bool stubInit(void);
 
+extern void stubForcedFlush(GLint con);
 extern void APIENTRY stub_GetChromiumParametervCR( GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values );
 
 extern void APIENTRY glBoundsInfoCR(const CRrecti *, const GLbyte *, GLint, GLint);
 
+#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
+# define CR_CTX_CON(_pCtx) ((_pCtx)->spuConnection)
+#else
+# define CR_CTX_CON(_pCtx) (0)
+#endif
+
 #endif /* CR_STUB_H */
