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 WINAPI
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 WINAPI
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(stubMsg, offset) ((stubMsg).StackTop + (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
, pDesc
->offset
);
161 *phBinding
= *(handle_t
*)ARG_FROM_OFFSET(*pStubMsg
, 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
, pDesc
->offset
);
176 pArg
= (void *)ARG_FROM_OFFSET(*pStubMsg
, 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
, pDesc
->offset
);
193 context_handle
= *(NDR_CCONTEXT
*)ARG_FROM_OFFSET(*pStubMsg
, 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
, pDesc
->offset
);
259 pArg
= (void *)ARG_FROM_OFFSET(*pStubMsg
, 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 short number_of_params
, unsigned char *pRetVal
)
290 /* current format string offset */
291 int current_offset
= 0;
292 /* current stack offset */
293 unsigned short current_stack_offset
= 0;
297 for (i
= 0; i
< number_of_params
; i
++)
299 const NDR_PARAM_OIF_BASETYPE
*pParam
=
300 (const NDR_PARAM_OIF_BASETYPE
*)&pFormat
[current_offset
];
301 unsigned char * pArg
;
303 current_stack_offset
= pParam
->stack_offset
;
304 pArg
= ARG_FROM_OFFSET(*pStubMsg
, current_stack_offset
);
306 TRACE("param[%d]: new format\n", i
);
307 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam
->param_attributes
); TRACE("\n");
308 TRACE("\tstack_offset: 0x%x\n", current_stack_offset
);
309 TRACE("\tmemory addr (before): %p\n", pArg
);
311 if (pParam
->param_attributes
.IsBasetype
)
313 const unsigned char * pTypeFormat
=
314 &pParam
->type_format_char
;
316 if (pParam
->param_attributes
.IsSimpleRef
)
317 pArg
= *(unsigned char **)pArg
;
319 TRACE("\tbase type: 0x%02x\n", *pTypeFormat
);
324 if (pParam
->param_attributes
.IsIn
)
325 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
328 if (pParam
->param_attributes
.IsIn
)
329 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
331 case PROXY_UNMARSHAL
:
332 if (pParam
->param_attributes
.IsOut
)
334 if (pParam
->param_attributes
.IsReturn
)
335 call_unmarshaller(pStubMsg
, &pRetVal
, pTypeFormat
, 0);
337 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
338 TRACE("pRetVal = %p\n", pRetVal
);
342 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
345 current_offset
+= sizeof(NDR_PARAM_OIF_BASETYPE
);
349 const NDR_PARAM_OIF_OTHER
*pParamOther
=
350 (const NDR_PARAM_OIF_OTHER
*)&pFormat
[current_offset
];
352 const unsigned char * pTypeFormat
=
353 &(pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
]);
355 /* if a simple ref pointer then we have to do the
356 * check for the pointer being non-NULL. */
357 if (pParam
->param_attributes
.IsSimpleRef
)
359 if (!*(unsigned char **)pArg
)
360 RpcRaiseException(RPC_X_NULL_REF_POINTER
);
363 TRACE("\tcomplex type: 0x%02x\n", *pTypeFormat
);
368 if (pParam
->param_attributes
.IsIn
)
370 if (pParam
->param_attributes
.IsByValue
)
371 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
373 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
377 if (pParam
->param_attributes
.IsIn
)
379 if (pParam
->param_attributes
.IsByValue
)
380 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
382 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
385 case PROXY_UNMARSHAL
:
386 if (pParam
->param_attributes
.IsOut
)
388 if (pParam
->param_attributes
.IsReturn
)
389 call_unmarshaller(pStubMsg
, &pRetVal
, pTypeFormat
, 0);
390 else if (pParam
->param_attributes
.IsByValue
)
391 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
393 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
397 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
400 current_offset
+= sizeof(NDR_PARAM_OIF_OTHER
);
402 TRACE("\tmemory addr (after): %p\n", pArg
);
406 static unsigned int type_stack_size(unsigned char fc
)
418 return sizeof(short);
425 return sizeof(float);
427 return sizeof(double);
429 return sizeof(ULONGLONG
);
430 case RPC_FC_ERROR_STATUS_T
:
431 return sizeof(error_status_t
);
433 return sizeof(void *);
435 ERR("invalid base type 0x%x\n", fc
);
436 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
440 static void client_do_args_old_format(PMIDL_STUB_MESSAGE pStubMsg
,
441 PFORMAT_STRING pFormat
, int phase
, unsigned short stack_size
,
442 unsigned char *pRetVal
, BOOL object_proc
)
444 /* current format string offset */
445 int current_offset
= 0;
446 /* current stack offset */
447 unsigned short current_stack_offset
= 0;
451 /* NOTE: V1 style format does't terminate on the number_of_params
452 * condition as it doesn't have this attribute. Instead it
453 * terminates when the stack size given in the header is exceeded.
455 for (i
= 0; TRUE
; i
++)
457 const NDR_PARAM_OI_BASETYPE
*pParam
=
458 (const NDR_PARAM_OI_BASETYPE
*)&pFormat
[current_offset
];
459 /* note: current_stack_offset starts after the This pointer
460 * if present, so adjust this */
461 unsigned short current_stack_offset_adjusted
= current_stack_offset
+
462 (object_proc
? sizeof(void *) : 0);
463 unsigned char * pArg
= ARG_FROM_OFFSET(*pStubMsg
, current_stack_offset_adjusted
);
465 /* no more parameters; exit loop */
466 if (current_stack_offset_adjusted
>= stack_size
)
469 TRACE("param[%d]: old format\n", i
);
470 TRACE("\tparam_direction: 0x%x\n", pParam
->param_direction
);
471 TRACE("\tstack_offset: 0x%x\n", current_stack_offset_adjusted
);
472 TRACE("\tmemory addr (before): %p\n", pArg
);
474 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
||
475 pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
477 const unsigned char * pTypeFormat
=
478 &pParam
->type_format_char
;
480 TRACE("\tbase type 0x%02x\n", *pTypeFormat
);
485 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
486 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
489 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
490 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
492 case PROXY_UNMARSHAL
:
493 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
495 if (pParam
->param_direction
& RPC_FC_RETURN_PARAM
)
496 call_unmarshaller(pStubMsg
, &pRetVal
, pTypeFormat
, 0);
498 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
502 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
505 current_stack_offset
+= type_stack_size(*pTypeFormat
);
506 current_offset
+= sizeof(NDR_PARAM_OI_BASETYPE
);
510 const NDR_PARAM_OI_OTHER
*pParamOther
=
511 (const NDR_PARAM_OI_OTHER
*)&pFormat
[current_offset
];
513 const unsigned char *pTypeFormat
=
514 &pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
];
516 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat
);
521 if (pParam
->param_direction
== RPC_FC_IN_PARAM
||
522 pParam
->param_direction
& RPC_FC_IN_OUT_PARAM
)
523 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
526 if (pParam
->param_direction
== RPC_FC_IN_PARAM
||
527 pParam
->param_direction
& RPC_FC_IN_OUT_PARAM
)
528 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
530 case PROXY_UNMARSHAL
:
531 if (pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
532 pParam
->param_direction
== RPC_FC_OUT_PARAM
)
533 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
534 else if (pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
535 call_unmarshaller(pStubMsg
, (unsigned char **)pRetVal
, pTypeFormat
, 0);
538 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
541 current_stack_offset
+= pParamOther
->stack_size
* sizeof(INT
);
542 current_offset
+= sizeof(NDR_PARAM_OI_OTHER
);
544 TRACE("\tmemory addr (after): %p\n", pArg
);
548 /* the return type should be CLIENT_CALL_RETURN, but this is incompatible
549 * with the way gcc returns structures. "void *" should be the largest type
550 * that MIDL should allow you to return anyway */
551 LONG_PTR WINAPIV
NdrClientCall2(PMIDL_STUB_DESC pStubDesc
, PFORMAT_STRING pFormat
, ...)
553 /* pointer to start of stack where arguments start */
555 MIDL_STUB_MESSAGE stubMsg
;
556 handle_t hBinding
= NULL
;
557 /* procedure number */
558 unsigned short procedure_number
;
560 unsigned short stack_size
;
561 /* number of parameters. optional for client to give it to us */
562 unsigned char number_of_params
= ~0;
563 /* cache of Oif_flags from v2 procedure header */
564 INTERPRETER_OPT_FLAGS Oif_flags
= { 0 };
565 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
566 INTERPRETER_OPT_FLAGS2 ext_flags
= { 0 };
567 /* the type of pass we are currently doing */
569 /* header for procedure string */
570 const NDR_PROC_HEADER
* pProcHeader
= (const NDR_PROC_HEADER
*)&pFormat
[0];
571 /* -Oif or -Oicf generated format */
572 BOOL bV2Format
= FALSE
;
573 /* the value to return to the client from the remote procedure */
575 /* the pointer to the object when in OLE mode */
577 PFORMAT_STRING pHandleFormat
;
578 /* correlation cache */
579 unsigned long NdrCorrCache
[256];
581 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc
, pFormat
);
583 /* Later NDR language versions probably won't be backwards compatible */
584 if (pStubDesc
->Version
> 0x50002)
586 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc
->Version
);
587 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
);
590 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
592 const NDR_PROC_HEADER_RPC
*pProcHeader
= (const NDR_PROC_HEADER_RPC
*)&pFormat
[0];
593 stack_size
= pProcHeader
->stack_size
;
594 procedure_number
= pProcHeader
->proc_num
;
595 pFormat
+= sizeof(NDR_PROC_HEADER_RPC
);
599 stack_size
= pProcHeader
->stack_size
;
600 procedure_number
= pProcHeader
->proc_num
;
601 pFormat
+= sizeof(NDR_PROC_HEADER
);
603 TRACE("stack size: 0x%x\n", stack_size
);
604 TRACE("proc num: %d\n", procedure_number
);
606 /* create the full pointer translation tables, if requested */
607 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
608 stubMsg
.FullPtrXlatTables
= NdrFullPointerXlatInit(0,XLAT_CLIENT
);
610 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
612 /* object is always the first argument */
613 This
= **(void *const **)(&pFormat
+1);
614 NdrProxyInitialize(This
, &rpcMsg
, &stubMsg
, pStubDesc
, procedure_number
);
617 NdrClientInitializeNew(&rpcMsg
, &stubMsg
, pStubDesc
, procedure_number
);
619 TRACE("Oi_flags = 0x%02x\n", pProcHeader
->Oi_flags
);
620 TRACE("MIDL stub version = 0x%x\n", pStubDesc
->MIDLVersion
);
622 /* needed for conformance of top-level objects */
624 stubMsg
.StackTop
= *(unsigned char **)(&pFormat
+1);
626 # warning Stack not retrieved for your CPU architecture
629 pHandleFormat
= pFormat
;
631 /* we only need a handle if this isn't an object method */
632 if (!(pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
))
634 pFormat
= client_get_handle(&stubMsg
, pProcHeader
, pHandleFormat
, &hBinding
);
635 if (!pFormat
) return 0;
638 bV2Format
= (pStubDesc
->Version
>= 0x20000);
642 const NDR_PROC_PARTIAL_OIF_HEADER
*pOIFHeader
=
643 (const NDR_PROC_PARTIAL_OIF_HEADER
*)pFormat
;
645 Oif_flags
= pOIFHeader
->Oi2Flags
;
646 number_of_params
= pOIFHeader
->number_of_params
;
648 pFormat
+= sizeof(NDR_PROC_PARTIAL_OIF_HEADER
);
651 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags
);
653 if (Oif_flags
.HasExtensions
)
655 const NDR_PROC_HEADER_EXTS
*pExtensions
=
656 (const NDR_PROC_HEADER_EXTS
*)pFormat
;
657 ext_flags
= pExtensions
->Flags2
;
658 pFormat
+= pExtensions
->Size
;
661 stubMsg
.BufferLength
= 0;
663 /* store the RPC flags away */
664 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
665 rpcMsg
.RpcFlags
= ((const NDR_PROC_HEADER_RPC
*)pProcHeader
)->rpc_flags
;
667 /* use alternate memory allocation routines */
668 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCSSALLOC
)
669 NdrRpcSmSetClientToOsf(&stubMsg
);
671 if (Oif_flags
.HasPipes
)
673 FIXME("pipes not supported yet\n");
674 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
); /* FIXME: remove when implemented */
675 /* init pipes package */
676 /* NdrPipesInitialize(...) */
678 if (ext_flags
.HasNewCorrDesc
)
680 /* initialize extra correlation package */
681 NdrCorrelationInitialize(&stubMsg
, NdrCorrCache
, sizeof(NdrCorrCache
), 0);
685 * 1. PROXY_CALCSIZE - calculate the buffer size
686 * 2. PROXY_GETBUFFER - allocate the buffer
687 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
688 * 4. PROXY_SENDRECEIVE - send/receive buffer
689 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
691 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
695 for (phase
= PROXY_CALCSIZE
; phase
<= PROXY_UNMARSHAL
; phase
++)
697 TRACE("phase = %d\n", phase
);
700 case PROXY_GETBUFFER
:
701 /* allocate the buffer */
702 NdrProxyGetBuffer(This
, &stubMsg
);
704 case PROXY_SENDRECEIVE
:
705 /* send the [in] params and receive the [out] and [retval]
707 NdrProxySendReceive(This
, &stubMsg
);
709 /* convert strings, floating point values and endianess into our
710 * preferred format */
711 if ((rpcMsg
.DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
712 NdrConvert(&stubMsg
, pFormat
);
717 case PROXY_UNMARSHAL
:
719 client_do_args(&stubMsg
, pFormat
, phase
, number_of_params
,
720 (unsigned char *)&RetVal
);
722 client_do_args_old_format(&stubMsg
, pFormat
, phase
, stack_size
,
723 (unsigned char *)&RetVal
,
724 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
));
727 ERR("shouldn't reach here. phase %d\n", phase
);
734 RetVal
= NdrProxyErrorHandler(GetExceptionCode());
741 * 1. PROXY_CALCSIZE - calculate the buffer size
742 * 2. PROXY_GETBUFFER - allocate the buffer
743 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
744 * 4. PROXY_SENDRECEIVE - send/receive buffer
745 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
747 for (phase
= PROXY_CALCSIZE
; phase
<= PROXY_UNMARSHAL
; phase
++)
749 TRACE("phase = %d\n", phase
);
752 case PROXY_GETBUFFER
:
753 /* allocate the buffer */
754 if (Oif_flags
.HasPipes
)
755 /* NdrGetPipeBuffer(...) */
756 FIXME("pipes not supported yet\n");
759 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
761 NdrNsGetBuffer(&stubMsg
, stubMsg
.BufferLength
, hBinding
);
763 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
766 NdrGetBuffer(&stubMsg
, stubMsg
.BufferLength
, hBinding
);
769 case PROXY_SENDRECEIVE
:
770 /* send the [in] params and receive the [out] and [retval]
772 if (Oif_flags
.HasPipes
)
773 /* NdrPipesSendReceive(...) */
774 FIXME("pipes not supported yet\n");
777 if (pProcHeader
->handle_type
== RPC_FC_AUTO_HANDLE
)
779 NdrNsSendReceive(&stubMsg
, stubMsg
.Buffer
, pStubDesc
->IMPLICIT_HANDLE_INFO
.pAutoHandle
);
781 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
784 NdrSendReceive(&stubMsg
, stubMsg
.Buffer
);
787 /* convert strings, floating point values and endianess into our
788 * preferred format */
789 if ((rpcMsg
.DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
790 NdrConvert(&stubMsg
, pFormat
);
795 case PROXY_UNMARSHAL
:
797 client_do_args(&stubMsg
, pFormat
, phase
, number_of_params
,
798 (unsigned char *)&RetVal
);
800 client_do_args_old_format(&stubMsg
, pFormat
, phase
, stack_size
,
801 (unsigned char *)&RetVal
,
802 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
));
805 ERR("shouldn't reach here. phase %d\n", phase
);
811 if (ext_flags
.HasNewCorrDesc
)
813 /* free extra correlation package */
814 NdrCorrelationFree(&stubMsg
);
817 if (Oif_flags
.HasPipes
)
819 /* NdrPipesDone(...) */
822 /* free the full pointer translation tables */
823 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
824 NdrFullPointerXlatFree(stubMsg
.FullPtrXlatTables
);
826 /* free marshalling buffer */
827 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
828 NdrProxyFreeBuffer(This
, &stubMsg
);
831 NdrFreeBuffer(&stubMsg
);
832 client_free_handle(&stubMsg
, pProcHeader
, pHandleFormat
, hBinding
);
835 TRACE("RetVal = 0x%lx\n", RetVal
);
840 /* calls a function with the specificed arguments, restoring the stack
841 * properly afterwards as we don't know the calling convention of the
843 #if defined __i386__ && defined _MSC_VER
844 __declspec(naked
) LONG_PTR __cdecl
call_server_func(SERVER_ROUTINE func
, unsigned char * args
, unsigned int stack_size
)
849 push edi
; Save registers
852 mov eax
, [ebp
+16] ; Get stack size
853 sub esp
, eax
; Make room in stack
for arguments
859 rep movsd
; Copy dword blocks
860 call
[ebp
+8] ; Call function
861 lea esp
, [ebp
-8] ; Restore stack
862 pop esi
; Restore registers
868 #elif defined __i386__ && defined __GNUC__
869 LONG_PTR __cdecl
call_server_func(SERVER_ROUTINE func
, unsigned char * args
, unsigned int stack_size
);
870 __ASM_GLOBAL_FUNC(call_server_func
,
872 "movl %esp, %ebp\n\t"
873 "pushl %edi\n\t" /* Save registers */
875 "movl 16(%ebp), %eax\n\t" /* Get stack size */
876 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
877 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for Mac OS X */
878 "movl %esp, %edi\n\t"
879 "movl %eax, %ecx\n\t"
880 "movl 12(%ebp), %esi\n\t"
881 "shrl $2, %ecx\n\t" /* divide by 4 */
883 "rep; movsl\n\t" /* Copy dword blocks */
884 "call *8(%ebp)\n\t" /* Call function */
885 "leal -8(%ebp), %esp\n\t" /* Restore stack */
886 "popl %esi\n\t" /* Restore registers */
891 #warning call_server_func not implemented for your architecture
892 LONG_PTR __cdecl
call_server_func(SERVER_ROUTINE func
, unsigned char * args
, unsigned short stack_size
)
894 FIXME("Not implemented for your architecture\n");
899 static DWORD
calc_arg_size(MIDL_STUB_MESSAGE
*pStubMsg
, PFORMAT_STRING pFormat
)
905 size
= *(const WORD
*)(pFormat
+ 2);
908 size
= *(const WORD
*)(pFormat
+ 2);
909 ComputeConformance(pStubMsg
, NULL
, pFormat
+ 4, 0);
910 size
*= pStubMsg
->MaxCount
;
912 case RPC_FC_SMFARRAY
:
913 size
= *(const WORD
*)(pFormat
+ 2);
915 case RPC_FC_LGFARRAY
:
916 size
= *(const DWORD
*)(pFormat
+ 2);
918 case RPC_FC_BOGUS_ARRAY
:
919 pFormat
= ComputeConformance(pStubMsg
, NULL
, pFormat
+ 4, *(const WORD
*)&pFormat
[2]);
920 TRACE("conformance = %ld\n", pStubMsg
->MaxCount
);
921 pFormat
= ComputeVariance(pStubMsg
, NULL
, pFormat
, pStubMsg
->MaxCount
);
922 size
= ComplexStructSize(pStubMsg
, pFormat
);
923 size
*= pStubMsg
->MaxCount
;
926 FIXME("Unhandled type %02x\n", *pFormat
);
929 size
= sizeof(void *);
935 static LONG_PTR
*stub_do_args(MIDL_STUB_MESSAGE
*pStubMsg
,
936 PFORMAT_STRING pFormat
, int phase
,
938 unsigned short number_of_params
)
942 /* current format string offset */
943 int current_offset
= 0;
944 /* current stack offset */
945 unsigned short current_stack_offset
= 0;
946 /* location to put retval into */
947 LONG_PTR
*retval_ptr
= NULL
;
949 for (i
= 0; i
< number_of_params
; i
++)
951 const NDR_PARAM_OIF_BASETYPE
*pParam
=
952 (const NDR_PARAM_OIF_BASETYPE
*)&pFormat
[current_offset
];
955 current_stack_offset
= pParam
->stack_offset
;
956 pArg
= args
+ current_stack_offset
;
958 TRACE("param[%d]: new format\n", i
);
959 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam
->param_attributes
); TRACE("\n");
960 TRACE("\tstack_offset: 0x%x\n", current_stack_offset
);
961 TRACE("\tmemory addr (before): %p -> %p\n", pArg
, *(unsigned char **)pArg
);
963 if (pParam
->param_attributes
.IsBasetype
)
965 const unsigned char *pTypeFormat
=
966 &pParam
->type_format_char
;
968 TRACE("\tbase type: 0x%02x\n", *pTypeFormat
);
970 /* make a note of the address of the return value parameter for later */
971 if (pParam
->param_attributes
.IsReturn
)
972 retval_ptr
= (LONG_PTR
*)pArg
;
976 case STUBLESS_MARSHAL
:
977 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
979 if (pParam
->param_attributes
.IsSimpleRef
)
980 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
982 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
986 if (pParam
->param_attributes
.ServerAllocSize
)
987 HeapFree(GetProcessHeap(), 0, *(void **)pArg
);
989 case STUBLESS_INITOUT
:
991 case STUBLESS_UNMARSHAL
:
992 if (pParam
->param_attributes
.ServerAllocSize
)
993 *(void **)pArg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
994 pParam
->param_attributes
.ServerAllocSize
* 8);
996 if (pParam
->param_attributes
.IsIn
)
998 if (pParam
->param_attributes
.IsSimpleRef
)
999 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
1001 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
1004 case STUBLESS_CALCSIZE
:
1005 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1007 if (pParam
->param_attributes
.IsSimpleRef
)
1008 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1010 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
1014 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1017 current_offset
+= sizeof(NDR_PARAM_OIF_BASETYPE
);
1021 const NDR_PARAM_OIF_OTHER
*pParamOther
=
1022 (const NDR_PARAM_OIF_OTHER
*)&pFormat
[current_offset
];
1024 const unsigned char * pTypeFormat
=
1025 &(pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
]);
1027 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat
);
1031 case STUBLESS_MARSHAL
:
1032 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1034 if (pParam
->param_attributes
.IsByValue
)
1035 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
1037 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1041 if (pParam
->param_attributes
.MustFree
)
1043 if (pParam
->param_attributes
.IsByValue
)
1044 call_freer(pStubMsg
, pArg
, pTypeFormat
);
1046 call_freer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1049 if (pParam
->param_attributes
.IsOut
&&
1050 !pParam
->param_attributes
.IsIn
&&
1051 !pParam
->param_attributes
.IsByValue
&&
1052 !pParam
->param_attributes
.ServerAllocSize
)
1054 pStubMsg
->pfnFree(*(void **)pArg
);
1057 if (pParam
->param_attributes
.ServerAllocSize
)
1058 HeapFree(GetProcessHeap(), 0, *(void **)pArg
);
1060 case STUBLESS_INITOUT
:
1061 if (!pParam
->param_attributes
.IsIn
&&
1062 pParam
->param_attributes
.IsOut
&&
1063 !pParam
->param_attributes
.ServerAllocSize
&&
1064 !pParam
->param_attributes
.IsByValue
)
1066 DWORD size
= calc_arg_size(pStubMsg
, pTypeFormat
);
1070 *(void **)pArg
= NdrAllocate(pStubMsg
, size
);
1071 memset(*(void **)pArg
, 0, size
);
1075 case STUBLESS_UNMARSHAL
:
1076 if (pParam
->param_attributes
.ServerAllocSize
)
1077 *(void **)pArg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1078 pParam
->param_attributes
.ServerAllocSize
* 8);
1080 if (pParam
->param_attributes
.IsIn
)
1082 if (pParam
->param_attributes
.IsByValue
)
1083 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
1085 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
1088 case STUBLESS_CALCSIZE
:
1089 if (pParam
->param_attributes
.IsOut
|| pParam
->param_attributes
.IsReturn
)
1091 if (pParam
->param_attributes
.IsByValue
)
1092 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
1094 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1098 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1101 current_offset
+= sizeof(NDR_PARAM_OIF_OTHER
);
1103 TRACE("\tmemory addr (after): %p -> %p\n", pArg
, *(unsigned char **)pArg
);
1109 static LONG_PTR
*stub_do_old_args(MIDL_STUB_MESSAGE
*pStubMsg
,
1110 PFORMAT_STRING pFormat
, int phase
,
1111 unsigned char *args
,
1112 unsigned short stack_size
, BOOL object
)
1116 /* current format string offset */
1117 int current_offset
= 0;
1118 /* current stack offset */
1119 unsigned short current_stack_offset
= 0;
1120 /* location to put retval into */
1121 LONG_PTR
*retval_ptr
= NULL
;
1123 for (i
= 0; TRUE
; i
++)
1125 const NDR_PARAM_OI_BASETYPE
*pParam
=
1126 (const NDR_PARAM_OI_BASETYPE
*)&pFormat
[current_offset
];
1127 /* note: current_stack_offset starts after the This pointer
1128 * if present, so adjust this */
1129 unsigned short current_stack_offset_adjusted
= current_stack_offset
+
1130 (object
? sizeof(void *) : 0);
1131 unsigned char *pArg
= args
+ current_stack_offset_adjusted
;
1133 /* no more parameters; exit loop */
1134 if (current_stack_offset_adjusted
>= stack_size
)
1137 TRACE("param[%d]: old format\n", i
);
1138 TRACE("\tparam_direction: 0x%x\n", pParam
->param_direction
);
1139 TRACE("\tstack_offset: 0x%x\n", current_stack_offset_adjusted
);
1141 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
||
1142 pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1144 const unsigned char *pTypeFormat
=
1145 &pParam
->type_format_char
;
1147 TRACE("\tbase type 0x%02x\n", *pTypeFormat
);
1149 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1150 retval_ptr
= (LONG_PTR
*)pArg
;
1154 case STUBLESS_MARSHAL
:
1155 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1156 call_marshaller(pStubMsg
, pArg
, pTypeFormat
);
1159 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
1160 call_freer(pStubMsg
, pArg
, pTypeFormat
);
1162 case STUBLESS_UNMARSHAL
:
1163 if (pParam
->param_direction
== RPC_FC_IN_PARAM_BASETYPE
)
1164 call_unmarshaller(pStubMsg
, &pArg
, pTypeFormat
, 0);
1166 case STUBLESS_CALCSIZE
:
1167 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM_BASETYPE
)
1168 call_buffer_sizer(pStubMsg
, pArg
, pTypeFormat
);
1171 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1174 current_stack_offset
+= type_stack_size(*pTypeFormat
);
1175 current_offset
+= sizeof(NDR_PARAM_OI_BASETYPE
);
1179 const NDR_PARAM_OI_OTHER
*pParamOther
=
1180 (const NDR_PARAM_OI_OTHER
*)&pFormat
[current_offset
];
1182 const unsigned char * pTypeFormat
=
1183 &pStubMsg
->StubDesc
->pFormatTypes
[pParamOther
->type_offset
];
1185 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat
);
1187 if (pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
1188 retval_ptr
= (LONG_PTR
*)pArg
;
1192 case STUBLESS_MARSHAL
:
1193 if (pParam
->param_direction
== RPC_FC_OUT_PARAM
||
1194 pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1195 pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
1196 call_marshaller(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1199 if (pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1200 pParam
->param_direction
== RPC_FC_IN_PARAM
)
1201 call_freer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1202 else if (pParam
->param_direction
== RPC_FC_OUT_PARAM
)
1203 pStubMsg
->pfnFree(*(void **)pArg
);
1205 case STUBLESS_INITOUT
:
1206 if (pParam
->param_direction
== RPC_FC_OUT_PARAM
)
1208 DWORD size
= calc_arg_size(pStubMsg
, pTypeFormat
);
1212 *(void **)pArg
= NdrAllocate(pStubMsg
, size
);
1213 memset(*(void **)pArg
, 0, size
);
1217 case STUBLESS_UNMARSHAL
:
1218 if (pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1219 pParam
->param_direction
== RPC_FC_IN_PARAM
)
1220 call_unmarshaller(pStubMsg
, (unsigned char **)pArg
, pTypeFormat
, 0);
1222 case STUBLESS_CALCSIZE
:
1223 if (pParam
->param_direction
== RPC_FC_OUT_PARAM
||
1224 pParam
->param_direction
== RPC_FC_IN_OUT_PARAM
||
1225 pParam
->param_direction
== RPC_FC_RETURN_PARAM
)
1226 call_buffer_sizer(pStubMsg
, *(unsigned char **)pArg
, pTypeFormat
);
1229 RpcRaiseException(RPC_S_INTERNAL_ERROR
);
1232 current_stack_offset
+= pParamOther
->stack_size
* sizeof(INT
);
1233 current_offset
+= sizeof(NDR_PARAM_OI_OTHER
);
1240 /***********************************************************************
1241 * NdrStubCall2 [RPCRT4.@]
1243 * Unmarshals [in] parameters, calls either a method in an object or a server
1244 * function, marshals any [out] parameters and frees any allocated data.
1247 * Used by stubless MIDL-generated code.
1249 LONG WINAPI
NdrStubCall2(
1250 struct IRpcStubBuffer
* pThis
,
1251 struct IRpcChannelBuffer
* pChannel
,
1252 PRPC_MESSAGE pRpcMsg
,
1253 DWORD
* pdwStubPhase
)
1255 const MIDL_SERVER_INFO
*pServerInfo
;
1256 const MIDL_STUB_DESC
*pStubDesc
;
1257 PFORMAT_STRING pFormat
;
1258 MIDL_STUB_MESSAGE stubMsg
;
1259 /* pointer to start of stack to pass into stub implementation */
1260 unsigned char * args
;
1262 unsigned short stack_size
;
1263 /* number of parameters. optional for client to give it to us */
1264 unsigned char number_of_params
= ~0;
1265 /* cache of Oif_flags from v2 procedure header */
1266 INTERPRETER_OPT_FLAGS Oif_flags
= { 0 };
1267 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
1268 INTERPRETER_OPT_FLAGS2 ext_flags
= { 0 };
1269 /* the type of pass we are currently doing */
1271 /* header for procedure string */
1272 const NDR_PROC_HEADER
*pProcHeader
;
1273 /* offset in format string for start of params */
1274 int parameter_start_offset
;
1275 /* current format string offset */
1277 /* -Oif or -Oicf generated format */
1278 BOOL bV2Format
= FALSE
;
1279 /* location to put retval into */
1280 LONG_PTR
*retval_ptr
= NULL
;
1282 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis
, pChannel
, pRpcMsg
, pdwStubPhase
);
1285 pServerInfo
= CStdStubBuffer_GetServerInfo(pThis
);
1287 pServerInfo
= ((RPC_SERVER_INTERFACE
*)pRpcMsg
->RpcInterfaceInformation
)->InterpreterInfo
;
1289 pStubDesc
= pServerInfo
->pStubDesc
;
1290 pFormat
= pServerInfo
->ProcString
+ pServerInfo
->FmtStringOffset
[pRpcMsg
->ProcNum
];
1291 pProcHeader
= (const NDR_PROC_HEADER
*)&pFormat
[0];
1293 /* Later NDR language versions probably won't be backwards compatible */
1294 if (pStubDesc
->Version
> 0x50002)
1296 FIXME("Incompatible stub description version: 0x%x\n", pStubDesc
->Version
);
1297 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
);
1300 /* create the full pointer translation tables, if requested */
1301 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
1302 stubMsg
.FullPtrXlatTables
= NdrFullPointerXlatInit(0,XLAT_SERVER
);
1304 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
1306 const NDR_PROC_HEADER_RPC
*pProcHeader
= (const NDR_PROC_HEADER_RPC
*)&pFormat
[0];
1307 stack_size
= pProcHeader
->stack_size
;
1308 current_offset
= sizeof(NDR_PROC_HEADER_RPC
);
1313 stack_size
= pProcHeader
->stack_size
;
1314 current_offset
= sizeof(NDR_PROC_HEADER
);
1317 TRACE("Oi_flags = 0x%02x\n", pProcHeader
->Oi_flags
);
1320 switch (pProcHeader
->handle_type
)
1322 /* explicit binding: parse additional section */
1323 case RPC_FC_BIND_EXPLICIT
:
1324 switch (pFormat
[current_offset
]) /* handle_type */
1326 case RPC_FC_BIND_PRIMITIVE
: /* explicit primitive */
1327 current_offset
+= sizeof(NDR_EHD_PRIMITIVE
);
1329 case RPC_FC_BIND_GENERIC
: /* explicit generic */
1330 current_offset
+= sizeof(NDR_EHD_GENERIC
);
1332 case RPC_FC_BIND_CONTEXT
: /* explicit context */
1333 current_offset
+= sizeof(NDR_EHD_CONTEXT
);
1336 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
1337 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
1340 case RPC_FC_BIND_GENERIC
: /* implicit generic */
1341 case RPC_FC_BIND_PRIMITIVE
: /* implicit primitive */
1342 case RPC_FC_CALLBACK_HANDLE
: /* implicit callback */
1343 case RPC_FC_AUTO_HANDLE
: /* implicit auto handle */
1346 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader
->handle_type
);
1347 RpcRaiseException(RPC_X_BAD_STUB_DATA
);
1350 bV2Format
= (pStubDesc
->Version
>= 0x20000);
1354 const NDR_PROC_PARTIAL_OIF_HEADER
*pOIFHeader
=
1355 (const NDR_PROC_PARTIAL_OIF_HEADER
*)&pFormat
[current_offset
];
1357 Oif_flags
= pOIFHeader
->Oi2Flags
;
1358 number_of_params
= pOIFHeader
->number_of_params
;
1360 current_offset
+= sizeof(NDR_PROC_PARTIAL_OIF_HEADER
);
1363 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags
);
1365 if (Oif_flags
.HasExtensions
)
1367 const NDR_PROC_HEADER_EXTS
*pExtensions
=
1368 (const NDR_PROC_HEADER_EXTS
*)&pFormat
[current_offset
];
1369 ext_flags
= pExtensions
->Flags2
;
1370 current_offset
+= pExtensions
->Size
;
1373 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1374 NdrStubInitialize(pRpcMsg
, &stubMsg
, pStubDesc
, pChannel
);
1376 NdrServerInitializeNew(pRpcMsg
, &stubMsg
, pStubDesc
);
1378 /* store the RPC flags away */
1379 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCFLAGS
)
1380 pRpcMsg
->RpcFlags
= ((const NDR_PROC_HEADER_RPC
*)pProcHeader
)->rpc_flags
;
1382 /* use alternate memory allocation routines */
1383 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_RPCSSALLOC
)
1385 NdrRpcSsEnableAllocate(&stubMsg
);
1387 FIXME("Set RPCSS memory allocation routines\n");
1390 if (Oif_flags
.HasPipes
)
1392 FIXME("pipes not supported yet\n");
1393 RpcRaiseException(RPC_X_WRONG_STUB_VERSION
); /* FIXME: remove when implemented */
1394 /* init pipes package */
1395 /* NdrPipesInitialize(...) */
1397 if (ext_flags
.HasNewCorrDesc
)
1399 /* initialize extra correlation package */
1400 FIXME("new correlation description not implemented\n");
1401 stubMsg
.fHasNewCorrDesc
= TRUE
;
1404 /* convert strings, floating point values and endianess into our
1405 * preferred format */
1406 if ((pRpcMsg
->DataRepresentation
& 0x0000FFFFUL
) != NDR_LOCAL_DATA_REPRESENTATION
)
1407 NdrConvert(&stubMsg
, pFormat
);
1409 parameter_start_offset
= current_offset
;
1411 TRACE("allocating memory for stack of size %x\n", stack_size
);
1413 args
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, stack_size
);
1414 stubMsg
.StackTop
= args
; /* used by conformance of top-level objects */
1416 /* add the implicit This pointer as the first arg to the function if we
1417 * are calling an object method */
1419 *(void **)args
= ((CStdStubBuffer
*)pThis
)->pvServerObject
;
1422 * 1. STUBLESS_UNMARHSAL - unmarshal [in] params from buffer
1423 * 2. STUBLESS_CALLSERVER - send/receive buffer
1424 * 3. STUBLESS_CALCSIZE - get [out] buffer size
1425 * 4. STUBLESS_GETBUFFER - allocate [out] buffer
1426 * 5. STUBLESS_MARHSAL - marshal [out] params to buffer
1428 for (phase
= STUBLESS_UNMARSHAL
; phase
<= STUBLESS_FREE
; phase
++)
1430 TRACE("phase = %d\n", phase
);
1433 case STUBLESS_CALLSERVER
:
1434 /* call the server function */
1435 if (pServerInfo
->ThunkTable
&& pServerInfo
->ThunkTable
[pRpcMsg
->ProcNum
])
1436 pServerInfo
->ThunkTable
[pRpcMsg
->ProcNum
](&stubMsg
);
1439 SERVER_ROUTINE func
;
1442 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1444 SERVER_ROUTINE
*vtbl
= *(SERVER_ROUTINE
**)((CStdStubBuffer
*)pThis
)->pvServerObject
;
1445 func
= vtbl
[pRpcMsg
->ProcNum
];
1448 func
= pServerInfo
->DispatchTable
[pRpcMsg
->ProcNum
];
1450 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1451 retval
= call_server_func(func
, args
, stack_size
);
1455 TRACE("stub implementation returned 0x%lx\n", retval
);
1456 *retval_ptr
= retval
;
1459 TRACE("void stub implementation\n");
1462 stubMsg
.Buffer
= NULL
;
1463 stubMsg
.BufferLength
= 0;
1466 case STUBLESS_GETBUFFER
:
1467 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
)
1468 NdrStubGetBuffer(pThis
, pChannel
, &stubMsg
);
1473 pRpcMsg
->BufferLength
= stubMsg
.BufferLength
;
1474 /* allocate buffer for [out] and [ret] params */
1475 Status
= I_RpcGetBuffer(pRpcMsg
);
1477 RpcRaiseException(Status
);
1478 stubMsg
.Buffer
= pRpcMsg
->Buffer
;
1481 case STUBLESS_UNMARSHAL
:
1482 case STUBLESS_INITOUT
:
1483 case STUBLESS_CALCSIZE
:
1484 case STUBLESS_MARSHAL
:
1487 retval_ptr
= stub_do_args(&stubMsg
, &pFormat
[parameter_start_offset
],
1488 phase
, args
, number_of_params
);
1490 retval_ptr
= stub_do_old_args(&stubMsg
, &pFormat
[parameter_start_offset
],
1491 phase
, args
, stack_size
,
1492 (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_OBJECT
));
1496 ERR("shouldn't reach here. phase %d\n", phase
);
1501 pRpcMsg
->BufferLength
= (unsigned int)(stubMsg
.Buffer
- (unsigned char *)pRpcMsg
->Buffer
);
1503 if (ext_flags
.HasNewCorrDesc
)
1505 /* free extra correlation package */
1506 /* NdrCorrelationFree(&stubMsg); */
1509 if (Oif_flags
.HasPipes
)
1511 /* NdrPipesDone(...) */
1514 /* free the full pointer translation tables */
1515 if (pProcHeader
->Oi_flags
& RPC_FC_PROC_OIF_FULLPTR
)
1516 NdrFullPointerXlatFree(stubMsg
.FullPtrXlatTables
);
1518 /* free server function stack */
1519 HeapFree(GetProcessHeap(), 0, args
);
1524 /***********************************************************************
1525 * NdrServerCall2 [RPCRT4.@]
1527 void WINAPI
NdrServerCall2(PRPC_MESSAGE pRpcMsg
)
1530 NdrStubCall2(NULL
, NULL
, pRpcMsg
, &dwPhase
);