diff mbox series

[hurd,commited] hurd mmap: Factorize MAP_SHARED flag check

Message ID 20210811164020.576277-1-samuel.thibault@ens-lyon.org
State New
Headers show
Series [hurd,commited] hurd mmap: Factorize MAP_SHARED flag check | expand

Commit Message

Samuel Thibault Aug. 11, 2021, 4:40 p.m. UTC
From: Sergey Bugaev <bugaevc@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 sysdeps/mach/hurd/mmap.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c
index ea0e61d571..9fa265f752 100644
--- a/sysdeps/mach/hurd/mmap.c
+++ b/sysdeps/mach/hurd/mmap.c
@@ -37,6 +37,7 @@  __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
   vm_prot_t vmprot;
   memory_object_t memobj;
   vm_address_t mapaddr;
+  boolean_t copy;
 
   mapaddr = (vm_address_t) addr;
 
@@ -52,6 +53,8 @@  __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
   if (prot & PROT_EXEC)
     vmprot |= VM_PROT_EXECUTE;
 
+  copy = ! (flags & MAP_SHARED);
+
   switch (flags & MAP_TYPE)
     {
     default:
@@ -98,7 +101,7 @@  __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 		__mach_port_deallocate (__mach_task_self (), memobj);
 	      }
 	    else if (wobj == MACH_PORT_NULL /* Not writable by mapping.  */
-		     && !(flags & MAP_SHARED))
+		     && copy)
 	      /* The file can only be mapped for reading.  Since we are
 		 making a private mapping, we will never try to write the
 		 object anyway, so we don't care.  */
@@ -123,9 +126,8 @@  __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 		  &mapaddr, (vm_size_t) len, (vm_address_t) 0,
 		  mapaddr == 0,
 		  memobj, (vm_offset_t) offset,
-		  ! (flags & MAP_SHARED),
-		  vmprot, VM_PROT_ALL,
-		  (flags & MAP_SHARED) ? VM_INHERIT_SHARE : VM_INHERIT_COPY);
+		  copy, vmprot, VM_PROT_ALL,
+		  copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE);
 
   if (flags & MAP_FIXED)
     {
@@ -138,10 +140,8 @@  __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 	    err = __vm_map (__mach_task_self (),
 			    &mapaddr, (vm_size_t) len, (vm_address_t) 0,
 			    0, memobj, (vm_offset_t) offset,
-			    ! (flags & MAP_SHARED),
-			    vmprot, VM_PROT_ALL,
-			    (flags & MAP_SHARED) ? VM_INHERIT_SHARE
-			    : VM_INHERIT_COPY);
+			    copy, vmprot, VM_PROT_ALL,
+			    copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE);
 	}
     }
   else
@@ -150,10 +150,8 @@  __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 	err = __vm_map (__mach_task_self (),
 			&mapaddr, (vm_size_t) len, (vm_address_t) 0,
 			1, memobj, (vm_offset_t) offset,
-			! (flags & MAP_SHARED),
-			vmprot, VM_PROT_ALL,
-			(flags & MAP_SHARED) ? VM_INHERIT_SHARE
-			: VM_INHERIT_COPY);
+			copy, vmprot, VM_PROT_ALL,
+			copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE);
     }
 
   if (memobj != MACH_PORT_NULL)