include: Move inline assembly definitions to a new wine/asm.h header.
[wine.git] / dlls / rpcrt4 / ndr_stubless.c
blobc912d93231de05d5939ec883e32392f5ca710cbf
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/asm.h"
43 #include "wine/debug.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 FC_RP:
158 if (pFormat[1] & FC_SIMPLE_POINTER)
160 size = 0;
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_UP:
220 case FC_OP:
221 case FC_FP:
222 case FC_IP:
223 size = sizeof(void *);
224 break;
226 return size;
229 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
231 #if 0 /* these functions are not defined yet */
232 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
233 pMessage->pfnFree = NdrRpcSmClientFree;
234 #endif
237 static const char *debugstr_PROC_PF(PARAM_ATTRIBUTES param_attributes)
239 char buffer[160];
241 buffer[0] = 0;
242 if (param_attributes.MustSize) strcat(buffer, " MustSize");
243 if (param_attributes.MustFree) strcat(buffer, " MustFree");
244 if (param_attributes.IsPipe) strcat(buffer, " IsPipe");
245 if (param_attributes.IsIn) strcat(buffer, " IsIn");
246 if (param_attributes.IsOut) strcat(buffer, " IsOut");
247 if (param_attributes.IsReturn) strcat(buffer, " IsReturn");
248 if (param_attributes.IsBasetype) strcat(buffer, " IsBasetype");
249 if (param_attributes.IsByValue) strcat(buffer, " IsByValue");
250 if (param_attributes.IsSimpleRef) strcat(buffer, " IsSimpleRef");
251 if (param_attributes.IsDontCallFreeInst) strcat(buffer, " IsDontCallFreeInst");
252 if (param_attributes.SaveForAsyncFinish) strcat(buffer, " SaveForAsyncFinish");
253 if (param_attributes.ServerAllocSize)
254 sprintf( buffer + strlen(buffer), " ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
255 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
258 static const char *debugstr_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
260 char buffer[160];
262 buffer[0] = 0;
263 if (Oi2Flags.ServerMustSize) strcat(buffer, " ServerMustSize");
264 if (Oi2Flags.ClientMustSize) strcat(buffer, " ClientMustSize");
265 if (Oi2Flags.HasReturn) strcat(buffer, " HasReturn");
266 if (Oi2Flags.HasPipes) strcat(buffer, " HasPipes");
267 if (Oi2Flags.Unused) strcat(buffer, " Unused");
268 if (Oi2Flags.HasAsyncUuid) strcat(buffer, " HasAsyncUuid");
269 if (Oi2Flags.HasExtensions) strcat(buffer, " HasExtensions");
270 if (Oi2Flags.HasAsyncHandle) strcat(buffer, " HasAsyncHandle");
271 return buffer[0] ? wine_dbg_sprintf( "%s", buffer + 1 ) : "";
274 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
276 static PFORMAT_STRING client_get_handle(
277 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
278 PFORMAT_STRING pFormat, handle_t *phBinding)
280 /* binding */
281 switch (pProcHeader->handle_type)
283 /* explicit binding: parse additional section */
284 case 0:
285 switch (*pFormat) /* handle_type */
287 case FC_BIND_PRIMITIVE: /* explicit primitive */
289 const NDR_EHD_PRIMITIVE *pDesc = (const NDR_EHD_PRIMITIVE *)pFormat;
291 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
293 if (pDesc->flag) /* pointer to binding */
294 *phBinding = **(handle_t **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
295 else
296 *phBinding = *(handle_t *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
297 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
299 case FC_BIND_GENERIC: /* explicit generic */
301 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
302 void *pObject = NULL;
303 void *pArg;
304 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
306 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
308 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
309 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
310 else
311 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
312 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
313 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
314 *phBinding = pGenPair->pfnBind(pObject);
315 return pFormat + sizeof(NDR_EHD_GENERIC);
317 case FC_BIND_CONTEXT: /* explicit context */
319 const NDR_EHD_CONTEXT *pDesc = (const NDR_EHD_CONTEXT *)pFormat;
320 NDR_CCONTEXT context_handle;
321 TRACE("Explicit bind context\n");
322 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
324 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
325 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
327 else
328 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
330 if (context_handle) *phBinding = NDRCContextBinding(context_handle);
331 else if (pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL)
333 ERR("null context handle isn't allowed\n");
334 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
335 return NULL;
337 /* FIXME: should we store this structure in stubMsg.pContext? */
338 return pFormat + sizeof(NDR_EHD_CONTEXT);
340 default:
341 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
342 RpcRaiseException(RPC_X_BAD_STUB_DATA);
344 break;
345 case FC_BIND_GENERIC: /* implicit generic */
346 FIXME("FC_BIND_GENERIC\n");
347 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
348 break;
349 case FC_BIND_PRIMITIVE: /* implicit primitive */
350 TRACE("Implicit primitive handle\n");
351 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
352 break;
353 case FC_CALLBACK_HANDLE: /* implicit callback */
354 TRACE("FC_CALLBACK_HANDLE\n");
355 /* server calls callback procedures only in response to remote call, and most recent
356 binding handle is used. Calling back to a client can potentially result in another
357 callback with different current handle. */
358 *phBinding = I_RpcGetCurrentCallHandle();
359 break;
360 case FC_AUTO_HANDLE: /* implicit auto handle */
361 /* strictly speaking, it isn't necessary to set hBinding here
362 * since it isn't actually used (hence the automatic in its name),
363 * but then why does MIDL generate a valid entry in the
364 * MIDL_STUB_DESC for it? */
365 TRACE("Implicit auto handle\n");
366 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
367 break;
368 default:
369 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
370 RpcRaiseException(RPC_X_BAD_STUB_DATA);
372 return pFormat;
375 static void client_free_handle(
376 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
377 PFORMAT_STRING pFormat, handle_t hBinding)
379 /* binding */
380 switch (pProcHeader->handle_type)
382 /* explicit binding: parse additional section */
383 case 0:
384 switch (*pFormat) /* handle_type */
386 case FC_BIND_GENERIC: /* explicit generic */
388 const NDR_EHD_GENERIC *pDesc = (const NDR_EHD_GENERIC *)pFormat;
389 void *pObject = NULL;
390 void *pArg;
391 const GENERIC_BINDING_ROUTINE_PAIR *pGenPair;
393 TRACE("Explicit generic binding handle #%d\n", pDesc->binding_routine_pair_index);
395 if (pDesc->flag_and_size & HANDLE_PARAM_IS_VIA_PTR)
396 pArg = *(void **)ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
397 else
398 pArg = ARG_FROM_OFFSET(pStubMsg->StackTop, pDesc->offset);
399 memcpy(&pObject, pArg, pDesc->flag_and_size & 0xf);
400 pGenPair = &pStubMsg->StubDesc->aGenericBindingRoutinePairs[pDesc->binding_routine_pair_index];
401 pGenPair->pfnUnbind(pObject, hBinding);
402 break;
404 case FC_BIND_CONTEXT: /* explicit context */
405 case FC_BIND_PRIMITIVE: /* explicit primitive */
406 break;
407 default:
408 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
409 RpcRaiseException(RPC_X_BAD_STUB_DATA);
411 break;
412 case FC_BIND_GENERIC: /* implicit generic */
413 FIXME("FC_BIND_GENERIC\n");
414 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
415 break;
416 case FC_CALLBACK_HANDLE: /* implicit callback */
417 case FC_BIND_PRIMITIVE: /* implicit primitive */
418 case FC_AUTO_HANDLE: /* implicit auto handle */
419 break;
420 default:
421 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
422 RpcRaiseException(RPC_X_BAD_STUB_DATA);
426 static inline BOOL param_needs_alloc( PARAM_ATTRIBUTES attr )
428 return attr.IsOut && !attr.IsIn && !attr.IsBasetype && !attr.IsByValue;
431 static inline BOOL param_is_out_basetype( PARAM_ATTRIBUTES attr )
433 return attr.IsOut && !attr.IsIn && attr.IsBasetype && attr.IsSimpleRef;
436 static size_t basetype_arg_size( unsigned char fc )
438 switch (fc)
440 case FC_BYTE:
441 case FC_CHAR:
442 case FC_SMALL:
443 case FC_USMALL:
444 return sizeof(char);
445 case FC_WCHAR:
446 case FC_SHORT:
447 case FC_USHORT:
448 return sizeof(short);
449 case FC_LONG:
450 case FC_ULONG:
451 case FC_ENUM16:
452 case FC_ENUM32:
453 case FC_ERROR_STATUS_T:
454 return sizeof(int);
455 case FC_FLOAT:
456 return sizeof(float);
457 case FC_HYPER:
458 return sizeof(LONGLONG);
459 case FC_DOUBLE:
460 return sizeof(double);
461 case FC_INT3264:
462 case FC_UINT3264:
463 return sizeof(INT_PTR);
464 default:
465 FIXME("Unhandled basetype %#x.\n", fc);
466 return 0;
470 void client_do_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, enum stubless_phase phase,
471 void **fpu_args, unsigned short number_of_params, unsigned char *pRetVal )
473 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
474 unsigned int i;
476 for (i = 0; i < number_of_params; i++)
478 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
479 PFORMAT_STRING pTypeFormat = (PFORMAT_STRING)&pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
481 #ifdef __x86_64__ /* floats are passed as doubles through varargs functions */
482 float f;
484 if (params[i].attr.IsBasetype &&
485 params[i].u.type_format_char == FC_FLOAT &&
486 !params[i].attr.IsSimpleRef &&
487 !fpu_args)
489 f = *(double *)pArg;
490 pArg = (unsigned char *)&f;
492 #endif
494 TRACE("param[%d]: %p type %02x %s\n", i, pArg,
495 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
496 debugstr_PROC_PF( params[i].attr ));
498 switch (phase)
500 case STUBLESS_INITOUT:
501 if (*(unsigned char **)pArg)
503 if (param_needs_alloc(params[i].attr))
504 memset( *(unsigned char **)pArg, 0, calc_arg_size( pStubMsg, pTypeFormat ));
505 else if (param_is_out_basetype(params[i].attr))
506 memset( *(unsigned char **)pArg, 0, basetype_arg_size( params[i].u.type_format_char ));
508 break;
509 case STUBLESS_CALCSIZE:
510 if (params[i].attr.IsSimpleRef && !*(unsigned char **)pArg)
511 RpcRaiseException(RPC_X_NULL_REF_POINTER);
512 if (params[i].attr.IsIn) call_buffer_sizer(pStubMsg, pArg, &params[i]);
513 break;
514 case STUBLESS_MARSHAL:
515 if (params[i].attr.IsIn) call_marshaller(pStubMsg, pArg, &params[i]);
516 break;
517 case STUBLESS_UNMARSHAL:
518 if (params[i].attr.IsOut)
520 if (params[i].attr.IsReturn && pRetVal) pArg = pRetVal;
521 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
523 break;
524 case STUBLESS_FREE:
525 if (!params[i].attr.IsBasetype && params[i].attr.IsOut && !params[i].attr.IsByValue)
526 NdrClearOutParameters( pStubMsg, pTypeFormat, *(unsigned char **)pArg );
527 break;
528 default:
529 RpcRaiseException(RPC_S_INTERNAL_ERROR);
534 static unsigned int type_stack_size(unsigned char fc)
536 switch (fc)
538 case FC_BYTE:
539 case FC_CHAR:
540 case FC_SMALL:
541 case FC_USMALL:
542 case FC_WCHAR:
543 case FC_SHORT:
544 case FC_USHORT:
545 case FC_LONG:
546 case FC_ULONG:
547 case FC_INT3264:
548 case FC_UINT3264:
549 case FC_ENUM16:
550 case FC_ENUM32:
551 case FC_FLOAT:
552 case FC_ERROR_STATUS_T:
553 case FC_IGNORE:
554 return sizeof(void *);
555 case FC_DOUBLE:
556 return sizeof(double);
557 case FC_HYPER:
558 return sizeof(ULONGLONG);
559 default:
560 ERR("invalid base type 0x%x\n", fc);
561 RpcRaiseException(RPC_S_INTERNAL_ERROR);
565 static BOOL is_by_value( PFORMAT_STRING format )
567 switch (*format)
569 case FC_USER_MARSHAL:
570 case FC_STRUCT:
571 case FC_PSTRUCT:
572 case FC_CSTRUCT:
573 case FC_CPSTRUCT:
574 case FC_CVSTRUCT:
575 case FC_BOGUS_STRUCT:
576 return TRUE;
577 default:
578 return FALSE;
582 PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
583 unsigned int stack_size, BOOL object_proc,
584 void *buffer, unsigned int size, unsigned int *count )
586 NDR_PARAM_OIF *args = buffer;
587 unsigned int i, stack_offset = object_proc ? sizeof(void *) : 0;
589 for (i = 0; stack_offset < stack_size; i++)
591 const NDR_PARAM_OI_BASETYPE *param = (const NDR_PARAM_OI_BASETYPE *)pFormat;
592 const NDR_PARAM_OI_OTHER *other = (const NDR_PARAM_OI_OTHER *)pFormat;
594 if (i + 1 > size / sizeof(*args))
596 FIXME( "%u args not supported\n", i );
597 RpcRaiseException( RPC_S_INTERNAL_ERROR );
600 args[i].stack_offset = stack_offset;
601 memset( &args[i].attr, 0, sizeof(args[i].attr) );
603 switch (param->param_direction)
605 case FC_IN_PARAM_BASETYPE:
606 args[i].attr.IsIn = 1;
607 args[i].attr.IsBasetype = 1;
608 break;
609 case FC_RETURN_PARAM_BASETYPE:
610 args[i].attr.IsOut = 1;
611 args[i].attr.IsReturn = 1;
612 args[i].attr.IsBasetype = 1;
613 break;
614 case FC_IN_PARAM:
615 args[i].attr.IsIn = 1;
616 args[i].attr.MustFree = 1;
617 break;
618 case FC_IN_PARAM_NO_FREE_INST:
619 args[i].attr.IsIn = 1;
620 args[i].attr.IsDontCallFreeInst = 1;
621 break;
622 case FC_IN_OUT_PARAM:
623 args[i].attr.IsIn = 1;
624 args[i].attr.IsOut = 1;
625 args[i].attr.MustFree = 1;
626 break;
627 case FC_OUT_PARAM:
628 args[i].attr.IsOut = 1;
629 break;
630 case FC_RETURN_PARAM:
631 args[i].attr.IsOut = 1;
632 args[i].attr.IsReturn = 1;
633 break;
635 if (args[i].attr.IsBasetype)
637 args[i].u.type_format_char = param->type_format_char;
638 stack_offset += type_stack_size( param->type_format_char );
639 pFormat += sizeof(NDR_PARAM_OI_BASETYPE);
641 else
643 args[i].u.type_offset = other->type_offset;
644 args[i].attr.IsByValue = is_by_value( &pStubMsg->StubDesc->pFormatTypes[other->type_offset] );
645 stack_offset += other->stack_size * sizeof(void *);
646 pFormat += sizeof(NDR_PARAM_OI_OTHER);
649 *count = i;
650 return (PFORMAT_STRING)args;
653 LONG_PTR CDECL DECLSPEC_HIDDEN ndr_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
654 void **stack_top, void **fpu_stack )
656 /* pointer to start of stack where arguments start */
657 RPC_MESSAGE rpcMsg;
658 MIDL_STUB_MESSAGE stubMsg;
659 handle_t hBinding = NULL;
660 /* procedure number */
661 unsigned short procedure_number;
662 /* size of stack */
663 unsigned short stack_size;
664 /* number of parameters. optional for client to give it to us */
665 unsigned int number_of_params;
666 /* cache of Oif_flags from v2 procedure header */
667 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
668 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
669 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
670 /* header for procedure string */
671 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
672 /* the value to return to the client from the remote procedure */
673 LONG_PTR RetVal = 0;
674 /* the pointer to the object when in OLE mode */
675 void * This = NULL;
676 PFORMAT_STRING pHandleFormat;
677 /* correlation cache */
678 ULONG_PTR NdrCorrCache[256];
680 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
682 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
684 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
686 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
687 stack_size = header_rpc->stack_size;
688 procedure_number = header_rpc->proc_num;
689 pFormat += sizeof(NDR_PROC_HEADER_RPC);
691 else
693 stack_size = pProcHeader->stack_size;
694 procedure_number = pProcHeader->proc_num;
695 pFormat += sizeof(NDR_PROC_HEADER);
697 TRACE("stack size: 0x%x\n", stack_size);
698 TRACE("proc num: %d\n", procedure_number);
700 /* create the full pointer translation tables, if requested */
701 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
702 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
704 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
706 /* object is always the first argument */
707 This = stack_top[0];
708 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
710 else
711 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
713 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
714 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
716 stubMsg.StackTop = (unsigned char *)stack_top;
717 pHandleFormat = pFormat;
719 /* we only need a handle if this isn't an object method */
720 if (!(pProcHeader->Oi_flags & Oi_OBJECT_PROC))
722 pFormat = client_get_handle(&stubMsg, pProcHeader, pHandleFormat, &hBinding);
723 if (!pFormat) goto done;
726 if (is_oicf_stubdesc(pStubDesc)) /* -Oicf format */
728 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
729 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
731 Oif_flags = pOIFHeader->Oi2Flags;
732 number_of_params = pOIFHeader->number_of_params;
734 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
736 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
738 if (Oif_flags.HasExtensions)
740 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
741 ext_flags = pExtensions->Flags2;
742 pFormat += pExtensions->Size;
743 #ifdef __x86_64__
744 if (pExtensions->Size > sizeof(*pExtensions) && fpu_stack)
746 int i;
747 unsigned short fpu_mask = *(unsigned short *)(pExtensions + 1);
748 for (i = 0; i < 4; i++, fpu_mask >>= 2)
749 switch (fpu_mask & 3)
751 case 1: *(float *)&stack_top[i] = *(float *)&fpu_stack[i]; break;
752 case 2: *(double *)&stack_top[i] = *(double *)&fpu_stack[i]; break;
755 #endif
758 else
760 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
761 pProcHeader->Oi_flags & Oi_OBJECT_PROC,
762 /* reuse the correlation cache, it's not needed for v1 format */
763 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
766 stubMsg.BufferLength = 0;
768 /* store the RPC flags away */
769 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
770 rpcMsg.RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
772 /* use alternate memory allocation routines */
773 if (pProcHeader->Oi_flags & Oi_RPCSS_ALLOC_USED)
774 NdrRpcSmSetClientToOsf(&stubMsg);
776 if (Oif_flags.HasPipes)
778 FIXME("pipes not supported yet\n");
779 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
780 /* init pipes package */
781 /* NdrPipesInitialize(...) */
783 if (ext_flags.HasNewCorrDesc)
785 /* initialize extra correlation package */
786 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
787 if (ext_flags.Unused & 0x2) /* has range on conformance */
788 stubMsg.CorrDespIncrement = 12;
791 /* order of phases:
792 * 1. INITOUT - zero [out] parameters (proxies only)
793 * 2. CALCSIZE - calculate the buffer size
794 * 3. GETBUFFER - allocate the buffer
795 * 4. MARSHAL - marshal [in] params into the buffer
796 * 5. SENDRECEIVE - send/receive buffer
797 * 6. UNMARSHAL - unmarshal [out] params from buffer
798 * 7. FREE - clear [out] parameters (for proxies, and only on error)
800 if ((pProcHeader->Oi_flags & Oi_OBJECT_PROC) ||
801 (pProcHeader->Oi_flags & Oi_HAS_COMM_OR_FAULT))
803 /* 1. INITOUT */
804 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
806 TRACE( "INITOUT\n" );
807 client_do_args(&stubMsg, pFormat, STUBLESS_INITOUT, fpu_stack,
808 number_of_params, (unsigned char *)&RetVal);
811 __TRY
813 /* 2. CALCSIZE */
814 TRACE( "CALCSIZE\n" );
815 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
816 number_of_params, (unsigned char *)&RetVal);
818 /* 3. GETBUFFER */
819 TRACE( "GETBUFFER\n" );
820 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
822 /* allocate the buffer */
823 NdrProxyGetBuffer(This, &stubMsg);
825 else
827 /* allocate the buffer */
828 if (Oif_flags.HasPipes)
829 /* NdrGetPipeBuffer(...) */
830 FIXME("pipes not supported yet\n");
831 else
833 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
834 #if 0
835 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
836 #else
837 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
838 #endif
839 else
840 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
844 /* 4. MARSHAL */
845 TRACE( "MARSHAL\n" );
846 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
847 number_of_params, (unsigned char *)&RetVal);
849 /* 5. SENDRECEIVE */
850 TRACE( "SENDRECEIVE\n" );
851 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
853 /* send the [in] params and receive the [out] and [retval]
854 * params */
855 NdrProxySendReceive(This, &stubMsg);
857 else
859 /* send the [in] params and receive the [out] and [retval]
860 * params */
861 if (Oif_flags.HasPipes)
862 /* NdrPipesSendReceive(...) */
863 FIXME("pipes not supported yet\n");
864 else
866 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
867 #if 0
868 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
869 #else
870 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
871 #endif
872 else
873 NdrSendReceive(&stubMsg, stubMsg.Buffer);
877 /* convert strings, floating point values and endianness into our
878 * preferred format */
879 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
880 NdrConvert(&stubMsg, pFormat);
882 /* 6. UNMARSHAL */
883 TRACE( "UNMARSHAL\n" );
884 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
885 number_of_params, (unsigned char *)&RetVal);
887 __EXCEPT_ALL
889 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
891 /* 7. FREE */
892 TRACE( "FREE\n" );
893 client_do_args(&stubMsg, pFormat, STUBLESS_FREE, fpu_stack,
894 number_of_params, (unsigned char *)&RetVal);
895 RetVal = NdrProxyErrorHandler(GetExceptionCode());
897 else
899 const COMM_FAULT_OFFSETS *comm_fault_offsets = &pStubDesc->CommFaultOffsets[procedure_number];
900 ULONG *comm_status;
901 ULONG *fault_status;
903 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets->CommOffset, comm_fault_offsets->FaultOffset);
905 if (comm_fault_offsets->CommOffset == -1)
906 comm_status = (ULONG *)&RetVal;
907 else if (comm_fault_offsets->CommOffset >= 0)
908 comm_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->CommOffset);
909 else
910 comm_status = NULL;
912 if (comm_fault_offsets->FaultOffset == -1)
913 fault_status = (ULONG *)&RetVal;
914 else if (comm_fault_offsets->FaultOffset >= 0)
915 fault_status = *(ULONG **)ARG_FROM_OFFSET(stubMsg.StackTop, comm_fault_offsets->FaultOffset);
916 else
917 fault_status = NULL;
919 NdrMapCommAndFaultStatus(&stubMsg, comm_status, fault_status,
920 GetExceptionCode());
923 __ENDTRY
925 else
927 /* 2. CALCSIZE */
928 TRACE( "CALCSIZE\n" );
929 client_do_args(&stubMsg, pFormat, STUBLESS_CALCSIZE, fpu_stack,
930 number_of_params, (unsigned char *)&RetVal);
932 /* 3. GETBUFFER */
933 TRACE( "GETBUFFER\n" );
934 if (Oif_flags.HasPipes)
935 /* NdrGetPipeBuffer(...) */
936 FIXME("pipes not supported yet\n");
937 else
939 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
940 #if 0
941 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
942 #else
943 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
944 #endif
945 else
946 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
949 /* 4. MARSHAL */
950 TRACE( "MARSHAL\n" );
951 client_do_args(&stubMsg, pFormat, STUBLESS_MARSHAL, fpu_stack,
952 number_of_params, (unsigned char *)&RetVal);
954 /* 5. SENDRECEIVE */
955 TRACE( "SENDRECEIVE\n" );
956 if (Oif_flags.HasPipes)
957 /* NdrPipesSendReceive(...) */
958 FIXME("pipes not supported yet\n");
959 else
961 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
962 #if 0
963 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
964 #else
965 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
966 #endif
967 else
968 NdrSendReceive(&stubMsg, stubMsg.Buffer);
971 /* convert strings, floating point values and endianness into our
972 * preferred format */
973 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
974 NdrConvert(&stubMsg, pFormat);
976 /* 6. UNMARSHAL */
977 TRACE( "UNMARSHAL\n" );
978 client_do_args(&stubMsg, pFormat, STUBLESS_UNMARSHAL, fpu_stack,
979 number_of_params, (unsigned char *)&RetVal);
982 if (ext_flags.HasNewCorrDesc)
984 /* free extra correlation package */
985 NdrCorrelationFree(&stubMsg);
988 if (Oif_flags.HasPipes)
990 /* NdrPipesDone(...) */
993 /* free the full pointer translation tables */
994 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
995 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
997 /* free marshalling buffer */
998 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
999 NdrProxyFreeBuffer(This, &stubMsg);
1000 else
1002 NdrFreeBuffer(&stubMsg);
1003 client_free_handle(&stubMsg, pProcHeader, pHandleFormat, hBinding);
1006 done:
1007 TRACE("RetVal = 0x%lx\n", RetVal);
1008 return RetVal;
1011 #ifdef __x86_64__
1013 __ASM_GLOBAL_FUNC( NdrClientCall2,
1014 "movq %r8,0x18(%rsp)\n\t"
1015 "movq %r9,0x20(%rsp)\n\t"
1016 "leaq 0x18(%rsp),%r8\n\t"
1017 "xorq %r9,%r9\n\t"
1018 "subq $0x28,%rsp\n\t"
1019 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
1020 "call " __ASM_NAME("ndr_client_call") "\n\t"
1021 "addq $0x28,%rsp\n\t"
1022 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
1023 "ret" );
1025 #else /* __x86_64__ */
1027 /***********************************************************************
1028 * NdrClientCall2 [RPCRT4.@]
1030 CLIENT_CALL_RETURN WINAPIV NdrClientCall2( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1032 __ms_va_list args;
1033 LONG_PTR ret;
1035 __ms_va_start( args, format );
1036 ret = ndr_client_call( desc, format, va_arg( args, void ** ), NULL );
1037 __ms_va_end( args );
1038 return *(CLIENT_CALL_RETURN *)&ret;
1041 #endif /* __x86_64__ */
1043 /* Calls a function with the specified arguments, restoring the stack
1044 * properly afterwards as we don't know the calling convention of the
1045 * function */
1046 #if defined __i386__ && defined _MSC_VER
1047 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
1049 __asm
1051 push ebp
1052 mov ebp, esp
1053 push edi ; Save registers
1054 push esi
1055 mov eax, [ebp+16] ; Get stack size
1056 sub esp, eax ; Make room in stack for arguments
1057 and esp, 0xFFFFFFF0
1058 mov edi, esp
1059 mov ecx, eax
1060 mov esi, [ebp+12]
1061 shr ecx, 2
1063 rep movsd ; Copy dword blocks
1064 call [ebp+8] ; Call function
1065 lea esp, [ebp-8] ; Restore stack
1066 pop esi ; Restore registers
1067 pop edi
1068 pop ebp
1072 #elif defined __i386__ && defined __GNUC__
1073 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1074 __ASM_GLOBAL_FUNC(call_server_func,
1075 "pushl %ebp\n\t"
1076 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1077 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1078 "movl %esp,%ebp\n\t"
1079 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1080 "pushl %edi\n\t" /* Save registers */
1081 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
1082 "pushl %esi\n\t"
1083 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
1084 "movl 16(%ebp), %eax\n\t" /* Get stack size */
1085 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
1086 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
1087 "movl %esp, %edi\n\t"
1088 "movl %eax, %ecx\n\t"
1089 "movl 12(%ebp), %esi\n\t"
1090 "shrl $2, %ecx\n\t" /* divide by 4 */
1091 "cld\n\t"
1092 "rep; movsl\n\t" /* Copy dword blocks */
1093 "call *8(%ebp)\n\t" /* Call function */
1094 "leal -8(%ebp), %esp\n\t" /* Restore stack */
1095 "popl %esi\n\t" /* Restore registers */
1096 __ASM_CFI(".cfi_same_value %esi\n\t")
1097 "popl %edi\n\t"
1098 __ASM_CFI(".cfi_same_value %edi\n\t")
1099 "popl %ebp\n\t"
1100 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1101 __ASM_CFI(".cfi_same_value %ebp\n\t")
1102 "ret" )
1103 #elif defined __x86_64__
1104 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
1105 __ASM_GLOBAL_FUNC( call_server_func,
1106 "pushq %rbp\n\t"
1107 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
1108 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
1109 "movq %rsp,%rbp\n\t"
1110 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
1111 "pushq %rsi\n\t"
1112 __ASM_CFI(".cfi_rel_offset %rsi,-8\n\t")
1113 "pushq %rdi\n\t"
1114 __ASM_CFI(".cfi_rel_offset %rdi,-16\n\t")
1115 "movq %rcx,%rax\n\t" /* function to call */
1116 "movq $32,%rcx\n\t" /* allocate max(32,stack_size) bytes of stack space */
1117 "cmpq %rcx,%r8\n\t"
1118 "cmovgq %r8,%rcx\n\t"
1119 "subq %rcx,%rsp\n\t"
1120 "andq $~15,%rsp\n\t"
1121 "movq %r8,%rcx\n\t"
1122 "shrq $3,%rcx\n\t"
1123 "movq %rsp,%rdi\n\t"
1124 "movq %rdx,%rsi\n\t"
1125 "rep; movsq\n\t" /* copy arguments */
1126 "movq 0(%rsp),%rcx\n\t"
1127 "movq 8(%rsp),%rdx\n\t"
1128 "movq 16(%rsp),%r8\n\t"
1129 "movq 24(%rsp),%r9\n\t"
1130 "movq 0(%rsp),%xmm0\n\t"
1131 "movq 8(%rsp),%xmm1\n\t"
1132 "movq 16(%rsp),%xmm2\n\t"
1133 "movq 24(%rsp),%xmm3\n\t"
1134 "callq *%rax\n\t"
1135 "leaq -16(%rbp),%rsp\n\t" /* restore stack */
1136 "popq %rdi\n\t"
1137 __ASM_CFI(".cfi_same_value %rdi\n\t")
1138 "popq %rsi\n\t"
1139 __ASM_CFI(".cfi_same_value %rsi\n\t")
1140 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
1141 "popq %rbp\n\t"
1142 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
1143 __ASM_CFI(".cfi_same_value %rbp\n\t")
1144 "ret")
1145 #elif defined __arm__
1146 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char *args, unsigned int stack_size);
1147 __ASM_GLOBAL_FUNC( call_server_func,
1148 ".arm\n\t"
1149 "push {r4, r5, LR}\n\t"
1150 "mov r4, r0\n\t"
1151 "mov r5, SP\n\t"
1152 "lsr r3, r2, #2\n\t"
1153 "cmp r3, #0\n\t"
1154 "beq 5f\n\t"
1155 "sub SP, SP, r2\n\t"
1156 "tst r3, #1\n\t"
1157 "subeq SP, SP, #4\n\t"
1158 "1:\tsub r2, r2, #4\n\t"
1159 "ldr r0, [r1, r2]\n\t"
1160 "str r0, [SP, r2]\n\t"
1161 "cmp r2, #0\n\t"
1162 "bgt 1b\n\t"
1163 "cmp r3, #1\n\t"
1164 "bgt 2f\n\t"
1165 "pop {r0}\n\t"
1166 "b 5f\n\t"
1167 "2:\tcmp r3, #2\n\t"
1168 "bgt 3f\n\t"
1169 "pop {r0-r1}\n\t"
1170 "b 5f\n\t"
1171 "3:\tcmp r3, #3\n\t"
1172 "bgt 4f\n\t"
1173 "pop {r0-r2}\n\t"
1174 "b 5f\n\t"
1175 "4:\tpop {r0-r3}\n\t"
1176 "5:\tblx r4\n\t"
1177 "mov SP, r5\n\t"
1178 "pop {r4, r5, PC}" )
1179 #else
1180 #warning call_server_func not implemented for your architecture
1181 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
1183 FIXME("Not implemented for your architecture\n");
1184 return 0;
1186 #endif
1188 static LONG_PTR *stub_do_args(MIDL_STUB_MESSAGE *pStubMsg,
1189 PFORMAT_STRING pFormat, enum stubless_phase phase,
1190 unsigned short number_of_params)
1192 const NDR_PARAM_OIF *params = (const NDR_PARAM_OIF *)pFormat;
1193 unsigned int i;
1194 LONG_PTR *retval_ptr = NULL;
1196 for (i = 0; i < number_of_params; i++)
1198 unsigned char *pArg = pStubMsg->StackTop + params[i].stack_offset;
1199 const unsigned char *pTypeFormat = &pStubMsg->StubDesc->pFormatTypes[params[i].u.type_offset];
1201 TRACE("param[%d]: %p -> %p type %02x %s\n", i,
1202 pArg, *(unsigned char **)pArg,
1203 params[i].attr.IsBasetype ? params[i].u.type_format_char : *pTypeFormat,
1204 debugstr_PROC_PF( params[i].attr ));
1206 switch (phase)
1208 case STUBLESS_MARSHAL:
1209 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1210 call_marshaller(pStubMsg, pArg, &params[i]);
1211 break;
1212 case STUBLESS_MUSTFREE:
1213 if (params[i].attr.MustFree)
1215 call_freer(pStubMsg, pArg, &params[i]);
1217 break;
1218 case STUBLESS_FREE:
1219 if (params[i].attr.ServerAllocSize)
1221 HeapFree(GetProcessHeap(), 0, *(void **)pArg);
1223 else if (param_needs_alloc(params[i].attr) &&
1224 (!params[i].attr.MustFree || params[i].attr.IsSimpleRef))
1226 if (*pTypeFormat != FC_BIND_CONTEXT) pStubMsg->pfnFree(*(void **)pArg);
1228 break;
1229 case STUBLESS_INITOUT:
1230 if (param_needs_alloc(params[i].attr) && !params[i].attr.ServerAllocSize)
1232 if (*pTypeFormat == FC_BIND_CONTEXT)
1234 NDR_SCONTEXT ctxt = NdrContextHandleInitialize(pStubMsg, pTypeFormat);
1235 *(void **)pArg = NDRSContextValue(ctxt);
1236 if (params[i].attr.IsReturn) retval_ptr = (LONG_PTR *)NDRSContextValue(ctxt);
1238 else
1240 DWORD size = calc_arg_size(pStubMsg, pTypeFormat);
1241 if (size)
1243 *(void **)pArg = NdrAllocate(pStubMsg, size);
1244 memset(*(void **)pArg, 0, size);
1248 if (!retval_ptr && params[i].attr.IsReturn) retval_ptr = (LONG_PTR *)pArg;
1249 break;
1250 case STUBLESS_UNMARSHAL:
1251 if (params[i].attr.ServerAllocSize)
1252 *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1253 params[i].attr.ServerAllocSize * 8);
1255 if (params[i].attr.IsIn)
1256 call_unmarshaller(pStubMsg, &pArg, &params[i], 0);
1257 break;
1258 case STUBLESS_CALCSIZE:
1259 if (params[i].attr.IsOut || params[i].attr.IsReturn)
1260 call_buffer_sizer(pStubMsg, pArg, &params[i]);
1261 break;
1262 default:
1263 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1265 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1267 return retval_ptr;
1270 /***********************************************************************
1271 * NdrStubCall2 [RPCRT4.@]
1273 * Unmarshals [in] parameters, calls either a method in an object or a server
1274 * function, marshals any [out] parameters and frees any allocated data.
1276 * NOTES
1277 * Used by stubless MIDL-generated code.
1279 LONG WINAPI NdrStubCall2(
1280 struct IRpcStubBuffer * pThis,
1281 struct IRpcChannelBuffer * pChannel,
1282 PRPC_MESSAGE pRpcMsg,
1283 DWORD * pdwStubPhase)
1285 const MIDL_SERVER_INFO *pServerInfo;
1286 const MIDL_STUB_DESC *pStubDesc;
1287 PFORMAT_STRING pFormat;
1288 MIDL_STUB_MESSAGE stubMsg;
1289 /* pointer to start of stack to pass into stub implementation */
1290 unsigned char * args;
1291 /* size of stack */
1292 unsigned short stack_size;
1293 /* number of parameters. optional for client to give it to us */
1294 unsigned int number_of_params;
1295 /* cache of Oif_flags from v2 procedure header */
1296 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1297 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1298 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1299 /* the type of pass we are currently doing */
1300 enum stubless_phase phase;
1301 /* header for procedure string */
1302 const NDR_PROC_HEADER *pProcHeader;
1303 /* location to put retval into */
1304 LONG_PTR *retval_ptr = NULL;
1305 /* correlation cache */
1306 ULONG_PTR NdrCorrCache[256];
1308 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1310 if (pThis)
1311 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1312 else
1313 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1315 pStubDesc = pServerInfo->pStubDesc;
1316 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1317 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1319 TRACE("NDR Version: 0x%x\n", pStubDesc->Version);
1321 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1323 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1324 stack_size = header_rpc->stack_size;
1325 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1328 else
1330 stack_size = pProcHeader->stack_size;
1331 pFormat += sizeof(NDR_PROC_HEADER);
1334 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1336 /* binding */
1337 switch (pProcHeader->handle_type)
1339 /* explicit binding: parse additional section */
1340 case 0:
1341 switch (*pFormat) /* handle_type */
1343 case FC_BIND_PRIMITIVE: /* explicit primitive */
1344 pFormat += sizeof(NDR_EHD_PRIMITIVE);
1345 break;
1346 case FC_BIND_GENERIC: /* explicit generic */
1347 pFormat += sizeof(NDR_EHD_GENERIC);
1348 break;
1349 case FC_BIND_CONTEXT: /* explicit context */
1350 pFormat += sizeof(NDR_EHD_CONTEXT);
1351 break;
1352 default:
1353 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1354 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1356 break;
1357 case FC_BIND_GENERIC: /* implicit generic */
1358 case FC_BIND_PRIMITIVE: /* implicit primitive */
1359 case FC_CALLBACK_HANDLE: /* implicit callback */
1360 case FC_AUTO_HANDLE: /* implicit auto handle */
1361 break;
1362 default:
1363 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1364 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1367 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1368 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1369 else
1370 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1372 /* create the full pointer translation tables, if requested */
1373 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1374 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1376 /* store the RPC flags away */
1377 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1378 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1380 /* use alternate memory allocation routines */
1381 if (pProcHeader->Oi_flags & Oi_RPCSS_ALLOC_USED)
1382 #if 0
1383 NdrRpcSsEnableAllocate(&stubMsg);
1384 #else
1385 FIXME("Set RPCSS memory allocation routines\n");
1386 #endif
1388 TRACE("allocating memory for stack of size %x\n", stack_size);
1390 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1391 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1393 /* add the implicit This pointer as the first arg to the function if we
1394 * are calling an object method */
1395 if (pThis)
1396 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1398 if (is_oicf_stubdesc(pStubDesc))
1400 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader = (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1402 Oif_flags = pOIFHeader->Oi2Flags;
1403 number_of_params = pOIFHeader->number_of_params;
1405 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1407 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1409 if (Oif_flags.HasExtensions)
1411 const NDR_PROC_HEADER_EXTS *pExtensions = (const NDR_PROC_HEADER_EXTS *)pFormat;
1412 ext_flags = pExtensions->Flags2;
1413 pFormat += pExtensions->Size;
1416 if (Oif_flags.HasPipes)
1418 FIXME("pipes not supported yet\n");
1419 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1420 /* init pipes package */
1421 /* NdrPipesInitialize(...) */
1423 if (ext_flags.HasNewCorrDesc)
1425 /* initialize extra correlation package */
1426 NdrCorrelationInitialize(&stubMsg, NdrCorrCache, sizeof(NdrCorrCache), 0);
1427 if (ext_flags.Unused & 0x2) /* has range on conformance */
1428 stubMsg.CorrDespIncrement = 12;
1431 else
1433 pFormat = convert_old_args( &stubMsg, pFormat, stack_size,
1434 pProcHeader->Oi_flags & Oi_OBJECT_PROC,
1435 /* reuse the correlation cache, it's not needed for v1 format */
1436 NdrCorrCache, sizeof(NdrCorrCache), &number_of_params );
1439 /* convert strings, floating point values and endianness into our
1440 * preferred format */
1441 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1442 NdrConvert(&stubMsg, pFormat);
1444 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_FREE; phase++)
1446 TRACE("phase = %d\n", phase);
1447 switch (phase)
1449 case STUBLESS_CALLSERVER:
1450 /* call the server function */
1451 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1452 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1453 else
1455 SERVER_ROUTINE func;
1456 LONG_PTR retval;
1458 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1460 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1461 func = vtbl[pRpcMsg->ProcNum];
1463 else
1464 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1466 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1467 retval = call_server_func(func, args, stack_size);
1469 if (retval_ptr)
1471 TRACE("stub implementation returned 0x%lx\n", retval);
1472 *retval_ptr = retval;
1474 else
1475 TRACE("void stub implementation\n");
1478 stubMsg.Buffer = NULL;
1479 stubMsg.BufferLength = 0;
1481 break;
1482 case STUBLESS_GETBUFFER:
1483 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1484 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1485 else
1487 RPC_STATUS Status;
1489 pRpcMsg->BufferLength = stubMsg.BufferLength;
1490 /* allocate buffer for [out] and [ret] params */
1491 Status = I_RpcGetBuffer(pRpcMsg);
1492 if (Status)
1493 RpcRaiseException(Status);
1494 stubMsg.Buffer = pRpcMsg->Buffer;
1496 break;
1497 case STUBLESS_UNMARSHAL:
1498 case STUBLESS_INITOUT:
1499 case STUBLESS_CALCSIZE:
1500 case STUBLESS_MARSHAL:
1501 case STUBLESS_MUSTFREE:
1502 case STUBLESS_FREE:
1503 retval_ptr = stub_do_args(&stubMsg, pFormat, phase, number_of_params);
1504 break;
1505 default:
1506 ERR("shouldn't reach here. phase %d\n", phase);
1507 break;
1511 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1513 if (ext_flags.HasNewCorrDesc)
1515 /* free extra correlation package */
1516 NdrCorrelationFree(&stubMsg);
1519 if (Oif_flags.HasPipes)
1521 /* NdrPipesDone(...) */
1524 /* free the full pointer translation tables */
1525 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1526 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1528 /* free server function stack */
1529 HeapFree(GetProcessHeap(), 0, args);
1531 return S_OK;
1534 /***********************************************************************
1535 * NdrServerCall2 [RPCRT4.@]
1537 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1539 DWORD dwPhase;
1540 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);
1543 /***********************************************************************
1544 * NdrStubCall [RPCRT4.@]
1546 LONG WINAPI NdrStubCall( struct IRpcStubBuffer *This, struct IRpcChannelBuffer *channel,
1547 PRPC_MESSAGE msg, DWORD *phase )
1549 return NdrStubCall2( This, channel, msg, phase );
1552 /***********************************************************************
1553 * NdrServerCall [RPCRT4.@]
1555 void WINAPI NdrServerCall( PRPC_MESSAGE msg )
1557 DWORD phase;
1558 NdrStubCall( NULL, NULL, msg, &phase );
1561 /***********************************************************************
1562 * NdrServerCallAll [RPCRT4.@]
1564 void WINAPI NdrServerCallAll( PRPC_MESSAGE msg )
1566 FIXME("%p stub\n", msg);
1569 struct async_call_data
1571 MIDL_STUB_MESSAGE *pStubMsg;
1572 const NDR_PROC_HEADER *pProcHeader;
1573 PFORMAT_STRING pHandleFormat;
1574 PFORMAT_STRING pParamFormat;
1575 RPC_BINDING_HANDLE hBinding;
1576 /* size of stack */
1577 unsigned short stack_size;
1578 /* number of parameters. optional for client to give it to us */
1579 unsigned int number_of_params;
1580 /* correlation cache */
1581 ULONG_PTR NdrCorrCache[256];
1584 LONG_PTR CDECL DECLSPEC_HIDDEN ndr_async_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
1585 void **stack_top )
1587 /* pointer to start of stack where arguments start */
1588 PRPC_MESSAGE pRpcMsg;
1589 PMIDL_STUB_MESSAGE pStubMsg;
1590 RPC_ASYNC_STATE *pAsync;
1591 struct async_call_data *async_call_data;
1592 /* procedure number */
1593 unsigned short procedure_number;
1594 /* cache of Oif_flags from v2 procedure header */
1595 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
1596 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1597 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
1598 /* header for procedure string */
1599 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1600 RPC_STATUS status;
1602 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
1604 /* Later NDR language versions probably won't be backwards compatible */
1605 if (pStubDesc->Version > 0x50002)
1607 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc->Version);
1608 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1611 async_call_data = I_RpcAllocate(sizeof(*async_call_data) + sizeof(MIDL_STUB_MESSAGE) + sizeof(RPC_MESSAGE));
1612 if (!async_call_data) RpcRaiseException(RPC_X_NO_MEMORY);
1613 async_call_data->pProcHeader = pProcHeader;
1615 async_call_data->pStubMsg = pStubMsg = (PMIDL_STUB_MESSAGE)(async_call_data + 1);
1616 pRpcMsg = (PRPC_MESSAGE)(pStubMsg + 1);
1618 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1620 const NDR_PROC_HEADER_RPC *header_rpc = (const NDR_PROC_HEADER_RPC *)&pFormat[0];
1621 async_call_data->stack_size = header_rpc->stack_size;
1622 procedure_number = header_rpc->proc_num;
1623 pFormat += sizeof(NDR_PROC_HEADER_RPC);
1625 else
1627 async_call_data->stack_size = pProcHeader->stack_size;
1628 procedure_number = pProcHeader->proc_num;
1629 pFormat += sizeof(NDR_PROC_HEADER);
1631 TRACE("stack size: 0x%x\n", async_call_data->stack_size);
1632 TRACE("proc num: %d\n", procedure_number);
1634 /* create the full pointer translation tables, if requested */
1635 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1636 pStubMsg->FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
1638 if (pProcHeader->Oi_flags & Oi_OBJECT_PROC)
1640 ERR("objects not supported\n");
1641 I_RpcFree(async_call_data);
1642 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1645 NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDesc, procedure_number);
1647 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1648 TRACE("MIDL stub version = 0x%x\n", pStubDesc->MIDLVersion);
1650 /* needed for conformance of top-level objects */
1651 pStubMsg->StackTop = I_RpcAllocate(async_call_data->stack_size);
1652 memcpy(pStubMsg->StackTop, stack_top, async_call_data->stack_size);
1654 pAsync = *(RPC_ASYNC_STATE **)pStubMsg->StackTop;
1655 pAsync->StubInfo = async_call_data;
1656 async_call_data->pHandleFormat = pFormat;
1658 pFormat = client_get_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, &async_call_data->hBinding);
1659 if (!pFormat) goto done;
1661 if (is_oicf_stubdesc(pStubDesc))
1663 const NDR_PROC_PARTIAL_OIF_HEADER *pOIFHeader =
1664 (const NDR_PROC_PARTIAL_OIF_HEADER *)pFormat;
1666 Oif_flags = pOIFHeader->Oi2Flags;
1667 async_call_data->number_of_params = pOIFHeader->number_of_params;
1669 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1671 TRACE("Oif_flags = %s\n", debugstr_INTERPRETER_OPT_FLAGS(Oif_flags) );
1673 if (Oif_flags.HasExtensions)
1675 const NDR_PROC_HEADER_EXTS *pExtensions =
1676 (const NDR_PROC_HEADER_EXTS *)pFormat;
1677 ext_flags = pExtensions->Flags2;
1678 pFormat += pExtensions->Size;
1681 else
1683 pFormat = convert_old_args( pStubMsg, pFormat, async_call_data->stack_size,
1684 pProcHeader->Oi_flags & Oi_OBJECT_PROC,
1685 async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache),
1686 &async_call_data->number_of_params );
1689 async_call_data->pParamFormat = pFormat;
1691 pStubMsg->BufferLength = 0;
1693 /* store the RPC flags away */
1694 if (pProcHeader->Oi_flags & Oi_HAS_RPCFLAGS)
1695 pRpcMsg->RpcFlags = ((const NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1697 /* use alternate memory allocation routines */
1698 if (pProcHeader->Oi_flags & Oi_RPCSS_ALLOC_USED)
1699 NdrRpcSmSetClientToOsf(pStubMsg);
1701 if (Oif_flags.HasPipes)
1703 FIXME("pipes not supported yet\n");
1704 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1705 /* init pipes package */
1706 /* NdrPipesInitialize(...) */
1708 if (ext_flags.HasNewCorrDesc)
1710 /* initialize extra correlation package */
1711 NdrCorrelationInitialize(pStubMsg, async_call_data->NdrCorrCache, sizeof(async_call_data->NdrCorrCache), 0);
1712 if (ext_flags.Unused & 0x2) /* has range on conformance */
1713 pStubMsg->CorrDespIncrement = 12;
1716 /* order of phases:
1717 * 1. CALCSIZE - calculate the buffer size
1718 * 2. GETBUFFER - allocate the buffer
1719 * 3. MARSHAL - marshal [in] params into the buffer
1720 * 4. SENDRECEIVE - send buffer
1721 * Then in NdrpCompleteAsyncClientCall:
1722 * 1. SENDRECEIVE - receive buffer
1723 * 2. UNMARSHAL - unmarshal [out] params from buffer
1726 /* 1. CALCSIZE */
1727 TRACE( "CALCSIZE\n" );
1728 client_do_args(pStubMsg, pFormat, STUBLESS_CALCSIZE, NULL, async_call_data->number_of_params, NULL);
1730 /* 2. GETBUFFER */
1731 TRACE( "GETBUFFER\n" );
1732 if (Oif_flags.HasPipes)
1733 /* NdrGetPipeBuffer(...) */
1734 FIXME("pipes not supported yet\n");
1735 else
1737 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
1738 #if 0
1739 NdrNsGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1740 #else
1741 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1742 #endif
1743 else
1744 NdrGetBuffer(pStubMsg, pStubMsg->BufferLength, async_call_data->hBinding);
1746 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1747 status = I_RpcAsyncSetHandle(pRpcMsg, pAsync);
1748 if (status != RPC_S_OK)
1749 RpcRaiseException(status);
1751 /* 3. MARSHAL */
1752 TRACE( "MARSHAL\n" );
1753 client_do_args(pStubMsg, pFormat, STUBLESS_MARSHAL, NULL, async_call_data->number_of_params, NULL);
1755 /* 4. SENDRECEIVE */
1756 TRACE( "SEND\n" );
1757 pRpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1758 /* send the [in] params only */
1759 if (Oif_flags.HasPipes)
1760 /* NdrPipesSend(...) */
1761 FIXME("pipes not supported yet\n");
1762 else
1764 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
1765 #if 0
1766 NdrNsSend(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1767 #else
1768 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1769 #endif
1770 else
1772 pStubMsg->RpcMsg->BufferLength = pStubMsg->Buffer - (unsigned char *)pStubMsg->RpcMsg->Buffer;
1773 status = I_RpcSend(pStubMsg->RpcMsg);
1774 if (status != RPC_S_OK)
1775 RpcRaiseException(status);
1779 done:
1780 TRACE("returning 0\n");
1781 return 0;
1784 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply)
1786 /* pointer to start of stack where arguments start */
1787 PMIDL_STUB_MESSAGE pStubMsg;
1788 struct async_call_data *async_call_data;
1789 /* header for procedure string */
1790 const NDR_PROC_HEADER * pProcHeader;
1791 RPC_STATUS status = RPC_S_OK;
1793 if (!pAsync->StubInfo)
1794 return RPC_S_INVALID_ASYNC_HANDLE;
1796 async_call_data = pAsync->StubInfo;
1797 pStubMsg = async_call_data->pStubMsg;
1798 pProcHeader = async_call_data->pProcHeader;
1800 /* order of phases:
1801 * 1. CALCSIZE - calculate the buffer size
1802 * 2. GETBUFFER - allocate the buffer
1803 * 3. MARSHAL - marshal [in] params into the buffer
1804 * 4. SENDRECEIVE - send buffer
1805 * Then in NdrpCompleteAsyncClientCall:
1806 * 1. SENDRECEIVE - receive buffer
1807 * 2. UNMARSHAL - unmarshal [out] params from buffer
1810 /* 1. SENDRECEIVE */
1811 TRACE( "RECEIVE\n" );
1812 pStubMsg->RpcMsg->RpcFlags |= RPC_BUFFER_ASYNC;
1813 /* receive the [out] params */
1814 if (pProcHeader->handle_type == FC_AUTO_HANDLE)
1815 #if 0
1816 NdrNsReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
1817 #else
1818 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1819 #endif
1820 else
1822 status = I_RpcReceive(pStubMsg->RpcMsg);
1823 if (status != RPC_S_OK)
1824 goto cleanup;
1825 pStubMsg->BufferLength = pStubMsg->RpcMsg->BufferLength;
1826 pStubMsg->BufferStart = pStubMsg->RpcMsg->Buffer;
1827 pStubMsg->BufferEnd = pStubMsg->BufferStart + pStubMsg->BufferLength;
1828 pStubMsg->Buffer = pStubMsg->BufferStart;
1831 /* convert strings, floating point values and endianness into our
1832 * preferred format */
1833 #if 0
1834 if ((pStubMsg->RpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1835 NdrConvert(pStubMsg, pFormat);
1836 #endif
1838 /* 2. UNMARSHAL */
1839 TRACE( "UNMARSHAL\n" );
1840 client_do_args(pStubMsg, async_call_data->pParamFormat, STUBLESS_UNMARSHAL,
1841 NULL, async_call_data->number_of_params, Reply);
1843 cleanup:
1844 if (pStubMsg->fHasNewCorrDesc)
1846 /* free extra correlation package */
1847 NdrCorrelationFree(pStubMsg);
1850 /* free the full pointer translation tables */
1851 if (pProcHeader->Oi_flags & Oi_FULL_PTR_USED)
1852 NdrFullPointerXlatFree(pStubMsg->FullPtrXlatTables);
1854 /* free marshalling buffer */
1855 NdrFreeBuffer(pStubMsg);
1856 client_free_handle(pStubMsg, pProcHeader, async_call_data->pHandleFormat, async_call_data->hBinding);
1858 I_RpcFree(pStubMsg->StackTop);
1859 I_RpcFree(async_call_data);
1861 TRACE("-- 0x%x\n", status);
1862 return status;
1865 #ifdef __x86_64__
1867 __ASM_GLOBAL_FUNC( NdrAsyncClientCall,
1868 "movq %r8,0x18(%rsp)\n\t"
1869 "movq %r9,0x20(%rsp)\n\t"
1870 "leaq 0x18(%rsp),%r8\n\t"
1871 "subq $0x28,%rsp\n\t"
1872 __ASM_CFI(".cfi_adjust_cfa_offset 0x28\n\t")
1873 "call " __ASM_NAME("ndr_async_client_call") "\n\t"
1874 "addq $0x28,%rsp\n\t"
1875 __ASM_CFI(".cfi_adjust_cfa_offset -0x28\n\t")
1876 "ret" );
1878 #else /* __x86_64__ */
1880 /***********************************************************************
1881 * NdrAsyncClientCall [RPCRT4.@]
1883 CLIENT_CALL_RETURN WINAPIV NdrAsyncClientCall( PMIDL_STUB_DESC desc, PFORMAT_STRING format, ... )
1885 __ms_va_list args;
1886 LONG_PTR ret;
1888 __ms_va_start( args, format );
1889 ret = ndr_async_client_call( desc, format, va_arg( args, void ** ));
1890 __ms_va_end( args );
1891 return *(CLIENT_CALL_RETURN *)&ret;
1894 #endif /* __x86_64__ */
1896 RPCRTAPI LONG RPC_ENTRY NdrAsyncStubCall(struct IRpcStubBuffer* pThis,
1897 struct IRpcChannelBuffer* pChannel, PRPC_MESSAGE pRpcMsg,
1898 DWORD * pdwStubPhase)
1900 FIXME("unimplemented, expect crash!\n");
1901 return 0;
1904 void RPC_ENTRY NdrAsyncServerCall(PRPC_MESSAGE pRpcMsg)
1906 FIXME("unimplemented, %p\n", pRpcMsg);