2 * NDR -Oi,-Oif,-Oicf Interpreter
4 * Copyright 2001 Ove Kåven, TransGaming Technologies
5 * Copyright 2003-5 Robert Shearman (for CodeWeavers)
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.
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.
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
23 * - Some types of binding handles
27 #include "wine/port.h"
41 #include "wine/exception.h"
42 #include "wine/debug.h"
43 #include "wine/rpcfc.h"
47 #include "ndr_stubless.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
51 #define NDR_TABLE_MASK 127
53 static inline void call_buffer_sizer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory, PFORMAT_STRING pFormat)
55 NDR_BUFFERSIZE m = NdrBufferSizer[pFormat[0] & NDR_TABLE_MASK];
56 if (m) m(pStubMsg, pMemory, pFormat);
59 FIXME("format type 0x%x not implemented\n", pFormat[0]);
60 RpcRaiseException(RPC_X_BAD_STUB_DATA);
64 static inline unsigned char *call_marshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory, PFORMAT_STRING pFormat)
66 NDR_MARSHALL m = NdrMarshaller[pFormat[0] & NDR_TABLE_MASK];
67 if (m) return m(pStubMsg, pMemory, pFormat);
70 FIXME("format type 0x%x not implemented\n", pFormat[0]);
71 RpcRaiseException(RPC_X_BAD_STUB_DATA);
76 static inline unsigned char *call_unmarshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char **ppMemory, PFORMAT_STRING pFormat, unsigned char fMustAlloc)
78 NDR_UNMARSHALL m = NdrUnmarshaller[pFormat[0] & NDR_TABLE_MASK];
79 if (m) return m(pStubMsg, ppMemory, pFormat, fMustAlloc);
82 FIXME("format type 0x%x not implemented\n", pFormat[0]);
83 RpcRaiseException(RPC_X_BAD_STUB_DATA);
88 static inline void call_freer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory, PFORMAT_STRING pFormat)
90 NDR_FREE m = NdrFreer[pFormat[0] & NDR_TABLE_MASK];
91 if (m) m(pStubMsg, pMemory, pFormat);
94 #define STUBLESS_UNMARSHAL 1
95 #define STUBLESS_INITOUT 2
96 #define STUBLESS_CALLSERVER 3
97 #define STUBLESS_CALCSIZE 4
98 #define STUBLESS_GETBUFFER 5
99 #define STUBLESS_MARSHAL 6
100 #define STUBLESS_FREE 7
102 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
104 #if 0 /* these functions are not defined yet */
105 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
106 pMessage->pfnFree = NdrRpcSmClientFree;
110 static void dump_RPC_FC_PROC_PF(PARAM_ATTRIBUTES param_attributes)
112 if (param_attributes.MustSize) TRACE(" MustSize");
113 if (param_attributes.MustFree) TRACE(" MustFree");
114 if (param_attributes.IsPipe) TRACE(" IsPipe");
115 if (param_attributes.IsIn) TRACE(" IsIn");
116 if (param_attributes.IsOut) TRACE(" IsOut");
117 if (param_attributes.IsReturn) TRACE(" IsReturn");
118 if (param_attributes.IsBasetype) TRACE(" IsBasetype");
119 if (param_attributes.IsByValue) TRACE(" IsByValue");
120 if (param_attributes.IsSimpleRef) TRACE(" IsSimpleRef");
121 if (param_attributes.IsDontCallFreeInst) TRACE(" IsDontCallFreeInst");
122 if (param_attributes.SaveForAsyncFinish) TRACE(" SaveForAsyncFinish");
123 if (param_attributes.ServerAllocSize) TRACE(" ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
126 static void dump_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
128 if (Oi2Flags.ServerMustSize) TRACE(" ServerMustSize");
129 if (Oi2Flags.ClientMustSize) TRACE(" ClientMustSize");
130 if (Oi2Flags.HasReturn) TRACE(" HasReturn");
131 if (Oi2Flags.HasPipes) TRACE(" HasPipes");
132 if (Oi2Flags.Unused) TRACE(" Unused");
133 if (Oi2Flags.HasAsyncUuid) TRACE(" HasAsyncUuid");
134 if (Oi2Flags.HasExtensions) TRACE(" HasExtensions");
135 if (Oi2Flags.HasAsyncHandle) TRACE(" HasAsyncHandle");
139 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
141 static PFORMAT_STRING client_get_handle(
142 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
143 PFORMAT_STRING pFormat, handle_t *phBinding)
146 switch (pProcHeader->handle_type)
148 /* explicit binding: parse additional section */
149 case RPC_FC_BIND_EXPLICIT:
150 switch (*pFormat) /* handle_type */
152 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
154 const NDR_EHD_PRIMITIVE *pDesc = (const NDR_EHD_PRIMITIVE *)pFormat;
156 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
158 if (pDesc->flag) /* pointer to binding */
159 *phBinding = **(handle_t **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
161 *phBinding = *(handle_t *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
162 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
164 case RPC_FC_BIND_GENERIC: /* explicit generic */
166 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
167 void *pObject = NULL;
169 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
171 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
173 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
174 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
176 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
177 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
178 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
179 *phBinding = pGenPair->pfnBind(pObject);
180 return pFormat + sizeof(NDR_EHD_GENERIC);
182 case RPC_FC_BIND_CONTEXT: /* explicit context */
184 const NDR_EHD_CONTEXT *pDesc = (const NDR_EHD_CONTEXT *)pFormat;
185 NDR_CCONTEXT context_handle;
186 TRACE("Explicit bind context\n");
187 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
189 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
190 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
193 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
194 if ((pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL) &&
197 ERR("null context handle isn't allowed\n");
198 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
201 *phBinding = NDRCContextBinding(context_handle);
202 /* FIXME: should we store this structure in stubMsg.pContext? */
203 return pFormat + sizeof(NDR_EHD_CONTEXT);
206 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
207 RpcRaiseException(RPC_X_BAD_STUB_DATA);
210 case RPC_FC_BIND_GENERIC: /* implicit generic */
211 FIXME("RPC_FC_BIND_GENERIC\n");
212 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
214 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
215 TRACE("Implicit primitive handle\n");
216 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
218 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
219 FIXME("RPC_FC_CALLBACK_HANDLE\n");
221 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
222 /* strictly speaking, it isn't necessary to set hBinding here
223 * since it isn't actually used (hence the automatic in its name),
224 * but then why does MIDL generate a valid entry in the
225 * MIDL_STUB_DESC for it? */
226 TRACE("Implicit auto handle\n");
227 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
230 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
231 RpcRaiseException(RPC_X_BAD_STUB_DATA);
236 static void client_free_handle(
237 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
238 PFORMAT_STRING pFormat, handle_t hBinding)
241 switch (pProcHeader->handle_type)
243 /* explicit binding: parse additional section */
244 case RPC_FC_BIND_EXPLICIT:
245 switch (*pFormat) /* handle_type */
247 case RPC_FC_BIND_GENERIC: /* explicit generic */
249 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
250 void *pObject = NULL;
252 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
254 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
256 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
257 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
259 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
260 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
261 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
262 pGenPair->pfnUnbind(pObject, hBinding);
265 case RPC_FC_BIND_CONTEXT: /* explicit context */
266 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
269 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
270 RpcRaiseException(RPC_X_BAD_STUB_DATA);
273 case RPC_FC_BIND_GENERIC: /* implicit generic */
274 FIXME("RPC_FC_BIND_GENERIC\n");
275 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
277 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
278 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
279 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
282 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
283 RpcRaiseException(RPC_X_BAD_STUB_DATA);
287 static void client_do_args(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
288 int phase, unsigned char *args, unsigned short number_of_params,
289 unsigned char *pRetVal)
291 /* current format string offset */
292 int current_offset = 0;
293 /* current stack offset */
294 unsigned short current_stack_offset = 0;
298 for (i = 0; i < number_of_params; i++)
300 const NDR_PARAM_OIF_BASETYPE *pParam =
301 (const NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];
302 unsigned char * pArg;
304 current_stack_offset = pParam->stack_offset;
305 pArg = ARG_FROM_OFFSET(args, current_stack_offset);
307 TRACE("param[%d]: new format\n", i);
308 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");
309 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
310 TRACE("\tmemory addr (before): %p\n", pArg);
312 if (pParam->param_attributes.IsBasetype)
314 const unsigned char * pTypeFormat =
315 &pParam->type_format_char;
317 if (pParam->param_attributes.IsSimpleRef)
318 pArg = *(unsigned char **)pArg;
320 TRACE("\tbase type: 0x%02x\n", *pTypeFormat);
325 if (pParam->param_attributes.IsIn)
326 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
329 if (pParam->param_attributes.IsIn)
330 call_marshaller(pStubMsg, pArg, pTypeFormat);
332 case PROXY_UNMARSHAL:
333 if (pParam->param_attributes.IsOut)
335 if (pParam->param_attributes.IsReturn)
336 call_unmarshaller(pStubMsg, &pRetVal, pTypeFormat, 0);
338 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
339 TRACE("pRetVal = %p\n", pRetVal);
343 RpcRaiseException(RPC_S_INTERNAL_ERROR);
346 current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);
350 const NDR_PARAM_OIF_OTHER *pParamOther =
351 (const NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];
353 const unsigned char * pTypeFormat =
354 &(pStubMsg->StubDesc->pFormatTypes[pParamOther->type_offset]);
356 /* if a simple ref pointer then we have to do the
357 * check for the pointer being non-NULL. */
358 if (pParam->param_attributes.IsSimpleRef)
360 if (!*(unsigned char **)pArg)
361 RpcRaiseException(RPC_X_NULL_REF_POINTER);
364 TRACE("\tcomplex type: 0x%02x\n", *pTypeFormat);
369 if (pParam->param_attributes.IsIn)
371 if (pParam->param_attributes.IsByValue)
372 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
374 call_buffer_sizer(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
378 if (pParam->param_attributes.IsIn)
380 if (pParam->param_attributes.IsByValue)
381 call_marshaller(pStubMsg, pArg, pTypeFormat);
383 call_marshaller(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
386 case PROXY_UNMARSHAL:
387 if (pParam->param_attributes.IsOut)
389 if (pParam->param_attributes.IsReturn)
390 call_unmarshaller(pStubMsg, &pRetVal, pTypeFormat, 0);
391 else if (pParam->param_attributes.IsByValue)
392 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
394 call_unmarshaller(pStubMsg, (unsigned char **)pArg, pTypeFormat, 0);
398 RpcRaiseException(RPC_S_INTERNAL_ERROR);
401 current_offset += sizeof(NDR_PARAM_OIF_OTHER);
403 TRACE("\tmemory addr (after): %p\n", pArg);
407 static unsigned int type_stack_size(unsigned char fc)
421 case RPC_FC_UINT3264:
425 case RPC_FC_ERROR_STATUS_T:
427 return sizeof(void *);
429 return sizeof(double);
431 return sizeof(ULONGLONG);
433 ERR("invalid base type 0x%x\n", fc);
434 RpcRaiseException(RPC_S_INTERNAL_ERROR);
438 static BOOL is_by_value( PFORMAT_STRING format )
442 case RPC_FC_USER_MARSHAL:
446 case RPC_FC_CPSTRUCT:
447 case RPC_FC_CVSTRUCT:
448 case RPC_FC_BOGUS_STRUCT:
455 void client_do_args_old_format(PMIDL_STUB_MESSAGE pStubMsg,
456 PFORMAT_STRING pFormat, int phase, unsigned char *args,
457 unsigned short stack_size,
458 unsigned char *pRetVal, BOOL object_proc, BOOL ignore_retval)
460 /* current format string offset */
461 int current_offset = 0;
462 /* current stack offset */
463 unsigned short current_stack_offset = object_proc ? sizeof(void *) : 0;
467 /* NOTE: V1 style format doesn't terminate on the number_of_params
468 * condition as it doesn't have this attribute. Instead it
469 * terminates when the stack size given in the header is exceeded.
471 for (i = 0; TRUE; i++)
473 const NDR_PARAM_OI_BASETYPE *pParam =
474 (const NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];
475 unsigned char * pArg = ARG_FROM_OFFSET(args, current_stack_offset);
477 /* no more parameters; exit loop */
478 if (current_stack_offset >= stack_size)
481 TRACE("param[%d]: old format\n", i);
482 TRACE("\tparam_direction: 0x%x\n", pParam->param_direction);
483 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
484 TRACE("\tmemory addr (before): %p\n", pArg);
486 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||
487 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
489 const unsigned char * pTypeFormat =
490 &pParam->type_format_char;
492 TRACE("\tbase type 0x%02x\n", *pTypeFormat);
497 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
498 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
501 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
502 call_marshaller(pStubMsg, pArg, pTypeFormat);
504 case PROXY_UNMARSHAL:
505 if (!ignore_retval &&
506 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
508 if (pParam->param_direction & RPC_FC_RETURN_PARAM)
509 call_unmarshaller(pStubMsg, &pRetVal, pTypeFormat, 0);
511 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
515 RpcRaiseException(RPC_S_INTERNAL_ERROR);
518 current_stack_offset += type_stack_size(*pTypeFormat);
519 current_offset += sizeof(NDR_PARAM_OI_BASETYPE);
523 const NDR_PARAM_OI_OTHER *pParamOther = (const NDR_PARAM_OI_OTHER *)&pFormat[current_offset];
524 const unsigned char *pTypeFormat = &pStubMsg->StubDesc->pFormatTypes[pParamOther->type_offset];
525 const BOOL by_value = is_by_value( pTypeFormat );
527 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
532 if (pParam->param_direction == RPC_FC_IN_PARAM ||
533 pParam->param_direction == RPC_FC_IN_OUT_PARAM)
535 if (!by_value) pArg = *(unsigned char **)pArg;
536 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
540 if (pParam->param_direction == RPC_FC_IN_PARAM ||
541 pParam->param_direction == RPC_FC_IN_OUT_PARAM)
543 if (!by_value) pArg = *(unsigned char **)pArg;
544 call_marshaller(pStubMsg, pArg, pTypeFormat);
547 case PROXY_UNMARSHAL:
548 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
549 pParam->param_direction == RPC_FC_OUT_PARAM)
552 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
554 call_unmarshaller(pStubMsg, (unsigned char **)pArg, pTypeFormat, 0);
556 else if (pParam->param_direction == RPC_FC_RETURN_PARAM)
557 call_unmarshaller(pStubMsg, (unsigned char **)pRetVal, pTypeFormat, 0);
560 RpcRaiseException(RPC_S_INTERNAL_ERROR);
563 current_stack_offset += pParamOther->stack_size * sizeof(void *);
564 current_offset += sizeof(NDR_PARAM_OI_OTHER);
569 CLIENT_CALL_RETURN WINAPIV NdrClientCall2(PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, ...)
571 /* pointer to start of stack where arguments start */
573 MIDL_STUB_MESSAGE stubMsg;
574 handle_t hBinding = NULL;
575 /* procedure number */
576 unsigned short procedure_number;
578 unsigned short stack_size;
579 /* number of parameters. optional for client to give it to us */
580 unsigned char number_of_params = ~0;
581 /* cache of Oif_flags from v2 procedure header */
582 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
583 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
584 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
585 /* the type of pass we are currently doing */
587 /* header for procedure string */
588 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
589 /* -Oif or -Oicf generated format */
590 BOOL bV2Format = FALSE;
591 /* the value to return to the client from the remote procedure */
593 /* the pointer to the object when in OLE mode */
595 PFORMAT_STRING pHandleFormat;
596 /* correlation cache */
597 ULONG_PTR NdrCorrCache[256];
600 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
602 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
604 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
606 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
607 stack_size = pProcHeader->stack_size;
608 procedure_number = pProcHeader->proc_num;
609 pFormat += sizeof(NDR_PROC_HEADER_RPC);
613 stack_size = pProcHeader->stack_size;
614 procedure_number = pProcHeader->proc_num;
615 pFormat += sizeof(NDR_PROC_HEADER);
617 TRACE("stack size: 0x%x\n", stack_size);
618 TRACE("proc num: %d\n", procedure_number);
620 /* create the full pointer translation tables, if requested */
621 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
622 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
624 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
626 /* object is always the first argument */
627 This = **(void *const **)(&pFormat+1);
628 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
631 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
633 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
634 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
636 /* needed for conformance of top-level objects */
637 __ms_va_start( args, pFormat );
638 stubMsg.StackTop = va_arg( args, unsigned char * );
641 pHandleFormat = pFormat;
643 /* we only need a handle if this isn't an object method */
644 if (!(pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT))
646 pFormat = client_get_handle(&stubMsg, pProcHeader, pHandleFormat, &hBinding);
647 if (!pFormat) goto done;
650 bV2Format = (pStubDesc->Version >= 0x20000);
654 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
655 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
657 Oif_flags = pOIFHeader->Oi2Flags;
658 number_of_params = pOIFHeader->number_of_params;
660 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
663 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags);
665 if (Oif_flags.HasExtensions)
667 const NDR_PROC_HEADER_EXTS *pExtensions =
668 (const NDR_PROC_HEADER_EXTS *)pFormat;
669 ext_flags = pExtensions->Flags2;
670 pFormat += pExtensions->Size;
673 stubMsg.BufferLength = 0;
675 /* store the RPC flags away */
676 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
677 rpcMsg.RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
679 /* use alternate memory allocation routines */
680 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
681 NdrRpcSmSetClientToOsf(&stubMsg);
683 if (Oif_flags.HasPipes)
685 FIXME("pipes not supported yet\n");
686 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
687 /* init pipes package */
688 /* NdrPipesInitialize(...) */
690 if (ext_flags.HasNewCorrDesc)
692 /* initialize extra correlation package */
693 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
697 * 1. PROXY_CALCSIZE - calculate the buffer size
698 * 2. PROXY_GETBUFFER - allocate the buffer
699 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
700 * 4. PROXY_SENDRECEIVE - send/receive buffer
701 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
703 if ((pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT) ||
704 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_HAS_COMM_OR_FAULT))
708 for (phase = PROXY_CALCSIZE; phase <= PROXY_UNMARSHAL; phase++)
710 TRACE("phase = %d\n", phase);
713 case PROXY_GETBUFFER:
714 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
716 /* allocate the buffer */
717 NdrProxyGetBuffer(This, &stubMsg);
721 /* allocate the buffer */
722 if (Oif_flags.HasPipes)
723 /* NdrGetPipeBuffer(...) */
724 FIXME("pipes not supported yet\n");
727 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
729 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
731 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
734 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
738 case PROXY_SENDRECEIVE:
739 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
741 /* send the [in] params and receive the [out] and [retval]
743 NdrProxySendReceive(This, &stubMsg);
747 /* send the [in] params and receive the [out] and [retval]
749 if (Oif_flags.HasPipes)
750 /* NdrPipesSendReceive(...) */
751 FIXME("pipes not supported yet\n");
754 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
756 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
758 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
761 NdrSendReceive(&stubMsg, stubMsg.Buffer);
765 /* convert strings, floating point values and endianess into our
766 * preferred format */
767 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
768 NdrConvert(&stubMsg, pFormat);
773 case PROXY_UNMARSHAL:
775 client_do_args(&stubMsg, pFormat, phase, stubMsg.StackTop,
776 number_of_params, (unsigned char *)&RetVal);
778 client_do_args_old_format(&stubMsg, pFormat, phase,
779 stubMsg.StackTop, stack_size, (unsigned char *)&RetVal,
780 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT), FALSE);
783 ERR("shouldn't reach here. phase %d\n", phase);
790 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
791 RetVal = NdrProxyErrorHandler(GetExceptionCode());
794 const COMM_FAULT_OFFSETS *comm_fault_offsets = &pStubDesc->CommFaultOffsets[procedure_number];
798 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets->CommOffset, comm_fault_offsets->FaultOffset);
800 if (comm_fault_offsets->CommOffset == -1)
801 comm_status = (ULONG *)&RetVal;
802 else if (comm_fault_offsets->CommOffset >= 0)
803 comm_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
807 if (comm_fault_offsets->FaultOffset == -1)
808 fault_status = (ULONG *)&RetVal;
809 else if (comm_fault_offsets->FaultOffset >= 0)
810 fault_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
814 NdrMapCommAndFaultStatus(&stubMsg, comm_status, fault_status,
823 * 1. PROXY_CALCSIZE - calculate the buffer size
824 * 2. PROXY_GETBUFFER - allocate the buffer
825 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
826 * 4. PROXY_SENDRECEIVE - send/receive buffer
827 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
829 for (phase = PROXY_CALCSIZE; phase <= PROXY_UNMARSHAL; phase++)
831 TRACE("phase = %d\n", phase);
834 case PROXY_GETBUFFER:
835 /* allocate the buffer */
836 if (Oif_flags.HasPipes)
837 /* NdrGetPipeBuffer(...) */
838 FIXME("pipes not supported yet\n");
841 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
843 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
845 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
848 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
851 case PROXY_SENDRECEIVE:
852 /* send the [in] params and receive the [out] and [retval]
854 if (Oif_flags.HasPipes)
855 /* NdrPipesSendReceive(...) */
856 FIXME("pipes not supported yet\n");
859 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
861 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
863 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
866 NdrSendReceive(&stubMsg, stubMsg.Buffer);
869 /* convert strings, floating point values and endianess into our
870 * preferred format */
871 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
872 NdrConvert(&stubMsg, pFormat);
877 case PROXY_UNMARSHAL:
879 client_do_args(&stubMsg, pFormat, phase, stubMsg.StackTop,
880 number_of_params, (unsigned char *)&RetVal);
882 client_do_args_old_format(&stubMsg, pFormat, phase,
883 stubMsg.StackTop, stack_size, (unsigned char *)&RetVal,
884 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT), FALSE);
887 ERR("shouldn't reach here. phase %d\n", phase);
893 if (ext_flags.HasNewCorrDesc)
895 /* free extra correlation package */
896 NdrCorrelationFree(&stubMsg);
899 if (Oif_flags.HasPipes)
901 /* NdrPipesDone(...) */
904 /* free the full pointer translation tables */
905 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
906 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
908 /* free marshalling buffer */
909 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
910 NdrProxyFreeBuffer(This, &stubMsg);
913 NdrFreeBuffer(&stubMsg);
914 client_free_handle(&stubMsg, pProcHeader, pHandleFormat, hBinding);
918 TRACE("RetVal = 0x%lx\n", RetVal);
919 return *(CLIENT_CALL_RETURN *)&RetVal;
922 /* Calls a function with the specified arguments, restoring the stack
923 * properly afterwards as we don't know the calling convention of the
925 #if defined __i386__ && defined _MSC_VER
926 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
931 push edi ; Save registers
934 mov eax, [ebp+16] ; Get stack size
935 sub esp, eax ; Make room in stack for arguments
941 rep movsd ; Copy dword blocks
942 call [ebp+8] ; Call function
943 lea esp, [ebp-8] ; Restore stack
944 pop esi ; Restore registers
950 #elif defined __i386__ && defined __GNUC__
951 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
952 __ASM_GLOBAL_FUNC(call_server_func,
954 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
955 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
957 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
958 "pushl %edi\n\t" /* Save registers */
959 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
961 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
962 "movl 16(%ebp), %eax\n\t" /* Get stack size */
963 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
964 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
965 "movl %esp, %edi\n\t"
966 "movl %eax, %ecx\n\t"
967 "movl 12(%ebp), %esi\n\t"
968 "shrl $2, %ecx\n\t" /* divide by 4 */
970 "rep; movsl\n\t" /* Copy dword blocks */
971 "call *8(%ebp)\n\t" /* Call function */
972 "leal -8(%ebp), %esp\n\t" /* Restore stack */
973 "popl %esi\n\t" /* Restore registers */
974 __ASM_CFI(".cfi_same_value %esi\n\t")
976 __ASM_CFI(".cfi_same_value %edi\n\t")
978 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
979 __ASM_CFI(".cfi_same_value %ebp\n\t")
982 #warning call_server_func not implemented for your architecture
983 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
985 FIXME("Not implemented for your architecture\n");
990 static DWORD calc_arg_size(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
996 size = *(const WORD*)(pFormat + 2);
998 case RPC_FC_BOGUS_STRUCT:
999 size = *(const WORD*)(pFormat + 2);
1000 if(*(const WORD*)(pFormat + 4))
1001 FIXME("Unhandled conformant description\n");
1004 size = *(const WORD*)(pFormat + 2);
1005 ComputeConformance(pStubMsg, NULL, pFormat + 4, 0);
1006 size *= pStubMsg->MaxCount;
1008 case RPC_FC_SMFARRAY:
1009 size = *(const WORD*)(pFormat + 2);
1011 case RPC_FC_LGFARRAY:
1012 size = *(const DWORD*)(pFormat + 2);
1014 case RPC_FC_BOGUS_ARRAY:
1015 pFormat = ComputeConformance(pStubMsg, NULL, pFormat + 4, *(const WORD*)&pFormat[2]);
1016 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
1017 pFormat = ComputeVariance(pStubMsg, NULL, pFormat, pStubMsg->MaxCount);
1018 size = ComplexStructSize(pStubMsg, pFormat);
1019 size *= pStubMsg->MaxCount;
1021 case RPC_FC_C_CSTRING:
1022 case RPC_FC_C_WSTRING:
1023 if (*pFormat == RPC_FC_C_CSTRING)
1024 size = sizeof(CHAR);
1026 size = sizeof(WCHAR);
1027 if (pFormat[1] == RPC_FC_STRING_SIZED)
1028 ComputeConformance(pStubMsg, NULL, pFormat + 2, 0);
1030 pStubMsg->MaxCount = 0;
1031 size *= pStubMsg->MaxCount;
1034 FIXME("Unhandled type %02x\n", *pFormat);
1037 size = sizeof(void *);
1043 static LONG_PTR *stub_do_args(MIDL_STUB_MESSAGE *pStubMsg,
1044 PFORMAT_STRING pFormat, int phase,
1045 unsigned char *args,
1046 unsigned short number_of_params)
1050 /* current format string offset */
1051 int current_offset = 0;
1052 /* current stack offset */
1053 unsigned short current_stack_offset = 0;
1054 /* location to put retval into */
1055 LONG_PTR *retval_ptr = NULL;
1057 for (i = 0; i < number_of_params; i++)
1059 const NDR_PARAM_OIF_BASETYPE *pParam =
1060 (const NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];
1061 unsigned char *pArg;
1063 current_stack_offset = pParam->stack_offset;
1064 pArg = args + current_stack_offset;
1066 TRACE("param[%d]: new format\n", i);
1067 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");
1068 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
1069 TRACE("\tmemory addr (before): %p -> %p\n", pArg, *(unsigned char **)pArg);
1071 if (pParam->param_attributes.IsBasetype)
1073 const unsigned char *pTypeFormat =
1074 &pParam->type_format_char;
1076 TRACE("\tbase type: 0x%02x\n", *pTypeFormat);
1078 /* make a note of the address of the return value parameter for later */
1079 if (pParam->param_attributes.IsReturn)
1080 retval_ptr = (LONG_PTR *)pArg;
1084 case STUBLESS_MARSHAL:
1085 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1087 if (pParam->param_attributes.IsSimpleRef)
1088 call_marshaller(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
1090 call_marshaller(pStubMsg, pArg, pTypeFormat);
1094 if (pParam->param_attributes.ServerAllocSize)
1095 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1097 case STUBLESS_INITOUT:
1099 case STUBLESS_UNMARSHAL:
1100 if (pParam->param_attributes.ServerAllocSize)
1101 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1102 pParam->param_attributes.ServerAllocSize * 8);
1104 if (pParam->param_attributes.IsIn)
1106 if (pParam->param_attributes.IsSimpleRef)
1107 call_unmarshaller(pStubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1109 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
1112 case STUBLESS_CALCSIZE:
1113 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1115 if (pParam->param_attributes.IsSimpleRef)
1116 call_buffer_sizer(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
1118 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
1122 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1125 current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);
1129 const NDR_PARAM_OIF_OTHER *pParamOther =
1130 (const NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];
1132 const unsigned char * pTypeFormat =
1133 &(pStubMsg->StubDesc->pFormatTypes[pParamOther->type_offset]);
1135 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
1139 case STUBLESS_MARSHAL:
1140 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1142 if (pParam->param_attributes.IsByValue)
1143 call_marshaller(pStubMsg, pArg, pTypeFormat);
1145 call_marshaller(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
1149 if (pParam->param_attributes.MustFree)
1151 if (pParam->param_attributes.IsByValue)
1152 call_freer(pStubMsg, pArg, pTypeFormat);
1154 call_freer(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
1157 if (pParam->param_attributes.IsOut &&
1158 !pParam->param_attributes.IsIn &&
1159 !pParam->param_attributes.IsByValue &&
1160 !pParam->param_attributes.ServerAllocSize)
1162 if (*pTypeFormat != RPC_FC_BIND_CONTEXT)
1163 pStubMsg->pfnFree(*(void **)pArg);
1166 if (pParam->param_attributes.ServerAllocSize)
1167 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1169 case STUBLESS_INITOUT:
1170 if (!pParam->param_attributes.IsIn &&
1171 pParam->param_attributes.IsOut &&
1172 !pParam->param_attributes.ServerAllocSize &&
1173 !pParam->param_attributes.IsByValue)
1175 if (*pTypeFormat == RPC_FC_BIND_CONTEXT)
1177 NDR_SCONTEXT ctxt = NdrContextHandleInitialize(
1178 pStubMsg, pTypeFormat);
1179 *(void **)pArg = NDRSContextValue(ctxt);
1183 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1187 *(void **)pArg = NdrAllocate(pStubMsg, size);
1188 memset(*(void **)pArg, 0, size);
1193 case STUBLESS_UNMARSHAL:
1194 if (pParam->param_attributes.ServerAllocSize)
1195 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1196 pParam->param_attributes.ServerAllocSize * 8);
1198 if (pParam->param_attributes.IsIn)
1200 if (pParam->param_attributes.IsByValue)
1201 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
1203 call_unmarshaller(pStubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1206 case STUBLESS_CALCSIZE:
1207 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1209 if (pParam->param_attributes.IsByValue)
1210 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
1212 call_buffer_sizer(pStubMsg, *(unsigned char **)pArg, pTypeFormat);
1216 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1219 current_offset += sizeof(NDR_PARAM_OIF_OTHER);
1221 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1227 static LONG_PTR *stub_do_old_args(MIDL_STUB_MESSAGE *pStubMsg,
1228 PFORMAT_STRING pFormat, int phase,
1229 unsigned char *args,
1230 unsigned short stack_size, BOOL object)
1234 /* current format string offset */
1235 int current_offset = 0;
1236 /* current stack offset */
1237 unsigned short current_stack_offset = object ? sizeof(void *) : 0;
1238 /* location to put retval into */
1239 LONG_PTR *retval_ptr = NULL;
1241 for (i = 0; TRUE; i++)
1243 const NDR_PARAM_OI_BASETYPE *pParam =
1244 (const NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];
1245 unsigned char *pArg = args + current_stack_offset;
1247 /* no more parameters; exit loop */
1248 if (current_stack_offset >= stack_size)
1251 TRACE("param[%d]: old format\n", i);
1252 TRACE("\tparam_direction: 0x%x\n", pParam->param_direction);
1253 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
1255 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||
1256 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1258 const unsigned char *pTypeFormat =
1259 &pParam->type_format_char;
1261 TRACE("\tbase type 0x%02x\n", *pTypeFormat);
1263 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1264 retval_ptr = (LONG_PTR *)pArg;
1268 case STUBLESS_MARSHAL:
1269 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1270 call_marshaller(pStubMsg, pArg, pTypeFormat);
1273 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
1274 call_freer(pStubMsg, pArg, pTypeFormat);
1276 case STUBLESS_INITOUT:
1278 case STUBLESS_UNMARSHAL:
1279 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
1280 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
1282 case STUBLESS_CALCSIZE:
1283 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1284 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
1287 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1290 current_stack_offset += type_stack_size(*pTypeFormat);
1291 current_offset += sizeof(NDR_PARAM_OI_BASETYPE);
1295 const NDR_PARAM_OI_OTHER *pParamOther =
1296 (const NDR_PARAM_OI_OTHER *)&pFormat[current_offset];
1298 const unsigned char * pTypeFormat =
1299 &pStubMsg->StubDesc->pFormatTypes[pParamOther->type_offset];
1300 const BOOL by_value = is_by_value( pTypeFormat );
1302 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
1304 if (pParam->param_direction == RPC_FC_RETURN_PARAM)
1305 retval_ptr = (LONG_PTR *)pArg;
1309 case STUBLESS_MARSHAL:
1310 if (pParam->param_direction == RPC_FC_OUT_PARAM ||
1311 pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1312 pParam->param_direction == RPC_FC_RETURN_PARAM)
1314 if (!by_value) pArg = *(unsigned char **)pArg;
1315 call_marshaller(pStubMsg, pArg, pTypeFormat);
1319 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1320 pParam->param_direction == RPC_FC_IN_PARAM)
1322 if (!by_value) pArg = *(unsigned char **)pArg;
1323 call_freer(pStubMsg, pArg, pTypeFormat);
1325 else if (pParam->param_direction == RPC_FC_OUT_PARAM && !by_value)
1326 pStubMsg->pfnFree(*(void **)pArg);
1328 case STUBLESS_INITOUT:
1329 if (pParam->param_direction == RPC_FC_OUT_PARAM && !by_value)
1331 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1335 *(void **)pArg = NdrAllocate(pStubMsg, size);
1336 memset(*(void **)pArg, 0, size);
1340 case STUBLESS_UNMARSHAL:
1341 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1342 pParam->param_direction == RPC_FC_IN_PARAM)
1345 call_unmarshaller(pStubMsg, &pArg, pTypeFormat, 0);
1347 call_unmarshaller(pStubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1350 case STUBLESS_CALCSIZE:
1351 if (pParam->param_direction == RPC_FC_OUT_PARAM ||
1352 pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1353 pParam->param_direction == RPC_FC_RETURN_PARAM)
1355 if (!by_value) pArg = *(unsigned char **)pArg;
1356 call_buffer_sizer(pStubMsg, pArg, pTypeFormat);
1360 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1363 current_stack_offset += pParamOther->stack_size * sizeof(void *);
1364 current_offset += sizeof(NDR_PARAM_OI_OTHER);
1371 /***********************************************************************
1372 * NdrStubCall2 [RPCRT4.@]
1374 * Unmarshals [in] parameters, calls either a method in an object or a server
1375 * function, marshals any [out] parameters and frees any allocated data.
1378 * Used by stubless MIDL-generated code.
1380 LONG WINAPI NdrStubCall2(
1381 struct IRpcStubBuffer * pThis,
1382 struct IRpcChannelBuffer * pChannel,
1383 PRPC_MESSAGE pRpcMsg,
1384 DWORD * pdwStubPhase)
1386 const MIDL_SERVER_INFO *pServerInfo;
1387 const MIDL_STUB_DESC *pStubDesc;
1388 PFORMAT_STRING pFormat;
1389 MIDL_STUB_MESSAGE stubMsg;
1390 /* pointer to start of stack to pass into stub implementation */
1391 unsigned char * args;
1393 unsigned short stack_size;
1394 /* number of parameters. optional for client to give it to us */
1395 unsigned char number_of_params = ~0;
1396 /* cache of Oif_flags from v2 procedure header */
1397 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1398 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1399 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1400 /* the type of pass we are currently doing */
1402 /* header for procedure string */
1403 const NDR_PROC_HEADER *pProcHeader;
1404 /* offset in format string for start of params */
1405 int parameter_start_offset;
1406 /* current format string offset */
1408 /* -Oif or -Oicf generated format */
1409 BOOL bV2Format = FALSE;
1410 /* location to put retval into */
1411 LONG_PTR *retval_ptr = NULL;
1413 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1416 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1418 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1420 pStubDesc = pServerInfo->pStubDesc;
1421 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1422 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1424 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
1426 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1428 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1429 stack_size = pProcHeader->stack_size;
1430 current_offset = sizeof(NDR_PROC_HEADER_RPC);
1435 stack_size = pProcHeader->stack_size;
1436 current_offset = sizeof(NDR_PROC_HEADER);
1439 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1442 switch (pProcHeader->handle_type)
1444 /* explicit binding: parse additional section */
1445 case RPC_FC_BIND_EXPLICIT:
1446 switch (pFormat[current_offset]) /* handle_type */
1448 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
1449 current_offset += sizeof(NDR_EHD_PRIMITIVE);
1451 case RPC_FC_BIND_GENERIC: /* explicit generic */
1452 current_offset += sizeof(NDR_EHD_GENERIC);
1454 case RPC_FC_BIND_CONTEXT: /* explicit context */
1455 current_offset += sizeof(NDR_EHD_CONTEXT);
1458 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1459 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1462 case RPC_FC_BIND_GENERIC: /* implicit generic */
1463 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
1464 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
1465 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
1468 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1469 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1472 bV2Format = (pStubDesc->Version >= 0x20000);
1476 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1477 (const NDR_PROC_PARTIAL_OIF_HEADER *)&pFormat[current_offset];
1479 Oif_flags = pOIFHeader->Oi2Flags;
1480 number_of_params = pOIFHeader->number_of_params;
1482 current_offset += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1485 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags);
1487 if (Oif_flags.HasExtensions)
1489 const NDR_PROC_HEADER_EXTS *pExtensions =
1490 (const NDR_PROC_HEADER_EXTS *)&pFormat[current_offset];
1491 ext_flags = pExtensions->Flags2;
1492 current_offset += pExtensions->Size;
1495 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1496 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1498 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1500 /* create the full pointer translation tables, if requested */
1501 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1502 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1504 /* store the RPC flags away */
1505 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1506 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1508 /* use alternate memory allocation routines */
1509 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1511 NdrRpcSsEnableAllocate(&stubMsg);
1513 FIXME("Set RPCSS memory allocation routines\n");
1516 if (Oif_flags.HasPipes)
1518 FIXME("pipes not supported yet\n");
1519 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1520 /* init pipes package */
1521 /* NdrPipesInitialize(...) */
1523 if (ext_flags.HasNewCorrDesc)
1525 /* initialize extra correlation package */
1526 FIXME("new correlation description not implemented\n");
1527 stubMsg.fHasNewCorrDesc = TRUE;
1530 /* convert strings, floating point values and endianess into our
1531 * preferred format */
1532 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1533 NdrConvert(&stubMsg, pFormat);
1535 parameter_start_offset = current_offset;
1537 TRACE("allocating memory for stack of size %x\n", stack_size);
1539 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1540 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1542 /* add the implicit This pointer as the first arg to the function if we
1543 * are calling an object method */
1545 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1547 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_FREE; phase++)
1549 TRACE("phase = %d\n", phase);
1552 case STUBLESS_CALLSERVER:
1553 /* call the server function */
1554 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1555 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1558 SERVER_ROUTINE func;
1561 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1563 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1564 func = vtbl[pRpcMsg->ProcNum];
1567 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1569 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1570 retval = call_server_func(func, args, stack_size);
1574 TRACE("stub implementation returned 0x%lx\n", retval);
1575 *retval_ptr = retval;
1578 TRACE("void stub implementation\n");
1581 stubMsg.Buffer = NULL;
1582 stubMsg.BufferLength = 0;
1585 case STUBLESS_GETBUFFER:
1586 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1587 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1592 pRpcMsg->BufferLength = stubMsg.BufferLength;
1593 /* allocate buffer for [out] and [ret] params */
1594 Status = I_RpcGetBuffer(pRpcMsg);
1596 RpcRaiseException(Status);
1597 stubMsg.Buffer = pRpcMsg->Buffer;
1600 case STUBLESS_UNMARSHAL:
1601 case STUBLESS_INITOUT:
1602 case STUBLESS_CALCSIZE:
1603 case STUBLESS_MARSHAL:
1606 retval_ptr = stub_do_args(&stubMsg, &pFormat[parameter_start_offset],
1607 phase, args, number_of_params);
1609 retval_ptr = stub_do_old_args(&stubMsg, &pFormat[parameter_start_offset],
1610 phase, args, stack_size,
1611 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT));
1615 ERR("shouldn't reach here. phase %d\n", phase);
1620 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1622 if (ext_flags.HasNewCorrDesc)
1624 /* free extra correlation package */
1625 /* NdrCorrelationFree(&stubMsg); */
1628 if (Oif_flags.HasPipes)
1630 /* NdrPipesDone(...) */
1633 /* free the full pointer translation tables */
1634 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1635 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1637 /* free server function stack */
1638 HeapFree(GetProcessHeap(), 0, args);
1643 /***********************************************************************
1644 * NdrServerCall2 [RPCRT4.@]
1646 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1649 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
1652 /***********************************************************************
1653 * NdrClientCall [RPCRT4.@]
1655 CLIENT_CALL_RETURN WINAPIV NdrClientCall( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1658 CLIENT_CALL_RETURN ret;
1660 __ms_va_start( args, format );
1661 ret = NdrClientCall2( desc, format, va_arg( args, unsigned char * ));
1662 __ms_va_end( args );
1666 /***********************************************************************
1667 * NdrStubCall [RPCRT4.@]
1669 LONG WINAPI NdrStubCall( struct IRpcStubBuffer *This, struct IRpcChannelBuffer *channel,
1670 PRPC_MESSAGE msg, DWORD *phase )
1672 return NdrStubCall2( This, channel, msg, phase );
1675 /***********************************************************************
1676 * NdrServerCall [RPCRT4.@]
1678 void WINAPI NdrServerCall( PRPC_MESSAGE msg )
1681 NdrStubCall( NULL, NULL, msg, &phase );
1684 struct async_call_data
1686 MIDL_STUB_MESSAGE *pStubMsg;
1687 const NDR_PROC_HEADER *pProcHeader;
1688 PFORMAT_STRING pHandleFormat;
1689 PFORMAT_STRING pParamFormat;
1690 RPC_BINDING_HANDLE hBinding;
1692 unsigned short stack_size;
1693 /* number of parameters. optional for client to give it to us */
1694 unsigned char number_of_params;
1695 /* correlation cache */
1696 ULONG_PTR NdrCorrCache[256];
1699 CLIENT_CALL_RETURN WINAPIV NdrAsyncClientCall(PMIDL_STUB_DESC pStubDesc,
1700 PFORMAT_STRING pFormat, ...)
1702 /* pointer to start of stack where arguments start */
1703 PRPC_MESSAGE pRpcMsg;
1704 PMIDL_STUB_MESSAGE pStubMsg;
1705 RPC_ASYNC_STATE *pAsync;
1706 struct async_call_data *async_call_data;
1707 /* procedure number */
1708 unsigned short procedure_number;
1709 /* cache of Oif_flags from v2 procedure header */
1710 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1711 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1712 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1713 /* the type of pass we are currently doing */
1715 /* header for procedure string */
1716 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1717 /* -Oif or -Oicf generated format */
1718 BOOL bV2Format = FALSE;
1722 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
1724 /* Later NDR language versions probably won't be backwards compatible */
1725 if (pStubDesc->Version > 0x50002)
1727 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
1728 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1731 async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
1732 if (!async_call_data) RpcRaiseException(ERROR_OUTOFMEMORY);
1733 async_call_data->number_of_params = ~0;
1734 async_call_data->pProcHeader = pProcHeader;
1736 async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
1737 pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
1739 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1741 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1742 async_call_data->stack_size = pProcHeader->stack_size;
1743 procedure_number = pProcHeader->proc_num;
1744 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1748 async_call_data->stack_size = pProcHeader->stack_size;
1749 procedure_number = pProcHeader->proc_num;
1750 pFormat += sizeof(NDR_PROC_HEADER);
1752 TRACE("stack size: 0x%x\n", async_call_data->stack_size);
1753 TRACE("proc num: %d\n", procedure_number);
1755 /* create the full pointer translation tables, if requested */
1756 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1757 pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
1759 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1761 ERR("objects not supported\n");
1762 I_RpcFree(async_call_data);
1763 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1766 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
1768 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1769 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
1771 /* needed for conformance of top-level objects */
1772 pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
1773 __ms_va_start( args, pFormat );
1774 memcpy(pStubMsg->StackTop, va_arg( args, unsigned char * ), async_call_data->stack_size);
1775 __ms_va_end( args );
1777 pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
1778 pAsync->StubInfo = async_call_data;
1779 async_call_data->pHandleFormat = pFormat;
1781 pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
1782 if (!pFormat) goto done;
1784 bV2Format = (pStubDesc->Version >= 0x20000);
1788 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1789 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1791 Oif_flags = pOIFHeader->Oi2Flags;
1792 async_call_data->number_of_params = pOIFHeader->number_of_params;
1794 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1797 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags);
1799 if (Oif_flags.HasExtensions)
1801 const NDR_PROC_HEADER_EXTS *pExtensions =
1802 (const NDR_PROC_HEADER_EXTS *)pFormat;
1803 ext_flags = pExtensions->Flags2;
1804 pFormat += pExtensions->Size;
1807 async_call_data->pParamFormat = pFormat;
1809 pStubMsg->BufferLength = 0;
1811 /* store the RPC flags away */
1812 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1813 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1815 /* use alternate memory allocation routines */
1816 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1817 NdrRpcSmSetClientToOsf(pStubMsg);
1819 if (Oif_flags.HasPipes)
1821 FIXME("pipes not supported yet\n");
1822 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1823 /* init pipes package */
1824 /* NdrPipesInitialize(...) */
1826 if (ext_flags.HasNewCorrDesc)
1828 /* initialize extra correlation package */
1829 NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
1833 * 1. PROXY_CALCSIZE - calculate the buffer size
1834 * 2. PROXY_GETBUFFER - allocate the buffer
1835 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
1836 * 4. PROXY_SENDRECEIVE - send buffer
1837 * Then in NdrpCompleteAsyncClientCall:
1838 * 1. PROXY_SENDRECEIVE - receive buffer
1839 * 2. PROXY_UNMARHSAL - unmarshal [out] params from buffer
1841 for (phase = PROXY_CALCSIZE; phase <= PROXY_SENDRECEIVE; phase++)
1844 TRACE("phase = %d\n", phase);
1847 case PROXY_GETBUFFER:
1848 /* allocate the buffer */
1849 if (Oif_flags.HasPipes)
1850 /* NdrGetPipeBuffer(...) */
1851 FIXME("pipes not supported yet\n");
1854 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1856 NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1858 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1861 NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1863 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1864 status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
1865 if (status != RPC_S_OK)
1866 RpcRaiseException(status);
1868 case PROXY_SENDRECEIVE:
1869 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1870 /* send the [in] params only */
1871 if (Oif_flags.HasPipes)
1872 /* NdrPipesSend(...) */
1873 FIXME("pipes not supported yet\n");
1876 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1878 NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1880 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1884 pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
1885 status = I_RpcSend(pStubMsg->RpcMsg);
1886 if (status != RPC_S_OK)
1887 RpcRaiseException(status);
1892 case PROXY_CALCSIZE:
1895 client_do_args(pStubMsg, pFormat, phase, pStubMsg->StackTop,
1896 async_call_data->number_of_params, NULL);
1898 client_do_args_old_format(pStubMsg, pFormat, phase,
1899 pStubMsg->StackTop, async_call_data->stack_size, NULL,
1900 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT), FALSE);
1903 ERR("shouldn't reach here. phase %d\n", phase);
1909 TRACE("returning 0\n");
1911 return *(CLIENT_CALL_RETURN *)&RetVal;
1914 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
1916 /* pointer to start of stack where arguments start */
1917 PMIDL_STUB_MESSAGE pStubMsg;
1918 struct async_call_data *async_call_data;
1919 /* the type of pass we are currently doing */
1921 /* header for procedure string */
1922 const NDR_PROC_HEADER * pProcHeader;
1923 /* -Oif or -Oicf generated format */
1925 RPC_STATUS status = RPC_S_OK;
1927 if (!pAsync->StubInfo)
1928 return RPC_S_INVALID_ASYNC_HANDLE;
1930 async_call_data = pAsync->StubInfo;
1931 pStubMsg = async_call_data->pStubMsg;
1932 pProcHeader = async_call_data->pProcHeader;
1934 bV2Format = (pStubMsg->StubDesc->Version >= 0x20000);
1937 * 1. PROXY_CALCSIZE - calculate the buffer size
1938 * 2. PROXY_GETBUFFER - allocate the buffer
1939 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
1940 * 4. PROXY_SENDRECEIVE - send buffer
1941 * Then in NdrpCompleteAsyncClientCall:
1942 * 1. PROXY_SENDRECEIVE - receive buffer
1943 * 2. PROXY_UNMARHSAL - unmarshal [out] params from buffer
1945 for (phase = PROXY_SENDRECEIVE; phase <= PROXY_UNMARSHAL; phase++)
1949 case PROXY_SENDRECEIVE:
1950 pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1951 /* receive the [out] params */
1952 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1954 NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1956 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1960 status = I_RpcReceive(pStubMsg->RpcMsg);
1961 if (status != RPC_S_OK)
1963 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
1964 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
1965 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
1966 pStubMsg->Buffer = pStubMsg->BufferStart;
1969 /* convert strings, floating point values and endianess into our
1970 * preferred format */
1972 if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1973 NdrConvert(pStubMsg, pFormat);
1977 case PROXY_UNMARSHAL:
1979 client_do_args(pStubMsg, async_call_data->pParamFormat, phase, pStubMsg->StackTop,
1980 async_call_data->number_of_params, Reply);
1982 client_do_args_old_format(pStubMsg, async_call_data->pParamFormat, phase,
1983 pStubMsg->StackTop, async_call_data->stack_size, Reply, FALSE, FALSE);
1986 ERR("shouldn't reach here. phase %d\n", phase);
1992 if (pStubMsg->fHasNewCorrDesc)
1994 /* free extra correlation package */
1995 NdrCorrelationFree(pStubMsg);
1998 /* free the full pointer translation tables */
1999 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
2000 NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
2002 /* free marshalling buffer */
2003 NdrFreeBuffer(pStubMsg);
2004 client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
2006 I_RpcFree(pStubMsg->StackTop);
2007 I_RpcFree(async_call_data);
2009 TRACE("-- 0x%x\n", status);
2013 RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
2014 struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
2015 DWORD * pdwStubPhase)
2017 FIXME("unimplemented, expect crash!\n");