aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-subr.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-06-19 12:20:47 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-06-21 13:04:02 +0100
commit65365aa856e5a258329dc350b02bbb51f84b4c16 (patch)
tree41b87c9af496cfda18bb854e3166f3ca002a080d /libctf/ctf-subr.c
parent24865428034f44d9fffe6b2d9a318e1bd507c63a (diff)
downloadgdb-65365aa856e5a258329dc350b02bbb51f84b4c16.zip
gdb-65365aa856e5a258329dc350b02bbb51f84b4c16.tar.gz
gdb-65365aa856e5a258329dc350b02bbb51f84b4c16.tar.bz2
libctf: drop mmap()-based CTF data allocator
This allocator has the ostensible benefit that it lets us mprotect() the memory used for CTF storage: but in exchange for this it adds considerable complexity, since we have to track allocation sizes ourselves for use at freeing time, note whether the data we are storing was ctf_data_alloc()ed or not so we know if we can safely mprotect() it... and while the mprotect()ing has found few bugs, it *has* been the cause of more than one due to errors in all this tracking leading to us mprotect()ing bits of the heap and stuff like that. We are about to start composing CTF buffers from pieces so that we can do usage-based optimizations on the strtab. This means we need realloc(), which needs nonportable mremap() and *more* tracking of the *original* allocation size, and the complexity and bureaucracy of all of this is just too high for its negligible benefits. Drop the whole thing and just use malloc() like everyone else. It knows better than we do when it is safe to use mmap() under the covers, anyway. While we're at it, don't leak the entire buffer if ctf_compress_write() fails to compress it. libctf/ * ctf-subr.c (_PAGESIZE): Remove. (ctf_data_alloc): Likewise. (ctf_data_free): Likewise. (ctf_data_protect): Likewise. * ctf-impl.h: Remove declarations. * ctf-create.c (ctf_update): No longer call ctf_data_protect: use ctf_free, not ctf_data_free. (ctf_compress_write): Use ctf_data_alloc, not ctf_alloc. Free the buffer again on compression error. * ctf-open.c (ctf_set_base): No longer track the size: call ctf_free, not ctf_data_free. (upgrade_types): Likewise. Call ctf_alloc, not ctf_data_alloc. (ctf_bufopen): Likewise. No longer call ctf_data_protect.
Diffstat (limited to 'libctf/ctf-subr.c')
-rw-r--r--libctf/ctf-subr.c51
1 files changed, 0 insertions, 51 deletions
diff --git a/libctf/ctf-subr.c b/libctf/ctf-subr.c
index b897351..454716a 100644
--- a/libctf/ctf-subr.c
+++ b/libctf/ctf-subr.c
@@ -26,49 +26,9 @@
#include <string.h>
#include <unistd.h>
-static size_t _PAGESIZE _libctf_unused_;
int _libctf_version = CTF_VERSION; /* Library client version. */
int _libctf_debug = 0; /* Debugging messages enabled. */
-_libctf_malloc_ void *
-ctf_data_alloc (size_t size)
-{
- void *ret;
-
-#ifdef HAVE_MMAP
- if (_PAGESIZE == 0)
- _PAGESIZE = sysconf(_SC_PAGESIZE);
-
- if (size > _PAGESIZE)
- {
- ret = mmap (NULL, size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON, -1, 0);
- if (ret == MAP_FAILED)
- ret = NULL;
- }
- else
- ret = calloc (1, size);
-#else
- ret = calloc (1, size);
-#endif
- return ret;
-}
-
-void
-ctf_data_free (void *buf, size_t size _libctf_unused_)
-{
-#ifdef HAVE_MMAP
- /* Must be the same as the check in ctf_data_alloc(). */
-
- if (size > _PAGESIZE)
- (void) munmap (buf, size);
- else
- free (buf);
-#else
- free (buf);
-#endif
-}
-
/* Private, read-only mmap from a file, with fallback to copying.
No handling of page-offset issues at all: the caller must allow for that. */
@@ -105,17 +65,6 @@ ctf_munmap (void *buf, size_t length _libctf_unused_)
#endif
}
-void
-ctf_data_protect (void *buf _libctf_unused_, size_t size _libctf_unused_)
-{
-#ifdef HAVE_MMAP
- /* Must be the same as the check in ctf_data_alloc(). */
-
- if (size > _PAGESIZE)
- (void) mprotect (buf, size, PROT_READ);
-#endif
-}
-
_libctf_malloc_ void *
ctf_alloc (size_t size)
{