2002-10-11 00:46:08 +02:00
|
|
|
/*
|
|
|
|
* COM stub (CStdStubBuffer) 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-11 00:46:08 +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-11 00:46:08 +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-11 00:46:08 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2006-06-10 13:33:40 +02:00
|
|
|
#include "excpt.h"
|
2002-10-11 00:46:08 +02:00
|
|
|
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2002-10-11 00:46:08 +02:00
|
|
|
#include "rpcproxy.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2006-06-10 13:33:40 +02:00
|
|
|
#include "wine/exception.h"
|
2002-10-11 00:46:08 +02:00
|
|
|
|
|
|
|
#include "cpsf.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
2006-11-11 15:56:45 +01:00
|
|
|
#define STUB_HEADER(This) (((const CInterfaceStubHeader*)((This)->lpVtbl))[-1])
|
2002-10-11 00:46:08 +02:00
|
|
|
|
2008-02-15 16:19:29 +01:00
|
|
|
static LONG WINAPI stub_filter(EXCEPTION_POINTERS *eptr)
|
2006-06-10 13:33:40 +02:00
|
|
|
{
|
2008-02-15 16:19:29 +01:00
|
|
|
if (eptr->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE)
|
2006-06-10 13:33:40 +02:00
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
|
2006-08-31 15:58:26 +02:00
|
|
|
static inline cstdstubbuffer_delegating_t *impl_from_delegating( IRpcStubBuffer *iface )
|
|
|
|
{
|
2015-04-21 10:22:04 +02:00
|
|
|
return CONTAINING_RECORD(iface, cstdstubbuffer_delegating_t, stub_buffer);
|
2006-08-31 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2009-05-27 13:04:33 +02:00
|
|
|
HRESULT CStdStubBuffer_Construct(REFIID riid,
|
|
|
|
LPUNKNOWN pUnkServer,
|
|
|
|
PCInterfaceName name,
|
|
|
|
CInterfaceStubVtbl *vtbl,
|
|
|
|
LPPSFACTORYBUFFER pPSFactory,
|
|
|
|
LPRPCSTUBBUFFER *ppStub)
|
2002-10-11 00:46:08 +02:00
|
|
|
{
|
|
|
|
CStdStubBuffer *This;
|
2006-08-23 15:53:24 +02:00
|
|
|
IUnknown *pvServer;
|
|
|
|
HRESULT r;
|
2003-05-20 06:13:44 +02:00
|
|
|
TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
|
2002-10-11 00:46:08 +02:00
|
|
|
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 stub creation\n");
|
|
|
|
return RPC_E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2006-08-23 15:53:24 +02:00
|
|
|
r = IUnknown_QueryInterface(pUnkServer, riid, (void**)&pvServer);
|
|
|
|
if(FAILED(r))
|
|
|
|
return r;
|
|
|
|
|
2002-10-11 00:46:08 +02:00
|
|
|
This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CStdStubBuffer));
|
2006-08-23 15:53:24 +02:00
|
|
|
if (!This) {
|
|
|
|
IUnknown_Release(pvServer);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2002-10-11 00:46:08 +02:00
|
|
|
|
|
|
|
This->lpVtbl = &vtbl->Vtbl;
|
|
|
|
This->RefCount = 1;
|
2006-08-23 15:53:24 +02:00
|
|
|
This->pvServerObject = pvServer;
|
2002-10-11 00:46:08 +02:00
|
|
|
This->pPSFactory = pPSFactory;
|
|
|
|
*ppStub = (LPRPCSTUBBUFFER)This;
|
|
|
|
|
|
|
|
IPSFactoryBuffer_AddRef(pPSFactory);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-31 15:58:26 +02:00
|
|
|
static CRITICAL_SECTION delegating_vtbl_section;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &delegating_vtbl_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": delegating_vtbl_section") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION delegating_vtbl_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD ref;
|
2007-12-03 17:09:05 +01:00
|
|
|
DWORD size;
|
2006-08-31 15:58:26 +02:00
|
|
|
IUnknownVtbl vtbl;
|
2007-12-03 17:09:05 +01:00
|
|
|
/* remaining entries in vtbl */
|
2006-08-31 15:58:26 +02:00
|
|
|
} ref_counted_vtbl;
|
|
|
|
|
2009-06-01 16:55:14 +02:00
|
|
|
static ref_counted_vtbl *current_vtbl;
|
2006-08-31 15:58:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI delegating_QueryInterface(IUnknown *pUnk, REFIID iid, void **ppv)
|
|
|
|
{
|
2009-02-16 09:54:10 +01:00
|
|
|
*ppv = pUnk;
|
2006-08-31 15:58:26 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI delegating_AddRef(IUnknown *pUnk)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI delegating_Release(IUnknown *pUnk)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The idea here is to replace the first param on the stack
|
|
|
|
ie. This (which will point to cstdstubbuffer_delegating_t)
|
|
|
|
with This->stub_buffer.pvServerObject and then jump to the
|
|
|
|
relevant offset in This->stub_buffer.pvServerObject's vtbl.
|
|
|
|
*/
|
2010-04-07 12:25:49 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
|
2006-08-31 15:58:26 +02:00
|
|
|
#include "pshpack1.h"
|
|
|
|
typedef struct {
|
2010-04-07 12:25:49 +02:00
|
|
|
BYTE mov1[4]; /* mov 0x4(%esp),%eax 8b 44 24 04 */
|
|
|
|
BYTE mov2[3]; /* mov 0x10(%eax),%eax 8b 40 10 */
|
|
|
|
BYTE mov3[4]; /* mov %eax,0x4(%esp) 89 44 24 04 */
|
|
|
|
BYTE mov4[2]; /* mov (%eax),%eax 8b 00 */
|
|
|
|
BYTE mov5[2]; /* jmp *offset(%eax) ff a0 offset */
|
|
|
|
DWORD offset;
|
|
|
|
BYTE pad[1]; /* nop 90 */
|
2006-08-31 15:58:26 +02:00
|
|
|
} vtbl_method_t;
|
|
|
|
#include "poppack.h"
|
|
|
|
|
2010-04-07 12:25:49 +02:00
|
|
|
static const BYTE opcodes[20] = { 0x8b, 0x44, 0x24, 0x04, 0x8b, 0x40, 0x10, 0x89, 0x44, 0x24, 0x04,
|
|
|
|
0x8b, 0x00, 0xff, 0xa0, 0, 0, 0, 0, 0x90 };
|
|
|
|
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
|
|
|
|
#include "pshpack1.h"
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE mov1[4]; /* movq 0x20(%rcx),%rcx 48 8b 49 20 */
|
|
|
|
BYTE mov2[3]; /* movq (%rcx),%rax 48 8b 01 */
|
|
|
|
BYTE jmp[2]; /* jmp *offset(%rax) ff a0 offset */
|
|
|
|
DWORD offset;
|
|
|
|
BYTE pad[3]; /* lea 0x0(%rsi),%rsi 48 8d 36 */
|
|
|
|
} vtbl_method_t;
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
static const BYTE opcodes[16] = { 0x48, 0x8b, 0x49, 0x20, 0x48, 0x8b, 0x01,
|
|
|
|
0xff, 0xa0, 0, 0, 0, 0, 0x48, 0x8d, 0x36 };
|
2018-11-13 16:08:06 +01:00
|
|
|
#elif defined(__arm__)
|
|
|
|
|
|
|
|
static const DWORD opcodes[] =
|
|
|
|
{
|
|
|
|
0xe52d4004, /* push {r4} */
|
|
|
|
0xe5900010, /* ldr r0, [r0, #16] */
|
|
|
|
0xe5904000, /* ldr r4, [r0] */
|
|
|
|
0xe59fc008, /* ldr ip, [pc, #8] */
|
|
|
|
0xe08cc004, /* add ip, ip, r4 */
|
|
|
|
0xe49d4004, /* pop {r4} */
|
|
|
|
0xe59cf000 /* ldr pc, [ip] */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD opcodes[ARRAY_SIZE(opcodes)];
|
|
|
|
DWORD offset;
|
|
|
|
} vtbl_method_t;
|
|
|
|
|
2019-09-27 12:39:49 +02:00
|
|
|
#elif defined(__aarch64__)
|
|
|
|
|
|
|
|
static const DWORD opcodes[] =
|
|
|
|
{
|
|
|
|
0xf9401000, /* ldr x0, [x0,#32] */
|
|
|
|
0xf9400010, /* ldr x16, [x0] */
|
|
|
|
0x18000071, /* ldr w17, offset */
|
|
|
|
0xf8716a10, /* ldr x16, [x16,x17] */
|
|
|
|
0xd61f0200 /* br x16 */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD opcodes[ARRAY_SIZE(opcodes)];
|
|
|
|
DWORD offset;
|
|
|
|
} vtbl_method_t;
|
|
|
|
|
2010-04-07 12:25:49 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
#warning You must implement delegated proxies/stubs for your CPU
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
DWORD offset;
|
|
|
|
} vtbl_method_t;
|
|
|
|
static const BYTE opcodes[1];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-06-01 16:40:44 +02:00
|
|
|
#define BLOCK_SIZE 1024
|
|
|
|
#define MAX_BLOCKS 64 /* 64k methods should be enough for anybody */
|
|
|
|
|
|
|
|
static const vtbl_method_t *method_blocks[MAX_BLOCKS];
|
|
|
|
|
|
|
|
static const vtbl_method_t *allocate_block( unsigned int num )
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
2009-06-01 16:40:44 +02:00
|
|
|
unsigned int i;
|
|
|
|
vtbl_method_t *prev, *block;
|
2014-06-21 18:44:57 +02:00
|
|
|
DWORD oldprot;
|
2009-06-01 16:40:44 +02:00
|
|
|
|
|
|
|
block = VirtualAlloc( NULL, BLOCK_SIZE * sizeof(*block),
|
|
|
|
MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
|
|
|
|
if (!block) return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < BLOCK_SIZE; i++)
|
|
|
|
{
|
2010-04-07 12:25:49 +02:00
|
|
|
memcpy( &block[i], opcodes, sizeof(opcodes) );
|
|
|
|
block[i].offset = (BLOCK_SIZE * num + i + 3) * sizeof(void *);
|
2009-06-01 16:40:44 +02:00
|
|
|
}
|
2014-06-21 18:44:57 +02:00
|
|
|
VirtualProtect( block, BLOCK_SIZE * sizeof(*block), PAGE_EXECUTE_READ, &oldprot );
|
2009-06-01 16:40:44 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL fill_delegated_stub_table(IUnknownVtbl *vtbl, DWORD num)
|
|
|
|
{
|
|
|
|
const void **entry = (const void **)(vtbl + 1);
|
|
|
|
DWORD i, j;
|
2006-08-31 15:58:26 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2006-08-31 15:58:26 +02:00
|
|
|
vtbl->QueryInterface = delegating_QueryInterface;
|
|
|
|
vtbl->AddRef = delegating_AddRef;
|
|
|
|
vtbl->Release = delegating_Release;
|
2009-06-01 16:40:44 +02:00
|
|
|
for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
2009-06-01 16:40:44 +02:00
|
|
|
const vtbl_method_t *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++ = &block[j];
|
2006-08-31 15:58:26 +02:00
|
|
|
}
|
2009-06-01 16:40:44 +02:00
|
|
|
return TRUE;
|
2006-08-31 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2009-06-03 16:42:50 +02:00
|
|
|
BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num)
|
|
|
|
{
|
|
|
|
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-03 16:42:50 +02:00
|
|
|
vtbl->QueryInterface = IUnknown_QueryInterface_Proxy;
|
|
|
|
vtbl->AddRef = IUnknown_AddRef_Proxy;
|
|
|
|
vtbl->Release = IUnknown_Release_Proxy;
|
|
|
|
for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
|
|
|
|
{
|
|
|
|
const vtbl_method_t *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) *entry = &block[j];
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-10 01:01:58 +01:00
|
|
|
IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
2009-06-01 16:55:14 +02:00
|
|
|
IUnknownVtbl *ret;
|
|
|
|
|
|
|
|
if (num_methods < 256) num_methods = 256; /* avoid frequent reallocations */
|
2006-08-31 15:58:26 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&delegating_vtbl_section);
|
2009-06-01 16:55:14 +02:00
|
|
|
|
|
|
|
if(!current_vtbl || num_methods > current_vtbl->size)
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
2009-06-01 16:55:14 +02:00
|
|
|
ref_counted_vtbl *table = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
FIELD_OFFSET(ref_counted_vtbl, vtbl) + num_methods * sizeof(void*));
|
|
|
|
if (!table)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&delegating_vtbl_section);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
table->ref = 0;
|
|
|
|
table->size = num_methods;
|
|
|
|
fill_delegated_stub_table(&table->vtbl, num_methods);
|
|
|
|
|
|
|
|
if (current_vtbl && current_vtbl->ref == 0)
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
|
|
|
TRACE("freeing old table\n");
|
2009-06-01 16:55:14 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, current_vtbl);
|
2006-08-31 15:58:26 +02:00
|
|
|
}
|
2009-06-01 16:55:14 +02:00
|
|
|
current_vtbl = table;
|
2006-08-31 15:58:26 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 16:55:14 +02:00
|
|
|
current_vtbl->ref++;
|
|
|
|
ret = ¤t_vtbl->vtbl;
|
2006-08-31 15:58:26 +02:00
|
|
|
LeaveCriticalSection(&delegating_vtbl_section);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-10 01:01:58 +01:00
|
|
|
void release_delegating_vtbl(IUnknownVtbl *vtbl)
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
|
|
|
ref_counted_vtbl *table = (ref_counted_vtbl*)((DWORD *)vtbl - 1);
|
|
|
|
|
|
|
|
EnterCriticalSection(&delegating_vtbl_section);
|
|
|
|
table->ref--;
|
2022-02-17 07:11:49 +01:00
|
|
|
TRACE("ref now %ld\n", table->ref);
|
2009-06-01 16:55:14 +02:00
|
|
|
if(table->ref == 0 && table != current_vtbl)
|
2006-08-31 15:58:26 +02:00
|
|
|
{
|
|
|
|
TRACE("... and we're not current so free'ing\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, table);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&delegating_vtbl_section);
|
|
|
|
}
|
|
|
|
|
2009-05-27 13:04:33 +02:00
|
|
|
HRESULT CStdStubBuffer_Delegating_Construct(REFIID riid,
|
|
|
|
LPUNKNOWN pUnkServer,
|
|
|
|
PCInterfaceName name,
|
|
|
|
CInterfaceStubVtbl *vtbl,
|
|
|
|
REFIID delegating_iid,
|
|
|
|
LPPSFACTORYBUFFER pPSFactory,
|
|
|
|
LPRPCSTUBBUFFER *ppStub)
|
2006-08-31 16:40:05 +02:00
|
|
|
{
|
|
|
|
cstdstubbuffer_delegating_t *This;
|
|
|
|
IUnknown *pvServer;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
|
|
|
|
TRACE("iid=%s delegating to %s\n", debugstr_guid(vtbl->header.piid), debugstr_guid(delegating_iid));
|
|
|
|
TRACE("vtbl=%p\n", &vtbl->Vtbl);
|
|
|
|
|
|
|
|
if (!IsEqualGUID(vtbl->header.piid, riid))
|
|
|
|
{
|
|
|
|
ERR("IID mismatch during stub creation\n");
|
|
|
|
return RPC_E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IUnknown_QueryInterface(pUnkServer, riid, (void**)&pvServer);
|
|
|
|
if(FAILED(r)) return r;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
|
|
|
|
if (!This)
|
|
|
|
{
|
|
|
|
IUnknown_Release(pvServer);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2009-06-01 16:55:14 +02:00
|
|
|
This->base_obj = get_delegating_vtbl( vtbl->header.DispatchTableCount );
|
2006-08-31 16:40:05 +02:00
|
|
|
r = create_stub(delegating_iid, (IUnknown*)&This->base_obj, &This->base_stub);
|
|
|
|
if(FAILED(r))
|
|
|
|
{
|
|
|
|
release_delegating_vtbl(This->base_obj);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
IUnknown_Release(pvServer);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->stub_buffer.lpVtbl = &vtbl->Vtbl;
|
|
|
|
This->stub_buffer.RefCount = 1;
|
|
|
|
This->stub_buffer.pvServerObject = pvServer;
|
|
|
|
This->stub_buffer.pPSFactory = pPSFactory;
|
|
|
|
*ppStub = (LPRPCSTUBBUFFER)&This->stub_buffer;
|
|
|
|
|
|
|
|
IPSFactoryBuffer_AddRef(pPSFactory);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-10-11 00:46:08 +02:00
|
|
|
HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *obj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
|
|
|
|
|
2006-08-30 15:57:20 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualIID(&IID_IRpcStubBuffer, riid))
|
|
|
|
{
|
2012-08-14 13:34:56 +02:00
|
|
|
IRpcStubBuffer_AddRef(iface);
|
2006-08-30 15:57:20 +02:00
|
|
|
*obj = iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2006-08-30 15:57:20 +02:00
|
|
|
*obj = NULL;
|
2002-10-11 00:46:08 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->AddRef()\n",This);
|
2006-08-30 16:16:29 +02:00
|
|
|
return InterlockedIncrement(&This->RefCount);
|
2002-10-11 00:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface,
|
|
|
|
LPPSFACTORYBUFFER pPSF)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2006-08-30 16:16:29 +02:00
|
|
|
ULONG refs;
|
|
|
|
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->Release()\n",This);
|
|
|
|
|
2006-08-30 16:16:29 +02:00
|
|
|
refs = InterlockedDecrement(&This->RefCount);
|
|
|
|
if (!refs)
|
|
|
|
{
|
2006-08-30 18:20:17 +02:00
|
|
|
/* test_Release shows that native doesn't call Disconnect here.
|
|
|
|
We'll leave it in for the time being. */
|
2005-07-19 21:12:54 +02:00
|
|
|
IRpcStubBuffer_Disconnect(iface);
|
2006-08-30 18:20:17 +02:00
|
|
|
|
|
|
|
IPSFactoryBuffer_Release(pPSF);
|
2002-10-11 00:46:08 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
}
|
2006-08-30 16:16:29 +02:00
|
|
|
return refs;
|
2002-10-11 00:46:08 +02:00
|
|
|
}
|
|
|
|
|
2005-10-26 15:56:00 +02:00
|
|
|
ULONG WINAPI NdrCStdStubBuffer2_Release(LPRPCSTUBBUFFER iface,
|
|
|
|
LPPSFACTORYBUFFER pPSF)
|
|
|
|
{
|
2006-08-31 16:40:05 +02:00
|
|
|
cstdstubbuffer_delegating_t *This = impl_from_delegating( iface );
|
|
|
|
ULONG refs;
|
|
|
|
|
|
|
|
TRACE("(%p)->Release()\n", This);
|
|
|
|
|
|
|
|
refs = InterlockedDecrement(&This->stub_buffer.RefCount);
|
|
|
|
if (!refs)
|
|
|
|
{
|
|
|
|
/* Just like NdrCStdStubBuffer_Release, we shouldn't call
|
|
|
|
Disconnect here */
|
|
|
|
IRpcStubBuffer_Disconnect((IRpcStubBuffer *)&This->stub_buffer);
|
|
|
|
|
|
|
|
IRpcStubBuffer_Release(This->base_stub);
|
|
|
|
release_delegating_vtbl(This->base_obj);
|
|
|
|
|
|
|
|
IPSFactoryBuffer_Release(pPSF);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refs;
|
2005-10-26 15:56:00 +02:00
|
|
|
}
|
|
|
|
|
2002-10-11 00:46:08 +02:00
|
|
|
HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface,
|
|
|
|
LPUNKNOWN lpUnkServer)
|
|
|
|
{
|
2006-08-23 17:37:48 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
|
|
|
HRESULT r;
|
|
|
|
IUnknown *new = NULL;
|
|
|
|
|
|
|
|
TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
|
|
|
|
|
|
|
|
r = IUnknown_QueryInterface(lpUnkServer, STUB_HEADER(This).piid, (void**)&new);
|
|
|
|
new = InterlockedExchangePointer((void**)&This->pvServerObject, new);
|
|
|
|
if(new)
|
|
|
|
IUnknown_Release(new);
|
|
|
|
return r;
|
2002-10-11 00:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
2006-08-23 17:36:43 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
|
|
|
IUnknown *old;
|
|
|
|
TRACE("(%p)->Disconnect()\n",This);
|
|
|
|
|
|
|
|
old = InterlockedExchangePointer((void**)&This->pvServerObject, NULL);
|
|
|
|
|
|
|
|
if(old)
|
|
|
|
IUnknown_Release(old);
|
2002-10-11 00:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface,
|
|
|
|
PRPCOLEMESSAGE pMsg,
|
|
|
|
LPRPCCHANNELBUFFER pChannel)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
DWORD dwPhase = STUB_UNMARSHAL;
|
2006-06-10 13:33:40 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel);
|
|
|
|
|
2006-06-10 13:33:40 +02:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
if (STUB_HEADER(This).pDispatchTable)
|
|
|
|
STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
|
|
|
|
else /* pure interpreted */
|
|
|
|
NdrStubCall2(iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
|
|
|
|
}
|
|
|
|
__EXCEPT(stub_filter)
|
|
|
|
{
|
|
|
|
DWORD dwExceptionCode = GetExceptionCode();
|
2022-02-17 07:11:49 +01:00
|
|
|
WARN("a stub call failed with exception 0x%08lx (%ld)\n", dwExceptionCode, dwExceptionCode);
|
2006-06-10 13:33:40 +02:00
|
|
|
if (FAILED(dwExceptionCode))
|
|
|
|
hr = dwExceptionCode;
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(dwExceptionCode);
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
|
|
|
|
return hr;
|
2002-10-11 00:46:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface,
|
|
|
|
REFIID riid)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid));
|
|
|
|
return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->CountRefs()\n",This);
|
|
|
|
return This->RefCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
|
|
|
|
LPVOID *ppv)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface,
|
|
|
|
LPVOID pv)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
2002-10-11 00:46:08 +02:00
|
|
|
TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);
|
|
|
|
}
|
2005-11-29 10:42:04 +01:00
|
|
|
|
2006-01-30 14:56:07 +01:00
|
|
|
const IRpcStubBufferVtbl CStdStubBuffer_Vtbl =
|
|
|
|
{
|
|
|
|
CStdStubBuffer_QueryInterface,
|
|
|
|
CStdStubBuffer_AddRef,
|
|
|
|
NULL,
|
|
|
|
CStdStubBuffer_Connect,
|
|
|
|
CStdStubBuffer_Disconnect,
|
|
|
|
CStdStubBuffer_Invoke,
|
|
|
|
CStdStubBuffer_IsIIDSupported,
|
|
|
|
CStdStubBuffer_CountRefs,
|
|
|
|
CStdStubBuffer_DebugServerQueryInterface,
|
|
|
|
CStdStubBuffer_DebugServerRelease
|
|
|
|
};
|
|
|
|
|
2006-08-31 16:40:05 +02:00
|
|
|
static HRESULT WINAPI CStdStubBuffer_Delegating_Connect(LPRPCSTUBBUFFER iface,
|
|
|
|
LPUNKNOWN lpUnkServer)
|
|
|
|
{
|
|
|
|
cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
|
|
|
|
HRESULT r;
|
|
|
|
TRACE("(%p)->Connect(%p)\n", This, lpUnkServer);
|
|
|
|
|
|
|
|
r = CStdStubBuffer_Connect(iface, lpUnkServer);
|
|
|
|
if(SUCCEEDED(r))
|
|
|
|
r = IRpcStubBuffer_Connect(This->base_stub, (IUnknown*)&This->base_obj);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI CStdStubBuffer_Delegating_Disconnect(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
|
|
|
cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
|
|
|
|
TRACE("(%p)->Disconnect()\n", This);
|
|
|
|
|
|
|
|
IRpcStubBuffer_Disconnect(This->base_stub);
|
|
|
|
CStdStubBuffer_Disconnect(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CStdStubBuffer_Delegating_CountRefs(LPRPCSTUBBUFFER iface)
|
|
|
|
{
|
|
|
|
cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
|
|
|
|
ULONG ret;
|
|
|
|
TRACE("(%p)->CountRefs()\n", This);
|
|
|
|
|
|
|
|
ret = CStdStubBuffer_CountRefs(iface);
|
|
|
|
ret += IRpcStubBuffer_CountRefs(This->base_stub);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IRpcStubBufferVtbl CStdStubBuffer_Delegating_Vtbl =
|
|
|
|
{
|
|
|
|
CStdStubBuffer_QueryInterface,
|
|
|
|
CStdStubBuffer_AddRef,
|
|
|
|
NULL,
|
|
|
|
CStdStubBuffer_Delegating_Connect,
|
|
|
|
CStdStubBuffer_Delegating_Disconnect,
|
|
|
|
CStdStubBuffer_Invoke,
|
|
|
|
CStdStubBuffer_IsIIDSupported,
|
|
|
|
CStdStubBuffer_Delegating_CountRefs,
|
|
|
|
CStdStubBuffer_DebugServerQueryInterface,
|
|
|
|
CStdStubBuffer_DebugServerRelease
|
|
|
|
};
|
|
|
|
|
2005-11-29 10:42:04 +01:00
|
|
|
const MIDL_SERVER_INFO *CStdStubBuffer_GetServerInfo(IRpcStubBuffer *iface)
|
|
|
|
{
|
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
|
|
|
return STUB_HEADER(This).pServerInfo;
|
|
|
|
}
|
2006-08-23 14:56:04 +02:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* NdrStubForwardingFunction [RPCRT4.@]
|
|
|
|
*/
|
2006-08-31 15:58:26 +02:00
|
|
|
void __RPC_STUB NdrStubForwardingFunction( IRpcStubBuffer *iface, IRpcChannelBuffer *pChannel,
|
2006-08-23 14:56:04 +02:00
|
|
|
PRPC_MESSAGE pMsg, DWORD *pdwStubPhase )
|
|
|
|
{
|
2006-08-31 16:40:05 +02:00
|
|
|
/* Note pMsg is passed intact since RPCOLEMESSAGE is basically a RPC_MESSAGE. */
|
2006-08-23 14:56:04 +02:00
|
|
|
|
2006-08-31 15:58:26 +02:00
|
|
|
cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
|
|
|
|
HRESULT r = IRpcStubBuffer_Invoke(This->base_stub, (RPCOLEMESSAGE*)pMsg, pChannel);
|
2006-08-23 14:56:04 +02:00
|
|
|
if(FAILED(r)) RpcRaiseException(r);
|
|
|
|
return;
|
|
|
|
}
|
2006-08-29 22:12:42 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrStubInitialize [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg,
|
|
|
|
PMIDL_STUB_DESC pStubDescriptor,
|
|
|
|
LPRPCCHANNELBUFFER pRpcChannelBuffer)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
|
|
|
|
NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
|
|
|
|
pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
|
2007-12-03 17:08:31 +01:00
|
|
|
IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
|
|
|
|
&pStubMsg->dwDestContext,
|
|
|
|
&pStubMsg->pvDestContext);
|
2006-08-29 22:12:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NdrStubGetBuffer [RPCRT4.@]
|
|
|
|
*/
|
2006-08-29 22:14:42 +02:00
|
|
|
void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER iface,
|
2006-08-29 22:12:42 +02:00
|
|
|
LPRPCCHANNELBUFFER pRpcChannelBuffer,
|
|
|
|
PMIDL_STUB_MESSAGE pStubMsg)
|
|
|
|
{
|
2006-08-29 22:14:42 +02:00
|
|
|
CStdStubBuffer *This = (CStdStubBuffer *)iface;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", This, pRpcChannelBuffer, pStubMsg);
|
|
|
|
|
2006-08-29 22:12:42 +02:00
|
|
|
pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
|
2006-08-29 22:14:42 +02:00
|
|
|
hr = IRpcChannelBuffer_GetBuffer(pRpcChannelBuffer,
|
|
|
|
(RPCOLEMESSAGE *)pStubMsg->RpcMsg, STUB_HEADER(This).piid);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
RpcRaiseException(hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-13 17:11:37 +01:00
|
|
|
pStubMsg->Buffer = pStubMsg->RpcMsg->Buffer;
|
2006-08-29 22:12:42 +02:00
|
|
|
}
|