Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp260721rwl; Thu, 30 Mar 2023 15:42:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZKnmlXm1Z8+90uKidSVFvFEUtgKkkWCt80ZLRdWkIVCkgfAnBget/W0xNK+R/Arpc6mQOo X-Received: by 2002:a17:902:c94d:b0:1a2:74bc:31d8 with SMTP id i13-20020a170902c94d00b001a274bc31d8mr6643089pla.4.1680216133473; Thu, 30 Mar 2023 15:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680216133; cv=none; d=google.com; s=arc-20160816; b=U5XI+6TOdxcdEjamPFmJv9iN69WP8um2R9jgDjXtmiIMVYZekLdS3uuTtIw1UzsS11 53iK/auWvXQx6rHCvBdvAnAJDMAT1ah71lcKBOsMXS7QMAPdizj/CbiaTgreWnu30e+/ R6FCfUVZPwCYdGjbsSq6Ryovuka5OLmyKYL7nUIICNHsZZLp1FcQ5BNHecWxpKi3UAz/ wOhQM2qC1licrUY4Dh9enWxddWksLK9YZohZNRw0HddMBavuUs+Kki++4bU0aFeNcRRF uCrH4pp/YdZwe6Mam/ZMbnsgIIL1JduRfeVkxcdGikQIq8Z+6H0dYkzVqPNmQUf2lOcJ cGbg== 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=XeSiGqg2CwSebiVN2ce25LntTFIojl0mClJDW8Z7Pok=; b=UPMEeGmE69WYuhbdScjyujkfMDOXfVt44DnLSwvBeb0hg1qnmqfboURk8vMyjZz6Ev KacuHr7JLOnuZGW/oeBCZYcGxapYpSC5Kq8EdubrprKVl3lfBCnzTo/6bhO2sFPj1Gy6 +ymCXLIfUTh3bFTyeSdHzh59RzwR9kIpvXefR3epAxwssQELkSd+6dtnGrFceyG3iUVk 56APgDwwD3b70cnOB6SfQ5bwe6BoTYAY1r/DcDdWYPe6+6X1h7tvLPBaNM08K00g0Mlo Qofxt2nGtdOnXJBkQZow7bC3Ai+l7KoZ6BNV8A8NaLZwvgr/URjyBOcqCJ/W7Vg8Hq/3 DP5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=EhX3fAjN; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=AUDSR6OO; 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 n18-20020a170902d2d200b001a298b11ee5si663244plc.410.2023.03.30.15.42.00; Thu, 30 Mar 2023 15:42:13 -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=EhX3fAjN; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=AUDSR6OO; 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 S230374AbjC3Wgf (ORCPT + 99 others); Thu, 30 Mar 2023 18:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjC3Wgd (ORCPT ); Thu, 30 Mar 2023 18:36:33 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD57DD308; Thu, 30 Mar 2023 15:36:31 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 0735832001C6; Thu, 30 Mar 2023 18:36:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 30 Mar 2023 18:36:28 -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= 1680215787; x=1680302187; bh=XeSiGqg2CwSebiVN2ce25LntTFIojl0mClJ DW8Z7Pok=; b=EhX3fAjN9Fr6yV5pb1z4rpHbLGkrwoLM8QUuEjyj2wbsJiahwSf 5pn/IcG1Xkzs7+cCmzwtDFzMbxn3phciU8bJ6pE+3OphkxwjjnW72F5Yd9p7D6U0 sUApF7bwzDyubK9ZcIAdbY3Eb41cfXF8n83df9Oj1RBsO/q8nFNLe1i+Y4KW/37H aQyvqinyp4LJes6GYg0QMbbr90pHG4FhTmzTUCz4JqnroJHDOngzN1jNOdMy6XrR VaI5JgTACJzKRXLrCUiK/N6pcURO/Tzq1NfZct7gDwhzIZ79kI3oTj1eBIlTjMLg vqL7UH94gmOtS2H6uvUeQfE4G3SAPMEyAMA== 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= 1680215787; x=1680302187; bh=XeSiGqg2CwSebiVN2ce25LntTFIojl0mClJ DW8Z7Pok=; b=AUDSR6OOiTzX3D0VrICdZyoxWH/+nv372dXGYxrDMobV6tNE6GB JIcKqdRiWzcnZVoXJqPVoNEa+HEbYlPnu6boCvfUnBGltn+QEu73lh08+N8mUfRd fFZYZ7n7aSPehdHWIQxFMqyiUCnuA5bEH/5J8uptBKTI86bGxQaazUaXV7GO3M7+ kLW6yKpfer89RmuLaeotBg9LChnEtFAYILj7dp80Lg27ETXI8BovW4NFenID21hv PAkBPPA/DedCf8gjfoFdwkMK2kh18yNoIsQDHLvNLqdLeKdzdObp1GwJOhEi44p3 pPYqL61+6m9Iy+ogDn86vlOzBpoA+0LBn3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeitddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe ehudduvdetkedvkedtudeludfgfffhudegjeeguedvvedtteevjeehheeiffefgeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhitggvse hrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 18:36:25 -0400 (EDT) Message-ID: <5dd90c62-0dc5-1225-c66c-e8f201cb0d59@ryhl.io> Date: Fri, 31 Mar 2023 00:36:24 +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 Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= 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 Reviewed-by: Alice Ryhl > +impl_zeroable! { > + // SAFETY: All primitives that are allowed to be zero. > + bool, > + char, > + u8, u16, u32, u64, u128, usize, > + i8, i16, i32, i64, i128, isize, > + f32, f64, > + // SAFETY: There is nothing to zero. > + core::marker::PhantomPinned, Infallible, (), > +} Here are some other types it might make sense to add: * Option> * Option> * Option * PhantomData * MaybeUninit > + > +// SAFETY: We are allowed to zero padding bytes. > +unsafe impl Zeroable for [T; N] {} There are no padding bytes in [T; N].