Print this page
rm code review
12259 CTF shouldn't assume enum size


   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 /*
  28  * Copyright 2018 Joyent, Inc.
  29  */
  30 
  31 #include <ctf_impl.h>
  32 #include <sys/debug.h>
  33 
  34 ssize_t
  35 ctf_get_ctt_size(const ctf_file_t *fp, const ctf_type_t *tp, ssize_t *sizep,
  36     ssize_t *incrementp)
  37 {
  38         ssize_t size, increment;
  39 
  40         if (fp->ctf_version > CTF_VERSION_1 &&
  41             tp->ctt_size == CTF_LSIZE_SENT) {
  42                 size = CTF_TYPE_LSIZE(tp);
  43                 increment = sizeof (ctf_type_t);
  44         } else {
  45                 size = tp->ctt_size;
  46                 increment = sizeof (ctf_stype_t);
  47         }
  48 
  49         if (sizep)
  50                 *sizep = size;
  51         if (incrementp)
  52                 *incrementp = increment;
  53 
  54         return (size);
  55 }
  56 












  57 /*
  58  * Iterate over the members of a STRUCT or UNION.  We pass the name, member
  59  * type, and offset of each member to the specified callback function.
  60  */
  61 int
  62 ctf_member_iter(ctf_file_t *fp, ctf_id_t type, ctf_member_f *func, void *arg)
  63 {
  64         ctf_file_t *ofp = fp;
  65         const ctf_type_t *tp;
  66         ssize_t size, increment;
  67         uint_t kind, n;
  68         int rc;
  69 
  70         if ((type = ctf_type_resolve(fp, type)) == CTF_ERR)
  71                 return (CTF_ERR); /* errno is set for us */
  72 
  73         if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
  74                 return (CTF_ERR); /* errno is set for us */
  75 
  76         (void) ctf_get_ctt_size(fp, tp, &size, &increment);


 464         ssize_t size;
 465         ctf_arinfo_t ar;
 466 
 467         if ((type = ctf_type_resolve(fp, type)) == CTF_ERR)
 468                 return (-1); /* errno is set for us */
 469 
 470         if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
 471                 return (-1); /* errno is set for us */
 472 
 473         switch (LCTF_INFO_KIND(fp, tp->ctt_info)) {
 474         case CTF_K_POINTER:
 475                 return (fp->ctf_dmodel->ctd_pointer);
 476 
 477         case CTF_K_FUNCTION:
 478                 return (0); /* function size is only known by symtab */
 479 
 480         case CTF_K_FORWARD:
 481                 return (0);
 482 
 483         case CTF_K_ENUM:
 484                 return (fp->ctf_dmodel->ctd_int);
 485 
 486         case CTF_K_ARRAY:
 487                 /*
 488                  * Array size is not directly returned by stabs data.  Instead,
 489                  * it defines the element type and requires the user to perform
 490                  * the multiplication.  If ctf_get_ctt_size() returns zero, the
 491                  * current version of ctfconvert does not compute member sizes
 492                  * and we compute the size here on its behalf.
 493                  */
 494                 if ((size = ctf_get_ctt_size(fp, tp, NULL, NULL)) > 0)
 495                         return (size);
 496 
 497                 if (ctf_array_info(fp, type, &ar) == CTF_ERR ||
 498                     (size = ctf_type_size(fp, ar.ctr_contents)) == CTF_ERR)
 499                         return (-1); /* errno is set for us */
 500 
 501                 return (size * ar.ctr_nelems);
 502         case CTF_K_STRUCT:
 503         case CTF_K_UNION:
 504                 /*


 561 
 562                 if (fp->ctf_version == CTF_VERSION_1 ||
 563                     size < CTF_LSTRUCT_THRESH) {
 564                         const ctf_member_t *mp = vmp;
 565                         for (; n != 0; n--, mp++) {
 566                                 ssize_t am = ctf_type_align(fp, mp->ctm_type);
 567                                 align = MAX(align, am);
 568                         }
 569                 } else {
 570                         const ctf_lmember_t *lmp = vmp;
 571                         for (; n != 0; n--, lmp++) {
 572                                 ssize_t am = ctf_type_align(fp, lmp->ctlm_type);
 573                                 align = MAX(align, am);
 574                         }
 575                 }
 576 
 577                 return (align);
 578         }
 579 
 580         case CTF_K_ENUM:
 581                 return (fp->ctf_dmodel->ctd_int);
 582 
 583         default:
 584                 return (ctf_get_ctt_size(fp, tp, NULL, NULL));
 585         }
 586 }
 587 
 588 /*
 589  * Return the kind (CTF_K_* constant) for the specified type ID.
 590  */
 591 int
 592 ctf_type_kind(ctf_file_t *fp, ctf_id_t type)
 593 {
 594         const ctf_type_t *tp;
 595 
 596         if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
 597                 return (CTF_ERR); /* errno is set for us */
 598 
 599         return (LCTF_INFO_KIND(fp, tp->ctt_info));
 600 }
 601 
 602 /*




   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 /*
  28  * Copyright 2020 Joyent, Inc.
  29  */
  30 
  31 #include <ctf_impl.h>
  32 #include <sys/debug.h>
  33 
  34 ssize_t
  35 ctf_get_ctt_size(const ctf_file_t *fp, const ctf_type_t *tp, ssize_t *sizep,
  36     ssize_t *incrementp)
  37 {
  38         ssize_t size, increment;
  39 
  40         if (fp->ctf_version > CTF_VERSION_1 &&
  41             tp->ctt_size == CTF_LSIZE_SENT) {
  42                 size = CTF_TYPE_LSIZE(tp);
  43                 increment = sizeof (ctf_type_t);
  44         } else {
  45                 size = tp->ctt_size;
  46                 increment = sizeof (ctf_stype_t);
  47         }
  48 
  49         if (sizep)
  50                 *sizep = size;
  51         if (incrementp)
  52                 *incrementp = increment;
  53 
  54         return (size);
  55 }
  56 
  57 void
  58 ctf_set_ctt_size(ctf_type_t *tp, ssize_t size)
  59 {
  60         if (size > CTF_MAX_SIZE) {
  61                 tp->ctt_size = CTF_LSIZE_SENT;
  62                 tp->ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);
  63                 tp->ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size);
  64         } else {
  65                 tp->ctt_size = (ushort_t)size;
  66         }
  67 }
  68 
  69 /*
  70  * Iterate over the members of a STRUCT or UNION.  We pass the name, member
  71  * type, and offset of each member to the specified callback function.
  72  */
  73 int
  74 ctf_member_iter(ctf_file_t *fp, ctf_id_t type, ctf_member_f *func, void *arg)
  75 {
  76         ctf_file_t *ofp = fp;
  77         const ctf_type_t *tp;
  78         ssize_t size, increment;
  79         uint_t kind, n;
  80         int rc;
  81 
  82         if ((type = ctf_type_resolve(fp, type)) == CTF_ERR)
  83                 return (CTF_ERR); /* errno is set for us */
  84 
  85         if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
  86                 return (CTF_ERR); /* errno is set for us */
  87 
  88         (void) ctf_get_ctt_size(fp, tp, &size, &increment);


 476         ssize_t size;
 477         ctf_arinfo_t ar;
 478 
 479         if ((type = ctf_type_resolve(fp, type)) == CTF_ERR)
 480                 return (-1); /* errno is set for us */
 481 
 482         if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
 483                 return (-1); /* errno is set for us */
 484 
 485         switch (LCTF_INFO_KIND(fp, tp->ctt_info)) {
 486         case CTF_K_POINTER:
 487                 return (fp->ctf_dmodel->ctd_pointer);
 488 
 489         case CTF_K_FUNCTION:
 490                 return (0); /* function size is only known by symtab */
 491 
 492         case CTF_K_FORWARD:
 493                 return (0);
 494 
 495         case CTF_K_ENUM:
 496                 return (ctf_get_ctt_size(fp, tp, NULL, NULL));
 497 
 498         case CTF_K_ARRAY:
 499                 /*
 500                  * Array size is not directly returned by stabs data.  Instead,
 501                  * it defines the element type and requires the user to perform
 502                  * the multiplication.  If ctf_get_ctt_size() returns zero, the
 503                  * current version of ctfconvert does not compute member sizes
 504                  * and we compute the size here on its behalf.
 505                  */
 506                 if ((size = ctf_get_ctt_size(fp, tp, NULL, NULL)) > 0)
 507                         return (size);
 508 
 509                 if (ctf_array_info(fp, type, &ar) == CTF_ERR ||
 510                     (size = ctf_type_size(fp, ar.ctr_contents)) == CTF_ERR)
 511                         return (-1); /* errno is set for us */
 512 
 513                 return (size * ar.ctr_nelems);
 514         case CTF_K_STRUCT:
 515         case CTF_K_UNION:
 516                 /*


 573 
 574                 if (fp->ctf_version == CTF_VERSION_1 ||
 575                     size < CTF_LSTRUCT_THRESH) {
 576                         const ctf_member_t *mp = vmp;
 577                         for (; n != 0; n--, mp++) {
 578                                 ssize_t am = ctf_type_align(fp, mp->ctm_type);
 579                                 align = MAX(align, am);
 580                         }
 581                 } else {
 582                         const ctf_lmember_t *lmp = vmp;
 583                         for (; n != 0; n--, lmp++) {
 584                                 ssize_t am = ctf_type_align(fp, lmp->ctlm_type);
 585                                 align = MAX(align, am);
 586                         }
 587                 }
 588 
 589                 return (align);
 590         }
 591 
 592         case CTF_K_ENUM:


 593         default:
 594                 return (ctf_get_ctt_size(fp, tp, NULL, NULL));
 595         }
 596 }
 597 
 598 /*
 599  * Return the kind (CTF_K_* constant) for the specified type ID.
 600  */
 601 int
 602 ctf_type_kind(ctf_file_t *fp, ctf_id_t type)
 603 {
 604         const ctf_type_t *tp;
 605 
 606         if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
 607                 return (CTF_ERR); /* errno is set for us */
 608 
 609         return (LCTF_INFO_KIND(fp, tp->ctt_info));
 610 }
 611 
 612 /*