aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-open-bfd.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2020-06-02 20:55:05 +0100
committerNick Alcock <nick.alcock@oracle.com>2020-07-22 17:57:33 +0100
commit601e455b758b7075d3027c030b9bd60f7b7face5 (patch)
tree655696f41764e9a7e7b6a5e76b5a87b52ffe6f42 /libctf/ctf-open-bfd.c
parent96e3ec29664810995d6d7d3b6fd6ae2d19c532bd (diff)
downloadgdb-601e455b758b7075d3027c030b9bd60f7b7face5.zip
gdb-601e455b758b7075d3027c030b9bd60f7b7face5.tar.gz
gdb-601e455b758b7075d3027c030b9bd60f7b7face5.tar.bz2
libctf, archive: stop ctf_arc_bufopen triggering crazy unmaps
The archive machinery mmap()s its archives when possible: so it arranges to do appropriately-sized unmaps by recording the unmap length in the ctfa_magic value and unmapping that. This brilliant (horrible) trick works less well when ctf_arc_bufopen is called with an existing buffer (which might be a readonly mapping). ctf_arc_bufopen always returns a ctf_archive_t wrapper, so record in there the necessity to not unmap anything when a bufopen'ed archive is closed again. libctf/ * ctf-impl.h (struct ctf_archive_internal) <ctfi_unmap_on_close>: New. (ctf_new_archive_internal): Adjust. * ctf-archive.c (ctf_new_archive_internal): Likewise. Initialize ctfi_unmap_on_close. Adjust error path. (ctf_arc_bufopen): Adjust ctf_new_archive_internal call (unmap_on_close is 0). (ctf_arc_close): Only unmap if ctfi_unmap_on_close. * ctf-open-bfd.c (ctf_fdopen): Adjust.
Diffstat (limited to 'libctf/ctf-open-bfd.c')
-rw-r--r--libctf/ctf-open-bfd.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
index dafa265..2d2d572 100644
--- a/libctf/ctf-open-bfd.c
+++ b/libctf/ctf-open-bfd.c
@@ -230,7 +230,7 @@ ctf_fdopen (int fd, const char *filename, const char *target, int *errp)
fp->ctf_data_mmapped = data;
fp->ctf_data_mmapped_len = (size_t) st.st_size;
- return ctf_new_archive_internal (0, NULL, fp, NULL, NULL, errp);
+ return ctf_new_archive_internal (0, 1, NULL, fp, NULL, NULL, errp);
}
if ((nbytes = ctf_pread (fd, &arc_magic, sizeof (arc_magic), 0)) <= 0)
@@ -243,7 +243,7 @@ ctf_fdopen (int fd, const char *filename, const char *target, int *errp)
if ((arc = ctf_arc_open_internal (filename, errp)) == NULL)
return NULL; /* errno is set for us. */
- return ctf_new_archive_internal (1, arc, NULL, NULL, NULL, errp);
+ return ctf_new_archive_internal (1, 1, arc, NULL, NULL, NULL, errp);
}
/* Attempt to open the file with BFD. We must dup the fd first, since bfd