1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1.  Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 * 2.  Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
16 *     contributors may be used to endorse or promote products derived from
17 *     this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Portions of this software have been released under the following terms:
31 *
32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
35 *
36 * To anyone who acknowledges that this file is provided "AS IS"
37 * without any express or implied warranty:
38 * permission to use, copy, modify, and distribute this file for any
39 * purpose is hereby granted without fee, provided that the above
40 * copyright notices and this notice appears in all source code copies,
41 * and that none of the names of Open Software Foundation, Inc., Hewlett-
42 * Packard Company or Digital Equipment Corporation be used
43 * in advertising or publicity pertaining to distribution of the software
44 * without specific, written prior permission.  Neither Open Software
45 * Foundation, Inc., Hewlett-Packard Company nor Digital
46 * Equipment Corporation makes any representations about the suitability
47 * of this software for any purpose.
48 *
49 * Copyright (c) 2007, Novell, Inc. All rights reserved.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 *
54 * 1.  Redistributions of source code must retain the above copyright
55 *     notice, this list of conditions and the following disclaimer.
56 * 2.  Redistributions in binary form must reproduce the above copyright
57 *     notice, this list of conditions and the following disclaimer in the
58 *     documentation and/or other materials provided with the distribution.
59 * 3.  Neither the name of Novell Inc. nor the names of its contributors
60 *     may be used to endorse or promote products derived from this
61 *     this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 *
74 * @APPLE_LICENSE_HEADER_END@
75 */
76
77/*
78**
79**  NAME:
80**
81**      idlddefs.h
82**
83**  FACILITY:
84**
85**      Interface Definition Language (IDL) Compiler
86**
87**  ABSTRACT:
88**
89**  Definitions used by stubs generated by MTS compiler
90**
91*/
92
93#ifndef IDLDDEFS_H
94#define IDLDDEFS_H	1
95
96#ifdef __cplusplus
97    extern "C" {
98#endif
99
100#include <dce/dce.h>
101#include <dce/rpc.h>
102#include <dce/idl_es.h>
103#include <dce/stubbase.h>
104
105/*
106 * IDL general defines
107 */
108
109#define IDL_BUFF_SIZE 2048
110
111/*
112 *The number of iovector elements in the iovector the NDR marshalling
113 * interpreter uses for transmits
114 */
115
116#define IDL_IOVECTOR_SIZE 10
117
118/*
119 * Arrays with the less than this number of elements are not NDR
120 *  marshalled by pointing
121 */
122
123#define IDL_POINT_THRESHOLD 256
124
125/*
126 * Arrays with more than this number of dimensions require interpreter
127 * data structures to be dynamically allocated
128*/
129
130#define IDL_NORMAL_DIMS 7
131
132/* Always try and get storage for at least this many pipe elements */
133
134#define IDL_MIN_PIPE_CHUNK_SIZE 8
135
136/*
137 * 'Address of array' macro - use to spell or not to spell '&' before array
138 * reference reliably depending on whether compiler is ANSI Standard C.
139 *
140 * The following definition had previously been the covered by the __STDC__
141 * macro. We make it the default, since we require an ANSI compiler for
142 * DCE 1.1
143 */
144
145#define IDL_AOA &
146
147/*
148 * Macro used to spell or not to spell 'const' keyword before data definition
149 * depending on whether compiler is ANSI Standard C.
150 *
151 * 1/10/94
152 * Strictly speaking, if the ANSI C Compiler supports "const" correctly
153 */
154
155#ifdef CONST_NOT_SUPPORTED
156#define IDL_CONST
157#else
158#define IDL_CONST const
159#endif
160
161/*
162 *  Flag types
163 *  "Client or server?", "Marshalling or Unmarshalling?"
164 */
165typedef enum {IDL_client_side_k, IDL_server_side_k} IDL_side_k_t;
166typedef enum {IDL_marshalling_k, IDL_unmarshalling_k} IDL_mar_or_unmar_k_t;
167typedef enum {IDL_lang_c_k
168                                                    } IDL_language_k_t;
169
170/* Structure with pointers to I-char tags */
171
172typedef struct IDL_cs_tags_t {
173    idl_ulong_int *p_marsh_tag;     /* Pointer to tag used for marshalling */
174    idl_ulong_int *p_unmar_tag;     /* Pointer to tag used for unmarshalling */
175} IDL_cs_tags_t;
176
177#define IDL_STACK_PACKET_SIZE 256
178
179typedef enum {
180    IDL_stack_packet_unused_k,  /* The marshalling interpeter's stack packet
181                                        has not been used for marshalling */
182    IDL_stack_packet_in_use_k,  /* The marshalling interpeter's stack packet
183                                        is the current marshalling buffer */
184    IDL_stack_packet_used_k,    /* The marshalling interpeter's stack packet
185                                        has been used and despatched */
186    IDL_stack_packet_part_used_k  /* The stack packet was being used for
187                               marshalling before a "marshall by pointing at" */
188} IDL_stack_packet_use_k_t;
189
190typedef void (*IDL_rtn_func_t)  (rpc_void_p_t );
191
192/*
193 *  Interpreter state block
194 */
195typedef struct IDL_ms_t {
196    idl_byte *IDL_type_vec;   /* The type vector for this interface       */
197    idl_ulong_int *IDL_offset_vec; /* The offset vector for this interface */
198    IDL_rtn_func_t *IDL_rtn_vec; /* The routine vector for this interface */
199    rpc_void_p_t *IDL_param_vec; /* The parameter vector for this operation */
200    IoVec_t(IDL_IOVECTOR_SIZE) IDL_iovec; /* RPC I/O vec pointing to buffers */
201    idl_byte *IDL_buff_addr; /* Address of current marshalling buffer */
202    idl_byte *IDL_data_addr; /* Address of start of data in current buff */
203    idl_byte *IDL_mp;   /* Pointer to first free location in current buffer */
204    rpc_iovector_elt_p_t IDL_elt_p;
205                        /* Address of iovector_elt being used for receives */
206    rpc_ss_mem_handle IDL_mem_handle;   /* Stub memory management handle */
207    rpc_ss_allocator_t IDL_allocator;
208    rpc_ss_node_table_t IDL_node_table;   /* node number to pointer table */
209    volatile rpc_call_handle_t IDL_call_h;  /* Call handle for RPC call */
210    handle_t IDL_h;  /* Client's binding handle - used with contexts
211                                                    and I-char machinery */
212    rpc_void_p_t IDL_pickling_handle;   /* Address of pickling state block */
213    volatile error_status_t IDL_status;
214                               /* Current Error status of last failing op  */
215    volatile idl_long_int IDL_fault;
216                                /* Current Fault status of last failing op  */
217    idl_ulong_int IDL_elts_in_use;   /* Number of I/O vec element in use     */
218    ndr_format_t IDL_drep;      /* Data rep for NDR transfer syntax */
219    idl_ulong_int IDL_mp_start_offset;  /* Offset of start of data from first
220                                        (0 mod 8) address in current buffer */
221    idl_ulong_int IDL_left_in_buff; /* Unused space in curr buff (in bytes) */
222    IDL_side_k_t IDL_side;      /* Client or server side? */
223    idl_ulong_int IDL_m_xmit_level; /* Level of [transmit_as] nesting when
224                                  marshalling. 0 when no [transmit_as] active */
225    IDL_language_k_t IDL_language;  /* Programming language of appl code */
226    idl_boolean IDL_marsh_pipe;     /* TRUE while a pipe is being marshalled */
227    volatile idl_boolean IDL_restartable;
228                           /* [auto_handle] TRUE => operation is restartable */
229    idl_byte IDL_ms_res_byte_1;
230    idl_byte IDL_ms_res_byte_2;
231    IDL_stack_packet_use_k_t IDL_stack_packet_status;
232    idl_byte *IDL_stack_packet_addr;
233    IDL_cs_tags_t *IDL_cs_tags_p;
234    rpc_void_p_t IDL_ms_res_ptr_4;
235    rpc_void_p_t IDL_ms_res_ptr_5;
236} IDL_ms_t, *IDL_msp_t;
237
238void rpc_ss_report_error_2  (
239    ndr_ulong_int ,
240    ndr_ulong_int ,
241    ndr_ulong_int ,
242    RPC_SS_THREADS_CANCEL_STATE_T *,
243    error_status_t *,
244    error_status_t *,
245    dcethread_exc *[],
246    IDL_msp_t
247);
248
249void rpc_ss_send_server_exception_2  (
250    rpc_call_handle_t ,
251    dcethread_exc *,
252    idl_long_int ,
253    dcethread_exc *[],
254    IDL_msp_t
255);
256
257void rpc_ss_type_vec_vers_check  (
258   IDL_msp_t
259);
260
261void rpc_ss_init_marsh_state  (
262   idl_byte [], IDL_msp_t
263);
264
265void rpc_ss_ndr_clean_up  (
266   IDL_ms_t *
267);
268
269/* Interpreter header access */
270
271#define IDL_INTERP_ENCODE_MAJOR     8
272#define IDL_INTERP_ENCODE_MINOR    10
273
274/* type vector offsets */
275#define TVEC_INT_REP_OFFSET 4
276#define IDL_VERSION_NUMBER(versno_offset)\
277    (IDL_msp->IDL_type_vec[TVEC_INT_REP_OFFSET] != NDR_LOCAL_INT_REP) ? \
278       (((*(idl_byte *)(IDL_msp->IDL_type_vec+versno_offset+1)) << 8) | \
279       *(idl_byte *)(IDL_msp->IDL_type_vec+versno_offset)) : \
280       (*(idl_short_int *)(IDL_msp->IDL_type_vec+versno_offset))
281
282/* Interpreter machinery - values of type byte */
283
284#define IDL_DT_NULL                   0
285#define IDL_DT_BOOLEAN                1
286#define IDL_DT_BYTE                   2
287#define IDL_DT_CHAR                   3
288#define IDL_DT_DOUBLE                 4
289#define IDL_DT_ENUM                   5
290#define IDL_DT_FLOAT                  6
291#define IDL_DT_SMALL                  7
292#define IDL_DT_SHORT                  8
293#define IDL_DT_LONG                   9
294#define IDL_DT_HYPER                 10
295#define IDL_DT_USMALL                11
296#define IDL_DT_USHORT                12
297#define IDL_DT_ULONG                 13
298#define IDL_DT_UHYPER                14
299#define IDL_DT_FIXED_STRUCT          15
300#define IDL_DT_CONF_STRUCT           16
301#define IDL_DT_BEGIN_NESTED_STRUCT   18
302#define IDL_DT_END_NESTED_STRUCT     19
303#define IDL_DT_FIXED_ARRAY           20
304#define IDL_DT_VARYING_ARRAY         21
305#define IDL_DT_CONF_ARRAY            22
306#define IDL_DT_OPEN_ARRAY            23
307#define IDL_DT_ENC_UNION             24
308#define IDL_DT_N_E_UNION             25
309#define IDL_DT_DOES_NOT_EXIST        26     /* Union has no default case */
310#define IDL_DT_VOID                  27     /* Empty union arm */
311#define IDL_DT_PASSED_BY_REF         28
312#define IDL_DT_FULL_PTR              29
313#define IDL_DT_UNIQUE_PTR            30
314#define IDL_DT_REF_PTR               31
315#define IDL_DT_IGNORE                32
316#define IDL_DT_STRING                33
317#define IDL_DT_TRANSMIT_AS           34
318#define IDL_DT_REPRESENT_AS          35
319#define IDL_DT_ALLOCATE              36
320#define IDL_DT_ALLOCATE_REF          37
321#define IDL_DT_NDR_ALIGN_2           38
322#define IDL_DT_NDR_ALIGN_4           39
323#define IDL_DT_NDR_ALIGN_8           40
324#define IDL_DT_PIPE                  41
325#define IDL_DT_IN_CONTEXT            42
326#define IDL_DT_IN_OUT_CONTEXT        43
327#define IDL_DT_OUT_CONTEXT           44
328#define IDL_DT_V1_ENUM               45
329#define IDL_DT_V1_ARRAY              46
330#define IDL_DT_V1_STRING             47
331#define IDL_DT_V1_CONF_STRUCT        48
332#define IDL_DT_FREE_REP              49
333#define IDL_DT_ERROR_STATUS          50
334#define IDL_DT_DELETED_NODES         51
335#define IDL_DT_CS_TYPE               52
336#define IDL_DT_CS_SHADOW             53
337#define IDL_DT_CS_ARRAY              54
338#define IDL_DT_CS_ATTRIBUTE          55
339#define IDL_DT_CS_RLSE_SHADOW        56
340#define IDL_DT_INTERFACE             57
341#define IDL_DT_DYN_INTERFACE         58
342#define IDL_DT_ORPC_INTERFACE        59 /* MIDL compat */
343#define IDL_DT_RANGE                 60 /* MIDL compat */
344#define IDL_DT_EOL                  254
345/* Reserved as filler byte          255 */
346
347#define IDL_TYPE_IS_NDR_ALIGN(type_byte)\
348    ((type_byte >= IDL_DT_NDR_ALIGN_2) && \
349        (type_byte <= IDL_DT_NDR_ALIGN_8))
350
351/* Get a long integer from the type/definition vector */
352
353#define IDL_GET_LONG_FROM_VECTOR(value,address)\
354    if (IDL_msp->IDL_type_vec[TVEC_INT_REP_OFFSET] != NDR_LOCAL_INT_REP){\
355    idl_byte *_d = (idl_byte*)&value; \
356    idl_byte *_s = (idl_byte*)(((address-(idl_byte *)0)+3) & (~3)); \
357     _d[0]=_s[3]; _d[1]=_s[2]; _d[2]=_s[1]; _d[3]=_s[0]; \
358    address = _s + 4;\
359    }\
360    else{\
361    address = (idl_byte *)(((address-(idl_byte *)0)+3) & (~3)); \
362    value = *(idl_ulong_int *)address; \
363    address += 4; }
364
365/* Step over a long integer from the type/definition vector */
366
367#define IDL_DISCARD_LONG_FROM_VECTOR(address)\
368{   address = (idl_byte *)(((address-(idl_byte *)0)+3) & (~3)); \
369    address += 4; }
370
371/* Range bound checking */
372#define IDL_INIT_RANGE(__range)\
373    ( (__range).lower = 0, (__range).upper = -1 )
374
375#define IDL_GET_RANGE_FROM_VECTOR(__range,__address)\
376    do { \
377        IDL_GET_LONG_FROM_VECTOR((__range).lower,(__address)); \
378        IDL_GET_LONG_FROM_VECTOR((__range).upper,(__address)); \
379    } while (0)
380
381#define IDL_CHECK_RANGE(__range,__type,__param_addr)\
382    do { \
383        if (!((__range).lower == 0 && (__range).upper == -1)) { \
384            if (((idl_long_int)(*(__type *)(__param_addr)) < (__range).lower) || \
385                ((idl_long_int)(*(__type *)(__param_addr)) > (__range).upper)) \
386            { \
387                DCETHREAD_RAISE(rpc_x_invalid_bound); \
388            } \
389            IDL_INIT_RANGE((__range)); /* reset for next field/parameter */ \
390        } \
391    } while (0)
392
393#define IDL_CHECK_RANGE_BYTE(__range,__param_addr)\
394    IDL_CHECK_RANGE(__range, idl_byte, __param_addr)
395
396#define IDL_CHECK_RANGE_CHAR(__range,__param_addr)\
397    IDL_CHECK_RANGE(__range, idl_char, __param_addr)
398
399#define IDL_CHECK_RANGE_BOOLEAN(__range,__param_addr)\
400    IDL_CHECK_RANGE(__range, idl_boolean, __param_addr)
401
402#define IDL_CHECK_RANGE_SMALL(__range,__param_addr)\
403    IDL_CHECK_RANGE(__range, idl_small_int, __param_addr)
404
405#define IDL_CHECK_RANGE_SHORT(__range,__param_addr)\
406    IDL_CHECK_RANGE(__range, idl_short_int, __param_addr)
407
408#define IDL_CHECK_RANGE_LONG(__range,__param_addr)\
409    IDL_CHECK_RANGE(__range, idl_long_int, __param_addr)
410
411#define IDL_CHECK_RANGE_USMALL(__range,__param_addr)\
412    IDL_CHECK_RANGE(__range, idl_usmall_int, __param_addr)
413
414#define IDL_CHECK_RANGE_USHORT(__range,__param_addr)\
415    IDL_CHECK_RANGE(__range, idl_ushort_int, __param_addr)
416
417#define IDL_CHECK_RANGE_ULONG(__range,__param_addr)\
418    IDL_CHECK_RANGE(__range, idl_ulong_int, __param_addr)
419
420#define IDL_CHECK_RANGE_FLOAT(__range,__param_addr)\
421    IDL_CHECK_RANGE(__range, idl_short_float, __param_addr)
422
423#define IDL_CHECK_RANGE_DOUBLE(__range,__param_addr)\
424    IDL_CHECK_RANGE(__range, idl_long_float, __param_addr)
425
426/* values for extra bound info byte in size_is/length_is etc. */
427#define IDL_FC_NONE		0
428#define IDL_FC_DIV_2	1
429#define IDL_FC_MUL_2	2
430#define IDL_FC_ADD_1	3
431#define IDL_FC_SUB_1	4
432#define IDL_FC_ALIGN_2	5
433#define IDL_FC_ALIGN_4	6
434#define IDL_FC_ALIGN_8	7
435#define IDL_FC_CALLBACK	8
436/* a bit of a hack but easier than extending the tuple */
437#define IDL_FC_DIV_4	9
438#define IDL_FC_MUL_4	10
439#define IDL_FC_DIV_8	11
440#define IDL_FC_MUL_8	12
441#define IDL_FC_FIXED	13
442
443/*
444 *  Signatures of interpreter modules
445 */
446
447void rpc_ss_ndr_marsh_interp  (
448    idl_ulong_int ,
449    idl_ulong_int ,
450    rpc_void_p_t [],
451    IDL_msp_t
452);
453
454void rpc_ss_ndr_unmar_interp  (
455    idl_ulong_int ,
456    idl_ulong_int ,
457    rpc_void_p_t [],
458    IDL_msp_t
459);
460
461/*
462 * Correlation checking machinery
463 *
464 * OR these flags with IDL_LIMIT_xxx and IDL_BOUND_xxx. We use
465 * flags rather than any extra opcode to avoid breaking binary
466 * compatability with existing stubs.
467 */
468#define IDL_CF_EARLY            0x10
469#define IDL_CF_SPLIT            0x20
470#define IDL_CF_IS_IID_IS        0x40
471#define IDL_CF_DONT_CHECK       0x80
472
473/*
474 *  Array machinery
475 */
476/*  Data limit type literals and machinery */
477
478#define IDL_LIMIT_FIXED         0
479#define IDL_LIMIT_FIRST_IS      1
480#define IDL_LIMIT_LAST_IS       2
481#define IDL_LIMIT_LENGTH_IS     3
482#define IDL_LIMIT_STRING        4
483#define IDL_LIMIT_UPPER_CONF    5
484
485#define IDL_LIMIT_TYPE_MASK                   0x0F
486
487#define IDL_DATA_LIMIT_PAIR_WIDTH 16
488
489typedef struct IDL_varying_control_t {
490    idl_ulong_int subslice_size;    /* Size in bytes of slice designated
491                                        by foo[I1][I2]...[Im] when array was
492                                        declared as foo[S1][S2]...[Sn] */
493    idl_ulong_int index_value;      /* Value of Im */
494} IDL_varying_control_t;
495
496/* Bound type literals and machinery */
497
498#define IDL_BOUND_FIXED     0
499#define IDL_BOUND_MIN_IS    1
500#define IDL_BOUND_MAX_IS    2
501#define IDL_BOUND_SIZE_IS   3
502#define IDL_BOUND_STRING    4
503
504#define IDL_BOUND_TYPE_MASK                   0x0F
505
506#define IDL_DATA_LIMIT_PAIR_WIDTH 16
507
508typedef struct IDL_bound_pair_t {
509    idl_long_int lower;
510    idl_long_int upper;
511} IDL_bound_pair_t;
512
513#define IDL_ALIGN_POINTER_TO_LONG(address)\
514    address = (idl_byte *)(((address-(idl_byte *)0)+3) & (~3));
515
516#define IDL_FIXED_BOUND_PAIR_WIDTH 8
517
518#define IDL_CONF_BOUND_PAIR_WIDTH 16
519
520/* Macro to advance a pointer over the bounds info for a conformant or open
521    array. Assumes that array dimensionality is at (3 mod 4) in
522    the definition vector */
523
524#define IDL_ADV_DEFN_PTR_OVER_BOUNDS(defn_ptr,dimensionality)\
525    {defn_ptr += 16 * dimensionality;}
526
527/* Size of base type of string - assuming defn_ptr is pointing at start of
528    an appropriate data limit pair */
529
530#define IDL_DATA_LIMIT_PAIR_CHAR_SIZE(defn_ptr)\
531    ((idl_ulong_int)*(defn_ptr+9))
532
533/*
534 *  Routine vector index literals
535 */
536
537#define IDL_RTN_TO_XMIT_INDEX   0
538#define IDL_RTN_FROM_XMIT_INDEX 1
539#define IDL_RTN_FREE_INST_INDEX 2
540#define IDL_RTN_FREE_XMIT_INDEX 3
541#define IDL_RTN_NET_SIZE_INDEX      0
542#define IDL_RTN_TO_NETCS_INDEX      1
543#define IDL_RTN_LOCAL_SIZE_INDEX    2
544#define IDL_RTN_FROM_NETCS_INDEX    3
545
546/*
547 *  Values and test for properties byte
548 */
549
550#define IDL_PROP_DEP_CHAR       0x01
551#define IDL_PROP_DEP_INT        0x02
552#define IDL_PROP_DEP_FLOAT      0x04
553#define IDL_PROP_DEP_ALL        0x07
554#define IDL_PROP_HAS_PTRS       0x08
555#define IDL_PROP_MAYBE_WIRE_ALIGNED 0x10
556#define IDL_PROP_HAS_LATE_CORRELATIONS	0x20
557#define IDL_PROP_TEST(prop_byte, property)\
558    ((prop_byte & property) != 0)
559
560/*
561 *  Union machinery
562 */
563
564#define IDL_UNION_ARM_DESC_WIDTH 16
565
566idl_ulong_int rpc_ss_arm_switch_value
567(
568    idl_byte *defn_vec_ptr,
569    idl_long_int index,
570    IDL_msp_t IDL_msp
571);
572
573#define IDL_ARM_SWITCH_VALUE(defn_vec_ptr, index)\
574   (IDL_msp->IDL_type_vec[TVEC_INT_REP_OFFSET] == NDR_LOCAL_INT_REP) ? \
575      (*(idl_ulong_int *)(defn_vec_ptr + index * IDL_UNION_ARM_DESC_WIDTH)) : \
576      rpc_ss_arm_switch_value(defn_vec_ptr, index, IDL_msp)
577
578/*
579 *  Alignment macros for NDR marshalling
580 *  Note that the end of a marshalling buffer is always 8-byte aligned.
581 *  Therefore if a buffer exists align bytes can always be written into it.
582 *  The pad bytes are zeroed out since this buffer eventually gets written
583 *  to the wire. Otherwise, user data may be inadvertently sent.
584 */
585
586#define IDL_MARSH_ALIGN_MP(IDL_msp, alignment)\
587    if (IDL_msp->IDL_buff_addr == NULL)\
588        rpc_ss_ndr_marsh_init_buffer(IDL_msp);\
589    {\
590        idl_ulong_int advance = IDL_msp->IDL_left_in_buff - (IDL_msp->IDL_left_in_buff & ~(alignment-1));\
591        memset(IDL_msp->IDL_mp, 0, advance);\
592        IDL_msp->IDL_mp += advance;\
593        IDL_msp->IDL_left_in_buff -= advance;\
594    }
595
596/*
597 *  Buffers delivered by the runtime are always 8-byte aligned multiples of
598 *  8 bytes. So alignment operations never switch buffers. Note that if the
599 *  buffer is not full IDL_left_in_buff will not share (mod 8) alignment
600 *  characteristics with IDL_mp.
601 */
602
603#define IDL_UNMAR_ALIGN_MP(IDL_msp, alignment)\
604{ \
605    uintptr_t advance;\
606    advance = (idl_byte *)\
607        (((IDL_msp->IDL_mp - (idl_byte *)0) + (alignment-1)) & ~(alignment-1)) \
608            - IDL_msp->IDL_mp; \
609    if (advance > IDL_msp->IDL_left_in_buff) { \
610        IDL_msp->IDL_status = rpc_s_stub_protocol_error; \
611        DCETHREAD_RAISE( rpc_x_ss_pipe_comm_error ); \
612    } \
613    IDL_msp->IDL_mp += advance; \
614    IDL_msp->IDL_left_in_buff -= advance;\
615}
616
617/*
618 *  Description of a pointee
619 */
620
621typedef struct IDL_pointee_desc_t {
622    idl_byte pointee_type;
623    /* Fields only used if pointee is non-fixed array */
624    idl_boolean base_type_has_pointers; /* TRUE => array of pointers or array
625                                            of type containing pointers */
626    idl_boolean already_unmarshalled;   /* T => pointee already unmarshalled */
627                                        /* Also used for conformant struct   */
628    idl_byte *array_base_defn_ptr;  /* Points at array base info */
629    idl_ulong_int dimensionality;
630    IDL_bound_pair_t *bounds_list;
631    idl_ulong_int *Z_values;
632    IDL_bound_pair_t *range_list;  /* Used only if pointee is varying or
633                                                                open array */
634    /*
635     * Fields used only if pointee is non-encapsulated union,
636     * or if correlation checking is enabled.
637     */
638    rpc_void_p_t struct_addr;
639    idl_ulong_int *struct_offset_vec_ptr;
640} IDL_pointee_desc_t;
641
642/*
643 *  Literal to flag a new [unique] node or a [ref] conformant structure
644 */
645
646#define IDL_NEW_NODE ((rpc_void_p_t)(-1))
647
648/*
649 *  MTS versions of storage management routines
650 */
651
652void rpc_ss_mts_client_estab_alloc  ( volatile IDL_ms_t * );
653
654/*
655 * Masks for testing -bug flags
656 */
657
658#define IDL_BUG_1 0x00000002
659#define IDL_BUG_2 0x00000004
660#define IDL_BUG_4 0x00000010
661
662/*
663 *  Machinery for pipes
664 */
665
666typedef struct IDL_pipe {
667    void (* pull)  (
668       rpc_ss_pipe_state_t,
669       rpc_void_p_t ,
670       idl_ulong_int,
671       idl_ulong_int *
672    );
673    void (* push)  (
674       rpc_ss_pipe_state_t ,
675       rpc_void_p_t ,
676       idl_ulong_int
677    );
678    void (* alloc)  (
679       rpc_ss_pipe_state_t ,
680       idl_ulong_int ,
681       rpc_void_p_t *,
682       idl_ulong_int *
683    );
684    rpc_ss_pipe_state_t state;
685} IDL_pipe;
686
687/*
688 *  Callee stub representation of context handle
689 */
690
691typedef struct IDL_ee_context_t {
692    rpc_ss_context_t local;
693    ndr_context_handle wire;
694} IDL_ee_context_t;
695
696/*
697 *  Flags used in routine calls
698 */
699
700#define IDL_M_V1_ARRAY      0x01
701                                /* Array with [v1_array] attribute */
702#define IDL_M_IS_PARAM      0x02
703                                /* Array is a parameter */
704#define IDL_M_IS_STRING     0x04
705                                /* Array with [string] attribute */
706#define IDL_M_ADD_NULL      0x08
707                          /* Explicit null terminator must be added to string */
708#define IDL_M_CONF_ARRAY    0x10
709                                /* Array is conformant */
710#define IDL_M_DO_NOT_POINT  0x20
711                                /* Do not marshall array by pointing */
712#define IDL_M_FLAGS_TEST(flags_word, property)\
713    ((flags_word & property) != 0)
714
715/*
716 *  Routines referenced from more than one interpreter module
717 */
718
719idl_ulong_int rpc_ss_type_size  (
720   idl_byte *,IDL_msp_t
721);
722
723void rpc_ss_Z_values_from_bounds  (
724    IDL_bound_pair_t *,
725    idl_ulong_int ,
726    idl_ulong_int **,
727    IDL_msp_t
728);
729
730void rpc_ss_ndr_contiguous_elt  (
731    idl_ulong_int ,
732    idl_ulong_int *,
733    IDL_bound_pair_t *,
734    idl_ulong_int ,
735    idl_boolean *,
736    idl_ulong_int *,
737    rpc_void_p_t *
738);
739
740void rpc_ss_ndr_arr_align_and_opt  (
741    IDL_mar_or_unmar_k_t ,
742    idl_ulong_int ,
743    idl_byte *,
744    idl_byte *,
745    idl_boolean *,
746    IDL_msp_t
747);
748
749void rpc_ss_ndr_marsh_init_buffer  (
750   IDL_msp_t
751);
752
753idl_long_int rpc_ss_get_typed_integer  (
754    idl_byte ,
755    rpc_void_p_t ,
756    IDL_msp_t
757);
758
759void rpc_ss_build_bounds_list  (
760    idl_byte **,
761    rpc_void_p_t ,
762    rpc_void_p_t ,
763    idl_ulong_int *,
764    idl_ulong_int ,
765    IDL_bound_pair_t **,
766    IDL_msp_t
767);
768
769void rpc_ss_build_bounds_list_2  (
770    idl_byte **,
771    rpc_void_p_t ,
772    rpc_void_p_t ,
773    idl_ulong_int *,
774    idl_ulong_int ,
775    idl_boolean *,
776    IDL_bound_pair_t **,
777    IDL_msp_t
778);
779
780void rpc_ss_build_range_list  (
781    idl_byte **,
782    rpc_void_p_t ,
783    rpc_void_p_t ,
784    idl_ulong_int *,
785    idl_ulong_int ,
786    IDL_bound_pair_t *,
787    IDL_bound_pair_t **,
788    idl_boolean *,
789    IDL_msp_t
790);
791
792void rpc_ss_build_range_list_2  (
793    idl_byte **,
794    rpc_void_p_t ,
795    rpc_void_p_t ,
796    idl_ulong_int *,
797    idl_ulong_int ,
798    IDL_bound_pair_t *,
799    idl_boolean *,
800    IDL_bound_pair_t **,
801    idl_boolean *,
802    IDL_msp_t
803);
804
805void rpc_ss_get_string_base_desc  (
806    idl_byte * ,
807    idl_ulong_int *,
808    idl_ulong_int *,
809    IDL_msp_t
810);
811
812idl_boolean rpc_ss_find_union_arm_defn  (
813    idl_byte *_vec_ptr,
814    idl_ulong_int ,
815    idl_ulong_int ,
816    idl_byte **   ,
817    IDL_msp_t
818);
819
820void rpc_ss_get_switch_from_data  (
821    idl_ulong_int ,
822    idl_byte ,
823    rpc_void_p_t ,
824    idl_ulong_int *,
825    idl_ulong_int *,
826    IDL_msp_t
827);
828
829idl_boolean rpc_ss_bug_1_thru_31  (
830    idl_ulong_int ,
831    IDL_msp_t
832);
833
834idl_ulong_int rpc_ss_ndr_bug_1_align  (
835    idl_byte *,
836    IDL_msp_t
837);
838
839/*
840 * MTS pipe state block
841 */
842
843typedef struct rpc_ss_mts_ee_pipe_state_t
844{
845    long pipe_number;
846    long next_in_pipe;               /* if -ve, next pipe is [out] */
847    long next_out_pipe;
848    long *p_current_pipe;            /* +ve curr pipe is [in], -ve for [out] */
849    unsigned long left_in_wire_array;
850    struct IDL_ms_t *IDL_msp;        /* Pointer to interpreter state block */
851    unsigned long IDL_base_type_offset;  /* Offset of pipe base type definition
852                                            in type vector */
853    ndr_boolean pipe_drained;         /* used only when pipe is [in] */
854    ndr_boolean pipe_filled;          /* used only when pipe is [out] */
855} rpc_ss_mts_ee_pipe_state_t;
856
857void rpc_ss_mts_init_callee_pipe  (
858    long ,    /* Index of pipe in set of pipes in the
859                            operation's parameter list */
860    long ,     /* Index of next [in] pipe to process */
861    long ,     /* Index of next [out] pipe to process */
862    long *,    /* Ptr to index num and dirn of curr active pipe */
863    struct IDL_ms_t *,       /* Pointer to interpreter state block */
864    unsigned long ,  /* Offset of pipe base type definition
865                                            in type vector */
866    rpc_ss_mts_ee_pipe_state_t **
867				/* Addr of ptr to pipe state block */
868);
869
870void rpc_ss_ndr_ee_marsh_pipe_chunk  (
871    rpc_ss_pipe_state_t ,
872    rpc_void_p_t ,
873    idl_ulong_int
874);
875
876void rpc_ss_ndr_ee_unmar_pipe_chunk  (
877    rpc_ss_pipe_state_t ,
878    rpc_void_p_t ,
879    idl_ulong_int ,
880    idl_ulong_int *
881);
882
883void rpc_ss_fixed_bounds_from_vector   (
884    idl_ulong_int ,
885    idl_byte *,
886    IDL_bound_pair_t **,
887    IDL_msp_t
888);
889
890idl_ulong_int rpc_ss_arm_switch_value   (
891    idl_byte *,
892    idl_long_int,
893    IDL_msp_t
894);
895
896/*
897 *  IDL encoding services
898 */
899/* Version number of the encoding state block pointed to by a handle */
900
901#define IDL_ES_STATE_VERSION 1
902
903/* Version of the pickle header stored with the pickle */
904
905#define IDL_ES_HEADER_VERSION 1
906
907/* A encoding services handle is either "encoding" or "decoding",
908    but a stub may be [encode, decode] */
909
910typedef enum {
911   IDL_encoding_k, IDL_decoding_k, IDL_both_k
912} IDL_es_action_type_k_t;
913
914/* Type of buffering - for decode non-dynamic = fixed */
915
916typedef enum {
917IDL_incremental_k, IDL_fixed_k, IDL_dynamic_k
918} IDL_es_action_style_k_t;
919
920/* An encoding dynamic buffer is built using a chain of rpc_iovector_elt's
921    which describe the intermediate buffers used during encoding */
922
923typedef struct IDL_dyn_buff_link_t {
924    rpc_iovector_elt_t *IDL_p_iovec_elt;
925    struct IDL_dyn_buff_link_t *IDL_next;
926} IDL_dyn_buff_link_t;
927
928/* Pickle header as a C structure */
929
930typedef struct idl_es_pvt_header_t {
931    idl_usmall_int IDL_version;	/* pickle header version (now version=1) */
932    idl_usmall_int IDL_int_drep;     /* drep of pickle header */
933    idl_usmall_int IDL_fill2;
934    idl_usmall_int IDL_fill3;
935    rpc_syntax_id_t IDL_syntax_id; /* encoding syntax used */
936    rpc_if_id_t IDL_if_id;    /* uuid/version of interface */
937    idl_ulong_int IDL_op_num;      /* operation number of encoding */
938} idl_es_pvt_header_t;
939
940/* Type pickling MS extension */
941
942#define IDL_ES_TYPE_COMMON_HEADER_LEN	8
943#define IDL_ES_TYPE_HEADER_LEN		(IDL_ES_TYPE_COMMON_HEADER_LEN + 8)
944
945typedef struct idl_es_type_pvt_header_t {
946    idl_usmall_int IDL_version;		/* type pickle header version (now version=1) */
947    idl_usmall_int IDL_endianness;	/* 0x10 for little-endian, 0x00 for big-endian */
948    idl_ushort_int IDL_common_header_length;	/* common header length (8) */
949    idl_byte IDL_fill[4];		/* filler bytes (0xcc) */
950} idl_es_type_pvt_header_t;
951
952/* If op_num in pickle header has the following value, the pickle header is
953    invalid */
954
955#define IDL_INVALID_OP_NUM 0xFFFFFFFF
956
957typedef struct idl_es_handle_s_t
958{
959    idl_ulong_int IDL_version;        /* This longword must appear first,
960                                        for compatibility with an existing form
961                                        of pickling used by MIA */
962    IDL_es_action_type_k_t IDL_action;  /* Encode or decode */
963    IDL_es_action_style_k_t IDL_style;  /* Type of buffering */
964    idl_boolean IDL_pickle_header_read; /* During decoding, TRUE => header for
965                                        current pickle has been read */
966    idl_es_pvt_header_t IDL_pickle_header;
967            /* For encoding, the transfer syntax is set when the state block is
968                created. The if_id and op_num are valid after an encoding has
969                been done.
970               During decoding this is a local copy of the pickle header */
971    IDL_msp_t IDL_msp;              /* For encode/decode the marshalling state
972                                        block is dynamically allocated */
973    idl_ulong_int IDL_es_flags;     /* attribute flags */
974/* Fields used for incremental buffering */
975
976    idl_void_p_t IDL_state;  /* User state */
977    idl_es_allocate_fn_t IDL_alloc;  /* User allocate routine */
978    idl_es_write_fn_t IDL_write;  /* User write routine */
979    idl_es_read_fn_t IDL_read;   /* User read routine */
980
981/* Fields used for fixed buffering */
982
983    idl_byte *IDL_buff_addr;            /* Address of user buffer */
984    idl_ulong_int IDL_bsize;  /* Size of user buffer */
985    idl_byte *IDL_align_buff_addr;    /* For a fixed decode, NULL unless we had
986                                        to allocate aligned storage */
987/* Field used for fixed and dynamic buffering */
988
989    idl_ulong_int *IDL_esize; /* Address to write pickle size to */
990
991/* Fields used for dynamic buffering */
992
993    idl_byte **IDL_p_buff_addr;	/* Address to write address of pickle to */
994    IDL_dyn_buff_link_t *IDL_dyn_buff_chain_head;
995                                    /* Head of chain of intermediate buffers */
996    IDL_dyn_buff_link_t *IDL_dyn_buff_chain_tail;
997                                    /* Tail of chain of intermediate buffers */
998} IDL_es_state_t;
999
1000void idl_es_encode_init_buffer   (
1001    idl_ulong_int *,
1002    IDL_msp_t
1003);
1004
1005void idl_es_encode_attach_buff  (
1006    IDL_msp_t
1007);
1008
1009error_status_t idl_es_encode_new_dyn_buff  (
1010    idl_ulong_int *,
1011    IDL_msp_t
1012);
1013
1014void idl_es_before_interp_call  (
1015    idl_es_handle_t ,      /* [in] User's encoding handle */
1016    rpc_if_handle_t ,    /* [in] Pointer to stub's ifspec */
1017    idl_byte [],    /* [in] Stub's type vector */
1018    idl_ulong_int ,   /* [in] operation number */
1019    IDL_es_action_type_k_t , /* [in] Is this operation labelled
1020                                            [encode], [decode] */
1021    idl_es_transfer_syntax_t *,
1022                            /* [out] Transfer syntax to use for encoding */
1023    IDL_msp_t
1024);
1025
1026void idl_es_after_interp_call  (
1027  IDL_msp_t
1028);
1029
1030void idl_es_clean_up  (
1031   IDL_msp_t
1032);
1033
1034void idl_es_decode_check_buffer  (
1035    IDL_msp_t
1036);
1037
1038/*
1039 *  International character support
1040 */
1041/* Layout of element of the cs_shadow for a structure or parameter list */
1042
1043typedef struct IDL_cs_shadow_elt_t {
1044    idl_boolean IDL_release;    /* Marshalling only - data field is pointer to
1045                                    storage which should be released */
1046    idl_cs_convert_t IDL_convert_type; /* Unmarshalling only
1047                                                         - conversion type */
1048    union {
1049        rpc_void_p_t IDL_storage_p; /* Pointer to wire form of [cs_char] or
1050                                        array of [cs_char] */
1051        idl_ulong_int IDL_value;    /* Transformed value of [size_is] or
1052                                        [length_is] of [cs_char] array */
1053    } IDL_data;
1054} IDL_cs_shadow_elt_t;
1055
1056void rpc_ss_put_typed_integer (
1057    /* in */ idl_ulong_int ,
1058    /* in */ idl_byte ,
1059    /* in */ rpc_void_p_t
1060);
1061
1062#ifdef __cplusplus
1063    }
1064#endif
1065
1066#endif /* _IDLDDEFS_H */
1067