From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705046; cv=none; d=zohomail.com; s=zohoarc; b=S7cwz45pQqmz3k5o3CSQ03MsG4xp6IfX16HcMgcfLTG4F+Db78hyQrnLQba7SS68uq0Ly3zj/CilAkt8RCP+HhKQ0XgrTVaH2Di9EXjRctKbmMQTdhqAzOFZKSJuz1Kk/uHOikIHE7QTBR0GGBylHr5olOLIkmsAUZGFZMjrZ20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705046; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7NoyIWNMvD+MTKirBcakZoomlbqaJX2sZ3AMUb91/xI=; b=PDiLt5TNJM0mxJ10SXCsNchC3Y9QlJv5r7SIu2J8vsoU2QXbAnXWOv7Gar3UNRavb6OWiyZeIT/rVIRVFESxI4HjGwr2vjmsIjEKcBUrVxJqeD6JDfMyPQWxLlqaLCg7+PT6EC2ypr1Ld2NDK3zKztDHO05Hkq4nKuPr4Cl88EQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705046636989.4789322903774; Fri, 20 Dec 2024 06:30:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe19-0004Nl-TE; Fri, 20 Dec 2024 09:30:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe12-0004KQ-CZ for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe0z-00061R-At for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:08 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-bQ3E0_G9MraOb6Qwjf7NpA-1; Fri, 20 Dec 2024 09:30:02 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9d23so16613865e9.3 for ; Fri, 20 Dec 2024 06:30:02 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436611ea40csm47240315e9.1.2024.12.20.06.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7NoyIWNMvD+MTKirBcakZoomlbqaJX2sZ3AMUb91/xI=; b=ipadB24y31PV9p7XYWo9pB5NXf2yazP4hne7h9dL04aVxC3uYePLg2G6x6OHAJuzgXL07y O470kPK2HAQYWetCeQDNmzM0DFZm5uRfbkbBJRn4EeIxnbCn3u0qfc9vKuMH343hvds/+z Ix87XUI9kyAt0czxD53+y1pfxhEPt1k= X-MC-Unique: bQ3E0_G9MraOb6Qwjf7NpA-1 X-Mimecast-MFC-AGG-ID: bQ3E0_G9MraOb6Qwjf7NpA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705000; x=1735309800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7NoyIWNMvD+MTKirBcakZoomlbqaJX2sZ3AMUb91/xI=; b=YlWV/aMKIJdXkIr8YoJNp63JLD7QwxFxsLi5I+gfUuYKsrow3i+i5SB2sT5mOpBnt4 9ibg9CFt5MS1EJLH2RS/t9BZDVA9a+qYLnThomII3M2A8bgAekoYfqdbED9QqiS/K6Dd kFGP2C6BI8EIpFxfN1YoySrL/TbGOn/ma2rA9eiBoLfOQzc3FMJ+imqpFOCSr/aZBOKK ux/hlGnucE5xABqkmK6Ipj9/+kq8qoTT/66bDVs2KJBPBfOOyjAfqyOF9HeioV6jUOkv es5l489T1fh45iD6Qt4isQtu8rIZl5R5Tr4beq1/q1yWmcIe7P5VIrDuIgIMBVneyuWZ 0cGQ== X-Gm-Message-State: AOJu0YwhYawxecQs4FEGpFXbhMVF5yv+dcOZ9XRMiFbnhfllL3xPM2cE RuTNFo/ejl+hd79QvQ8RYtBkikPlaxyZsBBLSeJPbS7BEHQ7AtnBA9NsjlZ8SkIukhp0yR2bkjG 9krf2LDZ1ySJGjSg/SYvXbOJA4Mu5YrL16uGtp/mr7uj8p10TWcroZFA1NnWZ7q7QWx3sOsW42B OcNxmcp3DDONkvcNgjiP1ajBr57Xo6h+BDrWFV X-Gm-Gg: ASbGncs2ULjid5bS1RgxX4yBvw2qkYTYVuYyMS2wGmq4BBJnDAyHMSrwFRvc1sHEQaQ +ZemUgMO39CXxMAJf1oOHH4/w8aZv5aRtoPnqUngwNN8SZaERhttb1+ShBzjVFiMqsV561aLkgj jrc+w/UzqqF5qezxTlltyYV3REoF1QR/vEbjgYX763puTuJd/+q3Mcwi2BSnc64CcjMcgdByDNd WgHoXHNWWC9jWSB+D/IyQ7qfCpJtXx+TXlF/qQjZBT5UAOgyARLp8nNxWr4 X-Received: by 2002:a05:600c:4fd3:b0:431:54f3:11ab with SMTP id 5b1f17b1804b1-43668b600c9mr24502875e9.33.1734704999810; Fri, 20 Dec 2024 06:29:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlEHQAr7bYdFZDw+3iR0shdi2P3SANySFEX5MJ78ENPPD8VFGXd59hcuXz0/Vck8la3t8vSw== X-Received: by 2002:a05:600c:4fd3:b0:431:54f3:11ab with SMTP id 5b1f17b1804b1-43668b600c9mr24502565e9.33.1734704999404; Fri, 20 Dec 2024 06:29:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 01/12] rust: qom: add ParentField Date: Fri, 20 Dec 2024 15:29:43 +0100 Message-ID: <20241220142955.652636-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705048857116600 Content-Type: text/plain; charset="utf-8" Add a type that, together with the C function object_deinit, ensures the correct drop order for QOM objects relative to their superclasses. Right now it is not possible to implement the Drop trait for QOM classes that are defined in Rust, as the drop() function would not be called when the object goes away; instead what is called is ObjectImpl::INSTANCE_FINALI= ZE. It would be nice for INSTANCE_FINALIZE to just drop the object, but this has a problem: suppose you have pub struct MySuperclass { parent: DeviceState, field: Box, ... } impl Drop for MySuperclass { ... } pub struct MySubclass { parent: MySuperclass, ... } and an instance_finalize implementation that is like unsafe extern "C" fn drop_object(obj: *mut Object) { unsafe { std::ptr::drop_in_place(obj.cast::()) } } When instance_finalize is called for MySubclass, it will walk the struct's list of fields and call the drop method for MySuperclass. Then, object_dei= nit recurses to the superclass and calls the same drop method again. This will cause double-freeing of the Box. What's happening here is that QOM wants to control the drop order of MySuperclass and MySubclass's fields. To do so, the parent field must be marked ManuallyDrop<>, which is quite ugly. Instead, add a wrapper type ParentField<> that is specific to QOM. This hides the implementation detail of *what* is special about the ParentField, and will also be easy to check in the #[derive(Object)] macro. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ++-- rust/qemu-api/src/qom.rs | 56 +++++++++++++++++++++++++++++--- rust/qemu-api/tests/tests.rs | 4 +-- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 18cc122951d..689202f4550 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -14,7 +14,7 @@ irq::InterruptSource, prelude::*, qdev::DeviceImpl, - qom::ObjectImpl, + qom::{ObjectImpl, ParentField}, }; =20 use crate::{ @@ -86,7 +86,7 @@ fn index(&self, idx: u32) -> &Self::Output { #[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)] /// PL011 Device Model in QEMU pub struct PL011State { - pub parent_obj: SysBusDevice, + pub parent_obj: ParentField, pub iomem: MemoryRegion, #[doc(alias =3D "fr")] pub flags: registers::Flags, @@ -645,7 +645,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result= <(), ()> { #[derive(Debug, qemu_api_macros::Object)] /// PL011 Luminary device model. pub struct PL011Luminary { - parent_obj: PL011State, + parent_obj: ParentField, } =20 impl PL011Luminary { diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 7d5fbef1e17..1341a173893 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -55,6 +55,7 @@ =20 use std::{ ffi::CStr, + fmt, ops::{Deref, DerefMut}, os::raw::c_void, }; @@ -105,6 +106,52 @@ fn as_ref(&self) -> &$parent { }; } =20 +/// This is the same as [`ManuallyDrop`](std::mem::ManuallyDrop), though +/// it hides the standard methods of `ManuallyDrop`. +/// +/// The first field of an `ObjectType` must be of type `ParentField`. +/// (Technically, this is only necessary if there is at least one Rust +/// superclass in the hierarchy). This is to ensure that the parent field= is +/// dropped after the subclass; this drop order is enforced by the C +/// `object_deinit` function. +/// +/// # Examples +/// +/// ```ignore +/// #[repr(C)] +/// #[derive(qemu_api_macros::Object)] +/// pub struct MyDevice { +/// parent: ParentField, +/// ... +/// } +/// ``` +#[derive(Debug)] +#[repr(transparent)] +pub struct ParentField(std::mem::ManuallyDrop); + +impl Deref for ParentField { + type Target =3D T; + + #[inline(always)] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for ParentField { + #[inline(always)] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl fmt::Display for ParentField { + #[inline(always)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + self.0.fmt(f) + } +} + unsafe extern "C" fn rust_instance_init(obj: *mut Object) { // SAFETY: obj is an instance of T, since rust_instance_init // is called from QOM core as the instance_init function @@ -151,8 +198,9 @@ fn as_ref(&self) -> &$parent { /// /// - the struct must be `#[repr(C)]`; /// -/// - the first field of the struct must be of the instance struct corresp= onding -/// to the superclass, which is `ObjectImpl::ParentType` +/// - the first field of the struct must be of type +/// [`ParentField`](ParentField), where `T` is the parent type +/// [`ObjectImpl::ParentType`] /// /// - likewise, the first field of the `Class` must be of the class struct /// corresponding to the superclass, which is `ObjectImpl::ParentType::C= lass`. @@ -384,8 +432,8 @@ impl ObjectCastMut for &mut T {} =20 /// Trait a type must implement to be registered with QEMU. pub trait ObjectImpl: ObjectType + ClassInitImpl { - /// The parent of the type. This should match the first field of - /// the struct that implements `ObjectImpl`: + /// The parent of the type. This should match the first field of the + /// struct that implements `ObjectImpl`, minus the `ParentField<_>` wr= apper. type ParentType: ObjectType; =20 /// Whether the object can be instantiated diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 1d2825b0986..526c3f4f8ea 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -15,7 +15,7 @@ declare_properties, define_property, prelude::*, qdev::{DeviceImpl, DeviceState, Property}, - qom::ObjectImpl, + qom::{ObjectImpl, ParentField}, vmstate::VMStateDescription, zeroable::Zeroable, }; @@ -31,7 +31,7 @@ #[repr(C)] #[derive(qemu_api_macros::Object)] pub struct DummyState { - parent: DeviceState, + parent: ParentField, migrate_clock: bool, } =20 --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705083; cv=none; d=zohomail.com; s=zohoarc; b=OUFTI/qdY+VBhljHgvpWnU4TmuJf2DHh3Y7p/7PT/99mS9P98InnbyQp5u82i7pm6qukRWfOkQrsRtGbgWS7SgdLiYfofh/kAN6Gy1g5iyLx9/xV50Hi4Ddp5njPs9bJgp7wwkD8Mcruz9DDQph5L7TmDBEYJfWZi63rcsp5tPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705083; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PdnJq0EU2A6dnq9zY8rdFIHGn/66sqWpQMYySJi7ef4=; b=msuIqeQ2JqW6TWWFIDY/jSd4xH/zqn7epvV2GjhuW/Ro/y7y8Is26Gid8qKSfmm1rnA9pCPsrsUG8ZYK9WIxAk6urmdhhMsJEY0o+UD+rAuCAgJzzup/5W+mlIlIDErTBG4tMQgSntkq9WBeYRkTSmmI1j2DPfEUL4ApN/zj8GQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705083429206.13911832040571; Fri, 20 Dec 2024 06:31:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1F-0004OD-N3; Fri, 20 Dec 2024 09:30:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe12-0004Kc-L7 for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe10-00067o-Sa for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:08 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-ohKqL5bVMM-0qMau_ZcrOw-1; Fri, 20 Dec 2024 09:30:04 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3862e986d17so963655f8f.3 for ; Fri, 20 Dec 2024 06:30:04 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4366127c639sm46735505e9.31.2024.12.20.06.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PdnJq0EU2A6dnq9zY8rdFIHGn/66sqWpQMYySJi7ef4=; b=HLmX+UV2C6Z5fOoP8wM+0Okwb5ose0GiI/XYhKcktQBgvxnVfkXHBn8jNBYVIrBrO6A7jd E0bsVyowbGqDaI35oC/qBcbsPZ6P3Zdk9XZX4ZKEi4WBfdFGaS3awjOlYKAg7Bfpc0tJt5 HWcuF2pfWqZz1uZ/JTCR7TQK8jij/xQ= X-MC-Unique: ohKqL5bVMM-0qMau_ZcrOw-1 X-Mimecast-MFC-AGG-ID: ohKqL5bVMM-0qMau_ZcrOw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705002; x=1735309802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PdnJq0EU2A6dnq9zY8rdFIHGn/66sqWpQMYySJi7ef4=; b=Fxm10y8OV7TPTkEC/HdEi5aSwMb5WFlDANoARxnCIYwPEsMmIi6QeBXkDHAMLsr6Fb YEAcIXzjeVmgQnyuwLk+QAarI2mNf715WmIj6JbpPdG5fl0vdcBR3qJV4twnryLjyXP2 z8hXMdzD8xvHmvHx+Gx0s48UwMp8B4oHhbgv8HuIbiO0PSHi/acEhI9Q1itjnIKzu7xi yb6c2ac6F2y0Wx21DeqjxtjWCLEU2/Uu0cGoknLMntdxHeyy+NYhBTDfNuwG3Wm5Uy++ Fzva+B8XnSaAx8y0FI8URiFONdcJiTLPCkT91JRVUQeUBb02Z6uwAzlqKc7q8m9wDzTS YyLQ== X-Gm-Message-State: AOJu0YzwrqJlqTWLuXWdqc+67JBLNUIjFaftDKajpuOiVAKX2l61Uv+m 6w8SusbKWkmC3S0va0UuWhaDzIdJ3Zu4yEicinmrl5OaAEBigVYdp7+AkkY7HtCW+XKZp4tsjt3 OeIR6/bPM6dm8KtYcazKjxMMTCh72m505A5P5r2jBIssGc5UBVAFvVDtV1MhPQ42Z/KARhKS+38 P7pczNafPWtnqsuHKIq+h7gnNwL9RWh7A1cdEP X-Gm-Gg: ASbGncv5ja1EOeZ48AzMwxNMJlakL4gH75ZWRCNy/x/Bd4CTFCbRjQ6FAfTazP0dJyg THXiwKgV4Mw6Q6jRoGGPCKuaVmEOj6nTKgyrL8Yiwd6mZLExP6/zXvtlwkUP3xQc2b6hc7Woev4 mCMA3osj8StfeODwMkJHUuS5ORLUDdO90QeFUQfa4wsjCbMFITZnPCRfaT7ojlmXjPn9kq+PTcG op6Hf0VolPBwZRRHqj3Mxc4xi25Vwlp56yCveeVc5X1JZkqYX+cO9LvXeZw X-Received: by 2002:a5d:584b:0:b0:385:fb40:e57b with SMTP id ffacd0b85a97d-38a221ea3a0mr3277808f8f.15.1734705002416; Fri, 20 Dec 2024 06:30:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsN/tGqxbpEuciSu3DsWPQVZMQQt4LfvegEF6vhfjKypBmaLgecIVVuqgqNKpN4kmgvCVHrw== X-Received: by 2002:a5d:584b:0:b0:385:fb40:e57b with SMTP id ffacd0b85a97d-38a221ea3a0mr3277778f8f.15.1734705001948; Fri, 20 Dec 2024 06:30:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 02/12] rust: add a utility module for compile-time type checks Date: Fri, 20 Dec 2024 15:29:44 +0100 Message-ID: <20241220142955.652636-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705084859116600 Content-Type: text/plain; charset="utf-8" It is relatively common in the low-level qemu_api code to assert that a field of a struct has a specific type; for example, it can be used to ensure that the fields match what the qemu_api and C code expects for safety. Signed-off-by: Paolo Bonzini --- rust/qemu-api/meson.build | 1 + rust/qemu-api/src/assertions.rs | 90 +++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 1 + 3 files changed, 92 insertions(+) create mode 100644 rust/qemu-api/src/assertions.rs diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 9425ba7100c..60944a657de 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -15,6 +15,7 @@ _qemu_api_rs =3D static_library( structured_sources( [ 'src/lib.rs', + 'src/assertions.rs', 'src/bindings.rs', 'src/bitops.rs', 'src/callbacks.rs', diff --git a/rust/qemu-api/src/assertions.rs b/rust/qemu-api/src/assertions= .rs new file mode 100644 index 00000000000..1a6cb3a6c7c --- /dev/null +++ b/rust/qemu-api/src/assertions.rs @@ -0,0 +1,90 @@ +// Copyright 2024, Red Hat Inc. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +//! This module provides macros to check the equality of types and +//! the type of `struct` fields. This can be useful to ensure that +//! types match the expectations of C code. + +// Based on https://stackoverflow.com/questions/64251852/x/70978292#709782= 92 +// (stackoverflow answers are released under MIT license). + +#[doc(hidden)] +pub trait EqType { + type Itself; +} + +impl EqType for T { + type Itself =3D T; +} + +/// Assert that two types are the same. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::assert_same_type; +/// # use std::ops::Deref; +/// assert_same_type!(u32, u32); +/// assert_same_type!( as Deref>::Target, u32); +/// ``` +/// +/// Different types will cause a compile failure +/// +/// ```compile_fail +/// # use qemu_api::assert_same_type; +/// assert_same_type!(&Box, &u32); +/// ``` +#[macro_export] +macro_rules! assert_same_type { + ($t1:ty, $t2:ty) =3D> { + const _: () =3D { + #[allow(unused)] + fn assert_same_type(v: $t1) { + fn types_must_be_equal(_: T) + where + T: $crate::assertions::EqType, + { + } + types_must_be_equal::<_, $t2>(v); + } + }; + }; +} + +/// Assert that a field of a struct has the given type. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::assert_field_type; +/// pub struct A { +/// field1: u32, +/// } +/// +/// assert_field_type!(A, field1, u32); +/// ``` +/// +/// Different types will cause a compile failure +/// +/// ```compile_fail +/// # use qemu_api::assert_field_type; +/// # pub struct A { field1: u32 } +/// assert_field_type!(A, field1, i32); +/// ``` +#[macro_export] +macro_rules! assert_field_type { + ($t:ty, $i:ident, $ti:ty) =3D> { + const _: () =3D { + #[allow(unused)] + fn assert_field_type(v: $t) { + fn types_must_be_equal(_: T) + where + T: $crate::assertions::EqType, + { + } + types_must_be_equal::<_, $ti>(v.$i); + } + }; + }; +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 4b43e02c0f9..83c6a987c05 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -12,6 +12,7 @@ #[rustfmt::skip] pub mod prelude; =20 +pub mod assertions; pub mod bitops; pub mod c_str; pub mod callbacks; --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705076; cv=none; d=zohomail.com; s=zohoarc; b=SSMq4OwWHzXA4rdvEWeZTWtcgrVXDpOOyMPppl9mUZsBfSOf6KzDm/RRp3LYee+Cteyt2mYxdCDE1vuAqefYn2OmzOgO9LK47HFY8MhmR8+xki8o8SScVka/wYuDvFuizpmH8pRvY14mTwVxRcgM6Ifx7qgo2ZuRgvNQtE6uB7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705076; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IqbmpoLQyfb2UAoXyBV1EOkxQeun0T/cCIXmsB4p+Sw=; b=Fl8z1ePKrM9MnyAk3IaxkD/VDy8jhfN8vNTfYKlhyK6FUbhcAyw/J94hdl2bQ0Zvni68unAyAqeaNOgmlMYU8WhA8ZfoZFMSmqMOXqr/n3c1OiQp9nj0PbLb3LyUfpRNrKWserC7o1jMpoK1k50oetcc4/SgDS3x//LVK8s6fBw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705076452747.5347357049138; Fri, 20 Dec 2024 06:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1O-0004RN-VB; Fri, 20 Dec 2024 09:30:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe15-0004Kt-3N for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe13-0006CW-J2 for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:10 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-uo4pgqnnPHODMnXIAoc5HQ-1; Fri, 20 Dec 2024 09:30:07 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-386321c8f4bso1149457f8f.0 for ; Fri, 20 Dec 2024 06:30:07 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656af6cbbsm81364845e9.3.2024.12.20.06.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IqbmpoLQyfb2UAoXyBV1EOkxQeun0T/cCIXmsB4p+Sw=; b=dA1o3E2iKH5K4Oj74xoMZbTHuvmpVzBVqMHDHf4WgPTm9wHjgXqbTLyV8rLybomFIz2zAm tioLNUfPki/jTktJpYmrCNhw52cormPty9c8kPbHU6dXiIZy2KXK9xKO7i9AwOS5Sb6CmB I+eIlHoi3nY52k4jOam4N3N03Ue+33A= X-MC-Unique: uo4pgqnnPHODMnXIAoc5HQ-1 X-Mimecast-MFC-AGG-ID: uo4pgqnnPHODMnXIAoc5HQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705005; x=1735309805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IqbmpoLQyfb2UAoXyBV1EOkxQeun0T/cCIXmsB4p+Sw=; b=na34YW4frB6WkNCEsBuP9ndW2WT+IMVChr7j/ZSvuF9dQZ8EAnmLSPTRzJXUTmZeqE FgGxI8J0HNsDvD4wTUxUV4bPfKGaYFD6L3vy8JxQQi7JmoX1XFpJWgY5tO1gClEWgkdx bkF++ViD153h7J8Ad6w7t54V5A9fs4Xb8ZwtC7c9H6W3+3GHAYdOGp5CsF2NAeSBIPvk 9f2VlcPQqrx0qnbm0bcnjSN+An3yratZfxOaKrJvWIdwrvOnpKTUVc2Nke7vcsFTLOgy XNXMkMrRmsczt6c7P51pTl7WZz9JzPNYZGyXAflap1574ZxKo1CFZCtKXvVas5Q+Qm+w xf+g== X-Gm-Message-State: AOJu0YylL/o5oZNdNgpc2842bXnExMAbgil2cBP1gxelSNrbhqm1+VSI IHGUMO/ZkI/8sC4JoolRIEwE8Rc5y34eS6PeDtaL+33JNUwSTaP5b7gLIsvcfW142CovmpVOGyM ghOrvoCPVG2uxMK6XUQXIjmH3p6epy+SNC03pr3SYUzIdPlj20uQE5yk34B62ortvo/gcKFl7BZ syW95vOA98w8h2g9e8eMUjiuLhvq/0x6tzlmGb X-Gm-Gg: ASbGncvvJe79jtFRd2Bx0/WemuvRo+1FpAmwEtQaJzn9U0+JK5t6EI0u2UW/uz02dpK jhIXYN4wfXekjbrCyukA0kuKNg59nO0PpROhAhe9l9bfg3UjjqWa7/r8x5oYLRWeEITFYmqnMam y4JlKQkxiHrv/fQF35iAObsjXUl2/L6+rNIEgtubcHc/kuU9lL8yQCJjU2eKaIE0AbgtbAjdlOz ZYW/zRccpG53jX+RSHpDrP/j8cXDD6Cju0Z6RHDKP8P1ar9aQ7a/mq+DpXo X-Received: by 2002:a05:6000:70a:b0:385:fd07:8616 with SMTP id ffacd0b85a97d-38a221403c5mr3545175f8f.0.1734705005284; Fri, 20 Dec 2024 06:30:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMO0aSdbfgVn0axKuvleQYQ7bUuDKX2ggtYKCo1HVYZ+0BomAdEB53tfQHu74Dyu9+vfOCrw== X-Received: by 2002:a05:6000:70a:b0:385:fd07:8616 with SMTP id ffacd0b85a97d-38a221403c5mr3545159f8f.0.1734705004934; Fri, 20 Dec 2024 06:30:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 03/12] rust: macros: check that the first field of a #[derive(Object)] struct is a ParentField Date: Fri, 20 Dec 2024 15:29:45 +0100 Message-ID: <20241220142955.652636-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705076820116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/src/lib.rs | 61 +++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 74a8bc7503e..778b698be45 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -19,6 +19,27 @@ fn from(err: CompileError) -> Self { } } =20 +fn get_fields<'a>( + input: &'a DeriveInput, + msg: &str, +) -> Result<&'a Punctuated, CompileError> { + if let Data::Struct(s) =3D &input.data { + if let Fields::Named(fs) =3D &s.fields { + Ok(&fs.named) + } else { + Err(CompileError( + format!("Named fields required for {}", msg), + input.ident.span(), + )) + } + } else { + Err(CompileError( + format!("Struct required for {}", msg), + input.ident.span(), + )) + } +} + fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), CompileError> { let expected =3D parse_quote! { #[repr(C)] }; =20 @@ -32,38 +53,28 @@ fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<= (), CompileError> { } } =20 -#[proc_macro_derive(Object)] -pub fn derive_object(input: TokenStream) -> TokenStream { - let input =3D parse_macro_input!(input as DeriveInput); - let name =3D input.ident; +fn derive_object_or_error(input: DeriveInput) -> Result { + let name =3D &input.ident; + let parent =3D &get_fields(&input, "#[derive(Object)]")?[0].ident; + + Ok(quote! { + ::qemu_api::assert_field_type!(#name, #parent, + ::qemu_api::qom::ParentField<<#name as ::qemu_api::qom::Object= Impl>::ParentType>); =20 - let expanded =3D quote! { ::qemu_api::module_init! { MODULE_INIT_QOM =3D> unsafe { ::qemu_api::bindings::type_register_static(&<#name as ::qe= mu_api::qom::ObjectImpl>::TYPE_INFO); } } - }; - - TokenStream::from(expanded) + }) } =20 -fn get_fields(input: &DeriveInput) -> Result<&Punctuated, Co= mpileError> { - if let Data::Struct(s) =3D &input.data { - if let Fields::Named(fs) =3D &s.fields { - Ok(&fs.named) - } else { - Err(CompileError( - "Cannot generate offsets for unnamed fields.".to_string(), - input.ident.span(), - )) - } - } else { - Err(CompileError( - "Cannot generate offsets for union or enum.".to_string(), - input.ident.span(), - )) - } +#[proc_macro_derive(Object)] +pub fn derive_object(input: TokenStream) -> TokenStream { + let input =3D parse_macro_input!(input as DeriveInput); + let expanded =3D derive_object_or_error(input).unwrap_or_else(Into::in= to); + + TokenStream::from(expanded) } =20 #[rustfmt::skip::macros(quote)] @@ -71,7 +82,7 @@ fn derive_offsets_or_error(input: DeriveInput) -> Result<= proc_macro2::TokenStrea is_c_repr(&input, "#[derive(offsets)]")?; =20 let name =3D &input.ident; - let fields =3D get_fields(&input)?; + let fields =3D get_fields(&input, "#[derive(offsets)]")?; let field_names: Vec<&Ident> =3D fields.iter().map(|f| f.ident.as_ref(= ).unwrap()).collect(); let field_types: Vec<&Type> =3D fields.iter().map(|f| &f.ty).collect(); let field_vis: Vec<&Visibility> =3D fields.iter().map(|f| &f.vis).coll= ect(); --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705159; cv=none; d=zohomail.com; s=zohoarc; b=XzaApupNAvlq50ahuNqhMDC2De8v+PRzDvpn1z9/yooN8RwwMRqa7dCIAR75VhLKsdLdtdkW93TfZ4xdjiQQefsOMil+0pEDy/zSPs4oLWJdDmX+Wo/OIvKYz9WpZe5DwGIbeKnxa/zRk3GZOFROeU/H79WqoiYaVBIjPLeHOms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705159; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=01O/MAUKR9Ox+siVKoWDUrcgLu5PuJZFTnesxu9l5+0=; b=MwsvrmqMbY21xsCNZn+oIONZzve58YAEwuzHNxNn4lpwOgRLYP3ILaAgkAPONbOVfY23WDYAG0FPrvzZMl4g8hVp95FpdBFHWmw2Q+xsLCJcSPZjrMBCTm6Kg4tFRRRZssZq6Z1/xwytI15C+x9EGFYyZQRgBjovYdHykOK1ePQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705159663683.523169144689; Fri, 20 Dec 2024 06:32:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1T-0004TP-GL; Fri, 20 Dec 2024 09:30:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe17-0004NE-CG for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe16-0006J7-0w for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:13 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-pQ-IAVwGPEq4BUJs0qiqwA-1; Fri, 20 Dec 2024 09:30:09 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e1339790so1217468f8f.2 for ; Fri, 20 Dec 2024 06:30:09 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c847263sm4175120f8f.50.2024.12.20.06.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=01O/MAUKR9Ox+siVKoWDUrcgLu5PuJZFTnesxu9l5+0=; b=invstnIb/SCLG/R5YWJVH5wdkc/ky7aWU133k1la9s59wVHfIQ0stDH2Y8yfEbz16gqBPz 6xGnHSZajeDo2R9xaqAYk8e/fSMu1Z3PKfsGO53u+MsHHJ9iRm+jNhK3yFwIpSPOYLWQ94 +FnLyHM0DJQjfZeESlZRIlrU9ApGUq4= X-MC-Unique: pQ-IAVwGPEq4BUJs0qiqwA-1 X-Mimecast-MFC-AGG-ID: pQ-IAVwGPEq4BUJs0qiqwA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705008; x=1735309808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=01O/MAUKR9Ox+siVKoWDUrcgLu5PuJZFTnesxu9l5+0=; b=aiZMOH7YNHpspc8ssb/ww+mjl0HhzMKqvMpm9ArP58RgQuz+ls6ikYstVD3KI7qh+G xmyMOw7N3gc7GgMzr8lDP1IbApOmSD7VgyKR3UpThFOW5tg3y+ggVuyht4kPGSiJfvqQ NkIUBIdBY2BzEwi4Z1ot2aBPsFF1abONWe4b+1nngExTlsRWLNwUzDLrDR0cssheecok T4KXffiPnUinnyxH3VxjxFdm9QjT/sQdvA5VP+19hvRjo5pZ8NGQflpG7A2IVEWXXcyZ NIvk2fg/1wqM2oKW3A4sAS3ggLBqUIJcXIhfnfWrg6ik9tgdhpq6ys+LQJJkJ8Mrl7Dp 9rqw== X-Gm-Message-State: AOJu0Yxc7qcCUNclLhtWXHZyLa8vH+qujzmF2NH+hGkvBdKNKqby/cz/ DeE3OMRxUlXaj/9QJqyvay2SkBeiAhd+GovwR/cJdqcuV2HN43KvTw9RvGiN2bE2CvEUtY+FYW3 FoswNXcJ5Jpwa3X+9z7AbgwIgr/WjxiCkHAOtx+XEYU0skDVWe82BhCY8Nvx9/Wk2wjZpnU1zpF AIVduRwPFuoE7aSbgXwXAClLuBGQdOZe4sUe5G X-Gm-Gg: ASbGnctb7Yk3Xis2oZRuNocnRkfhFo9mZtEDvggDMlx9VLDxxDEQxUa3gS1p1jWLJUl +S5js8dk/WGCNChrd8E0vPqGUa07hlFriKpfiKIBfe/WEt+tlT8Zp12U/VSqq6FgQaEHcW0AASW clZst7hZWoZ2tHYOcgse3ldGoXll6DtGEuCobVRK5EWnQkMqZuStRe7/rr4yLq62EHNmG3kYv9A 1fs4bW1h5iGRTPCts8ILGK3f6WDb/gXm0yyVCyzpGrm3RPoFmtRE4oAoV4R X-Received: by 2002:a05:6000:1886:b0:38a:1ba4:d066 with SMTP id ffacd0b85a97d-38a221f3228mr3301005f8f.27.1734705008291; Fri, 20 Dec 2024 06:30:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiP5HukOH7GegtweRyFGDnukgtcjESvzh/R2JhHyHSyefA2NJ44dQYwNxm25grUxPwM6Ewlg== X-Received: by 2002:a05:6000:1886:b0:38a:1ba4:d066 with SMTP id ffacd0b85a97d-38a221f3228mr3300970f8f.27.1734705007900; Fri, 20 Dec 2024 06:30:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 04/12] rust: macros: check that #[derive(Object)] requires #[repr(C)] Date: Fri, 20 Dec 2024 15:29:46 +0100 Message-ID: <20241220142955.652636-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705161218116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 778b698be45..0f04cca3841 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -54,6 +54,8 @@ fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<()= , CompileError> { } =20 fn derive_object_or_error(input: DeriveInput) -> Result { + is_c_repr(&input, "#[derive(Object)]")?; + let name =3D &input.ident; let parent =3D &get_fields(&input, "#[derive(Object)]")?[0].ident; =20 --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705158; cv=none; d=zohomail.com; s=zohoarc; b=mhVVwIKbSi6pu/zTL/Uh1C6EXZ6UbNEgpjykgjFW9oBqK/fRTzCgV5PJhdHNumIAYqxgMXudM+PRY25/AT+enu5YQ6SdwHz6L+DHqus0C3c41iKSUBMTZBpbKqMkXnEfGiHXNWgIzI0T6n5JxYy39ECsfLIKAzE+izIJMYuL9DQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705158; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MFM1GOCm15L/cPIdOg468IxeTeTqWnTkcNuwrJVlvEk=; b=S79l3UWMmc01oOVWxQ9KPvRHf2d5LRnbLdmW8WfZEvdPrNRuvkqOkvokfCv7L/Kcr5eSFLo+KTN8JXtiwZY/U8GJAdudA5jiwQ/r2Q7K08vupNf2UYDdtcS3fj5eEAkupX5cJHkuxEWjnZF9XqJT4G1dXNmTg422GHPf4cWwiFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705158160372.3705966229402; Fri, 20 Dec 2024 06:32:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1Z-0004Un-Hb; Fri, 20 Dec 2024 09:30:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1A-0004Pl-Ux for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe19-0006W7-EB for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:16 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-9CXvubYPO06Rwm7NMJyO7A-1; Fri, 20 Dec 2024 09:30:12 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361b090d23so11560415e9.0 for ; Fri, 20 Dec 2024 06:30:12 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c847214sm4169434f8f.46.2024.12.20.06.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MFM1GOCm15L/cPIdOg468IxeTeTqWnTkcNuwrJVlvEk=; b=UQ3+CzInOQLoxl8M2HvigDBDG345iE4E4Hq4JGU1f+PKDVcxuJst26ljDMZXfpItGtMa0g mjm4Gg5sW5VIBlqYp+WLHd5ssqG9W6u3ScjZXkX7I5S8UNvrakoUO55xXSrdVKNLeF2+vl oI4BcjSm/RkNX5HkVR5w/T7yRs6SlKY= X-MC-Unique: 9CXvubYPO06Rwm7NMJyO7A-1 X-Mimecast-MFC-AGG-ID: 9CXvubYPO06Rwm7NMJyO7A X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705011; x=1735309811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MFM1GOCm15L/cPIdOg468IxeTeTqWnTkcNuwrJVlvEk=; b=QSLLRPC/kQHvv8jZU3ZxJH/53zdgg42C6qVAjtC6Ugxkms2FM4ZM/gNjjfvC924ABz WYcThML2cBT5Gk92yjYwAkFK4UjyH7w8I7WFphA6PvXF1kONH62/tXh95De9/hWEknCZ pHClaQeitfNSQADBR8ngNVta8UxoE7cHF9BQJxUo56q1GgaBXr2sF909VYGip4GWtHsB LC7cnN11YxY3zzwCtMfxRudmkzB4idPEq4LsOjzHjZ5iOOef92zNwy4paKoQvHSx9Ho/ DGcdL2UBOVYPg3nCwmSEIGC86rcRtozK0oB/kJYIUFiOaNgGvl6UDc69i9W9GWaBtfqa 6zbA== X-Gm-Message-State: AOJu0YyqQ/q21iodLQtSmsas791zz4Ne7Opz0mOx3ek+vdmbmYrGFHCx rSiAYh+C9M6DcQ2mFFIxDyBzbwG3441qbc+lbPojuqu67qiahLaQ+Nt93Rky3obr9IPl4WJvVKw qtK1r9E2tcaYK1p6Vo47eVIrTFijKzr4dMu0yV6rl4Jrti9QF+bNlaG55VhWXEc/olKgUmuWNYI Wa9QK9nuEAqmpn6iR6MfaUsmwekfamXMHjbRVv X-Gm-Gg: ASbGncumuYXBKsYm8j3a7i3Uo19zCTsk2ZyLcbMopUNAczvDEvpdJWTzIK13gNATMrI kqWzXMhJllpyflWTvr3bYaXpJHqK5hL0WaY8BW8iLh9VWtQIJSKRErRuPmXApo0ttYdfbCjF0iY C0Jm1mZMVzuYta+JwXQ6smnw6rTVScojH/yP0a1kdG6qwu1aga0fVWsOqWwckviOgcVPsppd1jj 1TiIlRD4MLGY3NdL/cTZg5TwZHkX6tTs/ZXW4CqWcAhgwUfZxLcF930fyZY X-Received: by 2002:a5d:47a8:0:b0:385:eb17:cd3d with SMTP id ffacd0b85a97d-38a221f2ff4mr2920449f8f.8.1734705010845; Fri, 20 Dec 2024 06:30:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsBlOLZUrNwaMzIzkMoAZdbg7ZYA+lJtaTNcbzaEE8SW0FAHEdFEOqVd9ww/3VkaZ2sjX6fA== X-Received: by 2002:a5d:47a8:0:b0:385:eb17:cd3d with SMTP id ffacd0b85a97d-38a221f2ff4mr2920422f8f.8.1734705010492; Fri, 20 Dec 2024 06:30:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 05/12] rust: qom: automatically use Drop trait to implement instance_finalize Date: Fri, 20 Dec 2024 15:29:47 +0100 Message-ID: <20241220142955.652636-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705159215116600 Content-Type: text/plain; charset="utf-8" Replace the customizable INSTANCE_FINALIZE with a generic function that drops the Rust object. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/qom.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 1341a173893..861f1e50ac4 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -180,6 +180,16 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<()= , fmt::Error> { T::class_init(unsafe { &mut *klass.cast::() }) } =20 +unsafe extern "C" fn drop_object(obj: *mut Object) { + // SAFETY: obj is an instance of T, since drop_object is called + // from the QOM core function object_deinit() as the instance_finalize + // function for class T. Note that while object_deinit() will drop the + // superclass field separately after this function returns, `T` must + // implement the unsafe trait ObjectType; the safety rules for the + // trait mandate that the parent field is manually dropped. + unsafe { std::ptr::drop_in_place(obj.cast::()) } +} + /// Trait exposed by all structs corresponding to QOM objects. /// /// # Safety @@ -438,7 +448,6 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl { =20 /// Whether the object can be instantiated const ABSTRACT: bool =3D false; - const INSTANCE_FINALIZE: Option =3D None; =20 /// Function that is called to initialize an object. The parent class= will /// have already been initialized so the type is only responsible for @@ -474,7 +483,7 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl { None =3D> None, Some(_) =3D> Some(rust_instance_post_init::), }, - instance_finalize: Self::INSTANCE_FINALIZE, + instance_finalize: Some(drop_object::), abstract_: Self::ABSTRACT, class_size: core::mem::size_of::(), class_init: Some(rust_class_init::), --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705107; cv=none; d=zohomail.com; s=zohoarc; b=C+fXwH9oMswNq7+PllKp/7JgkgRlIVK97/rbgXfZK++EZsULtuGOySif3OLfr/Z5UuXkq30zlypeet+5Vk8aFmN/9DdqIGbvSlPfCTBx08iyIcFgHZAWhruRAKyC8ZsXQQRlAAQDSk/9jecC7LVwN8UgMUi96jZfTf6n0RqMYt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705107; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s6nygS97dluqx/BeGp3uSmNclmtr8ycVi93iMqAtirw=; b=hHDz5ohz0OUBsWXcf3HogLVS9e9Mobla4irMnipbzOALQQP/z3XJOzO24aacqIbM1fQaz1lEwXvUyl3rYfKzk+URVNlLbnd6HTXWwJvAl/it77HSgalRwMSh4UMtwOXDD4Vvq7E7vuvXrqjMnKPXxAxJoVkOOQO6dBbvZL/AUKM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705107696582.974549431632; Fri, 20 Dec 2024 06:31:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1d-0004Yg-0x; Fri, 20 Dec 2024 09:30:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1F-0004RP-Rp for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1D-0006Zn-80 for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:20 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-9SU16gcNOpmwkdiZ6S-30Q-1; Fri, 20 Dec 2024 09:30:14 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43610eba55bso15129105e9.3 for ; Fri, 20 Dec 2024 06:30:14 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656b119ccsm81386065e9.24.2024.12.20.06.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s6nygS97dluqx/BeGp3uSmNclmtr8ycVi93iMqAtirw=; b=hbyxJrsumY7grtRxAi60qNz8+jZDZM60SvpTc88W8XObeAYjGyvRBklOFcLjdow7TdGR28 2ejQvBtRCusAkHykp9COqc1o4w5n73w9faaQQoy3skQnzv67W4LVGeHBfcGx6iSuHxLV/j N18jJX/yyI5JuKgycJiby35r5b0qxXs= X-MC-Unique: 9SU16gcNOpmwkdiZ6S-30Q-1 X-Mimecast-MFC-AGG-ID: 9SU16gcNOpmwkdiZ6S-30Q X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705013; x=1735309813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s6nygS97dluqx/BeGp3uSmNclmtr8ycVi93iMqAtirw=; b=uunILdms2Nt3mC4fafjROzb+ITbw5Chwo+P/FSLrsja74oQE+7khgxqVX1y/L8C37r c35qFHV9pL+rjRZPxCoByMLXMOIJ6ZK+oPG9Eluk/Bm+sH467iqVp0MuxrrSN3CUEA4o SzPzP5l4UffCuvE8Txo53xY9GY9PsX3BfbbU2RtK/6Fc9Dj7qhpws4Vxb5DcEEfhzCCy S395BFNa8MumSLuP1mw4MSf+s0C5ZYLLt1cx7BA30EKSAINfh7RywPqoyecRWFyvHanW ZvtcU+6i+DMpR7mDxo85JvXpnLjK/OVT6s6w5xk3UjYiwyAQiX2asJYUJbCGKweP8AzK MSsA== X-Gm-Message-State: AOJu0Yxy1gVixSUWJXf3MQzz9zJIYYVal5PJFLjsmgdG2mxfB31/n7NQ +3rdcX5dliDb/s1PRG/vPWJewJDkEGho8M5MOx2Hci3BKZ8J2yxawyNx6lCTVo4GFi3l6q4OYlk 38aTulcOGfngRVHfKwDUGW8ZFBr10Q8CFohng/OpCiyokFIS2WQvNwVNsH1yKel17r4xqElZyan 8MtM0MDuMFHjcQyr51i1ylzXtAAlTXO4OWdOCx X-Gm-Gg: ASbGncu99KKhpDe+KSXFIPukamMMfIE1xq/6ZYvf4ot9raUqQtoQAsEz7fu2GGA84qK zuU0Jzb8U6Jul2pFUBsk2VdzfngBLJdSyzRJ/oG+WT6/1btSxc0x7pJhRXC05GDbxruOj16cGa/ 8vMKa/Qb7ZLrDJ+Q+DrMQV3keXLgWyqk8L4eLGaikqClicXBBsUuNd+3is7N3ux7eXlVAjVte0/ W+bn3VBCVZgDK9mb+aV9Fxi/U7w6EICG9DpaO+lbffvR8QmMRfZuF6blwUZ X-Received: by 2002:a05:600c:524c:b0:434:edcf:7474 with SMTP id 5b1f17b1804b1-43668b93c61mr23054155e9.33.1734705012880; Fri, 20 Dec 2024 06:30:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRBzfFniF4aiwf7rQItG/gdmPYjXGEn2f00FBMhasWdZgWSbzoExjwoyxTtHmrzLnCjc3Z3g== X-Received: by 2002:a05:600c:524c:b0:434:edcf:7474 with SMTP id 5b1f17b1804b1-43668b93c61mr23053905e9.33.1734705012500; Fri, 20 Dec 2024 06:30:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 06/12] rust: qom: move device_id to PL011 class side Date: Fri, 20 Dec 2024 15:29:48 +0100 Message-ID: <20241220142955.652636-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705109117116600 Content-Type: text/plain; charset="utf-8" There is no need to monkeypatch DeviceId::Luminary into the already-initial= ized PL011State. Instead, now that we can define a class hierarchy, we can defi= ne PL011Class and make device_id a field in there. There is also no need anymore to have "Arm" as zero, so change DeviceId int= o a wrapper for the array; all it does is provide an Index implementati= on because arrays can only be indexed by usize. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 59 +++++++++++++++----------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 689202f4550..215f94a6e4a 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -5,7 +5,7 @@ use core::ptr::{addr_of_mut, NonNull}; use std::{ ffi::CStr, - os::raw::{c_int, c_uchar, c_uint, c_void}, + os::raw::{c_int, c_uint, c_void}, }; =20 use qemu_api::{ @@ -14,7 +14,7 @@ irq::InterruptSource, prelude::*, qdev::DeviceImpl, - qom::{ObjectImpl, ParentField}, + qom::{ClassInitImpl, ObjectImpl, ParentField}, }; =20 use crate::{ @@ -33,27 +33,20 @@ /// QEMU sourced constant. pub const PL011_FIFO_DEPTH: u32 =3D 16; =20 -#[derive(Clone, Copy, Debug)] -enum DeviceId { - #[allow(dead_code)] - Arm =3D 0, - Luminary, -} +#[derive(Clone, Copy)] +struct DeviceId(&'static [u8; 8]); =20 impl std::ops::Index for DeviceId { - type Output =3D c_uchar; + type Output =3D u8; =20 fn index(&self, idx: hwaddr) -> &Self::Output { - match self { - Self::Arm =3D> &Self::PL011_ID_ARM[idx as usize], - Self::Luminary =3D> &Self::PL011_ID_LUMINARY[idx as usize], - } + &self.0[idx as usize] } } =20 impl DeviceId { - const PL011_ID_ARM: [c_uchar; 8] =3D [0x11, 0x10, 0x14, 0x00, 0x0d, 0x= f0, 0x05, 0xb1]; - const PL011_ID_LUMINARY: [c_uchar; 8] =3D [0x11, 0x00, 0x18, 0x01, 0x0= d, 0xf0, 0x05, 0xb1]; + const ARM: Self =3D Self(&[0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0= xb1]); + const LUMINARY: Self =3D Self(&[0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x= 05, 0xb1]); } =20 // FIFOs use 32-bit indices instead of usize, for compatibility with @@ -126,17 +119,28 @@ pub struct PL011State { pub clock: NonNull, #[doc(alias =3D "migrate_clk")] pub migrate_clock: bool, - /// The byte string that identifies the device. - device_id: DeviceId, } =20 qom_isa!(PL011State : SysBusDevice, DeviceState, Object); =20 +pub struct PL011Class { + parent_class: ::Class, + /// The byte string that identifies the device. + device_id: DeviceId, +} + unsafe impl ObjectType for PL011State { - type Class =3D ::Class; + type Class =3D PL011Class; const TYPE_NAME: &'static CStr =3D crate::TYPE_PL011; } =20 +impl ClassInitImpl for PL011State { + fn class_init(klass: &mut PL011Class) { + klass.device_id =3D DeviceId::ARM; + >::class_init(&mut klass.= parent_class); + } +} + impl ObjectImpl for PL011State { type ParentType =3D SysBusDevice; =20 @@ -214,7 +218,8 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -= > std::ops::ControlFlow> 2)) =3D> { - u32::from(self.device_id[(offset - 0xfe0) >> 2]) + let device_id =3D self.get_class().device_id; + u32::from(device_id[(offset - 0xfe0) >> 2]) } Err(_) =3D> { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset = 0x%x\n", (int)offset); @@ -648,16 +653,10 @@ pub struct PL011Luminary { parent_obj: ParentField, } =20 -impl PL011Luminary { - /// Initializes a pre-allocated, unitialized instance of `PL011Luminar= y`. - /// - /// # Safety - /// - /// We expect the FFI user of this function to pass a valid pointer, t= hat - /// has the same size as [`PL011Luminary`]. We also expect the device = is - /// readable/writeable from one thread at any time. - unsafe fn init(&mut self) { - self.parent_obj.device_id =3D DeviceId::Luminary; +impl ClassInitImpl for PL011Luminary { + fn class_init(klass: &mut PL011Class) { + klass.device_id =3D DeviceId::LUMINARY; + >::class_init(&mut klass.= parent_class); } } =20 @@ -670,8 +669,6 @@ unsafe impl ObjectType for PL011Luminary { =20 impl ObjectImpl for PL011Luminary { type ParentType =3D PL011State; - - const INSTANCE_INIT: Option =3D Some(Self::init); } =20 impl DeviceImpl for PL011Luminary {} --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705061; cv=none; d=zohomail.com; s=zohoarc; b=HcOsuC1smLwZGMu6LiXY+lTckfWm8so0EyCrc7uQZ3GdrEyaG33F5oDeLFjmDp2OmCxA9Sy/ViiOpkVFkyeiWeM7FpHCdFmODpLLqxq4jUm5n6UT6JfRvPfWThy2DsnziTM9inx/iZxwYKlf/cf4QpUYWfCUSlCXhJMAYPK72tI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705061; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MBnoMQiocVwxb195C5dPLUMqfWHTI2r8yktVChDs01k=; b=YzjO6EzzjtDiy1eKIQaIzWljb/trJi8IznInnHR7dBEwH/Nclj+LlePAfWEVE1bAPHESt2+T2QghZkCzByqfPFnF8YsqBUBE9ra8KwZeosOdDZv7kT03W2bQqFftmmNHFJ8FPItsvBY5vQE6R/cMBCmCmT2gekMUk8yIymrsNOU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 173470506196683.42980300014051; Fri, 20 Dec 2024 06:31:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1W-0004UM-Rq; Fri, 20 Dec 2024 09:30:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1E-0004RA-OH for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1C-0006Zt-Ue for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:20 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-rRHoOZWWMOKcxJpXQp3TJg-1; Fri, 20 Dec 2024 09:30:16 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43646b453bcso11453005e9.3 for ; Fri, 20 Dec 2024 06:30:16 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4366128a44fsm46908405e9.43.2024.12.20.06.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MBnoMQiocVwxb195C5dPLUMqfWHTI2r8yktVChDs01k=; b=dqYcT0NMIQZcmBDqtvaoqioVIxKNURgw522bF2QFnXmcptIvPVsp5BeE5ThrEM/iBYSIq3 GVgKXd62i1ZgPyJsbjL4OGGPvslzWlwJATXiRJdUnm4t7UTKCVL85G32ePytFrtKUd0gM4 uYQqVO3eXGL5RW9xSl8csfaA+o6/l7k= X-MC-Unique: rRHoOZWWMOKcxJpXQp3TJg-1 X-Mimecast-MFC-AGG-ID: rRHoOZWWMOKcxJpXQp3TJg X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705015; x=1735309815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MBnoMQiocVwxb195C5dPLUMqfWHTI2r8yktVChDs01k=; b=X+ZwjPRB3XiniGlHxrbldkg6PkGNnUkukNSg3vdEVtIN7NewO7kgbj1oHZ3RuAuwsp AIJ9N4KnaXbCwAOV9G7SzMa1i5b9YQA+lOXXf7R3BOLqeeO40q7Ys8ETQY5Fg34QNh9G ilzSCouDDI6OAXGnIbaG90hL3rkAMV6AXF6qFUQgpcPLoerLnmxarPb1rfT5xPVWH4TP SSK99lgGRyVvDC9O2u+X/o3OW4vqQ2rMcFdsV39elvzWQunyVRbxZRqX0fdElEDdgoqg /5xynV9UKbNdfNNX9P7RY1d8s0MbgU6RtJaInGQO4+DdTuej0F37RgygG9BF5ZIxnGx0 5ggA== X-Gm-Message-State: AOJu0Ywd8E8dnLDACkJ32644t6ToFghXZliMoPuDxOg8bdtfelEDpy/o 8a0Xfu634U/wdyKspxmIbt2ZyOQBBrLvznh5giGxVbY5cvHGg6UTsmrP4wdMOvebgYlTgDCHybR ZEl3B9mB3dXBmXrD0vBr4c1R4kFY8Zdkm+A3UqwaQcVE2FhLyz/Bes2JUxWpqTO9p5ZVYrFVXRE p05uV2vSOAm8cuotAA91sZmvqplzf69pZIro0R X-Gm-Gg: ASbGncuNFESj/3ARyoLsLB68KkRGk74FHK7GzPjaEiahC/kPn2IJxJ3/2koBl/pit5A G86vkfiuJMVaLa6ipqWQV5xwartB8i8JqpUoUmCbJ68XYZ4Gx6METaNyX3l9q9KxweEjzWFS9vC TcqdCJEJea4/IHxZsgSRl3gFJmNIiGM+DB9WH5WpgHSdgejZ1yWEeKS2DtRb9FzvljRm7KwxH+r Z237qtspxcks5xVJWT93U3tUbBu9sitN1O5oE2nPEOI0gltaTsrjdqDeez2 X-Received: by 2002:a05:600c:1c0b:b0:436:1ac2:1ad2 with SMTP id 5b1f17b1804b1-436686469d0mr27737375e9.19.1734705014991; Fri, 20 Dec 2024 06:30:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHl+ewunVjR6mCinfVZP+thQDwAsqkHpYJCgLoAuS8zEHmuseEDKxqGa6DmjfD0VI9ZoD7XUA== X-Received: by 2002:a05:600c:1c0b:b0:436:1ac2:1ad2 with SMTP id 5b1f17b1804b1-436686469d0mr27737085e9.19.1734705014576; Fri, 20 Dec 2024 06:30:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 07/12] rust: pl011: only leave embedded object initialization in instance_init Date: Fri, 20 Dec 2024 15:29:49 +0100 Message-ID: <20241220142955.652636-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705062711116600 Content-Type: text/plain; charset="utf-8" Leave IRQ and MMIO initialization to instance_post_init. In Rust the two callbacks are more distinct, because only instance_post_init has a fully initialized object available. While at it, add a wrapper for sysbus_init_mmio so that accesses to the SysBusDevice correctly use shared references. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 18 ++++++++++-------- rust/qemu-api/src/sysbus.rs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 215f94a6e4a..72a4cea042c 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -145,6 +145,7 @@ impl ObjectImpl for PL011State { type ParentType =3D SysBusDevice; =20 const INSTANCE_INIT: Option =3D Some(Self::init); + const INSTANCE_POST_INIT: Option =3D Some(Self::post_in= it); } =20 impl DeviceImpl for PL011State { @@ -183,14 +184,6 @@ unsafe fn init(&mut self) { Self::TYPE_NAME.as_ptr(), 0x1000, ); - - let sbd: &mut SysBusDevice =3D self.upcast_mut(); - sysbus_init_mmio(sbd, addr_of_mut!(self.iomem)); - } - - for irq in self.interrupts.iter() { - let sbd: &SysBusDevice =3D self.upcast(); - sbd.init_irq(irq); } =20 // SAFETY: @@ -213,6 +206,15 @@ unsafe fn init(&mut self) { } } =20 + fn post_init(&mut self) { + let sbd: &SysBusDevice =3D self.upcast(); + + sbd.init_mmio(&self.iomem); + for irq in self.interrupts.iter() { + sbd.init_irq(irq); + } + } + pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::Con= trolFlow { use RegisterOffset::*; =20 diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs index 8193734bde4..b96eaaf25f2 100644 --- a/rust/qemu-api/src/sysbus.rs +++ b/rust/qemu-api/src/sysbus.rs @@ -38,6 +38,18 @@ const fn as_mut_ptr(&self) -> *mut SysBusDevice { addr_of!(*self) as *mut _ } =20 + /// Expose a memory region to the board so that it can give it an addr= ess + /// in guest memory. Note that the ordering of calls to `init_mmio` is + /// important, since whoever creates the sysbus device will refer to t= he + /// region with a number that corresponds to the order of calls to + /// `init_mmio`. + pub fn init_mmio(&self, iomem: &bindings::MemoryRegion) { + assert!(bql_locked()); + unsafe { + bindings::sysbus_init_mmio(self.as_mut_ptr(), addr_of!(*iomem)= as *mut _); + } + } + /// Expose an interrupt source outside the device as a qdev GPIO outpu= t. /// Note that the ordering of calls to `init_irq` is important, since /// whoever creates the sysbus device will refer to the interrupts with --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705103; cv=none; d=zohomail.com; s=zohoarc; b=lzGPn4k7TxTYM6CKzlR0KUxdkA8xkI43zu3HH/q6nis9yOju/I4ifxcuyOSW5jWe+JZz9SObfo//vDg/6lb6fs1siS9O23pnbzqq++O/HMMo1g73+vqxaOO9yBT0/VCvRpaFu2sDsxdwhVF7VFQKYcZ4sPI8VvY6eshe7mBiMoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=u9nMTxyosvlBNmWHbdS3uU97thxBhf1W17a5325xukk=; b=RBMilDGhScylN1JKy1pX195tLVoLJ/uZrh9LRtmpmC+Lrar6KoLdiGKJbCk0H5pXe7p01N8YN0L6pCe+fKW/nM2zXRC4A81BmJvH7G5VOAjoi2yanm0DR1Nc7Bg5h81Va8/UbvtM4Fv8YnfU2gc+EK+h72sf0pxEx4OXYs+2s/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705103254236.70623281785868; Fri, 20 Dec 2024 06:31:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe26-0004ye-VN; Fri, 20 Dec 2024 09:31:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1K-0004Ra-C2 for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1I-0006ao-Py for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:26 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-jzTjaoisM32Xt8q1yzda4w-1; Fri, 20 Dec 2024 09:30:19 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43621907030so16664235e9.1 for ; Fri, 20 Dec 2024 06:30:19 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8b874asm4149698f8f.109.2024.12.20.06.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u9nMTxyosvlBNmWHbdS3uU97thxBhf1W17a5325xukk=; b=Fl6Xa/O/Z5tGLfmnQRsnt8p09Hk7zi0UCOl2lv+bSTri4Aej6SVdpe0Iz5sbdwtVwB+2lm qymcNpyfCMmz/L/s7gEUyzV6GT9ZzEW4PWmPCWVDYJ4OQrsKWHBLIioADeNi85qHa7e5++ PhVrwh8QFC8n3xNwaDxxmB/RrJ5pQpM= X-MC-Unique: jzTjaoisM32Xt8q1yzda4w-1 X-Mimecast-MFC-AGG-ID: jzTjaoisM32Xt8q1yzda4w X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705017; x=1735309817; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u9nMTxyosvlBNmWHbdS3uU97thxBhf1W17a5325xukk=; b=qjCzb2/7nudZhK6gzx39ZJIaRHU+ikSYfHVYu4iFVrEyM4hojahp8QkpyYCaE41LM/ QcLG9axYhNIR2t+fQj+uFNsKYc68jpoaMPRRRR7uKEL4ZbZM0Qiss0R4ssTn2qAJNdTd 8lLvU32t5m3qH/MRzvqCNpJRIKElb+LTCtPgidzB9mY+gySzE0z0CTgN4kz43gocC9Uj to1hl6YN0sshr3GUNmpXKFXuS6WEhjxi3SEjztAGXN79EIsp2pc7mpk9IH+721OOhYSN wXn0+6IggUIjsxz2CCbUKAO+0WwIbj1pOaYVF3KthKN16mZXaY6dKB/cg/BIp3j3oODs DJoA== X-Gm-Message-State: AOJu0YyYe1FXcjN6vmQDzETy0BiiH1LvxpgeBpQs3F1G1B4tKUH6ztd5 rhMQR7+xbhF1LwIuHUvI+w0QdrC2LDOVUJz1QnXQ2k+kABs+uBAs07Yx+q2WfyELPqKQo9kezk5 nZ+HApCHLDw/xXAb9l4NkH6ZkXSmSOurVfarurDkxICMJp+GFhRbz5ow60y11+oWTI91azz8kd+ Y0VscF9KzQ/IYkVxbV/TYvBfY5aVWB8qw8iDOT X-Gm-Gg: ASbGncsmD2GmE6ljXsFghKMDpklSfuaHZPaqhWBTsZQw6zR34hXsXSsJeXOoP+dy8ru qch6H9O86CvwZGeX4wZbNkzrSKkQS5qBqSUGmeMOtKX9F03GKszPx870LPLXVrJBLPptyR7dbZ2 sOQ/eGNYmp3Ie35CLs+R6RzjbW+LoOoL7DOR3UzNQtrMEsYkGyBA7qyodHQPaKWzvHs/5DPKSMR mkabT8T8/ZvMo0a5DOFI4MQQ41gJxVqvEk/pbteTuRlNH++581lRgCnqyXd X-Received: by 2002:a5d:6f16:0:b0:382:40ad:44b2 with SMTP id ffacd0b85a97d-38a221fadadmr3226265f8f.34.1734705017594; Fri, 20 Dec 2024 06:30:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMdSfYDHnwHgFPcEvubGZ+vNK9FWo7WkKZ58ryPBo0nFuBdtxeEjxS9+aS35ZbKylegm5Keg== X-Received: by 2002:a5d:6f16:0:b0:382:40ad:44b2 with SMTP id ffacd0b85a97d-38a221fadadmr3226233f8f.34.1734705017138; Fri, 20 Dec 2024 06:30:17 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 08/12] rust: qom: make INSTANCE_POST_INIT take a shared reference Date: Fri, 20 Dec 2024 15:29:50 +0100 Message-ID: <20241220142955.652636-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705104954116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 4 ++-- rust/qemu-api/src/qom.rs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 72a4cea042c..6792d13fb77 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -145,7 +145,7 @@ impl ObjectImpl for PL011State { type ParentType =3D SysBusDevice; =20 const INSTANCE_INIT: Option =3D Some(Self::init); - const INSTANCE_POST_INIT: Option =3D Some(Self::post_in= it); + const INSTANCE_POST_INIT: Option =3D Some(Self::post_init); } =20 impl DeviceImpl for PL011State { @@ -206,7 +206,7 @@ unsafe fn init(&mut self) { } } =20 - fn post_init(&mut self) { + fn post_init(&self) { let sbd: &SysBusDevice =3D self.upcast(); =20 sbd.init_mmio(&self.iomem); diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 861f1e50ac4..5934eb0cc50 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -163,11 +163,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<()= , fmt::Error> { // SAFETY: obj is an instance of T, since rust_instance_post_init // is called from QOM core as the instance_post_init function // for class T - // - // FIXME: it's not really guaranteed that there are no backpointers to - // obj; it's quite possible that they have been created by instance_in= it(). - // The receiver should be &self, not &mut self. - T::INSTANCE_POST_INIT.unwrap()(unsafe { &mut *obj.cast::() }) + T::INSTANCE_POST_INIT.unwrap()(unsafe { &*obj.cast::() }) } =20 unsafe extern "C" fn rust_class_init>( @@ -459,7 +455,7 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl { =20 /// Function that is called to finish initialization of an object, once /// `INSTANCE_INIT` functions have been called. - const INSTANCE_POST_INIT: Option =3D None; + const INSTANCE_POST_INIT: Option =3D None; =20 /// Called on descendent classes after all parent class initialization /// has occurred, but before the class itself is initialized. This --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705093; cv=none; d=zohomail.com; s=zohoarc; b=b5iEl8z+Ia5xt+8NY/FwWfaOxsplUa8mTjKM3QzTtZFOaQ0SDI6Ej6rR/r7RGXJ7ANBmzN3A3u0xHu7ZODmyenLnUZr8B5yCPEr7p75HugvlpPVAYNzIYKqr4VmRe6mpW9RAuy5N/soEY/78HCiek/iQNdaKe9HDOWhzbcqoptY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705093; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oLxf8SYyc8CAW4GO5JtinxFGsZxKuKqfgDppOT1xqOU=; b=bilaFIUREgAtjQpKh1qExmHxdTfIQscBJTQXqGlGhHUKXOAC6w1zmDmusZ0b8V4mypvMR6F0/OeVpUDXuIs1kZ9jxImMAuk/fyj3swg4iSestxt6EsNNOgYNDcIPhm782HeE5LD3jyjn8/xp7ON0Iq4ffGdpCiWN/I8jIrqtyVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705093217408.7779124923567; Fri, 20 Dec 2024 06:31:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1V-0004UG-1p; Fri, 20 Dec 2024 09:30:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1N-0004SA-Lb for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1K-0006bF-SN for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:28 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-Qf08Vmz2PMOv96ystZmCyQ-1; Fri, 20 Dec 2024 09:30:21 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361a8fc3bdso11135455e9.2 for ; Fri, 20 Dec 2024 06:30:21 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8a6abesm4186372f8f.90.2024.12.20.06.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oLxf8SYyc8CAW4GO5JtinxFGsZxKuKqfgDppOT1xqOU=; b=Y8k9W6zO5586ykU6BdGydZnLEKMbaTIZ7z2gQDUW0IcmZ8mF2be1xAU/YoOYmUgEhYyKwl 7YV6LKWVXAq+pChZ8MkTOjl5Eil5C4isNthct1vMSTCzsvWNTf7C3AFLDn065sf8eULZ6g 9xUDASF7PEyUl39l4am9qj8iXITCtng= X-MC-Unique: Qf08Vmz2PMOv96ystZmCyQ-1 X-Mimecast-MFC-AGG-ID: Qf08Vmz2PMOv96ystZmCyQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705020; x=1735309820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oLxf8SYyc8CAW4GO5JtinxFGsZxKuKqfgDppOT1xqOU=; b=Jnym0RuAmTeZ4BEC5lbBsGxri8CWBcdJRiNCwUQS67/nIdUGfhCb7d2Oqq/S/Y/isX N7GBBt4iWTqKThs+UIyANitByKRK/GJ+ct8PA8yntMioQQSgVUtnyOniXQsFL/GtL9Xx FR27BsWuqrLhsnQGPbPeMjuVIzZsqueWVtC8mwWB8LQxbh1bhtxYD5nu56PLnzRAIdvV BjZkq+fqR4IR/OpPlgSQn/9ZMpkF811qJCXeJc7CycHzfA1g+BP/gfCyBZA+3UR9Ng4f UBOIHJZsbPatiuJQHJUQoagfReHQRp53gAL9WmglHiTMxlR2c9K2oByoCKvhcXMdOMBU 7FnQ== X-Gm-Message-State: AOJu0YzglDfwPxa9Vp4h9k6fEHx3v1MKFGboevyDc7M7vtY9tnnLz/Oh 84Z/XWZrayc2ofX9O9fZiu0fH3+1t51WX9YLtj435cd2LMtr1N8idklRwRBaQ1xOZR9WmtjGK/h fKvRwEq4RxGz2bpO6NBrsvUa6IY62YDWpDTLxnTlB0qhkNy2zSZdrJj3T6kFxvQgn9vH6/WJPx9 WmYIsVKZM/WAE4kkktiYKKu6EUjHvXhqF7q3n4 X-Gm-Gg: ASbGncsI1VyOsBWLNYdL2uTePlo1LJngWlpCzXqjNgACLm9oNatG3bHoYEP+lQzv2dc QKm0Lny5zb0fJ63cwWN5YRht6h/8KGFZR49VsrpiarbrlUboc+1h30RhG6gC/CiH3elOILwC/tD fpNVO30WvskP3bUxyvOTsj5CpmVtQYH5vdBOO1S3L/d3MWBfTM+83u0INR8iXZvMSRjLg2ATqqR 1eCU5UX/35SxN2LZy+B1Y3tAfYDmRUqJXz/28p2hOVLXDFR5edCanH7jNRy X-Received: by 2002:a05:600c:4f09:b0:434:a711:ace4 with SMTP id 5b1f17b1804b1-4366864636dmr28668225e9.17.1734705019643; Fri, 20 Dec 2024 06:30:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+NnV0YF5Sr7YZ3y8TjPcAqyNNQXLBS8X8FBLy35qksVx98k94lBzfvCM1SFQ8v9Rv56x/0w== X-Received: by 2002:a05:600c:4f09:b0:434:a711:ace4 with SMTP id 5b1f17b1804b1-4366864636dmr28667835e9.17.1734705019127; Fri, 20 Dec 2024 06:30:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 09/12] rust: qdev: expose inherited methods to subclasses of SysBusDevice Date: Fri, 20 Dec 2024 15:29:51 +0100 Message-ID: <20241220142955.652636-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705094969116600 Content-Type: text/plain; charset="utf-8" The ObjectDeref trait now provides all the magic that is required to fake inheritance. Replace the "impl SysBusDevice" block of qemu_api::sysbus with a trait, so that sysbus_init_irq() can be invoked as "self.init_irq()" without any intermediate upcast. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ++---- rust/qemu-api/src/irq.rs | 3 +-- rust/qemu-api/src/prelude.rs | 2 ++ rust/qemu-api/src/sysbus.rs | 17 +++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 6792d13fb77..994c2fc0593 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -207,11 +207,9 @@ unsafe fn init(&mut self) { } =20 fn post_init(&self) { - let sbd: &SysBusDevice =3D self.upcast(); - - sbd.init_mmio(&self.iomem); + self.init_mmio(&self.iomem); for irq in self.interrupts.iter() { - sbd.init_irq(irq); + self.init_irq(irq); } } =20 diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs index 6258141bdf0..378e5202951 100644 --- a/rust/qemu-api/src/irq.rs +++ b/rust/qemu-api/src/irq.rs @@ -24,8 +24,7 @@ /// /// Interrupts are implemented as a pointer to the interrupt "sink", which= has /// type [`IRQState`]. A device exposes its source as a QOM link property= using -/// a function such as -/// [`SysBusDevice::init_irq`](crate::sysbus::SysBusDevice::init_irq), and +/// a function such as [`SysBusDeviceMethods::init_irq`], and /// initially leaves the pointer to a NULL value, representing an unconnec= ted /// interrupt. To connect it, whoever creates the device fills the pointer= with /// the sink's `IRQState *`, for example using `sysbus_connect_irq`. Beca= use diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index 6f32deeb2ed..4ea70b9c823 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -16,3 +16,5 @@ pub use crate::qom::ObjectType; =20 pub use crate::qom_isa; + +pub use crate::sysbus::SysBusDeviceMethods; diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs index b96eaaf25f2..e6762b5c145 100644 --- a/rust/qemu-api/src/sysbus.rs +++ b/rust/qemu-api/src/sysbus.rs @@ -32,18 +32,17 @@ fn class_init(sdc: &mut SysBusDeviceClass) { } } =20 -impl SysBusDevice { - /// Return `self` cast to a mutable pointer, for use in calls to C cod= e. - const fn as_mut_ptr(&self) -> *mut SysBusDevice { - addr_of!(*self) as *mut _ - } - +/// Trait for methods of [`SysBusDevice`] and its subclasses. +pub trait SysBusDeviceMethods: ObjectDeref +where + Self::Target: IsA, +{ /// Expose a memory region to the board so that it can give it an addr= ess /// in guest memory. Note that the ordering of calls to `init_mmio` is /// important, since whoever creates the sysbus device will refer to t= he /// region with a number that corresponds to the order of calls to /// `init_mmio`. - pub fn init_mmio(&self, iomem: &bindings::MemoryRegion) { + fn init_mmio(&self, iomem: &bindings::MemoryRegion) { assert!(bql_locked()); unsafe { bindings::sysbus_init_mmio(self.as_mut_ptr(), addr_of!(*iomem)= as *mut _); @@ -54,10 +53,12 @@ pub fn init_mmio(&self, iomem: &bindings::MemoryRegion)= { /// Note that the ordering of calls to `init_irq` is important, since /// whoever creates the sysbus device will refer to the interrupts with /// a number that corresponds to the order of calls to `init_irq`. - pub fn init_irq(&self, irq: &InterruptSource) { + fn init_irq(&self, irq: &InterruptSource) { assert!(bql_locked()); unsafe { bindings::sysbus_init_irq(self.as_mut_ptr(), irq.as_ptr()); } } } + +impl SysBusDeviceMethods for R where R::Target: IsA {} --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705149; cv=none; d=zohomail.com; s=zohoarc; b=TNjs6OvuutwykCh5v8PPPk7P7I9ZMXdtz5oeHEIfm78Aalff6nMSroiru7cMx0GmphVbf5TpCvmvSPb43BjPYcYanc6usxukt7B4plI8htZGpf0tG6YMi58kfYtH/4UlawXW5Ix0fP4qg+LvZCzy1a8vp5JiehH3zQOVbbECVyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705149; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Szoag27KIkqUli3n0xSrTUcaxn0aravcRGL/6Nt+Rm8=; b=OBmWbJZDqD6+5SxOw5lhcJEIR6BjYgwbniMbupFaGK3EGswjW6MCdHlrOtXNSVCWL/LRel5qR7shVuQJ3urIeNHZLYiu4V5wap5Ru0sxDdY+tbRFsyr1f9BcTtE0hSz0wYxQl+Zhq64Yr0yypGAu5x63hKRymLId3/z24YyRHY8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705148936477.1506540509813; Fri, 20 Dec 2024 06:32:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1W-0004UK-4z; Fri, 20 Dec 2024 09:30:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1P-0004Sn-BC for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1L-0006bP-8M for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:30 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-AEFODpjZPZ6tQICh2AhyoA-1; Fri, 20 Dec 2024 09:30:24 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385d735965bso1178949f8f.1 for ; Fri, 20 Dec 2024 06:30:24 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8330d4sm4154986f8f.29.2024.12.20.06.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Szoag27KIkqUli3n0xSrTUcaxn0aravcRGL/6Nt+Rm8=; b=QmQ4b/Umxa9zicyRjKfaTsnh4kVNaGfrwSsbsh3nVxotzH+Bvd7jOks0xCs059iT5xE1kJ aSw+zjTI0Aa7J80hf+zGxVsOes6MZ5U6xvuPSmIdB2OLvGyAudXksQ0qiYO226Hg2XeeOm AhsXdBht8j7vCXq/xs8qXKE9or+hn7o= X-MC-Unique: AEFODpjZPZ6tQICh2AhyoA-1 X-Mimecast-MFC-AGG-ID: AEFODpjZPZ6tQICh2AhyoA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705022; x=1735309822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Szoag27KIkqUli3n0xSrTUcaxn0aravcRGL/6Nt+Rm8=; b=UykYY19OeyGPgESLmpBY6UJ7613RBHMSEKCCgq6zs+7aLrJbwsteFkOudmPxRZXoyY N/w22FPIS560BdCEsXBrTbCaEAQU+1M1G8rhDykUNCAr8BaagqMNiduiXwmR6KFO+vl2 Wto3Ua6WkK8W1/U+LEigXUqjDoXEfas1pen35be2j2ZspPaZMmNupTr7cnF6l+QcvT3H iXy/nO2It6On4d6xRoHrYZ04qOBBv8VHr6Z1HAnCT1FqEADowivVsz4a3MY+dq0IqiRn b06fzFCQUJHKrNDixQmwBt1UhBam9ON1s+h4tJjr+LbbPBZIDXCriG0AL4XVQedx45fa HL9w== X-Gm-Message-State: AOJu0YzMnyHeekvrGa72gMxMhSL5XVkHLo9TJ/SBATb73FzRrkeV/59D mroejnxHcCu+Uxllrfen0xMdgaBJZHTEpLtWknR5jcMg6tl5uIFNIci7TxqxPkFXuwHax4aY6ut cutQdl9i2pQTtoRf8/Q+Yf741s5gpYve5XaiHct2oq3U4f6L/Ce8JkD9JPS5yR5NbHt89nG9kM+ LYmR/crmhfz/4Lv6KxxGByXNWWE1py5pElZdL3 X-Gm-Gg: ASbGncu0FLGAA6GRqDuX0tO3ekVNceEL5LrrQ9NlRh92m94e6INPhwbbINm0x9AScTX PK/afkip1NgzONE0WE4SMhEmsf+wJT/BiQLGSV8c/UtRt6TxWQOR/YtuNiXmeMb4uMv+/2md1ag mQ7VCvx+wCG9spyAVGv5pWR+50AvzKeqKY46CiqrIaV5mk/raSNhZo5CNBsiYEoq62ro2cKKAS6 I43+qdixfIsAMWBkZuesHh9uVWE2Byhiph9KRAPTEiiubjjWvhWcBzRyI9r X-Received: by 2002:a5d:6d07:0:b0:385:f2a5:ef6a with SMTP id ffacd0b85a97d-38a221eaa5fmr3293928f8f.15.1734705022197; Fri, 20 Dec 2024 06:30:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcGREriZdYrwfdKOQVlcM1YTgvD2rFEL6BRQMB0vo4IR5CccD8ADRPKD3WlS4diVwqozNl3Q== X-Received: by 2002:a5d:6d07:0:b0:385:f2a5:ef6a with SMTP id ffacd0b85a97d-38a221eaa5fmr3293884f8f.15.1734705021699; Fri, 20 Dec 2024 06:30:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 10/12] rust: qemu-api-macros: extend error reporting facility to parse errors Date: Fri, 20 Dec 2024 15:29:52 +0100 Message-ID: <20241220142955.652636-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705151111116600 Content-Type: text/plain; charset="utf-8" Generalize the CompileError tuple to an enum, that can be either an error message or a parse error from syn. Signed-off-by: Paolo Bonzini --- rust/qemu-api-macros/src/lib.rs | 27 ++++++++++----------------- rust/qemu-api-macros/src/utils.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 rust/qemu-api-macros/src/utils.rs diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 0f04cca3841..539c48df298 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -3,57 +3,50 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 use proc_macro::TokenStream; -use proc_macro2::Span; -use quote::{quote, quote_spanned}; +use quote::quote; use syn::{ parse_macro_input, parse_quote, punctuated::Punctuated, token::Comma, = Data, DeriveInput, Field, Fields, Ident, Type, Visibility, }; =20 -struct CompileError(String, Span); - -impl From for proc_macro2::TokenStream { - fn from(err: CompileError) -> Self { - let CompileError(msg, span) =3D err; - quote_spanned! { span =3D> compile_error!(#msg); } - } -} +mod utils; +use utils::MacroError; =20 fn get_fields<'a>( input: &'a DeriveInput, msg: &str, -) -> Result<&'a Punctuated, CompileError> { +) -> Result<&'a Punctuated, MacroError> { if let Data::Struct(s) =3D &input.data { if let Fields::Named(fs) =3D &s.fields { Ok(&fs.named) } else { - Err(CompileError( + Err(MacroError::Message( format!("Named fields required for {}", msg), input.ident.span(), )) } } else { - Err(CompileError( + Err(MacroError::Message( format!("Struct required for {}", msg), input.ident.span(), )) } } =20 -fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), CompileError> { +fn is_c_repr(input: &DeriveInput, msg: &str) -> Result<(), MacroError> { let expected =3D parse_quote! { #[repr(C)] }; =20 if input.attrs.iter().any(|attr| attr =3D=3D &expected) { Ok(()) } else { - Err(CompileError( + Err(MacroError::Message( format!("#[repr(C)] required for {}", msg), input.ident.span(), )) } } =20 -fn derive_object_or_error(input: DeriveInput) -> Result { +fn derive_object_or_error(input: DeriveInput) -> Result { is_c_repr(&input, "#[derive(Object)]")?; =20 let name =3D &input.ident; @@ -80,7 +73,7 @@ pub fn derive_object(input: TokenStream) -> TokenStream { } =20 #[rustfmt::skip::macros(quote)] -fn derive_offsets_or_error(input: DeriveInput) -> Result { +fn derive_offsets_or_error(input: DeriveInput) -> Result { is_c_repr(&input, "#[derive(offsets)]")?; =20 let name =3D &input.ident; diff --git a/rust/qemu-api-macros/src/utils.rs b/rust/qemu-api-macros/src/u= tils.rs new file mode 100644 index 00000000000..02c91aed7f6 --- /dev/null +++ b/rust/qemu-api-macros/src/utils.rs @@ -0,0 +1,26 @@ +// Procedural macro utilities. +// Author(s): Paolo Bonzini +// SPDX-License-Identifier: GPL-2.0-or-later + +use proc_macro2::Span; +use quote::quote_spanned; + +pub enum MacroError { + Message(String, Span), + ParseError(syn::Error), +} + +impl From for MacroError { + fn from(err: syn::Error) -> Self { + MacroError::ParseError(err) + } +} + +impl From for proc_macro2::TokenStream { + fn from(err: MacroError) -> Self { + match err { + MacroError::Message(msg, span) =3D> quote_spanned! { span =3D>= compile_error!(#msg); }, + MacroError::ParseError(err) =3D> err.into_compile_error(), + } + } +} --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705122; cv=none; d=zohomail.com; s=zohoarc; b=GgdrGcuOvLhHSZ7rS2JHF+lC/BEOlQZek5C2EL08iFJonTtc3wL4FRDAE7aCg33dT0wL6VFO9irtS4/0j1Neih87D00+CPLFcfSRhrML1IPGf0s+slTVqbJkF/sYeT1iZDfcpyD0NvUaIKaCeWYXvJM+lxHbP2otOMBS9l2d5kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705122; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5CE9shW3ftWbl1V1SBQeRNzap/cYi489BVwR842VWpQ=; b=BuUsdcU453uc1/xsEdT5E8HsQ5vRWt4ThLlrV/PYKN52E+P27FEICABxqiUNGWXzarfYVvVfVN8mNpPOEl80RNsMyBaSA9r+rOPOTmmuwtTwo9qdFXobdMbPFldoEMs79wSCZmSzvFPd3ZGHo7Y/4yFQjVlec1w5O2E7gmNww5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705122953479.939908111318; Fri, 20 Dec 2024 06:32:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1W-0004UJ-5C; Fri, 20 Dec 2024 09:30:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1P-0004Sm-Bu for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1N-0006be-F4 for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:30 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-YID_4nulNQywaQzAs_U7sw-1; Fri, 20 Dec 2024 09:30:26 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so17082095e9.3 for ; Fri, 20 Dec 2024 06:30:26 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43661289995sm46912885e9.36.2024.12.20.06.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5CE9shW3ftWbl1V1SBQeRNzap/cYi489BVwR842VWpQ=; b=gH4r/2Fap2gBjHsSbLvfpTYC0/SGMBTRL5K+Pd+9xByr13Hit3MnRuNVBrnpU1hH9lt4SK AwIubgbAIWvEXtV/e+cjcftxVV8z20mRHo7JkPpej7KZpy7ZAmAZxkhhX5fkiwkauCLz6J ZgO36t9NgG9pfZq9IvtaNxa9AJ2xpmA= X-MC-Unique: YID_4nulNQywaQzAs_U7sw-1 X-Mimecast-MFC-AGG-ID: YID_4nulNQywaQzAs_U7sw X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705025; x=1735309825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5CE9shW3ftWbl1V1SBQeRNzap/cYi489BVwR842VWpQ=; b=bBf8Ke4V8t0u7Wb6NR3eDFTkYXmqSeaSNB7/rNwN3a66U6oF2V/bGuDZPfQ0+y2K79 3R8yrRynjOea5MDjT78Lt/CIXaPxmKZFRbp135zRTy+EXoYaYJNuFfY4aJvJo2PSog+r tdpXYMvGQbbcX5yGBWh+pifSZ3r/kYRonid9ICgq1e1pa23y3y7LrA1wFUzahzkfrRVe 9uhPLU00wgiJYmFukkxrgJ5iXVcI3Ack9iSreiCh55SYhGpTc/2zKmYAC7XcvcvytGvi 2z4necaUiuuKewMwJOoWIOTFq8wjmupjcIP0EnBWSRgqebZYZeoqdqqOqNes4Mpd8n11 DZ3w== X-Gm-Message-State: AOJu0YzJyew+UyQsDXtChZfym/cMElRJ/7qAjXKisjwFvEUqQiZumov3 Jgt0+Y93l+AaR0KZjA8HEF7+fmQoPHLxC3KOYkIQCeLYqDNxcoKv/JTI19UBw/3YEHp0Ehx3A4P 91YMrYgFa2vsAqgQBGJsKk8iblcZalCzSHmd6fDaXhPb6UfdgxZj2d7N6i9xExMrJGE2PQ/sGmK NifGqiFjaBsXdi1AV0kwe7umLWmP4JqDmPPw68 X-Gm-Gg: ASbGnctDBICZ5OQlxBln7PBs92CLTJhgfaVbUBbPpyrLwGtY8bRieO2I6e3Itx1oLm1 C5tNXs4LdirckxnFmrlNj0Om75eqqUp1ba4VFcV/EVyRaCY+XJZszatn/q7HNNEsg0P1LE1N7bo I5BmHR+fxmzca4W4MheR6GKmnHWaRRGl3mcsKC5/9YUyTSxvXRrCkBUr540Xvx9p+/RzyqvM2ZZ db1mkRtDviWOIGDVR0xW1oIXP7kXE9DgZK4Ygn8vIYVFpZ+a2GriyhFI7tm X-Received: by 2002:a05:600c:3b9a:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-436685470f8mr21997485e9.1.1734705024572; Fri, 20 Dec 2024 06:30:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IETpWXaWaw9US5iVVn857lDgNrX33bWnLjJZuYEEXU6N/4z+3xZlssf+uLvsNzyHsfsNXkd8w== X-Received: by 2002:a05:600c:3b9a:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-436685470f8mr21997215e9.1.1734705024070; Fri, 20 Dec 2024 06:30:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 11/12] rust: qemu-api-macros: add automatic TryFrom/TryInto derivation Date: Fri, 20 Dec 2024 15:29:53 +0100 Message-ID: <20241220142955.652636-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705124960116600 Content-Type: text/plain; charset="utf-8" This is going to be fairly common. Using a custom procedural macro provides better error messages and automatically finds the right type. Note that this is different from the same-named macro in the derive_more crate. That one provides conversion from e.g. tuples to enums with tuple variants, not from integers to enums. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/lib.rs | 28 +------------ rust/qemu-api-macros/src/lib.rs | 74 ++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 29 deletions(-) diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 69064d6929b..0a89d393e0f 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -45,7 +45,7 @@ #[doc(alias =3D "offset")] #[allow(non_camel_case_types)] #[repr(u64)] -#[derive(Debug)] +#[derive(Debug, qemu_api_macros::TryInto)] pub enum RegisterOffset { /// Data Register /// @@ -102,32 +102,6 @@ pub enum RegisterOffset { //Reserved =3D 0x04C, } =20 -impl core::convert::TryFrom for RegisterOffset { - type Error =3D u64; - - fn try_from(value: u64) -> Result { - macro_rules! case { - ($($discriminant:ident),*$(,)*) =3D> { - /* check that matching on all macro arguments compiles, wh= ich means we are not - * missing any enum value; if the type definition ever cha= nges this will stop - * compiling. - */ - const fn _assert_exhaustive(val: RegisterOffset) { - match val { - $(RegisterOffset::$discriminant =3D> (),)* - } - } - - match value { - $(x if x =3D=3D Self::$discriminant as u64 =3D> Ok(Sel= f::$discriminant),)* - _ =3D> Err(value), - } - } - } - case! { DR, RSR, FR, FBRD, ILPR, IBRD, LCR_H, CR, FLS, IMSC, RIS, = MIS, ICR, DMACR } - } -} - pub mod registers { //! Device registers exposed as typed structs which are backed by arbi= trary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. diff --git a/rust/qemu-api-macros/src/lib.rs b/rust/qemu-api-macros/src/lib= .rs index 539c48df298..7ec218202f4 100644 --- a/rust/qemu-api-macros/src/lib.rs +++ b/rust/qemu-api-macros/src/lib.rs @@ -5,8 +5,8 @@ use proc_macro::TokenStream; use quote::quote; use syn::{ - parse_macro_input, parse_quote, punctuated::Punctuated, token::Comma, = Data, DeriveInput, Field, - Fields, Ident, Type, Visibility, + parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spann= ed, token::Comma, Data, + DeriveInput, Field, Fields, Ident, Meta, Path, Token, Type, Variant, V= isibility, }; =20 mod utils; @@ -98,3 +98,73 @@ pub fn derive_offsets(input: TokenStream) -> TokenStream= { =20 TokenStream::from(expanded) } + +#[allow(non_snake_case)] +fn get_repr_uN(input: &DeriveInput, msg: &str) -> Result= { + let repr =3D input.attrs.iter().find(|attr| attr.path().is_ident("repr= ")); + if let Some(repr) =3D repr { + let nested =3D repr.parse_args_with(Punctuated:::= :parse_terminated)?; + for meta in nested { + match meta { + Meta::Path(path) if path.is_ident("u8") =3D> return Ok(pat= h), + Meta::Path(path) if path.is_ident("u16") =3D> return Ok(pa= th), + Meta::Path(path) if path.is_ident("u32") =3D> return Ok(pa= th), + Meta::Path(path) if path.is_ident("u64") =3D> return Ok(pa= th), + _ =3D> {} + } + } + } + + Err(MacroError::Message( + format!("#[repr(u8/u16/u32/u64) required for {}", msg), + input.ident.span(), + )) +} + +fn get_variants(input: &DeriveInput) -> Result<&Punctuated= , MacroError> { + if let Data::Enum(e) =3D &input.data { + if let Some(v) =3D e.variants.iter().find(|v| v.fields !=3D Fields= ::Unit) { + return Err(MacroError::Message( + "Cannot derive TryInto for enum with non-unit variants.".t= o_string(), + v.fields.span(), + )); + } + Ok(&e.variants) + } else { + Err(MacroError::Message( + "Cannot derive TryInto for union or struct.".to_string(), + input.ident.span(), + )) + } +} + +#[rustfmt::skip::macros(quote)] +fn derive_tryinto_or_error(input: DeriveInput) -> Result { + let repr =3D get_repr_uN(&input, "#[derive(TryInto)]")?; + + let name =3D &input.ident; + let variants =3D get_variants(&input)?; + let discriminants: Vec<&Ident> =3D variants.iter().map(|f| &f.ident).c= ollect(); + + Ok(quote! { + impl core::convert::TryFrom<#repr> for #name { + type Error =3D #repr; + + fn try_from(value: #repr) -> Result { + #(const #discriminants: #repr =3D #name::#discriminants as= #repr;)*; + match value { + #(#discriminants =3D> Ok(Self::#discriminants),)* + _ =3D> Err(value), + } + } + } + }) +} + +#[proc_macro_derive(TryInto)] +pub fn derive_tryinto(input: TokenStream) -> TokenStream { + let input =3D parse_macro_input!(input as DeriveInput); + let expanded =3D derive_tryinto_or_error(input).unwrap_or_else(Into::i= nto); + + TokenStream::from(expanded) +} --=20 2.47.1 From nobody Mon Dec 23 23:00:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705064; cv=none; d=zohomail.com; s=zohoarc; b=PTsQZygxMymn1H/96/N0SyvlAAjVk50HRtREuexnFewYuPAicO7zFWFcYraKO6bTlBqfTlrd3ls7lr1nK3CH36v6cgfafiyUrejWuCr9B9jwNYXCwRAPdT5BTrOIvggllLOqo7sRHRo8EKzrj2Hft6JnoGoCLj/REC0w6AExkCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705064; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jaco5xotTc07rSOEymQLIbqY1EI1Y0mpghelNUkIUoI=; b=YPNo2xT4ye3oCJoDQ4Z1Vk/cOqnV4jCHrV5idYF7u8fYNM2/x2DTp5bWn862rM2svci68rM9kiZ9RE+wJYQQJXB2fElKBeGXBrwTZFXQuBy8RpxqmCUI4g25ofLWi1cggq3GNWpvl6FsuhLi7v50R992G55Rj9X40YbEgCWPUjw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705064883424.1216433878943; Fri, 20 Dec 2024 06:31:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1e-0004dL-6l; Fri, 20 Dec 2024 09:30:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1R-0004Tj-UM for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1P-0006c2-OP for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:33 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-rPTmgOc9OXK-RsQ4u-_h2w-1; Fri, 20 Dec 2024 09:30:29 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361f371908so15248975e9.0 for ; Fri, 20 Dec 2024 06:30:29 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656b1143dsm80478705e9.18.2024.12.20.06.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jaco5xotTc07rSOEymQLIbqY1EI1Y0mpghelNUkIUoI=; b=ZqvN1yK9AH2ZhsKcfgc05eNSzg70h8mTVjScoMn59WkjYhyLAKnphlKGCE9bb8X76yckaZ sAwlKXFelJe05t+e61vUdOY8YaRHlFnh5zf2VCnB6grJOgAWuCeyEYgv9maB7LCliYvftb Ezqa4wvrFr0E09RWmFztYqIywlgYIzI= X-MC-Unique: rPTmgOc9OXK-RsQ4u-_h2w-1 X-Mimecast-MFC-AGG-ID: rPTmgOc9OXK-RsQ4u-_h2w X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705027; x=1735309827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jaco5xotTc07rSOEymQLIbqY1EI1Y0mpghelNUkIUoI=; b=HEIE0d0DAY+v+bahKoh8QyoJ2zv8GnVyERSpGu2EU1v9OHqk/6rb80vzdprm+GCnWA 9U8eMj/kIssFVWFGW5TTocNFbaDuhqxb+/2Ve9xGPUVgxOp6mZgkgem7GA9vco8Cec5x iP+hxnG9i/byffTEHTxavdgH7VLkZr0d8EYahvZJHpgWcT90fuJTtFy4qOEqUFa7eYLP 6WUkjtUB/C68XxjC0k0mTdXM1GUsNSFZwOHudK6tjUBhuMg1qA3W0HZkdE74Z2EelJhr pCax2K4b2YBYMVSUV0njihsvQDigAYhwyQWeVdv2hfHBQNicXa4MMWnqC37xupbUQbj4 X3JQ== X-Gm-Message-State: AOJu0YwdPzdzZVsvcmMRM1FftcyzB4sPKjytTwwVGOUNbk9Vn7+jif2Z OrWS5UVMV4q6+WgVWjhbWP7Bd+wugiN618s4rNq9FVGhiCV5jyvSOu0ZbYJOHUUSs/TEFYlZF7m g3eJ8kzM6e29xjrwpgCpKtyxVhumpNc483GsnQXpaXFYOZ4ogHTPa+l1TRESiorCBXkpcOKKgPa oC0+Dv1dxbPiBbPKaVt7eEpY6IrivrqhpCjOpA X-Gm-Gg: ASbGnctUmbDQiCvqyTB5EqmJOBaKp42K+PKMRta1pgz6lec3J3i5xKezMwP9FJzbT5r Vz6zaZtoobX+Nqy00+y6MPl2qpKaXwhmqZ8sghRg+gC2UAzmnVhit0lZ/+m/piwKltLca/xweEU 4fXFEhH/DjR5PlVc9oHJGcpajUK47yA2W4DKOkfgUDU3Xm4cqoRQvMzMVzBe0I5MpNFXgsd45c/ vhOA4GOldRzeUxXpX6WZQAym6L9223OqKQmGk+Yvg5wOuZpboknFqlz+7K2 X-Received: by 2002:a05:600c:4588:b0:434:fff1:1ade with SMTP id 5b1f17b1804b1-4366864413dmr26655185e9.13.1734705026822; Fri, 20 Dec 2024 06:30:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjwiZAwWz8CyvCKQsR4HIFv9MB5TCCSARFcJw+39WSfkTpj9Kyj1VStJv6YhhUnORDnMem6w== X-Received: by 2002:a05:600c:4588:b0:434:fff1:1ade with SMTP id 5b1f17b1804b1-4366864413dmr26654875e9.13.1734705026323; Fri, 20 Dec 2024 06:30:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 12/12] rust: hide warnings for subprojects Date: Fri, 20 Dec 2024 15:29:54 +0100 Message-ID: <20241220142955.652636-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734705067091116600 Content-Type: text/plain; charset="utf-8" This matches cargo's own usage of "--cap-lints allow" when building depende= ncies. Signed-off-by: Paolo Bonzini --- subprojects/arbitrary-int-1-rs.wrap | 3 +++ subprojects/bilge-0.2-rs.wrap | 3 +++ subprojects/bilge-impl-0.2-rs.wrap | 3 +++ subprojects/either-1-rs.wrap | 3 +++ subprojects/itertools-0.11-rs.wrap | 3 +++ .../arbitrary-int-1-rs/meson.build | 1 + .../packagefiles/bilge-0.2-rs/meson.build | 1 + .../bilge-impl-0.2-rs/meson.build | 1 + .../packagefiles/either-1-rs/meson.build | 1 + .../itertools-0.11-rs/meson.build | 1 + .../proc-macro-error-1-rs/meson.build | 1 + .../proc-macro-error-attr-1-rs/meson.build | 1 + .../packagefiles/proc-macro2-1-rs/meson.build | 1 + .../packagefiles/quote-1-rs/meson.build | 1 + subprojects/packagefiles/syn-2-rs/meson.build | 1 + .../unicode-ident-1-rs/meson.build | 1 + subprojects/proc-macro-error-1-rs.wrap | 3 +++ subprojects/proc-macro-error-attr-1-rs.wrap | 3 +++ subprojects/proc-macro2-1-rs.wrap | 3 +++ subprojects/quote-1-rs.wrap | 3 +++ subprojects/syn-2-rs.wrap | 3 +++ subprojects/unicode-ident-1-rs.wrap | 3 +++ subprojects/unicode-ident-1-rs/meson.build | 20 ------------------- 23 files changed, 44 insertions(+), 20 deletions(-) delete mode 100644 subprojects/unicode-ident-1-rs/meson.build diff --git a/subprojects/arbitrary-int-1-rs.wrap b/subprojects/arbitrary-in= t-1-rs.wrap index e580538a877..a1838b20b0f 100644 --- a/subprojects/arbitrary-int-1-rs.wrap +++ b/subprojects/arbitrary-int-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D arbitrary-int-1.2.7.tar.gz source_hash =3D c84fc003e338a6f69fbd4f7fe9f92b535ff13e9af8997f3b14b6ddff8b= 1df46d #method =3D cargo patch_directory =3D arbitrary-int-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/bilge-0.2-rs.wrap b/subprojects/bilge-0.2-rs.wrap index 7a4339d2989..900bb1497b9 100644 --- a/subprojects/bilge-0.2-rs.wrap +++ b/subprojects/bilge-0.2-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D bilge-0.2.0.tar.gz source_hash =3D dc707ed8ebf81de5cd6c7f48f54b4c8621760926cdf35a57000747c512= e67b57 #method =3D cargo patch_directory =3D bilge-0.2-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/bilge-impl-0.2-rs.wrap b/subprojects/bilge-impl-0.= 2-rs.wrap index b24c34a9043..d14c3dc769b 100644 --- a/subprojects/bilge-impl-0.2-rs.wrap +++ b/subprojects/bilge-impl-0.2-rs.wrap @@ -6,3 +6,6 @@ source_hash =3D feb11e002038ad243af39c2068c8a72bcf147acf050= 25dcdb916fcc000adb2d8 #method =3D cargo patch_directory =3D bilge-impl-0.2-rs diff_files =3D bilge-impl-1.63.0.patch + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/either-1-rs.wrap b/subprojects/either-1-rs.wrap index 6046712036c..352e11cfee6 100644 --- a/subprojects/either-1-rs.wrap +++ b/subprojects/either-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D either-1.12.0.tar.gz source_hash =3D 3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb233= 85b58b #method =3D cargo patch_directory =3D either-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/itertools-0.11-rs.wrap b/subprojects/itertools-0.1= 1-rs.wrap index 66b05252cd5..ee12d0053bc 100644 --- a/subprojects/itertools-0.11-rs.wrap +++ b/subprojects/itertools-0.11-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D itertools-0.11.0.tar.gz source_hash =3D b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418= c3fe57 #method =3D cargo patch_directory =3D itertools-0.11-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/packagefiles/arbitrary-int-1-rs/meson.build b/subp= rojects/packagefiles/arbitrary-int-1-rs/meson.build index cff3f62ce74..00733d1faab 100644 --- a/subprojects/packagefiles/arbitrary-int-1-rs/meson.build +++ b/subprojects/packagefiles/arbitrary-int-1-rs/meson.build @@ -9,6 +9,7 @@ _arbitrary_int_rs =3D static_library( files('src/lib.rs'), gnu_symbol_visibility: 'hidden', override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_args: ['--cap-lints', 'allow'], rust_abi: 'rust', dependencies: [], ) diff --git a/subprojects/packagefiles/bilge-0.2-rs/meson.build b/subproject= s/packagefiles/bilge-0.2-rs/meson.build index e69bac91b40..ce13d0fe80f 100644 --- a/subprojects/packagefiles/bilge-0.2-rs/meson.build +++ b/subprojects/packagefiles/bilge-0.2-rs/meson.build @@ -17,6 +17,7 @@ lib =3D static_library( 'src/lib.rs', override_options : ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi : 'rust', + rust_args: ['--cap-lints', 'allow'], dependencies: [ arbitrary_int_dep, bilge_impl_dep, diff --git a/subprojects/packagefiles/bilge-impl-0.2-rs/meson.build b/subpr= ojects/packagefiles/bilge-impl-0.2-rs/meson.build index f8f3486fc08..42b03dcd53c 100644 --- a/subprojects/packagefiles/bilge-impl-0.2-rs/meson.build +++ b/subprojects/packagefiles/bilge-impl-0.2-rs/meson.build @@ -25,6 +25,7 @@ _bilge_impl_rs =3D rust.proc_macro( files('src/lib.rs'), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_args: [ + '--cap-lints', 'allow', '--cfg', 'use_fallback', '--cfg', 'feature=3D"syn-error"', '--cfg', 'feature=3D"proc-macro"', diff --git a/subprojects/packagefiles/either-1-rs/meson.build b/subprojects= /packagefiles/either-1-rs/meson.build index 608e64e31fc..04c96cc5fb3 100644 --- a/subprojects/packagefiles/either-1-rs/meson.build +++ b/subprojects/packagefiles/either-1-rs/meson.build @@ -11,6 +11,7 @@ _either_rs =3D static_library( override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'], rust_abi: 'rust', rust_args: [ + '--cap-lints', 'allow', '--cfg', 'feature=3D"use_std"', '--cfg', 'feature=3D"use_alloc"', ], diff --git a/subprojects/packagefiles/itertools-0.11-rs/meson.build b/subpr= ojects/packagefiles/itertools-0.11-rs/meson.build index 30982a4ee76..2a3fbe9ee5a 100644 --- a/subprojects/packagefiles/itertools-0.11-rs/meson.build +++ b/subprojects/packagefiles/itertools-0.11-rs/meson.build @@ -15,6 +15,7 @@ _itertools_rs =3D static_library( override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'], rust_abi: 'rust', rust_args: [ + '--cap-lints', 'allow', '--cfg', 'feature=3D"use_std"', '--cfg', 'feature=3D"use_alloc"', ], diff --git a/subprojects/packagefiles/proc-macro-error-1-rs/meson.build b/s= ubprojects/packagefiles/proc-macro-error-1-rs/meson.build index ae27a696862..10c2741085c 100644 --- a/subprojects/packagefiles/proc-macro-error-1-rs/meson.build +++ b/subprojects/packagefiles/proc-macro-error-1-rs/meson.build @@ -20,6 +20,7 @@ _proc_macro_error_rs =3D static_library( override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'], rust_abi: 'rust', rust_args: [ + '--cap-lints', 'allow', '--cfg', 'use_fallback', '--cfg', 'feature=3D"syn-error"', '--cfg', 'feature=3D"proc-macro"', diff --git a/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.buil= d b/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build index 3281b264333..c4c4c5e397c 100644 --- a/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build +++ b/subprojects/packagefiles/proc-macro-error-attr-1-rs/meson.build @@ -16,6 +16,7 @@ _proc_macro_error_attr_rs =3D rust.proc_macro( files('src/lib.rs'), override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'], rust_args: [ + '--cap-lints', 'allow', '--cfg', 'use_fallback', '--cfg', 'feature=3D"syn-error"', '--cfg', 'feature=3D"proc-macro"' diff --git a/subprojects/packagefiles/proc-macro2-1-rs/meson.build b/subpro= jects/packagefiles/proc-macro2-1-rs/meson.build index f9c8675ebad..5759df3ecc9 100644 --- a/subprojects/packagefiles/proc-macro2-1-rs/meson.build +++ b/subprojects/packagefiles/proc-macro2-1-rs/meson.build @@ -15,6 +15,7 @@ _proc_macro2_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: [ + '--cap-lints', 'allow', '--cfg', 'feature=3D"proc-macro"', '--cfg', 'no_literal_byte_character', '--cfg', 'no_literal_c_string', diff --git a/subprojects/packagefiles/quote-1-rs/meson.build b/subprojects/= packagefiles/quote-1-rs/meson.build index 7f7792569b9..bf41fad99bb 100644 --- a/subprojects/packagefiles/quote-1-rs/meson.build +++ b/subprojects/packagefiles/quote-1-rs/meson.build @@ -15,6 +15,7 @@ _quote_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: [ + '--cap-lints', 'allow', '--cfg', 'feature=3D"proc-macro"', ], dependencies: [ diff --git a/subprojects/packagefiles/syn-2-rs/meson.build b/subprojects/pa= ckagefiles/syn-2-rs/meson.build index 2c62cf7e1b0..a0094174084 100644 --- a/subprojects/packagefiles/syn-2-rs/meson.build +++ b/subprojects/packagefiles/syn-2-rs/meson.build @@ -19,6 +19,7 @@ _syn_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: [ + '--cap-lints', 'allow', '--cfg', 'feature=3D"full"', '--cfg', 'feature=3D"derive"', '--cfg', 'feature=3D"parsing"', diff --git a/subprojects/packagefiles/unicode-ident-1-rs/meson.build b/subp= rojects/packagefiles/unicode-ident-1-rs/meson.build index 9d76ebbd1ad..11a5dab97df 100644 --- a/subprojects/packagefiles/unicode-ident-1-rs/meson.build +++ b/subprojects/packagefiles/unicode-ident-1-rs/meson.build @@ -10,6 +10,7 @@ _unicode_ident_rs =3D static_library( gnu_symbol_visibility: 'hidden', override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', + rust_args: ['--cap-lints', 'allow'], dependencies: [], native: true, ) diff --git a/subprojects/proc-macro-error-1-rs.wrap b/subprojects/proc-macr= o-error-1-rs.wrap index b7db03b06a0..59f892f7825 100644 --- a/subprojects/proc-macro-error-1-rs.wrap +++ b/subprojects/proc-macro-error-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D proc-macro-error-1.0.4.tar.gz source_hash =3D da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a= 5ce38c #method =3D cargo patch_directory =3D proc-macro-error-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/proc-macro-error-attr-1-rs.wrap b/subprojects/proc= -macro-error-attr-1-rs.wrap index d13d8a239ac..5aeb224a103 100644 --- a/subprojects/proc-macro-error-attr-1-rs.wrap +++ b/subprojects/proc-macro-error-attr-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D proc-macro-error-attr-1.0.4.tar.gz source_hash =3D a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b= 35f869 #method =3D cargo patch_directory =3D proc-macro-error-attr-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/proc-macro2-1-rs.wrap b/subprojects/proc-macro2-1-= rs.wrap index 7053e2c013c..6c9369f0df3 100644 --- a/subprojects/proc-macro2-1-rs.wrap +++ b/subprojects/proc-macro2-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D proc-macro2-1.0.84.0.tar.gz source_hash =3D ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc1202= 4a49d6 #method =3D cargo patch_directory =3D proc-macro2-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/quote-1-rs.wrap b/subprojects/quote-1-rs.wrap index 6e7ea69049f..8b721dfa00b 100644 --- a/subprojects/quote-1-rs.wrap +++ b/subprojects/quote-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D quote-1.0.36.0.tar.gz source_hash =3D 0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208= acaca7 #method =3D cargo patch_directory =3D quote-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/syn-2-rs.wrap b/subprojects/syn-2-rs.wrap index 13ffdac3c3b..d79cf750fb4 100644 --- a/subprojects/syn-2-rs.wrap +++ b/subprojects/syn-2-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D syn-2.0.66.0.tar.gz source_hash =3D c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3= cdcff5 #method =3D cargo patch_directory =3D syn-2-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/unicode-ident-1-rs.wrap b/subprojects/unicode-iden= t-1-rs.wrap index 4609f96ed97..50988f612e2 100644 --- a/subprojects/unicode-ident-1-rs.wrap +++ b/subprojects/unicode-ident-1-rs.wrap @@ -5,3 +5,6 @@ source_filename =3D unicode-ident-1.0.12.tar.gz source_hash =3D 3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec= 0fee4b #method =3D cargo patch_directory =3D unicode-ident-1-rs + +# bump this version number on every change to meson.build or the patches: +# v2 diff --git a/subprojects/unicode-ident-1-rs/meson.build b/subprojects/unico= de-ident-1-rs/meson.build deleted file mode 100644 index 54f23768545..00000000000 --- a/subprojects/unicode-ident-1-rs/meson.build +++ /dev/null @@ -1,20 +0,0 @@ -project('unicode-ident-1-rs', 'rust', - version: '1.0.12', - license: '(MIT OR Apache-2.0) AND Unicode-DFS-2016', - default_options: []) - -_unicode_ident_rs =3D static_library( - 'unicode_ident', - files('src/lib.rs'), - gnu_symbol_visibility: 'hidden', - override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], - rust_abi: 'rust', - dependencies: [], - native: true, -) - -unicode_ident_dep =3D declare_dependency( - link_with: _unicode_ident_rs, -) - -meson.override_dependency('unicode-ident-1-rs', unicode_ident_dep, native:= true) --=20 2.47.1