wsdapi/tests: Add tests for AppSequence in Probe message.
[wine.git] / dlls / rpcrt4 / ndr_stubless.c
bloba645a245d071d4fead0052a324d36b5ad8fdd828
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"
44 #include "cpsf.h"
45 #include "ndr_misc.h"
46 #include "ndr_stubless.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
50 #define NDR_TABLE_MASK 127
52 static inline BOOL is_oicf_stubdesc(const PMIDL_STUB_DESC pStubDesc)
54 return pStubDesc->Version >= 0x20000;
57 static inline void call_buffer_sizer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
58 const NDR_PARAM_OIF *param)
60 PFORMAT_STRING pFormat;
61 NDR_BUFFERSIZE m;
63 if (param->attr.IsBasetype)
65 pFormat = &param->u.type_format_char;
66 if (param->attr.IsSimpleRef) pMemory = *(unsigned char **)pMemory;
68 else
70 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
71 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
74 m = NdrBufferSizer[pFormat[0] & NDR_TABLE_MASK];
75 if (m) m(pStubMsg, pMemory, pFormat);
76 else
78 FIXME("format type 0x%x not implemented\n", pFormat[0]);
79 RpcRaiseException(RPC_X_BAD_STUB_DATA);
83 static inline unsigned char *call_marshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
84 const NDR_PARAM_OIF *param)
86 PFORMAT_STRING pFormat;
87 NDR_MARSHALL m;
89 if (param->attr.IsBasetype)
91 pFormat = &param->u.type_format_char;
92 if (param->attr.IsSimpleRef) pMemory = *(unsigned char **)pMemory;
94 else
96 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
97 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
100 m = NdrMarshaller[pFormat[0] & NDR_TABLE_MASK];
101 if (m) return m(pStubMsg, pMemory, pFormat);
102 else
104 FIXME("format type 0x%x not implemented\n", pFormat[0]);
105 RpcRaiseException(RPC_X_BAD_STUB_DATA);
106 return NULL;
110 static inline unsigned char *call_unmarshaller(PMIDL_STUB_MESSAGE pStubMsg, unsigned char **ppMemory,
111 const NDR_PARAM_OIF *param, unsigned char fMustAlloc)
113 PFORMAT_STRING pFormat;
114 NDR_UNMARSHALL m;
116 if (param->attr.IsBasetype)
118 pFormat = &param->u.type_format_char;
119 if (param->attr.IsSimpleRef) ppMemory = (unsigned char **)*ppMemory;
121 else
123 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
124 if (!param->attr.IsByValue) ppMemory = (unsigned char **)*ppMemory;
127 m = NdrUnmarshaller[pFormat[0] & NDR_TABLE_MASK];
128 if (m) return m(pStubMsg, ppMemory, pFormat, fMustAlloc);
129 else
131 FIXME("format type 0x%x not implemented\n", pFormat[0]);
132 RpcRaiseException(RPC_X_BAD_STUB_DATA);
133 return NULL;
137 static inline void call_freer(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory,
138 const NDR_PARAM_OIF *param)
140 PFORMAT_STRING pFormat;
141 NDR_FREE m;
143 if (param->attr.IsBasetype) return; /* nothing to do */
144 pFormat = &pStubMsg->StubDesc->pFormatTypes[param->u.type_offset];
145 if (!param->attr.IsByValue) pMemory = *(unsigned char **)pMemory;
147 m = NdrFreer[pFormat[0] & NDR_TABLE_MASK];
148 if (m) m(pStubMsg, pMemory, pFormat);
151 static DWORD calc_arg_size(MIDL_STUB_MESSAGE *pStubMsg, PFORMAT_STRING pFormat)
153 DWORD size;
154 switch(*pFormat)
156 case FC_RP:
157 if (pFormat[1] & FC_SIMPLE_POINTER)
159 FIXME("Simple reference pointer (type %#x).\n", pFormat[2]);
160 size = sizeof(void *);
161 break;
163 size = calc_arg_size(pStubMsg, &pFormat[2] + *(const SHORT*)&pFormat[2]);
164 break;
165 case FC_STRUCT:
166 case FC_PSTRUCT:
167 size = *(const WORD*)(pFormat + 2);
168 break;
169 case FC_BOGUS_STRUCT:
170 size = *(const WORD*)(pFormat + 2);
171 if(*(const WORD*)(pFormat + 4))
172 FIXME("Unhandled conformant description\n");
173 break;
174 case FC_CARRAY:
175 case FC_CVARRAY:
176 size = *(const WORD*)(pFormat + 2);
177 ComputeConformance(pStubMsg, NULL, pFormat + 4, 0);
178 size *= pStubMsg->MaxCount;
179 break;
180 case FC_SMFARRAY:
181 case FC_SMVARRAY:
182 size = *(const WORD*)(pFormat + 2);
183 break;
184 case FC_LGFARRAY:
185 case FC_LGVARRAY:
186 size = *(const DWORD*)(pFormat + 2);
187 break;
188 case FC_BOGUS_ARRAY:
189 pFormat = ComputeConformance(pStubMsg, NULL, pFormat + 4, *(const WORD*)&pFormat[2]);
190 TRACE("conformance = %ld\n", pStubMsg->MaxCount);
191 pFormat = ComputeVariance(pStubMsg, NULL, pFormat, pStubMsg->MaxCount);
192 size = ComplexStructSize(pStubMsg, pFormat);
193 size *= pStubMsg->MaxCount;
194 break;
195 case FC_USER_MARSHAL:
196 size = *(const WORD*)(pFormat + 4);
197 break;
198 case FC_CSTRING:
199 size = *(const WORD*)(pFormat + 2);
200 break;
201 case FC_WSTRING:
202 size = *(const WORD*)(pFormat + 2) * sizeof(WCHAR);
203 break;
204 case FC_C_CSTRING:
205 case FC_C_WSTRING:
206 if (*pFormat == FC_C_CSTRING)
207 size = sizeof(CHAR);
208 else
209 size = sizeof(WCHAR);
210 if (pFormat[1] == FC_STRING_SIZED)
211 ComputeConformance(pStubMsg, NULL, pFormat + 2, 0);
212 else
213 pStubMsg->MaxCount = 0;
214 size *= pStubMsg->MaxCount;
215 break;
216 default:
217 FIXME("Unhandled type %02x\n", *pFormat);
218 /* fallthrough */
219 case FC_IP:
220 size = sizeof(void *);
221 break;
223 return size;
226 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
228 #if 0 /* these functions are not defined yet */
229 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
230 pMessage->pfnFree = NdrRpcSmClientFree;
231 #endif
234 static const char *debugstr_PROC_PF(PARAM_ATTRIBUTES param_attributes)
236 char buffer[160];
238 buffer[0] = 0;
239 if (param_attributes.MustSize) strcat(buffer, " MustSize");
240 if (param_attributes.MustFree) strcat(buffer, " MustFree");
241 if (param_attributes.IsPipe) strcat(buffer, " IsPipe");
242 if (param_attributes.IsIn) strcat(buffer, " IsIn");
243 if (param_attributes.IsOut) strcat(buffer, " IsOut");
244 if (param_attributes.IsReturn) strcat(buffer, " IsReturn");
245 if (param_attributes.IsBasetype) strcat(buffer, " IsBasetype");
246 if (param_attributes.IsByValue) strcat(buffer, " IsByValue");
247 if (param_attributes.IsSimpleRef) strcat(buffer, " IsSimpleRef");
248 if (param_attributes.IsDontCallFreeInst) strcat(buffer, " IsDontCallFreeInst");
249 if (param_attributes.SaveForAsyncFinish) strcat(buffer, " SaveForAsyncFinish");
250 if (param_attributes.ServerAllocSize)
251 sprintf( buffer + strlen(buffer), " ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
252 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
255 static const char *debugstr_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
257 char buffer[160];
259 buffer[0] = 0;
260 if (Oi2Flags.ServerMustSize) strcat(buffer, " ServerMustSize");
261 if (Oi2Flags.ClientMustSize) strcat(buffer, " ClientMustSize");
262 if (Oi2Flags.HasReturn) strcat(buffer, " HasReturn");
263 if (Oi2Flags.HasPipes) strcat(buffer, " HasPipes");
264 if (Oi2Flags.Unused) strcat(buffer, " Unused");
265 if (Oi2Flags.HasAsyncUuid) strcat(buffer, " HasAsyncUuid");
266 if (Oi2Flags.HasExtensions) strcat(buffer, " HasExtensions");
267 if (Oi2Flags.HasAsyncHandle) strcat(buffer, " HasAsyncHandle");
268 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
271 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
273 static PFORMAT_STRING client_get_handle(
274 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
275 PFORMAT_STRING pFormat, handle_t *phBinding)
277 /* binding */
278 switch (pProcHeader->handle_type)
280 /* explicit binding: parse additional section */
281 case 0:
282 switch (*pFormat) /* handle_type */
284 case FC_BIND_PRIMITIVE: /* explicit primitive */
286 const NDR_EHD_PRIMITIVE *pDesc = (const NDR_EHD_PRIMITIVE *)pFormat;
288 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
290 if (pDesc->flag) /* pointer to binding */
291 *phBinding = **(handle_t **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
292 else
293 *phBinding = *(handle_t *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
294 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
296 case FC_BIND_GENERIC: /* explicit generic */
298 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
299 void *pObject = NULL;
300 void *pArg;
301 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
303 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
305 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
306 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
307 else
308 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
309 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
310 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
311 *phBinding = pGenPair->pfnBind(pObject);
312 return pFormat + sizeof(NDR_EHD_GENERIC);
314 case FC_BIND_CONTEXT: /* explicit context */
316 const NDR_EHD_CONTEXT *pDesc = (const NDR_EHD_CONTEXT *)pFormat;
317 NDR_CCONTEXT context_handle;
318 TRACE("Explicit bind context\n");
319 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
321 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
322 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
324 else
325 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
327 if (context_handle) *phBinding = NDRCContextBinding(context_handle);
328 else if (pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL)
330 ERR("null context handle isn't allowed\n");
331 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
332 return NULL;
334 /* FIXME: should we store this structure in stubMsg.pContext? */
335 return pFormat + sizeof(NDR_EHD_CONTEXT);
337 default:
338 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
339 RpcRaiseException(RPC_X_BAD_STUB_DATA);
341 break;
342 case FC_BIND_GENERIC: /* implicit generic */
343 FIXME("FC_BIND_GENERIC\n");
344 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
345 break;
346 case FC_BIND_PRIMITIVE: /* implicit primitive */
347 TRACE("Implicit primitive handle\n");
348 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
349 break;
350 case FC_CALLBACK_HANDLE: /* implicit callback */
351 TRACE("FC_CALLBACK_HANDLE\n");
352 /* server calls callback procedures only in response to remote call, and most recent
353 binding handle is used. Calling back to a client can potentially result in another
354 callback with different current handle. */
355 *phBinding = I_RpcGetCurrentCallHandle();
356 break;
357 case FC_AUTO_HANDLE: /* implicit auto handle */
358 /* strictly speaking, it isn't necessary to set hBinding here
359 * since it isn't actually used (hence the automatic in its name),
360 * but then why does MIDL generate a valid entry in the
361 * MIDL_STUB_DESC for it? */
362 TRACE("Implicit auto handle\n");
363 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
364 break;
365 default:
366 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
367 RpcRaiseException(RPC_X_BAD_STUB_DATA);
369 return pFormat;
372 static void client_free_handle(
373 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
374 PFORMAT_STRING pFormat, handle_t hBinding)
376 /* binding */
377 switch (pProcHeader->handle_type)
379 /* explicit binding: parse additional section */
380 case 0:
381 switch (*pFormat) /* handle_type */
383 case FC_BIND_GENERIC: /* explicit generic */
385 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
386 void *pObject = NULL;
387 void *pArg;
388 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
390 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
392 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
393 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
394 else
395 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
396 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
397 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
398 pGenPair->pfnUnbind(pObject, hBinding);
399 break;
401 case FC_BIND_CONTEXT: /* explicit context */
402 case FC_BIND_PRIMITIVE: /* explicit primitive */
403 break;
404 default:
405 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
406 RpcRaiseException(RPC_X_BAD_STUB_DATA);
408 break;
409 case FC_BIND_GENERIC: /* implicit generic */
410 FIXME("FC_BIND_GENERIC\n");
411 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
412 break;
413 case FC_CALLBACK_HANDLE: /* implicit callback */
414 case FC_BIND_PRIMITIVE: /* implicit primitive */
415 case FC_AUTO_HANDLE: /* implicit auto handle */
416 break;
417 default:
418 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
419 RpcRaiseException(RPC_X_BAD_STUB_DATA);
423 void client_do_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, enum stubless_phase phase,
424 void **fpu_args, unsigned short number_of_params, unsigned char *pRetVal )
426 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
427 unsigned int i;
429 for (i = 0; i < number_of_params; i++)
431 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
432 PFORMAT_STRING pTypeFormat = (PFORMAT_STRING)&pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
434 #ifdef __x86_64__ /* floats are passed as doubles through varargs functions */
435 float f;
437 if (params[i].attr.IsBasetype &&
438 params[i].u.type_format_char == FC_FLOAT &&
439 !params[i].attr.IsSimpleRef &&
440 !fpu_args)
442 f = *(double *)pArg;
443 pArg = (unsigned char *)&f;
445 #endif
447 TRACE("param[%d]: %p type %02x %s\n", i, pArg,
448 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
449 debugstr_PROC_PF( params[i].attr ));
451 switch (phase)
453 case STUBLESS_INITOUT:
454 if (!params[i].attr.IsBasetype && params[i].attr.IsOut &&
455 !params[i].attr.IsIn && !params[i].attr.IsByValue)
457 memset( *(unsigned char **)pArg, 0, calc_arg_size( pStubMsg, pTypeFormat ));
459 break;
460 case STUBLESS_CALCSIZE:
461 if (params[i].attr.IsSimpleRef && !*(unsigned char **)pArg)
462 RpcRaiseException(RPC_X_NULL_REF_POINTER);
463 if (params[i].attr.IsIn) call_buffer_sizer(pStubMsg, pArg, &params[i]);
464 break;
465 case STUBLESS_MARSHAL:
466 if (params[i].attr.IsIn) call_marshaller(pStubMsg, pArg, &params[i]);
467 break;
468 case STUBLESS_UNMARSHAL:
469 if (params[i].attr.IsOut)
471 if (params[i].attr.IsReturn && pRetVal) pArg = pRetVal;
472 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
474 break;
475 case STUBLESS_FREE:
476 if (!params[i].attr.IsBasetype && params[i].attr.IsOut && !params[i].attr.IsByValue)
477 NdrClearOutParameters( pStubMsg, pTypeFormat, *(unsigned char **)pArg );
478 break;
479 default:
480 RpcRaiseException(RPC_S_INTERNAL_ERROR);
485 static unsigned int type_stack_size(unsigned char fc)
487 switch (fc)
489 case FC_BYTE:
490 case FC_CHAR:
491 case FC_SMALL:
492 case FC_USMALL:
493 case FC_WCHAR:
494 case FC_SHORT:
495 case FC_USHORT:
496 case FC_LONG:
497 case FC_ULONG:
498 case FC_INT3264:
499 case FC_UINT3264:
500 case FC_ENUM16:
501 case FC_ENUM32:
502 case FC_FLOAT:
503 case FC_ERROR_STATUS_T:
504 case FC_IGNORE:
505 return sizeof(void *);
506 case FC_DOUBLE:
507 return sizeof(double);
508 case FC_HYPER:
509 return sizeof(ULONGLONG);
510 default:
511 ERR("invalid base type 0x%x\n", fc);
512 RpcRaiseException(RPC_S_INTERNAL_ERROR);
516 static BOOL is_by_value( PFORMAT_STRING format )
518 switch (*format)
520 case FC_USER_MARSHAL:
521 case FC_STRUCT:
522 case FC_PSTRUCT:
523 case FC_CSTRUCT:
524 case FC_CPSTRUCT:
525 case FC_CVSTRUCT:
526 case FC_BOGUS_STRUCT:
527 return TRUE;
528 default:
529 return FALSE;
533 PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
534 unsigned int stack_size, BOOL object_proc,
535 void *buffer, unsigned int size, unsigned int *count )
537 NDR_PARAM_OIF *args = buffer;
538 unsigned int i, stack_offset = object_proc ? sizeof(void *) : 0;
540 for (i = 0; stack_offset < stack_size; i++)
542 const NDR_PARAM_OI_BASETYPE *param = (const NDR_PARAM_OI_BASETYPE *)pFormat;
543 const NDR_PARAM_OI_OTHER *other = (const NDR_PARAM_OI_OTHER *)pFormat;
545 if (i + 1 > size / sizeof(*args))
547 FIXME( "%u args not supported\n", i );
548 RpcRaiseException( RPC_S_INTERNAL_ERROR );
551 args[i].stack_offset = stack_offset;
552 memset( &args[i].attr, 0, sizeof(args[i].attr) );
554 switch (param->param_direction)
556 case FC_IN_PARAM_BASETYPE:
557 args[i].attr.IsIn = 1;
558 args[i].attr.IsBasetype = 1;
559 break;
560 case FC_RETURN_PARAM_BASETYPE:
561 args[i].attr.IsOut = 1;
562 args[i].attr.IsReturn = 1;
563 args[i].attr.IsBasetype = 1;
564 break;
565 case FC_IN_PARAM:
566 args[i].attr.IsIn = 1;
567 args[i].attr.MustFree = 1;
568 break;
569 case FC_IN_PARAM_NO_FREE_INST:
570 args[i].attr.IsIn = 1;
571 args[i].attr.IsDontCallFreeInst = 1;
572 break;
573 case FC_IN_OUT_PARAM:
574 args[i].attr.IsIn = 1;
575 args[i].attr.IsOut = 1;
576 args[i].attr.MustFree = 1;
577 break;
578 case FC_OUT_PARAM:
579 args[i].attr.IsOut = 1;
580 break;
581 case FC_RETURN_PARAM:
582 args[i].attr.IsOut = 1;
583 args[i].attr.IsReturn = 1;
584 break;
586 if (args[i].attr.IsBasetype)
588 args[i].u.type_format_char = param->type_format_char;
589 stack_offset += type_stack_size( param->type_format_char );
590 pFormat += sizeof(NDR_PARAM_OI_BASETYPE);
592 else
594 args[i].u.type_offset = other->type_offset;
595 args[i].attr.IsByValue = is_by_value( &pStubMsg->StubDesc->pFormatTypes[other->type_offset] );
596 stack_offset += other->stack_size * sizeof(void *);
597 pFormat += sizeof(NDR_PARAM_OI_OTHER);
600 *count = i;
601 return (PFORMAT_STRING)args;
604 LONG_PTR CDECL DECLSPEC_HIDDEN ndr_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
605 void **stack_top, void **fpu_stack )
607 /* pointer to start of stack where arguments start */
608 RPC_MESSAGE rpcMsg;
609 MIDL_STUB_MESSAGE stubMsg;
610 handle_t hBinding = NULL;
611 /* procedure number */
612 unsigned short procedure_number;
613 /* size of stack */
614 unsigned short stack_size;
615 /* number of parameters. optional for client to give it to us */
616 unsigned int number_of_params;
617 /* cache of Oif_flags from v2 procedure header */
618 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
619 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
620 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
621 /* header for procedure string */
622 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
623 /* the value to return to the client from the remote procedure */
624 LONG_PTR RetVal = 0;
625 /* the pointer to the object when in OLE mode */
626 void * This = NULL;
627 PFORMAT_STRING pHandleFormat;
628 /* correlation cache */
629 ULONG_PTR NdrCorrCache[256];
631 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
633 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
635 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
637 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
638 stack_size = header_rpc->stack_size;
639 procedure_number = header_rpc->proc_num;
640 pFormat += sizeof(NDR_PROC_HEADER_RPC);
642 else
644 stack_size = pProcHeader->stack_size;
645 procedure_number = pProcHeader->proc_num;
646 pFormat += sizeof(NDR_PROC_HEADER);
648 TRACE("stack size: 0x%x\n", stack_size);
649 TRACE("proc num: %d\n", procedure_number);
651 /* create the full pointer translation tables, if requested */
652 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
653 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
655 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
657 /* object is always the first argument */
658 This = stack_top[0];
659 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
661 else
662 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
664 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
665 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
667 stubMsg.StackTop = (unsigned char *)stack_top;
668 pHandleFormat = pFormat;
670 /* we only need a handle if this isn't an object method */
671 if (!(pProcHeader->Oi_flags & Oi_OBJECT_PROC))
673 pFormat = client_get_handle(&stubMsg, pProcHeader, pHandleFormat, &hBinding);
674 if (!pFormat) goto done;
677 if (is_oicf_stubdesc(pStubDesc)) /* -Oicf format */
679 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
680 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
682 Oif_flags = pOIFHeader->Oi2Flags;
683 number_of_params = pOIFHeader->number_of_params;
685 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
687 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
689 if (Oif_flags.HasExtensions)
691 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
692 ext_flags = pExtensions->Flags2;
693 pFormat += pExtensions->Size;
694 #ifdef __x86_64__
695 if (pExtensions->Size > sizeof(*pExtensions) && fpu_stack)
697 int i;
698 unsigned short fpu_mask = *(unsigned short *)(pExtensions + 1);
699 for (i = 0; i < 4; i++, fpu_mask >>= 2)
700 switch (fpu_mask & 3)
702 case 1: *(float *)&stack_top[i] = *(float *)&fpu_stack[i]; break;
703 case 2: *(double *)&stack_top[i] = *(double *)&fpu_stack[i]; break;
706 #endif
709 else
711 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
712 pProcHeader->Oi_flags & Oi_OBJECT_PROC,
713 /* reuse the correlation cache, it's not needed for v1 format */
714 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
717 stubMsg.BufferLength = 0;
719 /* store the RPC flags away */
720 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
721 rpcMsg.RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
723 /* use alternate memory allocation routines */
724 if (pProcHeader->Oi_flags & Oi_RPCSS_ALLOC_USED)
725 NdrRpcSmSetClientToOsf(&stubMsg);
727 if (Oif_flags.HasPipes)
729 FIXME("pipes not supported yet\n");
730 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
731 /* init pipes package */
732 /* NdrPipesInitialize(...) */
734 if (ext_flags.HasNewCorrDesc)
736 /* initialize extra correlation package */
737 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
738 if (ext_flags.Unused & 0x2) /* has range on conformance */
739 stubMsg.CorrDespIncrement = 12;
742 /* order of phases:
743 * 1. INITOUT - zero [out] parameters (proxies only)
744 * 2. CALCSIZE - calculate the buffer size
745 * 3. GETBUFFER - allocate the buffer
746 * 4. MARSHAL - marshal [in] params into the buffer
747 * 5. SENDRECEIVE - send/receive buffer
748 * 6. UNMARSHAL - unmarshal [out] params from buffer
749 * 7. FREE - clear [out] parameters (for proxies, and only on error)
751 if ((pProcHeader->Oi_flags & Oi_OBJECT_PROC) ||
752 (pProcHeader->Oi_flags & Oi_HAS_COMM_OR_FAULT))
754 /* 1. INITOUT */
755 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
757 TRACE( "INITOUT\n" );
758 client_do_args(&stubMsg, pFormat, STUBLESS_INITOUT, fpu_stack,
759 number_of_params, (unsigned char *)&RetVal);
762 __TRY
764 /* 2. CALCSIZE */
765 TRACE( "CALCSIZE\n" );
766 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
767 number_of_params, (unsigned char *)&RetVal);
769 /* 3. GETBUFFER */
770 TRACE( "GETBUFFER\n" );
771 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
773 /* allocate the buffer */
774 NdrProxyGetBuffer(This, &stubMsg);
776 else
778 /* allocate the buffer */
779 if (Oif_flags.HasPipes)
780 /* NdrGetPipeBuffer(...) */
781 FIXME("pipes not supported yet\n");
782 else
784 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
785 #if 0
786 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
787 #else
788 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
789 #endif
790 else
791 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
795 /* 4. MARSHAL */
796 TRACE( "MARSHAL\n" );
797 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
798 number_of_params, (unsigned char *)&RetVal);
800 /* 5. SENDRECEIVE */
801 TRACE( "SENDRECEIVE\n" );
802 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
804 /* send the [in] params and receive the [out] and [retval]
805 * params */
806 NdrProxySendReceive(This, &stubMsg);
808 else
810 /* send the [in] params and receive the [out] and [retval]
811 * params */
812 if (Oif_flags.HasPipes)
813 /* NdrPipesSendReceive(...) */
814 FIXME("pipes not supported yet\n");
815 else
817 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
818 #if 0
819 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
820 #else
821 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
822 #endif
823 else
824 NdrSendReceive(&stubMsg, stubMsg.Buffer);
828 /* convert strings, floating point values and endianness into our
829 * preferred format */
830 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
831 NdrConvert(&stubMsg, pFormat);
833 /* 6. UNMARSHAL */
834 TRACE( "UNMARSHAL\n" );
835 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
836 number_of_params, (unsigned char *)&RetVal);
838 __EXCEPT_ALL
840 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
842 /* 7. FREE */
843 TRACE( "FREE\n" );
844 client_do_args(&stubMsg, pFormat, STUBLESS_FREE, fpu_stack,
845 number_of_params, (unsigned char *)&RetVal);
846 RetVal = NdrProxyErrorHandler(GetExceptionCode());
848 else
850 const COMM_FAULT_OFFSETS *comm_fault_offsets = &pStubDesc->CommFaultOffsets[procedure_number];
851 ULONG *comm_status;
852 ULONG *fault_status;
854 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets->CommOffset, comm_fault_offsets->FaultOffset);
856 if (comm_fault_offsets->CommOffset == -1)
857 comm_status = (ULONG *)&RetVal;
858 else if (comm_fault_offsets->CommOffset >= 0)
859 comm_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
860 else
861 comm_status = NULL;
863 if (comm_fault_offsets->FaultOffset == -1)
864 fault_status = (ULONG *)&RetVal;
865 else if (comm_fault_offsets->FaultOffset >= 0)
866 fault_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->FaultOffset);
867 else
868 fault_status = NULL;
870 NdrMapCommAndFaultStatus(&stubMsg, comm_status, fault_status,
871 GetExceptionCode());
874 __ENDTRY
876 else
878 /* 2. CALCSIZE */
879 TRACE( "CALCSIZE\n" );
880 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
881 number_of_params, (unsigned char *)&RetVal);
883 /* 3. GETBUFFER */
884 TRACE( "GETBUFFER\n" );
885 if (Oif_flags.HasPipes)
886 /* NdrGetPipeBuffer(...) */
887 FIXME("pipes not supported yet\n");
888 else
890 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
891 #if 0
892 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
893 #else
894 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
895 #endif
896 else
897 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
900 /* 4. MARSHAL */
901 TRACE( "MARSHAL\n" );
902 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
903 number_of_params, (unsigned char *)&RetVal);
905 /* 5. SENDRECEIVE */
906 TRACE( "SENDRECEIVE\n" );
907 if (Oif_flags.HasPipes)
908 /* NdrPipesSendReceive(...) */
909 FIXME("pipes not supported yet\n");
910 else
912 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
913 #if 0
914 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
915 #else
916 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
917 #endif
918 else
919 NdrSendReceive(&stubMsg, stubMsg.Buffer);
922 /* convert strings, floating point values and endianness into our
923 * preferred format */
924 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
925 NdrConvert(&stubMsg, pFormat);
927 /* 6. UNMARSHAL */
928 TRACE( "UNMARSHAL\n" );
929 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
930 number_of_params, (unsigned char *)&RetVal);
933 if (ext_flags.HasNewCorrDesc)
935 /* free extra correlation package */
936 NdrCorrelationFree(&stubMsg);
939 if (Oif_flags.HasPipes)
941 /* NdrPipesDone(...) */
944 /* free the full pointer translation tables */
945 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
946 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
948 /* free marshalling buffer */
949 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
950 NdrProxyFreeBuffer(This, &stubMsg);
951 else
953 NdrFreeBuffer(&stubMsg);
954 client_free_handle(&stubMsg, pProcHeader, pHandleFormat, hBinding);
957 done:
958 TRACE("RetVal = 0x%lx\n", RetVal);
959 return RetVal;
962 #ifdef __x86_64__
964 __ASM_GLOBAL_FUNC( NdrClientCall2,
965 "movq %r8,0x18(%rsp)\n\t"
966 "movq %r9,0x20(%rsp)\n\t"
967 "leaq 0x18(%rsp),%r8\n\t"
968 "xorq %r9,%r9\n\t"
969 "subq $0x28,%rsp\n\t"
970 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
971 "call " __ASM_NAME("ndr_client_call") "\n\t"
972 "addq $0x28,%rsp\n\t"
973 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
974 "ret" );
976 #else /* __x86_64__ */
978 /***********************************************************************
979 * NdrClientCall2 [RPCRT4.@]
981 CLIENT_CALL_RETURN WINAPIV NdrClientCall2( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
983 __ms_va_list args;
984 LONG_PTR ret;
986 __ms_va_start( args, format );
987 ret = ndr_client_call( desc, format, va_arg( args, void ** ), NULL );
988 __ms_va_end( args );
989 return *(CLIENT_CALL_RETURN *)&ret;
992 #endif /* __x86_64__ */
994 /* Calls a function with the specified arguments, restoring the stack
995 * properly afterwards as we don't know the calling convention of the
996 * function */
997 #if defined __i386__ && defined _MSC_VER
998 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
1000 __asm
1002 push ebp
1003 mov ebp, esp
1004 push edi ; Save registers
1005 push esi
1006 mov eax, [ebp+16] ; Get stack size
1007 sub esp, eax ; Make room in stack for arguments
1008 and esp, 0xFFFFFFF0
1009 mov edi, esp
1010 mov ecx, eax
1011 mov esi, [ebp+12]
1012 shr ecx, 2
1014 rep movsd ; Copy dword blocks
1015 call [ebp+8] ; Call function
1016 lea esp, [ebp-8] ; Restore stack
1017 pop esi ; Restore registers
1018 pop edi
1019 pop ebp
1023 #elif defined __i386__ && defined __GNUC__
1024 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1025 __ASM_GLOBAL_FUNC(call_server_func,
1026 "pushl %ebp\n\t"
1027 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1028 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1029 "movl %esp,%ebp\n\t"
1030 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1031 "pushl %edi\n\t" /* Save registers */
1032 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
1033 "pushl %esi\n\t"
1034 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
1035 "movl 16(%ebp), %eax\n\t" /* Get stack size */
1036 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
1037 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
1038 "movl %esp, %edi\n\t"
1039 "movl %eax, %ecx\n\t"
1040 "movl 12(%ebp), %esi\n\t"
1041 "shrl $2, %ecx\n\t" /* divide by 4 */
1042 "cld\n\t"
1043 "rep; movsl\n\t" /* Copy dword blocks */
1044 "call *8(%ebp)\n\t" /* Call function */
1045 "leal -8(%ebp), %esp\n\t" /* Restore stack */
1046 "popl %esi\n\t" /* Restore registers */
1047 __ASM_CFI(".cfi_same_value %esi\n\t")
1048 "popl %edi\n\t"
1049 __ASM_CFI(".cfi_same_value %edi\n\t")
1050 "popl %ebp\n\t"
1051 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1052 __ASM_CFI(".cfi_same_value %ebp\n\t")
1053 "ret" )
1054 #elif defined __x86_64__
1055 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1056 __ASM_GLOBAL_FUNC( call_server_func,
1057 "pushq %rbp\n\t"
1058 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
1059 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
1060 "movq %rsp,%rbp\n\t"
1061 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
1062 "pushq %rsi\n\t"
1063 __ASM_CFI(".cfi_rel_offset %rsi,-8\n\t")
1064 "pushq %rdi\n\t"
1065 __ASM_CFI(".cfi_rel_offset %rdi,-16\n\t")
1066 "movq %rcx,%rax\n\t" /* function to call */
1067 "movq $32,%rcx\n\t" /* allocate max(32,stack_size) bytes of stack space */
1068 "cmpq %rcx,%r8\n\t"
1069 "cmovgq %r8,%rcx\n\t"
1070 "subq %rcx,%rsp\n\t"
1071 "andq $~15,%rsp\n\t"
1072 "movq %r8,%rcx\n\t"
1073 "shrq $3,%rcx\n\t"
1074 "movq %rsp,%rdi\n\t"
1075 "movq %rdx,%rsi\n\t"
1076 "rep; movsq\n\t" /* copy arguments */
1077 "movq 0(%rsp),%rcx\n\t"
1078 "movq 8(%rsp),%rdx\n\t"
1079 "movq 16(%rsp),%r8\n\t"
1080 "movq 24(%rsp),%r9\n\t"
1081 "movq 0(%rsp),%xmm0\n\t"
1082 "movq 8(%rsp),%xmm1\n\t"
1083 "movq 16(%rsp),%xmm2\n\t"
1084 "movq 24(%rsp),%xmm3\n\t"
1085 "callq *%rax\n\t"
1086 "leaq -16(%rbp),%rsp\n\t" /* restore stack */
1087 "popq %rdi\n\t"
1088 __ASM_CFI(".cfi_same_value %rdi\n\t")
1089 "popq %rsi\n\t"
1090 __ASM_CFI(".cfi_same_value %rsi\n\t")
1091 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
1092 "popq %rbp\n\t"
1093 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
1094 __ASM_CFI(".cfi_same_value %rbp\n\t")
1095 "ret")
1096 #elif defined __arm__
1097 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char *args, unsigned int stack_size);
1098 __ASM_GLOBAL_FUNC( call_server_func,
1099 ".arm\n\t"
1100 "push {r4, r5, LR}\n\t"
1101 "mov r4, r0\n\t"
1102 "mov r5, SP\n\t"
1103 "lsr r3, r2, #2\n\t"
1104 "cmp r3, #0\n\t"
1105 "beq 5f\n\t"
1106 "sub SP, SP, r2\n\t"
1107 "tst r3, #1\n\t"
1108 "subeq SP, SP, #4\n\t"
1109 "1:\tsub r2, r2, #4\n\t"
1110 "ldr r0, [r1, r2]\n\t"
1111 "str r0, [SP, r2]\n\t"
1112 "cmp r2, #0\n\t"
1113 "bgt 1b\n\t"
1114 "cmp r3, #1\n\t"
1115 "bgt 2f\n\t"
1116 "pop {r0}\n\t"
1117 "b 5f\n\t"
1118 "2:\tcmp r3, #2\n\t"
1119 "bgt 3f\n\t"
1120 "pop {r0-r1}\n\t"
1121 "b 5f\n\t"
1122 "3:\tcmp r3, #3\n\t"
1123 "bgt 4f\n\t"
1124 "pop {r0-r2}\n\t"
1125 "b 5f\n\t"
1126 "4:\tpop {r0-r3}\n\t"
1127 "5:\tblx r4\n\t"
1128 "mov SP, r5\n\t"
1129 "pop {r4, r5, PC}" )
1130 #else
1131 #warning call_server_func not implemented for your architecture
1132 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
1134 FIXME("Not implemented for your architecture\n");
1135 return 0;
1137 #endif
1139 static inline BOOL param_needs_alloc( PARAM_ATTRIBUTES attr )
1141 return attr.IsOut && !attr.IsIn && !attr.IsBasetype && !attr.IsByValue;
1144 static LONG_PTR *stub_do_args(MIDL_STUB_MESSAGE *pStubMsg,
1145 PFORMAT_STRING pFormat, enum stubless_phase phase,
1146 unsigned short number_of_params)
1148 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
1149 unsigned int i;
1150 LONG_PTR *retval_ptr = NULL;
1152 for (i = 0; i < number_of_params; i++)
1154 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
1155 const unsigned char *pTypeFormat = &pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
1157 TRACE("param[%d]: %p -> %p type %02x %s\n", i,
1158 pArg, *(unsigned char **)pArg,
1159 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
1160 debugstr_PROC_PF( params[i].attr ));
1162 switch (phase)
1164 case STUBLESS_MARSHAL:
1165 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1166 call_marshaller(pStubMsg, pArg, &params[i]);
1167 break;
1168 case STUBLESS_MUSTFREE:
1169 if (params[i].attr.MustFree)
1171 call_freer(pStubMsg, pArg, &params[i]);
1173 break;
1174 case STUBLESS_FREE:
1175 if (params[i].attr.ServerAllocSize)
1177 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1179 else if (param_needs_alloc(params[i].attr) &&
1180 (!params[i].attr.MustFree || params[i].attr.IsSimpleRef))
1182 if (*pTypeFormat != FC_BIND_CONTEXT) pStubMsg->pfnFree(*(void **)pArg);
1184 break;
1185 case STUBLESS_INITOUT:
1186 if (param_needs_alloc(params[i].attr) && !params[i].attr.ServerAllocSize)
1188 if (*pTypeFormat == FC_BIND_CONTEXT)
1190 NDR_SCONTEXT ctxt = NdrContextHandleInitialize(pStubMsg, pTypeFormat);
1191 *(void **)pArg = NDRSContextValue(ctxt);
1193 else
1195 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1196 if (size)
1198 *(void **)pArg = NdrAllocate(pStubMsg, size);
1199 memset(*(void **)pArg, 0, size);
1203 break;
1204 case STUBLESS_UNMARSHAL:
1205 if (params[i].attr.ServerAllocSize)
1206 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1207 params[i].attr.ServerAllocSize * 8);
1209 if (params[i].attr.IsIn)
1210 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
1211 break;
1212 case STUBLESS_CALCSIZE:
1213 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1214 call_buffer_sizer(pStubMsg, pArg, &params[i]);
1215 break;
1216 default:
1217 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1219 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1221 /* make a note of the address of the return value parameter for later */
1222 if (params[i].attr.IsReturn) retval_ptr = (LONG_PTR *)pArg;
1224 return retval_ptr;
1227 /***********************************************************************
1228 * NdrStubCall2 [RPCRT4.@]
1230 * Unmarshals [in] parameters, calls either a method in an object or a server
1231 * function, marshals any [out] parameters and frees any allocated data.
1233 * NOTES
1234 * Used by stubless MIDL-generated code.
1236 LONG WINAPI NdrStubCall2(
1237 struct IRpcStubBuffer * pThis,
1238 struct IRpcChannelBuffer * pChannel,
1239 PRPC_MESSAGE pRpcMsg,
1240 DWORD * pdwStubPhase)
1242 const MIDL_SERVER_INFO *pServerInfo;
1243 const MIDL_STUB_DESC *pStubDesc;
1244 PFORMAT_STRING pFormat;
1245 MIDL_STUB_MESSAGE stubMsg;
1246 /* pointer to start of stack to pass into stub implementation */
1247 unsigned char * args;
1248 /* size of stack */
1249 unsigned short stack_size;
1250 /* number of parameters. optional for client to give it to us */
1251 unsigned int number_of_params;
1252 /* cache of Oif_flags from v2 procedure header */
1253 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1254 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1255 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1256 /* the type of pass we are currently doing */
1257 enum stubless_phase phase;
1258 /* header for procedure string */
1259 const NDR_PROC_HEADER *pProcHeader;
1260 /* location to put retval into */
1261 LONG_PTR *retval_ptr = NULL;
1262 /* correlation cache */
1263 ULONG_PTR NdrCorrCache[256];
1265 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1267 if (pThis)
1268 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1269 else
1270 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1272 pStubDesc = pServerInfo->pStubDesc;
1273 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1274 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1276 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
1278 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1280 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1281 stack_size = header_rpc->stack_size;
1282 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1285 else
1287 stack_size = pProcHeader->stack_size;
1288 pFormat += sizeof(NDR_PROC_HEADER);
1291 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1293 /* binding */
1294 switch (pProcHeader->handle_type)
1296 /* explicit binding: parse additional section */
1297 case 0:
1298 switch (*pFormat) /* handle_type */
1300 case FC_BIND_PRIMITIVE: /* explicit primitive */
1301 pFormat += sizeof(NDR_EHD_PRIMITIVE);
1302 break;
1303 case FC_BIND_GENERIC: /* explicit generic */
1304 pFormat += sizeof(NDR_EHD_GENERIC);
1305 break;
1306 case FC_BIND_CONTEXT: /* explicit context */
1307 pFormat += sizeof(NDR_EHD_CONTEXT);
1308 break;
1309 default:
1310 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1311 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1313 break;
1314 case FC_BIND_GENERIC: /* implicit generic */
1315 case FC_BIND_PRIMITIVE: /* implicit primitive */
1316 case FC_CALLBACK_HANDLE: /* implicit callback */
1317 case FC_AUTO_HANDLE: /* implicit auto handle */
1318 break;
1319 default:
1320 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1321 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1324 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1325 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1326 else
1327 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1329 /* create the full pointer translation tables, if requested */
1330 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1331 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1333 /* store the RPC flags away */
1334 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1335 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1337 /* use alternate memory allocation routines */
1338 if (pProcHeader->Oi_flags & Oi_RPCSS_ALLOC_USED)
1339 #if 0
1340 NdrRpcSsEnableAllocate(&stubMsg);
1341 #else
1342 FIXME("Set RPCSS memory allocation routines\n");
1343 #endif
1345 TRACE("allocating memory for stack of size %x\n", stack_size);
1347 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1348 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1350 /* add the implicit This pointer as the first arg to the function if we
1351 * are calling an object method */
1352 if (pThis)
1353 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1355 if (is_oicf_stubdesc(pStubDesc))
1357 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader = (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1359 Oif_flags = pOIFHeader->Oi2Flags;
1360 number_of_params = pOIFHeader->number_of_params;
1362 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1364 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1366 if (Oif_flags.HasExtensions)
1368 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
1369 ext_flags = pExtensions->Flags2;
1370 pFormat += pExtensions->Size;
1373 if (Oif_flags.HasPipes)
1375 FIXME("pipes not supported yet\n");
1376 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1377 /* init pipes package */
1378 /* NdrPipesInitialize(...) */
1380 if (ext_flags.HasNewCorrDesc)
1382 /* initialize extra correlation package */
1383 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
1384 if (ext_flags.Unused & 0x2) /* has range on conformance */
1385 stubMsg.CorrDespIncrement = 12;
1388 else
1390 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
1391 pProcHeader->Oi_flags & Oi_OBJECT_PROC,
1392 /* reuse the correlation cache, it's not needed for v1 format */
1393 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
1396 /* convert strings, floating point values and endianness into our
1397 * preferred format */
1398 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1399 NdrConvert(&stubMsg, pFormat);
1401 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_FREE; phase++)
1403 TRACE("phase = %d\n", phase);
1404 switch (phase)
1406 case STUBLESS_CALLSERVER:
1407 /* call the server function */
1408 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1409 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1410 else
1412 SERVER_ROUTINE func;
1413 LONG_PTR retval;
1415 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1417 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1418 func = vtbl[pRpcMsg->ProcNum];
1420 else
1421 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1423 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1424 retval = call_server_func(func, args, stack_size);
1426 if (retval_ptr)
1428 TRACE("stub implementation returned 0x%lx\n", retval);
1429 *retval_ptr = retval;
1431 else
1432 TRACE("void stub implementation\n");
1435 stubMsg.Buffer = NULL;
1436 stubMsg.BufferLength = 0;
1438 break;
1439 case STUBLESS_GETBUFFER:
1440 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1441 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1442 else
1444 RPC_STATUS Status;
1446 pRpcMsg->BufferLength = stubMsg.BufferLength;
1447 /* allocate buffer for [out] and [ret] params */
1448 Status = I_RpcGetBuffer(pRpcMsg);
1449 if (Status)
1450 RpcRaiseException(Status);
1451 stubMsg.Buffer = pRpcMsg->Buffer;
1453 break;
1454 case STUBLESS_UNMARSHAL:
1455 case STUBLESS_INITOUT:
1456 case STUBLESS_CALCSIZE:
1457 case STUBLESS_MARSHAL:
1458 case STUBLESS_MUSTFREE:
1459 case STUBLESS_FREE:
1460 retval_ptr = stub_do_args(&stubMsg, pFormat, phase, number_of_params);
1461 break;
1462 default:
1463 ERR("shouldn't reach here. phase %d\n", phase);
1464 break;
1468 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1470 if (ext_flags.HasNewCorrDesc)
1472 /* free extra correlation package */
1473 NdrCorrelationFree(&stubMsg);
1476 if (Oif_flags.HasPipes)
1478 /* NdrPipesDone(...) */
1481 /* free the full pointer translation tables */
1482 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1483 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1485 /* free server function stack */
1486 HeapFree(GetProcessHeap(), 0, args);
1488 return S_OK;
1491 /***********************************************************************
1492 * NdrServerCall2 [RPCRT4.@]
1494 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1496 DWORD dwPhase;
1497 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
1500 /***********************************************************************
1501 * NdrStubCall [RPCRT4.@]
1503 LONG WINAPI NdrStubCall( struct IRpcStubBuffer *This, struct IRpcChannelBuffer *channel,
1504 PRPC_MESSAGE msg, DWORD *phase )
1506 return NdrStubCall2( This, channel, msg, phase );
1509 /***********************************************************************
1510 * NdrServerCall [RPCRT4.@]
1512 void WINAPI NdrServerCall( PRPC_MESSAGE msg )
1514 DWORD phase;
1515 NdrStubCall( NULL, NULL, msg, &phase );
1518 struct async_call_data
1520 MIDL_STUB_MESSAGE *pStubMsg;
1521 const NDR_PROC_HEADER *pProcHeader;
1522 PFORMAT_STRING pHandleFormat;
1523 PFORMAT_STRING pParamFormat;
1524 RPC_BINDING_HANDLE hBinding;
1525 /* size of stack */
1526 unsigned short stack_size;
1527 /* number of parameters. optional for client to give it to us */
1528 unsigned int number_of_params;
1529 /* correlation cache */
1530 ULONG_PTR NdrCorrCache[256];
1533 LONG_PTR CDECL DECLSPEC_HIDDEN ndr_async_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
1534 void **stack_top )
1536 /* pointer to start of stack where arguments start */
1537 PRPC_MESSAGE pRpcMsg;
1538 PMIDL_STUB_MESSAGE pStubMsg;
1539 RPC_ASYNC_STATE *pAsync;
1540 struct async_call_data *async_call_data;
1541 /* procedure number */
1542 unsigned short procedure_number;
1543 /* cache of Oif_flags from v2 procedure header */
1544 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1545 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1546 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1547 /* header for procedure string */
1548 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1549 RPC_STATUS status;
1551 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
1553 /* Later NDR language versions probably won't be backwards compatible */
1554 if (pStubDesc->Version > 0x50002)
1556 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
1557 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1560 async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
1561 if (!async_call_data) RpcRaiseException(RPC_X_NO_MEMORY);
1562 async_call_data->pProcHeader = pProcHeader;
1564 async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
1565 pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
1567 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1569 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1570 async_call_data->stack_size = header_rpc->stack_size;
1571 procedure_number = header_rpc->proc_num;
1572 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1574 else
1576 async_call_data->stack_size = pProcHeader->stack_size;
1577 procedure_number = pProcHeader->proc_num;
1578 pFormat += sizeof(NDR_PROC_HEADER);
1580 TRACE("stack size: 0x%x\n", async_call_data->stack_size);
1581 TRACE("proc num: %d\n", procedure_number);
1583 /* create the full pointer translation tables, if requested */
1584 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1585 pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
1587 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1589 ERR("objects not supported\n");
1590 I_RpcFree(async_call_data);
1591 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1594 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
1596 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1597 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
1599 /* needed for conformance of top-level objects */
1600 pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
1601 memcpy(pStubMsg->StackTop, stack_top, async_call_data->stack_size);
1603 pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
1604 pAsync->StubInfo = async_call_data;
1605 async_call_data->pHandleFormat = pFormat;
1607 pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
1608 if (!pFormat) goto done;
1610 if (is_oicf_stubdesc(pStubDesc))
1612 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1613 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1615 Oif_flags = pOIFHeader->Oi2Flags;
1616 async_call_data->number_of_params = pOIFHeader->number_of_params;
1618 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1620 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1622 if (Oif_flags.HasExtensions)
1624 const NDR_PROC_HEADER_EXTS *pExtensions =
1625 (const NDR_PROC_HEADER_EXTS *)pFormat;
1626 ext_flags = pExtensions->Flags2;
1627 pFormat += pExtensions->Size;
1630 else
1632 pFormat = convert_old_args( pStubMsg, pFormat, async_call_data->stack_size,
1633 pProcHeader->Oi_flags & Oi_OBJECT_PROC,
1634 async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache),
1635 &async_call_data->number_of_params );
1638 async_call_data->pParamFormat = pFormat;
1640 pStubMsg->BufferLength = 0;
1642 /* store the RPC flags away */
1643 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1644 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1646 /* use alternate memory allocation routines */
1647 if (pProcHeader->Oi_flags & Oi_RPCSS_ALLOC_USED)
1648 NdrRpcSmSetClientToOsf(pStubMsg);
1650 if (Oif_flags.HasPipes)
1652 FIXME("pipes not supported yet\n");
1653 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1654 /* init pipes package */
1655 /* NdrPipesInitialize(...) */
1657 if (ext_flags.HasNewCorrDesc)
1659 /* initialize extra correlation package */
1660 NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
1661 if (ext_flags.Unused & 0x2) /* has range on conformance */
1662 pStubMsg->CorrDespIncrement = 12;
1665 /* order of phases:
1666 * 1. CALCSIZE - calculate the buffer size
1667 * 2. GETBUFFER - allocate the buffer
1668 * 3. MARSHAL - marshal [in] params into the buffer
1669 * 4. SENDRECEIVE - send buffer
1670 * Then in NdrpCompleteAsyncClientCall:
1671 * 1. SENDRECEIVE - receive buffer
1672 * 2. UNMARSHAL - unmarshal [out] params from buffer
1675 /* 1. CALCSIZE */
1676 TRACE( "CALCSIZE\n" );
1677 client_do_args(pStubMsg, pFormat, STUBLESS_CALCSIZE, NULL, async_call_data->number_of_params, NULL);
1679 /* 2. GETBUFFER */
1680 TRACE( "GETBUFFER\n" );
1681 if (Oif_flags.HasPipes)
1682 /* NdrGetPipeBuffer(...) */
1683 FIXME("pipes not supported yet\n");
1684 else
1686 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
1687 #if 0
1688 NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1689 #else
1690 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1691 #endif
1692 else
1693 NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1695 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1696 status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
1697 if (status != RPC_S_OK)
1698 RpcRaiseException(status);
1700 /* 3. MARSHAL */
1701 TRACE( "MARSHAL\n" );
1702 client_do_args(pStubMsg, pFormat, STUBLESS_MARSHAL, NULL, async_call_data->number_of_params, NULL);
1704 /* 4. SENDRECEIVE */
1705 TRACE( "SEND\n" );
1706 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1707 /* send the [in] params only */
1708 if (Oif_flags.HasPipes)
1709 /* NdrPipesSend(...) */
1710 FIXME("pipes not supported yet\n");
1711 else
1713 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
1714 #if 0
1715 NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1716 #else
1717 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1718 #endif
1719 else
1721 pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
1722 status = I_RpcSend(pStubMsg->RpcMsg);
1723 if (status != RPC_S_OK)
1724 RpcRaiseException(status);
1728 done:
1729 TRACE("returning 0\n");
1730 return 0;
1733 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
1735 /* pointer to start of stack where arguments start */
1736 PMIDL_STUB_MESSAGE pStubMsg;
1737 struct async_call_data *async_call_data;
1738 /* header for procedure string */
1739 const NDR_PROC_HEADER * pProcHeader;
1740 RPC_STATUS status = RPC_S_OK;
1742 if (!pAsync->StubInfo)
1743 return RPC_S_INVALID_ASYNC_HANDLE;
1745 async_call_data = pAsync->StubInfo;
1746 pStubMsg = async_call_data->pStubMsg;
1747 pProcHeader = async_call_data->pProcHeader;
1749 /* order of phases:
1750 * 1. CALCSIZE - calculate the buffer size
1751 * 2. GETBUFFER - allocate the buffer
1752 * 3. MARSHAL - marshal [in] params into the buffer
1753 * 4. SENDRECEIVE - send buffer
1754 * Then in NdrpCompleteAsyncClientCall:
1755 * 1. SENDRECEIVE - receive buffer
1756 * 2. UNMARSHAL - unmarshal [out] params from buffer
1759 /* 1. SENDRECEIVE */
1760 TRACE( "RECEIVE\n" );
1761 pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1762 /* receive the [out] params */
1763 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
1764 #if 0
1765 NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1766 #else
1767 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1768 #endif
1769 else
1771 status = I_RpcReceive(pStubMsg->RpcMsg);
1772 if (status != RPC_S_OK)
1773 goto cleanup;
1774 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
1775 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
1776 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
1777 pStubMsg->Buffer = pStubMsg->BufferStart;
1780 /* convert strings, floating point values and endianness into our
1781 * preferred format */
1782 #if 0
1783 if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1784 NdrConvert(pStubMsg, pFormat);
1785 #endif
1787 /* 2. UNMARSHAL */
1788 TRACE( "UNMARSHAL\n" );
1789 client_do_args(pStubMsg, async_call_data->pParamFormat, STUBLESS_UNMARSHAL,
1790 NULL, async_call_data->number_of_params, Reply);
1792 cleanup:
1793 if (pStubMsg->fHasNewCorrDesc)
1795 /* free extra correlation package */
1796 NdrCorrelationFree(pStubMsg);
1799 /* free the full pointer translation tables */
1800 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1801 NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
1803 /* free marshalling buffer */
1804 NdrFreeBuffer(pStubMsg);
1805 client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
1807 I_RpcFree(pStubMsg->StackTop);
1808 I_RpcFree(async_call_data);
1810 TRACE("-- 0x%x\n", status);
1811 return status;
1814 #ifdef __x86_64__
1816 __ASM_GLOBAL_FUNC( NdrAsyncClientCall,
1817 "movq %r8,0x18(%rsp)\n\t"
1818 "movq %r9,0x20(%rsp)\n\t"
1819 "leaq 0x18(%rsp),%r8\n\t"
1820 "subq $0x28,%rsp\n\t"
1821 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
1822 "call " __ASM_NAME("ndr_async_client_call") "\n\t"
1823 "addq $0x28,%rsp\n\t"
1824 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
1825 "ret" );
1827 #else /* __x86_64__ */
1829 /***********************************************************************
1830 * NdrAsyncClientCall [RPCRT4.@]
1832 CLIENT_CALL_RETURN WINAPIV NdrAsyncClientCall( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1834 __ms_va_list args;
1835 LONG_PTR ret;
1837 __ms_va_start( args, format );
1838 ret = ndr_async_client_call( desc, format, va_arg( args, void ** ));
1839 __ms_va_end( args );
1840 return *(CLIENT_CALL_RETURN *)&ret;
1843 #endif /* __x86_64__ */
1845 RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
1846 struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
1847 DWORD * pdwStubPhase)
1849 FIXME("unimplemented, expect crash!\n");
1850 return 0;
1853 void RPC_ENTRY NdrAsyncServerCall(PRPC_MESSAGE pRpcMsg)
1855 FIXME("unimplemented, %p\n", pRpcMsg);