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** bedeck.h 82** 83** FACILITY: 84** 85** Interface Definition Language (IDL) Compiler 86** 87** ABSTRACT: 88** 89** Decoration structures and definitions 90** 91** VERSION: DCE 1.0 92** 93*/ 94 95#ifndef BEDECK_H 96#define BEDECK_H 97 98#include <nametbl.h> 99 100typedef unsigned long BE_flags_t; 101 102#define BE_Is_Open_Record(type)\ 103 ((type)->kind == AST_structure_k && AST_CONFORMANT_SET(type)) 104 105#define BE_Is_SP_Pointer(param)\ 106 ((param)->type->kind == AST_pointer_k &&\ 107 AST_SELF_POINTER_SET((param)->type->type_structure.pointer->pointee_type)) 108 109/* 110 * Macro to determine whether parameter is an array of [ref] pointers 111 */ 112#define BE_Is_Arr_of_Refs(param)\ 113 (param->type->kind == AST_array_k &&\ 114 param->type->type_structure.array->element_type->kind == AST_pointer_k &&\ 115 AST_REF_SET(param->type->type_structure.array->element_type)) 116 117/* 118 * BE_Is_Arrayified macro returns true if all of the following: 119 * 1) pt type is pointer 120 * 2) pt base type has array_rep_type set 121 * 3) param has an arrayification attribute (field_attrs or [string]) 122 */ 123#define BE_Is_Arrayified(p,pt) \ 124 (((pt)->kind == AST_pointer_k) && \ 125 ((pt)->type_structure.pointer->pointee_type->array_rep_type != NULL) && \ 126 ( ((p)->field_attrs != NULL) || AST_STRING_SET(p) )) 127 128/* 129 * BE_array_i_t flags 130 */ 131#define BE_SIMPLE_ARRAY 0x00001 /* make certain marshalling optimizations */ 132 133typedef struct BE_array_i_t 134{ 135 BE_flags_t flags; 136 137 boolean decorated; 138 boolean element_ptr_var_declared; 139 140 NAMETABLE_id_t index_var; 141 NAMETABLE_id_t frag_var; 142 143 NAMETABLE_id_t element_ptr_var; 144 struct AST_type_n_t *element_ptr_type; 145 146 NAMETABLE_id_t alloc_var; 147 struct AST_type_n_t *alloc_type; 148 NAMETABLE_id_t block_var; 149 150 char *first_element_exp; 151 152 NAMETABLE_id_t count_var; 153 NAMETABLE_id_t pcount_var; 154 NAMETABLE_id_t size_var; 155 char *count_exp; 156 char *size_exp; 157 158 /* 159 * These fields are for 2.0 NDR only. They are vectors, with a 160 * distinct value for each dimension of the array. 161 */ 162 NAMETABLE_id_t *Z; /* conformance variables */ 163 NAMETABLE_id_t *A; /* variance variables */ 164 NAMETABLE_id_t *B; 165 char **Z_exps; 166 char **A_exps; 167 char **B_exps; 168 169 int num_elts; /* for non-conformant arrays only */ 170 int ndr_elt_size; /* the ndr size of an element of the array */ 171 int loop_nest_count; /* the number of nested loops to be spelt when 172 (un)marshalling the array */ 173 174 struct AST_parameter_n_t *flat_elt; /* flattened array element */ 175 struct AST_parameter_n_t *flat_base_elt; /* points to same structure as 176 flat_elt unless flat_elt is an [out_of_line] array type, 177 in which case it points to a flattened element of 178 the ultimate array base type */ 179 struct AST_parameter_n_t *original; /* link from REF_PASS to first pass */ 180} BE_array_i_t; 181 182/* 183 * Conformant structure info 184 */ 185typedef struct BE_orecord_i_t 186{ 187 NAMETABLE_id_t alloc_var; /* name of thing to malloc */ 188 struct AST_type_n_t *alloc_type; /* type of thing to malloc */ 189 struct AST_type_n_t *alloc_typep; /* type pointer to above type */ 190 struct AST_parameter_n_t *open_array; /* pointer to open array field */ 191} BE_orecord_i_t; 192 193/* 194 * BE_arm_t flags 195 */ 196#define BE_POINTERS 0x00001 /* are there any pointer fields in this arm */ 197 198/* 199 * Flattened union arm 200 */ 201typedef struct BE_arm_t 202{ 203 BE_flags_t flags; 204 205 struct AST_case_label_n_t *labels; 206 struct AST_parameter_n_t *flat; /* flattened parameter */ 207 struct BE_arm_t *referred_to_by; /* Used in the arms of a BE_REF_PASS 208 union object to find the arm which gave rise to these pointers */ 209 210 struct BE_arm_t *next; 211 struct BE_arm_t *last; 212} BE_arm_t; 213 214/* 215 * Pipe info 216 */ 217typedef struct BE_pipe_i_t 218{ 219 boolean decorated; 220 struct AST_parameter_n_t *flat; /* conformant array of base type */ 221 struct AST_field_attr_n_t *attrs; /* generated field attributes */ 222} BE_pipe_i_t; 223 224/* 225 * Discriminated union info 226 */ 227typedef struct BE_du_i_t 228{ 229 struct AST_parameter_n_t *discrim; /* flattened disciminator */ 230 struct BE_arm_t *arms; /* list of flattened arms */ 231 232 int vec_size; /* slots required for this param */ 233} BE_du_i_t; 234 235/* 236 * Pointer info 237 */ 238typedef struct BE_ptr_i_t 239{ 240#if 0 241 struct AST_parameter_n_t *pointee; /* flattened pointee */ 242 int pointee_slots; /* slots occupied by the pointee */ 243#endif 244 struct AST_parameter_n_t *flat_array; /* flattened original type of [ptr] 245 arrays */ 246} BE_ptr_i_t; 247 248/* 249 * OOL info 250 */ 251typedef struct BE_ool_i_t 252{ 253 struct AST_type_n_t *type; /* original unflattened type of param */ 254 NAMETABLE_id_t name; /* name to use for ool param */ 255 struct AST_type_n_t *call_type; /* Type to be used when generating call 256 to ool routine */ 257 NAMETABLE_id_t call_name; /* Parameter name to be used when 258 generating call to ool routine */ 259 boolean any_pointers; /* param's type contains pointers */ 260 boolean use_P_rtn; /* invoke ool pointer routine */ 261 boolean has_calls_before; /* xmit_as or rep_as type */ 262 boolean top_level; /* object being OOLed is top-level param */ 263} BE_ool_i_t; 264 265/* 266 * Type info 267 */ 268typedef struct BE_type_i_t 269{ 270 struct AST_type_n_t *clone; /* named clone for anonymous pa types */ 271} BE_type_i_t; 272 273/* 274 * Call record types 275 */ 276typedef enum 277{ 278 BE_call_xmit_as, /* calls associated with [transmit_as] */ 279 BE_call_rep_as, /* calls associated with [represent_as] */ 280 BE_call_ctx_handle, /* calls associated with [context_handle] */ 281 BE_init_ptr_to_array, /* action associated with [ptr] array parameters */ 282 BE_init_ptr_to_conf /* action assoiciated with ptr to conformant 283 array parameters (such as strings) */ 284} BE_call_type_t; 285 286/* 287 * Ordered list of calls to invoke before or after parameter marshalling 288 */ 289typedef struct BE_call_rec_t 290{ 291 struct BE_call_rec_t *next; 292 struct BE_call_rec_t *last; 293 294 BE_call_type_t type; /* union discriminator */ 295 296 union 297 { 298 /* 299 * type == BE_call_xmit_as 300 */ 301 struct 302 { 303 NAMETABLE_id_t native_name; /* presented parameter name */ 304 struct AST_type_n_t *native_type; /* presented parameter type */ 305 306 NAMETABLE_id_t xmit_name; /* unmarshalling xmissible name */ 307 NAMETABLE_id_t pxmit_name; /* marshalling xmissible name */ 308 309 struct AST_type_n_t *xmit_type; /* unmarshalling xmissible type */ 310 311 } xmit_as; 312 313 /* 314 * type == BE_call_rep_as 315 */ 316 struct 317 { 318 NAMETABLE_id_t local_name; /* local parameter name */ 319 320 NAMETABLE_id_t net_name; /* unmarshalling network name */ 321 NAMETABLE_id_t pnet_name; /* marshalling network name */ 322 323 struct AST_type_n_t *net_type; /* unmarshalling network type */ 324 } rep_as; 325 326 /* 327 * type == BE_call_ctx_handle 328 */ 329 struct 330 { 331 NAMETABLE_id_t native_name; /* void * parameter name */ 332 struct AST_type_n_t *native_type; /* original parameter type */ 333 334 NAMETABLE_id_t wire_name; /* ndr_context_handle param */ 335 336 boolean rundown; 337 } ctx_handle; 338 339 /* 340 * type == BE_init_ptr_to_array 341 */ 342 struct 343 { 344 NAMETABLE_id_t param_name; /* array parameter's name */ 345 346 NAMETABLE_id_t ptr_name; /* name of ptr to array */ 347 struct AST_type_n_t *ptr_type; /* (ptr to array) type */ 348 } ptr_to_array; 349 350 /* 351 * type == BE_init_ptr_to_conf 352 */ 353 struct 354 { 355 NAMETABLE_id_t param_name; /* pointer parameter's name */ 356 357 NAMETABLE_id_t pointee_name; /* helper var name */ 358 struct AST_type_n_t *param_type; /* param's type */ 359 } ptr_to_conf; 360 } call; 361 362} BE_call_rec_t; 363 364/* 365 * BE_param_i_t flags 366 */ 367 368/* 369 * Special backend parameter types 370 */ 371#define BE_OPEN_RECORD 0x00000001 /* magic open record header*/ 372#define BE_ARRAY_HEADER 0x00000002 /* magic array header*/ 373 374#define BE_ALIGN_MP 0x00000004 /* align mp before this parameter */ 375#define BE_SYNC_MP 0x00000008 /* synchronize mp with offset pointer */ 376#define BE_NEW_SLOT 0x00000010 /* does this parameter require a new slot */ 377#define BE_FIELD 0x00000020 /* was this parameter originally a field */ 378#define BE_CHECK_BUFFER 0x00000040 /* unmarshalling: check for new comm_receive */ 379#define BE_ALLOCATE 0x00000080 /* allocate this parameter when unmrshlling */ 380#define BE_IN_ORECORD 0x00000100 /* this open array is in an open record */ 381#define BE_ADVANCE_MP 0x00000200 /* advance mp after this parameter */ 382#define BE_NEW_BLOCK 0x00000400 /* this parameter is the first in a block */ 383#define BE_DEFER 0x00000800 /* for non-[ref] pointers within structs */ 384#define BE_STRING0 0x00001000 /* for 1-d [string0] arrays of char */ 385#define BE_FATTRS_FLAT 0x00002000 /* param's field attrs. have been flattened */ 386#define BE_REF_PASS 0x00004000 /* marshall referents of pointer array elts. */ 387#define BE_PARRAY 0x00008000 /* pointed-at array decoration/marshalling */ 388#define BE_LAST_FIELD 0x00010000 /* last field of a conformant structure */ 389#define BE_PTR_ARRAY 0x00020000 /* this pointer used to be a [ptr] array */ 390#define BE_ARRAYIFIED 0x00040000 /* this pointer to an array used to be a scalar pointer */ 391#define BE_PTR2STR 0x00080000 /* this is a pointer to a [string] array */ 392#define BE_OOL 0x00100000 /* a param to be marshalled out-of-line */ 393#define BE_SKIP 0x00200000 /* don't marshall this param at all */ 394#define BE_OOL_HEADER 0x00400000 /* a header for an OOL parameter */ 395#define BE_XMITCFMT 0x00800000 /* conformant xmit/repas net type */ 396#define BE_HDRLESS 0x01000000 /* array has had it header pruned away */ 397#define BE_OOL_YANK_ME 0x02000000 /* an OOL param for which a "use_p" clone is needed */ 398#define BE_ARR_OF_STR 0x04000000 /* an array whose elements are strings */ 399#define BE_NEU_DISCRIM 0x80000000 /* discriminant of a non-encapsulated union */ 400 401typedef struct BE_param_i_t 402{ 403 BE_flags_t flags; 404 405 /* 406 * The only significant fields in the BE_param_i_t structure of a 407 * pristine (unflattened) parameter are the following two: 408 */ 409 struct AST_parameter_n_t *flat; /* pointer to flattened counterpart */ 410 NAMETABLE_id_t name; /* IDL-generated name for parameter */ 411 412 BE_array_i_t *array_info; /* etc. for array parameters */ 413 BE_orecord_i_t *orecord_info; /* " " conformant struct parameters */ 414 BE_du_i_t *du_info; /* " " discriminated unions params*/ 415 BE_ptr_i_t *ptr_info; /* " " non-ref pointer parameters */ 416 BE_ool_i_t *ool_info; /* " " parameters of [ool] type */ 417 418 BE_call_rec_t *call_before; /* functions to call pre-un/marshalling */ 419 BE_call_rec_t *call_after; /* " " " post-un/marshalling */ 420} BE_param_i_t; 421 422#define BE_PI_Flags(p)\ 423 ((p)->be_info.param->flags) 424 425#define BE_Array_Info(p)\ 426 ((p)->be_info.param->array_info) 427 428#define BE_Orecord_Info(p)\ 429 ((p)->be_info.param->orecord_info) 430 431#define BE_Open_Array(p)\ 432 (BE_Orecord_Info(p)->open_array) 433 434#define BE_Du_Info(p)\ 435 ((p)->be_info.param->du_info) 436 437#define BE_Ptr_Info(p)\ 438 ((p)->be_info.param->ptr_info) 439 440#define BE_Ool_Info(p)\ 441 ((p)->be_info.param->ool_info) 442 443#define BE_Calls_Before(p)\ 444 ((p)->be_info.param->call_before) 445 446#define BE_Calls_After(p)\ 447 ((p)->be_info.param->call_after) 448 449typedef struct BE_field_i_t 450{ 451 struct AST_parameter_n_t *flat; /* field's flat counterpart */ 452} BE_field_i_t; 453 454/* 455 * A pointer initialization node for server side [ref] pointer surrogates 456 */ 457typedef struct BE_ptr_init_t 458{ 459 boolean heap; /* allocate on heap */ 460 461 NAMETABLE_id_t pointer_name; 462 struct AST_type_n_t *pointer_type; /* only used if (heap) */ 463 464 NAMETABLE_id_t pointee_name; /* only used if (!heap) */ 465 struct AST_type_n_t *pointee_type; /* only used if (heap) */ 466 467 struct BE_ptr_init_t *next; 468 struct BE_ptr_init_t *last; 469} BE_ptr_init_t; 470 471/* 472 * BE_oper_i_t flags 473 */ 474#define BE_MAINTAIN_OP 0x00001 /* maintain offset pointer */ 475#define BE_BUFF_BOOL 0x00002 /* currently unused--any arrays of structs */ 476#define BE_HELPERS_EXIST 0x00004 /* Helper variables already declared */ 477 478typedef struct BE_oper_i_t 479{ 480 BE_flags_t flags; 481 struct AST_parameter_n_t *flat_params; /* flattened parameter list */ 482 struct BE_param_blk_t *sends; /* parameter block list */ 483 struct AST_parameter_n_t *recs; /* parameter block list */ 484 struct BE_local_var_t *local_vars; /* local variables */ 485 struct BE_ptr_init_t *pointers; /* pointer initialization list */ 486 487 int vec_size; /* size of marshalling iovector */ 488 int pkt_size; /* size of stack packet */ 489 int next_local_var; /* obsolete */ 490} BE_oper_i_t; 491 492#define BE_Flat_Params(o) ((o)->be_info.oper->flat_params) 493#define BE_Sends(o) ((o)->be_info.oper->sends) 494#define BE_Recs(o) ((o)->be_info.oper->recs) 495#define BE_Pointers(o) ((o)->be_info.oper->pointers) 496 497/* 498 * BE_param_blk_t flags 499 */ 500#define BE_SP_BLOCK 0x00001 /* block contains only a self-pointing param */ 501#define BE_PTR_BLOCK 0x00002 /* block contains only a pointer param */ 502#define BE_FIRST_BLOCK 0x00004 /* this is the first marshalling block */ 503#define BE_PRUNED_BLOCK 0x00008 /* block contains no marshallable params */ 504 505typedef struct BE_param_blk_t 506{ 507 BE_flags_t flags; 508 struct AST_parameter_n_t *params; 509 510 struct BE_param_blk_t *next; /* next block in this direction */ 511 struct BE_param_blk_t *last; /* last block in this direction */ 512 513 int vec_size; /* number of iovector slots required */ 514} BE_param_blk_t; 515 516#endif 517