Robert Shearman : ole: Verify that the proxy is being used in the correct thread.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jan 20 13:20:20 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 1b7d346d1f46aa28b77524a9f752bd038b27a231
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=1b7d346d1f46aa28b77524a9f752bd038b27a231

Author: Robert Shearman <rob at codeweavers.com>
Date:   Fri Jan 20 16:16:08 2006 +0100

ole: Verify that the proxy is being used in the correct thread.

---

 dlls/ole32/rpc.c           |   39 ++++++++++++++++++++++++++++++++++-----
 dlls/ole32/tests/marshal.c |    4 +---
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/dlls/ole32/rpc.c b/dlls/ole32/rpc.c
index 06c24d3..c45df68 100644
--- a/dlls/ole32/rpc.c
+++ b/dlls/ole32/rpc.c
@@ -98,6 +98,7 @@ typedef struct
     RpcChannelBuffer       super; /* superclass */
 
     RPC_BINDING_HANDLE     bind; /* handle to the remote server */
+    OXID                   oxid; /* apartment in which the channel is valid */
 } ClientRpcChannelBuffer;
 
 struct dispatch_params
@@ -206,6 +207,12 @@ static HRESULT WINAPI ClientRpcChannelBu
     return HRESULT_FROM_WIN32(status);
 }
 
+static HRESULT WINAPI ServerRpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
+{
+    FIXME("stub\n");
+    return E_NOTIMPL;
+}
+
 /* this thread runs an outgoing RPC */
 static DWORD WINAPI rpc_sendreceive_thread(LPVOID param)
 {
@@ -219,9 +226,22 @@ static DWORD WINAPI rpc_sendreceive_thre
     return 0;
 }
 
-static HRESULT WINAPI RpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
+static inline HRESULT ClientRpcChannelBuffer_IsCorrectApartment(ClientRpcChannelBuffer *This, APARTMENT *apt)
 {
-    HRESULT hr = S_OK;
+    OXID oxid;
+    if (!apt)
+        return S_FALSE;
+    if (apartment_getoxid(apt, &oxid) != S_OK)
+        return S_FALSE;
+    if (This->oxid != oxid)
+        return S_FALSE;
+    return S_OK;
+}
+
+static HRESULT WINAPI ClientRpcChannelBuffer_SendReceive(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE *olemsg, ULONG *pstatus)
+{
+    ClientRpcChannelBuffer *This = (ClientRpcChannelBuffer *)iface;
+    HRESULT hr;
     RPC_MESSAGE *msg = (RPC_MESSAGE *)olemsg;
     RPC_STATUS status;
     DWORD index;
@@ -232,9 +252,17 @@ static HRESULT WINAPI RpcChannelBuffer_S
 
     TRACE("(%p) iMethod=%ld\n", olemsg, olemsg->iMethod);
 
+    hr = ClientRpcChannelBuffer_IsCorrectApartment(This, COM_CurrentApt());
+    if (hr != S_OK)
+    {
+        ERR("called from wrong apartment, should have been 0x%s\n",
+            wine_dbgstr_longlong(This->oxid));
+        return RPC_E_WRONG_THREAD;
+    }
+
     params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*params));
     if (!params) return E_OUTOFMEMORY;
-    
+
     params->msg = olemsg;
     params->status = RPC_S_OK;
     params->hr = S_OK;
@@ -369,7 +397,7 @@ static const IRpcChannelBufferVtbl Clien
     RpcChannelBuffer_AddRef,
     ClientRpcChannelBuffer_Release,
     ClientRpcChannelBuffer_GetBuffer,
-    RpcChannelBuffer_SendReceive,
+    ClientRpcChannelBuffer_SendReceive,
     ClientRpcChannelBuffer_FreeBuffer,
     RpcChannelBuffer_GetDestCtx,
     RpcChannelBuffer_IsConnected
@@ -381,7 +409,7 @@ static const IRpcChannelBufferVtbl Serve
     RpcChannelBuffer_AddRef,
     ServerRpcChannelBuffer_Release,
     ServerRpcChannelBuffer_GetBuffer,
-    RpcChannelBuffer_SendReceive,
+    ServerRpcChannelBuffer_SendReceive,
     ServerRpcChannelBuffer_FreeBuffer,
     RpcChannelBuffer_GetDestCtx,
     RpcChannelBuffer_IsConnected
@@ -440,6 +468,7 @@ HRESULT RPC_CreateClientChannel(const OX
     This->super.lpVtbl = &ClientRpcChannelBufferVtbl;
     This->super.refs = 1;
     This->bind = bind;
+    apartment_getoxid(COM_CurrentApt(), &This->oxid);
 
     *chan = (IRpcChannelBuffer*)This;
 
diff --git a/dlls/ole32/tests/marshal.c b/dlls/ole32/tests/marshal.c
index dc445e5..10c690c 100644
--- a/dlls/ole32/tests/marshal.c
+++ b/dlls/ole32/tests/marshal.c
@@ -1021,14 +1021,12 @@ static DWORD CALLBACK bad_thread_proc(LP
     IUnknown * proxy = NULL;
 
     pCoInitializeEx(NULL, COINIT_MULTITHREADED);
-    
+
     hr = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (LPVOID*)&proxy);
     if (proxy) IUnknown_Release(proxy);
-    todo_wine {
     ok(hr == RPC_E_WRONG_THREAD,
         "COM should have failed with RPC_E_WRONG_THREAD on using proxy from wrong apartment, but instead returned 0x%08lx\n",
         hr);
-    }
 
     CoUninitialize();
 




More information about the wine-cvs mailing list