Print this page
12259 CTF shouldn't assume enum size

Split Close
Expand all
Collapse all
          --- old/usr/src/common/ctf/ctf_create.c
          +++ new/usr/src/common/ctf/ctf_create.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  
  23   23  /*
  24   24   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25   25   * Use is subject to license terms.
  26   26   */
  27   27  /*
  28      - * Copyright (c) 2019, Joyent, Inc.
       28 + * Copyright 2020 Joyent, Inc.
  29   29   */
  30   30  
  31   31  #include <sys/sysmacros.h>
  32   32  #include <sys/param.h>
  33   33  #include <sys/mman.h>
  34   34  #include <ctf_impl.h>
  35   35  #include <sys/debug.h>
  36   36  
  37   37  /*
  38   38   * This static string is used as the template for initially populating a
↓ open down ↓ 1200 lines elided ↑ open up ↑
1239 1239          dtd->dtd_data.ctt_size = 0;
1240 1240  
1241 1241          /*
1242 1242           * Always dirty in case we modified a forward.
1243 1243           */
1244 1244          fp->ctf_flags |= LCTF_DIRTY;
1245 1245  
1246 1246          return (type);
1247 1247  }
1248 1248  
     1249 +/*
     1250 + * If size is 0, we use the standard integer size. This is almost always the
     1251 + * case, except for packed enums.
     1252 + */
1249 1253  ctf_id_t
1250      -ctf_add_enum(ctf_file_t *fp, uint_t flag, const char *name)
     1254 +ctf_add_enum(ctf_file_t *fp, uint_t flag, const char *name, size_t size)
1251 1255  {
1252 1256          ctf_hash_t *hp = &fp->ctf_enums;
1253 1257          ctf_helem_t *hep = NULL;
1254 1258          ctf_dtdef_t *dtd = NULL;
1255 1259          ctf_id_t type = CTF_ERR;
1256 1260  
1257 1261          if (name != NULL)
1258 1262                  hep = ctf_hash_lookup(hp, fp, name, strlen(name));
1259 1263  
1260 1264          if (hep != NULL && ctf_type_kind(fp, hep->h_type) == CTF_K_FORWARD) {
↓ open down ↓ 4 lines elided ↑ open up ↑
1265 1269          }
1266 1270  
1267 1271          if (dtd == NULL) {
1268 1272                  type = ctf_add_generic(fp, flag, name, &dtd);
1269 1273                  if (type == CTF_ERR)
1270 1274                          return (CTF_ERR); /* errno is set for us */
1271 1275          }
1272 1276  
1273 1277          VERIFY(type != CTF_ERR);
1274 1278          dtd->dtd_data.ctt_info = CTF_TYPE_INFO(CTF_K_ENUM, flag, 0);
1275      -        dtd->dtd_data.ctt_size = fp->ctf_dmodel->ctd_int;
1276 1279  
     1280 +        if (size == 0) {
     1281 +                dtd->dtd_data.ctt_size = fp->ctf_dmodel->ctd_int;
     1282 +        } else {
     1283 +                if (size > CTF_MAX_SIZE) {
     1284 +                        dtd->dtd_data.ctt_size = CTF_LSIZE_SENT;
     1285 +                        dtd->dtd_data.ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);
     1286 +                        dtd->dtd_data.ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size);
     1287 +                } else
     1288 +                        dtd->dtd_data.ctt_size = size;
     1289 +        }
     1290 +
1277 1291          /*
1278 1292           * Always dirty in case we modified a forward.
1279 1293           */
1280 1294          fp->ctf_flags |= LCTF_DIRTY;
1281 1295  
1282 1296          return (type);
1283 1297  }
1284 1298  
1285 1299  ctf_id_t
1286 1300  ctf_add_forward(ctf_file_t *fp, uint_t flag, const char *name, uint_t kind)
↓ open down ↓ 634 lines elided ↑ open up ↑
1921 1935                          ctf_ref_inc(dst_fp, dmd->dmd_type);
1922 1936                  break;
1923 1937          }
1924 1938  
1925 1939          case CTF_K_ENUM:
1926 1940                  if (dst_type != CTF_ERR && dst_kind != CTF_K_FORWARD) {
1927 1941                          if (ctf_enum_iter(src_fp, src_type, enumcmp, &dst) ||
1928 1942                              ctf_enum_iter(dst_fp, dst_type, enumcmp, &src))
1929 1943                                  return (ctf_set_errno(dst_fp, ECTF_CONFLICT));
1930 1944                  } else {
1931      -                        dst_type = ctf_add_enum(dst_fp, flag, name);
     1945 +                        size_t size = ctf_type_size(src_fp, src_type);
     1946 +                        dst_type = ctf_add_enum(dst_fp, flag, name, size);
1932 1947                          if ((dst.ctb_type = dst_type) == CTF_ERR ||
1933 1948                              ctf_enum_iter(src_fp, src_type, enumadd, &dst))
1934 1949                                  return (CTF_ERR); /* errno is set for us */
1935 1950                  }
1936 1951                  break;
1937 1952  
1938 1953          case CTF_K_FORWARD:
1939 1954                  if (dst_type == CTF_ERR) {
1940 1955                          dst_type = ctf_add_forward(dst_fp,
1941 1956                              flag, name, CTF_K_STRUCT); /* assume STRUCT */
↓ open down ↓ 256 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX