kernel32: Add parentheses to clarify the precedence between '&' and '||'.
[wine/multimedia.git] / dlls / rpcrt4 / ndr_stubless.c
blobb68ff3212f8db6374039c341a4b5d5b45266e535
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_STRUCT:
153 case RPC_FC_PSTRUCT:
154 size = *(const WORD*)(pFormat + 2);
155 break;
156 case RPC_FC_BOGUS_STRUCT:
157 size = *(const WORD*)(pFormat + 2);
158 if(*(const WORD*)(pFormat + 4))
159 FIXME("Unhandled conformant description\n");
160 break;
161 case RPC_FC_CARRAY:
162 case RPC_FC_CVARRAY:
163 size = *(const WORD*)(pFormat + 2);
164 ComputeConformance(pStubMsg, NULL, pFormat + 4, 0);
165 size *= pStubMsg->MaxCount;
166 break;
167 case RPC_FC_SMFARRAY:
168 case RPC_FC_SMVARRAY:
169 size = *(const WORD*)(pFormat + 2);
170 break;
171 case RPC_FC_LGFARRAY:
172 case RPC_FC_LGVARRAY:
173 size = *(const DWORD*)(pFormat + 2);
174 break;
175 case RPC_FC_BOGUS_ARRAY:
176 pFormat = ComputeConformance(pStubMsg, NULL, pFormat + 4, *(const WORD*)&pFormat[2]);
177 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
178 pFormat = ComputeVariance(pStubMsg, NULL, pFormat, pStubMsg->MaxCount);
179 size = ComplexStructSize(pStubMsg, pFormat);
180 size *= pStubMsg->MaxCount;
181 break;
182 case RPC_FC_USER_MARSHAL:
183 size = *(const WORD*)(pFormat + 4);
184 break;
185 case RPC_FC_CSTRING:
186 size = *(const WORD*)(pFormat + 2);
187 break;
188 case RPC_FC_WSTRING:
189 size = *(const WORD*)(pFormat + 2) * sizeof(WCHAR);
190 break;
191 case RPC_FC_C_CSTRING:
192 case RPC_FC_C_WSTRING:
193 if (*pFormat == RPC_FC_C_CSTRING)
194 size = sizeof(CHAR);
195 else
196 size = sizeof(WCHAR);
197 if (pFormat[1] == RPC_FC_STRING_SIZED)
198 ComputeConformance(pStubMsg, NULL, pFormat + 2, 0);
199 else
200 pStubMsg->MaxCount = 0;
201 size *= pStubMsg->MaxCount;
202 break;
203 default:
204 FIXME("Unhandled type %02x\n", *pFormat);
205 /* fallthrough */
206 case RPC_FC_RP:
207 size = sizeof(void *);
208 break;
210 return size;
213 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
215 #if 0 /* these functions are not defined yet */
216 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
217 pMessage->pfnFree = NdrRpcSmClientFree;
218 #endif
221 static const char *debugstr_PROC_PF(PARAM_ATTRIBUTES param_attributes)
223 char buffer[160];
225 buffer[0] = 0;
226 if (param_attributes.MustSize) strcat(buffer, " MustSize");
227 if (param_attributes.MustFree) strcat(buffer, " MustFree");
228 if (param_attributes.IsPipe) strcat(buffer, " IsPipe");
229 if (param_attributes.IsIn) strcat(buffer, " IsIn");
230 if (param_attributes.IsOut) strcat(buffer, " IsOut");
231 if (param_attributes.IsReturn) strcat(buffer, " IsReturn");
232 if (param_attributes.IsBasetype) strcat(buffer, " IsBasetype");
233 if (param_attributes.IsByValue) strcat(buffer, " IsByValue");
234 if (param_attributes.IsSimpleRef) strcat(buffer, " IsSimpleRef");
235 if (param_attributes.IsDontCallFreeInst) strcat(buffer, " IsDontCallFreeInst");
236 if (param_attributes.SaveForAsyncFinish) strcat(buffer, " SaveForAsyncFinish");
237 if (param_attributes.ServerAllocSize)
238 sprintf( buffer + strlen(buffer), " ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
239 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
242 static const char *debugstr_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
244 char buffer[160];
246 buffer[0] = 0;
247 if (Oi2Flags.ServerMustSize) strcat(buffer, " ServerMustSize");
248 if (Oi2Flags.ClientMustSize) strcat(buffer, " ClientMustSize");
249 if (Oi2Flags.HasReturn) strcat(buffer, " HasReturn");
250 if (Oi2Flags.HasPipes) strcat(buffer, " HasPipes");
251 if (Oi2Flags.Unused) strcat(buffer, " Unused");
252 if (Oi2Flags.HasAsyncUuid) strcat(buffer, " HasAsyncUuid");
253 if (Oi2Flags.HasExtensions) strcat(buffer, " HasExtensions");
254 if (Oi2Flags.HasAsyncHandle) strcat(buffer, " HasAsyncHandle");
255 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
258 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
260 static PFORMAT_STRING client_get_handle(
261 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
262 PFORMAT_STRING pFormat, handle_t *phBinding)
264 /* binding */
265 switch (pProcHeader->handle_type)
267 /* explicit binding: parse additional section */
268 case RPC_FC_BIND_EXPLICIT:
269 switch (*pFormat) /* handle_type */
271 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
273 const NDR_EHD_PRIMITIVE *pDesc = (const NDR_EHD_PRIMITIVE *)pFormat;
275 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
277 if (pDesc->flag) /* pointer to binding */
278 *phBinding = **(handle_t **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
279 else
280 *phBinding = *(handle_t *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
281 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
283 case RPC_FC_BIND_GENERIC: /* explicit generic */
285 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
286 void *pObject = NULL;
287 void *pArg;
288 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
290 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
292 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
293 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
294 else
295 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
296 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
297 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
298 *phBinding = pGenPair->pfnBind(pObject);
299 return pFormat + sizeof(NDR_EHD_GENERIC);
301 case RPC_FC_BIND_CONTEXT: /* explicit context */
303 const NDR_EHD_CONTEXT *pDesc = (const NDR_EHD_CONTEXT *)pFormat;
304 NDR_CCONTEXT context_handle;
305 TRACE("Explicit bind context\n");
306 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
308 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
309 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
311 else
312 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
314 if (context_handle) *phBinding = NDRCContextBinding(context_handle);
315 else if (pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL)
317 ERR("null context handle isn't allowed\n");
318 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
319 return NULL;
321 /* FIXME: should we store this structure in stubMsg.pContext? */
322 return pFormat + sizeof(NDR_EHD_CONTEXT);
324 default:
325 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
326 RpcRaiseException(RPC_X_BAD_STUB_DATA);
328 break;
329 case RPC_FC_BIND_GENERIC: /* implicit generic */
330 FIXME("RPC_FC_BIND_GENERIC\n");
331 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
332 break;
333 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
334 TRACE("Implicit primitive handle\n");
335 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
336 break;
337 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
338 FIXME("RPC_FC_CALLBACK_HANDLE\n");
339 break;
340 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
341 /* strictly speaking, it isn't necessary to set hBinding here
342 * since it isn't actually used (hence the automatic in its name),
343 * but then why does MIDL generate a valid entry in the
344 * MIDL_STUB_DESC for it? */
345 TRACE("Implicit auto handle\n");
346 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
347 break;
348 default:
349 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
350 RpcRaiseException(RPC_X_BAD_STUB_DATA);
352 return pFormat;
355 static void client_free_handle(
356 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
357 PFORMAT_STRING pFormat, handle_t hBinding)
359 /* binding */
360 switch (pProcHeader->handle_type)
362 /* explicit binding: parse additional section */
363 case RPC_FC_BIND_EXPLICIT:
364 switch (*pFormat) /* handle_type */
366 case RPC_FC_BIND_GENERIC: /* explicit generic */
368 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
369 void *pObject = NULL;
370 void *pArg;
371 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
373 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
375 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
376 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
377 else
378 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
379 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
380 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
381 pGenPair->pfnUnbind(pObject, hBinding);
382 break;
384 case RPC_FC_BIND_CONTEXT: /* explicit context */
385 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
386 break;
387 default:
388 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
389 RpcRaiseException(RPC_X_BAD_STUB_DATA);
391 break;
392 case RPC_FC_BIND_GENERIC: /* implicit generic */
393 FIXME("RPC_FC_BIND_GENERIC\n");
394 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
395 break;
396 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
397 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
398 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
399 break;
400 default:
401 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
402 RpcRaiseException(RPC_X_BAD_STUB_DATA);
406 void client_do_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, enum stubless_phase phase,
407 void **fpu_args, unsigned short number_of_params, unsigned char *pRetVal )
409 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
410 unsigned int i;
412 for (i = 0; i < number_of_params; i++)
414 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
415 PFORMAT_STRING pTypeFormat = (PFORMAT_STRING)&pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
417 #ifdef __x86_64__ /* floats are passed as doubles through varargs functions */
418 float f;
420 if (params[i].attr.IsBasetype &&
421 params[i].u.type_format_char == RPC_FC_FLOAT &&
422 !params[i].attr.IsSimpleRef &&
423 !fpu_args)
425 f = *(double *)pArg;
426 pArg = (unsigned char *)&f;
428 #endif
430 TRACE("param[%d]: %p type %02x %s\n", i, pArg,
431 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
432 debugstr_PROC_PF( params[i].attr ));
434 switch (phase)
436 case STUBLESS_INITOUT:
437 if (!params[i].attr.IsBasetype && params[i].attr.IsOut &&
438 !params[i].attr.IsIn && !params[i].attr.IsByValue)
440 memset( *(unsigned char **)pArg, 0, calc_arg_size( pStubMsg, pTypeFormat ));
442 break;
443 case STUBLESS_CALCSIZE:
444 if (params[i].attr.IsSimpleRef && !*(unsigned char **)pArg)
445 RpcRaiseException(RPC_X_NULL_REF_POINTER);
446 if (params[i].attr.IsIn) call_buffer_sizer(pStubMsg, pArg, &params[i]);
447 break;
448 case STUBLESS_MARSHAL:
449 if (params[i].attr.IsIn) call_marshaller(pStubMsg, pArg, &params[i]);
450 break;
451 case STUBLESS_UNMARSHAL:
452 if (params[i].attr.IsOut)
454 if (params[i].attr.IsReturn && pRetVal) pArg = pRetVal;
455 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
457 break;
458 case STUBLESS_FREE:
459 if (!params[i].attr.IsBasetype && params[i].attr.IsOut && !params[i].attr.IsByValue)
460 NdrClearOutParameters( pStubMsg, pTypeFormat, *(unsigned char **)pArg );
461 break;
462 default:
463 RpcRaiseException(RPC_S_INTERNAL_ERROR);
468 static unsigned int type_stack_size(unsigned char fc)
470 switch (fc)
472 case RPC_FC_BYTE:
473 case RPC_FC_CHAR:
474 case RPC_FC_SMALL:
475 case RPC_FC_USMALL:
476 case RPC_FC_WCHAR:
477 case RPC_FC_SHORT:
478 case RPC_FC_USHORT:
479 case RPC_FC_LONG:
480 case RPC_FC_ULONG:
481 case RPC_FC_INT3264:
482 case RPC_FC_UINT3264:
483 case RPC_FC_ENUM16:
484 case RPC_FC_ENUM32:
485 case RPC_FC_FLOAT:
486 case RPC_FC_ERROR_STATUS_T:
487 case RPC_FC_IGNORE:
488 return sizeof(void *);
489 case RPC_FC_DOUBLE:
490 return sizeof(double);
491 case RPC_FC_HYPER:
492 return sizeof(ULONGLONG);
493 default:
494 ERR("invalid base type 0x%x\n", fc);
495 RpcRaiseException(RPC_S_INTERNAL_ERROR);
499 static BOOL is_by_value( PFORMAT_STRING format )
501 switch (*format)
503 case RPC_FC_USER_MARSHAL:
504 case RPC_FC_STRUCT:
505 case RPC_FC_PSTRUCT:
506 case RPC_FC_CSTRUCT:
507 case RPC_FC_CPSTRUCT:
508 case RPC_FC_CVSTRUCT:
509 case RPC_FC_BOGUS_STRUCT:
510 return TRUE;
511 default:
512 return FALSE;
516 PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
517 unsigned int stack_size, BOOL object_proc,
518 void *buffer, unsigned int size, unsigned int *count )
520 NDR_PARAM_OIF *args = buffer;
521 unsigned int i, stack_offset = object_proc ? sizeof(void *) : 0;
523 for (i = 0; stack_offset < stack_size; i++)
525 const NDR_PARAM_OI_BASETYPE *param = (const NDR_PARAM_OI_BASETYPE *)pFormat;
526 const NDR_PARAM_OI_OTHER *other = (const NDR_PARAM_OI_OTHER *)pFormat;
528 if (i + 1 > size / sizeof(*args))
530 FIXME( "%u args not supported\n", i );
531 RpcRaiseException( RPC_S_INTERNAL_ERROR );
534 args[i].stack_offset = stack_offset;
535 memset( &args[i].attr, 0, sizeof(args[i].attr) );
537 switch (param->param_direction)
539 case RPC_FC_IN_PARAM_BASETYPE:
540 args[i].attr.IsIn = 1;
541 args[i].attr.IsBasetype = 1;
542 break;
543 case RPC_FC_RETURN_PARAM_BASETYPE:
544 args[i].attr.IsOut = 1;
545 args[i].attr.IsReturn = 1;
546 args[i].attr.IsBasetype = 1;
547 break;
548 case RPC_FC_IN_PARAM:
549 args[i].attr.IsIn = 1;
550 args[i].attr.MustFree = 1;
551 break;
552 case RPC_FC_IN_PARAM_NO_FREE_INST:
553 args[i].attr.IsIn = 1;
554 args[i].attr.IsDontCallFreeInst = 1;
555 break;
556 case RPC_FC_IN_OUT_PARAM:
557 args[i].attr.IsIn = 1;
558 args[i].attr.IsOut = 1;
559 args[i].attr.MustFree = 1;
560 break;
561 case RPC_FC_OUT_PARAM:
562 args[i].attr.IsOut = 1;
563 break;
564 case RPC_FC_RETURN_PARAM:
565 args[i].attr.IsOut = 1;
566 args[i].attr.IsReturn = 1;
567 break;
569 if (args[i].attr.IsBasetype)
571 args[i].u.type_format_char = param->type_format_char;
572 stack_offset += type_stack_size( param->type_format_char );
573 pFormat += sizeof(NDR_PARAM_OI_BASETYPE);
575 else
577 args[i].u.type_offset = other->type_offset;
578 args[i].attr.IsByValue = is_by_value( &pStubMsg->StubDesc->pFormatTypes[other->type_offset] );
579 stack_offset += other->stack_size * sizeof(void *);
580 pFormat += sizeof(NDR_PARAM_OI_OTHER);
583 *count = i;
584 return (PFORMAT_STRING)args;
587 LONG_PTR CDECL ndr_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
588 void **stack_top, void **fpu_stack )
590 /* pointer to start of stack where arguments start */
591 RPC_MESSAGE rpcMsg;
592 MIDL_STUB_MESSAGE stubMsg;
593 handle_t hBinding = NULL;
594 /* procedure number */
595 unsigned short procedure_number;
596 /* size of stack */
597 unsigned short stack_size;
598 /* number of parameters. optional for client to give it to us */
599 unsigned int number_of_params;
600 /* cache of Oif_flags from v2 procedure header */
601 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
602 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
603 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
604 /* header for procedure string */
605 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
606 /* the value to return to the client from the remote procedure */
607 LONG_PTR RetVal = 0;
608 /* the pointer to the object when in OLE mode */
609 void * This = NULL;
610 PFORMAT_STRING pHandleFormat;
611 /* correlation cache */
612 ULONG_PTR NdrCorrCache[256];
614 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
616 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
618 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
620 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
621 stack_size = pProcHeader->stack_size;
622 procedure_number = pProcHeader->proc_num;
623 pFormat += sizeof(NDR_PROC_HEADER_RPC);
625 else
627 stack_size = pProcHeader->stack_size;
628 procedure_number = pProcHeader->proc_num;
629 pFormat += sizeof(NDR_PROC_HEADER);
631 TRACE("stack size: 0x%x\n", stack_size);
632 TRACE("proc num: %d\n", procedure_number);
634 /* create the full pointer translation tables, if requested */
635 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
636 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
638 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
640 /* object is always the first argument */
641 This = stack_top[0];
642 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
644 else
645 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
647 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
648 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
650 stubMsg.StackTop = (unsigned char *)stack_top;
651 pHandleFormat = pFormat;
653 /* we only need a handle if this isn't an object method */
654 if (!(pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT))
656 pFormat = client_get_handle(&stubMsg, pProcHeader, pHandleFormat, &hBinding);
657 if (!pFormat) goto done;
660 if (pStubDesc->Version >= 0x20000) /* -Oicf format */
662 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
663 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
665 Oif_flags = pOIFHeader->Oi2Flags;
666 number_of_params = pOIFHeader->number_of_params;
668 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
670 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
672 if (Oif_flags.HasExtensions)
674 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
675 ext_flags = pExtensions->Flags2;
676 pFormat += pExtensions->Size;
677 #ifdef __x86_64__
678 if (pExtensions->Size > sizeof(*pExtensions) && fpu_stack)
680 int i;
681 unsigned short fpu_mask = *(unsigned short *)(pExtensions + 1);
682 for (i = 0; i < 4; i++, fpu_mask >>= 2)
683 switch (fpu_mask & 3)
685 case 1: *(float *)&stack_top[i] = *(float *)&fpu_stack[i]; break;
686 case 2: *(double *)&stack_top[i] = *(double *)&fpu_stack[i]; break;
689 #endif
692 else
694 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
695 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
696 /* reuse the correlation cache, it's not needed for v1 format */
697 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
700 stubMsg.BufferLength = 0;
702 /* store the RPC flags away */
703 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
704 rpcMsg.RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
706 /* use alternate memory allocation routines */
707 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
708 NdrRpcSmSetClientToOsf(&stubMsg);
710 if (Oif_flags.HasPipes)
712 FIXME("pipes not supported yet\n");
713 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
714 /* init pipes package */
715 /* NdrPipesInitialize(...) */
717 if (ext_flags.HasNewCorrDesc)
719 /* initialize extra correlation package */
720 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
723 /* order of phases:
724 * 1. INITOUT - zero [out] parameters (proxies only)
725 * 2. CALCSIZE - calculate the buffer size
726 * 3. GETBUFFER - allocate the buffer
727 * 4. MARSHAL - marshal [in] params into the buffer
728 * 5. SENDRECEIVE - send/receive buffer
729 * 6. UNMARSHAL - unmarshal [out] params from buffer
730 * 7. FREE - clear [out] parameters (for proxies, and only on error)
732 if ((pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT) ||
733 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_HAS_COMM_OR_FAULT))
735 /* 1. INITOUT */
736 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
738 TRACE( "INITOUT\n" );
739 client_do_args(&stubMsg, pFormat, STUBLESS_INITOUT, fpu_stack,
740 number_of_params, (unsigned char *)&RetVal);
743 __TRY
745 /* 2. CALCSIZE */
746 TRACE( "CALCSIZE\n" );
747 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
748 number_of_params, (unsigned char *)&RetVal);
750 /* 3. GETBUFFER */
751 TRACE( "GETBUFFER\n" );
752 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
754 /* allocate the buffer */
755 NdrProxyGetBuffer(This, &stubMsg);
757 else
759 /* allocate the buffer */
760 if (Oif_flags.HasPipes)
761 /* NdrGetPipeBuffer(...) */
762 FIXME("pipes not supported yet\n");
763 else
765 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
766 #if 0
767 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
768 #else
769 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
770 #endif
771 else
772 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
776 /* 4. MARSHAL */
777 TRACE( "MARSHAL\n" );
778 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
779 number_of_params, (unsigned char *)&RetVal);
781 /* 5. SENDRECEIVE */
782 TRACE( "SENDRECEIVE\n" );
783 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
785 /* send the [in] params and receive the [out] and [retval]
786 * params */
787 NdrProxySendReceive(This, &stubMsg);
789 else
791 /* send the [in] params and receive the [out] and [retval]
792 * params */
793 if (Oif_flags.HasPipes)
794 /* NdrPipesSendReceive(...) */
795 FIXME("pipes not supported yet\n");
796 else
798 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
799 #if 0
800 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
801 #else
802 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
803 #endif
804 else
805 NdrSendReceive(&stubMsg, stubMsg.Buffer);
809 /* convert strings, floating point values and endianness into our
810 * preferred format */
811 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
812 NdrConvert(&stubMsg, pFormat);
814 /* 6. UNMARSHAL */
815 TRACE( "UNMARSHAL\n" );
816 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
817 number_of_params, (unsigned char *)&RetVal);
819 __EXCEPT_ALL
821 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
823 /* 7. FREE */
824 TRACE( "FREE\n" );
825 client_do_args(&stubMsg, pFormat, STUBLESS_FREE, fpu_stack,
826 number_of_params, (unsigned char *)&RetVal);
827 RetVal = NdrProxyErrorHandler(GetExceptionCode());
829 else
831 const COMM_FAULT_OFFSETS *comm_fault_offsets = &pStubDesc->CommFaultOffsets[procedure_number];
832 ULONG *comm_status;
833 ULONG *fault_status;
835 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets->CommOffset, comm_fault_offsets->FaultOffset);
837 if (comm_fault_offsets->CommOffset == -1)
838 comm_status = (ULONG *)&RetVal;
839 else if (comm_fault_offsets->CommOffset >= 0)
840 comm_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
841 else
842 comm_status = NULL;
844 if (comm_fault_offsets->FaultOffset == -1)
845 fault_status = (ULONG *)&RetVal;
846 else if (comm_fault_offsets->FaultOffset >= 0)
847 fault_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
848 else
849 fault_status = NULL;
851 NdrMapCommAndFaultStatus(&stubMsg, comm_status, fault_status,
852 GetExceptionCode());
855 __ENDTRY
857 else
859 /* 2. CALCSIZE */
860 TRACE( "CALCSIZE\n" );
861 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
862 number_of_params, (unsigned char *)&RetVal);
864 /* 3. GETBUFFER */
865 TRACE( "GETBUFFER\n" );
866 if (Oif_flags.HasPipes)
867 /* NdrGetPipeBuffer(...) */
868 FIXME("pipes not supported yet\n");
869 else
871 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
872 #if 0
873 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
874 #else
875 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
876 #endif
877 else
878 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
881 /* 4. MARSHAL */
882 TRACE( "MARSHAL\n" );
883 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
884 number_of_params, (unsigned char *)&RetVal);
886 /* 5. SENDRECEIVE */
887 TRACE( "SENDRECEIVE\n" );
888 if (Oif_flags.HasPipes)
889 /* NdrPipesSendReceive(...) */
890 FIXME("pipes not supported yet\n");
891 else
893 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
894 #if 0
895 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
896 #else
897 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
898 #endif
899 else
900 NdrSendReceive(&stubMsg, stubMsg.Buffer);
903 /* convert strings, floating point values and endianness into our
904 * preferred format */
905 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
906 NdrConvert(&stubMsg, pFormat);
908 /* 6. UNMARSHAL */
909 TRACE( "UNMARSHAL\n" );
910 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
911 number_of_params, (unsigned char *)&RetVal);
914 if (ext_flags.HasNewCorrDesc)
916 /* free extra correlation package */
917 NdrCorrelationFree(&stubMsg);
920 if (Oif_flags.HasPipes)
922 /* NdrPipesDone(...) */
925 /* free the full pointer translation tables */
926 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
927 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
929 /* free marshalling buffer */
930 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
931 NdrProxyFreeBuffer(This, &stubMsg);
932 else
934 NdrFreeBuffer(&stubMsg);
935 client_free_handle(&stubMsg, pProcHeader, pHandleFormat, hBinding);
938 done:
939 TRACE("RetVal = 0x%lx\n", RetVal);
940 return RetVal;
943 #ifdef __x86_64__
945 __ASM_GLOBAL_FUNC( NdrClientCall2,
946 "movq %r8,0x18(%rsp)\n\t"
947 "movq %r9,0x20(%rsp)\n\t"
948 "leaq 0x18(%rsp),%r8\n\t"
949 "xorq %r9,%r9\n\t"
950 "subq $0x28,%rsp\n\t"
951 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
952 "call " __ASM_NAME("ndr_client_call") "\n\t"
953 "addq $0x28,%rsp\n\t"
954 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
955 "ret" );
957 #else /* __x86_64__ */
959 /***********************************************************************
960 * NdrClientCall2 [RPCRT4.@]
962 CLIENT_CALL_RETURN WINAPIV NdrClientCall2( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
964 __ms_va_list args;
965 LONG_PTR ret;
967 __ms_va_start( args, format );
968 ret = ndr_client_call( desc, format, va_arg( args, void ** ), NULL );
969 __ms_va_end( args );
970 return *(CLIENT_CALL_RETURN *)&ret;
973 #endif /* __x86_64__ */
975 /* Calls a function with the specified arguments, restoring the stack
976 * properly afterwards as we don't know the calling convention of the
977 * function */
978 #if defined __i386__ && defined _MSC_VER
979 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
981 __asm
983 push ebp
984 push edi ; Save registers
985 push esi
986 mov ebp, esp
987 mov eax, [ebp+16] ; Get stack size
988 sub esp, eax ; Make room in stack for arguments
989 mov edi, esp
990 mov ecx, eax
991 mov esi, [ebp+12]
992 shr ecx, 2
994 rep movsd ; Copy dword blocks
995 call [ebp+8] ; Call function
996 lea esp, [ebp-8] ; Restore stack
997 pop esi ; Restore registers
998 pop edi
999 pop ebp
1003 #elif defined __i386__ && defined __GNUC__
1004 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1005 __ASM_GLOBAL_FUNC(call_server_func,
1006 "pushl %ebp\n\t"
1007 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1008 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1009 "movl %esp,%ebp\n\t"
1010 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1011 "pushl %edi\n\t" /* Save registers */
1012 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
1013 "pushl %esi\n\t"
1014 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
1015 "movl 16(%ebp), %eax\n\t" /* Get stack size */
1016 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
1017 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
1018 "movl %esp, %edi\n\t"
1019 "movl %eax, %ecx\n\t"
1020 "movl 12(%ebp), %esi\n\t"
1021 "shrl $2, %ecx\n\t" /* divide by 4 */
1022 "cld\n\t"
1023 "rep; movsl\n\t" /* Copy dword blocks */
1024 "call *8(%ebp)\n\t" /* Call function */
1025 "leal -8(%ebp), %esp\n\t" /* Restore stack */
1026 "popl %esi\n\t" /* Restore registers */
1027 __ASM_CFI(".cfi_same_value %esi\n\t")
1028 "popl %edi\n\t"
1029 __ASM_CFI(".cfi_same_value %edi\n\t")
1030 "popl %ebp\n\t"
1031 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1032 __ASM_CFI(".cfi_same_value %ebp\n\t")
1033 "ret" )
1034 #elif defined __x86_64__
1035 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1036 __ASM_GLOBAL_FUNC( call_server_func,
1037 "pushq %rbp\n\t"
1038 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
1039 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
1040 "movq %rsp,%rbp\n\t"
1041 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
1042 "pushq %rsi\n\t"
1043 __ASM_CFI(".cfi_rel_offset %rsi,-8\n\t")
1044 "pushq %rdi\n\t"
1045 __ASM_CFI(".cfi_rel_offset %rdi,-16\n\t")
1046 "movq %rcx,%rax\n\t" /* function to call */
1047 "movq $32,%rcx\n\t" /* allocate max(32,stack_size) bytes of stack space */
1048 "cmpq %rcx,%r8\n\t"
1049 "cmovgq %r8,%rcx\n\t"
1050 "subq %rcx,%rsp\n\t"
1051 "andq $~15,%rsp\n\t"
1052 "movq %r8,%rcx\n\t"
1053 "shrq $3,%rcx\n\t"
1054 "movq %rsp,%rdi\n\t"
1055 "movq %rdx,%rsi\n\t"
1056 "rep; movsq\n\t" /* copy arguments */
1057 "movq 0(%rsp),%rcx\n\t"
1058 "movq 8(%rsp),%rdx\n\t"
1059 "movq 16(%rsp),%r8\n\t"
1060 "movq 24(%rsp),%r9\n\t"
1061 "movq %rcx,%xmm0\n\t"
1062 "movq %rdx,%xmm1\n\t"
1063 "movq %r8,%xmm2\n\t"
1064 "movq %r9,%xmm3\n\t"
1065 "callq *%rax\n\t"
1066 "leaq -16(%rbp),%rsp\n\t" /* restore stack */
1067 "popq %rdi\n\t"
1068 __ASM_CFI(".cfi_same_value %rdi\n\t")
1069 "popq %rsi\n\t"
1070 __ASM_CFI(".cfi_same_value %rsi\n\t")
1071 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
1072 "popq %rbp\n\t"
1073 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
1074 __ASM_CFI(".cfi_same_value %rbp\n\t")
1075 "ret")
1076 #else
1077 #warning call_server_func not implemented for your architecture
1078 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
1080 FIXME("Not implemented for your architecture\n");
1081 return 0;
1083 #endif
1085 static LONG_PTR *stub_do_args(MIDL_STUB_MESSAGE *pStubMsg,
1086 PFORMAT_STRING pFormat, enum stubless_phase phase,
1087 unsigned short number_of_params)
1089 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
1090 unsigned int i;
1091 LONG_PTR *retval_ptr = NULL;
1093 for (i = 0; i < number_of_params; i++)
1095 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
1096 const unsigned char *pTypeFormat = &pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
1098 TRACE("param[%d]: %p -> %p type %02x %s\n", i,
1099 pArg, *(unsigned char **)pArg,
1100 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
1101 debugstr_PROC_PF( params[i].attr ));
1103 switch (phase)
1105 case STUBLESS_MARSHAL:
1106 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1107 call_marshaller(pStubMsg, pArg, &params[i]);
1108 break;
1109 case STUBLESS_FREE:
1110 if (params[i].attr.MustFree)
1112 call_freer(pStubMsg, pArg, &params[i]);
1114 else if (params[i].attr.ServerAllocSize)
1116 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1118 else if (params[i].attr.IsOut &&
1119 !params[i].attr.IsIn &&
1120 !params[i].attr.IsBasetype &&
1121 !params[i].attr.IsByValue)
1123 if (*pTypeFormat != RPC_FC_BIND_CONTEXT) pStubMsg->pfnFree(*(void **)pArg);
1125 break;
1126 case STUBLESS_INITOUT:
1127 if (!params[i].attr.IsIn &&
1128 params[i].attr.IsOut &&
1129 !params[i].attr.IsBasetype &&
1130 !params[i].attr.ServerAllocSize &&
1131 !params[i].attr.IsByValue)
1133 if (*pTypeFormat == RPC_FC_BIND_CONTEXT)
1135 NDR_SCONTEXT ctxt = NdrContextHandleInitialize(pStubMsg, pTypeFormat);
1136 *(void **)pArg = NDRSContextValue(ctxt);
1138 else
1140 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1141 if (size)
1143 *(void **)pArg = NdrAllocate(pStubMsg, size);
1144 memset(*(void **)pArg, 0, size);
1148 break;
1149 case STUBLESS_UNMARSHAL:
1150 if (params[i].attr.ServerAllocSize)
1151 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1152 params[i].attr.ServerAllocSize * 8);
1154 if (params[i].attr.IsIn)
1155 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
1156 break;
1157 case STUBLESS_CALCSIZE:
1158 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1159 call_buffer_sizer(pStubMsg, pArg, &params[i]);
1160 break;
1161 default:
1162 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1164 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1166 /* make a note of the address of the return value parameter for later */
1167 if (params[i].attr.IsReturn) retval_ptr = (LONG_PTR *)pArg;
1169 return retval_ptr;
1172 /***********************************************************************
1173 * NdrStubCall2 [RPCRT4.@]
1175 * Unmarshals [in] parameters, calls either a method in an object or a server
1176 * function, marshals any [out] parameters and frees any allocated data.
1178 * NOTES
1179 * Used by stubless MIDL-generated code.
1181 LONG WINAPI NdrStubCall2(
1182 struct IRpcStubBuffer * pThis,
1183 struct IRpcChannelBuffer * pChannel,
1184 PRPC_MESSAGE pRpcMsg,
1185 DWORD * pdwStubPhase)
1187 const MIDL_SERVER_INFO *pServerInfo;
1188 const MIDL_STUB_DESC *pStubDesc;
1189 PFORMAT_STRING pFormat;
1190 MIDL_STUB_MESSAGE stubMsg;
1191 /* pointer to start of stack to pass into stub implementation */
1192 unsigned char * args;
1193 /* size of stack */
1194 unsigned short stack_size;
1195 /* number of parameters. optional for client to give it to us */
1196 unsigned int number_of_params;
1197 /* cache of Oif_flags from v2 procedure header */
1198 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1199 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1200 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1201 /* the type of pass we are currently doing */
1202 enum stubless_phase phase;
1203 /* header for procedure string */
1204 const NDR_PROC_HEADER *pProcHeader;
1205 /* location to put retval into */
1206 LONG_PTR *retval_ptr = NULL;
1207 /* correlation cache */
1208 ULONG_PTR NdrCorrCache[256];
1210 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1212 if (pThis)
1213 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1214 else
1215 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1217 pStubDesc = pServerInfo->pStubDesc;
1218 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1219 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1221 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
1223 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1225 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1226 stack_size = pProcHeader->stack_size;
1227 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1230 else
1232 stack_size = pProcHeader->stack_size;
1233 pFormat += sizeof(NDR_PROC_HEADER);
1236 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1238 /* binding */
1239 switch (pProcHeader->handle_type)
1241 /* explicit binding: parse additional section */
1242 case RPC_FC_BIND_EXPLICIT:
1243 switch (*pFormat) /* handle_type */
1245 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
1246 pFormat += sizeof(NDR_EHD_PRIMITIVE);
1247 break;
1248 case RPC_FC_BIND_GENERIC: /* explicit generic */
1249 pFormat += sizeof(NDR_EHD_GENERIC);
1250 break;
1251 case RPC_FC_BIND_CONTEXT: /* explicit context */
1252 pFormat += sizeof(NDR_EHD_CONTEXT);
1253 break;
1254 default:
1255 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1256 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1258 break;
1259 case RPC_FC_BIND_GENERIC: /* implicit generic */
1260 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
1261 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
1262 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
1263 break;
1264 default:
1265 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1266 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1269 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1270 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1271 else
1272 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1274 /* create the full pointer translation tables, if requested */
1275 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1276 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1278 /* store the RPC flags away */
1279 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1280 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1282 /* use alternate memory allocation routines */
1283 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1284 #if 0
1285 NdrRpcSsEnableAllocate(&stubMsg);
1286 #else
1287 FIXME("Set RPCSS memory allocation routines\n");
1288 #endif
1290 TRACE("allocating memory for stack of size %x\n", stack_size);
1292 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1293 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1295 /* add the implicit This pointer as the first arg to the function if we
1296 * are calling an object method */
1297 if (pThis)
1298 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1300 if (pStubDesc->Version >= 0x20000) /* -Oicf format */
1302 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader = (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1304 Oif_flags = pOIFHeader->Oi2Flags;
1305 number_of_params = pOIFHeader->number_of_params;
1307 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1309 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1311 if (Oif_flags.HasExtensions)
1313 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
1314 ext_flags = pExtensions->Flags2;
1315 pFormat += pExtensions->Size;
1318 if (Oif_flags.HasPipes)
1320 FIXME("pipes not supported yet\n");
1321 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1322 /* init pipes package */
1323 /* NdrPipesInitialize(...) */
1325 if (ext_flags.HasNewCorrDesc)
1327 /* initialize extra correlation package */
1328 FIXME("new correlation description not implemented\n");
1329 stubMsg.fHasNewCorrDesc = TRUE;
1332 else
1334 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
1335 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
1336 /* reuse the correlation cache, it's not needed for v1 format */
1337 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
1340 /* convert strings, floating point values and endianness into our
1341 * preferred format */
1342 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1343 NdrConvert(&stubMsg, pFormat);
1345 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_FREE; phase++)
1347 TRACE("phase = %d\n", phase);
1348 switch (phase)
1350 case STUBLESS_CALLSERVER:
1351 /* call the server function */
1352 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1353 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1354 else
1356 SERVER_ROUTINE func;
1357 LONG_PTR retval;
1359 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1361 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1362 func = vtbl[pRpcMsg->ProcNum];
1364 else
1365 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1367 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1368 retval = call_server_func(func, args, stack_size);
1370 if (retval_ptr)
1372 TRACE("stub implementation returned 0x%lx\n", retval);
1373 *retval_ptr = retval;
1375 else
1376 TRACE("void stub implementation\n");
1379 stubMsg.Buffer = NULL;
1380 stubMsg.BufferLength = 0;
1382 break;
1383 case STUBLESS_GETBUFFER:
1384 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1385 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1386 else
1388 RPC_STATUS Status;
1390 pRpcMsg->BufferLength = stubMsg.BufferLength;
1391 /* allocate buffer for [out] and [ret] params */
1392 Status = I_RpcGetBuffer(pRpcMsg);
1393 if (Status)
1394 RpcRaiseException(Status);
1395 stubMsg.Buffer = pRpcMsg->Buffer;
1397 break;
1398 case STUBLESS_UNMARSHAL:
1399 case STUBLESS_INITOUT:
1400 case STUBLESS_CALCSIZE:
1401 case STUBLESS_MARSHAL:
1402 case STUBLESS_FREE:
1403 retval_ptr = stub_do_args(&stubMsg, pFormat, phase, number_of_params);
1404 break;
1405 default:
1406 ERR("shouldn't reach here. phase %d\n", phase);
1407 break;
1411 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1413 if (ext_flags.HasNewCorrDesc)
1415 /* free extra correlation package */
1416 /* NdrCorrelationFree(&stubMsg); */
1419 if (Oif_flags.HasPipes)
1421 /* NdrPipesDone(...) */
1424 /* free the full pointer translation tables */
1425 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1426 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1428 /* free server function stack */
1429 HeapFree(GetProcessHeap(), 0, args);
1431 return S_OK;
1434 /***********************************************************************
1435 * NdrServerCall2 [RPCRT4.@]
1437 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1439 DWORD dwPhase;
1440 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
1443 /***********************************************************************
1444 * NdrStubCall [RPCRT4.@]
1446 LONG WINAPI NdrStubCall( struct IRpcStubBuffer *This, struct IRpcChannelBuffer *channel,
1447 PRPC_MESSAGE msg, DWORD *phase )
1449 return NdrStubCall2( This, channel, msg, phase );
1452 /***********************************************************************
1453 * NdrServerCall [RPCRT4.@]
1455 void WINAPI NdrServerCall( PRPC_MESSAGE msg )
1457 DWORD phase;
1458 NdrStubCall( NULL, NULL, msg, &phase );
1461 struct async_call_data
1463 MIDL_STUB_MESSAGE *pStubMsg;
1464 const NDR_PROC_HEADER *pProcHeader;
1465 PFORMAT_STRING pHandleFormat;
1466 PFORMAT_STRING pParamFormat;
1467 RPC_BINDING_HANDLE hBinding;
1468 /* size of stack */
1469 unsigned short stack_size;
1470 /* number of parameters. optional for client to give it to us */
1471 unsigned int number_of_params;
1472 /* correlation cache */
1473 ULONG_PTR NdrCorrCache[256];
1476 LONG_PTR CDECL ndr_async_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, void **stack_top )
1478 /* pointer to start of stack where arguments start */
1479 PRPC_MESSAGE pRpcMsg;
1480 PMIDL_STUB_MESSAGE pStubMsg;
1481 RPC_ASYNC_STATE *pAsync;
1482 struct async_call_data *async_call_data;
1483 /* procedure number */
1484 unsigned short procedure_number;
1485 /* cache of Oif_flags from v2 procedure header */
1486 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1487 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1488 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1489 /* header for procedure string */
1490 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1491 /* -Oif or -Oicf generated format */
1492 BOOL bV2Format = FALSE;
1493 RPC_STATUS status;
1495 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
1497 /* Later NDR language versions probably won't be backwards compatible */
1498 if (pStubDesc->Version > 0x50002)
1500 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
1501 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1504 async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
1505 if (!async_call_data) RpcRaiseException(ERROR_OUTOFMEMORY);
1506 async_call_data->pProcHeader = pProcHeader;
1508 async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
1509 pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
1511 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1513 const NDR_PROC_HEADER_RPC *pProcHeader = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1514 async_call_data->stack_size = pProcHeader->stack_size;
1515 procedure_number = pProcHeader->proc_num;
1516 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1518 else
1520 async_call_data->stack_size = pProcHeader->stack_size;
1521 procedure_number = pProcHeader->proc_num;
1522 pFormat += sizeof(NDR_PROC_HEADER);
1524 TRACE("stack size: 0x%x\n", async_call_data->stack_size);
1525 TRACE("proc num: %d\n", procedure_number);
1527 /* create the full pointer translation tables, if requested */
1528 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1529 pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
1531 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1533 ERR("objects not supported\n");
1534 I_RpcFree(async_call_data);
1535 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1538 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
1540 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1541 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
1543 /* needed for conformance of top-level objects */
1544 pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
1545 memcpy(pStubMsg->StackTop, stack_top, async_call_data->stack_size);
1547 pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
1548 pAsync->StubInfo = async_call_data;
1549 async_call_data->pHandleFormat = pFormat;
1551 pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
1552 if (!pFormat) goto done;
1554 bV2Format = (pStubDesc->Version >= 0x20000);
1556 if (bV2Format)
1558 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1559 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1561 Oif_flags = pOIFHeader->Oi2Flags;
1562 async_call_data->number_of_params = pOIFHeader->number_of_params;
1564 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1566 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1568 if (Oif_flags.HasExtensions)
1570 const NDR_PROC_HEADER_EXTS *pExtensions =
1571 (const NDR_PROC_HEADER_EXTS *)pFormat;
1572 ext_flags = pExtensions->Flags2;
1573 pFormat += pExtensions->Size;
1576 else
1578 pFormat = convert_old_args( pStubMsg, pFormat, async_call_data->stack_size,
1579 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
1580 async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache),
1581 &async_call_data->number_of_params );
1584 async_call_data->pParamFormat = pFormat;
1586 pStubMsg->BufferLength = 0;
1588 /* store the RPC flags away */
1589 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1590 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1592 /* use alternate memory allocation routines */
1593 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1594 NdrRpcSmSetClientToOsf(pStubMsg);
1596 if (Oif_flags.HasPipes)
1598 FIXME("pipes not supported yet\n");
1599 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1600 /* init pipes package */
1601 /* NdrPipesInitialize(...) */
1603 if (ext_flags.HasNewCorrDesc)
1605 /* initialize extra correlation package */
1606 NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
1609 /* order of phases:
1610 * 1. CALCSIZE - calculate the buffer size
1611 * 2. GETBUFFER - allocate the buffer
1612 * 3. MARSHAL - marshal [in] params into the buffer
1613 * 4. SENDRECEIVE - send buffer
1614 * Then in NdrpCompleteAsyncClientCall:
1615 * 1. SENDRECEIVE - receive buffer
1616 * 2. UNMARSHAL - unmarshal [out] params from buffer
1619 /* 1. CALCSIZE */
1620 TRACE( "CALCSIZE\n" );
1621 client_do_args(pStubMsg, pFormat, STUBLESS_CALCSIZE, NULL, async_call_data->number_of_params, NULL);
1623 /* 2. GETBUFFER */
1624 TRACE( "GETBUFFER\n" );
1625 if (Oif_flags.HasPipes)
1626 /* NdrGetPipeBuffer(...) */
1627 FIXME("pipes not supported yet\n");
1628 else
1630 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1631 #if 0
1632 NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1633 #else
1634 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1635 #endif
1636 else
1637 NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1639 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1640 status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
1641 if (status != RPC_S_OK)
1642 RpcRaiseException(status);
1644 /* 3. MARSHAL */
1645 TRACE( "MARSHAL\n" );
1646 client_do_args(pStubMsg, pFormat, STUBLESS_MARSHAL, NULL, async_call_data->number_of_params, NULL);
1648 /* 4. SENDRECEIVE */
1649 TRACE( "SEND\n" );
1650 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1651 /* send the [in] params only */
1652 if (Oif_flags.HasPipes)
1653 /* NdrPipesSend(...) */
1654 FIXME("pipes not supported yet\n");
1655 else
1657 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1658 #if 0
1659 NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1660 #else
1661 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1662 #endif
1663 else
1665 pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
1666 status = I_RpcSend(pStubMsg->RpcMsg);
1667 if (status != RPC_S_OK)
1668 RpcRaiseException(status);
1672 done:
1673 TRACE("returning 0\n");
1674 return 0;
1677 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
1679 /* pointer to start of stack where arguments start */
1680 PMIDL_STUB_MESSAGE pStubMsg;
1681 struct async_call_data *async_call_data;
1682 /* header for procedure string */
1683 const NDR_PROC_HEADER * pProcHeader;
1684 RPC_STATUS status = RPC_S_OK;
1686 if (!pAsync->StubInfo)
1687 return RPC_S_INVALID_ASYNC_HANDLE;
1689 async_call_data = pAsync->StubInfo;
1690 pStubMsg = async_call_data->pStubMsg;
1691 pProcHeader = async_call_data->pProcHeader;
1693 /* order of phases:
1694 * 1. CALCSIZE - calculate the buffer size
1695 * 2. GETBUFFER - allocate the buffer
1696 * 3. MARSHAL - marshal [in] params into the buffer
1697 * 4. SENDRECEIVE - send buffer
1698 * Then in NdrpCompleteAsyncClientCall:
1699 * 1. SENDRECEIVE - receive buffer
1700 * 2. UNMARSHAL - unmarshal [out] params from buffer
1703 /* 1. SENDRECEIVE */
1704 TRACE( "RECEIVE\n" );
1705 pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1706 /* receive the [out] params */
1707 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1708 #if 0
1709 NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1710 #else
1711 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1712 #endif
1713 else
1715 status = I_RpcReceive(pStubMsg->RpcMsg);
1716 if (status != RPC_S_OK)
1717 goto cleanup;
1718 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
1719 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
1720 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
1721 pStubMsg->Buffer = pStubMsg->BufferStart;
1724 /* convert strings, floating point values and endianness into our
1725 * preferred format */
1726 #if 0
1727 if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1728 NdrConvert(pStubMsg, pFormat);
1729 #endif
1731 /* 2. UNMARSHAL */
1732 TRACE( "UNMARSHAL\n" );
1733 client_do_args(pStubMsg, async_call_data->pParamFormat, STUBLESS_UNMARSHAL,
1734 NULL, async_call_data->number_of_params, Reply);
1736 cleanup:
1737 if (pStubMsg->fHasNewCorrDesc)
1739 /* free extra correlation package */
1740 NdrCorrelationFree(pStubMsg);
1743 /* free the full pointer translation tables */
1744 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1745 NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
1747 /* free marshalling buffer */
1748 NdrFreeBuffer(pStubMsg);
1749 client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
1751 I_RpcFree(pStubMsg->StackTop);
1752 I_RpcFree(async_call_data);
1754 TRACE("-- 0x%x\n", status);
1755 return status;
1758 #ifdef __x86_64__
1760 __ASM_GLOBAL_FUNC( NdrAsyncClientCall,
1761 "movq %r8,0x18(%rsp)\n\t"
1762 "movq %r9,0x20(%rsp)\n\t"
1763 "leaq 0x18(%rsp),%r8\n\t"
1764 "subq $0x28,%rsp\n\t"
1765 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
1766 "call " __ASM_NAME("ndr_async_client_call") "\n\t"
1767 "addq $0x28,%rsp\n\t"
1768 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
1769 "ret" );
1771 #else /* __x86_64__ */
1773 /***********************************************************************
1774 * NdrAsyncClientCall [RPCRT4.@]
1776 CLIENT_CALL_RETURN WINAPIV NdrAsyncClientCall( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1778 __ms_va_list args;
1779 LONG_PTR ret;
1781 __ms_va_start( args, format );
1782 ret = ndr_async_client_call( desc, format, va_arg( args, void ** ));
1783 __ms_va_end( args );
1784 return *(CLIENT_CALL_RETURN *)&ret;
1787 #endif /* __x86_64__ */
1789 RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
1790 struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
1791 DWORD * pdwStubPhase)
1793 FIXME("unimplemented, expect crash!\n");
1794 return 0;