Print this page
12259 CTF shouldn't assume enum size


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  25  * Copyright (c) 2015 Joyent, Inc. All rights reserved.
  26  */
  27 
  28 #include <strings.h>
  29 #include <stdlib.h>
  30 #include <limits.h>
  31 #include <alloca.h>
  32 #include <assert.h>
  33 
  34 #include <dt_decl.h>
  35 #include <dt_parser.h>
  36 #include <dt_module.h>
  37 #include <dt_impl.h>
  38 
  39 static dt_decl_t *
  40 dt_decl_check(dt_decl_t *ddp)
  41 {
  42         if (ddp->dd_kind == CTF_K_UNKNOWN)
  43                 return (ddp); /* nothing to check if the type is not yet set */
  44 
  45         if (ddp->dd_name != NULL && strcmp(ddp->dd_name, "char") == 0 &&


 677         char n[DT_TYPE_NAMELEN];
 678         ctf_file_t *ctfp;
 679         ctf_id_t type;
 680         uint_t flag;
 681 
 682         if (yypcb->pcb_idepth != 0)
 683                 ctfp = yypcb->pcb_hdl->dt_cdefs->dm_ctfp;
 684         else
 685                 ctfp = yypcb->pcb_hdl->dt_ddefs->dm_ctfp;
 686 
 687         if (yypcb->pcb_dstack.ds_next != NULL)
 688                 flag = CTF_ADD_NONROOT;
 689         else
 690                 flag = CTF_ADD_ROOT;
 691 
 692         (void) snprintf(n, sizeof (n), "enum %s", name ? name : "(anon)");
 693 
 694         if (name != NULL && (type = ctf_lookup_by_name(ctfp, n)) != CTF_ERR) {
 695                 if (ctf_enum_iter(ctfp, type, dt_decl_hasmembers, NULL))
 696                         xyerror(D_DECL_TYPERED, "type redeclared: %s\n", n);
 697         } else if ((type = ctf_add_enum(ctfp, flag, name)) == CTF_ERR) {
 698                 xyerror(D_UNKNOWN, "failed to define %s: %s\n",
 699                     n, ctf_errmsg(ctf_errno(ctfp)));
 700         }
 701 
 702         ddp->dd_ctfp = ctfp;
 703         ddp->dd_type = type;
 704 
 705         dt_scope_push(ctfp, type);
 706         return (ddp);
 707 }
 708 
 709 void
 710 dt_decl_enumerator(char *s, dt_node_t *dnp)
 711 {
 712         dt_scope_t *dsp = yypcb->pcb_dstack.ds_next;
 713         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 714 
 715         dt_idnode_t *inp;
 716         dt_ident_t *idp;
 717         char *name;




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  25  * Copyright 2020 Joyent, Inc.
  26  */
  27 
  28 #include <strings.h>
  29 #include <stdlib.h>
  30 #include <limits.h>
  31 #include <alloca.h>
  32 #include <assert.h>
  33 
  34 #include <dt_decl.h>
  35 #include <dt_parser.h>
  36 #include <dt_module.h>
  37 #include <dt_impl.h>
  38 
  39 static dt_decl_t *
  40 dt_decl_check(dt_decl_t *ddp)
  41 {
  42         if (ddp->dd_kind == CTF_K_UNKNOWN)
  43                 return (ddp); /* nothing to check if the type is not yet set */
  44 
  45         if (ddp->dd_name != NULL && strcmp(ddp->dd_name, "char") == 0 &&


 677         char n[DT_TYPE_NAMELEN];
 678         ctf_file_t *ctfp;
 679         ctf_id_t type;
 680         uint_t flag;
 681 
 682         if (yypcb->pcb_idepth != 0)
 683                 ctfp = yypcb->pcb_hdl->dt_cdefs->dm_ctfp;
 684         else
 685                 ctfp = yypcb->pcb_hdl->dt_ddefs->dm_ctfp;
 686 
 687         if (yypcb->pcb_dstack.ds_next != NULL)
 688                 flag = CTF_ADD_NONROOT;
 689         else
 690                 flag = CTF_ADD_ROOT;
 691 
 692         (void) snprintf(n, sizeof (n), "enum %s", name ? name : "(anon)");
 693 
 694         if (name != NULL && (type = ctf_lookup_by_name(ctfp, n)) != CTF_ERR) {
 695                 if (ctf_enum_iter(ctfp, type, dt_decl_hasmembers, NULL))
 696                         xyerror(D_DECL_TYPERED, "type redeclared: %s\n", n);
 697         } else if ((type = ctf_add_enum(ctfp, flag, name, 0)) == CTF_ERR) {
 698                 xyerror(D_UNKNOWN, "failed to define %s: %s\n",
 699                     n, ctf_errmsg(ctf_errno(ctfp)));
 700         }
 701 
 702         ddp->dd_ctfp = ctfp;
 703         ddp->dd_type = type;
 704 
 705         dt_scope_push(ctfp, type);
 706         return (ddp);
 707 }
 708 
 709 void
 710 dt_decl_enumerator(char *s, dt_node_t *dnp)
 711 {
 712         dt_scope_t *dsp = yypcb->pcb_dstack.ds_next;
 713         dtrace_hdl_t *dtp = yypcb->pcb_hdl;
 714 
 715         dt_idnode_t *inp;
 716         dt_ident_t *idp;
 717         char *name;