17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22e4586ebfSmws
237c478bd9Sstevel@tonic-gate /*
24e4586ebfSmws * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
286ef284f1SJohn Levon /*
296ef284f1SJohn Levon * Copyright 2019, Joyent, Inc.
306ef284f1SJohn Levon */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <ctf_impl.h>
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * Compare the given input string and length against a table of known C storage
37e4586ebfSmws * qualifier keywords. We just ignore these in ctf_lookup_by_name, below. To
38e4586ebfSmws * do this quickly, we use a pre-computed Perfect Hash Function similar to the
39e4586ebfSmws * technique originally described in the classic paper:
40e4586ebfSmws *
41e4586ebfSmws * R.J. Cichelli, "Minimal Perfect Hash Functions Made Simple",
42e4586ebfSmws * Communications of the ACM, Volume 23, Issue 1, January 1980, pp. 17-19.
43e4586ebfSmws *
44e4586ebfSmws * For an input string S of length N, we use hash H = S[N - 1] + N - 105, which
45e4586ebfSmws * for the current set of qualifiers yields a unique H in the range [0 .. 20].
46e4586ebfSmws * The hash can be modified when the keyword set changes as necessary. We also
47e4586ebfSmws * store the length of each keyword and check it prior to the final strcmp().
487c478bd9Sstevel@tonic-gate */
497c478bd9Sstevel@tonic-gate static int
isqualifier(const char * s,size_t len)507c478bd9Sstevel@tonic-gate isqualifier(const char *s, size_t len)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate static const struct qual {
537c478bd9Sstevel@tonic-gate const char *q_name;
547c478bd9Sstevel@tonic-gate size_t q_len;
55e4586ebfSmws } qhash[] = {
56e4586ebfSmws { "static", 6 }, { "", 0 }, { "", 0 }, { "", 0 },
57e4586ebfSmws { "volatile", 8 }, { "", 0 }, { "", 0 }, { "", 0 }, { "", 0 },
58e4586ebfSmws { "", 0 }, { "auto", 4 }, { "extern", 6 }, { "", 0 }, { "", 0 },
59e4586ebfSmws { "", 0 }, { "", 0 }, { "const", 5 }, { "register", 8 },
60e4586ebfSmws { "", 0 }, { "restrict", 8 }, { "_Restrict", 9 }
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate
63e4586ebfSmws int h = s[len - 1] + (int)len - 105;
64e4586ebfSmws const struct qual *qp = &qhash[h];
657c478bd9Sstevel@tonic-gate
66e4586ebfSmws return (h >= 0 && h < sizeof (qhash) / sizeof (qhash[0]) &&
67e4586ebfSmws len == qp->q_len && strncmp(qp->q_name, s, qp->q_len) == 0);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate * Attempt to convert the given C type name into the corresponding CTF type ID.
727c478bd9Sstevel@tonic-gate * It is not possible to do complete and proper conversion of type names
737c478bd9Sstevel@tonic-gate * without implementing a more full-fledged parser, which is necessary to
747c478bd9Sstevel@tonic-gate * handle things like types that are function pointers to functions that
757c478bd9Sstevel@tonic-gate * have arguments that are function pointers, and fun stuff like that.
767c478bd9Sstevel@tonic-gate * Instead, this function implements a very simple conversion algorithm that
777c478bd9Sstevel@tonic-gate * finds the things that we actually care about: structs, unions, enums,
787c478bd9Sstevel@tonic-gate * integers, floats, typedefs, and pointers to any of these named types.
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate ctf_id_t
ctf_lookup_by_name(ctf_file_t * fp,const char * name)817c478bd9Sstevel@tonic-gate ctf_lookup_by_name(ctf_file_t *fp, const char *name)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate static const char delimiters[] = " \t\n\r\v\f*";
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate const ctf_lookup_t *lp;
867c478bd9Sstevel@tonic-gate const ctf_helem_t *hp;
877c478bd9Sstevel@tonic-gate const char *p, *q, *end;
887c478bd9Sstevel@tonic-gate ctf_id_t type = 0;
897c478bd9Sstevel@tonic-gate ctf_id_t ntype, ptype;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate if (name == NULL)
927c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, EINVAL));
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate for (p = name, end = name + strlen(name); *p != '\0'; p = q) {
957c478bd9Sstevel@tonic-gate while (isspace(*p))
967c478bd9Sstevel@tonic-gate p++; /* skip leading ws */
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate if (p == end)
997c478bd9Sstevel@tonic-gate break;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate if ((q = strpbrk(p + 1, delimiters)) == NULL)
1027c478bd9Sstevel@tonic-gate q = end; /* compare until end */
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate if (*p == '*') {
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate * Find a pointer to type by looking in fp->ctf_ptrtab.
1077c478bd9Sstevel@tonic-gate * If we can't find a pointer to the given type, see if
1087c478bd9Sstevel@tonic-gate * we can compute a pointer to the type resulting from
1097c478bd9Sstevel@tonic-gate * resolving the type down to its base type and use
1107c478bd9Sstevel@tonic-gate * that instead. This helps with cases where the CTF
1117c478bd9Sstevel@tonic-gate * data includes "struct foo *" but not "foo_t *" and
1127c478bd9Sstevel@tonic-gate * the user tries to access "foo_t *" in the debugger.
1137c478bd9Sstevel@tonic-gate */
1147c478bd9Sstevel@tonic-gate ntype = fp->ctf_ptrtab[CTF_TYPE_TO_INDEX(type)];
1157c478bd9Sstevel@tonic-gate if (ntype == 0) {
1167c478bd9Sstevel@tonic-gate ntype = ctf_type_resolve(fp, type);
1177c478bd9Sstevel@tonic-gate if (ntype == CTF_ERR || (ntype = fp->ctf_ptrtab[
1187c478bd9Sstevel@tonic-gate CTF_TYPE_TO_INDEX(ntype)]) == 0) {
1197c478bd9Sstevel@tonic-gate (void) ctf_set_errno(fp, ECTF_NOTYPE);
1207c478bd9Sstevel@tonic-gate goto err;
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate type = CTF_INDEX_TO_TYPE(ntype,
1257c478bd9Sstevel@tonic-gate (fp->ctf_flags & LCTF_CHILD));
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate q = p + 1;
1287c478bd9Sstevel@tonic-gate continue;
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate if (isqualifier(p, (size_t)(q - p)))
1327c478bd9Sstevel@tonic-gate continue; /* skip qualifier keyword */
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate for (lp = fp->ctf_lookups; lp->ctl_prefix != NULL; lp++) {
1357c478bd9Sstevel@tonic-gate if (lp->ctl_prefix[0] == '\0' ||
136*d15d17d4SNicolò Mazzucato ((size_t)(q - p) >= lp->ctl_len && strncmp(p,
137*d15d17d4SNicolò Mazzucato lp->ctl_prefix, (size_t)(q - p)) == 0)) {
1387c478bd9Sstevel@tonic-gate for (p += lp->ctl_len; isspace(*p); p++)
1397c478bd9Sstevel@tonic-gate continue; /* skip prefix and next ws */
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate if ((q = strchr(p, '*')) == NULL)
1427c478bd9Sstevel@tonic-gate q = end; /* compare until end */
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate while (isspace(q[-1]))
1457c478bd9Sstevel@tonic-gate q--; /* exclude trailing ws */
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate if ((hp = ctf_hash_lookup(lp->ctl_hash, fp, p,
1487c478bd9Sstevel@tonic-gate (size_t)(q - p))) == NULL) {
1497c478bd9Sstevel@tonic-gate (void) ctf_set_errno(fp, ECTF_NOTYPE);
1507c478bd9Sstevel@tonic-gate goto err;
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate type = hp->h_type;
1547c478bd9Sstevel@tonic-gate break;
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate if (lp->ctl_prefix == NULL) {
1597c478bd9Sstevel@tonic-gate (void) ctf_set_errno(fp, ECTF_NOTYPE);
1607c478bd9Sstevel@tonic-gate goto err;
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate if (*p != '\0' || type == 0)
1657c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_SYNTAX));
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate return (type);
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate err:
1707c478bd9Sstevel@tonic-gate if (fp->ctf_parent != NULL &&
1717c478bd9Sstevel@tonic-gate (ptype = ctf_lookup_by_name(fp->ctf_parent, name)) != CTF_ERR)
1727c478bd9Sstevel@tonic-gate return (ptype);
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate return (CTF_ERR);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * Given a symbol table index, return the type of the data object described
1797c478bd9Sstevel@tonic-gate * by the corresponding entry in the symbol table.
1807c478bd9Sstevel@tonic-gate */
1817c478bd9Sstevel@tonic-gate ctf_id_t
ctf_lookup_by_symbol(ctf_file_t * fp,ulong_t symidx)1827c478bd9Sstevel@tonic-gate ctf_lookup_by_symbol(ctf_file_t *fp, ulong_t symidx)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate const ctf_sect_t *sp = &fp->ctf_symtab;
1857c478bd9Sstevel@tonic-gate ctf_id_t type;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate if (sp->cts_data == NULL)
1887c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOSYMTAB));
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate if (symidx >= fp->ctf_nsyms)
1917c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, EINVAL));
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate if (sp->cts_entsize == sizeof (Elf32_Sym)) {
1947c478bd9Sstevel@tonic-gate const Elf32_Sym *symp = (Elf32_Sym *)sp->cts_data + symidx;
1957c478bd9Sstevel@tonic-gate if (ELF32_ST_TYPE(symp->st_info) != STT_OBJECT)
1967c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOTDATA));
1977c478bd9Sstevel@tonic-gate } else {
1987c478bd9Sstevel@tonic-gate const Elf64_Sym *symp = (Elf64_Sym *)sp->cts_data + symidx;
1997c478bd9Sstevel@tonic-gate if (ELF64_ST_TYPE(symp->st_info) != STT_OBJECT)
2007c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOTDATA));
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate if (fp->ctf_sxlate[symidx] == -1u)
2047c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOTYPEDAT));
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate type = *(ushort_t *)((uintptr_t)fp->ctf_buf + fp->ctf_sxlate[symidx]);
2077c478bd9Sstevel@tonic-gate if (type == 0)
2087c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOTYPEDAT));
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate return (type);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate * Return the pointer to the internal CTF type data corresponding to the
2157c478bd9Sstevel@tonic-gate * given type ID. If the ID is invalid, the function returns NULL.
2167c478bd9Sstevel@tonic-gate * This function is not exported outside of the library.
2177c478bd9Sstevel@tonic-gate */
2187c478bd9Sstevel@tonic-gate const ctf_type_t *
ctf_lookup_by_id(ctf_file_t ** fpp,ctf_id_t type)2197c478bd9Sstevel@tonic-gate ctf_lookup_by_id(ctf_file_t **fpp, ctf_id_t type)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate ctf_file_t *fp = *fpp; /* caller passes in starting CTF container */
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate if ((fp->ctf_flags & LCTF_CHILD) && CTF_TYPE_ISPARENT(type) &&
2247c478bd9Sstevel@tonic-gate (fp = fp->ctf_parent) == NULL) {
2257c478bd9Sstevel@tonic-gate (void) ctf_set_errno(*fpp, ECTF_NOPARENT);
2267c478bd9Sstevel@tonic-gate return (NULL);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate type = CTF_TYPE_TO_INDEX(type);
2307c478bd9Sstevel@tonic-gate if (type > 0 && type <= fp->ctf_typemax) {
2317c478bd9Sstevel@tonic-gate *fpp = fp; /* function returns ending CTF container */
2327c478bd9Sstevel@tonic-gate return (LCTF_INDEX_TO_TYPEPTR(fp, type));
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate (void) ctf_set_errno(fp, ECTF_BADID);
2367c478bd9Sstevel@tonic-gate return (NULL);
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate * Given a symbol table index, return the info for the function described
2417c478bd9Sstevel@tonic-gate * by the corresponding entry in the symbol table.
2427c478bd9Sstevel@tonic-gate */
2437c478bd9Sstevel@tonic-gate int
ctf_func_info(ctf_file_t * fp,ulong_t symidx,ctf_funcinfo_t * fip)2447c478bd9Sstevel@tonic-gate ctf_func_info(ctf_file_t *fp, ulong_t symidx, ctf_funcinfo_t *fip)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate const ctf_sect_t *sp = &fp->ctf_symtab;
2477c478bd9Sstevel@tonic-gate const ushort_t *dp;
2487c478bd9Sstevel@tonic-gate ushort_t info, kind, n;
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate if (sp->cts_data == NULL)
2517c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOSYMTAB));
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate if (symidx >= fp->ctf_nsyms)
2547c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, EINVAL));
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate if (sp->cts_entsize == sizeof (Elf32_Sym)) {
2577c478bd9Sstevel@tonic-gate const Elf32_Sym *symp = (Elf32_Sym *)sp->cts_data + symidx;
2587c478bd9Sstevel@tonic-gate if (ELF32_ST_TYPE(symp->st_info) != STT_FUNC)
2597c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOTFUNC));
2607c478bd9Sstevel@tonic-gate } else {
2617c478bd9Sstevel@tonic-gate const Elf64_Sym *symp = (Elf64_Sym *)sp->cts_data + symidx;
2627c478bd9Sstevel@tonic-gate if (ELF64_ST_TYPE(symp->st_info) != STT_FUNC)
2637c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOTFUNC));
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate if (fp->ctf_sxlate[symidx] == -1u)
2677c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOFUNCDAT));
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate dp = (ushort_t *)((uintptr_t)fp->ctf_buf + fp->ctf_sxlate[symidx]);
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate info = *dp++;
2727c478bd9Sstevel@tonic-gate kind = LCTF_INFO_KIND(fp, info);
2737c478bd9Sstevel@tonic-gate n = LCTF_INFO_VLEN(fp, info);
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate if (kind == CTF_K_UNKNOWN && n == 0)
2767c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_NOFUNCDAT));
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate if (kind != CTF_K_FUNCTION)
2797c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ECTF_CORRUPT));
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate fip->ctc_return = *dp++;
2827c478bd9Sstevel@tonic-gate fip->ctc_argc = n;
2837c478bd9Sstevel@tonic-gate fip->ctc_flags = 0;
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate if (n != 0 && dp[n - 1] == 0) {
2867c478bd9Sstevel@tonic-gate fip->ctc_flags |= CTF_FUNC_VARARG;
2877c478bd9Sstevel@tonic-gate fip->ctc_argc--;
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate return (0);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate * Given a symbol table index, return the arguments for the function described
2957c478bd9Sstevel@tonic-gate * by the corresponding entry in the symbol table.
2967c478bd9Sstevel@tonic-gate */
2977c478bd9Sstevel@tonic-gate int
ctf_func_args(ctf_file_t * fp,ulong_t symidx,uint_t argc,ctf_id_t * argv)2987c478bd9Sstevel@tonic-gate ctf_func_args(ctf_file_t *fp, ulong_t symidx, uint_t argc, ctf_id_t *argv)
2997c478bd9Sstevel@tonic-gate {
3007c478bd9Sstevel@tonic-gate const ushort_t *dp;
3017c478bd9Sstevel@tonic-gate ctf_funcinfo_t f;
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate if (ctf_func_info(fp, symidx, &f) == CTF_ERR)
3047c478bd9Sstevel@tonic-gate return (CTF_ERR); /* errno is set for us */
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate * The argument data is two ushort_t's past the translation table
3087c478bd9Sstevel@tonic-gate * offset: one for the function info, and one for the return type.
3097c478bd9Sstevel@tonic-gate */
3107c478bd9Sstevel@tonic-gate dp = (ushort_t *)((uintptr_t)fp->ctf_buf + fp->ctf_sxlate[symidx]) + 2;
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate for (argc = MIN(argc, f.ctc_argc); argc != 0; argc--)
3137c478bd9Sstevel@tonic-gate *argv++ = *dp++;
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate return (0);
3167c478bd9Sstevel@tonic-gate }
3176ef284f1SJohn Levon
3186ef284f1SJohn Levon /*
3196ef284f1SJohn Levon * Unlike the normal lookup routines, ctf_dyn_*() variants consult both the
3206ef284f1SJohn Levon * processed CTF contents of a ctf_file_t as well as the dynamic types in the
3216ef284f1SJohn Levon * dtdef list.
3226ef284f1SJohn Levon */
3236ef284f1SJohn Levon
3246ef284f1SJohn Levon const ctf_type_t *
ctf_dyn_lookup_by_id(ctf_file_t * fp,ctf_id_t id)3256ef284f1SJohn Levon ctf_dyn_lookup_by_id(ctf_file_t *fp, ctf_id_t id)
3266ef284f1SJohn Levon {
3276ef284f1SJohn Levon ctf_file_t **fpp = &fp;
3286ef284f1SJohn Levon const ctf_type_t *t;
3296ef284f1SJohn Levon ctf_dtdef_t *dtd;
3306ef284f1SJohn Levon
3316ef284f1SJohn Levon if ((t = ctf_lookup_by_id(fpp, id)) != NULL)
3326ef284f1SJohn Levon return (t);
3336ef284f1SJohn Levon
3346ef284f1SJohn Levon if ((dtd = ctf_dtd_lookup(fp, id)) == NULL)
3356ef284f1SJohn Levon return (NULL);
3366ef284f1SJohn Levon
3376ef284f1SJohn Levon return (&dtd->dtd_data);
3386ef284f1SJohn Levon }
3396ef284f1SJohn Levon
3406ef284f1SJohn Levon int
ctf_dyn_array_info(ctf_file_t * infp,ctf_id_t id,ctf_arinfo_t * arinfop)3416ef284f1SJohn Levon ctf_dyn_array_info(ctf_file_t *infp, ctf_id_t id, ctf_arinfo_t *arinfop)
3426ef284f1SJohn Levon {
3436ef284f1SJohn Levon ctf_file_t *fp = infp;
3446ef284f1SJohn Levon const ctf_type_t *t;
3456ef284f1SJohn Levon ctf_dtdef_t *dtd;
3466ef284f1SJohn Levon
3476ef284f1SJohn Levon if ((t = ctf_lookup_by_id(&fp, id)) != NULL) {
3486ef284f1SJohn Levon
3496ef284f1SJohn Levon if (LCTF_INFO_KIND(fp, t->ctt_info) != CTF_K_ARRAY)
3506ef284f1SJohn Levon return (ctf_set_errno(infp, ECTF_NOTARRAY));
3516ef284f1SJohn Levon
3526ef284f1SJohn Levon return (ctf_array_info(fp, id, arinfop));
3536ef284f1SJohn Levon }
3546ef284f1SJohn Levon
3556ef284f1SJohn Levon if ((dtd = ctf_dtd_lookup(fp, id)) == NULL)
3566ef284f1SJohn Levon return (ctf_set_errno(infp, ENOENT));
3576ef284f1SJohn Levon
3586ef284f1SJohn Levon if (LCTF_INFO_KIND(fp, dtd->dtd_data.ctt_info) != CTF_K_ARRAY)
3596ef284f1SJohn Levon return (ctf_set_errno(infp, ECTF_NOTARRAY));
3606ef284f1SJohn Levon
3616ef284f1SJohn Levon bcopy(&dtd->dtd_u.dtu_arr, arinfop, sizeof (*arinfop));
3626ef284f1SJohn Levon return (0);
3636ef284f1SJohn Levon }
364