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
23 * - Some types of binding handles
27 #include "wine/port.h"
41 #include "wine/exception.h"
42 #include "wine/debug.h"
43 #include "wine/rpcfc.h"
47 #include "ndr_stubless.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
51 #define NDR_TABLE_MASK 127
53 static inline void call_buffer_sizer(PMIDL_STUB_MESSAGE pStubMsg
, unsigned char *pMemory
, PFORMAT_STRING pFormat
)
55 NDR_BUFFERSIZE m
= NdrBufferSizer
[pFormat
[0] & NDR_TABLE_MASK
];
56 if (m
) m(pStubMsg
, pMemory
, pFormat
);
59 FIXME("format type 0x%x not implemented\n", pFormat
[0]);
60 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
64 static inline unsigned char *call_marshaller(PMIDL_STUB_MESSAGE pStubMsg
, unsigned char *pMemory
, PFORMAT_STRING pFormat
)
66 NDR_MARSHALL m
= NdrMarshaller
[pFormat
[0] & NDR_TABLE_MASK
];
67 if (m
) return m(pStubMsg
, pMemory
, pFormat
);
70 FIXME("format type 0x%x not implemented\n", pFormat
[0]);
71 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
76 static inline unsigned char *call_unmarshaller(PMIDL_STUB_MESSAGE pStubMsg
, unsigned char **ppMemory
, PFORMAT_STRING pFormat
, unsigned char fMustAlloc
)
78 NDR_UNMARSHALL m
= NdrUnmarshaller
[pFormat
[0] & NDR_TABLE_MASK
];
79 if (m
) return m(pStubMsg
, ppMemory
, pFormat
, fMustAlloc
);
82 FIXME("format type 0x%x not implemented\n", pFormat
[0]);
83 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
88 static inline void call_freer(PMIDL_STUB_MESSAGE pStubMsg
, unsigned char *pMemory
, PFORMAT_STRING pFormat
)
90 NDR_FREE m
= NdrFreer
[pFormat
[0] & NDR_TABLE_MASK
];
91 if (m
) m(pStubMsg
, pMemory
, pFormat
);
94 #define STUBLESS_UNMARSHAL 1
95 #define STUBLESS_INITOUT 2
96 #define STUBLESS_CALLSERVER 3
97 #define STUBLESS_CALCSIZE 4
98 #define STUBLESS_GETBUFFER 5
99 #define STUBLESS_MARSHAL 6
100 #define STUBLESS_FREE 7
102 void WINAPI
NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage
)
104 #if 0 /* these functions are not defined yet */
105 pMessage
->pfnAllocate
= NdrRpcSmClientAllocate
;
106 pMessage
->pfnFree
= NdrRpcSmClientFree
;
110 static void dump_RPC_FC_PROC_PF(PARAM_ATTRIBUTES param_attributes
)
112 if (param_attributes
.MustSize
) TRACE(" MustSize");
113 if (param_attributes
.MustFree
) TRACE(" MustFree");
114 if (param_attributes
.IsPipe
) TRACE(" IsPipe");
115 if (param_attributes
.IsIn
) TRACE(" IsIn");
116 if (param_attributes
.IsOut
) TRACE(" IsOut");
117 if (param_attributes
.IsReturn
) TRACE(" IsReturn");
118 if (param_attributes
.IsBasetype
) TRACE(" IsBasetype");
119 if (param_attributes
.IsByValue
) TRACE(" IsByValue");
120 if (param_attributes
.IsSimpleRef
) TRACE(" IsSimpleRef");
121 if (param_attributes
.IsDontCallFreeInst
) TRACE(" IsDontCallFreeInst");
122 if (param_attributes
.SaveForAsyncFinish
) TRACE(" SaveForAsyncFinish");
123 if (param_attributes
.ServerAllocSize
) TRACE(" ServerAllocSize = %d", param_attributes
.ServerAllocSize
* 8);
126 static void dump_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags
)
128 if (Oi2Flags
.ServerMustSize
) TRACE(" ServerMustSize");
129 if (Oi2Flags
.ClientMustSize
) TRACE(" ClientMustSize");
130 if (Oi2Flags
.HasReturn
) TRACE(" HasReturn");
131 if (Oi2Flags
.HasPipes
) TRACE(" HasPipes");
132 if (Oi2Flags
.Unused
) TRACE(" Unused");
133 if (Oi2Flags
.HasAsyncUuid
) TRACE(" HasAsyncUuid");
134 if (Oi2Flags
.HasExtensions
) TRACE(" HasExtensions");
135 if (Oi2Flags
.HasAsyncHandle
) TRACE(" HasAsyncHandle");
139 #define ARG_FROM_OFFSET(args, offset) ((args) + (offset))
141 static PFORMAT_STRING
client_get_handle(
142 PMIDL_STUB_MESSAGE pStubMsg
, const NDR_PROC_HEADER
*pProcHeader
,
143 PFORMAT_STRING pFormat
, handle_t
*phBinding
)
146 switch (pProcHeader
->handle_type
)
148 /* explicit binding: parse additional section */
149 case RPC_FC_BIND_EXPLICIT
:
150 switch (*pFormat
) /* handle_type */
152 case RPC_FC_BIND_PRIMITIVE
: /* explicit primitive */
154 const NDR_EHD_PRIMITIVE
*pDesc
= (const NDR_EHD_PRIMITIVE
*)pFormat
;
156 TRACE("Explicit primitive handle @ %d\n", pDesc
->offset
);
158 if (pDesc
->flag
) /* pointer to binding */
159 *phBinding
= **(handle_t
**)ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
161 *phBinding
= *(handle_t
*)ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
162 return pFormat
+ sizeof(NDR_EHD_PRIMITIVE
);
164 case RPC_FC_BIND_GENERIC
: /* explicit generic */
166 const NDR_EHD_GENERIC
*pDesc
= (const NDR_EHD_GENERIC
*)pFormat
;
167 void *pObject
= NULL
;
169 const GENERIC_BINDING_ROUTINE_PAIR
*pGenPair
;
171 TRACE("Explicit generic binding handle #%d\n", pDesc
->binding_routine_pair_index
);
173 if (pDesc
->flag_and_size
& HANDLE_PARAM_IS_VIA_PTR
)
174 pArg
= *(void **)ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
176 pArg
= ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
177 memcpy(&pObject
, pArg
, pDesc
->flag_and_size
& 0xf);
178 pGenPair
= &pStubMsg
->StubDesc
->aGenericBindingRoutinePairs
[pDesc
->binding_routine_pair_index
];
179 *phBinding
= pGenPair
->pfnBind(pObject
);
180 return pFormat
+ sizeof(NDR_EHD_GENERIC
);
182 case RPC_FC_BIND_CONTEXT
: /* explicit context */
184 const NDR_EHD_CONTEXT
*pDesc
= (const NDR_EHD_CONTEXT
*)pFormat
;
185 NDR_CCONTEXT context_handle
;
186 TRACE("Explicit bind context\n");
187 if (pDesc
->flags
& HANDLE_PARAM_IS_VIA_PTR
)
189 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
190 context_handle
= **(NDR_CCONTEXT
**)ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
193 context_handle
= *(NDR_CCONTEXT
*)ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
194 if ((pDesc
->flags
& NDR_CONTEXT_HANDLE_CANNOT_BE_NULL
) &&
197 ERR("null context handle isn't allowed\n");
198 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT
);
201 *phBinding
= NDRCContextBinding(context_handle
);
202 /* FIXME: should we store this structure in stubMsg.pContext? */
203 return pFormat
+ sizeof(NDR_EHD_CONTEXT
);
206 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
207 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
210 case RPC_FC_BIND_GENERIC
: /* implicit generic */
211 FIXME("RPC_FC_BIND_GENERIC\n");
212 RpcRaiseException(RPC_X_BAD_STUB_DATA
); /* FIXME: remove when implemented */
214 case RPC_FC_BIND_PRIMITIVE
: /* implicit primitive */
215 TRACE("Implicit primitive handle\n");
216 *phBinding
= *pStubMsg
->StubDesc
->IMPLICIT_HANDLE_INFO
.pPrimitiveHandle
;
218 case RPC_FC_CALLBACK_HANDLE
: /* implicit callback */
219 FIXME("RPC_FC_CALLBACK_HANDLE\n");
221 case RPC_FC_AUTO_HANDLE
: /* implicit auto handle */
222 /* strictly speaking, it isn't necessary to set hBinding here
223 * since it isn't actually used (hence the automatic in its name),
224 * but then why does MIDL generate a valid entry in the
225 * MIDL_STUB_DESC for it? */
226 TRACE("Implicit auto handle\n");
227 *phBinding
= *pStubMsg
->StubDesc
->IMPLICIT_HANDLE_INFO
.pAutoHandle
;
230 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
231 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
236 static void client_free_handle(
237 PMIDL_STUB_MESSAGE pStubMsg
, const NDR_PROC_HEADER
*pProcHeader
,
238 PFORMAT_STRING pFormat
, handle_t hBinding
)
241 switch (pProcHeader
->handle_type
)
243 /* explicit binding: parse additional section */
244 case RPC_FC_BIND_EXPLICIT
:
245 switch (*pFormat
) /* handle_type */
247 case RPC_FC_BIND_GENERIC
: /* explicit generic */
249 const NDR_EHD_GENERIC
*pDesc
= (const NDR_EHD_GENERIC
*)pFormat
;
250 void *pObject
= NULL
;
252 const GENERIC_BINDING_ROUTINE_PAIR
*pGenPair
;
254 TRACE("Explicit generic binding handle #%d\n", pDesc
->binding_routine_pair_index
);
256 if (pDesc
->flag_and_size
& HANDLE_PARAM_IS_VIA_PTR
)
257 pArg
= *(void **)ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
259 pArg
= ARG_FROM_OFFSET(pStubMsg
->StackTop
, pDesc
->offset
);
260 memcpy(&pObject
, pArg
, pDesc
->flag_and_size
& 0xf);
261 pGenPair
= &pStubMsg
->StubDesc
->aGenericBindingRoutinePairs
[pDesc
->binding_routine_pair_index
];
262 pGenPair
->pfnUnbind(pObject
, hBinding
);
265 case RPC_FC_BIND_CONTEXT
: /* explicit context */
266 case RPC_FC_BIND_PRIMITIVE
: /* explicit primitive */
269 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
270 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
273 case RPC_FC_BIND_GENERIC
: /* implicit generic */
274 FIXME("RPC_FC_BIND_GENERIC\n");
275 RpcRaiseException(RPC_X_BAD_STUB_DATA
); /* FIXME: remove when implemented */
277 case RPC_FC_CALLBACK_HANDLE
: /* implicit callback */
278 case RPC_FC_BIND_PRIMITIVE
: /* implicit primitive */
279 case RPC_FC_AUTO_HANDLE
: /* implicit auto handle */
282 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
283 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
287 static void client_do_args(PMIDL_STUB_MESSAGE pStubMsg
, PFORMAT_STRING pFormat
,
288 int phase
, unsigned char *args
, unsigned short number_of_params
,
289 unsigned char *pRetVal
)
291 /* current format string offset */
292 int current_offset
= 0;
293 /* current stack offset */
294 unsigned short current_stack_offset
= 0;
298 for (i
= 0; i
< number_of_params
; i
++)
300 const NDR_PARAM_OIF_BASETYPE
*pParam
=
301 (const NDR_PARAM_OIF_BASETYPE
*)&pFormat
[current_offset
];
302 unsigned char * pArg
;
304 current_stack_offset
= pParam
->stack_offset
;
305 pArg
= ARG_FROM_OFFSET(args
, current_stack_offset
);
307 TRACE("param[%d]: new format\n", i
);
308 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam
->param_attributes
); TRACE("\n");
309 TRACE("\tstack_offset: 0x%x\n", current_stack_offset
);
310 TRACE("\tmemory addr (before): %p\n", pArg
);
312 if (pParam
->param_attributes
.IsBasetype
)
314 const unsigned char * pTypeFormat
=
315 &pParam
->type_format_char
;
317 if (pParam
->param_attributes
.IsSimpleRef
)
318 pArg
= *(unsigned char **)pArg
;
320 TRACE("\tbase type: 0x%02x\n", *pTypeFormat
);
325 if (pParam
->param_attributes
.IsIn
)
326 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
329 if (pParam
->param_attributes
.IsIn
)
330 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
332 case PROXY_UNMARSHAL
:
333 if (pParam
->param_attributes
.IsOut
)
335 if (pParam
->param_attributes
.IsReturn
)
336 call_unmarshaller(pStubMsg
, &pRetVal
, pTypeFormat
, 0);
338 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
339 TRACE("pRetVal = %p\n", pRetVal
);
343 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
346 current_offset
+= sizeof(NDR_PARAM_OIF_BASETYPE
);
350 const NDR_PARAM_OIF_OTHER
*pParamOther
=
351 (const NDR_PARAM_OIF_OTHER
*)&pFormat
[current_offset
];
353 const unsigned char * pTypeFormat
=
354 &(pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
]);
356 /* if a simple ref pointer then we have to do the
357 * check for the pointer being non-NULL. */
358 if (pParam
->param_attributes
.IsSimpleRef
)
360 if (!*(unsigned char **)pArg
)
361 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
364 TRACE("\tcomplex type: 0x%02x\n", *pTypeFormat
);
369 if (pParam
->param_attributes
.IsIn
)
371 if (pParam
->param_attributes
.IsByValue
)
372 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
374 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
378 if (pParam
->param_attributes
.IsIn
)
380 if (pParam
->param_attributes
.IsByValue
)
381 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
383 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
386 case PROXY_UNMARSHAL
:
387 if (pParam
->param_attributes
.IsOut
)
389 if (pParam
->param_attributes
.IsReturn
)
390 call_unmarshaller(pStubMsg
, &pRetVal
, pTypeFormat
, 0);
391 else if (pParam
->param_attributes
.IsByValue
)
392 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
394 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
398 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
401 current_offset
+= sizeof(NDR_PARAM_OIF_OTHER
);
403 TRACE("\tmemory addr (after): %p\n", pArg
);
407 static unsigned int type_stack_size(unsigned char fc
)
419 return sizeof(short);
426 return sizeof(float);
428 return sizeof(double);
430 return sizeof(ULONGLONG
);
431 case RPC_FC_ERROR_STATUS_T
:
432 return sizeof(error_status_t
);
434 return sizeof(void *);
436 ERR("invalid base type 0x%x\n", fc
);
437 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
441 void client_do_args_old_format(PMIDL_STUB_MESSAGE pStubMsg
,
442 PFORMAT_STRING pFormat
, int phase
, unsigned char *args
,
443 unsigned short stack_size
,
444 unsigned char *pRetVal
, BOOL object_proc
, BOOL ignore_retval
)
446 /* current format string offset */
447 int current_offset
= 0;
448 /* current stack offset */
449 unsigned short current_stack_offset
= 0;
453 /* NOTE: V1 style format doesn't terminate on the number_of_params
454 * condition as it doesn't have this attribute. Instead it
455 * terminates when the stack size given in the header is exceeded.
457 for (i
= 0; TRUE
; i
++)
459 const NDR_PARAM_OI_BASETYPE
*pParam
=
460 (const NDR_PARAM_OI_BASETYPE
*)&pFormat
[current_offset
];
461 /* note: current_stack_offset starts after the This pointer
462 * if present, so adjust this */
463 unsigned short current_stack_offset_adjusted
= current_stack_offset
+
464 (object_proc
? sizeof(void *) : 0);
465 unsigned char * pArg
= ARG_FROM_OFFSET(args
, current_stack_offset_adjusted
);
467 /* no more parameters; exit loop */
468 if (current_stack_offset_adjusted
>= stack_size
)
471 TRACE("param[%d]: old format\n", i
);
472 TRACE("\tparam_direction: 0x%x\n", pParam
->param_direction
);
473 TRACE("\tstack_offset: 0x%x\n", current_stack_offset_adjusted
);
474 TRACE("\tmemory addr (before): %p\n", pArg
);
476 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
||
477 pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
479 const unsigned char * pTypeFormat
=
480 &pParam
->type_format_char
;
482 TRACE("\tbase type 0x%02x\n", *pTypeFormat
);
487 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
488 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
491 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
492 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
494 case PROXY_UNMARSHAL
:
495 if (!ignore_retval
&&
496 pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
498 if (pParam
->param_direction
& RPC_FC_RETURN_PARAM
)
499 call_unmarshaller(pStubMsg
, &pRetVal
, pTypeFormat
, 0);
501 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
505 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
508 current_stack_offset
+= type_stack_size(*pTypeFormat
);
509 current_offset
+= sizeof(NDR_PARAM_OI_BASETYPE
);
513 const NDR_PARAM_OI_OTHER
*pParamOther
=
514 (const NDR_PARAM_OI_OTHER
*)&pFormat
[current_offset
];
516 const unsigned char *pTypeFormat
=
517 &pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
];
519 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat
);
524 if (pParam
->param_direction
== RPC_FC_IN_PARAM
||
525 pParam
->param_direction
& RPC_FC_IN_OUT_PARAM
)
526 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
529 if (pParam
->param_direction
== RPC_FC_IN_PARAM
||
530 pParam
->param_direction
& RPC_FC_IN_OUT_PARAM
)
531 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
533 case PROXY_UNMARSHAL
:
534 if (pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
535 pParam
->param_direction
== RPC_FC_OUT_PARAM
)
536 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
537 else if (pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
538 call_unmarshaller(pStubMsg
, (unsigned char **)pRetVal
, pTypeFormat
, 0);
541 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
544 current_stack_offset
+= pParamOther
->stack_size
* sizeof(INT
);
545 current_offset
+= sizeof(NDR_PARAM_OI_OTHER
);
547 TRACE("\tmemory addr (after): %p\n", pArg
);
551 /* the return type should be CLIENT_CALL_RETURN, but this is incompatible
552 * with the way gcc returns structures. "void *" should be the largest type
553 * that MIDL should allow you to return anyway */
554 LONG_PTR WINAPIV
NdrClientCall2(PMIDL_STUB_DESC pStubDesc
, PFORMAT_STRING pFormat
, ...)
556 /* pointer to start of stack where arguments start */
558 MIDL_STUB_MESSAGE stubMsg
;
559 handle_t hBinding
= NULL
;
560 /* procedure number */
561 unsigned short procedure_number
;
563 unsigned short stack_size
;
564 /* number of parameters. optional for client to give it to us */
565 unsigned char number_of_params
= ~0;
566 /* cache of Oif_flags from v2 procedure header */
567 INTERPRETER_OPT_FLAGS Oif_flags
= { 0 };
568 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
569 INTERPRETER_OPT_FLAGS2 ext_flags
= { 0 };
570 /* the type of pass we are currently doing */
572 /* header for procedure string */
573 const NDR_PROC_HEADER
* pProcHeader
= (const NDR_PROC_HEADER
*)&pFormat
[0];
574 /* -Oif or -Oicf generated format */
575 BOOL bV2Format
= FALSE
;
576 /* the value to return to the client from the remote procedure */
578 /* the pointer to the object when in OLE mode */
580 PFORMAT_STRING pHandleFormat
;
581 /* correlation cache */
582 unsigned long NdrCorrCache
[256];
584 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc
, pFormat
);
586 TRACE("NDR Version: 0x%x\n", pStubDesc
->Version
);
588 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
590 const NDR_PROC_HEADER_RPC
*pProcHeader
= (const NDR_PROC_HEADER_RPC
*)&pFormat
[0];
591 stack_size
= pProcHeader
->stack_size
;
592 procedure_number
= pProcHeader
->proc_num
;
593 pFormat
+= sizeof(NDR_PROC_HEADER_RPC
);
597 stack_size
= pProcHeader
->stack_size
;
598 procedure_number
= pProcHeader
->proc_num
;
599 pFormat
+= sizeof(NDR_PROC_HEADER
);
601 TRACE("stack size: 0x%x\n", stack_size
);
602 TRACE("proc num: %d\n", procedure_number
);
604 /* create the full pointer translation tables, if requested */
605 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
606 stubMsg
.FullPtrXlatTables
= NdrFullPointerXlatInit(0,XLAT_CLIENT
);
608 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
610 /* object is always the first argument */
611 This
= **(void *const **)(&pFormat
+1);
612 NdrProxyInitialize(This
, &rpcMsg
, &stubMsg
, pStubDesc
, procedure_number
);
615 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, pStubDesc
, procedure_number
);
617 TRACE("Oi_flags = 0x%02x\n", pProcHeader
->Oi_flags
);
618 TRACE("MIDL stub version = 0x%x\n", pStubDesc
->MIDLVersion
);
620 /* needed for conformance of top-level objects */
622 stubMsg
.StackTop
= *(unsigned char **)(&pFormat
+1);
624 # warning Stack not retrieved for your CPU architecture
627 pHandleFormat
= pFormat
;
629 /* we only need a handle if this isn't an object method */
630 if (!(pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
))
632 pFormat
= client_get_handle(&stubMsg
, pProcHeader
, pHandleFormat
, &hBinding
);
633 if (!pFormat
) return 0;
636 bV2Format
= (pStubDesc
->Version
>= 0x20000);
640 const NDR_PROC_PARTIAL_OIF_HEADER
*pOIFHeader
=
641 (const NDR_PROC_PARTIAL_OIF_HEADER
*)pFormat
;
643 Oif_flags
= pOIFHeader
->Oi2Flags
;
644 number_of_params
= pOIFHeader
->number_of_params
;
646 pFormat
+= sizeof(NDR_PROC_PARTIAL_OIF_HEADER
);
649 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags
);
651 if (Oif_flags
.HasExtensions
)
653 const NDR_PROC_HEADER_EXTS
*pExtensions
=
654 (const NDR_PROC_HEADER_EXTS
*)pFormat
;
655 ext_flags
= pExtensions
->Flags2
;
656 pFormat
+= pExtensions
->Size
;
659 stubMsg
.BufferLength
= 0;
661 /* store the RPC flags away */
662 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
663 rpcMsg
.RpcFlags
= ((const NDR_PROC_HEADER_RPC
*)pProcHeader
)->rpc_flags
;
665 /* use alternate memory allocation routines */
666 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCSSALLOC
)
667 NdrRpcSmSetClientToOsf(&stubMsg
);
669 if (Oif_flags
.HasPipes
)
671 FIXME("pipes not supported yet\n");
672 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
); /* FIXME: remove when implemented */
673 /* init pipes package */
674 /* NdrPipesInitialize(...) */
676 if (ext_flags
.HasNewCorrDesc
)
678 /* initialize extra correlation package */
679 NdrCorrelationInitialize(&stubMsg
, NdrCorrCache
, sizeof(NdrCorrCache
), 0);
683 * 1. PROXY_CALCSIZE - calculate the buffer size
684 * 2. PROXY_GETBUFFER - allocate the buffer
685 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
686 * 4. PROXY_SENDRECEIVE - send/receive buffer
687 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
689 if ((pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
) ||
690 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_HAS_COMM_OR_FAULT
))
694 for (phase
= PROXY_CALCSIZE
; phase
<= PROXY_UNMARSHAL
; phase
++)
696 TRACE("phase = %d\n", phase
);
699 case PROXY_GETBUFFER
:
700 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
702 /* allocate the buffer */
703 NdrProxyGetBuffer(This
, &stubMsg
);
707 /* allocate the buffer */
708 if (Oif_flags
.HasPipes
)
709 /* NdrGetPipeBuffer(...) */
710 FIXME("pipes not supported yet\n");
713 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
715 NdrNsGetBuffer(&stubMsg
, stubMsg
.BufferLength
, hBinding
);
717 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
720 NdrGetBuffer(&stubMsg
, stubMsg
.BufferLength
, hBinding
);
724 case PROXY_SENDRECEIVE
:
725 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
727 /* send the [in] params and receive the [out] and [retval]
729 NdrProxySendReceive(This
, &stubMsg
);
733 /* send the [in] params and receive the [out] and [retval]
735 if (Oif_flags
.HasPipes
)
736 /* NdrPipesSendReceive(...) */
737 FIXME("pipes not supported yet\n");
740 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
742 NdrNsSendReceive(&stubMsg
, stubMsg
.Buffer
, pStubDesc
->IMPLICIT_HANDLE_INFO
.pAutoHandle
);
744 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
747 NdrSendReceive(&stubMsg
, stubMsg
.Buffer
);
751 /* convert strings, floating point values and endianess into our
752 * preferred format */
753 if ((rpcMsg
.DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
754 NdrConvert(&stubMsg
, pFormat
);
759 case PROXY_UNMARSHAL
:
761 client_do_args(&stubMsg
, pFormat
, phase
, stubMsg
.StackTop
,
762 number_of_params
, (unsigned char *)&RetVal
);
764 client_do_args_old_format(&stubMsg
, pFormat
, phase
,
765 stubMsg
.StackTop
, stack_size
, (unsigned char *)&RetVal
,
766 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
), FALSE
);
769 ERR("shouldn't reach here. phase %d\n", phase
);
776 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
777 RetVal
= NdrProxyErrorHandler(GetExceptionCode());
780 const COMM_FAULT_OFFSETS
*comm_fault_offsets
= &pStubDesc
->CommFaultOffsets
[procedure_number
];
784 TRACE("comm_fault_offsets = {0x%hx, 0x%hx}\n", comm_fault_offsets
->CommOffset
, comm_fault_offsets
->FaultOffset
);
786 if (comm_fault_offsets
->CommOffset
== -1)
787 comm_status
= (ULONG
*)&RetVal
;
788 else if (comm_fault_offsets
->CommOffset
>= 0)
789 comm_status
= *(ULONG
**)ARG_FROM_OFFSET(stubMsg
.StackTop
, comm_fault_offsets
->CommOffset
);
793 if (comm_fault_offsets
->FaultOffset
== -1)
794 fault_status
= (ULONG
*)&RetVal
;
795 else if (comm_fault_offsets
->FaultOffset
>= 0)
796 fault_status
= *(ULONG
**)ARG_FROM_OFFSET(stubMsg
.StackTop
, comm_fault_offsets
->CommOffset
);
800 NdrMapCommAndFaultStatus(&stubMsg
, comm_status
, fault_status
,
809 * 1. PROXY_CALCSIZE - calculate the buffer size
810 * 2. PROXY_GETBUFFER - allocate the buffer
811 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
812 * 4. PROXY_SENDRECEIVE - send/receive buffer
813 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
815 for (phase
= PROXY_CALCSIZE
; phase
<= PROXY_UNMARSHAL
; phase
++)
817 TRACE("phase = %d\n", phase
);
820 case PROXY_GETBUFFER
:
821 /* allocate the buffer */
822 if (Oif_flags
.HasPipes
)
823 /* NdrGetPipeBuffer(...) */
824 FIXME("pipes not supported yet\n");
827 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
829 NdrNsGetBuffer(&stubMsg
, stubMsg
.BufferLength
, hBinding
);
831 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
834 NdrGetBuffer(&stubMsg
, stubMsg
.BufferLength
, hBinding
);
837 case PROXY_SENDRECEIVE
:
838 /* send the [in] params and receive the [out] and [retval]
840 if (Oif_flags
.HasPipes
)
841 /* NdrPipesSendReceive(...) */
842 FIXME("pipes not supported yet\n");
845 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
847 NdrNsSendReceive(&stubMsg
, stubMsg
.Buffer
, pStubDesc
->IMPLICIT_HANDLE_INFO
.pAutoHandle
);
849 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
852 NdrSendReceive(&stubMsg
, stubMsg
.Buffer
);
855 /* convert strings, floating point values and endianess into our
856 * preferred format */
857 if ((rpcMsg
.DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
858 NdrConvert(&stubMsg
, pFormat
);
863 case PROXY_UNMARSHAL
:
865 client_do_args(&stubMsg
, pFormat
, phase
, stubMsg
.StackTop
,
866 number_of_params
, (unsigned char *)&RetVal
);
868 client_do_args_old_format(&stubMsg
, pFormat
, phase
,
869 stubMsg
.StackTop
, stack_size
, (unsigned char *)&RetVal
,
870 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
), FALSE
);
873 ERR("shouldn't reach here. phase %d\n", phase
);
879 if (ext_flags
.HasNewCorrDesc
)
881 /* free extra correlation package */
882 NdrCorrelationFree(&stubMsg
);
885 if (Oif_flags
.HasPipes
)
887 /* NdrPipesDone(...) */
890 /* free the full pointer translation tables */
891 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
892 NdrFullPointerXlatFree(stubMsg
.FullPtrXlatTables
);
894 /* free marshalling buffer */
895 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
896 NdrProxyFreeBuffer(This
, &stubMsg
);
899 NdrFreeBuffer(&stubMsg
);
900 client_free_handle(&stubMsg
, pProcHeader
, pHandleFormat
, hBinding
);
903 TRACE("RetVal = 0x%lx\n", RetVal
);
908 /* Calls a function with the specified arguments, restoring the stack
909 * properly afterwards as we don't know the calling convention of the
911 #if defined __i386__ && defined _MSC_VER
912 __declspec(naked
) LONG_PTR __cdecl
call_server_func(SERVER_ROUTINE func
, unsigned char * args
, unsigned int stack_size
)
917 push edi
; Save registers
920 mov eax
, [ebp
+16] ; Get stack size
921 sub esp
, eax
; Make room in stack
for arguments
927 rep movsd
; Copy dword blocks
928 call
[ebp
+8] ; Call function
929 lea esp
, [ebp
-8] ; Restore stack
930 pop esi
; Restore registers
936 #elif defined __i386__ && defined __GNUC__
937 LONG_PTR __cdecl
call_server_func(SERVER_ROUTINE func
, unsigned char * args
, unsigned int stack_size
);
938 __ASM_GLOBAL_FUNC(call_server_func
,
940 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
941 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
943 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
944 "pushl %edi\n\t" /* Save registers */
945 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
947 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
948 "movl 16(%ebp), %eax\n\t" /* Get stack size */
949 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
950 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
951 "movl %esp, %edi\n\t"
952 "movl %eax, %ecx\n\t"
953 "movl 12(%ebp), %esi\n\t"
954 "shrl $2, %ecx\n\t" /* divide by 4 */
956 "rep; movsl\n\t" /* Copy dword blocks */
957 "call *8(%ebp)\n\t" /* Call function */
958 "leal -8(%ebp), %esp\n\t" /* Restore stack */
959 "popl %esi\n\t" /* Restore registers */
960 __ASM_CFI(".cfi_same_value %esi\n\t")
962 __ASM_CFI(".cfi_same_value %edi\n\t")
964 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
965 __ASM_CFI(".cfi_same_value %ebp\n\t")
968 #warning call_server_func not implemented for your architecture
969 LONG_PTR __cdecl
call_server_func(SERVER_ROUTINE func
, unsigned char * args
, unsigned short stack_size
)
971 FIXME("Not implemented for your architecture\n");
976 static DWORD
calc_arg_size(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
982 size
= *(const WORD
*)(pFormat
+ 2);
985 size
= *(const WORD
*)(pFormat
+ 2);
986 ComputeConformance(pStubMsg
, NULL
, pFormat
+ 4, 0);
987 size
*= pStubMsg
->MaxCount
;
989 case RPC_FC_SMFARRAY
:
990 size
= *(const WORD
*)(pFormat
+ 2);
992 case RPC_FC_LGFARRAY
:
993 size
= *(const DWORD
*)(pFormat
+ 2);
995 case RPC_FC_BOGUS_ARRAY
:
996 pFormat
= ComputeConformance(pStubMsg
, NULL
, pFormat
+ 4, *(const WORD
*)&pFormat
[2]);
997 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
998 pFormat
= ComputeVariance(pStubMsg
, NULL
, pFormat
, pStubMsg
->MaxCount
);
999 size
= ComplexStructSize(pStubMsg
, pFormat
);
1000 size
*= pStubMsg
->MaxCount
;
1003 FIXME("Unhandled type %02x\n", *pFormat
);
1006 size
= sizeof(void *);
1012 static LONG_PTR
*stub_do_args(MIDL_STUB_MESSAGE
*pStubMsg
,
1013 PFORMAT_STRING pFormat
, int phase
,
1014 unsigned char *args
,
1015 unsigned short number_of_params
)
1019 /* current format string offset */
1020 int current_offset
= 0;
1021 /* current stack offset */
1022 unsigned short current_stack_offset
= 0;
1023 /* location to put retval into */
1024 LONG_PTR
*retval_ptr
= NULL
;
1026 for (i
= 0; i
< number_of_params
; i
++)
1028 const NDR_PARAM_OIF_BASETYPE
*pParam
=
1029 (const NDR_PARAM_OIF_BASETYPE
*)&pFormat
[current_offset
];
1030 unsigned char *pArg
;
1032 current_stack_offset
= pParam
->stack_offset
;
1033 pArg
= args
+ current_stack_offset
;
1035 TRACE("param[%d]: new format\n", i
);
1036 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam
->param_attributes
); TRACE("\n");
1037 TRACE("\tstack_offset: 0x%x\n", current_stack_offset
);
1038 TRACE("\tmemory addr (before): %p -> %p\n", pArg
, *(unsigned char **)pArg
);
1040 if (pParam
->param_attributes
.IsBasetype
)
1042 const unsigned char *pTypeFormat
=
1043 &pParam
->type_format_char
;
1045 TRACE("\tbase type: 0x%02x\n", *pTypeFormat
);
1047 /* make a note of the address of the return value parameter for later */
1048 if (pParam
->param_attributes
.IsReturn
)
1049 retval_ptr
= (LONG_PTR
*)pArg
;
1053 case STUBLESS_MARSHAL
:
1054 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1056 if (pParam
->param_attributes
.IsSimpleRef
)
1057 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1059 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
1063 if (pParam
->param_attributes
.ServerAllocSize
)
1064 HeapFree(GetProcessHeap(), 0, *(void **)pArg
);
1066 case STUBLESS_INITOUT
:
1068 case STUBLESS_UNMARSHAL
:
1069 if (pParam
->param_attributes
.ServerAllocSize
)
1070 *(void **)pArg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1071 pParam
->param_attributes
.ServerAllocSize
* 8);
1073 if (pParam
->param_attributes
.IsIn
)
1075 if (pParam
->param_attributes
.IsSimpleRef
)
1076 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
1078 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
1081 case STUBLESS_CALCSIZE
:
1082 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1084 if (pParam
->param_attributes
.IsSimpleRef
)
1085 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1087 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
1091 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1094 current_offset
+= sizeof(NDR_PARAM_OIF_BASETYPE
);
1098 const NDR_PARAM_OIF_OTHER
*pParamOther
=
1099 (const NDR_PARAM_OIF_OTHER
*)&pFormat
[current_offset
];
1101 const unsigned char * pTypeFormat
=
1102 &(pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
]);
1104 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat
);
1108 case STUBLESS_MARSHAL
:
1109 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1111 if (pParam
->param_attributes
.IsByValue
)
1112 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
1114 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1118 if (pParam
->param_attributes
.MustFree
)
1120 if (pParam
->param_attributes
.IsByValue
)
1121 call_freer(pStubMsg
, pArg
, pTypeFormat
);
1123 call_freer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1126 if (pParam
->param_attributes
.IsOut
&&
1127 !pParam
->param_attributes
.IsIn
&&
1128 !pParam
->param_attributes
.IsByValue
&&
1129 !pParam
->param_attributes
.ServerAllocSize
)
1131 pStubMsg
->pfnFree(*(void **)pArg
);
1134 if (pParam
->param_attributes
.ServerAllocSize
)
1135 HeapFree(GetProcessHeap(), 0, *(void **)pArg
);
1137 case STUBLESS_INITOUT
:
1138 if (!pParam
->param_attributes
.IsIn
&&
1139 pParam
->param_attributes
.IsOut
&&
1140 !pParam
->param_attributes
.ServerAllocSize
&&
1141 !pParam
->param_attributes
.IsByValue
)
1143 DWORD size
= calc_arg_size(pStubMsg
, pTypeFormat
);
1147 *(void **)pArg
= NdrAllocate(pStubMsg
, size
);
1148 memset(*(void **)pArg
, 0, size
);
1152 case STUBLESS_UNMARSHAL
:
1153 if (pParam
->param_attributes
.ServerAllocSize
)
1154 *(void **)pArg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1155 pParam
->param_attributes
.ServerAllocSize
* 8);
1157 if (pParam
->param_attributes
.IsIn
)
1159 if (pParam
->param_attributes
.IsByValue
)
1160 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
1162 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
1165 case STUBLESS_CALCSIZE
:
1166 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1168 if (pParam
->param_attributes
.IsByValue
)
1169 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
1171 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1175 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1178 current_offset
+= sizeof(NDR_PARAM_OIF_OTHER
);
1180 TRACE("\tmemory addr (after): %p -> %p\n", pArg
, *(unsigned char **)pArg
);
1186 static LONG_PTR
*stub_do_old_args(MIDL_STUB_MESSAGE
*pStubMsg
,
1187 PFORMAT_STRING pFormat
, int phase
,
1188 unsigned char *args
,
1189 unsigned short stack_size
, BOOL object
)
1193 /* current format string offset */
1194 int current_offset
= 0;
1195 /* current stack offset */
1196 unsigned short current_stack_offset
= 0;
1197 /* location to put retval into */
1198 LONG_PTR
*retval_ptr
= NULL
;
1200 for (i
= 0; TRUE
; i
++)
1202 const NDR_PARAM_OI_BASETYPE
*pParam
=
1203 (const NDR_PARAM_OI_BASETYPE
*)&pFormat
[current_offset
];
1204 /* note: current_stack_offset starts after the This pointer
1205 * if present, so adjust this */
1206 unsigned short current_stack_offset_adjusted
= current_stack_offset
+
1207 (object
? sizeof(void *) : 0);
1208 unsigned char *pArg
= args
+ current_stack_offset_adjusted
;
1210 /* no more parameters; exit loop */
1211 if (current_stack_offset_adjusted
>= stack_size
)
1214 TRACE("param[%d]: old format\n", i
);
1215 TRACE("\tparam_direction: 0x%x\n", pParam
->param_direction
);
1216 TRACE("\tstack_offset: 0x%x\n", current_stack_offset_adjusted
);
1218 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
||
1219 pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1221 const unsigned char *pTypeFormat
=
1222 &pParam
->type_format_char
;
1224 TRACE("\tbase type 0x%02x\n", *pTypeFormat
);
1226 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1227 retval_ptr
= (LONG_PTR
*)pArg
;
1231 case STUBLESS_MARSHAL
:
1232 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1233 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
1236 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
1237 call_freer(pStubMsg
, pArg
, pTypeFormat
);
1239 case STUBLESS_UNMARSHAL
:
1240 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
1241 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
1243 case STUBLESS_CALCSIZE
:
1244 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1245 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
1248 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1251 current_stack_offset
+= type_stack_size(*pTypeFormat
);
1252 current_offset
+= sizeof(NDR_PARAM_OI_BASETYPE
);
1256 const NDR_PARAM_OI_OTHER
*pParamOther
=
1257 (const NDR_PARAM_OI_OTHER
*)&pFormat
[current_offset
];
1259 const unsigned char * pTypeFormat
=
1260 &pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
];
1262 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat
);
1264 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
1265 retval_ptr
= (LONG_PTR
*)pArg
;
1269 case STUBLESS_MARSHAL
:
1270 if (pParam
->param_direction
== RPC_FC_OUT_PARAM
||
1271 pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1272 pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
1273 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1276 if (pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1277 pParam
->param_direction
== RPC_FC_IN_PARAM
)
1278 call_freer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1279 else if (pParam
->param_direction
== RPC_FC_OUT_PARAM
)
1280 pStubMsg
->pfnFree(*(void **)pArg
);
1282 case STUBLESS_INITOUT
:
1283 if (pParam
->param_direction
== RPC_FC_OUT_PARAM
)
1285 DWORD size
= calc_arg_size(pStubMsg
, pTypeFormat
);
1289 *(void **)pArg
= NdrAllocate(pStubMsg
, size
);
1290 memset(*(void **)pArg
, 0, size
);
1294 case STUBLESS_UNMARSHAL
:
1295 if (pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1296 pParam
->param_direction
== RPC_FC_IN_PARAM
)
1297 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
1299 case STUBLESS_CALCSIZE
:
1300 if (pParam
->param_direction
== RPC_FC_OUT_PARAM
||
1301 pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1302 pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
1303 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1306 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1309 current_stack_offset
+= pParamOther
->stack_size
* sizeof(INT
);
1310 current_offset
+= sizeof(NDR_PARAM_OI_OTHER
);
1317 /***********************************************************************
1318 * NdrStubCall2 [RPCRT4.@]
1320 * Unmarshals [in] parameters, calls either a method in an object or a server
1321 * function, marshals any [out] parameters and frees any allocated data.
1324 * Used by stubless MIDL-generated code.
1326 LONG WINAPI
NdrStubCall2(
1327 struct IRpcStubBuffer
* pThis
,
1328 struct IRpcChannelBuffer
* pChannel
,
1329 PRPC_MESSAGE pRpcMsg
,
1330 DWORD
* pdwStubPhase
)
1332 const MIDL_SERVER_INFO
*pServerInfo
;
1333 const MIDL_STUB_DESC
*pStubDesc
;
1334 PFORMAT_STRING pFormat
;
1335 MIDL_STUB_MESSAGE stubMsg
;
1336 /* pointer to start of stack to pass into stub implementation */
1337 unsigned char * args
;
1339 unsigned short stack_size
;
1340 /* number of parameters. optional for client to give it to us */
1341 unsigned char number_of_params
= ~0;
1342 /* cache of Oif_flags from v2 procedure header */
1343 INTERPRETER_OPT_FLAGS Oif_flags
= { 0 };
1344 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1345 INTERPRETER_OPT_FLAGS2 ext_flags
= { 0 };
1346 /* the type of pass we are currently doing */
1348 /* header for procedure string */
1349 const NDR_PROC_HEADER
*pProcHeader
;
1350 /* offset in format string for start of params */
1351 int parameter_start_offset
;
1352 /* current format string offset */
1354 /* -Oif or -Oicf generated format */
1355 BOOL bV2Format
= FALSE
;
1356 /* location to put retval into */
1357 LONG_PTR
*retval_ptr
= NULL
;
1359 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis
, pChannel
, pRpcMsg
, pdwStubPhase
);
1362 pServerInfo
= CStdStubBuffer_GetServerInfo(pThis
);
1364 pServerInfo
= ((RPC_SERVER_INTERFACE
*)pRpcMsg
->RpcInterfaceInformation
)->InterpreterInfo
;
1366 pStubDesc
= pServerInfo
->pStubDesc
;
1367 pFormat
= pServerInfo
->ProcString
+ pServerInfo
->FmtStringOffset
[pRpcMsg
->ProcNum
];
1368 pProcHeader
= (const NDR_PROC_HEADER
*)&pFormat
[0];
1370 TRACE("NDR Version: 0x%x\n", pStubDesc
->Version
);
1372 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
1374 const NDR_PROC_HEADER_RPC
*pProcHeader
= (const NDR_PROC_HEADER_RPC
*)&pFormat
[0];
1375 stack_size
= pProcHeader
->stack_size
;
1376 current_offset
= sizeof(NDR_PROC_HEADER_RPC
);
1381 stack_size
= pProcHeader
->stack_size
;
1382 current_offset
= sizeof(NDR_PROC_HEADER
);
1385 TRACE("Oi_flags = 0x%02x\n", pProcHeader
->Oi_flags
);
1388 switch (pProcHeader
->handle_type
)
1390 /* explicit binding: parse additional section */
1391 case RPC_FC_BIND_EXPLICIT
:
1392 switch (pFormat
[current_offset
]) /* handle_type */
1394 case RPC_FC_BIND_PRIMITIVE
: /* explicit primitive */
1395 current_offset
+= sizeof(NDR_EHD_PRIMITIVE
);
1397 case RPC_FC_BIND_GENERIC
: /* explicit generic */
1398 current_offset
+= sizeof(NDR_EHD_GENERIC
);
1400 case RPC_FC_BIND_CONTEXT
: /* explicit context */
1401 current_offset
+= sizeof(NDR_EHD_CONTEXT
);
1404 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
1405 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
1408 case RPC_FC_BIND_GENERIC
: /* implicit generic */
1409 case RPC_FC_BIND_PRIMITIVE
: /* implicit primitive */
1410 case RPC_FC_CALLBACK_HANDLE
: /* implicit callback */
1411 case RPC_FC_AUTO_HANDLE
: /* implicit auto handle */
1414 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
1415 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
1418 bV2Format
= (pStubDesc
->Version
>= 0x20000);
1422 const NDR_PROC_PARTIAL_OIF_HEADER
*pOIFHeader
=
1423 (const NDR_PROC_PARTIAL_OIF_HEADER
*)&pFormat
[current_offset
];
1425 Oif_flags
= pOIFHeader
->Oi2Flags
;
1426 number_of_params
= pOIFHeader
->number_of_params
;
1428 current_offset
+= sizeof(NDR_PROC_PARTIAL_OIF_HEADER
);
1431 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags
);
1433 if (Oif_flags
.HasExtensions
)
1435 const NDR_PROC_HEADER_EXTS
*pExtensions
=
1436 (const NDR_PROC_HEADER_EXTS
*)&pFormat
[current_offset
];
1437 ext_flags
= pExtensions
->Flags2
;
1438 current_offset
+= pExtensions
->Size
;
1441 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1442 NdrStubInitialize(pRpcMsg
, &stubMsg
, pStubDesc
, pChannel
);
1444 NdrServerInitializeNew(pRpcMsg
, &stubMsg
, pStubDesc
);
1446 /* create the full pointer translation tables, if requested */
1447 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
1448 stubMsg
.FullPtrXlatTables
= NdrFullPointerXlatInit(0,XLAT_SERVER
);
1450 /* store the RPC flags away */
1451 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
1452 pRpcMsg
->RpcFlags
= ((const NDR_PROC_HEADER_RPC
*)pProcHeader
)->rpc_flags
;
1454 /* use alternate memory allocation routines */
1455 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCSSALLOC
)
1457 NdrRpcSsEnableAllocate(&stubMsg
);
1459 FIXME("Set RPCSS memory allocation routines\n");
1462 if (Oif_flags
.HasPipes
)
1464 FIXME("pipes not supported yet\n");
1465 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
); /* FIXME: remove when implemented */
1466 /* init pipes package */
1467 /* NdrPipesInitialize(...) */
1469 if (ext_flags
.HasNewCorrDesc
)
1471 /* initialize extra correlation package */
1472 FIXME("new correlation description not implemented\n");
1473 stubMsg
.fHasNewCorrDesc
= TRUE
;
1476 /* convert strings, floating point values and endianess into our
1477 * preferred format */
1478 if ((pRpcMsg
->DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
1479 NdrConvert(&stubMsg
, pFormat
);
1481 parameter_start_offset
= current_offset
;
1483 TRACE("allocating memory for stack of size %x\n", stack_size
);
1485 args
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, stack_size
);
1486 stubMsg
.StackTop
= args
; /* used by conformance of top-level objects */
1488 /* add the implicit This pointer as the first arg to the function if we
1489 * are calling an object method */
1491 *(void **)args
= ((CStdStubBuffer
*)pThis
)->pvServerObject
;
1494 * 1. STUBLESS_UNMARHSAL - unmarshal [in] params from buffer
1495 * 2. STUBLESS_CALLSERVER - send/receive buffer
1496 * 3. STUBLESS_CALCSIZE - get [out] buffer size
1497 * 4. STUBLESS_GETBUFFER - allocate [out] buffer
1498 * 5. STUBLESS_MARHSAL - marshal [out] params to buffer
1500 for (phase
= STUBLESS_UNMARSHAL
; phase
<= STUBLESS_FREE
; phase
++)
1502 TRACE("phase = %d\n", phase
);
1505 case STUBLESS_CALLSERVER
:
1506 /* call the server function */
1507 if (pServerInfo
->ThunkTable
&& pServerInfo
->ThunkTable
[pRpcMsg
->ProcNum
])
1508 pServerInfo
->ThunkTable
[pRpcMsg
->ProcNum
](&stubMsg
);
1511 SERVER_ROUTINE func
;
1514 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1516 SERVER_ROUTINE
*vtbl
= *(SERVER_ROUTINE
**)((CStdStubBuffer
*)pThis
)->pvServerObject
;
1517 func
= vtbl
[pRpcMsg
->ProcNum
];
1520 func
= pServerInfo
->DispatchTable
[pRpcMsg
->ProcNum
];
1522 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1523 retval
= call_server_func(func
, args
, stack_size
);
1527 TRACE("stub implementation returned 0x%lx\n", retval
);
1528 *retval_ptr
= retval
;
1531 TRACE("void stub implementation\n");
1534 stubMsg
.Buffer
= NULL
;
1535 stubMsg
.BufferLength
= 0;
1538 case STUBLESS_GETBUFFER
:
1539 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1540 NdrStubGetBuffer(pThis
, pChannel
, &stubMsg
);
1545 pRpcMsg
->BufferLength
= stubMsg
.BufferLength
;
1546 /* allocate buffer for [out] and [ret] params */
1547 Status
= I_RpcGetBuffer(pRpcMsg
);
1549 RpcRaiseException(Status
);
1550 stubMsg
.Buffer
= pRpcMsg
->Buffer
;
1553 case STUBLESS_UNMARSHAL
:
1554 case STUBLESS_INITOUT
:
1555 case STUBLESS_CALCSIZE
:
1556 case STUBLESS_MARSHAL
:
1559 retval_ptr
= stub_do_args(&stubMsg
, &pFormat
[parameter_start_offset
],
1560 phase
, args
, number_of_params
);
1562 retval_ptr
= stub_do_old_args(&stubMsg
, &pFormat
[parameter_start_offset
],
1563 phase
, args
, stack_size
,
1564 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
));
1568 ERR("shouldn't reach here. phase %d\n", phase
);
1573 pRpcMsg
->BufferLength
= (unsigned int)(stubMsg
.Buffer
- (unsigned char *)pRpcMsg
->Buffer
);
1575 if (ext_flags
.HasNewCorrDesc
)
1577 /* free extra correlation package */
1578 /* NdrCorrelationFree(&stubMsg); */
1581 if (Oif_flags
.HasPipes
)
1583 /* NdrPipesDone(...) */
1586 /* free the full pointer translation tables */
1587 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
1588 NdrFullPointerXlatFree(stubMsg
.FullPtrXlatTables
);
1590 /* free server function stack */
1591 HeapFree(GetProcessHeap(), 0, args
);
1596 /***********************************************************************
1597 * NdrServerCall2 [RPCRT4.@]
1599 void WINAPI
NdrServerCall2(PRPC_MESSAGE pRpcMsg
)
1602 NdrStubCall2(NULL
, NULL
, pRpcMsg
, &dwPhase
);
1605 struct async_call_data
1607 MIDL_STUB_MESSAGE
*pStubMsg
;
1608 const NDR_PROC_HEADER
*pProcHeader
;
1609 PFORMAT_STRING pHandleFormat
;
1610 PFORMAT_STRING pParamFormat
;
1611 RPC_BINDING_HANDLE hBinding
;
1613 unsigned short stack_size
;
1614 /* number of parameters. optional for client to give it to us */
1615 unsigned char number_of_params
;
1616 /* correlation cache */
1617 unsigned long NdrCorrCache
[256];
1620 LONG_PTR WINAPIV
NdrAsyncClientCall(PMIDL_STUB_DESC pStubDesc
,
1621 PFORMAT_STRING pFormat
, ...)
1623 /* pointer to start of stack where arguments start */
1624 PRPC_MESSAGE pRpcMsg
;
1625 PMIDL_STUB_MESSAGE pStubMsg
;
1626 RPC_ASYNC_STATE
*pAsync
;
1627 struct async_call_data
*async_call_data
;
1628 /* procedure number */
1629 unsigned short procedure_number
;
1630 /* cache of Oif_flags from v2 procedure header */
1631 INTERPRETER_OPT_FLAGS Oif_flags
= { 0 };
1632 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1633 INTERPRETER_OPT_FLAGS2 ext_flags
= { 0 };
1634 /* the type of pass we are currently doing */
1636 /* header for procedure string */
1637 const NDR_PROC_HEADER
* pProcHeader
= (const NDR_PROC_HEADER
*)&pFormat
[0];
1638 /* -Oif or -Oicf generated format */
1639 BOOL bV2Format
= FALSE
;
1641 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc
, pFormat
);
1643 /* Later NDR language versions probably won't be backwards compatible */
1644 if (pStubDesc
->Version
> 0x50002)
1646 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc
->Version
);
1647 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
);
1650 async_call_data
= I_RpcAllocate(sizeof(*async_call_data
) + sizeof(MIDL_STUB_MESSAGE
) + sizeof(RPC_MESSAGE
));
1651 if (!async_call_data
) RpcRaiseException(ERROR_OUTOFMEMORY
);
1652 async_call_data
->number_of_params
= ~0;
1653 async_call_data
->pProcHeader
= pProcHeader
;
1655 async_call_data
->pStubMsg
= pStubMsg
= (PMIDL_STUB_MESSAGE
)(async_call_data
+ 1);
1656 pRpcMsg
= (PRPC_MESSAGE
)(pStubMsg
+ 1);
1658 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
1660 const NDR_PROC_HEADER_RPC
*pProcHeader
= (const NDR_PROC_HEADER_RPC
*)&pFormat
[0];
1661 async_call_data
->stack_size
= pProcHeader
->stack_size
;
1662 procedure_number
= pProcHeader
->proc_num
;
1663 pFormat
+= sizeof(NDR_PROC_HEADER_RPC
);
1667 async_call_data
->stack_size
= pProcHeader
->stack_size
;
1668 procedure_number
= pProcHeader
->proc_num
;
1669 pFormat
+= sizeof(NDR_PROC_HEADER
);
1671 TRACE("stack size: 0x%x\n", async_call_data
->stack_size
);
1672 TRACE("proc num: %d\n", procedure_number
);
1674 /* create the full pointer translation tables, if requested */
1675 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
1676 pStubMsg
->FullPtrXlatTables
= NdrFullPointerXlatInit(0,XLAT_CLIENT
);
1678 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1680 ERR("objects not supported\n");
1681 I_RpcFree(async_call_data
);
1682 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
1685 NdrClientInitializeNew(pRpcMsg
, pStubMsg
, pStubDesc
, procedure_number
);
1687 TRACE("Oi_flags = 0x%02x\n", pProcHeader
->Oi_flags
);
1688 TRACE("MIDL stub version = 0x%x\n", pStubDesc
->MIDLVersion
);
1690 /* needed for conformance of top-level objects */
1692 pStubMsg
->StackTop
= I_RpcAllocate(async_call_data
->stack_size
);
1693 /* FIXME: this may read one more DWORD than is necessary, but it shouldn't hurt */
1694 memcpy(pStubMsg
->StackTop
, *(unsigned char **)(&pFormat
+1), async_call_data
->stack_size
);
1696 # warning Stack not retrieved for your CPU architecture
1699 pAsync
= *(RPC_ASYNC_STATE
**)pStubMsg
->StackTop
;
1700 pAsync
->StubInfo
= async_call_data
;
1701 async_call_data
->pHandleFormat
= pFormat
;
1703 pFormat
= client_get_handle(pStubMsg
, pProcHeader
, async_call_data
->pHandleFormat
, &async_call_data
->hBinding
);
1704 if (!pFormat
) return 0;
1706 bV2Format
= (pStubDesc
->Version
>= 0x20000);
1710 const NDR_PROC_PARTIAL_OIF_HEADER
*pOIFHeader
=
1711 (const NDR_PROC_PARTIAL_OIF_HEADER
*)pFormat
;
1713 Oif_flags
= pOIFHeader
->Oi2Flags
;
1714 async_call_data
->number_of_params
= pOIFHeader
->number_of_params
;
1716 pFormat
+= sizeof(NDR_PROC_PARTIAL_OIF_HEADER
);
1719 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags
);
1721 if (Oif_flags
.HasExtensions
)
1723 const NDR_PROC_HEADER_EXTS
*pExtensions
=
1724 (const NDR_PROC_HEADER_EXTS
*)pFormat
;
1725 ext_flags
= pExtensions
->Flags2
;
1726 pFormat
+= pExtensions
->Size
;
1729 async_call_data
->pParamFormat
= pFormat
;
1731 pStubMsg
->BufferLength
= 0;
1733 /* store the RPC flags away */
1734 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
1735 pRpcMsg
->RpcFlags
= ((const NDR_PROC_HEADER_RPC
*)pProcHeader
)->rpc_flags
;
1737 /* use alternate memory allocation routines */
1738 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCSSALLOC
)
1739 NdrRpcSmSetClientToOsf(pStubMsg
);
1741 if (Oif_flags
.HasPipes
)
1743 FIXME("pipes not supported yet\n");
1744 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
); /* FIXME: remove when implemented */
1745 /* init pipes package */
1746 /* NdrPipesInitialize(...) */
1748 if (ext_flags
.HasNewCorrDesc
)
1750 /* initialize extra correlation package */
1751 NdrCorrelationInitialize(pStubMsg
, async_call_data
->NdrCorrCache
, sizeof(async_call_data
->NdrCorrCache
), 0);
1755 * 1. PROXY_CALCSIZE - calculate the buffer size
1756 * 2. PROXY_GETBUFFER - allocate the buffer
1757 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
1758 * 4. PROXY_SENDRECEIVE - send buffer
1759 * Then in NdrpCompleteAsyncClientCall:
1760 * 1. PROXY_SENDRECEIVE - receive buffer
1761 * 2. PROXY_UNMARHSAL - unmarshal [out] params from buffer
1763 for (phase
= PROXY_CALCSIZE
; phase
<= PROXY_SENDRECEIVE
; phase
++)
1766 TRACE("phase = %d\n", phase
);
1769 case PROXY_GETBUFFER
:
1770 /* allocate the buffer */
1771 if (Oif_flags
.HasPipes
)
1772 /* NdrGetPipeBuffer(...) */
1773 FIXME("pipes not supported yet\n");
1776 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
1778 NdrNsGetBuffer(pStubMsg
, pStubMsg
->BufferLength
, async_call_data
->hBinding
);
1780 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
1783 NdrGetBuffer(pStubMsg
, pStubMsg
->BufferLength
, async_call_data
->hBinding
);
1785 pRpcMsg
->RpcFlags
|= RPC_BUFFER_ASYNC
;
1786 status
= I_RpcAsyncSetHandle(pRpcMsg
, pAsync
);
1787 if (status
!= RPC_S_OK
)
1788 RpcRaiseException(status
);
1790 case PROXY_SENDRECEIVE
:
1791 pRpcMsg
->RpcFlags
|= RPC_BUFFER_ASYNC
;
1792 /* send the [in] params only */
1793 if (Oif_flags
.HasPipes
)
1794 /* NdrPipesSend(...) */
1795 FIXME("pipes not supported yet\n");
1798 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
1800 NdrNsSend(&stubMsg
, stubMsg
.Buffer
, pStubDesc
->IMPLICIT_HANDLE_INFO
.pAutoHandle
);
1802 FIXME("using auto handle - call NdrNsSend when it gets implemented\n");
1806 pStubMsg
->RpcMsg
->BufferLength
= pStubMsg
->Buffer
- (unsigned char *)pStubMsg
->RpcMsg
->Buffer
;
1807 status
= I_RpcSend(pStubMsg
->RpcMsg
);
1808 if (status
!= RPC_S_OK
)
1809 RpcRaiseException(status
);
1814 case PROXY_CALCSIZE
:
1817 client_do_args(pStubMsg
, pFormat
, phase
, pStubMsg
->StackTop
,
1818 async_call_data
->number_of_params
, NULL
);
1820 client_do_args_old_format(pStubMsg
, pFormat
, phase
,
1821 pStubMsg
->StackTop
, async_call_data
->stack_size
, NULL
,
1822 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
), FALSE
);
1825 ERR("shouldn't reach here. phase %d\n", phase
);
1830 TRACE("returning 0\n");
1834 RPC_STATUS
NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE
*pAsync
, void *Reply
)
1836 /* pointer to start of stack where arguments start */
1837 PMIDL_STUB_MESSAGE pStubMsg
;
1838 struct async_call_data
*async_call_data
;
1839 /* the type of pass we are currently doing */
1841 /* header for procedure string */
1842 const NDR_PROC_HEADER
* pProcHeader
;
1843 /* -Oif or -Oicf generated format */
1845 RPC_STATUS status
= RPC_S_OK
;
1847 if (!pAsync
->StubInfo
)
1848 return RPC_S_INVALID_ASYNC_HANDLE
;
1850 async_call_data
= pAsync
->StubInfo
;
1851 pStubMsg
= async_call_data
->pStubMsg
;
1852 pProcHeader
= async_call_data
->pProcHeader
;
1854 bV2Format
= (pStubMsg
->StubDesc
->Version
>= 0x20000);
1857 * 1. PROXY_CALCSIZE - calculate the buffer size
1858 * 2. PROXY_GETBUFFER - allocate the buffer
1859 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
1860 * 4. PROXY_SENDRECEIVE - send buffer
1861 * Then in NdrpCompleteAsyncClientCall:
1862 * 1. PROXY_SENDRECEIVE - receive buffer
1863 * 2. PROXY_UNMARHSAL - unmarshal [out] params from buffer
1865 for (phase
= PROXY_SENDRECEIVE
; phase
<= PROXY_UNMARSHAL
; phase
++)
1869 case PROXY_SENDRECEIVE
:
1870 pStubMsg
->RpcMsg
->RpcFlags
|= RPC_BUFFER_ASYNC
;
1871 /* receive the [out] params */
1872 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
1874 NdrNsReceive(&stubMsg
, stubMsg
.Buffer
, pStubDesc
->IMPLICIT_HANDLE_INFO
.pAutoHandle
);
1876 FIXME("using auto handle - call NdrNsReceive when it gets implemented\n");
1880 status
= I_RpcReceive(pStubMsg
->RpcMsg
);
1881 if (status
!= RPC_S_OK
)
1883 pStubMsg
->BufferLength
= pStubMsg
->RpcMsg
->BufferLength
;
1884 pStubMsg
->BufferStart
= pStubMsg
->RpcMsg
->Buffer
;
1885 pStubMsg
->BufferEnd
= pStubMsg
->BufferStart
+ pStubMsg
->BufferLength
;
1886 pStubMsg
->Buffer
= pStubMsg
->BufferStart
;
1889 /* convert strings, floating point values and endianess into our
1890 * preferred format */
1892 if ((pStubMsg
->RpcMsg
.DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
1893 NdrConvert(pStubMsg
, pFormat
);
1897 case PROXY_UNMARSHAL
:
1899 client_do_args(pStubMsg
, async_call_data
->pParamFormat
, phase
, pStubMsg
->StackTop
,
1900 async_call_data
->number_of_params
, Reply
);
1902 client_do_args_old_format(pStubMsg
, async_call_data
->pParamFormat
, phase
,
1903 pStubMsg
->StackTop
, async_call_data
->stack_size
, Reply
, FALSE
, FALSE
);
1906 ERR("shouldn't reach here. phase %d\n", phase
);
1912 if (pStubMsg
->fHasNewCorrDesc
)
1914 /* free extra correlation package */
1915 NdrCorrelationFree(pStubMsg
);
1918 /* free the full pointer translation tables */
1919 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
1920 NdrFullPointerXlatFree(pStubMsg
->FullPtrXlatTables
);
1922 /* free marshalling buffer */
1923 NdrFreeBuffer(pStubMsg
);
1924 client_free_handle(pStubMsg
, pProcHeader
, async_call_data
->pHandleFormat
, async_call_data
->hBinding
);
1926 I_RpcFree(pStubMsg
->StackTop
);
1927 I_RpcFree(async_call_data
);
1929 TRACE("-- 0x%x\n", status
);
1933 RPCRTAPI LONG RPC_ENTRY
NdrAsyncStubCall(struct IRpcStubBuffer
* pThis
,
1934 struct IRpcChannelBuffer
* pChannel
, PRPC_MESSAGE pRpcMsg
,
1935 DWORD
* pdwStubPhase
)
1937 FIXME("unimplemented, expect crash!\n");