* Sync up to trunk HEAD (r62975).
[reactos.git] / dll / win32 / rpcrt4 / ndr_stubless.h
1 /*
2 * NDR -Oi,-Oif,-Oicf Interpreter
3 *
4 * Copyright 2007 Robert Shearman (for CodeWeavers)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #pragma once
22
23 #include <ndrtypes.h>
24
25 /* there can't be any alignment with the structures in this file */
26 #include <pshpack1.h>
27
28 typedef struct _NDR_PROC_HEADER
29 {
30 /* type of handle to use:
31 * RPC_FC_BIND_EXPLICIT = 0 - Explicit handle.
32 * Handle is passed as a parameter to the function.
33 * Indicates that explicit handle information follows the header,
34 * which actually describes the handle.
35 * RPC_FC_BIND_GENERIC = 31 - Implicit handle with custom binding routines
36 * (MIDL_STUB_DESC::IMPLICIT_HANDLE_INFO::pGenericBindingInfo)
37 * RPC_FC_BIND_PRIMITIVE = 32 - Implicit handle using handle_t created by
38 * calling application
39 * RPC_FC_AUTO_HANDLE = 33 - Automatic handle
40 * RPC_FC_CALLBACK_HANDLE = 34 - undocumented
41 */
42 unsigned char handle_type;
43
44 /* procedure flags:
45 * Oi_FULL_PTR_USED = 0x01 - A full pointer can have the value NULL and can
46 * change during the call from NULL to non-NULL and supports aliasing
47 * and cycles. Indicates that the NdrFullPointerXlatInit function
48 * should be called.
49 * Oi_RPCSS_ALLOC_USED = 0x02 - Use RpcSS allocate/free routines instead of
50 * normal allocate/free routines
51 * Oi_OBJECT_PROC = 0x04 - Indicates a procedure that is part of an OLE
52 * interface, rather than a DCE RPC interface.
53 * Oi_HAS_RPCFLAGS = 0x08 - Indicates that the rpc_flags element is
54 * present in the header.
55 * Oi_HAS_COMM_OR_FAULT = 0x20 - If Oi_OBJECT_PROC not present only then
56 * indicates that the procedure has the comm_status or fault_status
57 * MIDL attribute.
58 * Oi_OBJ_USE_V2_INTERPRETER = 0x20 - If Oi_OBJECT_PROC present only
59 * then indicates that the format string is in -Oif or -Oicf format
60 * Oi_USE_NEW_INIT_ROUTINES = 0x40 - Use NdrXInitializeNew instead of
61 * NdrXInitialize?
62 */
63 unsigned char Oi_flags;
64
65 /* the zero-based index of the procedure */
66 unsigned short proc_num;
67
68 /* total size of all parameters on the stack, including any "this"
69 * pointer and/or return value */
70 unsigned short stack_size;
71 } NDR_PROC_HEADER;
72
73 /* same as above struct except additional element rpc_flags */
74 typedef struct _NDR_PROC_HEADER_RPC
75 {
76 unsigned char handle_type;
77 unsigned char Oi_flags;
78
79 /*
80 * RPCF_Idempotent = 0x0001 - [idempotent] MIDL attribute
81 * RPCF_Broadcast = 0x0002 - [broadcast] MIDL attribute
82 * RPCF_Maybe = 0x0004 - [maybe] MIDL attribute
83 * Reserved = 0x0008 - 0x0080
84 * RPCF_Message = 0x0100 - [message] MIDL attribute
85 * Reserved = 0x0200 - 0x1000
86 * RPCF_InputSynchronous = 0x2000 - unknown
87 * RPCF_Asynchronous = 0x4000 - [async] MIDL attribute
88 * Reserved = 0x8000
89 */
90 unsigned int rpc_flags;
91 unsigned short proc_num;
92 unsigned short stack_size;
93
94 } NDR_PROC_HEADER_RPC;
95
96 typedef struct _NDR_PROC_PARTIAL_OIF_HEADER
97 {
98 /* the pre-computed client buffer size so that interpreter can skip all
99 * or some (if the flag RPC_FC_PROC_OI2F_CLTMUSTSIZE is specified) of the
100 * sizing pass */
101 unsigned short constant_client_buffer_size;
102
103 /* the pre-computed server buffer size so that interpreter can skip all
104 * or some (if the flag RPC_FC_PROC_OI2F_SRVMUSTSIZE is specified) of the
105 * sizing pass */
106 unsigned short constant_server_buffer_size;
107
108 INTERPRETER_OPT_FLAGS Oi2Flags;
109
110 /* number of params */
111 unsigned char number_of_params;
112 } NDR_PROC_PARTIAL_OIF_HEADER;
113
114 typedef struct _NDR_PARAM_OI_BASETYPE
115 {
116 /* parameter direction. One of:
117 * FC_IN_PARAM_BASETYPE = 0x4e - an in param
118 * FC_RETURN_PARAM_BASETYPE = 0x53 - a return param
119 */
120 unsigned char param_direction;
121
122 /* One of: FC_BYTE,FC_CHAR,FC_SMALL,FC_USMALL,FC_WCHAR,FC_SHORT,FC_USHORT,
123 * FC_LONG,FC_ULONG,FC_FLOAT,FC_HYPER,FC_DOUBLE,FC_ENUM16,FC_ENUM32,
124 * FC_ERROR_STATUS_T,FC_INT3264,FC_UINT3264 */
125 unsigned char type_format_char;
126 } NDR_PARAM_OI_BASETYPE;
127
128 typedef struct _NDR_PARAM_OI_OTHER
129 {
130 /* One of:
131 * FC_IN_PARAM = 0x4d - An in param
132 * FC_IN_OUT_PARAM = 0x50 - An in/out param
133 * FC_OUT_PARAM = 0x51 - An out param
134 * FC_RETURN_PARAM = 0x52 - A return value
135 * FC_IN_PARAM_NO_FREE_INST = 0x4f - A param for which no freeing is done
136 */
137 unsigned char param_direction;
138
139 /* Size of param on stack in NUMBERS OF INTS */
140 unsigned char stack_size;
141
142 /* offset in the type format string table */
143 unsigned short type_offset;
144 } NDR_PARAM_OI_OTHER;
145
146 typedef struct
147 {
148 PARAM_ATTRIBUTES attr;
149 /* the offset on the calling stack where the parameter is located */
150 unsigned short stack_offset;
151 union
152 {
153 /* see NDR_PARAM_OI_BASETYPE::type_format_char */
154 unsigned char type_format_char;
155 /* offset into the provided type format string where the type for this
156 * parameter starts */
157 unsigned short type_offset;
158 } u;
159 } NDR_PARAM_OIF;
160
161 /* explicit handle description for FC_BIND_PRIMITIVE type */
162 typedef struct _NDR_EHD_PRIMITIVE
163 {
164 /* FC_BIND_PRIMITIVE */
165 unsigned char handle_type;
166
167 /* is the handle passed in via a pointer? */
168 unsigned char flag;
169
170 /* offset from the beginning of the stack to the handle in bytes */
171 unsigned short offset;
172 } NDR_EHD_PRIMITIVE;
173
174 /* explicit handle description for FC_BIND_GENERIC type */
175 typedef struct _NDR_EHD_GENERIC
176 {
177 /* FC_BIND_GENERIC */
178 unsigned char handle_type;
179
180 /* upper 4bits is a flag indicating whether the handle is passed in
181 * via a pointer. lower 4bits is the size of the user defined generic
182 * handle type. the size must be less than or equal to the machine
183 * register size */
184 unsigned char flag_and_size;
185
186 /* offset from the beginning of the stack to the handle in bytes */
187 unsigned short offset;
188
189 /* the index into the aGenericBindingRoutinesPairs field of MIDL_STUB_DESC
190 * giving the bind and unbind routines for the handle */
191 unsigned char binding_routine_pair_index;
192
193 /* FC_PAD */
194 unsigned char unused;
195 } NDR_EHD_GENERIC;
196
197 /* explicit handle description for FC_BIND_CONTEXT type */
198 typedef struct _NDR_EHD_CONTEXT
199 {
200 /* FC_BIND_CONTEXT */
201 unsigned char handle_type;
202
203 /* Any of the following flags:
204 * NDR_CONTEXT_HANDLE_CANNOT_BE_NULL = 0x01
205 * NDR_CONTEXT_HANDLE_SERIALIZE = 0x02
206 * NDR_CONTEXT_HANDLE_NO_SERIALIZE = 0x04
207 * NDR_STRICT_CONTEXT_HANDLE = 0x08
208 * HANDLE_PARAM_IS_OUT = 0x20
209 * HANDLE_PARAM_IS_RETURN = 0x21
210 * HANDLE_PARAM_IS_IN = 0x40
211 * HANDLE_PARAM_IS_VIA_PTR = 0x80
212 */
213 unsigned char flags;
214
215 /* offset from the beginning of the stack to the handle in bytes */
216 unsigned short offset;
217
218 /* zero-based index on rundown routine in apfnNdrRundownRoutines field
219 * of MIDL_STUB_DESC */
220 unsigned char context_rundown_routine_index;
221
222 /* varies depending on NDR version used.
223 * V1: zero-based index into parameters
224 * V2: zero-based index into handles that are parameters */
225 unsigned char param_num;
226 } NDR_EHD_CONTEXT;
227
228 #include <poppack.h>
229
230 enum stubless_phase
231 {
232 STUBLESS_UNMARSHAL,
233 STUBLESS_INITOUT,
234 STUBLESS_CALLSERVER,
235 STUBLESS_CALCSIZE,
236 STUBLESS_GETBUFFER,
237 STUBLESS_MARSHAL,
238 STUBLESS_FREE
239 };
240
241 LONG_PTR CDECL ndr_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
242 void **stack_top, void **fpu_stack ) DECLSPEC_HIDDEN;
243 LONG_PTR CDECL ndr_async_client_call( PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat,
244 void **stack_top ) DECLSPEC_HIDDEN;
245 void client_do_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, enum stubless_phase phase,
246 void **fpu_args, unsigned short number_of_params, unsigned char *pRetVal ) DECLSPEC_HIDDEN;
247 PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat,
248 unsigned int stack_size, BOOL object_proc,
249 void *buffer, unsigned int size, unsigned int *count ) DECLSPEC_HIDDEN;
250 RPC_STATUS NdrpCompleteAsyncClientCall(RPC_ASYNC_STATE *pAsync, void *Reply) DECLSPEC_HIDDEN;