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>

Split Close
Expand all
Collapse all
          --- old/usr/src/common/ctf/ctf_open.c
          +++ new/usr/src/common/ctf/ctf_open.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) 2012, Joyent, Inc.  All rights reserved.
       28 + * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
  29   29   */
  30   30  
  31   31  #include <ctf_impl.h>
  32   32  #include <sys/mman.h>
  33   33  #include <sys/zmod.h>
  34   34  
  35   35  static const ctf_dmodel_t _libctf_models[] = {
  36   36          { "ILP32", CTF_MODEL_ILP32, 4, 1, 2, 4, 4 },
  37   37          { "LP64", CTF_MODEL_LP64, 8, 1, 2, 4, 8 },
  38   38          { NULL, 0, 0, 0, 0, 0, 0 }
↓ open down ↓ 742 lines elided ↑ open up ↑
 781  781  
 782  782          fp->ctf_refcnt = 1;
 783  783          return (fp);
 784  784  
 785  785  bad:
 786  786          ctf_close(fp);
 787  787          return (NULL);
 788  788  }
 789  789  
 790  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 +/*
 791  877   * Close the specified CTF container and free associated data structures.  Note
 792  878   * that ctf_close() is a reference counted operation: if the specified file is
 793  879   * the parent of other active containers, its reference count will be greater
 794  880   * than one and it will be freed later when no active children exist.
 795  881   */
 796  882  void
 797  883  ctf_close(ctf_file_t *fp)
 798  884  {
 799  885          ctf_dtdef_t *dtd, *ntd;
 800  886  
↓ open down ↓ 159 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX