Print this page
4474 DTrace Userland CTF Support
4475 DTrace userland Keyword
4476 DTrace tests should be better citizens
4479 pid provider types
4480 dof emulation missing checks
Reviewed by: Bryan Cantrill <bryan@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) 2012, Joyent, Inc.  All rights reserved.
  29  */
  30 
  31 #include <ctf_impl.h>
  32 #include <sys/mman.h>
  33 #include <sys/zmod.h>
  34 
  35 static const ctf_dmodel_t _libctf_models[] = {
  36         { "ILP32", CTF_MODEL_ILP32, 4, 1, 2, 4, 4 },
  37         { "LP64", CTF_MODEL_LP64, 8, 1, 2, 4, 8 },
  38         { NULL, 0, 0, 0, 0, 0, 0 }
  39 };
  40 
  41 const char _CTF_SECTION[] = ".SUNW_ctf";
  42 const char _CTF_NULLSTR[] = "";
  43 
  44 int _libctf_version = CTF_VERSION;      /* library client version */
  45 int _libctf_debug = 0;                  /* debugging messages enabled */
  46 
  47 static ushort_t
  48 get_kind_v1(ushort_t info)


 771         fp->ctf_lookups[4].ctl_len = 0;
 772         fp->ctf_lookups[4].ctl_hash = NULL;
 773 
 774         if (symsect != NULL) {
 775                 if (symsect->cts_entsize == sizeof (Elf64_Sym))
 776                         (void) ctf_setmodel(fp, CTF_MODEL_LP64);
 777                 else
 778                         (void) ctf_setmodel(fp, CTF_MODEL_ILP32);
 779         } else
 780                 (void) ctf_setmodel(fp, CTF_MODEL_NATIVE);
 781 
 782         fp->ctf_refcnt = 1;
 783         return (fp);
 784 
 785 bad:
 786         ctf_close(fp);
 787         return (NULL);
 788 }
 789 
 790 /*






















































































 791  * Close the specified CTF container and free associated data structures.  Note
 792  * that ctf_close() is a reference counted operation: if the specified file is
 793  * the parent of other active containers, its reference count will be greater
 794  * than one and it will be freed later when no active children exist.
 795  */
 796 void
 797 ctf_close(ctf_file_t *fp)
 798 {
 799         ctf_dtdef_t *dtd, *ntd;
 800 
 801         if (fp == NULL)
 802                 return; /* allow ctf_close(NULL) to simplify caller code */
 803 
 804         ctf_dprintf("ctf_close(%p) refcnt=%u\n", (void *)fp, fp->ctf_refcnt);
 805 
 806         if (fp->ctf_refcnt > 1) {
 807                 fp->ctf_refcnt--;
 808                 return;
 809         }
 810 




   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) 2013, Joyent, Inc.  All rights reserved.
  29  */
  30 
  31 #include <ctf_impl.h>
  32 #include <sys/mman.h>
  33 #include <sys/zmod.h>
  34 
  35 static const ctf_dmodel_t _libctf_models[] = {
  36         { "ILP32", CTF_MODEL_ILP32, 4, 1, 2, 4, 4 },
  37         { "LP64", CTF_MODEL_LP64, 8, 1, 2, 4, 8 },
  38         { NULL, 0, 0, 0, 0, 0, 0 }
  39 };
  40 
  41 const char _CTF_SECTION[] = ".SUNW_ctf";
  42 const char _CTF_NULLSTR[] = "";
  43 
  44 int _libctf_version = CTF_VERSION;      /* library client version */
  45 int _libctf_debug = 0;                  /* debugging messages enabled */
  46 
  47 static ushort_t
  48 get_kind_v1(ushort_t info)


 771         fp->ctf_lookups[4].ctl_len = 0;
 772         fp->ctf_lookups[4].ctl_hash = NULL;
 773 
 774         if (symsect != NULL) {
 775                 if (symsect->cts_entsize == sizeof (Elf64_Sym))
 776                         (void) ctf_setmodel(fp, CTF_MODEL_LP64);
 777                 else
 778                         (void) ctf_setmodel(fp, CTF_MODEL_ILP32);
 779         } else
 780                 (void) ctf_setmodel(fp, CTF_MODEL_NATIVE);
 781 
 782         fp->ctf_refcnt = 1;
 783         return (fp);
 784 
 785 bad:
 786         ctf_close(fp);
 787         return (NULL);
 788 }
 789 
 790 /*
 791  * Dupliate a ctf_file_t and its underlying section information into a new
 792  * container. This works by copying the three ctf_sect_t's of the original
 793  * container if they exist and passing those into ctf_bufopen. To copy those, we
 794  * mmap anonymous memory with ctf_data_alloc and bcopy the data across. It's not
 795  * the cheapest thing, but it's what we've got.
 796  */
 797 ctf_file_t *
 798 ctf_dup(ctf_file_t *ofp)
 799 {
 800         ctf_file_t *fp;
 801         ctf_sect_t ctfsect, symsect, strsect;
 802         ctf_sect_t *ctp, *symp, *strp;
 803         void *cbuf, *symbuf, *strbuf;
 804         int err;
 805 
 806         cbuf = symbuf = strbuf = NULL;
 807         /*
 808          * The ctfsect isn't allowed to not exist, but the symbol and string
 809          * section might not. We only need to copy the data of the section, not
 810          * the name, as ctf_bufopen will take care of that.
 811          */
 812         bcopy(&ofp->ctf_data, &ctfsect, sizeof (ctf_sect_t));
 813         cbuf = ctf_data_alloc(ctfsect.cts_size);
 814         if (cbuf == NULL) {
 815                 (void) ctf_set_errno(ofp, ECTF_MMAP);
 816                 return (NULL);
 817         }
 818 
 819         bcopy(ctfsect.cts_data, cbuf, ctfsect.cts_size);
 820         ctf_data_protect(cbuf, ctfsect.cts_size);
 821         ctfsect.cts_data = cbuf;
 822         ctfsect.cts_offset = 0;
 823         ctp = &ctfsect;
 824 
 825         if (ofp->ctf_symtab.cts_data != NULL) {
 826                 bcopy(&ofp->ctf_symtab, &symsect, sizeof (ctf_sect_t));
 827                 symbuf = ctf_data_alloc(symsect.cts_size);
 828                 if (symbuf == NULL) {
 829                         (void) ctf_set_errno(ofp, ECTF_MMAP);
 830                         goto err;
 831                 }
 832                 bcopy(symsect.cts_data, symbuf, symsect.cts_size);
 833                 ctf_data_protect(symbuf, symsect.cts_size);
 834                 symsect.cts_data = symbuf;
 835                 symsect.cts_offset = 0;
 836                 symp = &symsect;
 837         } else {
 838                 symp = NULL;
 839         }
 840 
 841         if (ofp->ctf_strtab.cts_data != NULL) {
 842                 bcopy(&ofp->ctf_strtab, &strsect, sizeof (ctf_sect_t));
 843                 strbuf = ctf_data_alloc(strsect.cts_size);
 844                 if (strbuf == NULL) {
 845                         (void) ctf_set_errno(ofp, ECTF_MMAP);
 846                         goto err;
 847                 }
 848                 bcopy(strsect.cts_data, strbuf, strsect.cts_size);
 849                 ctf_data_protect(strbuf, strsect.cts_size);
 850                 strsect.cts_data = strbuf;
 851                 strsect.cts_offset = 0;
 852                 strp = &strsect;
 853         } else {
 854                 strp = NULL;
 855         }
 856 
 857         fp = ctf_bufopen(ctp, symp, strp, &err);
 858         if (fp == NULL) {
 859                 (void) ctf_set_errno(ofp, err);
 860                 goto err;
 861         }
 862 
 863         fp->ctf_flags |= LCTF_MMAP;
 864 
 865         return (fp);
 866 
 867 err:
 868         ctf_data_free(cbuf, ctfsect.cts_size);
 869         if (symbuf != NULL)
 870                 ctf_data_free(symbuf, symsect.cts_size);
 871         if (strbuf != NULL)
 872                 ctf_data_free(strbuf, strsect.cts_size);
 873         return (NULL);
 874 }
 875 
 876 /*
 877  * Close the specified CTF container and free associated data structures.  Note
 878  * that ctf_close() is a reference counted operation: if the specified file is
 879  * the parent of other active containers, its reference count will be greater
 880  * than one and it will be freed later when no active children exist.
 881  */
 882 void
 883 ctf_close(ctf_file_t *fp)
 884 {
 885         ctf_dtdef_t *dtd, *ntd;
 886 
 887         if (fp == NULL)
 888                 return; /* allow ctf_close(NULL) to simplify caller code */
 889 
 890         ctf_dprintf("ctf_close(%p) refcnt=%u\n", (void *)fp, fp->ctf_refcnt);
 891 
 892         if (fp->ctf_refcnt > 1) {
 893                 fp->ctf_refcnt--;
 894                 return;
 895         }
 896