aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-archive.c
diff options
context:
space:
mode:
Diffstat (limited to 'libctf/ctf-archive.c')
-rw-r--r--libctf/ctf-archive.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 799c3fb..90780da 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -32,8 +32,8 @@
#include <sys/mman.h>
#endif
-static off_t arc_write_one_ctf (ctf_file_t * f, int fd, size_t threshold);
-static ctf_file_t *ctf_arc_open_by_offset (const struct ctf_archive *arc,
+static off_t arc_write_one_ctf (ctf_dict_t * f, int fd, size_t threshold);
+static ctf_dict_t *ctf_arc_open_by_offset (const struct ctf_archive *arc,
const ctf_sect_t *symsect,
const ctf_sect_t *strsect,
size_t offset, int *errp);
@@ -45,12 +45,12 @@ static int arc_mmap_writeout (int fd, void *header, size_t headersz,
static int arc_mmap_unmap (void *header, size_t headersz, const char **errmsg);
/* Write out a CTF archive to the start of the file referenced by the passed-in
- fd. The entries in CTF_FILES are referenced by name: the names are passed in
- the names array, which must have CTF_FILES entries.
+ fd. The entries in CTF_DICTS are referenced by name: the names are passed in
+ the names array, which must have CTF_DICTS entries.
Returns 0 on success, or an errno, or an ECTF_* value. */
int
-ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
+ctf_arc_write_fd (int fd, ctf_dict_t **ctf_dicts, size_t ctf_dict_cnt,
const char **names, size_t threshold)
{
const char *errmsg;
@@ -66,14 +66,14 @@ ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
struct ctf_archive_modent *modent;
ctf_dprintf ("Writing CTF archive with %lu files\n",
- (unsigned long) ctf_file_cnt);
+ (unsigned long) ctf_dict_cnt);
/* Figure out the size of the mmap()ed header, including the
ctf_archive_modent array. We assume that all of this needs no
padding: a likely assumption, given that it's all made up of
uint64_t's. */
headersz = sizeof (struct ctf_archive)
- + (ctf_file_cnt * sizeof (uint64_t) * 2);
+ + (ctf_dict_cnt * sizeof (uint64_t) * 2);
ctf_dprintf ("headersz is %lu\n", (unsigned long) headersz);
/* From now on we work in two pieces: an mmap()ed region from zero up to the
@@ -101,7 +101,7 @@ ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
/* Fill in everything we can, which is everything other than the name
table offset. */
archdr->ctfa_magic = htole64 (CTFA_MAGIC);
- archdr->ctfa_nfiles = htole64 (ctf_file_cnt);
+ archdr->ctfa_ndicts = htole64 (ctf_dict_cnt);
archdr->ctfa_ctfs = htole64 (ctf_startoffs);
/* We could validate that all CTF files have the same data model, but
@@ -112,8 +112,8 @@ ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
this case, but we must be sure not to dereference uninitialized
memory.) */
- if (ctf_file_cnt > 0)
- archdr->ctfa_model = htole64 (ctf_getmodel (ctf_files[0]));
+ if (ctf_dict_cnt > 0)
+ archdr->ctfa_model = htole64 (ctf_getmodel (ctf_dicts[0]));
/* Now write out the CTFs: ctf_archive_modent array via the mapping,
ctfs via write(). The names themselves have not been written yet: we
@@ -122,7 +122,7 @@ ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
The name table is not sorted. */
- for (i = 0, namesz = 0; i < le64toh (archdr->ctfa_nfiles); i++)
+ for (i = 0, namesz = 0; i < le64toh (archdr->ctfa_ndicts); i++)
namesz += strlen (names[i]) + 1;
nametbl = malloc (namesz);
@@ -135,13 +135,13 @@ ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
for (i = 0, namesz = 0,
modent = (ctf_archive_modent_t *) ((char *) archdr
+ sizeof (struct ctf_archive));
- i < le64toh (archdr->ctfa_nfiles); i++)
+ i < le64toh (archdr->ctfa_ndicts); i++)
{
off_t off;
strcpy (&nametbl[namesz], names[i]);
- off = arc_write_one_ctf (ctf_files[i], fd, threshold);
+ off = arc_write_one_ctf (ctf_dicts[i], fd, threshold);
if ((off < 0) && (off > -ECTF_BASE))
{
errmsg = N_("ctf_arc_write(): cannot determine file "
@@ -163,7 +163,7 @@ ctf_arc_write_fd (int fd, ctf_file_t **ctf_files, size_t ctf_file_cnt,
ctf_qsort_r ((ctf_archive_modent_t *) ((char *) archdr
+ sizeof (struct ctf_archive)),
- le64toh (archdr->ctfa_nfiles),
+ le64toh (archdr->ctfa_ndicts),
sizeof (struct ctf_archive_modent), sort_modent_by_name,
nametbl);
@@ -204,19 +204,19 @@ err:
/* We report errors into the first file in the archive, if any: if this is a
zero-file archive, put it in the open-errors stream for lack of anywhere
else for it to go. */
- ctf_err_warn (ctf_file_cnt > 0 ? ctf_files[0] : NULL, 0, errno, "%s",
+ ctf_err_warn (ctf_dict_cnt > 0 ? ctf_dicts[0] : NULL, 0, errno, "%s",
gettext (errmsg));
return errno;
}
-/* Write out a CTF archive. The entries in CTF_FILES are referenced by name:
- the names are passed in the names array, which must have CTF_FILES entries.
+/* Write out a CTF archive. The entries in CTF_DICTS are referenced by name:
+ the names are passed in the names array, which must have CTF_DICTS entries.
If the filename is NULL, create a temporary file and return a pointer to it.
Returns 0 on success, or an errno, or an ECTF_* value. */
int
-ctf_arc_write (const char *file, ctf_file_t **ctf_files, size_t ctf_file_cnt,
+ctf_arc_write (const char *file, ctf_dict_t **ctf_dicts, size_t ctf_dict_cnt,
const char **names, size_t threshold)
{
int err;
@@ -224,17 +224,17 @@ ctf_arc_write (const char *file, ctf_file_t **ctf_files, size_t ctf_file_cnt,
if ((fd = open (file, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0666)) < 0)
{
- ctf_err_warn (ctf_file_cnt > 0 ? ctf_files[0] : NULL, 0, errno,
+ ctf_err_warn (ctf_dict_cnt > 0 ? ctf_dicts[0] : NULL, 0, errno,
_("ctf_arc_write(): cannot create %s"), file);
return errno;
}
- err = ctf_arc_write_fd (fd, ctf_files, ctf_file_cnt, names, threshold);
+ err = ctf_arc_write_fd (fd, ctf_dicts, ctf_dict_cnt, names, threshold);
if (err)
goto err_close;
if ((err = close (fd)) < 0)
- ctf_err_warn (ctf_file_cnt > 0 ? ctf_files[0] : NULL, 0, errno,
+ ctf_err_warn (ctf_dict_cnt > 0 ? ctf_dicts[0] : NULL, 0, errno,
_("ctf_arc_write(): cannot close after writing to archive"));
goto err;
@@ -252,13 +252,13 @@ ctf_arc_write (const char *file, ctf_file_t **ctf_files, size_t ctf_file_cnt,
negative errno or ctf_errno value. On error, the file position may no longer
be at the end of the file. */
static off_t
-arc_write_one_ctf (ctf_file_t * f, int fd, size_t threshold)
+arc_write_one_ctf (ctf_dict_t * f, int fd, size_t threshold)
{
off_t off, end_off;
uint64_t ctfsz = 0;
char *ctfszp;
size_t ctfsz_len;
- int (*writefn) (ctf_file_t * fp, int fd);
+ int (*writefn) (ctf_dict_t * fp, int fd);
if (ctf_serialize (f) < 0)
return f->ctf_errno * -1;
@@ -338,13 +338,13 @@ search_modent_by_name (const void *key, const void *ent, void *arg)
}
/* Make a new struct ctf_archive_internal wrapper for a ctf_archive or a
- ctf_file. Closes ARC and/or FP on error. Arrange to free the SYMSECT or
+ ctf_dict. Closes ARC and/or FP on error. Arrange to free the SYMSECT or
STRSECT, as needed, on close. Possibly do not unmap on close. */
struct ctf_archive_internal *
ctf_new_archive_internal (int is_archive, int unmap_on_close,
struct ctf_archive *arc,
- ctf_file_t *fp, const ctf_sect_t *symsect,
+ ctf_dict_t *fp, const ctf_sect_t *symsect,
const ctf_sect_t *strsect,
int *errp)
{
@@ -358,14 +358,14 @@ ctf_new_archive_internal (int is_archive, int unmap_on_close,
ctf_arc_close_internal (arc);
}
else
- ctf_file_close (fp);
+ ctf_dict_close (fp);
return (ctf_set_open_errno (errp, errno));
}
arci->ctfi_is_archive = is_archive;
if (is_archive)
arci->ctfi_archive = arc;
else
- arci->ctfi_file = fp;
+ arci->ctfi_dict = fp;
if (symsect)
memcpy (&arci->ctfi_symsect, symsect, sizeof (struct ctf_sect));
if (strsect)
@@ -386,7 +386,7 @@ ctf_arc_bufopen (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
{
struct ctf_archive *arc = NULL;
int is_archive;
- ctf_file_t *fp = NULL;
+ ctf_dict_t *fp = NULL;
if (ctfsect->cts_size > sizeof (uint64_t) &&
(le64toh ((*(uint64_t *) ctfsect->cts_data)) == CTFA_MAGIC))
@@ -492,7 +492,7 @@ ctf_arc_close (ctf_archive_t *arc)
ctf_arc_close_internal (arc->ctfi_archive);
}
else
- ctf_file_close (arc->ctfi_file);
+ ctf_dict_close (arc->ctfi_dict);
if (arc->ctfi_free_symsect)
free ((void *) arc->ctfi_symsect.cts_data);
if (arc->ctfi_free_strsect)
@@ -503,9 +503,9 @@ ctf_arc_close (ctf_archive_t *arc)
free (arc);
}
-/* Return the ctf_file_t with the given name, or NULL if none, setting 'err' if
+/* Return the ctf_dict_t with the given name, or NULL if none, setting 'err' if
non-NULL. A name of NULL means to open the default file. */
-static ctf_file_t *
+static ctf_dict_t *
ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
const ctf_sect_t *symsect,
const ctf_sect_t *strsect,
@@ -523,7 +523,7 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
+ sizeof (struct ctf_archive));
search_nametbl = (const char *) arc + le64toh (arc->ctfa_names);
- modent = bsearch_r (name, modent, le64toh (arc->ctfa_nfiles),
+ modent = bsearch_r (name, modent, le64toh (arc->ctfa_ndicts),
sizeof (struct ctf_archive_modent),
search_modent_by_name, (void *) search_nametbl);
@@ -540,13 +540,13 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
le64toh (modent->ctf_offset), errp);
}
-/* Return the ctf_file_t with the given name, or NULL if none, setting 'err' if
+/* Return the ctf_dict_t with the given name, or NULL if none, setting 'err' if
non-NULL. A name of NULL means to open the default file.
Use the specified string and symbol table sections.
Public entry point. */
-ctf_file_t *
+ctf_dict_t *
ctf_arc_open_by_name_sections (const ctf_archive_t *arc,
const ctf_sect_t *symsect,
const ctf_sect_t *strsect,
@@ -555,7 +555,7 @@ ctf_arc_open_by_name_sections (const ctf_archive_t *arc,
{
if (arc->ctfi_is_archive)
{
- ctf_file_t *ret;
+ ctf_dict_t *ret;
ret = ctf_arc_open_by_name_internal (arc->ctfi_archive, symsect, strsect,
name, errp);
if (ret)
@@ -569,18 +569,18 @@ ctf_arc_open_by_name_sections (const ctf_archive_t *arc,
*errp = ECTF_ARNNAME;
return NULL;
}
- arc->ctfi_file->ctf_archive = (ctf_archive_t *) arc;
+ arc->ctfi_dict->ctf_archive = (ctf_archive_t *) arc;
- /* Bump the refcount so that the user can ctf_file_close() it. */
- arc->ctfi_file->ctf_refcnt++;
- return arc->ctfi_file;
+ /* Bump the refcount so that the user can ctf_dict_close() it. */
+ arc->ctfi_dict->ctf_refcnt++;
+ return arc->ctfi_dict;
}
-/* Return the ctf_file_t with the given name, or NULL if none, setting 'err' if
+/* Return the ctf_dict_t with the given name, or NULL if none, setting 'err' if
non-NULL. A name of NULL means to open the default file.
Public entry point. */
-ctf_file_t *
+ctf_dict_t *
ctf_arc_open_by_name (const ctf_archive_t *arc, const char *name, int *errp)
{
const ctf_sect_t *symsect = &arc->ctfi_symsect;
@@ -594,16 +594,16 @@ ctf_arc_open_by_name (const ctf_archive_t *arc, const char *name, int *errp)
return ctf_arc_open_by_name_sections (arc, symsect, strsect, name, errp);
}
-/* Return the ctf_file_t at the given ctfa_ctfs-relative offset, or NULL if
+/* Return the ctf_dict_t at the given ctfa_ctfs-relative offset, or NULL if
none, setting 'err' if non-NULL. */
-static ctf_file_t *
+static ctf_dict_t *
ctf_arc_open_by_offset (const struct ctf_archive *arc,
const ctf_sect_t *symsect,
const ctf_sect_t *strsect, size_t offset,
int *errp)
{
ctf_sect_t ctfsect;
- ctf_file_t *fp;
+ ctf_dict_t *fp;
ctf_dprintf ("ctf_arc_open_by_offset(%lu): opening\n", (unsigned long) offset);
@@ -628,7 +628,7 @@ ctf_archive_count (const ctf_archive_t *wrapper)
if (!wrapper->ctfi_is_archive)
return 1;
- return wrapper->ctfi_archive->ctfa_nfiles;
+ return wrapper->ctfi_archive->ctfa_ndicts;
}
/* Raw iteration over all CTF files in an archive. We pass the raw data for all
@@ -646,7 +646,7 @@ ctf_archive_raw_iter_internal (const struct ctf_archive *arc,
+ sizeof (struct ctf_archive));
nametbl = (((const char *) arc) + le64toh (arc->ctfa_names));
- for (i = 0; i < le64toh (arc->ctfa_nfiles); i++)
+ for (i = 0; i < le64toh (arc->ctfa_ndicts); i++)
{
const char *name;
char *fp;
@@ -686,7 +686,7 @@ ctf_archive_iter_internal (const ctf_archive_t *wrapper,
{
int rc;
size_t i;
- ctf_file_t *f;
+ ctf_dict_t *f;
struct ctf_archive_modent *modent;
const char *nametbl;
@@ -694,7 +694,7 @@ ctf_archive_iter_internal (const ctf_archive_t *wrapper,
+ sizeof (struct ctf_archive));
nametbl = (((const char *) arc) + le64toh (arc->ctfa_names));
- for (i = 0; i < le64toh (arc->ctfa_nfiles); i++)
+ for (i = 0; i < le64toh (arc->ctfa_ndicts); i++)
{
const char *name;
@@ -706,11 +706,11 @@ ctf_archive_iter_internal (const ctf_archive_t *wrapper,
f->ctf_archive = (ctf_archive_t *) wrapper;
if ((rc = func (f, name, data)) != 0)
{
- ctf_file_close (f);
+ ctf_dict_close (f);
return rc;
}
- ctf_file_close (f);
+ ctf_dict_close (f);
}
return 0;
}
@@ -733,11 +733,11 @@ ctf_archive_iter (const ctf_archive_t *arc, ctf_archive_member_f *func,
return ctf_archive_iter_internal (arc, arc->ctfi_archive, symsect, strsect,
func, data);
- return func (arc->ctfi_file, _CTF_SECTION, data);
+ return func (arc->ctfi_dict, _CTF_SECTION, data);
}
/* Iterate over all CTF files in an archive, returning each dict in turn as a
- ctf_file_t, and NULL on error or end of iteration. It is the caller's
+ ctf_dict_t, and NULL on error or end of iteration. It is the caller's
responsibility to close it. Parent dicts may be skipped. Regardless of
whether they are skipped or not, the caller must ctf_import the parent if
need be.
@@ -745,11 +745,11 @@ ctf_archive_iter (const ctf_archive_t *arc, ctf_archive_member_f *func,
We identify parents by name rather than by flag value: for now, with the
linker only emitting parents named _CTF_SECTION, this works well enough. */
-ctf_file_t *
+ctf_dict_t *
ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **name,
int skip_parent, int *errp)
{
- ctf_file_t *f;
+ ctf_dict_t *f;
ctf_next_t *i = *it;
struct ctf_archive *arc;
struct ctf_archive_modent *modent;
@@ -783,7 +783,7 @@ ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **na
return NULL;
}
- /* Iteration is made a bit more complex by the need to handle ctf_file_t's
+ /* Iteration is made a bit more complex by the need to handle ctf_dict_t's
transparently wrapped in a single-member archive. These are parents: if
skip_parent is on, they are skipped and the iterator terminates
immediately. */
@@ -793,8 +793,8 @@ ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **na
i->ctn_n++;
if (!skip_parent)
{
- wrapper->ctfi_file->ctf_refcnt++;
- return wrapper->ctfi_file;
+ wrapper->ctfi_dict->ctf_refcnt++;
+ return wrapper->ctfi_dict;
}
}
@@ -809,7 +809,7 @@ ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **na
do
{
- if ((!wrapper->ctfi_is_archive) || (i->ctn_n >= le64toh (arc->ctfa_nfiles)))
+ if ((!wrapper->ctfi_is_archive) || (i->ctn_n >= le64toh (arc->ctfa_ndicts)))
{
ctf_next_destroy (i);
*it = NULL;