public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] hurd: Fix mmap(!MAP_FIXED) on bogus address
@ 2021-01-04 19:24 Samuel Thibault
  0 siblings, 0 replies; only message in thread
From: Samuel Thibault @ 2021-01-04 19:24 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b47b07c92d82df497ad4e3abebfdab51be5d0546

commit b47b07c92d82df497ad4e3abebfdab51be5d0546
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon Jan 4 20:22:59 2021 +0100

    hurd: Fix mmap(!MAP_FIXED) on bogus address
    
    In the !MAP_FIXED case, when a bogus address is given mmap should pick up a
    valide address rather than returning EINVAL: Posix only talks about
    EINVAL for the MAP_FIXED case.
    
    This fixes long-running ghc processes.

Diff:
---
 sysdeps/mach/hurd/mmap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c
index ed8faadee8..ea0e61d571 100644
--- a/sysdeps/mach/hurd/mmap.c
+++ b/sysdeps/mach/hurd/mmap.c
@@ -127,9 +127,9 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 		  vmprot, VM_PROT_ALL,
 		  (flags & MAP_SHARED) ? VM_INHERIT_SHARE : VM_INHERIT_COPY);
 
-  if (err == KERN_NO_SPACE)
+  if (flags & MAP_FIXED)
     {
-      if (flags & MAP_FIXED)
+      if (err == KERN_NO_SPACE)
 	{
 	  /* XXX this is not atomic as it is in unix! */
 	  /* The region is already allocated; deallocate it first.  */
@@ -143,7 +143,10 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 			    (flags & MAP_SHARED) ? VM_INHERIT_SHARE
 			    : VM_INHERIT_COPY);
 	}
-      else if (mapaddr != 0)
+    }
+  else
+    {
+      if (mapaddr != 0 && (err == KERN_NO_SPACE || err == KERN_INVALID_ADDRESS))
 	err = __vm_map (__mach_task_self (),
 			&mapaddr, (vm_size_t) len, (vm_address_t) 0,
 			1, memobj, (vm_offset_t) offset,


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-04 19:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04 19:24 [glibc] hurd: Fix mmap(!MAP_FIXED) on bogus address Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).