Merge r68232 to get Windows' rpcrt4.dll to work under ReactOS.
[reactos.git] / reactos / 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 DWORD oldprot;
180
181 block = VirtualAlloc( NULL, BLOCK_SIZE * sizeof(*block),
182 MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
183 if (!block) return NULL;
184
185 for (i = 0; i < BLOCK_SIZE; i++)
186 {
187 memcpy( &block[i], opcodes, sizeof(opcodes) );
188 block[i].offset = (BLOCK_SIZE * num + i + 3) * sizeof(void *);
189 }
190 VirtualProtect( block, BLOCK_SIZE * sizeof(*block), PAGE_EXECUTE_READ, &oldprot );
191 prev = InterlockedCompareExchangePointer( (void **)&method_blocks[num], block, NULL );
192 if (prev) /* someone beat us to it */
193 {
194 VirtualFree( block, 0, MEM_RELEASE );
195 block = prev;
196 }
197 return block;
198 }
199
200 static BOOL fill_delegated_stub_table(IUnknownVtbl *vtbl, DWORD num)
201 {
202 const void **entry = (const void **)(vtbl + 1);
203 DWORD i, j;
204
205 if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
206 {
207 FIXME( "%u methods not supported\n", num );
208 return FALSE;
209 }
210 vtbl->QueryInterface = delegating_QueryInterface;
211 vtbl->AddRef = delegating_AddRef;
212 vtbl->Release = delegating_Release;
213 for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
214 {
215 const vtbl_method_t *block = method_blocks[i];
216 if (!block && !(block = allocate_block( i ))) return FALSE;
217 for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++) *entry++ = &block[j];
218 }
219 return TRUE;
220 }
221
222 BOOL fill_delegated_proxy_table(IUnknownVtbl *vtbl, DWORD num)
223 {
224 const void **entry = (const void **)(vtbl + 1);
225 DWORD i, j;
226
227 if (num - 3 > BLOCK_SIZE * MAX_BLOCKS)
228 {
229 FIXME( "%u methods not supported\n", num );
230 return FALSE;
231 }
232 vtbl->QueryInterface = IUnknown_QueryInterface_Proxy;
233 vtbl->AddRef = IUnknown_AddRef_Proxy;
234 vtbl->Release = IUnknown_Release_Proxy;
235 for (i = 0; i < (num - 3 + BLOCK_SIZE - 1) / BLOCK_SIZE; i++)
236 {
237 const vtbl_method_t *block = method_blocks[i];
238 if (!block && !(block = allocate_block( i ))) return FALSE;
239 for (j = 0; j < BLOCK_SIZE && j < num - 3 - i * BLOCK_SIZE; j++, entry++)
240 if (!*entry) *entry = &block[j];
241 }
242 return TRUE;
243 }
244
245 static IUnknownVtbl *get_delegating_vtbl(DWORD num_methods)
246 {
247 IUnknownVtbl *ret;
248
249 if (num_methods < 256) num_methods = 256; /* avoid frequent reallocations */
250
251 EnterCriticalSection(&delegating_vtbl_section);
252
253 if(!current_vtbl || num_methods > current_vtbl->size)
254 {
255 ref_counted_vtbl *table = HeapAlloc(GetProcessHeap(), 0,
256 FIELD_OFFSET(ref_counted_vtbl, vtbl) + num_methods * sizeof(void*));
257 if (!table)
258 {
259 LeaveCriticalSection(&delegating_vtbl_section);
260 return NULL;
261 }
262
263 table->ref = 0;
264 table->size = num_methods;
265 fill_delegated_stub_table(&table->vtbl, num_methods);
266
267 if (current_vtbl && current_vtbl->ref == 0)
268 {
269 TRACE("freeing old table\n");
270 HeapFree(GetProcessHeap(), 0, current_vtbl);
271 }
272 current_vtbl = table;
273 }
274
275 current_vtbl->ref++;
276 ret = &current_vtbl->vtbl;
277 LeaveCriticalSection(&delegating_vtbl_section);
278 return ret;
279 }
280
281 static void release_delegating_vtbl(IUnknownVtbl *vtbl)
282 {
283 ref_counted_vtbl *table = (ref_counted_vtbl*)((DWORD *)vtbl - 1);
284
285 EnterCriticalSection(&delegating_vtbl_section);
286 table->ref--;
287 TRACE("ref now %d\n", table->ref);
288 if(table->ref == 0 && table != current_vtbl)
289 {
290 TRACE("... and we're not current so free'ing\n");
291 HeapFree(GetProcessHeap(), 0, table);
292 }
293 LeaveCriticalSection(&delegating_vtbl_section);
294 }
295
296 HRESULT CStdStubBuffer_Delegating_Construct(REFIID riid,
297 LPUNKNOWN pUnkServer,
298 PCInterfaceName name,
299 CInterfaceStubVtbl *vtbl,
300 REFIID delegating_iid,
301 LPPSFACTORYBUFFER pPSFactory,
302 LPRPCSTUBBUFFER *ppStub)
303 {
304 cstdstubbuffer_delegating_t *This;
305 IUnknown *pvServer;
306 HRESULT r;
307
308 TRACE("(%p,%p,%p,%p) %s\n", pUnkServer, vtbl, pPSFactory, ppStub, name);
309 TRACE("iid=%s delegating to %s\n", debugstr_guid(vtbl->header.piid), debugstr_guid(delegating_iid));
310 TRACE("vtbl=%p\n", &vtbl->Vtbl);
311
312 if (!IsEqualGUID(vtbl->header.piid, riid))
313 {
314 ERR("IID mismatch during stub creation\n");
315 return RPC_E_UNEXPECTED;
316 }
317
318 r = IUnknown_QueryInterface(pUnkServer, riid, (void**)&pvServer);
319 if(FAILED(r)) return r;
320
321 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
322 if (!This)
323 {
324 IUnknown_Release(pvServer);
325 return E_OUTOFMEMORY;
326 }
327
328 This->base_obj = get_delegating_vtbl( vtbl->header.DispatchTableCount );
329 r = create_stub(delegating_iid, (IUnknown*)&This->base_obj, &This->base_stub);
330 if(FAILED(r))
331 {
332 release_delegating_vtbl(This->base_obj);
333 HeapFree(GetProcessHeap(), 0, This);
334 IUnknown_Release(pvServer);
335 return r;
336 }
337
338 This->stub_buffer.lpVtbl = &vtbl->Vtbl;
339 This->stub_buffer.RefCount = 1;
340 This->stub_buffer.pvServerObject = pvServer;
341 This->stub_buffer.pPSFactory = pPSFactory;
342 *ppStub = (LPRPCSTUBBUFFER)&This->stub_buffer;
343
344 IPSFactoryBuffer_AddRef(pPSFactory);
345 return S_OK;
346 }
347
348 HRESULT WINAPI CStdStubBuffer_QueryInterface(LPRPCSTUBBUFFER iface,
349 REFIID riid,
350 LPVOID *obj)
351 {
352 CStdStubBuffer *This = (CStdStubBuffer *)iface;
353 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(riid),obj);
354
355 if (IsEqualIID(&IID_IUnknown, riid) ||
356 IsEqualIID(&IID_IRpcStubBuffer, riid))
357 {
358 IRpcStubBuffer_AddRef(iface);
359 *obj = iface;
360 return S_OK;
361 }
362 *obj = NULL;
363 return E_NOINTERFACE;
364 }
365
366 ULONG WINAPI CStdStubBuffer_AddRef(LPRPCSTUBBUFFER iface)
367 {
368 CStdStubBuffer *This = (CStdStubBuffer *)iface;
369 TRACE("(%p)->AddRef()\n",This);
370 return InterlockedIncrement(&This->RefCount);
371 }
372
373 ULONG WINAPI NdrCStdStubBuffer_Release(LPRPCSTUBBUFFER iface,
374 LPPSFACTORYBUFFER pPSF)
375 {
376 CStdStubBuffer *This = (CStdStubBuffer *)iface;
377 ULONG refs;
378
379 TRACE("(%p)->Release()\n",This);
380
381 refs = InterlockedDecrement(&This->RefCount);
382 if (!refs)
383 {
384 /* test_Release shows that native doesn't call Disconnect here.
385 We'll leave it in for the time being. */
386 IRpcStubBuffer_Disconnect(iface);
387
388 IPSFactoryBuffer_Release(pPSF);
389 HeapFree(GetProcessHeap(),0,This);
390 }
391 return refs;
392 }
393
394 ULONG WINAPI NdrCStdStubBuffer2_Release(LPRPCSTUBBUFFER iface,
395 LPPSFACTORYBUFFER pPSF)
396 {
397 cstdstubbuffer_delegating_t *This = impl_from_delegating( iface );
398 ULONG refs;
399
400 TRACE("(%p)->Release()\n", This);
401
402 refs = InterlockedDecrement(&This->stub_buffer.RefCount);
403 if (!refs)
404 {
405 /* Just like NdrCStdStubBuffer_Release, we shouldn't call
406 Disconnect here */
407 IRpcStubBuffer_Disconnect((IRpcStubBuffer *)&This->stub_buffer);
408
409 IRpcStubBuffer_Release(This->base_stub);
410 release_delegating_vtbl(This->base_obj);
411
412 IPSFactoryBuffer_Release(pPSF);
413 HeapFree(GetProcessHeap(), 0, This);
414 }
415
416 return refs;
417 }
418
419 HRESULT WINAPI CStdStubBuffer_Connect(LPRPCSTUBBUFFER iface,
420 LPUNKNOWN lpUnkServer)
421 {
422 CStdStubBuffer *This = (CStdStubBuffer *)iface;
423 HRESULT r;
424 IUnknown *new = NULL;
425
426 TRACE("(%p)->Connect(%p)\n",This,lpUnkServer);
427
428 r = IUnknown_QueryInterface(lpUnkServer, STUB_HEADER(This).piid, (void**)&new);
429 new = InterlockedExchangePointer((void**)&This->pvServerObject, new);
430 if(new)
431 IUnknown_Release(new);
432 return r;
433 }
434
435 void WINAPI CStdStubBuffer_Disconnect(LPRPCSTUBBUFFER iface)
436 {
437 CStdStubBuffer *This = (CStdStubBuffer *)iface;
438 IUnknown *old;
439 TRACE("(%p)->Disconnect()\n",This);
440
441 old = InterlockedExchangePointer((void**)&This->pvServerObject, NULL);
442
443 if(old)
444 IUnknown_Release(old);
445 }
446
447 HRESULT WINAPI CStdStubBuffer_Invoke(LPRPCSTUBBUFFER iface,
448 PRPCOLEMESSAGE pMsg,
449 LPRPCCHANNELBUFFER pChannel)
450 {
451 CStdStubBuffer *This = (CStdStubBuffer *)iface;
452 DWORD dwPhase = STUB_UNMARSHAL;
453 HRESULT hr = S_OK;
454
455 TRACE("(%p)->Invoke(%p,%p)\n",This,pMsg,pChannel);
456
457 __TRY
458 {
459 if (STUB_HEADER(This).pDispatchTable)
460 STUB_HEADER(This).pDispatchTable[pMsg->iMethod](iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
461 else /* pure interpreted */
462 NdrStubCall2(iface, pChannel, (PRPC_MESSAGE)pMsg, &dwPhase);
463 }
464 __EXCEPT(stub_filter)
465 {
466 DWORD dwExceptionCode = GetExceptionCode();
467 WARN("a stub call failed with exception 0x%08x (%d)\n", dwExceptionCode, dwExceptionCode);
468 if (FAILED(dwExceptionCode))
469 hr = dwExceptionCode;
470 else
471 hr = HRESULT_FROM_WIN32(dwExceptionCode);
472 }
473 __ENDTRY
474
475 return hr;
476 }
477
478 LPRPCSTUBBUFFER WINAPI CStdStubBuffer_IsIIDSupported(LPRPCSTUBBUFFER iface,
479 REFIID riid)
480 {
481 CStdStubBuffer *This = (CStdStubBuffer *)iface;
482 TRACE("(%p)->IsIIDSupported(%s)\n",This,debugstr_guid(riid));
483 return IsEqualGUID(STUB_HEADER(This).piid, riid) ? iface : NULL;
484 }
485
486 ULONG WINAPI CStdStubBuffer_CountRefs(LPRPCSTUBBUFFER iface)
487 {
488 CStdStubBuffer *This = (CStdStubBuffer *)iface;
489 TRACE("(%p)->CountRefs()\n",This);
490 return This->RefCount;
491 }
492
493 HRESULT WINAPI CStdStubBuffer_DebugServerQueryInterface(LPRPCSTUBBUFFER iface,
494 LPVOID *ppv)
495 {
496 CStdStubBuffer *This = (CStdStubBuffer *)iface;
497 TRACE("(%p)->DebugServerQueryInterface(%p)\n",This,ppv);
498 return S_OK;
499 }
500
501 void WINAPI CStdStubBuffer_DebugServerRelease(LPRPCSTUBBUFFER iface,
502 LPVOID pv)
503 {
504 CStdStubBuffer *This = (CStdStubBuffer *)iface;
505 TRACE("(%p)->DebugServerRelease(%p)\n",This,pv);
506 }
507
508 const IRpcStubBufferVtbl CStdStubBuffer_Vtbl =
509 {
510 CStdStubBuffer_QueryInterface,
511 CStdStubBuffer_AddRef,
512 NULL,
513 CStdStubBuffer_Connect,
514 CStdStubBuffer_Disconnect,
515 CStdStubBuffer_Invoke,
516 CStdStubBuffer_IsIIDSupported,
517 CStdStubBuffer_CountRefs,
518 CStdStubBuffer_DebugServerQueryInterface,
519 CStdStubBuffer_DebugServerRelease
520 };
521
522 static HRESULT WINAPI CStdStubBuffer_Delegating_Connect(LPRPCSTUBBUFFER iface,
523 LPUNKNOWN lpUnkServer)
524 {
525 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
526 HRESULT r;
527 TRACE("(%p)->Connect(%p)\n", This, lpUnkServer);
528
529 r = CStdStubBuffer_Connect(iface, lpUnkServer);
530 if(SUCCEEDED(r))
531 r = IRpcStubBuffer_Connect(This->base_stub, (IUnknown*)&This->base_obj);
532
533 return r;
534 }
535
536 static void WINAPI CStdStubBuffer_Delegating_Disconnect(LPRPCSTUBBUFFER iface)
537 {
538 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
539 TRACE("(%p)->Disconnect()\n", This);
540
541 IRpcStubBuffer_Disconnect(This->base_stub);
542 CStdStubBuffer_Disconnect(iface);
543 }
544
545 static ULONG WINAPI CStdStubBuffer_Delegating_CountRefs(LPRPCSTUBBUFFER iface)
546 {
547 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
548 ULONG ret;
549 TRACE("(%p)->CountRefs()\n", This);
550
551 ret = CStdStubBuffer_CountRefs(iface);
552 ret += IRpcStubBuffer_CountRefs(This->base_stub);
553
554 return ret;
555 }
556
557 const IRpcStubBufferVtbl CStdStubBuffer_Delegating_Vtbl =
558 {
559 CStdStubBuffer_QueryInterface,
560 CStdStubBuffer_AddRef,
561 NULL,
562 CStdStubBuffer_Delegating_Connect,
563 CStdStubBuffer_Delegating_Disconnect,
564 CStdStubBuffer_Invoke,
565 CStdStubBuffer_IsIIDSupported,
566 CStdStubBuffer_Delegating_CountRefs,
567 CStdStubBuffer_DebugServerQueryInterface,
568 CStdStubBuffer_DebugServerRelease
569 };
570
571 const MIDL_SERVER_INFO *CStdStubBuffer_GetServerInfo(IRpcStubBuffer *iface)
572 {
573 CStdStubBuffer *This = (CStdStubBuffer *)iface;
574 return STUB_HEADER(This).pServerInfo;
575 }
576
577 /************************************************************************
578 * NdrStubForwardingFunction [RPCRT4.@]
579 */
580 void __RPC_STUB NdrStubForwardingFunction( IRpcStubBuffer *iface, IRpcChannelBuffer *pChannel,
581 PRPC_MESSAGE pMsg, DWORD *pdwStubPhase )
582 {
583 /* Note pMsg is passed intact since RPCOLEMESSAGE is basically a RPC_MESSAGE. */
584
585 cstdstubbuffer_delegating_t *This = impl_from_delegating(iface);
586 HRESULT r = IRpcStubBuffer_Invoke(This->base_stub, (RPCOLEMESSAGE*)pMsg, pChannel);
587 if(FAILED(r)) RpcRaiseException(r);
588 return;
589 }
590
591 /***********************************************************************
592 * NdrStubInitialize [RPCRT4.@]
593 */
594 void WINAPI NdrStubInitialize(PRPC_MESSAGE pRpcMsg,
595 PMIDL_STUB_MESSAGE pStubMsg,
596 PMIDL_STUB_DESC pStubDescriptor,
597 LPRPCCHANNELBUFFER pRpcChannelBuffer)
598 {
599 TRACE("(%p,%p,%p,%p)\n", pRpcMsg, pStubMsg, pStubDescriptor, pRpcChannelBuffer);
600 NdrServerInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor);
601 pStubMsg->pRpcChannelBuffer = pRpcChannelBuffer;
602 IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer,
603 &pStubMsg->dwDestContext,
604 &pStubMsg->pvDestContext);
605 }
606
607 /***********************************************************************
608 * NdrStubGetBuffer [RPCRT4.@]
609 */
610 void WINAPI NdrStubGetBuffer(LPRPCSTUBBUFFER iface,
611 LPRPCCHANNELBUFFER pRpcChannelBuffer,
612 PMIDL_STUB_MESSAGE pStubMsg)
613 {
614 CStdStubBuffer *This = (CStdStubBuffer *)iface;
615 HRESULT hr;
616
617 TRACE("(%p, %p, %p)\n", This, pRpcChannelBuffer, pStubMsg);
618
619 pStubMsg->RpcMsg->BufferLength = pStubMsg->BufferLength;
620 hr = IRpcChannelBuffer_GetBuffer(pRpcChannelBuffer,
621 (RPCOLEMESSAGE *)pStubMsg->RpcMsg, STUB_HEADER(This).piid);
622 if (FAILED(hr))
623 {
624 RpcRaiseException(hr);
625 return;
626 }
627
628 pStubMsg->Buffer = pStubMsg->RpcMsg->Buffer;
629 }