IUnknown_[QAR]_Proxy implementations, VTbl construction, the dreaded

ObjectStubless, and other proxy-related goodies.
This commit is contained in:
Ove Kaaven 2002-10-10 21:18:29 +00:00 committed by Alexandre Julliard
parent c15b0a2515
commit b41d4feda1
4 changed files with 362 additions and 3 deletions

View File

@ -5,11 +5,13 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = rpcrt4.dll
IMPORTS = kernel32
EXTRALIBS = $(LIBUUID)
LDDLLFLAGS = @LDDLLFLAGS@
SYMBOLFILE = $(MODULE).tmp.o
C_SRCS = \
cproxy.c \
ndr_stubless.c \
rpc_binding.c \
rpc_message.c \

315
dlls/rpcrt4/cproxy.c Normal file
View File

@ -0,0 +1,315 @@
/*
* COM proxy implementation
*
* Copyright 2001 Ove Kåven, TransGaming Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* TODO: Handle non-i386 architectures
* Get rid of #if 0'ed code.
*/
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wine/obj_base.h"
#include "wine/obj_channel.h"
#include "rpcproxy.h"
#include "cpsf.h"
#include "ndr_misc.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
struct StublessThunk;
/* I don't know what MS's std proxy structure looks like,
so this probably doesn't match, but that shouldn't matter */
typedef struct {
ICOM_VTABLE(IRpcProxyBuffer) *lpVtbl;
LPVOID *PVtbl;
DWORD RefCount;
const MIDL_STUBLESS_PROXY_INFO *stubless;
const IID* piid;
LPUNKNOWN pUnkOuter;
LPPSFACTORYBUFFER pPSFactory;
LPRPCCHANNELBUFFER pChannel;
struct StublessThunk *thunks;
} StdProxyImpl;
static ICOM_VTABLE(IRpcProxyBuffer) StdProxy_Vtbl;
/* How the Windows stubless proxy thunks work is explained at
* http://msdn.microsoft.com/library/en-us/dnmsj99/html/com0199.asp,
* but I'll use a slightly different method, to make life easier */
#if defined(__i386__)
struct StublessThunk {
BYTE push WINE_PACKED;
DWORD index WINE_PACKED;
BYTE call WINE_PACKED;
LONG handler WINE_PACKED;
BYTE ret WINE_PACKED;
WORD bytes WINE_PACKED;
BYTE pad[3];
};
/* adjust the stack size since we don't use Windows's method */
#define STACK_ADJUST sizeof(DWORD)
#define FILL_STUBLESS(x,idx,stk) \
x->push = 0x68; /* pushl [immediate] */ \
x->index = (idx); \
x->call = 0xe8; /* call [near] */ \
x->handler = (char*)ObjectStubless - (char*)&x->ret; \
x->ret = 0xc2; /* ret [immediate] */ \
x->bytes = stk; \
x->pad[0] = 0x8d; /* leal (%esi),%esi */ \
x->pad[1] = 0x76; \
x->pad[2] = 0x00;
#else
/* can't do that on this arch */
struct ObjectStubless {};
#define FILL_STUBLESS(x,idx) \
ERR("stubless proxies are not supported on this architecture\n");
#endif
static HRESULT WINAPI ObjectStubless(DWORD index)
{
char *args = (char*)(&index + 2);
LPVOID iface = *(LPVOID*)args;
ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
PFORMAT_STRING fs = This->stubless->ProcFormatString + This->stubless->FormatStringOffset[index];
unsigned bytes = *(WORD*)(fs+8) - STACK_ADJUST;
TRACE("(%p)->(%ld)([%d bytes]) ret=%08lx\n", iface, index, bytes, *(DWORD*)(args+bytes));
return RPCRT4_NdrClientCall2(This->stubless->pStubDesc, fs, args);
}
HRESULT WINAPI StdProxy_Construct(REFIID riid,
LPUNKNOWN pUnkOuter,
CInterfaceProxyVtbl *vtbl,
CInterfaceStubVtbl *svtbl,
LPPSFACTORYBUFFER pPSFactory,
LPRPCPROXYBUFFER *ppProxy,
LPVOID *ppvObj)
{
StdProxyImpl *This;
const MIDL_STUBLESS_PROXY_INFO *stubless = NULL;
TRACE("(%p,%p,%p,%p,%p)\n", pUnkOuter, vtbl, pPSFactory, ppProxy, ppvObj);
/* I can't find any other way to detect stubless proxies than this hack */
if (!IsEqualGUID(vtbl->header.piid, riid)) {
stubless = *((const void **)vtbl)++;
TRACE("stubless=%p\n", stubless);
}
TRACE("iid=%s\n", debugstr_guid(vtbl->header.piid));
TRACE("vtbl=%p\n", vtbl->Vtbl);
if (!IsEqualGUID(vtbl->header.piid, riid)) {
ERR("IID mismatch during proxy creation\n");
return RPC_E_UNEXPECTED;
}
This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(StdProxyImpl));
if (!This) return E_OUTOFMEMORY;
if (stubless) {
unsigned i, count = svtbl->header.DispatchTableCount;
/* Maybe the original vtbl is just modified directly to point at
* ObjectStublessClientXXX thunks in real Windows, but I don't like it
*/
TRACE("stubless thunks: count=%d\n", count);
This->thunks = HeapAlloc(GetProcessHeap(),0,sizeof(struct StublessThunk)*count);
This->PVtbl = HeapAlloc(GetProcessHeap(),0,sizeof(LPVOID)*count);
for (i=0; i<count; i++) {
struct StublessThunk *thunk = &This->thunks[i];
if (vtbl->Vtbl[i] == (LPVOID)-1) {
PFORMAT_STRING fs = stubless->ProcFormatString + stubless->FormatStringOffset[i];
unsigned bytes = *(WORD*)(fs+8) - STACK_ADJUST;
TRACE("method %d: stacksize=%d\n", i, bytes);
FILL_STUBLESS(thunk, i, bytes)
This->PVtbl[i] = thunk;
}
else {
memset(thunk, 0, sizeof(struct StublessThunk));
This->PVtbl[i] = vtbl->Vtbl[i];
}
}
}
else
This->PVtbl = vtbl->Vtbl;
This->lpVtbl = &StdProxy_Vtbl;
This->RefCount = 1;
This->stubless = stubless;
This->piid = vtbl->header.piid;
This->pUnkOuter = pUnkOuter;
This->pPSFactory = pPSFactory;
This->pChannel = NULL;
*ppProxy = (LPRPCPROXYBUFFER)&This->lpVtbl;
*ppvObj = &This->PVtbl;
IPSFactoryBuffer_AddRef(pPSFactory);
return S_OK;
}
static void WINAPI StdProxy_Destruct(LPRPCPROXYBUFFER iface)
{
ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
IPSFactoryBuffer_Release(This->pPSFactory);
if (This->thunks) {
HeapFree(GetProcessHeap(),0,This->PVtbl);
HeapFree(GetProcessHeap(),0,This->thunks);
}
HeapFree(GetProcessHeap(),0,This);
}
static HRESULT WINAPI StdProxy_QueryInterface(LPRPCPROXYBUFFER iface,
REFIID riid,
LPVOID *obj)
{
ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
if (IsEqualGUID(&IID_IUnknown,riid) ||
IsEqualGUID(This->piid,riid)) {
*obj = &This->PVtbl;
This->RefCount++;
return S_OK;
}
if (IsEqualGUID(&IID_IRpcProxyBuffer,riid)) {
*obj = &This->lpVtbl;
This->RefCount++;
return S_OK;
}
return E_NOINTERFACE;
}
static ULONG WINAPI StdProxy_AddRef(LPRPCPROXYBUFFER iface)
{
ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
TRACE("(%p)->AddRef()\n",This);
return ++(This->RefCount);
}
static ULONG WINAPI StdProxy_Release(LPRPCPROXYBUFFER iface)
{
ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
TRACE("(%p)->Release()\n",This);
if (!--(This->RefCount)) {
StdProxy_Destruct((LPRPCPROXYBUFFER)&This->lpVtbl);
return 0;
}
return This->RefCount;
}
static HRESULT WINAPI StdProxy_Connect(LPRPCPROXYBUFFER iface,
LPRPCCHANNELBUFFER pChannel)
{
ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
TRACE("(%p)->Connect(%p)\n",This,pChannel);
This->pChannel = pChannel;
return S_OK;
}
static VOID WINAPI StdProxy_Disconnect(LPRPCPROXYBUFFER iface)
{
ICOM_THIS_MULTI(StdProxyImpl,lpVtbl,iface);
TRACE("(%p)->Disconnect()\n",This);
This->pChannel = NULL;
}
static ICOM_VTABLE(IRpcProxyBuffer) StdProxy_Vtbl =
{
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
StdProxy_QueryInterface,
StdProxy_AddRef,
StdProxy_Release,
StdProxy_Connect,
StdProxy_Disconnect
};
HRESULT WINAPI StdProxy_GetChannel(LPVOID iface,
LPRPCCHANNELBUFFER *ppChannel)
{
ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
TRACE("(%p)->GetChannel(%p)\n",This,ppChannel);
*ppChannel = This->pChannel;
return S_OK;
}
HRESULT WINAPI StdProxy_GetIID(LPVOID iface,
const IID **ppiid)
{
ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
TRACE("(%p)->GetIID(%p)\n",This,ppiid);
*ppiid = This->piid;
return S_OK;
}
HRESULT WINAPI IUnknown_QueryInterface_Proxy(LPUNKNOWN iface,
REFIID riid,
LPVOID *ppvObj)
{
ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),ppvObj);
return IUnknown_QueryInterface(This->pUnkOuter,riid,ppvObj);
}
ULONG WINAPI IUnknown_AddRef_Proxy(LPUNKNOWN iface)
{
ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
TRACE("(%p)->AddRef()\n",This);
#if 0 /* interface refcounting */
return ++(This->RefCount);
#else /* object refcounting */
return IUnknown_AddRef(This->pUnkOuter);
#endif
}
ULONG WINAPI IUnknown_Release_Proxy(LPUNKNOWN iface)
{
ICOM_THIS_MULTI(StdProxyImpl,PVtbl,iface);
TRACE("(%p)->Release()\n",This);
#if 0 /* interface refcounting */
if (!--(This->RefCount)) {
StdProxy_Destruct((LPRPCPROXYBUFFER)&This->lpVtbl);
return 0;
}
return This->RefCount;
#else /* object refcounting */
return IUnknown_Release(This->pUnkOuter);
#endif
}

