about summary refs log tree commit diff
path: root/elf/dl-load.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2005-10-17 20:59:28 +0000
committerRoland McGrath <roland@gnu.org>2005-10-17 20:59:28 +0000
commita3fcd5e8a45072b7450df091f0252ba3da242dd6 (patch)
tree7a5792613c3fda43f4fb6269771c94e146404fae /elf/dl-load.c
parent4fa64d66fef11970e4b57b5a60e8d23144c4b899 (diff)
downloadglibc-a3fcd5e8a45072b7450df091f0252ba3da242dd6.tar.gz
glibc-a3fcd5e8a45072b7450df091f0252ba3da242dd6.tar.xz
glibc-a3fcd5e8a45072b7450df091f0252ba3da242dd6.zip
2005-10-17 Roland McGrath <roland@redhat.com>
	* elf/dl-load.c (MAP_COPY): When undefined, define to
	MAP_PRIVATE|MAP_DENYWRITE instead of just MAP_PRIVATE.
	(_dl_map_object_from_fd): Don't use MAP_DENYWRITE explicitly.
Diffstat (limited to 'elf/dl-load.c')
-rw-r--r--elf/dl-load.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 0ed670d158..bba1c83ba0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -50,15 +50,17 @@
    overwritten.  Some losing VM systems like Linux's lack MAP_COPY.  All we
    get is MAP_PRIVATE, which copies each page when it is modified; this
    means if the file is overwritten, we may at some point get some pages
-   from the new version after starting with pages from the old version.  */
-#ifndef MAP_COPY
-# define MAP_COPY	MAP_PRIVATE
-#endif
+   from the new version after starting with pages from the old version.
 
-/* We want to prevent people from modifying DSOs which are currently in
-   use.  This is what MAP_DENYWRITE is for.  */
-#ifndef MAP_DENYWRITE
-# define MAP_DENYWRITE	0
+   To make up for the lack and avoid the overwriting problem,
+   what Linux does have is MAP_DENYWRITE.  This prevents anyone
+   from modifying the file while we have it mapped.  */
+#ifndef MAP_COPY
+# ifdef MAP_DENYWRITE
+#  define MAP_COPY	(MAP_PRIVATE | MAP_DENYWRITE)
+# else
+#  define MAP_COPY	MAP_PRIVATE
+# endif
 #endif
 
 /* Some systems link their relocatable objects for another base address
@@ -1181,7 +1183,7 @@ cannot allocate TLS data structures for initial thread");
 	/* Remember which part of the address space this object uses.  */
 	l->l_map_start = (ElfW(Addr)) __mmap ((void *) mappref, maplength,
 					      c->prot,
-					      MAP_COPY|MAP_FILE|MAP_DENYWRITE,
+					      MAP_COPY|MAP_FILE,
 					      fd, c->mapoff);
 	if (__builtin_expect ((void *) l->l_map_start == MAP_FAILED, 0))
 	  {
@@ -1229,7 +1231,7 @@ cannot allocate TLS data structures for initial thread");
 	    /* Map the segment contents from the file.  */
 	    && (__mmap ((void *) (l->l_addr + c->mapstart),
 			c->mapend - c->mapstart, c->prot,
-			MAP_FIXED|MAP_COPY|MAP_FILE|MAP_DENYWRITE,
+			MAP_FIXED|MAP_COPY|MAP_FILE,
 			fd, c->mapoff)
 		== MAP_FAILED))
 	  goto map_error;