Lines Matching refs:fp

112 init_symtab(ctf_file_t *fp, const ctf_header_t *hp,  in init_symtab()  argument
116 uint_t *xp = fp->ctf_sxlate; in init_symtab()
117 uint_t *xend = xp + fp->ctf_nsyms; in init_symtab()
171 info = *(ushort_t *)((uintptr_t)fp->ctf_buf + funcoff); in init_symtab()
172 vlen = LCTF_INFO_VLEN(fp, info); in init_symtab()
179 if (LCTF_INFO_KIND(fp, info) == CTF_K_UNKNOWN && in init_symtab()
192 ctf_dprintf("loaded %lu symtab entries\n", fp->ctf_nsyms); in init_symtab()
201 init_types(ctf_file_t *fp, const ctf_header_t *cth) in init_types() argument
204 const ctf_type_t *tbuf = (ctf_type_t *)(fp->ctf_buf + cth->cth_typeoff); in init_types()
206 const ctf_type_t *tend = (ctf_type_t *)(fp->ctf_buf + cth->cth_stroff); in init_types()
228 for (tp = tbuf; tp < tend; fp->ctf_typemax++) { in init_types()
229 ushort_t kind = LCTF_INFO_KIND(fp, tp->ctt_info); in init_types()
230 ulong_t vlen = LCTF_INFO_VLEN(fp, tp->ctt_info); in init_types()
236 (void) ctf_get_ctt_size(fp, tp, &size, &increment); in init_types()
251 if (fp->ctf_version == CTF_VERSION_1 || in init_types()
308 ctf_dprintf("CTF container %p is a child\n", (void *)fp); in init_types()
309 fp->ctf_flags |= LCTF_CHILD; in init_types()
311 ctf_dprintf("CTF container %p is a parent\n", (void *)fp); in init_types()
317 if ((err = ctf_hash_create(&fp->ctf_structs, pop[CTF_K_STRUCT])) != 0) in init_types()
320 if ((err = ctf_hash_create(&fp->ctf_unions, pop[CTF_K_UNION])) != 0) in init_types()
323 if ((err = ctf_hash_create(&fp->ctf_enums, pop[CTF_K_ENUM])) != 0) in init_types()
326 if ((err = ctf_hash_create(&fp->ctf_names, in init_types()
332 fp->ctf_txlate = ctf_alloc(sizeof (uint_t) * (fp->ctf_typemax + 1)); in init_types()
333 fp->ctf_ptrtab = ctf_alloc(sizeof (ushort_t) * (fp->ctf_typemax + 1)); in init_types()
335 if (fp->ctf_txlate == NULL || fp->ctf_ptrtab == NULL) in init_types()
338 xp = fp->ctf_txlate; in init_types()
341 bzero(fp->ctf_txlate, sizeof (uint_t) * (fp->ctf_typemax + 1)); in init_types()
342 bzero(fp->ctf_ptrtab, sizeof (ushort_t) * (fp->ctf_typemax + 1)); in init_types()
349 ushort_t kind = LCTF_INFO_KIND(fp, tp->ctt_info); in init_types()
350 ulong_t vlen = LCTF_INFO_VLEN(fp, tp->ctt_info); in init_types()
358 (void) ctf_get_ctt_size(fp, tp, &size, &increment); in init_types()
359 name = ctf_strptr(fp, tp->ctt_name); in init_types()
369 if ((hep = ctf_hash_lookup(&fp->ctf_names, fp, in init_types()
371 err = ctf_hash_insert(&fp->ctf_names, fp, in init_types()
375 } else if (ctf_type_encoding(fp, hep->h_type, in init_types()
391 err = ctf_hash_insert(&fp->ctf_names, fp, in init_types()
399 err = ctf_hash_define(&fp->ctf_structs, fp, in init_types()
405 if (fp->ctf_version == CTF_VERSION_1 || in init_types()
415 err = ctf_hash_define(&fp->ctf_unions, fp, in init_types()
421 if (fp->ctf_version == CTF_VERSION_1 || in init_types()
431 err = ctf_hash_define(&fp->ctf_enums, fp, in init_types()
441 err = ctf_hash_insert(&fp->ctf_names, fp, in init_types()
455 hp = &fp->ctf_structs; in init_types()
458 hp = &fp->ctf_unions; in init_types()
461 hp = &fp->ctf_enums; in init_types()
464 hp = &fp->ctf_structs; in init_types()
467 if (ctf_hash_lookup(hp, fp, in init_types()
469 err = ctf_hash_insert(hp, fp, in init_types()
484 CTF_TYPE_TO_INDEX(tp->ctt_type) <= fp->ctf_typemax) in init_types()
485 fp->ctf_ptrtab[ in init_types()
492 err = ctf_hash_insert(&fp->ctf_names, fp, in init_types()
503 *xp = (uint_t)((uintptr_t)tp - (uintptr_t)fp->ctf_buf); in init_types()
507 ctf_dprintf("%lu total types processed\n", fp->ctf_typemax); in init_types()
508 ctf_dprintf("%u enum names hashed\n", ctf_hash_size(&fp->ctf_enums)); in init_types()
510 ctf_hash_size(&fp->ctf_structs), nlstructs); in init_types()
512 ctf_hash_size(&fp->ctf_unions), nlunions); in init_types()
514 ctf_hash_size(&fp->ctf_names)); in init_types()
522 for (id = 1; id <= fp->ctf_typemax; id++) { in init_types()
523 if ((dst = fp->ctf_ptrtab[id]) != 0) { in init_types()
524 tp = LCTF_INDEX_TO_TYPEPTR(fp, id); in init_types()
526 if (LCTF_INFO_KIND(fp, tp->ctt_info) == CTF_K_TYPEDEF && in init_types()
527 strcmp(ctf_strptr(fp, tp->ctt_name), "") == 0 && in init_types()
529 CTF_TYPE_TO_INDEX(tp->ctt_type) <= fp->ctf_typemax) in init_types()
530 fp->ctf_ptrtab[ in init_types()
550 ctf_file_t *fp; in ctf_bufopen() local
680 if ((fp = ctf_alloc(sizeof (ctf_file_t))) == NULL) in ctf_bufopen()
683 bzero(fp, sizeof (ctf_file_t)); in ctf_bufopen()
684 fp->ctf_version = hp.cth_version; in ctf_bufopen()
685 fp->ctf_fileops = &ctf_fileops[hp.cth_version]; in ctf_bufopen()
686 fp->ctf_hflags = hflags; in ctf_bufopen()
687 bcopy(ctfsect, &fp->ctf_data, sizeof (ctf_sect_t)); in ctf_bufopen()
690 bcopy(symsect, &fp->ctf_symtab, sizeof (ctf_sect_t)); in ctf_bufopen()
691 bcopy(strsect, &fp->ctf_strtab, sizeof (ctf_sect_t)); in ctf_bufopen()
694 if (fp->ctf_data.cts_name != NULL) in ctf_bufopen()
695 fp->ctf_data.cts_name = ctf_strdup(fp->ctf_data.cts_name); in ctf_bufopen()
696 if (fp->ctf_symtab.cts_name != NULL) in ctf_bufopen()
697 fp->ctf_symtab.cts_name = ctf_strdup(fp->ctf_symtab.cts_name); in ctf_bufopen()
698 if (fp->ctf_strtab.cts_name != NULL) in ctf_bufopen()
699 fp->ctf_strtab.cts_name = ctf_strdup(fp->ctf_strtab.cts_name); in ctf_bufopen()
701 if (fp->ctf_data.cts_name == NULL) in ctf_bufopen()
702 fp->ctf_data.cts_name = _CTF_NULLSTR; in ctf_bufopen()
703 if (fp->ctf_symtab.cts_name == NULL) in ctf_bufopen()
704 fp->ctf_symtab.cts_name = _CTF_NULLSTR; in ctf_bufopen()
705 if (fp->ctf_strtab.cts_name == NULL) in ctf_bufopen()
706 fp->ctf_strtab.cts_name = _CTF_NULLSTR; in ctf_bufopen()
708 fp->ctf_str[CTF_STRTAB_0].cts_strs = (const char *)buf + hp.cth_stroff; in ctf_bufopen()
709 fp->ctf_str[CTF_STRTAB_0].cts_len = hp.cth_strlen; in ctf_bufopen()
712 fp->ctf_str[CTF_STRTAB_1].cts_strs = strsect->cts_data; in ctf_bufopen()
713 fp->ctf_str[CTF_STRTAB_1].cts_len = strsect->cts_size; in ctf_bufopen()
716 fp->ctf_base = base; in ctf_bufopen()
717 fp->ctf_buf = buf; in ctf_bufopen()
718 fp->ctf_size = size + hdrsz; in ctf_bufopen()
725 fp->ctf_parlabel = ctf_strptr(fp, hp.cth_parlabel); in ctf_bufopen()
727 fp->ctf_parname = ctf_strptr(fp, hp.cth_parname); in ctf_bufopen()
730 fp->ctf_parname ? fp->ctf_parname : "<NULL>", in ctf_bufopen()
731 fp->ctf_parlabel ? fp->ctf_parlabel : "<NULL>"); in ctf_bufopen()
738 fp->ctf_nsyms = symsect->cts_size / symsect->cts_entsize; in ctf_bufopen()
739 fp->ctf_sxlate = ctf_alloc(fp->ctf_nsyms * sizeof (uint_t)); in ctf_bufopen()
741 if (fp->ctf_sxlate == NULL) { in ctf_bufopen()
746 if ((err = init_symtab(fp, &hp, symsect, strsect)) != 0) { in ctf_bufopen()
752 if ((err = init_types(fp, &hp)) != 0) { in ctf_bufopen()
762 fp->ctf_lookups[0].ctl_prefix = "struct"; in ctf_bufopen()
763 fp->ctf_lookups[0].ctl_len = strlen(fp->ctf_lookups[0].ctl_prefix); in ctf_bufopen()
764 fp->ctf_lookups[0].ctl_hash = &fp->ctf_structs; in ctf_bufopen()
765 fp->ctf_lookups[1].ctl_prefix = "union"; in ctf_bufopen()
766 fp->ctf_lookups[1].ctl_len = strlen(fp->ctf_lookups[1].ctl_prefix); in ctf_bufopen()
767 fp->ctf_lookups[1].ctl_hash = &fp->ctf_unions; in ctf_bufopen()
768 fp->ctf_lookups[2].ctl_prefix = "enum"; in ctf_bufopen()
769 fp->ctf_lookups[2].ctl_len = strlen(fp->ctf_lookups[2].ctl_prefix); in ctf_bufopen()
770 fp->ctf_lookups[2].ctl_hash = &fp->ctf_enums; in ctf_bufopen()
771 fp->ctf_lookups[3].ctl_prefix = _CTF_NULLSTR; in ctf_bufopen()
772 fp->ctf_lookups[3].ctl_len = strlen(fp->ctf_lookups[3].ctl_prefix); in ctf_bufopen()
773 fp->ctf_lookups[3].ctl_hash = &fp->ctf_names; in ctf_bufopen()
774 fp->ctf_lookups[4].ctl_prefix = NULL; in ctf_bufopen()
775 fp->ctf_lookups[4].ctl_len = 0; in ctf_bufopen()
776 fp->ctf_lookups[4].ctl_hash = NULL; in ctf_bufopen()
780 (void) ctf_setmodel(fp, CTF_MODEL_LP64); in ctf_bufopen()
782 (void) ctf_setmodel(fp, CTF_MODEL_ILP32); in ctf_bufopen()
784 (void) ctf_setmodel(fp, CTF_MODEL_NATIVE); in ctf_bufopen()
786 fp->ctf_refcnt = 1; in ctf_bufopen()
787 return (fp); in ctf_bufopen()
790 ctf_close(fp); in ctf_bufopen()
804 ctf_file_t *fp; in ctf_dup() local
861 fp = ctf_bufopen(ctp, symp, strp, &err); in ctf_dup()
862 if (fp == NULL) { in ctf_dup()
867 fp->ctf_flags |= LCTF_MMAP; in ctf_dup()
869 return (fp); in ctf_dup()
887 ctf_close(ctf_file_t *fp) in ctf_close() argument
893 if (fp == NULL) in ctf_close()
896 ctf_dprintf("ctf_close(%p) refcnt=%u\n", (void *)fp, fp->ctf_refcnt); in ctf_close()
898 if (fp->ctf_refcnt > 1) { in ctf_close()
899 fp->ctf_refcnt--; in ctf_close()
903 if (fp->ctf_parent != NULL) in ctf_close()
904 ctf_close(fp->ctf_parent); in ctf_close()
910 for (dtd = ctf_list_prev(&fp->ctf_dtdefs); dtd != NULL; dtd = ntd) { in ctf_close()
912 ctf_dtd_delete(fp, dtd); in ctf_close()
915 for (dsd = ctf_list_prev(&fp->ctf_dsdefs); dsd != NULL; dsd = nsd) { in ctf_close()
917 ctf_dsd_delete(fp, dsd); in ctf_close()
920 for (dld = ctf_list_prev(&fp->ctf_dldefs); dld != NULL; dld = nld) { in ctf_close()
922 ctf_dld_delete(fp, dld); in ctf_close()
925 ctf_free(fp->ctf_dthash, fp->ctf_dthashlen * sizeof (ctf_dtdef_t *)); in ctf_close()
927 if (fp->ctf_flags & LCTF_MMAP) { in ctf_close()
932 if (fp->ctf_data.cts_data != NULL && in ctf_close()
933 !(fp->ctf_flags & LCTF_RDWR)) in ctf_close()
934 ctf_sect_munmap(&fp->ctf_data); in ctf_close()
935 if (fp->ctf_symtab.cts_data != NULL) in ctf_close()
936 ctf_sect_munmap(&fp->ctf_symtab); in ctf_close()
937 if (fp->ctf_strtab.cts_data != NULL) in ctf_close()
938 ctf_sect_munmap(&fp->ctf_strtab); in ctf_close()
940 if (fp->ctf_flags & LCTF_FREE) { in ctf_close()
941 ctf_data_free((void *)fp->ctf_data.cts_data, in ctf_close()
942 fp->ctf_data.cts_size); in ctf_close()
945 if (fp->ctf_data.cts_name != _CTF_NULLSTR && in ctf_close()
946 fp->ctf_data.cts_name != NULL) { in ctf_close()
947 ctf_free((char *)fp->ctf_data.cts_name, in ctf_close()
948 strlen(fp->ctf_data.cts_name) + 1); in ctf_close()
951 if (fp->ctf_symtab.cts_name != _CTF_NULLSTR && in ctf_close()
952 fp->ctf_symtab.cts_name != NULL) { in ctf_close()
953 ctf_free((char *)fp->ctf_symtab.cts_name, in ctf_close()
954 strlen(fp->ctf_symtab.cts_name) + 1); in ctf_close()
957 if (fp->ctf_strtab.cts_name != _CTF_NULLSTR && in ctf_close()
958 fp->ctf_strtab.cts_name != NULL) { in ctf_close()
959 ctf_free((char *)fp->ctf_strtab.cts_name, in ctf_close()
960 strlen(fp->ctf_strtab.cts_name) + 1); in ctf_close()
963 if (fp->ctf_base != fp->ctf_data.cts_data && fp->ctf_base != NULL) in ctf_close()
964 ctf_data_free((void *)fp->ctf_base, fp->ctf_size); in ctf_close()
966 if (fp->ctf_sxlate != NULL) in ctf_close()
967 ctf_free(fp->ctf_sxlate, sizeof (uint_t) * fp->ctf_nsyms); in ctf_close()
969 if (fp->ctf_txlate != NULL) { in ctf_close()
970 ctf_free(fp->ctf_txlate, in ctf_close()
971 sizeof (uint_t) * (fp->ctf_typemax + 1)); in ctf_close()
974 if (fp->ctf_ptrtab != NULL) { in ctf_close()
975 ctf_free(fp->ctf_ptrtab, in ctf_close()
976 sizeof (ushort_t) * (fp->ctf_typemax + 1)); in ctf_close()
979 ctf_hash_destroy(&fp->ctf_structs); in ctf_close()
980 ctf_hash_destroy(&fp->ctf_unions); in ctf_close()
981 ctf_hash_destroy(&fp->ctf_enums); in ctf_close()
982 ctf_hash_destroy(&fp->ctf_names); in ctf_close()
984 ctf_free(fp, sizeof (ctf_file_t)); in ctf_close()
992 ctf_parent_file(ctf_file_t *fp) in ctf_parent_file() argument
994 return (fp->ctf_parent); in ctf_parent_file()
1002 ctf_parent_name(ctf_file_t *fp) in ctf_parent_name() argument
1004 return (fp->ctf_parname); in ctf_parent_name()
1012 ctf_parent_label(ctf_file_t *fp) in ctf_parent_label() argument
1014 return (fp->ctf_parlabel); in ctf_parent_label()
1023 ctf_import(ctf_file_t *fp, ctf_file_t *pfp) in ctf_import() argument
1025 if (fp == NULL || fp == pfp || (pfp != NULL && pfp->ctf_refcnt == 0)) in ctf_import()
1026 return (ctf_set_errno(fp, EINVAL)); in ctf_import()
1028 if (pfp != NULL && pfp->ctf_dmodel != fp->ctf_dmodel) in ctf_import()
1029 return (ctf_set_errno(fp, ECTF_DMODEL)); in ctf_import()
1031 if (fp->ctf_parent != NULL) in ctf_import()
1032 ctf_close(fp->ctf_parent); in ctf_import()
1035 fp->ctf_flags |= LCTF_CHILD; in ctf_import()
1039 fp->ctf_parent = pfp; in ctf_import()
1047 ctf_setmodel(ctf_file_t *fp, int model) in ctf_setmodel() argument
1053 fp->ctf_dmodel = dp; in ctf_setmodel()
1058 return (ctf_set_errno(fp, EINVAL)); in ctf_setmodel()
1065 ctf_getmodel(ctf_file_t *fp) in ctf_getmodel() argument
1067 return (fp->ctf_dmodel->ctd_code); in ctf_getmodel()
1071 ctf_setspecific(ctf_file_t *fp, void *data) in ctf_setspecific() argument
1073 fp->ctf_specific = data; in ctf_setspecific()
1077 ctf_getspecific(ctf_file_t *fp) in ctf_getspecific() argument
1079 return (fp->ctf_specific); in ctf_getspecific()
1083 ctf_flags(ctf_file_t *fp) in ctf_flags() argument
1085 return (fp->ctf_hflags); in ctf_flags()