* Sync up to trunk HEAD (r62502).
[reactos.git] / dll / win32 / rpcrt4 / cstub.c
1 /*
2 * COM stub (CStdStubBuffer) implementation
3 *
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2009 Alexandre Julliard
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "precomp.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(ole);
25
26 #define STUB_HEADER(This) (((const CInterfaceStubHeader*)((This)->lpVtbl))[-1])
27
28 static LONG WINAPI stub_filter(EXCEPTION_POINTERS *eptr)
29 {
30 if (eptr->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE)
31 return EXCEPTION_CONTINUE_SEARCH;
32 return EXCEPTION_EXECUTE_HANDLER;
33 }
34
35 typedef struct
36 {
37 IUnknownVtbl *base_obj;
38 IRpcStubBuffer *base_stub;
39 CStdStubBuffer stub_buffer;
40 } cstdstubbuffer_delegating_t;
41
42 static inline cstdstubbuffer_delegating_t *impl_from_delegating( IRpcStubBuffer *iface )
43 {
44 return (cstdstubbuffer_delegating_t*)((char *)iface - FIELD_OFFSET(cstdstubbuffer_delegating_t, stub_buffer));
45 }
46
47 HRESULT CStdStubBuffer_Construct(REFIID riid,
48 LPUNKNOWN pUnkServer,
49 PCInterfaceName name,
50 CInterfaceStubVtbl *vtbl,
51 LPPSFACTORYBUFFER pPSFactory,
52 LPRPCSTUBBUFFER *ppStub)
53 {
54 CStdStubBuffer *This;
55 IUnknown *pvServer;
56 HRESULT r;
57 TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
58 TRACE("iid=%s\n", debugstr_guid(vtbl->header.piid));
59 TRACE("vtbl=%p\n", &vtbl->Vtbl);
60
61 if (!IsEqualGUID(vtbl->header.piid, riid)) {
62 ERR("IID mismatch during stub creation\n");
63 return RPC_E_UNEXPECTED;
64 }
65
66 r = IUnknown_QueryInterface(pUnkServer, riid, (void**)&pvServer);
67 if(FAILED(r))
68 return r;
69
70 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(CStdStubBuffer));
71 if (!This) {
72 IUnknown_Release(pvServer);
73 return E_OUTOFMEMORY;
74 }
75
76 This->lpVtbl = &vtbl->Vtbl;
77 This->RefCount = 1;
78 This->pvServerObject = pvServer;
79 This->pPSFactory = pPSFactory;
80 *ppStub = (LPRPCSTUBBUFFER)This;
81
82 IPSFactoryBuffer_AddRef(pPSFactory);
83 return S_OK;
84 }
85
86 static CRITICAL_SECTION delegating_vtbl_section;
87 static CRITICAL_SECTION_DEBUG critsect_debug =
88 {
89 0, 0, &delegating_vtbl_section,
90 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
91 0, 0, { (DWORD_PTR)(__FILE__ ": delegating_vtbl_section") }
92 };
93 static CRITICAL_SECTION delegating_vtbl_section = { &critsect_debug, -1, 0, 0, 0, 0 };
94
95 typedef struct
96 {
97 DWORD ref;
98 DWORD size;
99 IUnknownVtbl vtbl;
100 /* remaining entries in vtbl */
101 } ref_counted_vtbl;
102
103 static ref_counted_vtbl *current_vtbl;
104
105
106 static HRESULT WINAPI delegating_QueryInterface(IUnknown *pUnk, REFIID iid, void **ppv)
107 {
108 *ppv = pUnk;
109 return S_OK;
110 }
111
112 static ULONG WINAPI delegating_AddRef(IUnknown *pUnk)
113 {
114 return 1;
115 }
116
117 static ULONG WINAPI delegating_Release(IUnknown *pUnk)
118 {
119 return 1;
120 }
121
122 /* The idea here is to replace the first param on the stack
123 ie. This (which will point to cstdstubbuffer_delegating_t)
124 with This->stub_buffer.pvServerObject and then jump to the
125 relevant offset in This->stub_buffer.pvServerObject's vtbl.
126 */
127 #ifdef __i386__
128
129 #include "pshpack1.h"
130 typedef struct {
131 BYTE mov1[4]; /* mov 0x4(%esp),%eax 8b 44 24 04 */
132 BYTE mov2[3]; /* mov 0x10(%eax),%eax 8b 40 10 */
133 BYTE mov3[4]; /* mov %eax,0x4(%esp) 89 44 24 04 */
134 BYTE mov4[2]; /* mov (%eax),%eax 8b 00 */
135 BYTE mov5[2]; /* jmp *offset(%eax) ff a0 offset */
136 DWORD offset;
137 BYTE pad[1]; /* nop 90 */
138 } vtbl_method_t;
139 #include "poppack.h"
140
141 static const BYTE opcodes[20] = { 0x8b, 0x44, 0x24, 0x04, 0x8b, 0x40, 0x10, 0x89, 0x44, 0x24, 0x04,
142 0x8b, 0x00, 0xff, 0xa0, 0, 0, 0, 0, 0x90 };
143
144 #elif defined(__x86_64__)
145
146 #include "pshpack1.h"
147 typedef struct
148 {
149 BYTE mov1[4]; /* movq 0x20(%rcx),%rcx 48 8b 49 20 */
150 BYTE mov2[3]; /* movq (%rcx),%rax 48 8b 01 */
151 BYTE jmp[2]; /* jmp *offset(%rax) ff a0 offset */
152 DWORD offset;
153 BYTE pad[3]; /* lea 0x0(%rsi),%rsi 48 8d 36 */
154 } vtbl_method_t;
155 #include "poppack.h"
156
157 static const BYTE opcodes[16] = { 0x48, 0x8b, 0x49, 0x20, 0x48, 0x8b, 0x01,
158 0xff, 0xa0, 0, 0, 0, 0, 0x48, 0x8d, 0x36 };
159 #else
160
161 #warning You must implement delegated proxies/stubs for your CPU
162 typedef struct
163 {
164 DWORD offset;
165 } vtbl_method_t;
166 static const BYTE opcodes[1];
167
168 #endif
169
170 #define BLOCK_SIZE 1024
171 #define MAX_BLOCKS 64 /* 64k methods should be enough for anybody */
172
173 static const vtbl_method_t *method_blocks[MAX_BLOCKS];
174
175 static const vtbl_method_t *allocate_block( unsigned int num )
176 {
177 unsigned int i;
178 vtbl_method_t *prev, *block;
179
180 block = VirtualAlloc( NULL, BLOCK_SIZE * sizeof(*block),
181 MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
182 if (!block) return NULL;
183
184 for (i = 0; i < BLOCK_SIZE; i++)
185 {
186 memcpy( &block[i], opcodes, sizeof(opcodes) );
187 block[i].offset = (BLOCK_SIZE * num + i + 3) * sizeof(void *);
188 }
189 VirtualProtect( block, BLOCK_SIZE * sizeof(*block), PAGE_EXECUTE_READ, NULL );
190 prev = InterlockedCompareExchangePointer( (void **)&method_blocks[num], block, NULL );
191 if (prev) /* someone beat us to it */
192 {
193 VirtualFree( block, 0, MEM_RELEASE );
194 block = prev;
195 }
196 return block;
197 }
198
199 static BOOL fill_delegated_stub_table(IUnknownVtbl *vtbl, DWORD num)
200 {
201 const void **entry = (const void **)(vtbl + 1);
202 DWORD i, j;
203
204 if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
205 {
206 FIXME( "%u methods not supported\n", num );
207 return FALSE;
208 }
209 vtbl->QueryInterface = delegating_QueryInterface;
210 vtbl->AddRef = delegating_AddRef;
211 vtbl->Release = delegating_Release;
212 for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
213 {
214 const vtbl_method_t *block = method_blocks[i];
215 if (!block && !(block = allocate_block( i ))) return FALSE;
216 for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++) *entry++ = &block[j];
217 }
218 return TRUE;
219 }
220
221 BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num)
222 {
223 const void **entry = (const void **)(vtbl + 1);
224 DWORD i, j;
225
226 if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
227 {
228 FIXME( "%u methods not supported\n", num );
229 return FALSE;
230 }
231 vtbl->QueryInterface = IUnknown_QueryInterface_Proxy;
232 vtbl->AddRef = IUnknown_AddRef_Proxy;
233 vtbl->Release = IUnknown_Release_Proxy;
234 for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
235 {
236 const vtbl_method_t *block = method_blocks[i];
237 if (!block && !(block = allocate_block( i ))) return FALSE;
238 for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++, entry++)
239 if (!*entry) *entry = &block[j];
240 }
241 return TRUE;
242 }
243
244 static IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
245 {
246 IUnknownVtbl *ret;
247
248 if (num_methods < 256) num_methods = 256; /* avoid frequent reallocations */
249
250 EnterCriticalSection(&delegating_vtbl_section);
251
252 if(!current_vtbl || num_methods > current_vtbl->size)
253 {
254 ref_counted_vtbl *table = HeapAlloc(GetProcessHeap(), 0,
255 FIELD_OFFSET(ref_counted_vtbl, vtbl) + num_methods * sizeof(void*));
256 if (!table)
257 {
258 LeaveCriticalSection(&delegating_vtbl_section);
259 return NULL;
260 }
261
262 table->ref = 0;
263 table->size = num_methods;
264 fill_delegated_stub_table(&table->vtbl, num_methods);
265
266 if (current_vtbl && current_vtbl->ref == 0)
267 {
268 TRACE("freeing old table\n");
269 HeapFree(GetProcessHeap(), 0, current_vtbl);
270 }
271 current_vtbl = table;
272 }
273
274 current_vtbl->ref++;
275 ret = &current_vtbl->vtbl;
276 LeaveCriticalSection(&delegating_vtbl_section);
277 return ret;
278 }
279
280 static void release_delegating_vtbl(IUnknownVtbl *vtbl)
281 {
282 ref_counted_vtbl *table = (ref_counted_vtbl*)((DWORD *)vtbl - 1);
283
284 EnterCriticalSection(&delegating_vtbl_section);
285 table->ref--;
286 TRACE("ref now %d\n", table->ref);
287 if(table->ref == 0 && table != current_vtbl)
288 {
289 TRACE("... and we're not current so free'ing\n");
290 HeapFree(GetProcessHeap(), 0, table);
291 }
292 LeaveCriticalSection(&delegating_vtbl_section);
293 }
294
295 HRESULT CStdStubBuffer_Delegating_Construct(REFIID riid,
296 LPUNKNOWN pUnkServer,
297 PCInterfaceName name,
298 CInterfaceStubVtbl *vtbl,
299 REFIID delegating_iid,
300 LPPSFACTORYBUFFER pPSFactory,
301 LPRPCSTUBBUFFER *ppStub)
302 {
303 cstdstubbuffer_delegating_t *This;
304 IUnknown *pvServer;
305 HRESULT r;
306
307 TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
308 TRACE("iid=%s delegating to %s\n", debugstr_guid(vtbl->header.piid), debugstr_guid(delegating_iid));
309 TRACE("vtbl=%p\n", &vtbl->Vtbl);
310
311 if (!IsEqualGUID(vtbl->header.piid, riid))
312 {
313 ERR("IID mismatch during stub creation\n");
314 return RPC_E_UNEXPECTED;
315 }
316
317 r = IUnknown_QueryInterface(pUnkServer, riid, (void**)&pvServer);
318 if(FAILED(r)) return r;
319
320 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
321 if (!This)
322 {
323 IUnknown_Release(pvServer);
324 return E_OUTOFMEMORY;
325 }
326
327 This->base_obj = get_delegating_vtbl( vtbl->header.DispatchTableCount );
328 r = create_stub(delegating_iid, (IUnknown*)&This->base_obj, &This->base_stub);
329 if(FAILED(r))
330 {
331 release_delegating_vtbl(This->base_obj);
332 HeapFree(GetProcessHeap(), 0, This);
333 IUnknown_Release(pvServer);
334 return r;
335 }
336
337 This->stub_buffer.lpVtbl = &vtbl->Vtbl;
338 This->stub_buffer.RefCount = 1;
339 This->stub_buffer.pvServerObject = pvServer;
340 This->stub_buffer.pPSFactory = pPSFactory;
341 *ppStub = (LPRPCSTUBBUFFER)&This->stub_buffer;
342
343 IPSFactoryBuffer_AddRef(pPSFactory);
344 return S_OK;
345 }
346
347 HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface,
348 REFIID riid,
349 LPVOID *obj)
350 {
351 CStdStubBuffer *This = (CStdStubBuffer *)iface;
352 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
353
354 if (IsEqualIID(&IID_IUnknown, riid) ||
355 IsEqualIID(&IID_IRpcStubBuffer, riid))
356 {
357 IRpcStubBuffer_AddRef(iface);
358 *obj = iface;
359 return S_OK;
360 }
361 *obj = NULL;
362 return E_NOINTERFACE;
363 }
364
365 ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface)
366 {
367 CStdStubBuffer *This = (CStdStubBuffer *)iface;
368 TRACE("(%p)->AddRef()\n",This);
369 return InterlockedIncrement(&This->RefCount);
370 }
371
372 ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface,
373 LPPSFACTORYBUFFER pPSF)
374 {
375 CStdStubBuffer *This = (CStdStubBuffer *)iface;
376 ULONG refs;
377
378 TRACE("(%p)->Release()\n",This);
379
380 refs = InterlockedDecrement(&This->RefCount);
381 if (!refs)
382 {
383 /* test_Release shows that native doesn't call Disconnect here.
384 We'll leave it in for the time being. */
385 IRpcStubBuffer_Disconnect(iface);
386
387 IPSFactoryBuffer_Release(pPSF);
388 HeapFree(GetProcessHeap(),0,This);
389 }
390 return refs;
391 }
392
393 ULONG WINAPI NdrCStdStubBuffer2_Release(LPRPCSTUBBUFFER iface,
394 LPPSFACTORYBUFFER pPSF)
395 {
396 cstdstubbuffer_delegating_t *This = impl_from_delegating( iface );
397 ULONG refs;
398
399 TRACE("(%p)->Release()\n", This);
400
401 refs = InterlockedDecrement(&This->stub_buffer.RefCount);
402 if (!refs)
403 {
404 /* Just like NdrCStdStubBuffer_Release, we shouldn't call
405 Disconnect here */
406 IRpcStubBuffer_Disconnect((IRpcStubBuffer *)&This->stub_buffer);
407
408 IRpcStubBuffer_Release(This->base_stub);
409 release_delegating_vtbl(This->base_obj);
410
411 IPSFactoryBuffer_Release(pPSF);
412 HeapFree(GetProcessHeap(), 0, This);
413 }
414
415 return refs;
416 }
417
418 HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface,
419 LPUNKNOWN lpUnkServer)
420 {
421 CStdStubBuffer *This = (CStdStubBuffer *)iface;
422 HRESULT r;
423 IUnknown *new = NULL;
424
425 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
426
427 r = IUnknown_QueryInterface(lpUnkServer, STUB_HEADER(This).piid, (void**)&new);
428 new = InterlockedExchangePointer((void**)&This->pvServerObject, new);
429 if(new)
430 IUnknown_Release(new);
431 return r;
432 }
433
434 void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface)
435 {
436 CStdStubBuffer *This = (CStdStubBuffer *)iface;
437 IUnknown *old;
438 TRACE("(%p)->Disconnect()\n",This);
439
440 old = InterlockedExchangePointer((void**)&This->pvServerObject, NULL);
441
442 if(old)
443 IUnknown_Release(old);
444 }
445
446 HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface,
447 PRPCOLEMESSAGE pMsg,
448 LPRPCCHANNELBUFFER pChannel)
449 {
450 CStdStubBuffer *This = (CStdStubBuffer *)iface;
451 DWORD dwPhase = STUB_UNMARSHAL;
452 HRESULT hr = S_OK;
453
454 TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel);
455
456 __TRY
457 {
458 if (STUB_HEADER(This).pDispatchTable)
459 STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
460 else /* pure interpreted */
461 NdrStubCall2(iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
462 }
463 __EXCEPT(stub_filter)
464 {
465 DWORD dwExceptionCode = GetExceptionCode();
466 WARN("a stub call failed with exception 0x%08x (%d)\n", dwExceptionCode, dwExceptionCode);
467 if (FAILED(dwExceptionCode))
468 hr = dwExceptionCode;
469 else
470 hr = HRESULT_FROM_WIN32(dwExceptionCode);
471 }
472 __ENDTRY
473
474 return hr;
475 }
476
477 LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface,
478 REFIID riid)
479 {
480 CStdStubBuffer *This = (CStdStubBuffer *)iface;
481 TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid));
482 return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;
483 }
484
485 ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface)
486 {
487 CStdStubBuffer *This = (CStdStubBuffer *)iface;
488 TRACE("(%p)->CountRefs()\n",This);
489 return This->RefCount;
490 }
491
492 HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
493 LPVOID *ppv)
494 {
495 CStdStubBuffer *This = (CStdStubBuffer *)iface;
496 TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
497 return S_OK;
498 }
499
500 void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface,
501 LPVOID pv)
502 {
503 CStdStubBuffer *This = (CStdStubBuffer *)iface;
504 TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);
505 }
506
507 const IRpcStubBufferVtbl CStdStubBuffer_Vtbl =
508 {
509 CStdStubBuffer_QueryInterface,
510 CStdStubBuffer_AddRef,
511 NULL,
512 CStdStubBuffer_Connect,
513 CStdStubBuffer_Disconnect,
514 CStdStubBuffer_Invoke,
515 CStdStubBuffer_IsIIDSupported,
516 CStdStubBuffer_CountRefs,
517 CStdStubBuffer_DebugServerQueryInterface,
518 CStdStubBuffer_DebugServerRelease
519 };
520
521 static HRESULT WINAPI CStdStubBuffer_Delegating_Connect(LPRPCSTUBBUFFER iface,
522 LPUNKNOWN lpUnkServer)
523 {
524 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
525 HRESULT r;
526 TRACE("(%p)->Connect(%p)\n", This, lpUnkServer);
527
528 r = CStdStubBuffer_Connect(iface, lpUnkServer);
529 if(SUCCEEDED(r))
530 r = IRpcStubBuffer_Connect(This->base_stub, (IUnknown*)&This->base_obj);
531
532 return r;
533 }
534
535 static void WINAPI CStdStubBuffer_Delegating_Disconnect(LPRPCSTUBBUFFER iface)
536 {
537 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
538 TRACE("(%p)->Disconnect()\n", This);
539
540 IRpcStubBuffer_Disconnect(This->base_stub);
541 CStdStubBuffer_Disconnect(iface);
542 }
543
544 static ULONG WINAPI CStdStubBuffer_Delegating_CountRefs(LPRPCSTUBBUFFER iface)
545 {
546 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
547 ULONG ret;
548 TRACE("(%p)->CountRefs()\n", This);
549
550 ret = CStdStubBuffer_CountRefs(iface);
551 ret += IRpcStubBuffer_CountRefs(This->base_stub);
552
553 return ret;
554 }
555
556 const IRpcStubBufferVtbl CStdStubBuffer_Delegating_Vtbl =
557 {
558 CStdStubBuffer_QueryInterface,
559 CStdStubBuffer_AddRef,
560 NULL,
561 CStdStubBuffer_Delegating_Connect,
562 CStdStubBuffer_Delegating_Disconnect,
563 CStdStubBuffer_Invoke,
564 CStdStubBuffer_IsIIDSupported,
565 CStdStubBuffer_Delegating_CountRefs,
566 CStdStubBuffer_DebugServerQueryInterface,
567 CStdStubBuffer_DebugServerRelease
568 };
569
570 const MIDL_SERVER_INFO *CStdStubBuffer_GetServerInfo(IRpcStubBuffer *iface)
571 {
572 CStdStubBuffer *This = (CStdStubBuffer *)iface;
573 return STUB_HEADER(This).pServerInfo;
574 }
575
576 /************************************************************************
577 * NdrStubForwardingFunction [RPCRT4.@]
578 */
579 void __RPC_STUB NdrStubForwardingFunction( IRpcStubBuffer *iface, IRpcChannelBuffer *pChannel,
580 PRPC_MESSAGE pMsg, DWORD *pdwStubPhase )
581 {
582 /* Note pMsg is passed intact since RPCOLEMESSAGE is basically a RPC_MESSAGE. */
583
584 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
585 HRESULT r = IRpcStubBuffer_Invoke(This->base_stub, (RPCOLEMESSAGE*)pMsg, pChannel);
586 if(FAILED(r)) RpcRaiseException(r);
587 return;
588 }
589
590 /***********************************************************************
591 * NdrStubInitialize [RPCRT4.@]
592 */
593 void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
594 PMIDL_STUB_MESSAGE pStubMsg,
595 PMIDL_STUB_DESC pStubDescriptor,
596 LPRPCCHANNELBUFFER pRpcChannelBuffer)
597 {
598 TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
599 NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
600 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
601 IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
602 &pStubMsg->dwDestContext,
603 &pStubMsg->pvDestContext);
604 }
605
606 /***********************************************************************
607 * NdrStubGetBuffer [RPCRT4.@]
608 */
609 void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER iface,
610 LPRPCCHANNELBUFFER pRpcChannelBuffer,
611 PMIDL_STUB_MESSAGE pStubMsg)
612 {
613 CStdStubBuffer *This = (CStdStubBuffer *)iface;
614 HRESULT hr;
615
616 TRACE("(%p, %p, %p)\n", This, pRpcChannelBuffer, pStubMsg);
617
618 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
619 hr = IRpcChannelBuffer_GetBuffer(pRpcChannelBuffer,
620 (RPCOLEMESSAGE *)pStubMsg->RpcMsg, STUB_HEADER(This).piid);
621 if (FAILED(hr))
622 {
623 RpcRaiseException(hr);
624 return;
625 }
626
627 pStubMsg->Buffer = pStubMsg->RpcMsg->Buffer;
628 }