From ce7ae11acfd9db8eb92cc6823c132e1825918d92 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Mon, 16 Apr 2018 20:54:36 +0300 Subject: ldso, malloc: implement reclaim_gaps via __malloc_donate Split 'free' into unmap_chunk and bin_chunk, use the latter to introduce __malloc_donate and use it in reclaim_gaps instead of calling 'free'. --- ldso/dynlink.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'ldso') diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 9bf6924b..b9ff41bc 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -476,23 +476,15 @@ static void redo_lazy_relocs() /* A huge hack: to make up for the wastefulness of shared libraries * needing at least a page of dirty memory even if they have no global * data, we reclaim the gaps at the beginning and end of writable maps - * and "donate" them to the heap by setting up minimal malloc - * structures and then freeing them. */ + * and "donate" them to the heap. */ static void reclaim(struct dso *dso, size_t start, size_t end) { - size_t *a, *z; + void __malloc_donate(char *, char *); if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end; if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start; - start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t); - end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t); - if (start>end || end-start < 4*sizeof(size_t)) return; - a = laddr(dso, start); - z = laddr(dso, end); - a[-2] = 1; - a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1; - z[1] = 1; - free(a); + if (start >= end) return; + __malloc_donate(laddr(dso, start), laddr(dso, end)); } static void reclaim_gaps(struct dso *dso) -- cgit v1.2.1