about summary refs log tree commit diff
path: root/ldso
diff options
context:
space:
mode:
authorAlexander Monakov <amonakov@ispras.ru>2018-04-16 20:54:36 +0300
committerRich Felker <dalias@aerifal.cx>2018-04-17 19:23:00 -0400
commitce7ae11acfd9db8eb92cc6823c132e1825918d92 (patch)
tree209dc86f7454ff68af570afb3ad29e2bbc1a1a27 /ldso
parentd889cc3463edc92869676c1eec34a8f52d942adb (diff)
downloadmusl-ce7ae11acfd9db8eb92cc6823c132e1825918d92.tar.gz
musl-ce7ae11acfd9db8eb92cc6823c132e1825918d92.tar.xz
musl-ce7ae11acfd9db8eb92cc6823c132e1825918d92.zip
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'.
Diffstat (limited to 'ldso')
-rw-r--r--ldso/dynlink.c16
1 files changed, 4 insertions, 12 deletions
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)