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 8ED663858D20 for ; Fri, 5 May 2023 00:24:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8ED663858D20 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 1pujFb-00064X-7C; Thu, 04 May 2023 20:24:43 -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=S4KVKqLq1qCCsacqywArFb6zPlYf9zKHxCp7+3YNBzc=; b=EU8acrmr/u+PI8EoTX6T 7VEJ9VQ7Nre0CxqC3HHVF2BE624xOXiILWM7gooPmaBbdV2kxjnEmQp153fCrfG3JtZpPjGPr/2Iq nOj6/UHqwoLsQw7CXYrnu0FvwJgUY8YoC6KRm+EFcfgNiOv84yn7aYPuWnBHbBYcNJLH7G9y/RXMK uYvAg7eS9yBFkwU4ojE76XL6tfH3rVsfFubiatjpzkYcL+Ou9DK6kXuqUTyaYTruzsNpIoj0IB7s2 gUjPc072uqalMZxgcruT+GVZNkfe5CSW88ZOp8mKJ6RDIiSihFtL1Pg2LX4x1Gl4ac7pt7iO93+XP 6MAZQ4z2Aro0xw==; 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 1pujFb-0004PM-0d; Thu, 04 May 2023 20:24:43 -0400 Received: from samy by begin.home with local (Exim 4.96) (envelope-from ) id 1pujFZ-00EPRl-2k; Fri, 05 May 2023 02:24:41 +0200 Date: Fri, 5 May 2023 02:24:41 +0200 From: Samuel Thibault To: Flavio Cruz Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org Subject: Re: [PATCH glibc] Update hurd/intr-msg.c to be more portable Message-ID: <20230505002441.igzepmrpo5bqzwci@begin> Mail-Followup-To: Flavio Cruz , bug-hurd@gnu.org, libc-alpha@sourceware.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-12.3 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! Flavio Cruz via Libc-alpha, le jeu. 04 mai 2023 00:08:12 -0400, a ecrit: > Summary of the changes: > - Introduce BAD_TYPECHECK from MiG to make it simpler to do type > checking. > - Replace int type with mach_msg_type_t. This assumes that > mach_msg_type_t is always the same size as int which is not true for > x86_64. > - Calculate the size and align using PTR_ALIGN_UP, which is a bit > cleaner and similar to what we do elsewhere. > - Define mach_msg_type_t to check using designated initializers. > --- > hurd/intr-msg.c | 34 +++++++++++++++++++++------------- > 1 file changed, 21 insertions(+), 13 deletions(-) > > diff --git a/hurd/intr-msg.c b/hurd/intr-msg.c > index 716d87ab6a..a8e4d04041 100644 > --- a/hurd/intr-msg.c > +++ b/hurd/intr-msg.c > @@ -28,6 +28,11 @@ > # define mig_reply_header_t mig_reply_error_t > #endif > > +/* Macro used by MIG to cleanly check the type. */ > +#define BAD_TYPECHECK(type, check) __glibc_unlikely (({ \ > + union { mach_msg_type_t t; uint32_t w; } _t, _c; \ > + _t.t = *(type); _c.t = *(check);_t.w != _c.w; })) > + > error_t > _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, > mach_msg_option_t option, > @@ -61,7 +66,7 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, > #ifdef NDR_CHAR_ASCII > NDR_record_t ndr; > #else > - int type; > + mach_msg_type_t type; > #endif > int code; > } check; > @@ -222,11 +227,12 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, > > if (ty->msgtl_header.msgt_inline) > { > + /* Calculate length of data in bytes. */ > + const vm_size_t length = ((number * size) + 7) >> 3; > clean_ports ((void *) ty, 0); > - /* calculate length of data in bytes, rounding up */ > - ty = (void *) ty + (((((number * size) + 7) >> 3) > - + sizeof (mach_msg_type_t) - 1) > - &~ (sizeof (mach_msg_type_t) - 1)); > + /* Move to the next argument. */ > + ty = (void *) PTR_ALIGN_UP ((char *) ty + length, > + __alignof__ (uintptr_t)); > } > else > { > @@ -354,19 +360,21 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, > { > /* We got a reply. Was it EINTR? */ > #ifdef MACH_MSG_TYPE_BIT > - const union > - { > - mach_msg_type_t t; > - int i; > - } check = > - { t: { MACH_MSG_TYPE_INTEGER_T, sizeof (integer_t) * 8, > - 1, TRUE, FALSE, FALSE, 0 } }; > + static const mach_msg_type_t type_check = { > + .msgt_name = MACH_MSG_TYPE_INTEGER_T, > + .msgt_size = sizeof (integer_t) * 8, > + .msgt_number = 1, > + .msgt_inline = TRUE, > + .msgt_longform = FALSE, > + .msgt_deallocate = FALSE, > + .msgt_unused = 0 > + }; > #endif > > if (m->reply.RetCode == EINTR > && m->header.msgh_size == sizeof m->reply > #ifdef MACH_MSG_TYPE_BIT > - && m->check.type == check.i > + && !BAD_TYPECHECK(&m->check.type, &type_check) > #endif > && !(m->header.msgh_bits & MACH_MSGH_BITS_COMPLEX)) > { > -- > 2.39.2 > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.