2002-10-10 23:18:29 +02:00
|
|
|
/*
|
|
|
|
* COM proxy implementation
|
|
|
|
*
|
2008-10-18 19:20:44 +02:00
|
|
|
* Copyright 2001 Ove Kåven, TransGaming Technologies
|
2009-06-03 16:42:50 +02:00
|
|
|
* Copyright 2009 Alexandre Julliard
|
2002-10-10 23:18:29 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-10 23:18:29 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2002-10-10 23:18:29 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2002-10-10 23:18:29 +02:00
|
|
|
#include "rpcproxy.h"
|
|
|
|
|
|
|
|
#include "cpsf.h"
|
|
|
|
#include "ndr_misc.h"
|
2011-06-13 12:39:47 +02:00
|
|
|
#include "ndr_stubless.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2002-10-10 23:18:29 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IRpcProxyBufferVtbl StdProxy_Vtbl;
|
2002-10-10 23:18:29 +02:00
|
|
|
|
2010-12-30 11:57:18 +01:00
|
|
|
static inline StdProxyImpl *impl_from_IRpcProxyBuffer(IRpcProxyBuffer *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, StdProxyImpl, IRpcProxyBuffer_iface);
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:21:57 +01:00
|
|
|
static inline StdProxyImpl *impl_from_proxy_obj( void *iface )
|
|
|
|
{
|
2010-12-30 11:57:18 +01:00
|
|
|
return CONTAINING_RECORD(iface, StdProxyImpl, PVtbl);
|
2010-11-11 20:21:57 +01:00
|
|
|
}
|
2004-08-13 02:44:22 +02:00
|
|
|
|
2011-06-15 12:26:03 +02:00
|
|
|
#ifdef __i386__
|
2002-10-10 23:18:29 +02:00
|
|
|
|
2009-06-01 20:52:40 +02:00
|
|
|
extern void call_stubless_func(void);
|
|
|
|
__ASM_GLOBAL_FUNC(call_stubless_func,
|
2011-06-15 12:26:35 +02:00
|
|
|
"movl 4(%esp),%ecx\n\t" /* This pointer */
|
|
|
|
"movl (%ecx),%ecx\n\t" /* This->lpVtbl */
|
|
|
|
"movl -8(%ecx),%ecx\n\t" /* MIDL_STUBLESS_PROXY_INFO */
|
|
|
|
"movl 8(%ecx),%edx\n\t" /* info->FormatStringOffset */
|
|
|
|
"movzwl (%edx,%eax,2),%edx\n\t" /* FormatStringOffset[index] */
|
|
|
|
"addl 4(%ecx),%edx\n\t" /* info->ProcFormatString + offset */
|
2018-10-05 23:44:08 +02:00
|
|
|
"movzbl 1(%edx),%eax\n\t" /* Oi_flags */
|
|
|
|
"andl $0x08,%eax\n\t" /* Oi_HAS_RPCFLAGS */
|
|
|
|
"shrl $1,%eax\n\t"
|
|
|
|
"movzwl 4(%edx,%eax),%eax\n\t" /* arguments size */
|
2011-06-15 12:26:35 +02:00
|
|
|
"pushl %eax\n\t"
|
2010-08-26 17:03:31 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
2011-06-15 12:26:35 +02:00
|
|
|
"leal 8(%esp),%eax\n\t" /* &This */
|
|
|
|
"pushl %eax\n\t"
|
2009-06-25 11:51:30 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
2011-06-15 12:26:35 +02:00
|
|
|
"pushl %edx\n\t" /* format string */
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
"pushl (%ecx)\n\t" /* info->pStubDesc */
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
"call " __ASM_NAME("ndr_client_call") "\n\t"
|
|
|
|
"leal 12(%esp),%esp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -12\n\t")
|
|
|
|
"popl %edx\n\t" /* arguments size */
|
2009-06-25 11:51:30 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
|
2009-06-01 20:52:40 +02:00
|
|
|
"movl (%esp),%ecx\n\t" /* return address */
|
|
|
|
"addl %edx,%esp\n\t"
|
|
|
|
"jmp *%ecx" );
|
|
|
|
|
2011-06-15 12:26:35 +02:00
|
|
|
#include "pshpack1.h"
|
|
|
|
struct thunk
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2011-06-15 12:26:35 +02:00
|
|
|
BYTE mov_eax;
|
|
|
|
DWORD index;
|
|
|
|
BYTE jmp;
|
|
|
|
LONG handler;
|
|
|
|
};
|
|
|
|
#include "poppack.h"
|
2002-10-10 23:18:29 +02:00
|
|
|
|
2011-06-15 12:26:03 +02:00
|
|
|
static inline void init_thunk( struct thunk *thunk, unsigned int index )
|
|
|
|
{
|
|
|
|
thunk->mov_eax = 0xb8; /* movl $n,%eax */
|
|
|
|
thunk->index = index;
|
|
|
|
thunk->jmp = 0xe9; /* jmp */
|
|
|
|
thunk->handler = (char *)call_stubless_func - (char *)(&thunk->handler + 1);
|
|
|
|
}
|
|
|
|
|
2011-06-15 12:49:24 +02:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
|
|
|
|
extern void call_stubless_func(void);
|
|
|
|
__ASM_GLOBAL_FUNC(call_stubless_func,
|
2019-08-21 11:28:26 +02:00
|
|
|
"subq $0x38,%rsp\n\t"
|
|
|
|
__ASM_SEH(".seh_stackalloc 0x38\n\t")
|
|
|
|
__ASM_SEH(".seh_endprologue\n\t")
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 0x38\n\t")
|
|
|
|
"movq %rcx,0x40(%rsp)\n\t"
|
|
|
|
"movq %rdx,0x48(%rsp)\n\t"
|
|
|
|
"movq %r8,0x50(%rsp)\n\t"
|
|
|
|
"movq %r9,0x58(%rsp)\n\t"
|
|
|
|
"leaq 0x40(%rsp),%r8\n\t" /* &This */
|
2011-06-15 12:49:24 +02:00
|
|
|
"movq (%rcx),%rcx\n\t" /* This->lpVtbl */
|
|
|
|
"movq -0x10(%rcx),%rcx\n\t" /* MIDL_STUBLESS_PROXY_INFO */
|
|
|
|
"movq 0x10(%rcx),%rdx\n\t" /* info->FormatStringOffset */
|
|
|
|
"movzwq (%rdx,%r10,2),%rdx\n\t" /* FormatStringOffset[index] */
|
|
|
|
"addq 8(%rcx),%rdx\n\t" /* info->ProcFormatString + offset */
|
|
|
|
"movq (%rcx),%rcx\n\t" /* info->pStubDesc */
|
2011-06-13 13:39:21 +02:00
|
|
|
"movq %xmm1,0x20(%rsp)\n\t"
|
|
|
|
"movq %xmm2,0x28(%rsp)\n\t"
|
|
|
|
"movq %xmm3,0x30(%rsp)\n\t"
|
|
|
|
"leaq 0x18(%rsp),%r9\n\t" /* fpu_args */
|
2011-06-15 12:49:24 +02:00
|
|
|
"call " __ASM_NAME("ndr_client_call") "\n\t"
|
2011-06-13 13:39:21 +02:00
|
|
|
"addq $0x38,%rsp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -0x38\n\t")
|
2011-06-15 12:49:24 +02:00
|
|
|
"ret" );
|
|
|
|
|
|
|
|
#include "pshpack1.h"
|
|
|
|
struct thunk
|
|
|
|
{
|
|
|
|
BYTE mov_r10[3];
|
|
|
|
DWORD index;
|
|
|
|
BYTE mov_rax[2];
|
|
|
|
void *call_stubless;
|
|
|
|
BYTE jmp_rax[2];
|
|
|
|
};
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
static const struct thunk thunk_template =
|
|
|
|
{
|
|
|
|
{ 0x49, 0xc7, 0xc2 }, 0, /* movq $index,%r10 */
|
|
|
|
{ 0x48, 0xb8 }, 0, /* movq $call_stubless_func,%rax */
|
|
|
|
{ 0xff, 0xe0 } /* jmp *%rax */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void init_thunk( struct thunk *thunk, unsigned int index )
|
|
|
|
{
|
|
|
|
*thunk = thunk_template;
|
|
|
|
thunk->index = index;
|
|
|
|
thunk->call_stubless = call_stubless_func;
|
|
|
|
}
|
|
|
|
|
2018-11-13 16:07:49 +01:00
|
|
|
#elif defined(__arm__)
|
|
|
|
|
|
|
|
extern void call_stubless_func(void);
|
|
|
|
__ASM_GLOBAL_FUNC(call_stubless_func,
|
|
|
|
"push {r0-r3}\n\t"
|
|
|
|
"mov r2, sp\n\t" /* stack_top */
|
|
|
|
"push {fp,lr}\n\t"
|
|
|
|
"mov fp, sp\n\t"
|
|
|
|
"ldr r0, [r0]\n\t" /* This->lpVtbl */
|
|
|
|
"ldr r0, [r0,#-8]\n\t" /* MIDL_STUBLESS_PROXY_INFO */
|
|
|
|
"ldr r1, [r0,#8]\n\t" /* info->FormatStringOffset */
|
|
|
|
"ldrh r1, [r1,ip]\n\t" /* info->FormatStringOffset[index] */
|
|
|
|
"ldr ip, [r0,#4]\n\t" /* info->ProcFormatString */
|
|
|
|
"add r1, ip\n\t" /* info->ProcFormatString + offset */
|
|
|
|
"ldr r0, [r0]\n\t" /* info->pStubDesc */
|
|
|
|
#ifdef __SOFTFP__
|
|
|
|
"mov r3, #0\n\t"
|
|
|
|
#else
|
|
|
|
"vpush {s0-s15}\n\t" /* store the s0-s15/d0-d7 arguments */
|
|
|
|
"mov r3, sp\n\t" /* fpu_stack */
|
|
|
|
#endif
|
|
|
|
"bl " __ASM_NAME("ndr_client_call") "\n\t"
|
|
|
|
"mov sp, fp\n\t"
|
|
|
|
"pop {fp,lr}\n\t"
|
|
|
|
"add sp, #16\n\t"
|
|
|
|
"bx lr" );
|
|
|
|
|
|
|
|
struct thunk
|
|
|
|
{
|
|
|
|
DWORD ldr_ip; /* ldr ip,[pc] */
|
|
|
|
DWORD ldr_pc; /* ldr pc,[pc] */
|
|
|
|
DWORD index;
|
|
|
|
void *func;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void init_thunk( struct thunk *thunk, unsigned int index )
|
|
|
|
{
|
|
|
|
thunk->ldr_ip = 0xe59fc000; /* ldr ip,[pc] */
|
|
|
|
thunk->ldr_pc = 0xe59ff000; /* ldr pc,[pc] */
|
|
|
|
thunk->index = index * sizeof(unsigned short);
|
|
|
|
thunk->func = call_stubless_func;
|
|
|
|
}
|
|
|
|
|
2019-09-27 12:39:49 +02:00
|
|
|
#elif defined(__aarch64__)
|
|
|
|
|
|
|
|
extern void call_stubless_func(void);
|
|
|
|
__ASM_GLOBAL_FUNC( call_stubless_func,
|
|
|
|
"stp x29, x30, [sp, #-0x90]!\n\t"
|
|
|
|
"mov x29, sp\n\t"
|
|
|
|
"stp d0, d1, [sp, #0x10]\n\t"
|
|
|
|
"stp d2, d3, [sp, #0x20]\n\t"
|
|
|
|
"stp d4, d5, [sp, #0x30]\n\t"
|
|
|
|
"stp d6, d7, [sp, #0x40]\n\t"
|
|
|
|
"stp x0, x1, [sp, #0x50]\n\t"
|
|
|
|
"stp x2, x3, [sp, #0x60]\n\t"
|
|
|
|
"stp x4, x5, [sp, #0x70]\n\t"
|
|
|
|
"stp x6, x7, [sp, #0x80]\n\t"
|
|
|
|
"ldr x0, [x0]\n\t" /* This->lpVtbl */
|
|
|
|
"ldr x0, [x0, #-16]\n\t" /* MIDL_STUBLESS_PROXY_INFO */
|
|
|
|
"ldp x1, x4, [x0, #8]\n\t" /* info->ProcFormatString, FormatStringOffset */
|
|
|
|
"ldrh w4, [x4, x16, lsl #1]\n\t" /* info->FormatStringOffset[index] */
|
|
|
|
"add x1, x1, x4\n\t" /* info->ProcFormatString + offset */
|
|
|
|
"ldr x0, [x0]\n\t" /* info->pStubDesc */
|
|
|
|
"add x2, sp, #0x50\n\t" /* stack */
|
|
|
|
"add x3, sp, #0x10\n\t" /* fpu_stack */
|
|
|
|
"bl " __ASM_NAME("ndr_client_call") "\n\t"
|
|
|
|
"ldp x29, x30, [sp], #0x90\n\t"
|
|
|
|
"ret" )
|
|
|
|
|
|
|
|
struct thunk
|
|
|
|
{
|
|
|
|
DWORD ldr_index; /* ldr w16, index */
|
|
|
|
DWORD ldr_func; /* ldr x17, func */
|
|
|
|
DWORD br; /* br x17 */
|
|
|
|
DWORD index;
|
|
|
|
void *func;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void init_thunk( struct thunk *thunk, unsigned int index )
|
|
|
|
{
|
|
|
|
thunk->ldr_index = 0x18000070; /* ldr w16,index */
|
|
|
|
thunk->ldr_func = 0x58000071; /* ldr x17,func */
|
|
|
|
thunk->br = 0xd61f0220; /* br x17 */
|
|
|
|
thunk->index = index;
|
|
|
|
thunk->func = call_stubless_func;
|
|
|
|
}
|
|
|
|
|
2011-06-15 12:26:03 +02:00
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
#warning You must implement stubless proxies for your CPU
|
|
|
|
|
|
|
|
struct thunk
|
|
|
|
{
|
|
|
|
DWORD index;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void init_thunk( struct thunk *thunk, unsigned int index )
|
|
|
|
{
|
|
|
|
thunk->index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2009-06-01 21:19:56 +02:00
|
|
|
#define BLOCK_SIZE 1024
|
|
|
|
#define MAX_BLOCKS 64 /* 64k methods should be enough for anybody */
|
|
|
|
|
|
|
|
static const struct thunk *method_blocks[MAX_BLOCKS];
|
|
|
|
|
|
|
|
static const struct thunk *allocate_block( unsigned int num )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct thunk *prev, *block;
|
2014-06-21 18:44:57 +02:00
|
|
|
DWORD oldprot;
|
2009-06-01 21:19:56 +02:00
|
|
|
|
|
|
|
block = VirtualAlloc( NULL, BLOCK_SIZE * sizeof(*block),
|
|
|
|
MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
|
|
|
|
if (!block) return NULL;
|
|
|
|
|
2011-06-15 12:26:03 +02:00
|
|
|
for (i = 0; i < BLOCK_SIZE; i++) init_thunk( &block[i], BLOCK_SIZE * num + i + 3 );
|
2014-06-21 18:44:57 +02:00
|
|
|
VirtualProtect( block, BLOCK_SIZE * sizeof(*block), PAGE_EXECUTE_READ, &oldprot );
|
2009-06-01 21:19:56 +02:00
|
|
|
prev = InterlockedCompareExchangePointer( (void **)&method_blocks[num], block, NULL );
|
|
|
|
if (prev) /* someone beat us to it */
|
|
|
|
{
|
|
|
|
VirtualFree( block, 0, MEM_RELEASE );
|
|
|
|
block = prev;
|
|
|
|
}
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
2018-11-04 00:07:15 +01:00
|
|
|
BOOL fill_stubless_table( IUnknownVtbl *vtbl, DWORD num )
|
2009-06-01 21:19:56 +02:00
|
|
|
{
|
|
|
|
const void **entry = (const void **)(vtbl + 1);
|
|
|
|
DWORD i, j;
|
|
|
|
|
2009-06-03 16:52:06 +02:00
|
|
|
if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
|
|
|
|
{
|
2022-02-17 07:11:49 +01:00
|
|
|
FIXME( "%lu methods not supported\n", num );
|
2009-06-03 16:52:06 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-06-01 21:19:56 +02:00
|
|
|
for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
|
|
|
|
{
|
|
|
|
const struct thunk *block = method_blocks[i];
|
|
|
|
if (!block && !(block = allocate_block( i ))) return FALSE;
|
|
|
|
for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++, entry++)
|
|
|
|
if (*entry == (LPVOID)-1) *entry = &block[j];
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-05-27 13:04:33 +02:00
|
|
|
HRESULT StdProxy_Construct(REFIID riid,
|
|
|
|
LPUNKNOWN pUnkOuter,
|
|
|
|
const ProxyFileInfo *ProxyInfo,
|
|
|
|
int Index,
|
|
|
|
LPPSFACTORYBUFFER pPSFactory,
|
|
|
|
LPRPCPROXYBUFFER *ppProxy,
|
|
|
|
LPVOID *ppvObj)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
|
|
|
StdProxyImpl *This;
|
2006-01-20 16:15:25 +01:00
|
|
|
PCInterfaceName name = ProxyInfo->pNamesArray[Index];
|
|
|
|
CInterfaceProxyVtbl *vtbl = ProxyInfo->pProxyVtblList[Index];
|
2002-10-10 23:18:29 +02:00
|
|
|
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p,%p,%p,%p,%p) %s\n", pUnkOuter, vtbl, pPSFactory, ppProxy, ppvObj, name);
|
2002-10-10 23:18:29 +02:00
|
|
|
|
2006-01-20 16:15:25 +01:00
|
|
|
/* TableVersion = 2 means it is the stubless version of CInterfaceProxyVtbl */
|
|
|
|
if (ProxyInfo->TableVersion > 1) {
|
2009-06-01 21:19:56 +02:00
|
|
|
ULONG count = ProxyInfo->pStubVtblList[Index]->header.DispatchTableCount;
|
2004-04-19 21:24:03 +02:00
|
|
|
vtbl = (CInterfaceProxyVtbl *)((const void **)vtbl + 1);
|
2022-02-17 07:11:49 +01:00
|
|
|
TRACE("stubless vtbl %p: count=%ld\n", vtbl->Vtbl, count );
|
2009-06-01 21:19:56 +02:00
|
|
|
fill_stubless_table( (IUnknownVtbl *)vtbl->Vtbl, count );
|
2002-10-10 23:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-05-27 21:25:10 +02:00
|
|
|
if (!pUnkOuter) pUnkOuter = (IUnknown *)This;
|
2010-12-30 11:57:18 +01:00
|
|
|
This->IRpcProxyBuffer_iface.lpVtbl = &StdProxy_Vtbl;
|
2009-06-01 21:19:56 +02:00
|
|
|
This->PVtbl = vtbl->Vtbl;
|
2005-09-18 13:10:37 +02:00
|
|
|
/* one reference for the proxy */
|
|
|
|
This->RefCount = 1;
|
2002-10-10 23:18:29 +02:00
|
|
|
This->piid = vtbl->header.piid;
|
2009-06-03 16:42:50 +02:00
|
|
|
This->base_object = NULL;
|
|
|
|
This->base_proxy = NULL;
|
2002-10-10 23:18:29 +02:00
|
|
|
This->pUnkOuter = pUnkOuter;
|
2003-05-20 06:13:44 +02:00
|
|
|
This->name = name;
|
2002-10-10 23:18:29 +02:00
|
|
|
This->pPSFactory = pPSFactory;
|
|
|
|
This->pChannel = NULL;
|
2009-06-03 16:42:50 +02:00
|
|
|
|
|
|
|
if(ProxyInfo->pDelegatedIIDs && ProxyInfo->pDelegatedIIDs[Index])
|
|
|
|
{
|
|
|
|
HRESULT r = create_proxy( ProxyInfo->pDelegatedIIDs[Index], NULL,
|
|
|
|
&This->base_proxy, (void **)&This->base_object );
|
|
|
|
if (FAILED(r))
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-30 11:57:18 +01:00
|
|
|
*ppProxy = &This->IRpcProxyBuffer_iface;
|
2002-10-10 23:18:29 +02:00
|
|
|
*ppvObj = &This->PVtbl;
|
2009-05-27 21:25:10 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*ppvObj);
|
2002-10-10 23:18:29 +02:00
|
|
|
IPSFactoryBuffer_AddRef(pPSFactory);
|
|
|
|
|
2009-06-03 16:42:50 +02:00
|
|
|
TRACE( "iid=%s this %p proxy %p obj %p vtbl %p base proxy %p base obj %p\n",
|
|
|
|
debugstr_guid(riid), This, *ppProxy, *ppvObj, This->PVtbl, This->base_proxy, This->base_object );
|
2002-10-10 23:18:29 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-04 00:07:13 +01:00
|
|
|
HRESULT WINAPI StdProxy_QueryInterface(IRpcProxyBuffer *iface, REFIID riid, void **obj)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2010-12-30 11:57:18 +01:00
|
|
|
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
|
2002-10-10 23:18:29 +02:00
|
|
|
TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown,riid) ||
|
|
|
|
IsEqualGUID(This->piid,riid)) {
|
|
|
|
*obj = &This->PVtbl;
|
2006-08-29 22:16:44 +02:00
|
|
|
InterlockedIncrement(&This->RefCount);
|
2002-10-10 23:18:29 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualGUID(&IID_IRpcProxyBuffer,riid)) {
|
2010-12-30 11:57:18 +01:00
|
|
|
*obj = &This->IRpcProxyBuffer_iface;
|
2006-08-29 22:16:44 +02:00
|
|
|
InterlockedIncrement(&This->RefCount);
|
2002-10-10 23:18:29 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2018-11-04 00:07:13 +01:00
|
|
|
ULONG WINAPI StdProxy_AddRef(IRpcProxyBuffer *iface)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2010-12-30 11:57:18 +01:00
|
|
|
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
|
2002-10-10 23:18:29 +02:00
|
|
|
TRACE("(%p)->AddRef()\n",This);
|
|
|
|
|
2006-08-29 22:16:44 +02:00
|
|
|
return InterlockedIncrement(&This->RefCount);
|
2002-10-10 23:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI StdProxy_Release(LPRPCPROXYBUFFER iface)
|
|
|
|
{
|
2006-08-29 22:16:44 +02:00
|
|
|
ULONG refs;
|
2010-12-30 11:57:18 +01:00
|
|
|
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
|
2002-10-10 23:18:29 +02:00
|
|
|
TRACE("(%p)->Release()\n",This);
|
|
|
|
|
2006-08-29 22:16:44 +02:00
|
|
|
refs = InterlockedDecrement(&This->RefCount);
|
|
|
|
if (!refs)
|
2010-12-30 11:57:18 +01:00
|
|
|
{
|
|
|
|
if (This->pChannel)
|
|
|
|
IRpcProxyBuffer_Disconnect(&This->IRpcProxyBuffer_iface);
|
|
|
|
|
|
|
|
if (This->base_object) IUnknown_Release( This->base_object );
|
|
|
|
if (This->base_proxy) IRpcProxyBuffer_Release( This->base_proxy );
|
|
|
|
|
|
|
|
IPSFactoryBuffer_Release(This->pPSFactory);
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:16:44 +02:00
|
|
|
return refs;
|
2002-10-10 23:18:29 +02:00
|
|
|
}
|
|
|
|
|
2018-11-04 00:07:13 +01:00
|
|
|
HRESULT WINAPI StdProxy_Connect(IRpcProxyBuffer *iface, IRpcChannelBuffer *pChannel)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2010-12-30 11:57:18 +01:00
|
|
|
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
|
2002-10-10 23:18:29 +02:00
|
|
|
TRACE("(%p)->Connect(%p)\n",This,pChannel);
|
|
|
|
|
|
|
|
This->pChannel = pChannel;
|
2004-06-14 19:58:03 +02:00
|
|
|
IRpcChannelBuffer_AddRef(pChannel);
|
2009-06-03 16:42:50 +02:00
|
|
|
if (This->base_proxy) IRpcProxyBuffer_Connect( This->base_proxy, pChannel );
|
2002-10-10 23:18:29 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-04 00:07:13 +01:00
|
|
|
void WINAPI StdProxy_Disconnect(IRpcProxyBuffer *iface)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2010-12-30 11:57:18 +01:00
|
|
|
StdProxyImpl *This = impl_from_IRpcProxyBuffer(iface);
|
2002-10-10 23:18:29 +02:00
|
|
|
TRACE("(%p)->Disconnect()\n",This);
|
|
|
|
|
2009-06-03 16:42:50 +02:00
|
|
|
if (This->base_proxy) IRpcProxyBuffer_Disconnect( This->base_proxy );
|
|
|
|
|
2004-06-14 19:58:03 +02:00
|
|
|
IRpcChannelBuffer_Release(This->pChannel);
|
2002-10-10 23:18:29 +02:00
|
|
|
This->pChannel = NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IRpcProxyBufferVtbl StdProxy_Vtbl =
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
|
|
|
StdProxy_QueryInterface,
|
|
|
|
StdProxy_AddRef,
|
|
|
|
StdProxy_Release,
|
|
|
|
StdProxy_Connect,
|
|
|
|
StdProxy_Disconnect
|
|
|
|
};
|
|
|
|
|
2006-08-31 18:14:34 +02:00
|
|
|
static void StdProxy_GetChannel(LPVOID iface,
|
2006-08-29 22:12:42 +02:00
|
|
|
LPRPCCHANNELBUFFER *ppChannel)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2010-11-11 20:21:57 +01:00
|
|
|
StdProxyImpl *This = impl_from_proxy_obj( iface );
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p)->GetChannel(%p) %s\n",This,ppChannel,This->name);
|
2002-10-10 23:18:29 +02:00
|
|
|
|
|
|
|
*ppChannel = This->pChannel;
|
|
|
|
}
|
|
|
|
|
2006-08-31 18:14:34 +02:00
|
|
|
static void StdProxy_GetIID(LPVOID iface,
|
2006-08-29 22:12:42 +02:00
|
|
|
const IID **ppiid)
|
2002-10-10 23:18:29 +02:00
|
|
|
{
|
2010-11-11 20:21:57 +01:00
|
|
|
StdProxyImpl *This = impl_from_proxy_obj( iface );
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p)->GetIID(%p) %s\n",This,ppiid,This->name);
|
2002-10-10 23:18:29 +02:00
|
|
|
|
|
|
|
*ppiid = This->piid;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IUnknown_QueryInterface_Proxy(LPUNKNOWN iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvObj)
|
|
|
|
{
|
2010-11-11 20:21:57 +01:00
|
|
|
StdProxyImpl *This = impl_from_proxy_obj( iface );
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p)->QueryInterface(%s,%p) %s\n",This,debugstr_guid(riid),ppvObj,This->name);
|
2002-10-10 23:18:29 +02:00
|
|
|
return IUnknown_QueryInterface(This->pUnkOuter,riid,ppvObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI IUnknown_AddRef_Proxy(LPUNKNOWN iface)
|
|
|
|
{
|
2010-11-11 20:21:57 +01:00
|
|
|
StdProxyImpl *This = impl_from_proxy_obj( iface );
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p)->AddRef() %s\n",This,This->name);
|
2002-10-10 23:18:29 +02:00
|
|
|
return IUnknown_AddRef(This->pUnkOuter);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI IUnknown_Release_Proxy(LPUNKNOWN iface)
|
|
|
|
{
|
2010-11-11 20:21:57 +01:00
|
|
|
StdProxyImpl *This = impl_from_proxy_obj( iface );
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p)->Release() %s\n",This,This->name);
|
2002-10-10 23:18:29 +02:00
|
|
|
return IUnknown_Release(This->pUnkOuter);
|
|
|
|
}
|
2004-10-18 21:37:42 +02:00
|
|
|
|
2006-08-29 22:12:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NdrProxyInitialize [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
void WINAPI NdrProxyInitialize(void *This,
|
|
|
|
PRPC_MESSAGE pRpcMsg,
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg,
|
|
|
|
PMIDL_STUB_DESC pStubDescriptor,
|
|
|
|
unsigned int ProcNum)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p,%p,%p,%d)\n", This, pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
|
|
|
|
NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor, ProcNum);
|
2006-08-31 18:14:34 +02:00
|
|
|
StdProxy_GetChannel(This, &pStubMsg->pRpcChannelBuffer);
|
2019-05-21 06:30:53 +02:00
|
|
|
if (!pStubMsg->pRpcChannelBuffer)
|
|
|
|
RpcRaiseException(CO_E_OBJNOTCONNECTED);
|
2006-08-31 18:14:34 +02:00
|
|
|
IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
|
|
|
|
&pStubMsg->dwDestContext,
|
|
|
|
&pStubMsg->pvDestContext);
|
2006-08-29 22:12:42 +02:00
|
|
|
TRACE("channel=%p\n", pStubMsg->pRpcChannelBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrProxyGetBuffer [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
void WINAPI NdrProxyGetBuffer(void *This,
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
const IID *riid = NULL;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
|
|
|
pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
|
|
|
|
pStubMsg->dwStubPhase = PROXY_GETBUFFER;
|
2006-08-31 18:14:34 +02:00
|
|
|
StdProxy_GetIID(This, &riid);
|
2006-08-29 22:12:42 +02:00
|
|
|
hr = IRpcChannelBuffer_GetBuffer(pStubMsg->pRpcChannelBuffer,
|
|
|
|
(RPCOLEMESSAGE*)pStubMsg->RpcMsg,
|
|
|
|
riid);
|
2006-08-31 18:14:34 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
RpcRaiseException(hr);
|
|
|
|
return;
|
|
|
|
}
|
2008-01-08 13:02:55 +01:00
|
|
|
pStubMsg->fBufferValid = TRUE;
|
2006-08-29 22:12:42 +02:00
|
|
|
pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
|
|
|
|
pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart;
|
|
|
|
pStubMsg->dwStubPhase = PROXY_MARSHAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrProxySendReceive [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
void WINAPI NdrProxySendReceive(void *This,
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
{
|
|
|
|
ULONG Status = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
|
|
|
|
|
|
|
if (!pStubMsg->pRpcChannelBuffer)
|
|
|
|
{
|
|
|
|
WARN("Trying to use disconnected proxy %p\n", This);
|
|
|
|
RpcRaiseException(RPC_E_DISCONNECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
pStubMsg->dwStubPhase = PROXY_SENDRECEIVE;
|
2008-07-02 00:34:12 +02:00
|
|
|
/* avoid sending uninitialised parts of the buffer on the wire */
|
|
|
|
pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
|
2006-08-29 22:12:42 +02:00
|
|
|
hr = IRpcChannelBuffer_SendReceive(pStubMsg->pRpcChannelBuffer,
|
|
|
|
(RPCOLEMESSAGE*)pStubMsg->RpcMsg,
|
|
|
|
&Status);
|
|
|
|
pStubMsg->dwStubPhase = PROXY_UNMARSHAL;
|
|
|
|
pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
|
|
|
|
pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
|
|
|
|
pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
|
|
|
|
pStubMsg->Buffer = pStubMsg->BufferStart;
|
|
|
|
|
|
|
|
/* raise exception if call failed */
|
|
|
|
if (hr == RPC_S_CALL_FAILED) RpcRaiseException(*(DWORD*)pStubMsg->Buffer);
|
|
|
|
else if (FAILED(hr)) RpcRaiseException(hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrProxyFreeBuffer [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
void WINAPI NdrProxyFreeBuffer(void *This,
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", This, pStubMsg);
|
2008-01-08 13:02:55 +01:00
|
|
|
|
|
|
|
if (pStubMsg->fBufferValid)
|
|
|
|
{
|
|
|
|
IRpcChannelBuffer_FreeBuffer(pStubMsg->pRpcChannelBuffer,
|
|
|
|
(RPCOLEMESSAGE*)pStubMsg->RpcMsg);
|
|
|
|
pStubMsg->fBufferValid = TRUE;
|
|
|
|
}
|
2006-08-29 22:12:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrProxyErrorHandler [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI NdrProxyErrorHandler(DWORD dwExceptionCode)
|
|
|
|
{
|
2022-02-17 07:11:49 +01:00
|
|
|
WARN("(0x%08lx): a proxy call failed\n", dwExceptionCode);
|
2006-08-29 22:12:42 +02:00
|
|
|
|
|
|
|
if (FAILED(dwExceptionCode))
|
|
|
|
return dwExceptionCode;
|
|
|
|
else
|
|
|
|
return HRESULT_FROM_WIN32(dwExceptionCode);
|
|
|
|
}
|