42
dlls/rpcrt4/cpsf.h Normal file
View File

@ -0,0 +1,42 @@
/*
* COM proxy definitions
*
* Copyright 2001 Ove Kåven, TransGaming Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WINE_CPSF_H
#define __WINE_CPSF_H
HRESULT WINAPI StdProxy_Construct(REFIID riid,
LPUNKNOWN pUnkOuter,
CInterfaceProxyVtbl *vtbl,
CInterfaceStubVtbl *svtbl,
LPPSFACTORYBUFFER pPSFactory,
LPRPCPROXYBUFFER *ppProxy,
LPVOID *ppvObj);
HRESULT WINAPI StdProxy_GetChannel(LPVOID iface,
LPRPCCHANNELBUFFER *ppChannel);
HRESULT WINAPI StdProxy_GetIID(LPVOID iface,
const IID **piid);
HRESULT WINAPI CStdStubBuffer_Construct(REFIID riid,
LPUNKNOWN pUnkServer,
CInterfaceStubVtbl *vtbl,
LPPSFACTORYBUFFER pPSFactory,
LPRPCSTUBBUFFER *ppStub);
#endif /* __WINE_CPSF_H */

View File

@ -195,9 +195,9 @@ init RPCRT4_LibMain
@ stub NdrCStdStubBuffer2_Release
@ stub NdrCStdStubBuffer_Release
@ stub IUnknown_QueryInterface_Proxy
@ stub IUnknown_AddRef_Proxy
@ stub IUnknown_Release_Proxy
@ stdcall IUnknown_QueryInterface_Proxy(ptr ptr ptr) IUnknown_QueryInterface_Proxy
@ stdcall IUnknown_AddRef_Proxy(ptr) IUnknown_AddRef_Proxy
@ stdcall IUnknown_Release_Proxy(ptr) IUnknown_Release_Proxy
@ stub NdrAllocate
@ stub NdrAsyncClientCall