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"
43 #include "wine/debug.h"
44 #include "wine/rpcfc.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 FIXME("format type 0x%x not implemented\n", pFormat[0]);
95 RpcRaiseException(RPC_X_BAD_STUB_DATA);
99 static inline unsigned long call_memory_sizer(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat)
101 NDR_MEMORYSIZE m = NdrMemorySizer[pFormat[0] & NDR_TABLE_MASK];
102 if (m) return m(pStubMsg, pFormat);
105 FIXME("format type 0x%x not implemented\n", pFormat[0]);
106 RpcRaiseException(RPC_X_BAD_STUB_DATA);
111 /* there can't be any alignment with the structures in this file */
112 #include "pshpack1.h"
114 #define STUBLESS_UNMARSHAL 1
115 #define STUBLESS_CALLSERVER 2
116 #define STUBLESS_CALCSIZE 3
117 #define STUBLESS_GETBUFFER 4
118 #define STUBLESS_MARSHAL 5
120 /* From http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/parameter_descriptors.asp */
121 typedef struct _NDR_PROC_HEADER
123 /* type of handle to use:
124 * RPC_FC_BIND_EXPLICIT = 0 - Explicit handle.
125 * Handle is passed as a parameter to the function.
126 * Indicates that explicit handle information follows the header,
127 * which actually describes the handle.
128 * RPC_FC_BIND_GENERIC = 31 - Implicit handle with custom binding routines
129 * (MIDL_STUB_DESC::IMPLICIT_HANDLE_INFO::pGenericBindingInfo)
130 * RPC_FC_BIND_PRIMITIVE = 32 - Implicit handle using handle_t created by
131 * calling application
132 * RPC_FC_AUTO_HANDLE = 33 - Automatic handle
133 * RPC_FC_CALLBACK_HANDLE = 34 - undocmented
135 unsigned char handle_type;
138 * Oi_FULL_PTR_USED = 0x01 - A full pointer can have the value NULL and can
139 * change during the call from NULL to non-NULL and supports aliasing
140 * and cycles. Indicates that the NdrFullPointerXlatInit function
142 * Oi_RPCSS_ALLOC_USED = 0x02 - Use RpcSS allocate/free routines instead of
143 * normal allocate/free routines
144 * Oi_OBJECT_PROC = 0x04 - Indicates a procedure that is part of an OLE
145 * interface, rather than a DCE RPC interface.
146 * Oi_HAS_RPCFLAGS = 0x08 - Indicates that the rpc_flags element is
147 * present in the header.
148 * Oi_HAS_COMM_OR_FAULT = 0x20 - If Oi_OBJECT_PROC not present only then
149 * indicates that the procedure has the comm_status or fault_status
151 * Oi_OBJ_USE_V2_INTERPRETER = 0x20 - If Oi_OBJECT_PROC present only
152 * then indicates that the format string is in -Oif or -Oicf format
153 * Oi_USE_NEW_INIT_ROUTINES = 0x40 - Use NdrXInitializeNew instead of
156 unsigned char Oi_flags;
158 /* the zero-based index of the procedure */
159 unsigned short proc_num;
161 /* total size of all parameters on the stack, including any "this"
162 * pointer and/or return value */
163 unsigned short stack_size;
166 /* same as above struct except additional element rpc_flags */
167 typedef struct _NDR_PROC_HEADER_RPC
169 unsigned char handle_type;
170 unsigned char Oi_flags;
173 * RPCF_Idempotent = 0x0001 - [idempotent] MIDL attribute
174 * RPCF_Broadcast = 0x0002 - [broadcast] MIDL attribute
175 * RPCF_Maybe = 0x0004 - [maybe] MIDL attribute
176 * Reserved = 0x0008 - 0x0080
177 * RPCF_Message = 0x0100 - [message] MIDL attribute
178 * Reserved = 0x0200 - 0x1000
179 * RPCF_InputSynchronous = 0x2000 - unknown
180 * RPCF_Asynchronous = 0x4000 - [async] MIDL attribute
183 unsigned long rpc_flags;
184 unsigned short proc_num;
185 unsigned short stack_size;
187 } NDR_PROC_HEADER_RPC;
189 typedef struct _NDR_PROC_PARTIAL_OIF_HEADER
191 /* the pre-computed client buffer size so that interpreter can skip all
192 * or some (if the flag RPC_FC_PROC_OI2F_CLTMUSTSIZE is specified) of the
194 unsigned short constant_client_buffer_size;
196 /* the pre-computed server buffer size so that interpreter can skip all
197 * or some (if the flag RPC_FC_PROC_OI2F_SRVMUSTSIZE is specified) of the
199 unsigned short constant_server_buffer_size;
201 INTERPRETER_OPT_FLAGS Oi2Flags;
203 /* number of params */
204 unsigned char number_of_params;
205 } NDR_PROC_PARTIAL_OIF_HEADER;
207 typedef struct _NDR_PARAM_OI_BASETYPE
209 /* parameter direction. One of:
210 * FC_IN_PARAM_BASETYPE = 0x4e - an in param
211 * FC_RETURN_PARAM_BASETYPE = 0x53 - a return param
213 unsigned char param_direction;
215 /* One of: FC_BYTE,FC_CHAR,FC_SMALL,FC_USMALL,FC_WCHAR,FC_SHORT,FC_USHORT,
216 * FC_LONG,FC_ULONG,FC_FLOAT,FC_HYPER,FC_DOUBLE,FC_ENUM16,FC_ENUM32,
217 * FC_ERROR_STATUS_T,FC_INT3264,FC_UINT3264 */
218 unsigned char type_format_char;
219 } NDR_PARAM_OI_BASETYPE;
221 typedef struct _NDR_PARAM_OI_OTHER
224 * FC_IN_PARAM = 0x4d - An in param
225 * FC_IN_OUT_PARAM = 0x50 - An in/out param
226 * FC_OUT_PARAM = 0x51 - An out param
227 * FC_RETURN_PARAM = 0x52 - A return value
228 * FC_IN_PARAM_NO_FREE_INST = 0x4f - A param for which no freeing is done
230 unsigned char param_direction;
232 /* Size of param on stack in NUMBERS OF INTS */
233 unsigned char stack_size;
235 /* offset in the type format string table */
236 unsigned short type_offset;
237 } NDR_PARAM_OI_OTHER;
239 typedef struct _NDR_PARAM_OIF_BASETYPE
241 PARAM_ATTRIBUTES param_attributes;
243 /* the offset on the calling stack where the parameter is located */
244 unsigned short stack_offset;
246 /* see NDR_PARAM_OI_BASETYPE::type_format_char */
247 unsigned char type_format_char;
250 unsigned char unused;
251 } NDR_PARAM_OIF_BASETYPE;
253 typedef struct _NDR_PARAM_OIF_OTHER
255 PARAM_ATTRIBUTES param_attributes;
257 /* see NDR_PARAM_OIF_BASETYPE::stack_offset */
258 unsigned short stack_offset;
260 /* offset into the provided type format string where the type for this
261 * parameter starts */
262 unsigned short type_offset;
263 } NDR_PARAM_OIF_OTHER;
265 /* explicit handle description for FC_BIND_PRIMITIVE type */
266 typedef struct _NDR_EHD_PRIMITIVE
268 /* FC_BIND_PRIMITIVE */
269 unsigned char handle_type;
271 /* is the handle passed in via a pointer? */
274 /* offset from the beginning of the stack to the handle in bytes */
275 unsigned short offset;
278 /* explicit handle description for FC_BIND_GENERIC type */
279 typedef struct _NDR_EHD_GENERIC
281 /* FC_BIND_GENERIC */
282 unsigned char handle_type;
284 /* upper 4bits is a flag indicating whether the handle is passed in
285 * via a pointer. lower 4bits is the size of the user defined generic
286 * handle type. the size must be less than or equal to the machine
288 unsigned char flag_and_size;
290 /* offset from the beginning of the stack to the handle in bytes */
291 unsigned short offset;
293 /* the index into the aGenericBindingRoutinesPairs field of MIDL_STUB_DESC
294 * giving the bind and unbind routines for the handle */
295 unsigned char binding_routine_pair_index;
298 unsigned char unused;
301 /* explicit handle description for FC_BIND_CONTEXT type */
302 typedef struct _NDR_EHD_CONTEXT
304 /* FC_BIND_CONTEXT */
305 unsigned char handle_type;
307 /* Any of the following flags:
308 * NDR_CONTEXT_HANDLE_CANNOT_BE_NULL = 0x01
309 * NDR_CONTEXT_HANDLE_SERIALIZE = 0x02
310 * NDR_CONTEXT_HANDLE_NO_SERIALIZE = 0x04
311 * NDR_STRICT_CONTEXT_HANDLE = 0x08
312 * HANDLE_PARAM_IS_OUT = 0x20
313 * HANDLE_PARAM_IS_RETURN = 0x21
314 * HANDLE_PARAM_IS_IN = 0x40
315 * HANDLE_PARAM_IS_VIA_PTR = 0x80
319 /* offset from the beginning of the stack to the handle in bytes */
320 unsigned short offset;
322 /* zero-based index on rundown routine in apfnNdrRundownRoutines field
323 * of MIDL_STUB_DESC */
324 unsigned char context_rundown_routine_index;
326 /* varies depending on NDR version used.
327 * V1: zero-based index into parameters
328 * V2: zero-based index into handles that are parameters */
329 unsigned char param_num;
334 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
336 #if 0 /* these functions are not defined yet */
337 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
338 pMessage->pfnFree = NdrRpcSmClientFree;
342 static void WINAPI dump_RPC_FC_PROC_PF(PARAM_ATTRIBUTES param_attributes)
344 if (param_attributes.MustSize) TRACE(" MustSize");
345 if (param_attributes.MustFree) TRACE(" MustFree");
346 if (param_attributes.IsPipe) TRACE(" IsPipe");
347 if (param_attributes.IsIn) TRACE(" IsIn");
348 if (param_attributes.IsOut) TRACE(" IsOut");
349 if (param_attributes.IsReturn) TRACE(" IsReturn");
350 if (param_attributes.IsBasetype) TRACE(" IsBasetype");
351 if (param_attributes.IsByValue) TRACE(" IsByValue");
352 if (param_attributes.IsSimpleRef) TRACE(" IsSimpleRef");
353 if (param_attributes.IsDontCallFreeInst) TRACE(" IsDontCallFreeInst");
354 if (param_attributes.SaveForAsyncFinish) TRACE(" SaveForAsyncFinish");
355 if (param_attributes.ServerAllocSize) TRACE(" ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
358 static void WINAPI dump_INTERPRETER_OPT_FLAGS(INTERPRETER_OPT_FLAGS Oi2Flags)
360 if (Oi2Flags.ServerMustSize) TRACE(" ServerMustSize");
361 if (Oi2Flags.ClientMustSize) TRACE(" ClientMustSize");
362 if (Oi2Flags.HasReturn) TRACE(" HasReturn");
363 if (Oi2Flags.HasPipes) TRACE(" HasPipes");
364 if (Oi2Flags.Unused) TRACE(" Unused");
365 if (Oi2Flags.HasAsyncUuid) TRACE(" HasAsyncUuid");
366 if (Oi2Flags.HasExtensions) TRACE(" HasExtensions");
367 if (Oi2Flags.HasAsyncHandle) TRACE(" HasAsyncHandle");
371 #define ARG_FROM_OFFSET(stubMsg, offset) ((stubMsg).StackTop + (offset))
373 static PFORMAT_STRING client_get_handle(
374 PMIDL_STUB_MESSAGE pStubMsg, const NDR_PROC_HEADER *pProcHeader,
375 PFORMAT_STRING pFormat, handle_t *phBinding)
378 switch (pProcHeader->handle_type)
380 /* explicit binding: parse additional section */
381 case RPC_FC_BIND_EXPLICIT:
382 switch (*pFormat) /* handle_type */
384 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
386 NDR_EHD_PRIMITIVE * pDesc = (NDR_EHD_PRIMITIVE *)pFormat;
388 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
390 if (pDesc->flag) /* pointer to binding */
391 *phBinding = **(handle_t **)ARG_FROM_OFFSET(*pStubMsg, pDesc->offset);
393 *phBinding = *(handle_t *)ARG_FROM_OFFSET(*pStubMsg, pDesc->offset);
394 return pFormat + sizeof(NDR_EHD_PRIMITIVE);
396 case RPC_FC_BIND_GENERIC: /* explicit generic */
397 FIXME("RPC_FC_BIND_GENERIC\n");
398 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
399 return pFormat + sizeof(NDR_EHD_GENERIC);
400 case RPC_FC_BIND_CONTEXT: /* explicit context */
402 NDR_EHD_CONTEXT * pDesc = (NDR_EHD_CONTEXT *)pFormat;
403 NDR_CCONTEXT context_handle;
404 TRACE("Explicit bind context\n");
405 if (pDesc->flags & HANDLE_PARAM_IS_VIA_PTR)
407 TRACE("\tHANDLE_PARAM_IS_VIA_PTR\n");
408 context_handle = **(NDR_CCONTEXT **)ARG_FROM_OFFSET(*pStubMsg, pDesc->offset);
411 context_handle = *(NDR_CCONTEXT *)ARG_FROM_OFFSET(*pStubMsg, pDesc->offset);
412 if ((pDesc->flags & NDR_CONTEXT_HANDLE_CANNOT_BE_NULL) &&
415 ERR("null context handle isn't allowed\n");
416 RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);
419 *phBinding = NDRCContextBinding(context_handle);
420 /* FIXME: should we store this structure in stubMsg.pContext? */
421 return pFormat + sizeof(NDR_EHD_CONTEXT);
424 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
425 RpcRaiseException(RPC_X_BAD_STUB_DATA);
428 case RPC_FC_BIND_GENERIC: /* implicit generic */
429 FIXME("RPC_FC_BIND_GENERIC\n");
430 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
432 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
433 TRACE("Implicit primitive handle\n");
434 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
436 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
437 FIXME("RPC_FC_CALLBACK_HANDLE\n");
439 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
440 /* strictly speaking, it isn't necessary to set hBinding here
441 * since it isn't actually used (hence the automatic in its name),
442 * but then why does MIDL generate a valid entry in the
443 * MIDL_STUB_DESC for it? */
444 TRACE("Implicit auto handle\n");
445 *phBinding = *pStubMsg->StubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
448 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
449 RpcRaiseException(RPC_X_BAD_STUB_DATA);
454 /* the return type should be CLIENT_CALL_RETURN, but this is incompatible
455 * with the way gcc returns structures. "void *" should be the largest type
456 * that MIDL should allow you to return anyway */
457 LONG_PTR WINAPIV NdrClientCall2(PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, ...)
459 /* pointer to start of stack where arguments start */
461 MIDL_STUB_MESSAGE stubMsg;
462 handle_t hBinding = NULL;
463 /* procedure number */
464 unsigned short procedure_number;
466 unsigned short stack_size;
467 /* number of parameters. optional for client to give it to us */
468 unsigned char number_of_params = ~0;
469 /* cache of Oif_flags from v2 procedure header */
470 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
471 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
472 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
473 /* the type of pass we are currently doing */
475 /* header for procedure string */
476 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
477 /* -Oif or -Oicf generated format */
478 BOOL bV2Format = FALSE;
479 /* the value to return to the client from the remote procedure */
481 /* the pointer to the object when in OLE mode */
484 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
486 /* Later NDR language versions probably won't be backwards compatible */
487 if (pStubDesc->Version > 0x50002)
489 FIXME("Incompatible stub description version: 0x%lx\n", pStubDesc->Version);
490 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
493 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
495 NDR_PROC_HEADER_RPC * pProcHeader = (NDR_PROC_HEADER_RPC *)&pFormat[0];
496 stack_size = pProcHeader->stack_size;
497 procedure_number = pProcHeader->proc_num;
498 pFormat += sizeof(NDR_PROC_HEADER_RPC);
502 stack_size = pProcHeader->stack_size;
503 procedure_number = pProcHeader->proc_num;
504 TRACE("proc num: %d\n", procedure_number);
505 pFormat += sizeof(NDR_PROC_HEADER);
508 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
510 /* object is always the first argument */
511 This = *(void **)ARG_FROM_OFFSET(stubMsg, 0);
512 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
515 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
517 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
518 TRACE("MIDL stub version = 0x%lx\n", pStubDesc->MIDLVersion);
520 /* needed for conformance of top-level objects */
522 stubMsg.StackTop = *(unsigned char **)(&pFormat+1);
524 # warning Stack not retrieved for your CPU architecture
527 /* we only need a handle if this isn't an object method */
528 if (!(pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT))
530 pFormat = client_get_handle(&stubMsg, pProcHeader, pFormat, &hBinding);
531 if (!pFormat) return 0;
534 bV2Format = (pStubDesc->Version >= 0x20000);
538 NDR_PROC_PARTIAL_OIF_HEADER * pOIFHeader =
539 (NDR_PROC_PARTIAL_OIF_HEADER*)pFormat;
541 Oif_flags = pOIFHeader->Oi2Flags;
542 number_of_params = pOIFHeader->number_of_params;
544 pFormat += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
547 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags);
549 if (Oif_flags.HasExtensions)
551 NDR_PROC_HEADER_EXTS * pExtensions =
552 (NDR_PROC_HEADER_EXTS *)pFormat;
553 ext_flags = pExtensions->Flags2;
554 pFormat += pExtensions->Size;
557 /* create the full pointer translation tables, if requested */
558 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
560 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
562 FIXME("initialize full pointer translation tables\n");
565 stubMsg.BufferLength = 0;
567 /* store the RPC flags away */
568 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
569 rpcMsg.RpcFlags = ((NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
571 /* use alternate memory allocation routines */
572 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
573 NdrRpcSmSetClientToOsf(&stubMsg);
575 if (Oif_flags.HasPipes)
577 FIXME("pipes not supported yet\n");
578 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
579 /* init pipes package */
580 /* NdrPipesInitialize(...) */
582 if (ext_flags.HasNewCorrDesc)
584 /* initialize extra correlation package */
585 FIXME("new correlation description not implemented\n");
586 stubMsg.fHasNewCorrDesc = TRUE;
590 * 1. PROXY_CALCSIZE - calculate the buffer size
591 * 2. PROXY_GETBUFFER - allocate the buffer
592 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
593 * 4. PROXY_SENDRECEIVE - send/receive buffer
594 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
596 for (phase = PROXY_CALCSIZE; phase <= PROXY_UNMARSHAL; phase++)
598 /* current format string offset */
600 /* current stack offset */
601 unsigned short current_stack_offset;
605 TRACE("phase = %d\n", phase);
608 case PROXY_GETBUFFER:
609 /* allocate the buffer */
610 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
611 NdrProxyGetBuffer(This, &stubMsg);
612 else if (Oif_flags.HasPipes)
613 /* NdrGetPipeBuffer(...) */
614 FIXME("pipes not supported yet\n");
617 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
619 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
621 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
624 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
627 case PROXY_SENDRECEIVE:
628 /* send the [in] params and receive the [out] and [retval]
630 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
631 NdrProxySendReceive(This, &stubMsg);
632 else if (Oif_flags.HasPipes)
633 /* NdrPipesSendReceive(...) */
634 FIXME("pipes not supported yet\n");
637 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
639 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
641 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
644 NdrSendReceive(&stubMsg, stubMsg.Buffer);
647 /* convert strings, floating point values and endianess into our
648 * preferred format */
649 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
650 NdrConvert(&stubMsg, pFormat);
655 case PROXY_UNMARSHAL:
657 current_stack_offset = 0;
659 /* NOTE: V1 style format does't terminate on the number_of_params
660 * condition as it doesn't have this attribute. Instead it
661 * terminates when the stack size given in the header is exceeded.
663 for (i = 0; i < number_of_params; i++)
665 if (bV2Format) /* new parameter format */
667 NDR_PARAM_OIF_BASETYPE * pParam =
668 (NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];
669 unsigned char * pArg;
671 current_stack_offset = pParam->stack_offset;
672 pArg = ARG_FROM_OFFSET(stubMsg, current_stack_offset);
674 TRACE("param[%d]: new format\n", i);
675 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");
676 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
677 TRACE("\tmemory addr (before): %p\n", pArg);
679 if (pParam->param_attributes.IsBasetype)
681 const unsigned char * pTypeFormat =
682 &pParam->type_format_char;
684 if (pParam->param_attributes.IsSimpleRef)
685 pArg = *(unsigned char **)pArg;
687 TRACE("\tbase type: 0x%02x\n", *pTypeFormat);
692 if (pParam->param_attributes.IsIn)
693 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
696 if (pParam->param_attributes.IsIn)
697 call_marshaller(&stubMsg, pArg, pTypeFormat);
699 case PROXY_UNMARSHAL:
700 if (pParam->param_attributes.IsOut)
702 unsigned char *pRetVal = (unsigned char *)&RetVal;
703 if (pParam->param_attributes.IsReturn)
704 call_unmarshaller(&stubMsg, &pRetVal, pTypeFormat, 0);
706 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
707 TRACE("pRetVal = %p\n", pRetVal);
711 RpcRaiseException(RPC_S_INTERNAL_ERROR);
714 current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);
718 NDR_PARAM_OIF_OTHER * pParamOther =
719 (NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];
721 const unsigned char * pTypeFormat =
722 &(pStubDesc->pFormatTypes[pParamOther->type_offset]);
724 /* if a simple ref pointer then we have to do the
725 * check for the pointer being non-NULL. */
726 if (pParam->param_attributes.IsSimpleRef)
728 if (!*(unsigned char **)pArg)
729 RpcRaiseException(RPC_X_NULL_REF_POINTER);
732 TRACE("\tcomplex type: 0x%02x\n", *pTypeFormat);
737 if (pParam->param_attributes.IsIn)
739 if (pParam->param_attributes.IsByValue)
740 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
742 call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
746 if (pParam->param_attributes.IsIn)
748 if (pParam->param_attributes.IsByValue)
749 call_marshaller(&stubMsg, pArg, pTypeFormat);
751 call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
754 case PROXY_UNMARSHAL:
755 if (pParam->param_attributes.IsOut)
757 unsigned char *pRetVal = (unsigned char *)&RetVal;
758 if (pParam->param_attributes.IsReturn)
759 call_unmarshaller(&stubMsg, &pRetVal, pTypeFormat, 0);
760 else if (pParam->param_attributes.IsByValue)
761 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
763 call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);
767 RpcRaiseException(RPC_S_INTERNAL_ERROR);
770 current_offset += sizeof(NDR_PARAM_OIF_OTHER);
772 TRACE("\tmemory addr (after): %p\n", pArg);
774 else /* old parameter format */
776 NDR_PARAM_OI_BASETYPE * pParam =
777 (NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];
778 unsigned char * pArg = ARG_FROM_OFFSET(stubMsg, current_stack_offset);
780 /* no more parameters; exit loop */
781 if (current_stack_offset > stack_size)
784 TRACE("param[%d]: old format\n", i);
785 TRACE("\tparam_direction: %x\n", pParam->param_direction);
786 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
787 TRACE("\tmemory addr (before): %p\n", pArg);
789 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||
790 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
792 const unsigned char * pTypeFormat =
793 &pParam->type_format_char;
795 TRACE("\tbase type 0x%02x\n", *pTypeFormat);
800 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
801 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
804 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
805 call_marshaller(&stubMsg, pArg, pTypeFormat);
807 case PROXY_UNMARSHAL:
808 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
810 if (pParam->param_direction & RPC_FC_RETURN_PARAM)
811 call_unmarshaller(&stubMsg, (unsigned char **)&RetVal, pTypeFormat, 0);
813 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
817 RpcRaiseException(RPC_S_INTERNAL_ERROR);
820 current_stack_offset += call_memory_sizer(&stubMsg, pTypeFormat);
821 current_offset += sizeof(NDR_PARAM_OI_BASETYPE);
825 NDR_PARAM_OI_OTHER * pParamOther =
826 (NDR_PARAM_OI_OTHER *)&pFormat[current_offset];
828 const unsigned char *pTypeFormat =
829 &pStubDesc->pFormatTypes[pParamOther->type_offset];
831 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
836 if (pParam->param_direction == RPC_FC_IN_PARAM ||
837 pParam->param_direction & RPC_FC_IN_OUT_PARAM)
838 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
841 if (pParam->param_direction == RPC_FC_IN_PARAM ||
842 pParam->param_direction & RPC_FC_IN_OUT_PARAM)
843 call_marshaller(&stubMsg, pArg, pTypeFormat);
845 case PROXY_UNMARSHAL:
846 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
847 pParam->param_direction == RPC_FC_OUT_PARAM)
848 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
849 else if (pParam->param_direction == RPC_FC_RETURN_PARAM)
850 call_unmarshaller(&stubMsg, (unsigned char **)&RetVal, pTypeFormat, 0);
853 RpcRaiseException(RPC_S_INTERNAL_ERROR);
856 current_stack_offset += pParamOther->stack_size * sizeof(INT);
857 current_offset += sizeof(NDR_PARAM_OI_OTHER);
859 TRACE("\tmemory addr (after): %p\n", pArg);
865 ERR("shouldn't reach here. phase %d\n", phase);
870 /* FIXME: unbind the binding handle */
872 if (ext_flags.HasNewCorrDesc)
874 /* free extra correlation package */
875 /* NdrCorrelationFree(&stubMsg); */
878 if (Oif_flags.HasPipes)
880 /* NdrPipesDone(...) */
884 /* free the full pointer translation tables */
885 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
886 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
889 /* free marshalling buffer */
890 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
891 NdrProxyFreeBuffer(This, &stubMsg);
893 NdrFreeBuffer(&stubMsg);
895 TRACE("RetVal = 0x%lx\n", RetVal);
900 /* calls a function with the specificed arguments, restoring the stack
901 * properly afterwards as we don't know the calling convention of the
903 #if defined __i386__ && defined _MSC_VER
904 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
909 push edi ; Save registers
912 mov eax, [ebp+16] ; Get stack size
913 sub esp, eax ; Make room in stack for arguments
919 rep movsd ; Copy dword blocks
920 call [ebp+8] ; Call function
921 lea esp, [ebp-8] ; Restore stack
922 pop esi ; Restore registers
928 #elif defined __i386__ && defined __GNUC__
929 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
930 __ASM_GLOBAL_FUNC(call_server_func,
932 "movl %esp, %ebp\n\t"
933 "pushl %edi\n\t" /* Save registers */
935 "movl 16(%ebp), %eax\n\t" /* Get stack size */
936 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
937 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for MacOS X */
938 "movl %esp, %edi\n\t"
939 "movl %eax, %ecx\n\t"
940 "movl 12(%ebp), %esi\n\t"
941 "shrl $2, %ecx\n\t" /* divide by 4 */
943 "rep; movsl\n\t" /* Copy dword blocks */
944 "call *8(%ebp)\n\t" /* Call function */
945 "leal -8(%ebp), %esp\n\t" /* Restore stack */
946 "popl %esi\n\t" /* Restore registers */
951 #warning call_server_func not implemented for your architecture
952 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned short stack_size)
954 FIXME("Not implemented for your architecture\n");
959 /* FIXME: need to free some stuff in here too */
960 long WINAPI NdrStubCall2(
961 struct IRpcStubBuffer * pThis,
962 struct IRpcChannelBuffer * pChannel,
963 PRPC_MESSAGE pRpcMsg,
964 unsigned long * pdwStubPhase)
966 const MIDL_SERVER_INFO *pServerInfo;
967 const MIDL_STUB_DESC *pStubDesc;
968 PFORMAT_STRING pFormat;
969 MIDL_STUB_MESSAGE stubMsg;
970 /* pointer to start of stack to pass into stub implementation */
971 unsigned char * args;
973 unsigned short stack_size;
974 /* current stack offset */
975 unsigned short current_stack_offset;
976 /* number of parameters. optional for client to give it to us */
977 unsigned char number_of_params = ~0;
980 /* cache of Oif_flags from v2 procedure header */
981 INTERPRETER_OPT_FLAGS Oif_flags = { 0 };
982 /* cache of extension flags from NDR_PROC_HEADER_EXTS */
983 INTERPRETER_OPT_FLAGS2 ext_flags = { 0 };
984 /* the type of pass we are currently doing */
986 /* header for procedure string */
987 const NDR_PROC_HEADER *pProcHeader;
988 /* offset in format string for start of params */
989 int parameter_start_offset;
990 /* current format string offset */
992 /* -Oif or -Oicf generated format */
993 BOOL bV2Format = FALSE;
994 /* location to put retval into */
995 LONG_PTR *retval_ptr = NULL;
997 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1000 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1002 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1004 pStubDesc = pServerInfo->pStubDesc;
1005 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1006 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1008 /* Later NDR language versions probably won't be backwards compatible */
1009 if (pStubDesc->Version > 0x50002)
1011 FIXME("Incompatible stub description version: 0x%lx\n", pStubDesc->Version);
1012 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1015 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1017 NDR_PROC_HEADER_RPC * pProcHeader = (NDR_PROC_HEADER_RPC *)&pFormat[0];
1018 stack_size = pProcHeader->stack_size;
1019 current_offset = sizeof(NDR_PROC_HEADER_RPC);
1024 stack_size = pProcHeader->stack_size;
1025 current_offset = sizeof(NDR_PROC_HEADER);
1028 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1031 switch (pProcHeader->handle_type)
1033 /* explicit binding: parse additional section */
1034 case RPC_FC_BIND_EXPLICIT:
1035 switch (pFormat[current_offset]) /* handle_type */
1037 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
1038 current_offset += sizeof(NDR_EHD_PRIMITIVE);
1040 case RPC_FC_BIND_GENERIC: /* explicit generic */
1041 current_offset += sizeof(NDR_EHD_GENERIC);
1043 case RPC_FC_BIND_CONTEXT: /* explicit context */
1044 current_offset += sizeof(NDR_EHD_CONTEXT);
1047 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1048 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1051 case RPC_FC_BIND_GENERIC: /* implicit generic */
1052 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
1053 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
1054 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
1057 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1058 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1061 bV2Format = (pStubDesc->Version >= 0x20000);
1065 NDR_PROC_PARTIAL_OIF_HEADER * pOIFHeader =
1066 (NDR_PROC_PARTIAL_OIF_HEADER*)&pFormat[current_offset];
1068 Oif_flags = pOIFHeader->Oi2Flags;
1069 number_of_params = pOIFHeader->number_of_params;
1071 current_offset += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1074 TRACE("Oif_flags = "); dump_INTERPRETER_OPT_FLAGS(Oif_flags);
1076 if (Oif_flags.HasExtensions)
1078 NDR_PROC_HEADER_EXTS * pExtensions =
1079 (NDR_PROC_HEADER_EXTS *)&pFormat[current_offset];
1080 ext_flags = pExtensions->Flags2;
1081 current_offset += pExtensions->Size;
1084 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1085 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1087 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1089 /* create the full pointer translation tables, if requested */
1090 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1092 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1094 FIXME("initialize full pointer translation tables\n");
1097 /* store the RPC flags away */
1098 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1099 pRpcMsg->RpcFlags = ((NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1101 /* use alternate memory allocation routines */
1102 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1104 NdrRpcSsEnableAllocate(&stubMsg);
1106 FIXME("Set RPCSS memory allocation routines\n");
1109 if (Oif_flags.HasPipes)
1111 FIXME("pipes not supported yet\n");
1112 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1113 /* init pipes package */
1114 /* NdrPipesInitialize(...) */
1116 if (ext_flags.HasNewCorrDesc)
1118 /* initialize extra correlation package */
1119 FIXME("new correlation description not implemented\n");
1120 stubMsg.fHasNewCorrDesc = TRUE;
1123 /* convert strings, floating point values and endianess into our
1124 * preferred format */
1125 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1126 NdrConvert(&stubMsg, pFormat);
1128 parameter_start_offset = current_offset;
1130 TRACE("allocating memory for stack of size %x\n", stack_size);
1132 args = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, stack_size);
1133 stubMsg.StackTop = args; /* used by conformance of top-level objects */
1135 /* add the implicit This pointer as the first arg to the function if we
1136 * are calling an object method */
1138 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1141 * 1. STUBLESS_UNMARHSAL - unmarshal [in] params from buffer
1142 * 2. STUBLESS_CALLSERVER - send/receive buffer
1143 * 3. STUBLESS_CALCSIZE - get [out] buffer size
1144 * 4. STUBLESS_GETBUFFER - allocate [out] buffer
1145 * 5. STUBLESS_MARHSAL - marshal [out] params to buffer
1147 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_MARSHAL; phase++)
1149 TRACE("phase = %d\n", phase);
1152 case STUBLESS_CALLSERVER:
1153 /* call the server function */
1154 if (pServerInfo->ThunkTable && pServerInfo->ThunkTable[pRpcMsg->ProcNum])
1155 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1158 SERVER_ROUTINE func;
1161 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1163 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1164 func = vtbl[pRpcMsg->ProcNum];
1167 func = pServerInfo->DispatchTable[pRpcMsg->ProcNum];
1169 /* FIXME: what happens with return values that don't fit into a single register on x86? */
1170 retval = call_server_func(func, args, stack_size);
1174 TRACE("stub implementation returned 0x%lx\n", retval);
1175 *retval_ptr = retval;
1178 TRACE("void stub implementation\n");
1181 stubMsg.Buffer = NULL;
1182 stubMsg.BufferLength = 0;
1185 case STUBLESS_GETBUFFER:
1186 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1187 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1192 pRpcMsg->BufferLength = stubMsg.BufferLength;
1193 /* allocate buffer for [out] and [ret] params */
1194 Status = I_RpcGetBuffer(pRpcMsg);
1196 RpcRaiseException(Status);
1197 stubMsg.BufferStart = pRpcMsg->Buffer;
1198 stubMsg.BufferEnd = stubMsg.BufferStart + stubMsg.BufferLength;
1199 stubMsg.Buffer = stubMsg.BufferStart;
1202 case STUBLESS_MARSHAL:
1203 case STUBLESS_UNMARSHAL:
1204 case STUBLESS_CALCSIZE:
1205 current_offset = parameter_start_offset;
1206 current_stack_offset = 0;
1208 /* NOTE: V1 style format does't terminate on the number_of_params
1209 * condition as it doesn't have this attribute. Instead it
1210 * terminates when the stack size given in the header is exceeded.
1212 for (i = 0; i < number_of_params; i++)
1214 if (bV2Format) /* new parameter format */
1216 const NDR_PARAM_OIF_BASETYPE *pParam =
1217 (NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];
1218 unsigned char *pArg;
1220 current_stack_offset = pParam->stack_offset;
1221 pArg = (unsigned char *)(args+current_stack_offset);
1223 TRACE("param[%d]: new format\n", i);
1224 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");
1225 TRACE("\tstack_offset: %x\n", current_stack_offset);
1226 TRACE("\tmemory addr (before): %p -> %p\n", pArg, *(unsigned char **)pArg);
1228 if (pParam->param_attributes.ServerAllocSize)
1229 FIXME("ServerAllocSize of %d ignored for parameter %d\n",
1230 pParam->param_attributes.ServerAllocSize * 8, i);
1232 if (pParam->param_attributes.IsBasetype)
1234 const unsigned char *pTypeFormat =
1235 &pParam->type_format_char;
1237 TRACE("\tbase type: 0x%02x\n", *pTypeFormat);
1241 case STUBLESS_MARSHAL:
1242 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1244 if (pParam->param_attributes.IsSimpleRef)
1245 call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1247 call_marshaller(&stubMsg, pArg, pTypeFormat);
1249 /* FIXME: call call_freer here */
1251 case STUBLESS_UNMARSHAL:
1252 if (pParam->param_attributes.IsIn)
1254 if (pParam->param_attributes.IsSimpleRef)
1255 call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1257 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1260 /* make a note of the address of the return value parameter for later */
1261 if (pParam->param_attributes.IsReturn)
1262 retval_ptr = (LONG_PTR *)pArg;
1265 case STUBLESS_CALCSIZE:
1266 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1268 if (pParam->param_attributes.IsSimpleRef)
1269 call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1271 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1275 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1278 current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);
1282 NDR_PARAM_OIF_OTHER * pParamOther =
1283 (NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];
1285 const unsigned char * pTypeFormat =
1286 &(pStubDesc->pFormatTypes[pParamOther->type_offset]);
1288 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
1292 case STUBLESS_MARSHAL:
1293 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1295 if (pParam->param_attributes.IsByValue)
1296 call_marshaller(&stubMsg, pArg, pTypeFormat);
1299 call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1300 stubMsg.pfnFree(*(void **)pArg);
1303 /* FIXME: call call_freer here for IN types */
1305 case STUBLESS_UNMARSHAL:
1306 if (pParam->param_attributes.IsIn)
1308 if (pParam->param_attributes.IsByValue)
1309 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1311 call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1313 else if (pParam->param_attributes.IsOut &&
1314 !pParam->param_attributes.IsByValue)
1316 *(void **)pArg = NdrAllocate(&stubMsg, sizeof(void *));
1317 **(void ***)pArg = 0;
1320 case STUBLESS_CALCSIZE:
1321 if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)
1323 if (pParam->param_attributes.IsByValue)
1324 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1326 call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1330 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1333 current_offset += sizeof(NDR_PARAM_OIF_OTHER);
1335 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1337 else /* old parameter format */
1339 NDR_PARAM_OI_BASETYPE *pParam =
1340 (NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];
1341 unsigned char *pArg = (unsigned char *)(args+current_stack_offset);
1343 /* no more parameters; exit loop */
1344 if (current_stack_offset > stack_size)
1347 TRACE("param[%d]: old format\n\tparam_direction: 0x%x\n", i, pParam->param_direction);
1349 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||
1350 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1352 const unsigned char *pTypeFormat =
1353 &pParam->type_format_char;
1355 TRACE("\tbase type 0x%02x\n", *pTypeFormat);
1359 case STUBLESS_MARSHAL:
1360 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1361 call_marshaller(&stubMsg, pArg, pTypeFormat);
1363 case STUBLESS_UNMARSHAL:
1364 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
1365 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1367 case STUBLESS_CALCSIZE:
1368 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1369 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1372 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1375 current_stack_offset += call_memory_sizer(&stubMsg, pTypeFormat);
1376 current_offset += sizeof(NDR_PARAM_OI_BASETYPE);
1380 NDR_PARAM_OI_OTHER * pParamOther =
1381 (NDR_PARAM_OI_OTHER *)&pFormat[current_offset];
1383 const unsigned char * pTypeFormat =
1384 &pStubDesc->pFormatTypes[pParamOther->type_offset];
1386 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
1390 case STUBLESS_MARSHAL:
1391 if (pParam->param_direction == RPC_FC_OUT_PARAM ||
1392 pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1393 pParam->param_direction == RPC_FC_RETURN_PARAM)
1394 call_marshaller(&stubMsg, pArg, pTypeFormat);
1396 case STUBLESS_UNMARSHAL:
1397 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1398 pParam->param_direction == RPC_FC_IN_PARAM)
1399 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1401 case STUBLESS_CALCSIZE:
1402 if (pParam->param_direction == RPC_FC_OUT_PARAM ||
1403 pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1404 pParam->param_direction == RPC_FC_RETURN_PARAM)
1405 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1408 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1411 current_stack_offset += pParamOther->stack_size * sizeof(INT);
1412 current_offset += sizeof(NDR_PARAM_OI_OTHER);
1419 ERR("shouldn't reach here. phase %d\n", phase);
1424 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1426 if (ext_flags.HasNewCorrDesc)
1428 /* free extra correlation package */
1429 /* NdrCorrelationFree(&stubMsg); */
1432 if (Oif_flags.HasPipes)
1434 /* NdrPipesDone(...) */
1438 /* free the full pointer translation tables */
1439 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1440 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1443 /* free server function stack */
1444 HeapFree(GetProcessHeap(), 0, args);
1449 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1452 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);