This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Use munmap when loading ELF
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Mon, 8 Sep 2003 14:44:24 -0400
- Subject: Use munmap when loading ELF
There may be a reason I haven't thought of why this is a bad idea, but it
definitely works. This patch eliminates the "---p" mappings that glibc
tends to leave around on architectures with a larger MAXPAGESIZE (ARM,
PowerPC, et cetera).
Thoughts?
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
2003-09-08 Daniel Jacobowitz <drow@mvista.com>
* dl-load.c (_dl_map_object_from_fd): Unmap unreachable areas.
Index: dl-load.c
===================================================================
RCS file: /cvs/glibc/libc/elf/dl-load.c,v
retrieving revision 1.226
diff -u -p -r1.226 dl-load.c
--- dl-load.c 24 Jul 2003 20:03:31 -0000 1.226
+++ dl-load.c 8 Sep 2003 18:40:23 -0000
@@ -1107,15 +1107,14 @@ cannot allocate TLS data structures for
l->l_addr = l->l_map_start - c->mapstart;
if (has_holes)
- /* Change protection on the excess portion to disallow all access;
- the portions we do not remap later will be inaccessible as if
- unallocated. Then jump into the normal segment-mapping loop to
- handle the portion of the segment past the end of the file
- mapping. */
- __mprotect ((caddr_t) (l->l_addr + c->mapend),
- loadcmds[nloadcmds - 1].allocend - c->mapend,
- PROT_NONE);
+ /* Now that we've guaranteed that enough space is allocated,
+ we can unmap it. We don't allocate any other memory until
+ we're finished with loading these segments. */
+ __munmap ((caddr_t) (l->l_addr + c->mapend),
+ loadcmds[nloadcmds - 1].allocend - c->mapend);
+ /* Jump into the normal segment-mapping loop to handle the portion
+ of the segment past the end of the file mapping. */
goto postmap;
}
else