From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 0AC545A026D for ; Tue, 1 Aug 2023 05:36:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1690861010; bh=/LM63waPtFigeL0Tj0R1S8R/NQKbUMokSPxhj04veuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fR/nmHZ8TOn9xWvMr1+ly65gcZk9L3eKNY8PdIpgu5f+FWX8hHxN/kMrGfYRCHFZM 3mQZDFmxtInce7vvMtFnuMOsiAWXbPalkNPTIlntx7xEwCbGKEaVePvejg+nfoWGB8 FQYvpHoCfDXcghqSk2ebQCjWoXa8dggwxVsSHw80= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RFLPt2CHvz4wyN; Tue, 1 Aug 2023 13:36:50 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 3/3] Use static assertion to verify that union epoll_ref is the right size Date: Tue, 1 Aug 2023 13:36:47 +1000 Message-ID: <20230801033647.2135844-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801033647.2135844-1-david@gibson.dropbear.id.au> References: <20230801033647.2135844-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: BQNLLBWMPMPHSSXJPDYDKXOJGSDUHHBZ X-Message-ID-Hash: BQNLLBWMPMPHSSXJPDYDKXOJGSDUHHBZ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: union epoll_ref is used to subdivide the 64-bit data field in struct epoll_event. Thus it *must* fit within that field or we're likely to get very subtle and nasty bugs. C11 introduces the notion of static assertions which we can use to verify this is the case at compile time. Signed-off-by: David Gibson --- passt.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/passt.h b/passt.h index 8b7235a..edc4841 100644 --- a/passt.h +++ b/passt.h @@ -32,6 +32,8 @@ struct tap_l4_msg { union epoll_ref; #include +#include +#include #include "packet.h" #include "icmp.h" @@ -64,6 +66,8 @@ union epoll_ref { }; uint64_t u64; }; +static_assert(sizeof(union epoll_ref) <= sizeof(union epoll_data), + "epoll_ref must have same size as epoll_data"); #define TAP_BUF_BYTES \ ROUND_DOWN(((ETH_MAX_MTU + sizeof(uint32_t)) * 128), PAGE_SIZE) -- 2.41.0