From patchwork Wed Aug 11 16:40:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1515994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GlFth43WJz9sSs for ; Thu, 12 Aug 2021 02:40:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9622398544C for ; Wed, 11 Aug 2021 16:40:39 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id EF362385841C for ; Wed, 11 Aug 2021 16:40:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF362385841C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 863CFC34; Wed, 11 Aug 2021 18:40:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ces0Amf1CmcK; Wed, 11 Aug 2021 18:40:24 +0200 (CEST) Received: from begin (unknown [IPv6:2a01:cb19:956:1b00:de41:a9ff:fe47:ec49]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B78E32E; Wed, 11 Aug 2021 18:40:24 +0200 (CEST) Received: from samy by begin with local (Exim 4.94.2) (envelope-from ) id 1mDrHD-002PvZ-HI; Wed, 11 Aug 2021 18:40:23 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd mmap: Factorize MAP_SHARED flag check Date: Wed, 11 Aug 2021 18:40:20 +0200 Message-Id: <20210811164020.576277-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spamd-Bar: ++ X-Rspamd-Server: hera Authentication-Results: hera.aquilenet.fr X-Rspamd-Queue-Id: 863CFC34 X-Spamd-Result: default: False [2.58 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; BROKEN_CONTENT_TYPE(1.50)[]; R_MISSING_CHARSET(2.50)[]; RCVD_COUNT_THREE(0.00)[3]; MID_CONTAINS_FROM(1.00)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_CC(0.00)[gmail.com]; BAYES_HAM(-2.42)[97.33%] X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org, Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" From: Sergey Bugaev Reviewed-by: Samuel Thibault --- 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)