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** ndrmi.h 80** 81** FACILITY: 82** 83** Interface Definition Language (IDL) Compiler 84** 85** ABSTRACT: 86** 87** Header file for macros and procedures shared between ndrmi*.c modules 88** 89*/ 90 91/* Marshalling strategy 92 * 93 * All marshalling is done into buffers, except when an array is encountered 94 * that is sufficiently large to justify the "point at array optimization" 95 * A standard size iovector is used. When all its elements point at buffers 96 * or, by the optimization, arrays, it is despatched by an rpc_call_transmit. 97 * At the end of marshalling there is usually a further transmit, to send the 98 * data not already sent. On the server side, if there is no unsent data, 99 * there is no rpc_call_transmit. On the client side, if there is no unsent 100 * data there is still a transceive, to turn the line round. 101 * 102 * The following state block fields affect marshalling 103 * IDL_buff_addr address of the current buffer 104 * IDL_data_addr address of first byte in buffer to be transmitted 105 * IDL_mp_start_offset determines the position of the start of data in the 106 * current buffer relative to the first (0 mod 8) address 107 * in the buffer. This will be 0 unless marshalling the 108 * buffer follows a "marshall array by pointing" 109 * IDL_mp Address in buffer at which next data item can be placed 110 * IDL_left_in_buff Number of bytes in current buffer still available for 111 * marshalling. 112 */ 113 114/******************************************************************************/ 115/* */ 116/* Check whether there is enough space in the current buffer, if one exists */ 117/* If no buffer, create one */ 118/* If buffer is full, perform closure/despatch and start a new buffer */ 119/* */ 120/******************************************************************************/ 121#define rpc_ss_ndr_marsh_check_buffer( datum_size, IDL_msp ) \ 122{ \ 123 if (datum_size > IDL_msp->IDL_left_in_buff) \ 124 { \ 125 if (IDL_msp->IDL_buff_addr != NULL) \ 126 { \ 127 rpc_ss_attach_buff_to_iovec( IDL_msp ); \ 128 rpc_ss_xmit_iovec_if_necess( idl_false, IDL_msp ); \ 129 IDL_msp->IDL_mp_start_offset = 0; \ 130 } \ 131 rpc_ss_ndr_marsh_init_buffer( IDL_msp ); \ 132 } \ 133} 134 135/******************************************************************************/ 136/* */ 137/* Marshall a scalar */ 138/* */ 139/******************************************************************************/ 140 141#define IDL_MARSH_1_BYTE_SCALAR( marshalling_macro, type, param_addr ) \ 142{ \ 143 rpc_ss_ndr_marsh_check_buffer( 1, IDL_msp ); \ 144 marshalling_macro(IDL_msp->IDL_mp, *(type *)(param_addr)); \ 145 IDL_msp->IDL_mp += 1; \ 146 IDL_msp->IDL_left_in_buff -= 1; \ 147} 148 149#define IDL_MARSH_BOOLEAN( param_addr ) \ 150{ \ 151 IDL_MARSH_1_BYTE_SCALAR( rpc_marshall_boolean, idl_boolean, param_addr ); \ 152} 153 154#define IDL_MARSH_BYTE( param_addr ) \ 155 IDL_MARSH_1_BYTE_SCALAR( rpc_marshall_byte, idl_byte, param_addr ) 156 157#define IDL_MARSH_CHAR( param_addr ) \ 158 IDL_MARSH_1_BYTE_SCALAR( rpc_marshall_char, idl_char, param_addr ) 159 160#define IDL_MARSH_ALIGNED_SCALAR( marshalling_macro, size, type, param_addr ) \ 161{ \ 162 IDL_MARSH_ALIGN_MP( IDL_msp, size ); \ 163 rpc_ss_ndr_marsh_check_buffer( size, IDL_msp ); \ 164 marshalling_macro(IDL_msp->IDL_mp, *(type *)(param_addr)); \ 165 IDL_msp->IDL_mp += size; \ 166 IDL_msp->IDL_left_in_buff -= size; \ 167} 168 169#define IDL_MARSH_DOUBLE( param_addr ) \ 170 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_long_float, 8, idl_long_float, param_addr ) 171 172#define IDL_MARSH_ENUM( param_addr ) \ 173 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_enum, 2, int, param_addr ) 174 175#define IDL_MARSH_FLOAT( param_addr ) \ 176 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_short_float, 4, idl_short_float, param_addr ) 177 178#define IDL_MARSH_SMALL( param_addr ) \ 179{ \ 180 IDL_MARSH_1_BYTE_SCALAR( rpc_marshall_small_int, idl_small_int, param_addr ); \ 181} 182 183#define IDL_MARSH_SHORT( param_addr ) \ 184 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_short_int, 2, idl_short_int, param_addr ) 185 186#define IDL_MARSH_LONG( param_addr ) \ 187 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_long_int, 4, idl_long_int, param_addr ) 188 189#define IDL_MARSH_HYPER( param_addr ) \ 190 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_hyper_int, 8, idl_hyper_int, param_addr ) 191 192#define IDL_MARSH_USMALL( param_addr ) \ 193{ \ 194 IDL_MARSH_1_BYTE_SCALAR( rpc_marshall_usmall_int, idl_usmall_int, param_addr ); \ 195} 196 197#define IDL_MARSH_USHORT( param_addr ) \ 198{ \ 199 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_ushort_int, 2, idl_ushort_int, param_addr ); \ 200} 201 202#define IDL_MARSH_ULONG( param_addr ) \ 203 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_ulong_int, 4, idl_ulong_int, param_addr ) 204 205#define IDL_MARSH_UHYPER( param_addr ) \ 206 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_uhyper_int, 8, idl_uhyper_int, param_addr ) 207 208#define IDL_MARSH_V1_ENUM( param_addr ) \ 209 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_v1_enum, 4, int, param_addr ) 210 211#ifdef IDL_ENABLE_STATUS_MAPPING 212#define IDL_MARSH_ERROR_STATUS( param_addr ) \ 213{ \ 214 IDL_MARSH_ALIGN_MP( IDL_msp, 4 ); \ 215 rpc_ss_ndr_marsh_check_buffer( 4, IDL_msp ); \ 216 rpc_marshall_ulong_int(IDL_msp->IDL_mp, *(idl_ulong_int *)(param_addr)); \ 217 rpc_ss_map_local_to_dce_status((error_status_t *)(IDL_msp->IDL_mp)); \ 218 IDL_msp->IDL_mp += 4; \ 219 IDL_msp->IDL_left_in_buff -= 4; \ 220} 221#else 222#define IDL_MARSH_ERROR_STATUS( param_addr ) \ 223{ \ 224 IDL_MARSH_ALIGN_MP( IDL_msp, 4 ); \ 225 rpc_ss_ndr_marsh_check_buffer( 4, IDL_msp ); \ 226 rpc_marshall_ulong_int(IDL_msp->IDL_mp, *(idl_ulong_int *)(param_addr)); \ 227 IDL_msp->IDL_mp += 4; \ 228 IDL_msp->IDL_left_in_buff -= 4; \ 229} 230#endif 231 232/* For marshalling interpreter internal variables, which are always C format */ 233#define IDL_MARSH_CUSHORT( param_addr ) \ 234 IDL_MARSH_ALIGNED_SCALAR( rpc_marshall_ushort_int, 2, idl_ushort_int, param_addr ) 235 236#define IDL_MARSH_CUSMALL( param_addr ) \ 237 IDL_MARSH_1_BYTE_SCALAR( rpc_marshall_usmall_int, idl_usmall_int, param_addr ) 238 239/* Function prototypes */ 240 241void rpc_ss_attach_buff_to_iovec 242( 243 IDL_msp_t IDL_msp 244); 245 246void rpc_ss_conf_struct_cs_bounds 247( 248 idl_byte *defn_vec_ptr, 249 IDL_cs_shadow_elt_t *cs_shadow, 250 IDL_bound_pair_t *bounds_list, 251 IDL_msp_t IDL_msp 252); 253 254void rpc_ss_discard_allocate_ref 255( 256 idl_byte **p_type_vec_ptr 257); 258 259void rpc_ss_ndr_m_dfc_arr_ptees 260( 261 idl_ulong_int defn_index, 262 rpc_void_p_t array_addr, 263 rpc_void_p_t struct_addr, 264 idl_ulong_int *struct_offset_vec_ptr, 265 idl_ulong_int flags, 266 IDL_msp_t IDL_msp 267); 268 269void rpc_ss_ndr_m_dvo_arr_ptees 270( 271 idl_ulong_int defn_index, 272 rpc_void_p_t array_addr, 273 rpc_void_p_t struct_addr, 274 idl_ulong_int *struct_offset_vec_ptr, 275 idl_ulong_int flags, 276 IDL_msp_t IDL_msp 277); 278 279void rpc_ss_ndr_m_enc_union_or_ptees 280( 281 rpc_void_p_t param_addr, 282 idl_ulong_int defn_index, 283 idl_boolean pointees, 284 IDL_msp_t IDL_msp 285); 286 287void rpc_ss_ndr_m_fix_or_conf_arr 288( 289 rpc_void_p_t array_addr, 290 idl_ulong_int dimensionality, 291 IDL_bound_pair_t *bounds_list, 292 idl_byte *defn_vec_ptr, 293 idl_ulong_int flags, 294 IDL_msp_t IDL_msp 295); 296 297void rpc_ss_ndr_m_fixed_cs_array 298( 299 rpc_void_p_t array_addr, 300 idl_byte **p_defn_vec_ptr, 301 IDL_msp_t IDL_msp 302); 303 304void rpc_ss_ndr_m_n_e_union_or_ptees 305( 306 rpc_void_p_t param_addr, 307 idl_ulong_int switch_index, 308 idl_ulong_int defn_index, 309 rpc_void_p_t struct_addr, 310 idl_ulong_int *struct_offset_vec_ptr, 311 idl_boolean pointees, 312 IDL_msp_t IDL_msp 313); 314 315void rpc_ss_ndr_m_param_cs_shadow 316( 317 idl_byte *type_vec_ptr, 318 idl_ulong_int param_index, 319 idl_ulong_int shadow_length, 320 IDL_cs_shadow_elt_t **p_cs_shadow, 321 IDL_msp_t IDL_msp 322); 323 324void rpc_ss_ndr_m_rlse_cs_shadow 325( 326 IDL_cs_shadow_elt_t *cs_shadow, 327 idl_ulong_int shadow_length, 328 IDL_msp_t IDL_msp 329); 330 331void rpc_ss_ndr_m_struct_cs_shadow 332( 333 rpc_void_p_t struct_addr, 334 idl_byte struct_type, 335 idl_ulong_int shadow_length, 336 idl_ulong_int offset_index, 337 idl_byte *defn_vec_ptr, 338 IDL_cs_shadow_elt_t **p_cs_shadow, 339 IDL_msp_t IDL_msp 340); 341 342void rpc_ss_ndr_m_struct_pointees 343( 344 idl_byte struct_type, 345 idl_ulong_int defn_index, 346 rpc_void_p_t struct_addr, 347 IDL_msp_t IDL_msp 348); 349 350void rpc_ss_ndr_m_var_or_open_arr 351( 352 rpc_void_p_t array_addr, 353 idl_ulong_int *Z_values, 354 idl_ulong_int dimensionality, 355 IDL_bound_pair_t *range_list, 356 idl_byte *defn_vec_ptr, 357 idl_ulong_int flags, 358 IDL_msp_t IDL_msp 359); 360 361void rpc_ss_ndr_marsh_by_copying 362( 363 idl_ulong_int element_count, 364 idl_ulong_int element_size, 365 rpc_void_p_t array_addr, 366 IDL_msp_t IDL_msp 367); 368 369void rpc_ss_ndr_marsh_by_looping 370( 371 idl_ulong_int element_count, 372 idl_byte base_type, 373 rpc_void_p_t array_addr, 374 idl_ulong_int element_size, 375 idl_ulong_int element_defn_index, 376 IDL_msp_t IDL_msp 377); 378 379void rpc_ss_ndr_marsh_by_pointing 380( 381 idl_ulong_int element_count, 382 idl_ulong_int element_size, 383 rpc_void_p_t array_addr, 384 IDL_msp_t IDL_msp 385); 386 387void rpc_ss_ndr_marsh_context 388( 389 idl_byte context_type, 390 rpc_void_p_t param_addr, 391 IDL_msp_t IDL_msp 392); 393 394void rpc_ss_ndr_marsh_cs_array 395( 396 rpc_void_p_t array_addr, 397 IDL_cs_shadow_elt_t *cs_shadow, 398 idl_ulong_int shadow_index, 399 idl_boolean in_struct, 400 idl_byte **p_defn_vec_ptr, 401 IDL_msp_t IDL_msp 402); 403 404void rpc_ss_ndr_marsh_cs_char 405( 406 rpc_void_p_t char_addr, 407 idl_ulong_int cs_type_defn_index, 408 IDL_msp_t IDL_msp 409); 410 411void rpc_ss_ndr_marsh_deletes 412( 413 IDL_msp_t IDL_msp 414); 415 416void rpc_ss_ndr_marsh_fixed_arr 417( 418 idl_ulong_int defn_index, 419 rpc_void_p_t array_addr, 420 idl_ulong_int flags, 421 IDL_msp_t IDL_msp 422); 423 424void rpc_ss_ndr_marsh_open_arr 425( 426 idl_ulong_int defn_index, 427 rpc_void_p_t array_addr, 428 idl_ulong_int flags, 429 IDL_msp_t IDL_msp 430); 431 432void rpc_ss_ndr_marsh_pipe 433( 434 idl_ulong_int defn_index, 435 rpc_void_p_t param_addr, 436 IDL_msp_t IDL_msp 437); 438 439void rpc_ss_ndr_marsh_pointee 440( 441 idl_byte *defn_vec_ptr, 442 rpc_void_p_t pointee_addr, 443 idl_boolean register_node, 444 IDL_pointee_desc_t *p_pointee_desc, 445 IDL_msp_t IDL_msp 446); 447 448void rpc_ss_ndr_marsh_scalar 449( 450 idl_byte type_byte, 451 rpc_void_p_t param_addr, 452 IDL_msp_t IDL_msp 453); 454 455void rpc_ss_ndr_marsh_bounded_scalar 456( 457 IDL_bound_pair_t *range_bounds, 458 idl_byte type_byte, 459 rpc_void_p_t param_addr, 460 IDL_msp_t IDL_msp 461); 462 463void rpc_ss_ndr_marsh_interface 464( 465 idl_ulong_int defn_index, 466 void *param_addr, 467 IDL_msp_t IDL_msp 468); 469 470void rpc_ss_ndr_marsh_dyn_interface 471( 472 idl_ulong_int rtn_index, 473 void *param_addr, 474 idl_uuid_t *piid, 475 IDL_msp_t IDL_msp 476); 477 478void rpc_ss_ndr_marsh_struct 479( 480 idl_byte struct_type, 481 idl_ulong_int defn_index, 482 rpc_void_p_t struct_addr, 483 IDL_msp_t IDL_msp 484); 485 486void rpc_ss_ndr_marsh_v1_string 487( 488 rpc_void_p_t param_addr, 489 idl_ulong_int flags, 490 IDL_msp_t IDL_msp 491); 492 493void rpc_ss_ndr_marsh_varying_arr 494( 495 idl_ulong_int defn_index, 496 rpc_void_p_t array_addr, 497 rpc_void_p_t struct_addr, 498 idl_ulong_int *struct_offset_vec_ptr, 499 idl_ulong_int flags, 500 IDL_msp_t IDL_msp 501); 502 503void rpc_ss_ndr_marsh_xmit_as 504( 505 idl_ulong_int defn_index, 506 rpc_void_p_t param_addr, 507 IDL_msp_t IDL_msp 508); 509 510void rpc_ss_ndr_marsh_Z_values 511( 512 idl_ulong_int dimensionality, 513 idl_ulong_int *Z_values, 514 IDL_msp_t IDL_msp 515); 516 517void rpc_ss_pointee_desc_from_data 518( 519 idl_byte *defn_vec_ptr, 520 rpc_void_p_t array_addr, 521 rpc_void_p_t struct_addr, 522 idl_ulong_int *struct_offset_vec_ptr, 523 IDL_pointee_desc_t *p_pointee_desc, 524 IDL_msp_t IDL_msp 525); 526 527#define rpc_ss_rlse_data_pointee_desc( p_pointee_desc, IDL_msp ) \ 528 if ((p_pointee_desc)->dimensionality > 0) \ 529 { \ 530 rpc_ss_mem_item_free(&IDL_msp->IDL_mem_handle, \ 531 (byte_p_t)((p_pointee_desc)->Z_values)); \ 532 } 533 534void rpc_ss_xmit_iovec_if_necess 535( 536 idl_boolean attached_pointed_at, 537 IDL_msp_t IDL_msp 538); 539