From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592304; cv=none; d=zohomail.com; s=zohoarc; b=a0Cyv6jGDSHfomaEFZVISCBLAOFubx7A/jR0KIdQvmfg9dB/GHu/D47g/bJyDlMhBuGWftozZ/NgcO9vf2h4O7i3LDQOpqDv+De2LaAMPiZxpxAjqvq+voTIH85/SnOYPc0su892/C9oDaI6sHA4vIeS8ZfSb33QDCdQp6EK8MM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592304; 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=M6QoYP5WCSbSMFCMhfRa9ReIhHpAzUDchEI+NzMVEms=; b=TP2tO1o3h0hxyad5CWPO0Me9vVwn4rYYSNQ8nXciicS4hs8AUML0VAICI4DYWfltz5pBoO9ahBOtB/w1B8XDXtR3kJnoT2Ixh1IzncLCAGHFkqK6c+9hkQXMwKxjGV9a0wE5I/+c5ILBi2DzLOplSL6b3giwwIHGy+jf/1trWb4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592304294253.27305517742354; Fri, 30 May 2025 01:05:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKui3-0002OL-34; Fri, 30 May 2025 04:03:23 -0400 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 1uKui0-0002NE-OS for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:21 -0400 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 1uKuhw-0004XZ-Br for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:20 -0400 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-IIEwYzgzNeCLZU2VUzy92Q-1; Fri, 30 May 2025 04:03:13 -0400 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-601f3f35b88so1710070a12.1 for ; Fri, 30 May 2025 01:03:13 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60566c59f81sm1252212a12.18.2025.05.30.01.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592195; 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=M6QoYP5WCSbSMFCMhfRa9ReIhHpAzUDchEI+NzMVEms=; b=P23FgdZ3cKqZ+sKBZx7bgpJhQ1Z0TV0Kgqjeeknmzn2DQ+erObr7npr+gVfYVphKD16Y8V rEpv95CfPZmcY7nklmE/mI4R7fjRc5IxE+0SaS+id3BFzsynH4Eni0q+Rt7lt4bXi7aZPD naZMCHWOsGsOM0Zg95RlH7K5SV0Tqls= X-MC-Unique: IIEwYzgzNeCLZU2VUzy92Q-1 X-Mimecast-MFC-AGG-ID: IIEwYzgzNeCLZU2VUzy92Q_1748592192 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592192; x=1749196992; 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=M6QoYP5WCSbSMFCMhfRa9ReIhHpAzUDchEI+NzMVEms=; b=NSQiFXZr8N6ZoREUeg0hPFEKXZUDZ59wuiN1GYfNCES5EuRnAdZ6+y9QLAFwxWyuqg dx8s21JoTqSp3w73WXqDgNnQl3nLQ8upjZZVMBk7Vx6hFSjCdjTJ3sgMlT910HbYJWA6 ivz4V2NEHqfEb7J5xsmipMY6qNzl/4MriZzswLIWbCO68drj5e5nAV1bXTLH+r9xm8oh t3riZu+MyIEmQS6bnqJEMj7ystssRYxhliBFoAZ4HT3P0GYIb+t8jGcLzqhaqUa6d+uL Yc/Q8AN94OvCBQs6M2MSoP8eiEe/+6T0ezSckZvnT0gL/R1NUPeJbXG1GdVAAShQVcXQ Prqw== X-Gm-Message-State: AOJu0Yx+mRA5JZFw4mkfUI+fcmXB+rGOYpEM67JBjy7rGxiJvkc+ODy7 8r1Tdtub71B4xXv1aLwEFoUD/OABexsC+hu8lVpH1CKqigMLMxJDOdg75vw3mPohIPNWT7/5Gjz sS7XuIvX0fwEPFV4HD7CkRfdToJdcVnTSFRc04W6YuJXGoW795E2/YRKDTYAkKC/BTnfuKhDx3R vIlgJzh14X13xtER1ulQ67upjpOvEHBfVOh+EFsTgo X-Gm-Gg: ASbGncsrPbhA91KqtxJyXbTMHASxCAMonLUwWfemTOQiaORPV2gQYFpgEHqc1zvUXWs 1ncQXWFO7o0XGF0GeJSwy7GogAE+iZVCRDlo8N6VQR3q4jZ9FjY7SqA8lLwoJ4wx6KYw7w5fvRa 21S0/rbwBxK1KKoNLvBsqGfH1W4YaV9HPJiQ51xsEjbpySoYr7FipAekhCSf61H8hhq4PkfJztt f9iAXbg6tPAkWx20RMCUUnfLlMymZPV1W/jdIJCYGPxKDhFeMgggDtJ8UA77v3dCk19dthU46B9 12Raa62NYjkdfQ== X-Received: by 2002:a05:6402:34d0:b0:602:3e4:54de with SMTP id 4fb4d7f45d1cf-6056db31fdfmr2252486a12.10.1748592191648; Fri, 30 May 2025 01:03:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTV+NBOEZUNPTidm/yHYmvPTkjQLR5Zjaf7PHW0R7WQSmI2kZJjbN4co+1imMPkaADl0Nnew== X-Received: by 2002:a05:6402:34d0:b0:602:3e4:54de with SMTP id 4fb4d7f45d1cf-6056db31fdfmr2252451a12.10.1748592191179; Fri, 30 May 2025 01:03:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 01/14] subprojects: add the anyhow crate Date: Fri, 30 May 2025 10:02:53 +0200 Message-ID: <20250530080307.2055502-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592305831116600 Content-Type: text/plain; charset="utf-8" This is a standard replacement for Box which is more efficient (= it only occcupies one word) and provides a backtrace of the error. This could be p= lumbed into &error_abort in the future. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/meson.build | 2 ++ rust/qemu-api/meson.build | 2 +- scripts/archive-source.sh | 2 +- scripts/make-release | 2 +- subprojects/.gitignore | 1 + subprojects/anyhow-1-rs.wrap | 7 ++++ .../packagefiles/anyhow-1.0-rs/meson.build | 33 +++++++++++++++++++ 7 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 subprojects/anyhow-1-rs.wrap create mode 100644 subprojects/packagefiles/anyhow-1.0-rs/meson.build diff --git a/rust/meson.build b/rust/meson.build index afce62f4772..6227e01f32a 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,7 +1,9 @@ +subproject('anyhow-1-rs', required: true) subproject('bilge-0.2-rs', required: true) subproject('bilge-impl-0.2-rs', required: true) subproject('libc-0.2-rs', required: true) =20 +anyhow_rs =3D dependency('anyhow-1-rs') bilge_rs =3D dependency('bilge-0.2-rs') bilge_impl_rs =3D dependency('bilge-impl-0.2-rs') libc_rs =3D dependency('libc-0.2-rs') diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index d19f52af4da..181ceca9536 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -35,7 +35,7 @@ _qemu_api_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: _qemu_api_cfg, - dependencies: [libc_rs, qemu_api_macros, qemuutil_rs, + dependencies: [anyhow_rs, libc_rs, qemu_api_macros, qemuutil_rs, qom, hwcore, chardev, migration], ) =20 diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index e461c1531ed..816062fee94 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -27,7 +27,7 @@ sub_file=3D"${sub_tdir}/submodule.tar" # in their checkout, because the build environment is completely # different to the host OS. subprojects=3D"keycodemapdb libvfio-user berkeley-softfloat-3 - berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs + berkeley-testfloat-3 anyhow-1-rs arbitrary-int-1-rs bilge-0.2-rs bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-= 1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" diff --git a/scripts/make-release b/scripts/make-release index 8c3594a1a47..ea65bdcc0cf 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -40,7 +40,7 @@ fi =20 # Only include wraps that are invoked with subproject() SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softfloat-3 - berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs + berkeley-testfloat-3 anyhow-1-rs arbitrary-int-1-rs bilge-0.2-rs bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-= 1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" diff --git a/subprojects/.gitignore b/subprojects/.gitignore index d12d34618cc..b9ae507b85a 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -6,6 +6,7 @@ /keycodemapdb /libvfio-user /slirp +/anyhow-1.0.98 /arbitrary-int-1.2.7 /bilge-0.2.0 /bilge-impl-0.2.0 diff --git a/subprojects/anyhow-1-rs.wrap b/subprojects/anyhow-1-rs.wrap new file mode 100644 index 00000000000..a69a3645b49 --- /dev/null +++ b/subprojects/anyhow-1-rs.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory =3D anyhow-1.0.98 +source_url =3D https://crates.io/api/v1/crates/anyhow/1.0.98/download +source_filename =3D anyhow-1.0.98.tar.gz +source_hash =3D e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969b= dcd487 +#method =3D cargo +patch_directory =3D anyhow-1-rs diff --git a/subprojects/packagefiles/anyhow-1.0-rs/meson.build b/subprojec= ts/packagefiles/anyhow-1.0-rs/meson.build new file mode 100644 index 00000000000..348bab98b9f --- /dev/null +++ b/subprojects/packagefiles/anyhow-1.0-rs/meson.build @@ -0,0 +1,33 @@ +project('anyhow-1-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '1.0.98', + license: 'MIT OR Apache-2.0', + default_options: []) + +rustc =3D meson.get_compiler('rust') + +rust_args =3D ['--cap-lints', 'allow'] +rust_args +=3D ['--cfg', 'feature=3D"std"'] +if rustc.version().version_compare('<1.65.0') + error('rustc version ' + rustc.version() + ' is unsupported. Please upgr= ade to at least 1.65.0') +endif +rust_args +=3D [ '--cfg', 'std_backtrace' ] # >=3D 1.65.0 +if rustc.version().version_compare('<1.81.0') + rust_args +=3D [ '--cfg', 'anyhow_no_core_error' ] +endif + +_anyhow_rs =3D static_library( + 'anyhow', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=3D2018', 'build.rust_std=3D2018'], + rust_abi: 'rust', + rust_args: rust_args, + dependencies: [], +) + +anyhow_dep =3D declare_dependency( + link_with: _anyhow_rs, +) + +meson.override_dependency('anyhow-1-rs', anyhow_dep) --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592289; cv=none; d=zohomail.com; s=zohoarc; b=ToVVUwGaJCAl6MVAmS353cK8+cglaHREO3rj4Mk4qiuv4TXBSy3LVS7y/zhlIiH+Hcltkj9Guj6HPTUy/0JqlRiUU1VqMZILtJNCkxoZ0IDdbmMcQDrmg7HHGtpiYyTS2tX06L6Gktrr+mwkiPzrM1NBc7TnkGdRpKWPZZ0PGlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592289; 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=UUj6q6B+e336ffq5s6Zk0rCKpR7Qm0AOx4IF/wqWtHg=; b=AJtVsWlZnr8nBVG1glU3LkXTJAuu8tBSiiFutIqCZIzATVhmjIvPE5xedH0iC/bsVCW9CxzBvRlIihaAq3MzCNqsBGivw9mLrSnpEDbxFQq4EExfFEXmZBnxzQCjyuxSgVO72e+WjQfz5s2cEH92gjjyeMPfSSfngxfiMfxMsxA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592289670545.0622267926069; Fri, 30 May 2025 01:04:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKui4-0002Ou-50; Fri, 30 May 2025 04:03:24 -0400 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 1uKui0-0002NC-Np for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:21 -0400 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 1uKuhy-0004Xy-9R for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:20 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-TjJSTUJPN-Kpf1L1BBwoZA-1; Fri, 30 May 2025 04:03:15 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-adb32dbf60bso67157166b.1 for ; Fri, 30 May 2025 01:03:15 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada6ad3a6d7sm282708266b.155.2025.05.30.01.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592197; 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=UUj6q6B+e336ffq5s6Zk0rCKpR7Qm0AOx4IF/wqWtHg=; b=BuzoIo0GoYJ7OKAYRjooTYF579eNkmBPbdc524YVBxi5ZABfpfvpT9jKUdWRtKyWhcQqcf 9Bf0ZEyPbINyNEPyJr++xpFiTfKRMOdPpdg+v2/h9ATOyZ8DfN8XGOCR3xHXxZsr/XXOBu Cg1gPA3DuKqGTu7tu/dRFSkkGI4zm5s= X-MC-Unique: TjJSTUJPN-Kpf1L1BBwoZA-1 X-Mimecast-MFC-AGG-ID: TjJSTUJPN-Kpf1L1BBwoZA_1748592195 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592194; x=1749196994; 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=UUj6q6B+e336ffq5s6Zk0rCKpR7Qm0AOx4IF/wqWtHg=; b=pGcYymaHyI1JusKvcYjLND3MmmqPXh58kAbNff/+aSgoj7VttwNUNK7AscaxV2btTA CyaP2JAUY+fHqxFZY7TRyWDhZQS1+xMyTqUbSWtOsRWcVOWNtohqLngM9fFSxSd7IFT9 hk3e6QlF34SfQQo3eB37RleL9eWyG8vzpHe7k8LBpVu+7NUSgv7aKtgdApIwmis5edJi uL2a79q7PbataFmVMWFQiWpcXVuep7tD4Jfh74V5haFlXWNHq1RQJAJ5qIpYmYtFwFf1 6WnPxNyHGAfn2AdjtUayFuolo054XRv1xidS8V3adhvXmwNO6Ggq/7h4iNfXGRm+GQCv 6NaA== X-Gm-Message-State: AOJu0YzQXXnIawZ0cGdiy+3ZYX8dqJ7M3AsY8xKCe+uAaV2e6SQq3r6g hKde6B3mghu1NHmhhq2cE1e9Yve+qou3acP5GcYOKOmJJUyS7LLGh1WTIkWn11jHF2vjVCJtkOS O5Pz5YWIXaHCXdjz9UJhEWc0wM1JckzXwzPLOYhTTa5aPGlR7cyuOSjm+XlpybuV0uHedScTbru WhDVSmbCAdN1w006n3Mdv+haxTXCkUnW8PzmVn+UBf X-Gm-Gg: ASbGnctSkoMVFjXb9/DkEesHFPAc44NUNkxWD89Np8BawfUvdienhUFaCQHOk4/2ut4 fTdPEkF3aT5eDKb3XSIQBpgo/kbZfvsET1xd5ZTS9eY40tob9yXfiadZqtgJjQGC9gpAPEKUq3R haWUT2BOVZd1EPWYSbSWo9iYAmtNScQsBNn4FgdTC2KSf9UmPATHJRDdLuwpiMWvlhMurwyaFTY qGbLF6nHFQwwqa6swBXou9FpcCEocjyvLYXaAPGFHYJ1o1fZClOobtsu+DHkGMYqeyWF5pYRzA7 kBq3cysdGMqqsw== X-Received: by 2002:a17:907:1ca3:b0:ad2:4b0c:ee8c with SMTP id a640c23a62f3a-adb322a519amr196938866b.35.1748592193817; Fri, 30 May 2025 01:03:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEo1Hw4sjBjsj+Yc+BNtiU9OxmVUqqSMVhs3xXzI7t163AFUQEsY+/ECdsA3TBUxA2FYIjjnA== X-Received: by 2002:a17:907:1ca3:b0:ad2:4b0c:ee8c with SMTP id a640c23a62f3a-adb322a519amr196935766b.35.1748592193362; Fri, 30 May 2025 01:03:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 02/14] subprojects: add the foreign crate Date: Fri, 30 May 2025 10:02:54 +0200 Message-ID: <20250530080307.2055502-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748592291937116600 Content-Type: text/plain; charset="utf-8" This is a cleaned up and separated version of the patches at https://lore.kernel.org/all/20240701145853.1394967-4-pbonzini@redhat.com/ https://lore.kernel.org/all/20240701145853.1394967-5-pbonzini@redhat.com/ Its first user will be the Error bindings; for example a QEMU Error ** can = be converted to a Rust Option using unsafe { Option::::from_foreign(c_error) } Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/meson.build | 2 ++ rust/qemu-api/meson.build | 2 +- scripts/archive-source.sh | 3 ++- scripts/make-release | 3 ++- subprojects/.gitignore | 1 + subprojects/foreign-0.3-rs.wrap | 7 +++++ .../packagefiles/foreign-0.3-rs/meson.build | 26 +++++++++++++++++++ 7 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 subprojects/foreign-0.3-rs.wrap create mode 100644 subprojects/packagefiles/foreign-0.3-rs/meson.build diff --git a/rust/meson.build b/rust/meson.build index 6227e01f32a..59c7ed2736b 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -1,11 +1,13 @@ subproject('anyhow-1-rs', required: true) subproject('bilge-0.2-rs', required: true) subproject('bilge-impl-0.2-rs', required: true) +subproject('foreign-0.3-rs', required: true) subproject('libc-0.2-rs', required: true) =20 anyhow_rs =3D dependency('anyhow-1-rs') bilge_rs =3D dependency('bilge-0.2-rs') bilge_impl_rs =3D dependency('bilge-impl-0.2-rs') +foreign_rs =3D dependency('foreign-0.3-rs') libc_rs =3D dependency('libc-0.2-rs') =20 subproject('proc-macro2-1-rs', required: true) diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 181ceca9536..aa22252866d 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -35,7 +35,7 @@ _qemu_api_rs =3D static_library( override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: _qemu_api_cfg, - dependencies: [anyhow_rs, libc_rs, qemu_api_macros, qemuutil_rs, + dependencies: [anyhow_rs, foreign_rs, libc_rs, qemu_api_macros, qemuutil= _rs, qom, hwcore, chardev, migration], ) =20 diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index 816062fee94..035828c532e 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -28,7 +28,8 @@ sub_file=3D"${sub_tdir}/submodule.tar" # different to the host OS. subprojects=3D"keycodemapdb libvfio-user berkeley-softfloat-3 berkeley-testfloat-3 anyhow-1-rs arbitrary-int-1-rs bilge-0.2-rs - bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-= 1-rs + bilge-impl-0.2-rs either-1-rs foreign-0.3-rs itertools-0.11-rs + libc-0.2-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" sub_deinit=3D"" diff --git a/scripts/make-release b/scripts/make-release index ea65bdcc0cf..4509a9fabf5 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -41,7 +41,8 @@ fi # Only include wraps that are invoked with subproject() SUBPROJECTS=3D"libvfio-user keycodemapdb berkeley-softfloat-3 berkeley-testfloat-3 anyhow-1-rs arbitrary-int-1-rs bilge-0.2-rs - bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-= 1-rs + bilge-impl-0.2-rs either-1-rs foreign-0.3-rs itertools-0.11-rs + libc-0.2-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" =20 diff --git a/subprojects/.gitignore b/subprojects/.gitignore index b9ae507b85a..f4281934ce1 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -11,6 +11,7 @@ /bilge-0.2.0 /bilge-impl-0.2.0 /either-1.12.0 +/foreign-0.3.1 /itertools-0.11.0 /libc-0.2.162 /proc-macro-error-1.0.4 diff --git a/subprojects/foreign-0.3-rs.wrap b/subprojects/foreign-0.3-rs.w= rap new file mode 100644 index 00000000000..0d218ec2c25 --- /dev/null +++ b/subprojects/foreign-0.3-rs.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory =3D foreign-0.3.1 +source_url =3D https://crates.io/api/v1/crates/foreign/0.3.1/download +source_filename =3D foreign-0.3.1.tar.gz +source_hash =3D 17ca1b5be8c9d320daf386f1809c7acc0cb09accbae795c2001953fa50= 585846 +#method =3D cargo +patch_directory =3D foreign-0.3-rs diff --git a/subprojects/packagefiles/foreign-0.3-rs/meson.build b/subproje= cts/packagefiles/foreign-0.3-rs/meson.build new file mode 100644 index 00000000000..0901c02c527 --- /dev/null +++ b/subprojects/packagefiles/foreign-0.3-rs/meson.build @@ -0,0 +1,26 @@ +project('foreign-0.3-rs', 'rust', + meson_version: '>=3D1.5.0', + version: '0.2.0', + license: 'MIT OR Apache-2.0', + default_options: []) + +subproject('libc-0.2-rs', required: true) +libc_rs =3D dependency('libc-0.2-rs') + +_foreign_rs =3D static_library( + 'foreign', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi: 'rust', + rust_args: [ + '--cap-lints', 'allow', + ], + dependencies: [libc_rs], +) + +foreign_dep =3D declare_dependency( + link_with: _foreign_rs, +) + +meson.override_dependency('foreign-0.3-rs', foreign_dep) --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592329; cv=none; d=zohomail.com; s=zohoarc; b=PPuQ1CAhjaDuV/FPNBlaaDcUm/RDUlK9BQ8lLTitDFvRW6IFa+474Bn9G4qPG8Kp/CSdewEDobNmIY5zmugjMkb2bYNIoGYFsD7YQdypYixZCNBv2F8+pwFOFTzMHJwg2mJRsiYSW9Y7NSeIjRMtb2vygHsKBVcJX16IQHiTkqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592329; 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=ucBnDbok7v6Mu7KPseGvFTjV3duwh5RlIILFahRdtRA=; b=g38wMFa23z58yukU2AxhEyHQgvDSTnPGXu5LRXUs6ZeHuabpdrPuH4lfbUdMWV/JYM65pf+QhrIP530NusbV1rXG7ZpqY4FyLPw0BZhXTALIhoai4SY/fXr/NmWeM9SJJrRDwGd2vibDQGgqipkqJaElYMwhIQTGmpf+n6mVVo4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592329254110.85672956085205; Fri, 30 May 2025 01:05:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiD-0002W7-39; Fri, 30 May 2025 04:03:33 -0400 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 1uKui8-0002Ug-FZ for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:29 -0400 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 1uKui6-0004am-S5 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:28 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-uFPu5UrRM6yVn8KMI1MiNw-1; Fri, 30 May 2025 04:03:20 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ad56c5412f2so153907066b.1 for ; Fri, 30 May 2025 01:03:20 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adb32e347fasm111858866b.168.2025.05.30.01.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592206; 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=ucBnDbok7v6Mu7KPseGvFTjV3duwh5RlIILFahRdtRA=; b=VHNz+WniFEagXQB2cLfCCroUCFHgByqhLhcAkKTmgs21oVfDvRTPw7/cDk/9vx47Wwhmbg xGWHHJtq3FyXwxdQo4VrArBNgEUf2IYGf4zEDgg61TlHh95vPhUcOy/ySFRezjSGXI/1h6 kJnG7zfqcZm+j/AkTlot9jyA+QsVjwQ= X-MC-Unique: uFPu5UrRM6yVn8KMI1MiNw-1 X-Mimecast-MFC-AGG-ID: uFPu5UrRM6yVn8KMI1MiNw_1748592199 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592196; x=1749196996; 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=ucBnDbok7v6Mu7KPseGvFTjV3duwh5RlIILFahRdtRA=; b=OfnkbbSDpO0vOQS5kTQjYleIioiAVCraGY0MjqG7569uxn6kXwuINwAFOIUoGSzwea MM2tPHbDJ6ZW0q73UvilstjDKhZRFk35vdYtvOYUsMHihfw198OpCm9eTM7e1dnSdQ8Z 9Zhw4stWx7OoRklQLFdmSLcx2sau2vAsxwSkZyjKGFG9EjPdsjCcUEEmaKxq3n257JZE sQJ8VTIeMgobVxjgfYfQ0ZhnY975Uk9cjcD3lVA78WbM1DfWsHVPuiS+ceGXukob7i+/ ruzHmIxFXPfIVJ66dpcwsBYTRMGSe0Fbez0RTQqyTOTm97kdT5qq9lswMwYPxEP6ViAT msEA== X-Gm-Message-State: AOJu0YxkabdetOCfZ+sy5F4VcLmsX28yy8otsbI1f9ZX0RTzH8KPKp16 HnQGLyy9Yq58TNIvwZ3LjjHT6vSVmcQT15xG3FCkB6l8GjaHZogZrAl0jwCEihqpxSoX3BNdPq4 EvIEFGIpUdwpcmZT6sfUb5fzZO4BGJbZ0WEwx1ytyLigBOD2ca+iivHQQGItYcGwnIOT03qBYLn SWBCNDirszzUQRz4r3Qa+jykC7nDa+chO8eldB3zAf X-Gm-Gg: ASbGncsnBhWFS5lDgRSCqk6doTCsaq0jjcJCVfFuendYZr920JcfCd+6xtajhQkgZTw z43mrEU4E5+lvMXASgG89OQd+FKqXuAAODyfg2eydtZf6OgZ+7g1Hje7Y8F3NrU30FFsBbDPjj7 Shohi+pWe6z4/kZ2cwnElrD1DWS1IgXxcDNwhRQsEAhcZ+bbuo5GsK6kjNaVIWppPP8L/qKkfRP 03sbGaPu8RzYvzTaBsX6UM7CrQKRs/TH7a117h0MiPkv5fTLKFLMu/HKJCddHzwEGqZzvLsofW8 XEwlDPz8fRrF+OxtGj9Qxzn2 X-Received: by 2002:a17:907:3d90:b0:ad8:9257:571c with SMTP id a640c23a62f3a-adb36b4cdd9mr134316966b.20.1748592196338; Fri, 30 May 2025 01:03:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoaUH0pu+T1ZgUEPTJlRucO+jfglmnp6UDpzApsFnlT+8QhhfYXnmbuNXg/a34e/1wNM6Fhg== X-Received: by 2002:a17:907:3d90:b0:ad8:9257:571c with SMTP id a640c23a62f3a-adb36b4cdd9mr134313666b.20.1748592195840; Fri, 30 May 2025 01:03:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 03/14] util/error: expose Error definition to Rust code Date: Fri, 30 May 2025 10:02:55 +0200 Message-ID: <20250530080307.2055502-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592331939116600 Content-Type: text/plain; charset="utf-8" This is used to preserve the file and line in a roundtrip from C Error to Rust and back to C. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- include/qapi/error-internal.h | 26 ++++++++++++++++++++++++++ rust/wrapper.h | 1 + util/error.c | 10 +--------- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 include/qapi/error-internal.h diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h new file mode 100644 index 00000000000..d5c3904adec --- /dev/null +++ b/include/qapi/error-internal.h @@ -0,0 +1,26 @@ +/* + * QEMU Error Objects - struct definition + * + * Copyright IBM, Corp. 2011 + * Copyright (C) 2011-2015 Red Hat, Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster , + * + * This work is licensed under the terms of the GNU LGPL, version 2. See + * the COPYING.LIB file in the top-level directory. + */ + +#ifndef QAPI_ERROR_INTERNAL_H + +struct Error +{ + char *msg; + ErrorClass err_class; + const char *src, *func; + int line; + GString *hint; +}; + +#endif diff --git a/rust/wrapper.h b/rust/wrapper.h index beddd9aab2f..6060d3ba1ab 100644 --- a/rust/wrapper.h +++ b/rust/wrapper.h @@ -60,6 +60,7 @@ typedef enum memory_order { #include "hw/qdev-properties-system.h" #include "hw/irq.h" #include "qapi/error.h" +#include "qapi/error-internal.h" #include "migration/vmstate.h" #include "chardev/char-serial.h" #include "exec/memattrs.h" diff --git a/util/error.c b/util/error.c index 673011b89e9..e5bcb7c0225 100644 --- a/util/error.c +++ b/util/error.c @@ -15,15 +15,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/error-report.h" - -struct Error -{ - char *msg; - ErrorClass err_class; - const char *src, *func; - int line; - GString *hint; -}; +#include "qapi/error-internal.h" =20 Error *error_abort; Error *error_fatal; --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592257; cv=none; d=zohomail.com; s=zohoarc; b=OfyzCO1LNm9vKcnNZ1HH8gShgX9uqkqm9FwNK3uqF/sMfyUS73dvwoiWWKxpO9S87LhMr9XPe4odA7TnljmkF7VJea/BltHYGOD7IiH4OwjFJCqU/Ejn7M8shlv110doJtGjnOILOn3Cvf/K2x8ObIhdnULkf+6QDQGPxXeRcCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592257; 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=XCq8tY2fAXF+N+KSLu0bH/nomQD4+3xw+ZZePK8BKis=; b=WG3uXWl8ZBEjISoLv1jlBpw1qO1AV5KTfZ6C0EKvjoPLRPrRlr3AihbHUwdiFL6jjQbhdz6YFDPh773LIVRvuz0HCJQLpZHuaCsq4bHLy58HQsq4x9JR3X4qm8EXjqHaq2Ji9m8n9CLx944JDuqpQQn1rA1Hh4BcNxipUivaTPY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592257740627.2945918314052; Fri, 30 May 2025 01:04:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKui9-0002UE-G5; Fri, 30 May 2025 04:03:29 -0400 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 1uKui5-0002Ry-G1 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:25 -0400 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 1uKui3-0004ZI-So for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:25 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-zLbCjBSPP2qW_n44XIdVlg-1; Fri, 30 May 2025 04:03:20 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ac3e0c1336dso108176566b.3 for ; Fri, 30 May 2025 01:03:20 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada5d82d6fdsm282107766b.49.2025.05.30.01.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592202; 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=XCq8tY2fAXF+N+KSLu0bH/nomQD4+3xw+ZZePK8BKis=; b=bau0pGnRHB/9f4tdskmoA8en18Nvxb7qH/xvKBNqNg2g2wtiT+cDGKsDaCTKk/WwAKcLaQ C5/X2k2nZBoA6M5NxOkNbAdkHKXjUMG1hCN9+8RUC61AgRjtbrEbJO7E0aQoTO3vbuTnJt vkrjRccs6TFcea1T6qQ7DHevHLnazmw= X-MC-Unique: zLbCjBSPP2qW_n44XIdVlg-1 X-Mimecast-MFC-AGG-ID: zLbCjBSPP2qW_n44XIdVlg_1748592200 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592199; x=1749196999; 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=XCq8tY2fAXF+N+KSLu0bH/nomQD4+3xw+ZZePK8BKis=; b=RzQY+P7BCni4UkteUGhevwM7tx0/aADuyuXd6KKovmbKXx1P78HBJOM3lJAmOyH27A 1UEaZspHqKGRtu9A4uSkMyHtp8I4spSusN8Vjtz8gKnfDrKkfdTLtBFOxiwQNb7HX1L7 W+2qb27pgFX7oMdouhe1SrtiOqg6gPPe9sDJC0OSQNpfd4VuFeFTphpYrdTkKBsUyDqW /rQxrKkHGAK/Dgbh6xlI5o7qUGwxBoipsSR5ZqerjKTwgmodlmUPeD7IxsBCkn1uNYto d74TTNiD239sOVaBgZl4PyuHR5GrBUzpl6lztbxGzC3lRcb6TyTnQgIChYeIcf3pL/Bs kKmg== X-Gm-Message-State: AOJu0YxYsC/rX0DGJ2QwSbad36lWUjIFtJleWLL54WYL4J2w6fIs8ECj Y2T7rDzT1sg//Fj/gDh/BYTfkEzqO7cQGxG03dganhGqGwxptMnH58vPFGYRT+RCFH/suSnYknh pittBZCY8KXJpBRG510PRKXVYBJ7E+LBZhpDP0rRt/fONQor4aWwkHa+lj6xyQ+cVQulvynqtYP 24AY9eb7VwYyWUNAEaIodimKUxDKx9cHSizeJwxFJJ X-Gm-Gg: ASbGnctUI3nzmQdIMusxcKp5sj07XBrUsHUpDnwcvb7WsBvJcB4l27p7BGouqKLju7G TMuc7Fus1221rN8ojmt4wy2UhE8+hzO88qOsLhUvPOkWi7sG4xg5y850b4vVHL4vMFPWWKjJsNK 9kA0D48FguhXf4Q9+qZQbR/fkMhikfK6a8o8OnP4wPMSVzei3UFMtt+4rLgL8iNYoz3AQjU/gy9 NbKL9unWATt8fld2Vm7PQJqDgyH8U5wYYBe7hlftZjEVvgRTh/C3Qw8899gGYYgvuS+vt6+pX/A lK3pBB93uZ3sqQ== X-Received: by 2002:a17:907:3fa1:b0:ad8:8efe:3205 with SMTP id a640c23a62f3a-adb36c28fccmr117420666b.55.1748592199309; Fri, 30 May 2025 01:03:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEQo5YG2tBnLVZRsKJ1asxjNl5WUXpmCn1//UgZx80NcLLRq98xU2Qn9nIuErLvCzhcSS9LA== X-Received: by 2002:a17:907:3fa1:b0:ad8:8efe:3205 with SMTP id a640c23a62f3a-adb36c28fccmr117416966b.55.1748592198752; Fri, 30 May 2025 01:03:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 04/14] util/error: allow non-NUL-terminated err->src Date: Fri, 30 May 2025 10:02:56 +0200 Message-ID: <20250530080307.2055502-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592259325116600 Content-Type: text/plain; charset="utf-8" Rust makes the current file available as a statically-allocated string, but without a NUL terminator. Allow this by storing an optional maximum length in the Error. Note that for portability I am not relying on fprintf's precision specifier not accessing memory beyond what will be printed. Signed-off-by: Paolo Bonzini --- include/qapi/error-internal.h | 1 + util/error.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/qapi/error-internal.h b/include/qapi/error-internal.h index d5c3904adec..f5eb8ad2379 100644 --- a/include/qapi/error-internal.h +++ b/include/qapi/error-internal.h @@ -19,6 +19,7 @@ struct Error char *msg; ErrorClass err_class; const char *src, *func; + int src_len; int line; GString *hint; }; diff --git a/util/error.c b/util/error.c index e5bcb7c0225..3449ecc0b92 100644 --- a/util/error.c +++ b/util/error.c @@ -24,8 +24,8 @@ Error *error_warn; static void error_handle(Error **errp, Error *err) { if (errp =3D=3D &error_abort) { - fprintf(stderr, "Unexpected error in %s() at %s:%d:\n", - err->func, err->src, err->line); + fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n", + err->func, err->src_len, err->src, err->line); error_report("%s", error_get_pretty(err)); if (err->hint) { error_printf("%s", err->hint->str); @@ -67,6 +67,7 @@ static void error_setv(Error **errp, g_free(msg); } err->err_class =3D err_class; + err->src_len =3D -1; err->src =3D src; err->line =3D line; err->func =3D func; --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592257; cv=none; d=zohomail.com; s=zohoarc; b=PpT1YgjUguPVY/At4NzDaXGG4DEIngx3UG2pVzwwAsmwER0nD4MkGmWHPT0KcQs2ycqHxN6M5cONbb7+eCQXmKMRh9dU9TeDsUUI8xrFaq/Bn1/UOrCc4iNgNRPuvpktHbfJ9wTubYsJnGe4LB+3x37V7OpEKnM1Wn3MgLELx3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592257; 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=myOvVFZKA+ce91dh+2uxifrByBNZxhGHP7Vbe62GjBw=; b=VuCiYUIC8kRLy0uZk8NIlbA06/0x43+/DcSEHebhjZ1EfD+t04y+MO/yaWMkTRDq+L2usVFrTaXUeARf37HeKS8+wISFwKEtfpcEVGMsan9XApOal3vG9Nn8YOx8wNtpWv+7mRpkPh4wsXxKBApGuENqUMEIS2GOFbqJyaktIhg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17485922578071000.9547091265125; Fri, 30 May 2025 01:04:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiA-0002Vs-PV; Fri, 30 May 2025 04:03:31 -0400 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 1uKui6-0002Tz-U8 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:26 -0400 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 1uKui5-0004aR-H1 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:26 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-C2pr7AM5P02nwvMsW2CE5A-1; Fri, 30 May 2025 04:03:23 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-acb94dbd01fso162788666b.1 for ; Fri, 30 May 2025 01:03:23 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada6ad3a6ccsm279233966b.156.2025.05.30.01.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592204; 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=myOvVFZKA+ce91dh+2uxifrByBNZxhGHP7Vbe62GjBw=; b=WC1Q50b3Vq7rnv00hjhZL7dGR95lt7biFl9HX0iMVIm1j245cIgO4bIK+uO+P+X1YL601d IV3K5KdOCWVLP4TVfAcOC4TuD4R0MuBDBIt+tMhyevAnyEUItJI0B0DcH3+V/ZPWS0dW1v 7pua9AF9AseRW+cFRsR6880789E5FvU= X-MC-Unique: C2pr7AM5P02nwvMsW2CE5A-1 X-Mimecast-MFC-AGG-ID: C2pr7AM5P02nwvMsW2CE5A_1748592202 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592202; x=1749197002; 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=myOvVFZKA+ce91dh+2uxifrByBNZxhGHP7Vbe62GjBw=; b=adMEpoAip6H01eOSLqQoGwvn82n49GeWlFBl8W51R23g0hzOb3+27OMBIXsU2UqdSM TbTmjGI5WScBShmltDu+xA6lCirbt0Gt3fDlAyOl+BTWYSKEEy8NZn/9Ir3tWiCUddRA CuW3krnDSvCyFJnWQwumg7BveaiqeyPWwIv8bhZMlB91b1hzUtFB4bC8yqk7QczlPfF5 Fb/agnDXDFDPIUpycEqmbpAZBZ+vzBKDpFU+QswbAEzK087ZctC/wtRh9wJzzQpabN2i SABZETjmkdq0flxLbSySHWyQbxcewrQaWTsyxLAt81kfpyqxQsb8gGd7/bqHyzTi3lo+ DGCg== X-Gm-Message-State: AOJu0Yw58hyQZZ8640KKOEg/cQbSER5OLqgvKMdGncyg6D7DuHNFQ6Pr R1woINR92r/YPi2Vp9a3AMCVVOirRA0LNje4rEsmhZf/Y+K+7dmOPneHWXhsW0oXnnYbUwdycnj Be/UzuLGkZQTzheoERUJHAvC8MvwW2ecy99djc/KqS4o+HRsHuonE5r1CWxger0hRdcjFgcSxOx Emjed7eM0PWRwk9OsPUvvSB4lB0yQVP5thZwAHtLg/ X-Gm-Gg: ASbGncsgvlaQtJnih9cbPWTtY9T97gBMMVDoRcRmPUQ9DWbrwqDPOK/9gRRZk9FiPXH 0ZSESzO0DJd+eYAlLb0ZZXjv4aCEXaojfOXYF8XRPaOoFfZeTRQCY64UPDTmUcQnOgogSq+0RxO lOSRA5kdv/ZK2WmjqBdFP1lQOq84GCTIQ2X/IxNZj0onWtBH6XpD6RM2Pv7aRGMWlu3Lo9cXGyS 1esr1vTEEOH2tQIKp/Ypk0VpGa+9TmO95kI42LTU58PrweQQVF4c1CfuLymaMNkjhwyRJcLKyNO hJ7qWyzlo52T7g== X-Received: by 2002:a17:906:478d:b0:ace:5461:81dd with SMTP id a640c23a62f3a-adb36b05802mr118174266b.3.1748592201662; Fri, 30 May 2025 01:03:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGudTLYnNAM1SlXn1/5qLjhSkUub+t2LTPYnLarw/rLSgeYw9bvLuyVa3Da0r88P1XO23KT/A== X-Received: by 2002:a17:906:478d:b0:ace:5461:81dd with SMTP id a640c23a62f3a-adb36b05802mr118166766b.3.1748592200534; Fri, 30 May 2025 01:03:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 05/14] util/error: make func optional Date: Fri, 30 May 2025 10:02:57 +0200 Message-ID: <20250530080307.2055502-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592259266116600 Content-Type: text/plain; charset="utf-8" The function name is not available in Rust, so make it optional. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster --- util/error.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/util/error.c b/util/error.c index 3449ecc0b92..daea2142f30 100644 --- a/util/error.c +++ b/util/error.c @@ -24,8 +24,13 @@ Error *error_warn; static void error_handle(Error **errp, Error *err) { if (errp =3D=3D &error_abort) { - fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n", - err->func, err->src_len, err->src, err->line); + if (err->func) { + fprintf(stderr, "Unexpected error in %s() at %.*s:%d:\n", + err->func, err->src_len, err->src, err->line); + } else { + fprintf(stderr, "Unexpected error at %.*s:%d:\n", + err->src_len, err->src, err->line); + } error_report("%s", error_get_pretty(err)); if (err->hint) { error_printf("%s", err->hint->str); --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592360; cv=none; d=zohomail.com; s=zohoarc; b=CrSFIo6eR8QeA39/mEI/ddQS5M5qlHIxFlIRPMP1c/z7l8jBHjZWfVLlOxEDojZk+E5aD6BJK5x3a5xPBJloKuqnhfjk1U8/cGu3savBc94hKMdvRDp9W6gALeZAF5KDX+qkaQOFSj9nlyg5CzS9YF7NgBP/nBklg4nwvfXI5MY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592360; h=Content-Type: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=1azCmbJZuAfWQgPSVyPr6AsyjXwV0of9HtRemDDmemU=; b=kFBFFoooiSt/wqo68LkBCGEB1eSfW+ZJjyXpPiuPKgNoKrHHSRW7NMlBleVPKKYvyvaIav6cXzsLWxZBDcZD+IPVxUVF6MC3iv9buhibNAWY15XeiSuGN9rkRHhYFqbW11SfwXakJvdYRvZK9llzadpsa4s76v2m2tgSHTwqeC4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592360830550.6518134677588; Fri, 30 May 2025 01:06:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiT-0002b9-GC; Fri, 30 May 2025 04:03:49 -0400 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 1uKuiD-0002Wm-U0 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:35 -0400 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 1uKui9-0004bO-GV for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:32 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-Y21pxoK2OG2PZD9WWpDsUg-1; Fri, 30 May 2025 04:03:26 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-acb61452b27so137795066b.2 for ; Fri, 30 May 2025 01:03:26 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada6ad395dfsm281759766b.127.2025.05.30.01.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1azCmbJZuAfWQgPSVyPr6AsyjXwV0of9HtRemDDmemU=; b=DSjEiKHopEmnNkz2D7+7XMWXWPIcWw4XfdV2K7LfrZhOxylUjcTtMwR7wk9kUXT4CrHjFs C4YCvGxmHBkzy6eHn7BOmgmJ3hl6f/g43AZZdjLV5a5rw4MIV/j4E7TllMcLlb8bqIqTxm lxi7ra7NpZECpLQ3ZJ25HP2GUOxPViw= X-MC-Unique: Y21pxoK2OG2PZD9WWpDsUg-1 X-Mimecast-MFC-AGG-ID: Y21pxoK2OG2PZD9WWpDsUg_1748592206 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592204; x=1749197004; 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=1azCmbJZuAfWQgPSVyPr6AsyjXwV0of9HtRemDDmemU=; b=YBeYRbn//fiZ6lEvoiYwNBxLZonvC2lrLy9Wew1tlYx1XxlNUzgeOlDKlmthR/CspF myLhuK/r+dMEVLHdYY7xqnR+5ZSHicrAdd6ICH90gjGaBVNA7L0ltyPJNES+xBAQCPNR SfIA5wfUumEpDwPqwIyO4BLg5vjljWP2tiR9iY0Q66aRWQhi7atobyYtOzoLzocWdLT4 gLgFQfx809F+4IgAomYC3cwvRHs08RN+R/UkwoTjmYHQhAAwDyJYPl5i0CArdsYAXsNk ejZE86jWqXxK09J6rkSaRuS3asviYxM+NjNfVRJUHYHT7oc/Jw9THExqfMO0arkUNDAe b47g== X-Gm-Message-State: AOJu0Yxfh5ahwVZo0fZHPrNq0kQhNoutRcj57PRRWM4HtkbMwS/wa5NW NlE6Oak5+AtoxdIQGF07sUZsRM3dMMMxEPX0jhFsLkSsKHAqJlH06b+MIHDGex2jJTAkoPuOM13 i6eHDW9QIjkFNlWMvjRAKp/BbuBfnBCjXxzMauVaGlB6jGRsLkNNnphHzF/sMCV46xtwj5xce9y /dZHM5B4AavGz9RezZqmRn5+r1/bZngD9XBjCGHeLW X-Gm-Gg: ASbGncsLAcymU0MYX3ELmuhMAU8ibJofosG4y7UMM4l1Di0QzleLPP6ShQrNNZqTOI5 hEw9Rv6ZrGhXP8wZYP0I/m/ggJv4EF3/YwZO0BkAS9hjq9hSde81dieWnQQiSxVM4brgHAiIC10 gcz93XVmjPBis6txxRexHo3opEGxPkyYVnZTIecTT5evlweX5XYZSCtr2D7MuhvNLnC+pO7Jp+S 7XJ5//VOC5bhtzY2fEfWN0kBQG44JEVav0g1axVP8fvHPLV0E4NxBwvXjVRN3zv5meea7aVX/Bh qakEx/VH0yfcdA== X-Received: by 2002:a17:907:1c8c:b0:ad5:2d77:7ca7 with SMTP id a640c23a62f3a-adb3230513fmr221919066b.43.1748592204167; Fri, 30 May 2025 01:03:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEObLGVlMkxoHvdK//Zs9TBV2/VXjAaS4OCBscamgFKTe2ucV1UnEPBC0YVEAf3+nrdgH5OA== X-Received: by 2002:a17:907:1c8c:b0:ad5:2d77:7ca7 with SMTP id a640c23a62f3a-adb3230513fmr221916066b.43.1748592203646; Fri, 30 May 2025 01:03:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 06/14] rust: qemu-api: add bindings to Error Date: Fri, 30 May 2025 10:02:58 +0200 Message-ID: <20250530080307.2055502-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=unavailable 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: 1748592362629116600 Provide an implementation of std::error::Error that bridges the Rust anyhow::Error and std::panic::Location types with QEMU's Error*. It also has several utility methods, analogous to error_propagate(), that convert a Result into a return value + Error** pair. Signed-off-by: Paolo Bonzini --- rust/Cargo.lock | 17 +++ rust/Cargo.toml | 1 + rust/qemu-api/Cargo.toml | 2 + rust/qemu-api/meson.build | 1 + rust/qemu-api/src/error.rs | 299 +++++++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 3 + 6 files changed, 323 insertions(+) create mode 100644 rust/qemu-api/src/error.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 13d580c693b..961005bb513 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version =3D 3 =20 +[[package]] +name =3D "anyhow" +version =3D "1.0.98" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdc= d487" + [[package]] name =3D "arbitrary-int" version =3D "1.2.7" @@ -37,6 +43,15 @@ version =3D "1.12.0" source =3D "registry+https://github.com/rust-lang/crates.io-index" checksum =3D "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385= b58b" =20 +[[package]] +name =3D "foreign" +version =3D "0.3.1" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "17ca1b5be8c9d320daf386f1809c7acc0cb09accbae795c2001953fa5058= 5846" +dependencies =3D [ + "libc", +] + [[package]] name =3D "hpet" version =3D "0.1.0" @@ -106,6 +121,8 @@ dependencies =3D [ name =3D "qemu_api" version =3D "0.1.0" dependencies =3D [ + "anyhow", + "foreign", "libc", "qemu_api_macros", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index a00b8ad0bcd..26f3ec09d3d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -66,6 +66,7 @@ missing_safety_doc =3D "deny" mut_mut =3D "deny" needless_bitwise_bool =3D "deny" needless_pass_by_ref_mut =3D "deny" +needless_update =3D "deny" no_effect_underscore_binding =3D "deny" option_option =3D "deny" or_fun_call =3D "deny" diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index c96cf50e7a1..db7000dee44 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -15,7 +15,9 @@ rust-version.workspace =3D true =20 [dependencies] qemu_api_macros =3D { path =3D "../qemu-api-macros" } +anyhow =3D "~1.0" libc =3D "0.2.162" +foreign =3D "~0.3.1" =20 [features] default =3D ["debug_cell"] diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index aa22252866d..ef0de51266b 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -19,6 +19,7 @@ _qemu_api_rs =3D static_library( 'src/cell.rs', 'src/chardev.rs', 'src/errno.rs', + 'src/error.rs', 'src/irq.rs', 'src/memory.rs', 'src/module.rs', diff --git a/rust/qemu-api/src/error.rs b/rust/qemu-api/src/error.rs new file mode 100644 index 00000000000..0bdd413a0a2 --- /dev/null +++ b/rust/qemu-api/src/error.rs @@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +//! Error propagation for QEMU Rust code +//! +//! In QEMU, an `Error` usually consists of a message and an errno value. +//! In this wrapper, the errno value is replaced by an [`anyhow::Error`] +//! so that it is easy to pass any other Rust error type up to C code. +//! Note that the backtrace that is provided by `anyhow` is not used yet, +//! only the message ends up in the QEMU `Error*`. +//! +//! The message part can be used to clarify the inner error, similar to +//! `error_prepend`, and of course to describe an erroneous condition that +//! does not come from another [`Error`](std::error::Error) (for example an +//! invalid argument). +//! +//! On top of implementing [`std::error::Error`], [`Error`] provides funct= ions +//! to simplify conversion between [`Result<>`](std::result::Result) and +//! C `Error**` conventions. In particular: +//! +//! * [`ok_or_propagate`](qemu_api::Error::ok_or_propagate), +//! [`bool_or_propagate`](qemu_api::Error::bool_or_propagate), +//! [`ptr_or_propagate`](qemu_api::Error::ptr_or_propagate) can be used = to +//! build a C return value while also propagating an error condition +//! +//! * [`err_or_else`](qemu_api::Error::err_or_else) and +//! [`err_or_unit`](qemu_api::Error::err_or_unit) can be used to build a +//! `Result` +//! +//! While these facilities are useful at the boundary between C and Rust c= ode, +//! other Rust code need not care about the existence of this module; it c= an +//! just use the [`qemu_api::Result`] type alias and rely on the `?` opera= tor as +//! usual. +//! +//! @author Paolo Bonzini + +use std::{ + borrow::Cow, + ffi::{c_char, c_int, c_void, CStr}, + fmt::{self, Display}, + panic, ptr, +}; + +use foreign::{prelude::*, OwnedPointer}; + +use crate::bindings; + +pub type Result =3D std::result::Result; + +#[derive(Debug)] +pub struct Error { + msg: Option>, + /// Appends the print string of the error to the msg if not None + cause: Option, + file: &'static str, + line: u32, +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + self.cause.as_ref().map(AsRef::as_ref) + } + + #[allow(deprecated)] + fn description(&self) -> &str { + self.msg + .as_deref() + .or_else(|| self.cause.as_deref().map(std::error::Error::descr= iption)) + .unwrap_or("unknown error") + } +} + +impl Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut prefix =3D ""; + if let Some(ref msg) =3D self.msg { + write!(f, "{msg}")?; + prefix =3D ": "; + } + if let Some(ref cause) =3D self.cause { + write!(f, "{prefix}{cause}")?; + } else if prefix.is_empty() { + f.write_str("unknown error")?; + } + Ok(()) + } +} + +impl From for Error { + #[track_caller] + fn from(msg: String) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(Cow::Owned(msg)), + cause: None, + file: location.file(), + line: location.line(), + } + } +} + +impl From<&'static str> for Error { + #[track_caller] + fn from(msg: &'static str) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(Cow::Borrowed(msg)), + cause: None, + file: location.file(), + line: location.line(), + } + } +} + +impl From for Error { + #[track_caller] + fn from(error: anyhow::Error) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: None, + cause: Some(error), + file: location.file(), + line: location.line(), + } + } +} + +impl Error { + /// Create a new error, prepending `msg` to the + /// description of `cause` + #[track_caller] + pub fn with_error(msg: impl Into>, cause: impl Into<= anyhow::Error>) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(msg.into()), + cause: Some(cause.into()), + file: location.file(), + line: location.line(), + } + } + + /// Consume a result, returning `false` if it is an error and + /// `true` if it is successful. The error is propagated into + /// `errp` like the C API `error_propagate` would do. + /// + /// # Safety + /// + /// `errp` must be a valid argument to `error_propagate`; + /// typically it is received from C code and need not be + /// checked further at the Rust=E2=86=94C boundary. + pub unsafe fn bool_or_propagate(result: Result<()>, errp: *mut *mut bi= ndings::Error) -> bool { + // SAFETY: caller guarantees errp is valid + unsafe { Self::ok_or_propagate(result, errp) }.is_some() + } + + /// Consume a result, returning a `NULL` pointer if it is an + /// error and a C representation of the contents if it is + /// successful. The error is propagated into `errp` like + /// the C API `error_propagate` would do. + /// + /// # Safety + /// + /// `errp` must be a valid argument to `error_propagate`; + /// typically it is received from C code and need not be + /// checked further at the Rust=E2=86=94C boundary. + #[must_use] + pub unsafe fn ptr_or_propagate( + result: Result, + errp: *mut *mut bindings::Error, + ) -> *mut T::Foreign { + // SAFETY: caller guarantees errp is valid + unsafe { Self::ok_or_propagate(result, errp) }.clone_to_foreign_pt= r() + } + + /// Consume a result in the same way as `self.ok()`, but also propagate + /// a possible error into `errp`, like the C API `error_propagate` + /// would do. + /// + /// # Safety + /// + /// `errp` must be a valid argument to `error_propagate`; + /// typically it is received from C code and need not be + /// checked further at the Rust=E2=86=94C boundary. + pub unsafe fn ok_or_propagate( + result: Result, + errp: *mut *mut bindings::Error, + ) -> Option { + result.map_err(|err| unsafe { err.propagate(errp) }).ok() + } + + /// Equivalent of the C function `error_propagate`. Fill `*errp` + /// with the information container in `self` if `errp` is not NULL; + /// then consume it. + /// + /// # Safety + /// + /// `errp` must be a valid argument to `error_propagate`; + /// typically it is received from C code and need not be + /// checked further at the Rust=E2=86=94C boundary. + pub unsafe fn propagate(self, errp: *mut *mut bindings::Error) { + if errp.is_null() { + return; + } + + let err =3D self.clone_to_foreign_ptr(); + + // SAFETY: caller guarantees errp is valid + unsafe { + errp.write(err); + } + } + + /// Convert a C `Error*` into a Rust `Result`, using + /// `Ok(())` if `c_error` is NULL. Free the `Error*`. + /// + /// # Safety + /// + /// `c_error` must be `NULL` or valid; typically it was initialized + /// with `ptr::null_mut()` and passed by reference to a C function. + pub unsafe fn err_or_unit(c_error: *mut bindings::Error) -> Result<()>= { + // SAFETY: caller guarantees c_error is valid + unsafe { Self::err_or_else(c_error, || ()) } + } + + /// Convert a C `Error*` into a Rust `Result`, calling `f()` to + /// obtain an `Ok` value if `c_error` is NULL. Free the `Error*`. + /// + /// # Safety + /// + /// `c_error` must be `NULL` or valid; typically it was initialized + /// with `ptr::null_mut()` and passed by reference to a C function. + pub unsafe fn err_or_else T>( + c_error: *mut bindings::Error, + f: F, + ) -> Result { + // SAFETY: caller guarantees c_error is valid + let err =3D unsafe { Option::::from_foreign(c_error) }; + match err { + None =3D> Ok(f()), + Some(err) =3D> Err(err), + } + } +} + +impl FreeForeign for Error { + type Foreign =3D bindings::Error; + + unsafe fn free_foreign(p: *mut bindings::Error) { + // SAFETY: caller guarantees p is valid + unsafe { + bindings::error_free(p); + } + } +} + +impl CloneToForeign for Error { + fn clone_to_foreign(&self) -> OwnedPointer { + // SAFETY: all arguments are controlled by this function + unsafe { + let err: *mut c_void =3D libc::malloc(std::mem::size_of::()); + let err: &mut bindings::Error =3D &mut *err.cast(); + *err =3D bindings::Error { + msg: format!("{self}").clone_to_foreign_ptr(), + err_class: bindings::ERROR_CLASS_GENERIC_ERROR, + src_len: self.file.len() as c_int, + src: self.file.as_ptr().cast::(), + line: self.line as c_int, + func: ptr::null_mut(), + hint: ptr::null_mut(), + }; + OwnedPointer::new(err) + } + } +} + +impl FromForeign for Error { + unsafe fn cloned_from_foreign(c_error: *const bindings::Error) -> Self= { + // SAFETY: caller guarantees c_error is valid + unsafe { + let error =3D &*c_error; + let file =3D if error.src_len < 0 { + // NUL-terminated + CStr::from_ptr(error.src).to_str() + } else { + // Can become str::from_utf8 with Rust 1.87.0 + std::str::from_utf8(std::slice::from_raw_parts( + &*error.src.cast::(), + error.src_len as usize, + )) + }; + + Error { + msg: FromForeign::cloned_from_foreign(error.msg), + cause: None, + file: file.unwrap(), + line: error.line as u32, + } + } + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 234a94e3c29..93902fc94bc 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -19,6 +19,7 @@ pub mod cell; pub mod chardev; pub mod errno; +pub mod error; pub mod irq; pub mod memory; pub mod module; @@ -34,6 +35,8 @@ ffi::c_void, }; =20 +pub use error::{Error, Result}; + #[cfg(HAVE_GLIB_WITH_ALIGNED_ALLOC)] extern "C" { fn g_aligned_alloc0( --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592302; cv=none; d=zohomail.com; s=zohoarc; b=dC2m2yDz7utbwOa+YfqKcSPxgwpFziNf1dgJGtP9pGPVKcho+udtV99JceKS0gidF5VO8mudwggaGtTveSBCy5lpVCOXSy8PCiBQE4eeGAz0yFT+AiZ5AIuikVLHkFrOxStvAY5QEexxfWdxfyj0plMa7iXHCDSnbGkJUA/i334= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592302; 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=1iO/8dhA6WpfMpyaQHb2m/rin5HTfnhVCocpzfrKwgI=; b=jMVNZuVN3gTOVO4nsoO3RoRS6sdwNLT+oVzmwT5CvL4qWDXpFPyWoVUvuXNjGqVZ2ALzNiUm3b0/dktqo5/BDjcr5B7zQzMd9zeU3O7YxOXNXodj7axxU9Z8MO2MlLpkaFmBJfePUHgVjEJt5ZI+qn2ZBiAb6vdZx/eOIIHP5i4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592302769560.7745680199066; Fri, 30 May 2025 01:05:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiR-0002Y8-4y; Fri, 30 May 2025 04:03:47 -0400 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 1uKuiD-0002Wn-U8 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:35 -0400 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 1uKuiA-0004bk-BY for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:32 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-197-eAAom6RlPMenz7mZif1_lw-1; Fri, 30 May 2025 04:03:28 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ad8816c50e1so125200766b.0 for ; Fri, 30 May 2025 01:03:27 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adb2fb63cdasm140343566b.120.2025.05.30.01.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592209; 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=1iO/8dhA6WpfMpyaQHb2m/rin5HTfnhVCocpzfrKwgI=; b=IF2j4iavN37If3GcI+OJDZPAU3xoSsV2xgWozBBvvSE59Zo5zFmZZlkzueBSQ8lbj/BoAJ utvhHdDJVS67Wo1YshvghjudiYNih+BXoUl8MKKWkY6IiFIiNgLed9fZiZxc9eVEbIF64z RGA51I0KqrxMJ+ujhA5GzObppeMC5go= X-MC-Unique: eAAom6RlPMenz7mZif1_lw-1 X-Mimecast-MFC-AGG-ID: eAAom6RlPMenz7mZif1_lw_1748592207 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592206; x=1749197006; 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=1iO/8dhA6WpfMpyaQHb2m/rin5HTfnhVCocpzfrKwgI=; b=fTS+mbHydhcNj46DThGy3fjx5DzXHQ9Srw0vgcvX7kCX1YJK4CLpnl3eqqNs/CRVZH DT5brDubddECw45Fnb0NhP7CLPxI63YM0yFXjMWb+dsZpPjiGklO9DT1NXKXZLRQDGLx WXwxXRQCdCVZ82v2/6fL8rfI9zDfrt9+hQ/i9rLd4TH+ek0WkcS94B/aVu0u9hAGIyun Qw+RN4mrie6KVmMs+0MNmD5X+P1aaOkupsZKbXYvv4b8NLnxwnHv8hEBlQTtF8uH6xCQ kQlzAkNf8/leu+m+G8x2+DrDXhpZas3UxVX6h0Ei68O6BTcWsKpkuKva6Y6ohhhd8gtp CNLA== X-Gm-Message-State: AOJu0YytUBNo4CUjAUJD4oD9tW2gp/U1c0wo8c5MPQQDS728tEa+FEx7 gDGTMzZPkUmQC+yiw6y8X+/aofIJYI1mtOymdGIZ8USAjc/0d/9v4Fl8mla4co1P3tijVK9GKTb hYD/EfFajitC73K6R1tjQdtjp7bys8/+Ksa+47sLaWf6oCsTMX4hWcy3kyuYuJf8lzqph9UudpN Hn3YFdm1jLK6U6FAtrofPO9ibQKM3I3TVKrR989sNf X-Gm-Gg: ASbGnctdQZH8//WJ6GLS7pDxXZWhFY+JdUyImEAMd85Gc2HzwYRnDgENsDIL8P/3uta xZeFLkrX+oWyhIA4nMQFDablSN/nTCUoOneYT+QlYGtQChOkqD13EZM9rxB9gD5JG84nadjBCy6 XPtVVxb3rqsnsSfqbNLL4IzdCNAAq0RY/g08+wjPQVw5U1cBciOn0R0iuf7jpvvP3n1Am1nCfwA mgRzE0uKrFd1+UJ+Wzw08BYsyDPt8wNz2KjQBBk/TDxYtdD8eH6uUB99yEdEyg3pb0ULvjXGBrf CdaeSd0Dp3YDrVY40T870gW0 X-Received: by 2002:a17:907:971e:b0:ad8:81c2:64e9 with SMTP id a640c23a62f3a-adb322b3326mr182221766b.8.1748592205717; Fri, 30 May 2025 01:03:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPxF5qdEz3NKmDsuaFYI9b4VZqJVJYtzQtdLrNKwmuV5jFnsqnu8IIE1GfTQcpkdq3mSSH/g== X-Received: by 2002:a17:907:971e:b0:ad8:81c2:64e9 with SMTP id a640c23a62f3a-adb322b3326mr182218966b.8.1748592205171; Fri, 30 May 2025 01:03:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 07/14] rust: qemu-api: add tests for Error bindings Date: Fri, 30 May 2025 10:02:59 +0200 Message-ID: <20250530080307.2055502-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592303706116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/error.rs | 104 +++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/rust/qemu-api/src/error.rs b/rust/qemu-api/src/error.rs index 0bdd413a0a2..a91ce6fefaf 100644 --- a/rust/qemu-api/src/error.rs +++ b/rust/qemu-api/src/error.rs @@ -297,3 +297,107 @@ unsafe fn cloned_from_foreign(c_error: *const binding= s::Error) -> Self { } } } + +#[cfg(test)] +mod tests { + use std::ffi::CStr; + + use anyhow::anyhow; + use foreign::OwnedPointer; + + use super::*; + use crate::{assert_match, bindings}; + + #[track_caller] + fn error_for_test(msg: &CStr) -> OwnedPointer { + // SAFETY: all arguments are controlled by this function + let location =3D panic::Location::caller(); + unsafe { + let err: *mut c_void =3D libc::malloc(std::mem::size_of::()); + let err: &mut bindings::Error =3D &mut *err.cast(); + *err =3D bindings::Error { + msg: msg.clone_to_foreign_ptr(), + err_class: bindings::ERROR_CLASS_GENERIC_ERROR, + src_len: location.file().len() as c_int, + src: location.file().as_ptr().cast::(), + line: location.line() as c_int, + func: ptr::null_mut(), + hint: ptr::null_mut(), + }; + OwnedPointer::new(err) + } + } + + unsafe fn error_get_pretty<'a>(local_err: *mut bindings::Error) -> &'a= CStr { + unsafe { CStr::from_ptr(bindings::error_get_pretty(local_err)) } + } + + #[test] + #[allow(deprecated)] + fn test_description() { + use std::error::Error; + + assert_eq!(super::Error::from("msg").description(), "msg"); + assert_eq!(super::Error::from("msg".to_owned()).description(), "ms= g"); + } + + #[test] + fn test_display() { + assert_eq!(&*format!("{}", Error::from("msg")), "msg"); + assert_eq!(&*format!("{}", Error::from("msg".to_owned())), "msg"); + assert_eq!(&*format!("{}", Error::from(anyhow!("msg"))), "msg"); + + assert_eq!( + &*format!("{}", Error::with_error("msg", anyhow!("cause"))), + "msg: cause" + ); + } + + #[test] + fn test_bool_or_propagate() { + unsafe { + let mut local_err: *mut bindings::Error =3D ptr::null_mut(); + + assert!(Error::bool_or_propagate(Ok(()), &mut local_err)); + assert_eq!(local_err, ptr::null_mut()); + + let my_err =3D Error::from("msg"); + assert!(!Error::bool_or_propagate(Err(my_err), &mut local_err)= ); + assert_ne!(local_err, ptr::null_mut()); + assert_eq!(error_get_pretty(local_err), c"msg"); + bindings::error_free(local_err); + } + } + + #[test] + fn test_ptr_or_propagate() { + unsafe { + let mut local_err: *mut bindings::Error =3D ptr::null_mut(); + + let ret =3D Error::ptr_or_propagate(Ok("abc".to_owned()), &mut= local_err); + assert_eq!(String::from_foreign(ret), "abc"); + assert_eq!(local_err, ptr::null_mut()); + + let my_err =3D Error::from("msg"); + assert_eq!( + Error::ptr_or_propagate(Err::(my_err), &mut loc= al_err), + ptr::null_mut() + ); + assert_ne!(local_err, ptr::null_mut()); + assert_eq!(error_get_pretty(local_err), c"msg"); + bindings::error_free(local_err); + } + } + + #[test] + fn test_err_or_unit() { + unsafe { + let result =3D Error::err_or_unit(ptr::null_mut()); + assert_match!(result, Ok(())); + + let err =3D error_for_test(c"msg"); + let err =3D Error::err_or_unit(err.into_inner()).unwrap_err(); + assert_eq!(&*format!("{err}"), "msg"); + } + } +} --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592314; cv=none; d=zohomail.com; s=zohoarc; b=iB8BZcVmakNo4E5lOUK5hzTcMkIq4K1M67e0S61jUVHt5nC/Znpj0zD1SGp/5KAByJmW7IkPY37Ea4Efn/QubAvi/n9Nzn6u3VEINqbFmH7PQ67S5UyT7AXu2/nxAZTfDhFU/E+NTLzVBZsThpZUhiFrmhBqIUGrjVmwyk8ZtfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592314; 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=I9UYi4Cy39R5dTUfo2DeyIIhvEGm6Vs7YuCFqZJ0aIg=; b=EfH6RwLNluEjkDWjYIo3pR119/fKCINoITtvl+a9LteqD1OCZdG6IltWlBmlbnMidSXrQrwFtVc+q7AX8aKgbMK5fo8Fcet1IUw5mPmAJigwGGMpjkPmc5WmUgknA+F0K7OwP4w0HHXOXUnZZqpJ+3tdNptLgMrqUQJcyXa4jIM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17485923149111006.7693181728663; Fri, 30 May 2025 01:05:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiU-0002bt-Gu; Fri, 30 May 2025 04:03:50 -0400 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 1uKuiH-0002XO-74 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:39 -0400 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 1uKuiF-0004cn-AR for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:36 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-Jgx-WSZ6NNCmeyhh0vJvyg-1; Fri, 30 May 2025 04:03:33 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ab68fbe53a4so90907466b.2 for ; Fri, 30 May 2025 01:03:33 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada6ad39479sm281821066b.124.2025.05.30.01.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592214; 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=I9UYi4Cy39R5dTUfo2DeyIIhvEGm6Vs7YuCFqZJ0aIg=; b=Nmy5OmbHaEbFH84WhJhXN8CEqmx3sjYpMloOvwhAsysriFqH8Y3vQYyae+oSyaCA2Q0wvY smGvyaPRG+RdQro4lT8Nv+AjsS/EY6x9G469hNeB4IgHKSioQBy2cp1hu8po7+OBQLmFxW pWUdLKrNBLaHXdkdxyrn1j9feEWmlAE= X-MC-Unique: Jgx-WSZ6NNCmeyhh0vJvyg-1 X-Mimecast-MFC-AGG-ID: Jgx-WSZ6NNCmeyhh0vJvyg_1748592212 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592212; x=1749197012; 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=I9UYi4Cy39R5dTUfo2DeyIIhvEGm6Vs7YuCFqZJ0aIg=; b=qGxucVlUgaY0vSbEMe5htEt2fkVu/ms1YC4iIwJjlZCyLJSAmbGATVTXLFfA4e/2N+ D317ci2Z0dxYKFxW02vRlUnr5ecE5IL+Wki88DEzqDrwsxDanI7rl73lELtAU8FxW+3C j/xRfc+QBYsD1LZJl7EeR5zG+SrIGZquFWvm1PGSGRDd2fwfnLFx/azSV7tiuZ93Mj21 QBE0tIyg8/+hiQ6Rq0sqCXis5r2gYHieVqiUUdfmMIfjMhx0IRWWVA0SUlmHVZrElEc2 VkwdKwnRV7r1hDdKxSi07rANh0/4oYEr9EcrOWCRoe+EU5WD+eDDTzTtUO45dgYHCaRH FwqA== X-Gm-Message-State: AOJu0YxK4qbghgkAZZOGr7/ZOP3Yq/d4g+4xTZDTYqBh2be+c0nxQ0K6 Ali7vQdj771yV3zCXTGH/noryAhQj1WQKiLoCl5HA4pX+GeQS1Yl1LA/bHsugVU/QuDCOsEqW8i fcS3MX+cz+jKWVlcn3cqTRI0GxTs6cRaudOsmdSvTu1trKwIi6+JvAA9E9+c9IFDkFCC+pe+FR0 DQcAl19cx2eQUmVI2SNDMotHCEpOmMGsLxp9tqrwRA X-Gm-Gg: ASbGnculfJBpX9aOnjUaI458Zi0T8z6Y7SKWfYiQTWjyyzcEZp5bFV5AKzL21BuGxJJ s5Huu/F99G+POMyagVXGlzKBA60ZrBPczrw/AmhfMBZge4lN7BEP9Hdi7Ua11aceh/SKXi0ovNu ZbNN16hDt2xSvEgyuHoR3oW5mcgJUsupbCoLUSzeePoZ5istz+s4l0fdrVLc56KW4s/ScQeljyJ 5Wd8gmz92f/ZJrP8nRqd8NobEYCH29xSHXlygndN/ik9+Wp4aDs3ZDxBHrUFwOKq51dbKae9Kv0 FceFEpLlkMQA3g== X-Received: by 2002:a17:907:9450:b0:ad8:9c97:c2da with SMTP id a640c23a62f3a-adb36bfb187mr113379466b.40.1748592211526; Fri, 30 May 2025 01:03:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkp5F1NC9thYzOG8he490C6v6/TNy0j9MFH/yK+eGJ5b5OxeIRWqOL8unQCi4NlxlUbKXnDg== X-Received: by 2002:a17:907:9450:b0:ad8:9c97:c2da with SMTP id a640c23a62f3a-adb36bfb187mr113358666b.40.1748592208152; Fri, 30 May 2025 01:03:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 08/14] rust: qdev: support returning errors from realize Date: Fri, 30 May 2025 10:03:00 +0200 Message-ID: <20250530080307.2055502-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592315968116600 Content-Type: text/plain; charset="utf-8" Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 5 +++-- rust/hw/timer/hpet/src/device.rs | 5 +++-- rust/qemu-api/src/qdev.rs | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index bd5cee04647..1e715e91bc3 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -175,7 +175,7 @@ fn properties() -> &'static [Property] { fn vmsd() -> Option<&'static VMStateDescription> { Some(&device_class::VMSTATE_PL011) } - const REALIZE: Option =3D Some(Self::realize); + const REALIZE: Option qemu_api::Result<()>> =3D Some(Self= ::realize); } =20 impl ResettablePhasesImpl for PL011State { @@ -619,9 +619,10 @@ fn event(&self, event: Event) { } } =20 - fn realize(&self) { + fn realize(&self) -> qemu_api::Result<()> { self.char_backend .enable_handlers(self, Self::can_receive, Self::receive, Self:= :event); + Ok(()) } =20 fn reset_hold(&self, _type: ResetType) { diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index e3ba62b2875..68c82b09b60 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -724,7 +724,7 @@ fn post_init(&self) { } } =20 - fn realize(&self) { + fn realize(&self) -> qemu_api::Result<()> { if self.int_route_cap =3D=3D 0 { // TODO: Add error binding: warn_report() println!("Hpet's hpet-intcap property not initialized"); @@ -751,6 +751,7 @@ fn realize(&self) { =20 self.init_gpio_in(2, HPETState::handle_legacy_irq); self.init_gpio_out(from_ref(&self.pit_enabled)); + Ok(()) } =20 fn reset_hold(&self, _type: ResetType) { @@ -1042,7 +1043,7 @@ fn vmsd() -> Option<&'static VMStateDescription> { Some(&VMSTATE_HPET) } =20 - const REALIZE: Option =3D Some(Self::realize); + const REALIZE: Option qemu_api::Result<()>> =3D Some(Self= ::realize); } =20 impl ResettablePhasesImpl for HPETState { diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 1279d7a58d5..81052097071 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -12,10 +12,11 @@ pub use bindings::{ClockEvent, DeviceClass, Property, ResetType}; =20 use crate::{ - bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, Error, Resetta= bleClass}, + bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClas= s}, callbacks::FnCall, cell::{bql_locked, Opaque}, chardev::Chardev, + error::{Error, Result}, irq::InterruptSource, prelude::*, qom::{ObjectClass, ObjectImpl, Owned}, @@ -108,7 +109,7 @@ pub trait DeviceImpl: ObjectImpl + ResettablePhasesImpl= + IsA { /// /// If not `None`, the parent class's `realize` method is overridden /// with the function pointed to by `REALIZE`. - const REALIZE: Option =3D None; + const REALIZE: Option Result<()>> =3D None; =20 /// An array providing the properties that the user can set on the /// device. Not a `const` because referencing statics in constants @@ -134,10 +135,11 @@ fn vmsd() -> Option<&'static VMStateDescription> { /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_realize_fn( dev: *mut bindings::DeviceState, - _errp: *mut *mut Error, + errp: *mut *mut bindings::Error, ) { let state =3D NonNull::new(dev).unwrap().cast::(); - T::REALIZE.unwrap()(unsafe { state.as_ref() }); + let result =3D T::REALIZE.unwrap()(unsafe { state.as_ref() }); + unsafe { Error::ok_or_propagate(result, errp); } } =20 unsafe impl InterfaceType for ResettableClass { --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592299; cv=none; d=zohomail.com; s=zohoarc; b=BT7JkUPhwOcDSf9axq4UHoUWc5V+dUSrsO5LGYj3WW2hErFQ2zqvkENM9o9+IKrv2kMq7jx1hTzSxG6ffkqRlNW5fljY0X9H+u+8UCCbZF7qweLPlbTlj+v4JYohj4BzmNwPz3lqNFGVt3sfNdAFxsByMnTJkSReSFCGvuUGsqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592299; 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=ElGaxLGiSIb6e5dqiWIlm8oesZYBfD74a0jBFqGIj5Q=; b=SZ/xkZ9DRMUQ5uVXDJYFcVjyyCRiMB5yy17mLhP2GnCvCp3fcRZw3CzpEpcGZhU3ytuYfBaGKAGhGu5KEMYV73Ma4FPoOk20Fo4PgTEX6H8fvrqj1eW7oKBzJ+AQYH2wECKNCtiY5lT7w2jkP7/J8yaKx/c5k5/gxB+KG7V4KEk= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592298908622.7979137831687; Fri, 30 May 2025 01:04:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiU-0002bg-FJ; Fri, 30 May 2025 04:03:50 -0400 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 1uKuiJ-0002Y4-SY for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:40 -0400 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 1uKuiG-0004d6-VR for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:38 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-QEDzb3LKOq2sr2C8KEdWWw-1; Fri, 30 May 2025 04:03:34 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-ac3e0c1336dso108190566b.3 for ; Fri, 30 May 2025 01:03:34 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada5d7fecc5sm287680966b.10.2025.05.30.01.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592215; 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=ElGaxLGiSIb6e5dqiWIlm8oesZYBfD74a0jBFqGIj5Q=; b=ZiF+ka29QJWKqQHgmwvz8ZsG1RJTXzaqFQxLpf/Yv2/rDb2QHWtTAuDOkooAN2T5rbqnSG f2xIsJ7CJRT27/XlCFE6sKdYjWKudiOr7Paqq8+P5mOSsxhIbZCEeMUAEI55s5deKAyKo9 6lI+OLUhyY3qvDuBR9X4ccblBHxrxtk= X-MC-Unique: QEDzb3LKOq2sr2C8KEdWWw-1 X-Mimecast-MFC-AGG-ID: QEDzb3LKOq2sr2C8KEdWWw_1748592213 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592212; x=1749197012; 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=ElGaxLGiSIb6e5dqiWIlm8oesZYBfD74a0jBFqGIj5Q=; b=X6k/yGsF/fDs7U13puy7S039Nbou6XQmwPWYrjmEB1cDLvHWGyTnM9EB7pojYsE/vk BYpfVhKmISK4R9mxxXeYTg/XVEb1+3eWzfCb3GhTygMIee5Rg7KJMFtZkKWyMmiSdT8S Qz7nHe5L9lrd5TvTw/1nxQHtL7ewAkkbRR25a+UYV/YPKB2Gmz0g4sm9nF258QY6J/ut vcamZulndKs5WWyqbiwAO+FhI15I+8pswXuEF52kfAPBXg4dONX6s2WCJb4ShRFpzzTR NqP0H667mASR+MORSWubZUzXgdD9o0FFvQ2UPQjHifI8vh/+N4YKHanhFgcXujYlM5y2 KgCA== X-Gm-Message-State: AOJu0YwAgxJ6c+aPjWPspcnMcM+pWMBbqkKb2Z/O7BihondDY5k+f9Zj fQpZdTFwLOQKXWC5hQ2I/tg7dYkzOeWbQXe2iM57MmMD1RL7nK3nsDcGBigX9I3JkUIMtCp+aoe UyepxttKJiM6hVs8LRtVpY/1iPHN5T1F6jzcMhNNWoMDENYHMFBFC8b3JbfgkM+fup/Bd9o6cS4 KpxtQ/OKrqb5m5QwLZZOy5MJeIc3L2/vdlbIorz0fL X-Gm-Gg: ASbGncuLWb4yXtSs6/6zYMlLy8mUuMr0x/H3rt46/1UaAndAVV/3t5R+L3iZVhTqn3X wGo9yYuV0Aq0LvuD27shOy6BHVS/lHARYb6Thoij3T6h2yJwN1dxEmQnKCzZt/yNpid52b0eZr5 bcaCjGF03Q4bjgi3d9zAz8HQuUIu1dUFX0PqNYxqU4CS/Kn6PpIdxukbTK0LCOrmars1qNcn3fE H7iDexnE/GKudU4mkveKJwxmyGW1b4D7KVnHRIsN/7QAMq0pFOZ0qx5WUCGh/2pVZ6b2SFsy26H e6PpcX7qi+Ylhw== X-Received: by 2002:a17:907:2dab:b0:ad5:a121:6ebc with SMTP id a640c23a62f3a-adb369a920emr115420466b.0.1748592211854; Fri, 30 May 2025 01:03:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzlWwk+vNhNWbAmh9fEidfaKWhOYah4lEW53NzQosW8rlOvJbnHMfQ5hG1ycPNy1U7ojTbtg== X-Received: by 2002:a17:907:2dab:b0:ad5:a121:6ebc with SMTP id a640c23a62f3a-adb369a920emr115414566b.0.1748592211359; Fri, 30 May 2025 01:03:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 09/14] rust/hpet: change type of num_timers to usize Date: Fri, 30 May 2025 10:03:01 +0200 Message-ID: <20250530080307.2055502-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592299753116600 Content-Type: text/plain; charset="utf-8" Remove the need to convert after every read of the BqlCell. Because the vmstate uses a u8 as the size of the VARRAY, this requires switching the VARRAY to use num_timers_save; which in turn requires ensuring that the num_timers_save is always there. For simplicity do this by removing support for version 1, which QEMU has not been producing for ~15 years. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/timer/hpet/src/device.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index 68c82b09b60..a957de1e767 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -12,7 +12,7 @@ use qemu_api::{ bindings::{ address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_pr= op_bool, - qdev_prop_uint32, qdev_prop_uint8, + qdev_prop_uint32, qdev_prop_usize, }, cell::{BqlCell, BqlRefCell}, irq::InterruptSource, @@ -36,9 +36,9 @@ const HPET_REG_SPACE_LEN: u64 =3D 0x400; // 1024 bytes =20 /// Minimum recommended hardware implementation. -const HPET_MIN_TIMERS: u8 =3D 3; +const HPET_MIN_TIMERS: usize =3D 3; /// Maximum timers in each timer block. -const HPET_MAX_TIMERS: u8 =3D 32; +const HPET_MAX_TIMERS: usize =3D 32; =20 /// Flags that HPETState.flags supports. const HPET_FLAG_MSI_SUPPORT_SHIFT: usize =3D 0; @@ -561,8 +561,8 @@ pub struct HPETState { =20 /// HPET timer array managed by this timer block. #[doc(alias =3D "timer")] - timers: [BqlRefCell; HPET_MAX_TIMERS as usize], - num_timers: BqlCell, + timers: [BqlRefCell; HPET_MAX_TIMERS], + num_timers: BqlCell, num_timers_save: BqlCell, =20 /// Instance id (HPET timer block ID). @@ -572,7 +572,7 @@ pub struct HPETState { impl HPETState { // Get num_timers with `usize` type, which is useful to play with arra= y index. fn get_num_timers(&self) -> usize { - self.num_timers.get().into() + self.num_timers.get() } =20 const fn has_msi_flag(&self) -> bool { @@ -854,7 +854,7 @@ fn pre_save(&self) -> i32 { * also added to the migration stream. Check that it matches the = value * that was configured. */ - self.num_timers_save.set(self.num_timers.get()); + self.num_timers_save.set(self.num_timers.get() as u8); 0 } =20 @@ -884,7 +884,7 @@ fn is_offset_needed(&self) -> bool { } =20 fn validate_num_timers(&self, _version_id: u8) -> bool { - self.num_timers.get() =3D=3D self.num_timers_save.get() + self.num_timers.get() =3D=3D self.num_timers_save.get().into() } } =20 @@ -911,7 +911,7 @@ impl ObjectImpl for HPETState { c"timers", HPETState, num_timers, - unsafe { &qdev_prop_uint8 }, + unsafe { &qdev_prop_usize }, u8, default =3D HPET_MIN_TIMERS ), @@ -1016,16 +1016,16 @@ impl ObjectImpl for HPETState { static VMSTATE_HPET: VMStateDescription =3D VMStateDescription { name: c"hpet".as_ptr(), version_id: 2, - minimum_version_id: 1, + minimum_version_id: 2, pre_save: Some(hpet_pre_save), post_load: Some(hpet_post_load), fields: vmstate_fields! { vmstate_of!(HPETState, config), vmstate_of!(HPETState, int_status), vmstate_of!(HPETState, counter), - vmstate_of!(HPETState, num_timers_save).with_version_id(2), + vmstate_of!(HPETState, num_timers_save), vmstate_validate!(HPETState, VALIDATE_TIMERS_NAME, HPETState::vali= date_num_timers), - vmstate_struct!(HPETState, timers[0 .. num_timers], &VMSTATE_HPET_= TIMER, BqlRefCell, HPETState::validate_num_timers).with_version_= id(0), + vmstate_struct!(HPETState, timers[0 .. num_timers_save], &VMSTATE_= HPET_TIMER, BqlRefCell, HPETState::validate_num_timers).with_ver= sion_id(0), }, subsections: vmstate_subsections! { VMSTATE_HPET_RTC_IRQ_LEVEL, --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592308; cv=none; d=zohomail.com; s=zohoarc; b=W9RDOfqkL/EbM/sAil1SDnXTDWfagOyi54H4ct8wfOeXoZ9BOnR2B03sy7swJHjmxtgswUKA1kj4vfXfdxnNG2HLwdGpruVEy70ealjMd9gFPYdeeohWIuT+XzDfFCAnQzGq0Ffz+RO5e6SfYQUApREaMt1+mmd7mXU9KV4i6tY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592308; 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=T8G+ZwNewrKmt3y0x+FnEurAOu2EK1ulbB74Dqd2P+4=; b=LeUg4Sh+case5zfmxx9Qzj50I3n1vJ9REX2XobpNM0lKqLiVBSEJ+XoR72mgDe6S3p6EkWIb6rM4LU20tmvjIDeVR6faP+Kj/Lf+ipLL7PuYWHX5RpUEnYvrPKsoCqSNnffO6+B2nwnc9TWQ1t5W2PZHt0joGAdQVM1kL32Gasg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592308974644.1536573754537; Fri, 30 May 2025 01:05:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiY-0002e0-0C; Fri, 30 May 2025 04:03:54 -0400 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 1uKuiO-0002Yw-DT for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:45 -0400 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 1uKuiJ-0004de-Kq for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:43 -0400 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-gbNaLtv2Oqq9yfd8RSYH2Q-1; Fri, 30 May 2025 04:03:37 -0400 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-6045875e52fso1297263a12.2 for ; Fri, 30 May 2025 01:03:37 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60567141d48sm1232570a12.60.2025.05.30.01.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592218; 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=T8G+ZwNewrKmt3y0x+FnEurAOu2EK1ulbB74Dqd2P+4=; b=SLI8ZgtJn/qfm8Ae4zqAqoa4BwHxjmzuLZLEXA+zJdDkj1okZtG6UgZSKNN6aqkxPbmMcx 8hVh4Cfq5z/rTxUrsQFxf+K/XHfLMqx1zL4rByHFe15NmdJWRz/EsmuGNTxW3r253u+lvv qt/w4IFOU4jF5J5efkEPic4/yBULKM4= X-MC-Unique: gbNaLtv2Oqq9yfd8RSYH2Q-1 X-Mimecast-MFC-AGG-ID: gbNaLtv2Oqq9yfd8RSYH2Q_1748592216 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592215; x=1749197015; 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=T8G+ZwNewrKmt3y0x+FnEurAOu2EK1ulbB74Dqd2P+4=; b=gj1z5XR8wTIHrOnvIElNCTkDzDC6t1Ej3uDmtsrkHfMDTVNuqVv7k/xiPg/xvOTtp5 PYPh5CFwrVrOUF1K9AfsB6FqVhiKZHvhJ94Ve0GKnZS6zM9Td0R6dZoDk+mY+yGiepA8 gd5OE/s2seS2K3DY7G4krjzBDvt2+YCfqioPmyJctSk5STRPiMjVHcwcVQ4A3gR5IB4F AeG8sg9NjxQNjIT3XRp1W3XBJ9M+2KXwe1K4V9+GMXWpvNmawUcg3U7LSgrMGGHaQg/P /blvuxdvlN/D94/hQBPmKkMOW2iYFVatC59NTcw95fTPxwtLOyqVKFi4OmGJkD9q/KzH gBtQ== X-Gm-Message-State: AOJu0YwwSBMXobpDH0+N3nvjZZ7te3BAkMFiRBriui/CMIWDsGlPkXOp RD+DyZA2YCD2eSm5RtpODHcSRHIWL3YYzxEHT6FHAvrv/t5SIw7OrEYd0uEkqaCfVY90K5oelcJ krx8pOit3x/SE4t0hW/KGBlias0mYZOVuju5kenBRCYrVjk/Lu5FGb+hG8mBWKdqjRIlqPm3+h4 tl2R11/0JpmNN09msLEyJIcFVdTkXzStHjtKGc1sGh X-Gm-Gg: ASbGncvi7v+KWFhMmVYXnGvxfL5om+EGDWmxkxtClaI/6P88PBoVyOKwDYXeiLJpEkE 5AGnZveT3ScsRsdz4jaa5BdOOUhhHdeVVxoxM6QbvZUivJlVP3lrC3U49i0Y6Bo/8oz05n7nkzm Va3O08Ij1hQsf0WbMrTNz0megk+X8JwZEaKjB0u1TajbfWdodBL+nBsgfJ+ITObMq1j4GRwnE1O OOmZNt2dtuqHw/QGipr61Q79J6BqfWoY0XalhCD6/pafVGK5VBg+YyXDm6nLhWntNbr/rnXLvV1 DbJ7vHRdCiNQaZRtiM9a390Q X-Received: by 2002:a05:6402:50d0:b0:602:1b8b:290a with SMTP id 4fb4d7f45d1cf-6056d673ad4mr1982001a12.0.1748592215306; Fri, 30 May 2025 01:03:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLGzXezFRlg+nvYk3YPoKVr5+Ye7gtdDwNNem7qNeMTPnt09ZShpToc8TgQf2WbG4ALxvYwA== X-Received: by 2002:a05:6402:50d0:b0:602:1b8b:290a with SMTP id 4fb4d7f45d1cf-6056d673ad4mr1981969a12.0.1748592214847; Fri, 30 May 2025 01:03:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 10/14] hpet: adjust VMState for consistency with Rust version Date: Fri, 30 May 2025 10:03:02 +0200 Message-ID: <20250530080307.2055502-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592309693116600 Content-Type: text/plain; charset="utf-8" No functional change intended. Suggested-by: Zhao Liu Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- hw/timer/hpet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 0fd1337a156..9db027cf76f 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -328,16 +328,16 @@ static const VMStateDescription vmstate_hpet_timer = =3D { static const VMStateDescription vmstate_hpet =3D { .name =3D "hpet", .version_id =3D 2, - .minimum_version_id =3D 1, + .minimum_version_id =3D 2, .pre_save =3D hpet_pre_save, .post_load =3D hpet_post_load, .fields =3D (const VMStateField[]) { VMSTATE_UINT64(config, HPETState), VMSTATE_UINT64(isr, HPETState), VMSTATE_UINT64(hpet_counter, HPETState), - VMSTATE_UINT8_V(num_timers_save, HPETState, 2), + VMSTATE_UINT8(num_timers_save, HPETState), VMSTATE_VALIDATE("num_timers must match", hpet_validate_num_timers= ), - VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0, + VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers_save, 0, vmstate_hpet_timer, HPETTimer), VMSTATE_END_OF_LIST() }, --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592290; cv=none; d=zohomail.com; s=zohoarc; b=lBBd2BgII424fuxXRfhKP1nJybWqNb5iGvKXezNDrI4AdqslcMqfKemcw1NLl+RyTBfirGypMuOtwIPkBelzQEeIK3lBq89QI5uKNgNaz3qmfbBDlmQEjcQEI/Hn1ULHZuIsn7peek2RGpOQR4kFe8Zjg0oDDpcMQRNT7C08Knc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592290; 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=VTevlSH5ZQkYyW+Mm1Gr4K/vGmq39vmXxviFGBBggFI=; b=fNcsywZ/02n0Rd6/TfU/jy2jq8Qv/LYcalANG4SjNYYWkyZ/E0Cpoy2/d6/QyGIKZJLBOBgYtQ8L4iDRd+eOAvJ0+M3DFlRjnViwYwCTfZfdaw4gPVag0t1OSbC6ps0dDHFwTzhimnJKUr4Dbv7/+PasyrW1Si7mnJw+iCCGvcM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592290128708.9068863656103; Fri, 30 May 2025 01:04:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuiY-0002f4-SF; Fri, 30 May 2025 04:03:54 -0400 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 1uKuiO-0002Yx-EJ for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:45 -0400 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 1uKuiL-0004e8-Ge for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:43 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-75-MWJoTG4SNw6SXHKAAg9pKw-1; Fri, 30 May 2025 04:03:39 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ad556f5f1a9so131907666b.3 for ; Fri, 30 May 2025 01:03:39 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada5d82ccedsm283858666b.48.2025.05.30.01.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592220; 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=VTevlSH5ZQkYyW+Mm1Gr4K/vGmq39vmXxviFGBBggFI=; b=gVsPpSwsYFhRC2DlWsochc1nYu0nEnc7+AwWavoEyCwBR2Vdeuqhon/dGSZwRsODREUP1R ygtQSlqWIdcetg/YhxuD+cWA9w9/gPbcc3JWJ+8yFp8LpbWyhwxSSXZo6TJUno4il1WEKT BXzS7707dP9T+F6HZP5P9+0PeF7gCrw= X-MC-Unique: MWJoTG4SNw6SXHKAAg9pKw-1 X-Mimecast-MFC-AGG-ID: MWJoTG4SNw6SXHKAAg9pKw_1748592218 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592218; x=1749197018; 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=VTevlSH5ZQkYyW+Mm1Gr4K/vGmq39vmXxviFGBBggFI=; b=rHLUR+cBWSLB2nI2yDnW/rN0zZs4CAzA2AyUqYB0JdHwDWvm8Gb/KHJd0YDYWlphZJ drkbBn9u+AXW0/aZQHXeTFT3el+WHqvK7bWBrqgV+KDE/Epa5LC1klJd5xpwzYZYkTZZ Jy4eprZt50PndWXSg9YEbeDLSDRXmrktv+OgJns0QzELx0MIbzPT1c0ey0YC19VV2iFe IJQ88JtKD3Cp085d4o78vfAxyzbHkwhS2ltOydzsKcokv3Biq9/3TpBXy9YuDKBiDJed Sgp5ZdzlZT7jRljLpQf8uwP18qvJDQa144Hv64I10bwLkI8etjhhUMCrdZub3N9iNrls 8m8A== X-Gm-Message-State: AOJu0YzJS8Xkl1DkfPXVUpCIl2SmxemaT1s7WjLbqfLya2+cknI1vDEA 2DjuzSs5+y8jQ63iXvmqEdrgXirEtB5Hy+hSuIC3+aWV8AXQvTZmbvuuW1TquOBrWO49E7Zhx42 PgolxdhFKU6Y/fENmW4rpma7VITFmOSl7zI56zd7Eetmt1gCXuobaD4k6lCjYn9MRQr6OIFQD/R ZJXSNmDnVm8CgizA7Xmn6r0Ie/FNK4XD6KGpjyo2Ad X-Gm-Gg: ASbGncsqzAQy7fF/C0akjsJ+MbG6Dg726TaG7Nr634nqe3kNC6sxpuzc69A4bXnUZYg uFPTc0s4nbqaMQTeUCfO/VlvMMdCMVSiCG4aFLx7tB778MUvhcz1v1ZFZ0tddLsglwQeRc3Gmmd P/UOcdmroNz2R8HPz+cXLxGhQAMae4luJL8T2wy9LJYSBhRO9iZgKa5S6WNgRuodj9tB5n1uxVi TYPah9Kb9LGsuD4TuLPGOGOd2zIGoERnUbdUoGPAe+cVtOIQB0c+Jbk9l9nMBseIK9ll+AmzOGf YCbICYq2gRPwyArx2Ya43MuB X-Received: by 2002:a17:906:c110:b0:ad8:a935:b908 with SMTP id a640c23a62f3a-adb322ace09mr198482366b.30.1748592217962; Fri, 30 May 2025 01:03:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQGKio6NRXHsSIQTnkeXtmtHWiIdsWF3pF0J1K64iq//5rjyAERQNoX6NCZ32Oegrk6NwjPA== X-Received: by 2002:a17:906:c110:b0:ad8:a935:b908 with SMTP id a640c23a62f3a-adb322ace09mr198478966b.30.1748592217461; Fri, 30 May 2025 01:03:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Markus Armbruster , Zhao Liu Subject: [PATCH 11/14] hpet: return errors from realize if properties are incorrect Date: Fri, 30 May 2025 10:03:03 +0200 Message-ID: <20250530080307.2055502-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748592291783116600 Content-Type: text/plain; charset="utf-8" Do not silently adjust num_timers, and fail if intcap is 0. Reviewed-by: Markus Armbruster Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- hw/timer/hpet.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 9db027cf76f..cb48cc151f1 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -691,8 +691,14 @@ static void hpet_realize(DeviceState *dev, Error **err= p) int i; HPETTimer *timer; =20 + if (s->num_timers < HPET_MIN_TIMERS || s->num_timers > HPET_MAX_TIMERS= ) { + error_setg(errp, "hpet.num_timers must be between %d and %d", + HPET_MIN_TIMERS, HPET_MAX_TIMERS); + return; + } if (!s->intcap) { - warn_report("Hpet's intcap not initialized"); + error_setg(errp, "hpet.hpet-intcap not initialized"); + return; } if (hpet_fw_cfg.count =3D=3D UINT8_MAX) { /* first instance */ @@ -700,7 +706,7 @@ static void hpet_realize(DeviceState *dev, Error **errp) } =20 if (hpet_fw_cfg.count =3D=3D 8) { - error_setg(errp, "Only 8 instances of HPET is allowed"); + error_setg(errp, "Only 8 instances of HPET are allowed"); return; } =20 @@ -710,11 +716,6 @@ static void hpet_realize(DeviceState *dev, Error **err= p) sysbus_init_irq(sbd, &s->irqs[i]); } =20 - if (s->num_timers < HPET_MIN_TIMERS) { - s->num_timers =3D HPET_MIN_TIMERS; - } else if (s->num_timers > HPET_MAX_TIMERS) { - s->num_timers =3D HPET_MAX_TIMERS; - } for (i =3D 0; i < HPET_MAX_TIMERS; i++) { timer =3D &s->timer[i]; timer->qemu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, hpet_timer,= timer); --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592309; cv=none; d=zohomail.com; s=zohoarc; b=eAYeh0dDCQZkRURIdXWvTRuOpoEMewdXPa+MR8GU0ox45uHza0E7WjAdzKA7RhQGdEBH7GfjbcxvB3Ktuc8xe1ICIuCquwBHBxIsl+Yrvp0OYKUo2xtlxahk1YR4lpzmVqY7cpq+Qkb3PICRAR11++iZPiXvfCUSz1Z0Qzruz1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592309; 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=GD5j4iIBSM/wWOplLwp2FFPFSX88IRGEIBS2r4z9frY=; b=Byof4TgEgcEb8nEz+L1bzTSRaVtvCjt+/DihwJ4vzJEYfgkbzyNHeHrW1++ocqftRPSikuM+LTwYdhRO2URy5WUsMIjXF0olNoJ4npgWNqrSsNTUBy0RuQiMS70dcUhnRFUMb2xixt4jSqH0pJHqEGDlS3yteR5eVxso9js9vRE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592309634590.624081817809; Fri, 30 May 2025 01:05:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuia-0002gu-CR; Fri, 30 May 2025 04:03:56 -0400 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 1uKuiR-0002aC-Mw for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:47 -0400 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 1uKuiO-0004ej-D3 for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:46 -0400 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-p6px664lMw-0cGrtP4xzbw-1; Fri, 30 May 2025 04:03:42 -0400 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-604c41e0c10so1553515a12.1 for ; Fri, 30 May 2025 01:03:42 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-60566c2a757sm1247003a12.11.2025.05.30.01.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592223; 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=GD5j4iIBSM/wWOplLwp2FFPFSX88IRGEIBS2r4z9frY=; b=NsOqHWCplngkJ4aTDgWrwmjO4/cgdRDcOUuKTzol++q5/nFtMIpGnRIU8o0dMz/h7TrGtb ZmKEzA9OlWRX/nXr6Ig5VwJrUWSn3Leulbh9uUTSyt8kjCV0jVO8hgydEi8Om6bYvY8ad1 PfF0OmRPZgV2wQcOfHs3ppcWSrouvXw= X-MC-Unique: p6px664lMw-0cGrtP4xzbw-1 X-Mimecast-MFC-AGG-ID: p6px664lMw-0cGrtP4xzbw_1748592221 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592220; x=1749197020; 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=GD5j4iIBSM/wWOplLwp2FFPFSX88IRGEIBS2r4z9frY=; b=CwFCyhZo/Q4feBREgFW+C1y6xySfefLt/zKVwDau8lU38aB2GeCjFGeFEDGH4sSNHy 4JJuBy37UgL2OmTPRc1VLLjs+ZeR3CMc/Km0mNnbdqCDaVtoona9JCyKSr6oDqW35TQ0 nWEz9+XmWbsf7MxTdFWjF2p0CkAr8dmxjnGvr1l9GDt/5s4nKKl4eTXxUnocmQtFv1DF 7MgRbTBgxTV5EerpqYhAIGeI3apnYX2upd7S775X3tn+BpISCc3AMup3VTUlN8Xky3Ew fM9DNaVUgXfw4n0L7uDCuval+7xAUN4l2fbQdJZ59a/gZt1ynM+X/g5civlrTc4J+HmZ uHPA== X-Gm-Message-State: AOJu0YzSrR0Of1n02oUMpbC1uvR1/FABcOFhO2/UiJfPEQ6U7XY5ebEf yj0DeA21VHLrP2X3TM5lv9lCpLzb861ZVpV3yNLDqe3ODnle/95fTFZtBSnxXvxvG7b3BAhRgrL QWEBRYqwbzL4tWi2Gt7vuTZnIjKE3eSI/t9G+KBnRhU/WCrYIIlRxOAyR+dW4mf0aktB0MN4z++ nmDouZ/fwaJfOUqEh5QWMXnJIwnWHCreQyD7ZG9Bu5 X-Gm-Gg: ASbGncupCaZThOHZ+FhzMTYmTJIBeCarV/djVkSE07Sjw2SWKX+5eYeZGwK/3+JMrU+ YK2WnTP7sGSe3Qn5MagkOuhMHGlWG5DUzsWci9wJCjAhDm6aTxmV8IO5b+DTb3NCtJwYjoCtKYw 6TaSkxyBtJQU2/mQKibLz6aFjRlaBZ1ctEs/YhG72ViQj6+wHYU9fKxvFQ3C2wfw8cm6dx7wdxg wIOhTdonVTvIop9Muz7siSlqoXFZTWQbMIKkB5KfePE5GboxYGZgMUyTlwfbC4IJKNyT30E0iqa hH1XsRB2/+RLUQ== X-Received: by 2002:a05:6402:278c:b0:5f8:e6e5:54ac with SMTP id 4fb4d7f45d1cf-6057c1c36bfmr1160766a12.14.1748592220213; Fri, 30 May 2025 01:03:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNCdp6lDkMlujaocP8dWaACw5BnDqPn3Yld2gp69Q6EA29uYQsVMCayMPNnhnXpAWYk8OwEw== X-Received: by 2002:a05:6402:278c:b0:5f8:e6e5:54ac with SMTP id 4fb4d7f45d1cf-6057c1c36bfmr1160724a12.14.1748592219683; Fri, 30 May 2025 01:03:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 12/14] rust/hpet: return errors from realize if properties are incorrect Date: Fri, 30 May 2025 10:03:04 +0200 Message-ID: <20250530080307.2055502-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592312076116600 Content-Type: text/plain; charset="utf-8" Match the code in hpet.c; this also allows removing the BqlCell from the num_timers field. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/timer/hpet/src/device.rs | 16 +++++++--------- rust/hw/timer/hpet/src/fw_cfg.rs | 7 +++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index a957de1e767..cd439f90b7e 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -725,18 +725,16 @@ fn post_init(&self) { } =20 fn realize(&self) -> qemu_api::Result<()> { + if self.num_timers.get() < HPET_MIN_TIMERS || self.num_timers.get(= ) > HPET_MAX_TIMERS { + Err(format!( + "hpet.num_timers must be between {HPET_MIN_TIMERS} and {HP= ET_MAX_TIMERS}" + ))?; + } if self.int_route_cap =3D=3D 0 { - // TODO: Add error binding: warn_report() - println!("Hpet's hpet-intcap property not initialized"); + Err("hpet.hpet-intcap property not initialized")?; } =20 - self.hpet_id.set(HPETFwConfig::assign_hpet_id()); - - if self.num_timers.get() < HPET_MIN_TIMERS { - self.num_timers.set(HPET_MIN_TIMERS); - } else if self.num_timers.get() > HPET_MAX_TIMERS { - self.num_timers.set(HPET_MAX_TIMERS); - } + self.hpet_id.set(HPETFwConfig::assign_hpet_id()?); =20 self.init_timer(); // 64-bit General Capabilities and ID Register; LegacyReplacementR= oute. diff --git a/rust/hw/timer/hpet/src/fw_cfg.rs b/rust/hw/timer/hpet/src/fw_c= fg.rs index 6c10316104c..619d662ee1e 100644 --- a/rust/hw/timer/hpet/src/fw_cfg.rs +++ b/rust/hw/timer/hpet/src/fw_cfg.rs @@ -36,7 +36,7 @@ unsafe impl Zeroable for HPETFwConfig {} }; =20 impl HPETFwConfig { - pub(crate) fn assign_hpet_id() -> usize { + pub(crate) fn assign_hpet_id() -> Result { assert!(bql_locked()); // SAFETY: all accesses go through these methods, which guarantee // that the accesses are protected by the BQL. @@ -48,13 +48,12 @@ pub(crate) fn assign_hpet_id() -> usize { } =20 if fw_cfg.count =3D=3D 8 { - // TODO: Add error binding: error_setg() - panic!("Only 8 instances of HPET is allowed"); + Err("Only 8 instances of HPET are allowed")?; } =20 let id: usize =3D fw_cfg.count.into(); fw_cfg.count +=3D 1; - id + Ok(id) } =20 pub(crate) fn update_hpet_cfg(hpet_id: usize, timer_block_id: u32, add= ress: u64) { --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592266; cv=none; d=zohomail.com; s=zohoarc; b=c7/RjBKdOShkvQ22WomWsat8hbid6AVbamxnnCrxtx6la/HFu1xIhM64XP+tX2cetominrao5AL7+S2vQdGr18kWVenJ8f4ejSOGXCEBKUeFtduQYixDP22AsWGyXSYgrvjVxfopBP0rNhfHBTO40EH2D2Ht+8fk/91ITD42E8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592266; 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=1xUwrRORHhhFQcsqo0wojfaEACCcvTZjPhl1zMHXkSg=; b=mg5V3sM0COk32DiaMjvh7mN0bNs/Z30wa4nD9kDelBOIoChI0nAFsne2TV0kSjMTrYBQiUR/Vw6AlWcSLyWKt6j8xS1WxuM4iLZsjiTUnmLJNeNKNngU5TjjzDM35m+z9hH/hMW5DZPoH0EihOi4KvsAFpFCP9PFvPaHVaMKto8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592266691408.5869049638342; Fri, 30 May 2025 01:04:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuia-0002hL-OB; Fri, 30 May 2025 04:03:56 -0400 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 1uKuiX-0002eB-Cu for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:53 -0400 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 1uKuiV-0004fx-9s for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:52 -0400 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-216-jq0EMrfoMf6fkTC-Dzberw-1; Fri, 30 May 2025 04:03:49 -0400 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-604630fcce7so1639633a12.3 for ; Fri, 30 May 2025 01:03:49 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-605671437ebsm1244948a12.54.2025.05.30.01.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592230; 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=1xUwrRORHhhFQcsqo0wojfaEACCcvTZjPhl1zMHXkSg=; b=JtvJ+Wjp84naohgyf5uZJoiLZ/LUWE/ErxVXnP5CYtG2Prr2z5FtI0QtQacbJWL1Pdsxq3 DariQ9LZle6AiwBSvjRfc+Mspc49cqnQTwhMrRbCXCrk5n7IS95nQd/XvnCUdASUqw74hm I19yBKgNZWdKwwoxZNxpVtPMrKyUJdo= X-MC-Unique: jq0EMrfoMf6fkTC-Dzberw-1 X-Mimecast-MFC-AGG-ID: jq0EMrfoMf6fkTC-Dzberw_1748592228 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592227; x=1749197027; 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=1xUwrRORHhhFQcsqo0wojfaEACCcvTZjPhl1zMHXkSg=; b=ugMxucaZfSmREDK2TvSaF/cxo9y88SMfPRrTPLbaTh+7PoRJACdLgjj5CzkPyM2Mn0 ekpOuHcZ332fG4qy37uKLGT8rPjLvZfS6n95wPjwFVXxVTcfrB2veFYKvv5QEQEUi26l ctGjBEFkHAYH2u6kpviZetLvPpXnNc7Yn7fB32CstlIE6LqOsjESyhRv0h+JtNXxh5GY HShCyFFppTtH1EA8TDnfv6kyC/3XOCMaEDaQ9le9dPkdpfEUacQPioPIncRy5lxc7X7d aACkrbQeFQKHRNBz3UYQMKnF9j62jQ8uRZ93bhAitLr3IVJclG5BOpMAlVzTQhZiQka+ mwrA== X-Gm-Message-State: AOJu0YygACgS8Xnav1MljyeBwyq33eyGD0Ny+pCOniDWpKNLRCKv3eU9 nn3rnBm9tuzuh8KhFwAruah4d7Q48QIJ6Md39VblXn5a60Bx154BjdKFp3FHkK+tZVoi9f4kAGc Ev0PuF3HoOl7+gS05A7mkb0QgEg7HL5yWekKwXedfw5SN5S+ygao0yZ7TlSHJmCI2qHhPqhoo89 OdxSUnjaneo1Mn1jZoUbXs4+TPICA2nyt87JUhSjgM X-Gm-Gg: ASbGncuCg7i+fUr5uuW48/Yyjq7hsyV2FAGFHnRuWyO9HLv4NyFLzAF18h00nbEhCji TSLREXfFQZzDB3Yzfmz1M/QaGeZ4RMET4bdYq3qoOENTqzoywuZc3sKac9EypodwDcICdjjyJsZ E7rEV9BOPSM/QXnMVHdUc83lyIT07rLWKYpa8GGMFuMJldujitJWRwfBYRhoi+YtHgfdMVUB9UM DtVpgyqvl15wY2SHZglAiDIs1dmAWr96vgEwx0SmNT7hnHYFfdmSqM9zWZhSJE0bKhIJxzgd3xN js3GPTWSf4Lodw== X-Received: by 2002:a05:6402:2747:b0:600:e549:3c19 with SMTP id 4fb4d7f45d1cf-6056dd32172mr1890608a12.1.1748592227204; Fri, 30 May 2025 01:03:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENr6wMInrZzSNu4mB5xpd5xXz23G2fy9KRmV8MQ3JBJHdm0Yc0ynlIBVJr/49jhrxbX8/zqw== X-Received: by 2002:a05:6402:2747:b0:600:e549:3c19 with SMTP id 4fb4d7f45d1cf-6056dd32172mr1890307a12.1.1748592222087; Fri, 30 May 2025 01:03:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH 13/14] rust/hpet: Drop BqlCell wrapper for num_timers Date: Fri, 30 May 2025 10:03:05 +0200 Message-ID: <20250530080307.2055502-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1748592267392116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Now that the num_timers field is initialized as a property, someone may change its default value using qdev_prop_set_uint8(), but the value is fixed after the Rust code sees it first. Since there is no need to modify it after realize(), it is not to be necessary to have a BqlCell wrapper. Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250520152750.2542612-4-zhao1.liu@intel.com [Remove .into() as well. - Paolo] Signed-off-by: Paolo Bonzini --- rust/hw/timer/hpet/src/device.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index cd439f90b7e..735b2fbef79 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -562,7 +562,7 @@ pub struct HPETState { /// HPET timer array managed by this timer block. #[doc(alias =3D "timer")] timers: [BqlRefCell; HPET_MAX_TIMERS], - num_timers: BqlCell, + num_timers: usize, num_timers_save: BqlCell, =20 /// Instance id (HPET timer block ID). @@ -570,11 +570,6 @@ pub struct HPETState { } =20 impl HPETState { - // Get num_timers with `usize` type, which is useful to play with arra= y index. - fn get_num_timers(&self) -> usize { - self.num_timers.get() - } - const fn has_msi_flag(&self) -> bool { self.flags & (1 << HPET_FLAG_MSI_SUPPORT_SHIFT) !=3D 0 } @@ -636,7 +631,7 @@ fn set_cfg_reg(&self, shift: u32, len: u32, val: u64) { self.hpet_offset .set(ticks_to_ns(self.counter.get()) - CLOCK_VIRTUAL.get_n= s()); =20 - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { let mut t =3D timer.borrow_mut(); =20 if t.is_int_enabled() && t.is_int_active() { @@ -648,7 +643,7 @@ fn set_cfg_reg(&self, shift: u32, len: u32, val: u64) { // Halt main counter and disable interrupt generation. self.counter.set(self.get_ticks()); =20 - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { timer.borrow_mut().del_timer(); } } @@ -671,7 +666,7 @@ fn set_int_status_reg(&self, shift: u32, _len: u32, val= : u64) { let new_val =3D val << shift; let cleared =3D new_val & self.int_status.get(); =20 - for (index, timer) in self.timers.iter().take(self.get_num_timers(= )).enumerate() { + for (index, timer) in self.timers.iter().take(self.num_timers).enu= merate() { if cleared & (1 << index) !=3D 0 { timer.borrow_mut().update_irq(false); } @@ -725,7 +720,7 @@ fn post_init(&self) { } =20 fn realize(&self) -> qemu_api::Result<()> { - if self.num_timers.get() < HPET_MIN_TIMERS || self.num_timers.get(= ) > HPET_MAX_TIMERS { + if self.num_timers < HPET_MIN_TIMERS || self.num_timers > HPET_MAX= _TIMERS { Err(format!( "hpet.num_timers must be between {HPET_MIN_TIMERS} and {HP= ET_MAX_TIMERS}" ))?; @@ -743,7 +738,7 @@ fn realize(&self) -> qemu_api::Result<()> { 1 << HPET_CAP_COUNT_SIZE_CAP_SHIFT | 1 << HPET_CAP_LEG_RT_CAP_SHIFT | HPET_CAP_VENDER_ID_VALUE << HPET_CAP_VENDER_ID_SHIFT | - ((self.get_num_timers() - 1) as u64) << HPET_CAP_NUM_TIM_SHIFT= | // indicate the last timer + ((self.num_timers - 1) as u64) << HPET_CAP_NUM_TIM_SHIFT | // = indicate the last timer (HPET_CLK_PERIOD * FS_PER_NS) << HPET_CAP_CNT_CLK_PERIOD_SHIFT= , // 10 ns ); =20 @@ -753,7 +748,7 @@ fn realize(&self) -> qemu_api::Result<()> { } =20 fn reset_hold(&self, _type: ResetType) { - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { timer.borrow_mut().reset(); } =20 @@ -781,7 +776,7 @@ fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAd= drDecode { GlobalRegister::try_from(addr).map(HPETRegister::Global) } else { let timer_id: usize =3D ((addr - 0x100) / 0x20) as usize; - if timer_id <=3D self.get_num_timers() { + if timer_id < self.num_timers { // TODO: Add trace point - trace_hpet_ram_[read|write]_tim= er_id(timer_id) TimerRegister::try_from(addr & 0x18) .map(|reg| HPETRegister::Timer(&self.timers[timer_id],= reg)) @@ -852,12 +847,12 @@ fn pre_save(&self) -> i32 { * also added to the migration stream. Check that it matches the = value * that was configured. */ - self.num_timers_save.set(self.num_timers.get() as u8); + self.num_timers_save.set(self.num_timers as u8); 0 } =20 fn post_load(&self, _version_id: u8) -> i32 { - for timer in self.timers.iter().take(self.get_num_timers()) { + for timer in self.timers.iter().take(self.num_timers) { let mut t =3D timer.borrow_mut(); =20 t.cmp64 =3D t.calculate_cmp64(t.get_state().counter.get(), t.c= mp); @@ -882,7 +877,7 @@ fn is_offset_needed(&self) -> bool { } =20 fn validate_num_timers(&self, _version_id: u8) -> bool { - self.num_timers.get() =3D=3D self.num_timers_save.get().into() + self.num_timers =3D=3D self.num_timers_save.get().into() } } =20 --=20 2.49.0 From nobody Sat Nov 15 17:44:05 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748592362; cv=none; d=zohomail.com; s=zohoarc; b=Z0a/Wenj5mZAHcwA0N2R5bkxWon7NU7mTcRn8A3GRFhEpm4yLOyTbtkBJTtPOeu7p4v5m1vJowiz7RqpOgxYzLZlEV2lxIMB3PlDdZR8yHuoZyz34akCUMhG02WjqyMlr/7PeOHaduP61A7d8/496RswEYlF9bQ1qBmHG0+QUuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748592362; 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=RS6NkNuicN22cppwE3868JJ1vrcCIE30ciMJOFo5c6w=; b=TVb09qCl0DZbzuhdFvP2aZWgI49ilp8DbaZetZWfafVTuZYpyPTso9fBSoOueyqdLbQIBs4yWTN8msIHcG5YbnVK00jyhiTiCQ0jmXbwY5ZzjkZM9Yaff15gxHZVkbWnPNDf2vA105ZLQ+7fRv3wIgm9RSdO4lTDuU16/47mn7I= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748592362771143.0270969736879; Fri, 30 May 2025 01:06:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uKuic-0002hv-C3; Fri, 30 May 2025 04:03:58 -0400 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 1uKuiY-0002fM-RX for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:54 -0400 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 1uKuiX-0004gH-6r for qemu-devel@nongnu.org; Fri, 30 May 2025 04:03:54 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-8A5t8oJmP5-YGtwXXLNeFw-1; Fri, 30 May 2025 04:03:51 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ac6ef2d1b7dso128604266b.0 for ; Fri, 30 May 2025 01:03:51 -0700 (PDT) Received: from [192.168.122.1] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada5d7fecf6sm279883666b.30.2025.05.30.01.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 May 2025 01:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748592232; 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=RS6NkNuicN22cppwE3868JJ1vrcCIE30ciMJOFo5c6w=; b=CEPgvrqSfvNuSsMwZ2CZcnWrbVu+sFzRJIImbkUEquKW2FYXJ3PDHAD6+sZ4NdA//IMG2I 00BmgREYZCVCeRS6guxG/nEoL/3OboeQDS8xt/dQ+E5/LZVeG75tsdZP8orZoecM5CWYhm dv+C3sfjL91mn0oKW3PQBrUOlxxA0UI= X-MC-Unique: 8A5t8oJmP5-YGtwXXLNeFw-1 X-Mimecast-MFC-AGG-ID: 8A5t8oJmP5-YGtwXXLNeFw_1748592230 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748592230; x=1749197030; 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=RS6NkNuicN22cppwE3868JJ1vrcCIE30ciMJOFo5c6w=; b=N/QgTdzI7AvsHsFP0maZo1iwGtHCucgH09pmURC62kaiEOHHfAZy2r0MCJaHTTh+rQ asrhqUxS7HV0MbqASEN8J1ObR+XFD+SQGdGp+xrbmd4iZCYIuPFG4KlYidhmXhdKg6Pm b1/jmO/ry/in48yaHJhHGhzSgZgSIGl2fpakFXrfoKowuAIHdDSNh8mrjvsawpb3SSDI xDWOXGstiVPy0B659w3iE8+BrvFsD/XESGDENgrPQc9k1aTP1izuevpxRUWTSscLwERJ oPT8IcANm/oLK8OG2oCpVMzbY205n6Ygw6IFRawdIZvORTR890pnzvnzwaJd5a4pqf9w m3EA== X-Gm-Message-State: AOJu0YwJAcyq361n6k5QlkCFNuqb4V1x9nwCWK0IqOOK9tnfj1tHjiVK R5ziSffebRew/ednSWa7olm/5+KbXaQbPwS+yAqiWLM7F/yLUTLmLdE/zMfDoHP+6HTDcQ/o1KY 8uve4f9N/ISaW4mLRiaNT0kslreMRwfHZxMycC0cLnLImbcp1SNQFQCGeIU/10O7HWFM7xNTppB JKV6KATvrLAxnvXOrjlcSicqjytxQ5pzCTzfz4lCbm X-Gm-Gg: ASbGncu8ZuaF8RJ7fZ+CQJUwBuqlEJse5IiJpyo9qWpjkg2KdhVKh7JlABR1Oi+Lyag Fvkg5QiTSE6x5Sv/F+ZGbasayKnCMpo/yGgptZSHPIOVHn7Wdxzgy53y3EU5R0ZobneGWeSfKXr B/9qHAbJH1dUIjkuRIbE9mXKyidsECWgyb5+9T5DSEt8vwFyWntBJHQjacPN9RjeRhM7TaI9TcS a8bfYRB7dBwaZwnNaU4aAvs971eznAw7qkB9oEbHdEHoSoWicutf2OjIT097mghvkGCcNBRos7f NZqwJJFp1D2McQ== X-Received: by 2002:a17:906:6a09:b0:ad5:5447:6ec2 with SMTP id a640c23a62f3a-adb3244b7bbmr198161866b.53.1748592229716; Fri, 30 May 2025 01:03:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwqSK4c3tIVbuKW62gwkNC+WXhrSR8UgOdFlud+sIB0t13w65s6AuDSEAId9pOhOhzIEc+3A== X-Received: by 2002:a17:906:6a09:b0:ad5:5447:6ec2 with SMTP id a640c23a62f3a-adb3244b7bbmr198158766b.53.1748592229279; Fri, 30 May 2025 01:03:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-rust@nongnu.org Subject: [PATCH 14/14] docs: update Rust module status Date: Fri, 30 May 2025 10:03:06 +0200 Message-ID: <20250530080307.2055502-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530080307.2055502-1-pbonzini@redhat.com> References: <20250530080307.2055502-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: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.902, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1748592364380116600 Content-Type: text/plain; charset="utf-8" error is new; offset_of is gone. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- docs/devel/rust.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 34d9c7945b7..29ae59395e8 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -155,10 +155,10 @@ module status ``callbacks`` complete ``cell`` stable ``errno`` complete +``error`` stable ``irq`` complete ``memory`` stable ``module`` complete -``offset_of`` stable ``qdev`` stable ``qom`` stable ``sysbus`` stable --=20 2.49.0