From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 072893858D1E for ; Mon, 24 Apr 2023 20:42:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 072893858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pr31Q-0001ev-3O; Mon, 24 Apr 2023 16:42:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From: Date; bh=hWRJ623qr1NmrOed36r2+C1QS7xePMBIr3fLsnKsgqQ=; b=DOli4O8NjuvUeNOQBOZb VXS6en1gEnSelMrScHxYSqQimgxyog/xPMNqnzhvK9rn6qHu+Nf8gtTYAnO+ihZvKpipDtjLkuqg0 Mq37EwYwmGrq0emQnGTR2rgvhZ8rrJr0kAW8t9FVFMQ/05JVmFrB0cgukHyPbnz6xQUd0DsP30sDJ QEcCjYQC8KNXXpnHWK13UN5DM3hxAFZkAsiIQ9jvlQQEKMGhjTh7W3w/QtV60UHMv+rmAmiu9DsKw gEcXSGsmFDb1QKv+iVjeEVGwOr5waBL0+AmUquTq/ogxpI+bHuVtZotiZVUgGkCTAwToILD7OVW3G vCurEpcW4/VbiA==; Received: from [2a01:cb19:4a:a400:de41:a9ff:fe47:ec49] (helo=begin.home) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pr31P-00037I-Ki; Mon, 24 Apr 2023 16:42:51 -0400 Received: from samy by begin.home with local (Exim 4.96) (envelope-from ) id 1pr31O-003tmM-0S; Mon, 24 Apr 2023 22:42:50 +0200 Date: Mon, 24 Apr 2023 22:42:50 +0200 From: Samuel Thibault To: Sergey Bugaev Cc: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: Re: [PATCH 1/4] hurd: Implement MAP_32BIT Message-ID: <20230424204250.6mvdewc23crwpq6g@begin> Mail-Followup-To: Sergey Bugaev , libc-alpha@sourceware.org, bug-hurd@gnu.org References: <20230423215526.346009-1-bugaevc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230423215526.346009-1-bugaevc@gmail.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Applied, thanks! Sergey Bugaev, le lun. 24 avril 2023 00:55:23 +0300, a ecrit: > This is a flag that can be passed to mmap () to request that the mapping > being established should be located in the lower 2 GB area of the > address space, so only the lower 31 (not 32) bits can be set in its > address, and the address can be represented as a 32-bit integer without > truncating it. > > This flag is intended to be compatible with Linux, FreeBSD, and Darwin > flags of the same name. Out of those systems, it appears Linux and > FreeBSD take MAP_32BIT to mean "map 31 bit", whereas Darwin allows the > 32nd bit to be set in the address as well. The Hurd follows Linux and > FreeBSD behavior. > > Unlike on those systems, on the Hurd MAP_32BIT is defined on all > supported architectures (which currently are only i386 and x86_64). > > Signed-off-by: Sergey Bugaev > --- > sysdeps/mach/hurd/bits/mman_ext.h | 1 + > sysdeps/mach/hurd/dl-sysdep.c | 8 +++++--- > sysdeps/mach/hurd/mmap.c | 10 ++++++---- > 3 files changed, 12 insertions(+), 7 deletions(-) > > diff --git a/sysdeps/mach/hurd/bits/mman_ext.h b/sysdeps/mach/hurd/bits/mman_ext.h > index f022826e..bbb94743 100644 > --- a/sysdeps/mach/hurd/bits/mman_ext.h > +++ b/sysdeps/mach/hurd/bits/mman_ext.h > @@ -22,4 +22,5 @@ > > #ifdef __USE_GNU > # define SHM_ANON ((const char *) 1) > +# define MAP_32BIT 0x1000 > #endif /* __USE_GNU */ > diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c > index 6e167e12..d7b309e0 100644 > --- a/sysdeps/mach/hurd/dl-sysdep.c > +++ b/sysdeps/mach/hurd/dl-sysdep.c > @@ -451,7 +451,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > { > error_t err; > vm_prot_t vmprot; > - vm_address_t mapaddr; > + vm_address_t mapaddr, mask; > mach_port_t memobj_rd, memobj_wr; > > vmprot = VM_PROT_NONE; > @@ -462,6 +462,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > if (prot & PROT_EXEC) > vmprot |= VM_PROT_EXECUTE; > > + mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0; > + > if (flags & MAP_ANON) > memobj_rd = MACH_PORT_NULL; > else > @@ -476,7 +478,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > > mapaddr = (vm_address_t) addr; > err = __vm_map (__mach_task_self (), > - &mapaddr, (vm_size_t) len, 0, > + &mapaddr, (vm_size_t) len, mask, > !(flags & MAP_FIXED), > memobj_rd, > (vm_offset_t) offset, > @@ -491,7 +493,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > if (! err) > err = __vm_map (__mach_task_self (), > &mapaddr, (vm_size_t) len, > - 0, > + mask, > !(flags & MAP_FIXED), > memobj_rd, (vm_offset_t) offset, > flags & (MAP_COPY|MAP_PRIVATE), > diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c > index 20a41e36..c3cc1856 100644 > --- a/sysdeps/mach/hurd/mmap.c > +++ b/sysdeps/mach/hurd/mmap.c > @@ -36,7 +36,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > error_t err; > vm_prot_t vmprot, max_vmprot; > memory_object_t memobj; > - vm_address_t mapaddr; > + vm_address_t mapaddr, mask; > boolean_t copy; > > mapaddr = (vm_address_t) addr; > @@ -55,6 +55,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > > copy = ! (flags & MAP_SHARED); > > + mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0; > + > switch (flags & MAP_TYPE) > { > default: > @@ -134,7 +136,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > max_vmprot = VM_PROT_ALL; > > err = __vm_map (__mach_task_self (), > - &mapaddr, (vm_size_t) len, (vm_address_t) 0, > + &mapaddr, (vm_size_t) len, mask, > mapaddr == 0, > memobj, (vm_offset_t) offset, > copy, vmprot, max_vmprot, > @@ -149,7 +151,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > err = __vm_deallocate (__mach_task_self (), mapaddr, len); > if (! err) > err = __vm_map (__mach_task_self (), > - &mapaddr, (vm_size_t) len, (vm_address_t) 0, > + &mapaddr, (vm_size_t) len, mask, > 0, memobj, (vm_offset_t) offset, > copy, vmprot, max_vmprot, > copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); > @@ -159,7 +161,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) > { > 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, > + &mapaddr, (vm_size_t) len, mask, > 1, memobj, (vm_offset_t) offset, > copy, vmprot, max_vmprot, > copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); > -- > 2.40.0 > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.