libctf: drop mmap()-based CTF data allocator
authorNick Alcock <nick.alcock@oracle.com>
Wed, 19 Jun 2019 11:20:47 +0000 (12:20 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 21 Jun 2019 12:04:02 +0000 (13:04 +0100)
commit65365aa856e5a258329dc350b02bbb51f84b4c16
tree41b87c9af496cfda18bb854e3166f3ca002a080d
parent24865428034f44d9fffe6b2d9a318e1bd507c63a
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.
libctf/ChangeLog
libctf/ctf-create.c
libctf/ctf-impl.h
libctf/ctf-open.c
libctf/ctf-subr.c
This page took 0.023918 seconds and 4 git commands to generate.