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 2018 Joyent, Inc.
29 */
30
31 #include <ctf_impl.h>
32 #include <sys/debug.h>
33
34 ssize_t
35 ctf_get_ctt_size(const ctf_file_t *fp, const ctf_type_t *tp, ssize_t *sizep,
36 ssize_t *incrementp)
37 {
38 ssize_t size, increment;
39
40 if (fp->ctf_version > CTF_VERSION_1 &&
41 tp->ctt_size == CTF_LSIZE_SENT) {
42 size = CTF_TYPE_LSIZE(tp);
43 increment = sizeof (ctf_type_t);
44 } else {
45 size = tp->ctt_size;
46 increment = sizeof (ctf_stype_t);
47 }
48
464 ssize_t size;
465 ctf_arinfo_t ar;
466
467 if ((type = ctf_type_resolve(fp, type)) == CTF_ERR)
468 return (-1); /* errno is set for us */
469
470 if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
471 return (-1); /* errno is set for us */
472
473 switch (LCTF_INFO_KIND(fp, tp->ctt_info)) {
474 case CTF_K_POINTER:
475 return (fp->ctf_dmodel->ctd_pointer);
476
477 case CTF_K_FUNCTION:
478 return (0); /* function size is only known by symtab */
479
480 case CTF_K_FORWARD:
481 return (0);
482
483 case CTF_K_ENUM:
484 return (fp->ctf_dmodel->ctd_int);
485
486 case CTF_K_ARRAY:
487 /*
488 * Array size is not directly returned by stabs data. Instead,
489 * it defines the element type and requires the user to perform
490 * the multiplication. If ctf_get_ctt_size() returns zero, the
491 * current version of ctfconvert does not compute member sizes
492 * and we compute the size here on its behalf.
493 */
494 if ((size = ctf_get_ctt_size(fp, tp, NULL, NULL)) > 0)
495 return (size);
496
497 if (ctf_array_info(fp, type, &ar) == CTF_ERR ||
498 (size = ctf_type_size(fp, ar.ctr_contents)) == CTF_ERR)
499 return (-1); /* errno is set for us */
500
501 return (size * ar.ctr_nelems);
502 case CTF_K_STRUCT:
503 case CTF_K_UNION:
504 /*
561
562 if (fp->ctf_version == CTF_VERSION_1 ||
563 size < CTF_LSTRUCT_THRESH) {
564 const ctf_member_t *mp = vmp;
565 for (; n != 0; n--, mp++) {
566 ssize_t am = ctf_type_align(fp, mp->ctm_type);
567 align = MAX(align, am);
568 }
569 } else {
570 const ctf_lmember_t *lmp = vmp;
571 for (; n != 0; n--, lmp++) {
572 ssize_t am = ctf_type_align(fp, lmp->ctlm_type);
573 align = MAX(align, am);
574 }
575 }
576
577 return (align);
578 }
579
580 case CTF_K_ENUM:
581 return (fp->ctf_dmodel->ctd_int);
582
583 default:
584 return (ctf_get_ctt_size(fp, tp, NULL, NULL));
585 }
586 }
587
588 /*
589 * Return the kind (CTF_K_* constant) for the specified type ID.
590 */
591 int
592 ctf_type_kind(ctf_file_t *fp, ctf_id_t type)
593 {
594 const ctf_type_t *tp;
595
596 if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
597 return (CTF_ERR); /* errno is set for us */
598
599 return (LCTF_INFO_KIND(fp, tp->ctt_info));
600 }
601
602 /*
|
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 2020 Joyent, Inc.
29 */
30
31 #include <ctf_impl.h>
32 #include <sys/debug.h>
33
34 ssize_t
35 ctf_get_ctt_size(const ctf_file_t *fp, const ctf_type_t *tp, ssize_t *sizep,
36 ssize_t *incrementp)
37 {
38 ssize_t size, increment;
39
40 if (fp->ctf_version > CTF_VERSION_1 &&
41 tp->ctt_size == CTF_LSIZE_SENT) {
42 size = CTF_TYPE_LSIZE(tp);
43 increment = sizeof (ctf_type_t);
44 } else {
45 size = tp->ctt_size;
46 increment = sizeof (ctf_stype_t);
47 }
48
464 ssize_t size;
465 ctf_arinfo_t ar;
466
467 if ((type = ctf_type_resolve(fp, type)) == CTF_ERR)
468 return (-1); /* errno is set for us */
469
470 if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
471 return (-1); /* errno is set for us */
472
473 switch (LCTF_INFO_KIND(fp, tp->ctt_info)) {
474 case CTF_K_POINTER:
475 return (fp->ctf_dmodel->ctd_pointer);
476
477 case CTF_K_FUNCTION:
478 return (0); /* function size is only known by symtab */
479
480 case CTF_K_FORWARD:
481 return (0);
482
483 case CTF_K_ENUM:
484 return (ctf_get_ctt_size(fp, tp, NULL, NULL));
485
486 case CTF_K_ARRAY:
487 /*
488 * Array size is not directly returned by stabs data. Instead,
489 * it defines the element type and requires the user to perform
490 * the multiplication. If ctf_get_ctt_size() returns zero, the
491 * current version of ctfconvert does not compute member sizes
492 * and we compute the size here on its behalf.
493 */
494 if ((size = ctf_get_ctt_size(fp, tp, NULL, NULL)) > 0)
495 return (size);
496
497 if (ctf_array_info(fp, type, &ar) == CTF_ERR ||
498 (size = ctf_type_size(fp, ar.ctr_contents)) == CTF_ERR)
499 return (-1); /* errno is set for us */
500
501 return (size * ar.ctr_nelems);
502 case CTF_K_STRUCT:
503 case CTF_K_UNION:
504 /*
561
562 if (fp->ctf_version == CTF_VERSION_1 ||
563 size < CTF_LSTRUCT_THRESH) {
564 const ctf_member_t *mp = vmp;
565 for (; n != 0; n--, mp++) {
566 ssize_t am = ctf_type_align(fp, mp->ctm_type);
567 align = MAX(align, am);
568 }
569 } else {
570 const ctf_lmember_t *lmp = vmp;
571 for (; n != 0; n--, lmp++) {
572 ssize_t am = ctf_type_align(fp, lmp->ctlm_type);
573 align = MAX(align, am);
574 }
575 }
576
577 return (align);
578 }
579
580 case CTF_K_ENUM:
581 default:
582 return (ctf_get_ctt_size(fp, tp, NULL, NULL));
583 }
584 }
585
586 /*
587 * Return the kind (CTF_K_* constant) for the specified type ID.
588 */
589 int
590 ctf_type_kind(ctf_file_t *fp, ctf_id_t type)
591 {
592 const ctf_type_t *tp;
593
594 if ((tp = ctf_lookup_by_id(&fp, type)) == NULL)
595 return (CTF_ERR); /* errno is set for us */
596
597 return (LCTF_INFO_KIND(fp, tp->ctt_info));
598 }
599
600 /*
|