Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp261156rwl; Thu, 30 Mar 2023 15:42:43 -0700 (PDT) X-Google-Smtp-Source: AKy350YBghPgX345nxSvhwahwdNQs7H9wBTHlnP1H3a1tPrKL2n0IiBbEUXNaX+KeBDfGUGrC4qt X-Received: by 2002:a05:6a00:450e:b0:625:a08c:a8ba with SMTP id cw14-20020a056a00450e00b00625a08ca8bamr23014621pfb.1.1680216163280; Thu, 30 Mar 2023 15:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680216163; cv=none; d=google.com; s=arc-20160816; b=gqVjguksl1bd0U81GfSwWITk2xGxRGasLLsTOieYI7ZdNFo9IhA+uIDG0e53TnvNJy Wa3R4oC8jUDyMiTWJJhZSfLkMP/x71qqA0e82mhJWfOJhujSYLSCikWHy2KMokr1/k7H EKXrutH7s8rfHeIm0Nkr/GHTfwfEkVMFCWPmHkaRMeS946PMq/vk927ekogpXus7zG0V aXK2a52Iyzy9oUE6kBoY+B2btEa9KepWsoE/HmKgnI39PmMW0GzaR24TiR4qG++rR4RK iUEOkQR8gBUc6GyUc15TqXnAfMBAttcAl9oK+0HLKVzmemxMKIw0V+eBJiscsJcFRW70 3V/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=gOmL1aQ44MXyuPpeP7TtE2q5Dtn70Ay6Jf70/jGPMbQ=; b=LAbBmW9sr2mMaXHruybbqUOs/gX5AtVwuGVofmZDAZ99JUZo1KTlzHR0KxsZRl7+V8 UpZfAlma+H/mD9q9r8D+vPraTZw75nvQ5IGffRN/vQoTuVvzGmg9lHTaJ+uMG2s9SN/5 3Ye3DfMcZEiOYyRp6SNdVGn4FqricnmJF6R7IqSvl8w+p1qvYahxG0iqBJZoem2rv98l VDhIFVWiVQ7sgEC2iil34nNYLMpCq5UZllvpBKQwihkC5vFFhe0rhaXbNuoxxjRSaXnH jqASBbG/7Wc1kLSQnPupmJCrJS6l/yjH1gME/j7T/aF5mazGlScnrKRBsIDWocmmaNxY S+vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=UmmpMWz0; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=i3rXtGRc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q65-20020a632a44000000b0050b6f305b9fsi774103pgq.606.2023.03.30.15.42.31; Thu, 30 Mar 2023 15:42:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=UmmpMWz0; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=i3rXtGRc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbjC3Wkm (ORCPT + 99 others); Thu, 30 Mar 2023 18:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbjC3Wkj (ORCPT ); Thu, 30 Mar 2023 18:40:39 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF88ACC36; Thu, 30 Mar 2023 15:40:38 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id A83473200932; Thu, 30 Mar 2023 18:40:37 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 30 Mar 2023 18:40:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1680216037; x=1680302437; bh=gOmL1aQ44MXyuPpeP7TtE2q5Dtn70Ay6Jf7 0/jGPMbQ=; b=UmmpMWz0c+/b8wwa2Lmx3vygWTGvVa9srjxzpTn7XgG2Xc6GLce 5fLx7HH6GjpiV/Xf1v40gSPD8Tg14U6mcsr2ME8FvR7IRIq6rWFpd6oYsm3rfQNr G5Xm266MiTrwYAev5Wy3medhnNRhAH3WfH1niG0Gm40vIyaHJBbIWPHyE21Cc83V ufEHnJn7mTC3WhF65RhDCIXAcn4CrfWat5lkEYgo6t4v3/Km1ic/h7y0fH+ppIuS UaIbMq/4iVou8s6OjQmUufAUbTGs1j3JUY7zPYod0pdxBVAMr4/0wShjtbTeGMb8 eLrzSW5c9a226CDxTGDjCkR7FzVHFWeRCqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680216037; x=1680302437; bh=gOmL1aQ44MXyuPpeP7TtE2q5Dtn70Ay6Jf7 0/jGPMbQ=; b=i3rXtGRcGYyhzkDZjq7IEqnCOzWxIzUhWMLZDKpA5kRjbOASX/M TYsr8Opm0p29D1OWHLHD42QOER3saz/kedrVs2A1riDOkVtmUDlasypKD6dCGPnq HQOWxruE0kmPu4f4I4moat/cN5y+phK6hpDaQD1HyH1h5GXtJVQxZjoP3RMBiRWq joaLSQtPwl7Y2EXIvi+Yz5dxWTYonE/cPfOY+2PUnVjNBCI+eu87D1L2AKHXn+yM SsS/C0iESqr3hd0wn4ZHRKyvhK/VSbLNK2GHRExgr8BwPjsTUV2ha5tpr3aJK/8j FLPEDQfqghtWjz17r+vf6tf9wV9rXoUCP0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeitddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe fgvdeggeelvdeggeffveekheevleevkeeuudelhfefffefuedtteejjeekleffjeenucff ohhmrghinhepghhithhhuhgsrdgtohhmpdiivghrohgrsghlvgdrrhhsnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlihgtvgesrhihhhhl rdhioh X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 18:40:35 -0400 (EDT) Message-ID: <19db6213-297b-a33d-7331-3c1a5b72fad9@ryhl.io> Date: Fri, 31 Mar 2023 00:40:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v3 09/13] rust: init: add `Zeroable` trait and `init::zeroed` function Content-Language: en-US-large To: y86-dev@protonmail.com, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev References: <20230329223239.138757-10-y86-dev@protonmail.com> From: Alice Ryhl In-Reply-To: <20230329223239.138757-10-y86-dev@protonmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/30/23 00:33, y86-dev@protonmail.com wrote: > From: Benno Lossin > > Add the `Zeroable` trait which marks types that can be initialized by > writing `0x00` to every byte of the type. Also add the `init::zeroed` > function that creates an initializer for a `Zeroable` type that writes > `0x00` to every byte. > > Signed-off-by: Benno Lossin > --- > +// SAFETY: `null` pointer is valid. > +unsafe impl Zeroable for *mut T {} > +unsafe impl Zeroable for *const T {} Actually, I just realized that this is not ok for unsized types. When T is unsized, the raw pointer is a fat pointer with a vtable, and the vtable part is not necessarily zeroable. However, it would be ok to do it for `*const [T]` since the fat part of the pointer is just the length in this case, and a length of zero is fine. See more here: https://github.com/Lokathor/bytemuck/blob/8391afa876ba2e99dffb0c991cc7fa775287d106/src/zeroable.rs#L56-L65