quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / rpcrt4 / ndr_stubless.c
blob5eb699e181d890682fa51c1f95716aab9e181da1
1 /*
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
21 * TODO:
22 * - Pipes
23 * - Some types of binding handles
26 #include "config.h"
27 #include "wine/port.h"
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winerror.h"
37 #include "objbase.h"
38 #include "rpc.h"
39 #include "rpcproxy.h"
41 #include "wine/exception.h"
42 #include "wine/debug.h"
43 #include "wine/rpcfc.h"
45 #include "cpsf.h"
46 #include "ndr_misc.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,
54 const NDR_PARAM_OIF *param)
56 PFORMAT_STRING pFormat;
57 NDR_BUFFERSIZE m;
59 if (param->attr.IsBasetype)
61 pFormat = &param->u.type_format_char;
62 if (param->attr.IsSimpleRef) pMemory = *(unsigned char **)pMemory;
64 else
66 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
67 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
70 m = NdrBufferSizer[pFormat[0] & NDR_TABLE_MASK];
71 if (m) m(pStubMsg, pMemory, pFormat);
72 else
74 FIXME("format type 0x%x not implemented\n", pFormat[0]);
75 RpcRaiseException(RPC_X_BAD_STUB_DATA);
79 static inline unsigned char *call_marshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
80 const NDR_PARAM_OIF *param)
82 PFORMAT_STRING pFormat;
83 NDR_MARSHALL m;
85 if (param->attr.IsBasetype)
87 pFormat = &param->u.type_format_char;
88 if (param->attr.IsSimpleRef) pMemory = *(unsigned char **)pMemory;
90 else
92 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
93 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
96 m = NdrMarshaller[pFormat[0] & NDR_TABLE_MASK];
97 if (m) return m(pStubMsg, pMemory, pFormat);
98 else
100 FIXME("format type 0x%x not implemented\n", pFormat[0]);
101 RpcRaiseException(RPC_X_BAD_STUB_DATA);
102 return NULL;
106 static inline unsigned char *call_unmarshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char **ppMemory,
107 const NDR_PARAM_OIF *param, unsigned char fMustAlloc)
109 PFORMAT_STRING pFormat;
110 NDR_UNMARSHALL m;
112 if (param->attr.IsBasetype)
114 pFormat = &param->u.type_format_char;
115 if (param->attr.IsSimpleRef) ppMemory = (unsigned char **)*ppMemory;
117 else
119 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
120 if (!param->attr.IsByValue) ppMemory = (unsigned char **)*ppMemory;
123 m = NdrUnmarshaller[pFormat[0] & NDR_TABLE_MASK];
124 if (m) return m(pStubMsg, ppMemory, pFormat, fMustAlloc);
125 else
127 FIXME("format type 0x%x not implemented\n", pFormat[0]);
128 RpcRaiseException(RPC_X_BAD_STUB_DATA);
129 return NULL;
133 static inline void call_freer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
134 const NDR_PARAM_OIF *param)
136 PFORMAT_STRING pFormat;
137 NDR_FREE m;
139 if (param->attr.IsBasetype) return; /* nothing to do */
140 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
141 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
143 m = NdrFreer[pFormat[0] & NDR_TABLE_MASK];
144 if (m) m(pStubMsg, pMemory, pFormat);
147 static DWORD calc_arg_size(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
149 DWORD size;
150 switch(*pFormat)
152 case RPC_FC_RP:
153 if (pFormat[1] & RPC_FC_P_SIMPLEPOINTER)
155 FIXME("Simple reference pointer (type %#x).\n", pFormat[2]);
156 size = sizeof(void *);
157 break;
159 size = calc_arg_size(pStubMsg, &pFormat[2] + *(WORD *)&pFormat[2]);
160 break;
161 case RPC_FC_STRUCT:
162 case RPC_FC_PSTRUCT:
163 size = *(const WORD*)(pFormat + 2);
164 break;
165 case RPC_FC_BOGUS_STRUCT:
166 size = *(const WORD*)(pFormat + 2);
167 if(*(const WORD*)(pFormat + 4))
168 FIXME("Unhandled conformant description\n");
169 break;
170 case RPC_FC_CARRAY:
171 case RPC_FC_CVARRAY:
172 size = *(const WORD*)(pFormat + 2);
173 ComputeConformance(pStubMsg, NULL, pFormat + 4, 0);
174 size *= pStubMsg->MaxCount;
175 break;
176 case RPC_FC_SMFARRAY:
177 case RPC_FC_SMVARRAY:
178 size = *(const WORD*)(pFormat + 2);
179 break;
180 case RPC_FC_LGFARRAY:
181 case RPC_FC_LGVARRAY:
182 size = *(const DWORD*)(pFormat + 2);
183 break;
184 case RPC_FC_BOGUS_ARRAY:
185 pFormat = ComputeConformance(pStubMsg, NULL, pFormat + 4, *(const WORD*)&pFormat[2]);
186 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
187 pFormat = ComputeVariance(pStubMsg, NULL, pFormat, pStubMsg->MaxCount);
188 size = ComplexStructSize(pStubMsg, pFormat);
189 size *= pStubMsg->MaxCount;
190 break;
191 case RPC_FC_USER_MARSHAL:
192 size = *(const WORD*)(pFormat + 4);
193 break;
194 case RPC_FC_CSTRING:
195 size = *(const WORD*)(pFormat + 2);
196 break;
197 case RPC_FC_WSTRING:
198 size = *(const WORD*)(pFormat + 2) * sizeof(WCHAR);
199 break;
200 case RPC_FC_C_CSTRING:
201 case RPC_FC_C_WSTRING:
202 if (*pFormat == RPC_FC_C_CSTRING)
203 size = sizeof(CHAR);
204 else
205 size = sizeof(WCHAR);
206 if (pFormat[1] == RPC_FC_STRING_SIZED)
207 ComputeConformance(pStubMsg, NULL, pFormat + 2, 0);
208 else
209 pStubMsg->MaxCount = 0;
210 size *= pStubMsg->MaxCount;
211 break;
212 default:
213 FIXME("Unhandled type %02x\n", *pFormat);
214 size = sizeof(void *);
215 break;
217 return size;
220 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
222 #if 0 /* these functions are not defined yet */
223 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
224 pMessage->pfnFree = NdrRpcSmClientFree;
225 #endif
228 static const char *debugstr_PROC_PF(PARAM_ATTRIBUTES param_attributes)
230 char buffer[160];
232 buffer[0] = 0;
233 if (param_attributes.MustSize) strcat(buffer, " MustSize");
234 if (param_attributes.MustFree) strcat(buffer, " MustFree");
235 if (param_attributes.IsPipe) strcat(buffer, " IsPipe");
236 if (param_attributes.IsIn) strcat(buffer, " IsIn");
237 if (param_attributes.IsOut) strcat(buffer, " IsOut");
238 if (param_attributes.IsReturn) strcat(buffer, " IsReturn");
239 if (param_attributes.IsBasetype) strcat(buffer, " IsBasetype");
240 if (param_attributes.IsByValue) strcat(buffer, " IsByValue");
241 if (param_attributes.IsSimpleRef) strcat(buffer, " IsSimpleRef");
242 if (param_attributes.IsDontCallFreeInst) strcat(buffer, " IsDontCallFreeInst");
243 if (param_attributes.SaveForAsyncFinish) strcat(buffer, " SaveForAsyncFinish");
244 if (param_attributes.ServerAllocSize)
245 sprintf( buffer + strlen(buffer), " ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
246 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
249 static const char *debugstr_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
251 char buffer[160];
253 buffer[0] = 0;
254 if (Oi2Flags.ServerMustSize) strcat(buffer, " ServerMustSize");
255 if (Oi2Flags.ClientMustSize) strcat(buffer, " ClientMustSize");
256 if (Oi2Flags.HasReturn) strcat(buffer, " HasReturn");
257 if (Oi2Flags.HasPipes) strcat(buffer, " HasPipes");
258 if (Oi2Flags.Unused) strcat(buffer, " Unused");
259 if (Oi2Flags.HasAsyncUuid) strcat(buffer, " HasAsyncUuid");
260 if (Oi2Flags.HasExtensions) strcat(buffer, " HasExtensions");
261 if (Oi2Flags.HasAsyncHandle) strcat(buffer, " HasAsyncHandle");
262 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
265 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
267 static PFORMAT_STRING client_get_handle(
268 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
269 PFORMAT_STRING pFormat, handle_t *phBinding)
271 /* binding */
272 switch (pProcHeader->handle_type)
274 /* explicit binding: parse additional section */
275 case RPC_FC_BIND_EXPLICIT:
276 switch (*pFormat) /* handle_type */
278 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
280 const NDR_EHD_PRIMITIVE *pDesc = (const NDR_EHD_PRIMITIVE *)pFormat;
282 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
284 if (pDesc->flag) /* pointer to binding */
285 *phBinding = **(handle_t **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
286 else
287 *phBinding = *(handle_t *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
288 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
290 case RPC_FC_BIND_GENERIC: /* explicit generic */
292 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
293 void *pObject = NULL;
294 void *pArg;
295 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
297 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
299 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
300 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
301 else
302 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
303 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
304 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
305 *phBinding = pGenPair->pfnBind(pObject);
306 return pFormat + sizeof(NDR_EHD_GENERIC);
308 case RPC_FC_BIND_CONTEXT: /* explicit context */
310 const NDR_EHD_CONTEXT *pDesc = (const NDR_EHD_CONTEXT *)pFormat;
311 NDR_CCONTEXT context_handle;
312 TRACE("Explicit bind context\n");
313 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
315 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
316 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
318 else
319 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
321 if (context_handle) *phBinding = NDRCContextBinding(context_handle);
322 else if (pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL)
324 ERR("null context handle isn't allowed\n");
325 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
326 return NULL;
328 /* FIXME: should we store this structure in stubMsg.pContext? */
329 return pFormat + sizeof(NDR_EHD_CONTEXT);
331 default:
332 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
333 RpcRaiseException(RPC_X_BAD_STUB_DATA);
335 break;
336 case RPC_FC_BIND_GENERIC: /* implicit generic */
337 FIXME("RPC_FC_BIND_GENERIC\n");
338 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
339 break;
340 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
341 TRACE("Implicit primitive handle\n");
342 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
343 break;
344 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
345 FIXME("RPC_FC_CALLBACK_HANDLE\n");
346 break;
347 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
348 /* strictly speaking, it isn't necessary to set hBinding here
349 * since it isn't actually used (hence the automatic in its name),
350 * but then why does MIDL generate a valid entry in the
351 * MIDL_STUB_DESC for it? */
352 TRACE("Implicit auto handle\n");
353 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
354 break;
355 default:
356 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
357 RpcRaiseException(RPC_X_BAD_STUB_DATA);
359 return pFormat;
362 static void client_free_handle(
363 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
364 PFORMAT_STRING pFormat, handle_t hBinding)
366 /* binding */
367 switch (pProcHeader->handle_type)
369 /* explicit binding: parse additional section */
370 case RPC_FC_BIND_EXPLICIT:
371 switch (*pFormat) /* handle_type */
373 case RPC_FC_BIND_GENERIC: /* explicit generic */
375 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
376 void *pObject = NULL;
377 void *pArg;
378 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
380 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
382 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
383 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
384 else
385 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
386 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
387 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
388 pGenPair->pfnUnbind(pObject, hBinding);
389 break;
391 case RPC_FC_BIND_CONTEXT: /* explicit context */
392 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
393 break;
394 default:
395 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
396 RpcRaiseException(RPC_X_BAD_STUB_DATA);
398 break;
399 case RPC_FC_BIND_GENERIC: /* implicit generic */
400 FIXME("RPC_FC_BIND_GENERIC\n");
401 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
402 break;
403 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
404 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
405 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
406 break;
407 default:
408 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
409 RpcRaiseException(RPC_X_BAD_STUB_DATA);
413 void client_do_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, enum stubless_phase phase,
414 void **fpu_args, unsigned short number_of_params, unsigned char *pRetVal )
416 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
417 unsigned int i;
419 for (i = 0; i < number_of_params; i++)
421 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
422 PFORMAT_STRING pTypeFormat = (PFORMAT_STRING)&pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
424 #ifdef __x86_64__ /* floats are passed as doubles through varargs functions */
425 float f;
427 if (params[i].attr.IsBasetype &&
428 params[i].u.type_format_char == RPC_FC_FLOAT &&
429 !params[i].attr.IsSimpleRef &&
430 !fpu_args)
432 f = *(double *)pArg;
433 pArg = (unsigned char *)&f;
435 #endif
437 TRACE("param[%d]: %p type %02x %s\n", i, pArg,
438 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
439 debugstr_PROC_PF( params[i].attr ));
441 switch (phase)
443 case STUBLESS_INITOUT:
444 if (!params[i].attr.IsBasetype && params[i].attr.IsOut &&
445 !params[i].attr.IsIn && !params[i].attr.IsByValue)
447 memset( *(unsigned char **)pArg, 0, calc_arg_size( pStubMsg, pTypeFormat ));
449 break;
450 case STUBLESS_CALCSIZE:
451 if (params[i].attr.IsSimpleRef && !*(unsigned char **)pArg)
452 RpcRaiseException(RPC_X_NULL_REF_POINTER);
453 if (params[i].attr.IsIn) call_buffer_sizer(pStubMsg, pArg, &params[i]);
454 break;
455 case STUBLESS_MARSHAL:
456 if (params[i].attr.IsIn) call_marshaller(pStubMsg, pArg, &params[i]);
457 break;
458 case STUBLESS_UNMARSHAL:
459 if (params[i].attr.IsOut)
461 if (params[i].attr.IsReturn && pRetVal) pArg = pRetVal;
462 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
464 break;
465 case STUBLESS_FREE:
466 if (!params[i].attr.IsBasetype && params[i].attr.IsOut && !params[i].attr.IsByValue)
467 NdrClearOutParameters( pStubMsg, pTypeFormat, *(unsigned char **)pArg );
468 break;
469 default:
470 RpcRaiseException(RPC_S_INTERNAL_ERROR);
475 static unsigned int type_stack_size(unsigned char fc)
477 switch (fc)
479 case RPC_FC_BYTE:
480 case RPC_FC_CHAR:
481 case RPC_FC_SMALL:
482 case RPC_FC_USMALL:
483 case RPC_FC_WCHAR:
484 case RPC_FC_SHORT:
485 case RPC_FC_USHORT:
486 case RPC_FC_LONG:
487 case RPC_FC_ULONG:
488 case RPC_FC_INT3264:
489 case RPC_FC_UINT3264:
490 case RPC_FC_ENUM16:
491 case RPC_FC_ENUM32:
492 case RPC_FC_FLOAT:
493 case RPC_FC_ERROR_STATUS_T:
494 case RPC_FC_IGNORE:
495 return sizeof(void *);
496 case RPC_FC_DOUBLE:
497 return sizeof(double);
498 case RPC_FC_HYPER:
499 return sizeof(ULONGLONG);
500 default:
501 ERR("invalid base type 0x%x\n", fc);
502 RpcRaiseException(RPC_S_INTERNAL_ERROR);
506 static BOOL is_by_value( PFORMAT_STRING format )
508 switch (*format)
510 case RPC_FC_USER_MARSHAL:
511 case RPC_FC_STRUCT:
512 case RPC_FC_PSTRUCT:
513 case RPC_FC_CSTRUCT:
514 case RPC_FC_CPSTRUCT:
515 case RPC_FC_CVSTRUCT:
516 case RPC_FC_BOGUS_STRUCT:
517 return TRUE;
518 default:
519 return FALSE;
523 PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
524 unsigned int stack_size, BOOL object_proc,
525 void *buffer, unsigned int size, unsigned int *count )
527 NDR_PARAM_OIF *args = buffer;
528 unsigned int i, stack_offset = object_proc ? sizeof(void *) : 0;
530 for (i = 0; stack_offset < stack_size; i++)
532 const NDR_PARAM_OI_BASETYPE *param = (const NDR_PARAM_OI_BASETYPE *)pFormat;
533 const NDR_PARAM_OI_OTHER *other = (const NDR_PARAM_OI_OTHER *)pFormat;
535 if (i + 1 > size / sizeof(*args))
537 FIXME( "%u args not supported\n", i );
538 RpcRaiseException( RPC_S_INTERNAL_ERROR );
541 args[i].stack_offset = stack_offset;
542 memset( &args[i].attr, 0, sizeof(args[i].attr) );
544 switch (param->param_direction)
546 case RPC_FC_IN_PARAM_BASETYPE:
547 args[i].attr.IsIn = 1;
548 args[i].attr.IsBasetype = 1;
549 break;
550 case RPC_FC_RETURN_PARAM_BASETYPE:
551 args[i].attr.IsOut = 1;
552 args[i].attr.IsReturn = 1;
553 args[i].attr.IsBasetype = 1;
554 break;
555 case RPC_FC_IN_PARAM:
556 args[i].attr.IsIn = 1;
557 args[i].attr.MustFree = 1;
558 break;
559 case RPC_FC_IN_PARAM_NO_FREE_INST:
560 args[i].attr.IsIn = 1;
561 args[i].attr.IsDontCallFreeInst = 1;
562 break;
563 case RPC_FC_IN_OUT_PARAM:
564 args[i].attr.IsIn = 1;
565 args[i].attr.IsOut = 1;
566 args[i].attr.MustFree = 1;
567 break;
568 case RPC_FC_OUT_PARAM:
569 args[i].attr.IsOut = 1;
570 break;
571 case RPC_FC_RETURN_PARAM:
572 args[i].attr.IsOut = 1;
573 args[i].attr.IsReturn = 1;
574 break;
576 if (args[i].attr.IsBasetype)
578 args[i].u.type_format_char = param->type_format_char;
579 stack_offset += type_stack_size( param->type_format_char );
580 pFormat += sizeof(NDR_PARAM_OI_BASETYPE);
582 else
584 args[i].u.type_offset = other->type_offset;
585 args[i].attr.IsByValue = is_by_value( &pStubMsg->StubDesc->pFormatTypes[other->type_offset] );
586 stack_offset += other->stack_size * sizeof(void *);
587 pFormat += sizeof(NDR_PARAM_OI_OTHER);
590 *count = i;
591 return (PFORMAT_STRING)args;
594 LONG_PTR CDECL ndr_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
595 void **stack_top, void **fpu_stack )
597 /* pointer to start of stack where arguments start */
598 RPC_MESSAGE rpcMsg;
599 MIDL_STUB_MESSAGE stubMsg;
600 handle_t hBinding = NULL;
601 /* procedure number */
602 unsigned short procedure_number;
603 /* size of stack */
604 unsigned short stack_size;
605 /* number of parameters. optional for client to give it to us */
606 unsigned int number_of_params;
607 /* cache of Oif_flags from v2 procedure header */
608 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
609 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
610 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
611 /* header for procedure string */
612 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
613 /* the value to return to the client from the remote procedure */
614 LONG_PTR RetVal = 0;
615 /* the pointer to the object when in OLE mode */
616 void * This = NULL;
617 PFORMAT_STRING pHandleFormat;
618 /* correlation cache */
619 ULONG_PTR NdrCorrCache[256];
621 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
623 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
625 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
627 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
628 stack_size = pProcHeader->stack_size;
629 procedure_number = pProcHeader->proc_num;
630 pFormat += sizeof(NDR_PROC_HEADER_RPC);
632 else
634 stack_size = pProcHeader->stack_size;
635 procedure_number = pProcHeader->proc_num;
636 pFormat += sizeof(NDR_PROC_HEADER);
638 TRACE("stack size: 0x%x\n", stack_size);
639 TRACE("proc num: %d\n", procedure_number);
641 /* create the full pointer translation tables, if requested */
642 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
643 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
645 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
647 /* object is always the first argument */
648 This = stack_top[0];
649 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
651 else
652 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
654 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
655 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
657 stubMsg.StackTop = (unsigned char *)stack_top;
658 pHandleFormat = pFormat;
660 /* we only need a handle if this isn't an object method */
661 if (!(pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT))
663 pFormat = client_get_handle(&stubMsg, pProcHeader, pHandleFormat, &hBinding);
664 if (!pFormat) goto done;
667 if (pStubDesc->Version >= 0x20000) /* -Oicf format */
669 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
670 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
672 Oif_flags = pOIFHeader->Oi2Flags;
673 number_of_params = pOIFHeader->number_of_params;
675 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
677 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
679 if (Oif_flags.HasExtensions)
681 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
682 ext_flags = pExtensions->Flags2;
683 pFormat += pExtensions->Size;
684 #ifdef __x86_64__
685 if (pExtensions->Size > sizeof(*pExtensions) && fpu_stack)
687 int i;
688 unsigned short fpu_mask = *(unsigned short *)(pExtensions + 1);
689 for (i = 0; i < 4; i++, fpu_mask >>= 2)
690 switch (fpu_mask & 3)
692 case 1: *(float *)&stack_top[i] = *(float *)&fpu_stack[i]; break;
693 case 2: *(double *)&stack_top[i] = *(double *)&fpu_stack[i]; break;
696 #endif
699 else
701 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
702 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
703 /* reuse the correlation cache, it's not needed for v1 format */
704 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
707 stubMsg.BufferLength = 0;
709 /* store the RPC flags away */
710 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
711 rpcMsg.RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
713 /* use alternate memory allocation routines */
714 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
715 NdrRpcSmSetClientToOsf(&stubMsg);
717 if (Oif_flags.HasPipes)
719 FIXME("pipes not supported yet\n");
720 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
721 /* init pipes package */
722 /* NdrPipesInitialize(...) */
724 if (ext_flags.HasNewCorrDesc)
726 /* initialize extra correlation package */
727 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
730 /* order of phases:
731 * 1. INITOUT - zero [out] parameters (proxies only)
732 * 2. CALCSIZE - calculate the buffer size
733 * 3. GETBUFFER - allocate the buffer
734 * 4. MARSHAL - marshal [in] params into the buffer
735 * 5. SENDRECEIVE - send/receive buffer
736 * 6. UNMARSHAL - unmarshal [out] params from buffer
737 * 7. FREE - clear [out] parameters (for proxies, and only on error)
739 if ((pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT) ||
740 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_HAS_COMM_OR_FAULT))
742 /* 1. INITOUT */
743 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
745 TRACE( "INITOUT\n" );
746 client_do_args(&stubMsg, pFormat, STUBLESS_INITOUT, fpu_stack,
747 number_of_params, (unsigned char *)&RetVal);
750 __TRY
752 /* 2. CALCSIZE */
753 TRACE( "CALCSIZE\n" );
754 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
755 number_of_params, (unsigned char *)&RetVal);
757 /* 3. GETBUFFER */
758 TRACE( "GETBUFFER\n" );
759 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
761 /* allocate the buffer */
762 NdrProxyGetBuffer(This, &stubMsg);
764 else
766 /* allocate the buffer */
767 if (Oif_flags.HasPipes)
768 /* NdrGetPipeBuffer(...) */
769 FIXME("pipes not supported yet\n");
770 else
772 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
773 #if 0
774 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
775 #else
776 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
777 #endif
778 else
779 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
783 /* 4. MARSHAL */
784 TRACE( "MARSHAL\n" );
785 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
786 number_of_params, (unsigned char *)&RetVal);
788 /* 5. SENDRECEIVE */
789 TRACE( "SENDRECEIVE\n" );
790 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
792 /* send the [in] params and receive the [out] and [retval]
793 * params */
794 NdrProxySendReceive(This, &stubMsg);
796 else
798 /* send the [in] params and receive the [out] and [retval]
799 * params */
800 if (Oif_flags.HasPipes)
801 /* NdrPipesSendReceive(...) */
802 FIXME("pipes not supported yet\n");
803 else
805 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
806 #if 0
807 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
808 #else
809 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
810 #endif
811 else
812 NdrSendReceive(&stubMsg, stubMsg.Buffer);
816 /* convert strings, floating point values and endianness into our
817 * preferred format */
818 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
819 NdrConvert(&stubMsg, pFormat);
821 /* 6. UNMARSHAL */
822 TRACE( "UNMARSHAL\n" );
823 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
824 number_of_params, (unsigned char *)&RetVal);
826 __EXCEPT_ALL
828 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
830 /* 7. FREE */
831 TRACE( "FREE\n" );
832 client_do_args(&stubMsg, pFormat, STUBLESS_FREE, fpu_stack,
833 number_of_params, (unsigned char *)&RetVal);
834 RetVal = NdrProxyErrorHandler(GetExceptionCode());
836 else
838 const COMM_FAULT_OFFSETS *comm_fault_offsets = &pStubDesc->CommFaultOffsets[procedure_number];
839 ULONG *comm_status;
840 ULONG *fault_status;
842 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets->CommOffset, comm_fault_offsets->FaultOffset);
844 if (comm_fault_offsets->CommOffset == -1)
845 comm_status = (ULONG *)&RetVal;
846 else if (comm_fault_offsets->CommOffset >= 0)
847 comm_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
848 else
849 comm_status = NULL;
851 if (comm_fault_offsets->FaultOffset == -1)
852 fault_status = (ULONG *)&RetVal;
853 else if (comm_fault_offsets->FaultOffset >= 0)
854 fault_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
855 else
856 fault_status = NULL;
858 NdrMapCommAndFaultStatus(&stubMsg, comm_status, fault_status,
859 GetExceptionCode());
862 __ENDTRY
864 else
866 /* 2. CALCSIZE */
867 TRACE( "CALCSIZE\n" );
868 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
869 number_of_params, (unsigned char *)&RetVal);
871 /* 3. GETBUFFER */
872 TRACE( "GETBUFFER\n" );
873 if (Oif_flags.HasPipes)
874 /* NdrGetPipeBuffer(...) */
875 FIXME("pipes not supported yet\n");
876 else
878 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
879 #if 0
880 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
881 #else
882 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
883 #endif
884 else
885 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
888 /* 4. MARSHAL */
889 TRACE( "MARSHAL\n" );
890 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
891 number_of_params, (unsigned char *)&RetVal);
893 /* 5. SENDRECEIVE */
894 TRACE( "SENDRECEIVE\n" );
895 if (Oif_flags.HasPipes)
896 /* NdrPipesSendReceive(...) */
897 FIXME("pipes not supported yet\n");
898 else
900 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
901 #if 0
902 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
903 #else
904 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
905 #endif
906 else
907 NdrSendReceive(&stubMsg, stubMsg.Buffer);
910 /* convert strings, floating point values and endianness into our
911 * preferred format */
912 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
913 NdrConvert(&stubMsg, pFormat);
915 /* 6. UNMARSHAL */
916 TRACE( "UNMARSHAL\n" );
917 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
918 number_of_params, (unsigned char *)&RetVal);
921 if (ext_flags.HasNewCorrDesc)
923 /* free extra correlation package */
924 NdrCorrelationFree(&stubMsg);
927 if (Oif_flags.HasPipes)
929 /* NdrPipesDone(...) */
932 /* free the full pointer translation tables */
933 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
934 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
936 /* free marshalling buffer */
937 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
938 NdrProxyFreeBuffer(This, &stubMsg);
939 else
941 NdrFreeBuffer(&stubMsg);
942 client_free_handle(&stubMsg, pProcHeader, pHandleFormat, hBinding);
945 done:
946 TRACE("RetVal = 0x%lx\n", RetVal);
947 return RetVal;
950 #ifdef __x86_64__
952 __ASM_GLOBAL_FUNC( NdrClientCall2,
953 "movq %r8,0x18(%rsp)\n\t"
954 "movq %r9,0x20(%rsp)\n\t"
955 "leaq 0x18(%rsp),%r8\n\t"
956 "xorq %r9,%r9\n\t"
957 "subq $0x28,%rsp\n\t"
958 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
959 "call " __ASM_NAME("ndr_client_call") "\n\t"
960 "addq $0x28,%rsp\n\t"
961 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
962 "ret" );
964 #else /* __x86_64__ */
966 /***********************************************************************
967 * NdrClientCall2 [RPCRT4.@]
969 CLIENT_CALL_RETURN WINAPIV NdrClientCall2( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
971 __ms_va_list args;
972 LONG_PTR ret;
974 __ms_va_start( args, format );
975 ret = ndr_client_call( desc, format, va_arg( args, void ** ), NULL );
976 __ms_va_end( args );
977 return *(CLIENT_CALL_RETURN *)&ret;
980 #endif /* __x86_64__ */
982 /* Calls a function with the specified arguments, restoring the stack
983 * properly afterwards as we don't know the calling convention of the
984 * function */
985 #if defined __i386__ && defined _MSC_VER
986 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
988 __asm
990 push ebp
991 push edi ; Save registers
992 push esi
993 mov ebp, esp
994 mov eax, [ebp+16] ; Get stack size
995 sub esp, eax ; Make room in stack for arguments
996 mov edi, esp
997 mov ecx, eax
998 mov esi, [ebp+12]
999 shr ecx, 2
1001 rep movsd ; Copy dword blocks
1002 call [ebp+8] ; Call function
1003 lea esp, [ebp-8] ; Restore stack
1004 pop esi ; Restore registers
1005 pop edi
1006 pop ebp
1010 #elif defined __i386__ && defined __GNUC__
1011 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1012 __ASM_GLOBAL_FUNC(call_server_func,
1013 "pushl %ebp\n\t"
1014 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1015 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1016 "movl %esp,%ebp\n\t"
1017 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1018 "pushl %edi\n\t" /* Save registers */
1019 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
1020 "pushl %esi\n\t"
1021 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
1022 "movl 16(%ebp), %eax\n\t" /* Get stack size */
1023 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
1024 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
1025 "movl %esp, %edi\n\t"
1026 "movl %eax, %ecx\n\t"
1027 "movl 12(%ebp), %esi\n\t"
1028 "shrl $2, %ecx\n\t" /* divide by 4 */
1029 "cld\n\t"
1030 "rep; movsl\n\t" /* Copy dword blocks */
1031 "call *8(%ebp)\n\t" /* Call function */
1032 "leal -8(%ebp), %esp\n\t" /* Restore stack */
1033 "popl %esi\n\t" /* Restore registers */
1034 __ASM_CFI(".cfi_same_value %esi\n\t")
1035 "popl %edi\n\t"
1036 __ASM_CFI(".cfi_same_value %edi\n\t")
1037 "popl %ebp\n\t"
1038 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1039 __ASM_CFI(".cfi_same_value %ebp\n\t")
1040 "ret" )
1041 #elif defined __x86_64__
1042 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1043 __ASM_GLOBAL_FUNC( call_server_func,
1044 "pushq %rbp\n\t"
1045 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
1046 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
1047 "movq %rsp,%rbp\n\t"
1048 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
1049 "pushq %rsi\n\t"
1050 __ASM_CFI(".cfi_rel_offset %rsi,-8\n\t")
1051 "pushq %rdi\n\t"
1052 __ASM_CFI(".cfi_rel_offset %rdi,-16\n\t")
1053 "movq %rcx,%rax\n\t" /* function to call */
1054 "movq $32,%rcx\n\t" /* allocate max(32,stack_size) bytes of stack space */
1055 "cmpq %rcx,%r8\n\t"
1056 "cmovgq %r8,%rcx\n\t"
1057 "subq %rcx,%rsp\n\t"
1058 "andq $~15,%rsp\n\t"
1059 "movq %r8,%rcx\n\t"
1060 "shrq $3,%rcx\n\t"
1061 "movq %rsp,%rdi\n\t"
1062 "movq %rdx,%rsi\n\t"
1063 "rep; movsq\n\t" /* copy arguments */
1064 "movq 0(%rsp),%rcx\n\t"
1065 "movq 8(%rsp),%rdx\n\t"
1066 "movq 16(%rsp),%r8\n\t"
1067 "movq 24(%rsp),%r9\n\t"
1068 "movq %rcx,%xmm0\n\t"
1069 "movq %rdx,%xmm1\n\t"
1070 "movq %r8,%xmm2\n\t"
1071 "movq %r9,%xmm3\n\t"
1072 "callq *%rax\n\t"
1073 "leaq -16(%rbp),%rsp\n\t" /* restore stack */
1074 "popq %rdi\n\t"
1075 __ASM_CFI(".cfi_same_value %rdi\n\t")
1076 "popq %rsi\n\t"
1077 __ASM_CFI(".cfi_same_value %rsi\n\t")
1078 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
1079 "popq %rbp\n\t"
1080 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
1081 __ASM_CFI(".cfi_same_value %rbp\n\t")
1082 "ret")
1083 #else
1084 #warning call_server_func not implemented for your architecture
1085 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
1087 FIXME("Not implemented for your architecture\n");
1088 return 0;
1090 #endif
1092 static LONG_PTR *stub_do_args(MIDL_STUB_MESSAGE *pStubMsg,
1093 PFORMAT_STRING pFormat, enum stubless_phase phase,
1094 unsigned short number_of_params)
1096 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
1097 unsigned int i;
1098 LONG_PTR *retval_ptr = NULL;
1100 for (i = 0; i < number_of_params; i++)
1102 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
1103 const unsigned char *pTypeFormat = &pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
1105 TRACE("param[%d]: %p -> %p type %02x %s\n", i,
1106 pArg, *(unsigned char **)pArg,
1107 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
1108 debugstr_PROC_PF( params[i].attr ));
1110 switch (phase)
1112 case STUBLESS_MARSHAL:
1113 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1114 call_marshaller(pStubMsg, pArg, &params[i]);
1115 break;
1116 case STUBLESS_FREE:
1117 if (params[i].attr.MustFree)
1119 call_freer(pStubMsg, pArg, &params[i]);
1121 else if (params[i].attr.ServerAllocSize)
1123 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1125 else if (params[i].attr.IsOut &&
1126 !params[i].attr.IsIn &&
1127 !params[i].attr.IsBasetype &&
1128 !params[i].attr.IsByValue)
1130 if (*pTypeFormat != RPC_FC_BIND_CONTEXT) pStubMsg->pfnFree(*(void **)pArg);
1132 break;
1133 case STUBLESS_INITOUT:
1134 if (!params[i].attr.IsIn &&
1135 params[i].attr.IsOut &&
1136 !params[i].attr.IsBasetype &&
1137 !params[i].attr.ServerAllocSize &&
1138 !params[i].attr.IsByValue)
1140 if (*pTypeFormat == RPC_FC_BIND_CONTEXT)
1142 NDR_SCONTEXT ctxt = NdrContextHandleInitialize(pStubMsg, pTypeFormat);
1143 *(void **)pArg = NDRSContextValue(ctxt);
1145 else
1147 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1148 if (size)
1150 *(void **)pArg = NdrAllocate(pStubMsg, size);
1151 memset(*(void **)pArg, 0, size);
1155 break;
1156 case STUBLESS_UNMARSHAL:
1157 if (params[i].attr.ServerAllocSize)
1158 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1159 params[i].attr.ServerAllocSize * 8);
1161 if (params[i].attr.IsIn)
1162 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
1163 break;
1164 case STUBLESS_CALCSIZE:
1165 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1166 call_buffer_sizer(pStubMsg, pArg, &params[i]);
1167 break;
1168 default:
1169 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1171 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1173 /* make a note of the address of the return value parameter for later */
1174 if (params[i].attr.IsReturn) retval_ptr = (LONG_PTR *)pArg;
1176 return retval_ptr;
1179 /***********************************************************************
1180 * NdrStubCall2 [RPCRT4.@]
1182 * Unmarshals [in] parameters, calls either a method in an object or a server
1183 * function, marshals any [out] parameters and frees any allocated data.
1185 * NOTES
1186 * Used by stubless MIDL-generated code.
1188 LONG WINAPI NdrStubCall2(
1189 struct IRpcStubBuffer * pThis,
1190 struct IRpcChannelBuffer * pChannel,
1191 PRPC_MESSAGE pRpcMsg,
1192 DWORD * pdwStubPhase)
1194 const MIDL_SERVER_INFO *pServerInfo;
1195 const MIDL_STUB_DESC *pStubDesc;
1196 PFORMAT_STRING pFormat;
1197 MIDL_STUB_MESSAGE stubMsg;
1198 /* pointer to start of stack to pass into stub implementation */
1199 unsigned char * args;
1200 /* size of stack */
1201 unsigned short stack_size;
1202 /* number of parameters. optional for client to give it to us */
1203 unsigned int number_of_params;
1204 /* cache of Oif_flags from v2 procedure header */
1205 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1206 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1207 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1208 /* the type of pass we are currently doing */
1209 enum stubless_phase phase;
1210 /* header for procedure string */
1211 const NDR_PROC_HEADER *pProcHeader;
1212 /* location to put retval into */
1213 LONG_PTR *retval_ptr = NULL;
1214 /* correlation cache */
1215 ULONG_PTR NdrCorrCache[256];
1217 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1219 if (pThis)
1220 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1221 else
1222 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1224 pStubDesc = pServerInfo->pStubDesc;
1225 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1226 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1228 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
1230 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1232 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1233 stack_size = pProcHeader->stack_size;
1234 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1237 else
1239 stack_size = pProcHeader->stack_size;
1240 pFormat += sizeof(NDR_PROC_HEADER);
1243 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1245 /* binding */
1246 switch (pProcHeader->handle_type)
1248 /* explicit binding: parse additional section */
1249 case RPC_FC_BIND_EXPLICIT:
1250 switch (*pFormat) /* handle_type */
1252 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
1253 pFormat += sizeof(NDR_EHD_PRIMITIVE);
1254 break;
1255 case RPC_FC_BIND_GENERIC: /* explicit generic */
1256 pFormat += sizeof(NDR_EHD_GENERIC);
1257 break;
1258 case RPC_FC_BIND_CONTEXT: /* explicit context */
1259 pFormat += sizeof(NDR_EHD_CONTEXT);
1260 break;
1261 default:
1262 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1263 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1265 break;
1266 case RPC_FC_BIND_GENERIC: /* implicit generic */
1267 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
1268 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
1269 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
1270 break;
1271 default:
1272 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1273 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1276 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1277 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1278 else
1279 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1281 /* create the full pointer translation tables, if requested */
1282 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1283 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1285 /* store the RPC flags away */
1286 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1287 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1289 /* use alternate memory allocation routines */
1290 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1291 #if 0
1292 NdrRpcSsEnableAllocate(&stubMsg);
1293 #else
1294 FIXME("Set RPCSS memory allocation routines\n");
1295 #endif
1297 TRACE("allocating memory for stack of size %x\n", stack_size);
1299 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1300 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1302 /* add the implicit This pointer as the first arg to the function if we
1303 * are calling an object method */
1304 if (pThis)
1305 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1307 if (pStubDesc->Version >= 0x20000) /* -Oicf format */
1309 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader = (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1311 Oif_flags = pOIFHeader->Oi2Flags;
1312 number_of_params = pOIFHeader->number_of_params;
1314 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1316 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1318 if (Oif_flags.HasExtensions)
1320 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
1321 ext_flags = pExtensions->Flags2;
1322 pFormat += pExtensions->Size;
1325 if (Oif_flags.HasPipes)
1327 FIXME("pipes not supported yet\n");
1328 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1329 /* init pipes package */
1330 /* NdrPipesInitialize(...) */
1332 if (ext_flags.HasNewCorrDesc)
1334 /* initialize extra correlation package */
1335 FIXME("new correlation description not implemented\n");
1336 stubMsg.fHasNewCorrDesc = TRUE;
1339 else
1341 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
1342 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
1343 /* reuse the correlation cache, it's not needed for v1 format */
1344 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
1347 /* convert strings, floating point values and endianness into our
1348 * preferred format */
1349 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1350 NdrConvert(&stubMsg, pFormat);
1352 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_FREE; phase++)
1354 TRACE("phase = %d\n", phase);
1355 switch (phase)
1357 case STUBLESS_CALLSERVER:
1358 /* call the server function */
1359 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1360 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1361 else
1363 SERVER_ROUTINE func;
1364 LONG_PTR retval;
1366 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1368 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1369 func = vtbl[pRpcMsg->ProcNum];
1371 else
1372 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1374 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1375 retval = call_server_func(func, args, stack_size);
1377 if (retval_ptr)
1379 TRACE("stub implementation returned 0x%lx\n", retval);
1380 *retval_ptr = retval;
1382 else
1383 TRACE("void stub implementation\n");
1386 stubMsg.Buffer = NULL;
1387 stubMsg.BufferLength = 0;
1389 break;
1390 case STUBLESS_GETBUFFER:
1391 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1392 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1393 else
1395 RPC_STATUS Status;
1397 pRpcMsg->BufferLength = stubMsg.BufferLength;
1398 /* allocate buffer for [out] and [ret] params */
1399 Status = I_RpcGetBuffer(pRpcMsg);
1400 if (Status)
1401 RpcRaiseException(Status);
1402 stubMsg.Buffer = pRpcMsg->Buffer;
1404 break;
1405 case STUBLESS_UNMARSHAL:
1406 case STUBLESS_INITOUT:
1407 case STUBLESS_CALCSIZE:
1408 case STUBLESS_MARSHAL:
1409 case STUBLESS_FREE:
1410 retval_ptr = stub_do_args(&stubMsg, pFormat, phase, number_of_params);
1411 break;
1412 default:
1413 ERR("shouldn't reach here. phase %d\n", phase);
1414 break;
1418 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1420 if (ext_flags.HasNewCorrDesc)
1422 /* free extra correlation package */
1423 /* NdrCorrelationFree(&stubMsg); */
1426 if (Oif_flags.HasPipes)
1428 /* NdrPipesDone(...) */
1431 /* free the full pointer translation tables */
1432 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1433 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1435 /* free server function stack */
1436 HeapFree(GetProcessHeap(), 0, args);
1438 return S_OK;
1441 /***********************************************************************
1442 * NdrServerCall2 [RPCRT4.@]
1444 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1446 DWORD dwPhase;
1447 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
1450 /***********************************************************************
1451 * NdrStubCall [RPCRT4.@]
1453 LONG WINAPI NdrStubCall( struct IRpcStubBuffer *This, struct IRpcChannelBuffer *channel,
1454 PRPC_MESSAGE msg, DWORD *phase )
1456 return NdrStubCall2( This, channel, msg, phase );
1459 /***********************************************************************
1460 * NdrServerCall [RPCRT4.@]
1462 void WINAPI NdrServerCall( PRPC_MESSAGE msg )
1464 DWORD phase;
1465 NdrStubCall( NULL, NULL, msg, &phase );
1468 struct async_call_data
1470 MIDL_STUB_MESSAGE *pStubMsg;
1471 const NDR_PROC_HEADER *pProcHeader;
1472 PFORMAT_STRING pHandleFormat;
1473 PFORMAT_STRING pParamFormat;
1474 RPC_BINDING_HANDLE hBinding;
1475 /* size of stack */
1476 unsigned short stack_size;
1477 /* number of parameters. optional for client to give it to us */
1478 unsigned int number_of_params;
1479 /* correlation cache */
1480 ULONG_PTR NdrCorrCache[256];
1483 LONG_PTR CDECL ndr_async_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, void **stack_top )
1485 /* pointer to start of stack where arguments start */
1486 PRPC_MESSAGE pRpcMsg;
1487 PMIDL_STUB_MESSAGE pStubMsg;
1488 RPC_ASYNC_STATE *pAsync;
1489 struct async_call_data *async_call_data;
1490 /* procedure number */
1491 unsigned short procedure_number;
1492 /* cache of Oif_flags from v2 procedure header */
1493 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1494 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1495 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1496 /* header for procedure string */
1497 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1498 /* -Oif or -Oicf generated format */
1499 BOOL bV2Format = FALSE;
1500 RPC_STATUS status;
1502 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
1504 /* Later NDR language versions probably won't be backwards compatible */
1505 if (pStubDesc->Version > 0x50002)
1507 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
1508 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1511 async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
1512 if (!async_call_data) RpcRaiseException(ERROR_OUTOFMEMORY);
1513 async_call_data->pProcHeader = pProcHeader;
1515 async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
1516 pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
1518 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1520 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1521 async_call_data->stack_size = pProcHeader->stack_size;
1522 procedure_number = pProcHeader->proc_num;
1523 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1525 else
1527 async_call_data->stack_size = pProcHeader->stack_size;
1528 procedure_number = pProcHeader->proc_num;
1529 pFormat += sizeof(NDR_PROC_HEADER);
1531 TRACE("stack size: 0x%x\n", async_call_data->stack_size);
1532 TRACE("proc num: %d\n", procedure_number);
1534 /* create the full pointer translation tables, if requested */
1535 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1536 pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
1538 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1540 ERR("objects not supported\n");
1541 I_RpcFree(async_call_data);
1542 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1545 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
1547 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1548 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
1550 /* needed for conformance of top-level objects */
1551 pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
1552 memcpy(pStubMsg->StackTop, stack_top, async_call_data->stack_size);
1554 pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
1555 pAsync->StubInfo = async_call_data;
1556 async_call_data->pHandleFormat = pFormat;
1558 pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
1559 if (!pFormat) goto done;
1561 bV2Format = (pStubDesc->Version >= 0x20000);
1563 if (bV2Format)
1565 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1566 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1568 Oif_flags = pOIFHeader->Oi2Flags;
1569 async_call_data->number_of_params = pOIFHeader->number_of_params;
1571 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1573 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1575 if (Oif_flags.HasExtensions)
1577 const NDR_PROC_HEADER_EXTS *pExtensions =
1578 (const NDR_PROC_HEADER_EXTS *)pFormat;
1579 ext_flags = pExtensions->Flags2;
1580 pFormat += pExtensions->Size;
1583 else
1585 pFormat = convert_old_args( pStubMsg, pFormat, async_call_data->stack_size,
1586 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
1587 async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache),
1588 &async_call_data->number_of_params );
1591 async_call_data->pParamFormat = pFormat;
1593 pStubMsg->BufferLength = 0;
1595 /* store the RPC flags away */
1596 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1597 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1599 /* use alternate memory allocation routines */
1600 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1601 NdrRpcSmSetClientToOsf(pStubMsg);
1603 if (Oif_flags.HasPipes)
1605 FIXME("pipes not supported yet\n");
1606 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1607 /* init pipes package */
1608 /* NdrPipesInitialize(...) */
1610 if (ext_flags.HasNewCorrDesc)
1612 /* initialize extra correlation package */
1613 NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
1616 /* order of phases:
1617 * 1. CALCSIZE - calculate the buffer size
1618 * 2. GETBUFFER - allocate the buffer
1619 * 3. MARSHAL - marshal [in] params into the buffer
1620 * 4. SENDRECEIVE - send buffer
1621 * Then in NdrpCompleteAsyncClientCall:
1622 * 1. SENDRECEIVE - receive buffer
1623 * 2. UNMARSHAL - unmarshal [out] params from buffer
1626 /* 1. CALCSIZE */
1627 TRACE( "CALCSIZE\n" );
1628 client_do_args(pStubMsg, pFormat, STUBLESS_CALCSIZE, NULL, async_call_data->number_of_params, NULL);
1630 /* 2. GETBUFFER */
1631 TRACE( "GETBUFFER\n" );
1632 if (Oif_flags.HasPipes)
1633 /* NdrGetPipeBuffer(...) */
1634 FIXME("pipes not supported yet\n");
1635 else
1637 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1638 #if 0
1639 NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1640 #else
1641 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1642 #endif
1643 else
1644 NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1646 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1647 status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
1648 if (status != RPC_S_OK)
1649 RpcRaiseException(status);
1651 /* 3. MARSHAL */
1652 TRACE( "MARSHAL\n" );
1653 client_do_args(pStubMsg, pFormat, STUBLESS_MARSHAL, NULL, async_call_data->number_of_params, NULL);
1655 /* 4. SENDRECEIVE */
1656 TRACE( "SEND\n" );
1657 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1658 /* send the [in] params only */
1659 if (Oif_flags.HasPipes)
1660 /* NdrPipesSend(...) */
1661 FIXME("pipes not supported yet\n");
1662 else
1664 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1665 #if 0
1666 NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1667 #else
1668 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1669 #endif
1670 else
1672 pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
1673 status = I_RpcSend(pStubMsg->RpcMsg);
1674 if (status != RPC_S_OK)
1675 RpcRaiseException(status);
1679 done:
1680 TRACE("returning 0\n");
1681 return 0;
1684 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
1686 /* pointer to start of stack where arguments start */
1687 PMIDL_STUB_MESSAGE pStubMsg;
1688 struct async_call_data *async_call_data;
1689 /* header for procedure string */
1690 const NDR_PROC_HEADER * pProcHeader;
1691 RPC_STATUS status = RPC_S_OK;
1693 if (!pAsync->StubInfo)
1694 return RPC_S_INVALID_ASYNC_HANDLE;
1696 async_call_data = pAsync->StubInfo;
1697 pStubMsg = async_call_data->pStubMsg;
1698 pProcHeader = async_call_data->pProcHeader;
1700 /* order of phases:
1701 * 1. CALCSIZE - calculate the buffer size
1702 * 2. GETBUFFER - allocate the buffer
1703 * 3. MARSHAL - marshal [in] params into the buffer
1704 * 4. SENDRECEIVE - send buffer
1705 * Then in NdrpCompleteAsyncClientCall:
1706 * 1. SENDRECEIVE - receive buffer
1707 * 2. UNMARSHAL - unmarshal [out] params from buffer
1710 /* 1. SENDRECEIVE */
1711 TRACE( "RECEIVE\n" );
1712 pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1713 /* receive the [out] params */
1714 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1715 #if 0
1716 NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1717 #else
1718 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1719 #endif
1720 else
1722 status = I_RpcReceive(pStubMsg->RpcMsg);
1723 if (status != RPC_S_OK)
1724 goto cleanup;
1725 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
1726 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
1727 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
1728 pStubMsg->Buffer = pStubMsg->BufferStart;
1731 /* convert strings, floating point values and endianness into our
1732 * preferred format */
1733 #if 0
1734 if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1735 NdrConvert(pStubMsg, pFormat);
1736 #endif
1738 /* 2. UNMARSHAL */
1739 TRACE( "UNMARSHAL\n" );
1740 client_do_args(pStubMsg, async_call_data->pParamFormat, STUBLESS_UNMARSHAL,
1741 NULL, async_call_data->number_of_params, Reply);
1743 cleanup:
1744 if (pStubMsg->fHasNewCorrDesc)
1746 /* free extra correlation package */
1747 NdrCorrelationFree(pStubMsg);
1750 /* free the full pointer translation tables */
1751 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1752 NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
1754 /* free marshalling buffer */
1755 NdrFreeBuffer(pStubMsg);
1756 client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
1758 I_RpcFree(pStubMsg->StackTop);
1759 I_RpcFree(async_call_data);
1761 TRACE("-- 0x%x\n", status);
1762 return status;
1765 #ifdef __x86_64__
1767 __ASM_GLOBAL_FUNC( NdrAsyncClientCall,
1768 "movq %r8,0x18(%rsp)\n\t"
1769 "movq %r9,0x20(%rsp)\n\t"
1770 "leaq 0x18(%rsp),%r8\n\t"
1771 "subq $0x28,%rsp\n\t"
1772 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
1773 "call " __ASM_NAME("ndr_async_client_call") "\n\t"
1774 "addq $0x28,%rsp\n\t"
1775 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
1776 "ret" );
1778 #else /* __x86_64__ */
1780 /***********************************************************************
1781 * NdrAsyncClientCall [RPCRT4.@]
1783 CLIENT_CALL_RETURN WINAPIV NdrAsyncClientCall( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1785 __ms_va_list args;
1786 LONG_PTR ret;
1788 __ms_va_start( args, format );
1789 ret = ndr_async_client_call( desc, format, va_arg( args, void ** ));
1790 __ms_va_end( args );
1791 return *(CLIENT_CALL_RETURN *)&ret;
1794 #endif /* __x86_64__ */
1796 RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
1797 struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
1798 DWORD * pdwStubPhase)
1800 FIXME("unimplemented, expect crash!\n");
1801 return 0;