diff options
author | rpaulo <rpaulo@FreeBSD.org> | 2014-06-26 23:21:11 +0000 |
---|---|---|
committer | rpaulo <rpaulo@FreeBSD.org> | 2014-06-26 23:21:11 +0000 |
commit | 8c0e49065f210b6d5f3f7eae268cca2d60c727ba (patch) | |
tree | 6a80286a487fba6384a58aad25d078d5681e0abf /cddl/contrib/opensolaris/common | |
parent | b14d31acfe746e87bae81feaeeb78f15dc35ed86 (diff) | |
parent | 7d6b0e1d597adba3bf641fc23d3647b6db656985 (diff) | |
download | FreeBSD-src-8c0e49065f210b6d5f3f7eae268cca2d60c727ba.zip FreeBSD-src-8c0e49065f210b6d5f3f7eae268cca2d60c727ba.tar.gz |
MFV illumos
4474 DTrace Userland CTF Support
4475 DTrace userland Keyword
4476 DTrace tests should be better citizens
4479 pid provider types
4480 dof emulation is missing checks
MFC after: 2 weeks
Diffstat (limited to 'cddl/contrib/opensolaris/common')
-rw-r--r-- | cddl/contrib/opensolaris/common/ctf/ctf_open.c | 88 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/common/ctf/ctf_types.c | 41 |
2 files changed, 120 insertions, 9 deletions
diff --git a/cddl/contrib/opensolaris/common/ctf/ctf_open.c b/cddl/contrib/opensolaris/common/ctf/ctf_open.c index 2148389..001cf5c 100644 --- a/cddl/contrib/opensolaris/common/ctf/ctf_open.c +++ b/cddl/contrib/opensolaris/common/ctf/ctf_open.c @@ -25,7 +25,7 @@ * Use is subject to license terms. */ /* - * Copyright (c) 2012, Joyent, Inc. All rights reserved. + * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ #include <ctf_impl.h> @@ -788,6 +788,92 @@ bad: } /* + * Dupliate a ctf_file_t and its underlying section information into a new + * container. This works by copying the three ctf_sect_t's of the original + * container if they exist and passing those into ctf_bufopen. To copy those, we + * mmap anonymous memory with ctf_data_alloc and bcopy the data across. It's not + * the cheapest thing, but it's what we've got. + */ +ctf_file_t * +ctf_dup(ctf_file_t *ofp) +{ + ctf_file_t *fp; + ctf_sect_t ctfsect, symsect, strsect; + ctf_sect_t *ctp, *symp, *strp; + void *cbuf, *symbuf, *strbuf; + int err; + + cbuf = symbuf = strbuf = NULL; + /* + * The ctfsect isn't allowed to not exist, but the symbol and string + * section might not. We only need to copy the data of the section, not + * the name, as ctf_bufopen will take care of that. + */ + bcopy(&ofp->ctf_data, &ctfsect, sizeof (ctf_sect_t)); + cbuf = ctf_data_alloc(ctfsect.cts_size); + if (cbuf == NULL) { + (void) ctf_set_errno(ofp, ECTF_MMAP); + return (NULL); + } + + bcopy(ctfsect.cts_data, cbuf, ctfsect.cts_size); + ctf_data_protect(cbuf, ctfsect.cts_size); + ctfsect.cts_data = cbuf; + ctfsect.cts_offset = 0; + ctp = &ctfsect; + + if (ofp->ctf_symtab.cts_data != NULL) { + bcopy(&ofp->ctf_symtab, &symsect, sizeof (ctf_sect_t)); + symbuf = ctf_data_alloc(symsect.cts_size); + if (symbuf == NULL) { + (void) ctf_set_errno(ofp, ECTF_MMAP); + goto err; + } + bcopy(symsect.cts_data, symbuf, symsect.cts_size); + ctf_data_protect(symbuf, symsect.cts_size); + symsect.cts_data = symbuf; + symsect.cts_offset = 0; + symp = &symsect; + } else { + symp = NULL; + } + + if (ofp->ctf_strtab.cts_data != NULL) { + bcopy(&ofp->ctf_strtab, &strsect, sizeof (ctf_sect_t)); + strbuf = ctf_data_alloc(strsect.cts_size); + if (strbuf == NULL) { + (void) ctf_set_errno(ofp, ECTF_MMAP); + goto err; + } + bcopy(strsect.cts_data, strbuf, strsect.cts_size); + ctf_data_protect(strbuf, strsect.cts_size); + strsect.cts_data = strbuf; + strsect.cts_offset = 0; + strp = &strsect; + } else { + strp = NULL; + } + + fp = ctf_bufopen(ctp, symp, strp, &err); + if (fp == NULL) { + (void) ctf_set_errno(ofp, err); + goto err; + } + + fp->ctf_flags |= LCTF_MMAP; + + return (fp); + +err: + ctf_data_free(cbuf, ctfsect.cts_size); + if (symbuf != NULL) + ctf_data_free(symbuf, symsect.cts_size); + if (strbuf != NULL) + ctf_data_free(strbuf, strsect.cts_size); + return (NULL); +} + +/* * Close the specified CTF container and free associated data structures. Note * that ctf_close() is a reference counted operation: if the specified file is * the parent of other active containers, its reference count will be greater diff --git a/cddl/contrib/opensolaris/common/ctf/ctf_types.c b/cddl/contrib/opensolaris/common/ctf/ctf_types.c index 290c518..ab1b9ff 100644 --- a/cddl/contrib/opensolaris/common/ctf/ctf_types.c +++ b/cddl/contrib/opensolaris/common/ctf/ctf_types.c @@ -25,8 +25,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <ctf_impl.h> ssize_t @@ -199,8 +197,9 @@ ctf_type_resolve(ctf_file_t *fp, ctf_id_t type) * Lookup the given type ID and print a string name for it into buf. Return * the actual number of bytes (not including \0) needed to format the name. */ -ssize_t -ctf_type_lname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) +static ssize_t +ctf_type_qlname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len, + const char *qname) { ctf_decl_t cd; ctf_decl_node_t *cdp; @@ -255,6 +254,8 @@ ctf_type_lname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) case CTF_K_INTEGER: case CTF_K_FLOAT: case CTF_K_TYPEDEF: + if (qname != NULL) + ctf_decl_sprintf(&cd, "%s`", qname); ctf_decl_sprintf(&cd, "%s", name); break; case CTF_K_POINTER: @@ -268,13 +269,22 @@ ctf_type_lname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) break; case CTF_K_STRUCT: case CTF_K_FORWARD: - ctf_decl_sprintf(&cd, "struct %s", name); + ctf_decl_sprintf(&cd, "struct "); + if (qname != NULL) + ctf_decl_sprintf(&cd, "%s`", qname); + ctf_decl_sprintf(&cd, "%s", name); break; case CTF_K_UNION: - ctf_decl_sprintf(&cd, "union %s", name); + ctf_decl_sprintf(&cd, "union "); + if (qname != NULL) + ctf_decl_sprintf(&cd, "%s`", qname); + ctf_decl_sprintf(&cd, "%s", name); break; case CTF_K_ENUM: - ctf_decl_sprintf(&cd, "enum %s", name); + ctf_decl_sprintf(&cd, "enum "); + if (qname != NULL) + ctf_decl_sprintf(&cd, "%s`", qname); + ctf_decl_sprintf(&cd, "%s", name); break; case CTF_K_VOLATILE: ctf_decl_sprintf(&cd, "volatile"); @@ -301,6 +311,12 @@ ctf_type_lname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) return (cd.cd_len); } +ssize_t +ctf_type_lname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) +{ + return (ctf_type_qlname(fp, type, buf, len, NULL)); +} + /* * Lookup the given type ID and print a string name for it into buf. If buf * is too small, return NULL: the ECTF_NAMELEN error is set on 'fp' for us. @@ -308,10 +324,19 @@ ctf_type_lname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) char * ctf_type_name(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) { - ssize_t rv = ctf_type_lname(fp, type, buf, len); + ssize_t rv = ctf_type_qlname(fp, type, buf, len, NULL); + return (rv >= 0 && rv < len ? buf : NULL); +} + +char * +ctf_type_qname(ctf_file_t *fp, ctf_id_t type, char *buf, size_t len, + const char *qname) +{ + ssize_t rv = ctf_type_qlname(fp, type, buf, len, qname); return (rv >= 0 && rv < len ? buf : NULL); } + /* * Resolve the type down to a base type node, and then return the size * of the type storage in bytes. |