d0e518695adc90b82233b99af7dffbb3d3f92c00amw * CDDL HEADER START
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * The contents of this file are subject to the terms of the
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Common Development and Distribution License (the "License").
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * You may not use this file except in compliance with the License.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * See the License for the specific language governing permissions
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * and limitations under the License.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * When distributing Covered Code, include this CDDL HEADER in each
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * If applicable, add the following below this CDDL HEADER, with the
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * fields enclosed by brackets "[]" replaced with your own identifying
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * information: Portions Copyright [yyyy] [name of copyright owner]
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * CDDL HEADER END
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Use is subject to license terms.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#pragma ident "%Z%%M% %I% %E% SMI"
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void type_ident_decl(ndr_typeinfo_t *, char *, size_t, char *);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void type_ident_decl1(struct tup *, char *, size_t, char *);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void analyze_typeinfo_list(void);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void analyze_typeinfo_aggregate_finish(ndr_typeinfo_t *);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void analyze_member(ndr_node_t *, ndr_member_t *, unsigned long *, int);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void seed_basic_types(void);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void seed_construct_types(void);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic ndr_typeinfo_t *find_typeinfo_by_name(ndr_node_t *);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void determine_advice(ndr_advice_t *, ndr_node_t *);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic ndr_node_t *find_advice(ndr_node_t *advice_list, int label);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw p = "struct";
d0e518695adc90b82233b99af7dffbb3d3f92c00amw p = "union";
d0e518695adc90b82233b99af7dffbb3d3f92c00amw p = "typedef";
d0e518695adc90b82233b99af7dffbb3d3f92c00amw (void) printf("%s %s {\n", p, ti->type_name->n_sym->name);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw (void) printf("} fsiz=%d vsiz=%d algn=%d comp=%d ptrs=%d\n",
d0e518695adc90b82233b99af7dffbb3d3f92c00amwtype_extern_suffix(ndr_typeinfo_t *tsti, char *funcbuf, size_t buflen)
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amwtype_ident_decl1(struct tup *tup, char *funcbuf, size_t buflen, char *ident)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw "struct ", ti->type_name->n_sym->name, *fb ? " " : "", fb);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw "union ", ti->type_name->n_sym->name, *fb ? " " : "", fb);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw type_ident_decl1(tup->up, funcbuf+1, buflen - 1, ident);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw *p++ = '(';
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (*p == '*') {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw "%s[NDR_ANYSIZE_DIM]", p);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw *p++ = '(';
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (*p == '*') {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw (void) snprintf(funcbuf, buflen, "%s[NDR_STRING_DIM]", p);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw compile_error("unknown type or keyword <%d>", ti->type_op);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amwtype_ident_decl(ndr_typeinfo_t *tsti, char *funcbuf, size_t buflen, char *ident)
d0e518695adc90b82233b99af7dffbb3d3f92c00amwtype_null_decl(ndr_typeinfo_t *tsti, char *funcbuf, size_t buflen)
d0e518695adc90b82233b99af7dffbb3d3f92c00amwtype_name_decl(ndr_typeinfo_t *tsti, char *funcbuf, size_t buflen, char *name)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw int n = 0;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw for (i = 0; i < N_ADVICE; i++) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (n++ == 0)
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Snarf the advice.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw determine_advice(&ti->advice, ti->definition->n_c_advice);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Convert the members to table.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Determine layout metrics along the way.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* Align offset to determine overall size */
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Snarf the advice. Only recognize [operation()] for
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * struct definitions.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw determine_advice(&ti->advice, ti->definition->n_c_advice);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Convert the members from list to table.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Determine layout metrics along the way.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (!ti->advice.a_operation /* no var-size in op param */ &&
d0e518695adc90b82233b99af7dffbb3d3f92c00amw i == ti->n_member-1) /* only last mem may be var-size */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw analyze_typeinfo_aggregate_finish(ti); /* align,complete,ptrs,etc */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* Align offset to determine overall size */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* If last member is var-sized, so is this struct */
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Snarf the advice. None supported for union definitions.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Only [switch_is()] supported for union instances.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw determine_advice(&ti->advice, ti->definition->n_c_advice);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Convert the members from list to table.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Determine layout metrics along the way.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw analyze_typeinfo_aggregate_finish(ti); /* align,complete,ptrs,etc */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* align size to determine overall size */
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Set line_number for error reporting (so we know where to look)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Simple parts of member
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * The node list for the declarator is in outside-to-inside
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * order. It is also decorated with the LP nodes for
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * precedence, which are in our way at this point.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * These two loops reverse the list, which is easier
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * to analyze. For example, the declaration:
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * ulong * (id[100]);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * will have the node list (=> indicates n_d_descend):
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * ulong => STAR => LP => LB[100] => id
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * and the conversion will result in type info (=> indicates
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * type_down):
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * id => LB[100] => STAR => ulong
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * which is closer to how you would pronounce the declaration:
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * id is an array size 100 of pointers to ulong.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* first pass -- turn the list into a table */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw break; /* done */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw continue; /* ignore precedence nodes */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* second pass -- turn the table into push-back list */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw for (i = n_decl_ops; i-- > 0; ) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * bind_typeinfo() reuses (interns) typeinfo's to
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * make later code generation easier. It will report
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * some errors.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* bind the member to its type info */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw type_down->is_referenced = 1; /* we handle first-level indirection */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Now, apply the type info to the member layout metrics.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* alignment */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [case(x)] TYPE xxx;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [default] TYPE xxx;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * These only make sense within unions.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw int n = 0;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (n == 0)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw else if (n > 1)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [operation(x)] TYPE foo;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [interface(x)] TYPE foo;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [uuid(x)] TYPE foo;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * The [operation()] advice may only appear on a struct to
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * indicate that the structure is a top-most (parameter)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * structure, and the opcode associated with the parameters.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [switch_is(x)] union foo xxx;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow [switch_is] on anything which is not a union.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (mem->advice.a_switch_is && type_down->type_op != UNION_KW) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [size_is(x)] TYPE * ptr;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [size_is(x)] TYPE arr[];
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow [size_is()] on anything other than pointer and
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * variable length array.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [string] char * ptr_string;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow [string] on anything else. The determination
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * of size (for the outer header) on anything else is
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * impossible.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (mem->advice.a_string && type_down->type_op != STAR) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw type_down->type_dim == 0) { /* var-length array of some sort */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw int n = 0;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Requires [size_is()] directive
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * [size_is(x)] TYPE array[]
d0e518695adc90b82233b99af7dffbb3d3f92c00amw else if (n > 1)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Nested unions and struct members, other than the last one,
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * cannot contain variable sized members.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (type_down->size_variable_part && !(allow & ALLOW_VARSIZE)) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow unions in operations (i.e. [operation()] struct ...),
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * The switch_is() value is not reliably available. DCE/RPC
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * automatically synthesizes an encapsulated union for
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * these situations, which we have to do by hand:
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * struct { long switch_value; union foo x; } synth;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * We also can not allow unions within unions because
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * there is no way to pass the separate [switch_is(x)] selector.
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amw fatal_error("seed_construct unknown %d\n", ti->type_op);
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amw compile_error("bind_type internal error op=%d", ti->type_op);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * union foo *ptrfoo;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * There is no way to pass the selector (switch_is)in
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (ti->type_op == STAR && ti->type_down->type_op == UNION_KW) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Disallow
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * union foo fooarr[n];
d0e518695adc90b82233b99af7dffbb3d3f92c00amw * Each element needs a distinct selector
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if (ti->type_op == LB && ti->type_down->type_op == UNION_KW) {
d0e518695adc90b82233b99af7dffbb3d3f92c00amw compile_error("unknown type %s", typename->n_sym->name);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* fake BASIC_TYPE */
d0e518695adc90b82233b99af7dffbb3d3f92c00amwstatic void
d0e518695adc90b82233b99af7dffbb3d3f92c00amwdetermine_advice(ndr_advice_t *advice, ndr_node_t *advice_list)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* alias for basic types */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_transmit_as = find_advice(advice_list, TRANSMIT_AS_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* arg used for size, union, or generic purpose */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* operation parameter in/out stuff */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_operation = find_advice(advice_list, OPERATION_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* size stuff */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_size_is = find_advice(advice_list, SIZE_IS_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_length_is = find_advice(advice_list, LENGTH_IS_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* union stuff */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_default = find_advice(advice_list, DEFAULT_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_switch_is = find_advice(advice_list, SWITCH_IS_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw /* interface stuff */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_interface = find_advice(advice_list, INTERFACE_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_no_reorder = find_advice(advice_list, _NO_REORDER_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw advice->a_reference = find_advice(advice_list, REFERENCE_KW);
d0e518695adc90b82233b99af7dffbb3d3f92c00amw for (np = member_np->n_m_decl; np; np = np->n_d_descend)