From patchwork Thu May 4 04:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Cruz X-Patchwork-Id: 1776698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=AnFTXG4J; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QBgKY2gjvz20fg for ; Thu, 4 May 2023 14:08:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDF4E3858D28 for ; Thu, 4 May 2023 04:08:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDF4E3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683173310; bh=vQ/bwYw09IPMeJlKO9gSvOxZLlOphRXWCT9iYFBFk3A=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AnFTXG4JbJKjLNk358vxTZT5J4m5wd2ZvLwGQw7wqnLrHDAfaA5ZOq7q/IXVzMXAX w7ZOJfDo0tmHw8+J7nXBskJ9koNiRTwvL4Wh55WYLSgNQeJYF668G5OtNk1y8sBqVo CIDRyLP+ot/vt5szA1Y14rSTCFUr+WmNM23OzeL8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by sourceware.org (Postfix) with ESMTPS id CD7E73858D28 for ; Thu, 4 May 2023 04:08:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD7E73858D28 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-b9a6f17f2b6so6836544276.1 for ; Wed, 03 May 2023 21:08:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683173294; x=1685765294; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vQ/bwYw09IPMeJlKO9gSvOxZLlOphRXWCT9iYFBFk3A=; b=RAByJM44w42+AG5+BzufaFfJEiVXCGuJF9u6lTQ7Chd1DckYx4ZOfBqep2e3uMCbV8 cscfdt3/5cF/MBHdLmUbDQRQWwM5K5/dIbi4mV1cO3DPubj6Z/bm4OjcMAjWt/RYINr3 1PFJcN0ODrz4/KYcAuF4d9aTLU/4z0QoVpbFol2D11DSiJcLuEUYoNKY9ENr8n0lKYe9 TV7SgRvmQdnxKi/S0QWPxP3d1Inzg8K0lFlxgzIU1awvnJEjxhbb3NgemHU1EaF23q8H FmgFnv6E3kpupRJcegsjH6gzuvdprxn3GV96h+CzmCdF4mFKU6ef3KchHFMoTEZtOo8G 0L+w== X-Gm-Message-State: AC+VfDzAzz3GwEbA29yT7zEhyZwlfmMHaySKZAsy6r3gQj/0nY2mbBhx nrCJappGRRsg+C7QQTPneiUxWIfklA== X-Google-Smtp-Source: ACHHUZ5mqnF1sfCliBpOiW1+62S8GKSYP/topjlw5Zal+qc6Pfjkp/osWDB5hoGtXSbzivvg8JC9GQ== X-Received: by 2002:a25:ce45:0:b0:b9e:73bb:779c with SMTP id x66-20020a25ce45000000b00b9e73bb779cmr4679842ybe.17.1683173293927; Wed, 03 May 2023 21:08:13 -0700 (PDT) Received: from jupiter.tail36e24.ts.net (dynamic-acs-24-154-253-225.zoominternet.net. [24.154.253.225]) by smtp.gmail.com with ESMTPSA id e2-20020a251e02000000b00b9def138173sm2443951ybe.1.2023.05.03.21.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 21:08:13 -0700 (PDT) Date: Thu, 4 May 2023 00:08:12 -0400 To: bug-hurd@gnu.org, libc-alpha@sourceware.org Subject: [PATCH glibc] Update hurd/intr-msg.c to be more portable Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 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: , X-Patchwork-Original-From: Flavio Cruz via Libc-alpha From: Flavio Cruz Reply-To: Flavio Cruz Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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)) {