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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
202 * RPC_FC_PROC_OI2F_SRVMUSTSIZE = 0x01 - the server must perform a
204 * RPC_FC_PROC_OI2F_CLTMUSTSIZE = 0x02 - the client must perform a
206 * RPC_FC_PROC_OI2F_HASRETURN = 0x04 - procedure has a return value.
207 * RPC_FC_PROC_OI2F_HASPIPES = 0x08 - the pipe package should be used.
208 * RPC_FC_PROC_OI2F_HASASYNCUUID = 0x20 - indicates an asynchronous DCOM
210 * RPC_FC_PROC_OI2F_HASEXTS = 0x40 - indicates that Windows 2000
211 * extensions are in use.
212 * RPC_FC_PROC_OI2F_HASASYNCHND = 0x80 - indicates an asynchronous RPC
215 unsigned char Oif_flags;
217 /* number of params */
218 unsigned char number_of_params;
219 } NDR_PROC_PARTIAL_OIF_HEADER;
221 /* Windows 2000 extensions */
222 typedef struct _NDR_PROC_EXTENSION
224 /* size in bytes of all following extensions */
225 unsigned char extension_version;
228 * HasNewCorrDesc = 0x01 - indicates new correlation descriptors in use
229 * ClientCorrCheck = 0x02 - client needs correlation check
230 * ServerCorrCheck = 0x04 - server needs correlation check
231 * HasNotify = 0x08 - should call MIDL [notify] routine @ NotifyIndex
232 * HasNotify2 = 0x10 - should call MIDL [notify_flag] routine @
235 unsigned char ext_flags;
237 /* client cache size hint */
238 unsigned short ClientCorrHint;
240 /* server cache size hint */
241 unsigned short ServerCorrHint;
243 /* index of routine in MIDL_STUB_DESC::NotifyRoutineTable to call if
244 * HasNotify or HasNotify2 flag set */
245 unsigned short NotifyIndex;
246 } NDR_PROC_EXTENSION;
248 /* usually generated only on IA64 */
249 typedef struct _NDR_PROC_EXTENSION_64
251 NDR_PROC_EXTENSION ext;
253 /* needed only on IA64 to cope with float/register loading */
254 unsigned short FloatDoubleMask;
255 } NDR_PROC_EXTENSION_64;
258 typedef struct _NDR_PARAM_OI_BASETYPE
260 /* parameter direction. One of:
261 * FC_IN_PARAM_BASETYPE = 0x4e - an in param
262 * FC_RETURN_PARAM_BASETYPE = 0x53 - a return param
264 unsigned char param_direction;
266 /* One of: FC_BYTE,FC_CHAR,FC_SMALL,FC_USMALL,FC_WCHAR,FC_SHORT,FC_USHORT,
267 * FC_LONG,FC_ULONG,FC_FLOAT,FC_HYPER,FC_DOUBLE,FC_ENUM16,FC_ENUM32,
268 * FC_ERROR_STATUS_T,FC_INT3264,FC_UINT3264 */
269 unsigned char type_format_char;
270 } NDR_PARAM_OI_BASETYPE;
272 typedef struct _NDR_PARAM_OI_OTHER
275 * FC_IN_PARAM = 0x4d - An in param
276 * FC_IN_OUT_PARAM = 0x50 - An in/out param
277 * FC_OUT_PARAM = 0x51 - An out param
278 * FC_RETURN_PARAM = 0x52 - A return value
279 * FC_IN_PARAM_NO_FREE_INST = 0x4f - A param for which no freeing is done
281 unsigned char param_direction;
283 /* Size of param on stack in NUMBERS OF INTS */
284 unsigned char stack_size;
286 /* offset in the type format string table */
287 unsigned short type_offset;
288 } NDR_PARAM_OI_OTHER;
290 typedef struct _NDR_PARAM_OIF_BASETYPE
292 PARAM_ATTRIBUTES param_attributes;
294 /* the offset on the calling stack where the parameter is located */
295 unsigned short stack_offset;
297 /* see NDR_PARAM_OI_BASETYPE::type_format_char */
298 unsigned char type_format_char;
301 unsigned char unused;
302 } NDR_PARAM_OIF_BASETYPE;
304 typedef struct _NDR_PARAM_OIF_OTHER
306 PARAM_ATTRIBUTES param_attributes;
308 /* see NDR_PARAM_OIF_BASETYPE::stack_offset */
309 unsigned short stack_offset;
311 /* offset into the provided type format string where the type for this
312 * parameter starts */
313 unsigned short type_offset;
314 } NDR_PARAM_OIF_OTHER;
316 /* explicit handle description for FC_BIND_PRIMITIVE type */
317 typedef struct _NDR_EHD_PRIMITIVE
319 /* FC_BIND_PRIMITIVE */
320 unsigned char handle_type;
322 /* is the handle passed in via a pointer? */
325 /* offset from the beginning of the stack to the handle in bytes */
326 unsigned short offset;
329 /* explicit handle description for FC_BIND_GENERIC type */
330 typedef struct _NDR_EHD_GENERIC
332 /* FC_BIND_GENERIC */
333 unsigned char handle_type;
335 /* upper 4bits is a flag indicating whether the handle is passed in
336 * via a pointer. lower 4bits is the size of the user defined generic
337 * handle type. the size must be less than or equal to the machine
339 unsigned char flag_and_size;
341 /* offset from the beginning of the stack to the handle in bytes */
342 unsigned short offset;
344 /* the index into the aGenericBindingRoutinesPairs field of MIDL_STUB_DESC
345 * giving the bind and unbind routines for the handle */
346 unsigned char binding_routine_pair_index;
349 unsigned char unused;
352 /* explicit handle description for FC_BIND_CONTEXT type */
353 typedef struct _NDR_EHD_CONTEXT
355 /* FC_BIND_CONTEXT */
356 unsigned char handle_type;
358 /* Any of the following flags:
359 * NDR_CONTEXT_HANDLE_CANNOT_BE_NULL = 0x01
360 * NDR_CONTEXT_HANDLE_SERIALIZE = 0x02
361 * NDR_CONTEXT_HANDLE_NO_SERIALIZE = 0x04
362 * NDR_STRICT_CONTEXT_HANDLE = 0x08
363 * HANDLE_PARAM_IS_OUT = 0x20
364 * HANDLE_PARAM_IS_RETURN = 0x21
365 * HANDLE_PARAM_IS_IN = 0x40
366 * HANDLE_PARAM_IS_VIA_PTR = 0x80
370 /* offset from the beginning of the stack to the handle in bytes */
371 unsigned short offset;
373 /* zero-based index on rundown routine in apfnNdrRundownRoutines field
374 * of MIDL_STUB_DESC */
375 unsigned char context_rundown_routine_index;
377 /* varies depending on NDR version used.
378 * V1: zero-based index into parameters
379 * V2: zero-based index into handles that are parameters */
380 unsigned char param_num;
385 void WINAPI NdrRpcSmSetClientToOsf(PMIDL_STUB_MESSAGE pMessage)
387 #if 0 /* these functions are not defined yet */
388 pMessage->pfnAllocate = NdrRpcSmClientAllocate;
389 pMessage->pfnFree = NdrRpcSmClientFree;
393 static void WINAPI dump_RPC_FC_PROC_PF(PARAM_ATTRIBUTES param_attributes)
395 if (param_attributes.MustSize) TRACE(" MustSize");
396 if (param_attributes.MustFree) TRACE(" MustFree");
397 if (param_attributes.IsPipe) TRACE(" IsPipe");
398 if (param_attributes.IsIn) TRACE(" IsIn");
399 if (param_attributes.IsOut) TRACE(" IsOut");
400 if (param_attributes.IsReturn) TRACE(" IsReturn");
401 if (param_attributes.IsBasetype) TRACE(" IsBasetype");
402 if (param_attributes.IsByValue) TRACE(" IsByValue");
403 if (param_attributes.IsSimpleRef) TRACE(" IsSimpleRef");
404 if (param_attributes.IsDontCallFreeInst) TRACE(" IsDontCallFreeInst");
405 if (param_attributes.SaveForAsyncFinish) TRACE(" SaveForAsyncFinish");
406 if (param_attributes.ServerAllocSize) TRACE(" ServerAllocSize = %d", param_attributes.ServerAllocSize * 8);
409 /* FIXME: this will be different on other plaftorms than i386 */
410 #define ARG_FROM_OFFSET(args, offset) (*(unsigned char **)args + offset)
412 /* the return type should be CLIENT_CALL_RETURN, but this is incompatible
413 * with the way gcc returns structures. "void *" should be the largest type
414 * that MIDL should allow you to return anyway */
415 LONG_PTR WINAPIV NdrClientCall2(PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, ...)
417 /* pointer to start of stack where arguments start */
418 /* FIXME: not portable */
419 unsigned char *args = (unsigned char *)(&pFormat+1);
421 MIDL_STUB_MESSAGE stubMsg;
422 handle_t hBinding = NULL;
423 /* procedure number */
424 unsigned short procedure_number;
426 unsigned short stack_size;
427 /* current stack offset */
428 unsigned short current_stack_offset;
429 /* number of parameters. optional for client to give it to us */
430 unsigned char number_of_params = ~0;
433 /* cache of Oif_flags from v2 procedure header */
434 unsigned char Oif_flags = 0;
435 /* cache of extension flags from NDR_PROC_EXTENSION */
436 unsigned char ext_flags = 0;
437 /* the type of pass we are currently doing */
439 /* header for procedure string */
440 const NDR_PROC_HEADER * pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
441 /* offset in format string for start of params */
442 int parameter_start_offset;
443 /* current format string offset */
445 /* -Oif or -Oicf generated format */
446 BOOL bV2Format = FALSE;
447 /* the value to return to the client from the remote procedure */
449 /* the pointer to the object when in OLE mode */
452 TRACE("pStubDesc %p, pFormat %p, ...\n", pStubDesc, pFormat);
453 TRACE("&first_argument = %p -> %p\n", args, ARG_FROM_OFFSET(args, 0));
455 /* Later NDR language versions probably won't be backwards compatible */
456 if (pStubDesc->Version > 0x50002)
458 FIXME("Incompatible stub description version: 0x%lx\n", pStubDesc->Version);
459 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
462 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
464 NDR_PROC_HEADER_RPC * pProcHeader = (NDR_PROC_HEADER_RPC *)&pFormat[0];
465 stack_size = pProcHeader->stack_size;
466 procedure_number = pProcHeader->proc_num;
467 current_offset = sizeof(NDR_PROC_HEADER_RPC);
471 stack_size = pProcHeader->stack_size;
472 procedure_number = pProcHeader->proc_num;
473 TRACE("proc num: %d\n", procedure_number);
474 current_offset = sizeof(NDR_PROC_HEADER);
477 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
478 TRACE("MIDL stub version = 0x%lx\n", pStubDesc->MIDLVersion);
480 /* we only need a handle if this isn't an object method */
481 if (!(pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT))
484 switch (pProcHeader->handle_type)
486 /* explicit binding: parse additional section */
487 case RPC_FC_BIND_EXPLICIT:
488 switch (pFormat[current_offset]) /* handle_type */
490 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
492 NDR_EHD_PRIMITIVE * pDesc = (NDR_EHD_PRIMITIVE *)&pFormat[current_offset];
494 TRACE("Explicit primitive handle @ %d\n", pDesc->offset);
496 if (pDesc->flag) /* pointer to binding */
497 hBinding = **(handle_t **)ARG_FROM_OFFSET(args, pDesc->offset);
499 hBinding = *(handle_t *)ARG_FROM_OFFSET(args, pDesc->offset);
500 current_offset += sizeof(NDR_EHD_PRIMITIVE);
503 case RPC_FC_BIND_GENERIC: /* explicit generic */
504 FIXME("RPC_FC_BIND_GENERIC\n");
505 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
506 current_offset += sizeof(NDR_EHD_GENERIC);
508 case RPC_FC_BIND_CONTEXT: /* explicit context */
510 NDR_EHD_CONTEXT * pDesc = (NDR_EHD_CONTEXT *)&pFormat[current_offset];
511 TRACE("Explicit bind context\n");
512 hBinding = NDRCContextBinding(*(NDR_CCONTEXT *)ARG_FROM_OFFSET(args, pDesc->offset));
513 /* FIXME: should we store this structure in stubMsg.pContext? */
514 current_offset += sizeof(NDR_EHD_CONTEXT);
518 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
519 RpcRaiseException(RPC_X_BAD_STUB_DATA);
522 case RPC_FC_BIND_GENERIC: /* implicit generic */
523 FIXME("RPC_FC_BIND_GENERIC\n");
524 RpcRaiseException(RPC_X_BAD_STUB_DATA); /* FIXME: remove when implemented */
526 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
527 TRACE("Implicit primitive handle\n");
528 hBinding = *pStubDesc->IMPLICIT_HANDLE_INFO.pPrimitiveHandle;
530 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
531 FIXME("RPC_FC_CALLBACK_HANDLE\n");
533 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
534 /* strictly speaking, it isn't necessary to set hBinding here
535 * since it isn't actually used (hence the automatic in its name),
536 * but then why does MIDL generate a valid entry in the
537 * MIDL_STUB_DESC for it? */
538 TRACE("Implicit auto handle\n");
539 hBinding = *pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle;
542 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
543 RpcRaiseException(RPC_X_BAD_STUB_DATA);
547 bV2Format = (pStubDesc->Version >= 0x20000);
551 NDR_PROC_PARTIAL_OIF_HEADER * pOIFHeader =
552 (NDR_PROC_PARTIAL_OIF_HEADER*)&pFormat[current_offset];
554 Oif_flags = pOIFHeader->Oif_flags;
555 number_of_params = pOIFHeader->number_of_params;
557 current_offset += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
560 TRACE("Oif_flags = 0x%02x\n", Oif_flags);
562 if (Oif_flags & RPC_FC_PROC_OI2F_HASEXTS)
564 NDR_PROC_EXTENSION * pExtensions =
565 (NDR_PROC_EXTENSION *)&pFormat[current_offset];
566 ext_flags = pExtensions->ext_flags;
567 current_offset += pExtensions->extension_version;
570 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
572 /* object is always the first argument */
573 This = *(void **)ARG_FROM_OFFSET(args, 0);
574 NdrProxyInitialize(This, &rpcMsg, &stubMsg, pStubDesc, procedure_number);
577 NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDesc, procedure_number);
579 /* create the full pointer translation tables, if requested */
580 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
582 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_CLIENT);
584 FIXME("initialize full pointer translation tables\n");
587 stubMsg.BufferLength = 0;
589 /* store the RPC flags away */
590 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
591 rpcMsg.RpcFlags = ((NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
593 /* use alternate memory allocation routines */
594 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
595 NdrRpcSmSetClientToOsf(&stubMsg);
597 if (Oif_flags & RPC_FC_PROC_OI2F_HASPIPES)
599 FIXME("pipes not supported yet\n");
600 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
601 /* init pipes package */
602 /* NdrPipesInitialize(...) */
604 if (ext_flags & RPC_FC_PROC_EXT_NEWCORRDESC)
606 /* initialize extra correlation package */
607 FIXME("new correlation description not implemented\n");
608 stubMsg.fHasNewCorrDesc = TRUE;
611 parameter_start_offset = current_offset;
614 * 1. PROXY_CALCSIZE - calculate the buffer size
615 * 2. PROXY_GETBUFFER - allocate the buffer
616 * 3. PROXY_MARHSAL - marshal [in] params into the buffer
617 * 4. PROXY_SENDRECEIVE - send/receive buffer
618 * 5. PROXY_UNMARHSAL - unmarshal [out] params from buffer
620 for (phase = PROXY_CALCSIZE; phase <= PROXY_UNMARSHAL; phase++)
622 TRACE("phase = %d\n", phase);
625 case PROXY_GETBUFFER:
626 /* allocate the buffer */
627 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
628 NdrProxyGetBuffer(This, &stubMsg);
629 else if (Oif_flags & RPC_FC_PROC_OI2F_HASPIPES)
630 /* NdrGetPipeBuffer(...) */
631 FIXME("pipes not supported yet\n");
634 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
636 NdrNsGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
638 FIXME("using auto handle - call NdrNsGetBuffer when it gets implemented\n");
641 NdrGetBuffer(&stubMsg, stubMsg.BufferLength, hBinding);
644 case PROXY_SENDRECEIVE:
645 /* send the [in] params and receive the [out] and [retval]
647 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
648 NdrProxySendReceive(This, &stubMsg);
649 else if (Oif_flags & RPC_FC_PROC_OI2F_HASPIPES)
650 /* NdrPipesSendReceive(...) */
651 FIXME("pipes not supported yet\n");
654 if (pProcHeader->handle_type == RPC_FC_AUTO_HANDLE)
656 NdrNsSendReceive(&stubMsg, stubMsg.Buffer, pStubDesc->IMPLICIT_HANDLE_INFO.pAutoHandle);
658 FIXME("using auto handle - call NdrNsSendReceive when it gets implemented\n");
661 NdrSendReceive(&stubMsg, stubMsg.Buffer);
664 /* convert strings, floating point values and endianess into our
665 * preferred format */
666 if ((rpcMsg.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
667 NdrConvert(&stubMsg, pFormat);
672 case PROXY_UNMARSHAL:
673 current_offset = parameter_start_offset;
674 current_stack_offset = 0;
676 /* NOTE: V1 style format does't terminate on the number_of_params
677 * condition as it doesn't have this attribute. Instead it
678 * terminates when the stack size given in the header is exceeded.
680 for (i = 0; i < number_of_params; i++)
682 if (bV2Format) /* new parameter format */
684 NDR_PARAM_OIF_BASETYPE * pParam =
685 (NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];
686 unsigned char * pArg;
688 current_stack_offset = pParam->stack_offset;
689 pArg = ARG_FROM_OFFSET(args, current_stack_offset);
691 TRACE("param[%d]: new format\n", i);
692 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");
693 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
694 TRACE("\tmemory addr (before): %p\n", pArg);
696 if (pParam->param_attributes.IsBasetype)
698 const unsigned char * pTypeFormat =
699 &pParam->type_format_char;
701 if (pParam->param_attributes.IsSimpleRef)
702 pArg = *(unsigned char **)pArg;
704 TRACE("\tbase type: 0x%02x\n", *pTypeFormat);
709 if (pParam->param_attributes.IsIn)
710 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
713 if (pParam->param_attributes.IsIn)
714 call_marshaller(&stubMsg, pArg, pTypeFormat);
716 case PROXY_UNMARSHAL:
717 if (pParam->param_attributes.IsOut)
719 unsigned char *pRetVal = (unsigned char *)&RetVal;
720 if (pParam->param_attributes.IsReturn)
721 call_unmarshaller(&stubMsg, &pRetVal, pTypeFormat, 0);
723 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
724 TRACE("pRetVal = %p\n", pRetVal);
728 RpcRaiseException(RPC_S_INTERNAL_ERROR);
731 current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);
735 NDR_PARAM_OIF_OTHER * pParamOther =
736 (NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];
738 const unsigned char * pTypeFormat =
739 &(pStubDesc->pFormatTypes[pParamOther->type_offset]);
741 /* if a simple ref pointer then we have to do the
742 * check for the pointer being non-NULL. */
743 if (pParam->param_attributes.IsSimpleRef)
745 if (!*(unsigned char **)pArg)
746 RpcRaiseException(RPC_X_NULL_REF_POINTER);
749 TRACE("\tcomplex type: 0x%02x\n", *pTypeFormat);
754 if (pParam->param_attributes.IsIn)
756 if (pParam->param_attributes.IsByValue)
757 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
759 call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
763 if (pParam->param_attributes.IsIn)
765 if (pParam->param_attributes.IsByValue)
766 call_marshaller(&stubMsg, pArg, pTypeFormat);
768 call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
771 case PROXY_UNMARSHAL:
772 if (pParam->param_attributes.IsOut)
774 unsigned char *pRetVal = (unsigned char *)&RetVal;
775 if (pParam->param_attributes.IsReturn)
776 call_unmarshaller(&stubMsg, &pRetVal, pTypeFormat, 0);
777 else if (pParam->param_attributes.IsByValue)
778 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
780 call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);
784 RpcRaiseException(RPC_S_INTERNAL_ERROR);
787 current_offset += sizeof(NDR_PARAM_OIF_OTHER);
789 TRACE("\tmemory addr (after): %p\n", pArg);
791 else /* old parameter format */
793 NDR_PARAM_OI_BASETYPE * pParam =
794 (NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];
795 unsigned char * pArg = ARG_FROM_OFFSET(args, current_stack_offset);
797 /* no more parameters; exit loop */
798 if (current_stack_offset > stack_size)
801 TRACE("param[%d]: old format\n", i);
802 TRACE("\tparam_direction: %x\n", pParam->param_direction);
803 TRACE("\tstack_offset: 0x%x\n", current_stack_offset);
804 TRACE("\tmemory addr (before): %p\n", pArg);
806 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||
807 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
809 const unsigned char * pTypeFormat =
810 &pParam->type_format_char;
812 TRACE("\tbase type 0x%02x\n", *pTypeFormat);
817 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
818 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
821 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
822 call_marshaller(&stubMsg, pArg, pTypeFormat);
824 case PROXY_UNMARSHAL:
825 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
827 if (pParam->param_direction & RPC_FC_RETURN_PARAM)
828 call_unmarshaller(&stubMsg, (unsigned char **)&RetVal, pTypeFormat, 0);
830 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
834 RpcRaiseException(RPC_S_INTERNAL_ERROR);
837 current_stack_offset += call_memory_sizer(&stubMsg, pTypeFormat);
838 current_offset += sizeof(NDR_PARAM_OI_BASETYPE);
842 NDR_PARAM_OI_OTHER * pParamOther =
843 (NDR_PARAM_OI_OTHER *)&pFormat[current_offset];
845 const unsigned char *pTypeFormat =
846 &pStubDesc->pFormatTypes[pParamOther->type_offset];
848 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
853 if (pParam->param_direction == RPC_FC_IN_PARAM ||
854 pParam->param_direction & RPC_FC_IN_OUT_PARAM)
855 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
858 if (pParam->param_direction == RPC_FC_IN_PARAM ||
859 pParam->param_direction & RPC_FC_IN_OUT_PARAM)
860 call_marshaller(&stubMsg, pArg, pTypeFormat);
862 case PROXY_UNMARSHAL:
863 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
864 pParam->param_direction == RPC_FC_OUT_PARAM)
865 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
866 else if (pParam->param_direction == RPC_FC_RETURN_PARAM)
867 call_unmarshaller(&stubMsg, (unsigned char **)&RetVal, pTypeFormat, 0);
870 RpcRaiseException(RPC_S_INTERNAL_ERROR);
873 current_stack_offset += pParamOther->stack_size * sizeof(INT);
874 current_offset += sizeof(NDR_PARAM_OI_OTHER);
876 TRACE("\tmemory addr (after): %p\n", pArg);
882 ERR("shouldn't reach here. phase %d\n", phase);
887 /* FIXME: unbind the binding handle */
889 if (ext_flags & RPC_FC_PROC_EXT_NEWCORRDESC)
891 /* free extra correlation package */
892 /* NdrCorrelationFree(&stubMsg); */
895 if (Oif_flags & RPC_FC_PROC_OI2F_HASPIPES)
897 /* NdrPipesDone(...) */
901 /* free the full pointer translation tables */
902 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
903 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
906 /* free marshalling buffer */
907 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
908 NdrProxyFreeBuffer(This, &stubMsg);
910 NdrFreeBuffer(&stubMsg);
912 TRACE("RetVal = 0x%lx\n", RetVal);
917 /* calls a function with the specificed arguments, restoring the stack
918 * properly afterwards as we don't know the calling convention of the
920 #if defined __i386__ && defined _MSC_VER
921 __declspec(naked) LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size)
926 push edi ; Save registers
929 mov eax, [ebp+16] ; Get stack size
930 sub esp, eax ; Make room in stack for arguments
936 rep movsd ; Copy dword blocks
937 call [ebp+8] ; Call function
938 lea esp, [ebp-8] ; Restore stack
939 pop ebp ; Restore registers
945 #elif defined __i386__ && defined __GNUC__
946 LONG_PTR __cdecl call_server_func(SERVER_ROUTINE func, unsigned char * args, unsigned int stack_size);
947 __ASM_GLOBAL_FUNC(call_server_func,
949 "movl %esp, %ebp\n\t"
950 "pushl %edi\n\t" /* Save registers */
952 "movl 16(%ebp), %eax\n\t" /* Get stack size */
953 "subl %eax, %esp\n\t" /* Make room in stack for arguments */
954 "andl $~15, %esp\n\t" /* Make sure stack has 16-byte alignment for MacOS X */
955 "movl %esp, %edi\n\t"
956 "movl %eax, %ecx\n\t"
957 "movl 12(%ebp), %esi\n\t"
958 "shrl $2, %ecx\n\t" /* divide by 4 */
960 "rep; movsl\n\t" /* Copy dword blocks */
961 "call *8(%ebp)\n\t" /* Call function */
962 "leal -8(%ebp), %esp\n\t" /* Restore stack */
963 "popl %esi\n\t" /* Restore registers */
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 /* FIXME: need to free some stuff in here too */
977 long WINAPI NdrStubCall2(
978 struct IRpcStubBuffer * pThis,
979 struct IRpcChannelBuffer * pChannel,
980 PRPC_MESSAGE pRpcMsg,
981 unsigned long * pdwStubPhase)
983 const MIDL_SERVER_INFO *pServerInfo;
984 const MIDL_STUB_DESC *pStubDesc;
985 PFORMAT_STRING pFormat;
986 MIDL_STUB_MESSAGE stubMsg;
987 /* pointer to start of stack to pass into stub implementation */
988 unsigned char * args;
990 unsigned short stack_size;
991 /* current stack offset */
992 unsigned short current_stack_offset;
993 /* number of parameters. optional for client to give it to us */
994 unsigned char number_of_params = ~0;
997 /* cache of Oif_flags from v2 procedure header */
998 unsigned char Oif_flags = 0;
999 /* cache of extension flags from NDR_PROC_EXTENSION */
1000 unsigned char ext_flags = 0;
1001 /* the type of pass we are currently doing */
1003 /* header for procedure string */
1004 const NDR_PROC_HEADER *pProcHeader;
1005 /* offset in format string for start of params */
1006 int parameter_start_offset;
1007 /* current format string offset */
1009 /* -Oif or -Oicf generated format */
1010 BOOL bV2Format = FALSE;
1011 /* the return value (not from this function, but to be put back onto
1013 LONG_PTR RetVal = 0;
1015 TRACE("pThis %p, pChannel %p, pRpcMsg %p, pdwStubPhase %p\n", pThis, pChannel, pRpcMsg, pdwStubPhase);
1018 pServerInfo = CStdStubBuffer_GetServerInfo(pThis);
1020 pServerInfo = ((RPC_SERVER_INTERFACE *)pRpcMsg->RpcInterfaceInformation)->InterpreterInfo;
1022 pStubDesc = pServerInfo->pStubDesc;
1023 pFormat = pServerInfo->ProcString + pServerInfo->FmtStringOffset[pRpcMsg->ProcNum];
1024 pProcHeader = (const NDR_PROC_HEADER *)&pFormat[0];
1026 /* Later NDR language versions probably won't be backwards compatible */
1027 if (pStubDesc->Version > 0x50002)
1029 FIXME("Incompatible stub description version: 0x%lx\n", pStubDesc->Version);
1030 RpcRaiseException(RPC_X_WRONG_STUB_VERSION);
1033 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1035 NDR_PROC_HEADER_RPC * pProcHeader = (NDR_PROC_HEADER_RPC *)&pFormat[0];
1036 stack_size = pProcHeader->stack_size;
1037 current_offset = sizeof(NDR_PROC_HEADER_RPC);
1042 stack_size = pProcHeader->stack_size;
1043 current_offset = sizeof(NDR_PROC_HEADER);
1046 TRACE("Oi_flags = 0x%02x\n", pProcHeader->Oi_flags);
1049 switch (pProcHeader->handle_type)
1051 /* explicit binding: parse additional section */
1052 case RPC_FC_BIND_EXPLICIT:
1053 switch (pFormat[current_offset]) /* handle_type */
1055 case RPC_FC_BIND_PRIMITIVE: /* explicit primitive */
1056 current_offset += sizeof(NDR_EHD_PRIMITIVE);
1058 case RPC_FC_BIND_GENERIC: /* explicit generic */
1059 current_offset += sizeof(NDR_EHD_GENERIC);
1061 case RPC_FC_BIND_CONTEXT: /* explicit context */
1062 current_offset += sizeof(NDR_EHD_CONTEXT);
1065 ERR("bad explicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1066 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1069 case RPC_FC_BIND_GENERIC: /* implicit generic */
1070 case RPC_FC_BIND_PRIMITIVE: /* implicit primitive */
1071 case RPC_FC_CALLBACK_HANDLE: /* implicit callback */
1072 case RPC_FC_AUTO_HANDLE: /* implicit auto handle */
1075 ERR("bad implicit binding handle type (0x%02x)\n", pProcHeader->handle_type);
1076 RpcRaiseException(RPC_X_BAD_STUB_DATA);
1079 bV2Format = (pStubDesc->Version >= 0x20000);
1083 NDR_PROC_PARTIAL_OIF_HEADER * pOIFHeader =
1084 (NDR_PROC_PARTIAL_OIF_HEADER*)&pFormat[current_offset];
1086 Oif_flags = pOIFHeader->Oif_flags;
1087 number_of_params = pOIFHeader->number_of_params;
1089 current_offset += sizeof(NDR_PROC_PARTIAL_OIF_HEADER);
1092 TRACE("Oif_flags = 0x%02x\n", Oif_flags);
1094 if (Oif_flags & RPC_FC_PROC_OI2F_HASEXTS)
1096 NDR_PROC_EXTENSION * pExtensions =
1097 (NDR_PROC_EXTENSION *)&pFormat[current_offset];
1098 ext_flags = pExtensions->ext_flags;
1099 current_offset += pExtensions->extension_version;
1102 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1103 NdrStubInitialize(pRpcMsg, &stubMsg, pStubDesc, pChannel);
1105 NdrServerInitializeNew(pRpcMsg, &stubMsg, pStubDesc);
1107 /* create the full pointer translation tables, if requested */
1108 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1110 stubMsg.FullPtrXlatTables = NdrFullPointerXlatInit(0,XLAT_SERVER);
1112 FIXME("initialize full pointer translation tables\n");
1115 /* store the RPC flags away */
1116 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCFLAGS)
1117 pRpcMsg->RpcFlags = ((NDR_PROC_HEADER_RPC *)pProcHeader)->rpc_flags;
1119 /* use alternate memory allocation routines */
1120 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_RPCSSALLOC)
1122 NdrRpcSsEnableAllocate(&stubMsg);
1124 FIXME("Set RPCSS memory allocation routines\n");
1127 if (Oif_flags & RPC_FC_PROC_OI2F_HASPIPES)
1129 FIXME("pipes not supported yet\n");
1130 RpcRaiseException(RPC_X_WRONG_STUB_VERSION); /* FIXME: remove when implemented */
1131 /* init pipes package */
1132 /* NdrPipesInitialize(...) */
1134 if (ext_flags & RPC_FC_PROC_EXT_NEWCORRDESC)
1136 /* initialize extra correlation package */
1137 FIXME("new correlation description not implemented\n");
1138 stubMsg.fHasNewCorrDesc = TRUE;
1142 /* convert strings, floating point values and endianess into our
1143 * preferred format */
1144 if ((pRpcMsg->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)
1145 NdrConvert(&stubMsg, pFormat);
1147 parameter_start_offset = current_offset;
1149 TRACE("allocating memory for stack of size %x\n", stack_size);
1151 args = HeapAlloc(GetProcessHeap(), 0, stack_size);
1152 ZeroMemory(args, stack_size);
1154 /* add the implicit This pointer as the first arg to the function if we
1155 * are calling an object method */
1157 *(void **)args = ((CStdStubBuffer *)pThis)->pvServerObject;
1160 * 1. STUBLESS_UNMARHSAL - unmarshal [in] params from buffer
1161 * 2. STUBLESS_CALLSERVER - send/receive buffer
1162 * 3. STUBLESS_CALCSIZE - get [out] buffer size
1163 * 4. STUBLESS_GETBUFFER - allocate [out] buffer
1164 * 5. STUBLESS_MARHSAL - marshal [out] params to buffer
1166 for (phase = STUBLESS_UNMARSHAL; phase <= STUBLESS_MARSHAL; phase++)
1168 TRACE("phase = %d\n", phase);
1171 case STUBLESS_CALLSERVER:
1172 /* call the server function */
1173 if (pServerInfo->ThunkTable)
1175 stubMsg.StackTop = args;
1176 pServerInfo->ThunkTable[pRpcMsg->ProcNum](&stubMsg);
1177 /* FIXME: RetVal is stored as the last argument - retrieve it */
1179 else if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1181 SERVER_ROUTINE *vtbl = *(SERVER_ROUTINE **)((CStdStubBuffer *)pThis)->pvServerObject;
1182 RetVal = call_server_func(vtbl[pRpcMsg->ProcNum], args, stack_size);
1185 RetVal = call_server_func(pServerInfo->DispatchTable[pRpcMsg->ProcNum], args, stack_size);
1187 TRACE("stub implementation returned %p\n", (void *)RetVal);
1189 stubMsg.Buffer = NULL;
1190 stubMsg.BufferLength = 0;
1193 case STUBLESS_GETBUFFER:
1194 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT)
1195 NdrStubGetBuffer(pThis, pChannel, &stubMsg);
1200 pRpcMsg->BufferLength = stubMsg.BufferLength;
1201 /* allocate buffer for [out] and [ret] params */
1202 Status = I_RpcGetBuffer(pRpcMsg);
1204 RpcRaiseException(Status);
1205 stubMsg.BufferStart = pRpcMsg->Buffer;
1206 stubMsg.BufferEnd = stubMsg.BufferStart + stubMsg.BufferLength;
1207 stubMsg.Buffer = stubMsg.BufferStart;
1210 case STUBLESS_MARSHAL:
1211 case STUBLESS_UNMARSHAL:
1212 case STUBLESS_CALCSIZE:
1213 current_offset = parameter_start_offset;
1214 current_stack_offset = 0;
1216 /* NOTE: V1 style format does't terminate on the number_of_params
1217 * condition as it doesn't have this attribute. Instead it
1218 * terminates when the stack size given in the header is exceeded.
1220 for (i = 0; i < number_of_params; i++)
1222 if (bV2Format) /* new parameter format */
1224 const NDR_PARAM_OIF_BASETYPE *pParam =
1225 (NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];
1226 unsigned char *pArg;
1228 current_stack_offset = pParam->stack_offset;
1229 pArg = (unsigned char *)(args+current_stack_offset);
1231 TRACE("param[%d]: new format\n", i);
1232 TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");
1233 TRACE("\tstack_offset: %x\n", current_stack_offset);
1234 TRACE("\tmemory addr (before): %p -> %p\n", pArg, *(unsigned char **)pArg);
1236 if (pParam->param_attributes.ServerAllocSize)
1237 FIXME("ServerAllocSize of %d ignored for parameter %d\n",
1238 pParam->param_attributes.ServerAllocSize * 8, i);
1240 if (pParam->param_attributes.IsBasetype)
1242 const unsigned char *pTypeFormat =
1243 &pParam->type_format_char;
1245 TRACE("\tbase type: 0x%02x\n", *pTypeFormat);
1249 case STUBLESS_MARSHAL:
1250 if (pParam->param_attributes.IsReturn)
1251 call_marshaller(&stubMsg, (unsigned char *)&RetVal, pTypeFormat);
1252 else if (pParam->param_attributes.IsOut)
1254 if (pParam->param_attributes.IsSimpleRef)
1255 call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1257 call_marshaller(&stubMsg, pArg, pTypeFormat);
1259 /* FIXME: call call_freer here */
1261 case STUBLESS_UNMARSHAL:
1262 if (pParam->param_attributes.IsIn)
1264 if (pParam->param_attributes.IsSimpleRef)
1265 call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1267 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1270 case STUBLESS_CALCSIZE:
1271 if (pParam->param_attributes.IsReturn)
1272 call_buffer_sizer(&stubMsg, (unsigned char *)&RetVal, pTypeFormat);
1273 else if (pParam->param_attributes.IsOut)
1275 if (pParam->param_attributes.IsSimpleRef)
1276 call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1278 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1282 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1285 current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);
1289 NDR_PARAM_OIF_OTHER * pParamOther =
1290 (NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];
1292 const unsigned char * pTypeFormat =
1293 &(pStubDesc->pFormatTypes[pParamOther->type_offset]);
1295 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
1299 case STUBLESS_MARSHAL:
1300 if (pParam->param_attributes.IsReturn)
1301 call_marshaller(&stubMsg, (unsigned char *)&RetVal, pTypeFormat);
1302 else if (pParam->param_attributes.IsOut)
1304 if (pParam->param_attributes.IsByValue)
1305 call_marshaller(&stubMsg, pArg, pTypeFormat);
1308 call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1309 stubMsg.pfnFree(*(void **)pArg);
1312 /* FIXME: call call_freer here for IN types */
1314 case STUBLESS_UNMARSHAL:
1315 if (pParam->param_attributes.IsIn)
1317 if (pParam->param_attributes.IsByValue)
1318 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1320 call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);
1322 else if ((pParam->param_attributes.IsOut) &&
1323 !(pParam->param_attributes.IsByValue))
1325 *(void **)pArg = NdrAllocate(&stubMsg, sizeof(void *));
1326 **(void ***)pArg = 0;
1329 case STUBLESS_CALCSIZE:
1330 if (pParam->param_attributes.IsReturn)
1331 call_buffer_sizer(&stubMsg, (unsigned char *)&RetVal, pTypeFormat);
1332 else if (pParam->param_attributes.IsOut)
1334 if (pParam->param_attributes.IsByValue)
1335 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1337 call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);
1341 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1344 current_offset += sizeof(NDR_PARAM_OIF_OTHER);
1346 TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);
1348 else /* old parameter format */
1350 NDR_PARAM_OI_BASETYPE *pParam =
1351 (NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];
1352 unsigned char *pArg = (unsigned char *)(args+current_stack_offset);
1354 /* no more parameters; exit loop */
1355 if (current_stack_offset > stack_size)
1358 TRACE("param[%d]: old format\n\tparam_direction: 0x%x\n", i, pParam->param_direction);
1360 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||
1361 pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1363 const unsigned char *pTypeFormat =
1364 &pParam->type_format_char;
1366 TRACE("\tbase type 0x%02x\n", *pTypeFormat);
1370 case STUBLESS_MARSHAL:
1371 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1373 unsigned char *pRetVal = (unsigned char *)&RetVal;
1374 call_marshaller(&stubMsg, (unsigned char *)&pRetVal, pTypeFormat);
1377 case STUBLESS_UNMARSHAL:
1378 if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)
1379 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1381 case STUBLESS_CALCSIZE:
1382 if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)
1384 unsigned char * pRetVal = (unsigned char *)&RetVal;
1385 call_buffer_sizer(&stubMsg, (unsigned char *)&pRetVal, pTypeFormat);
1389 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1392 current_stack_offset += call_memory_sizer(&stubMsg, pTypeFormat);
1393 current_offset += sizeof(NDR_PARAM_OI_BASETYPE);
1397 NDR_PARAM_OI_OTHER * pParamOther =
1398 (NDR_PARAM_OI_OTHER *)&pFormat[current_offset];
1400 const unsigned char * pTypeFormat =
1401 &pStubDesc->pFormatTypes[pParamOther->type_offset];
1403 TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);
1407 case STUBLESS_MARSHAL:
1408 if (pParam->param_direction == RPC_FC_RETURN_PARAM)
1410 unsigned char *pRetVal = (unsigned char *)&RetVal;
1411 call_marshaller(&stubMsg, (unsigned char *)&pRetVal, pTypeFormat);
1413 else if (pParam->param_direction == RPC_FC_OUT_PARAM ||
1414 pParam->param_direction == RPC_FC_IN_OUT_PARAM)
1415 call_marshaller(&stubMsg, pArg, pTypeFormat);
1417 case STUBLESS_UNMARSHAL:
1418 if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||
1419 pParam->param_direction == RPC_FC_IN_PARAM)
1420 call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);
1422 case STUBLESS_CALCSIZE:
1423 if (pParam->param_direction == RPC_FC_RETURN_PARAM)
1425 unsigned char * pRetVal = (unsigned char *)&RetVal;
1426 call_buffer_sizer(&stubMsg, (unsigned char *)&pRetVal, pTypeFormat);
1428 else if (pParam->param_direction == RPC_FC_OUT_PARAM ||
1429 pParam->param_direction == RPC_FC_IN_OUT_PARAM)
1430 call_buffer_sizer(&stubMsg, pArg, pTypeFormat);
1433 RpcRaiseException(RPC_S_INTERNAL_ERROR);
1436 current_stack_offset += pParamOther->stack_size * sizeof(INT);
1437 current_offset += sizeof(NDR_PARAM_OI_OTHER);
1444 ERR("shouldn't reach here. phase %d\n", phase);
1449 pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);
1451 if (ext_flags & RPC_FC_PROC_EXT_NEWCORRDESC)
1453 /* free extra correlation package */
1454 /* NdrCorrelationFree(&stubMsg); */
1457 if (Oif_flags & RPC_FC_PROC_OI2F_HASPIPES)
1459 /* NdrPipesDone(...) */
1463 /* free the full pointer translation tables */
1464 if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)
1465 NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);
1468 /* free server function stack */
1469 HeapFree(GetProcessHeap(), 0, args);
1474 void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg)
1477 NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);