diff options
Diffstat (limited to 'libctf/ctf-open.c')
-rw-r--r-- | libctf/ctf-open.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index fee7789..8c30182 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -141,8 +141,8 @@ get_ctt_size_v2 (const ctf_file_t *fp, const ctf_type_t *tp, } static ssize_t -get_vbytes_common (unsigned short kind, ssize_t size _libctf_unused_, - size_t vlen) +get_vbytes_common (ctf_file_t *fp, unsigned short kind, + ssize_t size _libctf_unused_, size_t vlen) { switch (kind) { @@ -162,13 +162,14 @@ get_vbytes_common (unsigned short kind, ssize_t size _libctf_unused_, case CTF_K_RESTRICT: return 0; default: - ctf_dprintf ("detected invalid CTF kind -- %x\n", kind); - return ECTF_CORRUPT; + ctf_set_errno (fp, ECTF_CORRUPT); + ctf_err_warn (fp, 0, 0, _("detected invalid CTF kind: %x"), kind); + return -1; } } static ssize_t -get_vbytes_v1 (unsigned short kind, ssize_t size, size_t vlen) +get_vbytes_v1 (ctf_file_t *fp, unsigned short kind, ssize_t size, size_t vlen) { switch (kind) { @@ -184,11 +185,11 @@ get_vbytes_v1 (unsigned short kind, ssize_t size, size_t vlen) return (sizeof (ctf_lmember_v1_t) * vlen); } - return (get_vbytes_common (kind, size, vlen)); + return (get_vbytes_common (fp, kind, size, vlen)); } static ssize_t -get_vbytes_v2 (unsigned short kind, ssize_t size, size_t vlen) +get_vbytes_v2 (ctf_file_t *fp, unsigned short kind, ssize_t size, size_t vlen) { switch (kind) { @@ -204,7 +205,7 @@ get_vbytes_v2 (unsigned short kind, ssize_t size, size_t vlen) return (sizeof (ctf_lmember_t) * vlen); } - return (get_vbytes_common (kind, size, vlen)); + return (get_vbytes_common (fp, kind, size, vlen)); } static const ctf_fileops_t ctf_fileops[] = { @@ -428,11 +429,11 @@ upgrade_types_v1 (ctf_file_t *fp, ctf_header_t *cth) unsigned long vlen = CTF_V1_INFO_VLEN (tp->ctt_info); size = get_ctt_size_v1 (fp, (const ctf_type_t *) tp, NULL, &increment); - vbytes = get_vbytes_v1 (kind, size, vlen); + vbytes = get_vbytes_v1 (fp, kind, size, vlen); get_ctt_size_v2_unconverted (fp, (const ctf_type_t *) tp, NULL, &v2increment); - v2bytes = get_vbytes_v2 (kind, size, vlen); + v2bytes = get_vbytes_v2 (fp, kind, size, vlen); if ((vbytes < 0) || (size < 0)) return ECTF_CORRUPT; @@ -485,7 +486,7 @@ upgrade_types_v1 (ctf_file_t *fp, ctf_header_t *cth) void *vdata, *v2data; size = get_ctt_size_v1 (fp, (const ctf_type_t *) tp, NULL, &increment); - vbytes = get_vbytes_v1 (kind, size, vlen); + vbytes = get_vbytes_v1 (fp, kind, size, vlen); t2p->ctt_name = tp->ctt_name; t2p->ctt_info = CTF_TYPE_INFO (kind, isroot, vlen); @@ -519,7 +520,7 @@ upgrade_types_v1 (ctf_file_t *fp, ctf_header_t *cth) } v2size = get_ctt_size_v2 (fp, t2p, NULL, &v2increment); - v2bytes = get_vbytes_v2 (kind, v2size, vlen); + v2bytes = get_vbytes_v2 (fp, kind, v2size, vlen); /* Catch out-of-sync get_ctt_size_*(). The count goes wrong if these are not identical (and having them different makes no @@ -767,6 +768,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) (void) ctf_get_ctt_size (fp, tp, &size, &increment); name = ctf_strptr (fp, tp->ctt_name); + /* Cannot fail: shielded by call in loop above. */ vbytes = LCTF_VBYTES (fp, kind, size, vlen); switch (kind) @@ -905,8 +907,8 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) return err; break; default: - ctf_dprintf ("unhandled CTF kind in endianness conversion -- %x\n", - kind); + ctf_err_warn (fp, 0, ECTF_CORRUPT, + _("init_types(): unhandled CTF kind: %x"), kind); return ECTF_CORRUPT; } @@ -1043,7 +1045,7 @@ flip_vars (void *start, size_t len) ctf_stype followed by variable data. */ static int -flip_types (void *start, size_t len) +flip_types (ctf_file_t *fp, void *start, size_t len) { ctf_type_t *t = start; @@ -1056,7 +1058,7 @@ flip_types (void *start, size_t len) uint32_t kind = CTF_V2_INFO_KIND (t->ctt_info); size_t size = t->ctt_size; uint32_t vlen = CTF_V2_INFO_VLEN (t->ctt_info); - size_t vbytes = get_vbytes_v2 (kind, size, vlen); + size_t vbytes = get_vbytes_v2 (fp, kind, size, vlen); if (_libctf_unlikely_ (size == CTF_LSIZE_SENT)) { @@ -1181,8 +1183,9 @@ flip_types (void *start, size_t len) break; } default: - ctf_dprintf ("unhandled CTF kind in endianness conversion -- %x\n", - kind); + ctf_err_warn (fp, 0, ECTF_CORRUPT, + _("unhandled CTF kind in endianness conversion: %x"), + kind); return ECTF_CORRUPT; } @@ -1200,7 +1203,7 @@ flip_types (void *start, size_t len) data, this is no real loss. */ static int -flip_ctf (ctf_header_t *cth, unsigned char *buf) +flip_ctf (ctf_file_t *fp, ctf_header_t *cth, unsigned char *buf) { flip_lbls (buf + cth->cth_lbloff, cth->cth_objtoff - cth->cth_lbloff); flip_objts (buf + cth->cth_objtoff, cth->cth_funcoff - cth->cth_objtoff); @@ -1208,7 +1211,7 @@ flip_ctf (ctf_header_t *cth, unsigned char *buf) flip_objts (buf + cth->cth_objtidxoff, cth->cth_funcidxoff - cth->cth_objtidxoff); flip_objts (buf + cth->cth_funcidxoff, cth->cth_varoff - cth->cth_funcidxoff); flip_vars (buf + cth->cth_varoff, cth->cth_typeoff - cth->cth_varoff); - return flip_types (buf + cth->cth_typeoff, cth->cth_stroff - cth->cth_typeoff); + return flip_types (fp, buf + cth->cth_typeoff, cth->cth_stroff - cth->cth_typeoff); } /* Set up the ctl hashes in a ctf_file_t. Called by both writable and @@ -1376,8 +1379,8 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect, info. We do not support dynamically upgrading such entries (none should exist in any case, since dwarf2ctf does not create them). */ - ctf_dprintf ("ctf_bufopen: CTF version %d symsect not " - "supported\n", pp->ctp_version); + ctf_err_warn (NULL, 0, 0, _("ctf_bufopen: CTF version %d symsect not " + "supported"), pp->ctp_version); return (ctf_set_open_errno (errp, ECTF_NOTSUP)); } @@ -1470,16 +1473,17 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect, if ((rc = uncompress (fp->ctf_base, &dstlen, src, srclen)) != Z_OK) { - ctf_dprintf ("zlib inflate err: %s\n", zError (rc)); + ctf_err_warn (NULL, 0, ECTF_DECOMPRESS, _("zlib inflate err: %s"), + zError (rc)); err = ECTF_DECOMPRESS; goto bad; } if ((size_t) dstlen != fp->ctf_size) { - ctf_dprintf ("zlib inflate short -- got %lu of %lu " - "bytes\n", (unsigned long) dstlen, - (unsigned long) fp->ctf_size); + ctf_err_warn (NULL, 0, ECTF_CORRUPT, + _("zlib inflate short: got %lu of %lu bytes"), + (unsigned long) dstlen, (unsigned long) fp->ctf_size); err = ECTF_CORRUPT; goto bad; } @@ -1559,7 +1563,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect, fp->ctf_syn_ext_strtab = syn_strtab; if (foreign_endian && - (err = flip_ctf (hp, fp->ctf_buf)) != 0) + (err = flip_ctf (fp, hp, fp->ctf_buf)) != 0) { /* We can be certain that flip_ctf() will have endian-flipped everything other than the types table when we return. In particular the header @@ -1619,6 +1623,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect, bad: ctf_set_open_errno (errp, err); + ctf_err_warn_to_open (fp); ctf_file_close (fp); return NULL; } |