riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / rpcrt4 / ndr_stubless.c
blobc9d993073a840c6566df1ded3d71fedb2d552ac8
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 BOOL is_oicf_stubdesc(const PMIDL_STUB_DESC pStubDesc)
55 return pStubDesc->Version >= 0x20000;
58 static inline void call_buffer_sizer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
59 const NDR_PARAM_OIF *param)
61 PFORMAT_STRING pFormat;
62 NDR_BUFFERSIZE m;
64 if (param->attr.IsBasetype)
66 pFormat = &param->u.type_format_char;
67 if (param->attr.IsSimpleRef) pMemory = *(unsigned char **)pMemory;
69 else
71 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
72 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
75 m = NdrBufferSizer[pFormat[0] & NDR_TABLE_MASK];
76 if (m) m(pStubMsg, pMemory, pFormat);
77 else
79 FIXME("format type 0x%x not implemented\n", pFormat[0]);
80 RpcRaiseException(RPC_X_BAD_STUB_DATA);
84 static inline unsigned char *call_marshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
85 const NDR_PARAM_OIF *param)
87 PFORMAT_STRING pFormat;
88 NDR_MARSHALL m;
90 if (param->attr.IsBasetype)
92 pFormat = &param->u.type_format_char;
93 if (param->attr.IsSimpleRef) pMemory = *(unsigned char **)pMemory;
95 else
97 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
98 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
101 m = NdrMarshaller[pFormat[0] & NDR_TABLE_MASK];
102 if (m) return m(pStubMsg, pMemory, pFormat);
103 else
105 FIXME("format type 0x%x not implemented\n", pFormat[0]);
106 RpcRaiseException(RPC_X_BAD_STUB_DATA);
107 return NULL;
111 static inline unsigned char *call_unmarshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char **ppMemory,
112 const NDR_PARAM_OIF *param, unsigned char fMustAlloc)
114 PFORMAT_STRING pFormat;
115 NDR_UNMARSHALL m;
117 if (param->attr.IsBasetype)
119 pFormat = &param->u.type_format_char;
120 if (param->attr.IsSimpleRef) ppMemory = (unsigned char **)*ppMemory;
122 else
124 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
125 if (!param->attr.IsByValue) ppMemory = (unsigned char **)*ppMemory;
128 m = NdrUnmarshaller[pFormat[0] & NDR_TABLE_MASK];
129 if (m) return m(pStubMsg, ppMemory, pFormat, fMustAlloc);
130 else
132 FIXME("format type 0x%x not implemented\n", pFormat[0]);
133 RpcRaiseException(RPC_X_BAD_STUB_DATA);
134 return NULL;
138 static inline void call_freer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
139 const NDR_PARAM_OIF *param)
141 PFORMAT_STRING pFormat;
142 NDR_FREE m;
144 if (param->attr.IsBasetype) return; /* nothing to do */
145 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
146 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
148 m = NdrFreer[pFormat[0] & NDR_TABLE_MASK];
149 if (m) m(pStubMsg, pMemory, pFormat);
152 static DWORD calc_arg_size(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
154 DWORD size;
155 switch(*pFormat)
157 case RPC_FC_RP:
158 if (pFormat[1] & RPC_FC_P_SIMPLEPOINTER)
160 FIXME("Simple reference pointer (type %#x).\n", pFormat[2]);
161 size = sizeof(void *);
162 break;
164 size = calc_arg_size(pStubMsg, &pFormat[2] + *(const SHORT*)&pFormat[2]);
165 break;
166 case RPC_FC_STRUCT:
167 case RPC_FC_PSTRUCT:
168 size = *(const WORD*)(pFormat + 2);
169 break;
170 case RPC_FC_BOGUS_STRUCT:
171 size = *(const WORD*)(pFormat + 2);
172 if(*(const WORD*)(pFormat + 4))
173 FIXME("Unhandled conformant description\n");
174 break;
175 case RPC_FC_CARRAY:
176 case RPC_FC_CVARRAY:
177 size = *(const WORD*)(pFormat + 2);
178 ComputeConformance(pStubMsg, NULL, pFormat + 4, 0);
179 size *= pStubMsg->MaxCount;
180 break;
181 case RPC_FC_SMFARRAY:
182 case RPC_FC_SMVARRAY:
183 size = *(const WORD*)(pFormat + 2);
184 break;
185 case RPC_FC_LGFARRAY:
186 case RPC_FC_LGVARRAY:
187 size = *(const DWORD*)(pFormat + 2);
188 break;
189 case RPC_FC_BOGUS_ARRAY:
190 pFormat = ComputeConformance(pStubMsg, NULL, pFormat + 4, *(const WORD*)&pFormat[2]);
191 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
192 pFormat = ComputeVariance(pStubMsg, NULL, pFormat, pStubMsg->MaxCount);
193 size = ComplexStructSize(pStubMsg, pFormat);
194 size *= pStubMsg->MaxCount;
195 break;
196 case RPC_FC_USER_MARSHAL:
197 size = *(const WORD*)(pFormat + 4);
198 break;
199 case RPC_FC_CSTRING:
200 size = *(const WORD*)(pFormat + 2);
201 break;
202 case RPC_FC_WSTRING:
203 size = *(const WORD*)(pFormat + 2) * sizeof(WCHAR);
204 break;
205 case RPC_FC_C_CSTRING:
206 case RPC_FC_C_WSTRING:
207 if (*pFormat == RPC_FC_C_CSTRING)
208 size = sizeof(CHAR);
209 else
210 size = sizeof(WCHAR);
211 if (pFormat[1] == RPC_FC_STRING_SIZED)
212 ComputeConformance(pStubMsg, NULL, pFormat + 2, 0);
213 else
214 pStubMsg->MaxCount = 0;
215 size *= pStubMsg->MaxCount;
216 break;
217 default:
218 FIXME("Unhandled type %02x\n", *pFormat);
219 /* fallthrough */
220 case RPC_FC_IP:
221 size = sizeof(void *);
222 break;
224 return size;
227 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
229 #if 0 /* these functions are not defined yet */
230 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
231 pMessage->pfnFree = NdrRpcSmClientFree;
232 #endif
235 static const char *debugstr_PROC_PF(PARAM_ATTRIBUTES param_attributes)
237 char buffer[160];
239 buffer[0] = 0;
240 if (param_attributes.MustSize) strcat(buffer, " MustSize");
241 if (param_attributes.MustFree) strcat(buffer, " MustFree");
242 if (param_attributes.IsPipe) strcat(buffer, " IsPipe");
243 if (param_attributes.IsIn) strcat(buffer, " IsIn");
244 if (param_attributes.IsOut) strcat(buffer, " IsOut");
245 if (param_attributes.IsReturn) strcat(buffer, " IsReturn");
246 if (param_attributes.IsBasetype) strcat(buffer, " IsBasetype");
247 if (param_attributes.IsByValue) strcat(buffer, " IsByValue");
248 if (param_attributes.IsSimpleRef) strcat(buffer, " IsSimpleRef");
249 if (param_attributes.IsDontCallFreeInst) strcat(buffer, " IsDontCallFreeInst");
250 if (param_attributes.SaveForAsyncFinish) strcat(buffer, " SaveForAsyncFinish");
251 if (param_attributes.ServerAllocSize)
252 sprintf( buffer + strlen(buffer), " ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
253 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
256 static const char *debugstr_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
258 char buffer[160];
260 buffer[0] = 0;
261 if (Oi2Flags.ServerMustSize) strcat(buffer, " ServerMustSize");
262 if (Oi2Flags.ClientMustSize) strcat(buffer, " ClientMustSize");
263 if (Oi2Flags.HasReturn) strcat(buffer, " HasReturn");
264 if (Oi2Flags.HasPipes) strcat(buffer, " HasPipes");
265 if (Oi2Flags.Unused) strcat(buffer, " Unused");
266 if (Oi2Flags.HasAsyncUuid) strcat(buffer, " HasAsyncUuid");
267 if (Oi2Flags.HasExtensions) strcat(buffer, " HasExtensions");
268 if (Oi2Flags.HasAsyncHandle) strcat(buffer, " HasAsyncHandle");
269 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
272 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
274 static PFORMAT_STRING client_get_handle(
275 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
276 PFORMAT_STRING pFormat, handle_t *phBinding)
278 /* binding */
279 switch (pProcHeader->handle_type)
281 /* explicit binding: parse additional section */
282 case RPC_FC_BIND_EXPLICIT:
283 switch (*pFormat) /* handle_type */
285 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
287 const NDR_EHD_PRIMITIVE *pDesc = (const NDR_EHD_PRIMITIVE *)pFormat;
289 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
291 if (pDesc->flag) /* pointer to binding */
292 *phBinding = **(handle_t **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
293 else
294 *phBinding = *(handle_t *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
295 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
297 case RPC_FC_BIND_GENERIC: /* explicit generic */
299 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
300 void *pObject = NULL;
301 void *pArg;
302 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
304 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
306 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
307 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
308 else
309 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
310 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
311 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
312 *phBinding = pGenPair->pfnBind(pObject);
313 return pFormat + sizeof(NDR_EHD_GENERIC);
315 case RPC_FC_BIND_CONTEXT: /* explicit context */
317 const NDR_EHD_CONTEXT *pDesc = (const NDR_EHD_CONTEXT *)pFormat;
318 NDR_CCONTEXT context_handle;
319 TRACE("Explicit bind context\n");
320 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
322 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
323 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
325 else
326 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
328 if (context_handle) *phBinding = NDRCContextBinding(context_handle);
329 else if (pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL)
331 ERR("null context handle isn't allowed\n");
332 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
333 return NULL;
335 /* FIXME: should we store this structure in stubMsg.pContext? */
336 return pFormat + sizeof(NDR_EHD_CONTEXT);
338 default:
339 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
340 RpcRaiseException(RPC_X_BAD_STUB_DATA);
342 break;
343 case RPC_FC_BIND_GENERIC: /* implicit generic */
344 FIXME("RPC_FC_BIND_GENERIC\n");
345 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
346 break;
347 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
348 TRACE("Implicit primitive handle\n");
349 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
350 break;
351 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
352 TRACE("RPC_FC_CALLBACK_HANDLE\n");
353 /* server calls callback procedures only in response to remote call, and most recent
354 binding handle is used. Calling back to a client can potentially result in another
355 callback with different current handle. */
356 *phBinding = I_RpcGetCurrentCallHandle();
357 break;
358 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
359 /* strictly speaking, it isn't necessary to set hBinding here
360 * since it isn't actually used (hence the automatic in its name),
361 * but then why does MIDL generate a valid entry in the
362 * MIDL_STUB_DESC for it? */
363 TRACE("Implicit auto handle\n");
364 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
365 break;
366 default:
367 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
368 RpcRaiseException(RPC_X_BAD_STUB_DATA);
370 return pFormat;
373 static void client_free_handle(
374 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
375 PFORMAT_STRING pFormat, handle_t hBinding)
377 /* binding */
378 switch (pProcHeader->handle_type)
380 /* explicit binding: parse additional section */
381 case RPC_FC_BIND_EXPLICIT:
382 switch (*pFormat) /* handle_type */
384 case RPC_FC_BIND_GENERIC: /* explicit generic */
386 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
387 void *pObject = NULL;
388 void *pArg;
389 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
391 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
393 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
394 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
395 else
396 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
397 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
398 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
399 pGenPair->pfnUnbind(pObject, hBinding);
400 break;
402 case RPC_FC_BIND_CONTEXT: /* explicit context */
403 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
404 break;
405 default:
406 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
407 RpcRaiseException(RPC_X_BAD_STUB_DATA);
409 break;
410 case RPC_FC_BIND_GENERIC: /* implicit generic */
411 FIXME("RPC_FC_BIND_GENERIC\n");
412 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
413 break;
414 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
415 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
416 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
417 break;
418 default:
419 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
420 RpcRaiseException(RPC_X_BAD_STUB_DATA);
424 void client_do_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, enum stubless_phase phase,
425 void **fpu_args, unsigned short number_of_params, unsigned char *pRetVal )
427 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
428 unsigned int i;
430 for (i = 0; i < number_of_params; i++)
432 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
433 PFORMAT_STRING pTypeFormat = (PFORMAT_STRING)&pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
435 #ifdef __x86_64__ /* floats are passed as doubles through varargs functions */
436 float f;
438 if (params[i].attr.IsBasetype &&
439 params[i].u.type_format_char == RPC_FC_FLOAT &&
440 !params[i].attr.IsSimpleRef &&
441 !fpu_args)
443 f = *(double *)pArg;
444 pArg = (unsigned char *)&f;
446 #endif
448 TRACE("param[%d]: %p type %02x %s\n", i, pArg,
449 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
450 debugstr_PROC_PF( params[i].attr ));
452 switch (phase)
454 case STUBLESS_INITOUT:
455 if (!params[i].attr.IsBasetype && params[i].attr.IsOut &&
456 !params[i].attr.IsIn && !params[i].attr.IsByValue)
458 memset( *(unsigned char **)pArg, 0, calc_arg_size( pStubMsg, pTypeFormat ));
460 break;
461 case STUBLESS_CALCSIZE:
462 if (params[i].attr.IsSimpleRef && !*(unsigned char **)pArg)
463 RpcRaiseException(RPC_X_NULL_REF_POINTER);
464 if (params[i].attr.IsIn) call_buffer_sizer(pStubMsg, pArg, &params[i]);
465 break;
466 case STUBLESS_MARSHAL:
467 if (params[i].attr.IsIn) call_marshaller(pStubMsg, pArg, &params[i]);
468 break;
469 case STUBLESS_UNMARSHAL:
470 if (params[i].attr.IsOut)
472 if (params[i].attr.IsReturn && pRetVal) pArg = pRetVal;
473 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
475 break;
476 case STUBLESS_FREE:
477 if (!params[i].attr.IsBasetype && params[i].attr.IsOut && !params[i].attr.IsByValue)
478 NdrClearOutParameters( pStubMsg, pTypeFormat, *(unsigned char **)pArg );
479 break;
480 default:
481 RpcRaiseException(RPC_S_INTERNAL_ERROR);
486 static unsigned int type_stack_size(unsigned char fc)
488 switch (fc)
490 case RPC_FC_BYTE:
491 case RPC_FC_CHAR:
492 case RPC_FC_SMALL:
493 case RPC_FC_USMALL:
494 case RPC_FC_WCHAR:
495 case RPC_FC_SHORT:
496 case RPC_FC_USHORT:
497 case RPC_FC_LONG:
498 case RPC_FC_ULONG:
499 case RPC_FC_INT3264:
500 case RPC_FC_UINT3264:
501 case RPC_FC_ENUM16:
502 case RPC_FC_ENUM32:
503 case RPC_FC_FLOAT:
504 case RPC_FC_ERROR_STATUS_T:
505 case RPC_FC_IGNORE:
506 return sizeof(void *);
507 case RPC_FC_DOUBLE:
508 return sizeof(double);
509 case RPC_FC_HYPER:
510 return sizeof(ULONGLONG);
511 default:
512 ERR("invalid base type 0x%x\n", fc);
513 RpcRaiseException(RPC_S_INTERNAL_ERROR);
517 static BOOL is_by_value( PFORMAT_STRING format )
519 switch (*format)
521 case RPC_FC_USER_MARSHAL:
522 case RPC_FC_STRUCT:
523 case RPC_FC_PSTRUCT:
524 case RPC_FC_CSTRUCT:
525 case RPC_FC_CPSTRUCT:
526 case RPC_FC_CVSTRUCT:
527 case RPC_FC_BOGUS_STRUCT:
528 return TRUE;
529 default:
530 return FALSE;
534 PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
535 unsigned int stack_size, BOOL object_proc,
536 void *buffer, unsigned int size, unsigned int *count )
538 NDR_PARAM_OIF *args = buffer;
539 unsigned int i, stack_offset = object_proc ? sizeof(void *) : 0;
541 for (i = 0; stack_offset < stack_size; i++)
543 const NDR_PARAM_OI_BASETYPE *param = (const NDR_PARAM_OI_BASETYPE *)pFormat;
544 const NDR_PARAM_OI_OTHER *other = (const NDR_PARAM_OI_OTHER *)pFormat;
546 if (i + 1 > size / sizeof(*args))
548 FIXME( "%u args not supported\n", i );
549 RpcRaiseException( RPC_S_INTERNAL_ERROR );
552 args[i].stack_offset = stack_offset;
553 memset( &args[i].attr, 0, sizeof(args[i].attr) );
555 switch (param->param_direction)
557 case RPC_FC_IN_PARAM_BASETYPE:
558 args[i].attr.IsIn = 1;
559 args[i].attr.IsBasetype = 1;
560 break;
561 case RPC_FC_RETURN_PARAM_BASETYPE:
562 args[i].attr.IsOut = 1;
563 args[i].attr.IsReturn = 1;
564 args[i].attr.IsBasetype = 1;
565 break;
566 case RPC_FC_IN_PARAM:
567 args[i].attr.IsIn = 1;
568 args[i].attr.MustFree = 1;
569 break;
570 case RPC_FC_IN_PARAM_NO_FREE_INST:
571 args[i].attr.IsIn = 1;
572 args[i].attr.IsDontCallFreeInst = 1;
573 break;
574 case RPC_FC_IN_OUT_PARAM:
575 args[i].attr.IsIn = 1;
576 args[i].attr.IsOut = 1;
577 args[i].attr.MustFree = 1;
578 break;
579 case RPC_FC_OUT_PARAM:
580 args[i].attr.IsOut = 1;
581 break;
582 case RPC_FC_RETURN_PARAM:
583 args[i].attr.IsOut = 1;
584 args[i].attr.IsReturn = 1;
585 break;
587 if (args[i].attr.IsBasetype)
589 args[i].u.type_format_char = param->type_format_char;
590 stack_offset += type_stack_size( param->type_format_char );
591 pFormat += sizeof(NDR_PARAM_OI_BASETYPE);
593 else
595 args[i].u.type_offset = other->type_offset;
596 args[i].attr.IsByValue = is_by_value( &pStubMsg->StubDesc->pFormatTypes[other->type_offset] );
597 stack_offset += other->stack_size * sizeof(void *);
598 pFormat += sizeof(NDR_PARAM_OI_OTHER);
601 *count = i;
602 return (PFORMAT_STRING)args;
605 LONG_PTR CDECL ndr_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
606 void **stack_top, void **fpu_stack )
608 /* pointer to start of stack where arguments start */
609 RPC_MESSAGE rpcMsg;
610 MIDL_STUB_MESSAGE stubMsg;
611 handle_t hBinding = NULL;
612 /* procedure number */
613 unsigned short procedure_number;
614 /* size of stack */
615 unsigned short stack_size;
616 /* number of parameters. optional for client to give it to us */
617 unsigned int number_of_params;
618 /* cache of Oif_flags from v2 procedure header */
619 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
620 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
621 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
622 /* header for procedure string */
623 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
624 /* the value to return to the client from the remote procedure */
625 LONG_PTR RetVal = 0;
626 /* the pointer to the object when in OLE mode */
627 void * This = NULL;
628 PFORMAT_STRING pHandleFormat;
629 /* correlation cache */
630 ULONG_PTR NdrCorrCache[256];
632 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
634 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
636 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
638 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
639 stack_size = header_rpc->stack_size;
640 procedure_number = header_rpc->proc_num;
641 pFormat += sizeof(NDR_PROC_HEADER_RPC);
643 else
645 stack_size = pProcHeader->stack_size;
646 procedure_number = pProcHeader->proc_num;
647 pFormat += sizeof(NDR_PROC_HEADER);
649 TRACE("stack size: 0x%x\n", stack_size);
650 TRACE("proc num: %d\n", procedure_number);
652 /* create the full pointer translation tables, if requested */
653 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
654 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
656 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
658 /* object is always the first argument */
659 This = stack_top[0];
660 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
662 else
663 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
665 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
666 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
668 stubMsg.StackTop = (unsigned char *)stack_top;
669 pHandleFormat = pFormat;
671 /* we only need a handle if this isn't an object method */
672 if (!(pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT))
674 pFormat = client_get_handle(&stubMsg, pProcHeader, pHandleFormat, &hBinding);
675 if (!pFormat) goto done;
678 if (is_oicf_stubdesc(pStubDesc)) /* -Oicf format */
680 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
681 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
683 Oif_flags = pOIFHeader->Oi2Flags;
684 number_of_params = pOIFHeader->number_of_params;
686 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
688 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
690 if (Oif_flags.HasExtensions)
692 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
693 ext_flags = pExtensions->Flags2;
694 pFormat += pExtensions->Size;
695 #ifdef __x86_64__
696 if (pExtensions->Size > sizeof(*pExtensions) && fpu_stack)
698 int i;
699 unsigned short fpu_mask = *(unsigned short *)(pExtensions + 1);
700 for (i = 0; i < 4; i++, fpu_mask >>= 2)
701 switch (fpu_mask & 3)
703 case 1: *(float *)&stack_top[i] = *(float *)&fpu_stack[i]; break;
704 case 2: *(double *)&stack_top[i] = *(double *)&fpu_stack[i]; break;
707 #endif
710 else
712 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
713 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
714 /* reuse the correlation cache, it's not needed for v1 format */
715 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
718 stubMsg.BufferLength = 0;
720 /* store the RPC flags away */
721 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
722 rpcMsg.RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
724 /* use alternate memory allocation routines */
725 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
726 NdrRpcSmSetClientToOsf(&stubMsg);
728 if (Oif_flags.HasPipes)
730 FIXME("pipes not supported yet\n");
731 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
732 /* init pipes package */
733 /* NdrPipesInitialize(...) */
735 if (ext_flags.HasNewCorrDesc)
737 /* initialize extra correlation package */
738 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
741 /* order of phases:
742 * 1. INITOUT - zero [out] parameters (proxies only)
743 * 2. CALCSIZE - calculate the buffer size
744 * 3. GETBUFFER - allocate the buffer
745 * 4. MARSHAL - marshal [in] params into the buffer
746 * 5. SENDRECEIVE - send/receive buffer
747 * 6. UNMARSHAL - unmarshal [out] params from buffer
748 * 7. FREE - clear [out] parameters (for proxies, and only on error)
750 if ((pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT) ||
751 (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_HAS_COMM_OR_FAULT))
753 /* 1. INITOUT */
754 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
756 TRACE( "INITOUT\n" );
757 client_do_args(&stubMsg, pFormat, STUBLESS_INITOUT, fpu_stack,
758 number_of_params, (unsigned char *)&RetVal);
761 __TRY
763 /* 2. CALCSIZE */
764 TRACE( "CALCSIZE\n" );
765 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
766 number_of_params, (unsigned char *)&RetVal);
768 /* 3. GETBUFFER */
769 TRACE( "GETBUFFER\n" );
770 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
772 /* allocate the buffer */
773 NdrProxyGetBuffer(This, &stubMsg);
775 else
777 /* allocate the buffer */
778 if (Oif_flags.HasPipes)
779 /* NdrGetPipeBuffer(...) */
780 FIXME("pipes not supported yet\n");
781 else
783 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
784 #if 0
785 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
786 #else
787 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
788 #endif
789 else
790 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
794 /* 4. MARSHAL */
795 TRACE( "MARSHAL\n" );
796 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
797 number_of_params, (unsigned char *)&RetVal);
799 /* 5. SENDRECEIVE */
800 TRACE( "SENDRECEIVE\n" );
801 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
803 /* send the [in] params and receive the [out] and [retval]
804 * params */
805 NdrProxySendReceive(This, &stubMsg);
807 else
809 /* send the [in] params and receive the [out] and [retval]
810 * params */
811 if (Oif_flags.HasPipes)
812 /* NdrPipesSendReceive(...) */
813 FIXME("pipes not supported yet\n");
814 else
816 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
817 #if 0
818 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
819 #else
820 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
821 #endif
822 else
823 NdrSendReceive(&stubMsg, stubMsg.Buffer);
827 /* convert strings, floating point values and endianness into our
828 * preferred format */
829 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
830 NdrConvert(&stubMsg, pFormat);
832 /* 6. UNMARSHAL */
833 TRACE( "UNMARSHAL\n" );
834 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
835 number_of_params, (unsigned char *)&RetVal);
837 __EXCEPT_ALL
839 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
841 /* 7. FREE */
842 TRACE( "FREE\n" );
843 client_do_args(&stubMsg, pFormat, STUBLESS_FREE, fpu_stack,
844 number_of_params, (unsigned char *)&RetVal);
845 RetVal = NdrProxyErrorHandler(GetExceptionCode());
847 else
849 const COMM_FAULT_OFFSETS *comm_fault_offsets = &pStubDesc->CommFaultOffsets[procedure_number];
850 ULONG *comm_status;
851 ULONG *fault_status;
853 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets->CommOffset, comm_fault_offsets->FaultOffset);
855 if (comm_fault_offsets->CommOffset == -1)
856 comm_status = (ULONG *)&RetVal;
857 else if (comm_fault_offsets->CommOffset >= 0)
858 comm_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
859 else
860 comm_status = NULL;
862 if (comm_fault_offsets->FaultOffset == -1)
863 fault_status = (ULONG *)&RetVal;
864 else if (comm_fault_offsets->FaultOffset >= 0)
865 fault_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->FaultOffset);
866 else
867 fault_status = NULL;
869 NdrMapCommAndFaultStatus(&stubMsg, comm_status, fault_status,
870 GetExceptionCode());
873 __ENDTRY
875 else
877 /* 2. CALCSIZE */
878 TRACE( "CALCSIZE\n" );
879 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
880 number_of_params, (unsigned char *)&RetVal);
882 /* 3. GETBUFFER */
883 TRACE( "GETBUFFER\n" );
884 if (Oif_flags.HasPipes)
885 /* NdrGetPipeBuffer(...) */
886 FIXME("pipes not supported yet\n");
887 else
889 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
890 #if 0
891 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
892 #else
893 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
894 #endif
895 else
896 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
899 /* 4. MARSHAL */
900 TRACE( "MARSHAL\n" );
901 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
902 number_of_params, (unsigned char *)&RetVal);
904 /* 5. SENDRECEIVE */
905 TRACE( "SENDRECEIVE\n" );
906 if (Oif_flags.HasPipes)
907 /* NdrPipesSendReceive(...) */
908 FIXME("pipes not supported yet\n");
909 else
911 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
912 #if 0
913 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
914 #else
915 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
916 #endif
917 else
918 NdrSendReceive(&stubMsg, stubMsg.Buffer);
921 /* convert strings, floating point values and endianness into our
922 * preferred format */
923 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
924 NdrConvert(&stubMsg, pFormat);
926 /* 6. UNMARSHAL */
927 TRACE( "UNMARSHAL\n" );
928 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
929 number_of_params, (unsigned char *)&RetVal);
932 if (ext_flags.HasNewCorrDesc)
934 /* free extra correlation package */
935 NdrCorrelationFree(&stubMsg);
938 if (Oif_flags.HasPipes)
940 /* NdrPipesDone(...) */
943 /* free the full pointer translation tables */
944 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
945 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
947 /* free marshalling buffer */
948 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
949 NdrProxyFreeBuffer(This, &stubMsg);
950 else
952 NdrFreeBuffer(&stubMsg);
953 client_free_handle(&stubMsg, pProcHeader, pHandleFormat, hBinding);
956 done:
957 TRACE("RetVal = 0x%lx\n", RetVal);
958 return RetVal;
961 #ifdef __x86_64__
963 __ASM_GLOBAL_FUNC( NdrClientCall2,
964 "movq %r8,0x18(%rsp)\n\t"
965 "movq %r9,0x20(%rsp)\n\t"
966 "leaq 0x18(%rsp),%r8\n\t"
967 "xorq %r9,%r9\n\t"
968 "subq $0x28,%rsp\n\t"
969 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
970 "call " __ASM_NAME("ndr_client_call") "\n\t"
971 "addq $0x28,%rsp\n\t"
972 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
973 "ret" );
975 #else /* __x86_64__ */
977 /***********************************************************************
978 * NdrClientCall2 [RPCRT4.@]
980 CLIENT_CALL_RETURN WINAPIV NdrClientCall2( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
982 __ms_va_list args;
983 LONG_PTR ret;
985 __ms_va_start( args, format );
986 ret = ndr_client_call( desc, format, va_arg( args, void ** ), NULL );
987 __ms_va_end( args );
988 return *(CLIENT_CALL_RETURN *)&ret;
991 #endif /* __x86_64__ */
993 /* Calls a function with the specified arguments, restoring the stack
994 * properly afterwards as we don't know the calling convention of the
995 * function */
996 #if defined __i386__ && defined _MSC_VER
997 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
999 __asm
1001 push ebp
1002 mov ebp, esp
1003 push edi ; Save registers
1004 push esi
1005 mov eax, [ebp+16] ; Get stack size
1006 sub esp, eax ; Make room in stack for arguments
1007 and esp, 0xFFFFFFF0
1008 mov edi, esp
1009 mov ecx, eax
1010 mov esi, [ebp+12]
1011 shr ecx, 2
1013 rep movsd ; Copy dword blocks
1014 call [ebp+8] ; Call function
1015 lea esp, [ebp-8] ; Restore stack
1016 pop esi ; Restore registers
1017 pop edi
1018 pop ebp
1022 #elif defined __i386__ && defined __GNUC__
1023 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1024 __ASM_GLOBAL_FUNC(call_server_func,
1025 "pushl %ebp\n\t"
1026 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1027 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1028 "movl %esp,%ebp\n\t"
1029 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1030 "pushl %edi\n\t" /* Save registers */
1031 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
1032 "pushl %esi\n\t"
1033 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
1034 "movl 16(%ebp), %eax\n\t" /* Get stack size */
1035 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
1036 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
1037 "movl %esp, %edi\n\t"
1038 "movl %eax, %ecx\n\t"
1039 "movl 12(%ebp), %esi\n\t"
1040 "shrl $2, %ecx\n\t" /* divide by 4 */
1041 "cld\n\t"
1042 "rep; movsl\n\t" /* Copy dword blocks */
1043 "call *8(%ebp)\n\t" /* Call function */
1044 "leal -8(%ebp), %esp\n\t" /* Restore stack */
1045 "popl %esi\n\t" /* Restore registers */
1046 __ASM_CFI(".cfi_same_value %esi\n\t")
1047 "popl %edi\n\t"
1048 __ASM_CFI(".cfi_same_value %edi\n\t")
1049 "popl %ebp\n\t"
1050 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1051 __ASM_CFI(".cfi_same_value %ebp\n\t")
1052 "ret" )
1053 #elif defined __x86_64__
1054 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1055 __ASM_GLOBAL_FUNC( call_server_func,
1056 "pushq %rbp\n\t"
1057 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
1058 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
1059 "movq %rsp,%rbp\n\t"
1060 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
1061 "pushq %rsi\n\t"
1062 __ASM_CFI(".cfi_rel_offset %rsi,-8\n\t")
1063 "pushq %rdi\n\t"
1064 __ASM_CFI(".cfi_rel_offset %rdi,-16\n\t")
1065 "movq %rcx,%rax\n\t" /* function to call */
1066 "movq $32,%rcx\n\t" /* allocate max(32,stack_size) bytes of stack space */
1067 "cmpq %rcx,%r8\n\t"
1068 "cmovgq %r8,%rcx\n\t"
1069 "subq %rcx,%rsp\n\t"
1070 "andq $~15,%rsp\n\t"
1071 "movq %r8,%rcx\n\t"
1072 "shrq $3,%rcx\n\t"
1073 "movq %rsp,%rdi\n\t"
1074 "movq %rdx,%rsi\n\t"
1075 "rep; movsq\n\t" /* copy arguments */
1076 "movq 0(%rsp),%rcx\n\t"
1077 "movq 8(%rsp),%rdx\n\t"
1078 "movq 16(%rsp),%r8\n\t"
1079 "movq 24(%rsp),%r9\n\t"
1080 "movq 0(%rsp),%xmm0\n\t"
1081 "movq 8(%rsp),%xmm1\n\t"
1082 "movq 16(%rsp),%xmm2\n\t"
1083 "movq 24(%rsp),%xmm3\n\t"
1084 "callq *%rax\n\t"
1085 "leaq -16(%rbp),%rsp\n\t" /* restore stack */
1086 "popq %rdi\n\t"
1087 __ASM_CFI(".cfi_same_value %rdi\n\t")
1088 "popq %rsi\n\t"
1089 __ASM_CFI(".cfi_same_value %rsi\n\t")
1090 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
1091 "popq %rbp\n\t"
1092 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
1093 __ASM_CFI(".cfi_same_value %rbp\n\t")
1094 "ret")
1095 #else
1096 #warning call_server_func not implemented for your architecture
1097 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
1099 FIXME("Not implemented for your architecture\n");
1100 return 0;
1102 #endif
1104 static LONG_PTR *stub_do_args(MIDL_STUB_MESSAGE *pStubMsg,
1105 PFORMAT_STRING pFormat, enum stubless_phase phase,
1106 unsigned short number_of_params)
1108 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
1109 unsigned int i;
1110 LONG_PTR *retval_ptr = NULL;
1112 for (i = 0; i < number_of_params; i++)
1114 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
1115 const unsigned char *pTypeFormat = &pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
1117 TRACE("param[%d]: %p -> %p type %02x %s\n", i,
1118 pArg, *(unsigned char **)pArg,
1119 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
1120 debugstr_PROC_PF( params[i].attr ));
1122 switch (phase)
1124 case STUBLESS_MARSHAL:
1125 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1126 call_marshaller(pStubMsg, pArg, &params[i]);
1127 break;
1128 case STUBLESS_FREE:
1129 if (params[i].attr.MustFree)
1131 call_freer(pStubMsg, pArg, &params[i]);
1133 else if (params[i].attr.ServerAllocSize)
1135 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1137 else if (params[i].attr.IsOut &&
1138 !params[i].attr.IsIn &&
1139 !params[i].attr.IsBasetype &&
1140 !params[i].attr.IsByValue)
1142 if (*pTypeFormat != RPC_FC_BIND_CONTEXT) pStubMsg->pfnFree(*(void **)pArg);
1144 break;
1145 case STUBLESS_INITOUT:
1146 if (!params[i].attr.IsIn &&
1147 params[i].attr.IsOut &&
1148 !params[i].attr.IsBasetype &&
1149 !params[i].attr.ServerAllocSize &&
1150 !params[i].attr.IsByValue)
1152 if (*pTypeFormat == RPC_FC_BIND_CONTEXT)
1154 NDR_SCONTEXT ctxt = NdrContextHandleInitialize(pStubMsg, pTypeFormat);
1155 *(void **)pArg = NDRSContextValue(ctxt);
1157 else
1159 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1160 if (size)
1162 *(void **)pArg = NdrAllocate(pStubMsg, size);
1163 memset(*(void **)pArg, 0, size);
1167 break;
1168 case STUBLESS_UNMARSHAL:
1169 if (params[i].attr.ServerAllocSize)
1170 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1171 params[i].attr.ServerAllocSize * 8);
1173 if (params[i].attr.IsIn)
1174 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
1175 break;
1176 case STUBLESS_CALCSIZE:
1177 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1178 call_buffer_sizer(pStubMsg, pArg, &params[i]);
1179 break;
1180 default:
1181 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1183 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1185 /* make a note of the address of the return value parameter for later */
1186 if (params[i].attr.IsReturn) retval_ptr = (LONG_PTR *)pArg;
1188 return retval_ptr;
1191 /***********************************************************************
1192 * NdrStubCall2 [RPCRT4.@]
1194 * Unmarshals [in] parameters, calls either a method in an object or a server
1195 * function, marshals any [out] parameters and frees any allocated data.
1197 * NOTES
1198 * Used by stubless MIDL-generated code.
1200 LONG WINAPI NdrStubCall2(
1201 struct IRpcStubBuffer * pThis,
1202 struct IRpcChannelBuffer * pChannel,
1203 PRPC_MESSAGE pRpcMsg,
1204 DWORD * pdwStubPhase)
1206 const MIDL_SERVER_INFO *pServerInfo;
1207 const MIDL_STUB_DESC *pStubDesc;
1208 PFORMAT_STRING pFormat;
1209 MIDL_STUB_MESSAGE stubMsg;
1210 /* pointer to start of stack to pass into stub implementation */
1211 unsigned char * args;
1212 /* size of stack */
1213 unsigned short stack_size;
1214 /* number of parameters. optional for client to give it to us */
1215 unsigned int number_of_params;
1216 /* cache of Oif_flags from v2 procedure header */
1217 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1218 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1219 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1220 /* the type of pass we are currently doing */
1221 enum stubless_phase phase;
1222 /* header for procedure string */
1223 const NDR_PROC_HEADER *pProcHeader;
1224 /* location to put retval into */
1225 LONG_PTR *retval_ptr = NULL;
1226 /* correlation cache */
1227 ULONG_PTR NdrCorrCache[256];
1229 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1231 if (pThis)
1232 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1233 else
1234 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1236 pStubDesc = pServerInfo->pStubDesc;
1237 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1238 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1240 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
1242 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1244 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1245 stack_size = header_rpc->stack_size;
1246 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1249 else
1251 stack_size = pProcHeader->stack_size;
1252 pFormat += sizeof(NDR_PROC_HEADER);
1255 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1257 /* binding */
1258 switch (pProcHeader->handle_type)
1260 /* explicit binding: parse additional section */
1261 case RPC_FC_BIND_EXPLICIT:
1262 switch (*pFormat) /* handle_type */
1264 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
1265 pFormat += sizeof(NDR_EHD_PRIMITIVE);
1266 break;
1267 case RPC_FC_BIND_GENERIC: /* explicit generic */
1268 pFormat += sizeof(NDR_EHD_GENERIC);
1269 break;
1270 case RPC_FC_BIND_CONTEXT: /* explicit context */
1271 pFormat += sizeof(NDR_EHD_CONTEXT);
1272 break;
1273 default:
1274 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1275 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1277 break;
1278 case RPC_FC_BIND_GENERIC: /* implicit generic */
1279 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
1280 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
1281 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
1282 break;
1283 default:
1284 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1285 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1288 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1289 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1290 else
1291 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1293 /* create the full pointer translation tables, if requested */
1294 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1295 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1297 /* store the RPC flags away */
1298 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1299 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1301 /* use alternate memory allocation routines */
1302 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1303 #if 0
1304 NdrRpcSsEnableAllocate(&stubMsg);
1305 #else
1306 FIXME("Set RPCSS memory allocation routines\n");
1307 #endif
1309 TRACE("allocating memory for stack of size %x\n", stack_size);
1311 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1312 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1314 /* add the implicit This pointer as the first arg to the function if we
1315 * are calling an object method */
1316 if (pThis)
1317 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1319 if (is_oicf_stubdesc(pStubDesc))
1321 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader = (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1323 Oif_flags = pOIFHeader->Oi2Flags;
1324 number_of_params = pOIFHeader->number_of_params;
1326 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1328 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1330 if (Oif_flags.HasExtensions)
1332 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
1333 ext_flags = pExtensions->Flags2;
1334 pFormat += pExtensions->Size;
1337 if (Oif_flags.HasPipes)
1339 FIXME("pipes not supported yet\n");
1340 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1341 /* init pipes package */
1342 /* NdrPipesInitialize(...) */
1344 if (ext_flags.HasNewCorrDesc)
1346 /* initialize extra correlation package */
1347 FIXME("new correlation description not implemented\n");
1348 stubMsg.fHasNewCorrDesc = TRUE;
1351 else
1353 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
1354 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
1355 /* reuse the correlation cache, it's not needed for v1 format */
1356 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
1359 /* convert strings, floating point values and endianness into our
1360 * preferred format */
1361 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1362 NdrConvert(&stubMsg, pFormat);
1364 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_FREE; phase++)
1366 TRACE("phase = %d\n", phase);
1367 switch (phase)
1369 case STUBLESS_CALLSERVER:
1370 /* call the server function */
1371 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1372 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1373 else
1375 SERVER_ROUTINE func;
1376 LONG_PTR retval;
1378 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1380 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1381 func = vtbl[pRpcMsg->ProcNum];
1383 else
1384 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1386 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1387 retval = call_server_func(func, args, stack_size);
1389 if (retval_ptr)
1391 TRACE("stub implementation returned 0x%lx\n", retval);
1392 *retval_ptr = retval;
1394 else
1395 TRACE("void stub implementation\n");
1398 stubMsg.Buffer = NULL;
1399 stubMsg.BufferLength = 0;
1401 break;
1402 case STUBLESS_GETBUFFER:
1403 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1404 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1405 else
1407 RPC_STATUS Status;
1409 pRpcMsg->BufferLength = stubMsg.BufferLength;
1410 /* allocate buffer for [out] and [ret] params */
1411 Status = I_RpcGetBuffer(pRpcMsg);
1412 if (Status)
1413 RpcRaiseException(Status);
1414 stubMsg.Buffer = pRpcMsg->Buffer;
1416 break;
1417 case STUBLESS_UNMARSHAL:
1418 case STUBLESS_INITOUT:
1419 case STUBLESS_CALCSIZE:
1420 case STUBLESS_MARSHAL:
1421 case STUBLESS_FREE:
1422 retval_ptr = stub_do_args(&stubMsg, pFormat, phase, number_of_params);
1423 break;
1424 default:
1425 ERR("shouldn't reach here. phase %d\n", phase);
1426 break;
1430 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1432 if (ext_flags.HasNewCorrDesc)
1434 /* free extra correlation package */
1435 /* NdrCorrelationFree(&stubMsg); */
1438 if (Oif_flags.HasPipes)
1440 /* NdrPipesDone(...) */
1443 /* free the full pointer translation tables */
1444 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1445 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1447 /* free server function stack */
1448 HeapFree(GetProcessHeap(), 0, args);
1450 return S_OK;
1453 /***********************************************************************
1454 * NdrServerCall2 [RPCRT4.@]
1456 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1458 DWORD dwPhase;
1459 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
1462 /***********************************************************************
1463 * NdrStubCall [RPCRT4.@]
1465 LONG WINAPI NdrStubCall( struct IRpcStubBuffer *This, struct IRpcChannelBuffer *channel,
1466 PRPC_MESSAGE msg, DWORD *phase )
1468 return NdrStubCall2( This, channel, msg, phase );
1471 /***********************************************************************
1472 * NdrServerCall [RPCRT4.@]
1474 void WINAPI NdrServerCall( PRPC_MESSAGE msg )
1476 DWORD phase;
1477 NdrStubCall( NULL, NULL, msg, &phase );
1480 struct async_call_data
1482 MIDL_STUB_MESSAGE *pStubMsg;
1483 const NDR_PROC_HEADER *pProcHeader;
1484 PFORMAT_STRING pHandleFormat;
1485 PFORMAT_STRING pParamFormat;
1486 RPC_BINDING_HANDLE hBinding;
1487 /* size of stack */
1488 unsigned short stack_size;
1489 /* number of parameters. optional for client to give it to us */
1490 unsigned int number_of_params;
1491 /* correlation cache */
1492 ULONG_PTR NdrCorrCache[256];
1495 LONG_PTR CDECL ndr_async_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, void **stack_top )
1497 /* pointer to start of stack where arguments start */
1498 PRPC_MESSAGE pRpcMsg;
1499 PMIDL_STUB_MESSAGE pStubMsg;
1500 RPC_ASYNC_STATE *pAsync;
1501 struct async_call_data *async_call_data;
1502 /* procedure number */
1503 unsigned short procedure_number;
1504 /* cache of Oif_flags from v2 procedure header */
1505 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1506 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1507 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1508 /* header for procedure string */
1509 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1510 RPC_STATUS status;
1512 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
1514 /* Later NDR language versions probably won't be backwards compatible */
1515 if (pStubDesc->Version > 0x50002)
1517 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
1518 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1521 async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
1522 if (!async_call_data) RpcRaiseException(RPC_X_NO_MEMORY);
1523 async_call_data->pProcHeader = pProcHeader;
1525 async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
1526 pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
1528 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1530 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1531 async_call_data->stack_size = header_rpc->stack_size;
1532 procedure_number = header_rpc->proc_num;
1533 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1535 else
1537 async_call_data->stack_size = pProcHeader->stack_size;
1538 procedure_number = pProcHeader->proc_num;
1539 pFormat += sizeof(NDR_PROC_HEADER);
1541 TRACE("stack size: 0x%x\n", async_call_data->stack_size);
1542 TRACE("proc num: %d\n", procedure_number);
1544 /* create the full pointer translation tables, if requested */
1545 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1546 pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
1548 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1550 ERR("objects not supported\n");
1551 I_RpcFree(async_call_data);
1552 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1555 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
1557 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1558 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
1560 /* needed for conformance of top-level objects */
1561 pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
1562 memcpy(pStubMsg->StackTop, stack_top, async_call_data->stack_size);
1564 pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
1565 pAsync->StubInfo = async_call_data;
1566 async_call_data->pHandleFormat = pFormat;
1568 pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
1569 if (!pFormat) goto done;
1571 if (is_oicf_stubdesc(pStubDesc))
1573 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1574 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1576 Oif_flags = pOIFHeader->Oi2Flags;
1577 async_call_data->number_of_params = pOIFHeader->number_of_params;
1579 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1581 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1583 if (Oif_flags.HasExtensions)
1585 const NDR_PROC_HEADER_EXTS *pExtensions =
1586 (const NDR_PROC_HEADER_EXTS *)pFormat;
1587 ext_flags = pExtensions->Flags2;
1588 pFormat += pExtensions->Size;
1591 else
1593 pFormat = convert_old_args( pStubMsg, pFormat, async_call_data->stack_size,
1594 pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT,
1595 async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache),
1596 &async_call_data->number_of_params );
1599 async_call_data->pParamFormat = pFormat;
1601 pStubMsg->BufferLength = 0;
1603 /* store the RPC flags away */
1604 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1605 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1607 /* use alternate memory allocation routines */
1608 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1609 NdrRpcSmSetClientToOsf(pStubMsg);
1611 if (Oif_flags.HasPipes)
1613 FIXME("pipes not supported yet\n");
1614 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1615 /* init pipes package */
1616 /* NdrPipesInitialize(...) */
1618 if (ext_flags.HasNewCorrDesc)
1620 /* initialize extra correlation package */
1621 NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
1624 /* order of phases:
1625 * 1. CALCSIZE - calculate the buffer size
1626 * 2. GETBUFFER - allocate the buffer
1627 * 3. MARSHAL - marshal [in] params into the buffer
1628 * 4. SENDRECEIVE - send buffer
1629 * Then in NdrpCompleteAsyncClientCall:
1630 * 1. SENDRECEIVE - receive buffer
1631 * 2. UNMARSHAL - unmarshal [out] params from buffer
1634 /* 1. CALCSIZE */
1635 TRACE( "CALCSIZE\n" );
1636 client_do_args(pStubMsg, pFormat, STUBLESS_CALCSIZE, NULL, async_call_data->number_of_params, NULL);
1638 /* 2. GETBUFFER */
1639 TRACE( "GETBUFFER\n" );
1640 if (Oif_flags.HasPipes)
1641 /* NdrGetPipeBuffer(...) */
1642 FIXME("pipes not supported yet\n");
1643 else
1645 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1646 #if 0
1647 NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1648 #else
1649 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1650 #endif
1651 else
1652 NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1654 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1655 status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
1656 if (status != RPC_S_OK)
1657 RpcRaiseException(status);
1659 /* 3. MARSHAL */
1660 TRACE( "MARSHAL\n" );
1661 client_do_args(pStubMsg, pFormat, STUBLESS_MARSHAL, NULL, async_call_data->number_of_params, NULL);
1663 /* 4. SENDRECEIVE */
1664 TRACE( "SEND\n" );
1665 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1666 /* send the [in] params only */
1667 if (Oif_flags.HasPipes)
1668 /* NdrPipesSend(...) */
1669 FIXME("pipes not supported yet\n");
1670 else
1672 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1673 #if 0
1674 NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1675 #else
1676 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1677 #endif
1678 else
1680 pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
1681 status = I_RpcSend(pStubMsg->RpcMsg);
1682 if (status != RPC_S_OK)
1683 RpcRaiseException(status);
1687 done:
1688 TRACE("returning 0\n");
1689 return 0;
1692 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
1694 /* pointer to start of stack where arguments start */
1695 PMIDL_STUB_MESSAGE pStubMsg;
1696 struct async_call_data *async_call_data;
1697 /* header for procedure string */
1698 const NDR_PROC_HEADER * pProcHeader;
1699 RPC_STATUS status = RPC_S_OK;
1701 if (!pAsync->StubInfo)
1702 return RPC_S_INVALID_ASYNC_HANDLE;
1704 async_call_data = pAsync->StubInfo;
1705 pStubMsg = async_call_data->pStubMsg;
1706 pProcHeader = async_call_data->pProcHeader;
1708 /* order of phases:
1709 * 1. CALCSIZE - calculate the buffer size
1710 * 2. GETBUFFER - allocate the buffer
1711 * 3. MARSHAL - marshal [in] params into the buffer
1712 * 4. SENDRECEIVE - send buffer
1713 * Then in NdrpCompleteAsyncClientCall:
1714 * 1. SENDRECEIVE - receive buffer
1715 * 2. UNMARSHAL - unmarshal [out] params from buffer
1718 /* 1. SENDRECEIVE */
1719 TRACE( "RECEIVE\n" );
1720 pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1721 /* receive the [out] params */
1722 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
1723 #if 0
1724 NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1725 #else
1726 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1727 #endif
1728 else
1730 status = I_RpcReceive(pStubMsg->RpcMsg);
1731 if (status != RPC_S_OK)
1732 goto cleanup;
1733 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
1734 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
1735 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
1736 pStubMsg->Buffer = pStubMsg->BufferStart;
1739 /* convert strings, floating point values and endianness into our
1740 * preferred format */
1741 #if 0
1742 if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1743 NdrConvert(pStubMsg, pFormat);
1744 #endif
1746 /* 2. UNMARSHAL */
1747 TRACE( "UNMARSHAL\n" );
1748 client_do_args(pStubMsg, async_call_data->pParamFormat, STUBLESS_UNMARSHAL,
1749 NULL, async_call_data->number_of_params, Reply);
1751 cleanup:
1752 if (pStubMsg->fHasNewCorrDesc)
1754 /* free extra correlation package */
1755 NdrCorrelationFree(pStubMsg);
1758 /* free the full pointer translation tables */
1759 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1760 NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
1762 /* free marshalling buffer */
1763 NdrFreeBuffer(pStubMsg);
1764 client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
1766 I_RpcFree(pStubMsg->StackTop);
1767 I_RpcFree(async_call_data);
1769 TRACE("-- 0x%x\n", status);
1770 return status;
1773 #ifdef __x86_64__
1775 __ASM_GLOBAL_FUNC( NdrAsyncClientCall,
1776 "movq %r8,0x18(%rsp)\n\t"
1777 "movq %r9,0x20(%rsp)\n\t"
1778 "leaq 0x18(%rsp),%r8\n\t"
1779 "subq $0x28,%rsp\n\t"
1780 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
1781 "call " __ASM_NAME("ndr_async_client_call") "\n\t"
1782 "addq $0x28,%rsp\n\t"
1783 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
1784 "ret" );
1786 #else /* __x86_64__ */
1788 /***********************************************************************
1789 * NdrAsyncClientCall [RPCRT4.@]
1791 CLIENT_CALL_RETURN WINAPIV NdrAsyncClientCall( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1793 __ms_va_list args;
1794 LONG_PTR ret;
1796 __ms_va_start( args, format );
1797 ret = ndr_async_client_call( desc, format, va_arg( args, void ** ));
1798 __ms_va_end( args );
1799 return *(CLIENT_CALL_RETURN *)&ret;
1802 #endif /* __x86_64__ */
1804 RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
1805 struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
1806 DWORD * pdwStubPhase)
1808 FIXME("unimplemented, expect crash!\n");
1809 return 0;