public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Fangrui Song <maskray@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/maskray/lld] hurd mmap: Factorize MAP_SHARED flag check
Date: Mon, 16 Aug 2021 17:14:49 +0000 (GMT)	[thread overview]
Message-ID: <20210816171449.9B729395200D@sourceware.org> (raw)

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

commit 08fc6df294ab7e10e14492094a99b7861ad7d77e
Author: Sergey Bugaev <bugaevc@gmail.com>
Date:   Wed Aug 11 18:31:51 2021 +0200

    hurd mmap: Factorize MAP_SHARED flag check
    
    Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Diff:
---
 sysdeps/mach/hurd/mmap.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

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)


                 reply	other threads:[~2021-08-16 17:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210816171449.9B729395200D@sourceware.org \
    --to=maskray@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).