Print this page
10812 ctf tools shouldn't add blank labels
10813 ctf symbol mapping needs work
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>


   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 (c) 2015, Joyent, Inc.
  29  */
  30 
  31 #include <sys/sysmacros.h>
  32 #include <sys/param.h>
  33 #include <sys/mman.h>
  34 #include <ctf_impl.h>
  35 #include <sys/debug.h>
  36 
  37 /*
  38  * This static string is used as the template for initially populating a
  39  * dynamic container's string table.  We always store \0 in the first byte,
  40  * and we use the generic string "PARENT" to mark this container's parent
  41  * if one is associated with the container using ctf_import().
  42  */
  43 static const char _CTF_STRTAB_TEMPLATE[] = "\0PARENT";
  44 
  45 /*
  46  * To create an empty CTF container, we just declare a zeroed header and call
  47  * ctf_bufopen() on it.  If ctf_bufopen succeeds, we mark the new container r/w
  48  * and initialize the dynamic members.  We set dtstrlen to 1 to reserve the


2109 
2110         fpd = fp;
2111         if (type != 0 && ctf_lookup_by_id(&fpd, type) == NULL)
2112                 return (CTF_ERR); /* errno is set for us */
2113 
2114         if (type != 0 && (fp->ctf_flags & LCTF_CHILD) &&
2115             CTF_TYPE_ISPARENT(type))
2116                 return (ctf_set_errno(fp, ECTF_NOPARENT));
2117 
2118         if (ctf_dld_lookup(fp, name) != NULL)
2119                 return (ctf_set_errno(fp, ECTF_LABELEXISTS));
2120 
2121         if ((dld = ctf_alloc(sizeof (ctf_dldef_t))) == NULL)
2122                 return (ctf_set_errno(fp, EAGAIN));
2123 
2124         if ((dld->dld_name = ctf_strdup(name)) == NULL) {
2125                 ctf_free(dld, sizeof (ctf_dldef_t));
2126                 return (ctf_set_errno(fp, EAGAIN));
2127         }
2128 

2129         dld->dld_type = type;
2130         fp->ctf_dtstrlen += strlen(name) + 1;
2131         ctf_dld_insert(fp, dld, position);
2132         fp->ctf_flags |= LCTF_DIRTY;
2133 
2134         return (0);
2135 }
2136 
2137 /*
2138  * Update the size of a structure or union. Note that we don't allow this to
2139  * shrink the size of a struct or union, only to increase it. This is useful for
2140  * cases when you have a structure whose actual size is larger than the sum of
2141  * its members due to padding for natural alignment.
2142  */
2143 int
2144 ctf_set_size(ctf_file_t *fp, ctf_id_t id, const ulong_t newsz)
2145 {
2146         ctf_dtdef_t *dtd = ctf_dtd_lookup(fp, id);
2147         uint_t kind;
2148         size_t oldsz;




   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 (c) 2019, Joyent, Inc.
  29  */
  30 
  31 #include <sys/sysmacros.h>
  32 #include <sys/param.h>
  33 #include <sys/mman.h>
  34 #include <ctf_impl.h>
  35 #include <sys/debug.h>
  36 
  37 /*
  38  * This static string is used as the template for initially populating a
  39  * dynamic container's string table.  We always store \0 in the first byte,
  40  * and we use the generic string "PARENT" to mark this container's parent
  41  * if one is associated with the container using ctf_import().
  42  */
  43 static const char _CTF_STRTAB_TEMPLATE[] = "\0PARENT";
  44 
  45 /*
  46  * To create an empty CTF container, we just declare a zeroed header and call
  47  * ctf_bufopen() on it.  If ctf_bufopen succeeds, we mark the new container r/w
  48  * and initialize the dynamic members.  We set dtstrlen to 1 to reserve the


2109 
2110         fpd = fp;
2111         if (type != 0 && ctf_lookup_by_id(&fpd, type) == NULL)
2112                 return (CTF_ERR); /* errno is set for us */
2113 
2114         if (type != 0 && (fp->ctf_flags & LCTF_CHILD) &&
2115             CTF_TYPE_ISPARENT(type))
2116                 return (ctf_set_errno(fp, ECTF_NOPARENT));
2117 
2118         if (ctf_dld_lookup(fp, name) != NULL)
2119                 return (ctf_set_errno(fp, ECTF_LABELEXISTS));
2120 
2121         if ((dld = ctf_alloc(sizeof (ctf_dldef_t))) == NULL)
2122                 return (ctf_set_errno(fp, EAGAIN));
2123 
2124         if ((dld->dld_name = ctf_strdup(name)) == NULL) {
2125                 ctf_free(dld, sizeof (ctf_dldef_t));
2126                 return (ctf_set_errno(fp, EAGAIN));
2127         }
2128 
2129         ctf_dprintf("adding label %s, %ld\n", name, type);
2130         dld->dld_type = type;
2131         fp->ctf_dtstrlen += strlen(name) + 1;
2132         ctf_dld_insert(fp, dld, position);
2133         fp->ctf_flags |= LCTF_DIRTY;
2134 
2135         return (0);
2136 }
2137 
2138 /*
2139  * Update the size of a structure or union. Note that we don't allow this to
2140  * shrink the size of a struct or union, only to increase it. This is useful for
2141  * cases when you have a structure whose actual size is larger than the sum of
2142  * its members due to padding for natural alignment.
2143  */
2144 int
2145 ctf_set_size(ctf_file_t *fp, ctf_id_t id, const ulong_t newsz)
2146 {
2147         ctf_dtdef_t *dtd = ctf_dtd_lookup(fp, id);
2148         uint_t kind;
2149         size_t oldsz;